emulate 0.1.1 → 0.3.0

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.
@@ -0,0 +1,1615 @@
1
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/invalid_key_input.js
2
+ function message(msg, actual, ...types) {
3
+ types = types.filter(Boolean);
4
+ if (types.length > 2) {
5
+ const last = types.pop();
6
+ msg += `one of type ${types.join(", ")}, or ${last}.`;
7
+ } else if (types.length === 2) {
8
+ msg += `one of type ${types[0]} or ${types[1]}.`;
9
+ } else {
10
+ msg += `of type ${types[0]}.`;
11
+ }
12
+ if (actual == null) {
13
+ msg += ` Received ${actual}`;
14
+ } else if (typeof actual === "function" && actual.name) {
15
+ msg += ` Received function ${actual.name}`;
16
+ } else if (typeof actual === "object" && actual != null) {
17
+ if (actual.constructor?.name) {
18
+ msg += ` Received an instance of ${actual.constructor.name}`;
19
+ }
20
+ }
21
+ return msg;
22
+ }
23
+ var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
24
+ var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
25
+
26
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/base64.js
27
+ function encodeBase64(input) {
28
+ if (Uint8Array.prototype.toBase64) {
29
+ return input.toBase64();
30
+ }
31
+ const CHUNK_SIZE = 32768;
32
+ const arr = [];
33
+ for (let i = 0; i < input.length; i += CHUNK_SIZE) {
34
+ arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
35
+ }
36
+ return btoa(arr.join(""));
37
+ }
38
+ function decodeBase64(encoded) {
39
+ if (Uint8Array.fromBase64) {
40
+ return Uint8Array.fromBase64(encoded);
41
+ }
42
+ const binary = atob(encoded);
43
+ const bytes = new Uint8Array(binary.length);
44
+ for (let i = 0; i < binary.length; i++) {
45
+ bytes[i] = binary.charCodeAt(i);
46
+ }
47
+ return bytes;
48
+ }
49
+
50
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/errors.js
51
+ var JOSEError = class extends Error {
52
+ static code = "ERR_JOSE_GENERIC";
53
+ code = "ERR_JOSE_GENERIC";
54
+ constructor(message2, options) {
55
+ super(message2, options);
56
+ this.name = this.constructor.name;
57
+ Error.captureStackTrace?.(this, this.constructor);
58
+ }
59
+ };
60
+ var JWTClaimValidationFailed = class extends JOSEError {
61
+ static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
62
+ code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
63
+ claim;
64
+ reason;
65
+ payload;
66
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
67
+ super(message2, { cause: { claim, reason, payload } });
68
+ this.claim = claim;
69
+ this.reason = reason;
70
+ this.payload = payload;
71
+ }
72
+ };
73
+ var JWTExpired = class extends JOSEError {
74
+ static code = "ERR_JWT_EXPIRED";
75
+ code = "ERR_JWT_EXPIRED";
76
+ claim;
77
+ reason;
78
+ payload;
79
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
80
+ super(message2, { cause: { claim, reason, payload } });
81
+ this.claim = claim;
82
+ this.reason = reason;
83
+ this.payload = payload;
84
+ }
85
+ };
86
+ var JOSEAlgNotAllowed = class extends JOSEError {
87
+ static code = "ERR_JOSE_ALG_NOT_ALLOWED";
88
+ code = "ERR_JOSE_ALG_NOT_ALLOWED";
89
+ };
90
+ var JOSENotSupported = class extends JOSEError {
91
+ static code = "ERR_JOSE_NOT_SUPPORTED";
92
+ code = "ERR_JOSE_NOT_SUPPORTED";
93
+ };
94
+ var JWSInvalid = class extends JOSEError {
95
+ static code = "ERR_JWS_INVALID";
96
+ code = "ERR_JWS_INVALID";
97
+ };
98
+ var JWTInvalid = class extends JOSEError {
99
+ static code = "ERR_JWT_INVALID";
100
+ code = "ERR_JWT_INVALID";
101
+ };
102
+ var JWSSignatureVerificationFailed = class extends JOSEError {
103
+ static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
104
+ code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
105
+ constructor(message2 = "signature verification failed", options) {
106
+ super(message2, options);
107
+ }
108
+ };
109
+
110
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/is_key_like.js
111
+ var isCryptoKey = (key) => {
112
+ if (key?.[Symbol.toStringTag] === "CryptoKey")
113
+ return true;
114
+ try {
115
+ return key instanceof CryptoKey;
116
+ } catch {
117
+ return false;
118
+ }
119
+ };
120
+ var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
121
+ var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
122
+
123
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/asn1.js
124
+ var bytesEqual = (a, b) => {
125
+ if (a.byteLength !== b.length)
126
+ return false;
127
+ for (let i = 0; i < a.byteLength; i++) {
128
+ if (a[i] !== b[i])
129
+ return false;
130
+ }
131
+ return true;
132
+ };
133
+ var createASN1State = (data) => ({ data, pos: 0 });
134
+ var parseLength = (state) => {
135
+ const first = state.data[state.pos++];
136
+ if (first & 128) {
137
+ const lengthOfLen = first & 127;
138
+ let length = 0;
139
+ for (let i = 0; i < lengthOfLen; i++) {
140
+ length = length << 8 | state.data[state.pos++];
141
+ }
142
+ return length;
143
+ }
144
+ return first;
145
+ };
146
+ var expectTag = (state, expectedTag, errorMessage) => {
147
+ if (state.data[state.pos++] !== expectedTag) {
148
+ throw new Error(errorMessage);
149
+ }
150
+ };
151
+ var getSubarray = (state, length) => {
152
+ const result = state.data.subarray(state.pos, state.pos + length);
153
+ state.pos += length;
154
+ return result;
155
+ };
156
+ var parseAlgorithmOID = (state) => {
157
+ expectTag(state, 6, "Expected algorithm OID");
158
+ const oidLen = parseLength(state);
159
+ return getSubarray(state, oidLen);
160
+ };
161
+ function parsePKCS8Header(state) {
162
+ expectTag(state, 48, "Invalid PKCS#8 structure");
163
+ parseLength(state);
164
+ expectTag(state, 2, "Expected version field");
165
+ const verLen = parseLength(state);
166
+ state.pos += verLen;
167
+ expectTag(state, 48, "Expected algorithm identifier");
168
+ const algIdLen = parseLength(state);
169
+ const algIdStart = state.pos;
170
+ return { algIdStart, algIdLength: algIdLen };
171
+ }
172
+ var parseECAlgorithmIdentifier = (state) => {
173
+ const algOid = parseAlgorithmOID(state);
174
+ if (bytesEqual(algOid, [43, 101, 110])) {
175
+ return "X25519";
176
+ }
177
+ if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
178
+ throw new Error("Unsupported key algorithm");
179
+ }
180
+ expectTag(state, 6, "Expected curve OID");
181
+ const curveOidLen = parseLength(state);
182
+ const curveOid = getSubarray(state, curveOidLen);
183
+ for (const { name, oid } of [
184
+ { name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
185
+ { name: "P-384", oid: [43, 129, 4, 0, 34] },
186
+ { name: "P-521", oid: [43, 129, 4, 0, 35] }
187
+ ]) {
188
+ if (bytesEqual(curveOid, oid)) {
189
+ return name;
190
+ }
191
+ }
192
+ throw new Error("Unsupported named curve");
193
+ };
194
+ var genericImport = async (keyFormat, keyData, alg, options) => {
195
+ let algorithm;
196
+ let keyUsages;
197
+ const isPublic = keyFormat === "spki";
198
+ const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
199
+ const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
200
+ switch (alg) {
201
+ case "PS256":
202
+ case "PS384":
203
+ case "PS512":
204
+ algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
205
+ keyUsages = getSigUsages();
206
+ break;
207
+ case "RS256":
208
+ case "RS384":
209
+ case "RS512":
210
+ algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
211
+ keyUsages = getSigUsages();
212
+ break;
213
+ case "RSA-OAEP":
214
+ case "RSA-OAEP-256":
215
+ case "RSA-OAEP-384":
216
+ case "RSA-OAEP-512":
217
+ algorithm = {
218
+ name: "RSA-OAEP",
219
+ hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
220
+ };
221
+ keyUsages = getEncUsages();
222
+ break;
223
+ case "ES256":
224
+ case "ES384":
225
+ case "ES512": {
226
+ const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
227
+ algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
228
+ keyUsages = getSigUsages();
229
+ break;
230
+ }
231
+ case "ECDH-ES":
232
+ case "ECDH-ES+A128KW":
233
+ case "ECDH-ES+A192KW":
234
+ case "ECDH-ES+A256KW": {
235
+ try {
236
+ const namedCurve = options.getNamedCurve(keyData);
237
+ algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
238
+ } catch (cause) {
239
+ throw new JOSENotSupported("Invalid or unsupported key format");
240
+ }
241
+ keyUsages = isPublic ? [] : ["deriveBits"];
242
+ break;
243
+ }
244
+ case "Ed25519":
245
+ case "EdDSA":
246
+ algorithm = { name: "Ed25519" };
247
+ keyUsages = getSigUsages();
248
+ break;
249
+ case "ML-DSA-44":
250
+ case "ML-DSA-65":
251
+ case "ML-DSA-87":
252
+ algorithm = { name: alg };
253
+ keyUsages = getSigUsages();
254
+ break;
255
+ default:
256
+ throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
257
+ }
258
+ return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
259
+ };
260
+ var processPEMData = (pem, pattern) => {
261
+ return decodeBase64(pem.replace(pattern, ""));
262
+ };
263
+ var fromPKCS8 = (pem, alg, options) => {
264
+ const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
265
+ let opts = options;
266
+ if (alg?.startsWith?.("ECDH-ES")) {
267
+ opts ||= {};
268
+ opts.getNamedCurve = (keyData2) => {
269
+ const state = createASN1State(keyData2);
270
+ parsePKCS8Header(state);
271
+ return parseECAlgorithmIdentifier(state);
272
+ };
273
+ }
274
+ return genericImport("pkcs8", keyData, alg, opts);
275
+ };
276
+
277
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/buffer_utils.js
278
+ var encoder = new TextEncoder();
279
+ var decoder = new TextDecoder();
280
+ var MAX_INT32 = 2 ** 32;
281
+ function concat(...buffers) {
282
+ const size = buffers.reduce((acc, { length }) => acc + length, 0);
283
+ const buf = new Uint8Array(size);
284
+ let i = 0;
285
+ for (const buffer of buffers) {
286
+ buf.set(buffer, i);
287
+ i += buffer.length;
288
+ }
289
+ return buf;
290
+ }
291
+ function encode(string) {
292
+ const bytes = new Uint8Array(string.length);
293
+ for (let i = 0; i < string.length; i++) {
294
+ const code = string.charCodeAt(i);
295
+ if (code > 127) {
296
+ throw new TypeError("non-ASCII string encountered in encode()");
297
+ }
298
+ bytes[i] = code;
299
+ }
300
+ return bytes;
301
+ }
302
+
303
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/base64url.js
304
+ function decode(input) {
305
+ if (Uint8Array.fromBase64) {
306
+ return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
307
+ alphabet: "base64url"
308
+ });
309
+ }
310
+ let encoded = input;
311
+ if (encoded instanceof Uint8Array) {
312
+ encoded = decoder.decode(encoded);
313
+ }
314
+ encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
315
+ try {
316
+ return decodeBase64(encoded);
317
+ } catch {
318
+ throw new TypeError("The input to be decoded is not correctly encoded.");
319
+ }
320
+ }
321
+ function encode2(input) {
322
+ let unencoded = input;
323
+ if (typeof unencoded === "string") {
324
+ unencoded = encoder.encode(unencoded);
325
+ }
326
+ if (Uint8Array.prototype.toBase64) {
327
+ return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
328
+ }
329
+ return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
330
+ }
331
+
332
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/key_to_jwk.js
333
+ async function keyToJWK(key) {
334
+ if (isKeyObject(key)) {
335
+ if (key.type === "secret") {
336
+ key = key.export();
337
+ } else {
338
+ return key.export({ format: "jwk" });
339
+ }
340
+ }
341
+ if (key instanceof Uint8Array) {
342
+ return {
343
+ kty: "oct",
344
+ k: encode2(key)
345
+ };
346
+ }
347
+ if (!isCryptoKey(key)) {
348
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
349
+ }
350
+ if (!key.extractable) {
351
+ throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
352
+ }
353
+ const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
354
+ if (jwk.kty === "AKP") {
355
+ ;
356
+ jwk.alg = alg;
357
+ }
358
+ return jwk;
359
+ }
360
+
361
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/export.js
362
+ async function exportJWK(key) {
363
+ return keyToJWK(key);
364
+ }
365
+
366
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/crypto_key.js
367
+ var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
368
+ var isAlgorithm = (algorithm, name) => algorithm.name === name;
369
+ function getHashLength(hash) {
370
+ return parseInt(hash.name.slice(4), 10);
371
+ }
372
+ function checkHashLength(algorithm, expected) {
373
+ const actual = getHashLength(algorithm.hash);
374
+ if (actual !== expected)
375
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
376
+ }
377
+ function getNamedCurve(alg) {
378
+ switch (alg) {
379
+ case "ES256":
380
+ return "P-256";
381
+ case "ES384":
382
+ return "P-384";
383
+ case "ES512":
384
+ return "P-521";
385
+ default:
386
+ throw new Error("unreachable");
387
+ }
388
+ }
389
+ function checkUsage(key, usage) {
390
+ if (usage && !key.usages.includes(usage)) {
391
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
392
+ }
393
+ }
394
+ function checkSigCryptoKey(key, alg, usage) {
395
+ switch (alg) {
396
+ case "HS256":
397
+ case "HS384":
398
+ case "HS512": {
399
+ if (!isAlgorithm(key.algorithm, "HMAC"))
400
+ throw unusable("HMAC");
401
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
402
+ break;
403
+ }
404
+ case "RS256":
405
+ case "RS384":
406
+ case "RS512": {
407
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
408
+ throw unusable("RSASSA-PKCS1-v1_5");
409
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
410
+ break;
411
+ }
412
+ case "PS256":
413
+ case "PS384":
414
+ case "PS512": {
415
+ if (!isAlgorithm(key.algorithm, "RSA-PSS"))
416
+ throw unusable("RSA-PSS");
417
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
418
+ break;
419
+ }
420
+ case "Ed25519":
421
+ case "EdDSA": {
422
+ if (!isAlgorithm(key.algorithm, "Ed25519"))
423
+ throw unusable("Ed25519");
424
+ break;
425
+ }
426
+ case "ML-DSA-44":
427
+ case "ML-DSA-65":
428
+ case "ML-DSA-87": {
429
+ if (!isAlgorithm(key.algorithm, alg))
430
+ throw unusable(alg);
431
+ break;
432
+ }
433
+ case "ES256":
434
+ case "ES384":
435
+ case "ES512": {
436
+ if (!isAlgorithm(key.algorithm, "ECDSA"))
437
+ throw unusable("ECDSA");
438
+ const expected = getNamedCurve(alg);
439
+ const actual = key.algorithm.namedCurve;
440
+ if (actual !== expected)
441
+ throw unusable(expected, "algorithm.namedCurve");
442
+ break;
443
+ }
444
+ default:
445
+ throw new TypeError("CryptoKey does not support this operation");
446
+ }
447
+ checkUsage(key, usage);
448
+ }
449
+
450
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/signing.js
451
+ function checkKeyLength(alg, key) {
452
+ if (alg.startsWith("RS") || alg.startsWith("PS")) {
453
+ const { modulusLength } = key.algorithm;
454
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
455
+ throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
456
+ }
457
+ }
458
+ }
459
+ function subtleAlgorithm(alg, algorithm) {
460
+ const hash = `SHA-${alg.slice(-3)}`;
461
+ switch (alg) {
462
+ case "HS256":
463
+ case "HS384":
464
+ case "HS512":
465
+ return { hash, name: "HMAC" };
466
+ case "PS256":
467
+ case "PS384":
468
+ case "PS512":
469
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
470
+ case "RS256":
471
+ case "RS384":
472
+ case "RS512":
473
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
474
+ case "ES256":
475
+ case "ES384":
476
+ case "ES512":
477
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
478
+ case "Ed25519":
479
+ case "EdDSA":
480
+ return { name: "Ed25519" };
481
+ case "ML-DSA-44":
482
+ case "ML-DSA-65":
483
+ case "ML-DSA-87":
484
+ return { name: alg };
485
+ default:
486
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
487
+ }
488
+ }
489
+ async function getSigKey(alg, key, usage) {
490
+ if (key instanceof Uint8Array) {
491
+ if (!alg.startsWith("HS")) {
492
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
493
+ }
494
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
495
+ }
496
+ checkSigCryptoKey(key, alg, usage);
497
+ return key;
498
+ }
499
+ async function sign(alg, key, data) {
500
+ const cryptoKey = await getSigKey(alg, key, "sign");
501
+ checkKeyLength(alg, cryptoKey);
502
+ const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
503
+ return new Uint8Array(signature);
504
+ }
505
+ async function verify(alg, key, signature, data) {
506
+ const cryptoKey = await getSigKey(alg, key, "verify");
507
+ checkKeyLength(alg, cryptoKey);
508
+ const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
509
+ try {
510
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
511
+ } catch {
512
+ return false;
513
+ }
514
+ }
515
+
516
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/type_checks.js
517
+ var isObjectLike = (value) => typeof value === "object" && value !== null;
518
+ function isObject(input) {
519
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
520
+ return false;
521
+ }
522
+ if (Object.getPrototypeOf(input) === null) {
523
+ return true;
524
+ }
525
+ let proto = input;
526
+ while (Object.getPrototypeOf(proto) !== null) {
527
+ proto = Object.getPrototypeOf(proto);
528
+ }
529
+ return Object.getPrototypeOf(input) === proto;
530
+ }
531
+ function isDisjoint(...headers) {
532
+ const sources = headers.filter(Boolean);
533
+ if (sources.length === 0 || sources.length === 1) {
534
+ return true;
535
+ }
536
+ let acc;
537
+ for (const header of sources) {
538
+ const parameters = Object.keys(header);
539
+ if (!acc || acc.size === 0) {
540
+ acc = new Set(parameters);
541
+ continue;
542
+ }
543
+ for (const parameter of parameters) {
544
+ if (acc.has(parameter)) {
545
+ return false;
546
+ }
547
+ acc.add(parameter);
548
+ }
549
+ }
550
+ return true;
551
+ }
552
+ var isJWK = (key) => isObject(key) && typeof key.kty === "string";
553
+ var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
554
+ var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
555
+ var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
556
+
557
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/check_key_type.js
558
+ var tag = (key) => key?.[Symbol.toStringTag];
559
+ var jwkMatchesOp = (alg, key, usage) => {
560
+ if (key.use !== void 0) {
561
+ let expected;
562
+ switch (usage) {
563
+ case "sign":
564
+ case "verify":
565
+ expected = "sig";
566
+ break;
567
+ case "encrypt":
568
+ case "decrypt":
569
+ expected = "enc";
570
+ break;
571
+ }
572
+ if (key.use !== expected) {
573
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
574
+ }
575
+ }
576
+ if (key.alg !== void 0 && key.alg !== alg) {
577
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
578
+ }
579
+ if (Array.isArray(key.key_ops)) {
580
+ let expectedKeyOp;
581
+ switch (true) {
582
+ case (usage === "sign" || usage === "verify"):
583
+ case alg === "dir":
584
+ case alg.includes("CBC-HS"):
585
+ expectedKeyOp = usage;
586
+ break;
587
+ case alg.startsWith("PBES2"):
588
+ expectedKeyOp = "deriveBits";
589
+ break;
590
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
591
+ if (!alg.includes("GCM") && alg.endsWith("KW")) {
592
+ expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
593
+ } else {
594
+ expectedKeyOp = usage;
595
+ }
596
+ break;
597
+ case (usage === "encrypt" && alg.startsWith("RSA")):
598
+ expectedKeyOp = "wrapKey";
599
+ break;
600
+ case usage === "decrypt":
601
+ expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
602
+ break;
603
+ }
604
+ if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
605
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
606
+ }
607
+ }
608
+ return true;
609
+ };
610
+ var symmetricTypeCheck = (alg, key, usage) => {
611
+ if (key instanceof Uint8Array)
612
+ return;
613
+ if (isJWK(key)) {
614
+ if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
615
+ return;
616
+ 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`);
617
+ }
618
+ if (!isKeyLike(key)) {
619
+ throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
620
+ }
621
+ if (key.type !== "secret") {
622
+ throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
623
+ }
624
+ };
625
+ var asymmetricTypeCheck = (alg, key, usage) => {
626
+ if (isJWK(key)) {
627
+ switch (usage) {
628
+ case "decrypt":
629
+ case "sign":
630
+ if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
631
+ return;
632
+ throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
633
+ case "encrypt":
634
+ case "verify":
635
+ if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
636
+ return;
637
+ throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
638
+ }
639
+ }
640
+ if (!isKeyLike(key)) {
641
+ throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
642
+ }
643
+ if (key.type === "secret") {
644
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
645
+ }
646
+ if (key.type === "public") {
647
+ switch (usage) {
648
+ case "sign":
649
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
650
+ case "decrypt":
651
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
652
+ }
653
+ }
654
+ if (key.type === "private") {
655
+ switch (usage) {
656
+ case "verify":
657
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
658
+ case "encrypt":
659
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
660
+ }
661
+ }
662
+ };
663
+ function checkKeyType(alg, key, usage) {
664
+ switch (alg.substring(0, 2)) {
665
+ case "A1":
666
+ case "A2":
667
+ case "di":
668
+ case "HS":
669
+ case "PB":
670
+ symmetricTypeCheck(alg, key, usage);
671
+ break;
672
+ default:
673
+ asymmetricTypeCheck(alg, key, usage);
674
+ }
675
+ }
676
+
677
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_crit.js
678
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
679
+ if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
680
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
681
+ }
682
+ if (!protectedHeader || protectedHeader.crit === void 0) {
683
+ return /* @__PURE__ */ new Set();
684
+ }
685
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
686
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
687
+ }
688
+ let recognized;
689
+ if (recognizedOption !== void 0) {
690
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
691
+ } else {
692
+ recognized = recognizedDefault;
693
+ }
694
+ for (const parameter of protectedHeader.crit) {
695
+ if (!recognized.has(parameter)) {
696
+ throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
697
+ }
698
+ if (joseHeader[parameter] === void 0) {
699
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
700
+ }
701
+ if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
702
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
703
+ }
704
+ }
705
+ return new Set(protectedHeader.crit);
706
+ }
707
+
708
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwk_to_key.js
709
+ var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
710
+ function subtleMapping(jwk) {
711
+ let algorithm;
712
+ let keyUsages;
713
+ switch (jwk.kty) {
714
+ case "AKP": {
715
+ switch (jwk.alg) {
716
+ case "ML-DSA-44":
717
+ case "ML-DSA-65":
718
+ case "ML-DSA-87":
719
+ algorithm = { name: jwk.alg };
720
+ keyUsages = jwk.priv ? ["sign"] : ["verify"];
721
+ break;
722
+ default:
723
+ throw new JOSENotSupported(unsupportedAlg);
724
+ }
725
+ break;
726
+ }
727
+ case "RSA": {
728
+ switch (jwk.alg) {
729
+ case "PS256":
730
+ case "PS384":
731
+ case "PS512":
732
+ algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
733
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
734
+ break;
735
+ case "RS256":
736
+ case "RS384":
737
+ case "RS512":
738
+ algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
739
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
740
+ break;
741
+ case "RSA-OAEP":
742
+ case "RSA-OAEP-256":
743
+ case "RSA-OAEP-384":
744
+ case "RSA-OAEP-512":
745
+ algorithm = {
746
+ name: "RSA-OAEP",
747
+ hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
748
+ };
749
+ keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
750
+ break;
751
+ default:
752
+ throw new JOSENotSupported(unsupportedAlg);
753
+ }
754
+ break;
755
+ }
756
+ case "EC": {
757
+ switch (jwk.alg) {
758
+ case "ES256":
759
+ case "ES384":
760
+ case "ES512":
761
+ algorithm = {
762
+ name: "ECDSA",
763
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
764
+ };
765
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
766
+ break;
767
+ case "ECDH-ES":
768
+ case "ECDH-ES+A128KW":
769
+ case "ECDH-ES+A192KW":
770
+ case "ECDH-ES+A256KW":
771
+ algorithm = { name: "ECDH", namedCurve: jwk.crv };
772
+ keyUsages = jwk.d ? ["deriveBits"] : [];
773
+ break;
774
+ default:
775
+ throw new JOSENotSupported(unsupportedAlg);
776
+ }
777
+ break;
778
+ }
779
+ case "OKP": {
780
+ switch (jwk.alg) {
781
+ case "Ed25519":
782
+ case "EdDSA":
783
+ algorithm = { name: "Ed25519" };
784
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
785
+ break;
786
+ case "ECDH-ES":
787
+ case "ECDH-ES+A128KW":
788
+ case "ECDH-ES+A192KW":
789
+ case "ECDH-ES+A256KW":
790
+ algorithm = { name: jwk.crv };
791
+ keyUsages = jwk.d ? ["deriveBits"] : [];
792
+ break;
793
+ default:
794
+ throw new JOSENotSupported(unsupportedAlg);
795
+ }
796
+ break;
797
+ }
798
+ default:
799
+ throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
800
+ }
801
+ return { algorithm, keyUsages };
802
+ }
803
+ async function jwkToKey(jwk) {
804
+ if (!jwk.alg) {
805
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
806
+ }
807
+ const { algorithm, keyUsages } = subtleMapping(jwk);
808
+ const keyData = { ...jwk };
809
+ if (keyData.kty !== "AKP") {
810
+ delete keyData.alg;
811
+ }
812
+ delete keyData.use;
813
+ return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
814
+ }
815
+
816
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/normalize_key.js
817
+ var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
818
+ var cache;
819
+ var handleJWK = async (key, jwk, alg, freeze = false) => {
820
+ cache ||= /* @__PURE__ */ new WeakMap();
821
+ let cached = cache.get(key);
822
+ if (cached?.[alg]) {
823
+ return cached[alg];
824
+ }
825
+ const cryptoKey = await jwkToKey({ ...jwk, alg });
826
+ if (freeze)
827
+ Object.freeze(key);
828
+ if (!cached) {
829
+ cache.set(key, { [alg]: cryptoKey });
830
+ } else {
831
+ cached[alg] = cryptoKey;
832
+ }
833
+ return cryptoKey;
834
+ };
835
+ var handleKeyObject = (keyObject, alg) => {
836
+ cache ||= /* @__PURE__ */ new WeakMap();
837
+ let cached = cache.get(keyObject);
838
+ if (cached?.[alg]) {
839
+ return cached[alg];
840
+ }
841
+ const isPublic = keyObject.type === "public";
842
+ const extractable = isPublic ? true : false;
843
+ let cryptoKey;
844
+ if (keyObject.asymmetricKeyType === "x25519") {
845
+ switch (alg) {
846
+ case "ECDH-ES":
847
+ case "ECDH-ES+A128KW":
848
+ case "ECDH-ES+A192KW":
849
+ case "ECDH-ES+A256KW":
850
+ break;
851
+ default:
852
+ throw new TypeError(unusableForAlg);
853
+ }
854
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
855
+ }
856
+ if (keyObject.asymmetricKeyType === "ed25519") {
857
+ if (alg !== "EdDSA" && alg !== "Ed25519") {
858
+ throw new TypeError(unusableForAlg);
859
+ }
860
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
861
+ isPublic ? "verify" : "sign"
862
+ ]);
863
+ }
864
+ switch (keyObject.asymmetricKeyType) {
865
+ case "ml-dsa-44":
866
+ case "ml-dsa-65":
867
+ case "ml-dsa-87": {
868
+ if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
869
+ throw new TypeError(unusableForAlg);
870
+ }
871
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
872
+ isPublic ? "verify" : "sign"
873
+ ]);
874
+ }
875
+ }
876
+ if (keyObject.asymmetricKeyType === "rsa") {
877
+ let hash;
878
+ switch (alg) {
879
+ case "RSA-OAEP":
880
+ hash = "SHA-1";
881
+ break;
882
+ case "RS256":
883
+ case "PS256":
884
+ case "RSA-OAEP-256":
885
+ hash = "SHA-256";
886
+ break;
887
+ case "RS384":
888
+ case "PS384":
889
+ case "RSA-OAEP-384":
890
+ hash = "SHA-384";
891
+ break;
892
+ case "RS512":
893
+ case "PS512":
894
+ case "RSA-OAEP-512":
895
+ hash = "SHA-512";
896
+ break;
897
+ default:
898
+ throw new TypeError(unusableForAlg);
899
+ }
900
+ if (alg.startsWith("RSA-OAEP")) {
901
+ return keyObject.toCryptoKey({
902
+ name: "RSA-OAEP",
903
+ hash
904
+ }, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
905
+ }
906
+ cryptoKey = keyObject.toCryptoKey({
907
+ name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
908
+ hash
909
+ }, extractable, [isPublic ? "verify" : "sign"]);
910
+ }
911
+ if (keyObject.asymmetricKeyType === "ec") {
912
+ const nist = /* @__PURE__ */ new Map([
913
+ ["prime256v1", "P-256"],
914
+ ["secp384r1", "P-384"],
915
+ ["secp521r1", "P-521"]
916
+ ]);
917
+ const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
918
+ if (!namedCurve) {
919
+ throw new TypeError(unusableForAlg);
920
+ }
921
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
922
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
923
+ cryptoKey = keyObject.toCryptoKey({
924
+ name: "ECDSA",
925
+ namedCurve
926
+ }, extractable, [isPublic ? "verify" : "sign"]);
927
+ }
928
+ if (alg.startsWith("ECDH-ES")) {
929
+ cryptoKey = keyObject.toCryptoKey({
930
+ name: "ECDH",
931
+ namedCurve
932
+ }, extractable, isPublic ? [] : ["deriveBits"]);
933
+ }
934
+ }
935
+ if (!cryptoKey) {
936
+ throw new TypeError(unusableForAlg);
937
+ }
938
+ if (!cached) {
939
+ cache.set(keyObject, { [alg]: cryptoKey });
940
+ } else {
941
+ cached[alg] = cryptoKey;
942
+ }
943
+ return cryptoKey;
944
+ };
945
+ async function normalizeKey(key, alg) {
946
+ if (key instanceof Uint8Array) {
947
+ return key;
948
+ }
949
+ if (isCryptoKey(key)) {
950
+ return key;
951
+ }
952
+ if (isKeyObject(key)) {
953
+ if (key.type === "secret") {
954
+ return key.export();
955
+ }
956
+ if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
957
+ try {
958
+ return handleKeyObject(key, alg);
959
+ } catch (err) {
960
+ if (err instanceof TypeError) {
961
+ throw err;
962
+ }
963
+ }
964
+ }
965
+ let jwk = key.export({ format: "jwk" });
966
+ return handleJWK(key, jwk, alg);
967
+ }
968
+ if (isJWK(key)) {
969
+ if (key.k) {
970
+ return decode(key.k);
971
+ }
972
+ return handleJWK(key, key, alg, true);
973
+ }
974
+ throw new Error("unreachable");
975
+ }
976
+
977
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/helpers.js
978
+ function assertNotSet(value, name) {
979
+ if (value) {
980
+ throw new TypeError(`${name} can only be called once`);
981
+ }
982
+ }
983
+ function decodeBase64url(value, label, ErrorClass) {
984
+ try {
985
+ return decode(value);
986
+ } catch {
987
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
988
+ }
989
+ }
990
+
991
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/flattened/sign.js
992
+ var FlattenedSign = class {
993
+ #payload;
994
+ #protectedHeader;
995
+ #unprotectedHeader;
996
+ constructor(payload) {
997
+ if (!(payload instanceof Uint8Array)) {
998
+ throw new TypeError("payload must be an instance of Uint8Array");
999
+ }
1000
+ this.#payload = payload;
1001
+ }
1002
+ setProtectedHeader(protectedHeader) {
1003
+ assertNotSet(this.#protectedHeader, "setProtectedHeader");
1004
+ this.#protectedHeader = protectedHeader;
1005
+ return this;
1006
+ }
1007
+ setUnprotectedHeader(unprotectedHeader) {
1008
+ assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
1009
+ this.#unprotectedHeader = unprotectedHeader;
1010
+ return this;
1011
+ }
1012
+ async sign(key, options) {
1013
+ if (!this.#protectedHeader && !this.#unprotectedHeader) {
1014
+ throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
1015
+ }
1016
+ if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
1017
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
1018
+ }
1019
+ const joseHeader = {
1020
+ ...this.#protectedHeader,
1021
+ ...this.#unprotectedHeader
1022
+ };
1023
+ const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
1024
+ let b64 = true;
1025
+ if (extensions.has("b64")) {
1026
+ b64 = this.#protectedHeader.b64;
1027
+ if (typeof b64 !== "boolean") {
1028
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
1029
+ }
1030
+ }
1031
+ const { alg } = joseHeader;
1032
+ if (typeof alg !== "string" || !alg) {
1033
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
1034
+ }
1035
+ checkKeyType(alg, key, "sign");
1036
+ let payloadS;
1037
+ let payloadB;
1038
+ if (b64) {
1039
+ payloadS = encode2(this.#payload);
1040
+ payloadB = encode(payloadS);
1041
+ } else {
1042
+ payloadB = this.#payload;
1043
+ payloadS = "";
1044
+ }
1045
+ let protectedHeaderString;
1046
+ let protectedHeaderBytes;
1047
+ if (this.#protectedHeader) {
1048
+ protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
1049
+ protectedHeaderBytes = encode(protectedHeaderString);
1050
+ } else {
1051
+ protectedHeaderString = "";
1052
+ protectedHeaderBytes = new Uint8Array();
1053
+ }
1054
+ const data = concat(protectedHeaderBytes, encode("."), payloadB);
1055
+ const k = await normalizeKey(key, alg);
1056
+ const signature = await sign(alg, k, data);
1057
+ const jws = {
1058
+ signature: encode2(signature),
1059
+ payload: payloadS
1060
+ };
1061
+ if (this.#unprotectedHeader) {
1062
+ jws.header = this.#unprotectedHeader;
1063
+ }
1064
+ if (this.#protectedHeader) {
1065
+ jws.protected = protectedHeaderString;
1066
+ }
1067
+ return jws;
1068
+ }
1069
+ };
1070
+
1071
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/compact/sign.js
1072
+ var CompactSign = class {
1073
+ #flattened;
1074
+ constructor(payload) {
1075
+ this.#flattened = new FlattenedSign(payload);
1076
+ }
1077
+ setProtectedHeader(protectedHeader) {
1078
+ this.#flattened.setProtectedHeader(protectedHeader);
1079
+ return this;
1080
+ }
1081
+ async sign(key, options) {
1082
+ const jws = await this.#flattened.sign(key, options);
1083
+ if (jws.payload === void 0) {
1084
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
1085
+ }
1086
+ return `${jws.protected}.${jws.payload}.${jws.signature}`;
1087
+ }
1088
+ };
1089
+
1090
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
1091
+ var epoch = (date) => Math.floor(date.getTime() / 1e3);
1092
+ var minute = 60;
1093
+ var hour = minute * 60;
1094
+ var day = hour * 24;
1095
+ var week = day * 7;
1096
+ var year = day * 365.25;
1097
+ 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;
1098
+ function secs(str) {
1099
+ const matched = REGEX.exec(str);
1100
+ if (!matched || matched[4] && matched[1]) {
1101
+ throw new TypeError("Invalid time period format");
1102
+ }
1103
+ const value = parseFloat(matched[2]);
1104
+ const unit = matched[3].toLowerCase();
1105
+ let numericDate;
1106
+ switch (unit) {
1107
+ case "sec":
1108
+ case "secs":
1109
+ case "second":
1110
+ case "seconds":
1111
+ case "s":
1112
+ numericDate = Math.round(value);
1113
+ break;
1114
+ case "minute":
1115
+ case "minutes":
1116
+ case "min":
1117
+ case "mins":
1118
+ case "m":
1119
+ numericDate = Math.round(value * minute);
1120
+ break;
1121
+ case "hour":
1122
+ case "hours":
1123
+ case "hr":
1124
+ case "hrs":
1125
+ case "h":
1126
+ numericDate = Math.round(value * hour);
1127
+ break;
1128
+ case "day":
1129
+ case "days":
1130
+ case "d":
1131
+ numericDate = Math.round(value * day);
1132
+ break;
1133
+ case "week":
1134
+ case "weeks":
1135
+ case "w":
1136
+ numericDate = Math.round(value * week);
1137
+ break;
1138
+ default:
1139
+ numericDate = Math.round(value * year);
1140
+ break;
1141
+ }
1142
+ if (matched[1] === "-" || matched[4] === "ago") {
1143
+ return -numericDate;
1144
+ }
1145
+ return numericDate;
1146
+ }
1147
+ function validateInput(label, input) {
1148
+ if (!Number.isFinite(input)) {
1149
+ throw new TypeError(`Invalid ${label} input`);
1150
+ }
1151
+ return input;
1152
+ }
1153
+ var normalizeTyp = (value) => {
1154
+ if (value.includes("/")) {
1155
+ return value.toLowerCase();
1156
+ }
1157
+ return `application/${value.toLowerCase()}`;
1158
+ };
1159
+ var checkAudiencePresence = (audPayload, audOption) => {
1160
+ if (typeof audPayload === "string") {
1161
+ return audOption.includes(audPayload);
1162
+ }
1163
+ if (Array.isArray(audPayload)) {
1164
+ return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
1165
+ }
1166
+ return false;
1167
+ };
1168
+ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
1169
+ let payload;
1170
+ try {
1171
+ payload = JSON.parse(decoder.decode(encodedPayload));
1172
+ } catch {
1173
+ }
1174
+ if (!isObject(payload)) {
1175
+ throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
1176
+ }
1177
+ const { typ } = options;
1178
+ if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
1179
+ throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
1180
+ }
1181
+ const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
1182
+ const presenceCheck = [...requiredClaims];
1183
+ if (maxTokenAge !== void 0)
1184
+ presenceCheck.push("iat");
1185
+ if (audience !== void 0)
1186
+ presenceCheck.push("aud");
1187
+ if (subject !== void 0)
1188
+ presenceCheck.push("sub");
1189
+ if (issuer !== void 0)
1190
+ presenceCheck.push("iss");
1191
+ for (const claim of new Set(presenceCheck.reverse())) {
1192
+ if (!(claim in payload)) {
1193
+ throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
1194
+ }
1195
+ }
1196
+ if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
1197
+ throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
1198
+ }
1199
+ if (subject && payload.sub !== subject) {
1200
+ throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
1201
+ }
1202
+ if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
1203
+ throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
1204
+ }
1205
+ let tolerance;
1206
+ switch (typeof options.clockTolerance) {
1207
+ case "string":
1208
+ tolerance = secs(options.clockTolerance);
1209
+ break;
1210
+ case "number":
1211
+ tolerance = options.clockTolerance;
1212
+ break;
1213
+ case "undefined":
1214
+ tolerance = 0;
1215
+ break;
1216
+ default:
1217
+ throw new TypeError("Invalid clockTolerance option type");
1218
+ }
1219
+ const { currentDate } = options;
1220
+ const now = epoch(currentDate || /* @__PURE__ */ new Date());
1221
+ if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
1222
+ throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
1223
+ }
1224
+ if (payload.nbf !== void 0) {
1225
+ if (typeof payload.nbf !== "number") {
1226
+ throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
1227
+ }
1228
+ if (payload.nbf > now + tolerance) {
1229
+ throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
1230
+ }
1231
+ }
1232
+ if (payload.exp !== void 0) {
1233
+ if (typeof payload.exp !== "number") {
1234
+ throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
1235
+ }
1236
+ if (payload.exp <= now - tolerance) {
1237
+ throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
1238
+ }
1239
+ }
1240
+ if (maxTokenAge) {
1241
+ const age = now - payload.iat;
1242
+ const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
1243
+ if (age - tolerance > max) {
1244
+ throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
1245
+ }
1246
+ if (age < 0 - tolerance) {
1247
+ throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
1248
+ }
1249
+ }
1250
+ return payload;
1251
+ }
1252
+ var JWTClaimsBuilder = class {
1253
+ #payload;
1254
+ constructor(payload) {
1255
+ if (!isObject(payload)) {
1256
+ throw new TypeError("JWT Claims Set MUST be an object");
1257
+ }
1258
+ this.#payload = structuredClone(payload);
1259
+ }
1260
+ data() {
1261
+ return encoder.encode(JSON.stringify(this.#payload));
1262
+ }
1263
+ get iss() {
1264
+ return this.#payload.iss;
1265
+ }
1266
+ set iss(value) {
1267
+ this.#payload.iss = value;
1268
+ }
1269
+ get sub() {
1270
+ return this.#payload.sub;
1271
+ }
1272
+ set sub(value) {
1273
+ this.#payload.sub = value;
1274
+ }
1275
+ get aud() {
1276
+ return this.#payload.aud;
1277
+ }
1278
+ set aud(value) {
1279
+ this.#payload.aud = value;
1280
+ }
1281
+ set jti(value) {
1282
+ this.#payload.jti = value;
1283
+ }
1284
+ set nbf(value) {
1285
+ if (typeof value === "number") {
1286
+ this.#payload.nbf = validateInput("setNotBefore", value);
1287
+ } else if (value instanceof Date) {
1288
+ this.#payload.nbf = validateInput("setNotBefore", epoch(value));
1289
+ } else {
1290
+ this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
1291
+ }
1292
+ }
1293
+ set exp(value) {
1294
+ if (typeof value === "number") {
1295
+ this.#payload.exp = validateInput("setExpirationTime", value);
1296
+ } else if (value instanceof Date) {
1297
+ this.#payload.exp = validateInput("setExpirationTime", epoch(value));
1298
+ } else {
1299
+ this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
1300
+ }
1301
+ }
1302
+ set iat(value) {
1303
+ if (value === void 0) {
1304
+ this.#payload.iat = epoch(/* @__PURE__ */ new Date());
1305
+ } else if (value instanceof Date) {
1306
+ this.#payload.iat = validateInput("setIssuedAt", epoch(value));
1307
+ } else if (typeof value === "string") {
1308
+ this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
1309
+ } else {
1310
+ this.#payload.iat = validateInput("setIssuedAt", value);
1311
+ }
1312
+ }
1313
+ };
1314
+
1315
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/sign.js
1316
+ var SignJWT = class {
1317
+ #protectedHeader;
1318
+ #jwt;
1319
+ constructor(payload = {}) {
1320
+ this.#jwt = new JWTClaimsBuilder(payload);
1321
+ }
1322
+ setIssuer(issuer) {
1323
+ this.#jwt.iss = issuer;
1324
+ return this;
1325
+ }
1326
+ setSubject(subject) {
1327
+ this.#jwt.sub = subject;
1328
+ return this;
1329
+ }
1330
+ setAudience(audience) {
1331
+ this.#jwt.aud = audience;
1332
+ return this;
1333
+ }
1334
+ setJti(jwtId) {
1335
+ this.#jwt.jti = jwtId;
1336
+ return this;
1337
+ }
1338
+ setNotBefore(input) {
1339
+ this.#jwt.nbf = input;
1340
+ return this;
1341
+ }
1342
+ setExpirationTime(input) {
1343
+ this.#jwt.exp = input;
1344
+ return this;
1345
+ }
1346
+ setIssuedAt(input) {
1347
+ this.#jwt.iat = input;
1348
+ return this;
1349
+ }
1350
+ setProtectedHeader(protectedHeader) {
1351
+ this.#protectedHeader = protectedHeader;
1352
+ return this;
1353
+ }
1354
+ async sign(key, options) {
1355
+ const sig = new CompactSign(this.#jwt.data());
1356
+ sig.setProtectedHeader(this.#protectedHeader);
1357
+ if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
1358
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
1359
+ }
1360
+ return sig.sign(key, options);
1361
+ }
1362
+ };
1363
+
1364
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/generate_key_pair.js
1365
+ function getModulusLengthOption(options) {
1366
+ const modulusLength = options?.modulusLength ?? 2048;
1367
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
1368
+ throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
1369
+ }
1370
+ return modulusLength;
1371
+ }
1372
+ async function generateKeyPair(alg, options) {
1373
+ let algorithm;
1374
+ let keyUsages;
1375
+ switch (alg) {
1376
+ case "PS256":
1377
+ case "PS384":
1378
+ case "PS512":
1379
+ algorithm = {
1380
+ name: "RSA-PSS",
1381
+ hash: `SHA-${alg.slice(-3)}`,
1382
+ publicExponent: Uint8Array.of(1, 0, 1),
1383
+ modulusLength: getModulusLengthOption(options)
1384
+ };
1385
+ keyUsages = ["sign", "verify"];
1386
+ break;
1387
+ case "RS256":
1388
+ case "RS384":
1389
+ case "RS512":
1390
+ algorithm = {
1391
+ name: "RSASSA-PKCS1-v1_5",
1392
+ hash: `SHA-${alg.slice(-3)}`,
1393
+ publicExponent: Uint8Array.of(1, 0, 1),
1394
+ modulusLength: getModulusLengthOption(options)
1395
+ };
1396
+ keyUsages = ["sign", "verify"];
1397
+ break;
1398
+ case "RSA-OAEP":
1399
+ case "RSA-OAEP-256":
1400
+ case "RSA-OAEP-384":
1401
+ case "RSA-OAEP-512":
1402
+ algorithm = {
1403
+ name: "RSA-OAEP",
1404
+ hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
1405
+ publicExponent: Uint8Array.of(1, 0, 1),
1406
+ modulusLength: getModulusLengthOption(options)
1407
+ };
1408
+ keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
1409
+ break;
1410
+ case "ES256":
1411
+ algorithm = { name: "ECDSA", namedCurve: "P-256" };
1412
+ keyUsages = ["sign", "verify"];
1413
+ break;
1414
+ case "ES384":
1415
+ algorithm = { name: "ECDSA", namedCurve: "P-384" };
1416
+ keyUsages = ["sign", "verify"];
1417
+ break;
1418
+ case "ES512":
1419
+ algorithm = { name: "ECDSA", namedCurve: "P-521" };
1420
+ keyUsages = ["sign", "verify"];
1421
+ break;
1422
+ case "Ed25519":
1423
+ case "EdDSA": {
1424
+ keyUsages = ["sign", "verify"];
1425
+ algorithm = { name: "Ed25519" };
1426
+ break;
1427
+ }
1428
+ case "ML-DSA-44":
1429
+ case "ML-DSA-65":
1430
+ case "ML-DSA-87": {
1431
+ keyUsages = ["sign", "verify"];
1432
+ algorithm = { name: alg };
1433
+ break;
1434
+ }
1435
+ case "ECDH-ES":
1436
+ case "ECDH-ES+A128KW":
1437
+ case "ECDH-ES+A192KW":
1438
+ case "ECDH-ES+A256KW": {
1439
+ keyUsages = ["deriveBits"];
1440
+ const crv = options?.crv ?? "P-256";
1441
+ switch (crv) {
1442
+ case "P-256":
1443
+ case "P-384":
1444
+ case "P-521": {
1445
+ algorithm = { name: "ECDH", namedCurve: crv };
1446
+ break;
1447
+ }
1448
+ case "X25519":
1449
+ algorithm = { name: "X25519" };
1450
+ break;
1451
+ default:
1452
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
1453
+ }
1454
+ break;
1455
+ }
1456
+ default:
1457
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
1458
+ }
1459
+ return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
1460
+ }
1461
+
1462
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/import.js
1463
+ async function importPKCS8(pkcs8, alg, options) {
1464
+ if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
1465
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
1466
+ }
1467
+ return fromPKCS8(pkcs8, alg, options);
1468
+ }
1469
+
1470
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_algorithms.js
1471
+ function validateAlgorithms(option, algorithms) {
1472
+ if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1473
+ throw new TypeError(`"${option}" option must be an array of strings`);
1474
+ }
1475
+ if (!algorithms) {
1476
+ return void 0;
1477
+ }
1478
+ return new Set(algorithms);
1479
+ }
1480
+
1481
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/flattened/verify.js
1482
+ async function flattenedVerify(jws, key, options) {
1483
+ if (!isObject(jws)) {
1484
+ throw new JWSInvalid("Flattened JWS must be an object");
1485
+ }
1486
+ if (jws.protected === void 0 && jws.header === void 0) {
1487
+ throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
1488
+ }
1489
+ if (jws.protected !== void 0 && typeof jws.protected !== "string") {
1490
+ throw new JWSInvalid("JWS Protected Header incorrect type");
1491
+ }
1492
+ if (jws.payload === void 0) {
1493
+ throw new JWSInvalid("JWS Payload missing");
1494
+ }
1495
+ if (typeof jws.signature !== "string") {
1496
+ throw new JWSInvalid("JWS Signature missing or incorrect type");
1497
+ }
1498
+ if (jws.header !== void 0 && !isObject(jws.header)) {
1499
+ throw new JWSInvalid("JWS Unprotected Header incorrect type");
1500
+ }
1501
+ let parsedProt = {};
1502
+ if (jws.protected) {
1503
+ try {
1504
+ const protectedHeader = decode(jws.protected);
1505
+ parsedProt = JSON.parse(decoder.decode(protectedHeader));
1506
+ } catch {
1507
+ throw new JWSInvalid("JWS Protected Header is invalid");
1508
+ }
1509
+ }
1510
+ if (!isDisjoint(parsedProt, jws.header)) {
1511
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
1512
+ }
1513
+ const joseHeader = {
1514
+ ...parsedProt,
1515
+ ...jws.header
1516
+ };
1517
+ const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
1518
+ let b64 = true;
1519
+ if (extensions.has("b64")) {
1520
+ b64 = parsedProt.b64;
1521
+ if (typeof b64 !== "boolean") {
1522
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
1523
+ }
1524
+ }
1525
+ const { alg } = joseHeader;
1526
+ if (typeof alg !== "string" || !alg) {
1527
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
1528
+ }
1529
+ const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
1530
+ if (algorithms && !algorithms.has(alg)) {
1531
+ throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
1532
+ }
1533
+ if (b64) {
1534
+ if (typeof jws.payload !== "string") {
1535
+ throw new JWSInvalid("JWS Payload must be a string");
1536
+ }
1537
+ } else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
1538
+ throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
1539
+ }
1540
+ let resolvedKey = false;
1541
+ if (typeof key === "function") {
1542
+ key = await key(parsedProt, jws);
1543
+ resolvedKey = true;
1544
+ }
1545
+ checkKeyType(alg, key, "verify");
1546
+ const data = concat(jws.protected !== void 0 ? encode(jws.protected) : new Uint8Array(), encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
1547
+ const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
1548
+ const k = await normalizeKey(key, alg);
1549
+ const verified = await verify(alg, k, signature, data);
1550
+ if (!verified) {
1551
+ throw new JWSSignatureVerificationFailed();
1552
+ }
1553
+ let payload;
1554
+ if (b64) {
1555
+ payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
1556
+ } else if (typeof jws.payload === "string") {
1557
+ payload = encoder.encode(jws.payload);
1558
+ } else {
1559
+ payload = jws.payload;
1560
+ }
1561
+ const result = { payload };
1562
+ if (jws.protected !== void 0) {
1563
+ result.protectedHeader = parsedProt;
1564
+ }
1565
+ if (jws.header !== void 0) {
1566
+ result.unprotectedHeader = jws.header;
1567
+ }
1568
+ if (resolvedKey) {
1569
+ return { ...result, key: k };
1570
+ }
1571
+ return result;
1572
+ }
1573
+
1574
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/compact/verify.js
1575
+ async function compactVerify(jws, key, options) {
1576
+ if (jws instanceof Uint8Array) {
1577
+ jws = decoder.decode(jws);
1578
+ }
1579
+ if (typeof jws !== "string") {
1580
+ throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
1581
+ }
1582
+ const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
1583
+ if (length !== 3) {
1584
+ throw new JWSInvalid("Invalid Compact JWS");
1585
+ }
1586
+ const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
1587
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
1588
+ if (typeof key === "function") {
1589
+ return { ...result, key: verified.key };
1590
+ }
1591
+ return result;
1592
+ }
1593
+
1594
+ // ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/verify.js
1595
+ async function jwtVerify(jwt, key, options) {
1596
+ const verified = await compactVerify(jwt, key, options);
1597
+ if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
1598
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
1599
+ }
1600
+ const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
1601
+ const result = { payload, protectedHeader: verified.protectedHeader };
1602
+ if (typeof key === "function") {
1603
+ return { ...result, key: verified.key };
1604
+ }
1605
+ return result;
1606
+ }
1607
+
1608
+ export {
1609
+ importPKCS8,
1610
+ exportJWK,
1611
+ jwtVerify,
1612
+ SignJWT,
1613
+ generateKeyPair
1614
+ };
1615
+ //# sourceMappingURL=chunk-D6EKRYGP.js.map