Skip to content

Commit

Permalink
fix store cred
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Vijayvergiya <[email protected]>
  • Loading branch information
sarthakvijayvergiya committed Apr 3, 2024
1 parent a32f225 commit 9ded95b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 89 deletions.
26 changes: 13 additions & 13 deletions aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -300,29 +299,30 @@ 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

return await self._finish_store_credential(
credential_definition,
cred_recvd,
credential_data,
credential_request_metadata,
credential_attr_mime_types,
credential_id,
Expand Down
3 changes: 3 additions & 0 deletions aries_cloudagent/anoncreds/tests/test_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
93 changes: 17 additions & 76 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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:
Expand Down

0 comments on commit 9ded95b

Please sign in to comment.