Skip to content

Commit

Permalink
Update anoncreds presentation handler to avoid indy parsing
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed Dec 17, 2024
1 parent 1a7ad66 commit 3d1d374
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ......anoncreds.models.presentation_request import AnoncredsPresentationRequestSchema
from ......anoncreds.models.proof import AnoncredsProofSchema
from ......anoncreds.models.utils import get_requested_creds_from_proof_request_preview
from ......anoncreds.registry import AnonCredsRegistry
from ......anoncreds.util import generate_pr_nonce
from ......anoncreds.verifier import AnonCredsVerifier
from ......messaging.decorators.attach_decorator import AttachDecorator
Expand Down Expand Up @@ -175,7 +176,7 @@ async def create_pres(
async def receive_pres(self, message: V20Pres, pres_ex_record: V20PresExRecord):
"""Receive a presentation and check for presented values vs. proposal request."""

def _check_proof_vs_proposal():
async def _check_proof_vs_proposal():
"""Check for bait and switch in presented values vs. proposal request."""
from ..indy.handler import IndyPresExchangeHandler

Expand Down Expand Up @@ -231,15 +232,18 @@ def _check_proof_vs_proposal():
name: values["raw"] for name, values in attr_spec["values"].items()
}
sub_proof_index = attr_spec["sub_proof_index"]
registry = self.profile.inject(AnonCredsRegistry)
schema_id = proof["identifiers"][sub_proof_index]["schema_id"]
schema_info = await registry.get_schema_info_by_id(schema_id)
cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"]
cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id)
criteria = {
"schema_id": schema_id,
"schema_issuer_did": schema_id.split(":")[-4],
"schema_name": schema_id.split(":")[-2],
"schema_version": schema_id.split(":")[-1],
"schema_issuer_did": schema_info.issuer_id,
"schema_name": schema_info.name,
"schema_version": schema_info.version,
"cred_def_id": cred_def_id,
"issuer_did": cred_def_id.split(":")[-5],
"issuer_did": cred_def_info.issuer_id,
**{
f"attr::{name}::value": value
for name, value in proof_values.items()
Expand Down Expand Up @@ -292,15 +296,18 @@ def _check_proof_vs_proposal():
f"Proposed request predicate on {req_name} not in presentation"
)

registry = self.profile.inject(AnonCredsRegistry)
schema_id = proof["identifiers"][sub_proof_index]["schema_id"]
schema_info = await registry.get_schema_info_by_id(schema_id)
cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"]
cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id)
criteria = {
"schema_id": schema_id,
"schema_issuer_did": schema_id.split(":")[-4],
"schema_name": schema_id.split(":")[-2],
"schema_version": schema_id.split(":")[-1],
"schema_issuer_did": schema_info.issuer_id,
"schema_name": schema_info.name,
"schema_version": schema_info.version,
"cred_def_id": cred_def_id,
"issuer_did": cred_def_id.split(":")[-5],
"issuer_did": cred_def_info.issuer_id,
}

if (
Expand All @@ -313,7 +320,7 @@ def _check_proof_vs_proposal():
)

proof = message.attachment(AnonCredsPresExchangeHandler.format)
_check_proof_vs_proposal()
await _check_proof_vs_proposal()

async def verify_pres(self, pres_ex_record: V20PresExRecord) -> V20PresExRecord:
"""Verify a presentation.
Expand Down

0 comments on commit 3d1d374

Please sign in to comment.