Skip to content

Commit

Permalink
fix: make credential mapper a bit more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed May 4, 2023
1 parent eb1c48c commit 7248fae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 93 deletions.
6 changes: 3 additions & 3 deletions packages/ssi-types/src/mapper/credential-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ export class CredentialMapper {
}

static toCompactJWT(
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string
): string {
if (CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
if (!jwtDocument || CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
throw Error('Cannot convert non JWT credential to JWT')
}
if (typeof jwtDocument === 'string') {
Expand Down Expand Up @@ -478,7 +478,7 @@ export class CredentialMapper {
private static getFirstProof(
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
): IProof | undefined {
if (typeof document === 'string') {
if (!document || typeof document === 'string') {
return undefined
}
const proofs = 'vc' in document ? document.vc.proof : 'vp' in document ? document.vp.proof : (<IVerifiableCredential>document).proof
Expand Down
110 changes: 20 additions & 90 deletions packages/vc-handler-ld-local/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
"description": "Use this purpose for the verification method in the DID when doing a check (defaults to CredentialIssuancePurpose)"
}
},
"required": [
"credential"
],
"required": ["credential"],
"description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }"
},
"CredentialPayload": {
Expand Down Expand Up @@ -70,9 +68,7 @@
"type": "string"
}
},
"required": [
"issuer"
],
"required": ["issuer"],
"description": "Used as input when creating Verifiable Credentials"
},
"IssuerType": {
Expand All @@ -84,9 +80,7 @@
"type": "string"
}
},
"required": [
"id"
]
"required": ["id"]
},
{
"type": "string"
Expand Down Expand Up @@ -117,10 +111,7 @@
"type": "string"
}
},
"required": [
"id",
"type"
],
"required": ["id", "type"],
"description": "Used for the discovery of information about the current status of a verifiable credential, such as whether it is suspended or revoked. The precise contents of the credential status information is determined by the specific `credentialStatus` type definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status }"
},
"IAuthenticationProofPurpose": {
Expand Down Expand Up @@ -318,13 +309,7 @@
]
}
},
"required": [
"@context",
"credentialSubject",
"issuanceDate",
"issuer",
"proof"
]
"required": ["@context", "credentialSubject", "issuanceDate", "issuer", "proof"]
},
"CredentialStatusSP": {
"type": "object",
Expand All @@ -342,10 +327,7 @@
"type": "string"
}
},
"required": [
"id",
"type"
]
"required": ["id", "type"]
},
"CredentialProofSP": {
"type": "object",
Expand Down Expand Up @@ -398,12 +380,7 @@
}
}
},
"required": [
"type",
"created",
"proofPurpose",
"verificationMethod"
],
"required": ["type", "created", "proofPurpose", "verificationMethod"],
"additionalProperties": {
"anyOf": [
{
Expand Down Expand Up @@ -482,9 +459,7 @@
]
}
},
"required": [
"presentation"
],
"required": ["presentation"],
"description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }"
},
"PresentationPayload": {
Expand Down Expand Up @@ -527,9 +502,7 @@
"type": "string"
}
},
"required": [
"holder"
],
"required": ["holder"],
"description": "Used as input when creating Verifiable Presentations"
},
"W3CVerifiableCredential": {
Expand Down Expand Up @@ -594,13 +567,7 @@
"type": "string"
}
},
"required": [
"@context",
"credentialSubject",
"issuanceDate",
"issuer",
"proof"
],
"required": ["@context", "credentialSubject", "issuanceDate", "issuer", "proof"],
"description": "Represents a signed Verifiable Credential payload (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }"
},
"CompactJWT": {
Expand Down Expand Up @@ -680,13 +647,7 @@
]
}
},
"required": [
"@context",
"holder",
"proof",
"type",
"verifiableCredential"
]
"required": ["@context", "holder", "proof", "type", "verifiableCredential"]
},
"W3CVerifiableCredentialSP": {
"anyOf": [
Expand Down Expand Up @@ -720,11 +681,7 @@
"description": "List of descriptors of how the claims are being mapped to presentation definition"
}
},
"required": [
"id",
"definition_id",
"descriptor_map"
],
"required": ["id", "definition_id", "descriptor_map"],
"description": "It expresses how the inputs are presented as proofs to a Verifier."
},
"Descriptor": {
Expand All @@ -746,11 +703,7 @@
"description": "The Proof or JWT algorith that the proof is in"
}
},
"required": [
"id",
"path",
"format"
],
"required": ["id", "path", "format"],
"description": "descriptor map laying out the structure of the presentation submission."
},
"IVerifyCredentialLDArgs": {
Expand Down Expand Up @@ -794,18 +747,11 @@
"$ref": "#/components/schemas/interface-ib.es5.d.ts-10057-11521-ib.es5.d.ts-0-217681"
}
},
"required": [
"prototype",
"length",
"arguments",
"caller"
],
"required": ["prototype", "length", "arguments", "caller"],
"description": "Check status function, to check verifiableCredentials that have a credentialStatus property"
}
},
"required": [
"credential"
],
"required": ["credential"],
"description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }"
},
"interface-ib.es5.d.ts-10057-11521-ib.es5.d.ts-0-217681": {
Expand All @@ -820,12 +766,7 @@
"$ref": "#/components/schemas/interface-ib.es5.d.ts-10057-11521-ib.es5.d.ts-0-217681"
}
},
"required": [
"prototype",
"length",
"arguments",
"caller"
]
"required": ["prototype", "length", "arguments", "caller"]
},
"IVerifyPresentationLDArgs": {
"type": "object",
Expand Down Expand Up @@ -876,18 +817,11 @@
"$ref": "#/components/schemas/interface-ib.es5.d.ts-10057-11521-ib.es5.d.ts-0-217681"
}
},
"required": [
"prototype",
"length",
"arguments",
"caller"
],
"required": ["prototype", "length", "arguments", "caller"],
"description": "Check status function, to check verifiableCredentials that have a credentialStatus property"
}
},
"required": [
"presentation"
],
"required": ["presentation"],
"description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }"
},
"VerifiablePresentation": {
Expand Down Expand Up @@ -947,11 +881,7 @@
"type": "string"
}
},
"required": [
"@context",
"holder",
"proof"
],
"required": ["@context", "holder", "proof"],
"description": "Represents a signed Verifiable Presentation (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }"
}
},
Expand Down Expand Up @@ -995,4 +925,4 @@
}
}
}
}
}

0 comments on commit 7248fae

Please sign in to comment.