From 5c0540eac3538e833ff34347d5c27209d972a182 Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 21 Nov 2024 22:42:40 +0000 Subject: [PATCH] Add better comments for format compatibilty imports Signed-off-by: jamshale --- .../issue_credential/v2_0/formats/anoncreds/handler.py | 6 +++++- .../protocols/issue_credential/v2_0/formats/indy/handler.py | 6 +++--- .../present_proof/v2_0/formats/anoncreds/handler.py | 4 ++++ .../protocols/present_proof/v2_0/formats/indy/handler.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/acapy_agent/protocols/issue_credential/v2_0/formats/anoncreds/handler.py b/acapy_agent/protocols/issue_credential/v2_0/formats/anoncreds/handler.py index d2f65f6200..a25e4bb62c 100644 --- a/acapy_agent/protocols/issue_credential/v2_0/formats/anoncreds/handler.py +++ b/acapy_agent/protocols/issue_credential/v2_0/formats/anoncreds/handler.py @@ -250,10 +250,11 @@ async def create_request( ) await self._check_uniqueness(cred_ex_record.cred_ex_id) + holder_did = request_data.get("holder_did") if request_data else None + # For backwards compatibility, remove indy backup when indy format is retired from ..indy.handler import IndyCredFormatHandler - holder_did = request_data.get("holder_did") if request_data else None cred_offer = cred_ex_record.cred_offer.attachment( AnonCredsCredFormatHandler.format ) or cred_ex_record.cred_offer.attachment(IndyCredFormatHandler.format) @@ -324,6 +325,7 @@ async def issue_credential( """Issue anoncreds credential.""" await self._check_uniqueness(cred_ex_record.cred_ex_id) + # For backwards compatibility, remove indy backup when indy format is retired from ..indy.handler import IndyCredFormatHandler if cred_ex_record.cred_offer.attachment(IndyCredFormatHandler.format): @@ -393,6 +395,8 @@ async def store_credential( self, cred_ex_record: V20CredExRecord, cred_id: Optional[str] = None ) -> None: """Store anoncreds credential.""" + + # For backwards compatibility, remove indy backup when indy format is retired from ..indy.handler import IndyCredFormatHandler cred = cred_ex_record.cred_issue.attachment( diff --git a/acapy_agent/protocols/issue_credential/v2_0/formats/indy/handler.py b/acapy_agent/protocols/issue_credential/v2_0/formats/indy/handler.py index 1a3a9c9b56..19a2857cf3 100644 --- a/acapy_agent/protocols/issue_credential/v2_0/formats/indy/handler.py +++ b/acapy_agent/protocols/issue_credential/v2_0/formats/indy/handler.py @@ -182,7 +182,7 @@ async def create_proposal( self, cred_ex_record: V20CredExRecord, proposal_data: Mapping[str, str] ) -> Tuple[V20CredFormat, AttachDecorator]: """Create indy credential proposal.""" - # Temporary shim while the new anoncreds library integration is in progress + # Create the proposal with the anoncreds handler if agent is anoncreds capable if self.anoncreds_handler: return await self.anoncreds_handler.create_proposal( cred_ex_record, @@ -296,7 +296,7 @@ async def create_request( ) -> CredFormatAttachment: """Create indy credential request.""" - # This is for reverse compatibility + # Create the request with the anoncreds handler if agent is anoncreds capable if self.anoncreds_handler: return await self.anoncreds_handler.create_request( cred_ex_record, @@ -350,7 +350,7 @@ async def receive_request( self, cred_ex_record: V20CredExRecord, cred_request_message: V20CredRequest ) -> None: """Receive indy credential request.""" - # Temporary shim while the new anoncreds library integration is in progress + # Receive the request with the anoncreds handler if agent is anoncreds capable if self.anoncreds_handler: return await self.anoncreds_handler.receive_request( cred_ex_record, diff --git a/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py b/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py index e16450ec23..2c19d13443 100644 --- a/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py +++ b/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py @@ -132,11 +132,13 @@ async def create_pres( """Create a presentation.""" requested_credentials = {} + # This is used for the fallback to indy format from ..indy.handler import IndyPresExchangeHandler if not request_data: try: proof_request = pres_ex_record.pres_request + # Fall back to indy format should be removed when indy format retired proof_request = proof_request.attachment( AnonCredsPresExchangeHandler.format ) or proof_request.attachment(IndyPresExchangeHandler.format) @@ -150,6 +152,7 @@ async def create_pres( LOGGER.warning(f"{err}") raise V20PresFormatHandlerError(f"No matching credentials found: {err}") else: + # Fall back to indy format should be removed when indy format retired if ( AnonCredsPresExchangeHandler.format.api in request_data or IndyPresExchangeHandler.format.api in request_data @@ -176,6 +179,7 @@ def _check_proof_vs_proposal(): """Check for bait and switch in presented values vs. proposal request.""" from ..indy.handler import IndyPresExchangeHandler + # Fall back to indy format should be removed when indy format retired proof_req = pres_ex_record.pres_request.attachment( AnonCredsPresExchangeHandler.format ) or pres_ex_record.pres_request.attachment(IndyPresExchangeHandler.format) diff --git a/acapy_agent/protocols/present_proof/v2_0/formats/indy/handler.py b/acapy_agent/protocols/present_proof/v2_0/formats/indy/handler.py index 49d24885e7..bac3933919 100644 --- a/acapy_agent/protocols/present_proof/v2_0/formats/indy/handler.py +++ b/acapy_agent/protocols/present_proof/v2_0/formats/indy/handler.py @@ -346,8 +346,8 @@ async def verify_pres(self, pres_ex_record: V20PresExRecord) -> V20PresExRecord: return await self.anoncreds_handler.verify_pres(pres_ex_record) pres_request_msg = pres_ex_record.pres_request - from ..anoncreds.handler import AnonCredsPresExchangeHandler + # The `or` anoncreds format is for the indy <--> anoncreds compatibility indy_proof_request = pres_request_msg.attachment( IndyPresExchangeHandler.format ) or pres_request_msg.attachment(AnonCredsPresExchangeHandler.format)