@openid4vc/openid4vci 0.3.0-alpha-20251001121503 → 0.3.0-alpha-20251017092354

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.js CHANGED
@@ -1,2642 +1,2011 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
8
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
29
22
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- AuthorizationFlow: () => AuthorizationFlow,
34
- Openid4vciClient: () => Openid4vciClient,
35
- Openid4vciDraftVersion: () => Openid4vciDraftVersion,
36
- Openid4vciError: () => Openid4vciError,
37
- Openid4vciIssuer: () => Openid4vciIssuer,
38
- Openid4vciRetrieveCredentialsError: () => Openid4vciRetrieveCredentialsError,
39
- Openid4vciSendNotificationError: () => Openid4vciSendNotificationError,
40
- Openid4vciWalletProvider: () => Openid4vciWalletProvider,
41
- createKeyAttestationJwt: () => createKeyAttestationJwt,
42
- credentialsSupportedToCredentialConfigurationsSupported: () => credentialsSupportedToCredentialConfigurationsSupported,
43
- determineAuthorizationServerForCredentialOffer: () => determineAuthorizationServerForCredentialOffer,
44
- extractScopesForCredentialConfigurationIds: () => extractScopesForCredentialConfigurationIds,
45
- getCredentialConfigurationsMatchingRequestFormat: () => getCredentialConfigurationsMatchingRequestFormat,
46
- getGlobalConfig: () => import_utils22.getGlobalConfig,
47
- parseKeyAttestationJwt: () => parseKeyAttestationJwt,
48
- setGlobalConfig: () => import_utils22.setGlobalConfig,
49
- verifyKeyAttestationJwt: () => verifyKeyAttestationJwt
50
- });
51
- module.exports = __toCommonJS(index_exports);
23
+ //#endregion
24
+ let __openid4vc_utils = require("@openid4vc/utils");
25
+ __openid4vc_utils = __toESM(__openid4vc_utils);
26
+ let __openid4vc_oauth2 = require("@openid4vc/oauth2");
27
+ __openid4vc_oauth2 = __toESM(__openid4vc_oauth2);
28
+ let zod = require("zod");
29
+ zod = __toESM(zod);
52
30
 
53
- // src/credential-offer/credential-offer.ts
54
- var import_oauth22 = require("@openid4vc/oauth2");
55
- var import_utils2 = require("@openid4vc/utils");
31
+ //#region src/version.ts
32
+ let Openid4vciDraftVersion = /* @__PURE__ */ function(Openid4vciDraftVersion$1) {
33
+ Openid4vciDraftVersion$1["Draft16"] = "Draft16";
34
+ Openid4vciDraftVersion$1["Draft15"] = "Draft15";
35
+ Openid4vciDraftVersion$1["Draft14"] = "Draft14";
36
+ Openid4vciDraftVersion$1["Draft11"] = "Draft11";
37
+ return Openid4vciDraftVersion$1;
38
+ }({});
56
39
 
57
- // src/version.ts
58
- var Openid4vciDraftVersion = /* @__PURE__ */ ((Openid4vciDraftVersion2) => {
59
- Openid4vciDraftVersion2["Draft16"] = "Draft16";
60
- Openid4vciDraftVersion2["Draft15"] = "Draft15";
61
- Openid4vciDraftVersion2["Draft14"] = "Draft14";
62
- Openid4vciDraftVersion2["Draft11"] = "Draft11";
63
- return Openid4vciDraftVersion2;
64
- })(Openid4vciDraftVersion || {});
65
-
66
- // src/credential-offer/z-credential-offer.ts
67
- var import_oauth2 = require("@openid4vc/oauth2");
68
- var import_utils = require("@openid4vc/utils");
69
- var import_zod = __toESM(require("zod"));
70
- var zTxCode = import_zod.default.object({
71
- input_mode: import_zod.default.union([import_zod.default.literal("numeric"), import_zod.default.literal("text")]).optional(),
72
- length: import_zod.default.number().int().optional(),
73
- description: import_zod.default.string().max(300).optional()
40
+ //#endregion
41
+ //#region src/credential-offer/z-credential-offer.ts
42
+ const zTxCode = zod.default.object({
43
+ input_mode: zod.default.union([zod.default.literal("numeric"), zod.default.literal("text")]).optional(),
44
+ length: zod.default.number().int().optional(),
45
+ description: zod.default.string().max(300).optional()
74
46
  }).passthrough();
75
- var zCredentialOfferGrants = import_zod.default.object({
76
- authorization_code: import_zod.default.object({
77
- issuer_state: import_zod.default.string().optional(),
78
- authorization_server: import_utils.zHttpsUrl.optional()
79
- }).passthrough().optional(),
80
- [import_oauth2.preAuthorizedCodeGrantIdentifier]: import_zod.default.object({
81
- "pre-authorized_code": import_zod.default.string(),
82
- tx_code: zTxCode.optional(),
83
- authorization_server: import_utils.zHttpsUrl.optional()
84
- }).passthrough().optional()
47
+ const zCredentialOfferGrants = zod.default.object({
48
+ authorization_code: zod.default.object({
49
+ issuer_state: zod.default.string().optional(),
50
+ authorization_server: __openid4vc_utils.zHttpsUrl.optional()
51
+ }).passthrough().optional(),
52
+ [__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]: zod.default.object({
53
+ "pre-authorized_code": zod.default.string(),
54
+ tx_code: zTxCode.optional(),
55
+ authorization_server: __openid4vc_utils.zHttpsUrl.optional()
56
+ }).passthrough().optional()
85
57
  }).passthrough();
86
- var zCredentialOfferObjectDraft14 = import_zod.default.object({
87
- credential_issuer: import_utils.zHttpsUrl,
88
- credential_configuration_ids: import_zod.default.array(import_zod.default.string()),
89
- grants: import_zod.default.optional(zCredentialOfferGrants)
58
+ const zCredentialOfferObjectDraft14 = zod.default.object({
59
+ credential_issuer: __openid4vc_utils.zHttpsUrl,
60
+ credential_configuration_ids: zod.default.array(zod.default.string()),
61
+ grants: zod.default.optional(zCredentialOfferGrants)
90
62
  }).passthrough();
91
- var zCredentialOfferObjectDraft11To14 = import_zod.default.object({
92
- credential_issuer: import_utils.zHttpsUrl,
93
- // We don't support the inline offer objects from draft 11
94
- credentials: import_zod.default.array(
95
- import_zod.default.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })
96
- ),
97
- grants: import_zod.default.optional(
98
- import_zod.default.object({
99
- // Has extra param in draft 14, but doesn't matter for transform purposes
100
- authorization_code: zCredentialOfferGrants.shape.authorization_code,
101
- [import_oauth2.preAuthorizedCodeGrantIdentifier]: import_zod.default.object({
102
- "pre-authorized_code": import_zod.default.string(),
103
- user_pin_required: import_zod.default.optional(import_zod.default.boolean())
104
- }).passthrough().optional()
105
- })
106
- )
107
- }).passthrough().transform(({ credentials, grants, ...rest }) => {
108
- const v14 = {
109
- ...rest,
110
- credential_configuration_ids: credentials
111
- };
112
- if (grants) {
113
- v14.grants = { ...grants };
114
- if (grants[import_oauth2.preAuthorizedCodeGrantIdentifier]) {
115
- const { user_pin_required, ...restGrants } = grants[import_oauth2.preAuthorizedCodeGrantIdentifier];
116
- v14.grants[import_oauth2.preAuthorizedCodeGrantIdentifier] = {
117
- ...restGrants
118
- };
119
- if (user_pin_required) {
120
- v14.grants[import_oauth2.preAuthorizedCodeGrantIdentifier].tx_code = {
121
- input_mode: "text"
122
- };
123
- }
124
- }
125
- }
126
- return v14;
63
+ const zCredentialOfferObjectDraft11To14 = zod.default.object({
64
+ credential_issuer: __openid4vc_utils.zHttpsUrl,
65
+ credentials: zod.default.array(zod.default.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })),
66
+ grants: zod.default.optional(zod.default.object({
67
+ authorization_code: zCredentialOfferGrants.shape.authorization_code,
68
+ [__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]: zod.default.object({
69
+ "pre-authorized_code": zod.default.string(),
70
+ user_pin_required: zod.default.optional(zod.default.boolean())
71
+ }).passthrough().optional()
72
+ }))
73
+ }).passthrough().transform(({ credentials, grants,...rest }) => {
74
+ const v14 = {
75
+ ...rest,
76
+ credential_configuration_ids: credentials
77
+ };
78
+ if (grants) {
79
+ v14.grants = { ...grants };
80
+ if (grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]) {
81
+ const { user_pin_required,...restGrants } = grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier];
82
+ v14.grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier] = { ...restGrants };
83
+ if (user_pin_required) v14.grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier].tx_code = { input_mode: "text" };
84
+ }
85
+ }
86
+ return v14;
127
87
  }).pipe(zCredentialOfferObjectDraft14);
128
- var zCredentialOfferObject = import_zod.default.union([
129
- // First prioritize draft 14 (and 13)
130
- zCredentialOfferObjectDraft14,
131
- // Then try parsing draft 11 and transform into draft 14
132
- zCredentialOfferObjectDraft11To14
133
- ]);
88
+ const zCredentialOfferObject = zod.default.union([zCredentialOfferObjectDraft14, zCredentialOfferObjectDraft11To14]);
134
89
 
135
- // src/credential-offer/credential-offer.ts
90
+ //#endregion
91
+ //#region src/credential-offer/credential-offer.ts
92
+ /**
93
+ * Resolve a credential offer, optionally fetching it if the credential_offer_uri is provided.
94
+ */
136
95
  async function resolveCredentialOffer(credentialOffer, options) {
137
- const parsedQueryParams = (0, import_utils2.getQueryParams)(credentialOffer);
138
- let credentialOfferParseResult;
139
- if (parsedQueryParams.credential_offer_uri) {
140
- const fetchWithZod = (0, import_utils2.createZodFetcher)(options?.fetch);
141
- const { response, result } = await fetchWithZod(
142
- zCredentialOfferObject,
143
- import_utils2.ContentType.Json,
144
- parsedQueryParams.credential_offer_uri
145
- );
146
- if (!response.ok || !result) {
147
- throw new import_oauth22.InvalidFetchResponseError(
148
- `Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccessful response with status '${response.status}'`,
149
- await response.clone().text(),
150
- response
151
- );
152
- }
153
- credentialOfferParseResult = result;
154
- } else if (parsedQueryParams.credential_offer) {
155
- let credentialOfferJson;
156
- try {
157
- credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
158
- } catch (error) {
159
- throw new import_oauth22.Oauth2Error(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
160
- }
161
- credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
162
- } else {
163
- throw new import_oauth22.Oauth2Error(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
164
- }
165
- if (credentialOfferParseResult.error) {
166
- throw new import_utils2.ValidationError(
167
- `Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`,
168
- credentialOfferParseResult.error
169
- );
170
- }
171
- return credentialOfferParseResult.data;
96
+ const parsedQueryParams = (0, __openid4vc_utils.getQueryParams)(credentialOffer);
97
+ let credentialOfferParseResult;
98
+ if (parsedQueryParams.credential_offer_uri) {
99
+ const { response, result } = await (0, __openid4vc_utils.createZodFetcher)(options?.fetch)(zCredentialOfferObject, __openid4vc_utils.ContentType.Json, parsedQueryParams.credential_offer_uri);
100
+ if (!response.ok || !result) throw new __openid4vc_oauth2.InvalidFetchResponseError(`Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccessful response with status '${response.status}'`, await response.clone().text(), response);
101
+ credentialOfferParseResult = result;
102
+ } else if (parsedQueryParams.credential_offer) {
103
+ let credentialOfferJson;
104
+ try {
105
+ credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
106
+ } catch (_error) {
107
+ throw new __openid4vc_oauth2.Oauth2Error(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
108
+ }
109
+ credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
110
+ } else throw new __openid4vc_oauth2.Oauth2Error(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
111
+ if (credentialOfferParseResult.error) throw new __openid4vc_utils.ValidationError(`Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`, credentialOfferParseResult.error);
112
+ return credentialOfferParseResult.data;
172
113
  }
173
114
  function determineAuthorizationServerForCredentialOffer(options) {
174
- const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
175
- let authorizationServer;
176
- if (options.grantAuthorizationServer) {
177
- authorizationServer = options.grantAuthorizationServer;
178
- if (!authorizationServers) {
179
- throw new import_oauth22.Oauth2Error(
180
- `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.`
181
- );
182
- }
183
- if (!authorizationServers.includes(authorizationServer)) {
184
- throw new import_oauth22.Oauth2Error(
185
- `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(", ")}.`
186
- );
187
- }
188
- } else if (!authorizationServers) {
189
- authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
190
- } else {
191
- if (authorizationServers.length === 0) {
192
- throw new import_oauth22.Oauth2Error(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
193
- }
194
- if (authorizationServers.length > 1) {
195
- throw new import_oauth22.Oauth2Error(
196
- `Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`
197
- );
198
- }
199
- authorizationServer = authorizationServers[0];
200
- }
201
- return authorizationServer;
115
+ const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
116
+ let authorizationServer;
117
+ if (options.grantAuthorizationServer) {
118
+ authorizationServer = options.grantAuthorizationServer;
119
+ if (!authorizationServers) throw new __openid4vc_oauth2.Oauth2Error(`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.`);
120
+ if (!authorizationServers.includes(authorizationServer)) throw new __openid4vc_oauth2.Oauth2Error(`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(", ")}.`);
121
+ } else if (!authorizationServers) authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
122
+ else {
123
+ if (authorizationServers.length === 0) throw new __openid4vc_oauth2.Oauth2Error(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
124
+ if (authorizationServers.length > 1) throw new __openid4vc_oauth2.Oauth2Error(`Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`);
125
+ authorizationServer = authorizationServers[0];
126
+ }
127
+ return authorizationServer;
202
128
  }
203
129
  async function createCredentialOffer(options) {
204
- const {
205
- [import_oauth22.preAuthorizedCodeGrantIdentifier]: preAuthorizedCodeGrant,
206
- [import_oauth22.authorizationCodeGrantIdentifier]: authorizationCodeGrant,
207
- ...restGrants
208
- } = options.grants;
209
- const grants = { ...restGrants };
210
- if (authorizationCodeGrant) {
211
- determineAuthorizationServerForCredentialOffer({
212
- issuerMetadata: options.issuerMetadata,
213
- grantAuthorizationServer: authorizationCodeGrant.authorization_server
214
- });
215
- grants[import_oauth22.authorizationCodeGrantIdentifier] = authorizationCodeGrant;
216
- }
217
- if (preAuthorizedCodeGrant) {
218
- determineAuthorizationServerForCredentialOffer({
219
- issuerMetadata: options.issuerMetadata,
220
- grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
221
- });
222
- grants[import_oauth22.preAuthorizedCodeGrantIdentifier] = {
223
- ...preAuthorizedCodeGrant,
224
- "pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? (0, import_utils2.encodeToBase64Url)(await options.callbacks.generateRandom(32))
225
- };
226
- const txCode = grants[import_oauth22.preAuthorizedCodeGrantIdentifier].tx_code;
227
- if (txCode && options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
228
- grants[import_oauth22.preAuthorizedCodeGrantIdentifier].user_pin_required = txCode !== void 0;
229
- }
230
- }
231
- const idsNotInMetadata = options.credentialConfigurationIds.filter(
232
- (id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0
233
- );
234
- if (idsNotInMetadata.length > 0) {
235
- throw new import_oauth22.Oauth2Error(
236
- `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(", ")}.`
237
- );
238
- }
239
- const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
240
- const credentialOfferObject = (0, import_utils2.parseWithErrorHandling)(zCredentialOfferObject, {
241
- credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
242
- credential_configuration_ids: options.credentialConfigurationIds,
243
- grants,
244
- ...options.additionalPayload
245
- });
246
- if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
247
- credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
248
- }
249
- const url = new import_utils2.URL(credentialOfferScheme);
250
- url.search = `?${new import_utils2.URLSearchParams([
251
- ...url.searchParams.entries(),
252
- ...(0, import_utils2.objectToQueryParams)({
253
- credential_offer_uri: options.credentialOfferUri,
254
- // Only add credential_offer is uri is undefined
255
- credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
256
- }).entries()
257
- ]).toString()}`;
258
- return {
259
- credentialOffer: url.toString(),
260
- credentialOfferObject
261
- };
130
+ const { [__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]: preAuthorizedCodeGrant, [__openid4vc_oauth2.authorizationCodeGrantIdentifier]: authorizationCodeGrant,...restGrants } = options.grants;
131
+ const grants = { ...restGrants };
132
+ if (authorizationCodeGrant) {
133
+ determineAuthorizationServerForCredentialOffer({
134
+ issuerMetadata: options.issuerMetadata,
135
+ grantAuthorizationServer: authorizationCodeGrant.authorization_server
136
+ });
137
+ grants[__openid4vc_oauth2.authorizationCodeGrantIdentifier] = authorizationCodeGrant;
138
+ }
139
+ if (preAuthorizedCodeGrant) {
140
+ determineAuthorizationServerForCredentialOffer({
141
+ issuerMetadata: options.issuerMetadata,
142
+ grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
143
+ });
144
+ grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier] = {
145
+ ...preAuthorizedCodeGrant,
146
+ "pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? (0, __openid4vc_utils.encodeToBase64Url)(await options.callbacks.generateRandom(32))
147
+ };
148
+ const txCode = grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier].tx_code;
149
+ if (txCode && options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft11) grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier].user_pin_required = txCode !== void 0;
150
+ }
151
+ const idsNotInMetadata = options.credentialConfigurationIds.filter((id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0);
152
+ if (idsNotInMetadata.length > 0) throw new __openid4vc_oauth2.Oauth2Error(`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(", ")}.`);
153
+ const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
154
+ const credentialOfferObject = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialOfferObject, {
155
+ credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
156
+ credential_configuration_ids: options.credentialConfigurationIds,
157
+ grants,
158
+ ...options.additionalPayload
159
+ });
160
+ if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft11) credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
161
+ const url = new __openid4vc_utils.URL(credentialOfferScheme);
162
+ url.search = `?${new __openid4vc_utils.URLSearchParams([...url.searchParams.entries(), ...(0, __openid4vc_utils.objectToQueryParams)({
163
+ credential_offer_uri: options.credentialOfferUri,
164
+ credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
165
+ }).entries()]).toString()}`;
166
+ return {
167
+ credentialOffer: url.toString(),
168
+ credentialOfferObject
169
+ };
262
170
  }
263
171
 
264
- // src/index.ts
265
- var import_utils22 = require("@openid4vc/utils");
266
-
267
- // src/credential-request/credential-request-configurations.ts
268
- var import_utils6 = require("@openid4vc/utils");
269
-
270
- // src/metadata/credential-issuer/credential-issuer-metadata.ts
271
- var import_oauth25 = require("@openid4vc/oauth2");
272
- var import_utils5 = require("@openid4vc/utils");
273
-
274
- // src/metadata/credential-issuer/z-credential-issuer-metadata.ts
275
- var import_oauth24 = require("@openid4vc/oauth2");
276
- var import_utils4 = require("@openid4vc/utils");
277
- var import_zod13 = __toESM(require("zod"));
278
-
279
- // src/formats/credential/mso-mdoc/z-mso-mdoc.ts
280
- var import_zod5 = __toESM(require("zod"));
281
-
282
- // src/metadata/credential-issuer/z-claims-description.ts
283
- var import_zod2 = __toESM(require("zod"));
284
- var zCredentialConfigurationSupportedClaimsDescriptionDraft14 = import_zod2.default.object({
285
- mandatory: import_zod2.default.boolean().optional(),
286
- value_type: import_zod2.default.string().optional(),
287
- display: import_zod2.default.array(
288
- import_zod2.default.object({
289
- name: import_zod2.default.string().optional(),
290
- locale: import_zod2.default.string().optional()
291
- }).passthrough()
292
- ).optional()
172
+ //#endregion
173
+ //#region src/metadata/credential-issuer/z-claims-description.ts
174
+ const zCredentialConfigurationSupportedClaimsDescriptionDraft14 = zod.default.object({
175
+ mandatory: zod.default.boolean().optional(),
176
+ value_type: zod.default.string().optional(),
177
+ display: zod.default.array(zod.default.object({
178
+ name: zod.default.string().optional(),
179
+ locale: zod.default.string().optional()
180
+ }).passthrough()).optional()
293
181
  }).passthrough();
294
- var zCredentialConfigurationSupportedClaimsDraft14 = import_zod2.default.record(
295
- import_zod2.default.string(),
296
- import_zod2.default.union([
297
- zCredentialConfigurationSupportedClaimsDescriptionDraft14,
298
- import_zod2.default.lazy(() => zCredentialConfigurationSupportedClaimsDraft14)
299
- ])
300
- );
301
- var zClaimsDescriptionPath = import_zod2.default.array(import_zod2.default.union([import_zod2.default.string(), import_zod2.default.number().int().nonnegative(), import_zod2.default.null()])).nonempty();
302
- var zMsoMdocClaimsDescriptionPath = import_zod2.default.tuple([import_zod2.default.string(), import_zod2.default.string()], {
303
- 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"
304
- });
305
- var zIssuerMetadataClaimsDescription = import_zod2.default.object({
306
- path: zClaimsDescriptionPath,
307
- mandatory: import_zod2.default.boolean().optional(),
308
- display: import_zod2.default.array(
309
- import_zod2.default.object({
310
- name: import_zod2.default.string().optional(),
311
- locale: import_zod2.default.string().optional()
312
- }).passthrough()
313
- ).optional()
182
+ const zCredentialConfigurationSupportedClaimsDraft14 = zod.default.record(zod.default.string(), zod.default.union([zCredentialConfigurationSupportedClaimsDescriptionDraft14, zod.default.lazy(() => zCredentialConfigurationSupportedClaimsDraft14)]));
183
+ const zClaimsDescriptionPath = zod.default.array(zod.default.union([
184
+ zod.default.string(),
185
+ zod.default.number().int().nonnegative(),
186
+ zod.default.null()
187
+ ])).nonempty();
188
+ const zMsoMdocClaimsDescriptionPath = zod.default.tuple([zod.default.string(), zod.default.string()], { message: "mso_mdoc claims description path MUST be an array with exactly two string elements, pointing to the namespace and element identifier within an mdoc credential" });
189
+ const zIssuerMetadataClaimsDescription = zod.default.object({
190
+ path: zClaimsDescriptionPath,
191
+ mandatory: zod.default.boolean().optional(),
192
+ display: zod.default.array(zod.default.object({
193
+ name: zod.default.string().optional(),
194
+ locale: zod.default.string().optional()
195
+ }).passthrough()).optional()
314
196
  }).passthrough();
315
- var zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription.extend({
316
- path: zMsoMdocClaimsDescriptionPath
317
- });
318
-
319
- // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
320
- var import_zod4 = __toESM(require("zod"));
197
+ const zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription.extend({ path: zMsoMdocClaimsDescriptionPath });
321
198
 
322
- // src/key-attestation/z-key-attestation.ts
323
- var import_oauth23 = require("@openid4vc/oauth2");
324
- var import_utils3 = require("@openid4vc/utils");
325
- var import_zod3 = __toESM(require("zod"));
326
- var zKeyAttestationJwtHeader = import_zod3.default.object({
327
- ...import_oauth23.zJwtHeader.shape,
328
- typ: import_zod3.default.literal("keyattestation+jwt").or(
329
- // Draft 16
330
- import_zod3.default.literal("key-attestation+jwt")
331
- )
332
- }).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
333
- message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
334
- }).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
335
- message: `When 'trust_chain' is provided, 'kid' is required`
336
- });
337
- var zIso18045 = import_zod3.default.enum(["iso_18045_high", "iso_18045_moderate", "iso_18045_enhanced-basic", "iso_18045_basic"]);
338
- var zIso18045OrStringArray = import_zod3.default.array(import_zod3.default.union([zIso18045, import_zod3.default.string()]));
339
- var zKeyAttestationJwtPayload = import_zod3.default.object({
340
- ...import_oauth23.zJwtPayload.shape,
341
- iat: import_utils3.zInteger,
342
- attested_keys: import_zod3.default.array(import_oauth23.zJwk),
343
- key_storage: import_zod3.default.optional(zIso18045OrStringArray),
344
- user_authentication: import_zod3.default.optional(zIso18045OrStringArray),
345
- certification: import_zod3.default.optional(import_zod3.default.string().url())
199
+ //#endregion
200
+ //#region src/key-attestation/z-key-attestation.ts
201
+ const zKeyAttestationJwtHeader = zod.default.object({
202
+ ...__openid4vc_oauth2.zJwtHeader.shape,
203
+ typ: zod.default.literal("keyattestation+jwt").or(zod.default.literal("key-attestation+jwt"))
204
+ }).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, { message: `Both 'jwk' and 'kid' are defined. Only one is allowed` }).refine(({ trust_chain, kid }) => !trust_chain || !kid, { message: `When 'trust_chain' is provided, 'kid' is required` });
205
+ const zIso18045 = zod.default.enum([
206
+ "iso_18045_high",
207
+ "iso_18045_moderate",
208
+ "iso_18045_enhanced-basic",
209
+ "iso_18045_basic"
210
+ ]);
211
+ const zIso18045OrStringArray = zod.default.array(zod.default.union([zIso18045, zod.default.string()]));
212
+ const zKeyAttestationJwtPayload = zod.default.object({
213
+ ...__openid4vc_oauth2.zJwtPayload.shape,
214
+ iat: __openid4vc_utils.zInteger,
215
+ attested_keys: zod.default.array(__openid4vc_oauth2.zJwk),
216
+ key_storage: zod.default.optional(zIso18045OrStringArray),
217
+ user_authentication: zod.default.optional(zIso18045OrStringArray),
218
+ certification: zod.default.optional(zod.default.string().url())
346
219
  }).passthrough();
347
- var zKeyAttestationJwtPayloadForUse = (use) => import_zod3.default.object({
348
- ...zKeyAttestationJwtPayload.shape,
349
- // REQUIRED when used as proof_type.attesation directly
350
- nonce: use === "proof_type.attestation" ? import_zod3.default.string({
351
- message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly`
352
- }) : import_zod3.default.optional(import_zod3.default.string()),
353
- // REQUIRED when used within header of proof_type.jwt
354
- exp: use === "proof_type.jwt" ? import_utils3.zInteger : import_zod3.default.optional(import_utils3.zInteger)
220
+ const zKeyAttestationJwtPayloadForUse = (use) => zod.default.object({
221
+ ...zKeyAttestationJwtPayload.shape,
222
+ nonce: use === "proof_type.attestation" ? zod.default.string({ message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly` }) : zod.default.optional(zod.default.string()),
223
+ exp: use === "proof_type.jwt" ? __openid4vc_utils.zInteger : zod.default.optional(__openid4vc_utils.zInteger)
355
224
  }).passthrough();
356
225
 
357
- // src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
358
- var zCredentialConfigurationSupportedDisplayEntry = import_zod4.default.object({
359
- name: import_zod4.default.string(),
360
- locale: import_zod4.default.string().optional(),
361
- logo: import_zod4.default.object({
362
- // FIXME: make required again, but need to support draft 11 first
363
- uri: import_zod4.default.string().optional(),
364
- alt_text: import_zod4.default.string().optional()
365
- }).passthrough().optional(),
366
- description: import_zod4.default.string().optional(),
367
- background_color: import_zod4.default.string().optional(),
368
- background_image: import_zod4.default.object({
369
- // TODO: should be required, but paradym's metadata is wrong here.
370
- uri: import_zod4.default.string().optional()
371
- }).passthrough().optional(),
372
- text_color: import_zod4.default.string().optional()
226
+ //#endregion
227
+ //#region src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
228
+ const zCredentialConfigurationSupportedDisplayEntry = zod.default.object({
229
+ name: zod.default.string(),
230
+ locale: zod.default.string().optional(),
231
+ logo: zod.default.object({
232
+ uri: zod.default.string().optional(),
233
+ alt_text: zod.default.string().optional()
234
+ }).passthrough().optional(),
235
+ description: zod.default.string().optional(),
236
+ background_color: zod.default.string().optional(),
237
+ background_image: zod.default.object({ uri: zod.default.string().optional() }).passthrough().optional(),
238
+ text_color: zod.default.string().optional()
373
239
  }).passthrough();
374
- var zCredentialConfigurationSupportedCommonCredentialMetadata = import_zod4.default.object({
375
- display: import_zod4.default.array(zCredentialConfigurationSupportedDisplayEntry).optional()
376
- });
377
- var zCredentialConfigurationSupportedCommon = import_zod4.default.object({
378
- format: import_zod4.default.string(),
379
- scope: import_zod4.default.string().optional(),
380
- cryptographic_binding_methods_supported: import_zod4.default.array(import_zod4.default.string()).optional(),
381
- credential_signing_alg_values_supported: import_zod4.default.array(import_zod4.default.string()).or(import_zod4.default.array(import_zod4.default.number())).optional(),
382
- proof_types_supported: import_zod4.default.record(
383
- import_zod4.default.union([import_zod4.default.literal("jwt"), import_zod4.default.literal("attestation"), import_zod4.default.string()]),
384
- import_zod4.default.object({
385
- proof_signing_alg_values_supported: import_zod4.default.array(import_zod4.default.string()),
386
- key_attestations_required: import_zod4.default.object({
387
- key_storage: zIso18045OrStringArray.optional(),
388
- user_authentication: zIso18045OrStringArray.optional()
389
- }).passthrough().optional()
390
- })
391
- ).optional(),
392
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.optional(),
393
- // For typing purposes. Can be removed once we drop support for draft <= 15.
394
- claims: import_zod4.default.optional(import_zod4.default.never())
240
+ const zCredentialConfigurationSupportedCommonCredentialMetadata = zod.default.object({ display: zod.default.array(zCredentialConfigurationSupportedDisplayEntry).optional() });
241
+ const zCredentialConfigurationSupportedCommon = zod.default.object({
242
+ format: zod.default.string(),
243
+ scope: zod.default.string().optional(),
244
+ cryptographic_binding_methods_supported: zod.default.array(zod.default.string()).optional(),
245
+ credential_signing_alg_values_supported: zod.default.array(zod.default.string()).or(zod.default.array(zod.default.number())).optional(),
246
+ proof_types_supported: zod.default.record(zod.default.union([
247
+ zod.default.literal("jwt"),
248
+ zod.default.literal("attestation"),
249
+ zod.default.string()
250
+ ]), zod.default.object({
251
+ proof_signing_alg_values_supported: zod.default.array(zod.default.string()),
252
+ key_attestations_required: zod.default.object({
253
+ key_storage: zIso18045OrStringArray.optional(),
254
+ user_authentication: zIso18045OrStringArray.optional()
255
+ }).passthrough().optional()
256
+ })).optional(),
257
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.optional(),
258
+ claims: zod.default.optional(zod.default.never())
395
259
  }).passthrough();
396
- var zCredentialConfigurationSupportedCommonDraft15 = import_zod4.default.object({
397
- format: import_zod4.default.string(),
398
- scope: import_zod4.default.string().optional(),
399
- cryptographic_binding_methods_supported: import_zod4.default.array(import_zod4.default.string()).optional(),
400
- credential_signing_alg_values_supported: import_zod4.default.array(import_zod4.default.string()).or(import_zod4.default.array(import_zod4.default.number())).optional(),
401
- proof_types_supported: import_zod4.default.record(
402
- import_zod4.default.union([import_zod4.default.literal("jwt"), import_zod4.default.literal("attestation"), import_zod4.default.string()]),
403
- import_zod4.default.object({
404
- proof_signing_alg_values_supported: import_zod4.default.array(import_zod4.default.string()),
405
- key_attestations_required: import_zod4.default.object({
406
- key_storage: zIso18045OrStringArray.optional(),
407
- user_authentication: zIso18045OrStringArray.optional()
408
- }).passthrough().optional()
409
- })
410
- ).optional(),
411
- display: import_zod4.default.array(zCredentialConfigurationSupportedDisplayEntry).optional(),
412
- // For typing purposes.
413
- credential_metadata: import_zod4.default.optional(import_zod4.default.never())
260
+ const zCredentialConfigurationSupportedCommonDraft15 = zod.default.object({
261
+ format: zod.default.string(),
262
+ scope: zod.default.string().optional(),
263
+ cryptographic_binding_methods_supported: zod.default.array(zod.default.string()).optional(),
264
+ credential_signing_alg_values_supported: zod.default.array(zod.default.string()).or(zod.default.array(zod.default.number())).optional(),
265
+ proof_types_supported: zod.default.record(zod.default.union([
266
+ zod.default.literal("jwt"),
267
+ zod.default.literal("attestation"),
268
+ zod.default.string()
269
+ ]), zod.default.object({
270
+ proof_signing_alg_values_supported: zod.default.array(zod.default.string()),
271
+ key_attestations_required: zod.default.object({
272
+ key_storage: zIso18045OrStringArray.optional(),
273
+ user_authentication: zIso18045OrStringArray.optional()
274
+ }).passthrough().optional()
275
+ })).optional(),
276
+ display: zod.default.array(zCredentialConfigurationSupportedDisplayEntry).optional(),
277
+ credential_metadata: zod.default.optional(zod.default.never())
414
278
  }).passthrough();
415
279
 
416
- // src/formats/credential/mso-mdoc/z-mso-mdoc.ts
417
- var zMsoMdocFormatIdentifier = import_zod5.default.literal("mso_mdoc");
418
- var zMsoMdocCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
419
- format: zMsoMdocFormatIdentifier,
420
- doctype: import_zod5.default.string(),
421
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
422
- claims: import_zod5.default.array(zMsoMdocIssuerMetadataClaimsDescription).optional()
423
- }).optional()
280
+ //#endregion
281
+ //#region src/formats/credential/mso-mdoc/z-mso-mdoc.ts
282
+ const zMsoMdocFormatIdentifier = zod.default.literal("mso_mdoc");
283
+ const zMsoMdocCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
284
+ format: zMsoMdocFormatIdentifier,
285
+ doctype: zod.default.string(),
286
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zMsoMdocIssuerMetadataClaimsDescription).optional() }).optional()
424
287
  });
425
- var zMsoMdocCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
426
- format: zMsoMdocFormatIdentifier,
427
- doctype: import_zod5.default.string(),
428
- claims: import_zod5.default.array(zMsoMdocIssuerMetadataClaimsDescription).optional()
288
+ const zMsoMdocCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
289
+ format: zMsoMdocFormatIdentifier,
290
+ doctype: zod.default.string(),
291
+ claims: zod.default.array(zMsoMdocIssuerMetadataClaimsDescription).optional()
429
292
  });
