Skip to content

Commit

Permalink
fix: credential mapper for jtw
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 18, 2023
1 parent 559efe2 commit f04345b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class OpSession {
supportedDidMethods: this.supportedDidMethods || [],
expiresIn: this.expiresIn || 6000,
presentationSignCallback,
wellknownDidVerifyCallback
wellknownDidVerifyCallback,
},
this.context
)
Expand Down
40 changes: 22 additions & 18 deletions packages/ssi-types/src/mapper/credential-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}

0 comments on commit f04345b

Please sign in to comment.