@concavejs/cli 0.0.1-alpha.12 → 0.0.1-alpha.13

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.
@@ -958,6 +958,113 @@ var init_base64url2 = __esm(() => {
958
958
  init_buffer_utils2();
959
959
  });
960
960
 
961
+ // ../../node_modules/jose/dist/webapi/lib/crypto_key.js
962
+ function getHashLength2(hash) {
963
+ return parseInt(hash.name.slice(4), 10);
964
+ }
965
+ function checkHashLength2(algorithm, expected) {
966
+ const actual = getHashLength2(algorithm.hash);
967
+ if (actual !== expected)
968
+ throw unusable2(`SHA-${expected}`, "algorithm.hash");
969
+ }
970
+ function getNamedCurve2(alg) {
971
+ switch (alg) {
972
+ case "ES256":
973
+ return "P-256";
974
+ case "ES384":
975
+ return "P-384";
976
+ case "ES512":
977
+ return "P-521";
978
+ default:
979
+ throw new Error("unreachable");
980
+ }
981
+ }
982
+ function checkUsage2(key, usage) {
983
+ if (usage && !key.usages.includes(usage)) {
984
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
985
+ }
986
+ }
987
+ function checkSigCryptoKey2(key, alg, usage) {
988
+ switch (alg) {
989
+ case "HS256":
990
+ case "HS384":
991
+ case "HS512": {
992
+ if (!isAlgorithm2(key.algorithm, "HMAC"))
993
+ throw unusable2("HMAC");
994
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
995
+ break;
996
+ }
997
+ case "RS256":
998
+ case "RS384":
999
+ case "RS512": {
1000
+ if (!isAlgorithm2(key.algorithm, "RSASSA-PKCS1-v1_5"))
1001
+ throw unusable2("RSASSA-PKCS1-v1_5");
1002
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
1003
+ break;
1004
+ }
1005
+ case "PS256":
1006
+ case "PS384":
1007
+ case "PS512": {
1008
+ if (!isAlgorithm2(key.algorithm, "RSA-PSS"))
1009
+ throw unusable2("RSA-PSS");
1010
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
1011
+ break;
1012
+ }
1013
+ case "Ed25519":
1014
+ case "EdDSA": {
1015
+ if (!isAlgorithm2(key.algorithm, "Ed25519"))
1016
+ throw unusable2("Ed25519");
1017
+ break;
1018
+ }
1019
+ case "ML-DSA-44":
1020
+ case "ML-DSA-65":
1021
+ case "ML-DSA-87": {
1022
+ if (!isAlgorithm2(key.algorithm, alg))
1023
+ throw unusable2(alg);
1024
+ break;
1025
+ }
1026
+ case "ES256":
1027
+ case "ES384":
1028
+ case "ES512": {
1029
+ if (!isAlgorithm2(key.algorithm, "ECDSA"))
1030
+ throw unusable2("ECDSA");
1031
+ const expected = getNamedCurve2(alg);
1032
+ const actual = key.algorithm.namedCurve;
1033
+ if (actual !== expected)
1034
+ throw unusable2(expected, "algorithm.namedCurve");
1035
+ break;
1036
+ }
1037
+ default:
1038
+ throw new TypeError("CryptoKey does not support this operation");
1039
+ }
1040
+ checkUsage2(key, usage);
1041
+ }
1042
+ var unusable2 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`), isAlgorithm2 = (algorithm, name) => algorithm.name === name;
1043
+
1044
+ // ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
1045
+ function message2(msg, actual, ...types) {
1046
+ types = types.filter(Boolean);
1047
+ if (types.length > 2) {
1048
+ const last = types.pop();
1049
+ msg += `one of type ${types.join(", ")}, or ${last}.`;
1050
+ } else if (types.length === 2) {
1051
+ msg += `one of type ${types[0]} or ${types[1]}.`;
1052
+ } else {
1053
+ msg += `of type ${types[0]}.`;
1054
+ }
1055
+ if (actual == null) {
1056
+ msg += ` Received ${actual}`;
1057
+ } else if (typeof actual === "function" && actual.name) {
1058
+ msg += ` Received function ${actual.name}`;
1059
+ } else if (typeof actual === "object" && actual != null) {
1060
+ if (actual.constructor?.name) {
1061
+ msg += ` Received an instance of ${actual.constructor.name}`;
1062
+ }
1063
+ }
1064
+ return msg;
1065
+ }
1066
+ var invalidKeyInput2 = (actual, ...types) => message2("Key must be ", actual, ...types), withAlg2 = (alg, actual, ...types) => message2(`Key for the ${alg} algorithm must be `, actual, ...types);
1067
+
961
1068
  // ../../node_modules/jose/dist/webapi/util/errors.js
962
1069
  var exports_errors2 = {};
963
1070
  __export(exports_errors2, {
@@ -982,8 +1089,8 @@ var init_errors5 = __esm(() => {
982
1089
  JOSEError2 = class JOSEError2 extends Error {
983
1090
  static code = "ERR_JOSE_GENERIC";
984
1091
  code = "ERR_JOSE_GENERIC";
985
- constructor(message2, options) {
986
- super(message2, options);
1092
+ constructor(message3, options) {
1093
+ super(message3, options);
987
1094
  this.name = this.constructor.name;
988
1095
  Error.captureStackTrace?.(this, this.constructor);
989
1096
  }
@@ -994,8 +1101,8 @@ var init_errors5 = __esm(() => {
994
1101
  claim;
995
1102
  reason;
996
1103
  payload;
997
- constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
998
- super(message2, { cause: { claim, reason, payload } });
1104
+ constructor(message3, payload, claim = "unspecified", reason = "unspecified") {
1105
+ super(message3, { cause: { claim, reason, payload } });
999
1106
  this.claim = claim;
1000
1107
  this.reason = reason;
1001
1108
  this.payload = payload;
@@ -1007,8 +1114,8 @@ var init_errors5 = __esm(() => {
1007
1114
  claim;
1008
1115
  reason;
1009
1116
  payload;
1010
- constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
1011
- super(message2, { cause: { claim, reason, payload } });
1117
+ constructor(message3, payload, claim = "unspecified", reason = "unspecified") {
1118
+ super(message3, { cause: { claim, reason, payload } });
1012
1119
  this.claim = claim;
1013
1120
  this.reason = reason;
1014
1121
  this.payload = payload;
@@ -1025,8 +1132,8 @@ var init_errors5 = __esm(() => {
1025
1132
  JWEDecryptionFailed2 = class JWEDecryptionFailed2 extends JOSEError2 {
1026
1133
  static code = "ERR_JWE_DECRYPTION_FAILED";
1027
1134
  code = "ERR_JWE_DECRYPTION_FAILED";
1028
- constructor(message2 = "decryption operation failed", options) {
1029
- super(message2, options);
1135
+ constructor(message3 = "decryption operation failed", options) {
1136
+ super(message3, options);
1030
1137
  }
1031
1138
  };
1032
1139
  JWEInvalid2 = class JWEInvalid2 extends JOSEError2 {
@@ -1052,145 +1159,34 @@ var init_errors5 = __esm(() => {
1052
1159
  JWKSNoMatchingKey2 = class JWKSNoMatchingKey2 extends JOSEError2 {
1053
1160
  static code = "ERR_JWKS_NO_MATCHING_KEY";
1054
1161
  code = "ERR_JWKS_NO_MATCHING_KEY";
1055
- constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
1056
- super(message2, options);
1162
+ constructor(message3 = "no applicable key found in the JSON Web Key Set", options) {
1163
+ super(message3, options);
1057
1164
  }
1058
1165
  };
1059
1166
  JWKSMultipleMatchingKeys2 = class JWKSMultipleMatchingKeys2 extends JOSEError2 {
1060
1167
  [Symbol.asyncIterator];
1061
1168
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
1062
1169
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
1063
- constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
1064
- super(message2, options);
1170
+ constructor(message3 = "multiple matching keys found in the JSON Web Key Set", options) {
1171
+ super(message3, options);
1065
1172
  }
1066
1173
  };
1067
1174
  JWKSTimeout2 = class JWKSTimeout2 extends JOSEError2 {
1068
1175
  static code = "ERR_JWKS_TIMEOUT";
1069
1176
  code = "ERR_JWKS_TIMEOUT";
1070
- constructor(message2 = "request timed out", options) {
1071
- super(message2, options);
1177
+ constructor(message3 = "request timed out", options) {
1178
+ super(message3, options);
1072
1179
  }
1073
1180
  };
1074
1181
  JWSSignatureVerificationFailed2 = class JWSSignatureVerificationFailed2 extends JOSEError2 {
1075
1182
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
1076
1183
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
1077
- constructor(message2 = "signature verification failed", options) {
1078
- super(message2, options);
1184
+ constructor(message3 = "signature verification failed", options) {
1185
+ super(message3, options);
1079
1186
  }
1080
1187
  };
1081
1188
  });
1082
1189
 
1083
- // ../../node_modules/jose/dist/webapi/lib/crypto_key.js
1084
- function getHashLength2(hash) {
1085
- return parseInt(hash.name.slice(4), 10);
1086
- }
1087
- function getNamedCurve2(alg) {
1088
- switch (alg) {
1089
- case "ES256":
1090
- return "P-256";
1091
- case "ES384":
1092
- return "P-384";
1093
- case "ES512":
1094
- return "P-521";
1095
- default:
1096
- throw new Error("unreachable");
1097
- }
1098
- }
1099
- function checkUsage2(key, usage) {
1100
- if (usage && !key.usages.includes(usage)) {
1101
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
1102
- }
1103
- }
1104
- function checkSigCryptoKey2(key, alg, usage) {
1105
- switch (alg) {
1106
- case "HS256":
1107
- case "HS384":
1108
- case "HS512": {
1109
- if (!isAlgorithm2(key.algorithm, "HMAC"))
1110
- throw unusable2("HMAC");
1111
- const expected = parseInt(alg.slice(2), 10);
1112
- const actual = getHashLength2(key.algorithm.hash);
1113
- if (actual !== expected)
1114
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
1115
- break;
1116
- }
1117
- case "RS256":
1118
- case "RS384":
1119
- case "RS512": {
1120
- if (!isAlgorithm2(key.algorithm, "RSASSA-PKCS1-v1_5"))
1121
- throw unusable2("RSASSA-PKCS1-v1_5");
1122
- const expected = parseInt(alg.slice(2), 10);
1123
- const actual = getHashLength2(key.algorithm.hash);
1124
- if (actual !== expected)
1125
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
1126
- break;
1127
- }
1128
- case "PS256":
1129
- case "PS384":
1130
- case "PS512": {
1131
- if (!isAlgorithm2(key.algorithm, "RSA-PSS"))
1132
- throw unusable2("RSA-PSS");
1133
- const expected = parseInt(alg.slice(2), 10);
1134
- const actual = getHashLength2(key.algorithm.hash);
1135
- if (actual !== expected)
1136
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
1137
- break;
1138
- }
1139
- case "Ed25519":
1140
- case "EdDSA": {
1141
- if (!isAlgorithm2(key.algorithm, "Ed25519"))
1142
- throw unusable2("Ed25519");
1143
- break;
1144
- }
1145
- case "ML-DSA-44":
1146
- case "ML-DSA-65":
1147
- case "ML-DSA-87": {
1148
- if (!isAlgorithm2(key.algorithm, alg))
1149
- throw unusable2(alg);
1150
- break;
1151
- }
1152
- case "ES256":
1153
- case "ES384":
1154
- case "ES512": {
1155
- if (!isAlgorithm2(key.algorithm, "ECDSA"))
1156
- throw unusable2("ECDSA");
1157
- const expected = getNamedCurve2(alg);
1158
- const actual = key.algorithm.namedCurve;
1159
- if (actual !== expected)
1160
- throw unusable2(expected, "algorithm.namedCurve");
1161
- break;
1162
- }
1163
- default:
1164
- throw new TypeError("CryptoKey does not support this operation");
1165
- }
1166
- checkUsage2(key, usage);
1167
- }
1168
- var unusable2 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`), isAlgorithm2 = (algorithm, name) => algorithm.name === name;
1169
-
1170
- // ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
1171
- function message2(msg, actual, ...types) {
1172
- types = types.filter(Boolean);
1173
- if (types.length > 2) {
1174
- const last = types.pop();
1175
- msg += `one of type ${types.join(", ")}, or ${last}.`;
1176
- } else if (types.length === 2) {
1177
- msg += `one of type ${types[0]} or ${types[1]}.`;
1178
- } else {
1179
- msg += `of type ${types[0]}.`;
1180
- }
1181
- if (actual == null) {
1182
- msg += ` Received ${actual}`;
1183
- } else if (typeof actual === "function" && actual.name) {
1184
- msg += ` Received function ${actual.name}`;
1185
- } else if (typeof actual === "object" && actual != null) {
1186
- if (actual.constructor?.name) {
1187
- msg += ` Received an instance of ${actual.constructor.name}`;
1188
- }
1189
- }
1190
- return msg;
1191
- }
1192
- var invalidKeyInput2 = (actual, ...types) => message2("Key must be ", actual, ...types), withAlg2 = (alg, actual, ...types) => message2(`Key for the ${alg} algorithm must be `, actual, ...types);
1193
-
1194
1190
  // ../../node_modules/jose/dist/webapi/lib/is_key_like.js
