Skip to content

Commit

Permalink
feat: mdoc device response multiple documents
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Nov 1, 2024
1 parent 782b177 commit c9adac8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 0 additions & 3 deletions packages/ssi-types/__tests__/uniform-claims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,20 @@ describe('Uniform VC claims', () => {
it('should work with sd jwt VC from Funke', () => {
const jwtVc: string = getFile('packages/ssi-types/__tests__/vc_vp_examples/vc/sd.jwt')
const vc = CredentialMapper.toUniformCredential(jwtVc, { hasher: generateDigest })
console.log(JSON.stringify(vc, null, 2))
expect(vc.issuanceDate).toEqual('2024-08-16T09:29:44Z')
expect(vc.expirationDate).toEqual('2024-08-30T09:29:44Z')
})

it('should work with issuer signed (mdoc) VC from Funke', () => {
const issuerSigned: string = getFile('packages/ssi-types/__tests__/vc_vp_examples/vc/funke.issuersigned')
const vc = CredentialMapper.toUniformCredential(issuerSigned)
console.log(JSON.stringify(vc, null, 2))
expect(vc.issuanceDate).toEqual('2024-08-12T09:54:45Z')
expect(vc.expirationDate).toEqual('2024-08-26T09:54:45Z')
})

it('should work with sd jwt VC from Animo', () => {
const jwtVc: string = getFile('packages/ssi-types/__tests__/vc_vp_examples/vc/animo.sd.jwt')
const vc = CredentialMapper.toUniformCredential(jwtVc, { hasher: generateDigest })
console.log(JSON.stringify(vc, null, 2))
expect(vc.issuanceDate).toEqual('2024-08-26T00:06:09Z')
})
})
Expand Down
10 changes: 5 additions & 5 deletions packages/ssi-types/src/mapper/credential-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ export class CredentialMapper {
deviceResponse = originalPresentation
}

const mdocCredential = deviceResponse.documents
const mdocCredentials = deviceResponse.documents
?.map((doc) => CredentialMapper.toWrappedVerifiableCredential(doc, opts) as WrappedMdocCredential)
.find((value) => value !== undefined)
if (mdocCredential === undefined) {
throw Error('mdoc credential data corruption')
if (!mdocCredentials || mdocCredentials.length === 0 ) {
throw new Error('could not extract any mdoc credentials from mdoc device response')

Check warning on line 168 in packages/ssi-types/src/mapper/credential-mapper.ts

View check run for this annotation

Codecov / codecov/patch

packages/ssi-types/src/mapper/credential-mapper.ts#L168

Added line #L168 was not covered by tests
}

return {
type: CredentialMapper.isMsoMdocDecodedPresentation(originalPresentation) ? OriginalType.MSO_MDOC_DECODED : OriginalType.MSO_MDOC_ENCODED,
format: 'mso_mdoc',
original: originalPresentation,
presentation: deviceResponse,
decoded: deviceResponse,
vcs: [mdocCredential],
vcs: mdocCredentials,
}
}
// SD-JWT
Expand Down
5 changes: 3 additions & 2 deletions packages/ssi-types/src/types/mso_mdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ export interface WrappedMdocPresentation {
*/
presentation: MdocDeviceResponse
/**
* Wrapped Mdocs belonging to the Presentation. .
* Wrapped Mdocs belonging to the Presentation. There can be multiple
* documents in a single device response
*/
vcs: [WrappedMdocCredential]
vcs: WrappedMdocCredential[]
}

export function isWrappedMdocCredential(vc: WrappedVerifiableCredential): vc is WrappedMdocCredential {
Expand Down

0 comments on commit c9adac8

Please # to comment.