@happyvertical/auth 0.80.0 → 0.80.2

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.
Files changed (35) hide show
  1. package/dist/chunks/cognito-thQmKf7L.js +124 -0
  2. package/dist/chunks/cognito-thQmKf7L.js.map +1 -0
  3. package/dist/chunks/decode_jwt-BvtACpi_.js +1183 -0
  4. package/dist/chunks/decode_jwt-BvtACpi_.js.map +1 -0
  5. package/dist/chunks/errors-RgVH84_1.js +343 -0
  6. package/dist/chunks/errors-RgVH84_1.js.map +1 -0
  7. package/dist/chunks/github-uNnnVjFZ.js +311 -0
  8. package/dist/chunks/github-uNnnVjFZ.js.map +1 -0
  9. package/dist/chunks/google-C_p8rExJ.js +374 -0
  10. package/dist/chunks/google-C_p8rExJ.js.map +1 -0
  11. package/dist/chunks/kanidm-DTcc6ufi.js +567 -0
  12. package/dist/chunks/kanidm-DTcc6ufi.js.map +1 -0
  13. package/dist/chunks/keycloak-CzPHgI2z.js +632 -0
  14. package/dist/chunks/keycloak-CzPHgI2z.js.map +1 -0
  15. package/dist/chunks/nostr-zrMaYMU-.js +141 -0
  16. package/dist/chunks/nostr-zrMaYMU-.js.map +1 -0
  17. package/dist/cli/claude-context.js +17 -17
  18. package/dist/cli/claude-context.js.map +1 -1
  19. package/dist/index.js +204 -486
  20. package/dist/index.js.map +1 -1
  21. package/package.json +5 -5
  22. package/dist/chunks/cognito-dmypylFX.js +0 -128
  23. package/dist/chunks/cognito-dmypylFX.js.map +0 -1
  24. package/dist/chunks/decode_jwt-D2OK1b8a.js +0 -1395
  25. package/dist/chunks/decode_jwt-D2OK1b8a.js.map +0 -1
  26. package/dist/chunks/github-NSZp5tVm.js +0 -413
  27. package/dist/chunks/github-NSZp5tVm.js.map +0 -1
  28. package/dist/chunks/google-HXk2ctYR.js +0 -483
  29. package/dist/chunks/google-HXk2ctYR.js.map +0 -1
  30. package/dist/chunks/index-BpsMhFXS.js +0 -151
  31. package/dist/chunks/index-BpsMhFXS.js.map +0 -1
  32. package/dist/chunks/kanidm-hkw-YPVF.js +0 -747
  33. package/dist/chunks/kanidm-hkw-YPVF.js.map +0 -1
  34. package/dist/chunks/keycloak-t6JEUeOz.js +0 -871
  35. package/dist/chunks/keycloak-t6JEUeOz.js.map +0 -1
