Skip to content

Commit

Permalink
Add better comments for format compatibilty imports
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed Nov 22, 2024
1 parent 8863aad commit 5c0540e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5c0540e

Please sign in to comment.