@openid4vc/openid4vci 0.3.0-alpha-20250324183425 → 0.3.0-alpha-20250328112257

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.mjs CHANGED
@@ -1,3 +1,231 @@
1
+ // src/credential-offer/credential-offer.ts
2
+ import {
3
+ InvalidFetchResponseError,
4
+ Oauth2Error,
5
+ authorizationCodeGrantIdentifier,
6
+ getAuthorizationServerMetadataFromList,
7
+ preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier2
8
+ } from "@openid4vc/oauth2";
9
+ import {
10
+ ContentType,
11
+ URL,
12
+ URLSearchParams,
13
+ ValidationError,
14
+ createZodFetcher,
15
+ encodeToBase64Url,
16
+ getQueryParams,
17
+ objectToQueryParams,
18
+ parseWithErrorHandling
19
+ } from "@openid4vc/utils";
20
+
21
+ // src/version.ts
22
+ var Openid4vciDraftVersion = /* @__PURE__ */ ((Openid4vciDraftVersion2) => {
23
+ Openid4vciDraftVersion2["Draft15"] = "Draft15";
24
+ Openid4vciDraftVersion2["Draft14"] = "Draft14";
25
+ Openid4vciDraftVersion2["Draft11"] = "Draft11";
26
+ return Openid4vciDraftVersion2;
27
+ })(Openid4vciDraftVersion || {});
28
+
29
+ // src/credential-offer/z-credential-offer.ts
30
+ import {
31
+ preAuthorizedCodeGrantIdentifier
32
+ } from "@openid4vc/oauth2";
33
+ import { zHttpsUrl } from "@openid4vc/utils";
34
+ import z from "zod";
35
+ var zTxCode = z.object({
36
+ input_mode: z.union([z.literal("numeric"), z.literal("text")]).optional(),
37
+ length: z.number().int().optional(),
38
+ description: z.string().max(300).optional()
39
+ }).passthrough();
40
+ var zCredentialOfferGrants = z.object({
41
+ authorization_code: z.object({
42
+ issuer_state: z.string().optional(),
43
+ authorization_server: zHttpsUrl.optional()
44
+ }).passthrough().optional(),
45
+ [preAuthorizedCodeGrantIdentifier]: z.object({
46
+ "pre-authorized_code": z.string(),
47
+ tx_code: zTxCode.optional(),
48
+ authorization_server: zHttpsUrl.optional()
49
+ }).passthrough().optional()
50
+ }).passthrough();
51
+ var zCredentialOfferObjectDraft14 = z.object({
52
+ credential_issuer: zHttpsUrl,
53
+ credential_configuration_ids: z.array(z.string()),
54
+ grants: z.optional(zCredentialOfferGrants)
55
+ }).passthrough();
56
+ var zCredentialOfferObjectDraft11To14 = z.object({
57
+ credential_issuer: zHttpsUrl,
58
+ // We don't support the inline offer objects from draft 11
59
+ credentials: z.array(
60
+ z.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })
61
+ ),
62
+ grants: z.optional(
63
+ z.object({
64
+ // Has extra param in draft 14, but doesn't matter for transform purposes
65
+ authorization_code: zCredentialOfferGrants.shape.authorization_code,
66
+ [preAuthorizedCodeGrantIdentifier]: z.object({
67
+ "pre-authorized_code": z.string(),
68
+ user_pin_required: z.optional(z.boolean())
69
+ }).passthrough().optional()
70
+ })
71
+ )
72
+ }).passthrough().transform(({ credentials, grants, ...rest }) => {
73
+ const v14 = {
74
+ ...rest,
75
+ credential_configuration_ids: credentials
76
+ };
77
+ if (grants) {
78
+ v14.grants = { ...grants };
79
+ if (grants[preAuthorizedCodeGrantIdentifier]) {
80
+ const { user_pin_required, ...restGrants } = grants[preAuthorizedCodeGrantIdentifier];
81
+ v14.grants[preAuthorizedCodeGrantIdentifier] = {
82
+ ...restGrants
83
+ };
84
+ if (user_pin_required) {
85
+ v14.grants[preAuthorizedCodeGrantIdentifier].tx_code = {
86
+ input_mode: "text"
87
+ };
88
+ }
89
+ }
90
+ }
91
+ return v14;
92
+ }).pipe(zCredentialOfferObjectDraft14);
93
+ var zCredentialOfferObject = z.union([
94
+ // First prioritize draft 14 (and 13)
95
+ zCredentialOfferObjectDraft14,
96
+ // Then try parsing draft 11 and transform into draft 14
97
+ zCredentialOfferObjectDraft11To14
98
+ ]);
99
+
100
+ // src/credential-offer/credential-offer.ts
101
+ async function resolveCredentialOffer(credentialOffer, options) {
102
+ const parsedQueryParams = getQueryParams(credentialOffer);
103
+ let credentialOfferParseResult;
104
+ if (parsedQueryParams.credential_offer_uri) {
105
+ const fetchWithZod = createZodFetcher(options?.fetch);
106
+ const { response, result } = await fetchWithZod(
107
+ zCredentialOfferObject,
108
+ ContentType.Json,
109
+ parsedQueryParams.credential_offer_uri
110
+ );
111
+ if (!response.ok || !result) {
112
+ throw new InvalidFetchResponseError(
113
+ `Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccesfull response with status '${response.status}'`,
114
+ await response.clone().text(),
115
+ response
116
+ );
117
+ }
118
+ credentialOfferParseResult = result;
119
+ } else if (parsedQueryParams.credential_offer) {
120
+ let credentialOfferJson;
121
+ try {
122
+ credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
123
+ } catch (error) {
124
+ throw new Oauth2Error(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
125
+ }
126
+ credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
127
+ } else {
128
+ throw new Oauth2Error(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
129
+ }
130
+ if (credentialOfferParseResult.error) {
131
+ throw new ValidationError(
132
+ `Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`,
133
+ credentialOfferParseResult.error
134
+ );
135
+ }
136
+ return credentialOfferParseResult.data;
137
+ }
138
+ function determineAuthorizationServerForCredentialOffer(options) {
139
+ const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
140
+ let authorizationServer;
141
+ if (options.grantAuthorizationServer) {
142
+ authorizationServer = options.grantAuthorizationServer;
143
+ if (!authorizationServers) {
144
+ throw new Oauth2Error(
145
+ `Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not have an 'authorization_servers' property to match the value against.`
146
+ );
147
+ }
148
+ if (!authorizationServers.includes(authorizationServer)) {
149
+ throw new Oauth2Error(
150
+ `Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not include this authorization server. Available 'authorization_server' values are ${authorizationServers.join(", ")}.`
151
+ );
152
+ }
153
+ } else if (!authorizationServers) {
154
+ authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
155
+ } else {
156
+ if (authorizationServers.length === 0) {
157
+ throw new Oauth2Error(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
158
+ }
159
+ if (authorizationServers.length > 1) {
160
+ throw new Oauth2Error(
161
+ `Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`
162
+ );
163
+ }
164
+ authorizationServer = authorizationServers[0];
165
+ }
166
+ return authorizationServer;
167
+ }
168
+ async function createCredentialOffer(options) {
169
+ const {
170
+ [preAuthorizedCodeGrantIdentifier2]: preAuthorizedCodeGrant,
171
+ [authorizationCodeGrantIdentifier]: authorizationCodeGrant,
172
+ ...restGrants
173
+ } = options.grants;
174
+ const grants = { ...restGrants };
175
+ if (authorizationCodeGrant) {
176
+ determineAuthorizationServerForCredentialOffer({
177
+ issuerMetadata: options.issuerMetadata,
178
+ grantAuthorizationServer: authorizationCodeGrant.authorization_server
179
+ });
180
+ grants[authorizationCodeGrantIdentifier] = authorizationCodeGrant;
181
+ }
182
+ if (preAuthorizedCodeGrant) {
183
+ determineAuthorizationServerForCredentialOffer({
184
+ issuerMetadata: options.issuerMetadata,
185
+ grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
186
+ });
187
+ grants[preAuthorizedCodeGrantIdentifier2] = {
188
+ ...preAuthorizedCodeGrant,
189
+ "pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? encodeToBase64Url(await options.callbacks.generateRandom(32))
190
+ };
191
+ const txCode = grants[preAuthorizedCodeGrantIdentifier2].tx_code;
192
+ if (txCode && options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
193
+ grants[preAuthorizedCodeGrantIdentifier2].user_pin_required = txCode !== void 0;
194
+ }
195
+ }
196
+ const idsNotInMetadata = options.credentialConfigurationIds.filter(
197
+ (id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0
198
+ );
199
+ if (idsNotInMetadata.length > 0) {
200
+ throw new Oauth2Error(
201
+ `Credential configuration ids ${idsNotInMetadata} not found in the credential issuer metadata 'credential_configurations_supported'. Available ids are ${Object.keys(options.issuerMetadata.credentialIssuer.credential_configurations_supported).join(", ")}.`
202
+ );
203
+ }
204
+ const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
205
+ const credentialOfferObject = parseWithErrorHandling(zCredentialOfferObject, {
206
+ credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
207
+ credential_configuration_ids: options.credentialConfigurationIds,
208
+ grants,
209
+ ...options.additionalPayload
210
+ });
211
+ if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
212
+ credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
213
+ }
214
+ const url = new URL(credentialOfferScheme);
215
+ url.search = `?${new URLSearchParams([
216
+ ...url.searchParams.entries(),
217
+ ...objectToQueryParams({
218
+ credential_offer_uri: options.credentialOfferUri,
219
+ // Only add credential_offer is uri is undefined
220
+ credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
221
+ }).entries()
222
+ ]).toString()}`;
223
+ return {
224
+ credentialOffer: url.toString(),
225
+ credentialOfferObject
226
+ };
227
+ }
228
+
1
229
  // src/index.ts
2
230
  import { getGlobalConfig, setGlobalConfig } from "@openid4vc/utils";
3
231
 
@@ -5,54 +233,20 @@ import { getGlobalConfig, setGlobalConfig } from "@openid4vc/utils";
5
233
  import { arrayEqualsIgnoreOrder } from "@openid4vc/utils";
6
234
 
7
235
  // src/metadata/credential-issuer/credential-issuer-metadata.ts
8
- import { Oauth2Error, fetchWellKnownMetadata } from "@openid4vc/oauth2";
236
+ import { Oauth2Error as Oauth2Error2, fetchWellKnownMetadata } from "@openid4vc/oauth2";
9
237
  import { joinUriParts } from "@openid4vc/utils";
10
238
 
11
239
  // src/metadata/credential-issuer/z-credential-issuer-metadata.ts
12
240
  import { zCompactJwt } from "@openid4vc/oauth2";
13
- import { zHttpsUrl } from "@openid4vc/utils";
14
- import z9 from "zod";
241
+ import { zHttpsUrl as zHttpsUrl2 } from "@openid4vc/utils";
242
+ import z12 from "zod";
15
243
 
16
244
  // src/formats/credential/mso-mdoc/z-mso-mdoc.ts
17
245
  import z3 from "zod";
18
246
 
19
- // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
247
+ // src/metadata/credential-issuer/z-claims-description.ts
20
248
  import z2 from "zod";
21
-
22
- // src/key-attestation/z-key-attestation.ts
23
- import { zJwk, zJwtHeader, zJwtPayload } from "@openid4vc/oauth2";
24
- import { zInteger } from "@openid4vc/utils";
25
- import z from "zod";
26
- var zKeyAttestationJwtHeader = z.object({
27
- ...zJwtHeader.shape,
28
- typ: z.literal("keyattestation+jwt")
29
- }).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
30
- message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
31
- }).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
32
- message: `When 'trust_chain' is provided, 'kid' is required`
33
- });
34
- var zIso18045 = z.enum(["iso_18045_high", "iso_18045_moderate", "iso_18045_enhanced-basic", "iso_18045_basic"]);
35
- var zIso18045OrStringArray = z.array(z.union([zIso18045, z.string()]));
36
- var zKeyAttestationJwtPayload = z.object({
37
- ...zJwtPayload.shape,
38
- iat: zInteger,
39
- attested_keys: z.array(zJwk),
40
- key_storage: z.optional(zIso18045OrStringArray),
41
- user_authentication: z.optional(zIso18045OrStringArray),
42
- certification: z.optional(z.string())
43
- }).passthrough();
44
- var zKeyAttestationJwtPayloadForUse = (use) => z.object({
45
- ...zKeyAttestationJwtPayload.shape,
46
- // REQUIRED when used as proof_type.attesation directly
47
- nonce: use === "proof_type.attestation" ? z.string({
48
- message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly`
49
- }) : z.optional(z.string()),
50
- // REQUIRED when used within header of proof_type.jwt
51
- exp: use === "proof_type.jwt" ? zInteger : z.optional(zInteger)
52
- }).passthrough();
53
-
54
- // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
55
- var zCredentialConfigurationSupportedClaims = z2.object({
249
+ var zCredentialConfigurationSupportedClaimsDraft14 = z2.object({
56
250
  mandatory: z2.boolean().optional(),
57
251
  value_type: z2.string().optional(),
58
252
  display: z2.object({
@@ -60,108 +254,117 @@ var zCredentialConfigurationSupportedClaims = z2.object({
60
254
  locale: z2.string().optional()
61
255
  }).passthrough().optional()
62
256
  }).passthrough();
63
- var zCredentialConfigurationSupportedCommon = z2.object({
64
- format: z2.string(),
65
- scope: z2.string().optional(),
66
- cryptographic_binding_methods_supported: z2.array(z2.string()).optional(),
67
- credential_signing_alg_values_supported: z2.array(z2.string()).optional(),
68
- proof_types_supported: z2.record(
69
- z2.union([z2.literal("jwt"), z2.literal("attestation"), z2.string()]),
70
- z2.object({
71
- proof_signing_alg_values_supported: z2.array(z2.string()),
72
- key_attestations_required: z2.object({
73
- key_storage: zIso18045OrStringArray.optional(),
74
- user_authentication: zIso18045OrStringArray.optional()
75
- }).passthrough().optional()
76
- })
77
- ).optional(),
257
+ var zClaimsDescriptionPath = z2.array(z2.union([z2.string(), z2.number().int().nonnegative(), z2.null()])).nonempty();
258
+ var zMsoMdocClaimsDescriptionPath = z2.tuple([z2.string(), z2.string()], {
259
+ 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"
260
+ });
261
+ var zIssuerMetadataClaimsDescription = z2.object({
262
+ path: zClaimsDescriptionPath,
263
+ mandatory: z2.boolean().optional(),
78
264
  display: z2.array(
79
265
  z2.object({
80
- name: z2.string(),
81
- locale: z2.string().optional(),
82
- logo: z2.object({
83
- // FIXME: make required again, but need to support draft 11 first
84
- uri: z2.string().optional(),
85
- alt_text: z2.string().optional()
86
- }).passthrough().optional(),
87
- description: z2.string().optional(),
88
- background_color: z2.string().optional(),
89
- background_image: z2.object({
90
- // TODO: should be required, but paradym's metadata is wrong here.
91
- uri: z2.string().optional()
92
- }).passthrough().optional(),
93
- text_color: z2.string().optional()
266
+ name: z2.string().optional(),
267
+ locale: z2.string().optional()
94
268
  }).passthrough()
95
269
  ).optional()
96
270
  }).passthrough();
271
+ var zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription.extend({
272
+ path: zMsoMdocClaimsDescriptionPath
273
+ });
97
274
 
98
275
  // src/formats/credential/mso-mdoc/z-mso-mdoc.ts
99
276
  var zMsoMdocFormatIdentifier = z3.literal("mso_mdoc");
100
277
  var zMsoMdocCredentialIssuerMetadata = z3.object({
101
278
  format: zMsoMdocFormatIdentifier,
102
279
  doctype: z3.string(),
103
- claims: z3.optional(zCredentialConfigurationSupportedClaims),
280
+ claims: z3.array(zMsoMdocIssuerMetadataClaimsDescription).optional()
281
+ });
282
+ var zMsoMdocCredentialIssuerMetadataDraft14 = z3.object({
283
+ format: zMsoMdocFormatIdentifier,
284
+ doctype: z3.string(),
285
+ claims: zCredentialConfigurationSupportedClaimsDraft14.optional(),
104
286
  order: z3.optional(z3.array(z3.string()))
105
287
  });
106
- var zMsoMdocCredentialRequestFormat = z3.object({
288
+ var zMsoMdocCredentialRequestFormatDraft14 = z3.object({
107
289
  format: zMsoMdocFormatIdentifier,
108
290
  doctype: z3.string(),
109
- claims: z3.optional(zCredentialConfigurationSupportedClaims)
291
+ // Format based request is removed in Draft 15, so only old claims syntax supported.
292
+ claims: z3.optional(zCredentialConfigurationSupportedClaimsDraft14)
110
293
  });
111
294
 
112
295
  // src/formats/credential/sd-jwt-vc/z-sd-jwt-vc.ts
113
296
  import z4 from "zod";
114
297
  var zSdJwtVcFormatIdentifier = z4.literal("vc+sd-jwt");
115
- var zSdJwtVcCredentialIssuerMetadata = z4.object({
298
+ var zSdJwtVcCredentialIssuerMetadataDraft14 = z4.object({
116
299
  vct: z4.string(),
117
300
  format: zSdJwtVcFormatIdentifier,
118
- claims: z4.optional(zCredentialConfigurationSupportedClaims),
301
+ claims: z4.optional(zCredentialConfigurationSupportedClaimsDraft14),
119
302
  order: z4.optional(z4.array(z4.string()))
120
303
  });
121
- var zSdJwtVcCredentialRequestFormat = z4.object({
304
+ var zSdJwtVcCredentialRequestFormatDraft14 = z4.object({
122
305
  format: zSdJwtVcFormatIdentifier,
123
306
  vct: z4.string(),
124
- claims: z4.optional(zCredentialConfigurationSupportedClaims)
307
+ claims: z4.optional(zCredentialConfigurationSupportedClaimsDraft14)
308
+ });
309
+
310
+ // src/formats/credential/sd-jwt-dc/z-sd-jwt-dc.ts
311
+ import z5 from "zod";
312
+ var zSdJwtDcFormatIdentifier = z5.literal("dc+sd-jwt");
313
+ var zSdJwtDcCredentialIssuerMetadata = z5.object({
314
+ vct: z5.string(),
315
+ format: zSdJwtDcFormatIdentifier,
316
+ claims: z5.array(zIssuerMetadataClaimsDescription).optional()
125
317
  });
126
318
 
127
319
  // src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
128
- import z6 from "zod";
320
+ import z7 from "zod";
129
321
 
130
322
  // src/formats/credential/w3c-vc/z-w3c-vc-common.ts
131
- import z5 from "zod";
132
- var zCredentialSubjectLeafType = z5.object({
133
- mandatory: z5.boolean().optional(),
134
- value_type: z5.string().optional(),
135
- display: z5.array(
136
- z5.object({
137
- name: z5.string().optional(),
138
- locale: z5.string().optional()
323
+ import z6 from "zod";
324
+ var zCredentialSubjectLeafTypeDraft14 = z6.object({
325
+ mandatory: z6.boolean().optional(),
326
+ value_type: z6.string().optional(),
327
+ display: z6.array(
328
+ z6.object({
329
+ name: z6.string().optional(),
330
+ locale: z6.string().optional()
139
331
  }).passthrough()
140
332
  ).optional()
141
333
  }).passthrough();
142
- var zClaimValueSchema = z5.union([z5.array(z5.any()), z5.record(z5.string(), z5.any()), zCredentialSubjectLeafType]);
143
- var zW3cVcCredentialSubject = z5.record(z5.string(), zClaimValueSchema);
144
- var zW3cVcJsonLdCredentialDefinition = z5.object({
145
- "@context": z5.array(z5.string()),
146
- type: z5.array(z5.string()),
147
- credentialSubject: zW3cVcCredentialSubject.optional()
334
+ var zClaimValueSchemaDraft14 = z6.union([
335
+ z6.array(z6.any()),
336
+ z6.record(z6.string(), z6.any()),
337
+ zCredentialSubjectLeafTypeDraft14
338
+ ]);
339
+ var zW3cVcCredentialSubjectDraft14 = z6.record(z6.string(), zClaimValueSchemaDraft14);
340
+ var zW3cVcJsonLdCredentialDefinition = z6.object({
341
+ "@context": z6.array(z6.string()),
342
+ type: z6.array(z6.string())
148
343
  }).passthrough();
344
+ var zW3cVcJsonLdCredentialDefinitionDraft14 = zW3cVcJsonLdCredentialDefinition.extend({
345
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
346
+ });
149
347
 
150
348
  // src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
151
- var zLdpVcFormatIdentifier = z6.literal("ldp_vc");
152
- var zLdpVcCredentialIssuerMetadata = z6.object({
349
+ var zLdpVcFormatIdentifier = z7.literal("ldp_vc");
350
+ var zLdpVcCredentialIssuerMetadata = z7.object({
153
351
  format: zLdpVcFormatIdentifier,
154
352
  credential_definition: zW3cVcJsonLdCredentialDefinition,
155
- order: z6.array(z6.string()).optional()
353
+ claims: zIssuerMetadataClaimsDescription.optional()
354
+ });
355
+ var zLdpVcCredentialIssuerMetadataDraft14 = z7.object({
356
+ format: zLdpVcFormatIdentifier,
357
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
358
+ order: z7.array(z7.string()).optional()
156
359
  });
157
- var zLdpVcCredentialIssuerMetadataDraft11 = z6.object({
158
- order: z6.array(z6.string()).optional(),
360
+ var zLdpVcCredentialIssuerMetadataDraft11 = z7.object({
361
+ order: z7.array(z7.string()).optional(),
159
362
  format: zLdpVcFormatIdentifier,
160
363
  // Credential definition was spread on top level instead of a separatey property in v11
161
364
  // As well as using types instead of type
162
- "@context": z6.array(z6.string()),
163
- types: z6.array(z6.string()),
164
- credentialSubject: zW3cVcCredentialSubject.optional()
365
+ "@context": z7.array(z7.string()),
366
+ types: z7.array(z7.string()),
367
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
165
368
  }).passthrough();
166
369
  var zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDraft11.transform(
167
370
  ({ "@context": context, types, credentialSubject, ...rest }) => ({
@@ -174,22 +377,22 @@ var zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDr
174
377
  }
175
378
  })
176
379
  );
177
- var zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadata.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
380
+ var zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
178
381
  ...rest,
179
382
  ...credentialDefinition,
180
383
  types: type
181
384
  })).pipe(zLdpVcCredentialIssuerMetadataDraft11);
182
- var zLdpVcCredentialRequestFormat = z6.object({
385
+ var zLdpVcCredentialRequestFormatDraft14 = z7.object({
183
386
  format: zLdpVcFormatIdentifier,
184
- credential_definition: zW3cVcJsonLdCredentialDefinition
387
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14
185
388
  });
186
- var zLdpVcCredentialRequestDraft11 = z6.object({
389
+ var zLdpVcCredentialRequestDraft11 = z7.object({
187
390
  format: zLdpVcFormatIdentifier,
188
- credential_definition: z6.object({
189
- "@context": z6.array(z6.string()),
391
+ credential_definition: z7.object({
392
+ "@context": z7.array(z7.string()),
190
393
  // credential_definition was using types instead of type in v11
191
- types: z6.array(z6.string()),
192
- credentialSubject: zW3cVcCredentialSubject.optional()
394
+ types: z7.array(z7.string()),
395
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
193
396
  })
194
397
  }).passthrough();
195
398
  var zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transform(
@@ -201,7 +404,7 @@ var zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transfor
201
404
  }
202
405
  })
203
406
  );
204
- var zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormat.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
407
+ var zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
205
408
  ...rest,
206
409
  credential_definition: {
207
410
  ...restCredentialDefinition,
@@ -210,21 +413,26 @@ var zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormat.passthrou
210
413
  })).pipe(zLdpVcCredentialRequestDraft11);
211
414
 
212
415
  // src/formats/credential/w3c-vc/z-w3c-jwt-vc-json-ld.ts
213
- import z7 from "zod";
214
- var zJwtVcJsonLdFormatIdentifier = z7.literal("jwt_vc_json-ld");
215
- var zJwtVcJsonLdCredentialIssuerMetadata = z7.object({
416
+ import z8 from "zod";
417
+ var zJwtVcJsonLdFormatIdentifier = z8.literal("jwt_vc_json-ld");
418
+ var zJwtVcJsonLdCredentialIssuerMetadata = z8.object({
216
419
  format: zJwtVcJsonLdFormatIdentifier,
217
420
  credential_definition: zW3cVcJsonLdCredentialDefinition,
218
- order: z7.optional(z7.array(z7.string()))
421
+ claims: zIssuerMetadataClaimsDescription.optional()
219
422
  });
220
- var zJwtVcJsonLdCredentialIssuerMetadataDraft11 = z7.object({
221
- order: z7.array(z7.string()).optional(),
423
+ var zJwtVcJsonLdCredentialIssuerMetadataDraft14 = z8.object({
424
+ format: zJwtVcJsonLdFormatIdentifier,
425
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
426
+ order: z8.optional(z8.array(z8.string()))
427
+ });
428
+ var zJwtVcJsonLdCredentialIssuerMetadataDraft11 = z8.object({
429
+ order: z8.array(z8.string()).optional(),
222
430
  format: zJwtVcJsonLdFormatIdentifier,
223
431
  // Credential definition was spread on top level instead of a separatey property in v11
224
432
  // As well as using types instead of type
225
- "@context": z7.array(z7.string()),
226
- types: z7.array(z7.string()),
227
- credentialSubject: zW3cVcCredentialSubject.optional()
433
+ "@context": z8.array(z8.string()),
434
+ types: z8.array(z8.string()),
435
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
228
436
  }).passthrough();
229
437
  var zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssuerMetadataDraft11.transform(
230
438
  ({ "@context": context, types, credentialSubject, ...rest }) => ({
@@ -237,22 +445,22 @@ var zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssu
237
445
  }
238
446
  })
239
447
  );
240
- var zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadata.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
448
+ var zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
241
449
  ...rest,
242
450
  ...credentialDefinition,
243
451
  types: type
244
452
  })).pipe(zJwtVcJsonLdCredentialIssuerMetadataDraft11);
245
- var zJwtVcJsonLdCredentialRequestFormat = z7.object({
453
+ var zJwtVcJsonLdCredentialRequestFormatDraft14 = z8.object({
246
454
  format: zJwtVcJsonLdFormatIdentifier,
247
455
  credential_definition: zW3cVcJsonLdCredentialDefinition
248
456
  });
249
- var zJwtVcJsonLdCredentialRequestDraft11 = z7.object({
457
+ var zJwtVcJsonLdCredentialRequestDraft11 = z8.object({
250
458
  format: zJwtVcJsonLdFormatIdentifier,
251
- credential_definition: z7.object({
252
- "@context": z7.array(z7.string()),
459
+ credential_definition: z8.object({
460
+ "@context": z8.array(z8.string()),
253
461
  // credential_definition was using types instead of type in v11
254
- types: z7.array(z7.string()),
255
- credentialSubject: z7.optional(zW3cVcCredentialSubject)
462
+ types: z8.array(z8.string()),
463
+ credentialSubject: z8.optional(zW3cVcCredentialSubjectDraft14)
256
464
  }).passthrough()
257
465
  }).passthrough();
258
466
  var zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraft11.transform(
@@ -264,7 +472,7 @@ var zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraf
264
472
  }
265
473
  })
266
474
  );
267
- var zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormat.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
475
+ var zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
268
476
  ...rest,
269
477
  credential_definition: {
270
478
  ...restCredentialDefinition,
@@ -273,24 +481,31 @@ var zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestForm
273
481
  })).pipe(zJwtVcJsonLdCredentialRequestDraft11);
274
482
 
275
483
  // src/formats/credential/w3c-vc/z-w3c-jwt-vc-json.ts
276
- import z8 from "zod";
277
- var zJwtVcJsonFormatIdentifier = z8.literal("jwt_vc_json");
278
- var zJwtVcJsonCredentialDefinition = z8.object({
279
- type: z8.array(z8.string()),
280
- credentialSubject: zW3cVcCredentialSubject.optional()
484
+ import z9 from "zod";
485
+ var zJwtVcJsonFormatIdentifier = z9.literal("jwt_vc_json");
486
+ var zJwtVcJsonCredentialDefinition = z9.object({
487
+ type: z9.array(z9.string())
281
488
  }).passthrough();
282
- var zJwtVcJsonCredentialIssuerMetadata = z8.object({
489
+ var zJwtVcJsonCredentialDefinitionDraft14 = zJwtVcJsonCredentialDefinition.extend({
490
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
491
+ });
492
+ var zJwtVcJsonCredentialIssuerMetadata = z9.object({
283
493
  format: zJwtVcJsonFormatIdentifier,
284
494
  credential_definition: zJwtVcJsonCredentialDefinition,
285
- order: z8.array(z8.string()).optional()
495
+ claims: zIssuerMetadataClaimsDescription.optional()
286
496
  });
287
- var zJwtVcJsonCredentialIssuerMetadataDraft11 = z8.object({
497
+ var zJwtVcJsonCredentialIssuerMetadataDraft14 = z9.object({
288
498
  format: zJwtVcJsonFormatIdentifier,
289
- order: z8.array(z8.string()).optional(),
499
+ credential_definition: zJwtVcJsonCredentialDefinitionDraft14,
500
+ order: z9.array(z9.string()).optional()
501
+ });
502
+ var zJwtVcJsonCredentialIssuerMetadataDraft11 = z9.object({
503
+ format: zJwtVcJsonFormatIdentifier,
504
+ order: z9.array(z9.string()).optional(),
290
505
  // Credential definition was spread on top level instead of a separatey property in v11
291
506
  // As well as using types instead of type
292
- types: z8.array(z8.string()),
293
- credentialSubject: zW3cVcCredentialSubject.optional()
507
+ types: z9.array(z9.string()),
508
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
294
509
  }).passthrough();
295
510
  var zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMetadataDraft11.transform(
296
511
  ({ types, credentialSubject, ...rest }) => ({
@@ -302,21 +517,21 @@ var zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMe
302
517
  }
303
518
  })
304
519
  );
305
- var zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadata.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
520
+ var zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
306
521
  ...rest,
307
522
  types: type,
308
523
  ...credentialDefinition
309
524
  })).pipe(zJwtVcJsonCredentialIssuerMetadataDraft11);
310
- var zJwtVcJsonCredentialRequestFormat = z8.object({
525
+ var zJwtVcJsonCredentialRequestFormatDraft14 = z9.object({
311
526
  format: zJwtVcJsonFormatIdentifier,
312
527
  credential_definition: zJwtVcJsonCredentialDefinition
313
528
  });
314
- var zJwtVcJsonCredentialRequestDraft11 = z8.object({
529
+ var zJwtVcJsonCredentialRequestDraft11 = z9.object({
315
530
  format: zJwtVcJsonFormatIdentifier,
316
531
  // Credential definition was spread on top level instead of a separatey property in v11
317
532
  // As well as using types instead of type
318
- types: z8.array(z8.string()),
319
- credentialSubject: z8.optional(zW3cVcCredentialSubject)
533
+ types: z9.array(z9.string()),
534
+ credentialSubject: z9.optional(zW3cVcCredentialSubjectDraft14)
320
535
  }).passthrough();
321
536
  var zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.transform(
322
537
  ({ types, credentialSubject, ...rest }) => {
@@ -330,26 +545,98 @@ var zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.
330
545
  };
331
546
  }
332
547
  );
333
- var zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormat.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
548
+ var zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
334
549
  ...rest,
335
550
  types: type,
336
551
  ...credentialDefinition
337
552
  })).pipe(zJwtVcJsonCredentialRequestDraft11);
338
553
 
339
- // src/version.ts
340
- var Openid4vciDraftVersion = /* @__PURE__ */ ((Openid4vciDraftVersion2) => {
341
- Openid4vciDraftVersion2["Draft14"] = "Draft14";
342
- Openid4vciDraftVersion2["Draft11"] = "Draft11";
343
- return Openid4vciDraftVersion2;
344
- })(Openid4vciDraftVersion || {});
554
+ // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
555
+ import z11 from "zod";
556
+
557
+ // src/key-attestation/z-key-attestation.ts
558
+ import { zJwk, zJwtHeader, zJwtPayload } from "@openid4vc/oauth2";
559
+ import { zInteger } from "@openid4vc/utils";
560
+ import z10 from "zod";
561
+ var zKeyAttestationJwtHeader = z10.object({
562
+ ...zJwtHeader.shape,
563
+ typ: z10.literal("keyattestation+jwt").or(
564
+ // Draft 16
565
+ z10.literal("key-attestation+jwt")
566
+ )
567
+ }).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
568
+ message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
569
+ }).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
570
+ message: `When 'trust_chain' is provided, 'kid' is required`
571
+ });
572
+ var zIso18045 = z10.enum(["iso_18045_high", "iso_18045_moderate", "iso_18045_enhanced-basic", "iso_18045_basic"]);
573
+ var zIso18045OrStringArray = z10.array(z10.union([zIso18045, z10.string()]));
574
+ var zKeyAttestationJwtPayload = z10.object({
575
+ ...zJwtPayload.shape,
576
+ iat: zInteger,
577
+ attested_keys: z10.array(zJwk),
578
+ key_storage: z10.optional(zIso18045OrStringArray),
579
+ user_authentication: z10.optional(zIso18045OrStringArray),
580
+ certification: z10.optional(z10.string().url())
581
+ }).passthrough();
582
+ var zKeyAttestationJwtPayloadForUse = (use) => z10.object({
583
+ ...zKeyAttestationJwtPayload.shape,
584
+ // REQUIRED when used as proof_type.attesation directly
585
+ nonce: use === "proof_type.attestation" ? z10.string({
586
+ message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly`
587
+ }) : z10.optional(z10.string()),
588
+ // REQUIRED when used within header of proof_type.jwt
589
+ exp: use === "proof_type.jwt" ? zInteger : z10.optional(zInteger)
590
+ }).passthrough();
591
+
592
+ // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
593
+ var zCredentialConfigurationSupportedCommon = z11.object({
594
+ format: z11.string(),
595
+ scope: z11.string().optional(),
596
+ cryptographic_binding_methods_supported: z11.array(z11.string()).optional(),
597
+ credential_signing_alg_values_supported: z11.array(z11.string()).optional(),
598
+ proof_types_supported: z11.record(
599
+ z11.union([z11.literal("jwt"), z11.literal("attestation"), z11.string()]),
600
+ z11.object({
601
+ proof_signing_alg_values_supported: z11.array(z11.string()),
602
+ key_attestations_required: z11.object({
603
+ key_storage: zIso18045OrStringArray.optional(),
604
+ user_authentication: zIso18045OrStringArray.optional()
605
+ }).passthrough().optional()
606
+ })
607
+ ).optional(),
608
+ display: z11.array(
609
+ z11.object({
610
+ name: z11.string(),
611
+ locale: z11.string().optional(),
612
+ logo: z11.object({
613
+ // FIXME: make required again, but need to support draft 11 first
614
+ uri: z11.string().optional(),
615
+ alt_text: z11.string().optional()
616
+ }).passthrough().optional(),
617
+ description: z11.string().optional(),
618
+ background_color: z11.string().optional(),
619
+ background_image: z11.object({
620
+ // TODO: should be required, but paradym's metadata is wrong here.
621
+ uri: z11.string().optional()
622
+ }).passthrough().optional(),
623
+ text_color: z11.string().optional()
624
+ }).passthrough()
625
+ ).optional()
626
+ }).passthrough();
345
627
 
