@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.
@@ -2828,6 +2828,113 @@ var init_base64url = __esm(() => {
2828
2828
  init_buffer_utils();
2829
2829
  });
2830
2830
 
2831
+ // ../../node_modules/jose/dist/webapi/lib/crypto_key.js
2832
+ function getHashLength(hash) {
2833
+ return parseInt(hash.name.slice(4), 10);
2834
+ }
2835
+ function checkHashLength(algorithm, expected) {
2836
+ const actual = getHashLength(algorithm.hash);
2837
+ if (actual !== expected)
2838
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
2839
+ }
2840
+ function getNamedCurve(alg) {
2841
+ switch (alg) {
2842
+ case "ES256":
2843
+ return "P-256";
2844
+ case "ES384":
2845
+ return "P-384";
2846
+ case "ES512":
2847
+ return "P-521";
2848
+ default:
2849
+ throw new Error("unreachable");
2850
+ }
2851
+ }
2852
+ function checkUsage(key, usage) {
2853
+ if (usage && !key.usages.includes(usage)) {
2854
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
2855
+ }
2856
+ }
2857
+ function checkSigCryptoKey(key, alg, usage) {
2858
+ switch (alg) {
2859
+ case "HS256":
2860
+ case "HS384":
2861
+ case "HS512": {
2862
+ if (!isAlgorithm(key.algorithm, "HMAC"))
2863
+ throw unusable("HMAC");
2864
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
2865
+ break;
2866
+ }
2867
+ case "RS256":
2868
+ case "RS384":
2869
+ case "RS512": {
2870
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
2871
+ throw unusable("RSASSA-PKCS1-v1_5");
2872
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
2873
+ break;
2874
+ }
2875
+ case "PS256":
2876
+ case "PS384":
2877
+ case "PS512": {
2878
+ if (!isAlgorithm(key.algorithm, "RSA-PSS"))
2879
+ throw unusable("RSA-PSS");
2880
+ checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
2881
+ break;
2882
+ }
2883
+ case "Ed25519":
2884
+ case "EdDSA": {
2885
+ if (!isAlgorithm(key.algorithm, "Ed25519"))
2886
+ throw unusable("Ed25519");
2887
+ break;
2888
+ }
2889
+ case "ML-DSA-44":
2890
+ case "ML-DSA-65":
2891
+ case "ML-DSA-87": {
2892
+ if (!isAlgorithm(key.algorithm, alg))
2893
+ throw unusable(alg);
2894
+ break;
2895
+ }
2896
+ case "ES256":
2897
+ case "ES384":
2898
+ case "ES512": {
2899
+ if (!isAlgorithm(key.algorithm, "ECDSA"))
2900
+ throw unusable("ECDSA");
2901
+ const expected = getNamedCurve(alg);
2902
+ const actual = key.algorithm.namedCurve;
2903
+ if (actual !== expected)
2904
+ throw unusable(expected, "algorithm.namedCurve");
2905
+ break;
2906
+ }
2907
+ default:
2908
+ throw new TypeError("CryptoKey does not support this operation");
2909
+ }
2910
+ checkUsage(key, usage);
2911
+ }
2912
+ 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;
2913
+
2914
+ // ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
2915
+ function message(msg, actual, ...types) {
2916
+ types = types.filter(Boolean);
2917
+ if (types.length > 2) {
2918
+ const last = types.pop();
2919
+ msg += `one of type ${types.join(", ")}, or ${last}.`;
2920
+ } else if (types.length === 2) {
2921
+ msg += `one of type ${types[0]} or ${types[1]}.`;
2922
+ } else {
2923
+ msg += `of type ${types[0]}.`;
2924
+ }
2925
+ if (actual == null) {
2926
+ msg += ` Received ${actual}`;
2927
+ } else if (typeof actual === "function" && actual.name) {
2928
+ msg += ` Received function ${actual.name}`;
2929
+ } else if (typeof actual === "object" && actual != null) {
2930
+ if (actual.constructor?.name) {
2931
+ msg += ` Received an instance of ${actual.constructor.name}`;
2932
+ }
2933
+ }
2934
+ return msg;
2935
+ }
2936
+ var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types), withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
2937
+
2831
2938
  // ../../node_modules/jose/dist/webapi/util/errors.js
2832
2939
  var exports_errors = {};
