princejs 2.2.3 → 2.2.4

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.
@@ -1,21 +1,17 @@
1
1
  // @bun
2
2
  var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
3
  var __export = (target, all) => {
8
4
  for (var name in all)
9
5
  __defProp(target, name, {
10
6
  get: all[name],
11
7
  enumerable: true,
12
8
  configurable: true,
13
- set: __exportSetter.bind(all, name)
9
+ set: (newValue) => all[name] = () => newValue
14
10
  });
15
11
  };
16
12
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
13
 
18
- // node_modules/jose/dist/webapi/lib/buffer_utils.js
14
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/buffer_utils.js
19
15
  function concat(...buffers) {
20
16
  const size = buffers.reduce((acc, { length }) => acc + length, 0);
21
17
  const buf = new Uint8Array(size);
@@ -63,7 +59,7 @@ var init_buffer_utils = __esm(() => {
63
59
  MAX_INT32 = 2 ** 32;
64
60
  });
65
61
 
66
- // node_modules/jose/dist/webapi/lib/base64.js
62
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/base64.js
67
63
  function encodeBase64(input) {
68
64
  if (Uint8Array.prototype.toBase64) {
69
65
  return input.toBase64();
@@ -87,7 +83,7 @@ function decodeBase64(encoded) {
87
83
  return bytes;
88
84
  }
89
85
 
90
- // node_modules/jose/dist/webapi/util/base64url.js
86
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/base64url.js
91
87
  var exports_base64url = {};
92
88
  __export(exports_base64url, {
93
89
  encode: () => encode2,
@@ -124,7 +120,7 @@ var init_base64url = __esm(() => {
124
120
  init_buffer_utils();
125
121
  });
126
122
 
127
- // node_modules/jose/dist/webapi/lib/crypto_key.js
123
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/crypto_key.js
128
124
  function getHashLength(hash) {
129
125
  return parseInt(hash.name.slice(4), 10);
130
126
  }
@@ -261,7 +257,7 @@ function checkEncCryptoKey(key, alg, usage) {
261
257
  }
262
258
  var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`), isAlgorithm = (algorithm, name) => algorithm.name === name;
263
259
 
264
- // node_modules/jose/dist/webapi/lib/invalid_key_input.js
260
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/invalid_key_input.js
265
261
  function message(msg, actual, ...types) {
266
262
  types = types.filter(Boolean);
267
263
  if (types.length > 2) {
@@ -285,7 +281,7 @@ function message(msg, actual, ...types) {
285
281
  }
286
282
  var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types), withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
287
283
 
288
- // node_modules/jose/dist/webapi/util/errors.js
284
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/errors.js
289
285
  var exports_errors = {};
290
286
  __export(exports_errors, {
291
287
  JWTInvalid: () => JWTInvalid,
@@ -407,7 +403,7 @@ var init_errors = __esm(() => {
407
403
  };
408
404
  });
409
405
 
410
- // node_modules/jose/dist/webapi/lib/is_key_like.js
406
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/is_key_like.js
411
407
  function assertCryptoKey(key) {
412
408
  if (!isCryptoKey(key)) {
413
409
  throw new Error("CryptoKey instance expected");
@@ -423,7 +419,7 @@ var isCryptoKey = (key) => {
423
419
  }
424
420
  }, isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject", isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
425
421
 
426
- // node_modules/jose/dist/webapi/lib/content_encryption.js
422
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/content_encryption.js
427
423
  function cekLength(alg) {
428
424
  switch (alg) {
429
425
  case "A128GCM":
@@ -631,7 +627,7 @@ var init_content_encryption = __esm(() => {
631
627
  init_errors();
632
628
  });
633
629
 
634
- // node_modules/jose/dist/webapi/lib/helpers.js
630
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/helpers.js
635
631
  function assertNotSet(value, name) {
636
632
  if (value) {
637
633
  throw new TypeError(`${name} can only be called once`);
@@ -654,7 +650,7 @@ var init_helpers = __esm(() => {
654
650
  unprotected = Symbol();
655
651
  });
656
652
 
657
- // node_modules/jose/dist/webapi/lib/type_checks.js
653
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/type_checks.js
658
654
  function isObject(input) {
659
655
  if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
660
656
  return false;
@@ -691,7 +687,7 @@ function isDisjoint(...headers) {
691
687
  }
692
688
  var isObjectLike = (value) => typeof value === "object" && value !== null, isJWK = (key) => isObject(key) && typeof key.kty === "string", isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string"), isPublicJWK = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined, isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
693
689
 
694
- // node_modules/jose/dist/webapi/lib/aeskw.js
690
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/aeskw.js
695
691
  function checkKeySize(key, alg) {
696
692
  if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
697
693
  throw new TypeError(`Invalid key size for alg: ${alg}`);
@@ -718,7 +714,7 @@ async function unwrap(alg, key, encryptedKey) {
718
714
  }
719
715
  var init_aeskw = () => {};
720
716
 
721
- // node_modules/jose/dist/webapi/lib/ecdhes.js
717
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/ecdhes.js
722
718
  function lengthAndInput(input) {
723
719
  return concat(uint32be(input.length), input);
724
720
  }
@@ -773,7 +769,7 @@ var init_ecdhes = __esm(() => {
773
769
  init_helpers();
774
770
  });
775
771
 
776
- // node_modules/jose/dist/webapi/lib/pbes2kw.js
772
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/pbes2kw.js
777
773
  function getCryptoKey2(key, alg) {
778
774
  if (key instanceof Uint8Array) {
779
775
  return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
@@ -815,7 +811,7 @@ var init_pbes2kw = __esm(() => {
815
811
  init_errors();
816
812
  });
817
813
 
818
- // node_modules/jose/dist/webapi/lib/signing.js
814
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/signing.js
819
815
  function checkKeyLength(alg, key) {
820
816
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
821
817
  const { modulusLength } = key.algorithm;
@@ -884,7 +880,7 @@ var init_signing = __esm(() => {
884
880
  init_errors();
885
881
  });
886
882
 
887
- // node_modules/jose/dist/webapi/lib/rsaes.js
883
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/rsaes.js
888
884
  async function encrypt2(alg, key, cek) {
889
885
  checkEncCryptoKey(key, alg, "encrypt");
890
886
  checkKeyLength(alg, key);
@@ -911,7 +907,7 @@ var init_rsaes = __esm(() => {
911
907
  init_errors();
912
908
  });
913
909
 
914
- // node_modules/jose/dist/webapi/lib/jwk_to_key.js
910
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/jwk_to_key.js
915
911
  function subtleMapping(jwk) {
916
912
  let algorithm;
917
913
  let keyUsages;
@@ -1022,7 +1018,7 @@ var init_jwk_to_key = __esm(() => {
1022
1018
  init_errors();
1023
1019
  });
1024
1020
 
1025
- // node_modules/jose/dist/webapi/lib/normalize_key.js
1021
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/normalize_key.js
1026
1022
  async function normalizeKey(key, alg) {
1027
1023
  if (key instanceof Uint8Array) {
1028
1024
  return key;
@@ -1184,7 +1180,7 @@ var init_normalize_key = __esm(() => {
1184
1180
  init_jwk_to_key();
1185
1181
  });
1186
1182
 
1187
- // node_modules/jose/dist/webapi/lib/asn1.js
1183
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/asn1.js
1188
1184
  function parsePKCS8Header(state) {
1189
1185
  expectTag(state, 48, "Invalid PKCS#8 structure");
1190
1186
  parseLength(state);
@@ -1412,7 +1408,7 @@ var init_asn1 = __esm(() => {
1412
1408
  init_errors();
1413
1409
  });
1414
1410
 
1415
- // node_modules/jose/dist/webapi/key/import.js
1411
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/key/import.js
1416
1412
  async function importSPKI(spki, alg, options) {
1417
1413
  if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
1418
1414
  throw new TypeError('"spki" must be SPKI formatted string');
@@ -1472,7 +1468,7 @@ var init_import = __esm(() => {
1472
1468
  init_errors();
1473
1469
  });
1474
1470
 
1475
- // node_modules/jose/dist/webapi/lib/key_to_jwk.js
1471
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/key_to_jwk.js
1476
1472
  async function keyToJWK(key) {
1477
1473
  if (isKeyObject(key)) {
1478
1474
  if (key.type === "secret") {
@@ -1503,7 +1499,7 @@ var init_key_to_jwk = __esm(() => {
1503
1499
  init_base64url();
1504
1500
  });
1505
1501
 
1506
- // node_modules/jose/dist/webapi/key/export.js
1502
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/key/export.js
1507
1503
  async function exportSPKI(key) {
1508
1504
  return toSPKI(key);
1509
1505
  }
@@ -1518,7 +1514,7 @@ var init_export = __esm(() => {
1518
1514
  init_key_to_jwk();
1519
1515
  });
1520
1516
 
1521
- // node_modules/jose/dist/webapi/lib/aesgcmkw.js
1517
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/aesgcmkw.js
1522
1518
  async function wrap3(alg, key, cek, iv) {
1523
1519
  const jweAlgorithm = alg.slice(0, 7);
1524
1520
  const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array);
@@ -1537,7 +1533,7 @@ var init_aesgcmkw = __esm(() => {
1537
1533
  init_base64url();
1538
1534
  });
1539
1535
 
1540
- // node_modules/jose/dist/webapi/lib/key_management.js
1536
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/key_management.js
1541
1537
  function assertEncryptedKey(encryptedKey) {
1542
1538
  if (encryptedKey === undefined)
1543
1539
  throw new JWEInvalid("JWE Encrypted Key missing");
@@ -1724,7 +1720,7 @@ var init_key_management = __esm(() => {
1724
1720
  init_aesgcmkw();
1725
1721
  });
1726
1722
 
1727
- // node_modules/jose/dist/webapi/lib/validate_crit.js
1723
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/validate_crit.js
1728
1724
  function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1729
1725
  if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
1730
1726
  throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
@@ -1758,7 +1754,7 @@ var init_validate_crit = __esm(() => {
1758
1754
  init_errors();
1759
1755
  });
1760
1756
 
1761
- // node_modules/jose/dist/webapi/lib/validate_algorithms.js
1757
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/validate_algorithms.js
1762
1758
  function validateAlgorithms(option, algorithms) {
1763
1759
  if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1764
1760
  throw new TypeError(`"${option}" option must be an array of strings`);
@@ -1769,7 +1765,7 @@ function validateAlgorithms(option, algorithms) {
1769
1765
  return new Set(algorithms);
1770
1766
  }
1771
1767
 
1772
- // node_modules/jose/dist/webapi/lib/check_key_type.js
1768
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/check_key_type.js
1773
1769
  function checkKeyType(alg, key, usage) {
1774
1770
  switch (alg.substring(0, 2)) {
1775
1771
  case "A1":
@@ -1887,7 +1883,7 @@ var tag = (key) => key?.[Symbol.toStringTag], jwkMatchesOp = (alg, key, usage) =
1887
1883
  };
1888
1884
  var init_check_key_type = () => {};
1889
1885
 
1890
- // node_modules/jose/dist/webapi/lib/deflate.js
1886
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/deflate.js
1891
1887
  function supported(name) {
1892
1888
  if (typeof globalThis[name] === "undefined") {
1893
1889
  throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
@@ -1897,8 +1893,8 @@ async function compress(input) {
1897
1893
  supported("CompressionStream");
1898
1894
  const cs = new CompressionStream("deflate-raw");
1899
1895
  const writer = cs.writable.getWriter();
1900
- writer.write(input).catch(() => {});
1901
- writer.close().catch(() => {});
1896
+ writer.write(input);
1897
+ writer.close();
1902
1898
  const chunks = [];
1903
1899
  const reader = cs.readable.getReader();
1904
1900
  for (;; ) {
@@ -1913,8 +1909,8 @@ async function decompress(input, maxLength) {
1913
1909
  supported("DecompressionStream");
1914
1910
  const ds = new DecompressionStream("deflate-raw");
1915
1911
  const writer = ds.writable.getWriter();
1916
- writer.write(input).catch(() => {});
1917
- writer.close().catch(() => {});
1912
+ writer.write(input);
1913
+ writer.close();
1918
1914
  const chunks = [];
1919
1915
  let length = 0;
1920
1916
  const reader = ds.readable.getReader();
@@ -1935,7 +1931,7 @@ var init_deflate = __esm(() => {
1935
1931
  init_buffer_utils();
1936
1932
  });
1937
1933
 
1938
- // node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
1934
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
1939
1935
  async function flattenedDecrypt(jwe, key, options) {
1940
1936
  if (!isObject(jwe)) {
1941
1937
  throw new JWEInvalid("Flattened JWE must be an object");
@@ -2052,11 +2048,7 @@ async function flattenedDecrypt(jwe, key, options) {
2052
2048
  if (maxDecompressedLength !== Infinity && (!Number.isSafeInteger(maxDecompressedLength) || maxDecompressedLength < 1)) {
2053
2049
  throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
2054
2050
  }
2055
- result.plaintext = await decompress(plaintext, maxDecompressedLength).catch((cause) => {
2056
- if (cause instanceof JWEInvalid)
2057
- throw cause;
2058
- throw new JWEInvalid("Failed to decompress plaintext", { cause });
2059
- });
2051
+ result.plaintext = await decompress(plaintext, maxDecompressedLength);
2060
2052
  }
2061
2053
  if (jwe.protected !== undefined) {
2062
2054
  result.protectedHeader = parsedProt;
@@ -2089,7 +2081,7 @@ var init_decrypt = __esm(() => {
2089
2081
  init_deflate();
2090
2082
  });
2091
2083
 
2092
- // node_modules/jose/dist/webapi/jwe/compact/decrypt.js
2084
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/compact/decrypt.js
2093
2085
  async function compactDecrypt(jwe, key, options) {
2094
2086
  if (jwe instanceof Uint8Array) {
2095
2087
  jwe = decoder.decode(jwe);
@@ -2120,7 +2112,7 @@ var init_decrypt2 = __esm(() => {
2120
2112
  init_buffer_utils();
2121
2113
  });
2122
2114
 
2123
- // node_modules/jose/dist/webapi/jwe/general/decrypt.js
2115
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/general/decrypt.js
2124
2116
  async function generalDecrypt(jwe, key, options) {
2125
2117
  if (!isObject(jwe)) {
2126
2118
  throw new JWEInvalid("General JWE must be an object");
@@ -2152,7 +2144,7 @@ var init_decrypt3 = __esm(() => {
2152
2144
  init_errors();
2153
2145
  });
2154
2146
 
2155
- // node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
2147
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
2156
2148
  class FlattenedEncrypt {
2157
2149
  #plaintext;
2158
2150
  #protectedHeader;
@@ -2272,9 +2264,7 @@ class FlattenedEncrypt {
2272
2264
  }
2273
2265
  let plaintext = this.#plaintext;
2274
2266
  if (joseHeader.zip === "DEF") {
2275
- plaintext = await compress(plaintext).catch((cause) => {
2276
- throw new JWEInvalid("Failed to compress plaintext", { cause });
2277
- });
2267
+ plaintext = await compress(plaintext);
2278
2268
  }
2279
2269
  const { ciphertext, tag: tag2, iv } = await encrypt(enc, plaintext, cek, this.#iv, additionalData);
2280
2270
  const jwe = {
@@ -2317,7 +2307,7 @@ var init_encrypt = __esm(() => {
2317
2307
  init_deflate();
2318
2308
  });
2319
2309
 
2320
- // node_modules/jose/dist/webapi/jwe/general/encrypt.js
2310
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/general/encrypt.js
2321
2311
  class IndividualRecipient {
2322
2312
  #parent;
2323
2313
  unprotectedHeader;
@@ -2488,7 +2478,7 @@ var init_encrypt2 = __esm(() => {
2488
2478
  init_check_key_type();
2489
2479
  });
2490
2480
 
2491
- // node_modules/jose/dist/webapi/jws/flattened/verify.js
2481
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/flattened/verify.js
2492
2482
  async function flattenedVerify(jws, key, options) {
2493
2483
  if (!isObject(jws)) {
2494
2484
  throw new JWSInvalid("Flattened JWS must be an object");
@@ -2591,7 +2581,7 @@ var init_verify = __esm(() => {
2591
2581
  init_normalize_key();
2592
2582
  });
2593
2583
 
2594
- // node_modules/jose/dist/webapi/jws/compact/verify.js
2584
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/compact/verify.js
2595
2585
  async function compactVerify(jws, key, options) {
2596
2586
  if (jws instanceof Uint8Array) {
2597
2587
  jws = decoder.decode(jws);
@@ -2616,7 +2606,7 @@ var init_verify2 = __esm(() => {
2616
2606
  init_buffer_utils();
2617
2607
  });
2618
2608
 
2619
- // node_modules/jose/dist/webapi/jws/general/verify.js
2609
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/general/verify.js
2620
2610
  async function generalVerify(jws, key, options) {
2621
2611
  if (!isObject(jws)) {
2622
2612
  throw new JWSInvalid("General JWS must be an object");
@@ -2641,7 +2631,7 @@ var init_verify3 = __esm(() => {
2641
2631
  init_errors();
2642
2632
  });
2643
2633
 
2644
- // node_modules/jose/dist/webapi/lib/jwt_claims_set.js
2634
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
2645
2635
  function secs(str) {
2646
2636
  const matched = REGEX.exec(str);
2647
2637
  if (!matched || matched[4] && matched[1]) {
@@ -2867,7 +2857,7 @@ var init_jwt_claims_set = __esm(() => {
2867
2857
  REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
2868
2858
  });
2869
2859
 
2870
- // node_modules/jose/dist/webapi/jwt/verify.js
2860
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/verify.js
2871
2861
  async function jwtVerify(jwt, key, options) {
2872
2862
  const verified = await compactVerify(jwt, key, options);
2873
2863
  if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
@@ -2886,7 +2876,7 @@ var init_verify4 = __esm(() => {
2886
2876
  init_errors();
2887
2877
  });
2888
2878
 
2889
- // node_modules/jose/dist/webapi/jwt/decrypt.js
2879
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/decrypt.js
2890
2880
  async function jwtDecrypt(jwt, key, options) {
2891
2881
  const decrypted = await compactDecrypt(jwt, key, options);
2892
2882
  const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
@@ -2912,7 +2902,7 @@ var init_decrypt4 = __esm(() => {
2912
2902
  init_errors();
2913
2903
  });
2914
2904
 
2915
- // node_modules/jose/dist/webapi/jwe/compact/encrypt.js
2905
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwe/compact/encrypt.js
2916
2906
  class CompactEncrypt {
2917
2907
  #flattened;
2918
2908
  constructor(plaintext) {
@@ -2943,7 +2933,7 @@ var init_encrypt3 = __esm(() => {
2943
2933
  init_encrypt();
2944
2934
  });
2945
2935
 
2946
- // node_modules/jose/dist/webapi/jws/flattened/sign.js
2936
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/flattened/sign.js
2947
2937
  class FlattenedSign {
2948
2938
  #payload;
2949
2939
  #protectedHeader;
@@ -3033,7 +3023,7 @@ var init_sign = __esm(() => {
3033
3023
  init_helpers();
3034
3024
  });
3035
3025
 
3036
- // node_modules/jose/dist/webapi/jws/compact/sign.js
3026
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/compact/sign.js
3037
3027
  class CompactSign {
3038
3028
  #flattened;
3039
3029
  constructor(payload) {
@@ -3055,7 +3045,7 @@ var init_sign2 = __esm(() => {
3055
3045
  init_sign();
3056
3046
  });
3057
3047
 
3058
- // node_modules/jose/dist/webapi/jws/general/sign.js
3048
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/general/sign.js
3059
3049
  class IndividualSignature {
3060
3050
  #parent;
3061
3051
  protectedHeader;
@@ -3129,7 +3119,7 @@ var init_sign3 = __esm(() => {
3129
3119
  init_helpers();
3130
3120
  });
3131
3121
 
3132
- // node_modules/jose/dist/webapi/jwt/sign.js
3122
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/sign.js
3133
3123
  class SignJWT {
3134
3124
  #protectedHeader;
3135
3125
  #jwt;
@@ -3183,7 +3173,7 @@ var init_sign4 = __esm(() => {
3183
3173
  init_jwt_claims_set();
3184
3174
  });
3185
3175
 
3186
- // node_modules/jose/dist/webapi/jwt/encrypt.js
3176
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/encrypt.js
3187
3177
  class EncryptJWT {
3188
3178
  #cek;
3189
3179
  #iv;
@@ -3285,7 +3275,7 @@ var init_encrypt4 = __esm(() => {
3285
3275
  init_helpers();
3286
3276
  });
3287
3277
 
3288
- // node_modules/jose/dist/webapi/jwk/thumbprint.js
3278
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwk/thumbprint.js
3289
3279
  async function calculateJwkThumbprint(key, digestAlgorithm) {
3290
3280
  let jwk;
3291
3281
  if (isJWK(key)) {
@@ -3350,7 +3340,7 @@ var init_thumbprint = __esm(() => {
3350
3340
  init_export();
3351
3341
  });
3352
3342
 
3353
- // node_modules/jose/dist/webapi/jwk/embedded.js
3343
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwk/embedded.js
3354
3344
  async function EmbeddedJWK(protectedHeader, token) {
3355
3345
  const joseHeader = {
3356
3346
  ...protectedHeader,
@@ -3370,7 +3360,7 @@ var init_embedded = __esm(() => {
3370
3360
  init_errors();
3371
3361
  });
3372
3362
 
3373
- // node_modules/jose/dist/webapi/jwks/local.js
3363
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwks/local.js
3374
3364
  function getKtyFromAlg(alg) {
3375
3365
  switch (typeof alg === "string" && alg.slice(0, 2)) {
3376
3366
  case "RS":
@@ -3489,7 +3479,7 @@ var init_local = __esm(() => {
3489
3479
  init_errors();
3490
3480
  });
3491
3481
 
3492
- // node_modules/jose/dist/webapi/jwks/remote.js
3482
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwks/remote.js
3493
3483
  function isCloudflareWorkers() {
3494
3484
  return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
3495
3485
  }
@@ -3650,14 +3640,14 @@ var init_remote = __esm(() => {
3650
3640
  init_local();
3651
3641
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
3652
3642
  const NAME = "jose";
3653
- const VERSION = "v6.2.2";
3643
+ const VERSION = "v6.2.1";
3654
3644
  USER_AGENT = `${NAME}/${VERSION}`;
3655
3645
  }
3656
3646
  customFetch = Symbol();
3657
3647
  jwksCache = Symbol();
3658
3648
  });
3659
3649
 
3660
- // node_modules/jose/dist/webapi/jwt/unsecured.js
3650
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/unsecured.js
3661
3651
  class UnsecuredJWT {
3662
3652
  #jwt;
3663
3653
  constructor(payload = {}) {
@@ -3723,7 +3713,7 @@ var init_unsecured = __esm(() => {
3723
3713
  init_jwt_claims_set();
3724
3714
  });
3725
3715
 
3726
- // node_modules/jose/dist/webapi/util/decode_protected_header.js
3716
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/decode_protected_header.js
3727
3717
  function decodeProtectedHeader(token) {
3728
3718
  let protectedB64u;
3729
3719
  if (typeof token === "string") {
@@ -3756,7 +3746,7 @@ var init_decode_protected_header = __esm(() => {
3756
3746
  init_buffer_utils();
3757
3747
  });
3758
3748
 
3759
- // node_modules/jose/dist/webapi/util/decode_jwt.js
3749
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/decode_jwt.js
3760
3750
  function decodeJwt(jwt) {
3761
3751
  if (typeof jwt !== "string")
3762
3752
  throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
@@ -3789,7 +3779,7 @@ var init_decode_jwt = __esm(() => {
3789
3779
  init_errors();
3790
3780
  });
3791
3781
 
3792
- // node_modules/jose/dist/webapi/key/generate_key_pair.js
3782
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/key/generate_key_pair.js
3793
3783
  function getModulusLengthOption(options) {
3794
3784
  const modulusLength = options?.modulusLength ?? 2048;
3795
3785
  if (typeof modulusLength !== "number" || modulusLength < 2048) {
@@ -3890,7 +3880,7 @@ var init_generate_key_pair = __esm(() => {
3890
3880
  init_errors();
3891
3881
  });
3892
3882
 
3893
- // node_modules/jose/dist/webapi/key/generate_secret.js
3883
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/key/generate_secret.js
3894
3884
  async function generateSecret(alg, options) {
3895
3885
  let length;
3896
3886
  let algorithm;
@@ -3934,7 +3924,7 @@ var init_generate_secret = __esm(() => {
3934
3924
  init_errors();
3935
3925
  });
3936
3926
 
3937
- // node_modules/jose/dist/webapi/index.js
3927
+ // node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/index.js
3938
3928
  var exports_webapi = {};
3939
3929
  __export(exports_webapi, {
3940
3930
  jwtVerify: () => jwtVerify,
@@ -4064,7 +4054,7 @@ var logger = (options = {}) => {
4064
4054
  }
4065
4055
  };
4066
4056
  };
4067
- var cors = (origin = "*") => {
4057
+ var cors = (origin = "http://localhost:3000") => {
4068
4058
  return async (req, next) => {
4069
4059
  if (req.method === "OPTIONS") {
4070
4060
  return new Response(null, {
@@ -4092,11 +4082,12 @@ var cors = (origin = "*") => {
4092
4082
  return response;
4093
4083
  };
4094
4084
  };
4095
- var signJWT = async (payload, secret, expiresIn) => {
4096
- const jwt = await new SignJWT(payload).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
4085
+ var signJWT = async (payload, secret, expiresIn, alg = "HS256") => {
4086
+ const jwt = await new SignJWT(payload).setProtectedHeader({ alg }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
4097
4087
  return jwt;
4098
4088
  };
4099
- var jwt = (key) => {
4089
+ var jwt = (key, options) => {
4090
+ const algorithms = options?.algorithms ?? ["HS256", "HS512"];
4100
4091
  return async (req, next) => {
4101
4092
  const auth = req.headers.get("authorization");
4102
4093
  req.user = undefined;
@@ -4104,11 +4095,11 @@ var jwt = (key) => {
4104
4095
  const token = auth.slice(7).trim();
4105
4096
  try {
4106
4097
  const { payload } = await jwtVerify(token, key, {
4107
- algorithms: ["HS256", "HS512"]
4098
+ algorithms
4108
4099
  });
4109
4100
  req.user = payload;
4110
4101
  } catch (err) {
4111
- console.error("JWT Verification Failed:", err);
4102
+ console.error("JWT Verification Failed: Invalid token");
4112
4103
  }
4113
4104
  }
4114
4105
  const result = await next();
@@ -4117,9 +4108,11 @@ var jwt = (key) => {
4117
4108
  };
4118
4109
  var rateLimit = (max, window = 60) => {
4119
4110
  const store = {};
4111
+ let lastCleanup = Date.now();
4120
4112
  return async (req, next) => {
4121
- const ip = req.headers.get("cf-connecting-ip") || req.headers.get("x-real-ip") || req.headers.get("x-forwarded-for")?.split(",")[0].trim() || req.headers.get("x-client-ip") || "unknown";
4122
- const key = `${ip}:${Math.floor(Date.now() / (window * 1000))}`;
4113
+ const ip = req.ip || "127.0.0.1";
4114
+ const bucket = Math.floor(Date.now() / (window * 1000));
4115
+ const key = `${ip}:${bucket}`;
4123
4116
  store[key] = (store[key] || 0) + 1;
4124
4117
  if (store[key] > max) {
4125
4118
  return new Response(JSON.stringify({
@@ -4133,11 +4126,12 @@ var rateLimit = (max, window = 60) => {
4133
4126
  }
4134
4127
  });
4135
4128
  }
4136
- if (Math.random() < 0.01) {
4137
- const now = Math.floor(Date.now() / (window * 1000));
4129
+ if (Date.now() - lastCleanup > 1e4) {
4130
+ lastCleanup = Date.now();
4131
+ const currentBucket = Math.floor(Date.now() / (window * 1000));
4138
4132
  Object.keys(store).forEach((k) => {
4139
- const timestamp = parseInt(k.split(":")[1]);
4140
- if (now - timestamp > 2)
4133
+ const [_, b] = k.split(":");
4134
+ if (currentBucket - parseInt(b) > 2)
4141
4135
  delete store[k];
4142
4136
  });
4143
4137
  }
@@ -4410,6 +4404,34 @@ var trimTrailingSlash = (statusCode = 301) => {
4410
4404
  mw.__trimTrailingSlash = statusCode;
4411
4405
  return mw;
4412
4406
  };
4407
+ var csrf = (options) => {
4408
+ const cookieName = options?.cookieName ?? "csrf";
4409
+ const headerName = options?.headerName ?? "x-csrf-token";
4410
+ const keyLength = options?.keyLength ?? 32;
4411
+ return async (req, next) => {
4412
+ let token = req.cookies?.[cookieName];
4413
+ if (!token) {
4414
+ token = Array.from(crypto.getRandomValues(new Uint8Array(keyLength)), (b) => b.toString(16).padStart(2, "0")).join("");
4415
+ req.headers.set(cookieName, token);
4416
+ }
4417
+ if (["POST", "PUT", "PATCH", "DELETE"].includes(req.method)) {
4418
+ const provided = req.headers.get(headerName);
4419
+ if (!provided || provided !== token) {
4420
+ return new Response(JSON.stringify({ error: "CSRF validation failed" }), { status: 403, headers: { "Content-Type": "application/json" } });
4421
+ }
4422
+ }
4423
+ const response = await next();
4424
+ if (!response)
4425
+ return response;
4426
+ const headers = new Headers(response.headers);
4427
+ headers.append("Set-Cookie", `${cookieName}=${token}; HttpOnly; Secure; SameSite=Strict; Path=/; Max-Age=3600`);
4428
+ return new Response(response.body, {
4429
+ status: response.status,
4430
+ statusText: response.statusText,
4431
+ headers
4432
+ });
4433
+ };
4434
+ };
4413
4435
  var every = (...middlewares) => {
4414
4436
  return async (req, next) => {
4415
4437
  let idx = 0;
@@ -4469,6 +4491,7 @@ export {
4469
4491
  ipRestriction,
4470
4492
  except,
4471
4493
  every,
4494
+ csrf,
4472
4495
  cors,
4473
4496
  compress2 as compress,
4474
4497
  auth,