Skip to content

Commit

Permalink
Merge pull request #1493 from shaangill025/issue_1486
Browse files Browse the repository at this point in the history
DIF PresExch - ProblemReport and "is_holder"
  • Loading branch information
ianco authored Nov 17, 2021
2 parents f9506df + 642375a commit 255fc1e
Show file tree
Hide file tree
Showing 9 changed files with 889 additions and 321 deletions.
77 changes: 36 additions & 41 deletions aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def field_ids_for_is_holder(self, constraints: Constraints) -> Sequence[str]:
reqd_field_ids = []
return reqd_field_ids
for holder in constraints.holders:
if holder.directive == "required":
if holder.directive == "required" or holder.directive == "preferred":
reqd_field_ids = set.union(reqd_field_ids, set(holder.field_ids))
return list(reqd_field_ids)

Expand Down Expand Up @@ -1255,43 +1255,41 @@ async def create_vp(
return vp
else:
vp = await create_presentation(credentials=filtered_creds_list)
vp["presentation_submission"] = submission_property.serialize()
if self.proof_type is BbsBlsSignature2020.signature_type:
vp["@context"].append(SECURITY_CONTEXT_BBS_URL)
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
issue_suite = await self._get_issue_suite(
wallet=wallet,
issuer_id=issuer_id,
)
signed_vp = await sign_presentation(
presentation=vp,
suite=issue_suite,
challenge=challenge,
document_loader=document_loader,
)
return signed_vp
else:
vp = await create_presentation(credentials=applicable_creds_list)
vp["presentation_submission"] = submission_property.serialize()
if self.proof_type is BbsBlsSignature2020.signature_type:
vp["@context"].append(SECURITY_CONTEXT_BBS_URL)
if self.pres_signing_did:
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
issue_suite = await self._get_issue_suite(
wallet=wallet,
issuer_id=self.pres_signing_did,
)
signed_vp = await sign_presentation(
presentation=vp,
suite=issue_suite,
challenge=challenge,
document_loader=document_loader,
)
return signed_vp
if not self.pres_signing_did:
(
issuer_id,
filtered_creds_list,
) = await self.get_sign_key_credential_subject_id(
applicable_creds=applicable_creds
)
if not issuer_id:
vp = await create_presentation(credentials=applicable_creds_list)
vp["presentation_submission"] = submission_property.serialize()
if self.proof_type is BbsBlsSignature2020.signature_type:
vp["@context"].append(SECURITY_CONTEXT_BBS_URL)
return vp
else:
vp = await create_presentation(credentials=filtered_creds_list)
else:
return vp
issuer_id = self.pres_signing_did
vp = await create_presentation(credentials=applicable_creds_list)
vp["presentation_submission"] = submission_property.serialize()
if self.proof_type is BbsBlsSignature2020.signature_type:
vp["@context"].append(SECURITY_CONTEXT_BBS_URL)
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
issue_suite = await self._get_issue_suite(
wallet=wallet,
issuer_id=issuer_id,
)
signed_vp = await sign_presentation(
presentation=vp,
suite=issue_suite,
challenge=challenge,
document_loader=document_loader,
)
return signed_vp

def check_if_cred_id_derived(self, id: str) -> bool:
"""Check if credential or credentialSubjet id is derived."""
Expand Down Expand Up @@ -1366,9 +1364,6 @@ async def verify_received_pres(
desc_map_item_id = desc_map_item.get("id")
constraint = inp_desc_id_contraint_map.get(desc_map_item_id)
schema_filter = inp_desc_id_schemas_map.get(desc_map_item_id)
is_one_of_filtered = False
if desc_map_item_id in inp_desc_id_schema_one_of_filter:
is_one_of_filtered = True
desc_map_item_path = desc_map_item.get("path")
jsonpath = parse(desc_map_item_path)
match = jsonpath.find(pres)
Expand All @@ -1378,7 +1373,7 @@ async def verify_received_pres(
)
for match_item in match:
if not await self.apply_constraint_received_cred(
constraint, match_item.value, is_one_of_filtered
constraint, match_item.value
):
raise DIFPresExchError(
f"Constraint specified for {desc_map_item_id} does not "
Expand Down Expand Up @@ -1413,7 +1408,7 @@ async def restrict_field_paths_one_of_filter(
return applied_field_paths

async def apply_constraint_received_cred(
self, constraint: Constraints, cred_dict: dict, is_one_of_filtered: bool = False
self, constraint: Constraints, cred_dict: dict
) -> bool:
"""Evaluate constraint from the request against received credential."""
fields = constraint._fields
Expand Down
209 changes: 209 additions & 0 deletions aries_cloudagent/protocols/present_proof/dif/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,131 @@ def create_vcrecord(cred_dict: dict, expanded_types: list):
)


EXPANDED_CRED_FHIR_TYPE_1 = [
{
"https://www.w3.org/2018/credentials#credentialSubject": [
{
"http://hl7.org/fhir/Patient": [
{
"@id": "urn:bnid:_:c14n7",
"@type": ["http://hl7.org/fhir/resource-types#Patient"],
"http://hl7.org/fhir/Patient.address": [
{
"@id": "urn:bnid:_:c14n1",
"http://hl7.org/fhir/Address.city": [
{"@value": "Рума"}
],
"http://hl7.org/fhir/Address.country": [
{"@value": "test"}
],
},
{
"@id": "urn:bnid:_:c14n1",
"http://hl7.org/fhir/Address.city": [
{"@value": "Рума"}
],
},
],
}
],
"@id": "urn:bnid:_:c14n6",
}
],
"@id": "urn:bnid:_:c14n4",
"https://www.w3.org/2018/credentials#issuanceDate": [
{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2021-10-01T20:16:40+02:00",
}
],
"https://www.w3.org/2018/credentials#issuer": [{"@id": "did:key:test"}],
"https://w3id.org/security#proof": [
{
"@graph": [
{
"http://purl.org/dc/terms/created": [
{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2021-10-01T18:16:41.072975+00:00",
}
],
"https://w3id.org/security#nonce": [
{
"@value": "M9yQx0eKIAI3Zs0sLF1kQsO7/hV1ZKEnqX9f0V/SzwRMKEixa0tJgqbGwviMA04XoL0="
}
],
"https://w3id.org/security#proofPurpose": [
{"@id": "https://w3id.org/security#assertionMethod"}
],
"https://w3id.org/security#proofValue": [
{
"@value": "ACYgFHwPj5TxR9H+k+V+rBsfZ3SgOEvoKrYCcvAl4HhaKNR039r5UWE89tnHaVOx22k604EWibf0s7BTezijjYv1VWSVkZar4wtOslplXv6g7dVc8/0IWXQWOfn2hTE2N65Wv8xz2qw5dWwEzSXTx44o15wE2ubimgGFMM7Mv++SAoHC1dQGotGqKqOB2PS8yI+ToiWmswAAAHSD5NRIZHKeiWP8hK/e9xUYy5gSPBivDVAORybl62B/F3eaUC/pRdfsORAWRHL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n43nwhaJpbvQ6zr/XHbspH7oqe0eexfvzowzkKc9noWqQnU0IaMrtRgyOma"
}
],
"@type": ["https://w3id.org/security#BbsBlsSignatureProof2020"],
"https://w3id.org/security#verificationMethod": [
{"@id": "did:key:test"}
],
}
]
}
],
"@type": [
"https://www.vdel.com/MedicalPass",
"https://www.w3.org/2018/credentials#VerifiableCredential",
],
}
]

EXPANDED_CRED_FHIR_TYPE_2 = [
{
"https://www.w3.org/2018/credentials#credentialSubject": [{}],
"@id": "urn:bnid:_:c14n4",
"https://www.w3.org/2018/credentials#issuanceDate": [
{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2021-10-01T20:16:40+02:00",
}
],
"https://www.w3.org/2018/credentials#issuer": [{"@id": "did:key:test"}],
"https://w3id.org/security#proof": [
{
"@graph": [
{
"http://purl.org/dc/terms/created": [
{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2021-10-01T18:16:41.072975+00:00",
}
],
"https://w3id.org/security#nonce": [
{
"@value": "M9yQx0eKIAI3Zs0sLF1kQsO7/hV1ZKEnqX9f0V/SzwRMKEixa0tJgqbGwviMA04XoL0="
}
],
"https://w3id.org/security#proofPurpose": [
{"@id": "https://w3id.org/security#assertionMethod"}
],
"https://w3id.org/security#proofValue": [
{
"@value": "ACYgFHwPj5TxR9H+k+V+rBsfZ3SgOEvoKrYCcvAl4HhaKNR039r5UWE89tnHaVOx22k604EWibf0s7BTezijjYv1VWSVkZar4wtOslplXv6g7dVc8/0IWXQWOfn2hTE2N65Wv8xz2qw5dWwEzSXTx44o15wE2ubimgGFMM7Mv++SAoHC1dQGotGqKqOB2PS8yI+ToiWmswAAAHSD5NRIZHKeiWP8hK/e9xUYy5gSPBivDVAORybl62B/F3eaUC/pRdfsORAWRHLjmfcAAAACcOe6yrLqI3OmxkKUfsCGgIl83LLcQ9pLjaigdc/5XRs6KYo533Q/7cGryn2IvLFAJiHgZJ8Ovwi9xkDy1USKjZfjgRMil4PEiwZ2Gqu4g+HlJ11JemUX2HDAjJYgJHSFguZp/l/5y//0pQegHOi9hwAAABcp9nblpM/ALrFpdenGn23x5kdYC4gMyTV6a6RPuMwryVZcmTP50XDVHiY2t4JLvULdJcGDcOCpetMPhqyAf3VeNtorYjr1+YWSgjApfqZ594rMyohWGwkNu0zqv19qDkQ+aBibGhhsCBHe+jFy/BXQv2TlIMgX7YdUgVtUuO4YJT4cz4xrDlK58sJPpmJqraasoA0E+ciPOtGX5J7e4n+dGlPwkQjcD79cjBGs7hXmljeqbe2a82YQw/Q+L/yVKqxl8+ucLoqQ2QzREKslQ7ljchX8RsHQURflZTgPxGjNyCqHtEIcT6d7COcpmqGYSo5ge0pIXab97H97NBnk9mmdcCOCETWOJ8shuS7n4R4GdnRDjB5ArbBnpIMYUGEsdD0ZR87nVBbAfWFhQWJgsJvpPOGq2p6VPImfwhIoh7LIYkpwVogRLrSQGl5IZcHexlHwjZoogafCD5OSyEAO3au3UUoVde4S98v2233QuOwXvz3ptYOO+aJIbqmgdmGs41YfbyT830/H+248+Zbkob7T1FBWbYtEW+k8omat87tc3RfU9LYgNrXWUpJ/TZ+4Cqg7VljkPhCIEZYNUoKQxG1pP11HsmLvzhtnoNVLwjvJA7IrcinAr2pnWSBzjm/wBx8mANrCAHW4f4yyvSXCWZJOfnf/N8dt01Di0QaNbYs8Hlo6yjjjqkrvgLpZtAuuca8nQPPNZWrj3Oids/Z0nZsgKGwZxHo5negKE1JKEEz7zJQUd14JhRYiwfzWYprHcJ9szp5Tgmskksv3NIyKQ7XfLwnOY29zLOpTm51c99Ru6CVvAvIGckB+oE8cwPRjfE9fajJtQEODZ1ljbzYNACzLZ52iSsL+rSKq9LL79TgmN2lE0SkmgrwkOBAjmSwzrBc9DdQrkpWlSZzOWyL/QuNfHfEiNn43nwhaJpbvQ6zr/XHbspH7oqe0eexfvzowzkKc9noWqQnU0IaMrtRgyOma"
}
],
"@type": ["https://w3id.org/security#BbsBlsSignatureProof2020"],
"https://w3id.org/security#verificationMethod": [
{"@id": "did:key:test"}
],
}
]
}
],
"@type": [
"https://www.vdel.com/MedicalPass",
"https://www.w3.org/2018/credentials#VerifiableCredential",
],
}
]

is_holder_pd = PresentationDefinition.deserialize(
{
"id": "32f54163-7166-48f1-93d8-ff217bdb0653",
Expand Down Expand Up @@ -1625,6 +1750,25 @@ def create_vcrecord(cred_dict: dict, expanded_types: list):
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/bbs/v1",
{
"MedicalPass": {
"@id": "https://www.vdel.com/MedicalPass",
"@context": {
"description": "http://schema.org/description",
"identifier": "http://schema.org/identifier",
"name": "http://schema.org/name",
"image": "http://schema.org/image",
},
}
},
{
"Patient": {
"@id": "http://hl7.org/fhir/Patient",
"@context": [
"https://fhircat.org/fhir-r5/rdf-r5/contexts/patient.context.jsonld"
],
}
},
],
"id": "urn:bnid:_:c14n4",
"type": ["MedicalPass", "VerifiableCredential"],
Expand Down Expand Up @@ -1655,6 +1799,71 @@ def create_vcrecord(cred_dict: dict, expanded_types: list):
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/bbs/v1",
{
"LabReport": {
"@id": "https://www.vdel.com/LabReport",
"@context": {
"description": "http://schema.org/description",
"identifier": "http://schema.org/identifier",
"name": "http://schema.org/name",
"image": "http://schema.org/image",
},
}
},
{
"Specimen": {
"@id": "http://hl7.org/fhir/Specimen",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/specimen.context.jsonld",
],
}
},
{
"Observation": {
"@id": "http://hl7.org/fhir/Observation",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/observation.context.jsonld",
],
}
},
{
"Organization": {
"@id": "http://hl7.org/fhir/Organization",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/organization.context.jsonld",
],
}
},
{
"Practitioner": {
"@id": "http://hl7.org/fhir/Practitioner",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/practitioner.context.jsonld",
],
}
},
{
"DiagnosticReport": {
"@id": "http://hl7.org/fhir/DiagnosticReport",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/diagnosticreport.context.jsonld",
],
}
},
{
"PractitionerRole": {
"@id": "http://hl7.org/fhir/PractitionerRole",
"@context": [
None,
"https://fhircat.org/fhir-r5/rdf-r5/contexts/practitionerrole.context.jsonld",
],
}
},
],
"type": ["VerifiableCredential", "LabReport"],
"issuer": "did:key:zUC74FYQCzCbDpbVm9v1LVCc2RkxJY3XMdxV9UpsVaerTgEAAjpdWfE8WemccfdNhski3kHiXfLzPZW2wgsvSCkZFWV3zSNxQEqZoV8kVpwLtLzzpskRcskBB3M3DxaeBnDvK4H",
Expand Down
Loading

0 comments on commit 255fc1e

Please sign in to comment.