2833
2940
  __export(exports_errors, {
@@ -2852,8 +2959,8 @@ var init_errors2 = __esm(() => {
2852
2959
  JOSEError = class JOSEError extends Error {
2853
2960
  static code = "ERR_JOSE_GENERIC";
2854
2961
  code = "ERR_JOSE_GENERIC";
2855
- constructor(message, options) {
2856
- super(message, options);
2962
+ constructor(message2, options) {
2963
+ super(message2, options);
2857
2964
  this.name = this.constructor.name;
2858
2965
  Error.captureStackTrace?.(this, this.constructor);
2859
2966
  }
@@ -2864,8 +2971,8 @@ var init_errors2 = __esm(() => {
2864
2971
  claim;
2865
2972
  reason;
2866
2973
  payload;
2867
- constructor(message, payload, claim = "unspecified", reason = "unspecified") {
2868
- super(message, { cause: { claim, reason, payload } });
2974
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
2975
+ super(message2, { cause: { claim, reason, payload } });
2869
2976
  this.claim = claim;
2870
2977
  this.reason = reason;
2871
2978
  this.payload = payload;
@@ -2877,8 +2984,8 @@ var init_errors2 = __esm(() => {
2877
2984
  claim;
2878
2985
  reason;
2879
2986
  payload;
2880
- constructor(message, payload, claim = "unspecified", reason = "unspecified") {
2881
- super(message, { cause: { claim, reason, payload } });
2987
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
2988
+ super(message2, { cause: { claim, reason, payload } });
2882
2989
  this.claim = claim;
2883
2990
  this.reason = reason;
2884
2991
  this.payload = payload;
@@ -2895,8 +3002,8 @@ var init_errors2 = __esm(() => {
2895
3002
  JWEDecryptionFailed = class JWEDecryptionFailed extends JOSEError {
2896
3003
  static code = "ERR_JWE_DECRYPTION_FAILED";
2897
3004
  code = "ERR_JWE_DECRYPTION_FAILED";
2898
- constructor(message = "decryption operation failed", options) {
2899
- super(message, options);
3005
+ constructor(message2 = "decryption operation failed", options) {
3006
+ super(message2, options);
2900
3007
  }
2901
3008
  };
2902
3009
  JWEInvalid = class JWEInvalid extends JOSEError {
@@ -2922,145 +3029,34 @@ var init_errors2 = __esm(() => {
2922
3029
  JWKSNoMatchingKey = class JWKSNoMatchingKey extends JOSEError {
2923
3030
  static code = "ERR_JWKS_NO_MATCHING_KEY";
2924
3031
  code = "ERR_JWKS_NO_MATCHING_KEY";
2925
- constructor(message = "no applicable key found in the JSON Web Key Set", options) {
2926
- super(message, options);
3032
+ constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
3033
+ super(message2, options);
2927
3034
  }
2928
3035
  };
2929
3036
  JWKSMultipleMatchingKeys = class JWKSMultipleMatchingKeys extends JOSEError {
2930
3037
  [Symbol.asyncIterator];
2931
3038
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
2932
3039
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
2933
- constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
2934
- super(message, options);
3040
+ constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
3041
+ super(message2, options);
2935
3042
  }
2936
3043
  };
2937
3044
  JWKSTimeout = class JWKSTimeout extends JOSEError {
2938
3045
  static code = "ERR_JWKS_TIMEOUT";
2939
3046
  code = "ERR_JWKS_TIMEOUT";
2940
- constructor(message = "request timed out", options) {
2941
- super(message, options);
3047
+ constructor(message2 = "request timed out", options) {
3048
+ super(message2, options);
2942
3049
  }
2943
3050
  };
2944
3051
  JWSSignatureVerificationFailed = class JWSSignatureVerificationFailed extends JOSEError {
2945
3052
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
2946
3053
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
2947
- constructor(message = "signature verification failed", options) {
2948
- super(message, options);
3054
+ constructor(message2 = "signature verification failed", options) {
3055
+ super(message2, options);
2949
3056
  }
2950
3057
  };
2951
3058
  });
2952
3059
 
2953
- // ../../node_modules/jose/dist/webapi/lib/crypto_key.js
2954
- function getHashLength(hash) {
2955
- return parseInt(hash.name.slice(4), 10);
2956
- }
2957
- function getNamedCurve(alg) {
2958
- switch (alg) {
2959
- case "ES256":
2960
- return "P-256";
2961
- case "ES384":
2962
- return "P-384";
2963
- case "ES512":
2964
- return "P-521";
2965
- default:
2966
- throw new Error("unreachable");
2967
- }
2968
- }
2969
- function checkUsage(key, usage) {
2970
- if (usage && !key.usages.includes(usage)) {
2971
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
2972
- }
2973
- }
2974
- function checkSigCryptoKey(key, alg, usage) {
2975
- switch (alg) {
2976
- case "HS256":
2977
- case "HS384":
2978
- case "HS512": {
2979
- if (!isAlgorithm(key.algorithm, "HMAC"))
2980
- throw unusable("HMAC");
2981
- const expected = parseInt(alg.slice(2), 10);
2982
- const actual = getHashLength(key.algorithm.hash);
2983
- if (actual !== expected)
2984
- throw unusable(`SHA-${expected}`, "algorithm.hash");
2985
- break;
2986
- }
2987
- case "RS256":
2988
- case "RS384":
2989
- case "RS512": {
2990
- if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
2991
- throw unusable("RSASSA-PKCS1-v1_5");
2992
- const expected = parseInt(alg.slice(2), 10);
2993
- const actual = getHashLength(key.algorithm.hash);
2994
- if (actual !== expected)
2995
- throw unusable(`SHA-${expected}`, "algorithm.hash");
2996
- break;
2997
- }
2998
- case "PS256":
2999
- case "PS384":
3000
- case "PS512": {
3001
- if (!isAlgorithm(key.algorithm, "RSA-PSS"))
3002
- throw unusable("RSA-PSS");
3003
- const expected = parseInt(alg.slice(2), 10);
3004
- const actual = getHashLength(key.algorithm.hash);
3005
- if (actual !== expected)
3006
- throw unusable(`SHA-${expected}`, "algorithm.hash");
3007
- break;
3008
- }
3009
- case "Ed25519":
3010
- case "EdDSA": {
3011
- if (!isAlgorithm(key.algorithm, "Ed25519"))
3012
- throw unusable("Ed25519");
3013
- break;
3014
- }
3015
- case "ML-DSA-44":
3016
- case "ML-DSA-65":
3017
- case "ML-DSA-87": {
3018
- if (!isAlgorithm(key.algorithm, alg))
3019
- throw unusable(alg);
3020
- break;
3021
- }
3022
- case "ES256":
3023
- case "ES384":
3024
- case "ES512": {
3025
- if (!isAlgorithm(key.algorithm, "ECDSA"))
3026
- throw unusable("ECDSA");
3027
- const expected = getNamedCurve(alg);
3028
- const actual = key.algorithm.namedCurve;
3029
- if (actual !== expected)
3030
- throw unusable(expected, "algorithm.namedCurve");
3031
- break;
3032
- }
3033
- default:
3034
- throw new TypeError("CryptoKey does not support this operation");
3035
- }
3036
- checkUsage(key, usage);
3037
- }
3038
- 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;
3039
-
3040
- // ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
3041
- function message(msg, actual, ...types) {
3042
- types = types.filter(Boolean);
3043
- if (types.length > 2) {
3044
- const last = types.pop();
3045
- msg += `one of type ${types.join(", ")}, or ${last}.`;
3046
- } else if (types.length === 2) {
3047
- msg += `one of type ${types[0]} or ${types[1]}.`;
3048
- } else {
3049
- msg += `of type ${types[0]}.`;
3050
- }
3051
- if (actual == null) {
3052
- msg += ` Received ${actual}`;
3053
- } else if (typeof actual === "function" && actual.name) {
3054
- msg += ` Received function ${actual.name}`;
3055
- } else if (typeof actual === "object" && actual != null) {
3056
- if (actual.constructor?.name) {
3057
- msg += ` Received an instance of ${actual.constructor.name}`;
3058
- }
3059
- }
3060
- return msg;
3061
- }
3062
- var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types), withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
3063
-
3064
3060
  // ../../node_modules/jose/dist/webapi/lib/is_key_like.js
3065
3061
  var isCryptoKey = (key) => {
3066
3062
  if (key?.[Symbol.toStringTag] === "CryptoKey")
@@ -3072,7 +3068,34 @@ var isCryptoKey = (key) => {
3072
3068
  }
3073
3069
  }, isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject", isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
3074
3070
 
3075
- // ../../node_modules/jose/dist/webapi/lib/is_disjoint.js
3071
+ // ../../node_modules/jose/dist/webapi/lib/helpers.js
3072
+ function decodeBase64url(value, label, ErrorClass) {
3073
+ try {
3074
+ return decode(value);
3075
+ } catch {
3076
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
3077
+ }
3078
+ }
3079
+ var unprotected;
3080
+ var init_helpers = __esm(() => {
3081
+ init_base64url();
3082
+ unprotected = Symbol();
3083
+ });
3084
+
3085
+ // ../../node_modules/jose/dist/webapi/lib/type_checks.js
3086
+ function isObject(input) {
3087
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
3088
+ return false;
3089
+ }
3090
+ if (Object.getPrototypeOf(input) === null) {
3091
+ return true;
3092
+ }
3093
+ let proto = input;
3094
+ while (Object.getPrototypeOf(proto) !== null) {
3095
+ proto = Object.getPrototypeOf(proto);
3096
+ }
3097
+ return Object.getPrototypeOf(input) === proto;
3098
+ }
3076
3099
  function isDisjoint(...headers) {
3077
3100
  const sources = headers.filter(Boolean);
3078
3101
  if (sources.length === 0 || sources.length === 1) {
@@ -3094,24 +3117,9 @@ function isDisjoint(...headers) {
3094
3117
  }
3095
3118
  return true;
3096
3119
  }
3120
+ 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";
3097
3121
 
3098
- // ../../node_modules/jose/dist/webapi/lib/is_object.js
3099
- function isObject(input) {
3100
- if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
3101
- return false;
3102
- }
3103
- if (Object.getPrototypeOf(input) === null) {
3104
- return true;
3105
- }
3106
- let proto = input;
3107
- while (Object.getPrototypeOf(proto) !== null) {
3108
- proto = Object.getPrototypeOf(proto);
3109
- }
3110
- return Object.getPrototypeOf(input) === proto;
3111
- }
3112
- var isObjectLike = (value) => typeof value === "object" && value !== null;
3113
-
3114
- // ../../node_modules/jose/dist/webapi/lib/check_key_length.js
3122
+ // ../../node_modules/jose/dist/webapi/lib/signing.js
3115
3123
  function checkKeyLength(alg, key) {
3116
3124
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
3117
3125
  const { modulusLength } = key.algorithm;
@@ -3120,6 +3128,59 @@ function checkKeyLength(alg, key) {
3120
3128
  }
3121
3129
  }
3122
3130
  }
3131
+ function subtleAlgorithm(alg, algorithm) {
3132
+ const hash = `SHA-${alg.slice(-3)}`;
3133
+ switch (alg) {
3134
+ case "HS256":
3135
+ case "HS384":
3136
+ case "HS512":
3137
+ return { hash, name: "HMAC" };
3138
+ case "PS256":
3139
+ case "PS384":
3140
+ case "PS512":
3141
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
3142
+ case "RS256":
3143
+ case "RS384":
3144
+ case "RS512":
3145
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
3146
+ case "ES256":
3147
+ case "ES384":
3148
+ case "ES512":
3149
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
3150
+ case "Ed25519":
3151
+ case "EdDSA":
3152
+ return { name: "Ed25519" };
3153
+ case "ML-DSA-44":
3154
+ case "ML-DSA-65":
3155
+ case "ML-DSA-87":
3156
+ return { name: alg };
3157
+ default:
3158
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
3159
+ }
3160
+ }
3161
+ async function getSigKey(alg, key, usage) {
3162
+ if (key instanceof Uint8Array) {
3163
+ if (!alg.startsWith("HS")) {
3164
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
3165
+ }
3166
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
3167
+ }
3168
+ checkSigCryptoKey(key, alg, usage);
3169
+ return key;
3170
+ }
3171
+ async function verify(alg, key, signature, data) {
3172
+ const cryptoKey = await getSigKey(alg, key, "verify");
3173
+ checkKeyLength(alg, cryptoKey);
3174
+ const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
3175
+ try {
3176
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
3177
+ } catch {
3178
+ return false;
3179
+ }
3180
+ }
3181
+ var init_signing = __esm(() => {
3182
+ init_errors2();
3183
+ });
3123
3184
 
3124
3185
  // ../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
3125
3186
  function subtleMapping(jwk) {
@@ -3135,7 +3196,7 @@ function subtleMapping(jwk) {
3135
3196
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
3136
3197
  break;
3137
3198
  default:
3138
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3199
+ throw new JOSENotSupported(unsupportedAlg);
3139
3200
  }
3140
3201
  break;
3141
3202
  }
@@ -3164,22 +3225,19 @@ function subtleMapping(jwk) {
3164
3225
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
3165
3226
  break;
3166
3227
  default:
3167
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3228
+ throw new JOSENotSupported(unsupportedAlg);
3168
3229
  }
3169
3230
  break;
3170
3231
  }
3171
3232
  case "EC": {
3172
3233
  switch (jwk.alg) {
3173
3234
  case "ES256":
3174
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
3175
- keyUsages = jwk.d ? ["sign"] : ["verify"];
3176
- break;
3177
3235
  case "ES384":
3178
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
3179
- keyUsages = jwk.d ? ["sign"] : ["verify"];
3180
- break;
3181
3236
  case "ES512":
3182
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
3237
+ algorithm = {
3238
+ name: "ECDSA",
3239
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
3240
+ };
3183
3241
  keyUsages = jwk.d ? ["sign"] : ["verify"];
3184
3242
  break;
3185
3243
  case "ECDH-ES":
@@ -3190,7 +3248,7 @@ function subtleMapping(jwk) {
3190
3248
  keyUsages = jwk.d ? ["deriveBits"] : [];
3191
3249
  break;
3192
3250
  default:
3193
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3251
+ throw new JOSENotSupported(unsupportedAlg);
3194
3252
  }
3195
3253
  break;
3196
3254
  }
@@ -3209,7 +3267,7 @@ function subtleMapping(jwk) {
3209
3267
  keyUsages = jwk.d ? ["deriveBits"] : [];
3210
3268
  break;
3211
3269
  default:
3212
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3270
+ throw new JOSENotSupported(unsupportedAlg);
3213
3271
  }
3214
3272
  break;
3215
3273
  }
@@ -3230,100 +3288,11 @@ async function jwkToKey(jwk) {
3230
3288
  delete keyData.use;
3231
3289
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
3232
3290
  }
3291
+ var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
3233
3292
  var init_jwk_to_key = __esm(() => {
3234
3293
  init_errors2();
3235
3294
  });
3236
3295
 
3237
- // ../../node_modules/jose/dist/webapi/key/import.js
3238
- async function importJWK(jwk, alg, options) {
3239
- if (!isObject(jwk)) {
3240
- throw new TypeError("JWK must be an object");
3241
- }
3242
- let ext;
3243
- alg ??= jwk.alg;
3244
- ext ??= options?.extractable ?? jwk.ext;
3245
- switch (jwk.kty) {
3246
- case "oct":
3247
- if (typeof jwk.k !== "string" || !jwk.k) {
3248
- throw new TypeError('missing "k" (Key Value) Parameter value');
3249
- }
3250
- return decode(jwk.k);
3251
- case "RSA":
3252
- if ("oth" in jwk && jwk.oth !== undefined) {
3253
- throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
3254
- }
3255
- return jwkToKey({ ...jwk, alg, ext });
3256
- case "AKP": {
3257
- if (typeof jwk.alg !== "string" || !jwk.alg) {
3258
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
3259
- }
3260
- if (alg !== undefined && alg !== jwk.alg) {
3261
- throw new TypeError("JWK alg and alg option value mismatch");
3262
- }
3263
- return jwkToKey({ ...jwk, ext });
3264
- }
3265
- case "EC":
3266
- case "OKP":
3267
- return jwkToKey({ ...jwk, alg, ext });
3268
- default:
3269
- throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
3270
- }
3271
- }
3272
- var init_import = __esm(() => {
3273
- init_base64url();
3274
- init_jwk_to_key();
3275
- init_errors2();
3276
- });
3277
-
3278
- // ../../node_modules/jose/dist/webapi/lib/validate_crit.js
3279
- function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
3280
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
3281
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
3282
- }
3283
- if (!protectedHeader || protectedHeader.crit === undefined) {
3284
- return new Set;
3285
- }
3286
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
3287
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
3288
- }
3289
- let recognized;
3290
- if (recognizedOption !== undefined) {
3291
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
3292
- } else {
3293
- recognized = recognizedDefault;
3294
- }
3295
- for (const parameter of protectedHeader.crit) {
3296
- if (!recognized.has(parameter)) {
3297
- throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
3298
- }
3299
- if (joseHeader[parameter] === undefined) {
3300
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
3301
- }
3302
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
3303
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
3304
- }
3305
- }
3306
- return new Set(protectedHeader.crit);
3307
- }
3308
- var init_validate_crit = __esm(() => {
3309
- init_errors2();
3310
- });
3311
-
3312
- // ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
3313
- function validateAlgorithms(option, algorithms) {
3314
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
3315
- throw new TypeError(`"${option}" option must be an array of strings`);
3316
- }
3317
- if (!algorithms) {
3318
- return;
3319
- }
3320
- return new Set(algorithms);
3321
- }
3322
-
3323
- // ../../node_modules/jose/dist/webapi/lib/is_jwk.js
3324
- var 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";
3325
- var init_is_jwk = () => {};
3326
-
3327
3296
  // ../../node_modules/jose/dist/webapi/lib/normalize_key.js
3328
3297
  async function normalizeKey(key, alg) {
3329
3298
  if (key instanceof Uint8Array) {
@@ -3356,7 +3325,7 @@ async function normalizeKey(key, alg) {
3356
3325
  }
3357
3326
  throw new Error("unreachable");
3358
3327
  }
3359
- var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3328
+ var unusableForAlg = "given KeyObject instance cannot be used for this algorithm", cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3360
3329
  cache ||= new WeakMap;
3361
3330
  let cached = cache.get(key);
3362
3331
  if (cached?.[alg]) {
@@ -3388,13 +3357,13 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3388
3357
  case "ECDH-ES+A256KW":
3389
3358
  break;
3390
3359
  default:
3391
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3360
+ throw new TypeError(unusableForAlg);
3392
3361
  }
3393
3362
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
3394
3363
  }
3395
3364
  if (keyObject.asymmetricKeyType === "ed25519") {
3396
3365
  if (alg !== "EdDSA" && alg !== "Ed25519") {
3397
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3366
+ throw new TypeError(unusableForAlg);
3398
3367
  }
3399
3368
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
3400
3369
  isPublic ? "verify" : "sign"
@@ -3405,7 +3374,7 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3405
3374
  case "ml-dsa-65":
3406
3375
  case "ml-dsa-87": {
3407
3376
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
3408
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3377
+ throw new TypeError(unusableForAlg);
3409
3378
  }
3410
3379
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
3411
3380
  isPublic ? "verify" : "sign"
@@ -3434,7 +3403,7 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3434
3403
  hash = "SHA-512";
3435
3404
  break;
3436
3405
  default:
3437
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3406
+ throw new TypeError(unusableForAlg);
3438
3407
  }
3439
3408
  if (alg.startsWith("RSA-OAEP")) {
3440
3409
  return keyObject.toCryptoKey({
@@ -3455,21 +3424,10 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3455
3424
  ]);
3456
3425
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
3457
3426
  if (!namedCurve) {
3458
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3459
- }
3460
- if (alg === "ES256" && namedCurve === "P-256") {
3461
- cryptoKey = keyObject.toCryptoKey({
3462
- name: "ECDSA",
3463
- namedCurve
3464
- }, extractable, [isPublic ? "verify" : "sign"]);
3465
- }
3466
- if (alg === "ES384" && namedCurve === "P-384") {
3467
- cryptoKey = keyObject.toCryptoKey({
3468
- name: "ECDSA",
3469
- namedCurve
3470
- }, extractable, [isPublic ? "verify" : "sign"]);
3427
+ throw new TypeError(unusableForAlg);
3471
3428
  }
3472
- if (alg === "ES512" && namedCurve === "P-521") {
3429
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
3430
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
3473
3431
  cryptoKey = keyObject.toCryptoKey({
3474
3432
  name: "ECDSA",
3475
3433
  namedCurve
@@ -3483,7 +3441,7 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3483
3441
  }
3484
3442
  }
3485
3443
  if (!cryptoKey) {
3486
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
3444
+ throw new TypeError(unusableForAlg);
3487
3445
  }
3488
3446
  if (!cached) {
3489
3447
  cache.set(keyObject, { [alg]: cryptoKey });
@@ -3493,11 +3451,96 @@ var cache, handleJWK = async (key, jwk, alg, freeze = false) => {
3493
3451
  return cryptoKey;
3494
3452
  };
3495
3453
  var init_normalize_key = __esm(() => {
3496
- init_is_jwk();
3497
3454
  init_base64url();
3498
3455
  init_jwk_to_key();
3499
3456
  });
3500
3457
 
3458
+ // ../../node_modules/jose/dist/webapi/key/import.js
3459
+ async function importJWK(jwk, alg, options) {
3460
+ if (!isObject(jwk)) {
3461
+ throw new TypeError("JWK must be an object");
3462
+ }
3463
+ let ext;
3464
+ alg ??= jwk.alg;
3465
+ ext ??= options?.extractable ?? jwk.ext;
3466
+ switch (jwk.kty) {
3467
+ case "oct":
3468
+ if (typeof jwk.k !== "string" || !jwk.k) {
3469
+ throw new TypeError('missing "k" (Key Value) Parameter value');
3470
+ }
3471
+ return decode(jwk.k);
3472
+ case "RSA":
3473
+ if ("oth" in jwk && jwk.oth !== undefined) {
3474
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
3475
+ }
3476
+ return jwkToKey({ ...jwk, alg, ext });
3477
+ case "AKP": {
3478
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
3479
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
3480
+ }
3481
+ if (alg !== undefined && alg !== jwk.alg) {
3482
+ throw new TypeError("JWK alg and alg option value mismatch");
3483
+ }
3484
+ return jwkToKey({ ...jwk, ext });
3485
+ }
3486
+ case "EC":
3487
+ case "OKP":
3488
+ return jwkToKey({ ...jwk, alg, ext });
3489
+ default:
3490
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
3491
+ }
3492
+ }
3493
+ var init_import = __esm(() => {
3494
+ init_base64url();
3495
+ init_jwk_to_key();
3496
+ init_errors2();
3497
+ });
3498
+
3499
+ // ../../node_modules/jose/dist/webapi/lib/validate_crit.js
3500
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
3501
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
3502
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
3503
+ }
3504
+ if (!protectedHeader || protectedHeader.crit === undefined) {
3505
+ return new Set;
3506
+ }
3507
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
3508
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
3509
+ }
3510
+ let recognized;
3511
+ if (recognizedOption !== undefined) {
3512
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
3513
+ } else {
3514
+ recognized = recognizedDefault;
3515
+ }
3516
+ for (const parameter of protectedHeader.crit) {
3517
+ if (!recognized.has(parameter)) {
3518
+ throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
3519
+ }
3520
+ if (joseHeader[parameter] === undefined) {
3521
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
3522
+ }
3523
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
3524
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
3525
+ }
3526
+ }
3527
+ return new Set(protectedHeader.crit);
3528
+ }
3529
+ var init_validate_crit = __esm(() => {
3530
+ init_errors2();
3531
+ });
3532
+
3533
+ // ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
3534
+ function validateAlgorithms(option, algorithms) {
3535
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
3536
+ throw new TypeError(`"${option}" option must be an array of strings`);
3537
+ }
3538
+ if (!algorithms) {
3539
+ return;
3540
+ }
3541
+ return new Set(algorithms);
3542
+ }
3543
+
3501
3544
  // ../../node_modules/jose/dist/webapi/lib/check_key_type.js
3502
3545
  function checkKeyType(alg, key, usage) {
3503
3546
  switch (alg.substring(0, 2)) {
@@ -3614,73 +3657,7 @@ var tag = (key) => key?.[Symbol.toStringTag], jwkMatchesOp = (alg, key, usage) =
3614
3657
  }
3615
3658
  }
3616
3659
  };
3617
- var init_check_key_type = __esm(() => {
3618
- init_is_jwk();
3619
- });
3620
-
3621
- // ../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
3622
- function subtleAlgorithm(alg, algorithm) {
3623
- const hash = `SHA-${alg.slice(-3)}`;
3624
- switch (alg) {
3625
- case "HS256":
3626
- case "HS384":
3627
- case "HS512":
3628
- return { hash, name: "HMAC" };
3629
- case "PS256":
3630
- case "PS384":
3631
- case "PS512":
3632
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
3633
- case "RS256":
3634
- case "RS384":
3635
- case "RS512":
3636
- return { hash, name: "RSASSA-PKCS1-v1_5" };
3637
- case "ES256":
3638
- case "ES384":
3639
- case "ES512":
3640
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
3641
- case "Ed25519":
3642
- case "EdDSA":
3643
- return { name: "Ed25519" };
3644
- case "ML-DSA-44":
3645
- case "ML-DSA-65":
3646
- case "ML-DSA-87":
3647
- return { name: alg };
3648
- default:
3649
- throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
3650
- }
3651
- }
3652
- var init_subtle_dsa = __esm(() => {
3653
- init_errors2();
3654
- });
3655
-
3656
- // ../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
3657
- async function getSigKey(alg, key, usage) {
3658
- if (key instanceof Uint8Array) {
3659
- if (!alg.startsWith("HS")) {
3660
- throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
3661
- }
3662
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
3663
- }
3664
- checkSigCryptoKey(key, alg, usage);
3665
- return key;
3666
- }
3667
- var init_get_sign_verify_key = () => {};
3668
-
3669
- // ../../node_modules/jose/dist/webapi/lib/verify.js
3670
- async function verify(alg, key, signature, data) {
3671
- const cryptoKey = await getSigKey(alg, key, "verify");
3672
- checkKeyLength(alg, cryptoKey);
3673
- const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
3674
- try {
3675
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
3676
- } catch {
3677
- return false;
3678
- }
3679
- }
3680
- var init_verify = __esm(() => {
3681
- init_subtle_dsa();
3682
- init_get_sign_verify_key();
3683
- });
3660
+ var init_check_key_type = () => {};
3684
3661
 
3685
3662
  // ../../node_modules/jose/dist/webapi/jws/flattened/verify.js
3686
3663
  async function flattenedVerify(jws, key, options) {
@@ -3748,12 +3725,7 @@ async function flattenedVerify(jws, key, options) {
3748
3725
  }
3749
3726
  checkKeyType(alg, key, "verify");
3750
3727
  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);
3751
- let signature;
3752
- try {
3753
- signature = decode(jws.signature);
3754
- } catch {
3755
- throw new JWSInvalid("Failed to base64url decode the signature");
3756
- }
3728
+ const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
3757
3729
  const k = await normalizeKey(key, alg);
3758
3730
  const verified = await verify(alg, k, signature, data);
3759
3731
  if (!verified) {
@@ -3761,11 +3733,7 @@ async function flattenedVerify(jws, key, options) {
3761
3733
  }
3762
3734
  let payload;
3763
3735
  if (b64) {
3764
- try {
3765
- payload = decode(jws.payload);
3766
- } catch {
3767
- throw new JWSInvalid("Failed to base64url decode the payload");
3768
- }
3736
+ payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
3769
3737
  } else if (typeof jws.payload === "string") {
3770
3738
  payload = encoder.encode(jws.payload);
3771
3739
  } else {
@@ -3783,11 +3751,12 @@ async function flattenedVerify(jws, key, options) {
3783
3751
  }
3784
3752
  return result;
3785
3753
  }
3786
- var init_verify2 = __esm(() => {
3754
+ var init_verify = __esm(() => {
3787
3755
  init_base64url();
3788
- init_verify();
3756
+ init_signing();
3789
3757
  init_errors2();
3790
3758
  init_buffer_utils();
3759
+ init_helpers();
3791
3760
  init_check_key_type();
3792
3761
  init_validate_crit();
3793
3762
  init_normalize_key();
@@ -3812,8 +3781,8 @@ async function compactVerify(jws, key, options) {
3812
3781
  }
3813
3782
  return result;
3814
3783
  }
3815
- var init_verify3 = __esm(() => {
3816
- init_verify2();
3784
+ var init_verify2 = __esm(() => {
3785
+ init_verify();
3817
3786
  init_errors2();
3818
3787
  init_buffer_utils();
3819
3788
  });
@@ -4057,8 +4026,8 @@ async function jwtVerify(jwt, key, options) {
4057
4026
  }
4058
4027
  return result;
4059
4028
  }
4060
- var init_verify4 = __esm(() => {
4061
- init_verify3();
4029
+ var init_verify3 = __esm(() => {
4030
+ init_verify2();
4062
4031
  init_jwt_claims_set();
4063
4032
  init_errors2();
4064
4033
  });
@@ -4343,7 +4312,7 @@ var init_remote = __esm(() => {
4343
4312
  init_local();
4344
4313
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
4345
4314
  const NAME = "jose";
4346
- const VERSION = "v6.1.3";
4315
+ const VERSION = "v6.2.1";
4347
4316
  USER_AGENT = `${NAME}/${VERSION}`;
4348
4317
  }
4349
4318
  customFetch = Symbol();
@@ -4352,7 +4321,7 @@ var init_remote = __esm(() => {
4352
4321
 
4353
4322
  // ../../node_modules/jose/dist/webapi/index.js
4354
4323
  var init_webapi = __esm(() => {
4355
- init_verify4();
4324
+ init_verify3();
4356
4325
  init_local();
4357
4326
  init_remote();
4358
4327
  init_errors2();
@@ -13428,6 +13397,27 @@ function notFoundHttpResponse() {
13428
13397
  }
13429
13398
  });
13430
13399
  }
13400
+ function isMissingModuleError(error, moduleName) {
13401
+ if (!error) {
13402
+ return false;
13403
+ }
13404
+ const errorString = String(error);
13405
+ const moduleSpecifiers = [moduleName, `convex/${moduleName}`];
13406
+ const hasDirectMissingMessage = moduleSpecifiers.some((specifier) => errorString.includes(`Module not found: ${specifier}`));
13407
+ if (hasDirectMissingMessage || errorString.toLowerCase().includes("failed to load convex module")) {
13408
+ return true;
13409
+ }
13410
+ const hasResolutionMessage = moduleSpecifiers.some((specifier) => errorString.includes(`Unable to resolve module "${specifier}"`));
13411
+ const causes = error.causes;
13412
+ if (Array.isArray(causes) && causes.length > 0) {
13413
+ return hasResolutionMessage ? causes.every((cause2) => isMissingModuleError(cause2, moduleName)) : causes.some((cause2) => isMissingModuleError(cause2, moduleName));
13414
+ }
13415
+ const cause = error.cause;
13416
+ if (cause) {
13417
+ return isMissingModuleError(cause, moduleName);
13418
+ }
13419
+ return hasResolutionMessage;
13420
+ }
13431
13421
  function getHttpRouteRank(routePath) {
13432
13422
  if (routePath.endsWith("*")) {
13433
13423
  return { kind: 0, length: routePath.length - 1 };
@@ -13599,8 +13589,7 @@ class InlineUdfExecutor {
13599
13589
  try {
13600
13590
  return await loadConvexModule(moduleName, { componentPath });
13601
13591
  } catch (error) {
13602
- const message2 = error?.message?.toLowerCase();
13603
- if (message2 && (message2.includes("module not found") || message2.includes("failed to load convex module"))) {
13592
+ if (isMissingModuleError(error, moduleName)) {
13604
13593
  throw new Error(`UDF module not found: ${moduleName}`);
13605
13594
  }
13606
13595
  throw error;
@@ -18308,6 +18297,111 @@ function decode2(input) {
18308
18297
  var init_base64url2 = __esm2(() => {
18309
18298
  init_buffer_utils2();
18310
18299
  });
18300
+ function getHashLength2(hash) {
18301
+ return parseInt(hash.name.slice(4), 10);
18302
+ }
18303
+ function checkHashLength2(algorithm, expected) {
18304
+ const actual = getHashLength2(algorithm.hash);
18305
+ if (actual !== expected)
18306
+ throw unusable2(`SHA-${expected}`, "algorithm.hash");
18307
+ }
18308
+ function getNamedCurve2(alg) {
18309
+ switch (alg) {
18310
+ case "ES256":
18311
+ return "P-256";
18312
+ case "ES384":
18313
+ return "P-384";
18314
+ case "ES512":
18315
+ return "P-521";
18316
+ default:
18317
+ throw new Error("unreachable");
18318
+ }
18319
+ }
18320
+ function checkUsage2(key, usage) {
18321
+ if (usage && !key.usages.includes(usage)) {
18322
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
18323
+ }
18324
+ }
18325
+ function checkSigCryptoKey2(key, alg, usage) {
18326
+ switch (alg) {
18327
+ case "HS256":
18328
+ case "HS384":
18329
+ case "HS512": {
18330
+ if (!isAlgorithm2(key.algorithm, "HMAC"))
18331
+ throw unusable2("HMAC");
18332
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
18333
+ break;
18334
+ }
18335
+ case "RS256":
18336
+ case "RS384":
18337
+ case "RS512": {
18338
+ if (!isAlgorithm2(key.algorithm, "RSASSA-PKCS1-v1_5"))
18339
+ throw unusable2("RSASSA-PKCS1-v1_5");
18340
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
18341
+ break;
18342
+ }
18343
+ case "PS256":
18344
+ case "PS384":
18345
+ case "PS512": {
18346
+ if (!isAlgorithm2(key.algorithm, "RSA-PSS"))
18347
+ throw unusable2("RSA-PSS");
18348
+ checkHashLength2(key.algorithm, parseInt(alg.slice(2), 10));
18349
+ break;
18350
+ }
18351
+ case "Ed25519":
18352
+ case "EdDSA": {
18353
+ if (!isAlgorithm2(key.algorithm, "Ed25519"))
18354
+ throw unusable2("Ed25519");
18355
+ break;
18356
+ }
18357
+ case "ML-DSA-44":
18358
+ case "ML-DSA-65":
18359
+ case "ML-DSA-87": {
18360
+ if (!isAlgorithm2(key.algorithm, alg))
18361
+ throw unusable2(alg);
18362
+ break;
18363
+ }
18364
+ case "ES256":
18365
+ case "ES384":
18366
+ case "ES512": {
18367
+ if (!isAlgorithm2(key.algorithm, "ECDSA"))
18368
+ throw unusable2("ECDSA");
18369
+ const expected = getNamedCurve2(alg);
18370
+ const actual = key.algorithm.namedCurve;
18371
+ if (actual !== expected)
18372
+ throw unusable2(expected, "algorithm.namedCurve");
18373
+ break;
18374
+ }
18375
+ default:
18376
+ throw new TypeError("CryptoKey does not support this operation");
18377
+ }
18378
+ checkUsage2(key, usage);
18379
+ }
18380
+ var unusable2 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
18381
+ var isAlgorithm2 = (algorithm, name) => algorithm.name === name;
18382
+ function message2(msg, actual, ...types2) {
18383
+ types2 = types2.filter(Boolean);
18384
+ if (types2.length > 2) {
18385
+ const last = types2.pop();
18386
+ msg += `one of type ${types2.join(", ")}, or ${last}.`;
18387
+ } else if (types2.length === 2) {
18388
+ msg += `one of type ${types2[0]} or ${types2[1]}.`;
18389
+ } else {
18390
+ msg += `of type ${types2[0]}.`;
18391
+ }
18392
+ if (actual == null) {
18393
+ msg += ` Received ${actual}`;
18394
+ } else if (typeof actual === "function" && actual.name) {
18395
+ msg += ` Received function ${actual.name}`;
18396
+ } else if (typeof actual === "object" && actual != null) {
18397
+ if (actual.constructor?.name) {
18398
+ msg += ` Received an instance of ${actual.constructor.name}`;
18399
+ }
18400
+ }
18401
+ return msg;
18402
+ }
18403
+ var invalidKeyInput2 = (actual, ...types2) => message2("Key must be ", actual, ...types2);
18404
+ var withAlg2 = (alg, actual, ...types2) => message2(`Key for the ${alg} algorithm must be `, actual, ...types2);
18311
18405
  var exports_errors2 = {};
18312
18406
  __export2(exports_errors2, {
18313
18407
  JWTInvalid: () => JWTInvalid2,
@@ -18345,8 +18439,8 @@ var init_errors22 = __esm2(() => {
18345
18439
  JOSEError2 = class JOSEError3 extends Error {
18346
18440
  static code = "ERR_JOSE_GENERIC";
18347
18441
  code = "ERR_JOSE_GENERIC";
18348
- constructor(message2, options) {
18349
- super(message2, options);
18442
+ constructor(message22, options) {
18443
+ super(message22, options);
18350
18444
  this.name = this.constructor.name;
18351
18445
  Error.captureStackTrace?.(this, this.constructor);
18352
18446
  }
@@ -18357,8 +18451,8 @@ var init_errors22 = __esm2(() => {
18357
18451
  claim;
18358
18452
  reason;
18359
18453
  payload;
18360
- constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
18361
- super(message2, { cause: { claim, reason, payload } });
18454
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
18455
+ super(message22, { cause: { claim, reason, payload } });
18362
18456
  this.claim = claim;
18363
18457
  this.reason = reason;
18364
18458
  this.payload = payload;
@@ -18370,8 +18464,8 @@ var init_errors22 = __esm2(() => {
18370
18464
  claim;
18371
18465
  reason;
18372
18466
  payload;
18373
- constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
18374
- super(message2, { cause: { claim, reason, payload } });
18467
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
18468
+ super(message22, { cause: { claim, reason, payload } });
18375
18469
  this.claim = claim;
18376
18470
  this.reason = reason;
18377
18471
  this.payload = payload;
@@ -18388,8 +18482,8 @@ var init_errors22 = __esm2(() => {
18388
18482
  JWEDecryptionFailed2 = class JWEDecryptionFailed3 extends JOSEError2 {
18389
18483
  static code = "ERR_JWE_DECRYPTION_FAILED";
18390
18484
  code = "ERR_JWE_DECRYPTION_FAILED";
18391
- constructor(message2 = "decryption operation failed", options) {
18392
- super(message2, options);
18485
+ constructor(message22 = "decryption operation failed", options) {
18486
+ super(message22, options);
18393
18487
  }
18394
18488
  };
18395
18489
  JWEInvalid2 = class JWEInvalid3 extends JOSEError2 {
@@ -18415,142 +18509,33 @@ var init_errors22 = __esm2(() => {
18415
18509
  JWKSNoMatchingKey2 = class JWKSNoMatchingKey3 extends JOSEError2 {
18416
18510
  static code = "ERR_JWKS_NO_MATCHING_KEY";
18417
18511
  code = "ERR_JWKS_NO_MATCHING_KEY";
18418
- constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
18419
- super(message2, options);
18512
+ constructor(message22 = "no applicable key found in the JSON Web Key Set", options) {
18513
+ super(message22, options);
18420
18514
  }
18421
18515
  };
18422
18516
  JWKSMultipleMatchingKeys2 = class JWKSMultipleMatchingKeys3 extends JOSEError2 {
18423
18517
  [Symbol.asyncIterator];
18424
18518
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
18425
18519
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
18426
- constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
18427
- super(message2, options);
18520
+ constructor(message22 = "multiple matching keys found in the JSON Web Key Set", options) {
18521
+ super(message22, options);
18428
18522
  }
18429
18523
  };
18430
18524
  JWKSTimeout2 = class JWKSTimeout3 extends JOSEError2 {
18431
18525
  static code = "ERR_JWKS_TIMEOUT";
18432
18526
  code = "ERR_JWKS_TIMEOUT";
18433
- constructor(message2 = "request timed out", options) {
18434
- super(message2, options);
18527
+ constructor(message22 = "request timed out", options) {
18528
+ super(message22, options);
18435
18529
  }
18436
18530
  };
18437
18531
  JWSSignatureVerificationFailed2 = class JWSSignatureVerificationFailed3 extends JOSEError2 {
18438
18532
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
18439
18533
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
18440
- constructor(message2 = "signature verification failed", options) {
18441
- super(message2, options);
18534
+ constructor(message22 = "signature verification failed", options) {
18535
+ super(message22, options);
18442
18536
  }
18443
18537
  };
18444
18538
  });
18445
- function getHashLength2(hash) {
18446
- return parseInt(hash.name.slice(4), 10);
18447
- }
18448
- function getNamedCurve2(alg) {
18449
- switch (alg) {
18450
- case "ES256":
18451
- return "P-256";
18452
- case "ES384":
18453
- return "P-384";
18454
- case "ES512":
18455
- return "P-521";
18456
- default:
18457
- throw new Error("unreachable");
18458
- }
18459
- }
18460
- function checkUsage2(key, usage) {
18461
- if (usage && !key.usages.includes(usage)) {
18462
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
18463
- }
18464
- }
18465
- function checkSigCryptoKey2(key, alg, usage) {
18466
- switch (alg) {
18467
- case "HS256":
18468
- case "HS384":
18469
- case "HS512": {
18470
- if (!isAlgorithm2(key.algorithm, "HMAC"))
18471
- throw unusable2("HMAC");
18472
- const expected = parseInt(alg.slice(2), 10);
18473
- const actual = getHashLength2(key.algorithm.hash);
18474
- if (actual !== expected)
18475
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
18476
- break;
18477
- }
18478
- case "RS256":
18479
- case "RS384":
18480
- case "RS512": {
18481
- if (!isAlgorithm2(key.algorithm, "RSASSA-PKCS1-v1_5"))
18482
- throw unusable2("RSASSA-PKCS1-v1_5");
18483
- const expected = parseInt(alg.slice(2), 10);
18484
- const actual = getHashLength2(key.algorithm.hash);
18485
- if (actual !== expected)
18486
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
18487
- break;
18488
- }
18489
- case "PS256":
18490
- case "PS384":
18491
- case "PS512": {
18492
- if (!isAlgorithm2(key.algorithm, "RSA-PSS"))
18493
- throw unusable2("RSA-PSS");
18494
- const expected = parseInt(alg.slice(2), 10);
18495
- const actual = getHashLength2(key.algorithm.hash);
18496
- if (actual !== expected)
18497
- throw unusable2(`SHA-${expected}`, "algorithm.hash");
18498
- break;
18499
- }
18500
- case "Ed25519":
18501
- case "EdDSA": {
18502
- if (!isAlgorithm2(key.algorithm, "Ed25519"))
18503
- throw unusable2("Ed25519");
18504
- break;
18505
- }
18506
- case "ML-DSA-44":
18507
- case "ML-DSA-65":
18508
- case "ML-DSA-87": {
18509
- if (!isAlgorithm2(key.algorithm, alg))
18510
- throw unusable2(alg);
18511
- break;
18512
- }
18513
- case "ES256":
18514
- case "ES384":
18515
- case "ES512": {
18516
- if (!isAlgorithm2(key.algorithm, "ECDSA"))
18517
- throw unusable2("ECDSA");
18518
- const expected = getNamedCurve2(alg);
18519
- const actual = key.algorithm.namedCurve;
18520
- if (actual !== expected)
18521
- throw unusable2(expected, "algorithm.namedCurve");
18522
- break;
18523
- }
18524
- default:
18525
- throw new TypeError("CryptoKey does not support this operation");
18526
- }
18527
- checkUsage2(key, usage);
18528
- }
18529
- var unusable2 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
18530
- var isAlgorithm2 = (algorithm, name) => algorithm.name === name;
18531
- function message2(msg, actual, ...types2) {
18532
- types2 = types2.filter(Boolean);
18533
- if (types2.length > 2) {
18534
- const last = types2.pop();
18535
- msg += `one of type ${types2.join(", ")}, or ${last}.`;
18536
- } else if (types2.length === 2) {
18537
- msg += `one of type ${types2[0]} or ${types2[1]}.`;
18538
- } else {
18539
- msg += `of type ${types2[0]}.`;
18540
- }
18541
- if (actual == null) {
18542
- msg += ` Received ${actual}`;
18543
- } else if (typeof actual === "function" && actual.name) {
18544
- msg += ` Received function ${actual.name}`;
18545
- } else if (typeof actual === "object" && actual != null) {
18546
- if (actual.constructor?.name) {
18547
- msg += ` Received an instance of ${actual.constructor.name}`;
18548
- }
18549
- }
18550
- return msg;
18551
- }
18552
- var invalidKeyInput2 = (actual, ...types2) => message2("Key must be ", actual, ...types2);
18553
- var withAlg2 = (alg, actual, ...types2) => message2(`Key for the ${alg} algorithm must be `, actual, ...types2);
18554
18539
  var isCryptoKey2 = (key) => {
18555
18540
  if (key?.[Symbol.toStringTag] === "CryptoKey")
18556
18541
  return true;
@@ -18562,6 +18547,31 @@ var isCryptoKey2 = (key) => {
18562
18547
  };
18563
18548
  var isKeyObject2 = (key) => key?.[Symbol.toStringTag] === "KeyObject";
18564
18549
  var isKeyLike2 = (key) => isCryptoKey2(key) || isKeyObject2(key);
18550
+ function decodeBase64url2(value, label, ErrorClass) {
18551
+ try {
18552
+ return decode2(value);
18553
+ } catch {
18554
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
18555
+ }
18556
+ }
18557
+ var unprotected2;
18558
+ var init_helpers2 = __esm2(() => {
18559
+ init_base64url2();
18560
+ unprotected2 = Symbol();
18561
+ });
18562
+ function isObject2(input) {
18563
+ if (!isObjectLike2(input) || Object.prototype.toString.call(input) !== "[object Object]") {
18564
+ return false;
18565
+ }
18566
+ if (Object.getPrototypeOf(input) === null) {
18567
+ return true;
18568
+ }
18569
+ let proto = input;
18570
+ while (Object.getPrototypeOf(proto) !== null) {
18571
+ proto = Object.getPrototypeOf(proto);
18572
+ }
18573
+ return Object.getPrototypeOf(input) === proto;
18574
+ }
18565
18575
  function isDisjoint2(...headers) {
18566
18576
  const sources = headers.filter(Boolean);
18567
18577
  if (sources.length === 0 || sources.length === 1) {
@@ -18583,20 +18593,11 @@ function isDisjoint2(...headers) {
18583
18593
  }
18584
18594
  return true;
18585
18595
  }
18586
- function isObject2(input) {
18587
- if (!isObjectLike2(input) || Object.prototype.toString.call(input) !== "[object Object]") {
18588
- return false;
18589
- }
18590
- if (Object.getPrototypeOf(input) === null) {
18591
- return true;
18592
- }
18593
- let proto = input;
18594
- while (Object.getPrototypeOf(proto) !== null) {
18595
- proto = Object.getPrototypeOf(proto);
18596
- }
18597
- return Object.getPrototypeOf(input) === proto;
18598
- }
18599
18596
  var isObjectLike2 = (value) => typeof value === "object" && value !== null;
18597
+ var isJWK2 = (key) => isObject2(key) && typeof key.kty === "string";
18598
+ var isPrivateJWK2 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
18599
+ var isPublicJWK2 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
18600
+ var isSecretJWK2 = (key) => key.kty === "oct" && typeof key.k === "string";
18600
18601
  function checkKeyLength2(alg, key) {
18601
18602
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
18602
18603
  const { modulusLength } = key.algorithm;
@@ -18605,6 +18606,59 @@ function checkKeyLength2(alg, key) {
18605
18606
  }
18606
18607
  }
18607
18608
  }
18609
+ function subtleAlgorithm2(alg, algorithm) {
18610
+ const hash = `SHA-${alg.slice(-3)}`;
18611
+ switch (alg) {
18612
+ case "HS256":
18613
+ case "HS384":
18614
+ case "HS512":
18615
+ return { hash, name: "HMAC" };
18616
+ case "PS256":
18617
+ case "PS384":
18618
+ case "PS512":
18619
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
18620
+ case "RS256":
18621
+ case "RS384":
18622
+ case "RS512":
18623
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
18624
+ case "ES256":
18625
+ case "ES384":
18626
+ case "ES512":
18627
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
18628
+ case "Ed25519":
18629
+ case "EdDSA":
18630
+ return { name: "Ed25519" };
18631
+ case "ML-DSA-44":
18632
+ case "ML-DSA-65":
18633
+ case "ML-DSA-87":
18634
+ return { name: alg };
18635
+ default:
18636
+ throw new JOSENotSupported2(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
18637
+ }
18638
+ }
18639
+ async function getSigKey2(alg, key, usage) {
18640
+ if (key instanceof Uint8Array) {
18641
+ if (!alg.startsWith("HS")) {
18642
+ throw new TypeError(invalidKeyInput2(key, "CryptoKey", "KeyObject", "JSON Web Key"));
18643
+ }
18644
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
18645
+ }
18646
+ checkSigCryptoKey2(key, alg, usage);
18647
+ return key;
18648
+ }
18649
+ async function verify2(alg, key, signature, data) {
18650
+ const cryptoKey = await getSigKey2(alg, key, "verify");
18651
+ checkKeyLength2(alg, cryptoKey);
18652
+ const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
18653
+ try {
18654
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
18655
+ } catch {
18656
+ return false;
18657
+ }
18658
+ }
18659
+ var init_signing2 = __esm2(() => {
18660
+ init_errors22();
18661
+ });
18608
18662
  function subtleMapping2(jwk) {
18609
18663
  let algorithm;
18610
18664
  let keyUsages;
@@ -18618,7 +18672,7 @@ function subtleMapping2(jwk) {
18618
18672
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
18619
18673
  break;
18620
18674
  default:
18621
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
18675
+ throw new JOSENotSupported2(unsupportedAlg2);
18622
18676
  }
18623
18677
  break;
18624
18678
  }
@@ -18647,22 +18701,19 @@ function subtleMapping2(jwk) {
18647
18701
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
18648
18702
  break;
18649
18703
  default:
18650
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
18704
+ throw new JOSENotSupported2(unsupportedAlg2);
18651
18705
  }
18652
18706
  break;
18653
18707
  }
18654
18708
  case "EC": {
18655
18709
  switch (jwk.alg) {
18656
18710
  case "ES256":
18657
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
18658
- keyUsages = jwk.d ? ["sign"] : ["verify"];
18659
- break;
18660
18711
  case "ES384":
18661
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
18662
- keyUsages = jwk.d ? ["sign"] : ["verify"];
18663
- break;
18664
18712
  case "ES512":
18665
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
18713
+ algorithm = {
18714
+ name: "ECDSA",
18715
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
18716
+ };
18666
18717
  keyUsages = jwk.d ? ["sign"] : ["verify"];
18667
18718
  break;
18668
18719
  case "ECDH-ES":
@@ -18673,7 +18724,7 @@ function subtleMapping2(jwk) {
18673
18724
  keyUsages = jwk.d ? ["deriveBits"] : [];
18674
18725
  break;
18675
18726
  default:
18676
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
18727
+ throw new JOSENotSupported2(unsupportedAlg2);
18677
18728
  }
18678
18729
  break;
18679
18730
  }
@@ -18692,7 +18743,7 @@ function subtleMapping2(jwk) {
18692
18743
  keyUsages = jwk.d ? ["deriveBits"] : [];
18693
18744
  break;
18694
18745
  default:
18695
- throw new JOSENotSupported2('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
18746
+ throw new JOSENotSupported2(unsupportedAlg2);
18696
18747
  }
18697
18748
  break;
18698
18749
  }
@@ -18713,94 +18764,10 @@ async function jwkToKey2(jwk) {
18713
18764
  delete keyData.use;
18714
18765
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
18715
18766
  }
18767
+ var unsupportedAlg2 = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
18716
18768
  var init_jwk_to_key2 = __esm2(() => {
18717
18769
  init_errors22();
18718
18770
  });
18719
- async function importJWK2(jwk, alg, options) {
18720
- if (!isObject2(jwk)) {
18721
- throw new TypeError("JWK must be an object");
18722
- }
18723
- let ext;
18724
- alg ??= jwk.alg;
18725
- ext ??= options?.extractable ?? jwk.ext;
18726
- switch (jwk.kty) {
18727
- case "oct":
18728
- if (typeof jwk.k !== "string" || !jwk.k) {
18729
- throw new TypeError('missing "k" (Key Value) Parameter value');
18730
- }
18731
- return decode2(jwk.k);
18732
- case "RSA":
18733
- if ("oth" in jwk && jwk.oth !== undefined) {
18734
- throw new JOSENotSupported2('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
18735
- }
18736
- return jwkToKey2({ ...jwk, alg, ext });
18737
- case "AKP": {
18738
- if (typeof jwk.alg !== "string" || !jwk.alg) {
18739
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
18740
- }
18741
- if (alg !== undefined && alg !== jwk.alg) {
18742
- throw new TypeError("JWK alg and alg option value mismatch");
18743
- }
18744
- return jwkToKey2({ ...jwk, ext });
18745
- }
18746
- case "EC":
18747
- case "OKP":
18748
- return jwkToKey2({ ...jwk, alg, ext });
18749
- default:
18750
- throw new JOSENotSupported2('Unsupported "kty" (Key Type) Parameter value');
18751
- }
18752
- }
18753
- var init_import2 = __esm2(() => {
18754
- init_base64url2();
18755
- init_jwk_to_key2();
18756
- init_errors22();
18757
- });
18758
- function validateCrit2(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
18759
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
18760
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
18761
- }
18762
- if (!protectedHeader || protectedHeader.crit === undefined) {
18763
- return new Set;
18764
- }
18765
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
18766
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
18767
- }
18768
- let recognized;
18769
- if (recognizedOption !== undefined) {
18770
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
18771
- } else {
18772
- recognized = recognizedDefault;
18773
- }
18774
- for (const parameter of protectedHeader.crit) {
18775
- if (!recognized.has(parameter)) {
18776
- throw new JOSENotSupported2(`Extension Header Parameter "${parameter}" is not recognized`);
18777
- }
18778
- if (joseHeader[parameter] === undefined) {
18779
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
18780
- }
18781
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
18782
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
18783
- }
18784
- }
18785
- return new Set(protectedHeader.crit);
18786
- }
18787
- var init_validate_crit2 = __esm2(() => {
18788
- init_errors22();
18789
- });
18790
- function validateAlgorithms2(option, algorithms) {
18791
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
18792
- throw new TypeError(`"${option}" option must be an array of strings`);
18793
- }
18794
- if (!algorithms) {
18795
- return;
18796
- }
18797
- return new Set(algorithms);
18798
- }
18799
- var isJWK2 = (key) => isObject2(key) && typeof key.kty === "string";
18800
- var isPrivateJWK2 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
18801
- var isPublicJWK2 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
18802
- var isSecretJWK2 = (key) => key.kty === "oct" && typeof key.k === "string";
18803
- var init_is_jwk2 = () => {};
18804
18771
  async function normalizeKey2(key, alg) {
18805
18772
  if (key instanceof Uint8Array) {
18806
18773
  return key;
@@ -18832,6 +18799,7 @@ async function normalizeKey2(key, alg) {
18832
18799
  }
18833
18800
  throw new Error("unreachable");
18834
18801
  }
18802
+ var unusableForAlg2 = "given KeyObject instance cannot be used for this algorithm";
18835
18803
  var cache2;
18836
18804
  var handleJWK2 = async (key, jwk, alg, freeze = false) => {
18837
18805
  cache2 ||= new WeakMap;
@@ -18866,13 +18834,13 @@ var handleKeyObject2 = (keyObject, alg) => {
18866
18834
  case "ECDH-ES+A256KW":
18867
18835
  break;
18868
18836
  default:
18869
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18837
+ throw new TypeError(unusableForAlg2);
18870
18838
  }
18871
18839
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
18872
18840
  }
18873
18841
  if (keyObject.asymmetricKeyType === "ed25519") {
18874
18842
  if (alg !== "EdDSA" && alg !== "Ed25519") {
18875
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18843
+ throw new TypeError(unusableForAlg2);
18876
18844
  }
18877
18845
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
18878
18846
  isPublic ? "verify" : "sign"
@@ -18883,7 +18851,7 @@ var handleKeyObject2 = (keyObject, alg) => {
18883
18851
  case "ml-dsa-65":
18884
18852
  case "ml-dsa-87": {
18885
18853
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
18886
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18854
+ throw new TypeError(unusableForAlg2);
18887
18855
  }
18888
18856
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
18889
18857
  isPublic ? "verify" : "sign"
@@ -18912,7 +18880,7 @@ var handleKeyObject2 = (keyObject, alg) => {
18912
18880
  hash = "SHA-512";
18913
18881
  break;
18914
18882
  default:
18915
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18883
+ throw new TypeError(unusableForAlg2);
18916
18884
  }
18917
18885
  if (alg.startsWith("RSA-OAEP")) {
18918
18886
  return keyObject.toCryptoKey({
@@ -18933,21 +18901,10 @@ var handleKeyObject2 = (keyObject, alg) => {
18933
18901
  ]);
18934
18902
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
18935
18903
  if (!namedCurve) {
18936
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18937
- }
18938
- if (alg === "ES256" && namedCurve === "P-256") {
18939
- cryptoKey = keyObject.toCryptoKey({
18940
- name: "ECDSA",
18941
- namedCurve
18942
- }, extractable, [isPublic ? "verify" : "sign"]);
18943
- }
18944
- if (alg === "ES384" && namedCurve === "P-384") {
18945
- cryptoKey = keyObject.toCryptoKey({
18946
- name: "ECDSA",
18947
- namedCurve
18948
- }, extractable, [isPublic ? "verify" : "sign"]);
18904
+ throw new TypeError(unusableForAlg2);
18949
18905
  }
18950
- if (alg === "ES512" && namedCurve === "P-521") {
18906
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
18907
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
18951
18908
  cryptoKey = keyObject.toCryptoKey({
18952
18909
  name: "ECDSA",
18953
18910
  namedCurve
@@ -18961,7 +18918,7 @@ var handleKeyObject2 = (keyObject, alg) => {
18961
18918
  }
18962
18919
  }
18963
18920
  if (!cryptoKey) {
18964
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
18921
+ throw new TypeError(unusableForAlg2);
18965
18922
  }
18966
18923
  if (!cached) {
18967
18924
  cache2.set(keyObject, { [alg]: cryptoKey });
@@ -18971,10 +18928,89 @@ var handleKeyObject2 = (keyObject, alg) => {
18971
18928
  return cryptoKey;
18972
18929
  };
18973
18930
  var init_normalize_key2 = __esm2(() => {
18974
- init_is_jwk2();
18975
18931
  init_base64url2();
18976
18932
  init_jwk_to_key2();
18977
18933
  });
18934
+ async function importJWK2(jwk, alg, options) {
18935
+ if (!isObject2(jwk)) {
18936
+ throw new TypeError("JWK must be an object");
18937
+ }
18938
+ let ext;
18939
+ alg ??= jwk.alg;
18940
+ ext ??= options?.extractable ?? jwk.ext;
18941
+ switch (jwk.kty) {
18942
+ case "oct":
18943
+ if (typeof jwk.k !== "string" || !jwk.k) {
18944
+ throw new TypeError('missing "k" (Key Value) Parameter value');
18945
+ }
18946
+ return decode2(jwk.k);
18947
+ case "RSA":
18948
+ if ("oth" in jwk && jwk.oth !== undefined) {
18949
+ throw new JOSENotSupported2('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
18950
+ }
18951
+ return jwkToKey2({ ...jwk, alg, ext });
18952
+ case "AKP": {
18953
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
18954
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
18955
+ }
18956
+ if (alg !== undefined && alg !== jwk.alg) {
18957
+ throw new TypeError("JWK alg and alg option value mismatch");
18958
+ }
18959
+ return jwkToKey2({ ...jwk, ext });
18960
+ }
18961
+ case "EC":
18962
+ case "OKP":
18963
+ return jwkToKey2({ ...jwk, alg, ext });
18964
+ default:
18965
+ throw new JOSENotSupported2('Unsupported "kty" (Key Type) Parameter value');
18966
+ }
18967
+ }
18968
+ var init_import2 = __esm2(() => {
18969
+ init_base64url2();
18970
+ init_jwk_to_key2();
18971
+ init_errors22();
18972
+ });
18973
+ function validateCrit2(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
18974
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
18975
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
18976
+ }
18977
+ if (!protectedHeader || protectedHeader.crit === undefined) {
18978
+ return new Set;
18979
+ }
18980
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
18981
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
18982
+ }
18983
+ let recognized;
18984
+ if (recognizedOption !== undefined) {
18985
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
18986
+ } else {
18987
+ recognized = recognizedDefault;
18988
+ }
18989
+ for (const parameter of protectedHeader.crit) {
18990
+ if (!recognized.has(parameter)) {
18991
+ throw new JOSENotSupported2(`Extension Header Parameter "${parameter}" is not recognized`);
18992
+ }
18993
+ if (joseHeader[parameter] === undefined) {
18994
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
18995
+ }
18996
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
18997
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
18998
+ }
18999
+ }
19000
+ return new Set(protectedHeader.crit);
19001
+ }
19002
+ var init_validate_crit2 = __esm2(() => {
19003
+ init_errors22();
19004
+ });
19005
+ function validateAlgorithms2(option, algorithms) {
19006
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
19007
+ throw new TypeError(`"${option}" option must be an array of strings`);
19008
+ }
19009
+ if (!algorithms) {
19010
+ return;
19011
+ }
19012
+ return new Set(algorithms);
19013
+ }
18978
19014
  function checkKeyType2(alg, key, usage) {
18979
19015
  switch (alg.substring(0, 2)) {
18980
19016
  case "A1":
@@ -19093,67 +19129,7 @@ var asymmetricTypeCheck2 = (alg, key, usage) => {
19093
19129
  }
19094
19130
  }
19095
19131
  };
19096
- var init_check_key_type2 = __esm2(() => {
19097
- init_is_jwk2();
19098
- });
19099
- function subtleAlgorithm2(alg, algorithm) {
19100
- const hash = `SHA-${alg.slice(-3)}`;
19101
- switch (alg) {
19102
- case "HS256":
19103
- case "HS384":
19104
- case "HS512":
19105
- return { hash, name: "HMAC" };
19106
- case "PS256":
19107
- case "PS384":
19108
- case "PS512":
19109
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
19110
- case "RS256":
19111
- case "RS384":
19112
- case "RS512":
19113
- return { hash, name: "RSASSA-PKCS1-v1_5" };
19114
- case "ES256":
19115
- case "ES384":
19116
- case "ES512":
19117
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
19118
- case "Ed25519":
19119
- case "EdDSA":
19120
- return { name: "Ed25519" };
19121
- case "ML-DSA-44":
19122
- case "ML-DSA-65":
19123
- case "ML-DSA-87":
19124
- return { name: alg };
19125
- default:
19126
- throw new JOSENotSupported2(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
19127
- }
19128
- }
19129
- var init_subtle_dsa2 = __esm2(() => {
19130
- init_errors22();
19131
- });
19132
- async function getSigKey2(alg, key, usage) {
19133
- if (key instanceof Uint8Array) {
19134
- if (!alg.startsWith("HS")) {
19135
- throw new TypeError(invalidKeyInput2(key, "CryptoKey", "KeyObject", "JSON Web Key"));
19136
- }
19137
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
19138
- }
19139
- checkSigCryptoKey2(key, alg, usage);
19140
- return key;
19141
- }
19142
- var init_get_sign_verify_key2 = () => {};
19143
- async function verify2(alg, key, signature, data) {
19144
- const cryptoKey = await getSigKey2(alg, key, "verify");
19145
- checkKeyLength2(alg, cryptoKey);
19146
- const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
19147
- try {
19148
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
19149
- } catch {
19150
- return false;
19151
- }
19152
- }
19153
- var init_verify5 = __esm2(() => {
19154
- init_subtle_dsa2();
19155
- init_get_sign_verify_key2();
19156
- });
19132
+ var init_check_key_type2 = () => {};
19157
19133
  async function flattenedVerify2(jws, key, options) {
19158
19134
  if (!isObject2(jws)) {
19159
19135
  throw new JWSInvalid2("Flattened JWS must be an object");
@@ -19219,12 +19195,7 @@ async function flattenedVerify2(jws, key, options) {
19219
19195
  }
19220
19196
  checkKeyType2(alg, key, "verify");
19221
19197
  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);
19222
- let signature;
19223
- try {
19224
- signature = decode2(jws.signature);
19225
- } catch {
19226
- throw new JWSInvalid2("Failed to base64url decode the signature");
19227
- }
19198
+ const signature = decodeBase64url2(jws.signature, "signature", JWSInvalid2);
19228
19199
  const k = await normalizeKey2(key, alg);
19229
19200
  const verified = await verify2(alg, k, signature, data);
19230
19201
  if (!verified) {
@@ -19232,11 +19203,7 @@ async function flattenedVerify2(jws, key, options) {
19232
19203
  }
19233
19204
  let payload;
19234
19205
  if (b64) {
19235
- try {
19236
- payload = decode2(jws.payload);
19237
- } catch {
19238
- throw new JWSInvalid2("Failed to base64url decode the payload");
19239
- }
19206
+ payload = decodeBase64url2(jws.payload, "payload", JWSInvalid2);
19240
19207
  } else if (typeof jws.payload === "string") {
19241
19208
  payload = encoder2.encode(jws.payload);
19242
19209
  } else {
@@ -19254,11 +19221,12 @@ async function flattenedVerify2(jws, key, options) {
19254
19221
  }
19255
19222
  return result;
19256
19223
  }
19257
- var init_verify22 = __esm2(() => {
19224
+ var init_verify4 = __esm2(() => {
19258
19225
  init_base64url2();
19259
- init_verify5();
19226
+ init_signing2();
19260
19227
  init_errors22();
19261
19228
  init_buffer_utils2();
19229
+ init_helpers2();
19262
19230
  init_check_key_type2();
19263
19231
  init_validate_crit2();
19264
19232
  init_normalize_key2();
@@ -19281,8 +19249,8 @@ async function compactVerify2(jws, key, options) {
19281
19249
  }
19282
19250
  return result;
19283
19251
  }
19284
- var init_verify32 = __esm2(() => {
19285
- init_verify22();
19252
+ var init_verify22 = __esm2(() => {
19253
+ init_verify4();
19286
19254
  init_errors22();
19287
19255
  init_buffer_utils2();
19288
19256
  });
@@ -19530,8 +19498,8 @@ async function jwtVerify2(jwt2, key, options) {
19530
19498
  }
19531
19499
  return result;
19532
19500
  }
19533
- var init_verify42 = __esm2(() => {
19534
- init_verify32();
19501
+ var init_verify32 = __esm2(() => {
19502
+ init_verify22();
19535
19503
  init_jwt_claims_set2();
19536
19504
  init_errors22();
19537
19505
  });
@@ -19814,14 +19782,14 @@ var init_remote2 = __esm2(() => {
19814
19782
  init_local2();
19815
19783
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
19816
19784
  const NAME = "jose";
19817
- const VERSION = "v6.1.3";
19785
+ const VERSION = "v6.2.1";
19818
19786
  USER_AGENT2 = `${NAME}/${VERSION}`;
19819
19787
  }
19820
19788
  customFetch2 = Symbol();
19821
19789
  jwksCache2 = Symbol();
19822
19790
  });
19823
19791
  var init_webapi2 = __esm2(() => {
19824
- init_verify42();
19792
+ init_verify32();
19825
19793
  init_local2();
19826
19794
  init_remote2();
19827
19795
  init_errors22();
@@ -31595,6 +31563,111 @@ function decode3(input) {
31595
31563
  var init_base64url3 = __esm3(() => {
31596
31564
  init_buffer_utils3();
31597
31565
  });
31566
+ function getHashLength3(hash) {
31567
+ return parseInt(hash.name.slice(4), 10);
31568
+ }
31569
+ function checkHashLength3(algorithm, expected) {
31570
+ const actual = getHashLength3(algorithm.hash);
31571
+ if (actual !== expected)
31572
+ throw unusable3(`SHA-${expected}`, "algorithm.hash");
31573
+ }
31574
+ function getNamedCurve3(alg) {
31575
+ switch (alg) {
31576
+ case "ES256":
31577
+ return "P-256";
31578
+ case "ES384":
31579
+ return "P-384";
31580
+ case "ES512":
31581
+ return "P-521";
31582
+ default:
31583
+ throw new Error("unreachable");
31584
+ }
31585
+ }
31586
+ function checkUsage3(key, usage) {
31587
+ if (usage && !key.usages.includes(usage)) {
31588
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
31589
+ }
31590
+ }
31591
+ function checkSigCryptoKey3(key, alg, usage) {
31592
+ switch (alg) {
31593
+ case "HS256":
31594
+ case "HS384":
31595
+ case "HS512": {
31596
+ if (!isAlgorithm3(key.algorithm, "HMAC"))
31597
+ throw unusable3("HMAC");
31598
+ checkHashLength3(key.algorithm, parseInt(alg.slice(2), 10));
31599
+ break;
31600
+ }
31601
+ case "RS256":
31602
+ case "RS384":
31603
+ case "RS512": {
31604
+ if (!isAlgorithm3(key.algorithm, "RSASSA-PKCS1-v1_5"))
31605
+ throw unusable3("RSASSA-PKCS1-v1_5");
31606
+ checkHashLength3(key.algorithm, parseInt(alg.slice(2), 10));
31607
+ break;
31608
+ }
31609
+ case "PS256":
31610
+ case "PS384":
31611
+ case "PS512": {
31612
+ if (!isAlgorithm3(key.algorithm, "RSA-PSS"))
31613
+ throw unusable3("RSA-PSS");
31614
+ checkHashLength3(key.algorithm, parseInt(alg.slice(2), 10));
31615
+ break;
31616
+ }
31617
+ case "Ed25519":
31618
+ case "EdDSA": {
31619
+ if (!isAlgorithm3(key.algorithm, "Ed25519"))
31620
+ throw unusable3("Ed25519");
31621
+ break;
31622
+ }
31623
+ case "ML-DSA-44":
31624
+ case "ML-DSA-65":
31625
+ case "ML-DSA-87": {
31626
+ if (!isAlgorithm3(key.algorithm, alg))
31627
+ throw unusable3(alg);
31628
+ break;
31629
+ }
31630
+ case "ES256":
31631
+ case "ES384":
31632
+ case "ES512": {
31633
+ if (!isAlgorithm3(key.algorithm, "ECDSA"))
31634
+ throw unusable3("ECDSA");
31635
+ const expected = getNamedCurve3(alg);
31636
+ const actual = key.algorithm.namedCurve;
31637
+ if (actual !== expected)
31638
+ throw unusable3(expected, "algorithm.namedCurve");
31639
+ break;
31640
+ }
31641
+ default:
31642
+ throw new TypeError("CryptoKey does not support this operation");
31643
+ }
31644
+ checkUsage3(key, usage);
31645
+ }
31646
+ var unusable3 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
31647
+ var isAlgorithm3 = (algorithm, name) => algorithm.name === name;
31648
+ function message3(msg, actual, ...types2) {
31649
+ types2 = types2.filter(Boolean);
31650
+ if (types2.length > 2) {
31651
+ const last = types2.pop();
31652
+ msg += `one of type ${types2.join(", ")}, or ${last}.`;
31653
+ } else if (types2.length === 2) {
31654
+ msg += `one of type ${types2[0]} or ${types2[1]}.`;
31655
+ } else {
31656
+ msg += `of type ${types2[0]}.`;
31657
+ }
31658
+ if (actual == null) {
31659
+ msg += ` Received ${actual}`;
31660
+ } else if (typeof actual === "function" && actual.name) {
31661
+ msg += ` Received function ${actual.name}`;
31662
+ } else if (typeof actual === "object" && actual != null) {
31663
+ if (actual.constructor?.name) {
31664
+ msg += ` Received an instance of ${actual.constructor.name}`;
31665
+ }
31666
+ }
31667
+ return msg;
31668
+ }
31669
+ var invalidKeyInput3 = (actual, ...types2) => message3("Key must be ", actual, ...types2);
31670
+ var withAlg3 = (alg, actual, ...types2) => message3(`Key for the ${alg} algorithm must be `, actual, ...types2);
31598
31671
  var exports_errors3 = {};
31599
31672
  __export3(exports_errors3, {
31600
31673
  JWTInvalid: () => JWTInvalid3,
@@ -31632,8 +31705,8 @@ var init_errors23 = __esm3(() => {
31632
31705
  JOSEError3 = class JOSEError4 extends Error {
31633
31706
  static code = "ERR_JOSE_GENERIC";
31634
31707
  code = "ERR_JOSE_GENERIC";
31635
- constructor(message3, options) {
31636
- super(message3, options);
31708
+ constructor(message22, options) {
31709
+ super(message22, options);
31637
31710
  this.name = this.constructor.name;
31638
31711
  Error.captureStackTrace?.(this, this.constructor);
31639
31712
  }
@@ -31644,8 +31717,8 @@ var init_errors23 = __esm3(() => {
31644
31717
  claim;
31645
31718
  reason;
31646
31719
  payload;
31647
- constructor(message3, payload, claim = "unspecified", reason = "unspecified") {
31648
- super(message3, { cause: { claim, reason, payload } });
31720
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
31721
+ super(message22, { cause: { claim, reason, payload } });
31649
31722
  this.claim = claim;
31650
31723
  this.reason = reason;
31651
31724
  this.payload = payload;
@@ -31657,8 +31730,8 @@ var init_errors23 = __esm3(() => {
31657
31730
  claim;
31658
31731
  reason;
31659
31732
  payload;
31660
- constructor(message3, payload, claim = "unspecified", reason = "unspecified") {
31661
- super(message3, { cause: { claim, reason, payload } });
31733
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
31734
+ super(message22, { cause: { claim, reason, payload } });
31662
31735
  this.claim = claim;
31663
31736
  this.reason = reason;
31664
31737
  this.payload = payload;
@@ -31675,8 +31748,8 @@ var init_errors23 = __esm3(() => {
31675
31748
  JWEDecryptionFailed3 = class JWEDecryptionFailed4 extends JOSEError3 {
31676
31749
  static code = "ERR_JWE_DECRYPTION_FAILED";
31677
31750
  code = "ERR_JWE_DECRYPTION_FAILED";
31678
- constructor(message3 = "decryption operation failed", options) {
31679
- super(message3, options);
31751
+ constructor(message22 = "decryption operation failed", options) {
31752
+ super(message22, options);
31680
31753
  }
31681
31754
  };
31682
31755
  JWEInvalid3 = class JWEInvalid4 extends JOSEError3 {
@@ -31702,142 +31775,33 @@ var init_errors23 = __esm3(() => {
31702
31775
  JWKSNoMatchingKey3 = class JWKSNoMatchingKey4 extends JOSEError3 {
31703
31776
  static code = "ERR_JWKS_NO_MATCHING_KEY";
31704
31777
  code = "ERR_JWKS_NO_MATCHING_KEY";
31705
- constructor(message3 = "no applicable key found in the JSON Web Key Set", options) {
31706
- super(message3, options);
31778
+ constructor(message22 = "no applicable key found in the JSON Web Key Set", options) {
31779
+ super(message22, options);
31707
31780
  }
31708
31781
  };
31709
31782
  JWKSMultipleMatchingKeys3 = class JWKSMultipleMatchingKeys4 extends JOSEError3 {
31710
31783
  [Symbol.asyncIterator];
31711
31784
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
31712
31785
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
31713
- constructor(message3 = "multiple matching keys found in the JSON Web Key Set", options) {
31714
- super(message3, options);
31786
+ constructor(message22 = "multiple matching keys found in the JSON Web Key Set", options) {
31787
+ super(message22, options);
31715
31788
  }
31716
31789
  };
31717
31790
  JWKSTimeout3 = class JWKSTimeout4 extends JOSEError3 {
31718
31791
  static code = "ERR_JWKS_TIMEOUT";
31719
31792
  code = "ERR_JWKS_TIMEOUT";
31720
- constructor(message3 = "request timed out", options) {
31721
- super(message3, options);
31793
+ constructor(message22 = "request timed out", options) {
31794
+ super(message22, options);
31722
31795
  }
31723
31796
  };
31724
31797
  JWSSignatureVerificationFailed3 = class JWSSignatureVerificationFailed4 extends JOSEError3 {
31725
31798
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
31726
31799
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
31727
- constructor(message3 = "signature verification failed", options) {
31728
- super(message3, options);
31800
+ constructor(message22 = "signature verification failed", options) {
31801
+ super(message22, options);
31729
31802
  }
31730
31803
  };
31731
31804
  });
31732
- function getHashLength3(hash) {
31733
- return parseInt(hash.name.slice(4), 10);
31734
- }
31735
- function getNamedCurve3(alg) {
31736
- switch (alg) {
31737
- case "ES256":
31738
- return "P-256";
31739
- case "ES384":
31740
- return "P-384";
31741
- case "ES512":
31742
- return "P-521";
31743
- default:
31744
- throw new Error("unreachable");
31745
- }
31746
- }
31747
- function checkUsage3(key, usage) {
31748
- if (usage && !key.usages.includes(usage)) {
31749
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
31750
- }
31751
- }
31752
- function checkSigCryptoKey3(key, alg, usage) {
31753
- switch (alg) {
31754
- case "HS256":
31755
- case "HS384":
31756
- case "HS512": {
31757
- if (!isAlgorithm3(key.algorithm, "HMAC"))
31758
- throw unusable3("HMAC");
31759
- const expected = parseInt(alg.slice(2), 10);
31760
- const actual = getHashLength3(key.algorithm.hash);
31761
- if (actual !== expected)
31762
- throw unusable3(`SHA-${expected}`, "algorithm.hash");
31763
- break;
31764
- }
31765
- case "RS256":
31766
- case "RS384":
31767
- case "RS512": {
31768
- if (!isAlgorithm3(key.algorithm, "RSASSA-PKCS1-v1_5"))
31769
- throw unusable3("RSASSA-PKCS1-v1_5");
31770
- const expected = parseInt(alg.slice(2), 10);
31771
- const actual = getHashLength3(key.algorithm.hash);
31772
- if (actual !== expected)
31773
- throw unusable3(`SHA-${expected}`, "algorithm.hash");
31774
- break;
31775
- }
31776
- case "PS256":
31777
- case "PS384":
31778
- case "PS512": {
31779
- if (!isAlgorithm3(key.algorithm, "RSA-PSS"))
31780
- throw unusable3("RSA-PSS");
31781
- const expected = parseInt(alg.slice(2), 10);
31782
- const actual = getHashLength3(key.algorithm.hash);
31783
- if (actual !== expected)
31784
- throw unusable3(`SHA-${expected}`, "algorithm.hash");
31785
- break;
31786
- }
31787
- case "Ed25519":
31788
- case "EdDSA": {
31789
- if (!isAlgorithm3(key.algorithm, "Ed25519"))
31790
- throw unusable3("Ed25519");
31791
- break;
31792
- }
31793
- case "ML-DSA-44":
31794
- case "ML-DSA-65":
31795
- case "ML-DSA-87": {
31796
- if (!isAlgorithm3(key.algorithm, alg))
31797
- throw unusable3(alg);
31798
- break;
31799
- }
31800
- case "ES256":
31801
- case "ES384":
31802
- case "ES512": {
31803
- if (!isAlgorithm3(key.algorithm, "ECDSA"))
31804
- throw unusable3("ECDSA");
31805
- const expected = getNamedCurve3(alg);
31806
- const actual = key.algorithm.namedCurve;
31807
- if (actual !== expected)
31808
- throw unusable3(expected, "algorithm.namedCurve");
31809
- break;
31810
- }
31811
- default:
31812
- throw new TypeError("CryptoKey does not support this operation");
31813
- }
31814
- checkUsage3(key, usage);
31815
- }
31816
- var unusable3 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
31817
- var isAlgorithm3 = (algorithm, name) => algorithm.name === name;
31818
- function message3(msg, actual, ...types2) {
31819
- types2 = types2.filter(Boolean);
31820
- if (types2.length > 2) {
31821
- const last = types2.pop();
31822
- msg += `one of type ${types2.join(", ")}, or ${last}.`;
31823
- } else if (types2.length === 2) {
31824
- msg += `one of type ${types2[0]} or ${types2[1]}.`;
31825
- } else {
31826
- msg += `of type ${types2[0]}.`;
31827
- }
31828
- if (actual == null) {
31829
- msg += ` Received ${actual}`;
31830
- } else if (typeof actual === "function" && actual.name) {
31831
- msg += ` Received function ${actual.name}`;
31832
- } else if (typeof actual === "object" && actual != null) {
31833
- if (actual.constructor?.name) {
31834
- msg += ` Received an instance of ${actual.constructor.name}`;
31835
- }
31836
- }
31837
- return msg;
31838
- }
31839
- var invalidKeyInput3 = (actual, ...types2) => message3("Key must be ", actual, ...types2);
31840
- var withAlg3 = (alg, actual, ...types2) => message3(`Key for the ${alg} algorithm must be `, actual, ...types2);
31841
31805
  var isCryptoKey3 = (key) => {
31842
31806
  if (key?.[Symbol.toStringTag] === "CryptoKey")
31843
31807
  return true;
@@ -31849,6 +31813,31 @@ var isCryptoKey3 = (key) => {
31849
31813
  };
31850
31814
  var isKeyObject3 = (key) => key?.[Symbol.toStringTag] === "KeyObject";
31851
31815
  var isKeyLike3 = (key) => isCryptoKey3(key) || isKeyObject3(key);
31816
+ function decodeBase64url3(value, label, ErrorClass) {
31817
+ try {
31818
+ return decode3(value);
31819
+ } catch {
31820
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
31821
+ }
31822
+ }
31823
+ var unprotected3;
31824
+ var init_helpers3 = __esm3(() => {
31825
+ init_base64url3();
31826
+ unprotected3 = Symbol();
31827
+ });
31828
+ function isObject3(input) {
31829
+ if (!isObjectLike3(input) || Object.prototype.toString.call(input) !== "[object Object]") {
31830
+ return false;
31831
+ }
31832
+ if (Object.getPrototypeOf(input) === null) {
31833
+ return true;
31834
+ }
31835
+ let proto = input;
31836
+ while (Object.getPrototypeOf(proto) !== null) {
31837
+ proto = Object.getPrototypeOf(proto);
31838
+ }
31839
+ return Object.getPrototypeOf(input) === proto;
31840
+ }
31852
31841
  function isDisjoint3(...headers) {
31853
31842
  const sources = headers.filter(Boolean);
31854
31843
  if (sources.length === 0 || sources.length === 1) {
@@ -31870,20 +31859,11 @@ function isDisjoint3(...headers) {
31870
31859
  }
31871
31860
  return true;
31872
31861
  }
31873
- function isObject3(input) {
31874
- if (!isObjectLike3(input) || Object.prototype.toString.call(input) !== "[object Object]") {
31875
- return false;
31876
- }
31877
- if (Object.getPrototypeOf(input) === null) {
31878
- return true;
31879
- }
31880
- let proto = input;
31881
- while (Object.getPrototypeOf(proto) !== null) {
31882
- proto = Object.getPrototypeOf(proto);
31883
- }
31884
- return Object.getPrototypeOf(input) === proto;
31885
- }
31886
31862
  var isObjectLike3 = (value) => typeof value === "object" && value !== null;
31863
+ var isJWK3 = (key) => isObject3(key) && typeof key.kty === "string";
31864
+ var isPrivateJWK3 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
31865
+ var isPublicJWK3 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
31866
+ var isSecretJWK3 = (key) => key.kty === "oct" && typeof key.k === "string";
31887
31867
  function checkKeyLength3(alg, key) {
31888
31868
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
31889
31869
  const { modulusLength } = key.algorithm;
@@ -31892,6 +31872,59 @@ function checkKeyLength3(alg, key) {
31892
31872
  }
31893
31873
  }
31894
31874
  }
31875
+ function subtleAlgorithm3(alg, algorithm) {
31876
+ const hash = `SHA-${alg.slice(-3)}`;
31877
+ switch (alg) {
31878
+ case "HS256":
31879
+ case "HS384":
31880
+ case "HS512":
31881
+ return { hash, name: "HMAC" };
31882
+ case "PS256":
31883
+ case "PS384":
31884
+ case "PS512":
31885
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
31886
+ case "RS256":
31887
+ case "RS384":
31888
+ case "RS512":
31889
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
31890
+ case "ES256":
31891
+ case "ES384":
31892
+ case "ES512":
31893
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
31894
+ case "Ed25519":
31895
+ case "EdDSA":
31896
+ return { name: "Ed25519" };
31897
+ case "ML-DSA-44":
31898
+ case "ML-DSA-65":
31899
+ case "ML-DSA-87":
31900
+ return { name: alg };
31901
+ default:
31902
+ throw new JOSENotSupported3(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
31903
+ }
31904
+ }
31905
+ async function getSigKey3(alg, key, usage) {
31906
+ if (key instanceof Uint8Array) {
31907
+ if (!alg.startsWith("HS")) {
31908
+ throw new TypeError(invalidKeyInput3(key, "CryptoKey", "KeyObject", "JSON Web Key"));
31909
+ }
31910
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
31911
+ }
31912
+ checkSigCryptoKey3(key, alg, usage);
31913
+ return key;
31914
+ }
31915
+ async function verify3(alg, key, signature, data) {
31916
+ const cryptoKey = await getSigKey3(alg, key, "verify");
31917
+ checkKeyLength3(alg, cryptoKey);
31918
+ const algorithm = subtleAlgorithm3(alg, cryptoKey.algorithm);
31919
+ try {
31920
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
31921
+ } catch {
31922
+ return false;
31923
+ }
31924
+ }
31925
+ var init_signing3 = __esm3(() => {
31926
+ init_errors23();
31927
+ });
31895
31928
  function subtleMapping3(jwk) {
31896
31929
  let algorithm;
31897
31930
  let keyUsages;
@@ -31905,7 +31938,7 @@ function subtleMapping3(jwk) {
31905
31938
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
31906
31939
  break;
31907
31940
  default:
31908
- throw new JOSENotSupported3('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
31941
+ throw new JOSENotSupported3(unsupportedAlg3);
31909
31942
  }
31910
31943
  break;
31911
31944
  }
@@ -31934,22 +31967,19 @@ function subtleMapping3(jwk) {
31934
31967
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
31935
31968
  break;
31936
31969
  default:
31937
- throw new JOSENotSupported3('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
31970
+ throw new JOSENotSupported3(unsupportedAlg3);
31938
31971
  }
31939
31972
  break;
31940
31973
  }
31941
31974
  case "EC": {
31942
31975
  switch (jwk.alg) {
31943
31976
  case "ES256":
31944
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
31945
- keyUsages = jwk.d ? ["sign"] : ["verify"];
31946
- break;
31947
31977
  case "ES384":
31948
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
31949
- keyUsages = jwk.d ? ["sign"] : ["verify"];
31950
- break;
31951
31978
  case "ES512":
31952
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
31979
+ algorithm = {
31980
+ name: "ECDSA",
31981
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
31982
+ };
31953
31983
  keyUsages = jwk.d ? ["sign"] : ["verify"];
31954
31984
  break;
31955
31985
  case "ECDH-ES":
@@ -31960,7 +31990,7 @@ function subtleMapping3(jwk) {
31960
31990
  keyUsages = jwk.d ? ["deriveBits"] : [];
31961
31991
  break;
31962
31992
  default:
31963
- throw new JOSENotSupported3('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
31993
+ throw new JOSENotSupported3(unsupportedAlg3);
31964
31994
  }
31965
31995
  break;
31966
31996
  }
@@ -31979,7 +32009,7 @@ function subtleMapping3(jwk) {
31979
32009
  keyUsages = jwk.d ? ["deriveBits"] : [];
31980
32010
  break;
31981
32011
  default:
31982
- throw new JOSENotSupported3('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
32012
+ throw new JOSENotSupported3(unsupportedAlg3);
31983
32013
  }
31984
32014
  break;
31985
32015
  }
@@ -32000,94 +32030,10 @@ async function jwkToKey3(jwk) {
32000
32030
  delete keyData.use;
32001
32031
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
32002
32032
  }
32033
+ var unsupportedAlg3 = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
32003
32034
  var init_jwk_to_key3 = __esm3(() => {
32004
32035
  init_errors23();
32005
32036
  });
32006
- async function importJWK3(jwk, alg, options) {
32007
- if (!isObject3(jwk)) {
32008
- throw new TypeError("JWK must be an object");
32009
- }
32010
- let ext;
32011
- alg ??= jwk.alg;
32012
- ext ??= options?.extractable ?? jwk.ext;
32013
- switch (jwk.kty) {
32014
- case "oct":
32015
- if (typeof jwk.k !== "string" || !jwk.k) {
32016
- throw new TypeError('missing "k" (Key Value) Parameter value');
32017
- }
32018
- return decode3(jwk.k);
32019
- case "RSA":
32020
- if ("oth" in jwk && jwk.oth !== undefined) {
32021
- throw new JOSENotSupported3('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
32022
- }
32023
- return jwkToKey3({ ...jwk, alg, ext });
32024
- case "AKP": {
32025
- if (typeof jwk.alg !== "string" || !jwk.alg) {
32026
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
32027
- }
32028
- if (alg !== undefined && alg !== jwk.alg) {
32029
- throw new TypeError("JWK alg and alg option value mismatch");
32030
- }
32031
- return jwkToKey3({ ...jwk, ext });
32032
- }
32033
- case "EC":
32034
- case "OKP":
32035
- return jwkToKey3({ ...jwk, alg, ext });
32036
- default:
32037
- throw new JOSENotSupported3('Unsupported "kty" (Key Type) Parameter value');
32038
- }
32039
- }
32040
- var init_import3 = __esm3(() => {
32041
- init_base64url3();
32042
- init_jwk_to_key3();
32043
- init_errors23();
32044
- });
32045
- function validateCrit3(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
32046
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
32047
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
32048
- }
32049
- if (!protectedHeader || protectedHeader.crit === undefined) {
32050
- return new Set;
32051
- }
32052
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
32053
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
32054
- }
32055
- let recognized;
32056
- if (recognizedOption !== undefined) {
32057
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
32058
- } else {
32059
- recognized = recognizedDefault;
32060
- }
32061
- for (const parameter of protectedHeader.crit) {
32062
- if (!recognized.has(parameter)) {
32063
- throw new JOSENotSupported3(`Extension Header Parameter "${parameter}" is not recognized`);
32064
- }
32065
- if (joseHeader[parameter] === undefined) {
32066
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
32067
- }
32068
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
32069
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
32070
- }
32071
- }
32072
- return new Set(protectedHeader.crit);
32073
- }
32074
- var init_validate_crit3 = __esm3(() => {
32075
- init_errors23();
32076
- });
32077
- function validateAlgorithms3(option, algorithms) {
32078
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
32079
- throw new TypeError(`"${option}" option must be an array of strings`);
32080
- }
32081
- if (!algorithms) {
32082
- return;
32083
- }
32084
- return new Set(algorithms);
32085
- }
32086
- var isJWK3 = (key) => isObject3(key) && typeof key.kty === "string";
32087
- var isPrivateJWK3 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
32088
- var isPublicJWK3 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
32089
- var isSecretJWK3 = (key) => key.kty === "oct" && typeof key.k === "string";
32090
- var init_is_jwk3 = () => {};
32091
32037
  async function normalizeKey3(key, alg) {
32092
32038
  if (key instanceof Uint8Array) {
32093
32039
  return key;
@@ -32119,6 +32065,7 @@ async function normalizeKey3(key, alg) {
32119
32065
  }
32120
32066
  throw new Error("unreachable");
32121
32067
  }
32068
+ var unusableForAlg3 = "given KeyObject instance cannot be used for this algorithm";
32122
32069
  var cache3;
32123
32070
  var handleJWK3 = async (key, jwk, alg, freeze = false) => {
32124
32071
  cache3 ||= new WeakMap;
@@ -32153,13 +32100,13 @@ var handleKeyObject3 = (keyObject, alg) => {
32153
32100
  case "ECDH-ES+A256KW":
32154
32101
  break;
32155
32102
  default:
32156
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32103
+ throw new TypeError(unusableForAlg3);
32157
32104
  }
32158
32105
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
32159
32106
  }
32160
32107
  if (keyObject.asymmetricKeyType === "ed25519") {
32161
32108
  if (alg !== "EdDSA" && alg !== "Ed25519") {
32162
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32109
+ throw new TypeError(unusableForAlg3);
32163
32110
  }
32164
32111
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
32165
32112
  isPublic ? "verify" : "sign"
@@ -32170,7 +32117,7 @@ var handleKeyObject3 = (keyObject, alg) => {
32170
32117
  case "ml-dsa-65":
32171
32118
  case "ml-dsa-87": {
32172
32119
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
32173
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32120
+ throw new TypeError(unusableForAlg3);
32174
32121
  }
32175
32122
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
32176
32123
  isPublic ? "verify" : "sign"
@@ -32199,7 +32146,7 @@ var handleKeyObject3 = (keyObject, alg) => {
32199
32146
  hash = "SHA-512";
32200
32147
  break;
32201
32148
  default:
32202
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32149
+ throw new TypeError(unusableForAlg3);
32203
32150
  }
32204
32151
  if (alg.startsWith("RSA-OAEP")) {
32205
32152
  return keyObject.toCryptoKey({
@@ -32220,21 +32167,10 @@ var handleKeyObject3 = (keyObject, alg) => {
32220
32167
  ]);
32221
32168
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
32222
32169
  if (!namedCurve) {
32223
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32170
+ throw new TypeError(unusableForAlg3);
32224
32171
  }
32225
- if (alg === "ES256" && namedCurve === "P-256") {
32226
- cryptoKey = keyObject.toCryptoKey({
32227
- name: "ECDSA",
32228
- namedCurve
32229
- }, extractable, [isPublic ? "verify" : "sign"]);
32230
- }
32231
- if (alg === "ES384" && namedCurve === "P-384") {
32232
- cryptoKey = keyObject.toCryptoKey({
32233
- name: "ECDSA",
32234
- namedCurve
32235
- }, extractable, [isPublic ? "verify" : "sign"]);
32236
- }
32237
- if (alg === "ES512" && namedCurve === "P-521") {
32172
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
32173
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
32238
32174
  cryptoKey = keyObject.toCryptoKey({
32239
32175
  name: "ECDSA",
32240
32176
  namedCurve
@@ -32248,7 +32184,7 @@ var handleKeyObject3 = (keyObject, alg) => {
32248
32184
  }
32249
32185
  }
32250
32186
  if (!cryptoKey) {
32251
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
32187
+ throw new TypeError(unusableForAlg3);
32252
32188
  }
32253
32189
  if (!cached) {
32254
32190
  cache3.set(keyObject, { [alg]: cryptoKey });
@@ -32258,10 +32194,89 @@ var handleKeyObject3 = (keyObject, alg) => {
32258
32194
  return cryptoKey;
32259
32195
  };
32260
32196
  var init_normalize_key3 = __esm3(() => {
32261
- init_is_jwk3();
32262
32197
  init_base64url3();
32263
32198
  init_jwk_to_key3();
32264
32199
  });
32200
+ async function importJWK3(jwk, alg, options) {
32201
+ if (!isObject3(jwk)) {
32202
+ throw new TypeError("JWK must be an object");
32203
+ }
32204
+ let ext;
32205
+ alg ??= jwk.alg;
32206
+ ext ??= options?.extractable ?? jwk.ext;
32207
+ switch (jwk.kty) {
32208
+ case "oct":
32209
+ if (typeof jwk.k !== "string" || !jwk.k) {
32210
+ throw new TypeError('missing "k" (Key Value) Parameter value');
32211
+ }
32212
+ return decode3(jwk.k);
32213
+ case "RSA":
32214
+ if ("oth" in jwk && jwk.oth !== undefined) {
32215
+ throw new JOSENotSupported3('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
32216
+ }
32217
+ return jwkToKey3({ ...jwk, alg, ext });
32218
+ case "AKP": {
32219
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
32220
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
32221
+ }
32222
+ if (alg !== undefined && alg !== jwk.alg) {
32223
+ throw new TypeError("JWK alg and alg option value mismatch");
32224
+ }
32225
+ return jwkToKey3({ ...jwk, ext });
32226
+ }
32227
+ case "EC":
32228
+ case "OKP":
32229
+ return jwkToKey3({ ...jwk, alg, ext });
32230
+ default:
32231
+ throw new JOSENotSupported3('Unsupported "kty" (Key Type) Parameter value');
32232
+ }
32233
+ }
32234
+ var init_import3 = __esm3(() => {
32235
+ init_base64url3();
32236
+ init_jwk_to_key3();
32237
+ init_errors23();
32238
+ });
32239
+ function validateCrit3(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
32240
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
32241
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
32242
+ }
32243
+ if (!protectedHeader || protectedHeader.crit === undefined) {
32244
+ return new Set;
32245
+ }
32246
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
32247
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
32248
+ }
32249
+ let recognized;
32250
+ if (recognizedOption !== undefined) {
32251
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
32252
+ } else {
32253
+ recognized = recognizedDefault;
32254
+ }
32255
+ for (const parameter of protectedHeader.crit) {
32256
+ if (!recognized.has(parameter)) {
32257
+ throw new JOSENotSupported3(`Extension Header Parameter "${parameter}" is not recognized`);
32258
+ }
32259
+ if (joseHeader[parameter] === undefined) {
32260
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
32261
+ }
32262
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
32263
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
32264
+ }
32265
+ }
32266
+ return new Set(protectedHeader.crit);
32267
+ }
32268
+ var init_validate_crit3 = __esm3(() => {
32269
+ init_errors23();
32270
+ });
32271
+ function validateAlgorithms3(option, algorithms) {
32272
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
32273
+ throw new TypeError(`"${option}" option must be an array of strings`);
32274
+ }
32275
+ if (!algorithms) {
32276
+ return;
32277
+ }
32278
+ return new Set(algorithms);
32279
+ }
32265
32280
  function checkKeyType3(alg, key, usage) {
32266
32281
  switch (alg.substring(0, 2)) {
32267
32282
  case "A1":
@@ -32380,67 +32395,7 @@ var asymmetricTypeCheck3 = (alg, key, usage) => {
32380
32395
  }
32381
32396
  }
32382
32397
  };
32383
- var init_check_key_type3 = __esm3(() => {
32384
- init_is_jwk3();
32385
- });
32386
- function subtleAlgorithm3(alg, algorithm) {
32387
- const hash = `SHA-${alg.slice(-3)}`;
32388
- switch (alg) {
32389
- case "HS256":
32390
- case "HS384":
32391
- case "HS512":
32392
- return { hash, name: "HMAC" };
32393
- case "PS256":
32394
- case "PS384":
32395
- case "PS512":
32396
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
32397
- case "RS256":
32398
- case "RS384":
32399
- case "RS512":
32400
- return { hash, name: "RSASSA-PKCS1-v1_5" };
32401
- case "ES256":
32402
- case "ES384":
32403
- case "ES512":
32404
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
32405
- case "Ed25519":
32406
- case "EdDSA":
32407
- return { name: "Ed25519" };
32408
- case "ML-DSA-44":
32409
- case "ML-DSA-65":
32410
- case "ML-DSA-87":
32411
- return { name: alg };
32412
- default:
32413
- throw new JOSENotSupported3(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
32414
- }
32415
- }
32416
- var init_subtle_dsa3 = __esm3(() => {
32417
- init_errors23();
32418
- });
32419
- async function getSigKey3(alg, key, usage) {
32420
- if (key instanceof Uint8Array) {
32421
- if (!alg.startsWith("HS")) {
32422
- throw new TypeError(invalidKeyInput3(key, "CryptoKey", "KeyObject", "JSON Web Key"));
32423
- }
32424
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
32425
- }
32426
- checkSigCryptoKey3(key, alg, usage);
32427
- return key;
32428
- }
32429
- var init_get_sign_verify_key3 = () => {};
32430
- async function verify3(alg, key, signature, data) {
32431
- const cryptoKey = await getSigKey3(alg, key, "verify");
32432
- checkKeyLength3(alg, cryptoKey);
32433
- const algorithm = subtleAlgorithm3(alg, cryptoKey.algorithm);
32434
- try {
32435
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
32436
- } catch {
32437
- return false;
32438
- }
32439
- }
32440
- var init_verify6 = __esm3(() => {
32441
- init_subtle_dsa3();
32442
- init_get_sign_verify_key3();
32443
- });
32398
+ var init_check_key_type3 = () => {};
32444
32399
  async function flattenedVerify3(jws, key, options) {
32445
32400
  if (!isObject3(jws)) {
32446
32401
  throw new JWSInvalid3("Flattened JWS must be an object");
@@ -32506,12 +32461,7 @@ async function flattenedVerify3(jws, key, options) {
32506
32461
  }
32507
32462
  checkKeyType3(alg, key, "verify");
32508
32463
  const data = concat3(jws.protected !== undefined ? encode3(jws.protected) : new Uint8Array, encode3("."), typeof jws.payload === "string" ? b64 ? encode3(jws.payload) : encoder3.encode(jws.payload) : jws.payload);
32509
- let signature;
32510
- try {
32511
- signature = decode3(jws.signature);
32512
- } catch {
32513
- throw new JWSInvalid3("Failed to base64url decode the signature");
32514
- }
32464
+ const signature = decodeBase64url3(jws.signature, "signature", JWSInvalid3);
32515
32465
  const k = await normalizeKey3(key, alg);
32516
32466
  const verified = await verify3(alg, k, signature, data);
32517
32467
  if (!verified) {
@@ -32519,11 +32469,7 @@ async function flattenedVerify3(jws, key, options) {
32519
32469
  }
32520
32470
  let payload;
32521
32471
  if (b64) {
32522
- try {
32523
- payload = decode3(jws.payload);
32524
- } catch {
32525
- throw new JWSInvalid3("Failed to base64url decode the payload");
32526
- }
32472
+ payload = decodeBase64url3(jws.payload, "payload", JWSInvalid3);
32527
32473
  } else if (typeof jws.payload === "string") {
32528
32474
  payload = encoder3.encode(jws.payload);
32529
32475
  } else {
@@ -32541,11 +32487,12 @@ async function flattenedVerify3(jws, key, options) {
32541
32487
  }
32542
32488
  return result;
32543
32489
  }
32544
- var init_verify23 = __esm3(() => {
32490
+ var init_verify5 = __esm3(() => {
32545
32491
  init_base64url3();
32546
- init_verify6();
32492
+ init_signing3();
32547
32493
  init_errors23();
32548
32494
  init_buffer_utils3();
32495
+ init_helpers3();
32549
32496
  init_check_key_type3();
32550
32497
  init_validate_crit3();
32551
32498
  init_normalize_key3();
@@ -32568,8 +32515,8 @@ async function compactVerify3(jws, key, options) {
32568
32515
  }
32569
32516
  return result;
32570
32517
  }
32571
- var init_verify33 = __esm3(() => {
32572
- init_verify23();
32518
+ var init_verify23 = __esm3(() => {
32519
+ init_verify5();
32573
32520
  init_errors23();
32574
32521
  init_buffer_utils3();
32575
32522
  });
@@ -32817,8 +32764,8 @@ async function jwtVerify3(jwt2, key, options) {
32817
32764
  }
32818
32765
  return result;
32819
32766
  }
32820
- var init_verify43 = __esm3(() => {
32821
- init_verify33();
32767
+ var init_verify33 = __esm3(() => {
32768
+ init_verify23();
32822
32769
  init_jwt_claims_set3();
32823
32770
  init_errors23();
32824
32771
  });
@@ -33101,14 +33048,14 @@ var init_remote3 = __esm3(() => {
33101
33048
  init_local3();
33102
33049
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
33103
33050
  const NAME = "jose";
33104
- const VERSION = "v6.1.3";
33051
+ const VERSION = "v6.2.1";
33105
33052
  USER_AGENT3 = `${NAME}/${VERSION}`;
33106
33053
  }
33107
33054
  customFetch3 = Symbol();
33108
33055
  jwksCache3 = Symbol();
33109
33056
  });
33110
33057
  var init_webapi3 = __esm3(() => {
33111
- init_verify43();
33058
+ init_verify33();
33112
33059
  init_local3();
33113
33060
  init_remote3();
33114
33061
  init_errors23();
@@ -41825,6 +41772,111 @@ function decode4(input) {
41825
41772
  var init_base64url4 = __esm4(() => {
41826
41773
  init_buffer_utils4();
41827
41774
  });
41775
+ function getHashLength4(hash) {
41776
+ return parseInt(hash.name.slice(4), 10);
41777
+ }
41778
+ function checkHashLength4(algorithm, expected) {
41779
+ const actual = getHashLength4(algorithm.hash);
41780
+ if (actual !== expected)
41781
+ throw unusable4(`SHA-${expected}`, "algorithm.hash");
41782
+ }
41783
+ function getNamedCurve4(alg) {
41784
+ switch (alg) {
41785
+ case "ES256":
41786
+ return "P-256";
41787
+ case "ES384":
41788
+ return "P-384";
41789
+ case "ES512":
41790
+ return "P-521";
41791
+ default:
41792
+ throw new Error("unreachable");
41793
+ }
41794
+ }
41795
+ function checkUsage4(key, usage) {
41796
+ if (usage && !key.usages.includes(usage)) {
41797
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
41798
+ }
41799
+ }
41800
+ function checkSigCryptoKey4(key, alg, usage) {
41801
+ switch (alg) {
41802
+ case "HS256":
41803
+ case "HS384":
41804
+ case "HS512": {
41805
+ if (!isAlgorithm4(key.algorithm, "HMAC"))
41806
+ throw unusable4("HMAC");
41807
+ checkHashLength4(key.algorithm, parseInt(alg.slice(2), 10));
41808
+ break;
41809
+ }
41810
+ case "RS256":
41811
+ case "RS384":
41812
+ case "RS512": {
41813
+ if (!isAlgorithm4(key.algorithm, "RSASSA-PKCS1-v1_5"))
41814
+ throw unusable4("RSASSA-PKCS1-v1_5");
41815
+ checkHashLength4(key.algorithm, parseInt(alg.slice(2), 10));
41816
+ break;
41817
+ }
41818
+ case "PS256":
41819
+ case "PS384":
41820
+ case "PS512": {
41821
+ if (!isAlgorithm4(key.algorithm, "RSA-PSS"))
41822
+ throw unusable4("RSA-PSS");
41823
+ checkHashLength4(key.algorithm, parseInt(alg.slice(2), 10));
41824
+ break;
41825
+ }
41826
+ case "Ed25519":
41827
+ case "EdDSA": {
41828
+ if (!isAlgorithm4(key.algorithm, "Ed25519"))
41829
+ throw unusable4("Ed25519");
41830
+ break;
41831
+ }
41832
+ case "ML-DSA-44":
41833
+ case "ML-DSA-65":
41834
+ case "ML-DSA-87": {
41835
+ if (!isAlgorithm4(key.algorithm, alg))
41836
+ throw unusable4(alg);
41837
+ break;
41838
+ }
41839
+ case "ES256":
41840
+ case "ES384":
41841
+ case "ES512": {
41842
+ if (!isAlgorithm4(key.algorithm, "ECDSA"))
41843
+ throw unusable4("ECDSA");
41844
+ const expected = getNamedCurve4(alg);
41845
+ const actual = key.algorithm.namedCurve;
41846
+ if (actual !== expected)
41847
+ throw unusable4(expected, "algorithm.namedCurve");
41848
+ break;
41849
+ }
41850
+ default:
41851
+ throw new TypeError("CryptoKey does not support this operation");
41852
+ }
41853
+ checkUsage4(key, usage);
41854
+ }
41855
+ var unusable4 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
41856
+ var isAlgorithm4 = (algorithm, name) => algorithm.name === name;
41857
+ function message4(msg, actual, ...types2) {
41858
+ types2 = types2.filter(Boolean);
41859
+ if (types2.length > 2) {
41860
+ const last = types2.pop();
41861
+ msg += `one of type ${types2.join(", ")}, or ${last}.`;
41862
+ } else if (types2.length === 2) {
41863
+ msg += `one of type ${types2[0]} or ${types2[1]}.`;
41864
+ } else {
41865
+ msg += `of type ${types2[0]}.`;
41866
+ }
41867
+ if (actual == null) {
41868
+ msg += ` Received ${actual}`;
41869
+ } else if (typeof actual === "function" && actual.name) {
41870
+ msg += ` Received function ${actual.name}`;
41871
+ } else if (typeof actual === "object" && actual != null) {
41872
+ if (actual.constructor?.name) {
41873
+ msg += ` Received an instance of ${actual.constructor.name}`;
41874
+ }
41875
+ }
41876
+ return msg;
41877
+ }
41878
+ var invalidKeyInput4 = (actual, ...types2) => message4("Key must be ", actual, ...types2);
41879
+ var withAlg4 = (alg, actual, ...types2) => message4(`Key for the ${alg} algorithm must be `, actual, ...types2);
41828
41880
  var exports_errors4 = {};
41829
41881
  __export4(exports_errors4, {
41830
41882
  JWTInvalid: () => JWTInvalid4,
@@ -41862,8 +41914,8 @@ var init_errors24 = __esm4(() => {
41862
41914
  JOSEError4 = class JOSEError5 extends Error {
41863
41915
  static code = "ERR_JOSE_GENERIC";
41864
41916
  code = "ERR_JOSE_GENERIC";
41865
- constructor(message4, options) {
41866
- super(message4, options);
41917
+ constructor(message22, options) {
41918
+ super(message22, options);
41867
41919
  this.name = this.constructor.name;
41868
41920
  Error.captureStackTrace?.(this, this.constructor);
41869
41921
  }
@@ -41874,8 +41926,8 @@ var init_errors24 = __esm4(() => {
41874
41926
  claim;
41875
41927
  reason;
41876
41928
  payload;
41877
- constructor(message4, payload, claim = "unspecified", reason = "unspecified") {
41878
- super(message4, { cause: { claim, reason, payload } });
41929
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
41930
+ super(message22, { cause: { claim, reason, payload } });
41879
41931
  this.claim = claim;
41880
41932
  this.reason = reason;
41881
41933
  this.payload = payload;
@@ -41887,8 +41939,8 @@ var init_errors24 = __esm4(() => {
41887
41939
  claim;
41888
41940
  reason;
41889
41941
  payload;
41890
- constructor(message4, payload, claim = "unspecified", reason = "unspecified") {
41891
- super(message4, { cause: { claim, reason, payload } });
41942
+ constructor(message22, payload, claim = "unspecified", reason = "unspecified") {
41943
+ super(message22, { cause: { claim, reason, payload } });
41892
41944
  this.claim = claim;
41893
41945
  this.reason = reason;
41894
41946
  this.payload = payload;
@@ -41905,8 +41957,8 @@ var init_errors24 = __esm4(() => {
41905
41957
  JWEDecryptionFailed4 = class JWEDecryptionFailed5 extends JOSEError4 {
41906
41958
  static code = "ERR_JWE_DECRYPTION_FAILED";
41907
41959
  code = "ERR_JWE_DECRYPTION_FAILED";
41908
- constructor(message4 = "decryption operation failed", options) {
41909
- super(message4, options);
41960
+ constructor(message22 = "decryption operation failed", options) {
41961
+ super(message22, options);
41910
41962
  }
41911
41963
  };
41912
41964
  JWEInvalid4 = class JWEInvalid5 extends JOSEError4 {
@@ -41932,142 +41984,33 @@ var init_errors24 = __esm4(() => {
41932
41984
  JWKSNoMatchingKey4 = class JWKSNoMatchingKey5 extends JOSEError4 {
41933
41985
  static code = "ERR_JWKS_NO_MATCHING_KEY";
41934
41986
  code = "ERR_JWKS_NO_MATCHING_KEY";
41935
- constructor(message4 = "no applicable key found in the JSON Web Key Set", options) {
41936
- super(message4, options);
41987
+ constructor(message22 = "no applicable key found in the JSON Web Key Set", options) {
41988
+ super(message22, options);
41937
41989
  }
41938
41990
  };
41939
41991
  JWKSMultipleMatchingKeys4 = class JWKSMultipleMatchingKeys5 extends JOSEError4 {
41940
41992
  [Symbol.asyncIterator];
41941
41993
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
41942
41994
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
41943
- constructor(message4 = "multiple matching keys found in the JSON Web Key Set", options) {
41944
- super(message4, options);
41995
+ constructor(message22 = "multiple matching keys found in the JSON Web Key Set", options) {
41996
+ super(message22, options);
41945
41997
  }
41946
41998
  };
41947
41999
  JWKSTimeout4 = class JWKSTimeout5 extends JOSEError4 {
41948
42000
  static code = "ERR_JWKS_TIMEOUT";
41949
42001
  code = "ERR_JWKS_TIMEOUT";
41950
- constructor(message4 = "request timed out", options) {
41951
- super(message4, options);
42002
+ constructor(message22 = "request timed out", options) {
42003
+ super(message22, options);
41952
42004
  }
41953
42005
  };
41954
42006
  JWSSignatureVerificationFailed4 = class JWSSignatureVerificationFailed5 extends JOSEError4 {
41955
42007
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
41956
42008
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
41957
- constructor(message4 = "signature verification failed", options) {
41958
- super(message4, options);
42009
+ constructor(message22 = "signature verification failed", options) {
42010
+ super(message22, options);
41959
42011
  }
41960
42012
  };
41961
42013
  });
41962
- function getHashLength4(hash) {
41963
- return parseInt(hash.name.slice(4), 10);
41964
- }
41965
- function getNamedCurve4(alg) {
41966
- switch (alg) {
41967
- case "ES256":
41968
- return "P-256";
41969
- case "ES384":
41970
- return "P-384";
41971
- case "ES512":
41972
- return "P-521";
41973
- default:
41974
- throw new Error("unreachable");
41975
- }
41976
- }
41977
- function checkUsage4(key, usage) {
41978
- if (usage && !key.usages.includes(usage)) {
41979
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
41980
- }
41981
- }
41982
- function checkSigCryptoKey4(key, alg, usage) {
41983
- switch (alg) {
41984
- case "HS256":
41985
- case "HS384":
41986
- case "HS512": {
41987
- if (!isAlgorithm4(key.algorithm, "HMAC"))
41988
- throw unusable4("HMAC");
41989
- const expected = parseInt(alg.slice(2), 10);
41990
- const actual = getHashLength4(key.algorithm.hash);
41991
- if (actual !== expected)
41992
- throw unusable4(`SHA-${expected}`, "algorithm.hash");
41993
- break;
41994
- }
41995
- case "RS256":
41996
- case "RS384":
41997
- case "RS512": {
41998
- if (!isAlgorithm4(key.algorithm, "RSASSA-PKCS1-v1_5"))
41999
- throw unusable4("RSASSA-PKCS1-v1_5");
42000
- const expected = parseInt(alg.slice(2), 10);
42001
- const actual = getHashLength4(key.algorithm.hash);
42002
- if (actual !== expected)
42003
- throw unusable4(`SHA-${expected}`, "algorithm.hash");
42004
- break;
42005
- }
42006
- case "PS256":
42007
- case "PS384":
42008
- case "PS512": {
42009
- if (!isAlgorithm4(key.algorithm, "RSA-PSS"))
42010
- throw unusable4("RSA-PSS");
42011
- const expected = parseInt(alg.slice(2), 10);
42012
- const actual = getHashLength4(key.algorithm.hash);
42013
- if (actual !== expected)
42014
- throw unusable4(`SHA-${expected}`, "algorithm.hash");
42015
- break;
42016
- }
42017
- case "Ed25519":
42018
- case "EdDSA": {
42019
- if (!isAlgorithm4(key.algorithm, "Ed25519"))
42020
- throw unusable4("Ed25519");
42021
- break;
42022
- }
42023
- case "ML-DSA-44":
42024
- case "ML-DSA-65":
42025
- case "ML-DSA-87": {
42026
- if (!isAlgorithm4(key.algorithm, alg))
42027
- throw unusable4(alg);
42028
- break;
42029
- }
42030
- case "ES256":
42031
- case "ES384":
42032
- case "ES512": {
42033
- if (!isAlgorithm4(key.algorithm, "ECDSA"))
42034
- throw unusable4("ECDSA");
42035
- const expected = getNamedCurve4(alg);
42036
- const actual = key.algorithm.namedCurve;
42037
- if (actual !== expected)
42038
- throw unusable4(expected, "algorithm.namedCurve");
42039
- break;
42040
- }
42041
- default:
42042
- throw new TypeError("CryptoKey does not support this operation");
42043
- }
42044
- checkUsage4(key, usage);
42045
- }
42046
- var unusable4 = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
42047
- var isAlgorithm4 = (algorithm, name) => algorithm.name === name;
42048
- function message4(msg, actual, ...types2) {
42049
- types2 = types2.filter(Boolean);
42050
- if (types2.length > 2) {
42051
- const last = types2.pop();
42052
- msg += `one of type ${types2.join(", ")}, or ${last}.`;
42053
- } else if (types2.length === 2) {
42054
- msg += `one of type ${types2[0]} or ${types2[1]}.`;
42055
- } else {
42056
- msg += `of type ${types2[0]}.`;
42057
- }
42058
- if (actual == null) {
42059
- msg += ` Received ${actual}`;
42060
- } else if (typeof actual === "function" && actual.name) {
42061
- msg += ` Received function ${actual.name}`;
42062
- } else if (typeof actual === "object" && actual != null) {
42063
- if (actual.constructor?.name) {
42064
- msg += ` Received an instance of ${actual.constructor.name}`;
42065
- }
42066
- }
42067
- return msg;
42068
- }
42069
- var invalidKeyInput4 = (actual, ...types2) => message4("Key must be ", actual, ...types2);
42070
- var withAlg4 = (alg, actual, ...types2) => message4(`Key for the ${alg} algorithm must be `, actual, ...types2);
42071
42014
  var isCryptoKey4 = (key) => {
42072
42015
  if (key?.[Symbol.toStringTag] === "CryptoKey")
42073
42016
  return true;
@@ -42079,6 +42022,31 @@ var isCryptoKey4 = (key) => {
42079
42022
  };
42080
42023
  var isKeyObject4 = (key) => key?.[Symbol.toStringTag] === "KeyObject";
42081
42024
  var isKeyLike4 = (key) => isCryptoKey4(key) || isKeyObject4(key);
42025
+ function decodeBase64url4(value, label, ErrorClass) {
42026
+ try {
42027
+ return decode4(value);
42028
+ } catch {
42029
+ throw new ErrorClass(`Failed to base64url decode the ${label}`);
42030
+ }
42031
+ }
42032
+ var unprotected4;
42033
+ var init_helpers4 = __esm4(() => {
42034
+ init_base64url4();
42035
+ unprotected4 = Symbol();
42036
+ });
42037
+ function isObject4(input) {
42038
+ if (!isObjectLike4(input) || Object.prototype.toString.call(input) !== "[object Object]") {
42039
+ return false;
42040
+ }
42041
+ if (Object.getPrototypeOf(input) === null) {
42042
+ return true;
42043
+ }
42044
+ let proto = input;
42045
+ while (Object.getPrototypeOf(proto) !== null) {
42046
+ proto = Object.getPrototypeOf(proto);
42047
+ }
42048
+ return Object.getPrototypeOf(input) === proto;
42049
+ }
42082
42050
  function isDisjoint4(...headers) {
42083
42051
  const sources = headers.filter(Boolean);
42084
42052
  if (sources.length === 0 || sources.length === 1) {
@@ -42100,20 +42068,11 @@ function isDisjoint4(...headers) {
42100
42068
  }
42101
42069
  return true;
42102
42070
  }
42103
- function isObject4(input) {
42104
- if (!isObjectLike4(input) || Object.prototype.toString.call(input) !== "[object Object]") {
42105
- return false;
42106
- }
42107
- if (Object.getPrototypeOf(input) === null) {
42108
- return true;
42109
- }
42110
- let proto = input;
42111
- while (Object.getPrototypeOf(proto) !== null) {
42112
- proto = Object.getPrototypeOf(proto);
42113
- }
42114
- return Object.getPrototypeOf(input) === proto;
42115
- }
42116
42071
  var isObjectLike4 = (value) => typeof value === "object" && value !== null;
42072
+ var isJWK4 = (key) => isObject4(key) && typeof key.kty === "string";
42073
+ var isPrivateJWK4 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
42074
+ var isPublicJWK4 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
42075
+ var isSecretJWK4 = (key) => key.kty === "oct" && typeof key.k === "string";
42117
42076
  function checkKeyLength4(alg, key) {
42118
42077
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
42119
42078
  const { modulusLength } = key.algorithm;
@@ -42122,6 +42081,59 @@ function checkKeyLength4(alg, key) {
42122
42081
  }
42123
42082
  }
42124
42083
  }
42084
+ function subtleAlgorithm4(alg, algorithm) {
42085
+ const hash = `SHA-${alg.slice(-3)}`;
42086
+ switch (alg) {
42087
+ case "HS256":
42088
+ case "HS384":
42089
+ case "HS512":
42090
+ return { hash, name: "HMAC" };
42091
+ case "PS256":
42092
+ case "PS384":
42093
+ case "PS512":
42094
+ return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
42095
+ case "RS256":
42096
+ case "RS384":
42097
+ case "RS512":
42098
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
42099
+ case "ES256":
42100
+ case "ES384":
42101
+ case "ES512":
42102
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
42103
+ case "Ed25519":
42104
+ case "EdDSA":
42105
+ return { name: "Ed25519" };
42106
+ case "ML-DSA-44":
42107
+ case "ML-DSA-65":
42108
+ case "ML-DSA-87":
42109
+ return { name: alg };
42110
+ default:
42111
+ throw new JOSENotSupported4(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
42112
+ }
42113
+ }
42114
+ async function getSigKey4(alg, key, usage) {
42115
+ if (key instanceof Uint8Array) {
42116
+ if (!alg.startsWith("HS")) {
42117
+ throw new TypeError(invalidKeyInput4(key, "CryptoKey", "KeyObject", "JSON Web Key"));
42118
+ }
42119
+ return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
42120
+ }
42121
+ checkSigCryptoKey4(key, alg, usage);
42122
+ return key;
42123
+ }
42124
+ async function verify4(alg, key, signature, data) {
42125
+ const cryptoKey = await getSigKey4(alg, key, "verify");
42126
+ checkKeyLength4(alg, cryptoKey);
42127
+ const algorithm = subtleAlgorithm4(alg, cryptoKey.algorithm);
42128
+ try {
42129
+ return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
42130
+ } catch {
42131
+ return false;
42132
+ }
42133
+ }
42134
+ var init_signing4 = __esm4(() => {
42135
+ init_errors24();
42136
+ });
42125
42137
  function subtleMapping4(jwk) {
42126
42138
  let algorithm;
42127
42139
  let keyUsages;
@@ -42135,7 +42147,7 @@ function subtleMapping4(jwk) {
42135
42147
  keyUsages = jwk.priv ? ["sign"] : ["verify"];
42136
42148
  break;
42137
42149
  default:
42138
- throw new JOSENotSupported4('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
42150
+ throw new JOSENotSupported4(unsupportedAlg4);
42139
42151
  }
42140
42152
  break;
42141
42153
  }
@@ -42164,22 +42176,19 @@ function subtleMapping4(jwk) {
42164
42176
  keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
42165
42177
  break;
42166
42178
  default:
42167
- throw new JOSENotSupported4('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
42179
+ throw new JOSENotSupported4(unsupportedAlg4);
42168
42180
  }
42169
42181
  break;
42170
42182
  }
42171
42183
  case "EC": {
42172
42184
  switch (jwk.alg) {
42173
42185
  case "ES256":
42174
- algorithm = { name: "ECDSA", namedCurve: "P-256" };
42175
- keyUsages = jwk.d ? ["sign"] : ["verify"];
42176
- break;
42177
42186
  case "ES384":
42178
- algorithm = { name: "ECDSA", namedCurve: "P-384" };
42179
- keyUsages = jwk.d ? ["sign"] : ["verify"];
42180
- break;
42181
42187
  case "ES512":
42182
- algorithm = { name: "ECDSA", namedCurve: "P-521" };
42188
+ algorithm = {
42189
+ name: "ECDSA",
42190
+ namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
42191
+ };
42183
42192
  keyUsages = jwk.d ? ["sign"] : ["verify"];
42184
42193
  break;
42185
42194
  case "ECDH-ES":
@@ -42190,7 +42199,7 @@ function subtleMapping4(jwk) {
42190
42199
  keyUsages = jwk.d ? ["deriveBits"] : [];
42191
42200
  break;
42192
42201
  default:
42193
- throw new JOSENotSupported4('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
42202
+ throw new JOSENotSupported4(unsupportedAlg4);
42194
42203
  }
42195
42204
  break;
42196
42205
  }
@@ -42209,7 +42218,7 @@ function subtleMapping4(jwk) {
42209
42218
  keyUsages = jwk.d ? ["deriveBits"] : [];
42210
42219
  break;
42211
42220
  default:
42212
- throw new JOSENotSupported4('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
42221
+ throw new JOSENotSupported4(unsupportedAlg4);
42213
42222
  }
42214
42223
  break;
42215
42224
  }
@@ -42230,94 +42239,10 @@ async function jwkToKey4(jwk) {
42230
42239
  delete keyData.use;
42231
42240
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
42232
42241
  }
42242
+ var unsupportedAlg4 = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
42233
42243
  var init_jwk_to_key4 = __esm4(() => {
42234
42244
  init_errors24();
42235
42245
  });
42236
- async function importJWK4(jwk, alg, options) {
42237
- if (!isObject4(jwk)) {
42238
- throw new TypeError("JWK must be an object");
42239
- }
42240
- let ext;
42241
- alg ??= jwk.alg;
42242
- ext ??= options?.extractable ?? jwk.ext;
42243
- switch (jwk.kty) {
42244
- case "oct":
42245
- if (typeof jwk.k !== "string" || !jwk.k) {
42246
- throw new TypeError('missing "k" (Key Value) Parameter value');
42247
- }
42248
- return decode4(jwk.k);
42249
- case "RSA":
42250
- if ("oth" in jwk && jwk.oth !== undefined) {
42251
- throw new JOSENotSupported4('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
42252
- }
42253
- return jwkToKey4({ ...jwk, alg, ext });
42254
- case "AKP": {
42255
- if (typeof jwk.alg !== "string" || !jwk.alg) {
42256
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
42257
- }
42258
- if (alg !== undefined && alg !== jwk.alg) {
42259
- throw new TypeError("JWK alg and alg option value mismatch");
42260
- }
42261
- return jwkToKey4({ ...jwk, ext });
42262
- }
42263
- case "EC":
42264
- case "OKP":
42265
- return jwkToKey4({ ...jwk, alg, ext });
42266
- default:
42267
- throw new JOSENotSupported4('Unsupported "kty" (Key Type) Parameter value');
42268
- }
42269
- }
42270
- var init_import4 = __esm4(() => {
42271
- init_base64url4();
42272
- init_jwk_to_key4();
42273
- init_errors24();
42274
- });
42275
- function validateCrit4(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
42276
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
42277
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
42278
- }
42279
- if (!protectedHeader || protectedHeader.crit === undefined) {
42280
- return new Set;
42281
- }
42282
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
42283
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
42284
- }
42285
- let recognized;
42286
- if (recognizedOption !== undefined) {
42287
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
42288
- } else {
42289
- recognized = recognizedDefault;
42290
- }
42291
- for (const parameter of protectedHeader.crit) {
42292
- if (!recognized.has(parameter)) {
42293
- throw new JOSENotSupported4(`Extension Header Parameter "${parameter}" is not recognized`);
42294
- }
42295
- if (joseHeader[parameter] === undefined) {
42296
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
42297
- }
42298
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
42299
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
42300
- }
42301
- }
42302
- return new Set(protectedHeader.crit);
42303
- }
42304
- var init_validate_crit4 = __esm4(() => {
42305
- init_errors24();
42306
- });
42307
- function validateAlgorithms4(option, algorithms) {
42308
- if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
42309
- throw new TypeError(`"${option}" option must be an array of strings`);
42310
- }
42311
- if (!algorithms) {
42312
- return;
42313
- }
42314
- return new Set(algorithms);
42315
- }
42316
- var isJWK4 = (key) => isObject4(key) && typeof key.kty === "string";
42317
- var isPrivateJWK4 = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
42318
- var isPublicJWK4 = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
42319
- var isSecretJWK4 = (key) => key.kty === "oct" && typeof key.k === "string";
42320
- var init_is_jwk4 = () => {};
42321
42246
  async function normalizeKey4(key, alg) {
42322
42247
  if (key instanceof Uint8Array) {
42323
42248
  return key;
@@ -42349,6 +42274,7 @@ async function normalizeKey4(key, alg) {
42349
42274
  }
42350
42275
  throw new Error("unreachable");
42351
42276
  }
42277
+ var unusableForAlg4 = "given KeyObject instance cannot be used for this algorithm";
42352
42278
  var cache4;
42353
42279
  var handleJWK4 = async (key, jwk, alg, freeze = false) => {
42354
42280
  cache4 ||= new WeakMap;
@@ -42383,13 +42309,13 @@ var handleKeyObject4 = (keyObject, alg) => {
42383
42309
  case "ECDH-ES+A256KW":
42384
42310
  break;
42385
42311
  default:
42386
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42312
+ throw new TypeError(unusableForAlg4);
42387
42313
  }
42388
42314
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
42389
42315
  }
42390
42316
  if (keyObject.asymmetricKeyType === "ed25519") {
42391
42317
  if (alg !== "EdDSA" && alg !== "Ed25519") {
42392
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42318
+ throw new TypeError(unusableForAlg4);
42393
42319
  }
42394
42320
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
42395
42321
  isPublic ? "verify" : "sign"
@@ -42400,7 +42326,7 @@ var handleKeyObject4 = (keyObject, alg) => {
42400
42326
  case "ml-dsa-65":
42401
42327
  case "ml-dsa-87": {
42402
42328
  if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
42403
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42329
+ throw new TypeError(unusableForAlg4);
42404
42330
  }
42405
42331
  cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
42406
42332
  isPublic ? "verify" : "sign"
@@ -42429,7 +42355,7 @@ var handleKeyObject4 = (keyObject, alg) => {
42429
42355
  hash = "SHA-512";
42430
42356
  break;
42431
42357
  default:
42432
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42358
+ throw new TypeError(unusableForAlg4);
42433
42359
  }
42434
42360
  if (alg.startsWith("RSA-OAEP")) {
42435
42361
  return keyObject.toCryptoKey({
@@ -42450,21 +42376,10 @@ var handleKeyObject4 = (keyObject, alg) => {
42450
42376
  ]);
42451
42377
  const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
42452
42378
  if (!namedCurve) {
42453
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42454
- }
42455
- if (alg === "ES256" && namedCurve === "P-256") {
42456
- cryptoKey = keyObject.toCryptoKey({
42457
- name: "ECDSA",
42458
- namedCurve
42459
- }, extractable, [isPublic ? "verify" : "sign"]);
42460
- }
42461
- if (alg === "ES384" && namedCurve === "P-384") {
42462
- cryptoKey = keyObject.toCryptoKey({
42463
- name: "ECDSA",
42464
- namedCurve
42465
- }, extractable, [isPublic ? "verify" : "sign"]);
42379
+ throw new TypeError(unusableForAlg4);
42466
42380
  }
42467
- if (alg === "ES512" && namedCurve === "P-521") {
42381
+ const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
42382
+ if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
42468
42383
  cryptoKey = keyObject.toCryptoKey({
42469
42384
  name: "ECDSA",
42470
42385
  namedCurve
@@ -42478,7 +42393,7 @@ var handleKeyObject4 = (keyObject, alg) => {
42478
42393
  }
42479
42394
  }
42480
42395
  if (!cryptoKey) {
42481
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
42396
+ throw new TypeError(unusableForAlg4);
42482
42397
  }
42483
42398
  if (!cached) {
42484
42399
  cache4.set(keyObject, { [alg]: cryptoKey });
@@ -42488,10 +42403,89 @@ var handleKeyObject4 = (keyObject, alg) => {
42488
42403
  return cryptoKey;
42489
42404
  };
42490
42405
  var init_normalize_key4 = __esm4(() => {
42491
- init_is_jwk4();
42492
42406
  init_base64url4();
42493
42407
  init_jwk_to_key4();
42494
42408
  });
42409
+ async function importJWK4(jwk, alg, options) {
42410
+ if (!isObject4(jwk)) {
42411
+ throw new TypeError("JWK must be an object");
42412
+ }
42413
+ let ext;
42414
+ alg ??= jwk.alg;
42415
+ ext ??= options?.extractable ?? jwk.ext;
42416
+ switch (jwk.kty) {
42417
+ case "oct":
42418
+ if (typeof jwk.k !== "string" || !jwk.k) {
42419
+ throw new TypeError('missing "k" (Key Value) Parameter value');
42420
+ }
42421
+ return decode4(jwk.k);
42422
+ case "RSA":
42423
+ if ("oth" in jwk && jwk.oth !== undefined) {
42424
+ throw new JOSENotSupported4('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
42425
+ }
42426
+ return jwkToKey4({ ...jwk, alg, ext });
42427
+ case "AKP": {
42428
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
42429
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
42430
+ }
42431
+ if (alg !== undefined && alg !== jwk.alg) {
42432
+ throw new TypeError("JWK alg and alg option value mismatch");
42433
+ }
42434
+ return jwkToKey4({ ...jwk, ext });
42435
+ }
42436
+ case "EC":
42437
+ case "OKP":
42438
+ return jwkToKey4({ ...jwk, alg, ext });
42439
+ default:
42440
+ throw new JOSENotSupported4('Unsupported "kty" (Key Type) Parameter value');
42441
+ }
42442
+ }
42443
+ var init_import4 = __esm4(() => {
42444
+ init_base64url4();
42445
+ init_jwk_to_key4();
42446
+ init_errors24();
42447
+ });
42448
+ function validateCrit4(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
42449
+ if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
42450
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
42451
+ }
42452
+ if (!protectedHeader || protectedHeader.crit === undefined) {
42453
+ return new Set;
42454
+ }
42455
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
42456
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
42457
+ }
42458
+ let recognized;
42459
+ if (recognizedOption !== undefined) {
42460
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
42461
+ } else {
42462
+ recognized = recognizedDefault;
42463
+ }
42464
+ for (const parameter of protectedHeader.crit) {
42465
+ if (!recognized.has(parameter)) {
42466
+ throw new JOSENotSupported4(`Extension Header Parameter "${parameter}" is not recognized`);
42467
+ }
42468
+ if (joseHeader[parameter] === undefined) {
42469
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
42470
+ }
42471
+ if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
42472
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
42473
+ }
42474
+ }
42475
+ return new Set(protectedHeader.crit);
42476
+ }
42477
+ var init_validate_crit4 = __esm4(() => {
42478
+ init_errors24();
42479
+ });
42480
+ function validateAlgorithms4(option, algorithms) {
42481
+ if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
42482
+ throw new TypeError(`"${option}" option must be an array of strings`);
42483
+ }
42484
+ if (!algorithms) {
42485
+ return;
42486
+ }
42487
+ return new Set(algorithms);
42488
+ }
42495
42489
  function checkKeyType4(alg, key, usage) {
42496
42490
  switch (alg.substring(0, 2)) {
42497
42491
  case "A1":
@@ -42610,67 +42604,7 @@ var asymmetricTypeCheck4 = (alg, key, usage) => {
42610
42604
  }
42611
42605
  }
42612
42606
  };
42613
- var init_check_key_type4 = __esm4(() => {
42614
- init_is_jwk4();
42615
- });
42616
- function subtleAlgorithm4(alg, algorithm) {
42617
- const hash = `SHA-${alg.slice(-3)}`;
42618
- switch (alg) {
42619
- case "HS256":
42620
- case "HS384":
42621
- case "HS512":
42622
- return { hash, name: "HMAC" };
42623
- case "PS256":
42624
- case "PS384":
42625
- case "PS512":
42626
- return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
42627
- case "RS256":
42628
- case "RS384":
42629
- case "RS512":
42630
- return { hash, name: "RSASSA-PKCS1-v1_5" };
42631
- case "ES256":
42632
- case "ES384":
42633
- case "ES512":
42634
- return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
42635
- case "Ed25519":
42636
- case "EdDSA":
42637
- return { name: "Ed25519" };
42638
- case "ML-DSA-44":
42639
- case "ML-DSA-65":
42640
- case "ML-DSA-87":
42641
- return { name: alg };
42642
- default:
42643
- throw new JOSENotSupported4(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
42644
- }
42645
- }
42646
- var init_subtle_dsa4 = __esm4(() => {
42647
- init_errors24();
42648
- });
42649
- async function getSigKey4(alg, key, usage) {
42650
- if (key instanceof Uint8Array) {
42651
- if (!alg.startsWith("HS")) {
42652
- throw new TypeError(invalidKeyInput4(key, "CryptoKey", "KeyObject", "JSON Web Key"));
42653
- }
42654
- return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
42655
- }
42656
- checkSigCryptoKey4(key, alg, usage);
42657
- return key;
42658
- }
42659
- var init_get_sign_verify_key4 = () => {};
42660
- async function verify4(alg, key, signature, data) {
42661
- const cryptoKey = await getSigKey4(alg, key, "verify");
42662
- checkKeyLength4(alg, cryptoKey);
42663
- const algorithm = subtleAlgorithm4(alg, cryptoKey.algorithm);
42664
- try {
42665
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
42666
- } catch {
42667
- return false;
42668
- }
42669
- }
42670
- var init_verify7 = __esm4(() => {
42671
- init_subtle_dsa4();
42672
- init_get_sign_verify_key4();
42673
- });
42607
+ var init_check_key_type4 = () => {};
42674
42608
  async function flattenedVerify4(jws, key, options) {
42675
42609
  if (!isObject4(jws)) {
42676
42610
  throw new JWSInvalid4("Flattened JWS must be an object");
@@ -42736,12 +42670,7 @@ async function flattenedVerify4(jws, key, options) {
42736
42670
  }
42737
42671
  checkKeyType4(alg, key, "verify");
42738
42672
  const data = concat4(jws.protected !== undefined ? encode4(jws.protected) : new Uint8Array, encode4("."), typeof jws.payload === "string" ? b64 ? encode4(jws.payload) : encoder4.encode(jws.payload) : jws.payload);
42739
- let signature;
42740
- try {
42741
- signature = decode4(jws.signature);
42742
- } catch {
42743
- throw new JWSInvalid4("Failed to base64url decode the signature");
42744
- }
42673
+ const signature = decodeBase64url4(jws.signature, "signature", JWSInvalid4);
42745
42674
  const k = await normalizeKey4(key, alg);
42746
42675
  const verified = await verify4(alg, k, signature, data);
42747
42676
  if (!verified) {
@@ -42749,11 +42678,7 @@ async function flattenedVerify4(jws, key, options) {
42749
42678
  }
42750
42679
  let payload;
42751
42680
  if (b64) {
42752
- try {
42753
- payload = decode4(jws.payload);
42754
- } catch {
42755
- throw new JWSInvalid4("Failed to base64url decode the payload");
42756
- }
42681
+ payload = decodeBase64url4(jws.payload, "payload", JWSInvalid4);
42757
42682
  } else if (typeof jws.payload === "string") {
42758
42683
  payload = encoder4.encode(jws.payload);
42759
42684
  } else {
@@ -42771,11 +42696,12 @@ async function flattenedVerify4(jws, key, options) {
42771
42696
  }
42772
42697
  return result;
42773
42698
  }
42774
- var init_verify24 = __esm4(() => {
42699
+ var init_verify6 = __esm4(() => {
42775
42700
  init_base64url4();
42776
- init_verify7();
42701
+ init_signing4();
42777
42702
  init_errors24();
42778
42703
  init_buffer_utils4();
42704
+ init_helpers4();
42779
42705
  init_check_key_type4();
42780
42706
  init_validate_crit4();
42781
42707
  init_normalize_key4();
@@ -42798,8 +42724,8 @@ async function compactVerify4(jws, key, options) {
42798
42724
  }
42799
42725
  return result;
42800
42726
  }
42801
- var init_verify34 = __esm4(() => {
42802
- init_verify24();
42727
+ var init_verify24 = __esm4(() => {
42728
+ init_verify6();
42803
42729
  init_errors24();
42804
42730
  init_buffer_utils4();
42805
42731
  });
@@ -43047,8 +42973,8 @@ async function jwtVerify4(jwt2, key, options) {
43047
42973
  }
43048
42974
  return result;
43049
42975
  }
43050
- var init_verify44 = __esm4(() => {
43051
- init_verify34();
42976
+ var init_verify34 = __esm4(() => {
42977
+ init_verify24();
43052
42978
  init_jwt_claims_set4();
43053
42979
  init_errors24();
43054
42980
  });
@@ -43331,14 +43257,14 @@ var init_remote4 = __esm4(() => {
43331
43257
  init_local4();
43332
43258
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
43333
43259
  const NAME = "jose";
43334
- const VERSION = "v6.1.3";
43260
+ const VERSION = "v6.2.1";
43335
43261
  USER_AGENT4 = `${NAME}/${VERSION}`;
43336
43262
  }
43337
43263
  customFetch4 = Symbol();
43338
43264
  jwksCache4 = Symbol();
43339
43265
  });
43340
43266
  var init_webapi4 = __esm4(() => {
43341
- init_verify44();
43267
+ init_verify34();
43342
43268
  init_local4();
43343
43269
  init_remote4();
43344
43270
  init_errors24();