@solvapay/server 1.0.0-preview.1

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,3475 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-R5U7XKVJ.js";
4
+
5
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.js
6
+ import { Buffer as Buffer2 } from "buffer";
7
+
8
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/digest.js
9
+ import { createHash } from "crypto";
10
+ var digest = (algorithm, data) => createHash(algorithm).update(data).digest();
11
+ var digest_default = digest;
12
+
13
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.js
14
+ var encoder = new TextEncoder();
15
+ var decoder = new TextDecoder();
16
+ var MAX_INT32 = 2 ** 32;
17
+ function concat(...buffers) {
18
+ const size = buffers.reduce((acc, { length }) => acc + length, 0);
19
+ const buf = new Uint8Array(size);
20
+ let i = 0;
21
+ for (const buffer of buffers) {
22
+ buf.set(buffer, i);
23
+ i += buffer.length;
24
+ }
25
+ return buf;
26
+ }
27
+ function p2s(alg, p2sInput) {
28
+ return concat(encoder.encode(alg), new Uint8Array([0]), p2sInput);
29
+ }
30
+ function writeUInt32BE(buf, value, offset) {
31
+ if (value < 0 || value >= MAX_INT32) {
32
+ throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
33
+ }
34
+ buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
35
+ }
36
+ function uint64be(value) {
37
+ const high = Math.floor(value / MAX_INT32);
38
+ const low = value % MAX_INT32;
39
+ const buf = new Uint8Array(8);
40
+ writeUInt32BE(buf, high, 0);
41
+ writeUInt32BE(buf, low, 4);
42
+ return buf;
43
+ }
44
+ function uint32be(value) {
45
+ const buf = new Uint8Array(4);
46
+ writeUInt32BE(buf, value);
47
+ return buf;
48
+ }
49
+ function lengthAndInput(input) {
50
+ return concat(uint32be(input.length), input);
51
+ }
52
+ async function concatKdf(secret, bits, value) {
53
+ const iterations = Math.ceil((bits >> 3) / 32);
54
+ const res = new Uint8Array(iterations * 32);
55
+ for (let iter = 0; iter < iterations; iter++) {
56
+ const buf = new Uint8Array(4 + secret.length + value.length);
57
+ buf.set(uint32be(iter + 1));
58
+ buf.set(secret, 4);
59
+ buf.set(value, 4 + secret.length);
60
+ res.set(await digest_default("sha256", buf), iter * 32);
61
+ }
62
+ return res.slice(0, bits >> 3);
63
+ }
64
+
65
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.js
66
+ function normalize(input) {
67
+ let encoded = input;
68
+ if (encoded instanceof Uint8Array) {
69
+ encoded = decoder.decode(encoded);
70
+ }
71
+ return encoded;
72
+ }
73
+ var encode = (input) => Buffer2.from(input).toString("base64url");
74
+ var decode = (input) => new Uint8Array(Buffer2.from(normalize(input), "base64url"));
75
+
76
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/decrypt.js
77
+ import { createDecipheriv, KeyObject } from "crypto";
78
+
79
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.js
80
+ var errors_exports = {};
81
+ __export(errors_exports, {
82
+ JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
83
+ JOSEError: () => JOSEError,
84
+ JOSENotSupported: () => JOSENotSupported,
85
+ JWEDecryptionFailed: () => JWEDecryptionFailed,
86
+ JWEInvalid: () => JWEInvalid,
87
+ JWKInvalid: () => JWKInvalid,
88
+ JWKSInvalid: () => JWKSInvalid,
89
+ JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
90
+ JWKSNoMatchingKey: () => JWKSNoMatchingKey,
91
+ JWKSTimeout: () => JWKSTimeout,
92
+ JWSInvalid: () => JWSInvalid,
93
+ JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
94
+ JWTClaimValidationFailed: () => JWTClaimValidationFailed,
95
+ JWTExpired: () => JWTExpired,
96
+ JWTInvalid: () => JWTInvalid
97
+ });
98
+ var JOSEError = class extends Error {
99
+ static code = "ERR_JOSE_GENERIC";
100
+ code = "ERR_JOSE_GENERIC";
101
+ constructor(message2, options) {
102
+ super(message2, options);
103
+ this.name = this.constructor.name;
104
+ Error.captureStackTrace?.(this, this.constructor);
105
+ }
106
+ };
107
+ var JWTClaimValidationFailed = class extends JOSEError {
108
+ static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
109
+ code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
110
+ claim;
111
+ reason;
112
+ payload;
113
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
114
+ super(message2, { cause: { claim, reason, payload } });
115
+ this.claim = claim;
116
+ this.reason = reason;
117
+ this.payload = payload;
118
+ }
119
+ };
120
+ var JWTExpired = class extends JOSEError {
121
+ static code = "ERR_JWT_EXPIRED";
122
+ code = "ERR_JWT_EXPIRED";
123
+ claim;
124
+ reason;
125
+ payload;
126
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
127
+ super(message2, { cause: { claim, reason, payload } });
128
+ this.claim = claim;
129
+ this.reason = reason;
130
+ this.payload = payload;
131
+ }
132
+ };
133
+ var JOSEAlgNotAllowed = class extends JOSEError {
134
+ static code = "ERR_JOSE_ALG_NOT_ALLOWED";
135
+ code = "ERR_JOSE_ALG_NOT_ALLOWED";
136
+ };
137
+ var JOSENotSupported = class extends JOSEError {
138
+ static code = "ERR_JOSE_NOT_SUPPORTED";
139
+ code = "ERR_JOSE_NOT_SUPPORTED";
140
+ };
141
+ var JWEDecryptionFailed = class extends JOSEError {
142
+ static code = "ERR_JWE_DECRYPTION_FAILED";
143
+ code = "ERR_JWE_DECRYPTION_FAILED";
144
+ constructor(message2 = "decryption operation failed", options) {
145
+ super(message2, options);
146
+ }
147
+ };
148
+ var JWEInvalid = class extends JOSEError {
149
+ static code = "ERR_JWE_INVALID";
150
+ code = "ERR_JWE_INVALID";
151
+ };
152
+ var JWSInvalid = class extends JOSEError {
153
+ static code = "ERR_JWS_INVALID";
154
+ code = "ERR_JWS_INVALID";
155
+ };
156
+ var JWTInvalid = class extends JOSEError {
157
+ static code = "ERR_JWT_INVALID";
158
+ code = "ERR_JWT_INVALID";
159
+ };
160
+ var JWKInvalid = class extends JOSEError {
161
+ static code = "ERR_JWK_INVALID";
162
+ code = "ERR_JWK_INVALID";
163
+ };
164
+ var JWKSInvalid = class extends JOSEError {
165
+ static code = "ERR_JWKS_INVALID";
166
+ code = "ERR_JWKS_INVALID";
167
+ };
168
+ var JWKSNoMatchingKey = class extends JOSEError {
169
+ static code = "ERR_JWKS_NO_MATCHING_KEY";
170
+ code = "ERR_JWKS_NO_MATCHING_KEY";
171
+ constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
172
+ super(message2, options);
173
+ }
174
+ };
175
+ var JWKSMultipleMatchingKeys = class extends JOSEError {
176
+ [Symbol.asyncIterator];
177
+ static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
178
+ code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
179
+ constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
180
+ super(message2, options);
181
+ }
182
+ };
183
+ var JWKSTimeout = class extends JOSEError {
184
+ static code = "ERR_JWKS_TIMEOUT";
185
+ code = "ERR_JWKS_TIMEOUT";
186
+ constructor(message2 = "request timed out", options) {
187
+ super(message2, options);
188
+ }
189
+ };
190
+ var JWSSignatureVerificationFailed = class extends JOSEError {
191
+ static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
192
+ code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
193
+ constructor(message2 = "signature verification failed", options) {
194
+ super(message2, options);
195
+ }
196
+ };
197
+
198
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/random.js
199
+ import { randomFillSync } from "crypto";
200
+
201
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/iv.js
202
+ function bitLength(alg) {
203
+ switch (alg) {
204
+ case "A128GCM":
205
+ case "A128GCMKW":
206
+ case "A192GCM":
207
+ case "A192GCMKW":
208
+ case "A256GCM":
209
+ case "A256GCMKW":
210
+ return 96;
211
+ case "A128CBC-HS256":
212
+ case "A192CBC-HS384":
213
+ case "A256CBC-HS512":
214
+ return 128;
215
+ default:
216
+ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
217
+ }
218
+ }
219
+ var iv_default = (alg) => randomFillSync(new Uint8Array(bitLength(alg) >> 3));
220
+
221
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_iv_length.js
222
+ var checkIvLength = (enc, iv) => {
223
+ if (iv.length << 3 !== bitLength(enc)) {
224
+ throw new JWEInvalid("Invalid Initialization Vector length");
225
+ }
226
+ };
227
+ var check_iv_length_default = checkIvLength;
228
+
229
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js
230
+ import * as util from "util";
231
+ var is_key_object_default = (obj) => util.types.isKeyObject(obj);
232
+
233
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_cek_length.js
234
+ var checkCekLength = (enc, cek) => {
235
+ let expected;
236
+ switch (enc) {
237
+ case "A128CBC-HS256":
238
+ case "A192CBC-HS384":
239
+ case "A256CBC-HS512":
240
+ expected = parseInt(enc.slice(-3), 10);
241
+ break;
242
+ case "A128GCM":
243
+ case "A192GCM":
244
+ case "A256GCM":
245
+ expected = parseInt(enc.slice(1, 4), 10);
246
+ break;
247
+ default:
248
+ throw new JOSENotSupported(`Content Encryption Algorithm ${enc} is not supported either by JOSE or your javascript runtime`);
249
+ }
250
+ if (cek instanceof Uint8Array) {
251
+ const actual = cek.byteLength << 3;
252
+ if (actual !== expected) {
253
+ throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
254
+ }
255
+ return;
256
+ }
257
+ if (is_key_object_default(cek) && cek.type === "secret") {
258
+ const actual = cek.symmetricKeySize << 3;
259
+ if (actual !== expected) {
260
+ throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
261
+ }
262
+ return;
263
+ }
264
+ throw new TypeError("Invalid Content Encryption Key type");
265
+ };
266
+ var check_cek_length_default = checkCekLength;
267
+
268
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/timing_safe_equal.js
269
+ import { timingSafeEqual as impl } from "crypto";
270
+ var timingSafeEqual = impl;
271
+ var timing_safe_equal_default = timingSafeEqual;
272
+
273
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/cbc_tag.js
274
+ import { createHmac } from "crypto";
275
+ function cbcTag(aad, iv, ciphertext, macSize, macKey, keySize) {
276
+ const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
277
+ const hmac = createHmac(`sha${macSize}`, macKey);
278
+ hmac.update(macData);
279
+ return hmac.digest().slice(0, keySize >> 3);
280
+ }
281
+
282
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.js
283
+ import * as crypto from "crypto";
284
+ import * as util2 from "util";
285
+ var webcrypto2 = crypto.webcrypto;
286
+ var webcrypto_default = webcrypto2;
287
+ var isCryptoKey = (key) => util2.types.isCryptoKey(key);
288
+
289
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.js
290
+ function unusable(name, prop = "algorithm.name") {
291
+ return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
292
+ }
293
+ function isAlgorithm(algorithm, name) {
294
+ return algorithm.name === name;
295
+ }
296
+ function getHashLength(hash) {
297
+ return parseInt(hash.name.slice(4), 10);
298
+ }
299
+ function getNamedCurve(alg) {
300
+ switch (alg) {
301
+ case "ES256":
302
+ return "P-256";
303
+ case "ES384":
304
+ return "P-384";
305
+ case "ES512":
306
+ return "P-521";
307
+ default:
308
+ throw new Error("unreachable");
309
+ }
310
+ }
311
+ function checkUsage(key, usages) {
312
+ if (usages.length && !usages.some((expected) => key.usages.includes(expected))) {
313
+ let msg = "CryptoKey does not support this operation, its usages must include ";
314
+ if (usages.length > 2) {
315
+ const last = usages.pop();
316
+ msg += `one of ${usages.join(", ")}, or ${last}.`;
317
+ } else if (usages.length === 2) {
318
+ msg += `one of ${usages[0]} or ${usages[1]}.`;
319
+ } else {
320
+ msg += `${usages[0]}.`;
321
+ }
322
+ throw new TypeError(msg);
323
+ }
324
+ }
325
+ function checkSigCryptoKey(key, alg, ...usages) {
326
+ switch (alg) {
327
+ case "HS256":
328
+ case "HS384":
329
+ case "HS512": {
330
+ if (!isAlgorithm(key.algorithm, "HMAC"))
331
+ throw unusable("HMAC");
332
+ const expected = parseInt(alg.slice(2), 10);
333
+ const actual = getHashLength(key.algorithm.hash);
334
+ if (actual !== expected)
335
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
336
+ break;
337
+ }
338
+ case "RS256":
339
+ case "RS384":
340
+ case "RS512": {
341
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
342
+ throw unusable("RSASSA-PKCS1-v1_5");
343
+ const expected = parseInt(alg.slice(2), 10);
344
+ const actual = getHashLength(key.algorithm.hash);
345
+ if (actual !== expected)
346
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
347
+ break;
348
+ }
349
+ case "PS256":
350
+ case "PS384":
351
+ case "PS512": {
352
+ if (!isAlgorithm(key.algorithm, "RSA-PSS"))
353
+ throw unusable("RSA-PSS");
354
+ const expected = parseInt(alg.slice(2), 10);
355
+ const actual = getHashLength(key.algorithm.hash);
356
+ if (actual !== expected)
357
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
358
+ break;
359
+ }
360
+ case "EdDSA": {
361
+ if (key.algorithm.name !== "Ed25519" && key.algorithm.name !== "Ed448") {
362
+ throw unusable("Ed25519 or Ed448");
363
+ }
364
+ break;
365
+ }
366
+ case "Ed25519": {
367
+ if (!isAlgorithm(key.algorithm, "Ed25519"))
368
+ throw unusable("Ed25519");
369
+ break;
370
+ }
371
+ case "ES256":
372
+ case "ES384":
373
+ case "ES512": {
374
+ if (!isAlgorithm(key.algorithm, "ECDSA"))
375
+ throw unusable("ECDSA");
376
+ const expected = getNamedCurve(alg);
377
+ const actual = key.algorithm.namedCurve;
378
+ if (actual !== expected)
379
+ throw unusable(expected, "algorithm.namedCurve");
380
+ break;
381
+ }
382
+ default:
383
+ throw new TypeError("CryptoKey does not support this operation");
384
+ }
385
+ checkUsage(key, usages);
386
+ }
387
+ function checkEncCryptoKey(key, alg, ...usages) {
388
+ switch (alg) {
389
+ case "A128GCM":
390
+ case "A192GCM":
391
+ case "A256GCM": {
392
+ if (!isAlgorithm(key.algorithm, "AES-GCM"))
393
+ throw unusable("AES-GCM");
394
+ const expected = parseInt(alg.slice(1, 4), 10);
395
+ const actual = key.algorithm.length;
396
+ if (actual !== expected)
397
+ throw unusable(expected, "algorithm.length");
398
+ break;
399
+ }
400
+ case "A128KW":
401
+ case "A192KW":
402
+ case "A256KW": {
403
+ if (!isAlgorithm(key.algorithm, "AES-KW"))
404
+ throw unusable("AES-KW");
405
+ const expected = parseInt(alg.slice(1, 4), 10);
406
+ const actual = key.algorithm.length;
407
+ if (actual !== expected)
408
+ throw unusable(expected, "algorithm.length");
409
+ break;
410
+ }
411
+ case "ECDH": {
412
+ switch (key.algorithm.name) {
413
+ case "ECDH":
414
+ case "X25519":
415
+ case "X448":
416
+ break;
417
+ default:
418
+ throw unusable("ECDH, X25519, or X448");
419
+ }
420
+ break;
421
+ }
422
+ case "PBES2-HS256+A128KW":
423
+ case "PBES2-HS384+A192KW":
424
+ case "PBES2-HS512+A256KW":
425
+ if (!isAlgorithm(key.algorithm, "PBKDF2"))
426
+ throw unusable("PBKDF2");
427
+ break;
428
+ case "RSA-OAEP":
429
+ case "RSA-OAEP-256":
430
+ case "RSA-OAEP-384":
431
+ case "RSA-OAEP-512": {
432
+ if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
433
+ throw unusable("RSA-OAEP");
434
+ const expected = parseInt(alg.slice(9), 10) || 1;
435
+ const actual = getHashLength(key.algorithm.hash);
436
+ if (actual !== expected)
437
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
438
+ break;
439
+ }
440
+ default:
441
+ throw new TypeError("CryptoKey does not support this operation");
442
+ }
443
+ checkUsage(key, usages);
444
+ }
445
+
446
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.js
447
+ function message(msg, actual, ...types4) {
448
+ types4 = types4.filter(Boolean);
449
+ if (types4.length > 2) {
450
+ const last = types4.pop();
451
+ msg += `one of type ${types4.join(", ")}, or ${last}.`;
452
+ } else if (types4.length === 2) {
453
+ msg += `one of type ${types4[0]} or ${types4[1]}.`;
454
+ } else {
455
+ msg += `of type ${types4[0]}.`;
456
+ }
457
+ if (actual == null) {
458
+ msg += ` Received ${actual}`;
459
+ } else if (typeof actual === "function" && actual.name) {
460
+ msg += ` Received function ${actual.name}`;
461
+ } else if (typeof actual === "object" && actual != null) {
462
+ if (actual.constructor?.name) {
463
+ msg += ` Received an instance of ${actual.constructor.name}`;
464
+ }
465
+ }
466
+ return msg;
467
+ }
468
+ var invalid_key_input_default = (actual, ...types4) => {
469
+ return message("Key must be ", actual, ...types4);
470
+ };
471
+ function withAlg(alg, actual, ...types4) {
472
+ return message(`Key for the ${alg} algorithm must be `, actual, ...types4);
473
+ }
474
+
475
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/ciphers.js
476
+ import { getCiphers } from "crypto";
477
+ var ciphers;
478
+ var ciphers_default = (algorithm) => {
479
+ ciphers ||= new Set(getCiphers());
480
+ return ciphers.has(algorithm);
481
+ };
482
+
483
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js
484
+ var is_key_like_default = (key) => is_key_object_default(key) || isCryptoKey(key);
485
+ var types3 = ["KeyObject"];
486
+ if (globalThis.CryptoKey || webcrypto_default?.CryptoKey) {
487
+ types3.push("CryptoKey");
488
+ }
489
+
490
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/decrypt.js
491
+ function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
492
+ const keySize = parseInt(enc.slice(1, 4), 10);
493
+ if (is_key_object_default(cek)) {
494
+ cek = cek.export();
495
+ }
496
+ const encKey = cek.subarray(keySize >> 3);
497
+ const macKey = cek.subarray(0, keySize >> 3);
498
+ const macSize = parseInt(enc.slice(-3), 10);
499
+ const algorithm = `aes-${keySize}-cbc`;
500
+ if (!ciphers_default(algorithm)) {
501
+ throw new JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
502
+ }
503
+ const expectedTag = cbcTag(aad, iv, ciphertext, macSize, macKey, keySize);
504
+ let macCheckPassed;
505
+ try {
506
+ macCheckPassed = timing_safe_equal_default(tag2, expectedTag);
507
+ } catch {
508
+ }
509
+ if (!macCheckPassed) {
510
+ throw new JWEDecryptionFailed();
511
+ }
512
+ let plaintext;
513
+ try {
514
+ const decipher = createDecipheriv(algorithm, encKey, iv);
515
+ plaintext = concat(decipher.update(ciphertext), decipher.final());
516
+ } catch {
517
+ }
518
+ if (!plaintext) {
519
+ throw new JWEDecryptionFailed();
520
+ }
521
+ return plaintext;
522
+ }
523
+ function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
524
+ const keySize = parseInt(enc.slice(1, 4), 10);
525
+ const algorithm = `aes-${keySize}-gcm`;
526
+ if (!ciphers_default(algorithm)) {
527
+ throw new JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
528
+ }
529
+ try {
530
+ const decipher = createDecipheriv(algorithm, cek, iv, { authTagLength: 16 });
531
+ decipher.setAuthTag(tag2);
532
+ if (aad.byteLength) {
533
+ decipher.setAAD(aad, { plaintextLength: ciphertext.length });
534
+ }
535
+ const plaintext = decipher.update(ciphertext);
536
+ decipher.final();
537
+ return plaintext;
538
+ } catch {
539
+ throw new JWEDecryptionFailed();
540
+ }
541
+ }
542
+ var decrypt = (enc, cek, ciphertext, iv, tag2, aad) => {
543
+ let key;
544
+ if (isCryptoKey(cek)) {
545
+ checkEncCryptoKey(cek, enc, "decrypt");
546
+ key = KeyObject.from(cek);
547
+ } else if (cek instanceof Uint8Array || is_key_object_default(cek)) {
548
+ key = cek;
549
+ } else {
550
+ throw new TypeError(invalid_key_input_default(cek, ...types3, "Uint8Array"));
551
+ }
552
+ if (!iv) {
553
+ throw new JWEInvalid("JWE Initialization Vector missing");
554
+ }
555
+ if (!tag2) {
556
+ throw new JWEInvalid("JWE Authentication Tag missing");
557
+ }
558
+ check_cek_length_default(enc, key);
559
+ check_iv_length_default(enc, iv);
560
+ switch (enc) {
561
+ case "A128CBC-HS256":
562
+ case "A192CBC-HS384":
563
+ case "A256CBC-HS512":
564
+ return cbcDecrypt(enc, key, ciphertext, iv, tag2, aad);
565
+ case "A128GCM":
566
+ case "A192GCM":
567
+ case "A256GCM":
568
+ return gcmDecrypt(enc, key, ciphertext, iv, tag2, aad);
569
+ default:
570
+ throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
571
+ }
572
+ };
573
+ var decrypt_default = decrypt;
574
+
575
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js
576
+ var isDisjoint = (...headers) => {
577
+ const sources = headers.filter(Boolean);
578
+ if (sources.length === 0 || sources.length === 1) {
579
+ return true;
580
+ }
581
+ let acc;
582
+ for (const header of sources) {
583
+ const parameters = Object.keys(header);
584
+ if (!acc || acc.size === 0) {
585
+ acc = new Set(parameters);
586
+ continue;
587
+ }
588
+ for (const parameter of parameters) {
589
+ if (acc.has(parameter)) {
590
+ return false;
591
+ }
592
+ acc.add(parameter);
593
+ }
594
+ }
595
+ return true;
596
+ };
597
+ var is_disjoint_default = isDisjoint;
598
+
599
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js
600
+ function isObjectLike(value) {
601
+ return typeof value === "object" && value !== null;
602
+ }
603
+ function isObject(input) {
604
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
605
+ return false;
606
+ }
607
+ if (Object.getPrototypeOf(input) === null) {
608
+ return true;
609
+ }
610
+ let proto = input;
611
+ while (Object.getPrototypeOf(proto) !== null) {
612
+ proto = Object.getPrototypeOf(proto);
613
+ }
614
+ return Object.getPrototypeOf(input) === proto;
615
+ }
616
+
617
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/aeskw.js
618
+ import { Buffer as Buffer3 } from "buffer";
619
+ import { KeyObject as KeyObject2, createDecipheriv as createDecipheriv2, createCipheriv, createSecretKey } from "crypto";
620
+ function checkKeySize(key, alg) {
621
+ if (key.symmetricKeySize << 3 !== parseInt(alg.slice(1, 4), 10)) {
622
+ throw new TypeError(`Invalid key size for alg: ${alg}`);
623
+ }
624
+ }
625
+ function ensureKeyObject(key, alg, usage) {
626
+ if (is_key_object_default(key)) {
627
+ return key;
628
+ }
629
+ if (key instanceof Uint8Array) {
630
+ return createSecretKey(key);
631
+ }
632
+ if (isCryptoKey(key)) {
633
+ checkEncCryptoKey(key, alg, usage);
634
+ return KeyObject2.from(key);
635
+ }
636
+ throw new TypeError(invalid_key_input_default(key, ...types3, "Uint8Array"));
637
+ }
638
+ var wrap = (alg, key, cek) => {
639
+ const size = parseInt(alg.slice(1, 4), 10);
640
+ const algorithm = `aes${size}-wrap`;
641
+ if (!ciphers_default(algorithm)) {
642
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
643
+ }
644
+ const keyObject = ensureKeyObject(key, alg, "wrapKey");
645
+ checkKeySize(keyObject, alg);
646
+ const cipher = createCipheriv(algorithm, keyObject, Buffer3.alloc(8, 166));
647
+ return concat(cipher.update(cek), cipher.final());
648
+ };
649
+ var unwrap = (alg, key, encryptedKey) => {
650
+ const size = parseInt(alg.slice(1, 4), 10);
651
+ const algorithm = `aes${size}-wrap`;
652
+ if (!ciphers_default(algorithm)) {
653
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
654
+ }
655
+ const keyObject = ensureKeyObject(key, alg, "unwrapKey");
656
+ checkKeySize(keyObject, alg);
657
+ const cipher = createDecipheriv2(algorithm, keyObject, Buffer3.alloc(8, 166));
658
+ return concat(cipher.update(encryptedKey), cipher.final());
659
+ };
660
+
661
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/ecdhes.js
662
+ import { diffieHellman, generateKeyPair as generateKeyPairCb, KeyObject as KeyObject4 } from "crypto";
663
+ import { promisify } from "util";
664
+
665
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js
666
+ import { KeyObject as KeyObject3 } from "crypto";
667
+
668
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js
669
+ function isJWK(key) {
670
+ return isObject(key) && typeof key.kty === "string";
671
+ }
672
+ function isPrivateJWK(key) {
673
+ return key.kty !== "oct" && typeof key.d === "string";
674
+ }
675
+ function isPublicJWK(key) {
676
+ return key.kty !== "oct" && typeof key.d === "undefined";
677
+ }
678
+ function isSecretJWK(key) {
679
+ return isJWK(key) && key.kty === "oct" && typeof key.k === "string";
680
+ }
681
+
682
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js
683
+ var namedCurveToJOSE = (namedCurve) => {
684
+ switch (namedCurve) {
685
+ case "prime256v1":
686
+ return "P-256";
687
+ case "secp384r1":
688
+ return "P-384";
689
+ case "secp521r1":
690
+ return "P-521";
691
+ case "secp256k1":
692
+ return "secp256k1";
693
+ default:
694
+ throw new JOSENotSupported("Unsupported key curve for this operation");
695
+ }
696
+ };
697
+ var getNamedCurve2 = (kee, raw) => {
698
+ let key;
699
+ if (isCryptoKey(kee)) {
700
+ key = KeyObject3.from(kee);
701
+ } else if (is_key_object_default(kee)) {
702
+ key = kee;
703
+ } else if (isJWK(kee)) {
704
+ return kee.crv;
705
+ } else {
706
+ throw new TypeError(invalid_key_input_default(kee, ...types3));
707
+ }
708
+ if (key.type === "secret") {
709
+ throw new TypeError('only "private" or "public" type keys can be used for this operation');
710
+ }
711
+ switch (key.asymmetricKeyType) {
712
+ case "ed25519":
713
+ case "ed448":
714
+ return `Ed${key.asymmetricKeyType.slice(2)}`;
715
+ case "x25519":
716
+ case "x448":
717
+ return `X${key.asymmetricKeyType.slice(1)}`;
718
+ case "ec": {
719
+ const namedCurve = key.asymmetricKeyDetails.namedCurve;
720
+ if (raw) {
721
+ return namedCurve;
722
+ }
723
+ return namedCurveToJOSE(namedCurve);
724
+ }
725
+ default:
726
+ throw new TypeError("Invalid asymmetric key type for this operation");
727
+ }
728
+ };
729
+ var get_named_curve_default = getNamedCurve2;
730
+
731
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/ecdhes.js
732
+ var generateKeyPair = promisify(generateKeyPairCb);
733
+ async function deriveKey(publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
734
+ let publicKey;
735
+ if (isCryptoKey(publicKee)) {
736
+ checkEncCryptoKey(publicKee, "ECDH");
737
+ publicKey = KeyObject4.from(publicKee);
738
+ } else if (is_key_object_default(publicKee)) {
739
+ publicKey = publicKee;
740
+ } else {
741
+ throw new TypeError(invalid_key_input_default(publicKee, ...types3));
742
+ }
743
+ let privateKey;
744
+ if (isCryptoKey(privateKee)) {
745
+ checkEncCryptoKey(privateKee, "ECDH", "deriveBits");
746
+ privateKey = KeyObject4.from(privateKee);
747
+ } else if (is_key_object_default(privateKee)) {
748
+ privateKey = privateKee;
749
+ } else {
750
+ throw new TypeError(invalid_key_input_default(privateKee, ...types3));
751
+ }
752
+ const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
753
+ const sharedSecret = diffieHellman({ privateKey, publicKey });
754
+ return concatKdf(sharedSecret, keyLength, value);
755
+ }
756
+ async function generateEpk(kee) {
757
+ let key;
758
+ if (isCryptoKey(kee)) {
759
+ key = KeyObject4.from(kee);
760
+ } else if (is_key_object_default(kee)) {
761
+ key = kee;
762
+ } else {
763
+ throw new TypeError(invalid_key_input_default(kee, ...types3));
764
+ }
765
+ switch (key.asymmetricKeyType) {
766
+ case "x25519":
767
+ return generateKeyPair("x25519");
768
+ case "x448": {
769
+ return generateKeyPair("x448");
770
+ }
771
+ case "ec": {
772
+ const namedCurve = get_named_curve_default(key);
773
+ return generateKeyPair("ec", { namedCurve });
774
+ }
775
+ default:
776
+ throw new JOSENotSupported("Invalid or unsupported EPK");
777
+ }
778
+ }
779
+ var ecdhAllowed = (key) => ["P-256", "P-384", "P-521", "X25519", "X448"].includes(get_named_curve_default(key));
780
+
781
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/pbes2kw.js
782
+ import { promisify as promisify2 } from "util";
783
+ import { KeyObject as KeyObject5, pbkdf2 as pbkdf2cb } from "crypto";
784
+
785
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_p2s.js
786
+ function checkP2s(p2s2) {
787
+ if (!(p2s2 instanceof Uint8Array) || p2s2.length < 8) {
788
+ throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
789
+ }
790
+ }
791
+
792
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/pbes2kw.js
793
+ var pbkdf2 = promisify2(pbkdf2cb);
794
+ function getPassword(key, alg) {
795
+ if (is_key_object_default(key)) {
796
+ return key.export();
797
+ }
798
+ if (key instanceof Uint8Array) {
799
+ return key;
800
+ }
801
+ if (isCryptoKey(key)) {
802
+ checkEncCryptoKey(key, alg, "deriveBits", "deriveKey");
803
+ return KeyObject5.from(key).export();
804
+ }
805
+ throw new TypeError(invalid_key_input_default(key, ...types3, "Uint8Array"));
806
+ }
807
+ var encrypt = async (alg, key, cek, p2c = 2048, p2s2 = randomFillSync(new Uint8Array(16))) => {
808
+ checkP2s(p2s2);
809
+ const salt = p2s(alg, p2s2);
810
+ const keylen = parseInt(alg.slice(13, 16), 10) >> 3;
811
+ const password = getPassword(key, alg);
812
+ const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.slice(8, 11)}`);
813
+ const encryptedKey = await wrap(alg.slice(-6), derivedKey, cek);
814
+ return { encryptedKey, p2c, p2s: encode(p2s2) };
815
+ };
816
+ var decrypt2 = async (alg, key, encryptedKey, p2c, p2s2) => {
817
+ checkP2s(p2s2);
818
+ const salt = p2s(alg, p2s2);
819
+ const keylen = parseInt(alg.slice(13, 16), 10) >> 3;
820
+ const password = getPassword(key, alg);
821
+ const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.slice(8, 11)}`);
822
+ return unwrap(alg.slice(-6), derivedKey, encryptedKey);
823
+ };
824
+
825
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/rsaes.js
826
+ import { KeyObject as KeyObject7, publicEncrypt, constants, privateDecrypt } from "crypto";
827
+ import { deprecate } from "util";
828
+
829
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js
830
+ import { KeyObject as KeyObject6 } from "crypto";
831
+ var check_key_length_default = (key, alg) => {
832
+ let modulusLength;
833
+ try {
834
+ if (key instanceof KeyObject6) {
835
+ modulusLength = key.asymmetricKeyDetails?.modulusLength;
836
+ } else {
837
+ modulusLength = Buffer.from(key.n, "base64url").byteLength << 3;
838
+ }
839
+ } catch {
840
+ }
841
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
842
+ throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
843
+ }
844
+ };
845
+
846
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/rsaes.js
847
+ var checkKey = (key, alg) => {
848
+ if (key.asymmetricKeyType !== "rsa") {
849
+ throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be rsa");
850
+ }
851
+ check_key_length_default(key, alg);
852
+ };
853
+ var RSA1_5 = deprecate(() => constants.RSA_PKCS1_PADDING, 'The RSA1_5 "alg" (JWE Algorithm) is deprecated and will be removed in the next major revision.');
854
+ var resolvePadding = (alg) => {
855
+ switch (alg) {
856
+ case "RSA-OAEP":
857
+ case "RSA-OAEP-256":
858
+ case "RSA-OAEP-384":
859
+ case "RSA-OAEP-512":
860
+ return constants.RSA_PKCS1_OAEP_PADDING;
861
+ case "RSA1_5":
862
+ return RSA1_5();
863
+ default:
864
+ return void 0;
865
+ }
866
+ };
867
+ var resolveOaepHash = (alg) => {
868
+ switch (alg) {
869
+ case "RSA-OAEP":
870
+ return "sha1";
871
+ case "RSA-OAEP-256":
872
+ return "sha256";
873
+ case "RSA-OAEP-384":
874
+ return "sha384";
875
+ case "RSA-OAEP-512":
876
+ return "sha512";
877
+ default:
878
+ return void 0;
879
+ }
880
+ };
881
+ function ensureKeyObject2(key, alg, ...usages) {
882
+ if (is_key_object_default(key)) {
883
+ return key;
884
+ }
885
+ if (isCryptoKey(key)) {
886
+ checkEncCryptoKey(key, alg, ...usages);
887
+ return KeyObject7.from(key);
888
+ }
889
+ throw new TypeError(invalid_key_input_default(key, ...types3));
890
+ }
891
+ var encrypt2 = (alg, key, cek) => {
892
+ const padding = resolvePadding(alg);
893
+ const oaepHash = resolveOaepHash(alg);
894
+ const keyObject = ensureKeyObject2(key, alg, "wrapKey", "encrypt");
895
+ checkKey(keyObject, alg);
896
+ return publicEncrypt({ key: keyObject, oaepHash, padding }, cek);
897
+ };
898
+ var decrypt3 = (alg, key, encryptedKey) => {
899
+ const padding = resolvePadding(alg);
900
+ const oaepHash = resolveOaepHash(alg);
901
+ const keyObject = ensureKeyObject2(key, alg, "unwrapKey", "decrypt");
902
+ checkKey(keyObject, alg);
903
+ return privateDecrypt({ key: keyObject, oaepHash, padding }, encryptedKey);
904
+ };
905
+
906
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/normalize_key.js
907
+ var normalize_key_default = {};
908
+
909
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/cek.js
910
+ function bitLength2(alg) {
911
+ switch (alg) {
912
+ case "A128GCM":
913
+ return 128;
914
+ case "A192GCM":
915
+ return 192;
916
+ case "A256GCM":
917
+ case "A128CBC-HS256":
918
+ return 256;
919
+ case "A192CBC-HS384":
920
+ return 384;
921
+ case "A256CBC-HS512":
922
+ return 512;
923
+ default:
924
+ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
925
+ }
926
+ }
927
+ var cek_default = (alg) => randomFillSync(new Uint8Array(bitLength2(alg) >> 3));
928
+
929
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/asn1.js
930
+ import { createPrivateKey, createPublicKey, KeyObject as KeyObject8 } from "crypto";
931
+ import { Buffer as Buffer4 } from "buffer";
932
+ var genericExport = (keyType, keyFormat, key) => {
933
+ let keyObject;
934
+ if (isCryptoKey(key)) {
935
+ if (!key.extractable) {
936
+ throw new TypeError("CryptoKey is not extractable");
937
+ }
938
+ keyObject = KeyObject8.from(key);
939
+ } else if (is_key_object_default(key)) {
940
+ keyObject = key;
941
+ } else {
942
+ throw new TypeError(invalid_key_input_default(key, ...types3));
943
+ }
944
+ if (keyObject.type !== keyType) {
945
+ throw new TypeError(`key is not a ${keyType} key`);
946
+ }
947
+ return keyObject.export({ format: "pem", type: keyFormat });
948
+ };
949
+ var toSPKI = (key) => {
950
+ return genericExport("public", "spki", key);
951
+ };
952
+ var toPKCS8 = (key) => {
953
+ return genericExport("private", "pkcs8", key);
954
+ };
955
+ var fromPKCS8 = (pem) => createPrivateKey({
956
+ key: Buffer4.from(pem.replace(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, ""), "base64"),
957
+ type: "pkcs8",
958
+ format: "der"
959
+ });
960
+ var fromSPKI = (pem) => createPublicKey({
961
+ key: Buffer4.from(pem.replace(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, ""), "base64"),
962
+ type: "spki",
963
+ format: "der"
964
+ });
965
+ var fromX509 = (pem) => createPublicKey({
966
+ key: pem,
967
+ type: "spki",
968
+ format: "pem"
969
+ });
970
+
971
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js
972
+ import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2 } from "crypto";
973
+ var parse = (key) => {
974
+ if (key.d) {
975
+ return createPrivateKey2({ format: "jwk", key });
976
+ }
977
+ return createPublicKey2({ format: "jwk", key });
978
+ };
979
+ var jwk_to_key_default = parse;
980
+
981
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js
982
+ async function importSPKI(spki, alg, options) {
983
+ if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
984
+ throw new TypeError('"spki" must be SPKI formatted string');
985
+ }
986
+ return fromSPKI(spki, alg, options);
987
+ }
988
+ async function importX509(x509, alg, options) {
989
+ if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
990
+ throw new TypeError('"x509" must be X.509 formatted string');
991
+ }
992
+ return fromX509(x509, alg, options);
993
+ }
994
+ async function importPKCS8(pkcs8, alg, options) {
995
+ if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
996
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
997
+ }
998
+ return fromPKCS8(pkcs8, alg, options);
999
+ }
1000
+ async function importJWK(jwk, alg) {
1001
+ if (!isObject(jwk)) {
1002
+ throw new TypeError("JWK must be an object");
1003
+ }
1004
+ alg ||= jwk.alg;
1005
+ switch (jwk.kty) {
1006
+ case "oct":
1007
+ if (typeof jwk.k !== "string" || !jwk.k) {
1008
+ throw new TypeError('missing "k" (Key Value) Parameter value');
1009
+ }
1010
+ return decode(jwk.k);
1011
+ case "RSA":
1012
+ if ("oth" in jwk && jwk.oth !== void 0) {
1013
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
1014
+ }
1015
+ case "EC":
1016
+ case "OKP":
1017
+ return jwk_to_key_default({ ...jwk, alg });
1018
+ default:
1019
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
1020
+ }
1021
+ }
1022
+
1023
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.js
1024
+ var tag = (key) => key?.[Symbol.toStringTag];
1025
+ var jwkMatchesOp = (alg, key, usage) => {
1026
+ if (key.use !== void 0 && key.use !== "sig") {
1027
+ throw new TypeError("Invalid key for this operation, when present its use must be sig");
1028
+ }
1029
+ if (key.key_ops !== void 0 && key.key_ops.includes?.(usage) !== true) {
1030
+ throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
1031
+ }
1032
+ if (key.alg !== void 0 && key.alg !== alg) {
1033
+ throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
1034
+ }
1035
+ return true;
1036
+ };
1037
+ var symmetricTypeCheck = (alg, key, usage, allowJwk) => {
1038
+ if (key instanceof Uint8Array)
1039
+ return;
1040
+ if (allowJwk && isJWK(key)) {
1041
+ if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
1042
+ return;
1043
+ 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`);
1044
+ }
1045
+ if (!is_key_like_default(key)) {
1046
+ throw new TypeError(withAlg(alg, key, ...types3, "Uint8Array", allowJwk ? "JSON Web Key" : null));
1047
+ }
1048
+ if (key.type !== "secret") {
1049
+ throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
1050
+ }
1051
+ };
1052
+ var asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
1053
+ if (allowJwk && isJWK(key)) {
1054
+ switch (usage) {
1055
+ case "sign":
1056
+ if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
1057
+ return;
1058
+ throw new TypeError(`JSON Web Key for this operation be a private JWK`);
1059
+ case "verify":
1060
+ if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
1061
+ return;
1062
+ throw new TypeError(`JSON Web Key for this operation be a public JWK`);
1063
+ }
1064
+ }
1065
+ if (!is_key_like_default(key)) {
1066
+ throw new TypeError(withAlg(alg, key, ...types3, allowJwk ? "JSON Web Key" : null));
1067
+ }
1068
+ if (key.type === "secret") {
1069
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
1070
+ }
1071
+ if (usage === "sign" && key.type === "public") {
1072
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
1073
+ }
1074
+ if (usage === "decrypt" && key.type === "public") {
1075
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
1076
+ }
1077
+ if (key.algorithm && usage === "verify" && key.type === "private") {
1078
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
1079
+ }
1080
+ if (key.algorithm && usage === "encrypt" && key.type === "private") {
1081
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
1082
+ }
1083
+ };
1084
+ function checkKeyType(allowJwk, alg, key, usage) {
1085
+ const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(alg);
1086
+ if (symmetric) {
1087
+ symmetricTypeCheck(alg, key, usage, allowJwk);
1088
+ } else {
1089
+ asymmetricTypeCheck(alg, key, usage, allowJwk);
1090
+ }
1091
+ }
1092
+ var check_key_type_default = checkKeyType.bind(void 0, false);
1093
+ var checkKeyTypeWithJwk = checkKeyType.bind(void 0, true);
1094
+
1095
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/encrypt.js
1096
+ import { createCipheriv as createCipheriv2, KeyObject as KeyObject9 } from "crypto";
1097
+ function cbcEncrypt(enc, plaintext, cek, iv, aad) {
1098
+ const keySize = parseInt(enc.slice(1, 4), 10);
1099
+ if (is_key_object_default(cek)) {
1100
+ cek = cek.export();
1101
+ }
1102
+ const encKey = cek.subarray(keySize >> 3);
1103
+ const macKey = cek.subarray(0, keySize >> 3);
1104
+ const algorithm = `aes-${keySize}-cbc`;
1105
+ if (!ciphers_default(algorithm)) {
1106
+ throw new JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
1107
+ }
1108
+ const cipher = createCipheriv2(algorithm, encKey, iv);
1109
+ const ciphertext = concat(cipher.update(plaintext), cipher.final());
1110
+ const macSize = parseInt(enc.slice(-3), 10);
1111
+ const tag2 = cbcTag(aad, iv, ciphertext, macSize, macKey, keySize);
1112
+ return { ciphertext, tag: tag2, iv };
1113
+ }
1114
+ function gcmEncrypt(enc, plaintext, cek, iv, aad) {
1115
+ const keySize = parseInt(enc.slice(1, 4), 10);
1116
+ const algorithm = `aes-${keySize}-gcm`;
1117
+ if (!ciphers_default(algorithm)) {
1118
+ throw new JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
1119
+ }
1120
+ const cipher = createCipheriv2(algorithm, cek, iv, { authTagLength: 16 });
1121
+ if (aad.byteLength) {
1122
+ cipher.setAAD(aad, { plaintextLength: plaintext.length });
1123
+ }
1124
+ const ciphertext = cipher.update(plaintext);
1125
+ cipher.final();
1126
+ const tag2 = cipher.getAuthTag();
1127
+ return { ciphertext, tag: tag2, iv };
1128
+ }
1129
+ var encrypt3 = (enc, plaintext, cek, iv, aad) => {
1130
+ let key;
1131
+ if (isCryptoKey(cek)) {
1132
+ checkEncCryptoKey(cek, enc, "encrypt");
1133
+ key = KeyObject9.from(cek);
1134
+ } else if (cek instanceof Uint8Array || is_key_object_default(cek)) {
1135
+ key = cek;
1136
+ } else {
1137
+ throw new TypeError(invalid_key_input_default(cek, ...types3, "Uint8Array"));
1138
+ }
1139
+ check_cek_length_default(enc, key);
1140
+ if (iv) {
1141
+ check_iv_length_default(enc, iv);
1142
+ } else {
1143
+ iv = iv_default(enc);
1144
+ }
1145
+ switch (enc) {
1146
+ case "A128CBC-HS256":
1147
+ case "A192CBC-HS384":
1148
+ case "A256CBC-HS512":
1149
+ return cbcEncrypt(enc, plaintext, key, iv, aad);
1150
+ case "A128GCM":
1151
+ case "A192GCM":
1152
+ case "A256GCM":
1153
+ return gcmEncrypt(enc, plaintext, key, iv, aad);
1154
+ default:
1155
+ throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
1156
+ }
1157
+ };
1158
+ var encrypt_default = encrypt3;
1159
+
1160
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/aesgcmkw.js
1161
+ async function wrap2(alg, key, cek, iv) {
1162
+ const jweAlgorithm = alg.slice(0, 7);
1163
+ const wrapped = await encrypt_default(jweAlgorithm, cek, key, iv, new Uint8Array(0));
1164
+ return {
1165
+ encryptedKey: wrapped.ciphertext,
1166
+ iv: encode(wrapped.iv),
1167
+ tag: encode(wrapped.tag)
1168
+ };
1169
+ }
1170
+ async function unwrap2(alg, key, encryptedKey, iv, tag2) {
1171
+ const jweAlgorithm = alg.slice(0, 7);
1172
+ return decrypt_default(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array(0));
1173
+ }
1174
+
1175
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/decrypt_key_management.js
1176
+ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
1177
+ check_key_type_default(alg, key, "decrypt");
1178
+ key = await normalize_key_default.normalizePrivateKey?.(key, alg) || key;
1179
+ switch (alg) {
1180
+ case "dir": {
1181
+ if (encryptedKey !== void 0)
1182
+ throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
1183
+ return key;
1184
+ }
1185
+ case "ECDH-ES":
1186
+ if (encryptedKey !== void 0)
1187
+ throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
1188
+ case "ECDH-ES+A128KW":
1189
+ case "ECDH-ES+A192KW":
1190
+ case "ECDH-ES+A256KW": {
1191
+ if (!isObject(joseHeader.epk))
1192
+ throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
1193
+ if (!ecdhAllowed(key))
1194
+ throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
1195
+ const epk = await importJWK(joseHeader.epk, alg);
1196
+ let partyUInfo;
1197
+ let partyVInfo;
1198
+ if (joseHeader.apu !== void 0) {
1199
+ if (typeof joseHeader.apu !== "string")
1200
+ throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
1201
+ try {
1202
+ partyUInfo = decode(joseHeader.apu);
1203
+ } catch {
1204
+ throw new JWEInvalid("Failed to base64url decode the apu");
1205
+ }
1206
+ }
1207
+ if (joseHeader.apv !== void 0) {
1208
+ if (typeof joseHeader.apv !== "string")
1209
+ throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
1210
+ try {
1211
+ partyVInfo = decode(joseHeader.apv);
1212
+ } catch {
1213
+ throw new JWEInvalid("Failed to base64url decode the apv");
1214
+ }
1215
+ }
1216
+ const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? bitLength2(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
1217
+ if (alg === "ECDH-ES")
1218
+ return sharedSecret;
1219
+ if (encryptedKey === void 0)
1220
+ throw new JWEInvalid("JWE Encrypted Key missing");
1221
+ return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
1222
+ }
1223
+ case "RSA1_5":
1224
+ case "RSA-OAEP":
1225
+ case "RSA-OAEP-256":
1226
+ case "RSA-OAEP-384":
1227
+ case "RSA-OAEP-512": {
1228
+ if (encryptedKey === void 0)
1229
+ throw new JWEInvalid("JWE Encrypted Key missing");
1230
+ return decrypt3(alg, key, encryptedKey);
1231
+ }
1232
+ case "PBES2-HS256+A128KW":
1233
+ case "PBES2-HS384+A192KW":
1234
+ case "PBES2-HS512+A256KW": {
1235
+ if (encryptedKey === void 0)
1236
+ throw new JWEInvalid("JWE Encrypted Key missing");
1237
+ if (typeof joseHeader.p2c !== "number")
1238
+ throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
1239
+ const p2cLimit = options?.maxPBES2Count || 1e4;
1240
+ if (joseHeader.p2c > p2cLimit)
1241
+ throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
1242
+ if (typeof joseHeader.p2s !== "string")
1243
+ throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
1244
+ let p2s2;
1245
+ try {
1246
+ p2s2 = decode(joseHeader.p2s);
1247
+ } catch {
1248
+ throw new JWEInvalid("Failed to base64url decode the p2s");
1249
+ }
1250
+ return decrypt2(alg, key, encryptedKey, joseHeader.p2c, p2s2);
1251
+ }
1252
+ case "A128KW":
1253
+ case "A192KW":
1254
+ case "A256KW": {
1255
+ if (encryptedKey === void 0)
1256
+ throw new JWEInvalid("JWE Encrypted Key missing");
1257
+ return unwrap(alg, key, encryptedKey);
1258
+ }
1259
+ case "A128GCMKW":
1260
+ case "A192GCMKW":
1261
+ case "A256GCMKW": {
1262
+ if (encryptedKey === void 0)
1263
+ throw new JWEInvalid("JWE Encrypted Key missing");
1264
+ if (typeof joseHeader.iv !== "string")
1265
+ throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
1266
+ if (typeof joseHeader.tag !== "string")
1267
+ throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
1268
+ let iv;
1269
+ try {
1270
+ iv = decode(joseHeader.iv);
1271
+ } catch {
1272
+ throw new JWEInvalid("Failed to base64url decode the iv");
1273
+ }
1274
+ let tag2;
1275
+ try {
1276
+ tag2 = decode(joseHeader.tag);
1277
+ } catch {
1278
+ throw new JWEInvalid("Failed to base64url decode the tag");
1279
+ }
1280
+ return unwrap2(alg, key, encryptedKey, iv, tag2);
1281
+ }
1282
+ default: {
1283
+ throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
1284
+ }
1285
+ }
1286
+ }
1287
+ var decrypt_key_management_default = decryptKeyManagement;
1288
+
1289
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js
1290
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1291
+ if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
1292
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
1293
+ }
1294
+ if (!protectedHeader || protectedHeader.crit === void 0) {
1295
+ return /* @__PURE__ */ new Set();
1296
+ }
1297
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
1298
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
1299
+ }
1300
+ let recognized;
1301
+ if (recognizedOption !== void 0) {
1302
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
1303
+ } else {
1304
+ recognized = recognizedDefault;
1305
+ }
1306
+ for (const parameter of protectedHeader.crit) {
1307
+ if (!recognized.has(parameter)) {
1308
+ throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
1309
+ }
1310
+ if (joseHeader[parameter] === void 0) {
1311
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
1312
+ }
1313
+ if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
1314
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
1315
+ }
1316
+ }
1317
+ return new Set(protectedHeader.crit);
1318
+ }
1319
+ var validate_crit_default = validateCrit;
1320
+
1321
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js
1322
+ var validateAlgorithms = (option, algorithms) => {
1323
+ if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1324
+ throw new TypeError(`"${option}" option must be an array of strings`);
1325
+ }
1326
+ if (!algorithms) {
1327
+ return void 0;
1328
+ }
1329
+ return new Set(algorithms);
1330
+ };
1331
+ var validate_algorithms_default = validateAlgorithms;
1332
+
1333
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/flattened/decrypt.js
1334
+ async function flattenedDecrypt(jwe, key, options) {
1335
+ if (!isObject(jwe)) {
1336
+ throw new JWEInvalid("Flattened JWE must be an object");
1337
+ }
1338
+ if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
1339
+ throw new JWEInvalid("JOSE Header missing");
1340
+ }
1341
+ if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
1342
+ throw new JWEInvalid("JWE Initialization Vector incorrect type");
1343
+ }
1344
+ if (typeof jwe.ciphertext !== "string") {
1345
+ throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
1346
+ }
1347
+ if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
1348
+ throw new JWEInvalid("JWE Authentication Tag incorrect type");
1349
+ }
1350
+ if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
1351
+ throw new JWEInvalid("JWE Protected Header incorrect type");
1352
+ }
1353
+ if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
1354
+ throw new JWEInvalid("JWE Encrypted Key incorrect type");
1355
+ }
1356
+ if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
1357
+ throw new JWEInvalid("JWE AAD incorrect type");
1358
+ }
1359
+ if (jwe.header !== void 0 && !isObject(jwe.header)) {
1360
+ throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
1361
+ }
1362
+ if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
1363
+ throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
1364
+ }
1365
+ let parsedProt;
1366
+ if (jwe.protected) {
1367
+ try {
1368
+ const protectedHeader2 = decode(jwe.protected);
1369
+ parsedProt = JSON.parse(decoder.decode(protectedHeader2));
1370
+ } catch {
1371
+ throw new JWEInvalid("JWE Protected Header is invalid");
1372
+ }
1373
+ }
1374
+ if (!is_disjoint_default(parsedProt, jwe.header, jwe.unprotected)) {
1375
+ throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
1376
+ }
1377
+ const joseHeader = {
1378
+ ...parsedProt,
1379
+ ...jwe.header,
1380
+ ...jwe.unprotected
1381
+ };
1382
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
1383
+ if (joseHeader.zip !== void 0) {
1384
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
1385
+ }
1386
+ const { alg, enc } = joseHeader;
1387
+ if (typeof alg !== "string" || !alg) {
1388
+ throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
1389
+ }
1390
+ if (typeof enc !== "string" || !enc) {
1391
+ throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
1392
+ }
1393
+ const keyManagementAlgorithms = options && validate_algorithms_default("keyManagementAlgorithms", options.keyManagementAlgorithms);
1394
+ const contentEncryptionAlgorithms = options && validate_algorithms_default("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
1395
+ if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
1396
+ throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
1397
+ }
1398
+ if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
1399
+ throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
1400
+ }
1401
+ let encryptedKey;
1402
+ if (jwe.encrypted_key !== void 0) {
1403
+ try {
1404
+ encryptedKey = decode(jwe.encrypted_key);
1405
+ } catch {
1406
+ throw new JWEInvalid("Failed to base64url decode the encrypted_key");
1407
+ }
1408
+ }
1409
+ let resolvedKey = false;
1410
+ if (typeof key === "function") {
1411
+ key = await key(parsedProt, jwe);
1412
+ resolvedKey = true;
1413
+ }
1414
+ let cek;
1415
+ try {
1416
+ cek = await decrypt_key_management_default(alg, key, encryptedKey, joseHeader, options);
1417
+ } catch (err) {
1418
+ if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
1419
+ throw err;
1420
+ }
1421
+ cek = cek_default(enc);
1422
+ }
1423
+ let iv;
1424
+ let tag2;
1425
+ if (jwe.iv !== void 0) {
1426
+ try {
1427
+ iv = decode(jwe.iv);
1428
+ } catch {
1429
+ throw new JWEInvalid("Failed to base64url decode the iv");
1430
+ }
1431
+ }
1432
+ if (jwe.tag !== void 0) {
1433
+ try {
1434
+ tag2 = decode(jwe.tag);
1435
+ } catch {
1436
+ throw new JWEInvalid("Failed to base64url decode the tag");
1437
+ }
1438
+ }
1439
+ const protectedHeader = encoder.encode(jwe.protected ?? "");
1440
+ let additionalData;
1441
+ if (jwe.aad !== void 0) {
1442
+ additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(jwe.aad));
1443
+ } else {
1444
+ additionalData = protectedHeader;
1445
+ }
1446
+ let ciphertext;
1447
+ try {
1448
+ ciphertext = decode(jwe.ciphertext);
1449
+ } catch {
1450
+ throw new JWEInvalid("Failed to base64url decode the ciphertext");
1451
+ }
1452
+ const plaintext = await decrypt_default(enc, cek, ciphertext, iv, tag2, additionalData);
1453
+ const result = { plaintext };
1454
+ if (jwe.protected !== void 0) {
1455
+ result.protectedHeader = parsedProt;
1456
+ }
1457
+ if (jwe.aad !== void 0) {
1458
+ try {
1459
+ result.additionalAuthenticatedData = decode(jwe.aad);
1460
+ } catch {
1461
+ throw new JWEInvalid("Failed to base64url decode the aad");
1462
+ }
1463
+ }
1464
+ if (jwe.unprotected !== void 0) {
1465
+ result.sharedUnprotectedHeader = jwe.unprotected;
1466
+ }
1467
+ if (jwe.header !== void 0) {
1468
+ result.unprotectedHeader = jwe.header;
1469
+ }
1470
+ if (resolvedKey) {
1471
+ return { ...result, key };
1472
+ }
1473
+ return result;
1474
+ }
1475
+
1476
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/compact/decrypt.js
1477
+ async function compactDecrypt(jwe, key, options) {
1478
+ if (jwe instanceof Uint8Array) {
1479
+ jwe = decoder.decode(jwe);
1480
+ }
1481
+ if (typeof jwe !== "string") {
1482
+ throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
1483
+ }
1484
+ const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
1485
+ if (length !== 5) {
1486
+ throw new JWEInvalid("Invalid Compact JWE");
1487
+ }
1488
+ const decrypted = await flattenedDecrypt({
1489
+ ciphertext,
1490
+ iv: iv || void 0,
1491
+ protected: protectedHeader,
1492
+ tag: tag2 || void 0,
1493
+ encrypted_key: encryptedKey || void 0
1494
+ }, key, options);
1495
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
1496
+ if (typeof key === "function") {
1497
+ return { ...result, key: decrypted.key };
1498
+ }
1499
+ return result;
1500
+ }
1501
+
1502
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/general/decrypt.js
1503
+ async function generalDecrypt(jwe, key, options) {
1504
+ if (!isObject(jwe)) {
1505
+ throw new JWEInvalid("General JWE must be an object");
1506
+ }
1507
+ if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
1508
+ throw new JWEInvalid("JWE Recipients missing or incorrect type");
1509
+ }
1510
+ if (!jwe.recipients.length) {
1511
+ throw new JWEInvalid("JWE Recipients has no members");
1512
+ }
1513
+ for (const recipient of jwe.recipients) {
1514
+ try {
1515
+ return await flattenedDecrypt({
1516
+ aad: jwe.aad,
1517
+ ciphertext: jwe.ciphertext,
1518
+ encrypted_key: recipient.encrypted_key,
1519
+ header: recipient.header,
1520
+ iv: jwe.iv,
1521
+ protected: jwe.protected,
1522
+ tag: jwe.tag,
1523
+ unprotected: jwe.unprotected
1524
+ }, key, options);
1525
+ } catch {
1526
+ }
1527
+ }
1528
+ throw new JWEDecryptionFailed();
1529
+ }
1530
+
1531
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/private_symbols.js
1532
+ var unprotected = Symbol();
1533
+
1534
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/key_to_jwk.js
1535
+ import { KeyObject as KeyObject10 } from "crypto";
1536
+ var keyToJWK = (key) => {
1537
+ let keyObject;
1538
+ if (isCryptoKey(key)) {
1539
+ if (!key.extractable) {
1540
+ throw new TypeError("CryptoKey is not extractable");
1541
+ }
1542
+ keyObject = KeyObject10.from(key);
1543
+ } else if (is_key_object_default(key)) {
1544
+ keyObject = key;
1545
+ } else if (key instanceof Uint8Array) {
1546
+ return {
1547
+ kty: "oct",
1548
+ k: encode(key)
1549
+ };
1550
+ } else {
1551
+ throw new TypeError(invalid_key_input_default(key, ...types3, "Uint8Array"));
1552
+ }
1553
+ if (keyObject.type !== "secret" && !["rsa", "ec", "ed25519", "x25519", "ed448", "x448"].includes(keyObject.asymmetricKeyType)) {
1554
+ throw new JOSENotSupported("Unsupported key asymmetricKeyType");
1555
+ }
1556
+ return keyObject.export({ format: "jwk" });
1557
+ };
1558
+ var key_to_jwk_default = keyToJWK;
1559
+
1560
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/export.js
1561
+ async function exportSPKI(key) {
1562
+ return toSPKI(key);
1563
+ }
1564
+ async function exportPKCS8(key) {
1565
+ return toPKCS8(key);
1566
+ }
1567
+ async function exportJWK(key) {
1568
+ return key_to_jwk_default(key);
1569
+ }
1570
+
1571
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/encrypt_key_management.js
1572
+ async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
1573
+ let encryptedKey;
1574
+ let parameters;
1575
+ let cek;
1576
+ check_key_type_default(alg, key, "encrypt");
1577
+ key = await normalize_key_default.normalizePublicKey?.(key, alg) || key;
1578
+ switch (alg) {
1579
+ case "dir": {
1580
+ cek = key;
1581
+ break;
1582
+ }
1583
+ case "ECDH-ES":
1584
+ case "ECDH-ES+A128KW":
1585
+ case "ECDH-ES+A192KW":
1586
+ case "ECDH-ES+A256KW": {
1587
+ if (!ecdhAllowed(key)) {
1588
+ throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
1589
+ }
1590
+ const { apu, apv } = providedParameters;
1591
+ let { epk: ephemeralKey } = providedParameters;
1592
+ ephemeralKey ||= (await generateEpk(key)).privateKey;
1593
+ const { x, y, crv, kty } = await exportJWK(ephemeralKey);
1594
+ const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? bitLength2(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
1595
+ parameters = { epk: { x, crv, kty } };
1596
+ if (kty === "EC")
1597
+ parameters.epk.y = y;
1598
+ if (apu)
1599
+ parameters.apu = encode(apu);
1600
+ if (apv)
1601
+ parameters.apv = encode(apv);
1602
+ if (alg === "ECDH-ES") {
1603
+ cek = sharedSecret;
1604
+ break;
1605
+ }
1606
+ cek = providedCek || cek_default(enc);
1607
+ const kwAlg = alg.slice(-6);
1608
+ encryptedKey = await wrap(kwAlg, sharedSecret, cek);
1609
+ break;
1610
+ }
1611
+ case "RSA1_5":
1612
+ case "RSA-OAEP":
1613
+ case "RSA-OAEP-256":
1614
+ case "RSA-OAEP-384":
1615
+ case "RSA-OAEP-512": {
1616
+ cek = providedCek || cek_default(enc);
1617
+ encryptedKey = await encrypt2(alg, key, cek);
1618
+ break;
1619
+ }
1620
+ case "PBES2-HS256+A128KW":
1621
+ case "PBES2-HS384+A192KW":
1622
+ case "PBES2-HS512+A256KW": {
1623
+ cek = providedCek || cek_default(enc);
1624
+ const { p2c, p2s: p2s2 } = providedParameters;
1625
+ ({ encryptedKey, ...parameters } = await encrypt(alg, key, cek, p2c, p2s2));
1626
+ break;
1627
+ }
1628
+ case "A128KW":
1629
+ case "A192KW":
1630
+ case "A256KW": {
1631
+ cek = providedCek || cek_default(enc);
1632
+ encryptedKey = await wrap(alg, key, cek);
1633
+ break;
1634
+ }
1635
+ case "A128GCMKW":
1636
+ case "A192GCMKW":
1637
+ case "A256GCMKW": {
1638
+ cek = providedCek || cek_default(enc);
1639
+ const { iv } = providedParameters;
1640
+ ({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, iv));
1641
+ break;
1642
+ }
1643
+ default: {
1644
+ throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
1645
+ }
1646
+ }
1647
+ return { cek, encryptedKey, parameters };
1648
+ }
1649
+ var encrypt_key_management_default = encryptKeyManagement;
1650
+
1651
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/flattened/encrypt.js
1652
+ var FlattenedEncrypt = class {
1653
+ _plaintext;
1654
+ _protectedHeader;
1655
+ _sharedUnprotectedHeader;
1656
+ _unprotectedHeader;
1657
+ _aad;
1658
+ _cek;
1659
+ _iv;
1660
+ _keyManagementParameters;
1661
+ constructor(plaintext) {
1662
+ if (!(plaintext instanceof Uint8Array)) {
1663
+ throw new TypeError("plaintext must be an instance of Uint8Array");
1664
+ }
1665
+ this._plaintext = plaintext;
1666
+ }
1667
+ setKeyManagementParameters(parameters) {
1668
+ if (this._keyManagementParameters) {
1669
+ throw new TypeError("setKeyManagementParameters can only be called once");
1670
+ }
1671
+ this._keyManagementParameters = parameters;
1672
+ return this;
1673
+ }
1674
+ setProtectedHeader(protectedHeader) {
1675
+ if (this._protectedHeader) {
1676
+ throw new TypeError("setProtectedHeader can only be called once");
1677
+ }
1678
+ this._protectedHeader = protectedHeader;
1679
+ return this;
1680
+ }
1681
+ setSharedUnprotectedHeader(sharedUnprotectedHeader) {
1682
+ if (this._sharedUnprotectedHeader) {
1683
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
1684
+ }
1685
+ this._sharedUnprotectedHeader = sharedUnprotectedHeader;
1686
+ return this;
1687
+ }
1688
+ setUnprotectedHeader(unprotectedHeader) {
1689
+ if (this._unprotectedHeader) {
1690
+ throw new TypeError("setUnprotectedHeader can only be called once");
1691
+ }
1692
+ this._unprotectedHeader = unprotectedHeader;
1693
+ return this;
1694
+ }
1695
+ setAdditionalAuthenticatedData(aad) {
1696
+ this._aad = aad;
1697
+ return this;
1698
+ }
1699
+ setContentEncryptionKey(cek) {
1700
+ if (this._cek) {
1701
+ throw new TypeError("setContentEncryptionKey can only be called once");
1702
+ }
1703
+ this._cek = cek;
1704
+ return this;
1705
+ }
1706
+ setInitializationVector(iv) {
1707
+ if (this._iv) {
1708
+ throw new TypeError("setInitializationVector can only be called once");
1709
+ }
1710
+ this._iv = iv;
1711
+ return this;
1712
+ }
1713
+ async encrypt(key, options) {
1714
+ if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader) {
1715
+ throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
1716
+ }
1717
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader)) {
1718
+ throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
1719
+ }
1720
+ const joseHeader = {
1721
+ ...this._protectedHeader,
1722
+ ...this._unprotectedHeader,
1723
+ ...this._sharedUnprotectedHeader
1724
+ };
1725
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this._protectedHeader, joseHeader);
1726
+ if (joseHeader.zip !== void 0) {
1727
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
1728
+ }
1729
+ const { alg, enc } = joseHeader;
1730
+ if (typeof alg !== "string" || !alg) {
1731
+ throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
1732
+ }
1733
+ if (typeof enc !== "string" || !enc) {
1734
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
1735
+ }
1736
+ let encryptedKey;
1737
+ if (this._cek && (alg === "dir" || alg === "ECDH-ES")) {
1738
+ throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
1739
+ }
1740
+ let cek;
1741
+ {
1742
+ let parameters;
1743
+ ({ cek, encryptedKey, parameters } = await encrypt_key_management_default(alg, enc, key, this._cek, this._keyManagementParameters));
1744
+ if (parameters) {
1745
+ if (options && unprotected in options) {
1746
+ if (!this._unprotectedHeader) {
1747
+ this.setUnprotectedHeader(parameters);
1748
+ } else {
1749
+ this._unprotectedHeader = { ...this._unprotectedHeader, ...parameters };
1750
+ }
1751
+ } else if (!this._protectedHeader) {
1752
+ this.setProtectedHeader(parameters);
1753
+ } else {
1754
+ this._protectedHeader = { ...this._protectedHeader, ...parameters };
1755
+ }
1756
+ }
1757
+ }
1758
+ let additionalData;
1759
+ let protectedHeader;
1760
+ let aadMember;
1761
+ if (this._protectedHeader) {
1762
+ protectedHeader = encoder.encode(encode(JSON.stringify(this._protectedHeader)));
1763
+ } else {
1764
+ protectedHeader = encoder.encode("");
1765
+ }
1766
+ if (this._aad) {
1767
+ aadMember = encode(this._aad);
1768
+ additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(aadMember));
1769
+ } else {
1770
+ additionalData = protectedHeader;
1771
+ }
1772
+ const { ciphertext, tag: tag2, iv } = await encrypt_default(enc, this._plaintext, cek, this._iv, additionalData);
1773
+ const jwe = {
1774
+ ciphertext: encode(ciphertext)
1775
+ };
1776
+ if (iv) {
1777
+ jwe.iv = encode(iv);
1778
+ }
1779
+ if (tag2) {
1780
+ jwe.tag = encode(tag2);
1781
+ }
1782
+ if (encryptedKey) {
1783
+ jwe.encrypted_key = encode(encryptedKey);
1784
+ }
1785
+ if (aadMember) {
1786
+ jwe.aad = aadMember;
1787
+ }
1788
+ if (this._protectedHeader) {
1789
+ jwe.protected = decoder.decode(protectedHeader);
1790
+ }
1791
+ if (this._sharedUnprotectedHeader) {
1792
+ jwe.unprotected = this._sharedUnprotectedHeader;
1793
+ }
1794
+ if (this._unprotectedHeader) {
1795
+ jwe.header = this._unprotectedHeader;
1796
+ }
1797
+ return jwe;
1798
+ }
1799
+ };
1800
+
1801
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/general/encrypt.js
1802
+ var IndividualRecipient = class {
1803
+ parent;
1804
+ unprotectedHeader;
1805
+ key;
1806
+ options;
1807
+ constructor(enc, key, options) {
1808
+ this.parent = enc;
1809
+ this.key = key;
1810
+ this.options = options;
1811
+ }
1812
+ setUnprotectedHeader(unprotectedHeader) {
1813
+ if (this.unprotectedHeader) {
1814
+ throw new TypeError("setUnprotectedHeader can only be called once");
1815
+ }
1816
+ this.unprotectedHeader = unprotectedHeader;
1817
+ return this;
1818
+ }
1819
+ addRecipient(...args) {
1820
+ return this.parent.addRecipient(...args);
1821
+ }
1822
+ encrypt(...args) {
1823
+ return this.parent.encrypt(...args);
1824
+ }
1825
+ done() {
1826
+ return this.parent;
1827
+ }
1828
+ };
1829
+ var GeneralEncrypt = class {
1830
+ _plaintext;
1831
+ _recipients = [];
1832
+ _protectedHeader;
1833
+ _unprotectedHeader;
1834
+ _aad;
1835
+ constructor(plaintext) {
1836
+ this._plaintext = plaintext;
1837
+ }
1838
+ addRecipient(key, options) {
1839
+ const recipient = new IndividualRecipient(this, key, { crit: options?.crit });
1840
+ this._recipients.push(recipient);
1841
+ return recipient;
1842
+ }
1843
+ setProtectedHeader(protectedHeader) {
1844
+ if (this._protectedHeader) {
1845
+ throw new TypeError("setProtectedHeader can only be called once");
1846
+ }
1847
+ this._protectedHeader = protectedHeader;
1848
+ return this;
1849
+ }
1850
+ setSharedUnprotectedHeader(sharedUnprotectedHeader) {
1851
+ if (this._unprotectedHeader) {
1852
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
1853
+ }
1854
+ this._unprotectedHeader = sharedUnprotectedHeader;
1855
+ return this;
1856
+ }
1857
+ setAdditionalAuthenticatedData(aad) {
1858
+ this._aad = aad;
1859
+ return this;
1860
+ }
1861
+ async encrypt() {
1862
+ if (!this._recipients.length) {
1863
+ throw new JWEInvalid("at least one recipient must be added");
1864
+ }
1865
+ if (this._recipients.length === 1) {
1866
+ const [recipient] = this._recipients;
1867
+ const flattened = await new FlattenedEncrypt(this._plaintext).setAdditionalAuthenticatedData(this._aad).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).encrypt(recipient.key, { ...recipient.options });
1868
+ const jwe2 = {
1869
+ ciphertext: flattened.ciphertext,
1870
+ iv: flattened.iv,
1871
+ recipients: [{}],
1872
+ tag: flattened.tag
1873
+ };
1874
+ if (flattened.aad)
1875
+ jwe2.aad = flattened.aad;
1876
+ if (flattened.protected)
1877
+ jwe2.protected = flattened.protected;
1878
+ if (flattened.unprotected)
1879
+ jwe2.unprotected = flattened.unprotected;
1880
+ if (flattened.encrypted_key)
1881
+ jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
1882
+ if (flattened.header)
1883
+ jwe2.recipients[0].header = flattened.header;
1884
+ return jwe2;
1885
+ }
1886
+ let enc;
1887
+ for (let i = 0; i < this._recipients.length; i++) {
1888
+ const recipient = this._recipients[i];
1889
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader, recipient.unprotectedHeader)) {
1890
+ throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
1891
+ }
1892
+ const joseHeader = {
1893
+ ...this._protectedHeader,
1894
+ ...this._unprotectedHeader,
1895
+ ...recipient.unprotectedHeader
1896
+ };
1897
+ const { alg } = joseHeader;
1898
+ if (typeof alg !== "string" || !alg) {
1899
+ throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
1900
+ }
1901
+ if (alg === "dir" || alg === "ECDH-ES") {
1902
+ throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
1903
+ }
1904
+ if (typeof joseHeader.enc !== "string" || !joseHeader.enc) {
1905
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
1906
+ }
1907
+ if (!enc) {
1908
+ enc = joseHeader.enc;
1909
+ } else if (enc !== joseHeader.enc) {
1910
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
1911
+ }
1912
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), recipient.options.crit, this._protectedHeader, joseHeader);
1913
+ if (joseHeader.zip !== void 0) {
1914
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
1915
+ }
1916
+ }
1917
+ const cek = cek_default(enc);
1918
+ const jwe = {
1919
+ ciphertext: "",
1920
+ iv: "",
1921
+ recipients: [],
1922
+ tag: ""
1923
+ };
1924
+ for (let i = 0; i < this._recipients.length; i++) {
1925
+ const recipient = this._recipients[i];
1926
+ const target = {};
1927
+ jwe.recipients.push(target);
1928
+ const joseHeader = {
1929
+ ...this._protectedHeader,
1930
+ ...this._unprotectedHeader,
1931
+ ...recipient.unprotectedHeader
1932
+ };
1933
+ const p2c = joseHeader.alg.startsWith("PBES2") ? 2048 + i : void 0;
1934
+ if (i === 0) {
1935
+ const flattened = await new FlattenedEncrypt(this._plaintext).setAdditionalAuthenticatedData(this._aad).setContentEncryptionKey(cek).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).setKeyManagementParameters({ p2c }).encrypt(recipient.key, {
1936
+ ...recipient.options,
1937
+ [unprotected]: true
1938
+ });
1939
+ jwe.ciphertext = flattened.ciphertext;
1940
+ jwe.iv = flattened.iv;
1941
+ jwe.tag = flattened.tag;
1942
+ if (flattened.aad)
1943
+ jwe.aad = flattened.aad;
1944
+ if (flattened.protected)
1945
+ jwe.protected = flattened.protected;
1946
+ if (flattened.unprotected)
1947
+ jwe.unprotected = flattened.unprotected;
1948
+ target.encrypted_key = flattened.encrypted_key;
1949
+ if (flattened.header)
1950
+ target.header = flattened.header;
1951
+ continue;
1952
+ }
1953
+ const { encryptedKey, parameters } = await encrypt_key_management_default(recipient.unprotectedHeader?.alg || this._protectedHeader?.alg || this._unprotectedHeader?.alg, enc, recipient.key, cek, { p2c });
1954
+ target.encrypted_key = encode(encryptedKey);
1955
+ if (recipient.unprotectedHeader || parameters)
1956
+ target.header = { ...recipient.unprotectedHeader, ...parameters };
1957
+ }
1958
+ return jwe;
1959
+ }
1960
+ };
1961
+
1962
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js
1963
+ import * as crypto3 from "crypto";
1964
+ import { promisify as promisify4 } from "util";
1965
+
1966
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js
1967
+ function dsaDigest(alg) {
1968
+ switch (alg) {
1969
+ case "PS256":
1970
+ case "RS256":
1971
+ case "ES256":
1972
+ case "ES256K":
1973
+ return "sha256";
1974
+ case "PS384":
1975
+ case "RS384":
1976
+ case "ES384":
1977
+ return "sha384";
1978
+ case "PS512":
1979
+ case "RS512":
1980
+ case "ES512":
1981
+ return "sha512";
1982
+ case "Ed25519":
1983
+ case "EdDSA":
1984
+ return void 0;
1985
+ default:
1986
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
1987
+ }
1988
+ }
1989
+
1990
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js
1991
+ import { constants as constants2, KeyObject as KeyObject11 } from "crypto";
1992
+ var ecCurveAlgMap = /* @__PURE__ */ new Map([
1993
+ ["ES256", "P-256"],
1994
+ ["ES256K", "secp256k1"],
1995
+ ["ES384", "P-384"],
1996
+ ["ES512", "P-521"]
1997
+ ]);
1998
+ function keyForCrypto(alg, key) {
1999
+ let asymmetricKeyType;
2000
+ let asymmetricKeyDetails;
2001
+ let isJWK2;
2002
+ if (key instanceof KeyObject11) {
2003
+ asymmetricKeyType = key.asymmetricKeyType;
2004
+ asymmetricKeyDetails = key.asymmetricKeyDetails;
2005
+ } else {
2006
+ isJWK2 = true;
2007
+ switch (key.kty) {
2008
+ case "RSA":
2009
+ asymmetricKeyType = "rsa";
2010
+ break;
2011
+ case "EC":
2012
+ asymmetricKeyType = "ec";
2013
+ break;
2014
+ case "OKP": {
2015
+ if (key.crv === "Ed25519") {
2016
+ asymmetricKeyType = "ed25519";
2017
+ break;
2018
+ }
2019
+ if (key.crv === "Ed448") {
2020
+ asymmetricKeyType = "ed448";
2021
+ break;
2022
+ }
2023
+ throw new TypeError("Invalid key for this operation, its crv must be Ed25519 or Ed448");
2024
+ }
2025
+ default:
2026
+ throw new TypeError("Invalid key for this operation, its kty must be RSA, OKP, or EC");
2027
+ }
2028
+ }
2029
+ let options;
2030
+ switch (alg) {
2031
+ case "Ed25519":
2032
+ if (asymmetricKeyType !== "ed25519") {
2033
+ throw new TypeError(`Invalid key for this operation, its asymmetricKeyType must be ed25519`);
2034
+ }
2035
+ break;
2036
+ case "EdDSA":
2037
+ if (!["ed25519", "ed448"].includes(asymmetricKeyType)) {
2038
+ throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be ed25519 or ed448");
2039
+ }
2040
+ break;
2041
+ case "RS256":
2042
+ case "RS384":
2043
+ case "RS512":
2044
+ if (asymmetricKeyType !== "rsa") {
2045
+ throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be rsa");
2046
+ }
2047
+ check_key_length_default(key, alg);
2048
+ break;
2049
+ case "PS256":
2050
+ case "PS384":
2051
+ case "PS512":
2052
+ if (asymmetricKeyType === "rsa-pss") {
2053
+ const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = asymmetricKeyDetails;
2054
+ const length = parseInt(alg.slice(-3), 10);
2055
+ if (hashAlgorithm !== void 0 && (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm)) {
2056
+ throw new TypeError(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of "alg" ${alg}`);
2057
+ }
2058
+ if (saltLength !== void 0 && saltLength > length >> 3) {
2059
+ throw new TypeError(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of "alg" ${alg}`);
2060
+ }
2061
+ } else if (asymmetricKeyType !== "rsa") {
2062
+ throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss");
2063
+ }
2064
+ check_key_length_default(key, alg);
2065
+ options = {
2066
+ padding: constants2.RSA_PKCS1_PSS_PADDING,
2067
+ saltLength: constants2.RSA_PSS_SALTLEN_DIGEST
2068
+ };
2069
+ break;
2070
+ case "ES256":
2071
+ case "ES256K":
2072
+ case "ES384":
2073
+ case "ES512": {
2074
+ if (asymmetricKeyType !== "ec") {
2075
+ throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be ec");
2076
+ }
2077
+ const actual = get_named_curve_default(key);
2078
+ const expected = ecCurveAlgMap.get(alg);
2079
+ if (actual !== expected) {
2080
+ throw new TypeError(`Invalid key curve for the algorithm, its curve must be ${expected}, got ${actual}`);
2081
+ }
2082
+ options = { dsaEncoding: "ieee-p1363" };
2083
+ break;
2084
+ }
2085
+ default:
2086
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
2087
+ }
2088
+ if (isJWK2) {
2089
+ return { format: "jwk", key, ...options };
2090
+ }
2091
+ return options ? { ...options, key } : key;
2092
+ }
2093
+
2094
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js
2095
+ import * as crypto2 from "crypto";
2096
+ import { promisify as promisify3 } from "util";
2097
+
2098
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js
2099
+ function hmacDigest(alg) {
2100
+ switch (alg) {
2101
+ case "HS256":
2102
+ return "sha256";
2103
+ case "HS384":
2104
+ return "sha384";
2105
+ case "HS512":
2106
+ return "sha512";
2107
+ default:
2108
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
2109
+ }
2110
+ }
2111
+
2112
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js
2113
+ import { KeyObject as KeyObject12, createSecretKey as createSecretKey2 } from "crypto";
2114
+ function getSignVerifyKey(alg, key, usage) {
2115
+ if (key instanceof Uint8Array) {
2116
+ if (!alg.startsWith("HS")) {
2117
+ throw new TypeError(invalid_key_input_default(key, ...types3));
2118
+ }
2119
+ return createSecretKey2(key);
2120
+ }
2121
+ if (key instanceof KeyObject12) {
2122
+ return key;
2123
+ }
2124
+ if (isCryptoKey(key)) {
2125
+ checkSigCryptoKey(key, alg, usage);
2126
+ return KeyObject12.from(key);
2127
+ }
2128
+ if (isJWK(key)) {
2129
+ if (alg.startsWith("HS")) {
2130
+ return createSecretKey2(Buffer.from(key.k, "base64url"));
2131
+ }
2132
+ return key;
2133
+ }
2134
+ throw new TypeError(invalid_key_input_default(key, ...types3, "Uint8Array", "JSON Web Key"));
2135
+ }
2136
+
2137
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js
2138
+ var oneShotSign = promisify3(crypto2.sign);
2139
+ var sign2 = async (alg, key, data) => {
2140
+ const k = getSignVerifyKey(alg, key, "sign");
2141
+ if (alg.startsWith("HS")) {
2142
+ const hmac = crypto2.createHmac(hmacDigest(alg), k);
2143
+ hmac.update(data);
2144
+ return hmac.digest();
2145
+ }
2146
+ return oneShotSign(dsaDigest(alg), data, keyForCrypto(alg, k));
2147
+ };
2148
+ var sign_default = sign2;
2149
+
2150
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js
2151
+ var oneShotVerify = promisify4(crypto3.verify);
2152
+ var verify2 = async (alg, key, signature, data) => {
2153
+ const k = getSignVerifyKey(alg, key, "verify");
2154
+ if (alg.startsWith("HS")) {
2155
+ const expected = await sign_default(alg, k, data);
2156
+ const actual = signature;
2157
+ try {
2158
+ return crypto3.timingSafeEqual(actual, expected);
2159
+ } catch {
2160
+ return false;
2161
+ }
2162
+ }
2163
+ const algorithm = dsaDigest(alg);
2164
+ const keyInput = keyForCrypto(alg, k);
2165
+ try {
2166
+ return await oneShotVerify(algorithm, data, keyInput, signature);
2167
+ } catch {
2168
+ return false;
2169
+ }
2170
+ };
2171
+ var verify_default = verify2;
2172
+
2173
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js
2174
+ async function flattenedVerify(jws, key, options) {
2175
+ if (!isObject(jws)) {
2176
+ throw new JWSInvalid("Flattened JWS must be an object");
2177
+ }
2178
+ if (jws.protected === void 0 && jws.header === void 0) {
2179
+ throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
2180
+ }
2181
+ if (jws.protected !== void 0 && typeof jws.protected !== "string") {
2182
+ throw new JWSInvalid("JWS Protected Header incorrect type");
2183
+ }
2184
+ if (jws.payload === void 0) {
2185
+ throw new JWSInvalid("JWS Payload missing");
2186
+ }
2187
+ if (typeof jws.signature !== "string") {
2188
+ throw new JWSInvalid("JWS Signature missing or incorrect type");
2189
+ }
2190
+ if (jws.header !== void 0 && !isObject(jws.header)) {
2191
+ throw new JWSInvalid("JWS Unprotected Header incorrect type");
2192
+ }
2193
+ let parsedProt = {};
2194
+ if (jws.protected) {
2195
+ try {
2196
+ const protectedHeader = decode(jws.protected);
2197
+ parsedProt = JSON.parse(decoder.decode(protectedHeader));
2198
+ } catch {
2199
+ throw new JWSInvalid("JWS Protected Header is invalid");
2200
+ }
2201
+ }
2202
+ if (!is_disjoint_default(parsedProt, jws.header)) {
2203
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
2204
+ }
2205
+ const joseHeader = {
2206
+ ...parsedProt,
2207
+ ...jws.header
2208
+ };
2209
+ const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
2210
+ let b64 = true;
2211
+ if (extensions.has("b64")) {
2212
+ b64 = parsedProt.b64;
2213
+ if (typeof b64 !== "boolean") {
2214
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
2215
+ }
2216
+ }
2217
+ const { alg } = joseHeader;
2218
+ if (typeof alg !== "string" || !alg) {
2219
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
2220
+ }
2221
+ const algorithms = options && validate_algorithms_default("algorithms", options.algorithms);
2222
+ if (algorithms && !algorithms.has(alg)) {
2223
+ throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
2224
+ }
2225
+ if (b64) {
2226
+ if (typeof jws.payload !== "string") {
2227
+ throw new JWSInvalid("JWS Payload must be a string");
2228
+ }
2229
+ } else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
2230
+ throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
2231
+ }
2232
+ let resolvedKey = false;
2233
+ if (typeof key === "function") {
2234
+ key = await key(parsedProt, jws);
2235
+ resolvedKey = true;
2236
+ checkKeyTypeWithJwk(alg, key, "verify");
2237
+ if (isJWK(key)) {
2238
+ key = await importJWK(key, alg);
2239
+ }
2240
+ } else {
2241
+ checkKeyTypeWithJwk(alg, key, "verify");
2242
+ }
2243
+ const data = concat(encoder.encode(jws.protected ?? ""), encoder.encode("."), typeof jws.payload === "string" ? encoder.encode(jws.payload) : jws.payload);
2244
+ let signature;
2245
+ try {
2246
+ signature = decode(jws.signature);
2247
+ } catch {
2248
+ throw new JWSInvalid("Failed to base64url decode the signature");
2249
+ }
2250
+ const verified = await verify_default(alg, key, signature, data);
2251
+ if (!verified) {
2252
+ throw new JWSSignatureVerificationFailed();
2253
+ }
2254
+ let payload;
2255
+ if (b64) {
2256
+ try {
2257
+ payload = decode(jws.payload);
2258
+ } catch {
2259
+ throw new JWSInvalid("Failed to base64url decode the payload");
2260
+ }
2261
+ } else if (typeof jws.payload === "string") {
2262
+ payload = encoder.encode(jws.payload);
2263
+ } else {
2264
+ payload = jws.payload;
2265
+ }
2266
+ const result = { payload };
2267
+ if (jws.protected !== void 0) {
2268
+ result.protectedHeader = parsedProt;
2269
+ }
2270
+ if (jws.header !== void 0) {
2271
+ result.unprotectedHeader = jws.header;
2272
+ }
2273
+ if (resolvedKey) {
2274
+ return { ...result, key };
2275
+ }
2276
+ return result;
2277
+ }
2278
+
2279
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.js
2280
+ async function compactVerify(jws, key, options) {
2281
+ if (jws instanceof Uint8Array) {
2282
+ jws = decoder.decode(jws);
2283
+ }
2284
+ if (typeof jws !== "string") {
2285
+ throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
2286
+ }
2287
+ const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
2288
+ if (length !== 3) {
2289
+ throw new JWSInvalid("Invalid Compact JWS");
2290
+ }
2291
+ const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
2292
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
2293
+ if (typeof key === "function") {
2294
+ return { ...result, key: verified.key };
2295
+ }
2296
+ return result;
2297
+ }
2298
+
2299
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/general/verify.js
2300
+ async function generalVerify(jws, key, options) {
2301
+ if (!isObject(jws)) {
2302
+ throw new JWSInvalid("General JWS must be an object");
2303
+ }
2304
+ if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
2305
+ throw new JWSInvalid("JWS Signatures missing or incorrect type");
2306
+ }
2307
+ for (const signature of jws.signatures) {
2308
+ try {
2309
+ return await flattenedVerify({
2310
+ header: signature.header,
2311
+ payload: jws.payload,
2312
+ protected: signature.protected,
2313
+ signature: signature.signature
2314
+ }, key, options);
2315
+ } catch {
2316
+ }
2317
+ }
2318
+ throw new JWSSignatureVerificationFailed();
2319
+ }
2320
+
2321
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js
2322
+ var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
2323
+
2324
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js
2325
+ var minute = 60;
2326
+ var hour = minute * 60;
2327
+ var day = hour * 24;
2328
+ var week = day * 7;
2329
+ var year = day * 365.25;
2330
+ 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;
2331
+ var secs_default = (str) => {
2332
+ const matched = REGEX.exec(str);
2333
+ if (!matched || matched[4] && matched[1]) {
2334
+ throw new TypeError("Invalid time period format");
2335
+ }
2336
+ const value = parseFloat(matched[2]);
2337
+ const unit = matched[3].toLowerCase();
2338
+ let numericDate;
2339
+ switch (unit) {
2340
+ case "sec":
2341
+ case "secs":
2342
+ case "second":
2343
+ case "seconds":
2344
+ case "s":
2345
+ numericDate = Math.round(value);
2346
+ break;
2347
+ case "minute":
2348
+ case "minutes":
2349
+ case "min":
2350
+ case "mins":
2351
+ case "m":
2352
+ numericDate = Math.round(value * minute);
2353
+ break;
2354
+ case "hour":
2355
+ case "hours":
2356
+ case "hr":
2357
+ case "hrs":
2358
+ case "h":
2359
+ numericDate = Math.round(value * hour);
2360
+ break;
2361
+ case "day":
2362
+ case "days":
2363
+ case "d":
2364
+ numericDate = Math.round(value * day);
2365
+ break;
2366
+ case "week":
2367
+ case "weeks":
2368
+ case "w":
2369
+ numericDate = Math.round(value * week);
2370
+ break;
2371
+ default:
2372
+ numericDate = Math.round(value * year);
2373
+ break;
2374
+ }
2375
+ if (matched[1] === "-" || matched[4] === "ago") {
2376
+ return -numericDate;
2377
+ }
2378
+ return numericDate;
2379
+ };
2380
+
2381
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js
2382
+ var normalizeTyp = (value) => value.toLowerCase().replace(/^application\//, "");
2383
+ var checkAudiencePresence = (audPayload, audOption) => {
2384
+ if (typeof audPayload === "string") {
2385
+ return audOption.includes(audPayload);
2386
+ }
2387
+ if (Array.isArray(audPayload)) {
2388
+ return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
2389
+ }
2390
+ return false;
2391
+ };
2392
+ var jwt_claims_set_default = (protectedHeader, encodedPayload, options = {}) => {
2393
+ let payload;
2394
+ try {
2395
+ payload = JSON.parse(decoder.decode(encodedPayload));
2396
+ } catch {
2397
+ }
2398
+ if (!isObject(payload)) {
2399
+ throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
2400
+ }
2401
+ const { typ } = options;
2402
+ if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
2403
+ throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
2404
+ }
2405
+ const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
2406
+ const presenceCheck = [...requiredClaims];
2407
+ if (maxTokenAge !== void 0)
2408
+ presenceCheck.push("iat");
2409
+ if (audience !== void 0)
2410
+ presenceCheck.push("aud");
2411
+ if (subject !== void 0)
2412
+ presenceCheck.push("sub");
2413
+ if (issuer !== void 0)
2414
+ presenceCheck.push("iss");
2415
+ for (const claim of new Set(presenceCheck.reverse())) {
2416
+ if (!(claim in payload)) {
2417
+ throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
2418
+ }
2419
+ }
2420
+ if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
2421
+ throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
2422
+ }
2423
+ if (subject && payload.sub !== subject) {
2424
+ throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
2425
+ }
2426
+ if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
2427
+ throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
2428
+ }
2429
+ let tolerance;
2430
+ switch (typeof options.clockTolerance) {
2431
+ case "string":
2432
+ tolerance = secs_default(options.clockTolerance);
2433
+ break;
2434
+ case "number":
2435
+ tolerance = options.clockTolerance;
2436
+ break;
2437
+ case "undefined":
2438
+ tolerance = 0;
2439
+ break;
2440
+ default:
2441
+ throw new TypeError("Invalid clockTolerance option type");
2442
+ }
2443
+ const { currentDate } = options;
2444
+ const now = epoch_default(currentDate || /* @__PURE__ */ new Date());
2445
+ if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
2446
+ throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
2447
+ }
2448
+ if (payload.nbf !== void 0) {
2449
+ if (typeof payload.nbf !== "number") {
2450
+ throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
2451
+ }
2452
+ if (payload.nbf > now + tolerance) {
2453
+ throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
2454
+ }
2455
+ }
2456
+ if (payload.exp !== void 0) {
2457
+ if (typeof payload.exp !== "number") {
2458
+ throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
2459
+ }
2460
+ if (payload.exp <= now - tolerance) {
2461
+ throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
2462
+ }
2463
+ }
2464
+ if (maxTokenAge) {
2465
+ const age = now - payload.iat;
2466
+ const max = typeof maxTokenAge === "number" ? maxTokenAge : secs_default(maxTokenAge);
2467
+ if (age - tolerance > max) {
2468
+ throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
2469
+ }
2470
+ if (age < 0 - tolerance) {
2471
+ throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
2472
+ }
2473
+ }
2474
+ return payload;
2475
+ };
2476
+
2477
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js
2478
+ async function jwtVerify(jwt, key, options) {
2479
+ const verified = await compactVerify(jwt, key, options);
2480
+ if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
2481
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
2482
+ }
2483
+ const payload = jwt_claims_set_default(verified.protectedHeader, verified.payload, options);
2484
+ const result = { payload, protectedHeader: verified.protectedHeader };
2485
+ if (typeof key === "function") {
2486
+ return { ...result, key: verified.key };
2487
+ }
2488
+ return result;
2489
+ }
2490
+
2491
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/decrypt.js
2492
+ async function jwtDecrypt(jwt, key, options) {
2493
+ const decrypted = await compactDecrypt(jwt, key, options);
2494
+ const payload = jwt_claims_set_default(decrypted.protectedHeader, decrypted.plaintext, options);
2495
+ const { protectedHeader } = decrypted;
2496
+ if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
2497
+ throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
2498
+ }
2499
+ if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
2500
+ throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
2501
+ }
2502
+ if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
2503
+ throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
2504
+ }
2505
+ const result = { payload, protectedHeader };
2506
+ if (typeof key === "function") {
2507
+ return { ...result, key: decrypted.key };
2508
+ }
2509
+ return result;
2510
+ }
2511
+
2512
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwe/compact/encrypt.js
2513
+ var CompactEncrypt = class {
2514
+ _flattened;
2515
+ constructor(plaintext) {
2516
+ this._flattened = new FlattenedEncrypt(plaintext);
2517
+ }
2518
+ setContentEncryptionKey(cek) {
2519
+ this._flattened.setContentEncryptionKey(cek);
2520
+ return this;
2521
+ }
2522
+ setInitializationVector(iv) {
2523
+ this._flattened.setInitializationVector(iv);
2524
+ return this;
2525
+ }
2526
+ setProtectedHeader(protectedHeader) {
2527
+ this._flattened.setProtectedHeader(protectedHeader);
2528
+ return this;
2529
+ }
2530
+ setKeyManagementParameters(parameters) {
2531
+ this._flattened.setKeyManagementParameters(parameters);
2532
+ return this;
2533
+ }
2534
+ async encrypt(key, options) {
2535
+ const jwe = await this._flattened.encrypt(key, options);
2536
+ return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
2537
+ }
2538
+ };
2539
+
2540
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/sign.js
2541
+ var FlattenedSign = class {
2542
+ _payload;
2543
+ _protectedHeader;
2544
+ _unprotectedHeader;
2545
+ constructor(payload) {
2546
+ if (!(payload instanceof Uint8Array)) {
2547
+ throw new TypeError("payload must be an instance of Uint8Array");
2548
+ }
2549
+ this._payload = payload;
2550
+ }
2551
+ setProtectedHeader(protectedHeader) {
2552
+ if (this._protectedHeader) {
2553
+ throw new TypeError("setProtectedHeader can only be called once");
2554
+ }
2555
+ this._protectedHeader = protectedHeader;
2556
+ return this;
2557
+ }
2558
+ setUnprotectedHeader(unprotectedHeader) {
2559
+ if (this._unprotectedHeader) {
2560
+ throw new TypeError("setUnprotectedHeader can only be called once");
2561
+ }
2562
+ this._unprotectedHeader = unprotectedHeader;
2563
+ return this;
2564
+ }
2565
+ async sign(key, options) {
2566
+ if (!this._protectedHeader && !this._unprotectedHeader) {
2567
+ throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
2568
+ }
2569
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader)) {
2570
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
2571
+ }
2572
+ const joseHeader = {
2573
+ ...this._protectedHeader,
2574
+ ...this._unprotectedHeader
2575
+ };
2576
+ const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this._protectedHeader, joseHeader);
2577
+ let b64 = true;
2578
+ if (extensions.has("b64")) {
2579
+ b64 = this._protectedHeader.b64;
2580
+ if (typeof b64 !== "boolean") {
2581
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
2582
+ }
2583
+ }
2584
+ const { alg } = joseHeader;
2585
+ if (typeof alg !== "string" || !alg) {
2586
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
2587
+ }
2588
+ checkKeyTypeWithJwk(alg, key, "sign");
2589
+ let payload = this._payload;
2590
+ if (b64) {
2591
+ payload = encoder.encode(encode(payload));
2592
+ }
2593
+ let protectedHeader;
2594
+ if (this._protectedHeader) {
2595
+ protectedHeader = encoder.encode(encode(JSON.stringify(this._protectedHeader)));
2596
+ } else {
2597
+ protectedHeader = encoder.encode("");
2598
+ }
2599
+ const data = concat(protectedHeader, encoder.encode("."), payload);
2600
+ const signature = await sign_default(alg, key, data);
2601
+ const jws = {
2602
+ signature: encode(signature),
2603
+ payload: ""
2604
+ };
2605
+ if (b64) {
2606
+ jws.payload = decoder.decode(payload);
2607
+ }
2608
+ if (this._unprotectedHeader) {
2609
+ jws.header = this._unprotectedHeader;
2610
+ }
2611
+ if (this._protectedHeader) {
2612
+ jws.protected = decoder.decode(protectedHeader);
2613
+ }
2614
+ return jws;
2615
+ }
2616
+ };
2617
+
2618
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/sign.js
2619
+ var CompactSign = class {
2620
+ _flattened;
2621
+ constructor(payload) {
2622
+ this._flattened = new FlattenedSign(payload);
2623
+ }
2624
+ setProtectedHeader(protectedHeader) {
2625
+ this._flattened.setProtectedHeader(protectedHeader);
2626
+ return this;
2627
+ }
2628
+ async sign(key, options) {
2629
+ const jws = await this._flattened.sign(key, options);
2630
+ if (jws.payload === void 0) {
2631
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
2632
+ }
2633
+ return `${jws.protected}.${jws.payload}.${jws.signature}`;
2634
+ }
2635
+ };
2636
+
2637
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/general/sign.js
2638
+ var IndividualSignature = class {
2639
+ parent;
2640
+ protectedHeader;
2641
+ unprotectedHeader;
2642
+ options;
2643
+ key;
2644
+ constructor(sig, key, options) {
2645
+ this.parent = sig;
2646
+ this.key = key;
2647
+ this.options = options;
2648
+ }
2649
+ setProtectedHeader(protectedHeader) {
2650
+ if (this.protectedHeader) {
2651
+ throw new TypeError("setProtectedHeader can only be called once");
2652
+ }
2653
+ this.protectedHeader = protectedHeader;
2654
+ return this;
2655
+ }
2656
+ setUnprotectedHeader(unprotectedHeader) {
2657
+ if (this.unprotectedHeader) {
2658
+ throw new TypeError("setUnprotectedHeader can only be called once");
2659
+ }
2660
+ this.unprotectedHeader = unprotectedHeader;
2661
+ return this;
2662
+ }
2663
+ addSignature(...args) {
2664
+ return this.parent.addSignature(...args);
2665
+ }
2666
+ sign(...args) {
2667
+ return this.parent.sign(...args);
2668
+ }
2669
+ done() {
2670
+ return this.parent;
2671
+ }
2672
+ };
2673
+ var GeneralSign = class {
2674
+ _payload;
2675
+ _signatures = [];
2676
+ constructor(payload) {
2677
+ this._payload = payload;
2678
+ }
2679
+ addSignature(key, options) {
2680
+ const signature = new IndividualSignature(this, key, options);
2681
+ this._signatures.push(signature);
2682
+ return signature;
2683
+ }
2684
+ async sign() {
2685
+ if (!this._signatures.length) {
2686
+ throw new JWSInvalid("at least one signature must be added");
2687
+ }
2688
+ const jws = {
2689
+ signatures: [],
2690
+ payload: ""
2691
+ };
2692
+ for (let i = 0; i < this._signatures.length; i++) {
2693
+ const signature = this._signatures[i];
2694
+ const flattened = new FlattenedSign(this._payload);
2695
+ flattened.setProtectedHeader(signature.protectedHeader);
2696
+ flattened.setUnprotectedHeader(signature.unprotectedHeader);
2697
+ const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
2698
+ if (i === 0) {
2699
+ jws.payload = payload;
2700
+ } else if (jws.payload !== payload) {
2701
+ throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
2702
+ }
2703
+ jws.signatures.push(rest);
2704
+ }
2705
+ return jws;
2706
+ }
2707
+ };
2708
+
2709
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/produce.js
2710
+ function validateInput(label, input) {
2711
+ if (!Number.isFinite(input)) {
2712
+ throw new TypeError(`Invalid ${label} input`);
2713
+ }
2714
+ return input;
2715
+ }
2716
+ var ProduceJWT = class {
2717
+ _payload;
2718
+ constructor(payload = {}) {
2719
+ if (!isObject(payload)) {
2720
+ throw new TypeError("JWT Claims Set MUST be an object");
2721
+ }
2722
+ this._payload = payload;
2723
+ }
2724
+ setIssuer(issuer) {
2725
+ this._payload = { ...this._payload, iss: issuer };
2726
+ return this;
2727
+ }
2728
+ setSubject(subject) {
2729
+ this._payload = { ...this._payload, sub: subject };
2730
+ return this;
2731
+ }
2732
+ setAudience(audience) {
2733
+ this._payload = { ...this._payload, aud: audience };
2734
+ return this;
2735
+ }
2736
+ setJti(jwtId) {
2737
+ this._payload = { ...this._payload, jti: jwtId };
2738
+ return this;
2739
+ }
2740
+ setNotBefore(input) {
2741
+ if (typeof input === "number") {
2742
+ this._payload = { ...this._payload, nbf: validateInput("setNotBefore", input) };
2743
+ } else if (input instanceof Date) {
2744
+ this._payload = { ...this._payload, nbf: validateInput("setNotBefore", epoch_default(input)) };
2745
+ } else {
2746
+ this._payload = { ...this._payload, nbf: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
2747
+ }
2748
+ return this;
2749
+ }
2750
+ setExpirationTime(input) {
2751
+ if (typeof input === "number") {
2752
+ this._payload = { ...this._payload, exp: validateInput("setExpirationTime", input) };
2753
+ } else if (input instanceof Date) {
2754
+ this._payload = { ...this._payload, exp: validateInput("setExpirationTime", epoch_default(input)) };
2755
+ } else {
2756
+ this._payload = { ...this._payload, exp: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
2757
+ }
2758
+ return this;
2759
+ }
2760
+ setIssuedAt(input) {
2761
+ if (typeof input === "undefined") {
2762
+ this._payload = { ...this._payload, iat: epoch_default(/* @__PURE__ */ new Date()) };
2763
+ } else if (input instanceof Date) {
2764
+ this._payload = { ...this._payload, iat: validateInput("setIssuedAt", epoch_default(input)) };
2765
+ } else if (typeof input === "string") {
2766
+ this._payload = {
2767
+ ...this._payload,
2768
+ iat: validateInput("setIssuedAt", epoch_default(/* @__PURE__ */ new Date()) + secs_default(input))
2769
+ };
2770
+ } else {
2771
+ this._payload = { ...this._payload, iat: validateInput("setIssuedAt", input) };
2772
+ }
2773
+ return this;
2774
+ }
2775
+ };
2776
+
2777
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/sign.js
2778
+ var SignJWT = class extends ProduceJWT {
2779
+ _protectedHeader;
2780
+ setProtectedHeader(protectedHeader) {
2781
+ this._protectedHeader = protectedHeader;
2782
+ return this;
2783
+ }
2784
+ async sign(key, options) {
2785
+ const sig = new CompactSign(encoder.encode(JSON.stringify(this._payload)));
2786
+ sig.setProtectedHeader(this._protectedHeader);
2787
+ if (Array.isArray(this._protectedHeader?.crit) && this._protectedHeader.crit.includes("b64") && this._protectedHeader.b64 === false) {
2788
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
2789
+ }
2790
+ return sig.sign(key, options);
2791
+ }
2792
+ };
2793
+
2794
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/encrypt.js
2795
+ var EncryptJWT = class extends ProduceJWT {
2796
+ _cek;
2797
+ _iv;
2798
+ _keyManagementParameters;
2799
+ _protectedHeader;
2800
+ _replicateIssuerAsHeader;
2801
+ _replicateSubjectAsHeader;
2802
+ _replicateAudienceAsHeader;
2803
+ setProtectedHeader(protectedHeader) {
2804
+ if (this._protectedHeader) {
2805
+ throw new TypeError("setProtectedHeader can only be called once");
2806
+ }
2807
+ this._protectedHeader = protectedHeader;
2808
+ return this;
2809
+ }
2810
+ setKeyManagementParameters(parameters) {
2811
+ if (this._keyManagementParameters) {
2812
+ throw new TypeError("setKeyManagementParameters can only be called once");
2813
+ }
2814
+ this._keyManagementParameters = parameters;
2815
+ return this;
2816
+ }
2817
+ setContentEncryptionKey(cek) {
2818
+ if (this._cek) {
2819
+ throw new TypeError("setContentEncryptionKey can only be called once");
2820
+ }
2821
+ this._cek = cek;
2822
+ return this;
2823
+ }
2824
+ setInitializationVector(iv) {
2825
+ if (this._iv) {
2826
+ throw new TypeError("setInitializationVector can only be called once");
2827
+ }
2828
+ this._iv = iv;
2829
+ return this;
2830
+ }
2831
+ replicateIssuerAsHeader() {
2832
+ this._replicateIssuerAsHeader = true;
2833
+ return this;
2834
+ }
2835
+ replicateSubjectAsHeader() {
2836
+ this._replicateSubjectAsHeader = true;
2837
+ return this;
2838
+ }
2839
+ replicateAudienceAsHeader() {
2840
+ this._replicateAudienceAsHeader = true;
2841
+ return this;
2842
+ }
2843
+ async encrypt(key, options) {
2844
+ const enc = new CompactEncrypt(encoder.encode(JSON.stringify(this._payload)));
2845
+ if (this._replicateIssuerAsHeader) {
2846
+ this._protectedHeader = { ...this._protectedHeader, iss: this._payload.iss };
2847
+ }
2848
+ if (this._replicateSubjectAsHeader) {
2849
+ this._protectedHeader = { ...this._protectedHeader, sub: this._payload.sub };
2850
+ }
2851
+ if (this._replicateAudienceAsHeader) {
2852
+ this._protectedHeader = { ...this._protectedHeader, aud: this._payload.aud };
2853
+ }
2854
+ enc.setProtectedHeader(this._protectedHeader);
2855
+ if (this._iv) {
2856
+ enc.setInitializationVector(this._iv);
2857
+ }
2858
+ if (this._cek) {
2859
+ enc.setContentEncryptionKey(this._cek);
2860
+ }
2861
+ if (this._keyManagementParameters) {
2862
+ enc.setKeyManagementParameters(this._keyManagementParameters);
2863
+ }
2864
+ return enc.encrypt(key, options);
2865
+ }
2866
+ };
2867
+
2868
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwk/thumbprint.js
2869
+ var check = (value, description) => {
2870
+ if (typeof value !== "string" || !value) {
2871
+ throw new JWKInvalid(`${description} missing or invalid`);
2872
+ }
2873
+ };
2874
+ async function calculateJwkThumbprint(jwk, digestAlgorithm) {
2875
+ if (!isObject(jwk)) {
2876
+ throw new TypeError("JWK must be an object");
2877
+ }
2878
+ digestAlgorithm ??= "sha256";
2879
+ if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
2880
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
2881
+ }
2882
+ let components;
2883
+ switch (jwk.kty) {
2884
+ case "EC":
2885
+ check(jwk.crv, '"crv" (Curve) Parameter');
2886
+ check(jwk.x, '"x" (X Coordinate) Parameter');
2887
+ check(jwk.y, '"y" (Y Coordinate) Parameter');
2888
+ components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
2889
+ break;
2890
+ case "OKP":
2891
+ check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
2892
+ check(jwk.x, '"x" (Public Key) Parameter');
2893
+ components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
2894
+ break;
2895
+ case "RSA":
2896
+ check(jwk.e, '"e" (Exponent) Parameter');
2897
+ check(jwk.n, '"n" (Modulus) Parameter');
2898
+ components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
2899
+ break;
2900
+ case "oct":
2901
+ check(jwk.k, '"k" (Key Value) Parameter');
2902
+ components = { k: jwk.k, kty: jwk.kty };
2903
+ break;
2904
+ default:
2905
+ throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
2906
+ }
2907
+ const data = encoder.encode(JSON.stringify(components));
2908
+ return encode(await digest_default(digestAlgorithm, data));
2909
+ }
2910
+ async function calculateJwkThumbprintUri(jwk, digestAlgorithm) {
2911
+ digestAlgorithm ??= "sha256";
2912
+ const thumbprint = await calculateJwkThumbprint(jwk, digestAlgorithm);
2913
+ return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
2914
+ }
2915
+
2916
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwk/embedded.js
2917
+ async function EmbeddedJWK(protectedHeader, token) {
2918
+ const joseHeader = {
2919
+ ...protectedHeader,
2920
+ ...token?.header
2921
+ };
2922
+ if (!isObject(joseHeader.jwk)) {
2923
+ throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
2924
+ }
2925
+ const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
2926
+ if (key instanceof Uint8Array || key.type !== "public") {
2927
+ throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
2928
+ }
2929
+ return key;
2930
+ }
2931
+
2932
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwks/local.js
2933
+ function getKtyFromAlg(alg) {
2934
+ switch (typeof alg === "string" && alg.slice(0, 2)) {
2935
+ case "RS":
2936
+ case "PS":
2937
+ return "RSA";
2938
+ case "ES":
2939
+ return "EC";
2940
+ case "Ed":
2941
+ return "OKP";
2942
+ default:
2943
+ throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
2944
+ }
2945
+ }
2946
+ function isJWKSLike(jwks) {
2947
+ return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
2948
+ }
2949
+ function isJWKLike(key) {
2950
+ return isObject(key);
2951
+ }
2952
+ function clone(obj) {
2953
+ if (typeof structuredClone === "function") {
2954
+ return structuredClone(obj);
2955
+ }
2956
+ return JSON.parse(JSON.stringify(obj));
2957
+ }
2958
+ var LocalJWKSet = class {
2959
+ _jwks;
2960
+ _cached = /* @__PURE__ */ new WeakMap();
2961
+ constructor(jwks) {
2962
+ if (!isJWKSLike(jwks)) {
2963
+ throw new JWKSInvalid("JSON Web Key Set malformed");
2964
+ }
2965
+ this._jwks = clone(jwks);
2966
+ }
2967
+ async getKey(protectedHeader, token) {
2968
+ const { alg, kid } = { ...protectedHeader, ...token?.header };
2969
+ const kty = getKtyFromAlg(alg);
2970
+ const candidates = this._jwks.keys.filter((jwk2) => {
2971
+ let candidate = kty === jwk2.kty;
2972
+ if (candidate && typeof kid === "string") {
2973
+ candidate = kid === jwk2.kid;
2974
+ }
2975
+ if (candidate && typeof jwk2.alg === "string") {
2976
+ candidate = alg === jwk2.alg;
2977
+ }
2978
+ if (candidate && typeof jwk2.use === "string") {
2979
+ candidate = jwk2.use === "sig";
2980
+ }
2981
+ if (candidate && Array.isArray(jwk2.key_ops)) {
2982
+ candidate = jwk2.key_ops.includes("verify");
2983
+ }
2984
+ if (candidate) {
2985
+ switch (alg) {
2986
+ case "ES256":
2987
+ candidate = jwk2.crv === "P-256";
2988
+ break;
2989
+ case "ES256K":
2990
+ candidate = jwk2.crv === "secp256k1";
2991
+ break;
2992
+ case "ES384":
2993
+ candidate = jwk2.crv === "P-384";
2994
+ break;
2995
+ case "ES512":
2996
+ candidate = jwk2.crv === "P-521";
2997
+ break;
2998
+ case "Ed25519":
2999
+ candidate = jwk2.crv === "Ed25519";
3000
+ break;
3001
+ case "EdDSA":
3002
+ candidate = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
3003
+ break;
3004
+ }
3005
+ }
3006
+ return candidate;
3007
+ });
3008
+ const { 0: jwk, length } = candidates;
3009
+ if (length === 0) {
3010
+ throw new JWKSNoMatchingKey();
3011
+ }
3012
+ if (length !== 1) {
3013
+ const error = new JWKSMultipleMatchingKeys();
3014
+ const { _cached } = this;
3015
+ error[Symbol.asyncIterator] = async function* () {
3016
+ for (const jwk2 of candidates) {
3017
+ try {
3018
+ yield await importWithAlgCache(_cached, jwk2, alg);
3019
+ } catch {
3020
+ }
3021
+ }
3022
+ };
3023
+ throw error;
3024
+ }
3025
+ return importWithAlgCache(this._cached, jwk, alg);
3026
+ }
3027
+ };
3028
+ async function importWithAlgCache(cache, jwk, alg) {
3029
+ const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
3030
+ if (cached[alg] === void 0) {
3031
+ const key = await importJWK({ ...jwk, ext: true }, alg);
3032
+ if (key instanceof Uint8Array || key.type !== "public") {
3033
+ throw new JWKSInvalid("JSON Web Key Set members must be public keys");
3034
+ }
3035
+ cached[alg] = key;
3036
+ }
3037
+ return cached[alg];
3038
+ }
3039
+ function createLocalJWKSet(jwks) {
3040
+ const set = new LocalJWKSet(jwks);
3041
+ const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
3042
+ Object.defineProperties(localJWKSet, {
3043
+ jwks: {
3044
+ value: () => clone(set._jwks),
3045
+ enumerable: true,
3046
+ configurable: false,
3047
+ writable: false
3048
+ }
3049
+ });
3050
+ return localJWKSet;
3051
+ }
3052
+
3053
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/fetch_jwks.js
3054
+ import * as http from "http";
3055
+ import * as https from "https";
3056
+ import { once } from "events";
3057
+ var fetchJwks = async (url, timeout, options) => {
3058
+ let get3;
3059
+ switch (url.protocol) {
3060
+ case "https:":
3061
+ get3 = https.get;
3062
+ break;
3063
+ case "http:":
3064
+ get3 = http.get;
3065
+ break;
3066
+ default:
3067
+ throw new TypeError("Unsupported URL protocol.");
3068
+ }
3069
+ const { agent, headers } = options;
3070
+ const req = get3(url.href, {
3071
+ agent,
3072
+ timeout,
3073
+ headers
3074
+ });
3075
+ const [response] = await Promise.race([once(req, "response"), once(req, "timeout")]);
3076
+ if (!response) {
3077
+ req.destroy();
3078
+ throw new JWKSTimeout();
3079
+ }
3080
+ if (response.statusCode !== 200) {
3081
+ throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
3082
+ }
3083
+ const parts = [];
3084
+ for await (const part of response) {
3085
+ parts.push(part);
3086
+ }
3087
+ try {
3088
+ return JSON.parse(decoder.decode(concat(...parts)));
3089
+ } catch {
3090
+ throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
3091
+ }
3092
+ };
3093
+ var fetch_jwks_default = fetchJwks;
3094
+
3095
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwks/remote.js
3096
+ function isCloudflareWorkers() {
3097
+ return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
3098
+ }
3099
+ var USER_AGENT;
3100
+ if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
3101
+ const NAME = "jose";
3102
+ const VERSION = "v5.10.0";
3103
+ USER_AGENT = `${NAME}/${VERSION}`;
3104
+ }
3105
+ var jwksCache = Symbol();
3106
+ function isFreshJwksCache(input, cacheMaxAge) {
3107
+ if (typeof input !== "object" || input === null) {
3108
+ return false;
3109
+ }
3110
+ if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) {
3111
+ return false;
3112
+ }
3113
+ if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) {
3114
+ return false;
3115
+ }
3116
+ return true;
3117
+ }
3118
+ var RemoteJWKSet = class {
3119
+ _url;
3120
+ _timeoutDuration;
3121
+ _cooldownDuration;
3122
+ _cacheMaxAge;
3123
+ _jwksTimestamp;
3124
+ _pendingFetch;
3125
+ _options;
3126
+ _local;
3127
+ _cache;
3128
+ constructor(url, options) {
3129
+ if (!(url instanceof URL)) {
3130
+ throw new TypeError("url must be an instance of URL");
3131
+ }
3132
+ this._url = new URL(url.href);
3133
+ this._options = { agent: options?.agent, headers: options?.headers };
3134
+ this._timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
3135
+ this._cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
3136
+ this._cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
3137
+ if (options?.[jwksCache] !== void 0) {
3138
+ this._cache = options?.[jwksCache];
3139
+ if (isFreshJwksCache(options?.[jwksCache], this._cacheMaxAge)) {
3140
+ this._jwksTimestamp = this._cache.uat;
3141
+ this._local = createLocalJWKSet(this._cache.jwks);
3142
+ }
3143
+ }
3144
+ }
3145
+ coolingDown() {
3146
+ return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cooldownDuration : false;
3147
+ }
3148
+ fresh() {
3149
+ return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cacheMaxAge : false;
3150
+ }
3151
+ async getKey(protectedHeader, token) {
3152
+ if (!this._local || !this.fresh()) {
3153
+ await this.reload();
3154
+ }
3155
+ try {
3156
+ return await this._local(protectedHeader, token);
3157
+ } catch (err) {
3158
+ if (err instanceof JWKSNoMatchingKey) {
3159
+ if (this.coolingDown() === false) {
3160
+ await this.reload();
3161
+ return this._local(protectedHeader, token);
3162
+ }
3163
+ }
3164
+ throw err;
3165
+ }
3166
+ }
3167
+ async reload() {
3168
+ if (this._pendingFetch && isCloudflareWorkers()) {
3169
+ this._pendingFetch = void 0;
3170
+ }
3171
+ const headers = new Headers(this._options.headers);
3172
+ if (USER_AGENT && !headers.has("User-Agent")) {
3173
+ headers.set("User-Agent", USER_AGENT);
3174
+ this._options.headers = Object.fromEntries(headers.entries());
3175
+ }
3176
+ this._pendingFetch ||= fetch_jwks_default(this._url, this._timeoutDuration, this._options).then((json) => {
3177
+ this._local = createLocalJWKSet(json);
3178
+ if (this._cache) {
3179
+ this._cache.uat = Date.now();
3180
+ this._cache.jwks = json;
3181
+ }
3182
+ this._jwksTimestamp = Date.now();
3183
+ this._pendingFetch = void 0;
3184
+ }).catch((err) => {
3185
+ this._pendingFetch = void 0;
3186
+ throw err;
3187
+ });
3188
+ await this._pendingFetch;
3189
+ }
3190
+ };
3191
+ function createRemoteJWKSet(url, options) {
3192
+ const set = new RemoteJWKSet(url, options);
3193
+ const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
3194
+ Object.defineProperties(remoteJWKSet, {
3195
+ coolingDown: {
3196
+ get: () => set.coolingDown(),
3197
+ enumerable: true,
3198
+ configurable: false
3199
+ },
3200
+ fresh: {
3201
+ get: () => set.fresh(),
3202
+ enumerable: true,
3203
+ configurable: false
3204
+ },
3205
+ reload: {
3206
+ value: () => set.reload(),
3207
+ enumerable: true,
3208
+ configurable: false,
3209
+ writable: false
3210
+ },
3211
+ reloading: {
3212
+ get: () => !!set._pendingFetch,
3213
+ enumerable: true,
3214
+ configurable: false
3215
+ },
3216
+ jwks: {
3217
+ value: () => set._local?.jwks(),
3218
+ enumerable: true,
3219
+ configurable: false,
3220
+ writable: false
3221
+ }
3222
+ });
3223
+ return remoteJWKSet;
3224
+ }
3225
+ var experimental_jwksCache = jwksCache;
3226
+
3227
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/unsecured.js
3228
+ var UnsecuredJWT = class extends ProduceJWT {
3229
+ encode() {
3230
+ const header = encode(JSON.stringify({ alg: "none" }));
3231
+ const payload = encode(JSON.stringify(this._payload));
3232
+ return `${header}.${payload}.`;
3233
+ }
3234
+ static decode(jwt, options) {
3235
+ if (typeof jwt !== "string") {
3236
+ throw new JWTInvalid("Unsecured JWT must be a string");
3237
+ }
3238
+ const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
3239
+ if (length !== 3 || signature !== "") {
3240
+ throw new JWTInvalid("Invalid Unsecured JWT");
3241
+ }
3242
+ let header;
3243
+ try {
3244
+ header = JSON.parse(decoder.decode(decode(encodedHeader)));
3245
+ if (header.alg !== "none")
3246
+ throw new Error();
3247
+ } catch {
3248
+ throw new JWTInvalid("Invalid Unsecured JWT");
3249
+ }
3250
+ const payload = jwt_claims_set_default(header, decode(encodedPayload), options);
3251
+ return { payload, header };
3252
+ }
3253
+ };
3254
+
3255
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/base64url.js
3256
+ var base64url_exports2 = {};
3257
+ __export(base64url_exports2, {
3258
+ decode: () => decode2,
3259
+ encode: () => encode2
3260
+ });
3261
+ var encode2 = encode;
3262
+ var decode2 = decode;
3263
+
3264
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/decode_protected_header.js
3265
+ function decodeProtectedHeader(token) {
3266
+ let protectedB64u;
3267
+ if (typeof token === "string") {
3268
+ const parts = token.split(".");
3269
+ if (parts.length === 3 || parts.length === 5) {
3270
+ ;
3271
+ [protectedB64u] = parts;
3272
+ }
3273
+ } else if (typeof token === "object" && token) {
3274
+ if ("protected" in token) {
3275
+ protectedB64u = token.protected;
3276
+ } else {
3277
+ throw new TypeError("Token does not contain a Protected Header");
3278
+ }
3279
+ }
3280
+ try {
3281
+ if (typeof protectedB64u !== "string" || !protectedB64u) {
3282
+ throw new Error();
3283
+ }
3284
+ const result = JSON.parse(decoder.decode(decode2(protectedB64u)));
3285
+ if (!isObject(result)) {
3286
+ throw new Error();
3287
+ }
3288
+ return result;
3289
+ } catch {
3290
+ throw new TypeError("Invalid Token or Protected Header formatting");
3291
+ }
3292
+ }
3293
+
3294
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/decode_jwt.js
3295
+ function decodeJwt(jwt) {
3296
+ if (typeof jwt !== "string")
3297
+ throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
3298
+ const { 1: payload, length } = jwt.split(".");
3299
+ if (length === 5)
3300
+ throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
3301
+ if (length !== 3)
3302
+ throw new JWTInvalid("Invalid JWT");
3303
+ if (!payload)
3304
+ throw new JWTInvalid("JWTs must contain a payload");
3305
+ let decoded;
3306
+ try {
3307
+ decoded = decode2(payload);
3308
+ } catch {
3309
+ throw new JWTInvalid("Failed to base64url decode the payload");
3310
+ }
3311
+ let result;
3312
+ try {
3313
+ result = JSON.parse(decoder.decode(decoded));
3314
+ } catch {
3315
+ throw new JWTInvalid("Failed to parse the decoded payload as JSON");
3316
+ }
3317
+ if (!isObject(result))
3318
+ throw new JWTInvalid("Invalid JWT Claims Set");
3319
+ return result;
3320
+ }
3321
+
3322
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/generate.js
3323
+ import { createSecretKey as createSecretKey3, generateKeyPair as generateKeyPairCb2 } from "crypto";
3324
+ import { promisify as promisify5 } from "util";
3325
+ var generate = promisify5(generateKeyPairCb2);
3326
+ async function generateSecret(alg, options) {
3327
+ let length;
3328
+ switch (alg) {
3329
+ case "HS256":
3330
+ case "HS384":
3331
+ case "HS512":
3332
+ case "A128CBC-HS256":
3333
+ case "A192CBC-HS384":
3334
+ case "A256CBC-HS512":
3335
+ length = parseInt(alg.slice(-3), 10);
3336
+ break;
3337
+ case "A128KW":
3338
+ case "A192KW":
3339
+ case "A256KW":
3340
+ case "A128GCMKW":
3341
+ case "A192GCMKW":
3342
+ case "A256GCMKW":
3343
+ case "A128GCM":
3344
+ case "A192GCM":
3345
+ case "A256GCM":
3346
+ length = parseInt(alg.slice(1, 4), 10);
3347
+ break;
3348
+ default:
3349
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3350
+ }
3351
+ return createSecretKey3(randomFillSync(new Uint8Array(length >> 3)));
3352
+ }
3353
+ async function generateKeyPair2(alg, options) {
3354
+ switch (alg) {
3355
+ case "RS256":
3356
+ case "RS384":
3357
+ case "RS512":
3358
+ case "PS256":
3359
+ case "PS384":
3360
+ case "PS512":
3361
+ case "RSA-OAEP":
3362
+ case "RSA-OAEP-256":
3363
+ case "RSA-OAEP-384":
3364
+ case "RSA-OAEP-512":
3365
+ case "RSA1_5": {
3366
+ const modulusLength = options?.modulusLength ?? 2048;
3367
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
3368
+ throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
3369
+ }
3370
+ const keypair = await generate("rsa", {
3371
+ modulusLength,
3372
+ publicExponent: 65537
3373
+ });
3374
+ return keypair;
3375
+ }
3376
+ case "ES256":
3377
+ return generate("ec", { namedCurve: "P-256" });
3378
+ case "ES256K":
3379
+ return generate("ec", { namedCurve: "secp256k1" });
3380
+ case "ES384":
3381
+ return generate("ec", { namedCurve: "P-384" });
3382
+ case "ES512":
3383
+ return generate("ec", { namedCurve: "P-521" });
3384
+ case "Ed25519":
3385
+ return generate("ed25519");
3386
+ case "EdDSA": {
3387
+ switch (options?.crv) {
3388
+ case void 0:
3389
+ case "Ed25519":
3390
+ return generate("ed25519");
3391
+ case "Ed448":
3392
+ return generate("ed448");
3393
+ default:
3394
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are Ed25519 and Ed448");
3395
+ }
3396
+ }
3397
+ case "ECDH-ES":
3398
+ case "ECDH-ES+A128KW":
3399
+ case "ECDH-ES+A192KW":
3400
+ case "ECDH-ES+A256KW": {
3401
+ const crv = options?.crv ?? "P-256";
3402
+ switch (crv) {
3403
+ case void 0:
3404
+ case "P-256":
3405
+ case "P-384":
3406
+ case "P-521":
3407
+ return generate("ec", { namedCurve: crv });
3408
+ case "X25519":
3409
+ return generate("x25519");
3410
+ case "X448":
3411
+ return generate("x448");
3412
+ default:
3413
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448");
3414
+ }
3415
+ }
3416
+ default:
3417
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3418
+ }
3419
+ }
3420
+
3421
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/generate_key_pair.js
3422
+ async function generateKeyPair3(alg, options) {
3423
+ return generateKeyPair2(alg, options);
3424
+ }
3425
+
3426
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/generate_secret.js
3427
+ async function generateSecret2(alg, options) {
3428
+ return generateSecret(alg, options);
3429
+ }
3430
+
3431
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/runtime.js
3432
+ var runtime_default = "node:crypto";
3433
+
3434
+ // ../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/runtime.js
3435
+ var runtime_default2 = runtime_default;
3436
+ export {
3437
+ CompactEncrypt,
3438
+ CompactSign,
3439
+ EmbeddedJWK,
3440
+ EncryptJWT,
3441
+ FlattenedEncrypt,
3442
+ FlattenedSign,
3443
+ GeneralEncrypt,
3444
+ GeneralSign,
3445
+ SignJWT,
3446
+ UnsecuredJWT,
3447
+ base64url_exports2 as base64url,
3448
+ calculateJwkThumbprint,
3449
+ calculateJwkThumbprintUri,
3450
+ compactDecrypt,
3451
+ compactVerify,
3452
+ createLocalJWKSet,
3453
+ createRemoteJWKSet,
3454
+ runtime_default2 as cryptoRuntime,
3455
+ decodeJwt,
3456
+ decodeProtectedHeader,
3457
+ errors_exports as errors,
3458
+ experimental_jwksCache,
3459
+ exportJWK,
3460
+ exportPKCS8,
3461
+ exportSPKI,
3462
+ flattenedDecrypt,
3463
+ flattenedVerify,
3464
+ generalDecrypt,
3465
+ generalVerify,
3466
+ generateKeyPair3 as generateKeyPair,
3467
+ generateSecret2 as generateSecret,
3468
+ importJWK,
3469
+ importPKCS8,
3470
+ importSPKI,
3471
+ importX509,
3472
+ jwksCache,
3473
+ jwtDecrypt,
3474
+ jwtVerify
3475
+ };