430
- var zMsoMdocCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
431
- format: zMsoMdocFormatIdentifier,
432
- doctype: import_zod5.default.string(),
433
- claims: zCredentialConfigurationSupportedClaimsDraft14.optional(),
434
- order: import_zod5.default.optional(import_zod5.default.array(import_zod5.default.string()))
293
+ const zMsoMdocCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
294
+ format: zMsoMdocFormatIdentifier,
295
+ doctype: zod.default.string(),
296
+ claims: zCredentialConfigurationSupportedClaimsDraft14.optional(),
297
+ order: zod.default.optional(zod.default.array(zod.default.string()))
435
298
  });
436
- var zMsoMdocCredentialRequestFormatDraft14 = import_zod5.default.object({
437
- format: zMsoMdocFormatIdentifier,
438
- doctype: import_zod5.default.string(),
439
- // Format based request is removed in Draft 15, so only old claims syntax supported.
440
- claims: zCredentialConfigurationSupportedClaimsDraft14.optional()
299
+ const zMsoMdocCredentialRequestFormatDraft14 = zod.default.object({
300
+ format: zMsoMdocFormatIdentifier,
301
+ doctype: zod.default.string(),
302
+ claims: zCredentialConfigurationSupportedClaimsDraft14.optional()
441
303
  });
442
304
 
443
- // src/formats/credential/sd-jwt-vc/z-sd-jwt-vc.ts
444
- var import_zod6 = __toESM(require("zod"));
445
- var zLegacySdJwtVcFormatIdentifier = import_zod6.default.literal("vc+sd-jwt");
446
- var zLegacySdJwtVcCredentialIssuerMetadataDraft16 = zCredentialConfigurationSupportedCommon.extend({
447
- vct: import_zod6.default.string(),
448
- format: zLegacySdJwtVcFormatIdentifier,
449
- order: import_zod6.default.optional(import_zod6.default.array(import_zod6.default.string())),
450
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
451
- claims: import_zod6.default.array(zIssuerMetadataClaimsDescription).optional()
452
- }).optional(),
453
- credential_definition: import_zod6.default.optional(import_zod6.default.never())
305
+ //#endregion
306
+ //#region src/formats/credential/sd-jwt-dc/z-sd-jwt-dc.ts
307
+ const zSdJwtDcFormatIdentifier = zod.default.literal("dc+sd-jwt");
308
+ const zSdJwtDcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
309
+ vct: zod.default.string(),
310
+ format: zSdJwtDcFormatIdentifier,
311
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional()
454
312
  });
455
- var zLegacySdJwtVcCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
456
- vct: import_zod6.default.string(),
457
- format: zLegacySdJwtVcFormatIdentifier,
458
- claims: import_zod6.default.optional(zCredentialConfigurationSupportedClaimsDraft14),
459
- order: import_zod6.default.optional(import_zod6.default.array(import_zod6.default.string())),
460
- credential_definition: import_zod6.default.optional(import_zod6.default.never())
461
- });
462
- var zLegacySdJwtVcCredentialRequestFormatDraft14 = import_zod6.default.object({
463
- format: zLegacySdJwtVcFormatIdentifier,
464
- vct: import_zod6.default.string(),
465
- claims: import_zod6.default.optional(zCredentialConfigurationSupportedClaimsDraft14),
466
- credential_definition: import_zod6.default.optional(import_zod6.default.never())
313
+ const zSdJwtDcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
314
+ vct: zod.default.string(),
315
+ format: zSdJwtDcFormatIdentifier,
316
+ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional()
467
317
  });
468
318
 
469
- // src/formats/credential/sd-jwt-dc/z-sd-jwt-dc.ts
470
- var import_zod7 = __toESM(require("zod"));
471
- var zSdJwtDcFormatIdentifier = import_zod7.default.literal("dc+sd-jwt");
472
- var zSdJwtDcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
473
- vct: import_zod7.default.string(),
474
- format: zSdJwtDcFormatIdentifier,
475
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
476
- claims: import_zod7.default.array(zIssuerMetadataClaimsDescription).optional()
477
- }).optional()
319
+ //#endregion
320
+ //#region src/formats/credential/sd-jwt-vc/z-sd-jwt-vc.ts
321
+ /**
322
+ * @deprecated format has been deprecated in favor of "dc+sd-jwt" since Draft 23
323
+ * of the OpenID for Verifiable Presentations specification. Please update your
324
+ * implementations accordingly.
325
+ */
326
+ const zLegacySdJwtVcFormatIdentifier = zod.default.literal("vc+sd-jwt");
327
+ /**
328
+ * @deprecated format has been deprecated in favor of "dc+sd-jwt" since Draft 23
329
+ * of the OpenID for Verifiable Presentations specification. Please update your
330
+ * implementations accordingly.
331
+ */
332
+ const zLegacySdJwtVcCredentialIssuerMetadataDraft16 = zCredentialConfigurationSupportedCommon.extend({
333
+ vct: zod.default.string(),
334
+ format: zLegacySdJwtVcFormatIdentifier,
335
+ order: zod.default.optional(zod.default.array(zod.default.string())),
336
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional(),
337
+ credential_definition: zod.default.optional(zod.default.never())
478
338
  });
479
- var zSdJwtDcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
480
- vct: import_zod7.default.string(),
481
- format: zSdJwtDcFormatIdentifier,
482
- claims: import_zod7.default.array(zIssuerMetadataClaimsDescription).optional()
339
+ /**
340
+ * @deprecated format has been deprecated in favor of "dc+sd-jwt" since Draft 23
341
+ * of the OpenID for Verifiable Presentations specification. Please update your
342
+ * implementations accordingly.
343
+ */
344
+ const zLegacySdJwtVcCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
345
+ vct: zod.default.string(),
346
+ format: zLegacySdJwtVcFormatIdentifier,
347
+ claims: zod.default.optional(zCredentialConfigurationSupportedClaimsDraft14),
348
+ order: zod.default.optional(zod.default.array(zod.default.string())),
349
+ credential_definition: zod.default.optional(zod.default.never())
350
+ });
351
+ /**
352
+ * @deprecated format has been deprecated in favor of "dc+sd-jwt" since Draft 23
353
+ * of the OpenID for Verifiable Presentations specification. Please update your
354
+ * implementations accordingly.
355
+ */
356
+ const zLegacySdJwtVcCredentialRequestFormatDraft14 = zod.default.object({
357
+ format: zLegacySdJwtVcFormatIdentifier,
358
+ vct: zod.default.string(),
359
+ claims: zod.default.optional(zCredentialConfigurationSupportedClaimsDraft14),
360
+ credential_definition: zod.default.optional(zod.default.never())
483
361
  });
484
362
 
485
- // src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
486
- var import_zod9 = __toESM(require("zod"));
487
-
488
- // src/formats/credential/w3c-vc/z-w3c-vc-common.ts
489
- var import_zod8 = __toESM(require("zod"));
490
- var zCredentialSubjectLeafTypeDraft14 = import_zod8.default.object({
491
- mandatory: import_zod8.default.boolean().optional(),
492
- value_type: import_zod8.default.string().optional(),
493
- display: import_zod8.default.array(
494
- import_zod8.default.object({
495
- name: import_zod8.default.string().optional(),
496
- locale: import_zod8.default.string().optional()
497
- }).passthrough()
498
- ).optional()
363
+ //#endregion
364
+ //#region src/formats/credential/w3c-vc/z-w3c-vc-common.ts
365
+ const zCredentialSubjectLeafTypeDraft14 = zod.default.object({
366
+ mandatory: zod.default.boolean().optional(),
367
+ value_type: zod.default.string().optional(),
368
+ display: zod.default.array(zod.default.object({
369
+ name: zod.default.string().optional(),
370
+ locale: zod.default.string().optional()
371
+ }).passthrough()).optional()
499
372
  }).passthrough();
500
- var zClaimValueSchemaDraft14 = import_zod8.default.union([
501
- import_zod8.default.array(import_zod8.default.any()),
502
- import_zod8.default.record(import_zod8.default.string(), import_zod8.default.any()),
503
- zCredentialSubjectLeafTypeDraft14
373
+ const zClaimValueSchemaDraft14 = zod.default.union([
374
+ zod.default.array(zod.default.any()),
375
+ zod.default.record(zod.default.string(), zod.default.any()),
376
+ zCredentialSubjectLeafTypeDraft14
504
377
  ]);
505
- var zW3cVcCredentialSubjectDraft14 = import_zod8.default.record(import_zod8.default.string(), zClaimValueSchemaDraft14);
506
- var zW3cVcJsonLdCredentialDefinition = import_zod8.default.object({
507
- "@context": import_zod8.default.array(import_zod8.default.string()),
508
- type: import_zod8.default.array(import_zod8.default.string()).nonempty()
378
+ const zW3cVcCredentialSubjectDraft14 = zod.default.record(zod.default.string(), zClaimValueSchemaDraft14);
379
+ const zW3cVcJsonLdCredentialDefinition = zod.default.object({
380
+ "@context": zod.default.array(zod.default.string()),
381
+ type: zod.default.array(zod.default.string()).nonempty()
509
382
  }).passthrough();
510
- var zW3cVcJsonLdCredentialDefinitionDraft14 = zW3cVcJsonLdCredentialDefinition.extend({
511
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
512
- });
383
+ const zW3cVcJsonLdCredentialDefinitionDraft14 = zW3cVcJsonLdCredentialDefinition.extend({ credentialSubject: zW3cVcCredentialSubjectDraft14.optional() });
513
384
 
514
- // src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
515
- var zLdpVcFormatIdentifier = import_zod9.default.literal("ldp_vc");
516
- var zLdpVcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
517
- format: zLdpVcFormatIdentifier,
518
- credential_definition: zW3cVcJsonLdCredentialDefinition,
519
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
520
- claims: import_zod9.default.array(zIssuerMetadataClaimsDescription).optional()
521
- }).optional()
385
+ //#endregion
386
+ //#region src/formats/credential/w3c-vc/z-w3c-jwt-vc-json.ts
387
+ const zJwtVcJsonFormatIdentifier = zod.default.literal("jwt_vc_json");
388
+ const zJwtVcJsonCredentialDefinition = zod.default.object({ type: zod.default.array(zod.default.string()).nonempty() }).passthrough();
389
+ const zJwtVcJsonCredentialDefinitionDraft14 = zJwtVcJsonCredentialDefinition.extend({ credentialSubject: zW3cVcCredentialSubjectDraft14.optional() });
390
+ const zJwtVcJsonCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
391
+ format: zJwtVcJsonFormatIdentifier,
392
+ credential_definition: zJwtVcJsonCredentialDefinition,
393
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional()
522
394
  });
523
- var zLdpVcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
524
- format: zLdpVcFormatIdentifier,
525
- credential_definition: zW3cVcJsonLdCredentialDefinition,
526
- claims: import_zod9.default.array(zIssuerMetadataClaimsDescription).optional()
395
+ const zJwtVcJsonCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
396
+ format: zJwtVcJsonFormatIdentifier,
397
+ credential_definition: zJwtVcJsonCredentialDefinition,
398
+ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional()
527
399
  });
528
- var zLdpVcCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
529
- format: zLdpVcFormatIdentifier,
530
- credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
531
- order: import_zod9.default.array(import_zod9.default.string()).optional()
400
+ const zJwtVcJsonCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
401
+ format: zJwtVcJsonFormatIdentifier,
402
+ credential_definition: zJwtVcJsonCredentialDefinitionDraft14,
403
+ order: zod.default.array(zod.default.string()).optional()
532
404
  });
533
- var zLdpVcCredentialIssuerMetadataDraft11 = import_zod9.default.object({
534
- order: import_zod9.default.array(import_zod9.default.string()).optional(),
535
- format: zLdpVcFormatIdentifier,
536
- // Credential definition was spread on top level instead of a separatey property in v11
537
- // As well as using types instead of type
538
- "@context": import_zod9.default.array(import_zod9.default.string()),
539
- types: import_zod9.default.array(import_zod9.default.string()),
540
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
405
+ const zJwtVcJsonCredentialIssuerMetadataDraft11 = zod.default.object({
406
+ format: zJwtVcJsonFormatIdentifier,
407
+ order: zod.default.array(zod.default.string()).optional(),
408
+ types: zod.default.array(zod.default.string()),
409
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
541
410
  }).passthrough();
542
- var zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDraft11.transform(
543
- ({ "@context": context, types, credentialSubject, ...rest }) => ({
544
- ...rest,
545
- credential_definition: {
546
- "@context": context,
547
- type: types,
548
- // Prevent weird typing issue with optional vs undefined
549
- ...credentialSubject ? { credentialSubject } : {}
550
- }
551
- })
552
- );
553
- var zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
554
- ...rest,
555
- ...credentialDefinition,
556
- types: type
557
- })).pipe(zLdpVcCredentialIssuerMetadataDraft11);
558
- var zLdpVcCredentialRequestFormatDraft14 = import_zod9.default.object({
559
- format: zLdpVcFormatIdentifier,
560
- credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14
411
+ const zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMetadataDraft11.transform(({ types, credentialSubject,...rest }) => ({
412
+ ...rest,
413
+ credential_definition: {
414
+ type: types,
415
+ ...credentialSubject ? { credentialSubject } : {}
416
+ }
417
+ }));
418
+ const zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
419
+ ...rest,
420
+ types: type,
421
+ ...credentialDefinition
422
+ })).pipe(zJwtVcJsonCredentialIssuerMetadataDraft11);
423
+ const zJwtVcJsonCredentialRequestFormatDraft14 = zod.default.object({
424
+ format: zJwtVcJsonFormatIdentifier,
425
+ credential_definition: zJwtVcJsonCredentialDefinition
561
426
  });
562
- var zLdpVcCredentialRequestDraft11 = import_zod9.default.object({
563
- format: zLdpVcFormatIdentifier,
564
- credential_definition: import_zod9.default.object({
565
- "@context": import_zod9.default.array(import_zod9.default.string()),
566
- // credential_definition was using types instead of type in v11
567
- types: import_zod9.default.array(import_zod9.default.string()),
568
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
569
- })
427
+ const zJwtVcJsonCredentialRequestDraft11 = zod.default.object({
428
+ format: zJwtVcJsonFormatIdentifier,
429
+ types: zod.default.array(zod.default.string()),
430
+ credentialSubject: zod.default.optional(zW3cVcCredentialSubjectDraft14)
570
431
  }).passthrough();
571
- var zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transform(
572
- ({ credential_definition: { types, ...restCredentialDefinition }, ...rest }) => ({
573
- ...rest,
574
- credential_definition: {
575
- ...restCredentialDefinition,
576
- type: types
577
- }
578
- })
579
- );
580
- var zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
581
- ...rest,
582
- credential_definition: {
583
- ...restCredentialDefinition,
584
- types: type
585
- }
586
- })).pipe(zLdpVcCredentialRequestDraft11);
432
+ const zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.transform(({ types, credentialSubject,...rest }) => {
433
+ return {
434
+ ...rest,
435
+ credential_definition: {
436
+ type: types,
437
+ ...credentialSubject ? { credentialSubject } : {}
438
+ }
439
+ };
440
+ });
441
+ const zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
442
+ ...rest,
443
+ types: type,
444
+ ...credentialDefinition
445
+ })).pipe(zJwtVcJsonCredentialRequestDraft11);
587
446
 
588
- // src/formats/credential/w3c-vc/z-w3c-jwt-vc-json-ld.ts
589
- var import_zod10 = __toESM(require("zod"));
590
- var zJwtVcJsonLdFormatIdentifier = import_zod10.default.literal("jwt_vc_json-ld");
591
- var zJwtVcJsonLdCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
592
- format: zJwtVcJsonLdFormatIdentifier,
593
- credential_definition: zW3cVcJsonLdCredentialDefinition,
594
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
595
- claims: import_zod10.default.array(zIssuerMetadataClaimsDescription).optional()
596
- }).optional()
447
+ //#endregion
448
+ //#region src/formats/credential/w3c-vc/z-w3c-jwt-vc-json-ld.ts
449
+ const zJwtVcJsonLdFormatIdentifier = zod.default.literal("jwt_vc_json-ld");
450
+ const zJwtVcJsonLdCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
451
+ format: zJwtVcJsonLdFormatIdentifier,
452
+ credential_definition: zW3cVcJsonLdCredentialDefinition,
453
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional()
597
454
  });
598
- var zJwtVcJsonLdCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
599
- format: zJwtVcJsonLdFormatIdentifier,
600
- credential_definition: zW3cVcJsonLdCredentialDefinition,
601
- claims: import_zod10.default.array(zIssuerMetadataClaimsDescription).optional()
455
+ const zJwtVcJsonLdCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
456
+ format: zJwtVcJsonLdFormatIdentifier,
457
+ credential_definition: zW3cVcJsonLdCredentialDefinition,
458
+ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional()
602
459
  });
603
- var zJwtVcJsonLdCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
604
- format: zJwtVcJsonLdFormatIdentifier,
605
- credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
606
- order: import_zod10.default.optional(import_zod10.default.array(import_zod10.default.string()))
460
+ const zJwtVcJsonLdCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
461
+ format: zJwtVcJsonLdFormatIdentifier,
462
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
463
+ order: zod.default.optional(zod.default.array(zod.default.string()))
607
464
  });
608
- var zJwtVcJsonLdCredentialIssuerMetadataDraft11 = import_zod10.default.object({
609
- order: import_zod10.default.array(import_zod10.default.string()).optional(),
610
- format: zJwtVcJsonLdFormatIdentifier,
611
- // Credential definition was spread on top level instead of a separatey property in v11
612
- // As well as using types instead of type
613
- "@context": import_zod10.default.array(import_zod10.default.string()),
614
- types: import_zod10.default.array(import_zod10.default.string()),
615
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
465
+ const zJwtVcJsonLdCredentialIssuerMetadataDraft11 = zod.default.object({
466
+ order: zod.default.array(zod.default.string()).optional(),
467
+ format: zJwtVcJsonLdFormatIdentifier,
468
+ "@context": zod.default.array(zod.default.string()),
469
+ types: zod.default.array(zod.default.string()),
470
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
616
471
  }).passthrough();
617
- var zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssuerMetadataDraft11.transform(
618
- ({ "@context": context, types, credentialSubject, ...rest }) => ({
619
- ...rest,
620
- credential_definition: {
621
- "@context": context,
622
- type: types,
623
- // Prevent weird typing issue with optional vs undefined
624
- ...credentialSubject ? { credentialSubject } : {}
625
- }
626
- })
627
- );
628
- var zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
629
- ...rest,
630
- ...credentialDefinition,
631
- types: type
472
+ const zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssuerMetadataDraft11.transform(({ "@context": context, types, credentialSubject,...rest }) => ({
473
+ ...rest,
474
+ credential_definition: {
475
+ "@context": context,
476
+ type: types,
477
+ ...credentialSubject ? { credentialSubject } : {}
478
+ }
479
+ }));
480
+ const zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
481
+ ...rest,
482
+ ...credentialDefinition,
483
+ types: type
632
484
  })).pipe(zJwtVcJsonLdCredentialIssuerMetadataDraft11);
633
- var zJwtVcJsonLdCredentialRequestFormatDraft14 = import_zod10.default.object({
634
- format: zJwtVcJsonLdFormatIdentifier,
635
- credential_definition: zW3cVcJsonLdCredentialDefinition
485
+ const zJwtVcJsonLdCredentialRequestFormatDraft14 = zod.default.object({
486
+ format: zJwtVcJsonLdFormatIdentifier,
487
+ credential_definition: zW3cVcJsonLdCredentialDefinition
636
488
  });
637
- var zJwtVcJsonLdCredentialRequestDraft11 = import_zod10.default.object({
638
- format: zJwtVcJsonLdFormatIdentifier,
639
- credential_definition: import_zod10.default.object({
640
- "@context": import_zod10.default.array(import_zod10.default.string()),
641
- // credential_definition was using types instead of type in v11
642
- types: import_zod10.default.array(import_zod10.default.string()),
643
- credentialSubject: import_zod10.default.optional(zW3cVcCredentialSubjectDraft14)
644
- }).passthrough()
489
+ const zJwtVcJsonLdCredentialRequestDraft11 = zod.default.object({
490
+ format: zJwtVcJsonLdFormatIdentifier,
491
+ credential_definition: zod.default.object({
492
+ "@context": zod.default.array(zod.default.string()),
493
+ types: zod.default.array(zod.default.string()),
494
+ credentialSubject: zod.default.optional(zW3cVcCredentialSubjectDraft14)
495
+ }).passthrough()
645
496
  }).passthrough();
646
- var zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraft11.transform(
647
- ({ credential_definition: { types, ...restCredentialDefinition }, ...rest }) => ({
648
- ...rest,
649
- credential_definition: {
650
- ...restCredentialDefinition,
651
- type: types
652
- }
653
- })
654
- );
655
- var zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...restCredentialDefinition }, ...rest }) => ({
656
- ...rest,
657
- credential_definition: {
658
- ...restCredentialDefinition,
659
- types: type
660
- }
497
+ const zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraft11.transform(({ credential_definition: { types,...restCredentialDefinition },...rest }) => ({
498
+ ...rest,
499
+ credential_definition: {
500
+ ...restCredentialDefinition,
501
+ type: types
502
+ }
503
+ }));
504
+ const zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type,...restCredentialDefinition },...rest }) => ({
505
+ ...rest,
506
+ credential_definition: {
507
+ ...restCredentialDefinition,
508
+ types: type
509
+ }
661
510
  })).pipe(zJwtVcJsonLdCredentialRequestDraft11);
662
511
 
663
- // src/formats/credential/w3c-vc/z-w3c-jwt-vc-json.ts
664
- var import_zod11 = __toESM(require("zod"));
665
- var zJwtVcJsonFormatIdentifier = import_zod11.default.literal("jwt_vc_json");
666
- var zJwtVcJsonCredentialDefinition = import_zod11.default.object({
667
- type: import_zod11.default.array(import_zod11.default.string()).nonempty()
668
- }).passthrough();
669
- var zJwtVcJsonCredentialDefinitionDraft14 = zJwtVcJsonCredentialDefinition.extend({
670
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
671
- });
672
- var zJwtVcJsonCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
673
- format: zJwtVcJsonFormatIdentifier,
674
- credential_definition: zJwtVcJsonCredentialDefinition,
675
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
676
- claims: import_zod11.default.array(zIssuerMetadataClaimsDescription).optional()
677
- }).optional()
512
+ //#endregion
513
+ //#region src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
514
+ const zLdpVcFormatIdentifier = zod.default.literal("ldp_vc");
515
+ const zLdpVcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
516
+ format: zLdpVcFormatIdentifier,
517
+ credential_definition: zW3cVcJsonLdCredentialDefinition,
518
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional()
678
519
  });
679
- var zJwtVcJsonCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
680
- format: zJwtVcJsonFormatIdentifier,
681
- credential_definition: zJwtVcJsonCredentialDefinition,
682
- claims: import_zod11.default.array(zIssuerMetadataClaimsDescription).optional()
520
+ const zLdpVcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
521
+ format: zLdpVcFormatIdentifier,
522
+ credential_definition: zW3cVcJsonLdCredentialDefinition,
523
+ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional()
683
524
  });
684
- var zJwtVcJsonCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
685
- format: zJwtVcJsonFormatIdentifier,
686
- credential_definition: zJwtVcJsonCredentialDefinitionDraft14,
687
- order: import_zod11.default.array(import_zod11.default.string()).optional()
525
+ const zLdpVcCredentialIssuerMetadataDraft14 = zCredentialConfigurationSupportedCommonDraft15.extend({
526
+ format: zLdpVcFormatIdentifier,
527
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
528
+ order: zod.default.array(zod.default.string()).optional()
688
529
  });