1195
1191
  var isCryptoKey2 = (key) => {
1196
1192
  if (key?.[Symbol.toStringTag] === "CryptoKey")
@@ -1202,7 +1198,34 @@ var isCryptoKey2 = (key) => {
1202
1198
  }
1203
1199
  }, isKeyObject2 = (key) => key?.[Symbol.toStringTag] === "KeyObject", isKeyLike2 = (key) => isCryptoKey2(key) || isKeyObject2(key);
1204
1200
 
1205
- // ../../node_modules/jose/dist/webapi/lib/is_disjoint.js
1201
+ // ../../node_modules/jose/dist/webapi/lib/helpers.js
1202
+ function decodeBase64url2(value, label, ErrorClass) {
1203
+ try {
1204
+ return decode2(value);
1205
+ } catch {
1206
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
1207
+ }
1208
+ }
1209
+ var unprotected2;
1210
+ var init_helpers2 = __esm(() => {
1211
+ init_base64url2();
1212
+ unprotected2 = Symbol();
1213
+ });
1214
+
1215
+ // ../../node_modules/jose/dist/webapi/lib/type_checks.js
1216
+ function isObject2(input) {
1217
+ if (!isObjectLike2(input) || Object.prototype.toString.call(input) !== "[object Object]") {
1218
+ return false;
1219
+ }
1220
+ if (Object.getPrototypeOf(input) === null) {
1221
+ return true;
1222
+ }
1223
+ let proto = input;
1224
+ while (Object.getPrototypeOf(proto) !== null) {
1225
+ proto = Object.getPrototypeOf(proto);
1226
+ }
1227
+ return Object.getPrototypeOf(input) === proto;
1228
+ }
1206
1229
  function isDisjoint2(...headers) {
1207
1230
  const sources = headers.filter(Boolean);
1208
1231
  if (sources.length === 0 || sources.length === 1) {
@@ -1224,24 +1247,9 @@ function isDisjoint2(...headers) {
1224
1247
  }
1225
1248
  return true;
1226
1249
  }
1250
+ var isObjectLike2 = (value) => typeof value === "object" && value !== null, isJWK2 = (key) => isObject2(key) && typeof key.kty === "string", isPrivateJWK2 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string"), isPublicJWK2 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined, isSecretJWK2 = (key) => key.kty === "oct" && typeof key.k === "string";
1227
1251
 
1228
- // ../../node_modules/jose/dist/webapi/lib/is_object.js
1229
- function isObject2(input) {
1230
- if (!isObjectLike2(input) || Object.prototype.toString.call(input) !== "[object Object]") {
1231
- return false;
1232
- }
1233
- if (Object.getPrototypeOf(input) === null) {
1234
- return true;
1235
- }
1236
- let proto = input;
1237
- while (Object.getPrototypeOf(proto) !== null) {
1238
- proto = Object.getPrototypeOf(proto);
1239
- }
1240
- return Object.getPrototypeOf(input) === proto;
1241
- }
1242
- var isObjectLike2 = (value) => typeof value === "object" && value !== null;
1243
-
1244
- // ../../node_modules/jose/dist/webapi/lib/check_key_length.js
1252
+ // ../../node_modules/jose/dist/webapi/lib/signing.js
1245
1253
  function checkKeyLength2(alg, key) {
1246
1254
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
1247
1255
  const { modulusLength } = key.algorithm;
@@ -1250,10 +1258,63 @@ function checkKeyLength2(alg, key) {
1250
1258
  }
1251
1259
  }
1252
1260
  }
1253
-
1254
- // ../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
1255
- function subtleMapping2(jwk) {
1256
- let algorithm;
1261
+ function subtleAlgorithm2(alg, algorithm) {
1262
+ const hash = `SHA-${alg.slice(-3)}`;
1263
+ switch (alg) {
1264
+ case "HS256":
1265
+ case "HS384":
1266
+ case "HS512":
1267
+ return { hash, name: "HMAC" };
1268
+ case "PS256":
1269
+ case "PS384":
1270
+ case "PS512":
1271
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
1272
+ case "RS256":
1273
+ case "RS384":
1274
+ case "RS512":
1275
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
1276
+ case "ES256":
1277
+ case "ES384":
1278
+ case "ES512":
1279
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
1280
+ case "Ed25519":
1281
+ case "EdDSA":
1282
+ return { name: "Ed25519" };
1283
+ case "ML-DSA-44":
1284
+ case "ML-DSA-65":
1285
+ case "ML-DSA-87":
1286
+ return { name: alg };
1287
+ default:
1288
+ throw new JOSENotSupported2(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
1289
+ }
1290
+ }
1291
+ async function getSigKey2(alg, key, usage) {
1292
+ if (key instanceof Uint8Array) {
1293
+ if (!alg.startsWith("HS")) {
1294
+ throw new TypeError(invalidKeyInput2(key, "CryptoKey", "KeyObject", "JSON Web Key"));
1295
+ }
1296
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
1297
+ }
1298
+ checkSigCryptoKey2(key, alg, usage);
1299
+ return key;
1300
+ }
1301
+ async function verify2(alg, key, signature, data) {
1302
+ const cryptoKey = await getSigKey2(alg, key, "verify");
1303
+ checkKeyLength2(alg, cryptoKey);
1304
+ const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
1305
+ try {
1306
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
1307
+ } catch {
1308
+ return false;
1309
+ }
1310
+ }
1311
+ var init_signing2 = __esm(() => {
1312
+ init_errors5();
1313
+ });
1314
+
1315
+ // ../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
1316
+ function subtleMapping2(jwk) {
1317
+ let algorithm;
1257
1318
  let keyUsages;
1258
1319
  switch (jwk.kty) {
1259
1320
  case "AKP": {
@@ -1265,7 +1326,7 @@ function subtleMapping2(jwk) {
1265
1326
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
1266
1327
  break;
1267
1328
  default:
1268
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
1329
+ throw new JOSENotSupported2(unsupportedAlg2);
1269
1330
  }
1270
1331
  break;
1271
1332
  }
@@ -1294,22 +1355,19 @@ function subtleMapping2(jwk) {
1294
1355
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
1295
1356
  break;
1296
1357
  default:
1297
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
1358
+ throw new JOSENotSupported2(unsupportedAlg2);
1298
1359
  }
1299
1360
  break;
1300
1361
  }
1301
1362
  case "EC": {
1302
1363
  switch (jwk.alg) {
1303
1364
  case "ES256":
1304
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
1305
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1306
- break;
1307
1365
  case "ES384":
1308
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
1309
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1310
- break;
1311
1366
  case "ES512":
1312
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
1367
+ algorithm = {
1368
+ name: "ECDSA",
1369
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
1370
+ };
1313
1371
  keyUsages = jwk.d ? ["sign"] : ["verify"];
1314
1372
  break;
1315
1373
  case "ECDH-ES":
@@ -1320,7 +1378,7 @@ function subtleMapping2(jwk) {
1320
1378
  keyUsages = jwk.d ? ["deriveBits"] : [];
1321
1379
  break;
1322
1380
  default:
1323
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
1381
+ throw new JOSENotSupported2(unsupportedAlg2);
1324
1382
  }
1325
1383
  break;
1326
1384
  }
@@ -1339,7 +1397,7 @@ function subtleMapping2(jwk) {
1339
1397
  keyUsages = jwk.d ? ["deriveBits"] : [];
1340
1398
  break;
1341
1399
  default:
1342
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
1400
+ throw new JOSENotSupported2(unsupportedAlg2);
1343
1401
  }
1344
1402
  break;
1345
1403
  }
@@ -1360,100 +1418,11 @@ async function jwkToKey2(jwk) {
1360
1418
  delete keyData.use;
1361
1419
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
1362
1420
  }
1421
+ var unsupportedAlg2 = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
1363
1422
  var init_jwk_to_key2 = __esm(() => {
1364
1423
  init_errors5();
1365
1424
  });
1366
1425
 
1367
- // ../../node_modules/jose/dist/webapi/key/import.js
1368
- async function importJWK2(jwk, alg, options) {
1369
- if (!isObject2(jwk)) {
1370
- throw new TypeError("JWK must be an object");
1371
- }
1372
- let ext;
1373
- alg ??= jwk.alg;
1374
- ext ??= options?.extractable ?? jwk.ext;
1375
- switch (jwk.kty) {
1376
- case "oct":
1377
- if (typeof jwk.k !== "string" || !jwk.k) {
1378
- throw new TypeError('missing "k" (Key Value) Parameter value');
1379
- }
1380
- return decode2(jwk.k);
1381
- case "RSA":
1382
- if ("oth" in jwk && jwk.oth !== undefined) {
1383
- throw new JOSENotSupported2('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
1384
- }
1385
- return jwkToKey2({ ...jwk, alg, ext });
1386
- case "AKP": {
1387
- if (typeof jwk.alg !== "string" || !jwk.alg) {
1388
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
1389
- }
1390
- if (alg !== undefined && alg !== jwk.alg) {
1391
- throw new TypeError("JWK alg and alg option value mismatch");
1392
- }
1393
- return jwkToKey2({ ...jwk, ext });
1394
- }
1395
- case "EC":
1396
- case "OKP":
1397
- return jwkToKey2({ ...jwk, alg, ext });
1398
- default:
1399
- throw new JOSENotSupported2('Unsupported "kty" (Key Type) Parameter value');
1400
- }
1401
- }
1402
- var init_import2 = __esm(() => {
1403
- init_base64url2();
1404
- init_jwk_to_key2();
1405
- init_errors5();
1406
- });
1407
-
1408
- // ../../node_modules/jose/dist/webapi/lib/validate_crit.js
1409
- function validateCrit2(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1410
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
1411
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
1412
- }
1413
- if (!protectedHeader || protectedHeader.crit === undefined) {
1414
- return new Set;
1415
- }
1416
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
1417
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
1418
- }
1419
- let recognized;
1420
- if (recognizedOption !== undefined) {
1421
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
1422
- } else {
1423
- recognized = recognizedDefault;
1424
- }
1425
- for (const parameter of protectedHeader.crit) {
1426
- if (!recognized.has(parameter)) {
1427
- throw new JOSENotSupported2(`Extension Header Parameter "${parameter}" is not recognized`);
1428
- }
1429
- if (joseHeader[parameter] === undefined) {
1430
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
1431
- }
1432
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
1433
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
1434
- }
1435
- }
1436
- return new Set(protectedHeader.crit);
1437
- }
1438
- var init_validate_crit2 = __esm(() => {
1439
- init_errors5();
1440
- });
1441
-
1442
- // ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
1443
- function validateAlgorithms2(option, algorithms) {
1444
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1445
- throw new TypeError(`"${option}" option must be an array of strings`);
1446
- }
1447
- if (!algorithms) {
1448
- return;
1449
- }
1450
- return new Set(algorithms);
1451
- }
1452
-
1453
- // ../../node_modules/jose/dist/webapi/lib/is_jwk.js
1454
- var isJWK2 = (key) => isObject2(key) && typeof key.kty === "string", isPrivateJWK2 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string"), isPublicJWK2 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined, isSecretJWK2 = (key) => key.kty === "oct" && typeof key.k === "string";
1455
- var init_is_jwk2 = () => {};
1456
-
1457
1426
  // ../../node_modules/jose/dist/webapi/lib/normalize_key.js
1458
1427
  async function normalizeKey2(key, alg) {
1459
1428
  if (key instanceof Uint8Array) {
@@ -1486,7 +1455,7 @@ async function normalizeKey2(key, alg) {
1486
1455
  }
1487
1456
  throw new Error("unreachable");
1488
1457
  }
1489
- var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1458
+ var unusableForAlg2 = "given KeyObject instance cannot be used for this algorithm", cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1490
1459
  cache2 ||= new WeakMap;
1491
1460
  let cached = cache2.get(key);
1492
1461
  if (cached?.[alg]) {
@@ -1518,13 +1487,13 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1518
1487
  case "ECDH-ES+A256KW":
1519
1488
  break;
1520
1489
  default:
1521
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1490
+ throw new TypeError(unusableForAlg2);
1522
1491
  }
1523
1492
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
1524
1493
  }
1525
1494
  if (keyObject.asymmetricKeyType === "ed25519") {
1526
1495
  if (alg !== "EdDSA" && alg !== "Ed25519") {
1527
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1496
+ throw new TypeError(unusableForAlg2);
1528
1497
  }
1529
1498
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
1530
1499
  isPublic ? "verify" : "sign"
@@ -1535,7 +1504,7 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1535
1504
  case "ml-dsa-65":
1536
1505
  case "ml-dsa-87": {
1537
1506
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
1538
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1507
+ throw new TypeError(unusableForAlg2);
1539
1508
  }
1540
1509
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
1541
1510
  isPublic ? "verify" : "sign"
@@ -1564,7 +1533,7 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1564
1533
  hash = "SHA-512";
1565
1534
  break;
1566
1535
  default:
1567
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1536
+ throw new TypeError(unusableForAlg2);
1568
1537
  }
