-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vcdm 2.0 model and context #3436
base: main
Are you sure you want to change the base?
Changes from all commits
7ba9b99
9879a4a
262ae0a
5951683
3383cd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -884,8 +884,11 @@ def __call__(self, value): | |
class CredentialContext(Validator): | ||
"""Credential Context.""" | ||
|
||
FIRST_CONTEXT = "https://www.w3.org/2018/credentials/v1" | ||
EXAMPLE = [FIRST_CONTEXT, "https://www.w3.org/2018/credentials/examples/v1"] | ||
FIRST_CONTEXT = [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/ns/credentials/v2", | ||
] | ||
EXAMPLE = [FIRST_CONTEXT[0], "https://www.w3.org/2018/credentials/examples/v1"] | ||
|
||
def __init__(self) -> None: | ||
"""Initialize the instance.""" | ||
|
@@ -895,9 +898,9 @@ def __call__(self, value): | |
"""Validate input value.""" | ||
length = len(value) | ||
|
||
if length < 1 or value[0] != CredentialContext.FIRST_CONTEXT: | ||
if length < 1 or value[0] not in CredentialContext.FIRST_CONTEXT: | ||
raise ValidationError( | ||
f"First context must be {CredentialContext.FIRST_CONTEXT}" | ||
f"First context must be one of {CredentialContext.FIRST_CONTEXT}" | ||
) | ||
|
||
return value | ||
Comment on lines
898
to
906
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Probably worth asserting that value is of expected type before calling len or Something like: def __call__(self, value: List[str]) -> List[str]:
"""Validate input value."""
if not isinstance(value, list):
raise ValidationError("Value must be a non-empty list.")
if not value or value[0] not in CredentialContext.FIRST_CONTEXT:
raise ValidationError(
f"First context must be one of {CredentialContext.FIRST_CONTEXT}"
)
return value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can implement this, however this type of validation would of been done at the datamodel version in the class invoking this validation |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
TEST_DID_SOV = "did:sov:LjgpST2rjsoxYegQDRm7EL" | ||
TEST_DID_KEY = "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL" | ||
|
||
LD_PROOF_VC_DETAIL = { | ||
"credential": { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/2018/credentials/examples/v1", | ||
], | ||
"type": ["VerifiableCredential", "UniversityDegreeCredential"], | ||
"credentialSubject": {"test": "key"}, | ||
"issuanceDate": "2021-04-12", | ||
"issuer": TEST_DID_KEY, | ||
}, | ||
"options": { | ||
"proofType": "Ed25519Signature2018", | ||
"created": "2019-12-11T03:50:55", | ||
}, | ||
} | ||
LD_PROOF_VC_DETAIL_BBS = { | ||
"credential": { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/2018/credentials/examples/v1", | ||
], | ||
"type": ["VerifiableCredential", "UniversityDegreeCredential"], | ||
"credentialSubject": {"test": "key"}, | ||
"issuanceDate": "2021-04-12", | ||
"issuer": TEST_DID_KEY, | ||
}, | ||
"options": { | ||
"proofType": "BbsBlsSignature2020", | ||
"created": "2019-12-11T03:50:55", | ||
}, | ||
} | ||
LD_PROOF_VC_DETAIL_ED25519_2020 = { | ||
"credential": { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/2018/credentials/examples/v1", | ||
], | ||
"type": ["VerifiableCredential", "UniversityDegreeCredential"], | ||
"credentialSubject": {"test": "key"}, | ||
"issuanceDate": "2021-04-12", | ||
"issuer": TEST_DID_KEY, | ||
}, | ||
"options": { | ||
"proofType": "Ed25519Signature2020", | ||
"created": "2019-12-11T03:50:55", | ||
}, | ||
} | ||
LD_PROOF_VC = { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/2018/credentials/examples/v1", | ||
], | ||
"type": ["VerifiableCredential", "UniversityDegreeCredential"], | ||
"credentialSubject": {"test": "key"}, | ||
"issuanceDate": "2021-04-12", | ||
"issuer": TEST_DID_KEY, | ||
"proof": { | ||
"proofPurpose": "assertionMethod", | ||
"created": "2019-12-11T03:50:55", | ||
"type": "Ed25519Signature2018", | ||
"verificationMethod": "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", | ||
"jws": "eyJhbGciOiAiRWREU0EiLCAiYjY0IjogZmFsc2UsICJjcml0IjogWyJiNjQiXX0..Q6amIrxGiSbM7Ce6DxlfwLCjVcYyclas8fMxaecspXFUcFW9DAAxKzgHx93FWktnlZjM_biitkMgZdStgvivAQ", | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rename to a
VALID_CONTEXTS
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree