From 9ded95b44236ada55511af8e2022734ed494f9e9 Mon Sep 17 00:00:00 2001 From: Sarthak Vijayvergiya Date: Mon, 1 Apr 2024 21:13:36 +0200 Subject: [PATCH] fix store cred Signed-off-by: Sarthak Vijayvergiya --- aries_cloudagent/anoncreds/holder.py | 26 +++--- .../anoncreds/tests/test_holder.py | 3 + demo/runners/faber.py | 93 ++++--------------- 3 files changed, 33 insertions(+), 89 deletions(-) diff --git a/aries_cloudagent/anoncreds/holder.py b/aries_cloudagent/anoncreds/holder.py index dcf17dbbd9..42b2a6ccd9 100644 --- a/aries_cloudagent/anoncreds/holder.py +++ b/aries_cloudagent/anoncreds/holder.py @@ -209,7 +209,6 @@ async def store_credential( return await self._finish_store_credential( credential_definition, cred_recvd, - credential_data, credential_request_metadata, credential_attr_mime_types, credential_id, @@ -220,12 +219,12 @@ async def _finish_store_credential( self, credential_definition: dict, cred_recvd: Credential, - credential_data: dict, credential_request_metadata: dict, credential_attr_mime_types: dict = None, credential_id: str = None, rev_reg_def: dict = None, ) -> str: + credential_data = cred_recvd.to_dict() schema_id = cred_recvd.schema_id schema_id_parts = re.match(r"^(\w+):2:([^:]+):([^:]+)$", schema_id) if not schema_id_parts: @@ -300,21 +299,23 @@ async def store_credential_w3c( MIME types to store as non-secret record, if specified credential_id: optionally override the stored credential id rev_reg_def: revocation registry definition in json + Returns: the ID of the stored credential + """ try: - # secret = await self.get_master_secret() + secret = await self.get_master_secret() cred_w3c = W3cCredential.load(credential_data) - # cred_legacy = cred_w3c.to_legacy() - # cred_w3c_recvd = await asyncio.get_event_loop().run_in_executor( - # None, - # cred_w3c.process, - # credential_request_metadata, - # secret, - # credential_definition, - # rev_reg_def, - # ) + cred_w3c.to_legacy() + await asyncio.get_event_loop().run_in_executor( + None, + cred_w3c.process, + credential_request_metadata, + secret, + credential_definition, + rev_reg_def, + ) cred_recvd = Credential.from_w3c(cred_w3c) except AnoncredsError as err: raise AnonCredsHolderError("Error processing received credential") from err @@ -322,7 +323,6 @@ async def store_credential_w3c( return await self._finish_store_credential( credential_definition, cred_recvd, - credential_data, credential_request_metadata, credential_attr_mime_types, credential_id, diff --git a/aries_cloudagent/anoncreds/tests/test_holder.py b/aries_cloudagent/anoncreds/tests/test_holder.py index 6a286b050a..bbbcfee978 100644 --- a/aries_cloudagent/anoncreds/tests/test_holder.py +++ b/aries_cloudagent/anoncreds/tests/test_holder.py @@ -57,6 +57,9 @@ def __init__(self, bad_schema=False, bad_cred_def=False): def to_json_buffer(self): return b"credential" + def to_dict(self): + return MOCK_CRED + class MockCredential: def __init__(self, bad_schema=False, bad_cred_def=False): diff --git a/demo/runners/faber.py b/demo/runners/faber.py index e58420ba3f..2f80e2772f 100644 --- a/demo/runners/faber.py +++ b/demo/runners/faber.py @@ -342,61 +342,6 @@ def generate_proof_request_web_request( return proof_request_web_request elif cred_type == CRED_FORMAT_VC_DI: - req_attrs = [ - { - "name": "name", - "restrictions": [{"schema_name": "degree schema"}], - }, - { - "name": "date", - "restrictions": [{"schema_name": "degree schema"}], - }, - ] - if revocation: - req_attrs.append( - { - "name": "degree", - "restrictions": [{"schema_name": "degree schema"}], - "non_revoked": {"to": int(time.time() - 1)}, - }, - ) - else: - req_attrs.append( - { - "name": "degree", - "restrictions": [{"schema_name": "degree schema"}], - } - ) - if SELF_ATTESTED: - # test self-attested claims - req_attrs.append( - {"name": "self_attested_thing"}, - ) - req_preds = [ - # test zero-knowledge proofs - { - "name": "birthdate_dateint", - "p_type": "<=", - "p_value": int(birth_date.strftime(birth_date_format)), - "restrictions": [{"schema_name": "degree schema"}], - } - ] - - vc_di_proof_request = { - "name": "Proof of Education", - "version": "1.0", - "requested_attributes": { - f"0_{req_attr['name']}_uuid": req_attr for req_attr in req_attrs - }, - "requested_predicates": { - f"0_{req_pred['name']}_GE_uuid": req_pred - for req_pred in req_preds - }, - } - - if revocation: - vc_di_proof_request["non_revoked"] = {"to": int(time.time())} - proof_request_web_request = { "comment": "test proof request for json-ld", "presentation_request": { @@ -407,50 +352,46 @@ def generate_proof_request_web_request( }, "presentation_definition": { "id": "32f54163-7166-48f1-93d8-ff217bdb0654", - "format": {"ldp_vp": {"proof_type": [SIG_TYPE_BLS]}}, + "submission_requirements": [ + { + "name": "Citizenship Information", + "rule": "pick", + "min": 1, + "from": "A", + } + ], "input_descriptors": [ { "id": "citizenship_input_1", "name": "EU Driver's License", + "group": ["A"], "schema": [ { "uri": "https://www.w3.org/2018/credentials#VerifiableCredential" }, { - "uri": "https://w3id.org/citizenship#PermanentResident" + "uri": "https://w3id.org/citizenship#PermanentResidentCard" }, ], "constraints": { "limit_disclosure": "required", - "is_holder": [ - { - "directive": "required", - "field_id": [ - "1f44d55f-f161-4938-a659-f8026467f126" - ], - } - ], "fields": [ - { - "id": "1f44d55f-f161-4938-a659-f8026467f126", - "path": [ - "$.credentialSubject.familyName" - ], - "purpose": "The claim must be from one of the specified person", - "filter": {"const": "SMITH"}, - }, { "path": [ "$.credentialSubject.givenName" ], - "purpose": "The claim must be from one of the specified person", - }, + "purpose": "The claim must be from one of the specified issuers", + "filter": { + "type": "string", + "enum": ["JOHN", "CAI"], + }, + } ], }, } ], }, - } + }, }, } if not connectionless: