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