689
- var zJwtVcJsonCredentialIssuerMetadataDraft11 = import_zod11.default.object({
690
- format: zJwtVcJsonFormatIdentifier,
691
- order: import_zod11.default.array(import_zod11.default.string()).optional(),
692
- // Credential definition was spread on top level instead of a separatey property in v11
693
- // As well as using types instead of type
694
- types: import_zod11.default.array(import_zod11.default.string()),
695
- credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
530
+ const zLdpVcCredentialIssuerMetadataDraft11 = zod.default.object({
531
+ order: zod.default.array(zod.default.string()).optional(),
532
+ format: zLdpVcFormatIdentifier,
533
+ "@context": zod.default.array(zod.default.string()),
534
+ types: zod.default.array(zod.default.string()),
535
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
696
536
  }).passthrough();
697
- var zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMetadataDraft11.transform(
698
- ({ types, credentialSubject, ...rest }) => ({
699
- ...rest,
700
- credential_definition: {
701
- type: types,
702
- // Prevent weird typing issue with optional vs undefined
703
- ...credentialSubject ? { credentialSubject } : {}
704
- }
705
- })
706
- );
707
- var zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
708
- ...rest,
709
- types: type,
710
- ...credentialDefinition
711
- })).pipe(zJwtVcJsonCredentialIssuerMetadataDraft11);
712
- var zJwtVcJsonCredentialRequestFormatDraft14 = import_zod11.default.object({
713
- format: zJwtVcJsonFormatIdentifier,
714
- credential_definition: zJwtVcJsonCredentialDefinition
537
+ const zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDraft11.transform(({ "@context": context, types, credentialSubject,...rest }) => ({
538
+ ...rest,
539
+ credential_definition: {
540
+ "@context": context,
541
+ type: types,
542
+ ...credentialSubject ? { credentialSubject } : {}
543
+ }
544
+ }));
545
+ const zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDraft14.passthrough().transform(({ credential_definition: { type,...credentialDefinition },...rest }) => ({
546
+ ...rest,
547
+ ...credentialDefinition,
548
+ types: type
549
+ })).pipe(zLdpVcCredentialIssuerMetadataDraft11);
550
+ const zLdpVcCredentialRequestFormatDraft14 = zod.default.object({
551
+ format: zLdpVcFormatIdentifier,
552
+ credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14
715
553
  });
716
- var zJwtVcJsonCredentialRequestDraft11 = import_zod11.default.object({
717
- format: zJwtVcJsonFormatIdentifier,
718
- // Credential definition was spread on top level instead of a separatey property in v11
719
- // As well as using types instead of type
720
- types: import_zod11.default.array(import_zod11.default.string()),
721
- credentialSubject: import_zod11.default.optional(zW3cVcCredentialSubjectDraft14)
554
+ const zLdpVcCredentialRequestDraft11 = zod.default.object({
555
+ format: zLdpVcFormatIdentifier,
556
+ credential_definition: zod.default.object({
557
+ "@context": zod.default.array(zod.default.string()),
558
+ types: zod.default.array(zod.default.string()),
559
+ credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
560
+ })
722
561
  }).passthrough();
723
- var zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.transform(
724
- ({ types, credentialSubject, ...rest }) => {
725
- return {
726
- ...rest,
727
- credential_definition: {
728
- type: types,
729
- // Prevent weird typing issue with optional vs undefined
730
- ...credentialSubject ? { credentialSubject } : {}
731
- }
732
- };
733
- }
734
- );
735
- var zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type, ...credentialDefinition }, ...rest }) => ({
736
- ...rest,
737
- types: type,
738
- ...credentialDefinition
739
- })).pipe(zJwtVcJsonCredentialRequestDraft11);
562
+ const zLdpVcCredentialRequestDraft11To14 = zLdpVcCredentialRequestDraft11.transform(({ credential_definition: { types,...restCredentialDefinition },...rest }) => ({
563
+ ...rest,
564
+ credential_definition: {
565
+ ...restCredentialDefinition,
566
+ type: types
567
+ }
568
+ }));
569
+ const zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.passthrough().transform(({ credential_definition: { type,...restCredentialDefinition },...rest }) => ({
570
+ ...rest,
571
+ credential_definition: {
572
+ ...restCredentialDefinition,
573
+ types: type
574
+ }
575
+ })).pipe(zLdpVcCredentialRequestDraft11);
740
576
 
741
- // src/formats/credential/w3c-vc/z-w3c-sd-jwt-vc.ts
742
- var import_zod12 = __toESM(require("zod"));
743
- var zSdJwtW3VcFormatIdentifier = import_zod12.default.literal("vc+sd-jwt");
744
- var zSdJwtW3VcCredentialDefinition = import_zod12.default.object({
745
- type: import_zod12.default.array(import_zod12.default.string()).nonempty()
746
- }).passthrough();
747
- var zSdJwtW3VcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
748
- format: zSdJwtW3VcFormatIdentifier,
749
- credential_definition: zSdJwtW3VcCredentialDefinition,
750
- credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({
751
- claims: import_zod12.default.array(zIssuerMetadataClaimsDescription).optional()
752
- }).optional(),
753
- // FIXME(vc+sd-jwt): remove when dropping support for legacy vc+sd-jwt. Allows type narrowing.
754
- vct: import_zod12.default.optional(import_zod12.default.never())
577
+ //#endregion
578
+ //#region src/formats/credential/w3c-vc/z-w3c-sd-jwt-vc.ts
579
+ const zSdJwtW3VcFormatIdentifier = zod.default.literal("vc+sd-jwt");
580
+ const zSdJwtW3VcCredentialDefinition = zod.default.object({ type: zod.default.array(zod.default.string()).nonempty() }).passthrough();
581
+ const zSdJwtW3VcCredentialIssuerMetadata = zCredentialConfigurationSupportedCommon.extend({
582
+ format: zSdJwtW3VcFormatIdentifier,
583
+ credential_definition: zSdJwtW3VcCredentialDefinition,
584
+ credential_metadata: zCredentialConfigurationSupportedCommonCredentialMetadata.extend({ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional() }).optional(),
585
+ vct: zod.default.optional(zod.default.never())
755
586
  });
756
- var zSdJwtW3VcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
757
- format: zSdJwtW3VcFormatIdentifier,
758
- credential_definition: zSdJwtW3VcCredentialDefinition,
759
- claims: import_zod12.default.array(zIssuerMetadataClaimsDescription).optional(),
760
- // FIXME(vc+sd-jwt): remove when dropping support for legacy vc+sd-jwt. Allows type narrowing.
761
- vct: import_zod12.default.optional(import_zod12.default.never())
587
+ const zSdJwtW3VcCredentialIssuerMetadataDraft15 = zCredentialConfigurationSupportedCommonDraft15.extend({
588
+ format: zSdJwtW3VcFormatIdentifier,
589
+ credential_definition: zSdJwtW3VcCredentialDefinition,
590
+ claims: zod.default.array(zIssuerMetadataClaimsDescription).optional(),
591
+ vct: zod.default.optional(zod.default.never())
762
592
  });
