@openid4vc/openid4vci 0.3.0-alpha-20251017102623 → 0.3.0-alpha-20251017122507
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3857 -44136
- package/dist/index.d.ts +3857 -44136
- package/dist/index.js +119 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -17,23 +17,23 @@ const zTxCode = z.object({
|
|
|
17
17
|
input_mode: z.union([z.literal("numeric"), z.literal("text")]).optional(),
|
|
18
18
|
length: z.number().int().optional(),
|
|
19
19
|
description: z.string().max(300).optional()
|
|
20
|
-
}).
|
|
20
|
+
}).loose();
|
|
21
21
|
const zCredentialOfferGrants = z.object({
|
|
22
22
|
authorization_code: z.object({
|
|
23
23
|
issuer_state: z.string().optional(),
|
|
24
24
|
authorization_server: zHttpsUrl.optional()
|
|
25
|
-
}).
|
|
25
|
+
}).loose().optional(),
|
|
26
26
|
[preAuthorizedCodeGrantIdentifier]: z.object({
|
|
27
27
|
"pre-authorized_code": z.string(),
|
|
28
28
|
tx_code: zTxCode.optional(),
|
|
29
29
|
authorization_server: zHttpsUrl.optional()
|
|
30
|
-
}).
|
|
31
|
-
}).
|
|
30
|
+
}).loose().optional()
|
|
31
|
+
}).loose();
|
|
32
32
|
const zCredentialOfferObjectDraft14 = z.object({
|
|
33
33
|
credential_issuer: zHttpsUrl,
|
|
34
34
|
credential_configuration_ids: z.array(z.string()),
|
|
35
35
|
grants: z.optional(zCredentialOfferGrants)
|
|
36
|
-
}).
|
|
36
|
+
}).loose();
|
|
37
37
|
const zCredentialOfferObjectDraft11To14 = z.object({
|
|
38
38
|
credential_issuer: zHttpsUrl,
|
|
39
39
|
credentials: z.array(z.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })),
|
|
@@ -42,9 +42,9 @@ const zCredentialOfferObjectDraft11To14 = z.object({
|
|
|
42
42
|
[preAuthorizedCodeGrantIdentifier]: z.object({
|
|
43
43
|
"pre-authorized_code": z.string(),
|
|
44
44
|
user_pin_required: z.optional(z.boolean())
|
|
45
|
-
}).
|
|
45
|
+
}).loose().optional()
|
|
46
46
|
}))
|
|
47
|
-
}).
|
|
47
|
+
}).loose().transform(({ credentials, grants,...rest }) => {
|
|
48
48
|
const v14 = {
|
|
49
49
|
...rest,
|
|
50
50
|
credential_configuration_ids: credentials
|
|
@@ -151,14 +151,15 @@ const zCredentialConfigurationSupportedClaimsDescriptionDraft14 = z.object({
|
|
|
151
151
|
display: z.array(z.object({
|
|
152
152
|
name: z.string().optional(),
|
|
153
153
|
locale: z.string().optional()
|
|
154
|
-
}).
|
|
155
|
-
}).
|
|
154
|
+
}).loose()).optional()
|
|
155
|
+
}).loose();
|
|
156
156
|
const zCredentialConfigurationSupportedClaimsDraft14 = z.record(z.string(), z.union([zCredentialConfigurationSupportedClaimsDescriptionDraft14, z.lazy(() => zCredentialConfigurationSupportedClaimsDraft14)]));
|
|
157
|
-
const
|
|
157
|
+
const zClaimDescriptionPathValue = z.union([
|
|
158
158
|
z.string(),
|
|
159
159
|
z.number().int().nonnegative(),
|
|
160
160
|
z.null()
|
|
161
|
-
])
|
|
161
|
+
]);
|
|
162
|
+
const zClaimsDescriptionPath = z.tuple([zClaimDescriptionPathValue], zClaimDescriptionPathValue);
|
|
162
163
|
const zMsoMdocClaimsDescriptionPath = z.tuple([z.string(), z.string()], { message: "mso_mdoc claims description path MUST be an array with exactly two string elements, pointing to the namespace and element identifier within an mdoc credential" });
|
|
163
164
|
const zIssuerMetadataClaimsDescription = z.object({
|
|
164
165
|
path: zClaimsDescriptionPath,
|
|
@@ -166,8 +167,8 @@ const zIssuerMetadataClaimsDescription = z.object({
|
|
|
166
167
|
display: z.array(z.object({
|
|
167
168
|
name: z.string().optional(),
|
|
168
169
|
locale: z.string().optional()
|
|
169
|
-
}).
|
|
170
|
-
}).
|
|
170
|
+
}).loose()).optional()
|
|
171
|
+
}).loose();
|
|
171
172
|
const zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription.extend({ path: zMsoMdocClaimsDescriptionPath });
|
|
172
173
|
|
|
173
174
|
//#endregion
|
|
@@ -175,7 +176,7 @@ const zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription
|
|
|
175
176
|
const zKeyAttestationJwtHeader = z.object({
|
|
176
177
|
...zJwtHeader.shape,
|
|
177
178
|
typ: z.literal("keyattestation+jwt").or(z.literal("key-attestation+jwt"))
|
|
178
|
-
}).
|
|
179
|
+
}).loose().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, { message: `Both 'jwk' and 'kid' are defined. Only one is allowed` }).refine(({ trust_chain, kid }) => !trust_chain || !kid, { message: `When 'trust_chain' is provided, 'kid' is required` });
|
|
179
180
|
const zIso18045 = z.enum([
|
|
180
181
|
"iso_18045_high",
|
|
181
182
|
"iso_18045_moderate",
|
|
@@ -189,13 +190,13 @@ const zKeyAttestationJwtPayload = z.object({
|
|
|
189
190
|
attested_keys: z.array(zJwk),
|
|
190
191
|
key_storage: z.optional(zIso18045OrStringArray),
|
|
191
192
|
user_authentication: z.optional(zIso18045OrStringArray),
|
|
192
|
-
certification: z.optional(z.
|
|
193
|
-
}).
|
|
193
|
+
certification: z.optional(z.url())
|
|
194
|
+
}).loose();
|
|
194
195
|
const zKeyAttestationJwtPayloadForUse = (use) => z.object({
|
|
195
196
|
...zKeyAttestationJwtPayload.shape,
|
|
196
197
|
nonce: use === "proof_type.attestation" ? z.string({ message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly` }) : z.optional(z.string()),
|
|
197
198
|
exp: use === "proof_type.jwt" ? zInteger : z.optional(zInteger)
|
|
198
|
-
}).
|
|
199
|
+
}).loose();
|
|
199
200
|
|
|
200
201
|
//#endregion
|
|
201
202
|
//#region src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
|
|
@@ -205,12 +206,12 @@ const zCredentialConfigurationSupportedDisplayEntry = z.object({
|
|
|
205
206
|
logo: z.object({
|
|
206
207
|
uri: z.string().optional(),
|
|
207
208
|
alt_text: z.string().optional()
|
|
208
|
-
}).
|
|
209
|
+
}).loose().optional(),
|
|
209
210
|
description: z.string().optional(),
|
|
210
211
|
background_color: z.string().optional(),
|
|
211
|
-
background_image: z.object({ uri: z.string().optional() }).
|
|
212
|
+
background_image: z.object({ uri: z.string().optional() }).loose().optional(),
|
|
212
213
|
text_color: z.string().optional()
|
|
213
|
-
}).
|
|
214
|
+
}).loose();
|
|
214
215
|
const zCredentialConfigurationSupportedCommonCredentialMetadata = z.object({ display: z.array(zCredentialConfigurationSupportedDisplayEntry).optional() });
|
|
215
216
|
const zCredentialConfigurationSupportedCommon = z.object({
|
|
216
217
|
format: z.string(),
|
|
@@ -226,11 +227,11 @@ const zCredentialConfigurationSupportedCommon = z.object({
|
|
|
226
227
|
key_attestations_required: z.object({
|
|
227
228
|
key_storage: zIso18045OrStringArray.optional(),
|
|
228
229
|
user_authentication: zIso18045OrStringArray.optional()
|
|
229
|
-
}).
|
|
230
|
+
}).loose().optional()
|
|
230
231
|
})).optional(),
|
|
231
232
|
credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.optional(),
|
|
232
233
|
claims: z.optional(z.never())
|
|
233
|
-
}).
|
|
234
|
+
}).loose();
|
|
234
235
|
const zCredentialConfigurationSupportedCommonDraft15 = z.object({
|
|
235
236
|
format: z.string(),
|
|
236
237
|
scope: z.string().optional(),
|
|
@@ -245,11 +246,11 @@ const zCredentialConfigurationSupportedCommonDraft15 = z.object({
|
|
|
245
246
|
key_attestations_required: z.object({
|
|
246
247
|
key_storage: zIso18045OrStringArray.optional(),
|
|
247
248
|
user_authentication: zIso18045OrStringArray.optional()
|
|
248
|
-
}).
|
|
249
|
+
}).loose().optional()
|
|
249
250
|
})).optional(),
|
|
250
251
|
display: z.array(zCredentialConfigurationSupportedDisplayEntry).optional(),
|
|
251
252
|
credential_metadata: z.optional(z.never())
|
|
252
|
-
}).
|
|
253
|
+
}).loose();
|
|
253
254
|
|
|
254
255
|
//#endregion
|
|
255
256
|
//#region src/formats/credential/mso-mdoc/z-mso-mdoc.ts
|
|
@@ -342,8 +343,8 @@ const zCredentialSubjectLeafTypeDraft14 = z.object({
|
|
|
342
343
|
display: z.array(z.object({
|
|
343
344
|
name: z.string().optional(),
|
|
344
345
|
locale: z.string().optional()
|
|
345
|
-
}).
|
|
346
|
-
}).
|
|
346
|
+
}).loose()).optional()
|
|
347
|
+
}).loose();
|
|
347
348
|
const zClaimValueSchemaDraft14 = z.union([
|
|
348
349
|
z.array(z.any()),
|
|
349
350
|
z.record(z.string(), z.any()),
|
|
@@ -352,14 +353,14 @@ const zClaimValueSchemaDraft14 = z.union([
|
|
|
352
353
|
const zW3cVcCredentialSubjectDraft14 = z.record(z.string(), zClaimValueSchemaDraft14);
|
|
353
354
|
const zW3cVcJsonLdCredentialDefinition = z.object({
|
|
354
355
|
"@context": z.array(z.string()),
|
|
355
|
-
type: z.
|
|
356
|
-
}).
|
|
356
|
+
type: z.tuple([z.string()], z.string())
|
|
357
|
+
}).loose();
|
|
357
358
|
const zW3cVcJsonLdCredentialDefinitionDraft14 = zW3cVcJsonLdCredentialDefinition.extend({ credentialSubject: zW3cVcCredentialSubjectDraft14.optional() });
|
|
358
359
|
|
|
359
360
|
//#endregion
|
|
360
361
|
//#region src/formats/credential/w3c-vc/z-w3c-jwt-vc-json.ts
|
|
361
362
|
const zJwtVcJsonFormatIdentifier = z.literal("jwt_vc_json");
|
|
362
|
-
const zJwtVcJsonCredentialDefinition = z.object({ type: z.
|
|
363
|
+
const zJwtVcJsonCredentialDefinition = z.object({ type: z.tuple([z.string()], z.string()) }).loose();
|
|
363
364
|
const zJwtVcJsonCredentialDefinitionDraft14 = zJwtVcJsonCredentialDefinition.extend({ credentialSubject: zW3cVcCredentialSubjectDraft14.optional() });
|
|
364
365
|
const zJwtVcJsonCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
|
|
365
366
|
format: zJwtVcJsonFormatIdentifier,
|
|
@@ -379,9 +380,9 @@ const zJwtVcJsonCredentialIssuerMetadataDraft14 = zCredentialConfigurationSuppor
|
|
|
379
380
|
const zJwtVcJsonCredentialIssuerMetadataDraft11 = z.object({
|
|
380
381
|
format: zJwtVcJsonFormatIdentifier,
|
|
381
382
|
order: z.array(z.string()).optional(),
|
|
382
|
-
types: z.
|
|
383
|
+
types: z.tuple([z.string()], z.string()),
|
|
383
384
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
384
|
-
}).
|
|
385
|
+
}).loose();
|
|
385
386
|
const zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMetadataDraft11.transform(({ types, credentialSubject,...rest }) => ({
|
|
386
387
|
...rest,
|
|
387
388
|
credential_definition: {
|
|
@@ -389,7 +390,7 @@ const zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuer
|
|
|
389
390
|
...credentialSubject ? { credentialSubject } : {}
|
|
390
391
|
}
|
|
391
392
|
}));
|
|
392
|
-
const zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadataDraft14.
|
|
393
|
+
const zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadataDraft14.loose().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
|
|
393
394
|
...rest,
|
|
394
395
|
types: type,
|
|
395
396
|
...credentialDefinition
|
|
@@ -400,9 +401,9 @@ const zJwtVcJsonCredentialRequestFormatDraft14 = z.object({
|
|
|
400
401
|
});
|
|
401
402
|
const zJwtVcJsonCredentialRequestDraft11 = z.object({
|
|
402
403
|
format: zJwtVcJsonFormatIdentifier,
|
|
403
|
-
types: z.
|
|
404
|
+
types: z.tuple([z.string()], z.string()),
|
|
404
405
|
credentialSubject: z.optional(zW3cVcCredentialSubjectDraft14)
|
|
405
|
-
}).
|
|
406
|
+
}).loose();
|
|
406
407
|
const zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.transform(({ types, credentialSubject,...rest }) => {
|
|
407
408
|
return {
|
|
408
409
|
...rest,
|
|
@@ -412,7 +413,7 @@ const zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft1
|
|
|
412
413
|
}
|
|
413
414
|
};
|
|
414
415
|
});
|
|
415
|
-
const zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDraft14.
|
|
416
|
+
const zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDraft14.loose().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
|
|
416
417
|
...rest,
|
|
417
418
|
types: type,
|
|
418
419
|
...credentialDefinition
|
|
@@ -440,9 +441,9 @@ const zJwtVcJsonLdCredentialIssuerMetadataDraft11 = z.object({
|
|
|
440
441
|
order: z.array(z.string()).optional(),
|
|
441
442
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
442
443
|
"@context": z.array(z.string()),
|
|
443
|
-
types: z.
|
|
444
|
+
types: z.tuple([z.string()], z.string()),
|
|
444
445
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
445
|
-
}).
|
|
446
|
+
}).loose();
|
|
446
447
|
const zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssuerMetadataDraft11.transform(({ "@context": context, types, credentialSubject,...rest }) => ({
|
|
447
448
|
...rest,
|
|
448
449
|
credential_definition: {
|
|
@@ -451,7 +452,7 @@ const zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIs
|
|
|
451
452
|
...credentialSubject ? { credentialSubject } : {}
|
|
452
453
|
}
|
|
453
454
|
}));
|
|
454
|
-
const zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadataDraft14.
|
|
455
|
+
const zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadataDraft14.loose().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
|
|
455
456
|
...rest,
|
|
456
457
|
...credentialDefinition,
|
|
457
458
|
types: type
|
|
@@ -464,10 +465,10 @@ const zJwtVcJsonLdCredentialRequestDraft11 = z.object({
|
|
|
464
465
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
465
466
|
credential_definition: z.object({
|
|
466
467
|
"@context": z.array(z.string()),
|
|
467
|
-
types: z.
|
|
468
|
+
types: z.tuple([z.string()], z.string()),
|
|
468
469
|
credentialSubject: z.optional(zW3cVcCredentialSubjectDraft14)
|
|
469
|
-
}).
|
|
470
|
-
}).
|
|
470
|
+
}).loose()
|
|
471
|
+
}).loose();
|
|
471
472
|
const zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraft11.transform(({ credential_definition: { types,...restCredentialDefinition },...rest }) => ({
|
|
472
473
|
...rest,
|
|
473
474
|
credential_definition: {
|
|
@@ -475,7 +476,7 @@ const zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDr
|
|
|
475
476
|
type: types
|
|
476
477
|
}
|
|
477
478
|
}));
|
|
478
|
-
const zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormatDraft14.
|
|
479
|
+
const zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormatDraft14.loose().transform(({ credential_definition: { type,...restCredentialDefinition },...rest }) => ({
|
|
479
480
|
...rest,
|
|
480
481
|
credential_definition: {
|
|
481
482
|
...restCredentialDefinition,
|
|
@@ -505,9 +506,9 @@ const zLdpVcCredentialIssuerMetadataDraft11 = z.object({
|
|
|
505
506
|
order: z.array(z.string()).optional(),
|
|
506
507
|
format: zLdpVcFormatIdentifier,
|
|
507
508
|
"@context": z.array(z.string()),
|
|
508
|
-
types: z.
|
|
509
|
+
types: z.tuple([z.string()], z.string()),
|
|
509
510
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
510
|
-
}).
|
|
511
|
+
}).loose();
|
|
511
512
|
const zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDraft11.transform(({ "@context": context, types, credentialSubject,...rest }) => ({
|
|
512
513
|
...rest,
|
|
513
514
|
credential_definition: {
|
|
@@ -516,7 +517,7 @@ const zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadata
|
|
|
516
517
|
...credentialSubject ? { credentialSubject } : {}
|
|
517
518
|
}
|
|
518
519
|
}));
|
|
519
|
-
const zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDraft14.
|
|
520
|
+
const zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDraft14.loose().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
|
|
520
521
|
...rest,
|
|
521
522
|
...credentialDefinition,
|
|
522
523
|
types: type
|
|
@@ -529,10 +530,10 @@ const zLdpVcCredentialRequestDraft11 = z.object({
|
|
|
529
530
|
format: zLdpVcFormatIdentifier,
|
|
530
531
|
credential_definition: z.object({
|
|
531
532
|
"@context": z.array(z.string()),
|
|
532
|
-
types: z.
|
|
533
|
+
types: z.tuple([z.string()], z.string()),
|
|
533
534
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
534
535
|
})
|
|
535
|
-
}).
|
|
536
|
+
}).loose();
|
|
536
537
|
const zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transform(({ credential_definition: { types,...restCredentialDefinition },...rest }) => ({
|
|
537
538
|
...rest,
|
|
538
539
|
credential_definition: {
|
|
@@ -540,7 +541,7 @@ const zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transf
|
|
|
540
541
|
type: types
|
|
541
542
|
}
|
|
542
543
|
}));
|
|
543
|
-
const zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.
|
|
544
|
+
const zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.loose().transform(({ credential_definition: { type,...restCredentialDefinition },...rest }) => ({
|
|
544
545
|
...rest,
|
|
545
546
|
credential_definition: {
|
|
546
547
|
...restCredentialDefinition,
|
|
@@ -551,7 +552,7 @@ const zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.
|
|
|
551
552
|
//#endregion
|
|
552
553
|
//#region src/formats/credential/w3c-vc/z-w3c-sd-jwt-vc.ts
|
|
553
554
|
const zSdJwtW3VcFormatIdentifier = z.literal("vc+sd-jwt");
|
|
554
|
-
const zSdJwtW3VcCredentialDefinition = z.object({ type: z.
|
|
555
|
+
const zSdJwtW3VcCredentialDefinition = z.object({ type: z.tuple([z.string()], z.string()) }).loose();
|
|
555
556
|
const zSdJwtW3VcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
|
|
556
557
|
format: zSdJwtW3VcFormatIdentifier,
|
|
557
558
|
credential_definition: zSdJwtW3VcCredentialDefinition,
|
|
@@ -596,9 +597,12 @@ const allCredentialIssuerMetadataFormatIdentifiers = allCredentialIssuerMetadata
|
|
|
596
597
|
const zCredentialConfigurationSupportedWithFormats = z.union([zCredentialConfigurationSupportedCommon, zCredentialConfigurationSupportedCommonDraft15]).transform((data, ctx) => {
|
|
597
598
|
if (!allCredentialIssuerMetadataFormatIdentifiers.includes(data.format)) return data;
|
|
598
599
|
const validators = allCredentialIssuerMetadataFormats.filter((formatValidator) => formatValidator.shape.format.value === data.format);
|
|
599
|
-
const result = z.object({}).
|
|
600
|
+
const result = z.object({}).loose().and(validators.length > 1 ? z.union(validators) : validators[0]).safeParse(data);
|
|
600
601
|
if (result.success) return result.data;
|
|
601
|
-
for (const issue of result.error.issues) ctx.addIssue(
|
|
602
|
+
for (const issue of result.error.issues) ctx.addIssue({
|
|
603
|
+
...issue,
|
|
604
|
+
code: issue.code
|
|
605
|
+
});
|
|
602
606
|
return z.NEVER;
|
|
603
607
|
});
|
|
604
608
|
const zCredentialIssuerMetadataDisplayEntry = z.object({
|
|
@@ -607,8 +611,8 @@ const zCredentialIssuerMetadataDisplayEntry = z.object({
|
|
|
607
611
|
logo: z.object({
|
|
608
612
|
uri: z.string().optional(),
|
|
609
613
|
alt_text: z.string().optional()
|
|
610
|
-
}).
|
|
611
|
-
}).
|
|
614
|
+
}).loose().optional()
|
|
615
|
+
}).loose();
|
|
612
616
|
const zCredentialIssuerMetadataDraft14Draft15Draft16 = z.object({
|
|
613
617
|
credential_issuer: zHttpsUrl,
|
|
614
618
|
authorization_servers: z.array(zHttpsUrl).optional(),
|
|
@@ -620,22 +624,22 @@ const zCredentialIssuerMetadataDraft14Draft15Draft16 = z.object({
|
|
|
620
624
|
alg_values_supported: z.array(z.string()),
|
|
621
625
|
enc_values_supported: z.array(z.string()),
|
|
622
626
|
encryption_required: z.boolean()
|
|
623
|
-
}).
|
|
624
|
-
batch_credential_issuance: z.object({ batch_size: z.number().positive() }).
|
|
627
|
+
}).loose().optional(),
|
|
628
|
+
batch_credential_issuance: z.object({ batch_size: z.number().positive() }).loose().optional(),
|
|
625
629
|
signed_metadata: zCompactJwt.optional(),
|
|
626
630
|
display: z.array(zCredentialIssuerMetadataDisplayEntry).optional(),
|
|
627
631
|
credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedWithFormats)
|
|
628
|
-
}).
|
|
632
|
+
}).loose();
|
|
629
633
|
const zCredentialConfigurationSupportedDraft11To16 = z.object({
|
|
630
634
|
id: z.string().optional(),
|
|
631
635
|
format: z.string(),
|
|
632
636
|
cryptographic_suites_supported: z.array(z.string()).optional(),
|
|
633
637
|
display: z.array(z.object({
|
|
634
|
-
logo: z.object({ url: z.
|
|
635
|
-
background_image: z.object({ url: z.
|
|
636
|
-
}).
|
|
638
|
+
logo: z.object({ url: z.url().optional() }).loose().optional(),
|
|
639
|
+
background_image: z.object({ url: z.url().optional() }).loose().optional()
|
|
640
|
+
}).loose()).optional(),
|
|
637
641
|
claims: z.any().optional()
|
|
638
|
-
}).
|
|
642
|
+
}).loose().transform(({ cryptographic_suites_supported, display, claims, id,...rest }) => ({
|
|
639
643
|
...rest,
|
|
640
644
|
...cryptographic_suites_supported ? { credential_signing_alg_values_supported: cryptographic_suites_supported } : {},
|
|
641
645
|
...claims || display ? { credential_metadata: {
|
|
@@ -655,13 +659,16 @@ const zCredentialConfigurationSupportedDraft11To16 = z.object({
|
|
|
655
659
|
if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
|
|
656
660
|
const result = formatSpecificTransformations[data.format].safeParse(data);
|
|
657
661
|
if (result.success) return result.data;
|
|
658
|
-
for (const issue of result.error.issues) ctx.addIssue(
|
|
662
|
+
for (const issue of result.error.issues) ctx.addIssue({
|
|
663
|
+
...issue,
|
|
664
|
+
code: issue.code
|
|
665
|
+
});
|
|
659
666
|
return z.NEVER;
|
|
660
667
|
}).pipe(zCredentialConfigurationSupportedWithFormats);
|
|
661
668
|
const zCredentialConfigurationSupportedDraft16To11 = zCredentialConfigurationSupportedWithFormats.transform(({ credential_metadata,...rest }) => ({
|
|
662
669
|
...credential_metadata,
|
|
663
670
|
...rest
|
|
664
|
-
})).and(z.object({ id: z.string() }).
|
|
671
|
+
})).and(z.object({ id: z.string() }).loose()).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope,...rest }) => ({
|
|
665
672
|
...rest,
|
|
666
673
|
...credential_signing_alg_values_supported ? { cryptographic_suites_supported: credential_signing_alg_values_supported } : {},
|
|
667
674
|
...display ? { display: display.map(({ logo, background_image,...displayRest }) => {
|
|
@@ -688,18 +695,18 @@ const zCredentialConfigurationSupportedDraft16To11 = zCredentialConfigurationSup
|
|
|
688
695
|
zLdpVcFormatIdentifier.value,
|
|
689
696
|
zJwtVcJsonFormatIdentifier.value,
|
|
690
697
|
zJwtVcJsonLdFormatIdentifier.value
|
|
691
|
-
].includes(input)) }).
|
|
698
|
+
].includes(input)) }).loose()
|
|
692
699
|
]));
|
|
693
700
|
const zCredentialIssuerMetadataDraft11To16 = z.object({
|
|
694
701
|
authorization_server: z.string().optional(),
|
|
695
|
-
credentials_supported: z.array(z.object({ id: z.string().optional() }).
|
|
696
|
-
}).
|
|
702
|
+
credentials_supported: z.array(z.object({ id: z.string().optional() }).loose())
|
|
703
|
+
}).loose().transform(({ authorization_server, credentials_supported,...rest }) => {
|
|
697
704
|
return {
|
|
698
705
|
...rest,
|
|
699
706
|
...authorization_server ? { authorization_servers: [authorization_server] } : {},
|
|
700
707
|
credential_configurations_supported: Object.fromEntries(credentials_supported.map((supported) => supported.id ? [supported.id, supported] : void 0).filter((i) => i !== void 0))
|
|
701
708
|
};
|
|
702
|
-
}).pipe(z.object({ credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedDraft11To16) }).
|
|
709
|
+
}).pipe(z.object({ credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedDraft11To16) }).loose()).pipe(zCredentialIssuerMetadataDraft14Draft15Draft16);
|
|
703
710
|
const zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15Draft16.transform((issuerMetadata) => ({
|
|
704
711
|
...issuerMetadata,
|
|
705
712
|
...issuerMetadata.authorization_servers ? { authorization_server: issuerMetadata.authorization_servers[0] } : {},
|
|
@@ -736,8 +743,11 @@ const wellKnownCredentialIssuerSuffix = ".well-known/openid-credential-issuer";
|
|
|
736
743
|
* @inheritdoc {@link fetchWellKnownMetadata}
|
|
737
744
|
*/
|
|
738
745
|
async function fetchCredentialIssuerMetadata(credentialIssuer, fetch) {
|
|
739
|
-
const
|
|
740
|
-
const
|
|
746
|
+
const parsedIssuerUrl = new URL(credentialIssuer);
|
|
747
|
+
const legacyWellKnownMetadataUrl = joinUriParts(credentialIssuer, [wellKnownCredentialIssuerSuffix]);
|
|
748
|
+
const wellKnownMetadataUrl = joinUriParts(parsedIssuerUrl.origin, [wellKnownCredentialIssuerSuffix, parsedIssuerUrl.pathname]);
|
|
749
|
+
let result = await fetchWellKnownMetadata(wellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
|
|
750
|
+
if (!result && legacyWellKnownMetadataUrl !== wellKnownMetadataUrl) result = await fetchWellKnownMetadata(legacyWellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
|
|
741
751
|
if (result && result.credentialIssuerMetadata.credential_issuer !== credentialIssuer) throw new Oauth2Error(`The 'credential_issuer' parameter '${result.credentialIssuerMetadata.credential_issuer}' in the well known credential issuer metadata at '${wellKnownMetadataUrl}' does not match the provided credential issuer '${credentialIssuer}'.`);
|
|
742
752
|
return result;
|
|
743
753
|
}
|
|
@@ -953,16 +963,16 @@ const zCredentialRequestProofJwt = z.object({
|
|
|
953
963
|
const zCredentialRequestJwtProofTypeHeader = zJwtHeader.merge(z.object({
|
|
954
964
|
key_attestation: z.optional(zCompactJwt),
|
|
955
965
|
typ: z.literal("openid4vci-proof+jwt")
|
|
956
|
-
})).
|
|
966
|
+
})).loose().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, { message: `Both 'jwk' and 'kid' are defined. Only one is allowed` }).refine(({ trust_chain, kid }) => !trust_chain || !kid, { message: `When 'trust_chain' is provided, 'kid' is required` });
|
|
957
967
|
const zCredentialRequestJwtProofTypePayload = z.object({
|
|
958
968
|
...zJwtPayload.shape,
|
|
959
969
|
aud: zHttpsUrl,
|
|
960
970
|
iat: zInteger
|
|
961
|
-
}).
|
|
971
|
+
}).loose();
|
|
962
972
|
|
|
963
973
|
//#endregion
|
|
964
974
|
//#region src/credential-request/z-credential-request-common.ts
|
|
965
|
-
const zCredentialRequestProofCommon = z.object({ proof_type: z.string() }).
|
|
975
|
+
const zCredentialRequestProofCommon = z.object({ proof_type: z.string() }).loose();
|
|
966
976
|
const allCredentialRequestProofs = [zCredentialRequestProofJwt, zCredentialRequestProofAttestation];
|
|
967
977
|
const zCredentialRequestProof = z.union([zCredentialRequestProofCommon, z.discriminatedUnion("proof_type", allCredentialRequestProofs)]);
|
|
968
978
|
const zCredentialRequestProofsCommon = z.record(z.string(), z.array(z.unknown()));
|
|
@@ -977,8 +987,8 @@ const zCredentialRequestCommon = z.object({
|
|
|
977
987
|
jwk: zJwk,
|
|
978
988
|
alg: z.string(),
|
|
979
989
|
enc: z.string()
|
|
980
|
-
}).
|
|
981
|
-
}).
|
|
990
|
+
}).loose().optional()
|
|
991
|
+
}).loose().refine(({ proof, proofs }) => !(proof !== void 0 && proofs !== void 0), { message: `Both 'proof' and 'proofs' are defined. Only one is allowed` });
|
|
982
992
|
|
|
983
993
|
//#endregion
|
|
984
994
|
//#region src/credential-request/z-credential-request.ts
|
|
@@ -1005,12 +1015,15 @@ const zCredentialRequestFormat = z.object({
|
|
|
1005
1015
|
format: z.string(),
|
|
1006
1016
|
credential_identifier: z.never({ message: "'credential_identifier' cannot be defined when 'format' is set." }).optional(),
|
|
1007
1017
|
credential_configuration_id: z.never({ message: "'credential_configuration_id' cannot be defined when 'format' is set." }).optional()
|
|
1008
|
-
}).
|
|
1018
|
+
}).loose();
|
|
1009
1019
|
const zCredentialRequestDraft14WithFormat = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
|
|
1010
1020
|
if (!allCredentialRequestFormatIdentifiers.includes(data.format)) return data;
|
|
1011
|
-
const result = z.object({}).
|
|
1021
|
+
const result = z.object({}).loose().and(z.union(allCredentialRequestFormats)).safeParse(data);
|
|
1012
1022
|
if (result.success) return result.data;
|
|
1013
|
-
for (const issue of result.error.issues) ctx.addIssue(
|
|
1023
|
+
for (const issue of result.error.issues) ctx.addIssue({
|
|
1024
|
+
...issue,
|
|
1025
|
+
code: issue.code
|
|
1026
|
+
});
|
|
1014
1027
|
return z.NEVER;
|
|
1015
1028
|
});
|
|
1016
1029
|
const zCredentialRequestDraft15 = z.union([zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest), zCredentialRequestCommon.and(zCredentialRequestCredentialConfigurationId)]);
|
|
@@ -1024,10 +1037,22 @@ const zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRe
|
|
|
1024
1037
|
if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
|
|
1025
1038
|
const result = formatSpecificTransformations[data.format].safeParse(data);
|
|
1026
1039
|
if (result.success) return result.data;
|
|
1027
|
-
for (const issue of result.error.issues) ctx.addIssue(
|
|
1040
|
+
for (const issue of result.error.issues) ctx.addIssue({
|
|
1041
|
+
...issue,
|
|
1042
|
+
code: issue.code
|
|
1043
|
+
});
|
|
1028
1044
|
return z.NEVER;
|
|
1029
1045
|
}).pipe(zCredentialRequestDraft14);
|
|
1030
|
-
const zCredentialRequestDraft14To11 = zCredentialRequestDraft14.
|
|
1046
|
+
const zCredentialRequestDraft14To11 = zCredentialRequestDraft14.transform((data, ctx) => {
|
|
1047
|
+
if (data.credential_identifier !== void 0) {
|
|
1048
|
+
ctx.addIssue({
|
|
1049
|
+
code: "custom",
|
|
1050
|
+
continue: false,
|
|
1051
|
+
message: `'credential_identifier' is not supported in OpenID4VCI draft 11`,
|
|
1052
|
+
path: ["credential_identifier"]
|
|
1053
|
+
});
|
|
1054
|
+
return z.NEVER;
|
|
1055
|
+
}
|
|
1031
1056
|
const formatSpecificTransformations = {
|
|
1032
1057
|
[zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft14To11,
|
|
1033
1058
|
[zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft14To11,
|
|
@@ -1036,7 +1061,10 @@ const zCredentialRequestDraft14To11 = zCredentialRequestDraft14.refine((data) =>
|
|
|
1036
1061
|
if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
|
|
1037
1062
|
const result = formatSpecificTransformations[data.format].safeParse(data);
|
|
1038
1063
|
if (result.success) return result.data;
|
|
1039
|
-
for (const issue of result.error.issues) ctx.addIssue(
|
|
1064
|
+
for (const issue of result.error.issues) ctx.addIssue({
|
|
1065
|
+
...issue,
|
|
1066
|
+
code: issue.code
|
|
1067
|
+
});
|
|
1040
1068
|
return z.NEVER;
|
|
1041
1069
|
});
|
|
1042
1070
|
const zCredentialRequest = z.union([
|
|
@@ -1050,7 +1078,7 @@ const zDeferredCredentialRequest = z.object({
|
|
|
1050
1078
|
jwk: zJwk,
|
|
1051
1079
|
alg: z.string(),
|
|
1052
1080
|
enc: z.string()
|
|
1053
|
-
}).
|
|
1081
|
+
}).loose().optional()
|
|
1054
1082
|
});
|
|
1055
1083
|
|
|
1056
1084
|
//#endregion
|
|
@@ -1095,10 +1123,10 @@ let Oauth2ErrorCodes$1 = /* @__PURE__ */ function(Oauth2ErrorCodes$2) {
|
|
|
1095
1123
|
return Oauth2ErrorCodes$2;
|
|
1096
1124
|
}({});
|
|
1097
1125
|
const zOauth2ErrorResponse = z.object({
|
|
1098
|
-
error: z.union([z.
|
|
1126
|
+
error: z.union([z.enum(Oauth2ErrorCodes$1), z.string()]),
|
|
1099
1127
|
error_description: z.string().optional(),
|
|
1100
1128
|
error_uri: z.string().optional()
|
|
1101
|
-
}).
|
|
1129
|
+
}).loose();
|
|
1102
1130
|
|
|
1103
1131
|
//#endregion
|
|
1104
1132
|
//#region src/credential-request/z-credential-response.ts
|
|
@@ -1107,28 +1135,28 @@ const zBaseCredentialResponse = z.object({
|
|
|
1107
1135
|
credentials: z.union([z.array(z.object({ credential: zCredentialEncoding })), z.array(zCredentialEncoding)]).optional(),
|
|
1108
1136
|
interval: z.number().int().positive().optional(),
|
|
1109
1137
|
notification_id: z.string().optional()
|
|
1110
|
-
}).
|
|
1138
|
+
}).loose();
|
|
1111
1139
|
const zCredentialResponse = zBaseCredentialResponse.extend({
|
|
1112
1140
|
credential: z.optional(zCredentialEncoding),
|
|
1113
1141
|
transaction_id: z.string().optional(),
|
|
1114
1142
|
c_nonce: z.string().optional(),
|
|
1115
1143
|
c_nonce_expires_in: z.number().int().optional()
|
|
1116
|
-
}).
|
|
1144
|
+
}).loose().superRefine((value, ctx) => {
|
|
1117
1145
|
const { credential, credentials, transaction_id, interval, notification_id } = value;
|
|
1118
1146
|
if ([
|
|
1119
1147
|
credential,
|
|
1120
1148
|
credentials,
|
|
1121
1149
|
transaction_id
|
|
1122
1150
|
].filter((i) => i !== void 0).length !== 1) ctx.addIssue({
|
|
1123
|
-
code:
|
|
1151
|
+
code: "custom",
|
|
1124
1152
|
message: `Exactly one of 'credential', 'credentials', or 'transaction_id' MUST be defined.`
|
|
1125
1153
|
});
|
|
1126
1154
|
if (transaction_id && !interval) ctx.addIssue({
|
|
1127
|
-
code:
|
|
1155
|
+
code: "custom",
|
|
1128
1156
|
message: `'interval' MUST be defined when 'transaction_id' is defined.`
|
|
1129
1157
|
});
|
|
1130
1158
|
if (notification_id && !(credentials || credential)) ctx.addIssue({
|
|
1131
|
-
code:
|
|
1159
|
+
code: "custom",
|
|
1132
1160
|
message: `'notification_id' MUST NOT be defined when 'credential' or 'credentials' are not defined.`
|
|
1133
1161
|
});
|
|
1134
1162
|
});
|
|
@@ -1136,7 +1164,7 @@ const zCredentialErrorResponse = z.object({
|
|
|
1136
1164
|
...zOauth2ErrorResponse.shape,
|
|
1137
1165
|
c_nonce: z.string().optional(),
|
|
1138
1166
|
c_nonce_expires_in: z.number().int().optional()
|
|
1139
|
-
}).
|
|
1167
|
+
}).loose();
|
|
1140
1168
|
const zDeferredCredentialResponse = zBaseCredentialResponse.refine((value) => {
|
|
1141
1169
|
const { credentials, interval } = value;
|
|
1142
1170
|
return [credentials, interval].filter((i) => i !== void 0).length === 1;
|
|
@@ -1362,7 +1390,7 @@ async function resolveIssuerMetadata(credentialIssuer, options) {
|
|
|
1362
1390
|
const zNonceResponse = z.object({
|
|
1363
1391
|
c_nonce: z.string(),
|
|
1364
1392
|
c_nonce_expires_in: z.optional(zInteger)
|
|
1365
|
-
}).
|
|
1393
|
+
}).loose();
|
|
1366
1394
|
|
|
1367
1395
|
//#endregion
|
|
1368
1396
|
//#region src/nonce/nonce-request.ts
|
|
@@ -1401,8 +1429,8 @@ const zNotificationRequest = z.object({
|
|
|
1401
1429
|
notification_id: z.string(),
|
|
1402
1430
|
event: zNotificationEvent,
|
|
1403
1431
|
event_description: z.optional(z.string())
|
|
1404
|
-
}).
|
|
1405
|
-
const zNotificationErrorResponse = z.object({ error: z.enum(["invalid_notification_id", "invalid_notification_request"]) }).
|
|
1432
|
+
}).loose();
|
|
1433
|
+
const zNotificationErrorResponse = z.object({ error: z.enum(["invalid_notification_id", "invalid_notification_request"]) }).loose();
|
|
1406
1434
|
|
|
1407
1435
|
//#endregion
|
|
1408
1436
|
//#region src/notification/notification.ts
|