Skip to content

Commit

Permalink
Add DIF presentation exchange context and cache document (openwallet-…
Browse files Browse the repository at this point in the history
…foundation#3093)

* add static cache, and append fields

Signed-off-by: George Mulhearn <[email protected]>

* linting and try load the test doc loader

Signed-off-by: George Mulhearn <[email protected]>

---------

Signed-off-by: George Mulhearn <[email protected]>
Co-authored-by: George Mulhearn <[email protected]>
Co-authored-by: gmulhearn-anonyome <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent c96a43e commit 76f5a71
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ include aries_cloudagent/vc/ld_proofs/resources/status_list_context.jsonld
include aries_cloudagent/vc/ld_proofs/resources/security-v1-context.jsonld
include aries_cloudagent/vc/ld_proofs/resources/security-v2-context.jsonld
include aries_cloudagent/vc/ld_proofs/resources/ed25519-2020-context.jsonld
include aries_cloudagent/vc/ld_proofs/resources/bbs-v1-context.jsonld
include aries_cloudagent/vc/ld_proofs/resources/dif-presentation-exchange-submission-v1.jsonld
include README.md
25 changes: 16 additions & 9 deletions aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,7 @@ async def create_vp(
)
if not issuer_id and len(filtered_creds_list) == 0:
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)
vp = self.__add_dif_fields_to_vp(vp, submission_property)
result_vp.append(vp)
continue
else:
Expand All @@ -1280,19 +1278,15 @@ async def create_vp(
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)
vp = self.__add_dif_fields_to_vp(vp, submission_property)
result_vp.append(vp)
continue
else:
vp = await create_presentation(credentials=filtered_creds_list)
else:
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)
vp = self.__add_dif_fields_to_vp(vp, submission_property)
issue_suite = await self._get_issue_suite(
issuer_id=issuer_id,
)
Expand All @@ -1307,6 +1301,19 @@ async def create_vp(
return result_vp[0]
return result_vp

def __add_dif_fields_to_vp(
self,
vp: dict,
submission_property: PresentationSubmission
) -> dict:
vp["@context"].append(PRESENTATION_SUBMISSION_JSONLD_CONTEXT)
vp["type"].append(PRESENTATION_SUBMISSION_JSONLD_TYPE)
vp["presentation_submission"] = submission_property.serialize()
if self.proof_type is BbsBlsSignature2020.signature_type:
vp["@context"].append(SECURITY_CONTEXT_BBS_URL)

return vp

def check_if_cred_id_derived(self, id: str) -> bool:
"""Check if credential or credentialSubject id is derived."""
if id.startswith("urn:bnid:_:c14n"):
Expand Down
2 changes: 2 additions & 0 deletions aries_cloudagent/vc/ld_proofs/document_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class StaticCacheJsonLdDownloader:
"https://w3id.org/security/v2": "security-v2-context.jsonld",
"https://w3id.org/security/suites/ed25519-2020/v1": "ed25519-2020-context.jsonld",
"https://w3id.org/security/bbs/v1": "bbs-v1-context.jsonld",
"https://identity.foundation/presentation-exchange/submission/v1":
"dif-presentation-exchange-submission-v1.jsonld",
}

def __init__(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@context": {
"@version": 1.1,
"PresentationSubmission": {
"@id": "https://identity.foundation/presentation-exchange/#presentation-submission",
"@context": {
"@version": 1.1,
"presentation_submission": {
"@id": "https://identity.foundation/presentation-exchange/#presentation-submission",
"@type": "@json"
}
}
}
}
}
2 changes: 2 additions & 0 deletions aries_cloudagent/vc/tests/contexts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .did_v1 import DID_V1
from .dif_presentation_submission_v1 import DIF_PRESENTATION_SUBMISSION_V1
from .security_v1 import SECURITY_V1
from .security_v2 import SECURITY_V2
from .security_v3_unstable import SECURITY_V3_UNSTABLE
Expand All @@ -14,6 +15,7 @@

__all__ = [
"DID_V1",
"DIF_PRESENTATION_SUBMISSION_V1",
"SECURITY_V1",
"SECURITY_V2",
"SECURITY_V3_UNSTABLE",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DIF_PRESENTATION_SUBMISSION_V1 = {
"@context": {
"@version": 1.1,
"PresentationSubmission": {
"@id": "https://identity.foundation/presentation-exchange/#presentation-submission",
"@context": {
"@version": 1.1,
"presentation_submission": {
"@id": "https://identity.foundation/presentation-exchange/#presentation-submission",
"@type": "@json"
}
}
}
}
}
2 changes: 2 additions & 0 deletions aries_cloudagent/vc/tests/document_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
VACCINATION_V1,
ODRL,
SCHEMA_ORG,
DIF_PRESENTATION_SUBMISSION_V1,
)
from ..ld_proofs.constants import (
SECURITY_CONTEXT_V2_URL,
Expand Down Expand Up @@ -49,6 +50,7 @@
"https://www.w3.org/ns/odrl.jsonld": ODRL,
"http://schema.org/": SCHEMA_ORG,
"https://w3id.org/vaccination/v1": VACCINATION_V1,
"https://identity.foundation/presentation-exchange/submission/v1": DIF_PRESENTATION_SUBMISSION_V1,
}


Expand Down

0 comments on commit 76f5a71

Please sign in to comment.