Skip to content

Commit 9dcf9e1

Browse files
committed
feat(oid4vci): add a few tests
Signed-off-by: Henrique Dias <mail@hacdias.com>
1 parent 265b3df commit 9dcf9e1

5 files changed

Lines changed: 168 additions & 19 deletions

File tree

packages/openid4vci/src/formats/credential/mso-mdoc/__tests__/z-mso-mdoc.test.mts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect, test } from 'vitest'
22
import {
33
zMsoMdocCredentialIssuerMetadata,
44
zMsoMdocCredentialIssuerMetadataDraft14,
5+
zMsoMdocCredentialIssuerMetadataDraft15,
56
zMsoMdocFormatIdentifier,
67
} from '../z-mso-mdoc.js'
78

@@ -17,9 +18,78 @@ test('should parse mso mdoc format identifier', () => {
1718
})
1819
})
1920

20-
test('should parse mso mdoc credential issuer metadata draft 15', () => {
21+
test('should parse mso mdoc credential issuer metadata draft 16', () => {
2122
expect(
2223
zMsoMdocCredentialIssuerMetadata.safeParse({
24+
format: 'mso_mdoc',
25+
doctype: 'org.iso.18013.5.1.mDL',
26+
cryptographic_binding_methods_supported: ['cose_key'],
27+
credential_signing_alg_values_supported: [-6, -7],
28+
credential_metadata: {
29+
display: [
30+
{
31+
name: 'Mobile Driving License',
32+
locale: 'en-US',
33+
logo: {
34+
uri: 'https://state.example.org/public/mdl.png',
35+
alt_text: 'state mobile driving license',
36+
},
37+
background_color: '#12107c',
38+
text_color: '#FFFFFF',
39+
},
40+
{
41+
name: 'モバイル運転免許証',
42+
locale: 'ja-JP',
43+
logo: {
44+
uri: 'https://state.example.org/public/mdl.png',
45+
alt_text: '米国州発行のモバイル運転免許証',
46+
},
47+
background_color: '#12107c',
48+
text_color: '#FFFFFF',
49+
},
50+
],
51+
claims: [
52+
{
53+
path: ['org.iso.18013.5.1', 'given_name'],
54+
display: [
55+
{
56+
name: 'Given Name',
57+
locale: 'en-US',
58+
},
59+
{
60+
name: '名前',
61+
locale: 'ja-JP',
62+
},
63+
],
64+
},
65+
{
66+
path: ['org.iso.18013.5.1', 'family_name'],
67+
display: [
68+
{
69+
name: 'Surname',
70+
locale: 'en-US',
71+
},
72+
],
73+
},
74+
{
75+
path: ['org.iso.18013.5.1', 'birth_date'],
76+
mandatory: true,
77+
},
78+
{
79+
path: ['org.iso.18013.5.1.aamva', 'organ_donor'],
80+
},
81+
],
82+
},
83+
})
84+
).toStrictEqual({
85+
data: expect.objectContaining({}),
86+
success: true,
87+
})
88+
})
89+
90+
test('should parse mso mdoc credential issuer metadata draft 15', () => {
91+
expect(
92+
zMsoMdocCredentialIssuerMetadataDraft15.safeParse({
2393
format: 'mso_mdoc',
2494
doctype: 'org.iso.18013.5.1.mDL',
2595
cryptographic_binding_methods_supported: ['cose_key'],

packages/openid4vci/src/formats/credential/sd-jwt-dc/__tests__/z-sd-jwt-dc.test.mts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { expect, test } from 'vitest'
2-
import { zSdJwtDcCredentialIssuerMetadata, zSdJwtDcFormatIdentifier } from '../z-sd-jwt-dc.js'
2+
import {
3+
zSdJwtDcCredentialIssuerMetadata,
4+
zSdJwtDcCredentialIssuerMetadataDraft15,
5+
zSdJwtDcFormatIdentifier,
6+
} from '../z-sd-jwt-dc.js'
37

48
test('should parse sd-jwt-dc format identifier', () => {
59
expect(zSdJwtDcFormatIdentifier.safeParse('dc+sd-jwt')).toStrictEqual({
@@ -16,6 +20,71 @@ test('should parse sd-jwt-dc format identifier', () => {
1620
test('should parse sd-jwt-dc credential issuer metadata', () => {
1721
expect(
1822
zSdJwtDcCredentialIssuerMetadata.safeParse({
23+
format: 'dc+sd-jwt',
24+
scope: 'SD_JWT_DC_example_in_OpenID4VCI',
25+
cryptographic_binding_methods_supported: ['jwk'],
26+
credential_signing_alg_values_supported: ['ES256'],
27+
credential_metadata: {
28+
display: [
29+
{
30+
name: 'IdentityCredential',
31+
logo: {
32+
uri: 'https://university.example.edu/public/logo.png',
33+
alt_text: 'a square logo of a university',
34+
},
35+
locale: 'en-US',
36+
background_color: '#12107c',
37+
text_color: '#FFFFFF',
38+
},
39+
],
40+
claims: [
41+
{
42+
path: ['given_name'],
43+
display: [
44+
{
45+
name: 'Given Name',
46+
locale: 'en-US',
47+
},
48+
{
49+
name: 'Vorname',
50+
locale: 'de-DE',
51+
},
52+
],
53+
},
54+
{
55+
path: ['family_name'],
56+
display: [
57+
{
58+
name: 'Surname',
59+
locale: 'en-US',
60+
},
61+
{
62+
name: 'Nachname',
63+
locale: 'de-DE',
64+
},
65+
],
66+
},
67+
{
68+
path: ['email'],
69+
},
70+
],
71+
},
72+
proof_types_supported: {
73+
jwt: {
74+
proof_signing_alg_values_supported: ['ES256'],
75+
},
76+
},
77+
vct: 'SD_JWT_DC_example_in_OpenID4VCI',
78+
})
79+
).toStrictEqual({
80+
data: expect.objectContaining({}),
81+
success: true,
82+
})
83+
})
84+
85+
test('should parse sd-jwt-dc credential issuer metadata draft 15', () => {
86+
expect(
87+
zSdJwtDcCredentialIssuerMetadataDraft15.safeParse({
1988
format: 'dc+sd-jwt',
2089
scope: 'SD_JWT_DC_example_in_OpenID4VCI',
2190
cryptographic_binding_methods_supported: ['jwk'],

packages/openid4vci/src/metadata/credential-issuer/credential-configurations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ExtractScopesForCredentialConfigurationIdsOptions {
1515
credentialConfigurationIds: string[]
1616

1717
/**
18-
* Wheter to throw an error if the correspdong credential configuration
18+
* Whether to throw an error if the corresponding credential configuration
1919
* for a provided credential configuration id has no scope.
2020
*
2121
* @default false

packages/openid4vci/src/metadata/credential-issuer/z-credential-issuer-metadata.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,28 +363,37 @@ export const zCredentialIssuerMetadata = z.union([
363363

364364
export const zCredentialIssuerMetadataWithDraftVersion = z.union([
365365
zCredentialIssuerMetadataDraft14Draft15Draft16.transform((credentialIssuerMetadata) => {
366-
const isDraft15 = Object.values(credentialIssuerMetadata.credential_configurations_supported).some(
367-
(configuration) => {
368-
const knownConfiguration = configuration as CredentialConfigurationSupportedWithFormats
366+
const credentialConfigurations = Object.values(credentialIssuerMetadata.credential_configurations_supported)
369367

370-
// Added in draft 15, it's not possible to detect with 100% guarantee
371-
if (knownConfiguration.format === zSdJwtDcFormatIdentifier.value) return true
372-
if (Array.isArray(knownConfiguration.claims)) return true
373-
if (
374-
Object.values(knownConfiguration.proof_types_supported ?? {}).some(
375-
(proofType) => proofType.key_attestations_required !== undefined
376-
)
368+
const isDraft15 = credentialConfigurations.some((configuration) => {
369+
const knownConfiguration = configuration as CredentialConfigurationSupportedWithFormats
370+
371+
// Added in draft 15, it's not possible to detect with 100% guarantee
372+
if (knownConfiguration.format === zSdJwtDcFormatIdentifier.value) return true
373+
if (Array.isArray(knownConfiguration.claims)) return true
374+
if (
375+
Object.values(knownConfiguration.proof_types_supported ?? {}).some(
376+
(proofType) => proofType.key_attestations_required !== undefined
377377
)
378-
return true
378+
)
379+
return true
379380

380-
// For now we assume draft 14 if we don't have any evidence it's draft 15
381-
return false
382-
}
383-
)
381+
// For now we assume draft 14 if we don't have any evidence it's draft 15
382+
return false
383+
})
384+
385+
const isDraft16 = credentialConfigurations.some((configuration) => {
386+
// Added in draft 16
387+
return configuration.credential_metadata
388+
})
384389

385390
return {
386391
credentialIssuerMetadata,
387-
originalDraftVersion: isDraft15 ? Openid4vciDraftVersion.Draft15 : Openid4vciDraftVersion.Draft14,
392+
originalDraftVersion: isDraft16
393+
? Openid4vciDraftVersion.Draft16
394+
: isDraft15
395+
? Openid4vciDraftVersion.Draft15
396+
: Openid4vciDraftVersion.Draft14,
388397
}
389398
}),
390399
// Then try parsing draft 11 and transform into draft 14

packages/openid4vci/src/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum Openid4vciDraftVersion {
2+
Draft16 = 'Draft16',
23
Draft15 = 'Draft15',
34
Draft14 = 'Draft14',
45
Draft11 = 'Draft11',

0 commit comments

Comments
 (0)