763
- var zSdJwtW3VcCredentialRequestFormatDraft14 = import_zod12.default.object({
764
- format: zSdJwtW3VcFormatIdentifier,
765
- credential_definition: zSdJwtW3VcCredentialDefinition,
766
- // FIXME(vc+sd-jwt): remove when dropping support for legacy vc+sd-jwt. Allows type narrowing.
767
- vct: import_zod12.default.optional(import_zod12.default.never())
593
+ const zSdJwtW3VcCredentialRequestFormatDraft14 = zod.default.object({
594
+ format: zSdJwtW3VcFormatIdentifier,
595
+ credential_definition: zSdJwtW3VcCredentialDefinition,
596
+ vct: zod.default.optional(zod.default.never())
768
597
  });
769
598
 
770
- // src/metadata/credential-issuer/z-credential-issuer-metadata.ts
771
- var allCredentialIssuerMetadataFormats = [
772
- zSdJwtDcCredentialIssuerMetadata,
773
- zMsoMdocCredentialIssuerMetadata,
774
- zJwtVcJsonLdCredentialIssuerMetadata,
775
- zLdpVcCredentialIssuerMetadata,
776
- zJwtVcJsonCredentialIssuerMetadata,
777
- zSdJwtW3VcCredentialIssuerMetadata,
778
- zSdJwtW3VcCredentialIssuerMetadataDraft15,
779
- zLegacySdJwtVcCredentialIssuerMetadataDraft16,
780
- zSdJwtDcCredentialIssuerMetadataDraft15,
781
- zMsoMdocCredentialIssuerMetadataDraft15,
782
- zJwtVcJsonLdCredentialIssuerMetadataDraft15,
783
- zLdpVcCredentialIssuerMetadataDraft15,
784
- zJwtVcJsonCredentialIssuerMetadataDraft15,
785
- zMsoMdocCredentialIssuerMetadataDraft14,
786
- zLegacySdJwtVcCredentialIssuerMetadataDraft14,
787
- zJwtVcJsonLdCredentialIssuerMetadataDraft14,
788
- zLdpVcCredentialIssuerMetadataDraft14,
789
- zJwtVcJsonCredentialIssuerMetadataDraft14
599
+ //#endregion
600
+ //#region src/metadata/credential-issuer/z-credential-issuer-metadata.ts
601
+ const allCredentialIssuerMetadataFormats = [
602
+ zSdJwtDcCredentialIssuerMetadata,
603
+ zMsoMdocCredentialIssuerMetadata,
604
+ zJwtVcJsonLdCredentialIssuerMetadata,
605
+ zLdpVcCredentialIssuerMetadata,
606
+ zJwtVcJsonCredentialIssuerMetadata,
607
+ zSdJwtW3VcCredentialIssuerMetadata,
608
+ zSdJwtW3VcCredentialIssuerMetadataDraft15,
609
+ zLegacySdJwtVcCredentialIssuerMetadataDraft16,
610
+ zSdJwtDcCredentialIssuerMetadataDraft15,
611
+ zMsoMdocCredentialIssuerMetadataDraft15,
612
+ zJwtVcJsonLdCredentialIssuerMetadataDraft15,
613
+ zLdpVcCredentialIssuerMetadataDraft15,
614
+ zJwtVcJsonCredentialIssuerMetadataDraft15,
615
+ zMsoMdocCredentialIssuerMetadataDraft14,
616
+ zLegacySdJwtVcCredentialIssuerMetadataDraft14,
617
+ zJwtVcJsonLdCredentialIssuerMetadataDraft14,
618
+ zLdpVcCredentialIssuerMetadataDraft14,
619
+ zJwtVcJsonCredentialIssuerMetadataDraft14
790
620
  ];
791
- var allCredentialIssuerMetadataFormatIdentifiers = allCredentialIssuerMetadataFormats.map(
792
- (format) => format.shape.format.value
793
- );
794
- var zCredentialConfigurationSupportedWithFormats = import_zod13.default.union([zCredentialConfigurationSupportedCommon, zCredentialConfigurationSupportedCommonDraft15]).transform((data, ctx) => {
795
- if (!allCredentialIssuerMetadataFormatIdentifiers.includes(data.format)) return data;
796
- const validators = allCredentialIssuerMetadataFormats.filter(
797
- (formatValidator) => formatValidator.shape.format.value === data.format
798
- );
799
- const result = import_zod13.default.object({}).passthrough().and(
800
- validators.length > 1 ? import_zod13.default.union(
801
- validators
802
- ) : validators[0]
803
- ).safeParse(data);
804
- if (result.success) {
805
- return result.data;
806
- }
807
- for (const issue of result.error.issues) {
808
- ctx.addIssue(issue);
809
- }
810
- return import_zod13.default.NEVER;
621
+ const allCredentialIssuerMetadataFormatIdentifiers = allCredentialIssuerMetadataFormats.map((format) => format.shape.format.value);
622
+ const zCredentialConfigurationSupportedWithFormats = zod.default.union([zCredentialConfigurationSupportedCommon, zCredentialConfigurationSupportedCommonDraft15]).transform((data, ctx) => {
623
+ if (!allCredentialIssuerMetadataFormatIdentifiers.includes(data.format)) return data;
624
+ const validators = allCredentialIssuerMetadataFormats.filter((formatValidator) => formatValidator.shape.format.value === data.format);
625
+ const result = zod.default.object({}).passthrough().and(validators.length > 1 ? zod.default.union(validators) : validators[0]).safeParse(data);
626
+ if (result.success) return result.data;
627
+ for (const issue of result.error.issues) ctx.addIssue(issue);
628
+ return zod.default.NEVER;
811
629
  });
812
- var zCredentialIssuerMetadataDisplayEntry = import_zod13.default.object({
813
- name: import_zod13.default.string().optional(),
814
- locale: import_zod13.default.string().optional(),
815
- logo: import_zod13.default.object({
816
- // FIXME: make required again, but need to support draft 11 first
817
- uri: import_zod13.default.string().optional(),
818
- alt_text: import_zod13.default.string().optional()
819
- }).passthrough().optional()
630
+ const zCredentialIssuerMetadataDisplayEntry = zod.default.object({
631
+ name: zod.default.string().optional(),
632
+ locale: zod.default.string().optional(),
633
+ logo: zod.default.object({
634
+ uri: zod.default.string().optional(),
635
+ alt_text: zod.default.string().optional()
636
+ }).passthrough().optional()
820
637
  }).passthrough();
821
- var zCredentialIssuerMetadataDraft14Draft15Draft16 = import_zod13.default.object({
822
- credential_issuer: import_utils4.zHttpsUrl,
823
- authorization_servers: import_zod13.default.array(import_utils4.zHttpsUrl).optional(),
824
- credential_endpoint: import_utils4.zHttpsUrl,
825
- deferred_credential_endpoint: import_utils4.zHttpsUrl.optional(),
826
- notification_endpoint: import_utils4.zHttpsUrl.optional(),
827
- // Added after draft 14, but needed for proper
828
- nonce_endpoint: import_utils4.zHttpsUrl.optional(),
829
- credential_response_encryption: import_zod13.default.object({
830
- alg_values_supported: import_zod13.default.array(import_zod13.default.string()),
831
- enc_values_supported: import_zod13.default.array(import_zod13.default.string()),
832
- encryption_required: import_zod13.default.boolean()
833
- }).passthrough().optional(),
834
- batch_credential_issuance: import_zod13.default.object({
835
- batch_size: import_zod13.default.number().positive()
836
- }).passthrough().optional(),
837
- signed_metadata: import_oauth24.zCompactJwt.optional(),
838
- display: import_zod13.default.array(zCredentialIssuerMetadataDisplayEntry).optional(),
839
- credential_configurations_supported: import_zod13.default.record(import_zod13.default.string(), zCredentialConfigurationSupportedWithFormats)
638
+ const zCredentialIssuerMetadataDraft14Draft15Draft16 = zod.default.object({
639
+ credential_issuer: __openid4vc_utils.zHttpsUrl,
640
+ authorization_servers: zod.default.array(__openid4vc_utils.zHttpsUrl).optional(),
641
+ credential_endpoint: __openid4vc_utils.zHttpsUrl,
642
+ deferred_credential_endpoint: __openid4vc_utils.zHttpsUrl.optional(),
643
+ notification_endpoint: __openid4vc_utils.zHttpsUrl.optional(),
644
+ nonce_endpoint: __openid4vc_utils.zHttpsUrl.optional(),
645
+ credential_response_encryption: zod.default.object({
646
+ alg_values_supported: zod.default.array(zod.default.string()),
647
+ enc_values_supported: zod.default.array(zod.default.string()),
648
+ encryption_required: zod.default.boolean()
649
+ }).passthrough().optional(),
650
+ batch_credential_issuance: zod.default.object({ batch_size: zod.default.number().positive() }).passthrough().optional(),
651
+ signed_metadata: __openid4vc_oauth2.zCompactJwt.optional(),
652
+ display: zod.default.array(zCredentialIssuerMetadataDisplayEntry).optional(),
653
+ credential_configurations_supported: zod.default.record(zod.default.string(), zCredentialConfigurationSupportedWithFormats)
840
654
  }).passthrough();
841
- var zCredentialConfigurationSupportedDraft11To16 = import_zod13.default.object({
842
- id: import_zod13.default.string().optional(),
843
- format: import_zod13.default.string(),
844
- cryptographic_suites_supported: import_zod13.default.array(import_zod13.default.string()).optional(),
845
- display: import_zod13.default.array(
846
- import_zod13.default.object({
847
- logo: import_zod13.default.object({
848
- url: import_zod13.default.string().url().optional()
849
- }).passthrough().optional(),
850
- background_image: import_zod13.default.object({
851
- url: import_zod13.default.string().url().optional()
852
- }).passthrough().optional()
853
- }).passthrough()
854
- ).optional(),
855
- claims: import_zod13.default.any().optional()
856
- }).passthrough().transform(({ cryptographic_suites_supported, display, claims, id, ...rest }) => ({
857
- ...rest,
858
- ...cryptographic_suites_supported ? { credential_signing_alg_values_supported: cryptographic_suites_supported } : {},
859
- ...claims || display ? {
860
- credential_metadata: {
861
- ...claims ? { claims } : {},
862
- ...display ? {
863
- display: display.map(({ logo, background_image, ...displayRest }) => ({
864
- ...displayRest,
865
- // url became uri and also required
866
- // so if there's no url in the logo, we remove the whole logo object
867
- ...logo?.url ? {
868
- // TODO: we should add the other params from logo as well
869
- logo: {
870
- uri: logo.url
871
- }
872
- } : {},
873
- // TODO: we should add the other params from background_image as well
874
- // url became uri and also required
875
- // so if there's no url in the background_image, we remove the whole logo object
876
- ...background_image?.url ? {
877
- background_image: {
878
- uri: background_image.url
879
- }
880
- } : {}
881
- }))
882
- } : {}
883
- }
884
- } : {}
655
+ const zCredentialConfigurationSupportedDraft11To16 = zod.default.object({
656
+ id: zod.default.string().optional(),
657
+ format: zod.default.string(),
658
+ cryptographic_suites_supported: zod.default.array(zod.default.string()).optional(),
659
+ display: zod.default.array(zod.default.object({
660
+ logo: zod.default.object({ url: zod.default.string().url().optional() }).passthrough().optional(),
661
+ background_image: zod.default.object({ url: zod.default.string().url().optional() }).passthrough().optional()
662
+ }).passthrough()).optional(),
663
+ claims: zod.default.any().optional()
664
+ }).passthrough().transform(({ cryptographic_suites_supported, display, claims, id,...rest }) => ({
665
+ ...rest,
666
+ ...cryptographic_suites_supported ? { credential_signing_alg_values_supported: cryptographic_suites_supported } : {},
667
+ ...claims || display ? { credential_metadata: {
668
+ ...claims ? { claims } : {},
669
+ ...display ? { display: display.map(({ logo, background_image,...displayRest }) => ({
670
+ ...displayRest,
671
+ ...logo?.url ? { logo: { uri: logo.url } } : {},
672
+ ...background_image?.url ? { background_image: { uri: background_image.url } } : {}
673
+ })) } : {}
674
+ } } : {}
885
675
  })).transform((data, ctx) => {
886
- const formatSpecificTransformations = {
887
- [zLdpVcFormatIdentifier.value]: zLdpVcCredentialIssuerMetadataDraft11To14,
888
- [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialIssuerMetadataDraft11To14,
889
- [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialIssuerMetadataDraft11To14
890
- };
891
- if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
892
- const schema = formatSpecificTransformations[data.format];
893
- const result = schema.safeParse(data);
894
- if (result.success) return result.data;
895
- for (const issue of result.error.issues) {
896
- ctx.addIssue(issue);
897
- }
898
- return import_zod13.default.NEVER;
676
+ const formatSpecificTransformations = {
677
+ [zLdpVcFormatIdentifier.value]: zLdpVcCredentialIssuerMetadataDraft11To14,
678
+ [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialIssuerMetadataDraft11To14,
679
+ [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialIssuerMetadataDraft11To14
680
+ };
681
+ if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
682
+ const result = formatSpecificTransformations[data.format].safeParse(data);
683
+ if (result.success) return result.data;
684
+ for (const issue of result.error.issues) ctx.addIssue(issue);
685
+ return zod.default.NEVER;
899
686
  }).pipe(zCredentialConfigurationSupportedWithFormats);
900
- var zCredentialConfigurationSupportedDraft16To15 = zCredentialConfigurationSupportedWithFormats.transform(
901
- ({ credential_metadata, ...rest }) => ({
902
- ...credential_metadata,
903
- ...rest
904
- })
905
- );
906
- var zCredentialConfigurationSupportedDraft16To11 = zCredentialConfigurationSupportedDraft16To15.and(
907
- import_zod13.default.object({
908
- id: import_zod13.default.string()
909
- }).passthrough()
910
- ).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope, ...rest }) => ({
911
- ...rest,
912
- ...credential_signing_alg_values_supported ? { cryptographic_suites_supported: credential_signing_alg_values_supported } : {},
913
- ...display ? {
914
- display: display.map(({ logo, background_image, ...displayRest }) => {
915
- const { uri: logoUri, ...logoRest } = logo ?? {};
916
- const { uri: backgroundImageUri, ...backgroundImageRest } = background_image ?? {};
917
- return {
918
- ...displayRest,
919
- // draft 11 uses url, draft 13/14 uses uri
920
- ...logoUri ? { logo: { url: logoUri, ...logoRest } } : {},
921
- // draft 11 uses url, draft 13/14 uses uri
922
- ...backgroundImageUri ? { logo: { url: backgroundImageUri, ...backgroundImageRest } } : {}
923
- };
924
- })
925
- } : {},
926
- id
927
- })).pipe(
928
- import_zod13.default.union([
929
- zLdpVcCredentialIssuerMetadataDraft14To11,
930
- zJwtVcJsonCredentialIssuerMetadataDraft14To11,
931
- zJwtVcJsonLdCredentialIssuerMetadataDraft14To11,
932
- // To handle unrecognized formats and not error immediately we allow the common format as well
933
- // but they can't use any of the format identifiers that have a specific transformation. This way if a format is
934
- // has a transformation it NEEDS to use the format specific transformation, and otherwise we fall back to the common validation
935
- import_zod13.default.object({
936
- format: import_zod13.default.string().refine(
937
- (input) => ![
938
- zLdpVcFormatIdentifier.value,
939
- zJwtVcJsonFormatIdentifier.value,
940
- zJwtVcJsonLdFormatIdentifier.value
941
- ].includes(input)
942
- )
943
- }).passthrough()
944
- ])
945
- );
946
- var zCredentialIssuerMetadataDraft11To16 = import_zod13.default.object({
947
- authorization_server: import_zod13.default.string().optional(),
948
- credentials_supported: import_zod13.default.array(
949
- import_zod13.default.object({
950
- id: import_zod13.default.string().optional()
951
- }).passthrough()
952
- )
953
- }).passthrough().transform(({ authorization_server, credentials_supported, ...rest }) => {
954
- return {
955
- ...rest,
956
- ...authorization_server ? { authorization_servers: [authorization_server] } : {},
957
- // Go from array to map but keep v11 structure
958
- credential_configurations_supported: Object.fromEntries(
959
- credentials_supported.map((supported) => supported.id ? [supported.id, supported] : void 0).filter((i) => i !== void 0)
960
- )
961
- };
962
- }).pipe(
963
- import_zod13.default.object({
964
- // Update from v11 structure to v14 structure
965
- credential_configurations_supported: import_zod13.default.record(import_zod13.default.string(), zCredentialConfigurationSupportedDraft11To16)
966
- }).passthrough()
967
- ).pipe(zCredentialIssuerMetadataDraft14Draft15Draft16);
968
- var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15Draft16.transform((issuerMetadata) => ({
969
- ...issuerMetadata,
970
- ...issuerMetadata.authorization_servers ? { authorization_server: issuerMetadata.authorization_servers[0] } : {},
971
- credentials_supported: Object.entries(issuerMetadata.credential_configurations_supported).map(([id, value]) => ({
972
- ...value,
973
- id
974
- }))
975
- })).pipe(
976
- zCredentialIssuerMetadataDraft14Draft15Draft16.extend({
977
- credentials_supported: import_zod13.default.array(zCredentialConfigurationSupportedDraft16To11)
978
- })
979
- );
980
- var zCredentialIssuerMetadata = import_zod13.default.union([
981
- // First prioritize draft 16/15/14 (and 13)
982
- zCredentialIssuerMetadataDraft14Draft15Draft16,
983
- // Then try parsing draft 11 and transform into draft 16
984
- zCredentialIssuerMetadataDraft11To16
985
- ]);
986
- var zCredentialIssuerMetadataWithDraftVersion = import_zod13.default.union([
987
- zCredentialIssuerMetadataDraft14Draft15Draft16.transform((credentialIssuerMetadata) => {
988
- const credentialConfigurations = Object.values(credentialIssuerMetadata.credential_configurations_supported);
989
- const isDraft15 = credentialConfigurations.some((configuration) => {
990
- const knownConfiguration = configuration;
991
- if (knownConfiguration.format === zSdJwtDcFormatIdentifier.value) return true;
992
- if (Array.isArray(knownConfiguration.claims)) return true;
993
- if (Object.values(knownConfiguration.proof_types_supported ?? {}).some(
994
- (proofType) => proofType.key_attestations_required !== void 0
995
- ))
996
- return true;
997
- return false;
998
- });
999
- const isDraft16 = credentialConfigurations.some((configuration) => {
1000
- return configuration.credential_metadata;
1001
- });
1002
- return {
1003
- credentialIssuerMetadata,
1004
- originalDraftVersion: isDraft16 ? "Draft16" /* Draft16 */ : isDraft15 ? "Draft15" /* Draft15 */ : "Draft14" /* Draft14 */
1005
- };
1006
- }),
1007
- // Then try parsing draft 11 and transform into draft 14
1008
- zCredentialIssuerMetadataDraft11To16.transform((credentialIssuerMetadata) => ({
1009
- credentialIssuerMetadata,
1010
- originalDraftVersion: "Draft11" /* Draft11 */
1011
- }))
1012
- ]);
687
+ const zCredentialConfigurationSupportedDraft16To11 = zCredentialConfigurationSupportedWithFormats.transform(({ credential_metadata,...rest }) => ({
688
+ ...credential_metadata,
689
+ ...rest
690
+ })).and(zod.default.object({ id: zod.default.string() }).passthrough()).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope,...rest }) => ({
691
+ ...rest,
692
+ ...credential_signing_alg_values_supported ? { cryptographic_suites_supported: credential_signing_alg_values_supported } : {},
693
+ ...display ? { display: display.map(({ logo, background_image,...displayRest }) => {
694
+ const { uri: logoUri,...logoRest } = logo ?? {};
695
+ const { uri: backgroundImageUri,...backgroundImageRest } = background_image ?? {};
696
+ return {
697
+ ...displayRest,
698
+ ...logoUri ? { logo: {
699
+ url: logoUri,
700
+ ...logoRest
701
+ } } : {},
702
+ ...backgroundImageUri ? { logo: {
703
+ url: backgroundImageUri,
704
+ ...backgroundImageRest
705
+ } } : {}
706
+ };
707
+ }) } : {},
708
+ id
709
+ })).pipe(zod.default.union([
710
+ zLdpVcCredentialIssuerMetadataDraft14To11,
711
+ zJwtVcJsonCredentialIssuerMetadataDraft14To11,
712
+ zJwtVcJsonLdCredentialIssuerMetadataDraft14To11,
713
+ zod.default.object({ format: zod.default.string().refine((input) => ![
714
+ zLdpVcFormatIdentifier.value,
715
+ zJwtVcJsonFormatIdentifier.value,
716
+ zJwtVcJsonLdFormatIdentifier.value
717
+ ].includes(input)) }).passthrough()
718
+ ]));
719
+ const zCredentialIssuerMetadataDraft11To16 = zod.default.object({
720
+ authorization_server: zod.default.string().optional(),
721
+ credentials_supported: zod.default.array(zod.default.object({ id: zod.default.string().optional() }).passthrough())
722
+ }).passthrough().transform(({ authorization_server, credentials_supported,...rest }) => {
723
+ return {
724
+ ...rest,
725
+ ...authorization_server ? { authorization_servers: [authorization_server] } : {},
726
+ credential_configurations_supported: Object.fromEntries(credentials_supported.map((supported) => supported.id ? [supported.id, supported] : void 0).filter((i) => i !== void 0))
727
+ };
728
+ }).pipe(zod.default.object({ credential_configurations_supported: zod.default.record(zod.default.string(), zCredentialConfigurationSupportedDraft11To16) }).passthrough()).pipe(zCredentialIssuerMetadataDraft14Draft15Draft16);
729
+ const zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15Draft16.transform((issuerMetadata) => ({
730
+ ...issuerMetadata,
731
+ ...issuerMetadata.authorization_servers ? { authorization_server: issuerMetadata.authorization_servers[0] } : {},
732
+ credentials_supported: Object.entries(issuerMetadata.credential_configurations_supported).map(([id, value]) => ({
733
+ ...value,
734
+ id
735
+ }))
736
+ })).pipe(zCredentialIssuerMetadataDraft14Draft15Draft16.extend({ credentials_supported: zod.default.array(zCredentialConfigurationSupportedDraft16To11) }));
737
+ const zCredentialIssuerMetadata = zod.default.union([zCredentialIssuerMetadataDraft14Draft15Draft16, zCredentialIssuerMetadataDraft11To16]);
738
+ const zCredentialIssuerMetadataWithDraftVersion = zod.default.union([zCredentialIssuerMetadataDraft14Draft15Draft16.transform((credentialIssuerMetadata) => {
739
+ const credentialConfigurations = Object.values(credentialIssuerMetadata.credential_configurations_supported);
740
+ const isDraft15 = credentialConfigurations.some((configuration) => {
741
+ const knownConfiguration = configuration;
742
+ if (knownConfiguration.format === zSdJwtDcFormatIdentifier.value) return true;
743
+ if (Array.isArray(knownConfiguration.claims)) return true;
744
+ if (Object.values(knownConfiguration.proof_types_supported ?? {}).some((proofType) => proofType.key_attestations_required !== void 0)) return true;
745
+ return false;
746
+ });
747
+ return {
748
+ credentialIssuerMetadata,
749
+ originalDraftVersion: credentialConfigurations.some((configuration) => {
750
+ return configuration.credential_metadata;
751
+ }) ? Openid4vciDraftVersion.Draft16 : isDraft15 ? Openid4vciDraftVersion.Draft15 : Openid4vciDraftVersion.Draft14
752
+ };
753
+ }), zCredentialIssuerMetadataDraft11To16.transform((credentialIssuerMetadata) => ({
754
+ credentialIssuerMetadata,
755
+ originalDraftVersion: Openid4vciDraftVersion.Draft11
756
+ }))]);
1013
757
 
1014
- // src/metadata/credential-issuer/credential-issuer-metadata.ts
1015
- var wellKnownCredentialIssuerSuffix = ".well-known/openid-credential-issuer";
758
+ //#endregion
759
+ //#region src/metadata/credential-issuer/credential-issuer-metadata.ts
760
+ const wellKnownCredentialIssuerSuffix = ".well-known/openid-credential-issuer";
761
+ /**
762
+ * @inheritdoc {@link fetchWellKnownMetadata}
763
+ */
1016
764
  async function fetchCredentialIssuerMetadata(credentialIssuer, fetch) {
1017
- const wellKnownMetadataUrl = (0, import_utils5.joinUriParts)(credentialIssuer, [wellKnownCredentialIssuerSuffix]);
1018
- const result = await (0, import_oauth25.fetchWellKnownMetadata)(wellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
1019
- if (result && result.credentialIssuerMetadata.credential_issuer !== credentialIssuer) {
1020
- throw new import_oauth25.Oauth2Error(
1021
- `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}'.`
1022
- );
1023
- }
1024
- return result;
765
+ const wellKnownMetadataUrl = (0, __openid4vc_utils.joinUriParts)(credentialIssuer, [wellKnownCredentialIssuerSuffix]);
766
+ const result = await (0, __openid4vc_oauth2.fetchWellKnownMetadata)(wellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
767
+ if (result && result.credentialIssuerMetadata.credential_issuer !== credentialIssuer) throw new __openid4vc_oauth2.Oauth2Error(`The 'credential_issuer' parameter '${result.credentialIssuerMetadata.credential_issuer}' in the well known credential issuer metadata at '${wellKnownMetadataUrl}' does not match the provided credential issuer '${credentialIssuer}'.`);
768
+ return result;
1025
769
  }
770
+ /**
771
+ * Extract credential configuration supported entries where the `format` is known to this
772
+ * library. Should be ran only after verifying the credential issuer metadata structure, so
773
+ * we can be certain that if the `format` matches the other format specific requirements are also met.
774
+ *
775
+ * Validation is done when resolving issuer metadata, or when calling `createIssuerMetadata`.
776
+ */
1026
777
  function extractKnownCredentialConfigurationSupportedFormats(credentialConfigurationsSupported) {
1027
- return Object.fromEntries(
1028
- Object.entries(credentialConfigurationsSupported).filter(
1029
- (entry) => allCredentialIssuerMetadataFormatIdentifiers.includes(entry[1].format)
1030
- )
1031
- );
778
+ return Object.fromEntries(Object.entries(credentialConfigurationsSupported).filter((entry) => allCredentialIssuerMetadataFormatIdentifiers.includes(entry[1].format)));
1032
779
  }
1033
780
  function getCredentialConfigurationSupportedById(credentialConfigurations, credentialConfigurationId) {
1034
- const configuration = credentialConfigurations[credentialConfigurationId];
1035
- if (!configuration) {
1036
- throw new import_oauth25.Oauth2Error(
1037
- `Credential configuration with id '${credentialConfigurationId}' not found in credential configurations supported.`
1038
- );
1039
- }
1040
- return configuration;
781
+ const configuration = credentialConfigurations[credentialConfigurationId];
782
+ if (!configuration) throw new __openid4vc_oauth2.Oauth2Error(`Credential configuration with id '${credentialConfigurationId}' not found in credential configurations supported.`);
783
+ return configuration;
1041
784
  }
1042
785
 
1043
- // src/credential-request/credential-request-configurations.ts
1044
- function getCredentialConfigurationsMatchingRequestFormat({
1045
- requestFormat,
1046
- credentialConfigurations
1047
- }) {
1048
- const knownCredentialConfigurations = extractKnownCredentialConfigurationSupportedFormats(credentialConfigurations);
1049
- return Object.fromEntries(
1050
- Object.entries(knownCredentialConfigurations).filter(([, credentialConfiguration]) => {
1051
- if (credentialConfiguration.format !== requestFormat.format) return false;
1052
- const r = requestFormat;
1053
- const c = credentialConfiguration;
1054
- if ((c.format === "ldp_vc" || c.format === "jwt_vc_json-ld") && r.format === c.format) {
1055
- return (0, import_utils6.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type) && (0, import_utils6.arrayEqualsIgnoreOrder)(r.credential_definition["@context"], c.credential_definition["@context"]);
1056
- }
1057
- if (c.format === "jwt_vc_json" && r.format === c.format) {
1058
- return (0, import_utils6.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type);
1059
- }
1060
- if (c.format === "vc+sd-jwt" && r.format === c.format) {
1061
- if (r.vct && c.vct) {
1062
- return r.vct === c.vct;
1063
- }
1064
- if (c.credential_definition && r.credential_definition) {
1065
- return (0, import_utils6.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type);
1066
- }
1067
- }
1068
- if (c.format === "mso_mdoc" && r.format === c.format) {
1069
- return r.doctype === c.doctype;
1070
- }
1071
- return false;
1072
- })
1073
- );
786
+ //#endregion
787
+ //#region src/credential-request/credential-request-configurations.ts
788
+ function getCredentialConfigurationsMatchingRequestFormat({ requestFormat, credentialConfigurations }) {
789
+ const knownCredentialConfigurations = extractKnownCredentialConfigurationSupportedFormats(credentialConfigurations);
790
+ return Object.fromEntries(Object.entries(knownCredentialConfigurations).filter(([, credentialConfiguration]) => {
791
+ if (credentialConfiguration.format !== requestFormat.format) return false;
792
+ const r = requestFormat;
793
+ const c = credentialConfiguration;
794
+ if ((c.format === "ldp_vc" || c.format === "jwt_vc_json-ld") && r.format === c.format) return (0, __openid4vc_utils.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type) && (0, __openid4vc_utils.arrayEqualsIgnoreOrder)(r.credential_definition["@context"], c.credential_definition["@context"]);
795
+ if (c.format === "jwt_vc_json" && r.format === c.format) return (0, __openid4vc_utils.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type);
796
+ if (c.format === "vc+sd-jwt" && r.format === c.format) {
797
+ if (r.vct && c.vct) return r.vct === c.vct;
798
+ if (c.credential_definition && r.credential_definition) return (0, __openid4vc_utils.arrayEqualsIgnoreOrder)(r.credential_definition.type, c.credential_definition.type);
799
+ }
800
+ if (c.format === "mso_mdoc" && r.format === c.format) return r.doctype === c.doctype;
801
+ return false;
802
+ }));
1074
803
  }
1075
804
 
1076
- // src/error/Openid4vciError.ts
805
+ //#endregion
806
+ //#region src/error/Openid4vciError.ts
1077
807
  var Openid4vciError = class extends Error {
1078
- constructor(message, options) {
1079
- const errorMessage = message ?? "Unknown error occured.";
1080
- const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${options?.cause}` : "";
1081
- super(`${errorMessage}${causeMessage}`);
1082
- this.cause = options?.cause;
1083
- }
808
+ constructor(message, options) {
809
+ const errorMessage = message ?? "Unknown error occured.";
810
+ const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${options?.cause}` : "";
811
+ super(`${errorMessage}${causeMessage}`);
812
+ this.cause = options?.cause;
813
+ }
1084
814
  };
1085
815
 
1086
- // src/error/Openid4vciRetrieveCredentialsError.ts
1087
- var import_utils7 = require("@openid4vc/utils");
816
+ //#endregion
817
+ //#region src/error/Openid4vciRetrieveCredentialsError.ts
1088
818
  var Openid4vciRetrieveCredentialsError = class extends Openid4vciError {
1089
- constructor(message, response, responseText) {
1090
- const errorData = response.credentialResponseResult?.data ?? response.credentialErrorResponseResult?.data ?? (response.credentialResponseResult?.error ? (0, import_utils7.formatZodError)(response.credentialResponseResult.error) : void 0) ?? responseText;
1091
- super(`${message}
1092
- ${JSON.stringify(errorData, null, 2)}`);
1093
- this.response = response;
1094
- }
819
+ constructor(message, response, responseText) {
820
+ const errorData = response.credentialResponseResult?.data ?? response.credentialErrorResponseResult?.data ?? (response.credentialResponseResult?.error ? (0, __openid4vc_utils.formatZodError)(response.credentialResponseResult.error) : void 0) ?? responseText;
821
+ super(`${message}\n${JSON.stringify(errorData, null, 2)}`);
822
+ this.response = response;
823
+ }
1095
824
  };
1096
825
 
1097
- // src/error/Openid4vciSendNotificationError.ts
826
+ //#endregion
827
+ //#region src/error/Openid4vciSendNotificationError.ts
1098
828
  var Openid4vciSendNotificationError = class extends Openid4vciError {
1099
- constructor(message, response) {
1100
- super(message);
1101
- this.response = response;
1102
- }
829
+ constructor(message, response) {
830
+ super(message);
831
+ this.response = response;
832
+ }
1103
833
  };
1104
834
 
1105
- // src/key-attestation/key-attestation.ts
1106
- var import_oauth26 = require("@openid4vc/oauth2");
1107
- var import_oauth27 = require("@openid4vc/oauth2");
1108
- var import_utils8 = require("@openid4vc/utils");
835
+ //#endregion
836
+ //#region src/key-attestation/key-attestation.ts
1109
837
  async function createKeyAttestationJwt(options) {
1110
- const header = (0, import_utils8.parseWithErrorHandling)(zKeyAttestationJwtHeader, {
1111
- ...(0, import_oauth26.jwtHeaderFromJwtSigner)(options.signer),
1112
- typ: "keyattestation+jwt"
1113
- });
1114
- const payload = (0, import_utils8.parseWithErrorHandling)(zKeyAttestationJwtPayloadForUse(options.use), {
1115
- iat: (0, import_utils8.dateToSeconds)(options.issuedAt),
1116
- exp: options.expiresAt ? (0, import_utils8.dateToSeconds)(options.expiresAt) : void 0,
1117
- nonce: options.nonce,
1118
- attested_keys: options.attestedKeys,
1119
- user_authentication: options.userAuthentication,
1120
- key_storage: options.keyStorage,
1121
- certification: options.certification,
1122
- ...options.additionalPayload
1123
- });
1124
- const { jwt } = await options.callbacks.signJwt(options.signer, { header, payload });
1125
- return jwt;
838
+ const header = (0, __openid4vc_utils.parseWithErrorHandling)(zKeyAttestationJwtHeader, {
839
+ ...(0, __openid4vc_oauth2.jwtHeaderFromJwtSigner)(options.signer),
840
+ typ: "keyattestation+jwt"
841
+ });
842
+ const payload = (0, __openid4vc_utils.parseWithErrorHandling)(zKeyAttestationJwtPayloadForUse(options.use), {
843
+ iat: (0, __openid4vc_utils.dateToSeconds)(options.issuedAt),
844
+ exp: options.expiresAt ? (0, __openid4vc_utils.dateToSeconds)(options.expiresAt) : void 0,
845
+ nonce: options.nonce,
846
+ attested_keys: options.attestedKeys,
847
+ user_authentication: options.userAuthentication,
848
+ key_storage: options.keyStorage,
849
+ certification: options.certification,
850
+ ...options.additionalPayload
851
+ });
852
+ const { jwt } = await options.callbacks.signJwt(options.signer, {
853
+ header,
854
+ payload
855
+ });
856
+ return jwt;
1126
857
  }
1127
858
  function parseKeyAttestationJwt({ keyAttestationJwt, use }) {
1128
- return (0, import_oauth26.decodeJwt)({
1129
- jwt: keyAttestationJwt,
1130
- headerSchema: zKeyAttestationJwtHeader,
1131
- payloadSchema: zKeyAttestationJwtPayloadForUse(use)
1132
- });
859
+ return (0, __openid4vc_oauth2.decodeJwt)({
860
+ jwt: keyAttestationJwt,
861
+ headerSchema: zKeyAttestationJwtHeader,
862
+ payloadSchema: zKeyAttestationJwtPayloadForUse(use)
863
+ });
1133
864
  }
1134
865
  async function verifyKeyAttestationJwt(options) {
1135
- const { header, payload } = parseKeyAttestationJwt({ keyAttestationJwt: options.keyAttestationJwt, use: options.use });
1136
- const now = options.now?.getTime() ?? Date.now();
1137
- if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
1138
- throw new Openid4vciError("Nonce used for key attestation jwt expired");
1139
- }
1140
- const { signer } = await (0, import_oauth27.verifyJwt)({
1141
- compact: options.keyAttestationJwt,
1142
- header,
1143
- payload,
1144
- signer: (0, import_oauth27.jwtSignerFromJwt)({ header, payload }),
1145
- verifyJwtCallback: options.callbacks.verifyJwt,
1146
- errorMessage: "Error verifiying key attestation jwt",
1147
- expectedNonce: options.expectedNonce,
1148
- now: options.now
1149
- });
1150
- return {
1151
- header,
1152
- payload,
1153
- signer
1154
- };
866
+ const { header, payload } = parseKeyAttestationJwt({
867
+ keyAttestationJwt: options.keyAttestationJwt,
868
+ use: options.use
869
+ });
870
+ const now = options.now?.getTime() ?? Date.now();
871
+ if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) throw new Openid4vciError("Nonce used for key attestation jwt expired");
872
+ const { signer } = await (0, __openid4vc_oauth2.verifyJwt)({
873
+ compact: options.keyAttestationJwt,
874
+ header,
875
+ payload,
876
+ signer: (0, __openid4vc_oauth2.jwtSignerFromJwt)({
877
+ header,
878
+ payload
879
+ }),
880
+ verifyJwtCallback: options.callbacks.verifyJwt,
881
+ errorMessage: "Error verifiying key attestation jwt",
882
+ expectedNonce: options.expectedNonce,
883
+ now: options.now
884
+ });
885
+ return {
886
+ header,
887
+ payload,
888
+ signer
889
+ };
1155
890
  }
1156
891
 
1157
- // src/metadata/credential-issuer/credential-configurations.ts
1158
- var import_oauth28 = require("@openid4vc/oauth2");
1159
- var import_utils9 = require("@openid4vc/utils");
892
+ //#endregion
893
+ //#region src/metadata/credential-issuer/credential-configurations.ts
1160
894
  function extractScopesForCredentialConfigurationIds(options) {
1161
- const scopes = /* @__PURE__ */ new Set();
1162
- for (const credentialConfigurationId of options.credentialConfigurationIds) {
1163
- const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[credentialConfigurationId];
1164
- if (!credentialConfiguration) {
1165
- throw new import_oauth28.Oauth2Error(
1166
- `Credential configuration with id '${credentialConfigurationId}' not found in metadata from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
1167
- );
1168
- }
1169
- const scope = credentialConfiguration.scope;
1170
- if (scope) scopes.add(scope);
1171
- else if (!scope && options.throwOnConfigurationWithoutScope) {
1172
- throw new import_oauth28.Oauth2Error(
1173
- `Credential configuration with id '${credentialConfigurationId}' does not have a 'scope' configured, and 'throwOnConfigurationWithoutScope' was enabled.`
1174
- );
1175
- }
1176
- }
1177
- return scopes.size > 0 ? Array.from(scopes) : void 0;
895
+ const scopes = /* @__PURE__ */ new Set();
896
+ for (const credentialConfigurationId of options.credentialConfigurationIds) {
897
+ const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[credentialConfigurationId];
898
+ if (!credentialConfiguration) throw new __openid4vc_oauth2.Oauth2Error(`Credential configuration with id '${credentialConfigurationId}' not found in metadata from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`);
899
+ const scope = credentialConfiguration.scope;
900
+ if (scope) scopes.add(scope);
901
+ else if (!scope && options.throwOnConfigurationWithoutScope) throw new __openid4vc_oauth2.Oauth2Error(`Credential configuration with id '${credentialConfigurationId}' does not have a 'scope' configured, and 'throwOnConfigurationWithoutScope' was enabled.`);
902
+ }
903
+ return scopes.size > 0 ? Array.from(scopes) : void 0;
1178
904
  }
905
+ /**
906
+ * Transforms draft 11 credentials supported syntax to credential configurations supported
907
+ *
908
+ * @throws if a credentials supported entry without id is passed
909
+ * @throws if a credentials supported entry with invalid structure or format specific properties is passed
910
+ */
1179
911
  function credentialsSupportedToCredentialConfigurationsSupported(credentialsSupported) {
1180
- const credentialConfigurationsSupported = {};
1181
- for (let index = 0; index < credentialsSupported.length; index++) {
1182
- const credentialSupported = credentialsSupported[index];
1183
- if (!credentialSupported.id) {
1184
- throw new Openid4vciError(
1185
- `Credential supported at index '${index}' does not have an 'id' property. Credential configuration requires the 'id' property as key`
1186
- );
1187
- }
1188
- const parseResult = zCredentialConfigurationSupportedDraft11To16.safeParse(credentialSupported);
1189
- if (!parseResult.success) {
1190
- throw new import_utils9.ValidationError(
1191
- `Error transforming credential supported with id '${credentialSupported.id}' to credential configuration supported format`,
1192
- parseResult.error
1193
- );
1194
- }
1195
- credentialConfigurationsSupported[credentialSupported.id] = parseResult.data;
1196
- }
1197
- return credentialConfigurationsSupported;
912
+ const credentialConfigurationsSupported = {};
913
+ for (let index = 0; index < credentialsSupported.length; index++) {
914
+ const credentialSupported = credentialsSupported[index];
915
+ if (!credentialSupported.id) throw new Openid4vciError(`Credential supported at index '${index}' does not have an 'id' property. Credential configuration requires the 'id' property as key`);
916
+ const parseResult = zCredentialConfigurationSupportedDraft11To16.safeParse(credentialSupported);
917
+ if (!parseResult.success) throw new __openid4vc_utils.ValidationError(`Error transforming credential supported with id '${credentialSupported.id}' to credential configuration supported format`, parseResult.error);
918
+ credentialConfigurationsSupported[credentialSupported.id] = parseResult.data;
919
+ }
920
+ return credentialConfigurationsSupported;
1198
921
  }
1199
922
 
1200
- // src/Openid4vciClient.ts
1201
- var import_oauth219 = require("@openid4vc/oauth2");
1202
-
1203
- // src/credential-request/format-payload.ts
1204
- var import_utils10 = require("@openid4vc/utils");
923
+ //#endregion
924
+ //#region src/credential-request/format-payload.ts
1205
925
  function getCredentialRequestFormatPayloadForCredentialConfigurationId(options) {
1206
- const credentialConfiguration = getCredentialConfigurationSupportedById(
1207
- options.issuerMetadata.credentialIssuer.credential_configurations_supported,
1208
- options.credentialConfigurationId
1209
- );
1210
- if ((0, import_utils10.zIs)(zLegacySdJwtVcCredentialIssuerMetadataDraft16, credentialConfiguration) || (0, import_utils10.zIs)(zLegacySdJwtVcCredentialIssuerMetadataDraft14, credentialConfiguration)) {
1211
- return {
1212
- format: credentialConfiguration.format,
1213
- vct: credentialConfiguration.vct
1214
- };
1215
- }
1216
- if ((0, import_utils10.zIs)(zMsoMdocCredentialIssuerMetadata, credentialConfiguration) || (0, import_utils10.zIs)(zMsoMdocCredentialIssuerMetadataDraft14, credentialConfiguration)) {
1217
- return {
1218
- format: credentialConfiguration.format,
1219
- doctype: credentialConfiguration.doctype
1220
- };
1221
- }
1222
- if ((0, import_utils10.zIs)(zLdpVcCredentialIssuerMetadata, credentialConfiguration) || (0, import_utils10.zIs)(zLdpVcCredentialIssuerMetadataDraft14, credentialConfiguration)) {
1223
- return {
1224
- format: credentialConfiguration.format,
1225
- credential_definition: {
1226
- "@context": credentialConfiguration.credential_definition["@context"],
1227
- type: credentialConfiguration.credential_definition.type
1228
- }
1229
- };
1230
- }
1231
- if ((0, import_utils10.zIs)(zJwtVcJsonLdCredentialIssuerMetadata, credentialConfiguration) || (0, import_utils10.zIs)(zJwtVcJsonLdCredentialIssuerMetadataDraft14, credentialConfiguration)) {
1232
- return {
1233
- format: credentialConfiguration.format,
1234
- credential_definition: {
1235
- "@context": credentialConfiguration.credential_definition["@context"],
1236
- type: credentialConfiguration.credential_definition.type
1237
- }
1238
- };
1239
- }
1240
- if ((0, import_utils10.zIs)(zJwtVcJsonCredentialIssuerMetadata, credentialConfiguration) || (0, import_utils10.zIs)(zJwtVcJsonCredentialIssuerMetadataDraft14, credentialConfiguration)) {
1241
- return {
1242
- format: credentialConfiguration.format,
1243
- credential_definition: {
1244
- type: credentialConfiguration.credential_definition.type
1245
- }
1246
- };
1247
- }
1248
- if ((0, import_utils10.zIs)(zSdJwtDcCredentialIssuerMetadata, credentialConfiguration)) {
1249
- throw new Openid4vciError(
1250
- `Credential configuration id '${options.credentialConfigurationId}' with format ${zLegacySdJwtVcFormatIdentifier.value} does not support credential request based on 'format'. Use 'credential_configuration_id' directly.`
1251
- );
1252
- }
1253
- if ((0, import_utils10.zIs)(zSdJwtW3VcCredentialIssuerMetadata, credentialConfiguration)) {
1254
- return {
1255
- format: credentialConfiguration.format,
1256
- credential_definition: {
1257
- type: credentialConfiguration.credential_definition.type
1258
- }
1259
- };
1260
- }
1261
- throw new Openid4vciError(
1262
- `Unknown format '${credentialConfiguration.format}' in credential configuration with id '${options.credentialConfigurationId}' for credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
1263
- );
926
+ const credentialConfiguration = getCredentialConfigurationSupportedById(options.issuerMetadata.credentialIssuer.credential_configurations_supported, options.credentialConfigurationId);
927
+ if ((0, __openid4vc_utils.zIs)(zLegacySdJwtVcCredentialIssuerMetadataDraft16, credentialConfiguration) || (0, __openid4vc_utils.zIs)(zLegacySdJwtVcCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
928
+ format: credentialConfiguration.format,
929
+ vct: credentialConfiguration.vct
930
+ };
931
+ if ((0, __openid4vc_utils.zIs)(zMsoMdocCredentialIssuerMetadata, credentialConfiguration) || (0, __openid4vc_utils.zIs)(zMsoMdocCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
932
+ format: credentialConfiguration.format,
933
+ doctype: credentialConfiguration.doctype
934
+ };
935
+ if ((0, __openid4vc_utils.zIs)(zLdpVcCredentialIssuerMetadata, credentialConfiguration) || (0, __openid4vc_utils.zIs)(zLdpVcCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
936
+ format: credentialConfiguration.format,
937
+ credential_definition: {
938
+ "@context": credentialConfiguration.credential_definition["@context"],
939
+ type: credentialConfiguration.credential_definition.type
940
+ }
941
+ };
942
+ if ((0, __openid4vc_utils.zIs)(zJwtVcJsonLdCredentialIssuerMetadata, credentialConfiguration) || (0, __openid4vc_utils.zIs)(zJwtVcJsonLdCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
943
+ format: credentialConfiguration.format,
944
+ credential_definition: {
945
+ "@context": credentialConfiguration.credential_definition["@context"],
946
+ type: credentialConfiguration.credential_definition.type
947
+ }
948
+ };
949
+ if ((0, __openid4vc_utils.zIs)(zJwtVcJsonCredentialIssuerMetadata, credentialConfiguration) || (0, __openid4vc_utils.zIs)(zJwtVcJsonCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
950
+ format: credentialConfiguration.format,
951
+ credential_definition: { type: credentialConfiguration.credential_definition.type }
952
+ };
953
+ if ((0, __openid4vc_utils.zIs)(zSdJwtDcCredentialIssuerMetadata, credentialConfiguration)) throw new Openid4vciError(`Credential configuration id '${options.credentialConfigurationId}' with format ${zLegacySdJwtVcFormatIdentifier.value} does not support credential request based on 'format'. Use 'credential_configuration_id' directly.`);
954
+ if ((0, __openid4vc_utils.zIs)(zSdJwtW3VcCredentialIssuerMetadata, credentialConfiguration)) return {
955
+ format: credentialConfiguration.format,
956
+ credential_definition: { type: credentialConfiguration.credential_definition.type }
957
+ };
958
+ throw new Openid4vciError(`Unknown format '${credentialConfiguration.format}' in credential configuration with id '${options.credentialConfigurationId}' for credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`);
1264
959
  }
1265
960
 
1266
- // src/credential-request/retrieve-credentials.ts
1267
- var import_oauth213 = require("@openid4vc/oauth2");
1268
- var import_utils12 = require("@openid4vc/utils");
1269
-
1270
- // src/credential-request/z-credential-request.ts
1271
- var import_oauth212 = require("@openid4vc/oauth2");
1272
- var import_zod17 = __toESM(require("zod"));
1273
-
1274
- // src/credential-request/z-credential-request-common.ts
1275
- var import_oauth211 = require("@openid4vc/oauth2");
1276
- var import_zod16 = __toESM(require("zod"));
1277
-
1278
- // src/formats/proof-type/jwt/z-jwt-proof-type.ts
1279
- var import_oauth29 = require("@openid4vc/oauth2");
1280
- var import_utils11 = require("@openid4vc/utils");
1281
- var import_zod14 = __toESM(require("zod"));
1282
- var zJwtProofTypeIdentifier = import_zod14.default.literal("jwt");
1283
- var jwtProofTypeIdentifier = zJwtProofTypeIdentifier.value;
1284
- var zCredentialRequestProofJwt = import_zod14.default.object({
1285
- proof_type: zJwtProofTypeIdentifier,
1286
- jwt: import_oauth29.zCompactJwt
961
+ //#endregion
962
+ //#region src/formats/proof-type/attestation/z-attestation-proof-type.ts
963
+ const zAttestationProofTypeIdentifier = zod.default.literal("attestation");
964
+ const attestationProofTypeIdentifier = zAttestationProofTypeIdentifier.value;
965
+ const zCredentialRequestProofAttestation = zod.default.object({
966
+ proof_type: zAttestationProofTypeIdentifier,
967
+ attestation: __openid4vc_oauth2.zCompactJwt
1287
968
  });
1288
- var zCredentialRequestJwtProofTypeHeader = import_oauth29.zJwtHeader.merge(
1289
- import_zod14.default.object({
1290
- key_attestation: import_zod14.default.optional(import_oauth29.zCompactJwt),
1291
- typ: import_zod14.default.literal("openid4vci-proof+jwt")
1292
- })
1293
- ).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
1294
- message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
1295
- }).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
1296
- message: `When 'trust_chain' is provided, 'kid' is required`
1297
- });
1298
- var zCredentialRequestJwtProofTypePayload = import_zod14.default.object({
1299
- ...import_oauth29.zJwtPayload.shape,
1300
- aud: import_utils11.zHttpsUrl,
1301
- iat: import_utils11.zInteger
1302
- }).passthrough();
969
+ const zCredentialRequestAttestationProofTypePayload = zKeyAttestationJwtPayloadForUse("proof_type.attestation");
1303
970
 
1304
- // src/formats/proof-type/attestation/z-attestation-proof-type.ts
1305
- var import_oauth210 = require("@openid4vc/oauth2");
1306
- var import_zod15 = __toESM(require("zod"));
1307
- var zAttestationProofTypeIdentifier = import_zod15.default.literal("attestation");
1308
- var attestationProofTypeIdentifier = zAttestationProofTypeIdentifier.value;
1309
- var zCredentialRequestProofAttestation = import_zod15.default.object({
1310
- proof_type: zAttestationProofTypeIdentifier,
1311
- attestation: import_oauth210.zCompactJwt
971
+ //#endregion
972
+ //#region src/formats/proof-type/jwt/z-jwt-proof-type.ts
973
+ const zJwtProofTypeIdentifier = zod.default.literal("jwt");
974
+ const jwtProofTypeIdentifier = zJwtProofTypeIdentifier.value;
975
+ const zCredentialRequestProofJwt = zod.default.object({
976
+ proof_type: zJwtProofTypeIdentifier,
977
+ jwt: __openid4vc_oauth2.zCompactJwt
1312
978
  });
1313
- var zCredentialRequestAttestationProofTypePayload = zKeyAttestationJwtPayloadForUse("proof_type.attestation");
1314
-
1315
- // src/credential-request/z-credential-request-common.ts
1316
- var zCredentialRequestProofCommon = import_zod16.default.object({
1317
- proof_type: import_zod16.default.string()
979
+ const zCredentialRequestJwtProofTypeHeader = __openid4vc_oauth2.zJwtHeader.merge(zod.default.object({
980
+ key_attestation: zod.default.optional(__openid4vc_oauth2.zCompactJwt),
981
+ typ: zod.default.literal("openid4vci-proof+jwt")
982
+ })).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, { message: `Both 'jwk' and 'kid' are defined. Only one is allowed` }).refine(({ trust_chain, kid }) => !trust_chain || !kid, { message: `When 'trust_chain' is provided, 'kid' is required` });
983
+ const zCredentialRequestJwtProofTypePayload = zod.default.object({
984
+ ...__openid4vc_oauth2.zJwtPayload.shape,
985
+ aud: __openid4vc_utils.zHttpsUrl,
986
+ iat: __openid4vc_utils.zInteger
1318
987
  }).passthrough();
1319
- var allCredentialRequestProofs = [zCredentialRequestProofJwt, zCredentialRequestProofAttestation];
1320
- var zCredentialRequestProof = import_zod16.default.union([
1321
- zCredentialRequestProofCommon,
1322
- import_zod16.default.discriminatedUnion("proof_type", allCredentialRequestProofs)
1323
- ]);
1324
- var zCredentialRequestProofsCommon = import_zod16.default.record(import_zod16.default.string(), import_zod16.default.array(import_zod16.default.unknown()));
1325
- var zCredentialRequestProofs = import_zod16.default.object({
1326
- [zJwtProofTypeIdentifier.value]: import_zod16.default.optional(import_zod16.default.array(zCredentialRequestProofJwt.shape.jwt)),
1327
- [zAttestationProofTypeIdentifier.value]: import_zod16.default.optional(import_zod16.default.array(zCredentialRequestProofAttestation.shape.attestation))
1328
- });
1329
- var zCredentialRequestCommon = import_zod16.default.object({
1330
- proof: zCredentialRequestProof.optional(),
1331
- proofs: import_zod16.default.optional(
1332
- import_zod16.default.intersection(zCredentialRequestProofsCommon, zCredentialRequestProofs).refine((proofs) => Object.values(proofs).length === 1, {
1333
- message: `The 'proofs' object in a credential request should contain exactly one attribute`
1334
- })
1335
- ),
1336
- credential_response_encryption: import_zod16.default.object({
1337
- jwk: import_oauth211.zJwk,
1338
- alg: import_zod16.default.string(),
1339
- enc: import_zod16.default.string()
1340
- }).passthrough().optional()
1341
- }).passthrough().refine(({ proof, proofs }) => !(proof !== void 0 && proofs !== void 0), {
1342
- message: `Both 'proof' and 'proofs' are defined. Only one is allowed`
988
+
989
+ //#endregion
990
+ //#region src/credential-request/z-credential-request-common.ts
991
+ const zCredentialRequestProofCommon = zod.default.object({ proof_type: zod.default.string() }).passthrough();
992
+ const allCredentialRequestProofs = [zCredentialRequestProofJwt, zCredentialRequestProofAttestation];
993
+ const zCredentialRequestProof = zod.default.union([zCredentialRequestProofCommon, zod.default.discriminatedUnion("proof_type", allCredentialRequestProofs)]);
994
+ const zCredentialRequestProofsCommon = zod.default.record(zod.default.string(), zod.default.array(zod.default.unknown()));
995
+ const zCredentialRequestProofs = zod.default.object({
996
+ [zJwtProofTypeIdentifier.value]: zod.default.optional(zod.default.array(zCredentialRequestProofJwt.shape.jwt)),
997
+ [zAttestationProofTypeIdentifier.value]: zod.default.optional(zod.default.array(zCredentialRequestProofAttestation.shape.attestation))
1343
998
  });
999
+ const zCredentialRequestCommon = zod.default.object({
1000
+ proof: zCredentialRequestProof.optional(),
1001
+ proofs: zod.default.optional(zod.default.intersection(zCredentialRequestProofsCommon, zCredentialRequestProofs).refine((proofs) => Object.values(proofs).length === 1, { message: `The 'proofs' object in a credential request should contain exactly one attribute` })),
1002
+ credential_response_encryption: zod.default.object({
1003
+ jwk: __openid4vc_oauth2.zJwk,
1004
+ alg: zod.default.string(),
1005
+ enc: zod.default.string()
1006
+ }).passthrough().optional()
1007
+ }).passthrough().refine(({ proof, proofs }) => !(proof !== void 0 && proofs !== void 0), { message: `Both 'proof' and 'proofs' are defined. Only one is allowed` });
1344
1008
 
1345
- // src/credential-request/z-credential-request.ts
1346
- var allCredentialRequestFormats = [
1347
- zSdJwtW3VcCredentialRequestFormatDraft14,
1348
- zMsoMdocCredentialRequestFormatDraft14,
1349
- zLdpVcCredentialRequestFormatDraft14,
1350
- zJwtVcJsonLdCredentialRequestFormatDraft14,
1351
- zJwtVcJsonCredentialRequestFormatDraft14,
1352
- zLegacySdJwtVcCredentialRequestFormatDraft14
1009
+ //#endregion
1010
+ //#region src/credential-request/z-credential-request.ts
1011
+ const allCredentialRequestFormats = [
1012
+ zSdJwtW3VcCredentialRequestFormatDraft14,
1013
+ zMsoMdocCredentialRequestFormatDraft14,
1014
+ zLdpVcCredentialRequestFormatDraft14,
1015
+ zJwtVcJsonLdCredentialRequestFormatDraft14,
1016
+ zJwtVcJsonCredentialRequestFormatDraft14,
1017
+ zLegacySdJwtVcCredentialRequestFormatDraft14
1353
1018
  ];
1354
- var allCredentialRequestFormatIdentifiers = allCredentialRequestFormats.map(
1355
- (format) => format.shape.format.value
1356
- );
1357
- var zCredentialRequestCredentialConfigurationId = import_zod17.default.object({
1358
- credential_configuration_id: import_zod17.default.string(),
1359
- format: import_zod17.default.never({ message: "'format' cannot be defined when 'credential_configuration_id' is set." }).optional(),
1360
- credential_identifier: import_zod17.default.never({ message: "'credential_identifier' cannot be defined when 'credential_configuration_id' is set." }).optional()
1019
+ const allCredentialRequestFormatIdentifiers = allCredentialRequestFormats.map((format) => format.shape.format.value);
1020
+ const zCredentialRequestCredentialConfigurationId = zod.default.object({
1021
+ credential_configuration_id: zod.default.string(),
1022
+ format: zod.default.never({ message: "'format' cannot be defined when 'credential_configuration_id' is set." }).optional(),
1023
+ credential_identifier: zod.default.never({ message: "'credential_identifier' cannot be defined when 'credential_configuration_id' is set." }).optional()
1361
1024
  });
1362
- var zAuthorizationDetailsCredentialRequest = import_zod17.default.object({
1363
- credential_identifier: import_zod17.default.string(),
1364
- credential_configuration_id: import_zod17.default.never({ message: "'credential_configuration_id' cannot be defined when 'credential_identifier' is set." }).optional(),
1365
- // Cannot be present if credential identifier is present
1366
- format: import_zod17.default.never({ message: "'format' cannot be defined when 'credential_identifier' is set." }).optional()
1025
+ const zAuthorizationDetailsCredentialRequest = zod.default.object({
1026
+ credential_identifier: zod.default.string(),
1027
+ credential_configuration_id: zod.default.never({ message: "'credential_configuration_id' cannot be defined when 'credential_identifier' is set." }).optional(),
1028
+ format: zod.default.never({ message: "'format' cannot be defined when 'credential_identifier' is set." }).optional()
1367
1029
  });
1368
- var zCredentialRequestFormat = import_zod17.default.object({
1369
- format: import_zod17.default.string(),
1370
- credential_identifier: import_zod17.default.never({ message: "'credential_identifier' cannot be defined when 'format' is set." }).optional(),
1371
- credential_configuration_id: import_zod17.default.never({ message: "'credential_configuration_id' cannot be defined when 'format' is set." }).optional()
1030
+ const zCredentialRequestFormat = zod.default.object({
1031
+ format: zod.default.string(),
1032
+ credential_identifier: zod.default.never({ message: "'credential_identifier' cannot be defined when 'format' is set." }).optional(),
1033
+ credential_configuration_id: zod.default.never({ message: "'credential_configuration_id' cannot be defined when 'format' is set." }).optional()
1372
1034
  }).passthrough();
1373
- var zCredentialRequestDraft14WithFormat = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1374
- if (!allCredentialRequestFormatIdentifiers.includes(
1375
- data.format
1376
- ))
1377
- return data;
1378
- const result = import_zod17.default.object({}).passthrough().and(import_zod17.default.union(allCredentialRequestFormats)).safeParse(data);
1379
- if (result.success) {
1380
- return result.data;
1381
- }
1382
- for (const issue of result.error.issues) {
1383
- ctx.addIssue(issue);
1384
- }
1385
- return import_zod17.default.NEVER;
1035
+ const zCredentialRequestDraft14WithFormat = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1036
+ if (!allCredentialRequestFormatIdentifiers.includes(data.format)) return data;
1037
+ const result = zod.default.object({}).passthrough().and(zod.default.union(allCredentialRequestFormats)).safeParse(data);
1038
+ if (result.success) return result.data;
1039
+ for (const issue of result.error.issues) ctx.addIssue(issue);
1040
+ return zod.default.NEVER;
1386
1041
  });
1387
- var zCredentialRequestDraft15 = import_zod17.default.union([
1388
- zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest),
1389
- zCredentialRequestCommon.and(zCredentialRequestCredentialConfigurationId)
1390
- ]);
1391
- var zCredentialRequestDraft14 = import_zod17.default.union([
1392
- zCredentialRequestDraft14WithFormat,
1393
- zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest)
1394
- ]);
1395
- var zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1396
- const formatSpecificTransformations = {
1397
- [zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft11To14,
1398
- [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft11To14,
1399
- [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialRequestDraft11To14
1400
- };
1401
- if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
1402
- const schema = formatSpecificTransformations[data.format];
1403
- const result = schema.safeParse(data);
1404
- if (result.success) return result.data;
1405
- for (const issue of result.error.issues) {
1406
- ctx.addIssue(issue);
1407
- }
1408
- return import_zod17.default.NEVER;
1042
+ const zCredentialRequestDraft15 = zod.default.union([zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest), zCredentialRequestCommon.and(zCredentialRequestCredentialConfigurationId)]);
1043
+ const zCredentialRequestDraft14 = zod.default.union([zCredentialRequestDraft14WithFormat, zCredentialRequestCommon.and(zAuthorizationDetailsCredentialRequest)]);
1044
+ const zCredentialRequestDraft11To14 = zCredentialRequestCommon.and(zCredentialRequestFormat).transform((data, ctx) => {
1045
+ const formatSpecificTransformations = {
1046
+ [zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft11To14,
1047
+ [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft11To14,
1048
+ [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialRequestDraft11To14
1049
+ };
1050
+ if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
1051
+ const result = formatSpecificTransformations[data.format].safeParse(data);
1052
+ if (result.success) return result.data;
1053
+ for (const issue of result.error.issues) ctx.addIssue(issue);
1054
+ return zod.default.NEVER;
1409
1055
  }).pipe(zCredentialRequestDraft14);
1410
- var zCredentialRequestDraft14To11 = zCredentialRequestDraft14.refine(
1411
- (data) => data.credential_identifier === void 0,
1412
- `'credential_identifier' is not supported in OpenID4VCI draft 11`
1413
- ).transform((data, ctx) => {
1414
- const formatSpecificTransformations = {
1415
- [zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft14To11,
1416
- [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft14To11,
1417
- [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialRequestDraft14To11
1418
- };
1419
- if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
1420
- const schema = formatSpecificTransformations[data.format];
1421
- const result = schema.safeParse(data);
1422
- if (result.success) return result.data;
1423
- for (const issue of result.error.issues) {
1424
- ctx.addIssue(issue);
1425
- }
1426
- return import_zod17.default.NEVER;
1056
+ const zCredentialRequestDraft14To11 = zCredentialRequestDraft14.refine((data) => data.credential_identifier === void 0, `'credential_identifier' is not supported in OpenID4VCI draft 11`).transform((data, ctx) => {
1057
+ const formatSpecificTransformations = {
1058
+ [zLdpVcFormatIdentifier.value]: zLdpVcCredentialRequestDraft14To11,
1059
+ [zJwtVcJsonFormatIdentifier.value]: zJwtVcJsonCredentialRequestDraft14To11,
1060
+ [zJwtVcJsonLdFormatIdentifier.value]: zJwtVcJsonLdCredentialRequestDraft14To11
1061
+ };
1062
+ if (!Object.keys(formatSpecificTransformations).includes(data.format)) return data;
1063
+ const result = formatSpecificTransformations[data.format].safeParse(data);
1064
+ if (result.success) return result.data;
1065
+ for (const issue of result.error.issues) ctx.addIssue(issue);
1066
+ return zod.default.NEVER;
1427
1067
  });
1428
- var zCredentialRequest = import_zod17.default.union([
1429
- zCredentialRequestDraft15,
1430
- zCredentialRequestDraft14,
1431
- zCredentialRequestDraft11To14
1068
+ const zCredentialRequest = zod.default.union([
1069
+ zCredentialRequestDraft15,
1070
+ zCredentialRequestDraft14,
1071
+ zCredentialRequestDraft11To14
1432
1072
  ]);
1433
- var zDeferredCredentialRequest = import_zod17.default.object({
1434
- transaction_id: import_zod17.default.string().nonempty(),
1435
- credential_response_encryption: import_zod17.default.object({
1436
- jwk: import_oauth212.zJwk,
1437
- alg: import_zod17.default.string(),
1438
- enc: import_zod17.default.string()
1439
- }).passthrough().optional()
1073
+ const zDeferredCredentialRequest = zod.default.object({
1074
+ transaction_id: zod.default.string().nonempty(),
1075
+ credential_response_encryption: zod.default.object({
1076
+ jwk: __openid4vc_oauth2.zJwk,
1077
+ alg: zod.default.string(),
1078
+ enc: zod.default.string()
1079
+ }).passthrough().optional()
1440
1080
  });
1441
1081
 
1442
- // src/credential-request/z-credential-response.ts
1443
- var import_zod19 = __toESM(require("zod"));
1444
-
1445
- // ../oauth2/src/common/z-oauth2-error.ts
1446
- var import_zod18 = __toESM(require("zod"));
1447
- var Oauth2ErrorCodes = /* @__PURE__ */ ((Oauth2ErrorCodes4) => {
1448
- Oauth2ErrorCodes4["ServerError"] = "server_error";
1449
- Oauth2ErrorCodes4["InvalidTarget"] = "invalid_target";
1450
- Oauth2ErrorCodes4["InvalidRequest"] = "invalid_request";
1451
- Oauth2ErrorCodes4["InvalidToken"] = "invalid_token";
1452
- Oauth2ErrorCodes4["InsufficientScope"] = "insufficient_scope";
1453
- Oauth2ErrorCodes4["InvalidGrant"] = "invalid_grant";
1454
- Oauth2ErrorCodes4["InvalidClient"] = "invalid_client";
1455
- Oauth2ErrorCodes4["UnauthorizedClient"] = "unauthorized_client";
1456
- Oauth2ErrorCodes4["UnsupportedGrantType"] = "unsupported_grant_type";
1457
- Oauth2ErrorCodes4["InvalidScope"] = "invalid_scope";
1458
- Oauth2ErrorCodes4["InvalidDpopProof"] = "invalid_dpop_proof";
1459
- Oauth2ErrorCodes4["UseDpopNonce"] = "use_dpop_nonce";
1460
- Oauth2ErrorCodes4["RedirectToWeb"] = "redirect_to_web";
1461
- Oauth2ErrorCodes4["InvalidSession"] = "invalid_session";
1462
- Oauth2ErrorCodes4["InsufficientAuthorization"] = "insufficient_authorization";
1463
- Oauth2ErrorCodes4["InvalidCredentialRequest"] = "invalid_credential_request";
1464
- Oauth2ErrorCodes4["CredentialRequestDenied"] = "credential_request_denied";
1465
- Oauth2ErrorCodes4["InvalidProof"] = "invalid_proof";
1466
- Oauth2ErrorCodes4["InvalidNonce"] = "invalid_nonce";
1467
- Oauth2ErrorCodes4["InvalidEncryptionParameters"] = "invalid_encryption_parameters";
1468
- Oauth2ErrorCodes4["UnknownCredentialConfiguration"] = "unknown_credential_configuration";
1469
- Oauth2ErrorCodes4["UnknownCredentialIdentifier"] = "unknown_credential_identifier";
1470
- Oauth2ErrorCodes4["InvalidTransactionId"] = "invalid_transaction_id";
1471
- Oauth2ErrorCodes4["UnsupportedCredentialType"] = "unsupported_credential_type";
1472
- Oauth2ErrorCodes4["UnsupportedCredentialFormat"] = "unsupported_credential_format";
1473
- Oauth2ErrorCodes4["InvalidRequestUri"] = "invalid_request_uri";
1474
- Oauth2ErrorCodes4["InvalidRequestObject"] = "invalid_request_object";
1475
- Oauth2ErrorCodes4["RequestNotSupported"] = "request_not_supported";
1476
- Oauth2ErrorCodes4["RequestUriNotSupported"] = "request_uri_not_supported";
1477
- Oauth2ErrorCodes4["VpFormatsNotSupported"] = "vp_formats_not_supported";
1478
- Oauth2ErrorCodes4["AccessDenied"] = "access_denied";
1479
- Oauth2ErrorCodes4["InvalidPresentationDefinitionUri"] = "invalid_presentation_definition_uri";
1480
- Oauth2ErrorCodes4["InvalidPresentationDefinitionReference"] = "invalid_presentation_definition_reference";
1481
- Oauth2ErrorCodes4["InvalidRequestUriMethod"] = "invalid_request_uri_method";
1482
- Oauth2ErrorCodes4["InvalidTransactionData"] = "invalid_transaction_data";
1483
- Oauth2ErrorCodes4["WalletUnavailable"] = "wallet_unavailable";
1484
- return Oauth2ErrorCodes4;
1485
- })(Oauth2ErrorCodes || {});
1486
- var zOauth2ErrorResponse = import_zod18.default.object({
1487
- error: import_zod18.default.union([import_zod18.default.nativeEnum(Oauth2ErrorCodes), import_zod18.default.string()]),
1488
- error_description: import_zod18.default.string().optional(),
1489
- error_uri: import_zod18.default.string().optional()
1082
+ //#endregion
1083
+ //#region ../oauth2/src/common/z-oauth2-error.ts
1084
+ let Oauth2ErrorCodes$2 = /* @__PURE__ */ function(Oauth2ErrorCodes$3) {
1085
+ Oauth2ErrorCodes$3["ServerError"] = "server_error";
1086
+ Oauth2ErrorCodes$3["InvalidTarget"] = "invalid_target";
1087
+ Oauth2ErrorCodes$3["InvalidRequest"] = "invalid_request";
1088
+ Oauth2ErrorCodes$3["InvalidToken"] = "invalid_token";
1089
+ Oauth2ErrorCodes$3["InsufficientScope"] = "insufficient_scope";
1090
+ Oauth2ErrorCodes$3["InvalidGrant"] = "invalid_grant";
1091
+ Oauth2ErrorCodes$3["InvalidClient"] = "invalid_client";
1092
+ Oauth2ErrorCodes$3["UnauthorizedClient"] = "unauthorized_client";
1093
+ Oauth2ErrorCodes$3["UnsupportedGrantType"] = "unsupported_grant_type";
1094
+ Oauth2ErrorCodes$3["InvalidScope"] = "invalid_scope";
1095
+ Oauth2ErrorCodes$3["InvalidDpopProof"] = "invalid_dpop_proof";
1096
+ Oauth2ErrorCodes$3["UseDpopNonce"] = "use_dpop_nonce";
1097
+ Oauth2ErrorCodes$3["RedirectToWeb"] = "redirect_to_web";
1098
+ Oauth2ErrorCodes$3["InvalidSession"] = "invalid_session";
1099
+ Oauth2ErrorCodes$3["InsufficientAuthorization"] = "insufficient_authorization";
1100
+ Oauth2ErrorCodes$3["InvalidCredentialRequest"] = "invalid_credential_request";
1101
+ Oauth2ErrorCodes$3["CredentialRequestDenied"] = "credential_request_denied";
1102
+ Oauth2ErrorCodes$3["InvalidProof"] = "invalid_proof";
1103
+ Oauth2ErrorCodes$3["InvalidNonce"] = "invalid_nonce";
1104
+ Oauth2ErrorCodes$3["InvalidEncryptionParameters"] = "invalid_encryption_parameters";
1105
+ Oauth2ErrorCodes$3["UnknownCredentialConfiguration"] = "unknown_credential_configuration";
1106
+ Oauth2ErrorCodes$3["UnknownCredentialIdentifier"] = "unknown_credential_identifier";
1107
+ Oauth2ErrorCodes$3["InvalidTransactionId"] = "invalid_transaction_id";
1108
+ Oauth2ErrorCodes$3["UnsupportedCredentialType"] = "unsupported_credential_type";
1109
+ Oauth2ErrorCodes$3["UnsupportedCredentialFormat"] = "unsupported_credential_format";
1110
+ Oauth2ErrorCodes$3["InvalidRequestUri"] = "invalid_request_uri";
1111
+ Oauth2ErrorCodes$3["InvalidRequestObject"] = "invalid_request_object";
1112
+ Oauth2ErrorCodes$3["RequestNotSupported"] = "request_not_supported";
1113
+ Oauth2ErrorCodes$3["RequestUriNotSupported"] = "request_uri_not_supported";
1114
+ Oauth2ErrorCodes$3["VpFormatsNotSupported"] = "vp_formats_not_supported";
1115
+ Oauth2ErrorCodes$3["AccessDenied"] = "access_denied";
1116
+ Oauth2ErrorCodes$3["InvalidPresentationDefinitionUri"] = "invalid_presentation_definition_uri";
1117
+ Oauth2ErrorCodes$3["InvalidPresentationDefinitionReference"] = "invalid_presentation_definition_reference";
1118
+ Oauth2ErrorCodes$3["InvalidRequestUriMethod"] = "invalid_request_uri_method";
1119
+ Oauth2ErrorCodes$3["InvalidTransactionData"] = "invalid_transaction_data";
1120
+ Oauth2ErrorCodes$3["WalletUnavailable"] = "wallet_unavailable";
1121
+ return Oauth2ErrorCodes$3;
1122
+ }({});
1123
+ const zOauth2ErrorResponse = zod.default.object({
1124
+ error: zod.default.union([zod.default.nativeEnum(Oauth2ErrorCodes$2), zod.default.string()]),
1125
+ error_description: zod.default.string().optional(),
1126
+ error_uri: zod.default.string().optional()
1490
1127
  }).passthrough();
1491
1128
 
1492
- // src/credential-request/z-credential-response.ts
1493
- var zCredentialEncoding = import_zod19.default.union([import_zod19.default.string(), import_zod19.default.record(import_zod19.default.string(), import_zod19.default.any())]);
1494
- var zBaseCredentialResponse = import_zod19.default.object({
1495
- credentials: import_zod19.default.union([
1496
- // Draft >= 15
1497
- import_zod19.default.array(import_zod19.default.object({ credential: zCredentialEncoding })),
1498
- // Draft < 15
1499
- import_zod19.default.array(zCredentialEncoding)
1500
- ]).optional(),
1501
- interval: import_zod19.default.number().int().positive().optional(),
1502
- notification_id: import_zod19.default.string().optional()
1129
+ //#endregion
1130
+ //#region src/credential-request/z-credential-response.ts
1131
+ const zCredentialEncoding = zod.default.union([zod.default.string(), zod.default.record(zod.default.string(), zod.default.any())]);
1132
+ const zBaseCredentialResponse = zod.default.object({
1133
+ credentials: zod.default.union([zod.default.array(zod.default.object({ credential: zCredentialEncoding })), zod.default.array(zCredentialEncoding)]).optional(),
1134
+ interval: zod.default.number().int().positive().optional(),
1135
+ notification_id: zod.default.string().optional()
1503
1136
  }).passthrough();
1504
- var zCredentialResponse = zBaseCredentialResponse.extend({
1505
- credential: import_zod19.default.optional(zCredentialEncoding),
1506
- transaction_id: import_zod19.default.string().optional(),
1507
- c_nonce: import_zod19.default.string().optional(),
1508
- c_nonce_expires_in: import_zod19.default.number().int().optional()
1137
+ const zCredentialResponse = zBaseCredentialResponse.extend({
1138
+ credential: zod.default.optional(zCredentialEncoding),
1139
+ transaction_id: zod.default.string().optional(),
1140
+ c_nonce: zod.default.string().optional(),
1141
+ c_nonce_expires_in: zod.default.number().int().optional()
1509
1142
  }).passthrough().superRefine((value, ctx) => {
1510
- const { credential, credentials, transaction_id, interval, notification_id } = value;
1511
- if ([credential, credentials, transaction_id].filter((i) => i !== void 0).length !== 1) {
1512
- ctx.addIssue({
1513
- code: import_zod19.default.ZodIssueCode.custom,
1514
- message: `Exactly one of 'credential', 'credentials', or 'transaction_id' MUST be defined.`
1515
- });
1516
- }
1517
- if (transaction_id && !interval) {
1518
- ctx.addIssue({
1519
- code: import_zod19.default.ZodIssueCode.custom,
1520
- message: `'interval' MUST be defined when 'transaction_id' is defined.`
1521
- });
1522
- }
1523
- if (notification_id && !(credentials || credential)) {
1524
- ctx.addIssue({
1525
- code: import_zod19.default.ZodIssueCode.custom,
1526
- message: `'notification_id' MUST NOT be defined when 'credential' or 'credentials' are not defined.`
1527
- });
1528
- }
1143
+ const { credential, credentials, transaction_id, interval, notification_id } = value;
1144
+ if ([
1145
+ credential,
1146
+ credentials,
1147
+ transaction_id
1148
+ ].filter((i) => i !== void 0).length !== 1) ctx.addIssue({
1149
+ code: zod.default.ZodIssueCode.custom,
1150
+ message: `Exactly one of 'credential', 'credentials', or 'transaction_id' MUST be defined.`
1151
+ });
1152
+ if (transaction_id && !interval) ctx.addIssue({
1153
+ code: zod.default.ZodIssueCode.custom,
1154
+ message: `'interval' MUST be defined when 'transaction_id' is defined.`
1155
+ });
1156
+ if (notification_id && !(credentials || credential)) ctx.addIssue({
1157
+ code: zod.default.ZodIssueCode.custom,
1158
+ message: `'notification_id' MUST NOT be defined when 'credential' or 'credentials' are not defined.`
1159
+ });
1529
1160
  });
1530
- var zCredentialErrorResponse = import_zod19.default.object({
1531
- ...zOauth2ErrorResponse.shape,
1532
- c_nonce: import_zod19.default.string().optional(),
1533
- c_nonce_expires_in: import_zod19.default.number().int().optional()
1161
+ const zCredentialErrorResponse = zod.default.object({
1162
+ ...zOauth2ErrorResponse.shape,
1163
+ c_nonce: zod.default.string().optional(),
1164
+ c_nonce_expires_in: zod.default.number().int().optional()
1534
1165
  }).passthrough();
1535
- var zDeferredCredentialResponse = zBaseCredentialResponse.refine(
1536
- (value) => {
1537
- const { credentials, interval } = value;
1538
- return [credentials, interval].filter((i) => i !== void 0).length === 1;
1539
- },
1540
- {
1541
- message: `Exactly one of 'credentials' or 'interval' MUST be defined.`
1542
- }
1543
- );
1166
+ const zDeferredCredentialResponse = zBaseCredentialResponse.refine((value) => {
1167
+ const { credentials, interval } = value;
1168
+ return [credentials, interval].filter((i) => i !== void 0).length === 1;
1169
+ }, { message: `Exactly one of 'credentials' or 'interval' MUST be defined.` });
1544
1170
 
1545
- // src/credential-request/retrieve-credentials.ts
1171
+ //#endregion
1172
+ //#region src/credential-request/retrieve-credentials.ts
1546
1173
  async function retrieveCredentialsWithCredentialConfigurationId(options) {
1547
- if (options.issuerMetadata.originalDraftVersion !== "Draft15" /* Draft15 */ && options.issuerMetadata.originalDraftVersion !== "Draft16" /* Draft16 */) {
1548
- throw new Openid4vciError(
1549
- "Requesting credentials based on credential configuration ID is not supported in OpenID4VCI below draft 15. Make sure to provide the format and format specific claims in the request."
1550
- );
1551
- }
1552
- getCredentialConfigurationSupportedById(
1553
- options.issuerMetadata.credentialIssuer.credential_configurations_supported,
1554
- options.credentialConfigurationId
1555
- );
1556
- const credentialRequest = {
1557
- ...options.additionalRequestPayload,
1558
- credential_configuration_id: options.credentialConfigurationId,
1559
- proof: options.proof,
1560
- proofs: options.proofs
1561
- };
1562
- return retrieveCredentials({
1563
- callbacks: options.callbacks,
1564
- credentialRequest,
1565
- issuerMetadata: options.issuerMetadata,
1566
- accessToken: options.accessToken,
1567
- dpop: options.dpop
1568
- });
1174
+ if (options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.Draft15 && options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.Draft16) throw new Openid4vciError("Requesting credentials based on credential configuration ID is not supported in OpenID4VCI below draft 15. Make sure to provide the format and format specific claims in the request.");
1175
+ getCredentialConfigurationSupportedById(options.issuerMetadata.credentialIssuer.credential_configurations_supported, options.credentialConfigurationId);
1176
+ const credentialRequest = {
1177
+ ...options.additionalRequestPayload,
1178
+ credential_configuration_id: options.credentialConfigurationId,
1179
+ proof: options.proof,
1180
+ proofs: options.proofs
1181
+ };
1182
+ return retrieveCredentials({
1183
+ callbacks: options.callbacks,
1184
+ credentialRequest,
1185
+ issuerMetadata: options.issuerMetadata,
1186
+ accessToken: options.accessToken,
1187
+ dpop: options.dpop
1188
+ });
1569
1189
  }
1570
1190
  async function retrieveCredentialsWithFormat(options) {
1571
- if (options.issuerMetadata.originalDraftVersion === "Draft15" /* Draft15 */ || options.issuerMetadata.originalDraftVersion === "Draft16" /* Draft16 */) {
1572
- throw new Openid4vciError(
1573
- "Requesting credentials based on format is not supported in OpenID4VCI draft 15. Provide the credential configuration id directly in the request."
1574
- );
1575
- }
1576
- const credentialRequest = {
1577
- ...options.formatPayload,
1578
- ...options.additionalRequestPayload,
1579
- proof: options.proof,
1580
- proofs: options.proofs
1581
- };
1582
- return retrieveCredentials({
1583
- callbacks: options.callbacks,
1584
- credentialRequest,
1585
- issuerMetadata: options.issuerMetadata,
1586
- accessToken: options.accessToken,
1587
- dpop: options.dpop
1588
- });
1191
+ if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft16) throw new Openid4vciError("Requesting credentials based on format is not supported in OpenID4VCI draft 15. Provide the credential configuration id directly in the request.");
1192
+ const credentialRequest = {
1193
+ ...options.formatPayload,
1194
+ ...options.additionalRequestPayload,
1195
+ proof: options.proof,
1196
+ proofs: options.proofs
1197
+ };
1198
+ return retrieveCredentials({
1199
+ callbacks: options.callbacks,
1200
+ credentialRequest,
1201
+ issuerMetadata: options.issuerMetadata,
1202
+ accessToken: options.accessToken,
1203
+ dpop: options.dpop
1204
+ });
1589
1205
  }
1206
+ /**
1207
+ * internal method
1208
+ */
1590
1209
  async function retrieveCredentials(options) {
1591
- const credentialEndpoint = options.issuerMetadata.credentialIssuer.credential_endpoint;
1592
- let credentialRequest = (0, import_utils12.parseWithErrorHandling)(
1593
- zCredentialRequest,
1594
- options.credentialRequest,
1595
- "Error validating credential request"
1596
- );
1597
- if (credentialRequest.proofs) {
1598
- const { batch_credential_issuance } = options.issuerMetadata.credentialIssuer;
1599
- if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
1600
- throw new import_oauth213.Oauth2Error(
1601
- `Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not support batch credential issuance using the 'proofs' request property. Only 'proof' is supported.`
1602
- );
1603
- }
1604
- const proofs = Object.values(credentialRequest.proofs)[0];
1605
- if (proofs.length > (batch_credential_issuance?.batch_size ?? 1)) {
1606
- throw new import_oauth213.Oauth2Error(
1607
- `Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' supports batch issuance, but the max batch size is '${batch_credential_issuance?.batch_size ?? 1}'. A total of '${proofs.length}' proofs were provided.`
1608
- );
1609
- }
1610
- }
1611
- if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
1612
- credentialRequest = (0, import_utils12.parseWithErrorHandling)(
1613
- zCredentialRequestDraft14To11,
1614
- credentialRequest,
1615
- `Error transforming credential request from ${"Draft14" /* Draft14 */} to ${"Draft11" /* Draft11 */}`
1616
- );
1617
- }
1618
- const resourceResponse = await (0, import_oauth213.resourceRequest)({
1619
- dpop: options.dpop,
1620
- accessToken: options.accessToken,
1621
- callbacks: options.callbacks,
1622
- url: credentialEndpoint,
1623
- requestOptions: {
1624
- method: "POST",
1625
- headers: {
1626
- "Content-Type": import_utils12.ContentType.Json
1627
- },
1628
- body: JSON.stringify(credentialRequest)
1629
- }
1630
- });
1631
- if (!resourceResponse.ok) {
1632
- const credentialErrorResponseResult = (0, import_utils12.isResponseContentType)(import_utils12.ContentType.Json, resourceResponse.response) ? zCredentialErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1633
- return {
1634
- ...resourceResponse,
1635
- credentialErrorResponseResult
1636
- };
1637
- }
1638
- const credentialResponseResult = (0, import_utils12.isResponseContentType)(import_utils12.ContentType.Json, resourceResponse.response) ? zCredentialResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1639
- if (!credentialResponseResult?.success) {
1640
- return {
1641
- ...resourceResponse,
1642
- ok: false,
1643
- credentialResponseResult
1644
- };
1645
- }
1646
- return {
1647
- ...resourceResponse,
1648
- credentialResponse: credentialResponseResult.data
1649
- };
1210
+ const credentialEndpoint = options.issuerMetadata.credentialIssuer.credential_endpoint;
1211
+ let credentialRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialRequest, options.credentialRequest, "Error validating credential request");
1212
+ if (credentialRequest.proofs) {
1213
+ const { batch_credential_issuance } = options.issuerMetadata.credentialIssuer;
1214
+ if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft11) throw new __openid4vc_oauth2.Oauth2Error(`Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not support batch credential issuance using the 'proofs' request property. Only 'proof' is supported.`);
1215
+ const proofs = Object.values(credentialRequest.proofs)[0];
1216
+ if (proofs.length > (batch_credential_issuance?.batch_size ?? 1)) throw new __openid4vc_oauth2.Oauth2Error(`Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' supports batch issuance, but the max batch size is '${batch_credential_issuance?.batch_size ?? 1}'. A total of '${proofs.length}' proofs were provided.`);
1217
+ }
1218
+ if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft11) credentialRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialRequestDraft14To11, credentialRequest, `Error transforming credential request from ${Openid4vciDraftVersion.Draft14} to ${Openid4vciDraftVersion.Draft11}`);
1219
+ const resourceResponse = await (0, __openid4vc_oauth2.resourceRequest)({
1220
+ dpop: options.dpop,
1221
+ accessToken: options.accessToken,
1222
+ callbacks: options.callbacks,
1223
+ url: credentialEndpoint,
1224
+ requestOptions: {
1225
+ method: "POST",
1226
+ headers: { "Content-Type": __openid4vc_utils.ContentType.Json },
1227
+ body: JSON.stringify(credentialRequest)
1228
+ }
1229
+ });
1230
+ if (!resourceResponse.ok) {
1231
+ const credentialErrorResponseResult = (0, __openid4vc_utils.isResponseContentType)(__openid4vc_utils.ContentType.Json, resourceResponse.response) ? zCredentialErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1232
+ return {
1233
+ ...resourceResponse,
1234
+ credentialErrorResponseResult
1235
+ };
1236
+ }
1237
+ const credentialResponseResult = (0, __openid4vc_utils.isResponseContentType)(__openid4vc_utils.ContentType.Json, resourceResponse.response) ? zCredentialResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1238
+ if (!credentialResponseResult?.success) return {
1239
+ ...resourceResponse,
1240
+ ok: false,
1241
+ credentialResponseResult
1242
+ };
1243
+ return {
1244
+ ...resourceResponse,
1245
+ credentialResponse: credentialResponseResult.data
1246
+ };
1650
1247
  }
1651
1248
  async function retrieveDeferredCredentials(options) {
1652
- const credentialEndpoint = options.issuerMetadata.credentialIssuer.deferred_credential_endpoint;
1653
- if (!credentialEndpoint) {
1654
- throw new Openid4vciError(
1655
- `Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not support deferred credential retrieval.`
1656
- );
1657
- }
1658
- const deferredCredentialRequest = (0, import_utils12.parseWithErrorHandling)(
1659
- zDeferredCredentialRequest,
1660
- {
1661
- transaction_id: options.transactionId,
1662
- ...options.additionalRequestPayload
1663
- },
1664
- "Error validating deferred credential request"
1665
- );
1666
- const resourceResponse = await (0, import_oauth213.resourceRequest)({
1667
- dpop: options.dpop,
1668
- accessToken: options.accessToken,
1669
- callbacks: options.callbacks,
1670
- url: credentialEndpoint,
1671
- requestOptions: {
1672
- method: "POST",
1673
- headers: {
1674
- "Content-Type": import_utils12.ContentType.Json
1675
- },
1676
- body: JSON.stringify(deferredCredentialRequest)
1677
- }
1678
- });
1679
- if (!resourceResponse.ok) {
1680
- const deferredCredentialErrorResponseResult = (0, import_utils12.isResponseContentType)(import_utils12.ContentType.Json, resourceResponse.response) ? zCredentialErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1681
- return {
1682
- ...resourceResponse,
1683
- deferredCredentialErrorResponseResult
1684
- };
1685
- }
1686
- const deferredCredentialResponseResult = (0, import_utils12.isResponseContentType)(import_utils12.ContentType.Json, resourceResponse.response) ? zDeferredCredentialResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1687
- if (!deferredCredentialResponseResult?.success) {
1688
- return {
1689
- ...resourceResponse,
1690
- ok: false,
1691
- deferredCredentialResponseResult
1692
- };
1693
- }
1694
- return {
1695
- ...resourceResponse,
1696
- deferredCredentialResponse: deferredCredentialResponseResult.data
1697
- };
1249
+ const credentialEndpoint = options.issuerMetadata.credentialIssuer.deferred_credential_endpoint;
1250
+ if (!credentialEndpoint) throw new Openid4vciError(`Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not support deferred credential retrieval.`);
1251
+ const deferredCredentialRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zDeferredCredentialRequest, {
1252
+ transaction_id: options.transactionId,
1253
+ ...options.additionalRequestPayload
1254
+ }, "Error validating deferred credential request");
1255
+ const resourceResponse = await (0, __openid4vc_oauth2.resourceRequest)({
1256
+ dpop: options.dpop,
1257
+ accessToken: options.accessToken,
1258
+ callbacks: options.callbacks,
1259
+ url: credentialEndpoint,
1260
+ requestOptions: {
1261
+ method: "POST",
1262
+ headers: { "Content-Type": __openid4vc_utils.ContentType.Json },
1263
+ body: JSON.stringify(deferredCredentialRequest)
1264
+ }
1265
+ });
1266
+ if (!resourceResponse.ok) {
1267
+ const deferredCredentialErrorResponseResult = (0, __openid4vc_utils.isResponseContentType)(__openid4vc_utils.ContentType.Json, resourceResponse.response) ? zCredentialErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1268
+ return {
1269
+ ...resourceResponse,
1270
+ deferredCredentialErrorResponseResult
1271
+ };
1272
+ }
1273
+ const deferredCredentialResponseResult = (0, __openid4vc_utils.isResponseContentType)(__openid4vc_utils.ContentType.Json, resourceResponse.response) ? zDeferredCredentialResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1274
+ if (!deferredCredentialResponseResult?.success) return {
1275
+ ...resourceResponse,
1276
+ ok: false,
1277
+ deferredCredentialResponseResult
1278
+ };
1279
+ return {
1280
+ ...resourceResponse,
1281
+ deferredCredentialResponse: deferredCredentialResponseResult.data
1282
+ };
1698
1283
  }
1699
1284
 
1700
- // src/formats/proof-type/jwt/jwt-proof-type.ts
1701
- var import_oauth214 = require("@openid4vc/oauth2");
1702
- var import_oauth215 = require("@openid4vc/oauth2");
1703
- var import_utils13 = require("@openid4vc/utils");
1285
+ //#endregion
1286
+ //#region src/formats/proof-type/jwt/jwt-proof-type.ts
1704
1287
  async function createCredentialRequestJwtProof(options) {
1705
- const header = (0, import_utils13.parseWithErrorHandling)(zCredentialRequestJwtProofTypeHeader, {
1706
- ...(0, import_oauth214.jwtHeaderFromJwtSigner)(options.signer),
1707
- key_attestation: options.keyAttestationJwt,
1708
- typ: "openid4vci-proof+jwt"
1709
- });
1710
- const payload = (0, import_utils13.parseWithErrorHandling)(zCredentialRequestJwtProofTypePayload, {
1711
- nonce: options.nonce,
1712
- aud: options.credentialIssuer,
1713
- iat: (0, import_utils13.dateToSeconds)(options.issuedAt),
1714
- iss: options.clientId
1715
- });
1716
- const { jwt, signerJwk } = await options.callbacks.signJwt(options.signer, { header, payload });
1717
- if (options.keyAttestationJwt) {
1718
- const decodedKeyAttestation = (0, import_oauth214.decodeJwt)({
1719
- jwt: options.keyAttestationJwt,
1720
- headerSchema: zKeyAttestationJwtHeader,
1721
- payloadSchema: zKeyAttestationJwtPayload
1722
- });
1723
- const isSigedWithAttestedKey = await (0, import_oauth214.isJwkInSet)({
1724
- jwk: signerJwk,
1725
- jwks: decodedKeyAttestation.payload.attested_keys,
1726
- callbacks: options.callbacks
1727
- });
1728
- if (!isSigedWithAttestedKey) {
1729
- throw new Openid4vciError(
1730
- `Credential request jwt proof is not signed with a key in the 'key_attestation' jwt payload 'attested_keys'`
1731
- );
1732
- }
1733
- }
1734
- return jwt;
1288
+ const header = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialRequestJwtProofTypeHeader, {
1289
+ ...(0, __openid4vc_oauth2.jwtHeaderFromJwtSigner)(options.signer),
1290
+ key_attestation: options.keyAttestationJwt,
1291
+ typ: "openid4vci-proof+jwt"
1292
+ });
1293
+ const payload = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialRequestJwtProofTypePayload, {
1294
+ nonce: options.nonce,
1295
+ aud: options.credentialIssuer,
1296
+ iat: (0, __openid4vc_utils.dateToSeconds)(options.issuedAt),
1297
+ iss: options.clientId
1298
+ });
1299
+ const { jwt, signerJwk } = await options.callbacks.signJwt(options.signer, {
1300
+ header,
1301
+ payload
1302
+ });
1303
+ if (options.keyAttestationJwt) {
1304
+ if (!await (0, __openid4vc_oauth2.isJwkInSet)({
1305
+ jwk: signerJwk,
1306
+ jwks: (0, __openid4vc_oauth2.decodeJwt)({
1307
+ jwt: options.keyAttestationJwt,
1308
+ headerSchema: zKeyAttestationJwtHeader,
1309
+ payloadSchema: zKeyAttestationJwtPayload
1310
+ }).payload.attested_keys,
1311
+ callbacks: options.callbacks
1312
+ })) throw new Openid4vciError(`Credential request jwt proof is not signed with a key in the 'key_attestation' jwt payload 'attested_keys'`);
1313
+ }
1314
+ return jwt;
1735
1315
  }
1736
1316
  async function verifyCredentialRequestJwtProof(options) {
1737
- const { header, payload } = (0, import_oauth214.decodeJwt)({
1738
- jwt: options.jwt,
1739
- headerSchema: zCredentialRequestJwtProofTypeHeader,
1740
- payloadSchema: zCredentialRequestJwtProofTypePayload
1741
- });
1742
- const now = options.now?.getTime() ?? Date.now();
1743
- if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
1744
- throw new Openid4vciError("Nonce used for credential request proof expired");
1745
- }
1746
- const { signer } = await (0, import_oauth215.verifyJwt)({
1747
- compact: options.jwt,
1748
- header,
1749
- payload,
1750
- signer: (0, import_oauth215.jwtSignerFromJwt)({ header, payload }),
1751
- verifyJwtCallback: options.callbacks.verifyJwt,
1752
- errorMessage: "Error verifiying credential request proof jwt.",
1753
- expectedNonce: options.expectedNonce,
1754
- expectedAudience: options.credentialIssuer,
1755
- expectedIssuer: options.clientId,
1756
- now: options.now
1757
- });
1758
- let keyAttestationResult = void 0;
1759
- if (header.key_attestation) {
1760
- keyAttestationResult = await verifyKeyAttestationJwt({
1761
- callbacks: options.callbacks,
1762
- keyAttestationJwt: header.key_attestation,
1763
- use: "proof_type.jwt"
1764
- });
1765
- const isSigedWithAttestedKey = await (0, import_oauth214.isJwkInSet)({
1766
- jwk: signer.publicJwk,
1767
- jwks: keyAttestationResult.payload.attested_keys,
1768
- callbacks: options.callbacks
1769
- });
1770
- if (!isSigedWithAttestedKey) {
1771
- throw new Openid4vciError(
1772
- `Credential request jwt proof is not signed with a key in the 'key_attestation' jwt payload 'attested_keys'`
1773
- );
1774
- }
1775
- }
1776
- return {
1777
- header,
1778
- payload,
1779
- signer,
1780
- keyAttestation: keyAttestationResult
1781
- };
1317
+ const { header, payload } = (0, __openid4vc_oauth2.decodeJwt)({
1318
+ jwt: options.jwt,
1319
+ headerSchema: zCredentialRequestJwtProofTypeHeader,
1320
+ payloadSchema: zCredentialRequestJwtProofTypePayload
1321
+ });
1322
+ const now = options.now?.getTime() ?? Date.now();
1323
+ if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) throw new Openid4vciError("Nonce used for credential request proof expired");
1324
+ const { signer } = await (0, __openid4vc_oauth2.verifyJwt)({
1325
+ compact: options.jwt,
1326
+ header,
1327
+ payload,
1328
+ signer: (0, __openid4vc_oauth2.jwtSignerFromJwt)({
1329
+ header,
1330
+ payload
1331
+ }),
1332
+ verifyJwtCallback: options.callbacks.verifyJwt,
1333
+ errorMessage: "Error verifiying credential request proof jwt.",
1334
+ expectedNonce: options.expectedNonce,
1335
+ expectedAudience: options.credentialIssuer,
1336
+ expectedIssuer: options.clientId,
1337
+ now: options.now
1338
+ });
1339
+ let keyAttestationResult;
1340
+ if (header.key_attestation) {
1341
+ keyAttestationResult = await verifyKeyAttestationJwt({
1342
+ callbacks: options.callbacks,
1343
+ keyAttestationJwt: header.key_attestation,
1344
+ use: "proof_type.jwt"
1345
+ });
1346
+ if (!await (0, __openid4vc_oauth2.isJwkInSet)({
1347
+ jwk: signer.publicJwk,
1348
+ jwks: keyAttestationResult.payload.attested_keys,
1349
+ callbacks: options.callbacks
1350
+ })) throw new Openid4vciError(`Credential request jwt proof is not signed with a key in the 'key_attestation' jwt payload 'attested_keys'`);
1351
+ }
1352
+ return {
1353
+ header,
1354
+ payload,
1355
+ signer,
1356
+ keyAttestation: keyAttestationResult
1357
+ };
1782
1358
  }
1783
1359
 
1784
- // src/metadata/fetch-issuer-metadata.ts
1785
- var import_oauth216 = require("@openid4vc/oauth2");
1786
- var import_utils14 = require("@openid4vc/utils");
1360
+ //#endregion
1361
+ //#region src/metadata/fetch-issuer-metadata.ts
1787
1362
  async function resolveIssuerMetadata(credentialIssuer, options) {
1788
- const allowAuthorizationMetadataFromCredentialIssuerMetadata = options?.allowAuthorizationMetadataFromCredentialIssuerMetadata ?? true;
1789
- const credentialIssuerMetadataWithDraftVersion = await fetchCredentialIssuerMetadata(credentialIssuer, options?.fetch);
1790
- if (!credentialIssuerMetadataWithDraftVersion) {
1791
- throw new import_oauth216.Oauth2Error(`Well known credential issuer metadata for issuer '${credentialIssuer}' not found.`);
1792
- }
1793
- const { credentialIssuerMetadata, originalDraftVersion } = credentialIssuerMetadataWithDraftVersion;
1794
- const authorizationServers = credentialIssuerMetadata.authorization_servers ?? [credentialIssuer];
1795
- const authoriationServersMetadata = [];
1796
- for (const authorizationServer of authorizationServers) {
1797
- if (options?.restrictToAuthorizationServers && !options.restrictToAuthorizationServers.includes(authorizationServer)) {
1798
- continue;
1799
- }
1800
- let authorizationServerMetadata = await (0, import_oauth216.fetchAuthorizationServerMetadata)(authorizationServer, options?.fetch);
1801
- if (!authorizationServerMetadata && authorizationServer === credentialIssuer && allowAuthorizationMetadataFromCredentialIssuerMetadata) {
1802
- authorizationServerMetadata = (0, import_utils14.parseWithErrorHandling)(
1803
- import_oauth216.zAuthorizationServerMetadata,
1804
- {
1805
- token_endpoint: credentialIssuerMetadata.token_endpoint,
1806
- issuer: credentialIssuer
1807
- },
1808
- `Well known authorization server metadata for authorization server '${authorizationServer}' not found, and could also not extract required values from the credential issuer metadata as a fallback.`
1809
- );
1810
- }
1811
- if (!authorizationServerMetadata) {
1812
- throw new import_oauth216.Oauth2Error(
1813
- `Well known openid configuration or authorization server metadata for authorization server '${authorizationServer}' not found.`
1814
- );
1815
- }
1816
- authoriationServersMetadata.push(authorizationServerMetadata);
1817
- }
1818
- return {
1819
- originalDraftVersion,
1820
- credentialIssuer: credentialIssuerMetadata,
1821
- authorizationServers: authoriationServersMetadata
1822
- };
1363
+ const allowAuthorizationMetadataFromCredentialIssuerMetadata = options?.allowAuthorizationMetadataFromCredentialIssuerMetadata ?? true;
1364
+ const credentialIssuerMetadataWithDraftVersion = await fetchCredentialIssuerMetadata(credentialIssuer, options?.fetch);
1365
+ if (!credentialIssuerMetadataWithDraftVersion) throw new __openid4vc_oauth2.Oauth2Error(`Well known credential issuer metadata for issuer '${credentialIssuer}' not found.`);
1366
+ const { credentialIssuerMetadata, originalDraftVersion } = credentialIssuerMetadataWithDraftVersion;
1367
+ const authorizationServers = credentialIssuerMetadata.authorization_servers ?? [credentialIssuer];
1368
+ const authoriationServersMetadata = [];
1369
+ for (const authorizationServer of authorizationServers) {
1370
+ if (options?.restrictToAuthorizationServers && !options.restrictToAuthorizationServers.includes(authorizationServer)) continue;
1371
+ let authorizationServerMetadata = await (0, __openid4vc_oauth2.fetchAuthorizationServerMetadata)(authorizationServer, options?.fetch);
1372
+ if (!authorizationServerMetadata && authorizationServer === credentialIssuer && allowAuthorizationMetadataFromCredentialIssuerMetadata) authorizationServerMetadata = (0, __openid4vc_utils.parseWithErrorHandling)(__openid4vc_oauth2.zAuthorizationServerMetadata, {
1373
+ token_endpoint: credentialIssuerMetadata.token_endpoint,
1374
+ issuer: credentialIssuer
1375
+ }, `Well known authorization server metadata for authorization server '${authorizationServer}' not found, and could also not extract required values from the credential issuer metadata as a fallback.`);
1376
+ if (!authorizationServerMetadata) throw new __openid4vc_oauth2.Oauth2Error(`Well known openid configuration or authorization server metadata for authorization server '${authorizationServer}' not found.`);
1377
+ authoriationServersMetadata.push(authorizationServerMetadata);
1378
+ }
1379
+ return {
1380
+ originalDraftVersion,
1381
+ credentialIssuer: credentialIssuerMetadata,
1382
+ authorizationServers: authoriationServersMetadata
1383
+ };
1823
1384
  }
1824
1385
 
1825
- // src/nonce/nonce-request.ts
1826
- var import_oauth217 = require("@openid4vc/oauth2");
1827
- var import_utils16 = require("@openid4vc/utils");
1828
-
1829
- // src/nonce/z-nonce.ts
1830
- var import_utils15 = require("@openid4vc/utils");
1831
- var import_zod20 = __toESM(require("zod"));
1832
- var zNonceResponse = import_zod20.default.object({
1833
- c_nonce: import_zod20.default.string(),
1834
- c_nonce_expires_in: import_zod20.default.optional(import_utils15.zInteger)
1386
+ //#endregion
1387
+ //#region src/nonce/z-nonce.ts
1388
+ const zNonceResponse = zod.default.object({
1389
+ c_nonce: zod.default.string(),
1390
+ c_nonce_expires_in: zod.default.optional(__openid4vc_utils.zInteger)
1835
1391
  }).passthrough();
1836
1392
 
1837
- // src/nonce/nonce-request.ts
1393
+ //#endregion
1394
+ //#region src/nonce/nonce-request.ts
1395
+ /**
1396
+ * Request a nonce from the `nonce_endpoint`
1397
+ *
1398
+ * @throws Openid4vciError - if no `nonce_endpoint` is configured in the issuer metadata
1399
+ * @throws InvalidFetchResponseError - if the nonce endpoint did not return a successful response
1400
+ * @throws ValidationError - if validating the nonce response failed
1401
+ */
1838
1402
  async function requestNonce(options) {
1839
- const fetchWithZod = (0, import_utils16.createZodFetcher)(options?.fetch);
1840
- const nonceEndpoint = options.issuerMetadata.credentialIssuer.nonce_endpoint;
1841
- if (!nonceEndpoint) {
1842
- throw new Openid4vciError(
1843
- `Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not have a nonce endpoint.`
1844
- );
1845
- }
1846
- const { response, result } = await fetchWithZod(zNonceResponse, import_utils16.ContentType.Json, nonceEndpoint, {
1847
- method: "POST"
1848
- });
1849
- if (!response.ok || !result) {
1850
- throw new import_oauth217.InvalidFetchResponseError(
1851
- `Requesting nonce from '${nonceEndpoint}' resulted in an unsuccessful response with status '${response.status}'`,
1852
- await response.clone().text(),
1853
- response
1854
- );
1855
- }
1856
- if (!result.success) {
1857
- throw new import_utils16.ValidationError("Error parsing nonce response", result.error);
1858
- }
1859
- return result.data;
1403
+ const fetchWithZod = (0, __openid4vc_utils.createZodFetcher)(options?.fetch);
1404
+ const nonceEndpoint = options.issuerMetadata.credentialIssuer.nonce_endpoint;
1405
+ if (!nonceEndpoint) throw new Openid4vciError(`Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not have a nonce endpoint.`);
1406
+ const { response, result } = await fetchWithZod(zNonceResponse, __openid4vc_utils.ContentType.Json, nonceEndpoint, { method: "POST" });
1407
+ if (!response.ok || !result) throw new __openid4vc_oauth2.InvalidFetchResponseError(`Requesting nonce from '${nonceEndpoint}' resulted in an unsuccessful response with status '${response.status}'`, await response.clone().text(), response);
1408
+ if (!result.success) throw new __openid4vc_utils.ValidationError("Error parsing nonce response", result.error);
1409
+ return result.data;
1860
1410
  }
1861
1411
  function createNonceResponse(options) {
1862
- return (0, import_utils16.parseWithErrorHandling)(zNonceResponse, {
1863
- c_nonce: options.cNonce,
1864
- c_nonce_expires_in: options.cNonceExpiresIn,
1865
- ...options.additionalPayload
1866
- });
1412
+ return (0, __openid4vc_utils.parseWithErrorHandling)(zNonceResponse, {
1413
+ c_nonce: options.cNonce,
1414
+ c_nonce_expires_in: options.cNonceExpiresIn,
1415
+ ...options.additionalPayload
1416
+ });
1867
1417
  }
1868
1418
 
1869
- // src/notification/notification.ts
1870
- var import_oauth218 = require("@openid4vc/oauth2");
1871
- var import_utils17 = require("@openid4vc/utils");
1872
-
1873
- // src/notification/z-notification.ts
1874
- var import_zod21 = __toESM(require("zod"));
1875
- var zNotificationEvent = import_zod21.default.enum(["credential_accepted", "credential_failure", "credential_deleted"]);
1876
- var zNotificationRequest = import_zod21.default.object({
1877
- notification_id: import_zod21.default.string(),
1878
- event: zNotificationEvent,
1879
- event_description: import_zod21.default.optional(import_zod21.default.string())
1880
- }).passthrough();
1881
- var zNotificationErrorResponse = import_zod21.default.object({
1882
- error: import_zod21.default.enum(["invalid_notification_id", "invalid_notification_request"])
1419
+ //#endregion
1420
+ //#region src/notification/z-notification.ts
1421
+ const zNotificationEvent = zod.default.enum([
1422
+ "credential_accepted",
1423
+ "credential_failure",
1424
+ "credential_deleted"
1425
+ ]);
1426
+ const zNotificationRequest = zod.default.object({
1427
+ notification_id: zod.default.string(),
1428
+ event: zNotificationEvent,
1429
+ event_description: zod.default.optional(zod.default.string())
1883
1430
  }).passthrough();
1431
+ const zNotificationErrorResponse = zod.default.object({ error: zod.default.enum(["invalid_notification_id", "invalid_notification_request"]) }).passthrough();
1884
1432
 
1885
- // src/notification/notification.ts
1433
+ //#endregion
1434
+ //#region src/notification/notification.ts
1886
1435
  async function sendNotification(options) {
1887
- const notificationEndpoint = options.issuerMetadata.credentialIssuer.notification_endpoint;
1888
- if (!notificationEndpoint) {
1889
- throw new import_oauth218.Oauth2Error(
1890
- `Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not have a notification endpiont configured.`
1891
- );
1892
- }
1893
- const notificationRequest = (0, import_utils17.parseWithErrorHandling)(
1894
- zNotificationRequest,
1895
- {
1896
- event: options.notification.event,
1897
- notification_id: options.notification.notificationId,
1898
- event_description: options.notification.eventDescription
1899
- },
1900
- "Error validating notification request"
1901
- );
1902
- const resourceResponse = await (0, import_oauth218.resourceRequest)({
1903
- dpop: options.dpop,
1904
- accessToken: options.accessToken,
1905
- callbacks: options.callbacks,
1906
- url: notificationEndpoint,
1907
- requestOptions: {
1908
- method: "POST",
1909
- headers: {
1910
- "Content-Type": import_utils17.ContentType.Json
1911
- },
1912
- body: JSON.stringify(notificationRequest)
1913
- }
1914
- });
1915
- if (!resourceResponse.ok) {
1916
- const notificationErrorResponseResult = (0, import_utils17.isResponseContentType)(import_utils17.ContentType.Json, resourceResponse.response) ? zNotificationErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1917
- return {
1918
- ...resourceResponse,
1919
- notificationErrorResponseResult
1920
- };
1921
- }
1922
- return resourceResponse;
1436
+ const notificationEndpoint = options.issuerMetadata.credentialIssuer.notification_endpoint;
1437
+ if (!notificationEndpoint) throw new __openid4vc_oauth2.Oauth2Error(`Credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}' does not have a notification endpiont configured.`);
1438
+ const notificationRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zNotificationRequest, {
1439
+ event: options.notification.event,
1440
+ notification_id: options.notification.notificationId,
1441
+ event_description: options.notification.eventDescription
1442
+ }, "Error validating notification request");
1443
+ const resourceResponse = await (0, __openid4vc_oauth2.resourceRequest)({
1444
+ dpop: options.dpop,
1445
+ accessToken: options.accessToken,
1446
+ callbacks: options.callbacks,
1447
+ url: notificationEndpoint,
1448
+ requestOptions: {
1449
+ method: "POST",
1450
+ headers: { "Content-Type": __openid4vc_utils.ContentType.Json },
1451
+ body: JSON.stringify(notificationRequest)
1452
+ }
1453
+ });
1454
+ if (!resourceResponse.ok) {
1455
+ const notificationErrorResponseResult = (0, __openid4vc_utils.isResponseContentType)(__openid4vc_utils.ContentType.Json, resourceResponse.response) ? zNotificationErrorResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
1456
+ return {
1457
+ ...resourceResponse,
1458
+ notificationErrorResponseResult
1459
+ };
1460
+ }
1461
+ return resourceResponse;
1923
1462
  }
1924
1463
 
1925
- // src/Openid4vciClient.ts
1926
- var AuthorizationFlow = /* @__PURE__ */ ((AuthorizationFlow2) => {
1927
- AuthorizationFlow2["Oauth2Redirect"] = "Oauth2Redirect";
1928
- AuthorizationFlow2["PresentationDuringIssuance"] = "PresentationDuringIssuance";
1929
- return AuthorizationFlow2;
1930
- })(AuthorizationFlow || {});
1464
+ //#endregion
1465
+ //#region src/Openid4vciClient.ts
1466
+ let AuthorizationFlow = /* @__PURE__ */ function(AuthorizationFlow$1) {
1467
+ AuthorizationFlow$1["Oauth2Redirect"] = "Oauth2Redirect";
1468
+ AuthorizationFlow$1["PresentationDuringIssuance"] = "PresentationDuringIssuance";
1469
+ return AuthorizationFlow$1;
1470
+ }({});
1931
1471
  var Openid4vciClient = class {
1932
- constructor(options) {
1933
- this.options = options;
1934
- this.oauth2Client = new import_oauth219.Oauth2Client({
1935
- callbacks: this.options.callbacks
1936
- });
1937
- }
1938
- getKnownCredentialConfigurationsSupported(credentialIssuerMetadata) {
1939
- return extractKnownCredentialConfigurationSupportedFormats(
1940
- credentialIssuerMetadata.credential_configurations_supported
1941
- );
1942
- }
1943
- /**
1944
- * Resolve a credential offer into a credential offer object, handling both
1945
- * 'credential_offer' and 'credential_offer_uri' params.
1946
- */
1947
- async resolveCredentialOffer(credentialOffer) {
1948
- return resolveCredentialOffer(credentialOffer, {
1949
- fetch: this.options.callbacks.fetch
1950
- });
1951
- }
1952
- async resolveIssuerMetadata(credentialIssuer) {
1953
- return resolveIssuerMetadata(credentialIssuer, {
1954
- fetch: this.options.callbacks.fetch
1955
- });
1956
- }
1957
- /**
1958
- * Retrieve an authorization code for a presentation during issuance session
1959
- *
1960
- * This can only be called if an authorization challenge was performed before and returned a
1961
- * `presentation` parameter along with an `auth_session`. If the presentation response included
1962
- * an `presentation_during_issuance_session` parameter it MUST be included in this request as well.
1963
- */
1964
- async retrieveAuthorizationCodeUsingPresentation(options) {
1965
- if (!options.credentialOffer.grants?.[import_oauth219.authorizationCodeGrantIdentifier]) {
1966
- throw new import_oauth219.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
1967
- }
1968
- const authorizationCodeGrant = options.credentialOffer.grants[import_oauth219.authorizationCodeGrantIdentifier];
1969
- const authorizationServer = determineAuthorizationServerForCredentialOffer({
1970
- issuerMetadata: options.issuerMetadata,
1971
- grantAuthorizationServer: authorizationCodeGrant.authorization_server
1972
- });
1973
- const authorizationServerMetadata = (0, import_oauth219.getAuthorizationServerMetadataFromList)(
1974
- options.issuerMetadata.authorizationServers,
1975
- authorizationServer
1976
- );
1977
- const oauth2Client = new import_oauth219.Oauth2Client({ callbacks: this.options.callbacks });
1978
- const { authorizationChallengeResponse, dpop } = await oauth2Client.sendAuthorizationChallengeRequest({
1979
- authorizationServerMetadata,
1980
- authSession: options.authSession,
1981
- presentationDuringIssuanceSession: options.presentationDuringIssuanceSession,
1982
- dpop: options.dpop
1983
- });
1984
- return { authorizationChallengeResponse, dpop };
1985
- }
1986
- /**
1987
- * Initiates authorization for credential issuance. It handles the following cases:
1988
- * - Authorization Challenge
1989
- * - Pushed Authorization Request
1990
- * - Regular Authorization url
1991
- *
1992
- * In case the authorization challenge request returns an error with `insufficient_authorization`
1993
- * with a `presentation` field it means the authorization server expects presentation of credentials
1994
- * before issuance of credentials. If this is the case, the value in `presentation` should be treated
1995
- * as an openid4vp authorization request and submitted to the verifier. Once the presentation response
1996
- * has been submitted, the RP will respond with a `presentation_during_issuance_session` parameter.
1997
- * Together with the `auth_session` parameter returned in this call you can retrieve an `authorization_code`
1998
- * using
1999
- */
2000
- async initiateAuthorization(options) {
2001
- if (!options.credentialOffer.grants?.[import_oauth219.authorizationCodeGrantIdentifier]) {
2002
- throw new import_oauth219.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
2003
- }
2004
- const authorizationCodeGrant = options.credentialOffer.grants[import_oauth219.authorizationCodeGrantIdentifier];
2005
- const authorizationServer = determineAuthorizationServerForCredentialOffer({
2006
- issuerMetadata: options.issuerMetadata,
2007
- grantAuthorizationServer: authorizationCodeGrant.authorization_server
2008
- });
2009
- const authorizationServerMetadata = (0, import_oauth219.getAuthorizationServerMetadataFromList)(
2010
- options.issuerMetadata.authorizationServers,
2011
- authorizationServer
2012
- );
2013
- const oauth2Client = new import_oauth219.Oauth2Client({ callbacks: this.options.callbacks });
2014
- try {
2015
- const result = await oauth2Client.initiateAuthorization({
2016
- clientId: options.clientId,
2017
- pkceCodeVerifier: options.pkceCodeVerifier,
2018
- redirectUri: options.redirectUri,
2019
- scope: options.scope,
2020
- additionalRequestPayload: {
2021
- ...options.additionalRequestPayload,
2022
- issuer_state: options.credentialOffer?.grants?.authorization_code?.issuer_state
2023
- },
2024
- dpop: options.dpop,
2025
- resource: options.issuerMetadata.credentialIssuer.credential_issuer,
2026
- authorizationServerMetadata
2027
- });
2028
- return {
2029
- ...result,
2030
- authorizationFlow: "Oauth2Redirect" /* Oauth2Redirect */,
2031
- authorizationServer: authorizationServerMetadata.issuer
2032
- };
2033
- } catch (error) {
2034
- if (error instanceof import_oauth219.Oauth2ClientAuthorizationChallengeError && error.errorResponse.error === import_oauth219.Oauth2ErrorCodes.InsufficientAuthorization && error.errorResponse.presentation) {
2035
- if (!error.errorResponse.auth_session) {
2036
- throw new Openid4vciError(
2037
- `Expected 'auth_session' to be defined with authorization challenge response error '${error.errorResponse.error}' and 'presentation' parameter`
2038
- );
2039
- }
2040
- return {
2041
- authorizationFlow: "PresentationDuringIssuance" /* PresentationDuringIssuance */,
2042
- openid4vpRequestUrl: error.errorResponse.presentation,
2043
- authSession: error.errorResponse.auth_session,
2044
- authorizationServer: authorizationServerMetadata.issuer
2045
- };
2046
- }
2047
- throw error;
2048
- }
2049
- }
2050
- /**
2051
- * Convenience method around {@link Oauth2Client.createAuthorizationRequestUrl}
2052
- * but specifically focused on a credential offer
2053
- */
2054
- async createAuthorizationRequestUrlFromOffer(options) {
2055
- if (!options.credentialOffer.grants?.[import_oauth219.authorizationCodeGrantIdentifier]) {
2056
- throw new import_oauth219.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
2057
- }
2058
- const authorizationCodeGrant = options.credentialOffer.grants[import_oauth219.authorizationCodeGrantIdentifier];
2059
- const authorizationServer = determineAuthorizationServerForCredentialOffer({
2060
- issuerMetadata: options.issuerMetadata,
2061
- grantAuthorizationServer: authorizationCodeGrant.authorization_server
2062
- });
2063
- const authorizationServerMetadata = (0, import_oauth219.getAuthorizationServerMetadataFromList)(
2064
- options.issuerMetadata.authorizationServers,
2065
- authorizationServer
2066
- );
2067
- const { authorizationRequestUrl, pkce, dpop } = await this.oauth2Client.createAuthorizationRequestUrl({
2068
- authorizationServerMetadata,
2069
- clientId: options.clientId,
2070
- additionalRequestPayload: {
2071
- ...options.additionalRequestPayload,
2072
- issuer_state: options.credentialOffer?.grants?.authorization_code?.issuer_state
2073
- },
2074
- resource: options.issuerMetadata.credentialIssuer.credential_issuer,
2075
- redirectUri: options.redirectUri,
2076
- scope: options.scope,
2077
- pkceCodeVerifier: options.pkceCodeVerifier,
2078
- dpop: options.dpop
2079
- });
2080
- return {
2081
- authorizationRequestUrl,
2082
- pkce,
2083
- dpop,
2084
- authorizationServer: authorizationServerMetadata.issuer
2085
- };
2086
- }
2087
- /**
2088
- * Convenience method around {@link Oauth2Client.retrievePreAuthorizedCodeAccessToken}
2089
- * but specifically focused on a credential offer
2090
- */
2091
- async retrievePreAuthorizedCodeAccessTokenFromOffer({
2092
- credentialOffer,
2093
- issuerMetadata,
2094
- additionalRequestPayload,
2095
- txCode,
2096
- dpop
2097
- }) {
2098
- if (!credentialOffer.grants?.[import_oauth219.preAuthorizedCodeGrantIdentifier]) {
2099
- throw new import_oauth219.Oauth2Error(`The credential offer does not contain the '${import_oauth219.preAuthorizedCodeGrantIdentifier}' grant.`);
2100
- }
2101
- if (credentialOffer.grants[import_oauth219.preAuthorizedCodeGrantIdentifier].tx_code && !txCode) {
2102
- throw new import_oauth219.Oauth2Error(
2103
- `Retrieving access token requires a 'tx_code' in the request, but the 'txCode' parameter was not provided.`
2104
- );
2105
- }
2106
- const preAuthorizedCode = credentialOffer.grants[import_oauth219.preAuthorizedCodeGrantIdentifier]["pre-authorized_code"];
2107
- const authorizationServer = determineAuthorizationServerForCredentialOffer({
2108
- grantAuthorizationServer: credentialOffer.grants[import_oauth219.preAuthorizedCodeGrantIdentifier].authorization_server,
2109
- issuerMetadata
2110
- });
2111
- const authorizationServerMetadata = (0, import_oauth219.getAuthorizationServerMetadataFromList)(
2112
- issuerMetadata.authorizationServers,
2113
- authorizationServer
2114
- );
2115
- const result = await this.oauth2Client.retrievePreAuthorizedCodeAccessToken({
2116
- authorizationServerMetadata,
2117
- preAuthorizedCode,
2118
- txCode,
2119
- resource: issuerMetadata.credentialIssuer.credential_issuer,
2120
- additionalRequestPayload,
2121
- dpop
2122
- });
2123
- return {
2124
- ...result,
2125
- authorizationServer
2126
- };
2127
- }
2128
- /**
2129
- * Convenience method around {@link Oauth2Client.retrieveAuthorizationCodeAccessTokenFrom}
2130
- * but specifically focused on a credential offer
2131
- */
2132
- async retrieveAuthorizationCodeAccessTokenFromOffer({
2133
- issuerMetadata,
2134
- additionalRequestPayload,
2135
- credentialOffer,
2136
- authorizationCode,
2137
- pkceCodeVerifier,
2138
- redirectUri,
2139
- dpop
2140
- }) {
2141
- if (!credentialOffer.grants?.[import_oauth219.authorizationCodeGrantIdentifier]) {
2142
- throw new import_oauth219.Oauth2Error(`The credential offer does not contain the '${import_oauth219.authorizationCodeGrantIdentifier}' grant.`);
2143
- }
2144
- const authorizationServer = determineAuthorizationServerForCredentialOffer({
2145
- grantAuthorizationServer: credentialOffer.grants[import_oauth219.authorizationCodeGrantIdentifier].authorization_server,
2146
- issuerMetadata
2147
- });
2148
- const authorizationServerMetadata = (0, import_oauth219.getAuthorizationServerMetadataFromList)(
2149
- issuerMetadata.authorizationServers,
2150
- authorizationServer
2151
- );
2152
- const result = await this.oauth2Client.retrieveAuthorizationCodeAccessToken({
2153
- authorizationServerMetadata,
2154
- authorizationCode,
2155
- pkceCodeVerifier,
2156
- additionalRequestPayload,
2157
- dpop,
2158
- redirectUri,
2159
- resource: issuerMetadata.credentialIssuer.credential_issuer
2160
- });
2161
- return {
2162
- ...result,
2163
- authorizationServer
2164
- };
2165
- }
2166
- /**
2167
- * Request a nonce to be used in credential request proofs from the `nonce_endpoint`
2168
- *
2169
- * @throws Openid4vciError - if no `nonce_endpoint` is configured in the issuer metadata
2170
- * @throws InvalidFetchResponseError - if the nonce endpoint did not return a successful response
2171
- * @throws ValidationError - if validating the nonce response failed
2172
- */
2173
- async requestNonce(options) {
2174
- return requestNonce({
2175
- ...options,
2176
- fetch: this.options.callbacks.fetch
2177
- });
2178
- }
2179
- /**
2180
- * Creates the jwt proof payload and header to be included in a credential request.
2181
- */
2182
- async createCredentialRequestJwtProof(options) {
2183
- const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[options.credentialConfigurationId];
2184
- if (!credentialConfiguration) {
2185
- throw new Openid4vciError(
2186
- `Credential configuration with '${options.credentialConfigurationId}' not found in 'credential_configurations_supported' from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
2187
- );
2188
- }
2189
- if (credentialConfiguration.proof_types_supported) {
2190
- if (!credentialConfiguration.proof_types_supported.jwt) {
2191
- throw new Openid4vciError(
2192
- `Credential configuration with id '${options.credentialConfigurationId}' does not support the 'jwt' proof type.`
2193
- );
2194
- }
2195
- if (!credentialConfiguration.proof_types_supported.jwt.proof_signing_alg_values_supported.includes(
2196
- options.signer.alg
2197
- )) {
2198
- throw new Openid4vciError(
2199
- `Credential configuration with id '${options.credentialConfigurationId}' does not support the '${options.signer.alg}' alg for 'jwt' proof type.`
2200
- );
2201
- }
2202
- if (credentialConfiguration.proof_types_supported.jwt.key_attestations_required && !options.keyAttestationJwt) {
2203
- throw new Openid4vciError(
2204
- `Credential configuration with id '${options.credentialConfigurationId}' requires key attestations for 'jwt' proof type but no 'keyAttestationJwt' was provided`
2205
- );
2206
- }
2207
- }
2208
- const jwt = await createCredentialRequestJwtProof({
2209
- credentialIssuer: options.issuerMetadata.credentialIssuer.credential_issuer,
2210
- signer: options.signer,
2211
- clientId: options.clientId,
2212
- issuedAt: options.issuedAt,
2213
- nonce: options.nonce,
2214
- keyAttestationJwt: options.keyAttestationJwt,
2215
- callbacks: this.options.callbacks
2216
- });
2217
- return {
2218
- jwt
2219
- };
2220
- }
2221
- /**
2222
- * @throws Openid4vciRetrieveCredentialsError - if an unsuccessful response or the response couldn't be parsed as credential response
2223
- * @throws ValidationError - if validation of the credential request failed
2224
- * @throws Openid4vciError - if the `credentialConfigurationId` couldn't be found, or if the the format specific request couldn't be constructed
2225
- */
2226
- async retrieveCredentials({
2227
- issuerMetadata,
2228
- proof,
2229
- proofs,
2230
- credentialConfigurationId,
2231
- additionalRequestPayload,
2232
- accessToken,
2233
- dpop
2234
- }) {
2235
- let credentialResponse;
2236
- if (issuerMetadata.originalDraftVersion === "Draft15" /* Draft15 */ || issuerMetadata.originalDraftVersion === "Draft16" /* Draft16 */) {
2237
- credentialResponse = await retrieveCredentialsWithCredentialConfigurationId({
2238
- accessToken,
2239
- credentialConfigurationId,
2240
- issuerMetadata,
2241
- additionalRequestPayload,
2242
- proof,
2243
- proofs,
2244
- callbacks: this.options.callbacks,
2245
- dpop
2246
- });
2247
- } else {
2248
- const formatPayload = getCredentialRequestFormatPayloadForCredentialConfigurationId({
2249
- credentialConfigurationId,
2250
- issuerMetadata
2251
- });
2252
- credentialResponse = await retrieveCredentialsWithFormat({
2253
- accessToken,
2254
- formatPayload,
2255
- issuerMetadata,
2256
- additionalRequestPayload,
2257
- proof,
2258
- proofs,
2259
- callbacks: this.options.callbacks,
2260
- dpop
2261
- });
2262
- }
2263
- if (!credentialResponse.ok) {
2264
- throw new Openid4vciRetrieveCredentialsError(
2265
- `Error retrieving credentials from '${issuerMetadata.credentialIssuer.credential_issuer}'`,
2266
- credentialResponse,
2267
- await credentialResponse.response.clone().text()
2268
- );
2269
- }
2270
- return credentialResponse;
2271
- }
2272
- /**
2273
- * @throws Openid4vciRetrieveCredentialsError - if an unsuccessful response or the response couldn't be parsed as credential response
2274
- * @throws ValidationError - if validation of the credential request failed
2275
- */
2276
- async retrieveDeferredCredentials(options) {
2277
- const credentialResponse = await retrieveDeferredCredentials({
2278
- ...options,
2279
- callbacks: this.options.callbacks
2280
- });
2281
- if (!credentialResponse.ok) {
2282
- throw new Openid4vciRetrieveCredentialsError(
2283
- `Error retrieving deferred credentials from '${options.issuerMetadata.credentialIssuer.credential_issuer}'`,
2284
- credentialResponse,
2285
- await credentialResponse.response.clone().text()
2286
- );
2287
- }
2288
- return credentialResponse;
2289
- }
2290
- /**
2291
- * @throws Openid4vciSendNotificationError - if an unsuccessful response
2292
- * @throws ValidationError - if validation of the notification request failed
2293
- */
2294
- async sendNotification({
2295
- issuerMetadata,
2296
- notification,
2297
- additionalRequestPayload,
2298
- accessToken,
2299
- dpop
2300
- }) {
2301
- const notificationResponse = await sendNotification({
2302
- accessToken,
2303
- issuerMetadata,
2304
- additionalRequestPayload,
2305
- callbacks: this.options.callbacks,
2306
- dpop,
2307
- notification
2308
- });
2309
- if (!notificationResponse.ok) {
2310
- throw new Openid4vciSendNotificationError(
2311
- `Error sending notification to '${issuerMetadata.credentialIssuer.credential_issuer}'`,
2312
- notificationResponse
2313
- );
2314
- }
2315
- return notificationResponse;
2316
- }
1472
+ constructor(options) {
1473
+ this.options = options;
1474
+ this.oauth2Client = new __openid4vc_oauth2.Oauth2Client({ callbacks: this.options.callbacks });
1475
+ }
1476
+ getKnownCredentialConfigurationsSupported(credentialIssuerMetadata) {
1477
+ return extractKnownCredentialConfigurationSupportedFormats(credentialIssuerMetadata.credential_configurations_supported);
1478
+ }
1479
+ /**
1480
+ * Resolve a credential offer into a credential offer object, handling both
1481
+ * 'credential_offer' and 'credential_offer_uri' params.
1482
+ */
1483
+ async resolveCredentialOffer(credentialOffer) {
1484
+ return resolveCredentialOffer(credentialOffer, { fetch: this.options.callbacks.fetch });
1485
+ }
1486
+ async resolveIssuerMetadata(credentialIssuer) {
1487
+ return resolveIssuerMetadata(credentialIssuer, { fetch: this.options.callbacks.fetch });
1488
+ }
1489
+ /**
1490
+ * Retrieve an authorization code for a presentation during issuance session
1491
+ *
1492
+ * This can only be called if an authorization challenge was performed before and returned a
1493
+ * `presentation` parameter along with an `auth_session`. If the presentation response included
1494
+ * an `presentation_during_issuance_session` parameter it MUST be included in this request as well.
1495
+ */
1496
+ async retrieveAuthorizationCodeUsingPresentation(options) {
1497
+ if (!options.credentialOffer.grants?.[__openid4vc_oauth2.authorizationCodeGrantIdentifier]) throw new __openid4vc_oauth2.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
1498
+ const authorizationCodeGrant = options.credentialOffer.grants[__openid4vc_oauth2.authorizationCodeGrantIdentifier];
1499
+ const authorizationServer = determineAuthorizationServerForCredentialOffer({
1500
+ issuerMetadata: options.issuerMetadata,
1501
+ grantAuthorizationServer: authorizationCodeGrant.authorization_server
1502
+ });
1503
+ const authorizationServerMetadata = (0, __openid4vc_oauth2.getAuthorizationServerMetadataFromList)(options.issuerMetadata.authorizationServers, authorizationServer);
1504
+ const { authorizationChallengeResponse, dpop } = await new __openid4vc_oauth2.Oauth2Client({ callbacks: this.options.callbacks }).sendAuthorizationChallengeRequest({
1505
+ authorizationServerMetadata,
1506
+ authSession: options.authSession,
1507
+ presentationDuringIssuanceSession: options.presentationDuringIssuanceSession,
1508
+ dpop: options.dpop
1509
+ });
1510
+ return {
1511
+ authorizationChallengeResponse,
1512
+ dpop
1513
+ };
1514
+ }
1515
+ /**
1516
+ * Initiates authorization for credential issuance. It handles the following cases:
1517
+ * - Authorization Challenge
1518
+ * - Pushed Authorization Request
1519
+ * - Regular Authorization url
1520
+ *
1521
+ * In case the authorization challenge request returns an error with `insufficient_authorization`
1522
+ * with a `presentation` field it means the authorization server expects presentation of credentials
1523
+ * before issuance of credentials. If this is the case, the value in `presentation` should be treated
1524
+ * as an openid4vp authorization request and submitted to the verifier. Once the presentation response
1525
+ * has been submitted, the RP will respond with a `presentation_during_issuance_session` parameter.
1526
+ * Together with the `auth_session` parameter returned in this call you can retrieve an `authorization_code`
1527
+ * using
1528
+ */
1529
+ async initiateAuthorization(options) {
1530
+ if (!options.credentialOffer.grants?.[__openid4vc_oauth2.authorizationCodeGrantIdentifier]) throw new __openid4vc_oauth2.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
1531
+ const authorizationCodeGrant = options.credentialOffer.grants[__openid4vc_oauth2.authorizationCodeGrantIdentifier];
1532
+ const authorizationServer = determineAuthorizationServerForCredentialOffer({
1533
+ issuerMetadata: options.issuerMetadata,
1534
+ grantAuthorizationServer: authorizationCodeGrant.authorization_server
1535
+ });
1536
+ const authorizationServerMetadata = (0, __openid4vc_oauth2.getAuthorizationServerMetadataFromList)(options.issuerMetadata.authorizationServers, authorizationServer);
1537
+ const oauth2Client = new __openid4vc_oauth2.Oauth2Client({ callbacks: this.options.callbacks });
1538
+ try {
1539
+ return {
1540
+ ...await oauth2Client.initiateAuthorization({
1541
+ clientId: options.clientId,
1542
+ pkceCodeVerifier: options.pkceCodeVerifier,
1543
+ redirectUri: options.redirectUri,
1544
+ scope: options.scope,
1545
+ additionalRequestPayload: {
1546
+ ...options.additionalRequestPayload,
1547
+ issuer_state: options.credentialOffer?.grants?.authorization_code?.issuer_state
1548
+ },
1549
+ dpop: options.dpop,
1550
+ resource: options.issuerMetadata.credentialIssuer.credential_issuer,
1551
+ authorizationServerMetadata
1552
+ }),
1553
+ authorizationFlow: AuthorizationFlow.Oauth2Redirect,
1554
+ authorizationServer: authorizationServerMetadata.issuer
1555
+ };
1556
+ } catch (error) {
1557
+ if (error instanceof __openid4vc_oauth2.Oauth2ClientAuthorizationChallengeError && error.errorResponse.error === __openid4vc_oauth2.Oauth2ErrorCodes.InsufficientAuthorization && error.errorResponse.presentation) {
1558
+ if (!error.errorResponse.auth_session) throw new Openid4vciError(`Expected 'auth_session' to be defined with authorization challenge response error '${error.errorResponse.error}' and 'presentation' parameter`);
1559
+ return {
1560
+ authorizationFlow: AuthorizationFlow.PresentationDuringIssuance,
1561
+ openid4vpRequestUrl: error.errorResponse.presentation,
1562
+ authSession: error.errorResponse.auth_session,
1563
+ authorizationServer: authorizationServerMetadata.issuer
1564
+ };
1565
+ }
1566
+ throw error;
1567
+ }
1568
+ }
1569
+ /**
1570
+ * Convenience method around {@link Oauth2Client.createAuthorizationRequestUrl}
1571
+ * but specifically focused on a credential offer
1572
+ */
1573
+ async createAuthorizationRequestUrlFromOffer(options) {
1574
+ if (!options.credentialOffer.grants?.[__openid4vc_oauth2.authorizationCodeGrantIdentifier]) throw new __openid4vc_oauth2.Oauth2Error(`Provided credential offer does not include the 'authorization_code' grant.`);
1575
+ const authorizationCodeGrant = options.credentialOffer.grants[__openid4vc_oauth2.authorizationCodeGrantIdentifier];
1576
+ const authorizationServer = determineAuthorizationServerForCredentialOffer({
1577
+ issuerMetadata: options.issuerMetadata,
1578
+ grantAuthorizationServer: authorizationCodeGrant.authorization_server
1579
+ });
1580
+ const authorizationServerMetadata = (0, __openid4vc_oauth2.getAuthorizationServerMetadataFromList)(options.issuerMetadata.authorizationServers, authorizationServer);
1581
+ const { authorizationRequestUrl, pkce, dpop } = await this.oauth2Client.createAuthorizationRequestUrl({
1582
+ authorizationServerMetadata,
1583
+ clientId: options.clientId,
1584
+ additionalRequestPayload: {
1585
+ ...options.additionalRequestPayload,
1586
+ issuer_state: options.credentialOffer?.grants?.authorization_code?.issuer_state
1587
+ },
1588
+ resource: options.issuerMetadata.credentialIssuer.credential_issuer,
1589
+ redirectUri: options.redirectUri,
1590
+ scope: options.scope,
1591
+ pkceCodeVerifier: options.pkceCodeVerifier,
1592
+ dpop: options.dpop
1593
+ });
1594
+ return {
1595
+ authorizationRequestUrl,
1596
+ pkce,
1597
+ dpop,
1598
+ authorizationServer: authorizationServerMetadata.issuer
1599
+ };
1600
+ }
1601
+ /**
1602
+ * Convenience method around {@link Oauth2Client.retrievePreAuthorizedCodeAccessToken}
1603
+ * but specifically focused on a credential offer
1604
+ */
1605
+ async retrievePreAuthorizedCodeAccessTokenFromOffer({ credentialOffer, issuerMetadata, additionalRequestPayload, txCode, dpop }) {
1606
+ if (!credentialOffer.grants?.[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]) throw new __openid4vc_oauth2.Oauth2Error(`The credential offer does not contain the '${__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier}' grant.`);
1607
+ if (credentialOffer.grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier].tx_code && !txCode) throw new __openid4vc_oauth2.Oauth2Error(`Retrieving access token requires a 'tx_code' in the request, but the 'txCode' parameter was not provided.`);
1608
+ const preAuthorizedCode = credentialOffer.grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier]["pre-authorized_code"];
1609
+ const authorizationServer = determineAuthorizationServerForCredentialOffer({
1610
+ grantAuthorizationServer: credentialOffer.grants[__openid4vc_oauth2.preAuthorizedCodeGrantIdentifier].authorization_server,
1611
+ issuerMetadata
1612
+ });
1613
+ const authorizationServerMetadata = (0, __openid4vc_oauth2.getAuthorizationServerMetadataFromList)(issuerMetadata.authorizationServers, authorizationServer);
1614
+ return {
1615
+ ...await this.oauth2Client.retrievePreAuthorizedCodeAccessToken({
1616
+ authorizationServerMetadata,
1617
+ preAuthorizedCode,
1618
+ txCode,
1619
+ resource: issuerMetadata.credentialIssuer.credential_issuer,
1620
+ additionalRequestPayload,
1621
+ dpop
1622
+ }),
1623
+ authorizationServer
1624
+ };
1625
+ }
1626
+ /**
1627
+ * Convenience method around {@link Oauth2Client.retrieveAuthorizationCodeAccessTokenFrom}
1628
+ * but specifically focused on a credential offer
1629
+ */
1630
+ async retrieveAuthorizationCodeAccessTokenFromOffer({ issuerMetadata, additionalRequestPayload, credentialOffer, authorizationCode, pkceCodeVerifier, redirectUri, dpop }) {
1631
+ if (!credentialOffer.grants?.[__openid4vc_oauth2.authorizationCodeGrantIdentifier]) throw new __openid4vc_oauth2.Oauth2Error(`The credential offer does not contain the '${__openid4vc_oauth2.authorizationCodeGrantIdentifier}' grant.`);
1632
+ const authorizationServer = determineAuthorizationServerForCredentialOffer({
1633
+ grantAuthorizationServer: credentialOffer.grants[__openid4vc_oauth2.authorizationCodeGrantIdentifier].authorization_server,
1634
+ issuerMetadata
1635
+ });
1636
+ const authorizationServerMetadata = (0, __openid4vc_oauth2.getAuthorizationServerMetadataFromList)(issuerMetadata.authorizationServers, authorizationServer);
1637
+ return {
1638
+ ...await this.oauth2Client.retrieveAuthorizationCodeAccessToken({
1639
+ authorizationServerMetadata,
1640
+ authorizationCode,
1641
+ pkceCodeVerifier,
1642
+ additionalRequestPayload,
1643
+ dpop,
1644
+ redirectUri,
1645
+ resource: issuerMetadata.credentialIssuer.credential_issuer
1646
+ }),
1647
+ authorizationServer
1648
+ };
1649
+ }
1650
+ /**
1651
+ * Request a nonce to be used in credential request proofs from the `nonce_endpoint`
1652
+ *
1653
+ * @throws Openid4vciError - if no `nonce_endpoint` is configured in the issuer metadata
1654
+ * @throws InvalidFetchResponseError - if the nonce endpoint did not return a successful response
1655
+ * @throws ValidationError - if validating the nonce response failed
1656
+ */
1657
+ async requestNonce(options) {
1658
+ return requestNonce({
1659
+ ...options,
1660
+ fetch: this.options.callbacks.fetch
1661
+ });
1662
+ }
1663
+ /**
1664
+ * Creates the jwt proof payload and header to be included in a credential request.
1665
+ */
1666
+ async createCredentialRequestJwtProof(options) {
1667
+ const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[options.credentialConfigurationId];
1668
+ if (!credentialConfiguration) throw new Openid4vciError(`Credential configuration with '${options.credentialConfigurationId}' not found in 'credential_configurations_supported' from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`);
1669
+ if (credentialConfiguration.proof_types_supported) {
1670
+ if (!credentialConfiguration.proof_types_supported.jwt) throw new Openid4vciError(`Credential configuration with id '${options.credentialConfigurationId}' does not support the 'jwt' proof type.`);
1671
+ if (!credentialConfiguration.proof_types_supported.jwt.proof_signing_alg_values_supported.includes(options.signer.alg)) throw new Openid4vciError(`Credential configuration with id '${options.credentialConfigurationId}' does not support the '${options.signer.alg}' alg for 'jwt' proof type.`);
1672
+ if (credentialConfiguration.proof_types_supported.jwt.key_attestations_required && !options.keyAttestationJwt) throw new Openid4vciError(`Credential configuration with id '${options.credentialConfigurationId}' requires key attestations for 'jwt' proof type but no 'keyAttestationJwt' was provided`);
1673
+ }
1674
+ return { jwt: await createCredentialRequestJwtProof({
1675
+ credentialIssuer: options.issuerMetadata.credentialIssuer.credential_issuer,
1676
+ signer: options.signer,
1677
+ clientId: options.clientId,
1678
+ issuedAt: options.issuedAt,
1679
+ nonce: options.nonce,
1680
+ keyAttestationJwt: options.keyAttestationJwt,
1681
+ callbacks: this.options.callbacks
1682
+ }) };
1683
+ }
1684
+ /**
1685
+ * @throws Openid4vciRetrieveCredentialsError - if an unsuccessful response or the response couldn't be parsed as credential response
1686
+ * @throws ValidationError - if validation of the credential request failed
1687
+ * @throws Openid4vciError - if the `credentialConfigurationId` couldn't be found, or if the the format specific request couldn't be constructed
1688
+ */
1689
+ async retrieveCredentials({ issuerMetadata, proof, proofs, credentialConfigurationId, additionalRequestPayload, accessToken, dpop }) {
1690
+ let credentialResponse;
1691
+ if (issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft16) credentialResponse = await retrieveCredentialsWithCredentialConfigurationId({
1692
+ accessToken,
1693
+ credentialConfigurationId,
1694
+ issuerMetadata,
1695
+ additionalRequestPayload,
1696
+ proof,
1697
+ proofs,
1698
+ callbacks: this.options.callbacks,
1699
+ dpop
1700
+ });
1701
+ else credentialResponse = await retrieveCredentialsWithFormat({
1702
+ accessToken,
1703
+ formatPayload: getCredentialRequestFormatPayloadForCredentialConfigurationId({
1704
+ credentialConfigurationId,
1705
+ issuerMetadata
1706
+ }),
1707
+ issuerMetadata,
1708
+ additionalRequestPayload,
1709
+ proof,
1710
+ proofs,
1711
+ callbacks: this.options.callbacks,
1712
+ dpop
1713
+ });
1714
+ if (!credentialResponse.ok) throw new Openid4vciRetrieveCredentialsError(`Error retrieving credentials from '${issuerMetadata.credentialIssuer.credential_issuer}'`, credentialResponse, await credentialResponse.response.clone().text());
1715
+ return credentialResponse;
1716
+ }
1717
+ /**
1718
+ * @throws Openid4vciRetrieveCredentialsError - if an unsuccessful response or the response couldn't be parsed as credential response
1719
+ * @throws ValidationError - if validation of the credential request failed
1720
+ */
1721
+ async retrieveDeferredCredentials(options) {
1722
+ const credentialResponse = await retrieveDeferredCredentials({
1723
+ ...options,
1724
+ callbacks: this.options.callbacks
1725
+ });
1726
+ if (!credentialResponse.ok) throw new Openid4vciRetrieveCredentialsError(`Error retrieving deferred credentials from '${options.issuerMetadata.credentialIssuer.credential_issuer}'`, credentialResponse, await credentialResponse.response.clone().text());
1727
+ return credentialResponse;
1728
+ }
1729
+ /**
1730
+ * @throws Openid4vciSendNotificationError - if an unsuccessful response
1731
+ * @throws ValidationError - if validation of the notification request failed
1732
+ */
1733
+ async sendNotification({ issuerMetadata, notification, additionalRequestPayload, accessToken, dpop }) {
1734
+ const notificationResponse = await sendNotification({
1735
+ accessToken,
1736
+ issuerMetadata,
1737
+ additionalRequestPayload,
1738
+ callbacks: this.options.callbacks,
1739
+ dpop,
1740
+ notification
1741
+ });
1742
+ if (!notificationResponse.ok) throw new Openid4vciSendNotificationError(`Error sending notification to '${issuerMetadata.credentialIssuer.credential_issuer}'`, notificationResponse);
1743
+ return notificationResponse;
1744
+ }
2317
1745
  };
2318
1746
 
2319
- // src/Openid4vciIssuer.ts
2320
- var import_oauth220 = require("@openid4vc/oauth2");
2321
- var import_utils21 = require("@openid4vc/utils");
2322
-
2323
- // src/credential-request/credential-response.ts
2324
- var import_utils18 = require("@openid4vc/utils");
1747
+ //#endregion
1748
+ //#region src/credential-request/credential-response.ts
2325
1749
  function createCredentialResponse(options) {
2326
- return (0, import_utils18.parseWithErrorHandling)(zCredentialResponse, {
2327
- c_nonce: options.cNonce,
2328
- c_nonce_expires_in: options.cNonceExpiresInSeconds,
2329
- credential: options.credential,
2330
- credentials: options.credentials,
2331
- notification_id: options.notificationId,
2332
- transaction_id: options.transactionId,
2333
- interval: options.interval,
2334
- // NOTE `format` is removed in draft 13. For now if a format was requested
2335
- // we just always return it in the response as well.
2336
- format: options.credentialRequest.format?.format,
2337
- ...options.additionalPayload
2338
- });
1750
+ return (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialResponse, {
1751
+ c_nonce: options.cNonce,
1752
+ c_nonce_expires_in: options.cNonceExpiresInSeconds,
1753
+ credential: options.credential,
1754
+ credentials: options.credentials,
1755
+ notification_id: options.notificationId,
1756
+ transaction_id: options.transactionId,
1757
+ interval: options.interval,
1758
+ format: options.credentialRequest.format?.format,
1759
+ ...options.additionalPayload
1760
+ });
2339
1761
  }
2340
1762
  function createDeferredCredentialResponse(options) {
2341
- return (0, import_utils18.parseWithErrorHandling)(zDeferredCredentialResponse, {
2342
- credentials: options.credentials,
2343
- notification_id: options.notificationId,
2344
- interval: options.interval,
2345
- ...options.additionalPayload
2346
- });
1763
+ return (0, __openid4vc_utils.parseWithErrorHandling)(zDeferredCredentialResponse, {
1764
+ credentials: options.credentials,
1765
+ notification_id: options.notificationId,
1766
+ interval: options.interval,
1767
+ ...options.additionalPayload
1768
+ });
2347
1769
  }
2348
1770
 
2349
- // src/credential-request/parse-credential-request.ts
2350
- var import_utils19 = require("@openid4vc/utils");
2351
- var import_zod22 = __toESM(require("zod"));
1771
+ //#endregion
1772
+ //#region src/credential-request/parse-credential-request.ts
2352
1773
  function parseCredentialRequest(options) {
2353
- const credentialRequest = (0, import_utils19.parseWithErrorHandling)(
2354
- zCredentialRequest,
2355
- options.credentialRequest,
2356
- "Error validating credential request"
2357
- );
2358
- let proofs = void 0;
2359
- const knownProofs = zCredentialRequestProofs.strict().safeParse(credentialRequest.proofs);
2360
- if (knownProofs.success) {
2361
- proofs = knownProofs.data;
2362
- }
2363
- const knownProof = import_zod22.default.union(allCredentialRequestProofs).safeParse(credentialRequest.proof);
2364
- if (knownProof.success && knownProof.data.proof_type === jwtProofTypeIdentifier) {
2365
- proofs = { [jwtProofTypeIdentifier]: [knownProof.data.jwt] };
2366
- } else if (knownProof.success && knownProof.data.proof_type === attestationProofTypeIdentifier) {
2367
- proofs = { [attestationProofTypeIdentifier]: [knownProof.data.attestation] };
2368
- }
2369
- if (credentialRequest.credential_configuration_id) {
2370
- getCredentialConfigurationSupportedById(
2371
- options.issuerMetadata.credentialIssuer.credential_configurations_supported,
2372
- credentialRequest.credential_configuration_id
2373
- );
2374
- const credentialConfigurations = extractKnownCredentialConfigurationSupportedFormats(
2375
- options.issuerMetadata.credentialIssuer.credential_configurations_supported
2376
- );
2377
- return {
2378
- credentialConfiguration: credentialConfigurations[credentialRequest.credential_configuration_id],
2379
- credentialConfigurationId: credentialRequest.credential_configuration_id,
2380
- credentialRequest,
2381
- proofs
2382
- };
2383
- }
2384
- if (credentialRequest.credential_identifier) {
2385
- return {
2386
- credentialIdentifier: credentialRequest.credential_identifier,
2387
- credentialRequest,
2388
- proofs
2389
- };
2390
- }
2391
- if (credentialRequest.format && allCredentialRequestFormatIdentifiers.includes(
2392
- credentialRequest.format
2393
- )) {
2394
- return {
2395
- // Removes all claims that are not specific to this format
2396
- format: (0, import_utils19.parseWithErrorHandling)(
2397
- import_zod22.default.union(allCredentialRequestFormats),
2398
- credentialRequest,
2399
- "Unable to validate format specific properties from credential request"
2400
- ),
2401
- credentialRequest,
2402
- proofs
2403
- };
2404
- }
2405
- return {
2406
- credentialRequest,
2407
- proofs
2408
- };
1774
+ const credentialRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialRequest, options.credentialRequest, "Error validating credential request");
1775
+ let proofs;
1776
+ const knownProofs = zCredentialRequestProofs.strict().safeParse(credentialRequest.proofs);
1777
+ if (knownProofs.success) proofs = knownProofs.data;
1778
+ const knownProof = zod.default.union(allCredentialRequestProofs).safeParse(credentialRequest.proof);
1779
+ if (knownProof.success && knownProof.data.proof_type === jwtProofTypeIdentifier) proofs = { [jwtProofTypeIdentifier]: [knownProof.data.jwt] };
1780
+ else if (knownProof.success && knownProof.data.proof_type === attestationProofTypeIdentifier) proofs = { [attestationProofTypeIdentifier]: [knownProof.data.attestation] };
1781
+ if (credentialRequest.credential_configuration_id) {
1782
+ getCredentialConfigurationSupportedById(options.issuerMetadata.credentialIssuer.credential_configurations_supported, credentialRequest.credential_configuration_id);
1783
+ return {
1784
+ credentialConfiguration: extractKnownCredentialConfigurationSupportedFormats(options.issuerMetadata.credentialIssuer.credential_configurations_supported)[credentialRequest.credential_configuration_id],
1785
+ credentialConfigurationId: credentialRequest.credential_configuration_id,
1786
+ credentialRequest,
1787
+ proofs
1788
+ };
1789
+ }
1790
+ if (credentialRequest.credential_identifier) return {
1791
+ credentialIdentifier: credentialRequest.credential_identifier,
1792
+ credentialRequest,
1793
+ proofs
1794
+ };
1795
+ if (credentialRequest.format && allCredentialRequestFormatIdentifiers.includes(credentialRequest.format)) return {
1796
+ format: (0, __openid4vc_utils.parseWithErrorHandling)(zod.default.union(allCredentialRequestFormats), credentialRequest, "Unable to validate format specific properties from credential request"),
1797
+ credentialRequest,
1798
+ proofs
1799
+ };
1800
+ return {
1801
+ credentialRequest,
1802
+ proofs
1803
+ };
2409
1804
  }
2410
1805
 
2411
- // src/credential-request/parse-deferred-credential-request.ts
2412
- var import_utils20 = require("@openid4vc/utils");
1806
+ //#endregion
1807
+ //#region src/credential-request/parse-deferred-credential-request.ts
2413
1808
  function parseDeferredCredentialRequest(options) {
2414
- const deferredCredentialRequest = (0, import_utils20.parseWithErrorHandling)(
2415
- zDeferredCredentialRequest,
2416
- options.deferredCredentialRequest,
2417
- "Error validating credential request"
2418
- );
2419
- return {
2420
- deferredCredentialRequest
2421
- };
1809
+ return { deferredCredentialRequest: (0, __openid4vc_utils.parseWithErrorHandling)(zDeferredCredentialRequest, options.deferredCredentialRequest, "Error validating credential request") };
2422
1810
  }
2423
1811
 
2424
- // src/formats/proof-type/attestation/attestation-proof-type.ts
1812
+ //#endregion
1813
+ //#region src/formats/proof-type/attestation/attestation-proof-type.ts
2425
1814
  async function verifyCredentialRequestAttestationProof(options) {
2426
- const verificationResult = await verifyKeyAttestationJwt({
2427
- ...options,
2428
- use: "proof_type.attestation"
2429
- });
2430
- return verificationResult;
1815
+ return await verifyKeyAttestationJwt({
1816
+ ...options,
1817
+ use: "proof_type.attestation"
1818
+ });
2431
1819
  }
2432
1820
 
2433
- // src/Openid4vciIssuer.ts
1821
+ //#endregion
1822
+ //#region src/Openid4vciIssuer.ts
2434
1823
  var Openid4vciIssuer = class {
2435
- constructor(options) {
2436
- this.options = options;
2437
- }
2438
- getCredentialIssuerMetadataDraft11(credentialIssuerMetadata) {
2439
- return (0, import_utils21.parseWithErrorHandling)(zCredentialIssuerMetadataWithDraft11, credentialIssuerMetadata);
2440
- }
2441
- getKnownCredentialConfigurationsSupported(credentialIssuerMetadata) {
2442
- return extractKnownCredentialConfigurationSupportedFormats(
2443
- credentialIssuerMetadata.credential_configurations_supported
2444
- );
2445
- }
2446
- /**
2447
- * Create issuer metadata and validates the structure is correct
2448
- */
2449
- createCredentialIssuerMetadata(credentialIssuerMetadata) {
2450
- return (0, import_utils21.parseWithErrorHandling)(
2451
- zCredentialIssuerMetadata,
2452
- credentialIssuerMetadata,
2453
- "Error validating credential issuer metadata"
2454
- );
2455
- }
2456
- async createCredentialOffer(options) {
2457
- return createCredentialOffer({
2458
- callbacks: this.options.callbacks,
2459
- credentialConfigurationIds: options.credentialConfigurationIds,
2460
- grants: options.grants,
2461
- issuerMetadata: options.issuerMetadata,
2462
- additionalPayload: options.additionalPayload,
2463
- credentialOfferScheme: options.credentialOfferScheme,
2464
- credentialOfferUri: options.credentialOfferUri
2465
- });
2466
- }
2467
- /**
2468
- * @throws Oauth2ServerErrorResponseError - if verification of the jwt failed. You can extract
2469
- * the credential error response from this.
2470
- */
2471
- async verifyCredentialRequestJwtProof(options) {
2472
- try {
2473
- return await verifyCredentialRequestJwtProof({
2474
- callbacks: this.options.callbacks,
2475
- credentialIssuer: options.issuerMetadata.credentialIssuer.credential_issuer,
2476
- expectedNonce: options.expectedNonce,
2477
- nonceExpiresAt: options.nonceExpiresAt,
2478
- jwt: options.jwt,
2479
- clientId: options.clientId,
2480
- now: options.now
2481
- });
2482
- } catch (error) {
2483
- throw new import_oauth220.Oauth2ServerErrorResponseError(
2484
- {
2485
- error: import_oauth220.Oauth2ErrorCodes.InvalidProof,
2486
- error_description: (
2487
- // TODO: error should have a internalErrorMessage and a publicErrorMessage
2488
- error instanceof import_oauth220.Oauth2JwtVerificationError || error instanceof Openid4vciError ? error.message : "Invalid proof"
2489
- )
2490
- },
2491
- {
2492
- internalMessage: "Error verifying credential request proof jwt",
2493
- cause: error
2494
- }
2495
- );
2496
- }
2497
- }
2498
- /**
2499
- * @throws Oauth2ServerErrorResponseError - if verification of the key attestation failed. You can extract
2500
- * the credential error response from this.
2501
- */
2502
- async verifyCredentialRequestAttestationProof(options) {
2503
- try {
2504
- return await verifyCredentialRequestAttestationProof({
2505
- callbacks: this.options.callbacks,
2506
- expectedNonce: options.expectedNonce,
2507
- keyAttestationJwt: options.keyAttestationJwt,
2508
- nonceExpiresAt: options.nonceExpiresAt,
2509
- now: options.now
2510
- });
2511
- } catch (error) {
2512
- throw new import_oauth220.Oauth2ServerErrorResponseError(
2513
- {
2514
- error: import_oauth220.Oauth2ErrorCodes.InvalidProof,
2515
- error_description: (
2516
- // TODO: error should have a internalErrorMessage and a publicErrorMessage
2517
- error instanceof import_oauth220.Oauth2JwtVerificationError || error instanceof Openid4vciError ? error.message : "Invalid proof"
2518
- )
2519
- },
2520
- {
2521
- internalMessage: "Error verifying credential request proof attestation",
2522
- cause: error
2523
- }
2524
- );
2525
- }
2526
- }
2527
- /**
2528
- * @throws Oauth2ServerErrorResponseError - when validation of the credential request fails
2529
- * You can extract the credential error response from this.
2530
- */
2531
- parseCredentialRequest(options) {
2532
- try {
2533
- return parseCredentialRequest(options);
2534
- } catch (error) {
2535
- throw new import_oauth220.Oauth2ServerErrorResponseError(
2536
- {
2537
- error: import_oauth220.Oauth2ErrorCodes.InvalidCredentialRequest,
2538
- error_description: (
2539
- // TODO: error should have a internalErrorMessage and a publicErrorMessage
2540
- error instanceof import_utils21.ValidationError ? error.message : "Invalid request"
2541
- )
2542
- },
2543
- {
2544
- internalMessage: "Error verifying credential request proof jwt",
2545
- cause: error
2546
- }
2547
- );
2548
- }
2549
- }
2550
- /**
2551
- * @throws Oauth2ServerErrorResponseError - when validation of the deferred credential request fails
2552
- */
2553
- parseDeferredCredentialRequest(options) {
2554
- try {
2555
- return parseDeferredCredentialRequest(options);
2556
- } catch (error) {
2557
- throw new import_oauth220.Oauth2ServerErrorResponseError(
2558
- {
2559
- error: import_oauth220.Oauth2ErrorCodes.InvalidCredentialRequest,
2560
- error_description: error instanceof import_utils21.ValidationError ? error.message : "Invalid request"
2561
- },
2562
- {
2563
- internalMessage: "Error parsing deferred credential request",
2564
- cause: error
2565
- }
2566
- );
2567
- }
2568
- }
2569
- /**
2570
- * @throws ValidationError - when validation of the credential response fails
2571
- */
2572
- createCredentialResponse(options) {
2573
- return createCredentialResponse(options);
2574
- }
2575
- /**
2576
- * @throws ValidationError - when validation of the credential response fails
2577
- */
2578
- createDeferredCredentialResponse(options) {
2579
- return createDeferredCredentialResponse(options);
2580
- }
2581
- /**
2582
- * @throws ValidationError - when validation of the nonce response fails
2583
- */
2584
- createNonceResponse(options) {
2585
- return createNonceResponse(options);
2586
- }
2587
- async verifyWalletAttestation(options) {
2588
- return new import_oauth220.Oauth2AuthorizationServer({
2589
- callbacks: this.options.callbacks
2590
- }).verifyClientAttestation(options);
2591
- }
1824
+ constructor(options) {
1825
+ this.options = options;
1826
+ }
1827
+ getCredentialIssuerMetadataDraft11(credentialIssuerMetadata) {
1828
+ return (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialIssuerMetadataWithDraft11, credentialIssuerMetadata);
1829
+ }
1830
+ getKnownCredentialConfigurationsSupported(credentialIssuerMetadata) {
1831
+ return extractKnownCredentialConfigurationSupportedFormats(credentialIssuerMetadata.credential_configurations_supported);
1832
+ }
1833
+ /**
1834
+ * Create issuer metadata and validates the structure is correct
1835
+ */
1836
+ createCredentialIssuerMetadata(credentialIssuerMetadata) {
1837
+ return (0, __openid4vc_utils.parseWithErrorHandling)(zCredentialIssuerMetadata, credentialIssuerMetadata, "Error validating credential issuer metadata");
1838
+ }
1839
+ async createCredentialOffer(options) {
1840
+ return createCredentialOffer({
1841
+ callbacks: this.options.callbacks,
1842
+ credentialConfigurationIds: options.credentialConfigurationIds,
1843
+ grants: options.grants,
1844
+ issuerMetadata: options.issuerMetadata,
1845
+ additionalPayload: options.additionalPayload,
1846
+ credentialOfferScheme: options.credentialOfferScheme,
1847
+ credentialOfferUri: options.credentialOfferUri
1848
+ });
1849
+ }
1850
+ /**
1851
+ * @throws Oauth2ServerErrorResponseError - if verification of the jwt failed. You can extract
1852
+ * the credential error response from this.
1853
+ */
1854
+ async verifyCredentialRequestJwtProof(options) {
1855
+ try {
1856
+ return await verifyCredentialRequestJwtProof({
1857
+ callbacks: this.options.callbacks,
1858
+ credentialIssuer: options.issuerMetadata.credentialIssuer.credential_issuer,
1859
+ expectedNonce: options.expectedNonce,
1860
+ nonceExpiresAt: options.nonceExpiresAt,
1861
+ jwt: options.jwt,
1862
+ clientId: options.clientId,
1863
+ now: options.now
1864
+ });
1865
+ } catch (error) {
1866
+ throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
1867
+ error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidProof,
1868
+ error_description: error instanceof __openid4vc_oauth2.Oauth2JwtVerificationError || error instanceof Openid4vciError ? error.message : "Invalid proof"
1869
+ }, {
1870
+ internalMessage: "Error verifying credential request proof jwt",
1871
+ cause: error
1872
+ });
1873
+ }
1874
+ }
1875
+ /**
1876
+ * @throws Oauth2ServerErrorResponseError - if verification of the key attestation failed. You can extract
1877
+ * the credential error response from this.
1878
+ */
1879
+ async verifyCredentialRequestAttestationProof(options) {
1880
+ try {
1881
+ return await verifyCredentialRequestAttestationProof({
1882
+ callbacks: this.options.callbacks,
1883
+ expectedNonce: options.expectedNonce,
1884
+ keyAttestationJwt: options.keyAttestationJwt,
1885
+ nonceExpiresAt: options.nonceExpiresAt,
1886
+ now: options.now
1887
+ });
1888
+ } catch (error) {
1889
+ throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
1890
+ error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidProof,
1891
+ error_description: error instanceof __openid4vc_oauth2.Oauth2JwtVerificationError || error instanceof Openid4vciError ? error.message : "Invalid proof"
1892
+ }, {
1893
+ internalMessage: "Error verifying credential request proof attestation",
1894
+ cause: error
1895
+ });
1896
+ }
1897
+ }
1898
+ /**
1899
+ * @throws Oauth2ServerErrorResponseError - when validation of the credential request fails
1900
+ * You can extract the credential error response from this.
1901
+ */
1902
+ parseCredentialRequest(options) {
1903
+ try {
1904
+ return parseCredentialRequest(options);
1905
+ } catch (error) {
1906
+ throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
1907
+ error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidCredentialRequest,
1908
+ error_description: error instanceof __openid4vc_utils.ValidationError ? error.message : "Invalid request"
1909
+ }, {
1910
+ internalMessage: "Error verifying credential request proof jwt",
1911
+ cause: error
1912
+ });
1913
+ }
1914
+ }
1915
+ /**
1916
+ * @throws Oauth2ServerErrorResponseError - when validation of the deferred credential request fails
1917
+ */
1918
+ parseDeferredCredentialRequest(options) {
1919
+ try {
1920
+ return parseDeferredCredentialRequest(options);
1921
+ } catch (error) {
1922
+ throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
1923
+ error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidCredentialRequest,
1924
+ error_description: error instanceof __openid4vc_utils.ValidationError ? error.message : "Invalid request"
1925
+ }, {
1926
+ internalMessage: "Error parsing deferred credential request",
1927
+ cause: error
1928
+ });
1929
+ }
1930
+ }
1931
+ /**
1932
+ * @throws ValidationError - when validation of the credential response fails
1933
+ */
1934
+ createCredentialResponse(options) {
1935
+ return createCredentialResponse(options);
1936
+ }
1937
+ /**
1938
+ * @throws ValidationError - when validation of the credential response fails
1939
+ */
1940
+ createDeferredCredentialResponse(options) {
1941
+ return createDeferredCredentialResponse(options);
1942
+ }
1943
+ /**
1944
+ * @throws ValidationError - when validation of the nonce response fails
1945
+ */
1946
+ createNonceResponse(options) {
1947
+ return createNonceResponse(options);
1948
+ }
1949
+ async verifyWalletAttestation(options) {
1950
+ return new __openid4vc_oauth2.Oauth2AuthorizationServer({ callbacks: this.options.callbacks }).verifyClientAttestation(options);
1951
+ }
2592
1952
  };
2593
1953
 
2594
- // src/Openid4vciWalletProvider.ts
2595
- var import_oauth221 = require("@openid4vc/oauth2");
1954
+ //#endregion
1955
+ //#region src/Openid4vciWalletProvider.ts
2596
1956
  var Openid4vciWalletProvider = class {
2597
- constructor(options) {
2598
- this.options = options;
2599
- }
2600
- async createWalletAttestationJwt(options) {
2601
- const additionalPayload = options.additionalPayload ? {
2602
- wallet_name: options.walletName,
2603
- wallet_link: options.walletLink,
2604
- ...options.additionalPayload
2605
- } : {
2606
- wallet_name: options.walletName,
2607
- wallet_link: options.walletLink
2608
- };
2609
- return await (0, import_oauth221.createClientAttestationJwt)({
2610
- ...options,
2611
- callbacks: this.options.callbacks,
2612
- additionalPayload
2613
- });
1957
+ constructor(options) {
1958
+ this.options = options;
1959
+ }
1960
+ async createWalletAttestationJwt(options) {
1961
+ const additionalPayload = options.additionalPayload ? {
1962
+ wallet_name: options.walletName,
1963
+ wallet_link: options.walletLink,
1964
+ ...options.additionalPayload
1965
+ } : {
1966
+ wallet_name: options.walletName,
1967
+ wallet_link: options.walletLink
1968
+ };
1969
+ return await (0, __openid4vc_oauth2.createClientAttestationJwt)({
1970
+ ...options,
1971
+ callbacks: this.options.callbacks,
1972
+ additionalPayload
1973
+ });
1974
+ }
1975
+ async createKeyAttestationJwt(options) {
1976
+ return await createKeyAttestationJwt({
1977
+ callbacks: this.options.callbacks,
1978
+ ...options
1979
+ });
1980
+ }
1981
+ };
1982
+
1983
+ //#endregion
1984
+ exports.AuthorizationFlow = AuthorizationFlow;
1985
+ exports.Openid4vciClient = Openid4vciClient;
1986
+ exports.Openid4vciDraftVersion = Openid4vciDraftVersion;
1987
+ exports.Openid4vciError = Openid4vciError;
1988
+ exports.Openid4vciIssuer = Openid4vciIssuer;
1989
+ exports.Openid4vciRetrieveCredentialsError = Openid4vciRetrieveCredentialsError;
1990
+ exports.Openid4vciSendNotificationError = Openid4vciSendNotificationError;
1991
+ exports.Openid4vciWalletProvider = Openid4vciWalletProvider;
1992
+ exports.createKeyAttestationJwt = createKeyAttestationJwt;
1993
+ exports.credentialsSupportedToCredentialConfigurationsSupported = credentialsSupportedToCredentialConfigurationsSupported;
1994
+ exports.determineAuthorizationServerForCredentialOffer = determineAuthorizationServerForCredentialOffer;
1995
+ exports.extractScopesForCredentialConfigurationIds = extractScopesForCredentialConfigurationIds;
1996
+ exports.getCredentialConfigurationsMatchingRequestFormat = getCredentialConfigurationsMatchingRequestFormat;
1997
+ Object.defineProperty(exports, 'getGlobalConfig', {
1998
+ enumerable: true,
1999
+ get: function () {
2000
+ return __openid4vc_utils.getGlobalConfig;
2614
2001
  }
2615
- async createKeyAttestationJwt(options) {
2616
- return await createKeyAttestationJwt({
2617
- callbacks: this.options.callbacks,
2618
- ...options
2619
- });
2002
+ });
2003
+ exports.parseKeyAttestationJwt = parseKeyAttestationJwt;
2004
+ Object.defineProperty(exports, 'setGlobalConfig', {
2005
+ enumerable: true,
2006
+ get: function () {
2007
+ return __openid4vc_utils.setGlobalConfig;
2620
2008
  }
2621
- };
2622
- // Annotate the CommonJS export names for ESM import in node:
2623
- 0 && (module.exports = {
2624
- AuthorizationFlow,
2625
- Openid4vciClient,
2626
- Openid4vciDraftVersion,
2627
- Openid4vciError,
2628
- Openid4vciIssuer,
2629
- Openid4vciRetrieveCredentialsError,
2630
- Openid4vciSendNotificationError,
2631
- Openid4vciWalletProvider,
2632
- createKeyAttestationJwt,
2633
- credentialsSupportedToCredentialConfigurationsSupported,
2634
- determineAuthorizationServerForCredentialOffer,
2635
- extractScopesForCredentialConfigurationIds,
2636
- getCredentialConfigurationsMatchingRequestFormat,
2637
- getGlobalConfig,
2638
- parseKeyAttestationJwt,
2639
- setGlobalConfig,
2640
- verifyKeyAttestationJwt
2641
2009
  });
2010
+ exports.verifyKeyAttestationJwt = verifyKeyAttestationJwt;
2642
2011
  //# sourceMappingURL=index.js.map