1569
1538
  if (alg.startsWith("RSA-OAEP")) {
1570
1539
  return keyObject.toCryptoKey({
@@ -1585,21 +1554,10 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1585
1554
  ]);
1586
1555
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
1587
1556
  if (!namedCurve) {
1588
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1589
- }
1590
- if (alg === "ES256" && namedCurve === "P-256") {
1591
- cryptoKey = keyObject.toCryptoKey({
1592
- name: "ECDSA",
1593
- namedCurve
1594
- }, extractable, [isPublic ? "verify" : "sign"]);
1595
- }
1596
- if (alg === "ES384" && namedCurve === "P-384") {
1597
- cryptoKey = keyObject.toCryptoKey({
1598
- name: "ECDSA",
1599
- namedCurve
1600
- }, extractable, [isPublic ? "verify" : "sign"]);
1557
+ throw new TypeError(unusableForAlg2);
1601
1558
  }
1602
- if (alg === "ES512" && namedCurve === "P-521") {
1559
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
1560
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
1603
1561
  cryptoKey = keyObject.toCryptoKey({
1604
1562
  name: "ECDSA",
1605
1563
  namedCurve
@@ -1613,7 +1571,7 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1613
1571
  }
1614
1572
  }
1615
1573
  if (!cryptoKey) {
1616
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
1574
+ throw new TypeError(unusableForAlg2);
1617
1575
  }
1618
1576
  if (!cached) {
1619
1577
  cache2.set(keyObject, { [alg]: cryptoKey });
@@ -1623,11 +1581,96 @@ var cache2, handleJWK2 = async (key, jwk, alg, freeze = false) => {
1623
1581
  return cryptoKey;
1624
1582
  };
1625
1583
  var init_normalize_key2 = __esm(() => {
1626
- init_is_jwk2();
1627
1584
  init_base64url2();
1628
1585
  init_jwk_to_key2();
1629
1586
  });
1630
1587
 
1588
+ // ../../node_modules/jose/dist/webapi/key/import.js
1589
+ async function importJWK2(jwk, alg, options) {
1590
+ if (!isObject2(jwk)) {
1591
+ throw new TypeError("JWK must be an object");
1592
+ }
1593
+ let ext;
1594
+ alg ??= jwk.alg;
1595
+ ext ??= options?.extractable ?? jwk.ext;
1596
+ switch (jwk.kty) {
1597
+ case "oct":
1598
+ if (typeof jwk.k !== "string" || !jwk.k) {
1599
+ throw new TypeError('missing "k" (Key Value) Parameter value');
1600
+ }
1601
+ return decode2(jwk.k);
1602
+ case "RSA":
1603
+ if ("oth" in jwk && jwk.oth !== undefined) {
1604
+ throw new JOSENotSupported2('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
1605
+ }
1606
+ return jwkToKey2({ ...jwk, alg, ext });
1607
+ case "AKP": {
1608
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
1609
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
1610
+ }
1611
+ if (alg !== undefined && alg !== jwk.alg) {
1612
+ throw new TypeError("JWK alg and alg option value mismatch");
1613
+ }
1614
+ return jwkToKey2({ ...jwk, ext });
1615
+ }
1616
+ case "EC":
1617
+ case "OKP":
1618
+ return jwkToKey2({ ...jwk, alg, ext });
1619
+ default:
1620
+ throw new JOSENotSupported2('Unsupported "kty" (Key Type) Parameter value');
1621
+ }
1622
+ }
1623
+ var init_import2 = __esm(() => {
1624
+ init_base64url2();
1625
+ init_jwk_to_key2();
1626
+ init_errors5();
1627
+ });
1628
+
1629
+ // ../../node_modules/jose/dist/webapi/lib/validate_crit.js
1630
+ function validateCrit2(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1631
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
1632
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
1633
+ }
1634
+ if (!protectedHeader || protectedHeader.crit === undefined) {
1635
+ return new Set;
1636
+ }
1637
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
1638
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
1639
+ }
1640
+ let recognized;
1641
+ if (recognizedOption !== undefined) {
1642
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
1643
+ } else {
1644
+ recognized = recognizedDefault;
1645
+ }
1646
+ for (const parameter of protectedHeader.crit) {
1647
+ if (!recognized.has(parameter)) {
1648
+ throw new JOSENotSupported2(`Extension Header Parameter "${parameter}" is not recognized`);
1649
+ }
1650
+ if (joseHeader[parameter] === undefined) {
1651
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
1652
+ }
1653
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
1654
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
1655
+ }
1656
+ }
1657
+ return new Set(protectedHeader.crit);
1658
+ }
1659
+ var init_validate_crit2 = __esm(() => {
1660
+ init_errors5();
1661
+ });
1662
+
1663
+ // ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
1664
+ function validateAlgorithms2(option, algorithms) {
1665
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1666
+ throw new TypeError(`"${option}" option must be an array of strings`);
1667
+ }
1668
+ if (!algorithms) {
1669
+ return;
1670
+ }
1671
+ return new Set(algorithms);
1672
+ }
1673
+
1631
1674
  // ../../node_modules/jose/dist/webapi/lib/check_key_type.js
1632
1675
  function checkKeyType2(alg, key, usage) {
1633
1676
  switch (alg.substring(0, 2)) {
@@ -1744,73 +1787,7 @@ var tag2 = (key) => key?.[Symbol.toStringTag], jwkMatchesOp2 = (alg, key, usage)
1744
1787
  }
1745
1788
  }
1746
1789
  };
