Skip to content

Commit

Permalink
fix: JWT VP sometimes was constructed as a JSON LD VP with JwtProof2020
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 3, 2024
1 parent 42c89b2 commit abb012c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/siopv2-oid4vp-op-auth/src/session/OID4VP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ export class OID4VP {
}
)

const verifiablePresentation =
typeof presentationResult.verifiablePresentation !== 'string' &&
'proof' in presentationResult.verifiablePresentation &&
'jwt' in presentationResult.verifiablePresentation.proof &&
presentationResult.verifiablePresentation.proof.jwt
? presentationResult.verifiablePresentation.proof.jwt
: presentationResult.verifiablePresentation

return {
...presentationResult,
verifiablePresentation,
verifiableCredentials: vcs.credentials,
definition: selectedVerifiableCredentials.definition,
identifierOpts: idOpts,
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-op-auth/src/session/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function createOPBuilder({
}): Promise<OPBuilder> {
const eventEmitter = opOptions.eventEmitter ?? new EventEmitter()
const builder = OP.builder()
.withResponseMode(opOptions.responseMode ?? ResponseMode.POST)
.withResponseMode(opOptions.responseMode ?? ResponseMode.DIRECT_POST)
.withSupportedVersions(
opOptions.supportedVersions ?? [
SupportedVersion.SIOPv2_ID1,
Expand Down
10 changes: 7 additions & 3 deletions packages/ssi-types/src/mapper/credential-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export class CredentialMapper {
...vc,
}

const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
const maxSkewInMS = opts?.maxTimeSkewInMS ?? 1500

if (exp) {
const expDate = credential.expirationDate
Expand Down Expand Up @@ -597,6 +597,8 @@ export class CredentialMapper {
}
} else if (type === DocumentFormat.JWT && 'vc' in credential) {
return CredentialMapper.toCompactJWT(credential)
} else if ('proof' in credential && credential.proof.type === 'JwtProof2020' && credential.proof.jwt) {
return credential.proof.jwt
}
return credential as W3CVerifiableCredential
}
Expand All @@ -611,6 +613,8 @@ export class CredentialMapper {
}
} else if (type === DocumentFormat.JWT && 'vp' in presentation) {
return CredentialMapper.toCompactJWT(presentation)
} else if ('proof' in presentation && presentation.proof.type === 'JwtProof2020' && presentation.proof.jwt) {
return presentation.proof.jwt
}
return presentation as W3CVerifiablePresentation
}
Expand All @@ -626,9 +630,9 @@ export class CredentialMapper {
}
let proof: string | undefined
if ('vp' in jwtDocument) {
proof = jwtDocument.vp.proof
proof = 'jwt' in jwtDocument.vp.proof ? jwtDocument.vp.proof.jwt : jwtDocument.vp.proof
} else if ('vc' in jwtDocument) {
proof = jwtDocument.vc.proof
proof = 'jwt' in jwtDocument.vc.proof ? jwtDocument.vc.proof.jwt : jwtDocument.vc.proof
} else {
proof = Array.isArray(jwtDocument.proof) ? jwtDocument.proof[0].jwt : jwtDocument.proof.jwt
}
Expand Down

0 comments on commit abb012c

Please sign in to comment.