@@ -0,0 +1,1183 @@
1
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/buffer_utils.js
2
+ var encoder = new TextEncoder();
3
+ var decoder = new TextDecoder();
4
+ function concat(...buffers) {
5
+ const size = buffers.reduce((acc, { length }) => acc + length, 0);
6
+ const buf = new Uint8Array(size);
7
+ let i = 0;
8
+ for (const buffer of buffers) {
9
+ buf.set(buffer, i);
10
+ i += buffer.length;
11
+ }
12
+ return buf;
13
+ }
14
+ function encode(string) {
15
+ const bytes = new Uint8Array(string.length);
16
+ for (let i = 0; i < string.length; i++) {
17
+ const code = string.charCodeAt(i);
18
+ if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
19
+ bytes[i] = code;
20
+ }
21
+ return bytes;
22
+ }
23
+ //#endregion
24
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/base64.js
25
+ function decodeBase64(encoded) {
26
+ if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
27
+ const binary = atob(encoded);
28
+ const bytes = new Uint8Array(binary.length);
29
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
30
+ return bytes;
31
+ }
32
+ //#endregion
33
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/base64url.js
34
+ function decode(input) {
35
+ if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
36
+ let encoded = input;
37
+ if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
38
+ encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
39
+ try {
40
+ return decodeBase64(encoded);
41
+ } catch {
42
+ throw new TypeError("The input to be decoded is not correctly encoded.");
43
+ }
44
+ }
45
+ //#endregion
46
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/crypto_key.js
47
+ var unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
48
+ var isAlgorithm = (algorithm, name) => algorithm.name === name;
49
+ function getHashLength(hash) {
50
+ return parseInt(hash.name.slice(4), 10);
51
+ }
52
+ function checkHashLength(algorithm, expected) {
53
+ if (getHashLength(algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
54
+ }
55
+ function getNamedCurve(alg) {
56
+ switch (alg) {
57
+ case "ES256": return "P-256";
58
+ case "ES384": return "P-384";
59
+ case "ES512": return "P-521";
60
+ default: throw new Error("unreachable");
61
+ }
62
+ }
63
+ function checkUsage(key, usage) {
64
+ if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
65
+ }
66
+ function checkSigCryptoKey(key, alg, usage) {
67
+ switch (alg) {
68
+ case "HS256":
69
+ case "HS384":
70
+ case "HS512":
71
+ if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
72
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
73
+ break;
74
+ case "RS256":
75
+ case "RS384":
76
+ case "RS512":
77
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
78
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
79
+ break;
80
+ case "PS256":
81
+ case "PS384":
82
+ case "PS512":
83
+ if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
84
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
85
+ break;
86
+ case "Ed25519":
87
+ case "EdDSA":
88
+ if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
89
+ break;
90
+ case "ML-DSA-44":
91
+ case "ML-DSA-65":
92
+ case "ML-DSA-87":
93
+ if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
94
+ break;
95
+ case "ES256":
96
+ case "ES384":
97
+ case "ES512": {
98
+ if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
99
+ const expected = getNamedCurve(alg);
100
+ if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
101
+ break;
102
+ }
103
+ default: throw new TypeError("CryptoKey does not support this operation");
104
+ }
105
+ checkUsage(key, usage);
106
+ }
107
+ //#endregion
108
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/invalid_key_input.js
109
+ function message(msg, actual, ...types) {
110
+ types = types.filter(Boolean);
111
+ if (types.length > 2) {
112
+ const last = types.pop();
113
+ msg += `one of type ${types.join(", ")}, or ${last}.`;
114
+ } else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
115
+ else msg += `of type ${types[0]}.`;
116
+ if (actual == null) msg += ` Received ${actual}`;
117
+ else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
118
+ else if (typeof actual === "object" && actual != null) {
119
+ if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
120
+ }
121
+ return msg;
122
+ }
123
+ var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
124
+ var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
125
+ //#endregion
126
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/errors.js
127
+ var JOSEError = class extends Error {
128
+ static code = "ERR_JOSE_GENERIC";
129
+ code = "ERR_JOSE_GENERIC";
130
+ constructor(message, options) {
131
+ super(message, options);
132
+ this.name = this.constructor.name;
133
+ Error.captureStackTrace?.(this, this.constructor);
134
+ }
135
+ };
136
+ var JWTClaimValidationFailed = class extends JOSEError {
137
+ static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
138
+ code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
139
+ claim;
140
+ reason;
141
+ payload;
142
+ constructor(message, payload, claim = "unspecified", reason = "unspecified") {
143
+ super(message, { cause: {
144
+ claim,
145
+ reason,
146
+ payload
147
+ } });
148
+ this.claim = claim;
149
+ this.reason = reason;
150
+ this.payload = payload;
151
+ }
152
+ };
153
+ var JWTExpired = class extends JOSEError {
154
+ static code = "ERR_JWT_EXPIRED";
155
+ code = "ERR_JWT_EXPIRED";
156
+ claim;
157
+ reason;
158
+ payload;
159
+ constructor(message, payload, claim = "unspecified", reason = "unspecified") {
160
+ super(message, { cause: {
161
+ claim,
162
+ reason,
163
+ payload
164
+ } });
165
+ this.claim = claim;
166
+ this.reason = reason;
167
+ this.payload = payload;
168
+ }
169
+ };
170
+ var JOSEAlgNotAllowed = class extends JOSEError {
171
+ static code = "ERR_JOSE_ALG_NOT_ALLOWED";
172
+ code = "ERR_JOSE_ALG_NOT_ALLOWED";
173
+ };
174
+ var JOSENotSupported = class extends JOSEError {
175
+ static code = "ERR_JOSE_NOT_SUPPORTED";
176
+ code = "ERR_JOSE_NOT_SUPPORTED";
177
+ };
178
+ var JWSInvalid = class extends JOSEError {
179
+ static code = "ERR_JWS_INVALID";
180
+ code = "ERR_JWS_INVALID";
181
+ };
182
+ var JWTInvalid = class extends JOSEError {
183
+ static code = "ERR_JWT_INVALID";
184
+ code = "ERR_JWT_INVALID";
185
+ };
186
+ var JWKSInvalid = class extends JOSEError {
187
+ static code = "ERR_JWKS_INVALID";
188
+ code = "ERR_JWKS_INVALID";
189
+ };
190
+ var JWKSNoMatchingKey = class extends JOSEError {
191
+ static code = "ERR_JWKS_NO_MATCHING_KEY";
192
+ code = "ERR_JWKS_NO_MATCHING_KEY";
193
+ constructor(message = "no applicable key found in the JSON Web Key Set", options) {
194
+ super(message, options);
195
+ }
196
+ };
197
+ var JWKSMultipleMatchingKeys = class extends JOSEError {
198
+ [Symbol.asyncIterator];
199
+ static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
200
+ code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
201
+ constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
202
+ super(message, options);
203
+ }
204
+ };
205
+ var JWKSTimeout = class extends JOSEError {
206
+ static code = "ERR_JWKS_TIMEOUT";
207
+ code = "ERR_JWKS_TIMEOUT";
208
+ constructor(message = "request timed out", options) {
209
+ super(message, options);
210
+ }
211
+ };
212
+ var JWSSignatureVerificationFailed = class extends JOSEError {
213
+ static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
214
+ code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
215
+ constructor(message = "signature verification failed", options) {
216
+ super(message, options);
217
+ }
218
+ };
219
+ //#endregion
220
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/is_key_like.js
221
+ var isCryptoKey = (key) => {
222
+ if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
223
+ try {
224
+ return key instanceof CryptoKey;
225
+ } catch {
226
+ return false;
227
+ }
228
+ };
229
+ var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
230
+ var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
231
+ //#endregion
232
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/helpers.js
233
+ function decodeBase64url(value, label, ErrorClass) {
234
+ try {
235
+ return decode(value);
236
+ } catch {
237
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
238
+ }
239
+ }
240
+ //#endregion
241
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/type_checks.js
242
+ var isObjectLike = (value) => typeof value === "object" && value !== null;
243
+ function isObject(input) {
244
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
245
+ if (Object.getPrototypeOf(input) === null) return true;
246
+ let proto = input;
247
+ while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
248
+ return Object.getPrototypeOf(input) === proto;
249
+ }
250
+ function isDisjoint(...headers) {
251
+ const sources = headers.filter(Boolean);
252
+ if (sources.length === 0 || sources.length === 1) return true;
253
+ let acc;
254
+ for (const header of sources) {
255
+ const parameters = Object.keys(header);
256
+ if (!acc || acc.size === 0) {
257
+ acc = new Set(parameters);
258
+ continue;
259
+ }
260
+ for (const parameter of parameters) {
261
+ if (acc.has(parameter)) return false;
262
+ acc.add(parameter);
263
+ }
264
+ }
265
+ return true;
266
+ }
267
+ var isJWK = (key) => isObject(key) && typeof key.kty === "string";
268
+ var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
269
+ var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
270
+ var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
271
+ //#endregion
272
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/signing.js
273
+ function checkKeyLength(alg, key) {
274
+ if (alg.startsWith("RS") || alg.startsWith("PS")) {
275
+ const { modulusLength } = key.algorithm;
276
+ if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
277
+ }
278
+ }
279
+ function subtleAlgorithm(alg, algorithm) {
280
+ const hash = `SHA-${alg.slice(-3)}`;
281
+ switch (alg) {
282
+ case "HS256":
283
+ case "HS384":
284
+ case "HS512": return {
285
+ hash,
286
+ name: "HMAC"
287
+ };
288
+ case "PS256":
289
+ case "PS384":
290
+ case "PS512": return {
291
+ hash,
292
+ name: "RSA-PSS",
293
+ saltLength: parseInt(alg.slice(-3), 10) >> 3
294
+ };
295
+ case "RS256":
296
+ case "RS384":
297
+ case "RS512": return {
298
+ hash,
299
+ name: "RSASSA-PKCS1-v1_5"
300
+ };
301
+ case "ES256":
302
+ case "ES384":
303
+ case "ES512": return {
304
+ hash,
305
+ name: "ECDSA",
306
+ namedCurve: algorithm.namedCurve
307
+ };
308
+ case "Ed25519":
309
+ case "EdDSA": return { name: "Ed25519" };
310
+ case "ML-DSA-44":
311
+ case "ML-DSA-65":
312
+ case "ML-DSA-87": return { name: alg };
313
+ default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
314
+ }
315
+ }
316
+ async function getSigKey(alg, key, usage) {
317
+ if (key instanceof Uint8Array) {
318
+ if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
319
+ return crypto.subtle.importKey("raw", key, {
320
+ hash: `SHA-${alg.slice(-3)}`,
321
+ name: "HMAC"
322
+ }, false, [usage]);
323
+ }
324
+ checkSigCryptoKey(key, alg, usage);
325
+ return key;
326
+ }
327
+ async function verify(alg, key, signature, data) {
328
+ const cryptoKey = await getSigKey(alg, key, "verify");
329
+ checkKeyLength(alg, cryptoKey);
330
+ const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
331
+ try {
332
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
333
+ } catch {
334
+ return false;
335
+ }
336
+ }
337
+ //#endregion
338
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwk_to_key.js
339
+ var unsupportedAlg = "Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value";
340
+ function subtleMapping(jwk) {
341
+ let algorithm;
342
+ let keyUsages;
343
+ switch (jwk.kty) {
344
+ case "AKP":
345
+ switch (jwk.alg) {
346
+ case "ML-DSA-44":
347
+ case "ML-DSA-65":
348
+ case "ML-DSA-87":
349
+ algorithm = { name: jwk.alg };
350
+ keyUsages = jwk.priv ? ["sign"] : ["verify"];
351
+ break;
352
+ default: throw new JOSENotSupported(unsupportedAlg);
353
+ }
354
+ break;
355
+ case "RSA":
356
+ switch (jwk.alg) {
357
+ case "PS256":
358
+ case "PS384":
359
+ case "PS512":
360
+ algorithm = {
361
+ name: "RSA-PSS",
362
+ hash: `SHA-${jwk.alg.slice(-3)}`
363
+ };
364
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
365
+ break;
366
+ case "RS256":
367
+ case "RS384":
368
+ case "RS512":
369
+ algorithm = {
370
+ name: "RSASSA-PKCS1-v1_5",
371
+ hash: `SHA-${jwk.alg.slice(-3)}`
372
+ };
373
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
374
+ break;
375
+ case "RSA-OAEP":
376
+ case "RSA-OAEP-256":
377
+ case "RSA-OAEP-384":
378
+ case "RSA-OAEP-512":
379
+ algorithm = {
380
+ name: "RSA-OAEP",
381
+ hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
382
+ };
383
+ keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
384
+ break;
385
+ default: throw new JOSENotSupported(unsupportedAlg);
386
+ }
387
+ break;
388
+ case "EC":
389
+ switch (jwk.alg) {
390
+ case "ES256":
391
+ case "ES384":
392
+ case "ES512":
393
+ algorithm = {
394
+ name: "ECDSA",
395
+ namedCurve: {
396
+ ES256: "P-256",
397
+ ES384: "P-384",
398
+ ES512: "P-521"
399
+ }[jwk.alg]
400
+ };
401
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
402
+ break;
403
+ case "ECDH-ES":
404
+ case "ECDH-ES+A128KW":
405
+ case "ECDH-ES+A192KW":
406
+ case "ECDH-ES+A256KW":
407
+ algorithm = {
408
+ name: "ECDH",
409
+ namedCurve: jwk.crv
410
+ };
411
+ keyUsages = jwk.d ? ["deriveBits"] : [];
412
+ break;
413
+ default: throw new JOSENotSupported(unsupportedAlg);
414
+ }
415
+ break;
416
+ case "OKP":
417
+ switch (jwk.alg) {
418
+ case "Ed25519":
419
+ case "EdDSA":
420
+ algorithm = { name: "Ed25519" };
421
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
422
+ break;
423
+ case "ECDH-ES":
424
+ case "ECDH-ES+A128KW":
425
+ case "ECDH-ES+A192KW":
426
+ case "ECDH-ES+A256KW":
427
+ algorithm = { name: jwk.crv };
428
+ keyUsages = jwk.d ? ["deriveBits"] : [];
429
+ break;
430
+ default: throw new JOSENotSupported(unsupportedAlg);
431
+ }
432
+ break;
433
+ default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
434
+ }
435
+ return {
436
+ algorithm,
437
+ keyUsages
438
+ };
439
+ }
440
+ async function jwkToKey(jwk) {
441
+ if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
442
+ const { algorithm, keyUsages } = subtleMapping(jwk);
443
+ const keyData = { ...jwk };
444
+ if (keyData.kty !== "AKP") delete keyData.alg;
445
+ delete keyData.use;
446
+ return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
447
+ }
448
+ //#endregion
449
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/normalize_key.js
450
+ var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
451
+ var cache;
452
+ var handleJWK = async (key, jwk, alg, freeze = false) => {
453
+ cache ||= /* @__PURE__ */ new WeakMap();
454
+ let cached = cache.get(key);
455
+ if (cached?.[alg]) return cached[alg];
456
+ const cryptoKey = await jwkToKey({
457
+ ...jwk,
458
+ alg
459
+ });
460
+ if (freeze) Object.freeze(key);
461
+ if (!cached) cache.set(key, { [alg]: cryptoKey });
462
+ else cached[alg] = cryptoKey;
463
+ return cryptoKey;
464
+ };
465
+ var handleKeyObject = (keyObject, alg) => {
466
+ cache ||= /* @__PURE__ */ new WeakMap();
467
+ let cached = cache.get(keyObject);
468
+ if (cached?.[alg]) return cached[alg];
469
+ const isPublic = keyObject.type === "public";
470
+ const extractable = isPublic ? true : false;
471
+ let cryptoKey;
472
+ if (keyObject.asymmetricKeyType === "x25519") {
473
+ switch (alg) {
474
+ case "ECDH-ES":
475
+ case "ECDH-ES+A128KW":
476
+ case "ECDH-ES+A192KW":
477
+ case "ECDH-ES+A256KW": break;
478
+ default: throw new TypeError(unusableForAlg);
479
+ }
480
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
481
+ }
482
+ if (keyObject.asymmetricKeyType === "ed25519") {
483
+ if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError(unusableForAlg);
484
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
485
+ }
486
+ switch (keyObject.asymmetricKeyType) {
487
+ case "ml-dsa-44":
488
+ case "ml-dsa-65":
489
+ case "ml-dsa-87":
490
+ if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError(unusableForAlg);
491
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
492
+ }
493
+ if (keyObject.asymmetricKeyType === "rsa") {
494
+ let hash;
495
+ switch (alg) {
496
+ case "RSA-OAEP":
497
+ hash = "SHA-1";
498
+ break;
499
+ case "RS256":
500
+ case "PS256":
501
+ case "RSA-OAEP-256":
502
+ hash = "SHA-256";
503
+ break;
504
+ case "RS384":
505
+ case "PS384":
506
+ case "RSA-OAEP-384":
507
+ hash = "SHA-384";
508
+ break;
509
+ case "RS512":
510
+ case "PS512":
511
+ case "RSA-OAEP-512":
512
+ hash = "SHA-512";
513
+ break;
514
+ default: throw new TypeError(unusableForAlg);
515
+ }
516
+ if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
517
+ name: "RSA-OAEP",
518
+ hash
519
+ }, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
520
+ cryptoKey = keyObject.toCryptoKey({
521
+ name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
522
+ hash
523
+ }, extractable, [isPublic ? "verify" : "sign"]);
524
+ }
525
+ if (keyObject.asymmetricKeyType === "ec") {
526
+ const namedCurve = (/* @__PURE__ */ new Map([
527
+ ["prime256v1", "P-256"],
528
+ ["secp384r1", "P-384"],
529
+ ["secp521r1", "P-521"]
530
+ ])).get(keyObject.asymmetricKeyDetails?.namedCurve);
531
+ if (!namedCurve) throw new TypeError(unusableForAlg);
532
+ const expectedCurve = {
533
+ ES256: "P-256",
534
+ ES384: "P-384",
535
+ ES512: "P-521"
536
+ };
537
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) cryptoKey = keyObject.toCryptoKey({
538
+ name: "ECDSA",
539
+ namedCurve
540
+ }, extractable, [isPublic ? "verify" : "sign"]);
541
+ if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
542
+ name: "ECDH",
543
+ namedCurve
544
+ }, extractable, isPublic ? [] : ["deriveBits"]);
545
+ }
546
+ if (!cryptoKey) throw new TypeError(unusableForAlg);
547
+ if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
548
+ else cached[alg] = cryptoKey;
549
+ return cryptoKey;
550
+ };
551
+ async function normalizeKey(key, alg) {
552
+ if (key instanceof Uint8Array) return key;
553
+ if (isCryptoKey(key)) return key;
554
+ if (isKeyObject(key)) {
555
+ if (key.type === "secret") return key.export();
556
+ if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
557
+ return handleKeyObject(key, alg);
558
+ } catch (err) {
559
+ if (err instanceof TypeError) throw err;
560
+ }
561
+ return handleJWK(key, key.export({ format: "jwk" }), alg);
562
+ }
563
+ if (isJWK(key)) {
564
+ if (key.k) return decode(key.k);
565
+ return handleJWK(key, key, alg, true);
566
+ }
567
+ throw new Error("unreachable");
568
+ }
569
+ //#endregion
570
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/import.js
571
+ async function importJWK(jwk, alg, options) {
572
+ if (!isObject(jwk)) throw new TypeError("JWK must be an object");
573
+ let ext;
574
+ alg ??= jwk.alg;
575
+ ext ??= options?.extractable ?? jwk.ext;
576
+ switch (jwk.kty) {
577
+ case "oct":
578
+ if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
579
+ return decode(jwk.k);
580
+ case "RSA":
581
+ if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
582
+ return jwkToKey({
583
+ ...jwk,
584
+ alg,
585
+ ext
586
+ });
587
+ case "AKP":
588
+ if (typeof jwk.alg !== "string" || !jwk.alg) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
589
+ if (alg !== void 0 && alg !== jwk.alg) throw new TypeError("JWK alg and alg option value mismatch");
590
+ return jwkToKey({
591
+ ...jwk,
592
+ ext
593
+ });
594
+ case "EC":
595
+ case "OKP": return jwkToKey({
596
+ ...jwk,
597
+ alg,
598
+ ext
599
+ });
600
+ default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
601
+ }
602
+ }
603
+ //#endregion
604
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_crit.js
605
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
606
+ if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
607
+ if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
608
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
609
+ let recognized;
610
+ if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
611
+ else recognized = recognizedDefault;
612
+ for (const parameter of protectedHeader.crit) {
613
+ if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
614
+ if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
615
+ if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
616
+ }
617
+ return new Set(protectedHeader.crit);
618
+ }
619
+ //#endregion
620
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_algorithms.js
621
+ function validateAlgorithms(option, algorithms) {
622
+ if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
623
+ if (!algorithms) return;
624
+ return new Set(algorithms);
625
+ }
626
+ //#endregion
627
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/check_key_type.js
628
+ var tag = (key) => key?.[Symbol.toStringTag];
629
+ var jwkMatchesOp = (alg, key, usage) => {
630
+ if (key.use !== void 0) {
631
+ let expected;
632
+ switch (usage) {
633
+ case "sign":
634
+ case "verify":
635
+ expected = "sig";
636
+ break;
637
+ case "encrypt":
638
+ case "decrypt":
639
+ expected = "enc";
640
+ break;
641
+ }
642
+ if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
643
+ }
644
+ if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
645
+ if (Array.isArray(key.key_ops)) {
646
+ let expectedKeyOp;
647
+ switch (true) {
648
+ case usage === "sign" || usage === "verify":
649
+ case alg === "dir":
650
+ case alg.includes("CBC-HS"):
651
+ expectedKeyOp = usage;
652
+ break;
653
+ case alg.startsWith("PBES2"):
654
+ expectedKeyOp = "deriveBits";
655
+ break;
656
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
657
+ if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
658
+ else expectedKeyOp = usage;
659
+ break;
660
+ case usage === "encrypt" && alg.startsWith("RSA"):
661
+ expectedKeyOp = "wrapKey";
662
+ break;
663
+ case usage === "decrypt":
664
+ expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
665
+ break;
666
+ }
667
+ if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
668
+ }
669
+ return true;
670
+ };
671
+ var symmetricTypeCheck = (alg, key, usage) => {
672
+ if (key instanceof Uint8Array) return;
673
+ if (isJWK(key)) {
674
+ if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
675
+ throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
676
+ }
677
+ if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
678
+ if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
679
+ };
680
+ var asymmetricTypeCheck = (alg, key, usage) => {
681
+ if (isJWK(key)) switch (usage) {
682
+ case "decrypt":
683
+ case "sign":
684
+ if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
685
+ throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
686
+ case "encrypt":
687
+ case "verify":
688
+ if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
689
+ throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
690
+ }
691
+ if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
692
+ if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
693
+ if (key.type === "public") switch (usage) {
694
+ case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
695
+ case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
696
+ }
697
+ if (key.type === "private") switch (usage) {
698
+ case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
699
+ case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
700
+ }
701
+ };
702
+ function checkKeyType(alg, key, usage) {
703
+ switch (alg.substring(0, 2)) {
704
+ case "A1":
705
+ case "A2":
706
+ case "di":
707
+ case "HS":
708
+ case "PB":
709
+ symmetricTypeCheck(alg, key, usage);
710
+ break;
711
+ default: asymmetricTypeCheck(alg, key, usage);
712
+ }
713
+ }
714
+ //#endregion
715
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/flattened/verify.js
716
+ async function flattenedVerify(jws, key, options) {
717
+ if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
718
+ if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
719
+ if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
720
+ if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
721
+ if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
722
+ if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
723
+ let parsedProt = {};
724
+ if (jws.protected) try {
725
+ const protectedHeader = decode(jws.protected);
726
+ parsedProt = JSON.parse(decoder.decode(protectedHeader));
727
+ } catch {
728
+ throw new JWSInvalid("JWS Protected Header is invalid");
729
+ }
730
+ if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
731
+ const joseHeader = {
732
+ ...parsedProt,
733
+ ...jws.header
734
+ };
735
+ const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
736
+ let b64 = true;
737
+ if (extensions.has("b64")) {
738
+ b64 = parsedProt.b64;
739
+ if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
740
+ }
741
+ const { alg } = joseHeader;
742
+ if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
743
+ const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
744
+ if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
745
+ if (b64) {
746
+ if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
747
+ } else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
748
+ let resolvedKey = false;
749
+ if (typeof key === "function") {
750
+ key = await key(parsedProt, jws);
751
+ resolvedKey = true;
752
+ }
753
+ checkKeyType(alg, key, "verify");
754
+ const data = concat(jws.protected !== void 0 ? encode(jws.protected) : /* @__PURE__ */ new Uint8Array(), encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
755
+ const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
756
+ const k = await normalizeKey(key, alg);
757
+ if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
758
+ let payload;
759
+ if (b64) payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
760
+ else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
761
+ else payload = jws.payload;
762
+ const result = { payload };
763
+ if (jws.protected !== void 0) result.protectedHeader = parsedProt;
764
+ if (jws.header !== void 0) result.unprotectedHeader = jws.header;
765
+ if (resolvedKey) return {
766
+ ...result,
767
+ key: k
768
+ };
769
+ return result;
770
+ }
771
+ //#endregion
772
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/compact/verify.js
773
+ async function compactVerify(jws, key, options) {
774
+ if (jws instanceof Uint8Array) jws = decoder.decode(jws);
775
+ if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
776
+ const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
777
+ if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
778
+ const verified = await flattenedVerify({
779
+ payload,
780
+ protected: protectedHeader,
781
+ signature
782
+ }, key, options);
783
+ const result = {
784
+ payload: verified.payload,
785
+ protectedHeader: verified.protectedHeader
786
+ };
787
+ if (typeof key === "function") return {
788
+ ...result,
789
+ key: verified.key
790
+ };
791
+ return result;
792
+ }
793
+ //#endregion
794
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
795
+ var epoch = (date) => Math.floor(date.getTime() / 1e3);
796
+ var minute = 60;
797
+ var hour = minute * 60;
798
+ var day = hour * 24;
799
+ var week = day * 7;
800
+ var year = day * 365.25;
801
+ var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
802
+ function secs(str) {
803
+ const matched = REGEX.exec(str);
804
+ if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
805
+ const value = parseFloat(matched[2]);
806
+ const unit = matched[3].toLowerCase();
807
+ let numericDate;
808
+ switch (unit) {
809
+ case "sec":
810
+ case "secs":
811
+ case "second":
812
+ case "seconds":
813
+ case "s":
814
+ numericDate = Math.round(value);
815
+ break;
816
+ case "minute":
817
+ case "minutes":
818
+ case "min":
819
+ case "mins":
820
+ case "m":
821
+ numericDate = Math.round(value * minute);
822
+ break;
823
+ case "hour":
824
+ case "hours":
825
+ case "hr":
826
+ case "hrs":
827
+ case "h":
828
+ numericDate = Math.round(value * hour);
829
+ break;
830
+ case "day":
831
+ case "days":
832
+ case "d":
833
+ numericDate = Math.round(value * day);
834
+ break;
835
+ case "week":
836
+ case "weeks":
837
+ case "w":
838
+ numericDate = Math.round(value * week);
839
+ break;
840
+ default:
841
+ numericDate = Math.round(value * year);
842
+ break;
843
+ }
844
+ if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
845
+ return numericDate;
846
+ }
847
+ var normalizeTyp = (value) => {
848
+ if (value.includes("/")) return value.toLowerCase();
849
+ return `application/${value.toLowerCase()}`;
850
+ };
851
+ var checkAudiencePresence = (audPayload, audOption) => {
852
+ if (typeof audPayload === "string") return audOption.includes(audPayload);
853
+ if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
854
+ return false;
855
+ };
856
+ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
857
+ let payload;
858
+ try {
859
+ payload = JSON.parse(decoder.decode(encodedPayload));
860
+ } catch {}
861
+ if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
862
+ const { typ } = options;
863
+ if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
864
+ const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
865
+ const presenceCheck = [...requiredClaims];
866
+ if (maxTokenAge !== void 0) presenceCheck.push("iat");
867
+ if (audience !== void 0) presenceCheck.push("aud");
868
+ if (subject !== void 0) presenceCheck.push("sub");
869
+ if (issuer !== void 0) presenceCheck.push("iss");
870
+ for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
871
+ if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
872
+ if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
873
+ if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
874
+ let tolerance;
875
+ switch (typeof options.clockTolerance) {
876
+ case "string":
877
+ tolerance = secs(options.clockTolerance);
878
+ break;
879
+ case "number":
880
+ tolerance = options.clockTolerance;
881
+ break;
882
+ case "undefined":
883
+ tolerance = 0;
884
+ break;
885
+ default: throw new TypeError("Invalid clockTolerance option type");
886
+ }
887
+ const { currentDate } = options;
888
+ const now = epoch(currentDate || /* @__PURE__ */ new Date());
889
+ if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
890
+ if (payload.nbf !== void 0) {
891
+ if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
892
+ if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
893
+ }
894
+ if (payload.exp !== void 0) {
895
+ if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
896
+ if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
897
+ }
898
+ if (maxTokenAge) {
899
+ const age = now - payload.iat;
900
+ const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
901
+ if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
902
+ if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
903
+ }
904
+ return payload;
905
+ }
906
+ //#endregion
907
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/verify.js
908
+ async function jwtVerify(jwt, key, options) {
909
+ const verified = await compactVerify(jwt, key, options);
910
+ if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
911
+ const result = {
912
+ payload: validateClaimsSet(verified.protectedHeader, verified.payload, options),
913
+ protectedHeader: verified.protectedHeader
914
+ };
915
+ if (typeof key === "function") return {
916
+ ...result,
917
+ key: verified.key
918
+ };
919
+ return result;
920
+ }
921
+ //#endregion
922
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwks/local.js
923
+ function getKtyFromAlg(alg) {
924
+ switch (typeof alg === "string" && alg.slice(0, 2)) {
925
+ case "RS":
926
+ case "PS": return "RSA";
927
+ case "ES": return "EC";
928
+ case "Ed": return "OKP";
929
+ case "ML": return "AKP";
930
+ default: throw new JOSENotSupported("Unsupported \"alg\" value for a JSON Web Key Set");
931
+ }
932
+ }
933
+ function isJWKSLike(jwks) {
934
+ return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
935
+ }
936
+ function isJWKLike(key) {
937
+ return isObject(key);
938
+ }
939
+ var LocalJWKSet = class {
940
+ #jwks;
941
+ #cached = /* @__PURE__ */ new WeakMap();
942
+ constructor(jwks) {
943
+ if (!isJWKSLike(jwks)) throw new JWKSInvalid("JSON Web Key Set malformed");
944
+ this.#jwks = structuredClone(jwks);
945
+ }
946
+ jwks() {
947
+ return this.#jwks;
948
+ }
949
+ async getKey(protectedHeader, token) {
950
+ const { alg, kid } = {
951
+ ...protectedHeader,
952
+ ...token?.header
953
+ };
954
+ const kty = getKtyFromAlg(alg);
955
+ const candidates = this.#jwks.keys.filter((jwk) => {
956
+ let candidate = kty === jwk.kty;
957
+ if (candidate && typeof kid === "string") candidate = kid === jwk.kid;
958
+ if (candidate && (typeof jwk.alg === "string" || kty === "AKP")) candidate = alg === jwk.alg;
959
+ if (candidate && typeof jwk.use === "string") candidate = jwk.use === "sig";
960
+ if (candidate && Array.isArray(jwk.key_ops)) candidate = jwk.key_ops.includes("verify");
961
+ if (candidate) switch (alg) {
962
+ case "ES256":
963
+ candidate = jwk.crv === "P-256";
964
+ break;
965
+ case "ES384":
966
+ candidate = jwk.crv === "P-384";
967
+ break;
968
+ case "ES512":
969
+ candidate = jwk.crv === "P-521";
970
+ break;
971
+ case "Ed25519":
972
+ case "EdDSA":
973
+ candidate = jwk.crv === "Ed25519";
974
+ break;
975
+ }
976
+ return candidate;
977
+ });
978
+ const { 0: jwk, length } = candidates;
979
+ if (length === 0) throw new JWKSNoMatchingKey();
980
+ if (length !== 1) {
981
+ const error = new JWKSMultipleMatchingKeys();
982
+ const _cached = this.#cached;
983
+ error[Symbol.asyncIterator] = async function* () {
984
+ for (const jwk of candidates) try {
985
+ yield await importWithAlgCache(_cached, jwk, alg);
986
+ } catch {}
987
+ };
988
+ throw error;
989
+ }
990
+ return importWithAlgCache(this.#cached, jwk, alg);
991
+ }
992
+ };
993
+ async function importWithAlgCache(cache, jwk, alg) {
994
+ const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
995
+ if (cached[alg] === void 0) {
996
+ const key = await importJWK({
997
+ ...jwk,
998
+ ext: true
999
+ }, alg);
1000
+ if (key instanceof Uint8Array || key.type !== "public") throw new JWKSInvalid("JSON Web Key Set members must be public keys");
1001
+ cached[alg] = key;
1002
+ }
1003
+ return cached[alg];
1004
+ }
1005
+ function createLocalJWKSet(jwks) {
1006
+ const set = new LocalJWKSet(jwks);
1007
+ const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
1008
+ Object.defineProperties(localJWKSet, { jwks: {
1009
+ value: () => structuredClone(set.jwks()),
1010
+ enumerable: false,
1011
+ configurable: false,
1012
+ writable: false
1013
+ } });
1014
+ return localJWKSet;
1015
+ }
1016
+ //#endregion
1017
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwks/remote.js
1018
+ function isCloudflareWorkers() {
1019
+ return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
1020
+ }
1021
+ var USER_AGENT;
1022
+ if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) USER_AGENT = `jose/v6.2.2`;
1023
+ var customFetch = Symbol();
1024
+ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
1025
+ const response = await fetchImpl(url, {
1026
+ method: "GET",
1027
+ signal,
1028
+ redirect: "manual",
1029
+ headers
1030
+ }).catch((err) => {
1031
+ if (err.name === "TimeoutError") throw new JWKSTimeout();
1032
+ throw err;
1033
+ });
1034
+ if (response.status !== 200) throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
1035
+ try {
1036
+ return await response.json();
1037
+ } catch {
1038
+ throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
1039
+ }
1040
+ }
1041
+ var jwksCache = Symbol();
1042
+ function isFreshJwksCache(input, cacheMaxAge) {
1043
+ if (typeof input !== "object" || input === null) return false;
1044
+ if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) return false;
1045
+ if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) return false;
1046
+ return true;
1047
+ }
1048
+ var RemoteJWKSet = class {
1049
+ #url;
1050
+ #timeoutDuration;
1051
+ #cooldownDuration;
1052
+ #cacheMaxAge;
1053
+ #jwksTimestamp;
1054
+ #pendingFetch;
1055
+ #headers;
1056
+ #customFetch;
1057
+ #local;
1058
+ #cache;
1059
+ constructor(url, options) {
1060
+ if (!(url instanceof URL)) throw new TypeError("url must be an instance of URL");
1061
+ this.#url = new URL(url.href);
1062
+ this.#timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
1063
+ this.#cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
1064
+ this.#cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
1065
+ this.#headers = new Headers(options?.headers);
1066
+ if (USER_AGENT && !this.#headers.has("User-Agent")) this.#headers.set("User-Agent", USER_AGENT);
1067
+ if (!this.#headers.has("accept")) {
1068
+ this.#headers.set("accept", "application/json");
1069
+ this.#headers.append("accept", "application/jwk-set+json");
1070
+ }
1071
+ this.#customFetch = options?.[customFetch];
1072
+ if (options?.[jwksCache] !== void 0) {
1073
+ this.#cache = options?.[jwksCache];
1074
+ if (isFreshJwksCache(options?.[jwksCache], this.#cacheMaxAge)) {
1075
+ this.#jwksTimestamp = this.#cache.uat;
1076
+ this.#local = createLocalJWKSet(this.#cache.jwks);
1077
+ }
1078
+ }
1079
+ }
1080
+ pendingFetch() {
1081
+ return !!this.#pendingFetch;
1082
+ }
1083
+ coolingDown() {
1084
+ return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cooldownDuration : false;
1085
+ }
1086
+ fresh() {
1087
+ return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge : false;
1088
+ }
1089
+ jwks() {
1090
+ return this.#local?.jwks();
1091
+ }
1092
+ async getKey(protectedHeader, token) {
1093
+ if (!this.#local || !this.fresh()) await this.reload();
1094
+ try {
1095
+ return await this.#local(protectedHeader, token);
1096
+ } catch (err) {
1097
+ if (err instanceof JWKSNoMatchingKey) {
1098
+ if (this.coolingDown() === false) {
1099
+ await this.reload();
1100
+ return this.#local(protectedHeader, token);
1101
+ }
1102
+ }
1103
+ throw err;
1104
+ }
1105
+ }
1106
+ async reload() {
1107
+ if (this.#pendingFetch && isCloudflareWorkers()) this.#pendingFetch = void 0;
1108
+ this.#pendingFetch ||= fetchJwks(this.#url.href, this.#headers, AbortSignal.timeout(this.#timeoutDuration), this.#customFetch).then((json) => {
1109
+ this.#local = createLocalJWKSet(json);
1110
+ if (this.#cache) {
1111
+ this.#cache.uat = Date.now();
1112
+ this.#cache.jwks = json;
1113
+ }
1114
+ this.#jwksTimestamp = Date.now();
1115
+ this.#pendingFetch = void 0;
1116
+ }).catch((err) => {
1117
+ this.#pendingFetch = void 0;
1118
+ throw err;
1119
+ });
1120
+ await this.#pendingFetch;
1121
+ }
1122
+ };
1123
+ function createRemoteJWKSet(url, options) {
1124
+ const set = new RemoteJWKSet(url, options);
1125
+ const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
1126
+ Object.defineProperties(remoteJWKSet, {
1127
+ coolingDown: {
1128
+ get: () => set.coolingDown(),
1129
+ enumerable: true,
1130
+ configurable: false
1131
+ },
1132
+ fresh: {
1133
+ get: () => set.fresh(),
1134
+ enumerable: true,
1135
+ configurable: false
1136
+ },
1137
+ reload: {
1138
+ value: () => set.reload(),
1139
+ enumerable: true,
1140
+ configurable: false,
1141
+ writable: false
1142
+ },
1143
+ reloading: {
1144
+ get: () => set.pendingFetch(),
1145
+ enumerable: true,
1146
+ configurable: false
1147
+ },
1148
+ jwks: {
1149
+ value: () => set.jwks(),
1150
+ enumerable: true,
1151
+ configurable: false,
1152
+ writable: false
1153
+ }
1154
+ });
1155
+ return remoteJWKSet;
1156
+ }
1157
+ //#endregion
1158
+ //#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/decode_jwt.js
1159
+ function decodeJwt(jwt) {
1160
+ if (typeof jwt !== "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
1161
+ const { 1: payload, length } = jwt.split(".");
1162
+ if (length === 5) throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
1163
+ if (length !== 3) throw new JWTInvalid("Invalid JWT");
1164
+ if (!payload) throw new JWTInvalid("JWTs must contain a payload");
1165
+ let decoded;
1166
+ try {
1167
+ decoded = decode(payload);
1168
+ } catch {
1169
+ throw new JWTInvalid("Failed to base64url decode the payload");
1170
+ }
1171
+ let result;
1172
+ try {
1173
+ result = JSON.parse(decoder.decode(decoded));
1174
+ } catch {
1175
+ throw new JWTInvalid("Failed to parse the decoded payload as JSON");
1176
+ }
1177
+ if (!isObject(result)) throw new JWTInvalid("Invalid JWT Claims Set");
1178
+ return result;
1179
+ }
1180
+ //#endregion
1181
+ export { JWTClaimValidationFailed as a, JWSSignatureVerificationFailed as i, createRemoteJWKSet as n, JWTExpired as o, jwtVerify as r, decodeJwt as t };
1182
+
1183
+ //# sourceMappingURL=decode_jwt-BvtACpi_.js.map