1747
- var init_check_key_type2 = __esm(() => {
1748
- init_is_jwk2();
1749
- });
1750
-
1751
- // ../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
1752
- function subtleAlgorithm2(alg, algorithm) {
1753
- const hash = `SHA-${alg.slice(-3)}`;
1754
- switch (alg) {
1755
- case "HS256":
1756
- case "HS384":
1757
- case "HS512":
1758
- return { hash, name: "HMAC" };
1759
- case "PS256":
1760
- case "PS384":
1761
- case "PS512":
1762
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
1763
- case "RS256":
1764
- case "RS384":
1765
- case "RS512":
1766
- return { hash, name: "RSASSA-PKCS1-v1_5" };
1767
- case "ES256":
1768
- case "ES384":
1769
- case "ES512":
1770
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
1771
- case "Ed25519":
1772
- case "EdDSA":
1773
- return { name: "Ed25519" };
1774
- case "ML-DSA-44":
1775
- case "ML-DSA-65":
1776
- case "ML-DSA-87":
1777
- return { name: alg };
1778
- default:
1779
- throw new JOSENotSupported2(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
1780
- }
1781
- }
1782
- var init_subtle_dsa2 = __esm(() => {
1783
- init_errors5();
1784
- });
1785
-
1786
- // ../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
1787
- async function getSigKey2(alg, key, usage) {
1788
- if (key instanceof Uint8Array) {
1789
- if (!alg.startsWith("HS")) {
1790
- throw new TypeError(invalidKeyInput2(key, "CryptoKey", "KeyObject", "JSON Web Key"));
1791
- }
1792
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
1793
- }
1794
- checkSigCryptoKey2(key, alg, usage);
1795
- return key;
1796
- }
1797
- var init_get_sign_verify_key2 = () => {};
1798
-
1799
- // ../../node_modules/jose/dist/webapi/lib/verify.js
1800
- async function verify2(alg, key, signature, data) {
1801
- const cryptoKey = await getSigKey2(alg, key, "verify");
1802
- checkKeyLength2(alg, cryptoKey);
1803
- const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
1804
- try {
1805
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
1806
- } catch {
1807
- return false;
1808
- }
1809
- }
1810
- var init_verify5 = __esm(() => {
1811
- init_subtle_dsa2();
1812
- init_get_sign_verify_key2();
1813
- });
1790
+ var init_check_key_type2 = () => {};
1814
1791
 
1815
1792
  // ../../node_modules/jose/dist/webapi/jws/flattened/verify.js
1816
1793
  async function flattenedVerify2(jws, key, options) {
@@ -1878,12 +1855,7 @@ async function flattenedVerify2(jws, key, options) {
1878
1855
  }
1879
1856
  checkKeyType2(alg, key, "verify");
1880
1857
  const data = concat2(jws.protected !== undefined ? encode2(jws.protected) : new Uint8Array, encode2("."), typeof jws.payload === "string" ? b64 ? encode2(jws.payload) : encoder2.encode(jws.payload) : jws.payload);
1881
- let signature;
1882
- try {
1883
- signature = decode2(jws.signature);
1884
- } catch {
1885
- throw new JWSInvalid2("Failed to base64url decode the signature");
1886
- }
1858
+ const signature = decodeBase64url2(jws.signature, "signature", JWSInvalid2);
1887
1859
  const k = await normalizeKey2(key, alg);
1888
1860
  const verified = await verify2(alg, k, signature, data);
1889
1861
  if (!verified) {
@@ -1891,11 +1863,7 @@ async function flattenedVerify2(jws, key, options) {
1891
1863
  }
1892
1864
  let payload;
1893
1865
  if (b64) {
1894
- try {
1895
- payload = decode2(jws.payload);
1896
- } catch {
1897
- throw new JWSInvalid2("Failed to base64url decode the payload");
1898
- }
1866
+ payload = decodeBase64url2(jws.payload, "payload", JWSInvalid2);
1899
1867
  } else if (typeof jws.payload === "string") {
1900
1868
  payload = encoder2.encode(jws.payload);
1901
1869
  } else {
@@ -1913,11 +1881,12 @@ async function flattenedVerify2(jws, key, options) {
1913
1881
  }
1914
1882
  return result;
1915
1883
  }
1916
- var init_verify7 = __esm(() => {
1884
+ var init_verify4 = __esm(() => {
1917
1885
  init_base64url2();
1918
- init_verify5();
1886
+ init_signing2();
1919
1887
  init_errors5();
1920
1888
  init_buffer_utils2();
1889
+ init_helpers2();
1921
1890
  init_check_key_type2();
1922
1891
  init_validate_crit2();
1923
1892
  init_normalize_key2();
@@ -1942,8 +1911,8 @@ async function compactVerify2(jws, key, options) {
1942
1911
  }
1943
1912
  return result;
1944
1913
  }
1945
- var init_verify8 = __esm(() => {
1946
- init_verify7();
1914
+ var init_verify6 = __esm(() => {
1915
+ init_verify4();
1947
1916
  init_errors5();
1948
1917
  init_buffer_utils2();
1949
1918
  });
@@ -2187,8 +2156,8 @@ async function jwtVerify2(jwt, key, options) {
2187
2156
  }
2188
2157
  return result;
2189
2158
  }
2190
- var init_verify9 = __esm(() => {
2191
- init_verify8();
2159
+ var init_verify7 = __esm(() => {
2160
+ init_verify6();
2192
2161
  init_jwt_claims_set2();
2193
2162
  init_errors5();
2194
2163
  });
@@ -2473,7 +2442,7 @@ var init_remote2 = __esm(() => {
2473
2442
  init_local2();
2474
2443
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
2475
2444
  const NAME = "jose";
2476
- const VERSION = "v6.1.3";
2445
+ const VERSION = "v6.2.1";
2477
2446
  USER_AGENT2 = `${NAME}/${VERSION}`;
2478
2447
  }
2479
2448
  customFetch2 = Symbol();
@@ -2482,7 +2451,7 @@ var init_remote2 = __esm(() => {
2482
2451
 
2483
2452
  // ../../node_modules/jose/dist/webapi/index.js
2484
2453
  var init_webapi2 = __esm(() => {
2485
- init_verify9();
2454
+ init_verify7();
2486
2455
  init_local2();
2487
2456
  init_remote2();
2488
2457
  init_errors5();
@@ -10257,6 +10226,111 @@ function decode(input) {
10257
10226
  var init_base64url = __esm2(() => {
10258
10227
  init_buffer_utils();
10259
10228
  });
10229
+ function getHashLength(hash) {
10230
+ return parseInt(hash.name.slice(4), 10);
10231
+ }
10232
+ function checkHashLength(algorithm, expected) {
10233
+ const actual = getHashLength(algorithm.hash);
10234
+ if (actual !== expected)
10235
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
10236
+ }
10237
+ function getNamedCurve(alg) {
10238
+ switch (alg) {
10239
+ case "ES256":
10240
+ return "P-256";
10241
+ case "ES384":
10242
+ return "P-384";
10243
+ case "ES512":
10244
+ return "P-521";
10245
+ default:
10246
+ throw new Error("unreachable");
10247
+ }
10248
+ }
10249
+ function checkUsage(key, usage) {
10250
+ if (usage && !key.usages.includes(usage)) {
10251
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
10252
+ }
10253
+ }
10254
+ function checkSigCryptoKey(key, alg, usage) {
10255
+ switch (alg) {
10256
+ case "HS256":
10257
+ case "HS384":
10258
+ case "HS512": {
10259
+ if (!isAlgorithm(key.algorithm, "HMAC"))
10260
+ throw unusable("HMAC");
10261
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
10262
+ break;
10263
+ }
10264
+ case "RS256":
10265
+ case "RS384":
10266
+ case "RS512": {
10267
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
10268
+ throw unusable("RSASSA-PKCS1-v1_5");
10269
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
10270
+ break;
10271
+ }
10272
+ case "PS256":
10273
+ case "PS384":
10274
+ case "PS512": {
10275
+ if (!isAlgorithm(key.algorithm, "RSA-PSS"))
10276
+ throw unusable("RSA-PSS");
10277
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
10278
+ break;
10279
+ }
10280
+ case "Ed25519":
10281
+ case "EdDSA": {
10282
+ if (!isAlgorithm(key.algorithm, "Ed25519"))
10283
+ throw unusable("Ed25519");
10284
+ break;
10285
+ }
10286
+ case "ML-DSA-44":
10287
+ case "ML-DSA-65":
10288
+ case "ML-DSA-87": {
10289
+ if (!isAlgorithm(key.algorithm, alg))
10290
+ throw unusable(alg);
10291
+ break;
10292
+ }
10293
+ case "ES256":
10294
+ case "ES384":
10295
+ case "ES512": {
10296
+ if (!isAlgorithm(key.algorithm, "ECDSA"))
10297
+ throw unusable("ECDSA");
10298
+ const expected = getNamedCurve(alg);
10299
+ const actual = key.algorithm.namedCurve;
10300
+ if (actual !== expected)
10301
+ throw unusable(expected, "algorithm.namedCurve");
10302
+ break;
10303
+ }
10304
+ default:
10305
+ throw new TypeError("CryptoKey does not support this operation");
10306
+ }
10307
+ checkUsage(key, usage);
10308
+ }
10309
+ var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
10310
+ var isAlgorithm = (algorithm, name) => algorithm.name === name;
10311
+ function message(msg, actual, ...types) {
10312
+ types = types.filter(Boolean);
10313
+ if (types.length > 2) {
10314
+ const last = types.pop();
10315
+ msg += `one of type ${types.join(", ")}, or ${last}.`;
10316
+ } else if (types.length === 2) {
10317
+ msg += `one of type ${types[0]} or ${types[1]}.`;
10318
+ } else {
10319
+ msg += `of type ${types[0]}.`;
10320
+ }
10321
+ if (actual == null) {
10322
+ msg += ` Received ${actual}`;
10323
+ } else if (typeof actual === "function" && actual.name) {
10324
+ msg += ` Received function ${actual.name}`;
10325
+ } else if (typeof actual === "object" && actual != null) {
10326
+ if (actual.constructor?.name) {
10327
+ msg += ` Received an instance of ${actual.constructor.name}`;
10328
+ }
10329
+ }
10330
+ return msg;
10331
+ }
10332
+ var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
10333
+ var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
10260
10334
  var exports_errors = {};
10261
10335
  __export2(exports_errors, {
10262
10336
  JWTInvalid: () => JWTInvalid,
@@ -10294,8 +10368,8 @@ var init_errors2 = __esm2(() => {
10294
10368
  JOSEError = class JOSEError2 extends Error {
10295
10369
  static code = "ERR_JOSE_GENERIC";
10296
10370
  code = "ERR_JOSE_GENERIC";
10297
- constructor(message, options) {
10298
- super(message, options);
10371
+ constructor(message2, options) {
10372
+ super(message2, options);
10299
10373
  this.name = this.constructor.name;
10300
10374
  Error.captureStackTrace?.(this, this.constructor);
10301
10375
  }
@@ -10306,8 +10380,8 @@ var init_errors2 = __esm2(() => {
10306
10380
  claim;
10307
10381
  reason;
10308
10382
  payload;
10309
- constructor(message, payload, claim = "unspecified", reason = "unspecified") {
10310
- super(message, { cause: { claim, reason, payload } });
10383
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
10384
+ super(message2, { cause: { claim, reason, payload } });
10311
10385
  this.claim = claim;
10312
10386
  this.reason = reason;
10313
10387
  this.payload = payload;
@@ -10319,8 +10393,8 @@ var init_errors2 = __esm2(() => {
10319
10393
  claim;
10320
10394
  reason;
10321
10395
  payload;
10322
- constructor(message, payload, claim = "unspecified", reason = "unspecified") {
10323
- super(message, { cause: { claim, reason, payload } });
10396
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
10397
+ super(message2, { cause: { claim, reason, payload } });
10324
10398
  this.claim = claim;
10325
10399
  this.reason = reason;
10326
10400
  this.payload = payload;
@@ -10337,8 +10411,8 @@ var init_errors2 = __esm2(() => {
10337
10411
  JWEDecryptionFailed = class JWEDecryptionFailed2 extends JOSEError {
10338
10412
  static code = "ERR_JWE_DECRYPTION_FAILED";
10339
10413
  code = "ERR_JWE_DECRYPTION_FAILED";
10340
- constructor(message = "decryption operation failed", options) {
10341
- super(message, options);
10414
+ constructor(message2 = "decryption operation failed", options) {
10415
+ super(message2, options);
10342
10416
  }
10343
10417
  };
10344
10418
  JWEInvalid = class JWEInvalid2 extends JOSEError {
@@ -10364,142 +10438,33 @@ var init_errors2 = __esm2(() => {
10364
10438
  JWKSNoMatchingKey = class JWKSNoMatchingKey2 extends JOSEError {
10365
10439
  static code = "ERR_JWKS_NO_MATCHING_KEY";
10366
10440
  code = "ERR_JWKS_NO_MATCHING_KEY";
10367
- constructor(message = "no applicable key found in the JSON Web Key Set", options) {
10368
- super(message, options);
10441
+ constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
10442
+ super(message2, options);
10369
10443
  }
10370
10444
  };
10371
10445
  JWKSMultipleMatchingKeys = class JWKSMultipleMatchingKeys2 extends JOSEError {
10372
10446
  [Symbol.asyncIterator];
10373
10447
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
10374
10448
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
10375
- constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
10376
- super(message, options);
10449
+ constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
10450
+ super(message2, options);
10377
10451
  }
10378
10452
  };
10379
10453
  JWKSTimeout = class JWKSTimeout2 extends JOSEError {
10380
10454
  static code = "ERR_JWKS_TIMEOUT";
10381
10455
  code = "ERR_JWKS_TIMEOUT";
10382
- constructor(message = "request timed out", options) {
10383
- super(message, options);
10456
+ constructor(message2 = "request timed out", options) {
10457
+ super(message2, options);
10384
10458
  }
10385
10459
  };
10386
10460
  JWSSignatureVerificationFailed = class JWSSignatureVerificationFailed2 extends JOSEError {
10387
10461
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
10388
10462
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
10389
- constructor(message = "signature verification failed", options) {
10390
- super(message, options);
10463
+ constructor(message2 = "signature verification failed", options) {
10464
+ super(message2, options);
10391
10465
  }
10392
10466
  };
10393
10467
  });
10394
- function getHashLength(hash) {
10395
- return parseInt(hash.name.slice(4), 10);
10396
- }
10397
- function getNamedCurve(alg) {
10398
- switch (alg) {
10399
- case "ES256":
10400
- return "P-256";
10401
- case "ES384":
10402
- return "P-384";
10403
- case "ES512":
10404
- return "P-521";
10405
- default:
10406
- throw new Error("unreachable");
10407
- }
10408
- }
10409
- function checkUsage(key, usage) {
10410
- if (usage && !key.usages.includes(usage)) {
10411
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
10412
- }
10413
- }
10414
- function checkSigCryptoKey(key, alg, usage) {
10415
- switch (alg) {
10416
- case "HS256":
10417
- case "HS384":
10418
- case "HS512": {
10419
- if (!isAlgorithm(key.algorithm, "HMAC"))
10420
- throw unusable("HMAC");
10421
- const expected = parseInt(alg.slice(2), 10);
10422
- const actual = getHashLength(key.algorithm.hash);
10423
- if (actual !== expected)
10424
- throw unusable(`SHA-${expected}`, "algorithm.hash");
10425
- break;
10426
- }
10427
- case "RS256":
10428
- case "RS384":
10429
- case "RS512": {
10430
- if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
10431
- throw unusable("RSASSA-PKCS1-v1_5");
10432
- const expected = parseInt(alg.slice(2), 10);
10433
- const actual = getHashLength(key.algorithm.hash);
10434
- if (actual !== expected)
10435
- throw unusable(`SHA-${expected}`, "algorithm.hash");
10436
- break;
10437
- }
10438
- case "PS256":
10439
- case "PS384":
10440
- case "PS512": {
10441
- if (!isAlgorithm(key.algorithm, "RSA-PSS"))
10442
- throw unusable("RSA-PSS");
10443
- const expected = parseInt(alg.slice(2), 10);
10444
- const actual = getHashLength(key.algorithm.hash);
10445
- if (actual !== expected)
10446
- throw unusable(`SHA-${expected}`, "algorithm.hash");
10447
- break;
10448
- }
10449
- case "Ed25519":
10450
- case "EdDSA": {
10451
- if (!isAlgorithm(key.algorithm, "Ed25519"))
10452
- throw unusable("Ed25519");
10453
- break;
10454
- }
10455
- case "ML-DSA-44":
10456
- case "ML-DSA-65":
10457
- case "ML-DSA-87": {
10458
- if (!isAlgorithm(key.algorithm, alg))
10459
- throw unusable(alg);
10460
- break;
10461
- }
10462
- case "ES256":
10463
- case "ES384":
10464
- case "ES512": {
10465
- if (!isAlgorithm(key.algorithm, "ECDSA"))
10466
- throw unusable("ECDSA");
10467
- const expected = getNamedCurve(alg);
10468
- const actual = key.algorithm.namedCurve;
10469
- if (actual !== expected)
10470
- throw unusable(expected, "algorithm.namedCurve");
10471
- break;
10472
- }
10473
- default:
10474
- throw new TypeError("CryptoKey does not support this operation");
10475
- }
10476
- checkUsage(key, usage);
10477
- }
10478
- var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
10479
- var isAlgorithm = (algorithm, name) => algorithm.name === name;
10480
- function message(msg, actual, ...types) {
10481
- types = types.filter(Boolean);
10482
- if (types.length > 2) {
10483
- const last = types.pop();
10484
- msg += `one of type ${types.join(", ")}, or ${last}.`;
10485
- } else if (types.length === 2) {
10486
- msg += `one of type ${types[0]} or ${types[1]}.`;
10487
- } else {
10488
- msg += `of type ${types[0]}.`;
10489
- }
10490
- if (actual == null) {
10491
- msg += ` Received ${actual}`;
10492
- } else if (typeof actual === "function" && actual.name) {
10493
- msg += ` Received function ${actual.name}`;
10494
- } else if (typeof actual === "object" && actual != null) {
10495
- if (actual.constructor?.name) {
10496
- msg += ` Received an instance of ${actual.constructor.name}`;
10497
- }
10498
- }
10499
- return msg;
10500
- }
10501
- var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
10502
- var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
10503
10468
  var isCryptoKey = (key) => {
10504
10469
  if (key?.[Symbol.toStringTag] === "CryptoKey")
10505
10470
  return true;
@@ -10511,6 +10476,31 @@ var isCryptoKey = (key) => {
10511
10476
  };
10512
10477
  var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
10513
10478
  var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
10479
+ function decodeBase64url(value, label, ErrorClass) {
10480
+ try {
10481
+ return decode(value);
10482
+ } catch {
10483
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
10484
+ }
10485
+ }
10486
+ var unprotected;
10487
+ var init_helpers = __esm2(() => {
10488
+ init_base64url();
10489
+ unprotected = Symbol();
10490
+ });
10491
+ function isObject(input) {
10492
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
10493
+ return false;
10494
+ }
10495
+ if (Object.getPrototypeOf(input) === null) {
10496
+ return true;
10497
+ }
10498
+ let proto = input;
10499
+ while (Object.getPrototypeOf(proto) !== null) {
10500
+ proto = Object.getPrototypeOf(proto);
10501
+ }
10502
+ return Object.getPrototypeOf(input) === proto;
10503
+ }
10514
10504
  function isDisjoint(...headers) {
10515
10505
  const sources = headers.filter(Boolean);
10516
10506
  if (sources.length === 0 || sources.length === 1) {
@@ -10532,20 +10522,11 @@ function isDisjoint(...headers) {
10532
10522
  }
10533
10523
  return true;
10534
10524
  }
10535
- function isObject(input) {
10536
- if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
10537
- return false;
10538
- }
10539
- if (Object.getPrototypeOf(input) === null) {
10540
- return true;
10541
- }
10542
- let proto = input;
10543
- while (Object.getPrototypeOf(proto) !== null) {
10544
- proto = Object.getPrototypeOf(proto);
10545
- }
10546
- return Object.getPrototypeOf(input) === proto;
10547
- }
10548
10525
  var isObjectLike = (value) => typeof value === "object" && value !== null;
10526
+ var isJWK = (key) => isObject(key) && typeof key.kty === "string";
10527
+ var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
10528
+ var isPublicJWK = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
10529
+ var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
10549
10530
  function checkKeyLength(alg, key) {
10550
10531
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
10551
10532
  const { modulusLength } = key.algorithm;
@@ -10554,6 +10535,59 @@ function checkKeyLength(alg, key) {
10554
10535
  }
10555
10536
  }
10556
10537
  }
10538
+ function subtleAlgorithm(alg, algorithm) {
10539
+ const hash = `SHA-${alg.slice(-3)}`;
10540
+ switch (alg) {
10541
+ case "HS256":
10542
+ case "HS384":
10543
+ case "HS512":
10544
+ return { hash, name: "HMAC" };
10545
+ case "PS256":
10546
+ case "PS384":
10547
+ case "PS512":
10548
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
10549
+ case "RS256":
10550
+ case "RS384":
10551
+ case "RS512":
10552
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
10553
+ case "ES256":
10554
+ case "ES384":
10555
+ case "ES512":
10556
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
10557
+ case "Ed25519":
10558
+ case "EdDSA":
10559
+ return { name: "Ed25519" };
10560
+ case "ML-DSA-44":
10561
+ case "ML-DSA-65":
10562
+ case "ML-DSA-87":
10563
+ return { name: alg };
10564
+ default:
10565
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
10566
+ }
10567
+ }
10568
+ async function getSigKey(alg, key, usage) {
10569
+ if (key instanceof Uint8Array) {
10570
+ if (!alg.startsWith("HS")) {
10571
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
10572
+ }
10573
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
10574
+ }
10575
+ checkSigCryptoKey(key, alg, usage);
10576
+ return key;
10577
+ }
10578
+ async function verify(alg, key, signature, data) {
10579
+ const cryptoKey = await getSigKey(alg, key, "verify");
10580
+ checkKeyLength(alg, cryptoKey);
10581
+ const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
10582
+ try {
10583
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
10584
+ } catch {
10585
+ return false;
10586
+ }
10587
+ }
10588
+ var init_signing = __esm2(() => {
10589
+ init_errors2();
10590
+ });
10557
10591
  function subtleMapping(jwk) {
10558
10592
  let algorithm;
10559
10593
  let keyUsages;
@@ -10567,7 +10601,7 @@ function subtleMapping(jwk) {
10567
10601
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
10568
10602
  break;
10569
10603
  default:
10570
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
10604
+ throw new JOSENotSupported(unsupportedAlg);
10571
10605
  }
10572
10606
  break;
10573
10607
  }
@@ -10596,22 +10630,19 @@ function subtleMapping(jwk) {
10596
10630
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
10597
10631
  break;
10598
10632
  default:
10599
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
10633
+ throw new JOSENotSupported(unsupportedAlg);
10600
10634
  }
10601
10635
  break;
10602
10636
  }
10603
10637
  case "EC": {
10604
10638
  switch (jwk.alg) {
10605
10639
  case "ES256":
10606
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
10607
- keyUsages = jwk.d ? ["sign"] : ["verify"];
10608
- break;
10609
10640
  case "ES384":
10610
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
10611
- keyUsages = jwk.d ? ["sign"] : ["verify"];
10612
- break;
10613
10641
  case "ES512":
10614
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
10642
+ algorithm = {
10643
+ name: "ECDSA",
10644
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
10645
+ };
10615
10646
  keyUsages = jwk.d ? ["sign"] : ["verify"];
10616
10647
  break;
10617
10648
  case "ECDH-ES":
@@ -10622,134 +10653,50 @@ function subtleMapping(jwk) {
10622
10653
  keyUsages = jwk.d ? ["deriveBits"] : [];
10623
10654
  break;
10624
10655
  default:
10625
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
10626
- }
10627
- break;
10628
- }
10629
- case "OKP": {
10630
- switch (jwk.alg) {
10631
- case "Ed25519":
10632
- case "EdDSA":
10633
- algorithm = { name: "Ed25519" };
10634
- keyUsages = jwk.d ? ["sign"] : ["verify"];
10635
- break;
10636
- case "ECDH-ES":
10637
- case "ECDH-ES+A128KW":
10638
- case "ECDH-ES+A192KW":
10639
- case "ECDH-ES+A256KW":
10640
- algorithm = { name: jwk.crv };
10641
- keyUsages = jwk.d ? ["deriveBits"] : [];
10642
- break;
10643
- default:
10644
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
10645
- }
10646
- break;
10647
- }
10648
- default:
10649
- throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
10650
- }
10651
- return { algorithm, keyUsages };
10652
- }
10653
- async function jwkToKey(jwk) {
10654
- if (!jwk.alg) {
10655
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
10656
- }
10657
- const { algorithm, keyUsages } = subtleMapping(jwk);
10658
- const keyData = { ...jwk };
10659
- if (keyData.kty !== "AKP") {
10660
- delete keyData.alg;
10661
- }
10662
- delete keyData.use;
10663
- return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
10664
- }
10665
- var init_jwk_to_key = __esm2(() => {
10666
- init_errors2();
10667
- });
10668
- async function importJWK(jwk, alg, options) {
10669
- if (!isObject(jwk)) {
10670
- throw new TypeError("JWK must be an object");
10671
- }
10672
- let ext;
10673
- alg ??= jwk.alg;
10674
- ext ??= options?.extractable ?? jwk.ext;
10675
- switch (jwk.kty) {
10676
- case "oct":
10677
- if (typeof jwk.k !== "string" || !jwk.k) {
10678
- throw new TypeError('missing "k" (Key Value) Parameter value');
10679
- }
10680
- return decode(jwk.k);
10681
- case "RSA":
10682
- if ("oth" in jwk && jwk.oth !== undefined) {
10683
- throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
10684
- }
10685
- return jwkToKey({ ...jwk, alg, ext });
10686
- case "AKP": {
10687
- if (typeof jwk.alg !== "string" || !jwk.alg) {
10688
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
10689
- }
10690
- if (alg !== undefined && alg !== jwk.alg) {
10691
- throw new TypeError("JWK alg and alg option value mismatch");
10656
+ throw new JOSENotSupported(unsupportedAlg);
10692
10657
  }
10693
- return jwkToKey({ ...jwk, ext });
10658
+ break;
10659
+ }
10660
+ case "OKP": {
10661
+ switch (jwk.alg) {
10662
+ case "Ed25519":
10663
+ case "EdDSA":
10664
+ algorithm = { name: "Ed25519" };
10665
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
10666
+ break;
10667
+ case "ECDH-ES":
10668
+ case "ECDH-ES+A128KW":
10669
+ case "ECDH-ES+A192KW":
10670
+ case "ECDH-ES+A256KW":
10671
+ algorithm = { name: jwk.crv };
10672
+ keyUsages = jwk.d ? ["deriveBits"] : [];
10673
+ break;
10674
+ default:
10675
+ throw new JOSENotSupported(unsupportedAlg);
10676
+ }
10677
+ break;
10694
10678
  }
10695
- case "EC":
10696
- case "OKP":
10697
- return jwkToKey({ ...jwk, alg, ext });
10698
10679
  default:
10699
- throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
10680
+ throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
10700
10681
  }
10682
+ return { algorithm, keyUsages };
10701
10683
  }
10702
- var init_import = __esm2(() => {
10703
- init_base64url();
10704
- init_jwk_to_key();
10705
- init_errors2();
10706
- });
10707
- function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
10708
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
10709
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
10710
- }
10711
- if (!protectedHeader || protectedHeader.crit === undefined) {
10712
- return new Set;
10713
- }
10714
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
10715
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
10716
- }
10717
- let recognized;
10718
- if (recognizedOption !== undefined) {
10719
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
10720
- } else {
10721
- recognized = recognizedDefault;
10684
+ async function jwkToKey(jwk) {
10685
+ if (!jwk.alg) {
10686
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
10722
10687
  }
10723
- for (const parameter of protectedHeader.crit) {
10724
- if (!recognized.has(parameter)) {
10725
- throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
10726
- }
10727
- if (joseHeader[parameter] === undefined) {
10728
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
10729
- }
10730
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
10731
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
10732
- }
10688
+ const { algorithm, keyUsages } = subtleMapping(jwk);
10689
+ const keyData = { ...jwk };
10690
+ if (keyData.kty !== "AKP") {
10691
+ delete keyData.alg;
10733
10692
  }
10734
- return new Set(protectedHeader.crit);
10693
+ delete keyData.use;
10694
+ return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
10735
10695
  }
10736
- var init_validate_crit = __esm2(() => {
10696
+ var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
10697
+ var init_jwk_to_key = __esm2(() => {
10737
10698
  init_errors2();
10738
10699
  });
10739
- function validateAlgorithms(option, algorithms) {
10740
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
10741
- throw new TypeError(`"${option}" option must be an array of strings`);
10742
- }
10743
- if (!algorithms) {
10744
- return;
10745
- }
10746
- return new Set(algorithms);
10747
- }
10748
- var isJWK = (key) => isObject(key) && typeof key.kty === "string";
10749
- var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
10750
- var isPublicJWK = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
10751
- var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
10752
- var init_is_jwk = () => {};
10753
10700
  async function normalizeKey(key, alg) {
10754
10701
  if (key instanceof Uint8Array) {
10755
10702
  return key;
@@ -10781,6 +10728,7 @@ async function normalizeKey(key, alg) {
10781
10728
  }
10782
10729
  throw new Error("unreachable");
10783
10730
  }
10731
+ var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
10784
10732
  var cache;
10785
10733
  var handleJWK = async (key, jwk, alg, freeze = false) => {
10786
10734
  cache ||= new WeakMap;
@@ -10815,13 +10763,13 @@ var handleKeyObject = (keyObject, alg) => {
10815
10763
  case "ECDH-ES+A256KW":
10816
10764
  break;
10817
10765
  default:
10818
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10766
+ throw new TypeError(unusableForAlg);
10819
10767
  }
10820
10768
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
10821
10769
  }
10822
10770
  if (keyObject.asymmetricKeyType === "ed25519") {
10823
10771
  if (alg !== "EdDSA" && alg !== "Ed25519") {
10824
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10772
+ throw new TypeError(unusableForAlg);
10825
10773
  }
10826
10774
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
10827
10775
  isPublic ? "verify" : "sign"
@@ -10832,7 +10780,7 @@ var handleKeyObject = (keyObject, alg) => {
10832
10780
  case "ml-dsa-65":
10833
10781
  case "ml-dsa-87": {
10834
10782
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
10835
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10783
+ throw new TypeError(unusableForAlg);
10836
10784
  }
10837
10785
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
10838
10786
  isPublic ? "verify" : "sign"
@@ -10861,7 +10809,7 @@ var handleKeyObject = (keyObject, alg) => {
10861
10809
  hash = "SHA-512";
10862
10810
  break;
10863
10811
  default:
10864
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10812
+ throw new TypeError(unusableForAlg);
10865
10813
  }
10866
10814
  if (alg.startsWith("RSA-OAEP")) {
10867
10815
  return keyObject.toCryptoKey({
@@ -10882,21 +10830,10 @@ var handleKeyObject = (keyObject, alg) => {
10882
10830
  ]);
10883
10831
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
10884
10832
  if (!namedCurve) {
10885
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10886
- }
10887
- if (alg === "ES256" && namedCurve === "P-256") {
10888
- cryptoKey = keyObject.toCryptoKey({
10889
- name: "ECDSA",
10890
- namedCurve
10891
- }, extractable, [isPublic ? "verify" : "sign"]);
10892
- }
10893
- if (alg === "ES384" && namedCurve === "P-384") {
10894
- cryptoKey = keyObject.toCryptoKey({
10895
- name: "ECDSA",
10896
- namedCurve
10897
- }, extractable, [isPublic ? "verify" : "sign"]);
10833
+ throw new TypeError(unusableForAlg);
10898
10834
  }
10899
- if (alg === "ES512" && namedCurve === "P-521") {
10835
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
10836
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
10900
10837
  cryptoKey = keyObject.toCryptoKey({
10901
10838
  name: "ECDSA",
10902
10839
  namedCurve
@@ -10910,7 +10847,7 @@ var handleKeyObject = (keyObject, alg) => {
10910
10847
  }
10911
10848
  }
10912
10849
  if (!cryptoKey) {
10913
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
10850
+ throw new TypeError(unusableForAlg);
10914
10851
  }
10915
10852
  if (!cached) {
10916
10853
  cache.set(keyObject, { [alg]: cryptoKey });
@@ -10920,10 +10857,89 @@ var handleKeyObject = (keyObject, alg) => {
10920
10857
  return cryptoKey;
10921
10858
  };
10922
10859
  var init_normalize_key = __esm2(() => {
10923
- init_is_jwk();
10924
10860
  init_base64url();
10925
10861
  init_jwk_to_key();
10926
10862
  });
10863
+ async function importJWK(jwk, alg, options) {
10864
+ if (!isObject(jwk)) {
10865
+ throw new TypeError("JWK must be an object");
10866
+ }
10867
+ let ext;
10868
+ alg ??= jwk.alg;
10869
+ ext ??= options?.extractable ?? jwk.ext;
10870
+ switch (jwk.kty) {
10871
+ case "oct":
10872
+ if (typeof jwk.k !== "string" || !jwk.k) {
10873
+ throw new TypeError('missing "k" (Key Value) Parameter value');
10874
+ }
10875
+ return decode(jwk.k);
10876
+ case "RSA":
10877
+ if ("oth" in jwk && jwk.oth !== undefined) {
10878
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
10879
+ }
10880
+ return jwkToKey({ ...jwk, alg, ext });
10881
+ case "AKP": {
10882
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
10883
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
10884
+ }
10885
+ if (alg !== undefined && alg !== jwk.alg) {
10886
+ throw new TypeError("JWK alg and alg option value mismatch");
10887
+ }
10888
+ return jwkToKey({ ...jwk, ext });
10889
+ }
10890
+ case "EC":
10891
+ case "OKP":
10892
+ return jwkToKey({ ...jwk, alg, ext });
10893
+ default:
10894
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
10895
+ }
10896
+ }
10897
+ var init_import = __esm2(() => {
10898
+ init_base64url();
10899
+ init_jwk_to_key();
10900
+ init_errors2();
10901
+ });
10902
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
10903
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
10904
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
10905
+ }
10906
+ if (!protectedHeader || protectedHeader.crit === undefined) {
10907
+ return new Set;
10908
+ }
10909
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
10910
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
10911
+ }
10912
+ let recognized;
10913
+ if (recognizedOption !== undefined) {
10914
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
10915
+ } else {
10916
+ recognized = recognizedDefault;
10917
+ }
10918
+ for (const parameter of protectedHeader.crit) {
10919
+ if (!recognized.has(parameter)) {
10920
+ throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
10921
+ }
10922
+ if (joseHeader[parameter] === undefined) {
10923
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
10924
+ }
10925
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
10926
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
10927
+ }
10928
+ }
10929
+ return new Set(protectedHeader.crit);
10930
+ }
10931
+ var init_validate_crit = __esm2(() => {
10932
+ init_errors2();
10933
+ });
10934
+ function validateAlgorithms(option, algorithms) {
10935
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
10936
+ throw new TypeError(`"${option}" option must be an array of strings`);
10937
+ }
10938
+ if (!algorithms) {
10939
+ return;
10940
+ }
10941
+ return new Set(algorithms);
10942
+ }
10927
10943
  function checkKeyType(alg, key, usage) {
10928
10944
  switch (alg.substring(0, 2)) {
10929
10945
  case "A1":
@@ -11042,67 +11058,7 @@ var asymmetricTypeCheck = (alg, key, usage) => {
11042
11058
  }
11043
11059
  }
11044
11060
  };
11045
- var init_check_key_type = __esm2(() => {
11046
- init_is_jwk();
11047
- });
11048
- function subtleAlgorithm(alg, algorithm) {
11049
- const hash = `SHA-${alg.slice(-3)}`;
11050
- switch (alg) {
11051
- case "HS256":
11052
- case "HS384":
11053
- case "HS512":
11054
- return { hash, name: "HMAC" };
11055
- case "PS256":
11056
- case "PS384":
11057
- case "PS512":
11058
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
11059
- case "RS256":
11060
- case "RS384":
11061
- case "RS512":
11062
- return { hash, name: "RSASSA-PKCS1-v1_5" };
11063
- case "ES256":
11064
- case "ES384":
11065
- case "ES512":
11066
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
11067
- case "Ed25519":
11068
- case "EdDSA":
11069
- return { name: "Ed25519" };
11070
- case "ML-DSA-44":
11071
- case "ML-DSA-65":
11072
- case "ML-DSA-87":
11073
- return { name: alg };
11074
- default:
11075
- throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
11076
- }
11077
- }
11078
- var init_subtle_dsa = __esm2(() => {
11079
- init_errors2();
11080
- });
11081
- async function getSigKey(alg, key, usage) {
11082
- if (key instanceof Uint8Array) {
11083
- if (!alg.startsWith("HS")) {
11084
- throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
11085
- }
11086
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
11087
- }
11088
- checkSigCryptoKey(key, alg, usage);
11089
- return key;
11090
- }
11091
- var init_get_sign_verify_key = () => {};
11092
- async function verify(alg, key, signature, data) {
11093
- const cryptoKey = await getSigKey(alg, key, "verify");
11094
- checkKeyLength(alg, cryptoKey);
11095
- const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
11096
- try {
11097
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
11098
- } catch {
11099
- return false;
11100
- }
11101
- }
11102
- var init_verify = __esm2(() => {
11103
- init_subtle_dsa();
11104
- init_get_sign_verify_key();
11105
- });
11061
+ var init_check_key_type = () => {};
11106
11062
  async function flattenedVerify(jws, key, options) {
11107
11063
  if (!isObject(jws)) {
11108
11064
  throw new JWSInvalid("Flattened JWS must be an object");
@@ -11168,12 +11124,7 @@ async function flattenedVerify(jws, key, options) {
11168
11124
  }
11169
11125
  checkKeyType(alg, key, "verify");
11170
11126
  const data = concat(jws.protected !== undefined ? encode(jws.protected) : new Uint8Array, encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
11171
- let signature;
11172
- try {
11173
- signature = decode(jws.signature);
11174
- } catch {
11175
- throw new JWSInvalid("Failed to base64url decode the signature");
11176
- }
11127
+ const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
11177
11128
  const k = await normalizeKey(key, alg);
11178
11129
  const verified = await verify(alg, k, signature, data);
11179
11130
  if (!verified) {
@@ -11181,11 +11132,7 @@ async function flattenedVerify(jws, key, options) {
11181
11132
  }
11182
11133
  let payload;
11183
11134
  if (b64) {
11184
- try {
11185
- payload = decode(jws.payload);
11186
- } catch {
11187
- throw new JWSInvalid("Failed to base64url decode the payload");
11188
- }
11135
+ payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
11189
11136
  } else if (typeof jws.payload === "string") {
11190
11137
  payload = encoder.encode(jws.payload);
11191
11138
  } else {
@@ -11203,11 +11150,12 @@ async function flattenedVerify(jws, key, options) {
11203
11150
  }
11204
11151
  return result;
11205
11152
  }
11206
- var init_verify2 = __esm2(() => {
11153
+ var init_verify = __esm2(() => {
11207
11154
  init_base64url();
11208
- init_verify();
11155
+ init_signing();
11209
11156
  init_errors2();
11210
11157
  init_buffer_utils();
11158
+ init_helpers();
11211
11159
  init_check_key_type();
11212
11160
  init_validate_crit();
11213
11161
  init_normalize_key();
@@ -11230,8 +11178,8 @@ async function compactVerify(jws, key, options) {
11230
11178
  }
11231
11179
  return result;
11232
11180
  }
11233
- var init_verify3 = __esm2(() => {
11234
- init_verify2();
11181
+ var init_verify2 = __esm2(() => {
11182
+ init_verify();
11235
11183
  init_errors2();
11236
11184
  init_buffer_utils();
11237
11185
  });
@@ -11479,8 +11427,8 @@ async function jwtVerify(jwt, key, options) {
11479
11427
  }
11480
11428
  return result;
11481
11429
  }
11482
- var init_verify4 = __esm2(() => {
11483
- init_verify3();
11430
+ var init_verify3 = __esm2(() => {
11431
+ init_verify2();
11484
11432
  init_jwt_claims_set();
11485
11433
  init_errors2();
11486
11434
  });
@@ -11763,14 +11711,14 @@ var init_remote = __esm2(() => {
11763
11711
  init_local();
11764
11712
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
11765
11713
  const NAME = "jose";
11766
- const VERSION = "v6.1.3";
11714
+ const VERSION = "v6.2.1";
11767
11715
  USER_AGENT = `${NAME}/${VERSION}`;
11768
11716
  }
11769
11717
  customFetch = Symbol();
11770
11718
  jwksCache = Symbol();
11771
11719
  });
11772
11720
  var init_webapi = __esm2(() => {
11773
- init_verify4();
11721
+ init_verify3();
11774
11722
  init_local();
11775
11723
  init_remote();
11776
11724
  init_errors2();
@@ -24507,6 +24455,27 @@ function notFoundHttpResponse() {
24507
24455
  }
24508
24456
  });
24509
24457
  }
24458
+ function isMissingModuleError(error, moduleName) {
24459
+ if (!error) {
24460
+ return false;
24461
+ }
24462
+ const errorString = String(error);
24463
+ const moduleSpecifiers = [moduleName, `convex/${moduleName}`];
24464
+ const hasDirectMissingMessage = moduleSpecifiers.some((specifier) => errorString.includes(`Module not found: ${specifier}`));
24465
+ if (hasDirectMissingMessage || errorString.toLowerCase().includes("failed to load convex module")) {
24466
+ return true;
24467
+ }
24468
+ const hasResolutionMessage = moduleSpecifiers.some((specifier) => errorString.includes(`Unable to resolve module "${specifier}"`));
24469
+ const causes = error.causes;
24470
+ if (Array.isArray(causes) && causes.length > 0) {
24471
+ return hasResolutionMessage ? causes.every((cause2) => isMissingModuleError(cause2, moduleName)) : causes.some((cause2) => isMissingModuleError(cause2, moduleName));
24472
+ }
24473
+ const cause = error.cause;
24474
+ if (cause) {
24475
+ return isMissingModuleError(cause, moduleName);
24476
+ }
24477
+ return hasResolutionMessage;
24478
+ }
24510
24479
  function getHttpRouteRank(routePath) {
24511
24480
  if (routePath.endsWith("*")) {
24512
24481
  return { kind: 0, length: routePath.length - 1 };
@@ -24678,8 +24647,7 @@ class InlineUdfExecutor {
24678
24647
  try {
24679
24648
  return await loadConvexModule2(moduleName, { componentPath });
24680
24649
  } catch (error) {
24681
- const message3 = error?.message?.toLowerCase();
24682
- if (message3 && (message3.includes("module not found") || message3.includes("failed to load convex module"))) {
24650
+ if (isMissingModuleError(error, moduleName)) {
24683
24651
  throw new Error(`UDF module not found: ${moduleName}`);
24684
24652
  }
24685
24653
  throw error;