@openid4vc/openid4vci 0.3.0-alpha-20250325212250 → 0.3.0-alpha-20250328112257
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8194 -5423
- package/dist/index.d.ts +8194 -5423
- package/dist/index.js +514 -500
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +487 -479
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,231 @@
|
|
|
1
|
+
// src/credential-offer/credential-offer.ts
|
|
2
|
+
import {
|
|
3
|
+
InvalidFetchResponseError,
|
|
4
|
+
Oauth2Error,
|
|
5
|
+
authorizationCodeGrantIdentifier,
|
|
6
|
+
getAuthorizationServerMetadataFromList,
|
|
7
|
+
preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier2
|
|
8
|
+
} from "@openid4vc/oauth2";
|
|
9
|
+
import {
|
|
10
|
+
ContentType,
|
|
11
|
+
URL,
|
|
12
|
+
URLSearchParams,
|
|
13
|
+
ValidationError,
|
|
14
|
+
createZodFetcher,
|
|
15
|
+
encodeToBase64Url,
|
|
16
|
+
getQueryParams,
|
|
17
|
+
objectToQueryParams,
|
|
18
|
+
parseWithErrorHandling
|
|
19
|
+
} from "@openid4vc/utils";
|
|
20
|
+
|
|
21
|
+
// src/version.ts
|
|
22
|
+
var Openid4vciDraftVersion = /* @__PURE__ */ ((Openid4vciDraftVersion2) => {
|
|
23
|
+
Openid4vciDraftVersion2["Draft15"] = "Draft15";
|
|
24
|
+
Openid4vciDraftVersion2["Draft14"] = "Draft14";
|
|
25
|
+
Openid4vciDraftVersion2["Draft11"] = "Draft11";
|
|
26
|
+
return Openid4vciDraftVersion2;
|
|
27
|
+
})(Openid4vciDraftVersion || {});
|
|
28
|
+
|
|
29
|
+
// src/credential-offer/z-credential-offer.ts
|
|
30
|
+
import {
|
|
31
|
+
preAuthorizedCodeGrantIdentifier
|
|
32
|
+
} from "@openid4vc/oauth2";
|
|
33
|
+
import { zHttpsUrl } from "@openid4vc/utils";
|
|
34
|
+
import z from "zod";
|
|
35
|
+
var zTxCode = z.object({
|
|
36
|
+
input_mode: z.union([z.literal("numeric"), z.literal("text")]).optional(),
|
|
37
|
+
length: z.number().int().optional(),
|
|
38
|
+
description: z.string().max(300).optional()
|
|
39
|
+
}).passthrough();
|
|
40
|
+
var zCredentialOfferGrants = z.object({
|
|
41
|
+
authorization_code: z.object({
|
|
42
|
+
issuer_state: z.string().optional(),
|
|
43
|
+
authorization_server: zHttpsUrl.optional()
|
|
44
|
+
}).passthrough().optional(),
|
|
45
|
+
[preAuthorizedCodeGrantIdentifier]: z.object({
|
|
46
|
+
"pre-authorized_code": z.string(),
|
|
47
|
+
tx_code: zTxCode.optional(),
|
|
48
|
+
authorization_server: zHttpsUrl.optional()
|
|
49
|
+
}).passthrough().optional()
|
|
50
|
+
}).passthrough();
|
|
51
|
+
var zCredentialOfferObjectDraft14 = z.object({
|
|
52
|
+
credential_issuer: zHttpsUrl,
|
|
53
|
+
credential_configuration_ids: z.array(z.string()),
|
|
54
|
+
grants: z.optional(zCredentialOfferGrants)
|
|
55
|
+
}).passthrough();
|
|
56
|
+
var zCredentialOfferObjectDraft11To14 = z.object({
|
|
57
|
+
credential_issuer: zHttpsUrl,
|
|
58
|
+
// We don't support the inline offer objects from draft 11
|
|
59
|
+
credentials: z.array(
|
|
60
|
+
z.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })
|
|
61
|
+
),
|
|
62
|
+
grants: z.optional(
|
|
63
|
+
z.object({
|
|
64
|
+
// Has extra param in draft 14, but doesn't matter for transform purposes
|
|
65
|
+
authorization_code: zCredentialOfferGrants.shape.authorization_code,
|
|
66
|
+
[preAuthorizedCodeGrantIdentifier]: z.object({
|
|
67
|
+
"pre-authorized_code": z.string(),
|
|
68
|
+
user_pin_required: z.optional(z.boolean())
|
|
69
|
+
}).passthrough().optional()
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
}).passthrough().transform(({ credentials, grants, ...rest }) => {
|
|
73
|
+
const v14 = {
|
|
74
|
+
...rest,
|
|
75
|
+
credential_configuration_ids: credentials
|
|
76
|
+
};
|
|
77
|
+
if (grants) {
|
|
78
|
+
v14.grants = { ...grants };
|
|
79
|
+
if (grants[preAuthorizedCodeGrantIdentifier]) {
|
|
80
|
+
const { user_pin_required, ...restGrants } = grants[preAuthorizedCodeGrantIdentifier];
|
|
81
|
+
v14.grants[preAuthorizedCodeGrantIdentifier] = {
|
|
82
|
+
...restGrants
|
|
83
|
+
};
|
|
84
|
+
if (user_pin_required) {
|
|
85
|
+
v14.grants[preAuthorizedCodeGrantIdentifier].tx_code = {
|
|
86
|
+
input_mode: "text"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return v14;
|
|
92
|
+
}).pipe(zCredentialOfferObjectDraft14);
|
|
93
|
+
var zCredentialOfferObject = z.union([
|
|
94
|
+
// First prioritize draft 14 (and 13)
|
|
95
|
+
zCredentialOfferObjectDraft14,
|
|
96
|
+
// Then try parsing draft 11 and transform into draft 14
|
|
97
|
+
zCredentialOfferObjectDraft11To14
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
// src/credential-offer/credential-offer.ts
|
|
101
|
+
async function resolveCredentialOffer(credentialOffer, options) {
|
|
102
|
+
const parsedQueryParams = getQueryParams(credentialOffer);
|
|
103
|
+
let credentialOfferParseResult;
|
|
104
|
+
if (parsedQueryParams.credential_offer_uri) {
|
|
105
|
+
const fetchWithZod = createZodFetcher(options?.fetch);
|
|
106
|
+
const { response, result } = await fetchWithZod(
|
|
107
|
+
zCredentialOfferObject,
|
|
108
|
+
ContentType.Json,
|
|
109
|
+
parsedQueryParams.credential_offer_uri
|
|
110
|
+
);
|
|
111
|
+
if (!response.ok || !result) {
|
|
112
|
+
throw new InvalidFetchResponseError(
|
|
113
|
+
`Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccesfull response with status '${response.status}'`,
|
|
114
|
+
await response.clone().text(),
|
|
115
|
+
response
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
credentialOfferParseResult = result;
|
|
119
|
+
} else if (parsedQueryParams.credential_offer) {
|
|
120
|
+
let credentialOfferJson;
|
|
121
|
+
try {
|
|
122
|
+
credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw new Oauth2Error(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
|
|
125
|
+
}
|
|
126
|
+
credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
|
|
127
|
+
} else {
|
|
128
|
+
throw new Oauth2Error(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
|
|
129
|
+
}
|
|
130
|
+
if (credentialOfferParseResult.error) {
|
|
131
|
+
throw new ValidationError(
|
|
132
|
+
`Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`,
|
|
133
|
+
credentialOfferParseResult.error
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return credentialOfferParseResult.data;
|
|
137
|
+
}
|
|
138
|
+
function determineAuthorizationServerForCredentialOffer(options) {
|
|
139
|
+
const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
|
|
140
|
+
let authorizationServer;
|
|
141
|
+
if (options.grantAuthorizationServer) {
|
|
142
|
+
authorizationServer = options.grantAuthorizationServer;
|
|
143
|
+
if (!authorizationServers) {
|
|
144
|
+
throw new Oauth2Error(
|
|
145
|
+
`Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not have an 'authorization_servers' property to match the value against.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (!authorizationServers.includes(authorizationServer)) {
|
|
149
|
+
throw new Oauth2Error(
|
|
150
|
+
`Credential offer grant contains 'authorization_server' with value '${options.grantAuthorizationServer}' but credential issuer metadata does not include this authorization server. Available 'authorization_server' values are ${authorizationServers.join(", ")}.`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
} else if (!authorizationServers) {
|
|
154
|
+
authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
|
|
155
|
+
} else {
|
|
156
|
+
if (authorizationServers.length === 0) {
|
|
157
|
+
throw new Oauth2Error(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
|
|
158
|
+
}
|
|
159
|
+
if (authorizationServers.length > 1) {
|
|
160
|
+
throw new Oauth2Error(
|
|
161
|
+
`Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
authorizationServer = authorizationServers[0];
|
|
165
|
+
}
|
|
166
|
+
return authorizationServer;
|
|
167
|
+
}
|
|
168
|
+
async function createCredentialOffer(options) {
|
|
169
|
+
const {
|
|
170
|
+
[preAuthorizedCodeGrantIdentifier2]: preAuthorizedCodeGrant,
|
|
171
|
+
[authorizationCodeGrantIdentifier]: authorizationCodeGrant,
|
|
172
|
+
...restGrants
|
|
173
|
+
} = options.grants;
|
|
174
|
+
const grants = { ...restGrants };
|
|
175
|
+
if (authorizationCodeGrant) {
|
|
176
|
+
determineAuthorizationServerForCredentialOffer({
|
|
177
|
+
issuerMetadata: options.issuerMetadata,
|
|
178
|
+
grantAuthorizationServer: authorizationCodeGrant.authorization_server
|
|
179
|
+
});
|
|
180
|
+
grants[authorizationCodeGrantIdentifier] = authorizationCodeGrant;
|
|
181
|
+
}
|
|
182
|
+
if (preAuthorizedCodeGrant) {
|
|
183
|
+
determineAuthorizationServerForCredentialOffer({
|
|
184
|
+
issuerMetadata: options.issuerMetadata,
|
|
185
|
+
grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
|
|
186
|
+
});
|
|
187
|
+
grants[preAuthorizedCodeGrantIdentifier2] = {
|
|
188
|
+
...preAuthorizedCodeGrant,
|
|
189
|
+
"pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? encodeToBase64Url(await options.callbacks.generateRandom(32))
|
|
190
|
+
};
|
|
191
|
+
const txCode = grants[preAuthorizedCodeGrantIdentifier2].tx_code;
|
|
192
|
+
if (txCode && options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
|
|
193
|
+
grants[preAuthorizedCodeGrantIdentifier2].user_pin_required = txCode !== void 0;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const idsNotInMetadata = options.credentialConfigurationIds.filter(
|
|
197
|
+
(id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0
|
|
198
|
+
);
|
|
199
|
+
if (idsNotInMetadata.length > 0) {
|
|
200
|
+
throw new Oauth2Error(
|
|
201
|
+
`Credential configuration ids ${idsNotInMetadata} not found in the credential issuer metadata 'credential_configurations_supported'. Available ids are ${Object.keys(options.issuerMetadata.credentialIssuer.credential_configurations_supported).join(", ")}.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
|
|
205
|
+
const credentialOfferObject = parseWithErrorHandling(zCredentialOfferObject, {
|
|
206
|
+
credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
|
|
207
|
+
credential_configuration_ids: options.credentialConfigurationIds,
|
|
208
|
+
grants,
|
|
209
|
+
...options.additionalPayload
|
|
210
|
+
});
|
|
211
|
+
if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
|
|
212
|
+
credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
|
|
213
|
+
}
|
|
214
|
+
const url = new URL(credentialOfferScheme);
|
|
215
|
+
url.search = `?${new URLSearchParams([
|
|
216
|
+
...url.searchParams.entries(),
|
|
217
|
+
...objectToQueryParams({
|
|
218
|
+
credential_offer_uri: options.credentialOfferUri,
|
|
219
|
+
// Only add credential_offer is uri is undefined
|
|
220
|
+
credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
|
|
221
|
+
}).entries()
|
|
222
|
+
]).toString()}`;
|
|
223
|
+
return {
|
|
224
|
+
credentialOffer: url.toString(),
|
|
225
|
+
credentialOfferObject
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
1
229
|
// src/index.ts
|
|
2
230
|
import { getGlobalConfig, setGlobalConfig } from "@openid4vc/utils";
|
|
3
231
|
|
|
@@ -5,38 +233,38 @@ import { getGlobalConfig, setGlobalConfig } from "@openid4vc/utils";
|
|
|
5
233
|
import { arrayEqualsIgnoreOrder } from "@openid4vc/utils";
|
|
6
234
|
|
|
7
235
|
// src/metadata/credential-issuer/credential-issuer-metadata.ts
|
|
8
|
-
import { Oauth2Error, fetchWellKnownMetadata } from "@openid4vc/oauth2";
|
|
236
|
+
import { Oauth2Error as Oauth2Error2, fetchWellKnownMetadata } from "@openid4vc/oauth2";
|
|
9
237
|
import { joinUriParts } from "@openid4vc/utils";
|
|
10
238
|
|
|
11
239
|
// src/metadata/credential-issuer/z-credential-issuer-metadata.ts
|
|
12
240
|
import { zCompactJwt } from "@openid4vc/oauth2";
|
|
13
|
-
import { zHttpsUrl } from "@openid4vc/utils";
|
|
14
|
-
import
|
|
241
|
+
import { zHttpsUrl as zHttpsUrl2 } from "@openid4vc/utils";
|
|
242
|
+
import z12 from "zod";
|
|
15
243
|
|
|
16
244
|
// src/formats/credential/mso-mdoc/z-mso-mdoc.ts
|
|
17
|
-
import
|
|
245
|
+
import z3 from "zod";
|
|
18
246
|
|
|
19
247
|
// src/metadata/credential-issuer/z-claims-description.ts
|
|
20
|
-
import
|
|
21
|
-
var zCredentialConfigurationSupportedClaimsDraft14 =
|
|
22
|
-
mandatory:
|
|
23
|
-
value_type:
|
|
24
|
-
display:
|
|
25
|
-
name:
|
|
26
|
-
locale:
|
|
248
|
+
import z2 from "zod";
|
|
249
|
+
var zCredentialConfigurationSupportedClaimsDraft14 = z2.object({
|
|
250
|
+
mandatory: z2.boolean().optional(),
|
|
251
|
+
value_type: z2.string().optional(),
|
|
252
|
+
display: z2.object({
|
|
253
|
+
name: z2.string().optional(),
|
|
254
|
+
locale: z2.string().optional()
|
|
27
255
|
}).passthrough().optional()
|
|
28
256
|
}).passthrough();
|
|
29
|
-
var zClaimsDescriptionPath =
|
|
30
|
-
var zMsoMdocClaimsDescriptionPath =
|
|
257
|
+
var zClaimsDescriptionPath = z2.array(z2.union([z2.string(), z2.number().int().nonnegative(), z2.null()])).nonempty();
|
|
258
|
+
var zMsoMdocClaimsDescriptionPath = z2.tuple([z2.string(), z2.string()], {
|
|
31
259
|
message: "mso_mdoc claims description path MUST be an array with exactly two string elements, pointing to the namespace and element identifier within an mdoc credential"
|
|
32
260
|
});
|
|
33
|
-
var zIssuerMetadataClaimsDescription =
|
|
261
|
+
var zIssuerMetadataClaimsDescription = z2.object({
|
|
34
262
|
path: zClaimsDescriptionPath,
|
|
35
|
-
mandatory:
|
|
36
|
-
display:
|
|
37
|
-
|
|
38
|
-
name:
|
|
39
|
-
locale:
|
|
263
|
+
mandatory: z2.boolean().optional(),
|
|
264
|
+
display: z2.array(
|
|
265
|
+
z2.object({
|
|
266
|
+
name: z2.string().optional(),
|
|
267
|
+
locale: z2.string().optional()
|
|
40
268
|
}).passthrough()
|
|
41
269
|
).optional()
|
|
42
270
|
}).passthrough();
|
|
@@ -45,97 +273,97 @@ var zMsoMdocIssuerMetadataClaimsDescription = zIssuerMetadataClaimsDescription.e
|
|
|
45
273
|
});
|
|
46
274
|
|
|
47
275
|
// src/formats/credential/mso-mdoc/z-mso-mdoc.ts
|
|
48
|
-
var zMsoMdocFormatIdentifier =
|
|
49
|
-
var zMsoMdocCredentialIssuerMetadata =
|
|
276
|
+
var zMsoMdocFormatIdentifier = z3.literal("mso_mdoc");
|
|
277
|
+
var zMsoMdocCredentialIssuerMetadata = z3.object({
|
|
50
278
|
format: zMsoMdocFormatIdentifier,
|
|
51
|
-
doctype:
|
|
52
|
-
claims:
|
|
279
|
+
doctype: z3.string(),
|
|
280
|
+
claims: z3.array(zMsoMdocIssuerMetadataClaimsDescription).optional()
|
|
53
281
|
});
|
|
54
|
-
var zMsoMdocCredentialIssuerMetadataDraft14 =
|
|
282
|
+
var zMsoMdocCredentialIssuerMetadataDraft14 = z3.object({
|
|
55
283
|
format: zMsoMdocFormatIdentifier,
|
|
56
|
-
doctype:
|
|
284
|
+
doctype: z3.string(),
|
|
57
285
|
claims: zCredentialConfigurationSupportedClaimsDraft14.optional(),
|
|
58
|
-
order:
|
|
286
|
+
order: z3.optional(z3.array(z3.string()))
|
|
59
287
|
});
|
|
60
|
-
var zMsoMdocCredentialRequestFormatDraft14 =
|
|
288
|
+
var zMsoMdocCredentialRequestFormatDraft14 = z3.object({
|
|
61
289
|
format: zMsoMdocFormatIdentifier,
|
|
62
|
-
doctype:
|
|
290
|
+
doctype: z3.string(),
|
|
63
291
|
// Format based request is removed in Draft 15, so only old claims syntax supported.
|
|
64
|
-
claims:
|
|
292
|
+
claims: z3.optional(zCredentialConfigurationSupportedClaimsDraft14)
|
|
65
293
|
});
|
|
66
294
|
|
|
67
295
|
// src/formats/credential/sd-jwt-vc/z-sd-jwt-vc.ts
|
|
68
|
-
import
|
|
69
|
-
var zSdJwtVcFormatIdentifier =
|
|
70
|
-
var zSdJwtVcCredentialIssuerMetadataDraft14 =
|
|
71
|
-
vct:
|
|
296
|
+
import z4 from "zod";
|
|
297
|
+
var zSdJwtVcFormatIdentifier = z4.literal("vc+sd-jwt");
|
|
298
|
+
var zSdJwtVcCredentialIssuerMetadataDraft14 = z4.object({
|
|
299
|
+
vct: z4.string(),
|
|
72
300
|
format: zSdJwtVcFormatIdentifier,
|
|
73
|
-
claims:
|
|
74
|
-
order:
|
|
301
|
+
claims: z4.optional(zCredentialConfigurationSupportedClaimsDraft14),
|
|
302
|
+
order: z4.optional(z4.array(z4.string()))
|
|
75
303
|
});
|
|
76
|
-
var zSdJwtVcCredentialRequestFormatDraft14 =
|
|
304
|
+
var zSdJwtVcCredentialRequestFormatDraft14 = z4.object({
|
|
77
305
|
format: zSdJwtVcFormatIdentifier,
|
|
78
|
-
vct:
|
|
79
|
-
claims:
|
|
306
|
+
vct: z4.string(),
|
|
307
|
+
claims: z4.optional(zCredentialConfigurationSupportedClaimsDraft14)
|
|
80
308
|
});
|
|
81
309
|
|
|
82
310
|
// src/formats/credential/sd-jwt-dc/z-sd-jwt-dc.ts
|
|
83
|
-
import
|
|
84
|
-
var zSdJwtDcFormatIdentifier =
|
|
85
|
-
var zSdJwtDcCredentialIssuerMetadata =
|
|
86
|
-
vct:
|
|
311
|
+
import z5 from "zod";
|
|
312
|
+
var zSdJwtDcFormatIdentifier = z5.literal("dc+sd-jwt");
|
|
313
|
+
var zSdJwtDcCredentialIssuerMetadata = z5.object({
|
|
314
|
+
vct: z5.string(),
|
|
87
315
|
format: zSdJwtDcFormatIdentifier,
|
|
88
|
-
claims:
|
|
316
|
+
claims: z5.array(zIssuerMetadataClaimsDescription).optional()
|
|
89
317
|
});
|
|
90
318
|
|
|
91
319
|
// src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
|
|
92
|
-
import
|
|
320
|
+
import z7 from "zod";
|
|
93
321
|
|
|
94
322
|
// src/formats/credential/w3c-vc/z-w3c-vc-common.ts
|
|
95
|
-
import
|
|
96
|
-
var zCredentialSubjectLeafTypeDraft14 =
|
|
97
|
-
mandatory:
|
|
98
|
-
value_type:
|
|
99
|
-
display:
|
|
100
|
-
|
|
101
|
-
name:
|
|
102
|
-
locale:
|
|
323
|
+
import z6 from "zod";
|
|
324
|
+
var zCredentialSubjectLeafTypeDraft14 = z6.object({
|
|
325
|
+
mandatory: z6.boolean().optional(),
|
|
326
|
+
value_type: z6.string().optional(),
|
|
327
|
+
display: z6.array(
|
|
328
|
+
z6.object({
|
|
329
|
+
name: z6.string().optional(),
|
|
330
|
+
locale: z6.string().optional()
|
|
103
331
|
}).passthrough()
|
|
104
332
|
).optional()
|
|
105
333
|
}).passthrough();
|
|
106
|
-
var zClaimValueSchemaDraft14 =
|
|
107
|
-
|
|
108
|
-
|
|
334
|
+
var zClaimValueSchemaDraft14 = z6.union([
|
|
335
|
+
z6.array(z6.any()),
|
|
336
|
+
z6.record(z6.string(), z6.any()),
|
|
109
337
|
zCredentialSubjectLeafTypeDraft14
|
|
110
338
|
]);
|
|
111
|
-
var zW3cVcCredentialSubjectDraft14 =
|
|
112
|
-
var zW3cVcJsonLdCredentialDefinition =
|
|
113
|
-
"@context":
|
|
114
|
-
type:
|
|
339
|
+
var zW3cVcCredentialSubjectDraft14 = z6.record(z6.string(), zClaimValueSchemaDraft14);
|
|
340
|
+
var zW3cVcJsonLdCredentialDefinition = z6.object({
|
|
341
|
+
"@context": z6.array(z6.string()),
|
|
342
|
+
type: z6.array(z6.string())
|
|
115
343
|
}).passthrough();
|
|
116
344
|
var zW3cVcJsonLdCredentialDefinitionDraft14 = zW3cVcJsonLdCredentialDefinition.extend({
|
|
117
345
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
118
346
|
});
|
|
119
347
|
|
|
120
348
|
// src/formats/credential/w3c-vc/z-w3c-ldp-vc.ts
|
|
121
|
-
var zLdpVcFormatIdentifier =
|
|
122
|
-
var zLdpVcCredentialIssuerMetadata =
|
|
349
|
+
var zLdpVcFormatIdentifier = z7.literal("ldp_vc");
|
|
350
|
+
var zLdpVcCredentialIssuerMetadata = z7.object({
|
|
123
351
|
format: zLdpVcFormatIdentifier,
|
|
124
352
|
credential_definition: zW3cVcJsonLdCredentialDefinition,
|
|
125
353
|
claims: zIssuerMetadataClaimsDescription.optional()
|
|
126
354
|
});
|
|
127
|
-
var zLdpVcCredentialIssuerMetadataDraft14 =
|
|
355
|
+
var zLdpVcCredentialIssuerMetadataDraft14 = z7.object({
|
|
128
356
|
format: zLdpVcFormatIdentifier,
|
|
129
357
|
credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
|
|
130
|
-
order:
|
|
358
|
+
order: z7.array(z7.string()).optional()
|
|
131
359
|
});
|
|
132
|
-
var zLdpVcCredentialIssuerMetadataDraft11 =
|
|
133
|
-
order:
|
|
360
|
+
var zLdpVcCredentialIssuerMetadataDraft11 = z7.object({
|
|
361
|
+
order: z7.array(z7.string()).optional(),
|
|
134
362
|
format: zLdpVcFormatIdentifier,
|
|
135
363
|
// Credential definition was spread on top level instead of a separatey property in v11
|
|
136
364
|
// As well as using types instead of type
|
|
137
|
-
"@context":
|
|
138
|
-
types:
|
|
365
|
+
"@context": z7.array(z7.string()),
|
|
366
|
+
types: z7.array(z7.string()),
|
|
139
367
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
140
368
|
}).passthrough();
|
|
141
369
|
var zLdpVcCredentialIssuerMetadataDraft11To14 = zLdpVcCredentialIssuerMetadataDraft11.transform(
|
|
@@ -154,16 +382,16 @@ var zLdpVcCredentialIssuerMetadataDraft14To11 = zLdpVcCredentialIssuerMetadataDr
|
|
|
154
382
|
...credentialDefinition,
|
|
155
383
|
types: type
|
|
156
384
|
})).pipe(zLdpVcCredentialIssuerMetadataDraft11);
|
|
157
|
-
var zLdpVcCredentialRequestFormatDraft14 =
|
|
385
|
+
var zLdpVcCredentialRequestFormatDraft14 = z7.object({
|
|
158
386
|
format: zLdpVcFormatIdentifier,
|
|
159
387
|
credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14
|
|
160
388
|
});
|
|
161
|
-
var zLdpVcCredentialRequestDraft11 =
|
|
389
|
+
var zLdpVcCredentialRequestDraft11 = z7.object({
|
|
162
390
|
format: zLdpVcFormatIdentifier,
|
|
163
|
-
credential_definition:
|
|
164
|
-
"@context":
|
|
391
|
+
credential_definition: z7.object({
|
|
392
|
+
"@context": z7.array(z7.string()),
|
|
165
393
|
// credential_definition was using types instead of type in v11
|
|
166
|
-
types:
|
|
394
|
+
types: z7.array(z7.string()),
|
|
167
395
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
168
396
|
})
|
|
169
397
|
}).passthrough();
|
|
@@ -185,25 +413,25 @@ var zLdpVcCredentialRequestDraft14To11 = zLdpVcCredentialRequestFormatDraft14.pa
|
|
|
185
413
|
})).pipe(zLdpVcCredentialRequestDraft11);
|
|
186
414
|
|
|
187
415
|
// src/formats/credential/w3c-vc/z-w3c-jwt-vc-json-ld.ts
|
|
188
|
-
import
|
|
189
|
-
var zJwtVcJsonLdFormatIdentifier =
|
|
190
|
-
var zJwtVcJsonLdCredentialIssuerMetadata =
|
|
416
|
+
import z8 from "zod";
|
|
417
|
+
var zJwtVcJsonLdFormatIdentifier = z8.literal("jwt_vc_json-ld");
|
|
418
|
+
var zJwtVcJsonLdCredentialIssuerMetadata = z8.object({
|
|
191
419
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
192
420
|
credential_definition: zW3cVcJsonLdCredentialDefinition,
|
|
193
421
|
claims: zIssuerMetadataClaimsDescription.optional()
|
|
194
422
|
});
|
|
195
|
-
var zJwtVcJsonLdCredentialIssuerMetadataDraft14 =
|
|
423
|
+
var zJwtVcJsonLdCredentialIssuerMetadataDraft14 = z8.object({
|
|
196
424
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
197
425
|
credential_definition: zW3cVcJsonLdCredentialDefinitionDraft14,
|
|
198
|
-
order:
|
|
426
|
+
order: z8.optional(z8.array(z8.string()))
|
|
199
427
|
});
|
|
200
|
-
var zJwtVcJsonLdCredentialIssuerMetadataDraft11 =
|
|
201
|
-
order:
|
|
428
|
+
var zJwtVcJsonLdCredentialIssuerMetadataDraft11 = z8.object({
|
|
429
|
+
order: z8.array(z8.string()).optional(),
|
|
202
430
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
203
431
|
// Credential definition was spread on top level instead of a separatey property in v11
|
|
204
432
|
// As well as using types instead of type
|
|
205
|
-
"@context":
|
|
206
|
-
types:
|
|
433
|
+
"@context": z8.array(z8.string()),
|
|
434
|
+
types: z8.array(z8.string()),
|
|
207
435
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
208
436
|
}).passthrough();
|
|
209
437
|
var zJwtVcJsonLdCredentialIssuerMetadataDraft11To14 = zJwtVcJsonLdCredentialIssuerMetadataDraft11.transform(
|
|
@@ -222,17 +450,17 @@ var zJwtVcJsonLdCredentialIssuerMetadataDraft14To11 = zJwtVcJsonLdCredentialIssu
|
|
|
222
450
|
...credentialDefinition,
|
|
223
451
|
types: type
|
|
224
452
|
})).pipe(zJwtVcJsonLdCredentialIssuerMetadataDraft11);
|
|
225
|
-
var zJwtVcJsonLdCredentialRequestFormatDraft14 =
|
|
453
|
+
var zJwtVcJsonLdCredentialRequestFormatDraft14 = z8.object({
|
|
226
454
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
227
455
|
credential_definition: zW3cVcJsonLdCredentialDefinition
|
|
228
456
|
});
|
|
229
|
-
var zJwtVcJsonLdCredentialRequestDraft11 =
|
|
457
|
+
var zJwtVcJsonLdCredentialRequestDraft11 = z8.object({
|
|
230
458
|
format: zJwtVcJsonLdFormatIdentifier,
|
|
231
|
-
credential_definition:
|
|
232
|
-
"@context":
|
|
459
|
+
credential_definition: z8.object({
|
|
460
|
+
"@context": z8.array(z8.string()),
|
|
233
461
|
// credential_definition was using types instead of type in v11
|
|
234
|
-
types:
|
|
235
|
-
credentialSubject:
|
|
462
|
+
types: z8.array(z8.string()),
|
|
463
|
+
credentialSubject: z8.optional(zW3cVcCredentialSubjectDraft14)
|
|
236
464
|
}).passthrough()
|
|
237
465
|
}).passthrough();
|
|
238
466
|
var zJwtVcJsonLdCredentialRequestDraft11To14 = zJwtVcJsonLdCredentialRequestDraft11.transform(
|
|
@@ -253,30 +481,30 @@ var zJwtVcJsonLdCredentialRequestDraft14To11 = zJwtVcJsonLdCredentialRequestForm
|
|
|
253
481
|
})).pipe(zJwtVcJsonLdCredentialRequestDraft11);
|
|
254
482
|
|
|
255
483
|
// src/formats/credential/w3c-vc/z-w3c-jwt-vc-json.ts
|
|
256
|
-
import
|
|
257
|
-
var zJwtVcJsonFormatIdentifier =
|
|
258
|
-
var zJwtVcJsonCredentialDefinition =
|
|
259
|
-
type:
|
|
484
|
+
import z9 from "zod";
|
|
485
|
+
var zJwtVcJsonFormatIdentifier = z9.literal("jwt_vc_json");
|
|
486
|
+
var zJwtVcJsonCredentialDefinition = z9.object({
|
|
487
|
+
type: z9.array(z9.string())
|
|
260
488
|
}).passthrough();
|
|
261
489
|
var zJwtVcJsonCredentialDefinitionDraft14 = zJwtVcJsonCredentialDefinition.extend({
|
|
262
490
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
263
491
|
});
|
|
264
|
-
var zJwtVcJsonCredentialIssuerMetadata =
|
|
492
|
+
var zJwtVcJsonCredentialIssuerMetadata = z9.object({
|
|
265
493
|
format: zJwtVcJsonFormatIdentifier,
|
|
266
494
|
credential_definition: zJwtVcJsonCredentialDefinition,
|
|
267
495
|
claims: zIssuerMetadataClaimsDescription.optional()
|
|
268
496
|
});
|
|
269
|
-
var zJwtVcJsonCredentialIssuerMetadataDraft14 =
|
|
497
|
+
var zJwtVcJsonCredentialIssuerMetadataDraft14 = z9.object({
|
|
270
498
|
format: zJwtVcJsonFormatIdentifier,
|
|
271
499
|
credential_definition: zJwtVcJsonCredentialDefinitionDraft14,
|
|
272
|
-
order:
|
|
500
|
+
order: z9.array(z9.string()).optional()
|
|
273
501
|
});
|
|
274
|
-
var zJwtVcJsonCredentialIssuerMetadataDraft11 =
|
|
502
|
+
var zJwtVcJsonCredentialIssuerMetadataDraft11 = z9.object({
|
|
275
503
|
format: zJwtVcJsonFormatIdentifier,
|
|
276
|
-
order:
|
|
504
|
+
order: z9.array(z9.string()).optional(),
|
|
277
505
|
// Credential definition was spread on top level instead of a separatey property in v11
|
|
278
506
|
// As well as using types instead of type
|
|
279
|
-
types:
|
|
507
|
+
types: z9.array(z9.string()),
|
|
280
508
|
credentialSubject: zW3cVcCredentialSubjectDraft14.optional()
|
|
281
509
|
}).passthrough();
|
|
282
510
|
var zJwtVcJsonCredentialIssuerMetadataDraft11To14 = zJwtVcJsonCredentialIssuerMetadataDraft11.transform(
|
|
@@ -294,16 +522,16 @@ var zJwtVcJsonCredentialIssuerMetadataDraft14To11 = zJwtVcJsonCredentialIssuerMe
|
|
|
294
522
|
types: type,
|
|
295
523
|
...credentialDefinition
|
|
296
524
|
})).pipe(zJwtVcJsonCredentialIssuerMetadataDraft11);
|
|
297
|
-
var zJwtVcJsonCredentialRequestFormatDraft14 =
|
|
525
|
+
var zJwtVcJsonCredentialRequestFormatDraft14 = z9.object({
|
|
298
526
|
format: zJwtVcJsonFormatIdentifier,
|
|
299
527
|
credential_definition: zJwtVcJsonCredentialDefinition
|
|
300
528
|
});
|
|
301
|
-
var zJwtVcJsonCredentialRequestDraft11 =
|
|
529
|
+
var zJwtVcJsonCredentialRequestDraft11 = z9.object({
|
|
302
530
|
format: zJwtVcJsonFormatIdentifier,
|
|
303
531
|
// Credential definition was spread on top level instead of a separatey property in v11
|
|
304
532
|
// As well as using types instead of type
|
|
305
|
-
types:
|
|
306
|
-
credentialSubject:
|
|
533
|
+
types: z9.array(z9.string()),
|
|
534
|
+
credentialSubject: z9.optional(zW3cVcCredentialSubjectDraft14)
|
|
307
535
|
}).passthrough();
|
|
308
536
|
var zJwtVcJsonCredentialRequestDraft11To14 = zJwtVcJsonCredentialRequestDraft11.transform(
|
|
309
537
|
({ types, credentialSubject, ...rest }) => {
|
|
@@ -323,81 +551,76 @@ var zJwtVcJsonCredentialRequestDraft14To11 = zJwtVcJsonCredentialRequestFormatDr
|
|
|
323
551
|
...credentialDefinition
|
|
324
552
|
})).pipe(zJwtVcJsonCredentialRequestDraft11);
|
|
325
553
|
|
|
326
|
-
// src/version.ts
|
|
327
|
-
var Openid4vciDraftVersion = /* @__PURE__ */ ((Openid4vciDraftVersion2) => {
|
|
328
|
-
Openid4vciDraftVersion2["Draft15"] = "Draft15";
|
|
329
|
-
Openid4vciDraftVersion2["Draft14"] = "Draft14";
|
|
330
|
-
Openid4vciDraftVersion2["Draft11"] = "Draft11";
|
|
331
|
-
return Openid4vciDraftVersion2;
|
|
332
|
-
})(Openid4vciDraftVersion || {});
|
|
333
|
-
|
|
334
554
|
// src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
|
|
335
|
-
import
|
|
555
|
+
import z11 from "zod";
|
|
336
556
|
|
|
337
557
|
// src/key-attestation/z-key-attestation.ts
|
|
338
558
|
import { zJwk, zJwtHeader, zJwtPayload } from "@openid4vc/oauth2";
|
|
339
559
|
import { zInteger } from "@openid4vc/utils";
|
|
340
|
-
import
|
|
341
|
-
var zKeyAttestationJwtHeader =
|
|
560
|
+
import z10 from "zod";
|
|
561
|
+
var zKeyAttestationJwtHeader = z10.object({
|
|
342
562
|
...zJwtHeader.shape,
|
|
343
|
-
typ:
|
|
563
|
+
typ: z10.literal("keyattestation+jwt").or(
|
|
564
|
+
// Draft 16
|
|
565
|
+
z10.literal("key-attestation+jwt")
|
|
566
|
+
)
|
|
344
567
|
}).passthrough().refine(({ kid, jwk }) => jwk === void 0 || kid === void 0, {
|
|
345
568
|
message: `Both 'jwk' and 'kid' are defined. Only one is allowed`
|
|
346
569
|
}).refine(({ trust_chain, kid }) => !trust_chain || !kid, {
|
|
347
570
|
message: `When 'trust_chain' is provided, 'kid' is required`
|
|
348
571
|
});
|
|
349
|
-
var zIso18045 =
|
|
350
|
-
var zIso18045OrStringArray =
|
|
351
|
-
var zKeyAttestationJwtPayload =
|
|
572
|
+
var zIso18045 = z10.enum(["iso_18045_high", "iso_18045_moderate", "iso_18045_enhanced-basic", "iso_18045_basic"]);
|
|
573
|
+
var zIso18045OrStringArray = z10.array(z10.union([zIso18045, z10.string()]));
|
|
574
|
+
var zKeyAttestationJwtPayload = z10.object({
|
|
352
575
|
...zJwtPayload.shape,
|
|
353
576
|
iat: zInteger,
|
|
354
|
-
attested_keys:
|
|
355
|
-
key_storage:
|
|
356
|
-
user_authentication:
|
|
357
|
-
certification:
|
|
577
|
+
attested_keys: z10.array(zJwk),
|
|
578
|
+
key_storage: z10.optional(zIso18045OrStringArray),
|
|
579
|
+
user_authentication: z10.optional(zIso18045OrStringArray),
|
|
580
|
+
certification: z10.optional(z10.string().url())
|
|
358
581
|
}).passthrough();
|
|
359
|
-
var zKeyAttestationJwtPayloadForUse = (use) =>
|
|
582
|
+
var zKeyAttestationJwtPayloadForUse = (use) => z10.object({
|
|
360
583
|
...zKeyAttestationJwtPayload.shape,
|
|
361
584
|
// REQUIRED when used as proof_type.attesation directly
|
|
362
|
-
nonce: use === "proof_type.attestation" ?
|
|
585
|
+
nonce: use === "proof_type.attestation" ? z10.string({
|
|
363
586
|
message: `Nonce must be defined when key attestation is used as 'proof_type.attestation' directly`
|
|
364
|
-
}) :
|
|
587
|
+
}) : z10.optional(z10.string()),
|
|
365
588
|
// REQUIRED when used within header of proof_type.jwt
|
|
366
|
-
exp: use === "proof_type.jwt" ? zInteger :
|
|
589
|
+
exp: use === "proof_type.jwt" ? zInteger : z10.optional(zInteger)
|
|
367
590
|
}).passthrough();
|
|
368
591
|
|
|
369
592
|
// src/metadata/credential-issuer/z-credential-configuration-supported-common.ts
|
|
370
|
-
var zCredentialConfigurationSupportedCommon =
|
|
371
|
-
format:
|
|
372
|
-
scope:
|
|
373
|
-
cryptographic_binding_methods_supported:
|
|
374
|
-
credential_signing_alg_values_supported:
|
|
375
|
-
proof_types_supported:
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
proof_signing_alg_values_supported:
|
|
379
|
-
key_attestations_required:
|
|
593
|
+
var zCredentialConfigurationSupportedCommon = z11.object({
|
|
594
|
+
format: z11.string(),
|
|
595
|
+
scope: z11.string().optional(),
|
|
596
|
+
cryptographic_binding_methods_supported: z11.array(z11.string()).optional(),
|
|
597
|
+
credential_signing_alg_values_supported: z11.array(z11.string()).optional(),
|
|
598
|
+
proof_types_supported: z11.record(
|
|
599
|
+
z11.union([z11.literal("jwt"), z11.literal("attestation"), z11.string()]),
|
|
600
|
+
z11.object({
|
|
601
|
+
proof_signing_alg_values_supported: z11.array(z11.string()),
|
|
602
|
+
key_attestations_required: z11.object({
|
|
380
603
|
key_storage: zIso18045OrStringArray.optional(),
|
|
381
604
|
user_authentication: zIso18045OrStringArray.optional()
|
|
382
605
|
}).passthrough().optional()
|
|
383
606
|
})
|
|
384
607
|
).optional(),
|
|
385
|
-
display:
|
|
386
|
-
|
|
387
|
-
name:
|
|
388
|
-
locale:
|
|
389
|
-
logo:
|
|
608
|
+
display: z11.array(
|
|
609
|
+
z11.object({
|
|
610
|
+
name: z11.string(),
|
|
611
|
+
locale: z11.string().optional(),
|
|
612
|
+
logo: z11.object({
|
|
390
613
|
// FIXME: make required again, but need to support draft 11 first
|
|
391
|
-
uri:
|
|
392
|
-
alt_text:
|
|
614
|
+
uri: z11.string().optional(),
|
|
615
|
+
alt_text: z11.string().optional()
|
|
393
616
|
}).passthrough().optional(),
|
|
394
|
-
description:
|
|
395
|
-
background_color:
|
|
396
|
-
background_image:
|
|
617
|
+
description: z11.string().optional(),
|
|
618
|
+
background_color: z11.string().optional(),
|
|
619
|
+
background_image: z11.object({
|
|
397
620
|
// TODO: should be required, but paradym's metadata is wrong here.
|
|
398
|
-
uri:
|
|
621
|
+
uri: z11.string().optional()
|
|
399
622
|
}).passthrough().optional(),
|
|
400
|
-
text_color:
|
|
623
|
+
text_color: z11.string().optional()
|
|
401
624
|
}).passthrough()
|
|
402
625
|
).optional()
|
|
403
626
|
}).passthrough();
|
|
@@ -432,8 +655,8 @@ var zCredentialConfigurationSupportedWithFormats = zCredentialConfigurationSuppo
|
|
|
432
655
|
},
|
|
433
656
|
{}
|
|
434
657
|
)[data.format];
|
|
435
|
-
const result =
|
|
436
|
-
validators.length > 1 ?
|
|
658
|
+
const result = z12.object({}).passthrough().and(
|
|
659
|
+
validators.length > 1 ? z12.union(validators) : validators[0]
|
|
437
660
|
).safeParse(data);
|
|
438
661
|
if (result.success) {
|
|
439
662
|
return result.data;
|
|
@@ -441,49 +664,49 @@ var zCredentialConfigurationSupportedWithFormats = zCredentialConfigurationSuppo
|
|
|
441
664
|
for (const issue of result.error.issues) {
|
|
442
665
|
ctx.addIssue(issue);
|
|
443
666
|
}
|
|
444
|
-
return
|
|
667
|
+
return z12.NEVER;
|
|
445
668
|
}
|
|
446
669
|
);
|
|
447
|
-
var zCredentialIssuerMetadataDisplayEntry =
|
|
448
|
-
name:
|
|
449
|
-
locale:
|
|
450
|
-
logo:
|
|
670
|
+
var zCredentialIssuerMetadataDisplayEntry = z12.object({
|
|
671
|
+
name: z12.string().optional(),
|
|
672
|
+
locale: z12.string().optional(),
|
|
673
|
+
logo: z12.object({
|
|
451
674
|
// FIXME: make required again, but need to support draft 11 first
|
|
452
|
-
uri:
|
|
453
|
-
alt_text:
|
|
675
|
+
uri: z12.string().optional(),
|
|
676
|
+
alt_text: z12.string().optional()
|
|
454
677
|
}).passthrough().optional()
|
|
455
678
|
}).passthrough();
|
|
456
|
-
var zCredentialIssuerMetadataDraft14Draft15 =
|
|
457
|
-
credential_issuer:
|
|
458
|
-
authorization_servers:
|
|
459
|
-
credential_endpoint:
|
|
460
|
-
deferred_credential_endpoint:
|
|
461
|
-
notification_endpoint:
|
|
679
|
+
var zCredentialIssuerMetadataDraft14Draft15 = z12.object({
|
|
680
|
+
credential_issuer: zHttpsUrl2,
|
|
681
|
+
authorization_servers: z12.array(zHttpsUrl2).optional(),
|
|
682
|
+
credential_endpoint: zHttpsUrl2,
|
|
683
|
+
deferred_credential_endpoint: zHttpsUrl2.optional(),
|
|
684
|
+
notification_endpoint: zHttpsUrl2.optional(),
|
|
462
685
|
// Added after draft 14, but needed for proper
|
|
463
|
-
nonce_endpoint:
|
|
464
|
-
credential_response_encryption:
|
|
465
|
-
alg_values_supported:
|
|
466
|
-
enc_values_supported:
|
|
467
|
-
encryption_required:
|
|
686
|
+
nonce_endpoint: zHttpsUrl2.optional(),
|
|
687
|
+
credential_response_encryption: z12.object({
|
|
688
|
+
alg_values_supported: z12.array(z12.string()),
|
|
689
|
+
enc_values_supported: z12.array(z12.string()),
|
|
690
|
+
encryption_required: z12.boolean()
|
|
468
691
|
}).passthrough().optional(),
|
|
469
|
-
batch_credential_issuance:
|
|
470
|
-
batch_size:
|
|
692
|
+
batch_credential_issuance: z12.object({
|
|
693
|
+
batch_size: z12.number().positive()
|
|
471
694
|
}).passthrough().optional(),
|
|
472
695
|
signed_metadata: zCompactJwt.optional(),
|
|
473
|
-
display:
|
|
474
|
-
credential_configurations_supported:
|
|
696
|
+
display: z12.array(zCredentialIssuerMetadataDisplayEntry).optional(),
|
|
697
|
+
credential_configurations_supported: z12.record(z12.string(), zCredentialConfigurationSupportedWithFormats)
|
|
475
698
|
}).passthrough();
|
|
476
|
-
var zCredentialConfigurationSupportedDraft11To14 =
|
|
477
|
-
id:
|
|
478
|
-
format:
|
|
479
|
-
cryptographic_suites_supported:
|
|
480
|
-
display:
|
|
481
|
-
|
|
482
|
-
logo:
|
|
483
|
-
url:
|
|
699
|
+
var zCredentialConfigurationSupportedDraft11To14 = z12.object({
|
|
700
|
+
id: z12.string().optional(),
|
|
701
|
+
format: z12.string(),
|
|
702
|
+
cryptographic_suites_supported: z12.array(z12.string()).optional(),
|
|
703
|
+
display: z12.array(
|
|
704
|
+
z12.object({
|
|
705
|
+
logo: z12.object({
|
|
706
|
+
url: z12.string().url().optional()
|
|
484
707
|
}).passthrough().optional(),
|
|
485
|
-
background_image:
|
|
486
|
-
url:
|
|
708
|
+
background_image: z12.object({
|
|
709
|
+
url: z12.string().url().optional()
|
|
487
710
|
}).passthrough().optional()
|
|
488
711
|
}).passthrough()
|
|
489
712
|
).optional()
|
|
@@ -524,11 +747,11 @@ var zCredentialConfigurationSupportedDraft11To14 = z11.object({
|
|
|
524
747
|
for (const issue of result.error.issues) {
|
|
525
748
|
ctx.addIssue(issue);
|
|
526
749
|
}
|
|
527
|
-
return
|
|
750
|
+
return z12.NEVER;
|
|
528
751
|
}).pipe(zCredentialConfigurationSupportedWithFormats);
|
|
529
752
|
var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSupportedWithFormats.and(
|
|
530
|
-
|
|
531
|
-
id:
|
|
753
|
+
z12.object({
|
|
754
|
+
id: z12.string()
|
|
532
755
|
}).passthrough()
|
|
533
756
|
).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope, ...rest }) => ({
|
|
534
757
|
...rest,
|
|
@@ -548,15 +771,15 @@ var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSuppo
|
|
|
548
771
|
} : {},
|
|
549
772
|
id
|
|
550
773
|
})).pipe(
|
|
551
|
-
|
|
774
|
+
z12.union([
|
|
552
775
|
zLdpVcCredentialIssuerMetadataDraft14To11,
|
|
553
776
|
zJwtVcJsonCredentialIssuerMetadataDraft14To11,
|
|
554
777
|
zJwtVcJsonLdCredentialIssuerMetadataDraft14To11,
|
|
555
778
|
// To handle unrecognized formats and not error immediately we allow the common format as well
|
|
556
779
|
// but they can't use any of the foramt identifiers that have a specific transformation. This way if a format is
|
|
557
780
|
// has a transformation it NEEDS to use the format specific transformation, and otherwise we fall back to the common validation
|
|
558
|
-
|
|
559
|
-
format:
|
|
781
|
+
z12.object({
|
|
782
|
+
format: z12.string().refine(
|
|
560
783
|
(input) => ![
|
|
561
784
|
zLdpVcFormatIdentifier.value,
|
|
562
785
|
zJwtVcJsonFormatIdentifier.value,
|
|
@@ -566,11 +789,11 @@ var zCredentialConfigurationSupportedDraft14To11 = zCredentialConfigurationSuppo
|
|
|
566
789
|
}).passthrough()
|
|
567
790
|
])
|
|
568
791
|
);
|
|
569
|
-
var zCredentialIssuerMetadataDraft11To14 =
|
|
570
|
-
authorization_server:
|
|
571
|
-
credentials_supported:
|
|
572
|
-
|
|
573
|
-
id:
|
|
792
|
+
var zCredentialIssuerMetadataDraft11To14 = z12.object({
|
|
793
|
+
authorization_server: z12.string().optional(),
|
|
794
|
+
credentials_supported: z12.array(
|
|
795
|
+
z12.object({
|
|
796
|
+
id: z12.string().optional()
|
|
574
797
|
}).passthrough()
|
|
575
798
|
)
|
|
576
799
|
}).passthrough().transform(({ authorization_server, credentials_supported, ...rest }) => {
|
|
@@ -583,9 +806,9 @@ var zCredentialIssuerMetadataDraft11To14 = z11.object({
|
|
|
583
806
|
)
|
|
584
807
|
};
|
|
585
808
|
}).pipe(
|
|
586
|
-
|
|
809
|
+
z12.object({
|
|
587
810
|
// Update from v11 structrue to v14 structure
|
|
588
|
-
credential_configurations_supported:
|
|
811
|
+
credential_configurations_supported: z12.record(z12.string(), zCredentialConfigurationSupportedDraft11To14)
|
|
589
812
|
}).passthrough()
|
|
590
813
|
).pipe(zCredentialIssuerMetadataDraft14Draft15);
|
|
591
814
|
var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15.transform((issuerMetadata) => ({
|
|
@@ -597,16 +820,16 @@ var zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft
|
|
|
597
820
|
}))
|
|
598
821
|
})).pipe(
|
|
599
822
|
zCredentialIssuerMetadataDraft14Draft15.extend({
|
|
600
|
-
credentials_supported:
|
|
823
|
+
credentials_supported: z12.array(zCredentialConfigurationSupportedDraft14To11)
|
|
601
824
|
})
|
|
602
825
|
);
|
|
603
|
-
var zCredentialIssuerMetadata =
|
|
826
|
+
var zCredentialIssuerMetadata = z12.union([
|
|
604
827
|
// First prioritize draft 15/14 (and 13)
|
|
605
828
|
zCredentialIssuerMetadataDraft14Draft15,
|
|
606
829
|
// Then try parsing draft 11 and transform into draft 14
|
|
607
830
|
zCredentialIssuerMetadataDraft11To14
|
|
608
831
|
]);
|
|
609
|
-
var zCredentialIssuerMetadataWithDraftVersion =
|
|
832
|
+
var zCredentialIssuerMetadataWithDraftVersion = z12.union([
|
|
610
833
|
zCredentialIssuerMetadataDraft14Draft15.transform((credentialIssuerMetadata) => {
|
|
611
834
|
const isDraft15 = Object.values(credentialIssuerMetadata.credential_configurations_supported).some(
|
|
612
835
|
(configuration) => {
|
|
@@ -638,7 +861,7 @@ async function fetchCredentialIssuerMetadata(credentialIssuer, fetch) {
|
|
|
638
861
|
const wellKnownMetadataUrl = joinUriParts(credentialIssuer, [wellKnownCredentialIssuerSuffix]);
|
|
639
862
|
const result = await fetchWellKnownMetadata(wellKnownMetadataUrl, zCredentialIssuerMetadataWithDraftVersion, fetch);
|
|
640
863
|
if (result && result.credentialIssuerMetadata.credential_issuer !== credentialIssuer) {
|
|
641
|
-
throw new
|
|
864
|
+
throw new Oauth2Error2(
|
|
642
865
|
`The 'credential_issuer' parameter '${result.credentialIssuerMetadata.credential_issuer}' in the well known credential issuer metadata at '${wellKnownMetadataUrl}' does not match the provided credential issuer '${credentialIssuer}'.`
|
|
643
866
|
);
|
|
644
867
|
}
|
|
@@ -654,7 +877,7 @@ function extractKnownCredentialConfigurationSupportedFormats(credentialConfigura
|
|
|
654
877
|
function getCredentialConfigurationSupportedById(credentialConfigurations, credentialConfigurationId) {
|
|
655
878
|
const configuration = credentialConfigurations[credentialConfigurationId];
|
|
656
879
|
if (!configuration) {
|
|
657
|
-
throw new
|
|
880
|
+
throw new Oauth2Error2(
|
|
658
881
|
`Credential configuration with id '${credentialConfigurationId}' not found in credential configurations supported.`
|
|
659
882
|
);
|
|
660
883
|
}
|
|
@@ -716,24 +939,76 @@ var Openid4vciSendNotificationError = class extends Openid4vciError {
|
|
|
716
939
|
super(message);
|
|
717
940
|
this.response = response;
|
|
718
941
|
}
|
|
719
|
-
};
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
// src/key-attestation/key-attestation.ts
|
|
945
|
+
import { decodeJwt, jwtHeaderFromJwtSigner } from "@openid4vc/oauth2";
|
|
946
|
+
import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
|
|
947
|
+
import { dateToSeconds, parseWithErrorHandling as parseWithErrorHandling2 } from "@openid4vc/utils";
|
|
948
|
+
async function createKeyAttestationJwt(options) {
|
|
949
|
+
const header = parseWithErrorHandling2(zKeyAttestationJwtHeader, {
|
|
950
|
+
...jwtHeaderFromJwtSigner(options.signer),
|
|
951
|
+
typ: "keyattestation+jwt"
|
|
952
|
+
});
|
|
953
|
+
const payload = parseWithErrorHandling2(zKeyAttestationJwtPayloadForUse(options.use), {
|
|
954
|
+
iat: dateToSeconds(options.issuedAt),
|
|
955
|
+
exp: options.expiresAt ? dateToSeconds(options.expiresAt) : void 0,
|
|
956
|
+
nonce: options.nonce,
|
|
957
|
+
attested_keys: options.attestedKeys,
|
|
958
|
+
user_authentication: options.userAuthentication,
|
|
959
|
+
key_storage: options.keyStorage,
|
|
960
|
+
certification: options.certification,
|
|
961
|
+
...options.additionalPayload
|
|
962
|
+
});
|
|
963
|
+
const { jwt } = await options.callbacks.signJwt(options.signer, { header, payload });
|
|
964
|
+
return jwt;
|
|
965
|
+
}
|
|
966
|
+
function parseKeyAttestationJwt({ keyAttestationJwt, use }) {
|
|
967
|
+
return decodeJwt({
|
|
968
|
+
jwt: keyAttestationJwt,
|
|
969
|
+
headerSchema: zKeyAttestationJwtHeader,
|
|
970
|
+
payloadSchema: zKeyAttestationJwtPayloadForUse(use)
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
async function verifyKeyAttestationJwt(options) {
|
|
974
|
+
const { header, payload } = parseKeyAttestationJwt({ keyAttestationJwt: options.keyAttestationJwt, use: options.use });
|
|
975
|
+
const now = options.now?.getTime() ?? Date.now();
|
|
976
|
+
if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
|
|
977
|
+
throw new Openid4vciError("Nonce used for key attestation jwt expired");
|
|
978
|
+
}
|
|
979
|
+
const { signer } = await verifyJwt({
|
|
980
|
+
compact: options.keyAttestationJwt,
|
|
981
|
+
header,
|
|
982
|
+
payload,
|
|
983
|
+
signer: jwtSignerFromJwt({ header, payload }),
|
|
984
|
+
verifyJwtCallback: options.callbacks.verifyJwt,
|
|
985
|
+
errorMessage: "Error verifiying key attestation jwt",
|
|
986
|
+
expectedNonce: options.expectedNonce,
|
|
987
|
+
now: options.now
|
|
988
|
+
});
|
|
989
|
+
return {
|
|
990
|
+
header,
|
|
991
|
+
payload,
|
|
992
|
+
signer
|
|
993
|
+
};
|
|
994
|
+
}
|
|
720
995
|
|
|
721
996
|
// src/metadata/credential-issuer/credential-configurations.ts
|
|
722
|
-
import { Oauth2Error as
|
|
723
|
-
import { ValidationError } from "@openid4vc/utils";
|
|
997
|
+
import { Oauth2Error as Oauth2Error3 } from "@openid4vc/oauth2";
|
|
998
|
+
import { ValidationError as ValidationError2 } from "@openid4vc/utils";
|
|
724
999
|
function extractScopesForCredentialConfigurationIds(options) {
|
|
725
1000
|
const scopes = /* @__PURE__ */ new Set();
|
|
726
1001
|
for (const credentialConfigurationId of options.credentialConfigurationIds) {
|
|
727
1002
|
const credentialConfiguration = options.issuerMetadata.credentialIssuer.credential_configurations_supported[credentialConfigurationId];
|
|
728
1003
|
if (!credentialConfiguration) {
|
|
729
|
-
throw new
|
|
1004
|
+
throw new Oauth2Error3(
|
|
730
1005
|
`Credential configuration with id '${credentialConfigurationId}' not found in metadata from credential issuer '${options.issuerMetadata.credentialIssuer.credential_issuer}'`
|
|
731
1006
|
);
|
|
732
1007
|
}
|
|
733
1008
|
const scope = credentialConfiguration.scope;
|
|
734
1009
|
if (scope) scopes.add(scope);
|
|
735
1010
|
else if (!scope && options.throwOnConfigurationWithoutScope) {
|
|
736
|
-
throw new
|
|
1011
|
+
throw new Oauth2Error3(
|
|
737
1012
|
`Credential configuration with id '${credentialConfigurationId}' does not have a 'scope' configured, and 'throwOnConfigurationWithoutScope' was enabled.`
|
|
738
1013
|
);
|
|
739
1014
|
}
|
|
@@ -751,7 +1026,7 @@ function credentialsSupportedToCredentialConfigurationsSupported(credentialsSupp
|
|
|
751
1026
|
}
|
|
752
1027
|
const parseResult = zCredentialConfigurationSupportedDraft11To14.safeParse(credentialSupported);
|
|
753
1028
|
if (!parseResult.success) {
|
|
754
|
-
throw new
|
|
1029
|
+
throw new ValidationError2(
|
|
755
1030
|
`Error transforming credential supported with id '${credentialSupported.id}' to credential configuration supported format`,
|
|
756
1031
|
parseResult.error
|
|
757
1032
|
);
|
|
@@ -772,226 +1047,6 @@ import {
|
|
|
772
1047
|
preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier3
|
|
773
1048
|
} from "@openid4vc/oauth2";
|
|
774
1049
|
|
|
775
|
-
// src/credential-offer/credential-offer.ts
|
|
776
|
-
import {
|
|
777
|
-
InvalidFetchResponseError,
|
|
778
|
-
Oauth2Error as Oauth2Error3,
|
|
779
|
-
authorizationCodeGrantIdentifier,
|
|
780
|
-
getAuthorizationServerMetadataFromList,
|
|
781
|
-
preAuthorizedCodeGrantIdentifier as preAuthorizedCodeGrantIdentifier2
|
|
782
|
-
} from "@openid4vc/oauth2";
|
|
783
|
-
import {
|
|
784
|
-
ContentType,
|
|
785
|
-
URL,
|
|
786
|
-
URLSearchParams,
|
|
787
|
-
ValidationError as ValidationError2,
|
|
788
|
-
createZodFetcher,
|
|
789
|
-
encodeToBase64Url,
|
|
790
|
-
getQueryParams,
|
|
791
|
-
objectToQueryParams,
|
|
792
|
-
parseWithErrorHandling
|
|
793
|
-
} from "@openid4vc/utils";
|
|
794
|
-
|
|
795
|
-
// src/credential-offer/z-credential-offer.ts
|
|
796
|
-
import {
|
|
797
|
-
preAuthorizedCodeGrantIdentifier
|
|
798
|
-
} from "@openid4vc/oauth2";
|
|
799
|
-
import { zHttpsUrl as zHttpsUrl2 } from "@openid4vc/utils";
|
|
800
|
-
import z12 from "zod";
|
|
801
|
-
var zTxCode = z12.object({
|
|
802
|
-
input_mode: z12.union([z12.literal("numeric"), z12.literal("text")]).optional(),
|
|
803
|
-
length: z12.number().int().optional(),
|
|
804
|
-
description: z12.string().max(300).optional()
|
|
805
|
-
}).passthrough();
|
|
806
|
-
var zCredentialOfferGrants = z12.object({
|
|
807
|
-
authorization_code: z12.object({
|
|
808
|
-
issuer_state: z12.string().optional(),
|
|
809
|
-
authorization_server: zHttpsUrl2.optional()
|
|
810
|
-
}).passthrough().optional(),
|
|
811
|
-
[preAuthorizedCodeGrantIdentifier]: z12.object({
|
|
812
|
-
"pre-authorized_code": z12.string(),
|
|
813
|
-
tx_code: zTxCode.optional(),
|
|
814
|
-
authorization_server: zHttpsUrl2.optional()
|
|
815
|
-
}).passthrough().optional()
|
|
816
|
-
}).passthrough();
|
|
817
|
-
var zCredentialOfferObjectDraft14 = z12.object({
|
|
818
|
-
credential_issuer: zHttpsUrl2,
|
|
819
|
-
credential_configuration_ids: z12.array(z12.string()),
|
|
820
|
-
grants: z12.optional(zCredentialOfferGrants)
|
|
821
|
-
}).passthrough();
|
|
822
|
-
var zCredentialOfferObjectDraft11To14 = z12.object({
|
|
823
|
-
credential_issuer: zHttpsUrl2,
|
|
824
|
-
// We don't support the inline offer objects from draft 11
|
|
825
|
-
credentials: z12.array(
|
|
826
|
-
z12.string({ message: "Only string credential identifiers are supported for draft 11 credential offers" })
|
|
827
|
-
),
|
|
828
|
-
grants: z12.optional(
|
|
829
|
-
z12.object({
|
|
830
|
-
// Has extra param in draft 14, but doesn't matter for transform purposes
|
|
831
|
-
authorization_code: zCredentialOfferGrants.shape.authorization_code,
|
|
832
|
-
[preAuthorizedCodeGrantIdentifier]: z12.object({
|
|
833
|
-
"pre-authorized_code": z12.string(),
|
|
834
|
-
user_pin_required: z12.optional(z12.boolean())
|
|
835
|
-
}).passthrough().optional()
|
|
836
|
-
})
|
|
837
|
-
)
|
|
838
|
-
}).passthrough().transform(({ credentials, grants, ...rest }) => {
|
|
839
|
-
const v14 = {
|
|
840
|
-
...rest,
|
|
841
|
-
credential_configuration_ids: credentials
|
|
842
|
-
};
|
|
843
|
-
if (grants) {
|
|
844
|
-
v14.grants = { ...grants };
|
|
845
|
-
if (grants[preAuthorizedCodeGrantIdentifier]) {
|
|
846
|
-
const { user_pin_required, ...restGrants } = grants[preAuthorizedCodeGrantIdentifier];
|
|
847
|
-
v14.grants[preAuthorizedCodeGrantIdentifier] = {
|
|
848
|
-
...restGrants
|
|
849
|
-
};
|
|
850
|
-
if (user_pin_required) {
|
|
851
|
-
v14.grants[preAuthorizedCodeGrantIdentifier].tx_code = {
|
|
852
|
-
input_mode: "text"
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
return v14;
|
|
858
|
-
}).pipe(zCredentialOfferObjectDraft14);
|
|
859
|
-
var zCredentialOfferObject = z12.union([
|
|
860
|
-
// First prioritize draft 14 (and 13)
|
|
861
|
-
zCredentialOfferObjectDraft14,
|
|
862
|
-
// Then try parsing draft 11 and transform into draft 14
|
|
863
|
-
zCredentialOfferObjectDraft11To14
|
|
864
|
-
]);
|
|
865
|
-
|
|
866
|
-
// src/credential-offer/credential-offer.ts
|
|
867
|
-
async function resolveCredentialOffer(credentialOffer, options) {
|
|
868
|
-
const parsedQueryParams = getQueryParams(credentialOffer);
|
|
869
|
-
let credentialOfferParseResult;
|
|
870
|
-
if (parsedQueryParams.credential_offer_uri) {
|
|
871
|
-
const fetchWithZod = createZodFetcher(options?.fetch);
|
|
872
|
-
const { response, result } = await fetchWithZod(
|
|
873
|
-
zCredentialOfferObject,
|
|
874
|
-
ContentType.Json,
|
|
875
|
-
parsedQueryParams.credential_offer_uri
|
|
876
|
-
);
|
|
877
|
-
if (!response.ok || !result) {
|
|
878
|
-
throw new InvalidFetchResponseError(
|
|
879
|
-
`Fetching credential offer from '${parsedQueryParams.credential_offer_uri}' resulted in an unsuccesfull response with status '${response.status}'`,
|
|
880
|
-
await response.clone().text(),
|
|
881
|
-
response
|
|
882
|
-
);
|
|
883
|
-
}
|
|
884
|
-
credentialOfferParseResult = result;
|
|
885
|
-
} else if (parsedQueryParams.credential_offer) {
|
|
886
|
-
let credentialOfferJson;
|
|
887
|
-
try {
|
|
888
|
-
credentialOfferJson = JSON.parse(decodeURIComponent(parsedQueryParams.credential_offer));
|
|
889
|
-
} catch (error) {
|
|
890
|
-
throw new Oauth2Error3(`Error parsing JSON from 'credential_offer' param in credential offer '${credentialOffer}'`);
|
|
891
|
-
}
|
|
892
|
-
credentialOfferParseResult = zCredentialOfferObject.safeParse(credentialOfferJson);
|
|
893
|
-
} else {
|
|
894
|
-
throw new Oauth2Error3(`Credential offer did not contain either 'credential_offer' or 'credential_offer_uri' param.`);
|
|
895
|
-
}
|
|
896
|
-
if (credentialOfferParseResult.error) {
|
|
897
|
-
throw new ValidationError2(
|
|
898
|
-
`Error parsing credential offer in draft 11, 13 or 14 format extracted from credential offer '${credentialOffer}'`,
|
|
899
|
-
credentialOfferParseResult.error
|
|
900
|
-
);
|
|
901
|
-
}
|
|
902
|
-
return credentialOfferParseResult.data;
|
|
903
|
-
}
|
|
904
|
-
function determineAuthorizationServerForCredentialOffer(options) {
|
|
905
|
-
const authorizationServers = options.issuerMetadata.credentialIssuer.authorization_servers;
|
|
906
|
-
let authorizationServer;
|
|
907
|
-
if (options.grantAuthorizationServer) {
|
|
908
|
-
authorizationServer = options.grantAuthorizationServer;
|
|
909
|
-
if (!authorizationServers) {
|
|
910
|
-
throw new Oauth2Error3(
|
|
911
|
-
`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.`
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
if (!authorizationServers.includes(authorizationServer)) {
|
|
915
|
-
throw new Oauth2Error3(
|
|
916
|
-
`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(", ")}.`
|
|
917
|
-
);
|
|
918
|
-
}
|
|
919
|
-
} else if (!authorizationServers) {
|
|
920
|
-
authorizationServer = options.issuerMetadata.credentialIssuer.credential_issuer;
|
|
921
|
-
} else {
|
|
922
|
-
if (authorizationServers.length === 0) {
|
|
923
|
-
throw new Oauth2Error3(`Credential issuer metadata has 'authorization_servers' value with length of 0`);
|
|
924
|
-
}
|
|
925
|
-
if (authorizationServers.length > 1) {
|
|
926
|
-
throw new Oauth2Error3(
|
|
927
|
-
`Credential issuer metadata has 'authorization_server' with multiple entries, but the credential offer grant did not specify which authorization server to use.`
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
authorizationServer = authorizationServers[0];
|
|
931
|
-
}
|
|
932
|
-
return authorizationServer;
|
|
933
|
-
}
|
|
934
|
-
async function createCredentialOffer(options) {
|
|
935
|
-
const {
|
|
936
|
-
[preAuthorizedCodeGrantIdentifier2]: preAuthorizedCodeGrant,
|
|
937
|
-
[authorizationCodeGrantIdentifier]: authorizationCodeGrant,
|
|
938
|
-
...restGrants
|
|
939
|
-
} = options.grants;
|
|
940
|
-
const grants = { ...restGrants };
|
|
941
|
-
if (authorizationCodeGrant) {
|
|
942
|
-
determineAuthorizationServerForCredentialOffer({
|
|
943
|
-
issuerMetadata: options.issuerMetadata,
|
|
944
|
-
grantAuthorizationServer: authorizationCodeGrant.authorization_server
|
|
945
|
-
});
|
|
946
|
-
grants[authorizationCodeGrantIdentifier] = authorizationCodeGrant;
|
|
947
|
-
}
|
|
948
|
-
if (preAuthorizedCodeGrant) {
|
|
949
|
-
determineAuthorizationServerForCredentialOffer({
|
|
950
|
-
issuerMetadata: options.issuerMetadata,
|
|
951
|
-
grantAuthorizationServer: preAuthorizedCodeGrant.authorization_server
|
|
952
|
-
});
|
|
953
|
-
grants[preAuthorizedCodeGrantIdentifier2] = {
|
|
954
|
-
...preAuthorizedCodeGrant,
|
|
955
|
-
"pre-authorized_code": preAuthorizedCodeGrant["pre-authorized_code"] ?? encodeToBase64Url(await options.callbacks.generateRandom(32))
|
|
956
|
-
};
|
|
957
|
-
const txCode = grants[preAuthorizedCodeGrantIdentifier2].tx_code;
|
|
958
|
-
if (txCode && options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
|
|
959
|
-
grants[preAuthorizedCodeGrantIdentifier2].user_pin_required = txCode !== void 0;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
const idsNotInMetadata = options.credentialConfigurationIds.filter(
|
|
963
|
-
(id) => options.issuerMetadata.credentialIssuer.credential_configurations_supported[id] === void 0
|
|
964
|
-
);
|
|
965
|
-
if (idsNotInMetadata.length > 0) {
|
|
966
|
-
throw new Oauth2Error3(
|
|
967
|
-
`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(", ")}.`
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
const credentialOfferScheme = options.credentialOfferScheme ?? "openid-credential-offer://";
|
|
971
|
-
const credentialOfferObject = parseWithErrorHandling(zCredentialOfferObject, {
|
|
972
|
-
credential_issuer: options.issuerMetadata.credentialIssuer.credential_issuer,
|
|
973
|
-
credential_configuration_ids: options.credentialConfigurationIds,
|
|
974
|
-
grants,
|
|
975
|
-
...options.additionalPayload
|
|
976
|
-
});
|
|
977
|
-
if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
|
|
978
|
-
credentialOfferObject.credentials = credentialOfferObject.credential_configuration_ids;
|
|
979
|
-
}
|
|
980
|
-
const url = new URL(credentialOfferScheme);
|
|
981
|
-
url.search = `?${new URLSearchParams([
|
|
982
|
-
...url.searchParams.entries(),
|
|
983
|
-
...objectToQueryParams({
|
|
984
|
-
credential_offer_uri: options.credentialOfferUri,
|
|
985
|
-
// Only add credential_offer is uri is undefined
|
|
986
|
-
credential_offer: options.credentialOfferUri ? void 0 : credentialOfferObject
|
|
987
|
-
}).entries()
|
|
988
|
-
]).toString()}`;
|
|
989
|
-
return {
|
|
990
|
-
credentialOffer: url.toString(),
|
|
991
|
-
credentialOfferObject
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
|
|
995
1050
|
// src/credential-request/format-payload.ts
|
|
996
1051
|
import { zIs } from "@openid4vc/utils";
|
|
997
1052
|
function getCredentialRequestFormatPayloadForCredentialConfigurationId(options) {
|
|
@@ -1052,7 +1107,7 @@ import {
|
|
|
1052
1107
|
Oauth2Error as Oauth2Error4,
|
|
1053
1108
|
resourceRequest
|
|
1054
1109
|
} from "@openid4vc/oauth2";
|
|
1055
|
-
import { ContentType as ContentType2, isResponseContentType, parseWithErrorHandling as
|
|
1110
|
+
import { ContentType as ContentType2, isResponseContentType, parseWithErrorHandling as parseWithErrorHandling3 } from "@openid4vc/utils";
|
|
1056
1111
|
|
|
1057
1112
|
// src/credential-request/z-credential-request.ts
|
|
1058
1113
|
import z16 from "zod";
|
|
@@ -1334,7 +1389,7 @@ async function retrieveCredentialsWithFormat(options) {
|
|
|
1334
1389
|
}
|
|
1335
1390
|
async function retrieveCredentials(options) {
|
|
1336
1391
|
const credentialEndpoint = options.issuerMetadata.credentialIssuer.credential_endpoint;
|
|
1337
|
-
let credentialRequest =
|
|
1392
|
+
let credentialRequest = parseWithErrorHandling3(
|
|
1338
1393
|
zCredentialRequest,
|
|
1339
1394
|
options.credentialRequest,
|
|
1340
1395
|
"Error validating credential request"
|
|
@@ -1354,7 +1409,7 @@ async function retrieveCredentials(options) {
|
|
|
1354
1409
|
}
|
|
1355
1410
|
}
|
|
1356
1411
|
if (options.issuerMetadata.originalDraftVersion === "Draft11" /* Draft11 */) {
|
|
1357
|
-
credentialRequest =
|
|
1412
|
+
credentialRequest = parseWithErrorHandling3(
|
|
1358
1413
|
zCredentialRequestDraft14To11,
|
|
1359
1414
|
credentialRequest,
|
|
1360
1415
|
`Error transforming credential request from ${"Draft14" /* Draft14 */} to ${"Draft11" /* Draft11 */}`
|
|
@@ -1398,57 +1453,6 @@ async function retrieveCredentials(options) {
|
|
|
1398
1453
|
import { decodeJwt as decodeJwt2, isJwkInSet, jwtHeaderFromJwtSigner as jwtHeaderFromJwtSigner2 } from "@openid4vc/oauth2";
|
|
1399
1454
|
import { jwtSignerFromJwt as jwtSignerFromJwt2, verifyJwt as verifyJwt2 } from "@openid4vc/oauth2";
|
|
1400
1455
|
import { dateToSeconds as dateToSeconds2, parseWithErrorHandling as parseWithErrorHandling4 } from "@openid4vc/utils";
|
|
1401
|
-
|
|
1402
|
-
// src/key-attestation/key-attestation.ts
|
|
1403
|
-
import { decodeJwt, jwtHeaderFromJwtSigner } from "@openid4vc/oauth2";
|
|
1404
|
-
import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
|
|
1405
|
-
import { dateToSeconds, parseWithErrorHandling as parseWithErrorHandling3 } from "@openid4vc/utils";
|
|
1406
|
-
async function createKeyAttestationJwt(options) {
|
|
1407
|
-
const header = parseWithErrorHandling3(zKeyAttestationJwtHeader, {
|
|
1408
|
-
...jwtHeaderFromJwtSigner(options.signer),
|
|
1409
|
-
typ: "keyattestation+jwt"
|
|
1410
|
-
});
|
|
1411
|
-
const payload = parseWithErrorHandling3(zKeyAttestationJwtPayloadForUse(options.use), {
|
|
1412
|
-
iat: dateToSeconds(options.issuedAt),
|
|
1413
|
-
exp: options.expiresAt ? dateToSeconds(options.expiresAt) : void 0,
|
|
1414
|
-
nonce: options.nonce,
|
|
1415
|
-
attested_keys: options.attestedKeys,
|
|
1416
|
-
user_authentication: options.userAuthentication,
|
|
1417
|
-
key_storage: options.keyStorage,
|
|
1418
|
-
certification: options.certification,
|
|
1419
|
-
...options.additionalPayload
|
|
1420
|
-
});
|
|
1421
|
-
const { jwt } = await options.callbacks.signJwt(options.signer, { header, payload });
|
|
1422
|
-
return jwt;
|
|
1423
|
-
}
|
|
1424
|
-
async function verifyKeyAttestationJwt(options) {
|
|
1425
|
-
const { header, payload } = decodeJwt({
|
|
1426
|
-
jwt: options.keyAttestationJwt,
|
|
1427
|
-
headerSchema: zKeyAttestationJwtHeader,
|
|
1428
|
-
payloadSchema: zKeyAttestationJwtPayloadForUse(options.use)
|
|
1429
|
-
});
|
|
1430
|
-
const now = options.now?.getTime() ?? Date.now();
|
|
1431
|
-
if (options.nonceExpiresAt && now > options.nonceExpiresAt.getTime()) {
|
|
1432
|
-
throw new Openid4vciError("Nonce used for key attestation jwt expired");
|
|
1433
|
-
}
|
|
1434
|
-
const { signer } = await verifyJwt({
|
|
1435
|
-
compact: options.keyAttestationJwt,
|
|
1436
|
-
header,
|
|
1437
|
-
payload,
|
|
1438
|
-
signer: jwtSignerFromJwt({ header, payload }),
|
|
1439
|
-
verifyJwtCallback: options.callbacks.verifyJwt,
|
|
1440
|
-
errorMessage: "Error verifiying key attestation jwt",
|
|
1441
|
-
expectedNonce: options.expectedNonce,
|
|
1442
|
-
now: options.now
|
|
1443
|
-
});
|
|
1444
|
-
return {
|
|
1445
|
-
header,
|
|
1446
|
-
payload,
|
|
1447
|
-
signer
|
|
1448
|
-
};
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
// src/formats/proof-type/jwt/jwt-proof-type.ts
|
|
1452
1456
|
async function createCredentialRequestJwtProof(options) {
|
|
1453
1457
|
const header = parseWithErrorHandling4(zCredentialRequestJwtProofTypeHeader, {
|
|
1454
1458
|
...jwtHeaderFromJwtSigner2(options.signer),
|
|
@@ -2325,10 +2329,14 @@ export {
|
|
|
2325
2329
|
Openid4vciRetrieveCredentialsError,
|
|
2326
2330
|
Openid4vciSendNotificationError,
|
|
2327
2331
|
Openid4vciWalletProvider,
|
|
2332
|
+
createKeyAttestationJwt,
|
|
2328
2333
|
credentialsSupportedToCredentialConfigurationsSupported,
|
|
2334
|
+
determineAuthorizationServerForCredentialOffer,
|
|
2329
2335
|
extractScopesForCredentialConfigurationIds,
|
|
2330
2336
|
getCredentialConfigurationsMatchingRequestFormat,
|
|
2331
2337
|
getGlobalConfig,
|
|
2332
|
-
|
|
2338
|
+
parseKeyAttestationJwt,
|
|
2339
|
+
setGlobalConfig,
|
|
2340
|
+
verifyKeyAttestationJwt
|
|
2333
2341
|
};
|
|
2334
2342
|
//# sourceMappingURL=index.mjs.map
|