Skip to content

Commit 3d1d374

Browse files
committed
Update anoncreds presentation handler to avoid indy parsing
Signed-off-by: jamshale <[email protected]>
1 parent 1a7ad66 commit 3d1d374

File tree

1 file changed

+17
-10
lines changed
  • acapy_agent/protocols/present_proof/v2_0/formats/anoncreds

1 file changed

+17
-10
lines changed

acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ......anoncreds.models.presentation_request import AnoncredsPresentationRequestSchema
1212
from ......anoncreds.models.proof import AnoncredsProofSchema
1313
from ......anoncreds.models.utils import get_requested_creds_from_proof_request_preview
14+
from ......anoncreds.registry import AnonCredsRegistry
1415
from ......anoncreds.util import generate_pr_nonce
1516
from ......anoncreds.verifier import AnonCredsVerifier
1617
from ......messaging.decorators.attach_decorator import AttachDecorator
@@ -175,7 +176,7 @@ async def create_pres(
175176
async def receive_pres(self, message: V20Pres, pres_ex_record: V20PresExRecord):
176177
"""Receive a presentation and check for presented values vs. proposal request."""
177178

178-
def _check_proof_vs_proposal():
179+
async def _check_proof_vs_proposal():
179180
"""Check for bait and switch in presented values vs. proposal request."""
180181
from ..indy.handler import IndyPresExchangeHandler
181182

@@ -231,15 +232,18 @@ def _check_proof_vs_proposal():
231232
name: values["raw"] for name, values in attr_spec["values"].items()
232233
}
233234
sub_proof_index = attr_spec["sub_proof_index"]
235+
registry = self.profile.inject(AnonCredsRegistry)
234236
schema_id = proof["identifiers"][sub_proof_index]["schema_id"]
237+
schema_info = await registry.get_schema_info_by_id(schema_id)
235238
cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"]
239+
cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id)
236240
criteria = {
237241
"schema_id": schema_id,
238-
"schema_issuer_did": schema_id.split(":")[-4],
239-
"schema_name": schema_id.split(":")[-2],
240-
"schema_version": schema_id.split(":")[-1],
242+
"schema_issuer_did": schema_info.issuer_id,
243+
"schema_name": schema_info.name,
244+
"schema_version": schema_info.version,
241245
"cred_def_id": cred_def_id,
242-
"issuer_did": cred_def_id.split(":")[-5],
246+
"issuer_did": cred_def_info.issuer_id,
243247
**{
244248
f"attr::{name}::value": value
245249
for name, value in proof_values.items()
@@ -292,15 +296,18 @@ def _check_proof_vs_proposal():
292296
f"Proposed request predicate on {req_name} not in presentation"
293297
)
294298

299+
registry = self.profile.inject(AnonCredsRegistry)
295300
schema_id = proof["identifiers"][sub_proof_index]["schema_id"]
301+
schema_info = await registry.get_schema_info_by_id(schema_id)
296302
cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"]
303+
cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id)
297304
criteria = {
298305
"schema_id": schema_id,
299-
"schema_issuer_did": schema_id.split(":")[-4],
300-
"schema_name": schema_id.split(":")[-2],
301-
"schema_version": schema_id.split(":")[-1],
306+
"schema_issuer_did": schema_info.issuer_id,
307+
"schema_name": schema_info.name,
308+
"schema_version": schema_info.version,
302309
"cred_def_id": cred_def_id,
303-
"issuer_did": cred_def_id.split(":")[-5],
310+
"issuer_did": cred_def_info.issuer_id,
304311
}
305312

306313
if (
@@ -313,7 +320,7 @@ def _check_proof_vs_proposal():
313320
)
314321

315322
proof = message.attachment(AnonCredsPresExchangeHandler.format)
316-
_check_proof_vs_proposal()
323+
await _check_proof_vs_proposal()
317324

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

0 commit comments

Comments
 (0)