346
628
  // src/metadata/credential-issuer/z-credential-issuer-metadata.ts
347
629
  var allCredentialIssuerMetadataFormats = [
348
- zSdJwtVcCredentialIssuerMetadata,
630
+ zSdJwtDcCredentialIssuerMetadata,
349
631
  zMsoMdocCredentialIssuerMetadata,
350
632
  zJwtVcJsonLdCredentialIssuerMetadata,
351
633
  zLdpVcCredentialIssuerMetadata,
352
- zJwtVcJsonCredentialIssuerMetadata
634
+ zJwtVcJsonCredentialIssuerMetadata,
635
+ zMsoMdocCredentialIssuerMetadataDraft14,
636
+ zSdJwtVcCredentialIssuerMetadataDraft14,
637
+ zJwtVcJsonLdCredentialIssuerMetadataDraft14,
638
+ zLdpVcCredentialIssuerMetadataDraft14,
639
+ zJwtVcJsonCredentialIssuerMetadataDraft14
353
640
  ];
354
641
  var allCredentialIssuerMetadataFormatIdentifiers = allCredentialIssuerMetadataFormats.map(
355
642
  (format) => format.shape.format.value
@@ -357,56 +644,69 @@ var allCredentialIssuerMetadataFormatIdentifiers = allCredentialIssuerMetadataFo
357
644
  var zCredentialConfigurationSupportedWithFormats = zCredentialConfigurationSupportedCommon.transform(
358
645
  (data, ctx) => {
359
646
  if (!allCredentialIssuerMetadataFormatIdentifiers.includes(data.format)) return data;
360
- const result = z9.object({}).passthrough().and(z9.discriminatedUnion("format", allCredentialIssuerMetadataFormats)).safeParse(data);
647
+ const validators = allCredentialIssuerMetadataFormats.reduce(
648
+ (validators2, formatValidator) => {
649
+ const format = formatValidator.shape.format.value;
650
+ if (!validators2[format]) {
651
+ validators2[format] = [];
652
+ }
653
+ validators2[format].push(formatValidator);
654
+ return validators2;
655
+ },
656
+ {}
657
+ )[data.format];
658
+ const result = z12.object({}).passthrough().and(
659
+ validators.length > 1 ? z12.union(validators) : validators[0]
660
+ ).safeParse(data);
361
661
  if (result.success) {
362
662
  return result.data;
363
663
  }
364
664
  for (const issue of result.error.issues) {
365
665
  ctx.addIssue(issue);
366
666
  }
367
- return z9.NEVER;
667
+ return z12.NEVER;
368
668
  }
369
669
  );
370
- var zCredentialIssuerMetadataDisplayEntry = z9.object({
371
- name: z9.string().optional(),
372
- locale: z9.string().optional(),
373
- logo: z9.object({
670
+ var zCredentialIssuerMetadataDisplayEntry = z12.object({
671
+ name: z12.string().optional(),
672
+ locale: z12.string().optional(),
673
+ logo: z12.object({
374
674
  // FIXME: make required again, but need to support draft 11 first
375
- uri: z9.string().optional(),
376
- alt_text: z9.string().optional()
675
+ uri: z12.string().optional(),
676
+ alt_text: z12.string().optional()
377
677
  }).passthrough().optional()
378
678
  }).passthrough();
379
- var zCredentialIssuerMetadataDraft14 = z9.object({
380
- credential_issuer: zHttpsUrl,
381
- authorization_servers: z9.array(zHttpsUrl).optional(),
382
- credential_endpoint: zHttpsUrl,
383
- deferred_credential_endpoint: zHttpsUrl.optional(),
384
- notification_endpoint: zHttpsUrl.optional(),
679
+ var zCredentialIssuerMetadataDraft14Draft15 = z12.object({
680
+ credential_issuer: zHttpsUrl2,
681
+ authorization_servers: z12.array(zHttpsUrl2).optional(),
682
+ credential_endpoint: zHttpsUrl2,
683
+ deferred_credential_endpoint: zHttpsUrl2.optional(),
684
+ notification_endpoint: zHttpsUrl2.optional(),
385
685
  // Added after draft 14, but needed for proper
386
- nonce_endpoint: zHttpsUrl.optional(),
387
- credential_response_encryption: z9.object({
388
- alg_values_supported: z9.array(z9.string()),
389
- enc_values_supported: z9.array(z9.string()),
390
- encryption_required: z9.boolean()
686
+ nonce_endpoint: zHttpsUrl2.optional(),
687
+ credential_response_encryption: z12.object({
688
+ alg_values_supported: z12.array(z12.string()),
689
+ enc_values_supported: z12.array(z12.string()),
690
+ encryption_required: z12.boolean()
391
691
  }).passthrough().optional(),
392
- batch_credential_issuance: z9.object({
393
- batch_size: z9.number().positive()
692
+ batch_credential_issuance: z12.object({
693
+ batch_size: z12.number().positive()
394
694
  }).passthrough().optional(),
395
695
  signed_metadata: zCompactJwt.optional(),
396
- display: z9.array(zCredentialIssuerMetadataDisplayEntry).optional(),
397
- credential_configurations_supported: z9.record(z9.string(), zCredentialConfigurationSupportedWithFormats)
696
+ display: z12.array(zCredentialIssuerMetadataDisplayEntry).optional(),
697
+ credential_configurations_supported: z12.record(z12.string(), zCredentialConfigurationSupportedWithFormats)
398
698
  }).passthrough();
399
- var zCredentialConfigurationSupportedDraft11To14 = z9.object({
400
- id: z9.string().optional(),
401
- format: z9.string(),
402
- cryptographic_suites_supported: z9.array(z9.string()).optional(),
403
- display: z9.array(
404
- z9.object({
405
- logo: z9.object({
406
- url: z9.string().url().optional()
699
+ var zCredentialConfigurationSupportedDraft11To14 = z12.object({
700
+ id: z12.string().optional(),
701
+ format: z12.string(),
702
+ cryptographic_suites_supported: z12.array(z12.string()).optional(),
703
+ display: z12.array(
704
+ z12.object({
705
+ logo: z12.object({
706
+ url: z12.string().url().optional()
407
707
  }).passthrough().optional(),
408
- background_image: z9.object({
409
- url: z9.string().url().optional()
708
+ background_image: z12.object({
709
+ url: z12.string().url().optional()
410
710
  }).passthrough().optional()
411
711
  }).passthrough()
412
712
  ).optional()
@@ -447,11 +747,11 @@ var zCredentialConfigurationSupportedDraft11To14 = z9.object({
447
747
  for (const issue of result.error.issues) {
448
748
  ctx.addIssue(issue);
449
749
  }
450
- return z9.NEVER;
750
+ return z12.NEVER;
451
751
  }).pipe(zCredentialConfigurationSupportedWithFormats);
452
752
  var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSupportedWithFormats.and(
453
- z9.object({
454
- id: z9.string()
753
+ z12.object({
754
+ id: z12.string()
455
755
  }).passthrough()
456
756
  ).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope, ...rest }) => ({
457
757
  ...rest,
@@ -471,15 +771,15 @@ var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSuppo
471
771
  } : {},
472
772
  id
473
773
  })).pipe(
474
- z9.union([
774
+ z12.union([
475
775
  zLdpVcCredentialIssuerMetadataDraft14To11,
476
776
  zJwtVcJsonCredentialIssuerMetadataDraft14To11,
477
777
  zJwtVcJsonLdCredentialIssuerMetadataDraft14To11,
478
778
  // To handle unrecognized formats and not error immediately we allow the common format as well
479
779
  // but they can't use any of the foramt identifiers that have a specific transformation. This way if a format is
480
780
  // has a transformation it NEEDS to use the format specific transformation, and otherwise we fall back to the common validation
481
- z9.object({
482
- format: z9.string().refine(
781
+ z12.object({
782
+ format: z12.string().refine(
483
783
  (input) => ![
484
784
  zLdpVcFormatIdentifier.value,
485
785
  zJwtVcJsonFormatIdentifier.value,
@@ -489,11 +789,11 @@ var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSuppo
489
789
  }).passthrough()
490
790
  ])
491
791
  );
492
- var zCredentialIssuerMetadataDraft11To14 = z9.object({
493
- authorization_server: z9.string().optional(),
494
- credentials_supported: z9.array(
495
- z9.object({
496
- id: z9.string().optional()
792
+ var zCredentialIssuerMetadataDraft11To14 = z12.object({
793
+ authorization_server: z12.string().optional(),
794
+ credentials_supported: z12.array(
795
+ z12.object({
796
+ id: z12.string().optional()
497
797
  }).passthrough()
498
798
  )
499
799
  }).passthrough().transform(({ authorization_server, credentials_supported, ...rest }) => {
@@ -506,12 +806,12 @@ var zCredentialIssuerMetadataDraft11To14 = z9.object({
506
806
  )
507
807
  };
508
808
  }).pipe(
509
- z9.object({
809
+ z12.object({
510
810
  // Update from v11 structrue to v14 structure
511
- credential_configurations_supported: z9.record(z9.string(), zCredentialConfigurationSupportedDraft11To14)
811
+ credential_configurations_supported: z12.record(z12.string(), zCredentialConfigurationSupportedDraft11To14)
512
812
  }).passthrough()
513
- ).pipe(zCredentialIssuerMetadataDraft14);
514
- var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14.transform((issuerMetadata) => ({
813
+ ).pipe(zCredentialIssuerMetadataDraft14Draft15);
814
+ var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15.transform((issuerMetadata) => ({
515
815
  ...issuerMetadata,
516
816
  ...issuerMetadata.authorization_servers ? { authorization_server: issuerMetadata.authorization_servers[0] } : {},
517
817
  credentials_supported: Object.entries(issuerMetadata.credential_configurations_supported).map(([id, value]) => ({
@@ -519,22 +819,35 @@ var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14.tran
519
819
  id
520
820
  }))
521
821
  })).pipe(
522
- zCredentialIssuerMetadataDraft14.extend({
523
- credentials_supported: z9.array(zCredentialConfigurationSupportedDraft14To11)
822
+ zCredentialIssuerMetadataDraft14Draft15.extend({
823
+ credentials_supported: z12.array(zCredentialConfigurationSupportedDraft14To11)
524
824
  })
525
825
  );
526
- var zCredentialIssuerMetadata = z9.union([
527
- // First prioritize draft 14 (and 13)
528
- zCredentialIssuerMetadataDraft14,
826
+ var zCredentialIssuerMetadata = z12.union([
827
+ // First prioritize draft 15/14 (and 13)
828
+ zCredentialIssuerMetadataDraft14Draft15,
529
829
  // Then try parsing draft 11 and transform into draft 14
530
830
  zCredentialIssuerMetadataDraft11To14
531
831
  ]);
532
- var zCredentialIssuerMetadataWithDraftVersion = z9.union([
533
- // First prioritize draft 14 (and 13)
534
- zCredentialIssuerMetadataDraft14.transform((credentialIssuerMetadata) => ({
535
- credentialIssuerMetadata,
536
- originalDraftVersion: "Draft14" /* Draft14 */
537
- })),
832
+ var zCredentialIssuerMetadataWithDraftVersion = z12.union([
833
+ zCredentialIssuerMetadataDraft14Draft15.transform((credentialIssuerMetadata) => {
834
+ const isDraft15 = Object.values(credentialIssuerMetadata.credential_configurations_supported).some(
835
+ (configuration) => {
836
+ const knownConfiguration = configuration;
837
+ if (knownConfiguration.format === zSdJwtDcFormatIdentifier.value) return true;
838
+ if (Array.isArray(knownConfiguration.claims)) return true;
839
+ if (Object.values(knownConfiguration.proof_types_supported ?? {}).some(
840
+ (proofType) => proofType.key_attestations_required !== void 0
841
+ ))
842
+ return true;
843
+ return false;
844
+ }
845
+ );
846
+ return {
847
+ credentialIssuerMetadata,
848
+ originalDraftVersion: isDraft15 ? "Draft15" /* Draft15 */ : "Draft14" /* Draft14 */
849
+ };
850
+ }),
538
851
  // Then try parsing draft 11 and transform into draft 14
539
852
  zCredentialIssuerMetadataDraft11To14.transform((credentialIssuerMetadata) => ({
540
853
  credentialIssuerMetadata,
@@ -548,7 +861,7 @@ async function fetchCredentialIssuerMetadata(credentialIssuer, fetch) {
548
861
  const wellKnownMetadataUrl = joinUriParts(credentialIssuer, [wellKnownCredentialIssuerSuffix]);
549
862
  const result = await fetchWellKnownMetadata(wellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
550
863
  if (result && result.credentialIssuerMetadata.credential_issuer !== credentialIssuer) {
551
- throw new Oauth2Error(
864
+ throw new Oauth2Error2(
552
865
  `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}'.`
553
866
  );
554
867
  }
@@ -561,6 +874,15 @@ function extractKnownCredentialConfigurationSupportedFormats(credentialConfigura
561
874
  )
562
875
  );
563
876
  }
877
+ function getCredentialConfigurationSupportedById(credentialConfigurations, credentialConfigurationId) {
878
+ const configuration = credentialConfigurations[credentialConfigurationId];
879
+ if (!configuration) {
880
+ throw new Oauth2Error2(
881
+ `Credential configuration with id '${credentialConfigurationId}' not found in credential configurations supported.`
882
+ );
883
+ }
884
+ return configuration;
885
+ }
564
886
 
565
887
  // src/credential-request/credential-request-configurations.ts
566
888
  function getCredentialConfigurationsMatchingRequestFormat({
@@ -619,302 +941,132 @@ var Openid4vciSendNotificationError = class extends Openid4vciError {
619
941
  }
620
942
  };
621
943
 
622
- // src/metadata/credential-issuer/credential-configurations.ts
623
- import { Oauth2Error as Oauth2Error2 } from "@openid4vc/oauth2";
624
- import { ValidationError } from "@openid4vc/utils";
625
- function extractScopesForCredentialConfigurationIds(options) {
626
- const scopes = /* @__PURE__ */ new Set();
627
- for (const credentialConfigurationId of options.credentialConfigurationIds) {
628
- const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[credentialConfigurationId];
629
- if (!credentialConfiguration) {
630
- throw new Oauth2Error2(
631
- `Credential configuration with id '${credentialConfigurationId}' not found in metadata from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
632
- );
633
- }
634
- const scope = credentialConfiguration.scope;
635
- if (scope) scopes.add(scope);
636
- else if (!scope && options.throwOnConfigurationWithoutScope) {
637
- throw new Oauth2Error2(
638
- `Credential configuration with id '${credentialConfigurationId}' does not have a 'scope' configured, and 'throwOnConfigurationWithoutScope' was enabled.`
639
- );
640
- }
641
- }
642
- return scopes.size > 0 ? Array.from(scopes) : void 0;
643
- }
644
- function credentialsSupportedToCredentialConfigurationsSupported(credentialsSupported) {
645
- const credentialConfigurationsSupported = {};
646
- for (let index = 0; index < credentialsSupported.length; index++) {
647
- const credentialSupported = credentialsSupported[index];
648
- if (!credentialSupported.id) {
649
- throw new Openid4vciError(
650
- `Credential supported at index '${index}' does not have an 'id' property. Credential configuration requires the 'id' property as key`
651
- );
652
- }
653
- const parseResult = zCredentialConfigurationSupportedDraft11To14.safeParse(credentialSupported);
654
- if (!parseResult.success) {
655
- throw new ValidationError(
656
- `Error transforming credential supported with id '${credentialSupported.id}' to credential configuration supported format`,
657
- parseResult.error
658
- );
659
- }
660
- credentialConfigurationsSupported[credentialSupported.id] = parseResult.data;
661
- }
662
- return credentialConfigurationsSupported;
944
+ // src/key-attestation/key-attestation.ts
945
+ import { decodeJwt, jwtHeaderFromJwtSigner } from "@openid4vc/oauth2";
946
+ import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
947
+ import { dateToSeconds, parseWithErrorHandling as parseWithErrorHandling2 } from "@openid4vc/utils";
948
+ async function createKeyAttestationJwt(options) {
949
+ const header = parseWithErrorHandling2(zKeyAttestationJwtHeader, {
950
+ ...jwtHeaderFromJwtSigner(options.signer),
951
+ typ: "keyattestation+jwt"
952
+ });
953
+ const payload = parseWithErrorHandling2(zKeyAttestationJwtPayloadForUse(options.use), {
954
+ iat: dateToSeconds(options.issuedAt),
955
+ exp: options.expiresAt ? dateToSeconds(options.expiresAt) : void 0,
956
+ nonce: options.nonce,
957
+ attested_keys: options.attestedKeys,
958
+ user_authentication: options.userAuthentication,
959
+ key_storage: options.keyStorage,
960
+ certification: options.certification,
961
+ ...options.additionalPayload
962
+ });
963
+ const { jwt } = await options.callbacks.signJwt(options.signer, { header, payload });
964
+ return jwt;
663
965
  }
664
-
665
- // src/Openid4vciClient.ts
666
- import {
667
- Oauth2Client,
668
- Oauth2ClientAuthorizationChallengeError,
669
- Oauth2Error as Oauth2Error7,
670
- Oauth2ErrorCodes as Oauth2ErrorCodes2,
671
- authorizationCodeGrantIdentifier as authorizationCodeGrantIdentifier2,
672
- getAuthorizationServerMetadataFromList as getAuthorizationServerMetadataFromList2,
673
- preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier3
674
- } from "@openid4vc/oauth2";
675
-
676
- // src/credential-offer/credential-offer.ts
677
- import {
678
- InvalidFetchResponseError,
679
- Oauth2Error as Oauth2Error3,
680
- authorizationCodeGrantIdentifier,
681
- getAuthorizationServerMetadataFromList,
682
- preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier2
683
- } from "@openid4vc/oauth2";
684
- import {
685
- ContentType,
686
- URL,
687
- URLSearchParams,
688
- ValidationError as ValidationError2,
689
- createZodFetcher,
690
- encodeToBase64Url,
691
- getQueryParams,
692
- objectToQueryParams,
693
- parseWithErrorHandling
694
- } from "@openid4vc/utils";
695
-
696
- // src/credential-offer/z-credential-offer.ts
697
- import {
698
- preAuthorizedCodeGrantIdentifier
699
- } from "@openid4vc/oauth2";
700
- import { zHttpsUrl as zHttpsUrl2 } from "@openid4vc/utils";
701
- import z10 from "zod";
702
- var zTxCode = z10.object({
703
- input_mode: z10.union([z10.literal("numeric"), z10.literal("text")]).optional(),
704
- length: z10.number().int().optional(),
705
- description: z10.string().max(300).optional()
706
- }).passthrough();
707
- var zCredentialOfferGrants = z10.object({
708
- authorization_code: z10.object({
709
- issuer_state: z10.string().optional(),
710
- authorization_server: zHttpsUrl2.optional()
711
- }).passthrough().optional(),
712
- [preAuthorizedCodeGrantIdentifier]: z10.object({
713
- "pre-authorized_code": z10.string(),
714
- tx_code: zTxCode.optional(),
715
- authorization_server: zHttpsUrl2.optional()
716
- }).passthrough().optional()
717
- }).passthrough();
718
- var zCredentialOfferObjectDraft14 = z10.object({
719
- credential_issuer: zHttpsUrl2,
720
- credential_configuration_ids: z10.array(z10.string()),
721
- grants: z10.optional(zCredentialOfferGrants)
722
- }).passthrough();
723
- var zCredentialOfferObjectDraft11To14 = z10.object({
724
- credential_issuer: zHttpsUrl2,
725
- // We don't support the inline offer objects from draft 11
726
- credentials: z10.array(
727
- z10.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })
728
- ),
729
- grants: z10.optional(
730
- z10.object({
731
- // Has extra param in draft 14, but doesn't matter for transform purposes
732
- authorization_code: zCredentialOfferGrants.shape.authorization_code,
733
- [preAuthorizedCodeGrantIdentifier]: z10.object({
734
- "pre-authorized_code": z10.string(),
735
- user_pin_required: z10.optional(z10.boolean())
736
- }).passthrough().optional()
737
- })
738
- )
739
- }).passthrough().transform(({ credentials, grants, ...rest }) => {
740
- const v14 = {
741
- ...rest,
742
- credential_configuration_ids: credentials
743
- };
744
- if (grants) {
745
- v14.grants = { ...grants };
746
- if (grants[preAuthorizedCodeGrantIdentifier]) {
747
- const { user_pin_required, ...restGrants } = grants[preAuthorizedCodeGrantIdentifier];
748
- v14.grants[preAuthorizedCodeGrantIdentifier] = {
749
- ...restGrants
750
- };
751
- if (user_pin_required) {
752
- v14.grants[preAuthorizedCodeGrantIdentifier].tx_code = {
753
- input_mode: "text"
754
- };
755
- }
756
- }
757
- }
758
- return v14;
759
- }).pipe(zCredentialOfferObjectDraft14);
760
- var zCredentialOfferObject = z10.union([
761
- // First prioritize draft 14 (and 13)
762
- zCredentialOfferObjectDraft14,
763
- // Then try parsing draft 11 and transform into draft 14
764
- zCredentialOfferObjectDraft11To14
765
- ]);
766
-
767
- // src/credential-offer/credential-offer.ts
768
- async function resolveCredentialOffer(credentialOffer, options) {
769
- const parsedQueryParams = getQueryParams(credentialOffer);
770
- let credentialOfferParseResult;
771
- if (parsedQueryParams.credential_offer_uri) {
772
- const fetchWithZod = createZodFetcher(options?.fetch);
773
- const { response, result } = await fetchWithZod(
774
- zCredentialOfferObject,
775
- ContentType.Json,
776
- parsedQueryParams.credential_offer_uri
777
- );
778
- if (!response.ok || !result) {
779
- throw new InvalidFetchResponseError(
780
- `Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccesfull response with status '${response.status}'`,
781
- await response.clone().text(),
782
- response
783
- );
784
- }
785
- credentialOfferParseResult = result;
786
- } else if (parsedQueryParams.credential_offer) {
787
- let credentialOfferJson;
788
- try {
789
- credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
790
- } catch (error) {
791
- throw new Oauth2Error3(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
792
- }
793
- credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
794
- } else {
795
- throw new Oauth2Error3(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
796
- }
797
- if (credentialOfferParseResult.error) {
798
- throw new ValidationError2(
799
- `Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`,
800
- credentialOfferParseResult.error
801
- );
966
+ function parseKeyAttestationJwt({ keyAttestationJwt, use }) {
967
+ return decodeJwt({
968
+ jwt: keyAttestationJwt,
969
+ headerSchema: zKeyAttestationJwtHeader,
970
+ payloadSchema: zKeyAttestationJwtPayloadForUse(use)
971
+ });
972
+ }
973
+ async function verifyKeyAttestationJwt(options) {
974
+ const { header, payload } = parseKeyAttestationJwt({ keyAttestationJwt: options.keyAttestationJwt, use: options.use });
975
+ const now = options.now?.getTime() ?? Date.now();
976
+ if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
977
+ throw new Openid4vciError("Nonce used for key attestation jwt expired");
802
978
  }
803
- return credentialOfferParseResult.data;
979
+ const { signer } = await verifyJwt({
980
+ compact: options.keyAttestationJwt,
981
+ header,
982
+ payload,
983
+ signer: jwtSignerFromJwt({ header, payload }),
984
+ verifyJwtCallback: options.callbacks.verifyJwt,
985
+ errorMessage: "Error verifiying key attestation jwt",
986
+ expectedNonce: options.expectedNonce,
987
+ now: options.now
988
+ });
989
+ return {
990
+ header,
991
+ payload,
992
+ signer
993
+ };
804
994
  }
805
- function determineAuthorizationServerForCredentialOffer(options) {
806
- const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
807
- let authorizationServer;
808
- if (options.grantAuthorizationServer) {
809
- authorizationServer = options.grantAuthorizationServer;
810
- if (!authorizationServers) {
811
- throw new Oauth2Error3(
812
- `Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not have an 'authorization_servers' property to match the value against.`
813
- );
814
- }
815
- if (!authorizationServers.includes(authorizationServer)) {
995
+
996
+ // src/metadata/credential-issuer/credential-configurations.ts
997
+ import { Oauth2Error as Oauth2Error3 } from "@openid4vc/oauth2";
998
+ import { ValidationError as ValidationError2 } from "@openid4vc/utils";
999
+ function extractScopesForCredentialConfigurationIds(options) {
1000
+ const scopes = /* @__PURE__ */ new Set();
1001
+ for (const credentialConfigurationId of options.credentialConfigurationIds) {
1002
+ const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[credentialConfigurationId];
1003
+ if (!credentialConfiguration) {
816
1004
  throw new Oauth2Error3(
817
- `Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not include this authorization server. Available 'authorization_server' values are ${authorizationServers.join(", ")}.`
1005
+ `Credential configuration with id '${credentialConfigurationId}' not found in metadata from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
818
1006
  );
819
1007
  }
820
- } else if (!authorizationServers) {
821
- authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
822
- } else {
823
- if (authorizationServers.length === 0) {
824
- throw new Oauth2Error3(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
825
- }
826
- if (authorizationServers.length > 1) {
1008
+ const scope = credentialConfiguration.scope;
1009
+ if (scope) scopes.add(scope);
1010
+ else if (!scope && options.throwOnConfigurationWithoutScope) {
827
1011
  throw new Oauth2Error3(
828
- `Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`
1012
+ `Credential configuration with id '${credentialConfigurationId}' does not have a 'scope' configured, and 'throwOnConfigurationWithoutScope' was enabled.`
829
1013
  );
830
1014
  }
831
- authorizationServer = authorizationServers[0];
832
1015
  }
833
- return authorizationServer;
1016
+ return scopes.size > 0 ? Array.from(scopes) : void 0;
834
1017
  }
835
- async function createCredentialOffer(options) {
836
- const {
837
- [preAuthorizedCodeGrantIdentifier2]: preAuthorizedCodeGrant,
838
- [authorizationCodeGrantIdentifier]: authorizationCodeGrant,
839
- ...restGrants
840
- } = options.grants;
841
- const grants = { ...restGrants };
842
- if (authorizationCodeGrant) {
843
- determineAuthorizationServerForCredentialOffer({
844
- issuerMetadata: options.issuerMetadata,
845
- grantAuthorizationServer: authorizationCodeGrant.authorization_server
846
- });
847
- grants[authorizationCodeGrantIdentifier] = authorizationCodeGrant;
848
- }
849
- if (preAuthorizedCodeGrant) {
850
- determineAuthorizationServerForCredentialOffer({
851
- issuerMetadata: options.issuerMetadata,
852
- grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
853
- });
854
- grants[preAuthorizedCodeGrantIdentifier2] = {
855
- ...preAuthorizedCodeGrant,
856
- "pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? encodeToBase64Url(await options.callbacks.generateRandom(32))
857
- };
858
- const txCode = grants[preAuthorizedCodeGrantIdentifier2].tx_code;
859
- if (txCode && options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
860
- grants[preAuthorizedCodeGrantIdentifier2].user_pin_required = txCode !== void 0;
1018
+ function credentialsSupportedToCredentialConfigurationsSupported(credentialsSupported) {
1019
+ const credentialConfigurationsSupported = {};
1020
+ for (let index = 0; index < credentialsSupported.length; index++) {
1021
+ const credentialSupported = credentialsSupported[index];
1022
+ if (!credentialSupported.id) {
1023
+ throw new Openid4vciError(
1024
+ `Credential supported at index '${index}' does not have an 'id' property. Credential configuration requires the 'id' property as key`
1025
+ );
861
1026
  }
1027
+ const parseResult = zCredentialConfigurationSupportedDraft11To14.safeParse(credentialSupported);
1028
+ if (!parseResult.success) {
1029
+ throw new ValidationError2(
1030
+ `Error transforming credential supported with id '${credentialSupported.id}' to credential configuration supported format`,
1031
+ parseResult.error
1032
+ );
1033
+ }
1034
+ credentialConfigurationsSupported[credentialSupported.id] = parseResult.data;
862
1035
  }
863
- const idsNotInMetadata = options.credentialConfigurationIds.filter(
864
- (id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0
865
- );
866
- if (idsNotInMetadata.length > 0) {
867
- throw new Oauth2Error3(
868
- `Credential configuration ids ${idsNotInMetadata} not found in the credential issuer metadata 'credential_configurations_supported'. Available ids are ${Object.keys(options.issuerMetadata.credentialIssuer.credential_configurations_supported).join(", ")}.`
869
- );
870
- }
871
- const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
872
- const credentialOfferObject = parseWithErrorHandling(zCredentialOfferObject, {
873
- credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
874
- credential_configuration_ids: options.credentialConfigurationIds,
875
- grants,
876
- ...options.additionalPayload
877
- });
878
- if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
879
- credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
880
- }
881
- const url = new URL(credentialOfferScheme);
882
- url.search = `?${new URLSearchParams([
883
- ...url.searchParams.entries(),
884
- ...objectToQueryParams({
885
- credential_offer_uri: options.credentialOfferUri,
886
- // Only add credential_offer is uri is undefined
887
- credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
888
- }).entries()
889
- ]).toString()}`;
890
- return {
891
- credentialOffer: url.toString(),
892
- credentialOfferObject
893
- };
1036
+ return credentialConfigurationsSupported;
894
1037
  }
895
1038
 
1039
+ // src/Openid4vciClient.ts
1040
+ import {
1041
+ Oauth2Client,
1042
+ Oauth2ClientAuthorizationChallengeError,
1043
+ Oauth2Error as Oauth2Error7,
1044
+ Oauth2ErrorCodes as Oauth2ErrorCodes2,
1045
+ authorizationCodeGrantIdentifier as authorizationCodeGrantIdentifier2,
1046
+ getAuthorizationServerMetadataFromList as getAuthorizationServerMetadataFromList2,
1047
+ preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier3
1048
+ } from "@openid4vc/oauth2";
1049
+
896
1050
  // src/credential-request/format-payload.ts
897
1051
  import { zIs } from "@openid4vc/utils";
898
1052
  function getCredentialRequestFormatPayloadForCredentialConfigurationId(options) {
899
- const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[options.credentialConfigurationId];
900
- if (!credentialConfiguration) {
901
- throw new Openid4vciError(
902
- `Could not find credential configuration with id '${options.credentialConfigurationId}' in metadata of credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'.`
903
- );
904
- }
905
- if (zIs(zSdJwtVcCredentialIssuerMetadata, credentialConfiguration)) {
1053
+ const credentialConfiguration = getCredentialConfigurationSupportedById(
1054
+ options.issuerMetadata.credentialIssuer.credential_configurations_supported,
1055
+ options.credentialConfigurationId
1056
+ );
1057
+ if (zIs(zSdJwtVcCredentialIssuerMetadataDraft14, credentialConfiguration)) {
906
1058
  return {
907
1059
  format: credentialConfiguration.format,
908
1060
  vct: credentialConfiguration.vct
909
1061
  };
910
1062
  }
911
- if (zIs(zMsoMdocCredentialIssuerMetadata, credentialConfiguration)) {
1063
+ if (zIs(zMsoMdocCredentialIssuerMetadata, credentialConfiguration) || zIs(zMsoMdocCredentialIssuerMetadataDraft14, credentialConfiguration)) {
912
1064
  return {
913
1065
  format: credentialConfiguration.format,
914
1066
  doctype: credentialConfiguration.doctype
915
1067
  };
916
1068
  }
917
- if (zIs(zLdpVcCredentialIssuerMetadata, credentialConfiguration)) {
1069
+ if (zIs(zLdpVcCredentialIssuerMetadata, credentialConfiguration) || zIs(zLdpVcCredentialIssuerMetadataDraft14, credentialConfiguration)) {
918
1070
  return {
919
1071
  format: credentialConfiguration.format,
920
1072
  credential_definition: {
@@ -923,7 +1075,7 @@ function getCredentialRequestFormatPayloadForCredentialConfigurationId(options)
923
1075
  }
924
1076
  };
925
1077
  }
926
- if (zIs(zJwtVcJsonLdCredentialIssuerMetadata, credentialConfiguration)) {
1078
+ if (zIs(zJwtVcJsonLdCredentialIssuerMetadata, credentialConfiguration) || zIs(zJwtVcJsonLdCredentialIssuerMetadataDraft14, credentialConfiguration)) {
927
1079
  return {
928
1080
  format: credentialConfiguration.format,
929
1081
  credential_definition: {
@@ -932,7 +1084,7 @@ function getCredentialRequestFormatPayloadForCredentialConfigurationId(options)
932
1084
  }
933
1085
  };
934
1086
  }
935
- if (zIs(zJwtVcJsonCredentialIssuerMetadata, credentialConfiguration)) {
1087
+ if (zIs(zJwtVcJsonCredentialIssuerMetadata, credentialConfiguration) || zIs(zJwtVcJsonCredentialIssuerMetadataDraft14, credentialConfiguration)) {
936
1088
  return {
937
1089
  format: credentialConfiguration.format,
938
1090
  credential_definition: {
@@ -940,6 +1092,11 @@ function getCredentialRequestFormatPayloadForCredentialConfigurationId(options)
940
1092
  }
941
1093
  };
942
1094
  }
1095
+ if (zIs(zSdJwtDcCredentialIssuerMetadata, credentialConfiguration)) {
1096
+ throw new Openid4vciError(
1097
+ `Credential configuration id '${options.credentialConfigurationId}' with format ${zSdJwtVcFormatIdentifier.value} does not support credential request based on 'format'. Use 'credential_configuration_id' directly.`
1098
+ );
1099
+ }
943
1100
  throw new Openid4vciError(
944
1101
  `Unknown format '${credentialConfiguration.format}' in credential configuration with id '${options.credentialConfigurationId}' for credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
945
1102
  );
@@ -950,36 +1107,36 @@ import {
950
1107
  Oauth2Error as Oauth2Error4,
951
1108
  resourceRequest
952
1109
  } from "@openid4vc/oauth2";
953
- import { ContentType as ContentType2, isResponseContentType, parseWithErrorHandling as parseWithErrorHandling2 } from "@openid4vc/utils";
1110
+ import { ContentType as ContentType2, isResponseContentType, parseWithErrorHandling as parseWithErrorHandling3 } from "@openid4vc/utils";
954
1111
 
955
1112
  // src/credential-request/z-credential-request.ts
956
- import z14 from "zod";
1113
+ import z16 from "zod";
957
1114
 
958
1115
  // src/credential-request/z-credential-request-common.ts
959
1116
  import { zJwk as zJwk2 } from "@openid4vc/oauth2";
960
- import z13 from "zod";
1117
+ import z15 from "zod";
961
1118
 
962
1119
  // src/formats/proof-type/jwt/z-jwt-proof-type.ts
963
1120
  import { zCompactJwt as zCompactJwt2, zJwtHeader as zJwtHeader2, zJwtPayload as zJwtPayload2 } from "@openid4vc/oauth2";
964
1121
  import { zHttpsUrl as zHttpsUrl3, zInteger as zInteger2 } from "@openid4vc/utils";
965
- import z11 from "zod";
966
- var zJwtProofTypeIdentifier = z11.literal("jwt");
1122
+ import z13 from "zod";
1123
+ var zJwtProofTypeIdentifier = z13.literal("jwt");
967
1124
  var jwtProofTypeIdentifier = zJwtProofTypeIdentifier.value;
968
- var zCredentialRequestProofJwt = z11.object({
1125
+ var zCredentialRequestProofJwt = z13.object({
969
1126
  proof_type: zJwtProofTypeIdentifier,
970
1127
  jwt: zCompactJwt2
971
1128
  });
972
1129
  var zCredentialRequestJwtProofTypeHeader = zJwtHeader2.merge(
973
- z11.object({
974
- key_attestation: z11.optional(zCompactJwt2),
975
- typ: z11.literal("openid4vci-proof+jwt")
1130
+ z13.object({
1131
+ key_attestation: z13.optional(zCompactJwt2),
1132
+ typ: z13.literal("openid4vci-proof+jwt")
976
1133
  })
977
1134
  ).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
978
1135
  message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
979
1136
  }).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
980
1137
  message: `When 'trust_chain' is provided, 'kid' is required`
981
1138
  });
982
- var zCredentialRequestJwtProofTypePayload = z11.object({
1139
+ var zCredentialRequestJwtProofTypePayload = z13.object({
983
1140
  ...zJwtPayload2.shape,
984
1141
  aud: zHttpsUrl3,
985
1142
  iat: zInteger2
@@ -987,40 +1144,40 @@ var zCredentialRequestJwtProofTypePayload = z11.object({
987
1144
 
988
1145
  // src/formats/proof-type/attestation/z-attestation-proof-type.ts
989
1146
  import { zCompactJwt as zCompactJwt3 } from "@openid4vc/oauth2";
990
- import z12 from "zod";
991
- var zAttestationProofTypeIdentifier = z12.literal("attestation");
1147
+ import z14 from "zod";
1148
+ var zAttestationProofTypeIdentifier = z14.literal("attestation");
992
1149
  var attestationProofTypeIdentifier = zAttestationProofTypeIdentifier.value;
993
- var zCredentialRequestProofAttestation = z12.object({
1150
+ var zCredentialRequestProofAttestation = z14.object({
994
1151
  proof_type: zAttestationProofTypeIdentifier,
995
1152
  attestation: zCompactJwt3
996
1153
  });
997
1154
  var zCredentialRequestAttestationProofTypePayload = zKeyAttestationJwtPayloadForUse("proof_type.attestation");
998
1155
 
999
1156
  // src/credential-request/z-credential-request-common.ts
1000
- var zCredentialRequestProofCommon = z13.object({
1001
- proof_type: z13.string()
1157
+ var zCredentialRequestProofCommon = z15.object({
1158
+ proof_type: z15.string()
1002
1159
  }).passthrough();
1003
1160
  var allCredentialRequestProofs = [zCredentialRequestProofJwt, zCredentialRequestProofAttestation];
1004
- var zCredentialRequestProof = z13.union([
1161
+ var zCredentialRequestProof = z15.union([
1005
1162
  zCredentialRequestProofCommon,
1006
- z13.discriminatedUnion("proof_type", allCredentialRequestProofs)
1163
+ z15.discriminatedUnion("proof_type", allCredentialRequestProofs)
1007
1164
  ]);
1008
- var zCredentialRequestProofsCommon = z13.record(z13.string(), z13.array(z13.unknown()));
1009
- var zCredentialRequestProofs = z13.object({
1010
- [zJwtProofTypeIdentifier.value]: z13.optional(z13.array(zCredentialRequestProofJwt.shape.jwt)),
1011
- [zAttestationProofTypeIdentifier.value]: z13.optional(z13.array(zCredentialRequestProofAttestation.shape.attestation))
1165
+ var zCredentialRequestProofsCommon = z15.record(z15.string(), z15.array(z15.unknown()));
1166
+ var zCredentialRequestProofs = z15.object({
1167
+ [zJwtProofTypeIdentifier.value]: z15.optional(z15.array(zCredentialRequestProofJwt.shape.jwt)),
1168
+ [zAttestationProofTypeIdentifier.value]: z15.optional(z15.array(zCredentialRequestProofAttestation.shape.attestation))
1012
1169
  });
1013
- var zCredentialRequestCommon = z13.object({
1170
+ var zCredentialRequestCommon = z15.object({
1014
1171
  proof: zCredentialRequestProof.optional(),
1015
- proofs: z13.optional(
1016
- z13.intersection(zCredentialRequestProofsCommon, zCredentialRequestProofs).refine((proofs) => Object.values(proofs).length === 1, {
1172
+ proofs: z15.optional(
1173
+ z15.intersection(zCredentialRequestProofsCommon, zCredentialRequestProofs).refine((proofs) => Object.values(proofs).length === 1, {
1017
1174
  message: `The 'proofs' object in a credential request should contain exactly one attribute`
1018
1175
  })
1019
1176
  ),
1020
- credential_response_encryption: z13.object({
1177
+ credential_response_encryption: z15.object({
1021
1178
  jwk: zJwk2,
1022
- alg: z13.string(),
1023
- enc: z13.string()
1179
+ alg: z15.string(),
1180
+ enc: z15.string()
1024
1181
  }).passthrough().optional()
1025
1182
  }).passthrough().refine(({ proof, proofs }) => !(proof !== void 0 && proofs !== void 0), {
1026
1183
  message: `Both 'proof' and 'proofs' are defined. Only one is allowed`
@@ -1028,40 +1185,54 @@ var zCredentialRequestCommon = z13.object({
1028
1185
 
1029
1186
  // src/credential-request/z-credential-request.ts
1030
1187
  var allCredentialRequestFormats = [
1031
- zSdJwtVcCredentialRequestFormat,
1032
- zMsoMdocCredentialRequestFormat,
1033
- zLdpVcCredentialRequestFormat,
1034
- zJwtVcJsonLdCredentialRequestFormat,
1035
- zJwtVcJsonCredentialRequestFormat
1188
+ zSdJwtVcCredentialRequestFormatDraft14,
1189
+ zMsoMdocCredentialRequestFormatDraft14,
1190
+ zLdpVcCredentialRequestFormatDraft14,
1191
+ zJwtVcJsonLdCredentialRequestFormatDraft14,
1192
+ zJwtVcJsonCredentialRequestFormatDraft14
1036
1193
  ];
1037
1194
  var allCredentialRequestFormatIdentifiers = allCredentialRequestFormats.map(
1038
1195
  (format) => format.shape.format.value
1039
1196
  );
1040
- var zAuthorizationDetailsCredentialRequest = z14.object({
1041
- credential_identifier: z14.string(),
1197
+ var zCredentialRequestCredentialConfigurationId = z16.object({
1198
+ credential_configuration_id: z16.string(),
1199
+ format: z16.never({ message: "'format' cannot be defined when 'credential_configuration_id' is set." }).optional(),
1200
+ credential_identifier: z16.never({ message: "'credential_identifier' cannot be defined when 'credential_configuration_id' is set." }).optional()
1201
+ });
1202
+ var zAuthorizationDetailsCredentialRequest = z16.object({
1203
+ credential_identifier: z16.string(),
1204
+ credential_configuration_id: z16.never({ message: "'credential_configuration_id' cannot be defined when 'credential_identifier' is set." }).optional(),
1042
1205
  // Cannot be present if credential identifier is present
1043
- format: z14.never({ message: "'format' cannot be defined when 'credential_identifier' is set." }).optional()
1206
+ format: z16.never({ message: "'format' cannot be defined when 'credential_identifier' is set." }).optional()
1044
1207
  });
1045
- var zCredentialRequestFormatNoCredentialIdentifier = z14.object({
1046
- format: z14.string(),
1047
- credential_identifier: z14.never({ message: "'credential_identifier' cannot be defined when 'format' is set." }).optional()
1208
+ var zCredentialRequestFormat = z16.object({
1209
+ format: z16.string(),
1210
+ credential_identifier: z16.never({ message: "'credential_identifier' cannot be defined when 'format' is set." }).optional(),
1211
+ credential_configuration_id: z16.never({ message: "'credential_configuration_id' cannot be defined when 'format' is set." }).optional()
1048
1212
  }).passthrough();
1049
- var zCredenialRequestDraft14WithFormat = zCredentialRequestCommon.and(zCredentialRequestFormatNoCredentialIdentifier).transform((data, ctx) => {
1050
- if (!allCredentialRequestFormatIdentifiers.includes(data.format)) return data;
1051
- const result = z14.object({}).passthrough().and(z14.discriminatedUnion("format", allCredentialRequestFormats)).safeParse(data);
1213
+ var zCredenialRequestDraft14WithFormat = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1214
+ if (!allCredentialRequestFormatIdentifiers.includes(
1215
+ data.format
1216
+ ))
1217
+ return data;
1218
+ const result = z16.object({}).passthrough().and(z16.discriminatedUnion("format", allCredentialRequestFormats)).safeParse(data);
1052
1219
  if (result.success) {
1053
1220
  return result.data;
1054
1221
  }
1055
1222
  for (const issue of result.error.issues) {
1056
1223
  ctx.addIssue(issue);
1057
1224
  }
1058
- return z14.NEVER;
1225
+ return z16.NEVER;
1059
1226
  });
1060
- var zCredentialRequestDraft14 = z14.union([
1227
+ var zCredentialRequestDraft15 = z16.union([
1228
+ zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest),
1229
+ zCredentialRequestCommon.and(zCredentialRequestCredentialConfigurationId)
1230
+ ]);
1231
+ var zCredentialRequestDraft14 = z16.union([
1061
1232
  zCredenialRequestDraft14WithFormat,
1062
1233
  zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest)
1063
1234
  ]);
1064
- var zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRequestFormatNoCredentialIdentifier).transform((data, ctx) => {
1235
+ var zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1065
1236
  const formatSpecificTransformations = {
1066
1237
  [zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft11To14,
1067
1238
  [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft11To14,
@@ -1074,7 +1245,7 @@ var zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRequ
1074
1245
  for (const issue of result.error.issues) {
1075
1246
  ctx.addIssue(issue);
1076
1247
  }
1077
- return z14.NEVER;
1248
+ return z16.NEVER;
1078
1249
  }).pipe(zCredentialRequestDraft14);
1079
1250
  var zCredentialRequestDraft14To11 = zCredentialRequestDraft14.refine(
1080
1251
  (data) => data.credential_identifier === void 0,
@@ -1092,15 +1263,19 @@ var zCredentialRequestDraft14To11 = zCredentialRequestDraft14.refine(
1092
1263
  for (const issue of result.error.issues) {
1093
1264
  ctx.addIssue(issue);
1094
1265
  }
1095
- return z14.NEVER;
1266
+ return z16.NEVER;
1096
1267
  });
1097
- var zCredentialRequest = z14.union([zCredentialRequestDraft14, zCredentialRequestDraft11To14]);
1268
+ var zCredentialRequest = z16.union([
1269
+ zCredentialRequestDraft15,
1270
+ zCredentialRequestDraft14,
1271
+ zCredentialRequestDraft11To14
1272
+ ]);
1098
1273
 
1099
1274
  // src/credential-request/z-credential-response.ts
1100
- import z16 from "zod";
1275
+ import z18 from "zod";
1101
1276
 
1102
1277
  // ../oauth2/src/common/z-oauth2-error.ts
1103
- import z15 from "zod";
1278
+ import z17 from "zod";
1104
1279
  var Oauth2ErrorCodes = /* @__PURE__ */ ((Oauth2ErrorCodes4) => {
1105
1280
  Oauth2ErrorCodes4["ServerError"] = "server_error";
1106
1281
  Oauth2ErrorCodes4["InvalidTarget"] = "invalid_target";
@@ -1137,21 +1312,21 @@ var Oauth2ErrorCodes = /* @__PURE__ */ ((Oauth2ErrorCodes4) => {
1137
1312
  Oauth2ErrorCodes4["WalletUnavailable"] = "wallet_unavailable";
1138
1313
  return Oauth2ErrorCodes4;
1139
1314
  })(Oauth2ErrorCodes || {});
1140
- var zOauth2ErrorResponse = z15.object({
1141
- error: z15.union([z15.nativeEnum(Oauth2ErrorCodes), z15.string()]),
1142
- error_description: z15.string().optional(),
1143
- error_uri: z15.string().optional()
1315
+ var zOauth2ErrorResponse = z17.object({
1316
+ error: z17.union([z17.nativeEnum(Oauth2ErrorCodes), z17.string()]),
1317
+ error_description: z17.string().optional(),
1318
+ error_uri: z17.string().optional()
1144
1319
  }).passthrough();
1145
1320
 
1146
1321
  // src/credential-request/z-credential-response.ts
1147
- var zCredentialEncoding = z16.union([z16.string(), z16.record(z16.string(), z16.any())]);
1148
- var zCredentialResponse = z16.object({
1149
- credential: z16.optional(zCredentialEncoding),
1150
- credentials: z16.optional(z16.array(zCredentialEncoding)),
1151
- transaction_id: z16.string().optional(),
1152
- c_nonce: z16.string().optional(),
1153
- c_nonce_expires_in: z16.number().int().optional(),
1154
- notification_id: z16.string().optional()
1322
+ var zCredentialEncoding = z18.union([z18.string(), z18.record(z18.string(), z18.any())]);
1323
+ var zCredentialResponse = z18.object({
1324
+ credential: z18.optional(zCredentialEncoding),
1325
+ credentials: z18.optional(z18.array(zCredentialEncoding)),
1326
+ transaction_id: z18.string().optional(),
1327
+ c_nonce: z18.string().optional(),
1328
+ c_nonce_expires_in: z18.number().int().optional(),
1329
+ notification_id: z18.string().optional()
1155
1330
  }).passthrough().refine(
1156
1331
  (value) => {
1157
1332
  const { credential, credentials, transaction_id } = value;
@@ -1161,14 +1336,43 @@ var zCredentialResponse = z16.object({
1161
1336
  message: `Exactly one of 'credential', 'credentials', or 'transaction_id' MUST be defined.`
1162
1337
  }
1163
1338
  );
1164
- var zCredentialErrorResponse = z16.object({
1339
+ var zCredentialErrorResponse = z18.object({
1165
1340
  ...zOauth2ErrorResponse.shape,
1166
- c_nonce: z16.string().optional(),
1167
- c_nonce_expires_in: z16.number().int().optional()
1341
+ c_nonce: z18.string().optional(),
1342
+ c_nonce_expires_in: z18.number().int().optional()
1168
1343
  }).passthrough();
1169
1344
 
1170
1345
  // src/credential-request/retrieve-credentials.ts
1346
+ async function retrieveCredentialsWithCredentialConfigurationId(options) {
1347
+ if (options.issuerMetadata.originalDraftVersion !== "Draft15" /* Draft15 */) {
1348
+ throw new Openid4vciError(
1349
+ "Requesting credentials based on format is not supported in OpenID4VCI below draft 15. Make sure to provide the format and format specific claims in the request."
1350
+ );
1351
+ }
1352
+ getCredentialConfigurationSupportedById(
1353
+ options.issuerMetadata.credentialIssuer.credential_configurations_supported,
1354
+ options.credentialConfigurationId
1355
+ );
1356
+ const credentialRequest = {
1357
+ ...options.additionalRequestPayload,
1358
+ credential_configuration_id: options.credentialConfigurationId,
1359
+ proof: options.proof,
1360
+ proofs: options.proofs
1361
+ };
1362
+ return retrieveCredentials({
1363
+ callbacks: options.callbacks,
1364
+ credentialRequest,
1365
+ issuerMetadata: options.issuerMetadata,
1366
+ accessToken: options.accessToken,
1367
+ dpop: options.dpop
1368
+ });
1369
+ }
1171
1370
  async function retrieveCredentialsWithFormat(options) {
1371
+ if (options.issuerMetadata.originalDraftVersion === "Draft15" /* Draft15 */) {
1372
+ throw new Openid4vciError(
1373
+ "Requesting credentials based on format is not supported in OpenID4VCI draft 15. Provide the credential configuration id directly in the request."
1374
+ );
1375
+ }
1172
1376
  const credentialRequest = {
1173
1377
  ...options.formatPayload,
1174
1378
  ...options.additionalRequestPayload,
@@ -1185,7 +1389,7 @@ async function retrieveCredentialsWithFormat(options) {
1185
1389
  }
1186
1390
  async function retrieveCredentials(options) {
1187
1391
  const credentialEndpoint = options.issuerMetadata.credentialIssuer.credential_endpoint;
1188
- let credentialRequest = parseWithErrorHandling2(
1392
+ let credentialRequest = parseWithErrorHandling3(
1189
1393
  zCredentialRequest,
1190
1394
  options.credentialRequest,
1191
1395
  "Error validating credential request"
@@ -1205,7 +1409,7 @@ async function retrieveCredentials(options) {
1205
1409
  }
1206
1410
  }
1207
1411
  if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
1208
- credentialRequest = parseWithErrorHandling2(
1412
+ credentialRequest = parseWithErrorHandling3(
1209
1413
  zCredentialRequestDraft14To11,
1210
1414
  credentialRequest,
1211
1415
  `Error transforming credential request from ${"Draft14" /* Draft14 */} to ${"Draft11" /* Draft11 */}`
@@ -1249,39 +1453,6 @@ async function retrieveCredentials(options) {
1249
1453
  import { decodeJwt as decodeJwt2, isJwkInSet, jwtHeaderFromJwtSigner as jwtHeaderFromJwtSigner2 } from "@openid4vc/oauth2";
1250
1454
  import { jwtSignerFromJwt as jwtSignerFromJwt2, verifyJwt as verifyJwt2 } from "@openid4vc/oauth2";
1251
1455
  import { dateToSeconds as dateToSeconds2, parseWithErrorHandling as parseWithErrorHandling4 } from "@openid4vc/utils";
1252
-
1253
- // src/key-attestation/key-attestation.ts
1254
- import { decodeJwt, jwtHeaderFromJwtSigner } from "@openid4vc/oauth2";
1255
- import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
1256
- import { dateToSeconds, parseWithErrorHandling as parseWithErrorHandling3 } from "@openid4vc/utils";
1257
- async function verifyKeyAttestationJwt(options) {
1258
- const { header, payload } = decodeJwt({
1259
- jwt: options.keyAttestationJwt,
1260
- headerSchema: zKeyAttestationJwtHeader,
1261
- payloadSchema: zKeyAttestationJwtPayloadForUse(options.use)
1262
- });
1263
- const now = options.now?.getTime() ?? Date.now();
1264
- if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
1265
- throw new Openid4vciError("Nonce used for key attestation jwt expired");
1266
- }
1267
- const { signer } = await verifyJwt({
1268
- compact: options.keyAttestationJwt,
1269
- header,
1270
- payload,
1271
- signer: jwtSignerFromJwt({ header, payload }),
1272
- verifyJwtCallback: options.callbacks.verifyJwt,
1273
- errorMessage: "Error verifiying key attestation jwt",
1274
- expectedNonce: options.expectedNonce,
1275
- now: options.now
1276
- });
1277
- return {
1278
- header,
1279
- payload,
1280
- signer
1281
- };
1282
- }
1283
-
1284
- // src/formats/proof-type/jwt/jwt-proof-type.ts
1285
1456
  async function createCredentialRequestJwtProof(options) {
1286
1457
  const header = parseWithErrorHandling4(zCredentialRequestJwtProofTypeHeader, {
1287
1458
  ...jwtHeaderFromJwtSigner2(options.signer),
@@ -1413,10 +1584,10 @@ import { ContentType as ContentType3, ValidationError as ValidationError3, creat
1413
1584
 
1414
1585
  // src/nonce/z-nonce.ts
1415
1586
  import { zInteger as zInteger3 } from "@openid4vc/utils";
1416
- import z17 from "zod";
1417
- var zNonceResponse = z17.object({
1418
- c_nonce: z17.string(),
1419
- c_nonce_expires_in: z17.optional(zInteger3)
1587
+ import z19 from "zod";
1588
+ var zNonceResponse = z19.object({
1589
+ c_nonce: z19.string(),
1590
+ c_nonce_expires_in: z19.optional(zInteger3)
1420
1591
  }).passthrough();
1421
1592
 
1422
1593
  // src/nonce/nonce-request.ts
@@ -1459,15 +1630,15 @@ import {
1459
1630
  import { ContentType as ContentType4, isResponseContentType as isResponseContentType2, parseWithErrorHandling as parseWithErrorHandling7 } from "@openid4vc/utils";
1460
1631
 
1461
1632
  // src/notification/z-notification.ts
1462
- import z18 from "zod";
1463
- var zNotificationEvent = z18.enum(["credential_accepted", "credential_failure", "credential_deleted"]);
1464
- var zNotificationRequest = z18.object({
1465
- notification_id: z18.string(),
1633
+ import z20 from "zod";
1634
+ var zNotificationEvent = z20.enum(["credential_accepted", "credential_failure", "credential_deleted"]);
1635
+ var zNotificationRequest = z20.object({
1636
+ notification_id: z20.string(),
1466
1637
  event: zNotificationEvent,
1467
- event_description: z18.optional(z18.string())
1638
+ event_description: z20.optional(z20.string())
1468
1639
  }).passthrough();
1469
- var zNotificationErrorResponse = z18.object({
1470
- error: z18.enum(["invalid_notification_id", "invalid_notification_request"])
1640
+ var zNotificationErrorResponse = z20.object({
1641
+ error: z20.enum(["invalid_notification_id", "invalid_notification_request"])
1471
1642
  }).passthrough();
1472
1643
 
1473
1644
  // src/notification/notification.ts
@@ -1610,7 +1781,6 @@ var Openid4vciClient = class {
1610
1781
  issuer_state: options.credentialOffer?.grants?.authorization_code?.issuer_state
1611
1782
  },
1612
1783
  dpop: options.dpop,
1613
- clientAttestation: options.clientAttestation,
1614
1784
  resource: options.issuerMetadata.credentialIssuer.credential_issuer,
1615
1785
  authorizationServerMetadata
1616
1786
  });
@@ -1664,7 +1834,6 @@ var Openid4vciClient = class {
1664
1834
  redirectUri: options.redirectUri,
1665
1835
  scope: options.scope,
1666
1836
  pkceCodeVerifier: options.pkceCodeVerifier,
1667
- clientAttestation: options.clientAttestation,
1668
1837
  dpop: options.dpop
1669
1838
  });
1670
1839
  return {
@@ -1683,8 +1852,7 @@ var Openid4vciClient = class {
1683
1852
  issuerMetadata,
1684
1853
  additionalRequestPayload,
1685
1854
  txCode,
1686
- dpop,
1687
- clientAttestation
1855
+ dpop
1688
1856
  }) {
1689
1857
  if (!credentialOffer.grants?.[preAuthorizedCodeGrantIdentifier3]) {
1690
1858
  throw new Oauth2Error7(`The credential offer does not contain the '${preAuthorizedCodeGrantIdentifier3}' grant.`);
@@ -1709,8 +1877,7 @@ var Openid4vciClient = class {
1709
1877
  txCode,
1710
1878
  resource: issuerMetadata.credentialIssuer.credential_issuer,
1711
1879
  additionalRequestPayload,
1712
- dpop,
1713
- clientAttestation
1880
+ dpop
1714
1881
  });
1715
1882
  return {
1716
1883
  ...result,
@@ -1728,8 +1895,7 @@ var Openid4vciClient = class {
1728
1895
  authorizationCode,
1729
1896
  pkceCodeVerifier,
1730
1897
  redirectUri,
1731
- dpop,
1732
- clientAttestation
1898
+ dpop
1733
1899
  }) {
1734
1900
  if (!credentialOffer.grants?.[authorizationCodeGrantIdentifier2]) {
1735
1901
  throw new Oauth2Error7(`The credential offer does not contain the '${authorizationCodeGrantIdentifier2}' grant.`);
@@ -1748,7 +1914,6 @@ var Openid4vciClient = class {
1748
1914
  pkceCodeVerifier,
1749
1915
  additionalRequestPayload,
1750
1916
  dpop,
1751
- clientAttestation,
1752
1917
  redirectUri,
1753
1918
  resource: issuerMetadata.credentialIssuer.credential_issuer
1754
1919
  });
@@ -1826,20 +1991,34 @@ var Openid4vciClient = class {
1826
1991
  accessToken,
1827
1992
  dpop
1828
1993
  }) {
1829
- const formatPayload = getCredentialRequestFormatPayloadForCredentialConfigurationId({
1830
- credentialConfigurationId,
1831
- issuerMetadata
1832
- });
1833
- const credentialResponse = await retrieveCredentialsWithFormat({
1834
- accessToken,
1835
- formatPayload,
1836
- issuerMetadata,
1837
- additionalRequestPayload,
1838
- proof,
1839
- proofs,
1840
- callbacks: this.options.callbacks,
1841
- dpop
1842
- });
1994
+ let credentialResponse;
1995
+ if (issuerMetadata.originalDraftVersion === "Draft15" /* Draft15 */) {
1996
+ credentialResponse = await retrieveCredentialsWithCredentialConfigurationId({
1997
+ accessToken,
1998
+ credentialConfigurationId,
1999
+ issuerMetadata,
2000
+ additionalRequestPayload,
2001
+ proof,
2002
+ proofs,
2003
+ callbacks: this.options.callbacks,
2004
+ dpop
2005
+ });
2006
+ } else {
2007
+ const formatPayload = getCredentialRequestFormatPayloadForCredentialConfigurationId({
2008
+ credentialConfigurationId,
2009
+ issuerMetadata
2010
+ });
2011
+ credentialResponse = await retrieveCredentialsWithFormat({
2012
+ accessToken,
2013
+ formatPayload,
2014
+ issuerMetadata,
2015
+ additionalRequestPayload,
2016
+ proof,
2017
+ proofs,
2018
+ callbacks: this.options.callbacks,
2019
+ dpop
2020
+ });
2021
+ }
1843
2022
  if (!credentialResponse.ok) {
1844
2023
  throw new Openid4vciRetrieveCredentialsError(
1845
2024
  `Error retrieving credentials from '${issuerMetadata.credentialIssuer.credential_issuer}'`,
@@ -1880,6 +2059,7 @@ var Openid4vciClient = class {
1880
2059
 
1881
2060
  // src/Openid4vciIssuer.ts
1882
2061
  import {
2062
+ Oauth2AuthorizationServer,
1883
2063
  Oauth2ErrorCodes as Oauth2ErrorCodes3,
1884
2064
  Oauth2JwtVerificationError,
1885
2065
  Oauth2ServerErrorResponseError
@@ -1905,7 +2085,7 @@ function createCredentialResponse(options) {
1905
2085
 
1906
2086
  // src/credential-request/parse-credential-request.ts
1907
2087
  import { parseWithErrorHandling as parseWithErrorHandling9 } from "@openid4vc/utils";
1908
- import z19 from "zod";
2088
+ import z21 from "zod";
1909
2089
  function parseCredentialRequest(options) {
1910
2090
  const credentialRequest = parseWithErrorHandling9(
1911
2091
  zCredentialRequest,
@@ -1917,12 +2097,27 @@ function parseCredentialRequest(options) {
1917
2097
  if (knownProofs.success) {
1918
2098
  proofs = knownProofs.data;
1919
2099
  }
1920
- const knownProof = z19.union(allCredentialRequestProofs).safeParse(credentialRequest.proof);
2100
+ const knownProof = z21.union(allCredentialRequestProofs).safeParse(credentialRequest.proof);
1921
2101
  if (knownProof.success && knownProof.data.proof_type === jwtProofTypeIdentifier) {
1922
2102
  proofs = { [jwtProofTypeIdentifier]: [knownProof.data.jwt] };
1923
2103
  } else if (knownProof.success && knownProof.data.proof_type === attestationProofTypeIdentifier) {
1924
2104
  proofs = { [attestationProofTypeIdentifier]: [knownProof.data.attestation] };
1925
2105
  }
2106
+ if (credentialRequest.credential_configuration_id) {
2107
+ getCredentialConfigurationSupportedById(
2108
+ options.issuerMetadata.credentialIssuer.credential_configurations_supported,
2109
+ credentialRequest.credential_configuration_id
2110
+ );
2111
+ const credentialConfigurations = extractKnownCredentialConfigurationSupportedFormats(
2112
+ options.issuerMetadata.credentialIssuer.credential_configurations_supported
2113
+ );
2114
+ return {
2115
+ credentialConfiguration: credentialConfigurations[credentialRequest.credential_configuration_id],
2116
+ credentialConfigurationId: credentialRequest.credential_configuration_id,
2117
+ credentialRequest,
2118
+ proofs
2119
+ };
2120
+ }
1926
2121
  if (credentialRequest.credential_identifier) {
1927
2122
  return {
1928
2123
  credentialIdentifier: credentialRequest.credential_identifier,
@@ -1930,11 +2125,13 @@ function parseCredentialRequest(options) {
1930
2125
  proofs
1931
2126
  };
1932
2127
  }
1933
- if (credentialRequest.format && allCredentialRequestFormatIdentifiers.includes(credentialRequest.format)) {
2128
+ if (credentialRequest.format && allCredentialRequestFormatIdentifiers.includes(
2129
+ credentialRequest.format
2130
+ )) {
1934
2131
  return {
1935
2132
  // Removes all claims that are not specific to this format
1936
2133
  format: parseWithErrorHandling9(
1937
- z19.union(allCredentialRequestFormats),
2134
+ z21.union(allCredentialRequestFormats),
1938
2135
  credentialRequest,
1939
2136
  "Unable to validate format specific properties from credential request"
1940
2137
  ),
@@ -2086,6 +2283,42 @@ var Openid4vciIssuer = class {
2086
2283
  createNonceResponse(options) {
2087
2284
  return createNonceResponse(options);
2088
2285
  }
2286
+ async verifyWalletAttestation(options) {
2287
+ return new Oauth2AuthorizationServer({
2288
+ callbacks: this.options.callbacks
2289
+ }).verifyClientAttestation(options);
2290
+ }
2291
+ };
2292
+
2293
+ // src/Openid4vciWalletProvider.ts
2294
+ import {
2295
+ createClientAttestationJwt
2296
+ } from "@openid4vc/oauth2";
2297
+ var Openid4vciWalletProvider = class {
2298
+ constructor(options) {
2299
+ this.options = options;
2300
+ }
2301
+ async createWalletAttestationJwt(options) {
2302
+ const additionalPayload = options.additionalPayload ? {
2303
+ wallet_name: options.walletName,
2304
+ wallet_link: options.walletLink,
2305
+ ...options.additionalPayload
2306
+ } : {
2307
+ wallet_name: options.walletName,
2308
+ wallet_link: options.walletLink
2309
+ };
2310
+ return await createClientAttestationJwt({
2311
+ ...options,
2312
+ callbacks: this.options.callbacks,
2313
+ additionalPayload
2314
+ });
2315
+ }
2316
+ async createKeyAttestationJwt(options) {
2317
+ return await createKeyAttestationJwt({
2318
+ callbacks: this.options.callbacks,
2319
+ ...options
2320
+ });
2321
+ }
2089
2322
  };
2090
2323
  export {
2091
2324
  AuthorizationFlow,
@@ -2095,10 +2328,15 @@ export {
2095
2328
  Openid4vciIssuer,
2096
2329
  Openid4vciRetrieveCredentialsError,
2097
2330
  Openid4vciSendNotificationError,
2331
+ Openid4vciWalletProvider,
2332
+ createKeyAttestationJwt,
2098
2333
  credentialsSupportedToCredentialConfigurationsSupported,
2334
+ determineAuthorizationServerForCredentialOffer,
2099
2335
  extractScopesForCredentialConfigurationIds,
2100
2336
  getCredentialConfigurationsMatchingRequestFormat,
2101
2337
  getGlobalConfig,
2102
- setGlobalConfig
2338
+ parseKeyAttestationJwt,
2339
+ setGlobalConfig,
2340
+ verifyKeyAttestationJwt
2103
2341
  };
2104
2342
  //# sourceMappingURL=index.mjs.map