Skip to content

Commit

Permalink
add backwards compatibility checks: limit proof type and add issuance…
Browse files Browse the repository at this point in the history
… date with vcdm 1.1

Signed-off-by: PatStLouis <patrick.st-louis@opsecid.ca>
  • Loading branch information
PatStLouis committed Jan 10, 2025
1 parent 7ba9b99 commit 9879a4a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
19 changes: 18 additions & 1 deletion acapy_agent/vc/vc_ld/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Manager for performing Linked Data Proof signatures over JSON-LD formatted W3C VCs."""

from datetime import datetime, timezone
from typing import Dict, List, Optional, Type, Union, cast

from pyld import jsonld
Expand All @@ -14,6 +15,8 @@
from ...wallet.error import WalletNotFoundError
from ...wallet.key_type import BLS12381G2, ED25519, KeyType
from ..ld_proofs.constants import (
CREDENTIALS_CONTEXT_V1_URL,
CREDENTIALS_CONTEXT_V2_URL,
SECURITY_CONTEXT_BBS_URL,
SECURITY_CONTEXT_ED25519_2020_URL,
)
Expand Down Expand Up @@ -271,6 +274,12 @@ async def prepare_credential(
and SECURITY_CONTEXT_ED25519_2020_URL not in credential.context_urls
):
credential.add_context(SECURITY_CONTEXT_ED25519_2020_URL)
# Limit VCDM 2.0 with Ed25519Signature2020
elif (
options.proof_type == Ed25519Signature2018.signature_type
and credential.context_urls[0] == CREDENTIALS_CONTEXT_V2_URL
):
raise VcLdpManagerError("Invalid proof type, use Ed25519Signature2020.")

# Permit late binding of credential subject:
# IFF credential subject doesn't already have an id, add holder_did as
Expand All @@ -281,7 +290,15 @@ async def prepare_credential(
# How should this be handled?
if isinstance(subject, list):
subject = subject[0]


if (
not credential.issuance_date
and credential.context_urls[0] == CREDENTIALS_CONTEXT_V1_URL
):
credential.issuance_date = str(
datetime.now(timezone.utc).isoformat('T', 'seconds')
)

if not subject:
raise VcLdpManagerError("Credential subject is required")

Expand Down
2 changes: 2 additions & 0 deletions acapy_agent/vc/vc_ld/models/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def issuance_date(self, date: Union[str, datetime]):
if not date.tzinfo:
date = date.replace(tzinfo=tz.UTC)
date = date.isoformat()


self._issuance_date = date

Expand Down Expand Up @@ -288,6 +289,7 @@ def proof(self, proof: LDProof):
def __eq__(self, o: object) -> bool:
"""Check equality."""
if isinstance(o, VerifiableCredential):

return (
self.context == o.context
and self.id == o.id
Expand Down
3 changes: 2 additions & 1 deletion acapy_agent/vc/vc_ld/models/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from ...ld_proofs.constants import (
CREDENTIALS_CONTEXT_V1_URL,
CREDENTIALS_CONTEXT_V2_URL,
VERIFIABLE_PRESENTATION_TYPE,
)
from .linked_data_proof import LDProof, LinkedDataProofSchema
Expand Down Expand Up @@ -61,7 +62,7 @@ def context(self, context: List[Union[str, dict]]):
First item must be credentials v1 url
"""
assert context[0] == CREDENTIALS_CONTEXT_V1_URL
assert context[0] in [CREDENTIALS_CONTEXT_V1_URL, CREDENTIALS_CONTEXT_V2_URL]

self._context = context

Expand Down

0 comments on commit 9879a4a

Please sign in to comment.