From f04345b97ff9a78a3dff096599f0b675b3239a3e Mon Sep 17 00:00:00 2001 From: nklomp Date: Sat, 18 Feb 2023 14:58:30 +0100 Subject: [PATCH] fix: credential mapper for jtw --- .../src/session/OpSession.ts | 2 +- .../ssi-types/src/mapper/credential-mapper.ts | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts index 822be6601..4006aac45 100644 --- a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts +++ b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts @@ -72,7 +72,7 @@ export class OpSession { supportedDidMethods: this.supportedDidMethods || [], expiresIn: this.expiresIn || 6000, presentationSignCallback, - wellknownDidVerifyCallback + wellknownDidVerifyCallback, }, this.context ) diff --git a/packages/ssi-types/src/mapper/credential-mapper.ts b/packages/ssi-types/src/mapper/credential-mapper.ts index 25342b9bf..6f00999e0 100644 --- a/packages/ssi-types/src/mapper/credential-mapper.ts +++ b/packages/ssi-types/src/mapper/credential-mapper.ts @@ -274,20 +274,30 @@ export class CredentialMapper { } static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential { - if (!verifiableCredential.proof.type) { - throw new Error('Verifiable credential proof is missing a type') - } + let proof + if (verifiableCredential.proof) { + if (!verifiableCredential.proof.type) { + throw new Error('Verifiable credential proof is missing a type') + } - if (!verifiableCredential.proof.created) { - throw new Error('Verifiable credential proof is missing a created date') - } + if (!verifiableCredential.proof.created) { + throw new Error('Verifiable credential proof is missing a created date') + } - if (!verifiableCredential.proof.proofPurpose) { - throw new Error('Verifiable credential proof is missing a proof purpose') - } + if (!verifiableCredential.proof.proofPurpose) { + throw new Error('Verifiable credential proof is missing a proof purpose') + } - if (!verifiableCredential.proof.verificationMethod) { - throw new Error('Verifiable credential proof is missing a verification method') + if (!verifiableCredential.proof.verificationMethod) { + throw new Error('Verifiable credential proof is missing a verification method') + } + proof = { + ...verifiableCredential.proof, + type: verifiableCredential.proof.type, + created: verifiableCredential.proof.created, + proofPurpose: verifiableCredential.proof.proofPurpose, + verificationMethod: verifiableCredential.proof.verificationMethod, + } } return { @@ -297,13 +307,7 @@ export class CredentialMapper { ? [verifiableCredential.type] : verifiableCredential.type : ['VerifiableCredential'], - proof: { - ...verifiableCredential.proof, - type: verifiableCredential.proof.type, - created: verifiableCredential.proof.created, - proofPurpose: verifiableCredential.proof.proofPurpose, - verificationMethod: verifiableCredential.proof.verificationMethod, - }, + proof, } } }