@zuplo/cli 7.12.4 → 7.12.5

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.
Files changed (106) hide show
  1. package/node_modules/@modelcontextprotocol/client/node_modules/jose/README.md +2 -2
  2. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
  3. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
  4. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
  5. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
  6. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
  7. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
  8. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
  9. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
  10. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
  11. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
  12. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
  13. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
  14. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/decrypt.d.ts +7 -6
  15. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
  16. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
  17. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/unsecured.d.ts +1 -1
  18. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/verify.d.ts +3 -5
  19. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/key/export.d.ts +1 -1
  20. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
  21. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/key/import.d.ts +2 -2
  22. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/types.d.ts +165 -107
  23. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/util/decode_jwt.d.ts +2 -2
  24. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/util/errors.d.ts +1 -1
  25. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
  26. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
  27. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwks/local.js +2 -1
  28. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwks/remote.js +4 -4
  29. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
  30. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/general/verify.js +3 -3
  31. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/encrypt.js +2 -2
  32. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
  33. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
  34. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
  35. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
  36. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
  37. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
  38. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +14 -14
  39. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +3 -3
  40. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
  41. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
  42. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
  43. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +44 -43
  44. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key.js +4 -4
  45. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key_management.js +17 -17
  46. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/validate.js +10 -10
  47. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
  48. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
  49. package/node_modules/@modelcontextprotocol/client/node_modules/jose/package.json +1 -1
  50. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/README.md +2 -2
  51. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
  52. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
  53. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
  54. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
  55. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
  56. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
  57. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
  58. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
  59. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
  60. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
  61. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
  62. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
  63. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/decrypt.d.ts +7 -6
  64. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
  65. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
  66. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +1 -1
  67. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/verify.d.ts +3 -5
  68. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/export.d.ts +1 -1
  69. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
  70. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/import.d.ts +2 -2
  71. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/types.d.ts +165 -107
  72. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_jwt.d.ts +2 -2
  73. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/errors.d.ts +1 -1
  74. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
  75. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
  76. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +2 -1
  77. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +4 -4
  78. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
  79. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +3 -3
  80. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/encrypt.js +2 -2
  81. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
  82. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
  83. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
  84. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
  85. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
  86. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
  87. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +14 -14
  88. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +3 -3
  89. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
  90. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
  91. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
  92. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +44 -43
  93. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +4 -4
  94. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +17 -17
  95. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate.js +10 -10
  96. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
  97. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
  98. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +1 -1
  99. package/node_modules/@zuplo/core/customer.cli.minified.js +231 -231
  100. package/node_modules/@zuplo/core/index.minified.js +254 -254
  101. package/node_modules/@zuplo/core/package.json +1 -1
  102. package/node_modules/@zuplo/graphql/package.json +1 -1
  103. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  104. package/node_modules/@zuplo/otel/package.json +1 -1
  105. package/node_modules/@zuplo/runtime/package.json +1 -1
  106. package/package.json +11 -11
@@ -19,30 +19,30 @@ async function calculateJwkThumbprint(key, digestAlgorithm) {
19
19
  throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
20
20
  if (digestAlgorithm ??= "sha256", digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512")
21
21
  throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
22
- let components;
22
+ let requiredMembers;
23
23
  switch (jwk.kty) {
24
24
  case "AKP":
25
- check(jwk.alg, '"alg" (Algorithm) Parameter'), check(jwk.pub, '"pub" (Public key) Parameter'), components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
25
+ check(jwk.alg, '"alg" (Algorithm) Parameter'), check(jwk.pub, '"pub" (Public key) Parameter'), requiredMembers = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
26
26
  break;
27
27
  case "EC":
28
- check(jwk.crv, '"crv" (Curve) Parameter'), check(jwk.x, '"x" (X Coordinate) Parameter'), check(jwk.y, '"y" (Y Coordinate) Parameter'), components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
28
+ check(jwk.crv, '"crv" (Curve) Parameter'), check(jwk.x, '"x" (X Coordinate) Parameter'), check(jwk.y, '"y" (Y Coordinate) Parameter'), requiredMembers = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
29
29
  break;
30
30
  case "OKP":
31
- check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter'), check(jwk.x, '"x" (Public Key) Parameter'), components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
31
+ check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter'), check(jwk.x, '"x" (Public Key) Parameter'), requiredMembers = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
32
32
  break;
33
33
  case "RSA":
34
- check(jwk.e, '"e" (Exponent) Parameter'), check(jwk.n, '"n" (Modulus) Parameter'), components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
34
+ check(jwk.e, '"e" (Exponent) Parameter'), check(jwk.n, '"n" (Modulus) Parameter'), requiredMembers = { e: jwk.e, kty: jwk.kty, n: jwk.n };
35
35
  break;
36
36
  case "oct":
37
37
  if (typeof jwk.k != "string")
38
38
  throw new JWKInvalid('"k" (Key Value) Parameter missing or invalid');
39
- components = { k: jwk.k, kty: jwk.kty };
39
+ requiredMembers = { k: jwk.k, kty: jwk.kty };
40
40
  break;
41
41
  default:
42
42
  throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
43
43
  }
44
- const data = encode(JSON.stringify(components));
45
- return b64u(await digest(digestAlgorithm, data));
44
+ const thumbprintInput = encode(JSON.stringify(requiredMembers));
45
+ return b64u(await digest(digestAlgorithm, thumbprintInput));
46
46
  }
47
47
  async function calculateJwkThumbprintUri(key, digestAlgorithm) {
48
48
  digestAlgorithm ??= "sha256";
@@ -24,7 +24,8 @@ function createLocalJWKSet(jwks) {
24
24
  let snapshot;
25
25
  try {
26
26
  snapshot = structuredClone(jwks);
27
- } catch {
27
+ } catch (cause) {
28
+ throw new JWKSInvalid("JSON Web Key Set malformed", { cause });
28
29
  }
29
30
  if (!isJwkSet(snapshot))
30
31
  throw new JWKSInvalid("JSON Web Key Set malformed");
@@ -5,7 +5,7 @@ function isCloudflareWorkers() {
5
5
  return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
6
6
  }
7
7
  let USER_AGENT;
8
- (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.12");
8
+ (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.13");
9
9
  const customFetch = /* @__PURE__ */ Symbol();
10
10
  async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
11
11
  const response = await fetchImpl(url, {
@@ -14,14 +14,14 @@ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
14
14
  redirect: "manual",
15
15
  headers
16
16
  }).catch((err) => {
17
- throw err.name === "TimeoutError" ? new JWKSTimeout() : err;
17
+ throw err.name === "TimeoutError" ? new JWKSTimeout(void 0, { cause: err }) : err;
18
18
  });
19
19
  if (response.status !== 200)
20
20
  throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
21
21
  try {
22
22
  return await response.json();
23
- } catch {
24
- throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
23
+ } catch (cause) {
24
+ throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON", { cause });
25
25
  }
26
26
  }
27
27
  const jwksCache = /* @__PURE__ */ Symbol();
@@ -40,15 +40,15 @@ class GeneralSign {
40
40
  const jws = {
41
41
  signatures: [],
42
42
  payload: ""
43
- }, encoded = [];
43
+ }, encodedPayloadCache = [];
44
44
  let b64;
45
45
  for (const signature of this.#signatures) {
46
- const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...rest }, signatureB64] = await createSignature([this.#payload, protectedHeader, unprotectedHeader, crit, encoded], key);
46
+ const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...signatureMembers }, signatureB64] = await createSignature([this.#payload, protectedHeader, unprotectedHeader, crit, encodedPayloadCache], key);
47
47
  if (b64 === void 0)
48
48
  b64 = signatureB64, jws.payload = payload;
49
49
  else if (b64 !== signatureB64)
50
50
  throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
51
- jws.signatures.push(rest);
51
+ jws.signatures.push(signatureMembers);
52
52
  }
53
53
  return jws;
54
54
  }
@@ -31,9 +31,9 @@ async function generalVerify(jws, key, options) {
31
31
  throw new JWSSignatureVerificationFailed();
32
32
  }
33
33
  const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
34
- let modes = 0;
35
- for (const [, , mode] of candidates)
36
- if (modes |= mode, modes === 3)
34
+ let payloadEncodings = 0;
35
+ for (const [, , payloadEncoding] of candidates)
36
+ if (payloadEncodings |= payloadEncoding, payloadEncodings === 3)
37
37
  throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
38
38
  for (const candidate of candidates)
39
39
  try {
@@ -1,5 +1,5 @@
1
1
  import { compactJWE, createJWE } from "../lib/jwe_encrypt.js";
2
- import { JWTClaimsBuilder, jwtClaim, jwtData } from "../lib/jwt_claims_set.js";
2
+ import { JWTClaimsBuilder, jwtClaim, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
3
3
  import { assertNotSet } from "../lib/validate.js";
4
4
  const EncryptJWT_base = JWTClaimsBuilder;
5
5
  class EncryptJWT extends EncryptJWT_base {
@@ -29,7 +29,7 @@ class EncryptJWT extends EncryptJWT_base {
29
29
  return this.#replicateAudienceAsHeader = !0, this;
30
30
  }
31
31
  async encrypt(key, options) {
32
- const plaintext = jwtData(this);
32
+ const plaintext = jwtClaimsSetBytes(this);
33
33
  this.#input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader) && (this.#input[1] = {
34
34
  ...this.#input[1],
35
35
  iss: this.#replicateIssuerAsHeader ? jwtClaim(this, "iss") : void 0,
@@ -1,6 +1,6 @@
1
1
  import { createCompactSignature } from "../lib/jws_sign.js";
2
2
  import { JWTInvalid } from "../util/errors.js";
3
- import { JWTClaimsBuilder, jwtData } from "../lib/jwt_claims_set.js";
3
+ import { JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
4
4
  import { assertNotSet } from "../lib/validate.js";
5
5
  const SignJWT_base = JWTClaimsBuilder;
6
6
  class SignJWT extends SignJWT_base {
@@ -9,7 +9,7 @@ class SignJWT extends SignJWT_base {
9
9
  return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
10
10
  }
11
11
  async sign(key, options) {
12
- return createCompactSignature(jwtData(this), this.#protectedHeader, options?.crit, key, () => {
12
+ return createCompactSignature(jwtClaimsSetBytes(this), this.#protectedHeader, options?.crit, key, () => {
13
13
  throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
14
14
  });
15
15
  }
@@ -1,12 +1,12 @@
1
1
  import * as b64u from "../util/base64url.js";
2
2
  import { decodeBase64url, parseJoseHeader, JWS_RECOGNIZED, validateB64, validateCrit } from "../lib/validate.js";
3
3
  import { JWSInvalid, JWTInvalid } from "../util/errors.js";
4
- import { validateClaimsSet, JWTClaimsBuilder, jwtData } from "../lib/jwt_claims_set.js";
4
+ import { validateClaimsSet, JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
5
5
  const UnsecuredJWT_base = JWTClaimsBuilder;
6
6
  class UnsecuredJWT extends UnsecuredJWT_base {
7
7
  encode() {
8
- const header = b64u.encode(JSON.stringify({ alg: "none" })), payload = b64u.encode(jwtData(this));
9
- return `${header}.${payload}.`;
8
+ const encodedProtectedHeader = b64u.encode(JSON.stringify({ alg: "none" })), encodedPayload = b64u.encode(jwtClaimsSetBytes(this));
9
+ return `${encodedProtectedHeader}.${encodedPayload}.`;
10
10
  }
11
11
  static decode(jwt, options) {
12
12
  if (typeof jwt != "string")
@@ -2,12 +2,12 @@ import { unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
2
2
  import { validateExtractableOption } from "../lib/key.js";
3
3
  async function generateSecret(alg, options) {
4
4
  const extractable = validateExtractableOption(options?.extractable);
5
- let length, algorithm, keyUsages;
5
+ let keyLengthBits, algorithm, keyUsages;
6
6
  switch (alg) {
7
7
  case "HS256":
8
8
  case "HS384":
9
9
  case "HS512":
10
- length = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${length}`, length }, keyUsages = ["sign", "verify"];
10
+ keyLengthBits = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${keyLengthBits}`, length: keyLengthBits }, keyUsages = ["sign", "verify"];
11
11
  break;
12
12
  case "A128CBC-HS256":
13
13
  case "A192CBC-HS384":
@@ -16,7 +16,7 @@ async function generateSecret(alg, options) {
16
16
  case "A128KW":
17
17
  case "A192KW":
18
18
  case "A256KW":
19
- length = +alg.slice(1, 4), algorithm = { name: "AES-KW", length }, keyUsages = ["wrapKey", "unwrapKey"];
19
+ keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-KW", length: keyLengthBits }, keyUsages = ["wrapKey", "unwrapKey"];
20
20
  break;
21
21
  case "A128GCMKW":
22
22
  case "A192GCMKW":
@@ -24,7 +24,7 @@ async function generateSecret(alg, options) {
24
24
  case "A128GCM":
25
25
  case "A192GCM":
26
26
  case "A256GCM":
27
- length = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length }, keyUsages = ["encrypt", "decrypt"];
27
+ keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length: keyLengthBits }, keyUsages = ["encrypt", "decrypt"];
28
28
  break;
29
29
  default:
30
30
  unsupportedAlg(algArgument);
@@ -94,8 +94,8 @@ const parseECAlgorithmIdentifier = (state) => {
94
94
  try {
95
95
  const state = createASN1State(keyData);
96
96
  parseKeyHeader(state, keyFormat), algorithm = entry.resolve({ crv: parseECAlgorithmIdentifier(state) });
97
- } catch {
98
- throw new JOSENotSupported("Invalid or unsupported key format");
97
+ } catch (cause) {
98
+ throw new JOSENotSupported("Invalid or unsupported key format", { cause });
99
99
  }
100
100
  else
101
101
  algorithm = entry.subtle;
@@ -1,4 +1,4 @@
1
- const encoder = new TextEncoder(), decoder = new TextDecoder(), strictDecoder = new TextDecoder("utf-8", { fatal: !0 }), MAX_INT32 = 2 ** 32;
1
+ const encoder = new TextEncoder(), decoder = new TextDecoder(), strictDecoder = new TextDecoder("utf-8", { fatal: !0 }), UINT32_RANGE = 2 ** 32;
2
2
  function concat(...buffers) {
3
3
  const size = buffers.reduce((acc, { length }) => acc + length, 0), buf = new Uint8Array(size);
4
4
  let i = 0;
@@ -7,12 +7,12 @@ function concat(...buffers) {
7
7
  return buf;
8
8
  }
9
9
  function writeUInt32BE(buf, value, offset) {
10
- if (value < 0 || value >= MAX_INT32)
11
- throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
10
+ if (value < 0 || value >= UINT32_RANGE)
11
+ throw new RangeError(`value must be >= 0 and <= ${UINT32_RANGE - 1}. Received ${value}`);
12
12
  buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
13
13
  }
14
14
  function uint64be(value) {
15
- const high = Math.floor(value / MAX_INT32), low = value % MAX_INT32, buf = new Uint8Array(8);
15
+ const high = Math.floor(value / UINT32_RANGE), low = value % UINT32_RANGE, buf = new Uint8Array(8);
16
16
  return writeUInt32BE(buf, high, 0), writeUInt32BE(buf, low, 4), buf;
17
17
  }
18
18
  function uint32be(value) {
@@ -15,20 +15,20 @@ function checkIvLength(enc, iv) {
15
15
  async function cbcKeySetup(enc, cek, usage) {
16
16
  if (!(cek instanceof Uint8Array))
17
17
  throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
18
- const keySize = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", !1, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
19
- hash: `SHA-${keySize << 1}`,
18
+ const keyLengthBits = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keyLengthBits >> 3), "AES-CBC", !1, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keyLengthBits >> 3), {
19
+ hash: `SHA-${keyLengthBits << 1}`,
20
20
  name: "HMAC"
21
21
  }, !1, ["sign"]);
22
- return [encKey, macKey, keySize];
22
+ return [encKey, macKey, keyLengthBits];
23
23
  }
24
- async function cbcHmacTag(macKey, macData, keySize) {
25
- return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
24
+ async function cbcHmacTag(macKey, macData, keyLengthBits) {
25
+ return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keyLengthBits >> 3));
26
26
  }
27
27
  async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
28
- const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
28
+ const [encKey, macKey, keyLengthBits] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
29
29
  iv,
30
30
  name: "AES-CBC"
31
- }, encKey, plaintext)), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), tag = await cbcHmacTag(macKey, macData, keySize);
31
+ }, encKey, plaintext)), al = uint64be(aad.length * 8), macData = concat(aad, iv, ciphertext, al), tag = await cbcHmacTag(macKey, macData, keyLengthBits);
32
32
  return { ciphertext, tag, iv };
33
33
  }
34
34
  async function timingSafeEqual(a, b) {
@@ -36,7 +36,7 @@ async function timingSafeEqual(a, b) {
36
36
  return crypto.subtle.verify(algorithm, key, aHmac, b);
37
37
  }
38
38
  async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
39
- const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt"), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), expectedTag = await cbcHmacTag(macKey, macData, keySize);
39
+ const [encKey, macKey, keyLengthBits] = await cbcKeySetup(enc, cek, "decrypt"), al = uint64be(aad.length * 8), macData = concat(aad, iv, ciphertext, al), expectedTag = await cbcHmacTag(macKey, macData, keyLengthBits);
40
40
  try {
41
41
  if (await timingSafeEqual(tag, expectedTag))
42
42
  return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
@@ -1,5 +1,5 @@
1
1
  import { decrypt, generateCek } from "./content_encryption.js";
2
- import { decodeBase64url, encodeBase64url, parseJoseHeader, isDisjoint, isObject, validateCrit, validateAlgorithms, JWE_RECOGNIZED } from "./validate.js";
2
+ import { decodeBase64url, encodeAsciiMember, parseJoseHeader, isDisjoint, isObject, validateCrit, validateAlgorithms, JWE_RECOGNIZED } from "./validate.js";
3
3
  import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from "../util/errors.js";
4
4
  import { decryptKeyManagement } from "./key_management.js";
5
5
  import { decoder } from "./buffer_utils.js";
@@ -59,13 +59,13 @@ function checkRecipient(jwe) {
59
59
  }
60
60
  function shareJWE(jwe) {
61
61
  const { protected: encodedProtected, ciphertext, iv, tag, aad } = jwe;
62
- let parsedProt;
63
- return encodedProtected !== void 0 && (parsedProt = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid")), [
64
- parsedProt,
62
+ let protectedHeader;
63
+ return encodedProtected !== void 0 && (protectedHeader = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid")), [
64
+ protectedHeader,
65
65
  decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
66
66
  iv !== void 0 ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
67
67
  tag !== void 0 ? decodeBase64url(tag, "tag", JWEInvalid) : void 0,
68
- encodeBase64url((encodedProtected ?? "") + (aad !== void 0 ? `.${aad}` : ""), "aad", JWEInvalid)
68
+ encodeAsciiMember((encodedProtected ?? "") + (aad !== void 0 ? `.${aad}` : ""), "aad", JWEInvalid)
69
69
  ];
70
70
  }
71
71
  function prepareDecrypt(options) {
@@ -78,16 +78,16 @@ function prepareDecrypt(options) {
78
78
  ];
79
79
  }
80
80
  async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
81
- const [parsedProt, ciphertext, iv, tag, additionalData] = token, { header, unprotected, aad } = jwe;
81
+ const [protectedHeader, ciphertext, iv, tag, additionalAuthenticatedData] = token, { header, unprotected, aad } = jwe;
82
82
  let joseHeader;
83
83
  if (header !== void 0 || unprotected !== void 0) {
84
- if (!isDisjoint(parsedProt, header, unprotected))
84
+ if (!isDisjoint(protectedHeader, header, unprotected))
85
85
  throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
86
- joseHeader = { ...parsedProt, ...header, ...unprotected };
86
+ joseHeader = { ...protectedHeader, ...header, ...unprotected };
87
87
  } else
88
- joseHeader = parsedProt ?? {};
88
+ joseHeader = protectedHeader ?? {};
89
89
  const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared, { encrypted_key: encodedKey } = jwe;
90
- validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, parsedProt, joseHeader), validateZip(joseHeader, parsedProt);
90
+ validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, protectedHeader, joseHeader), validateZip(joseHeader, protectedHeader);
91
91
  const { alg, enc } = joseHeader;
92
92
  if (typeof alg != "string" || !alg)
93
93
  throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
@@ -122,13 +122,13 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
122
122
  encryptedKey = new Uint8Array();
123
123
  }
124
124
  let resolvedKey = !1;
125
- typeof key == "function" && (key = await key(parsedProt, jwe), resolvedKey = !0);
125
+ typeof key == "function" && (key = await key(protectedHeader, jwe), resolvedKey = !0);
126
126
  const algEntry = selected ?? jweAlgorithm(alg);
127
127
  isJWECEKTransport(algEntry) && encryptedKey === void 0 && (encryptedKey = new Uint8Array());
128
128
  const k = await prepareKey(algEntry.mode === "direct-encryption" ? encEntry : algEntry, key, "decrypt");
129
129
  let plaintext;
130
130
  if (algEntry.mode === "integrated-encryption")
131
- plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext, additionalData, parsedProt, joseHeader);
131
+ plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext, additionalAuthenticatedData, protectedHeader, joseHeader);
132
132
  else {
133
133
  const encryption = encEntry;
134
134
  let cek;
@@ -139,7 +139,7 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
139
139
  throw err;
140
140
  cek = generateCek(encryption);
141
141
  }
142
- plaintext = await decrypt(encryption, cek, ciphertext, iv, tag, additionalData);
142
+ plaintext = await decrypt(encryption, cek, ciphertext, iv, tag, additionalAuthenticatedData);
143
143
  }
144
144
  if (joseHeader.zip === "DEF") {
145
145
  const decompressionLimit = maxDecompressedLength ?? 25e4;
@@ -153,7 +153,7 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
153
153
  }
154
154
  return {
155
155
  plaintext,
156
- ...parsedProt && { protectedHeader: parsedProt },
156
+ ...protectedHeader && { protectedHeader },
157
157
  ...aad !== void 0 && {
158
158
  additionalAuthenticatedData: decodeBase64url(aad, "aad", JWEInvalid)
159
159
  },
@@ -48,17 +48,17 @@ async function encryptJWE(input, checked, key) {
48
48
  const algEntry = selected ?? jweAlgorithm(joseHeader.alg);
49
49
  let encryptedKey, parameters, cek;
50
50
  algEntry.mode === "integrated-encryption" ? cek = await prepareKey(algEntry, key, "encrypt") : [cek, encryptedKey, parameters] = await encryptKeyManagement(algEntry, encEntry, key, joseHeader, providedCek, keyManagementParameters), parameters && (unprotectedParameters ? unprotectedHeader = unprotectedHeader ? { ...unprotectedHeader, ...parameters } : parameters : protectedHeader = protectedHeader ? { ...protectedHeader, ...parameters } : parameters, checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader));
51
- const protectedHeaderS = protectedHeader ? b64u(JSON.stringify(protectedHeader)) : "", aadMember = aad?.byteLength ? b64u(aad) : void 0, additionalData = encode(aadMember ? `${protectedHeaderS}.${aadMember}` : protectedHeaderS);
51
+ const encodedProtectedHeader = protectedHeader ? b64u(JSON.stringify(protectedHeader)) : "", encodedAad = aad?.byteLength ? b64u(aad) : void 0, additionalAuthenticatedData = encode(encodedAad ? `${encodedProtectedHeader}.${encodedAad}` : encodedProtectedHeader);
52
52
  let plaintext = inputPlaintext;
53
53
  joseHeader.zip === "DEF" && (plaintext = await compress(plaintext).catch((cause) => {
54
54
  throw new JWEInvalid("Failed to compress plaintext", { cause });
55
55
  }));
56
56
  let ciphertext, tag, iv;
57
- algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext, additionalData, protectedHeader, joseHeader, keyManagementParameters) : { ciphertext, tag, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalData);
57
+ algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext, additionalAuthenticatedData, protectedHeader, joseHeader, keyManagementParameters) : { ciphertext, tag, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalAuthenticatedData);
58
58
  const jwe = {
59
59
  ciphertext: b64u(ciphertext)
60
60
  };
61
- return iv && (jwe.iv = b64u(iv)), tag && (jwe.tag = b64u(tag)), encryptedKey?.byteLength && (jwe.encrypted_key = b64u(encryptedKey)), aadMember && (jwe.aad = aadMember), protectedHeader && (jwe.protected = protectedHeaderS), sharedUnprotectedHeader && (jwe.unprotected = sharedUnprotectedHeader), unprotectedHeader && (jwe.header = unprotectedHeader), jwe;
61
+ return iv && (jwe.iv = b64u(iv)), tag && (jwe.tag = b64u(tag)), encryptedKey?.byteLength && (jwe.encrypted_key = b64u(encryptedKey)), encodedAad && (jwe.aad = encodedAad), protectedHeader && (jwe.protected = encodedProtectedHeader), sharedUnprotectedHeader && (jwe.unprotected = sharedUnprotectedHeader), unprotectedHeader && (jwe.header = unprotectedHeader), jwe;
62
62
  }
63
63
  async function createJWE(input, key, options) {
64
64
  return encryptJWE(input, checkEncryptHeaders(input, options), key);
@@ -34,8 +34,8 @@ function eddsa() {
34
34
  usages: sig
35
35
  };
36
36
  }
37
- function mldsa(bits) {
38
- const subtle = { name: `ML-DSA-${bits}` };
37
+ function mldsa(parameterSet) {
38
+ const subtle = { name: `ML-DSA-${parameterSet}` };
39
39
  return {
40
40
  kty: ["AKP"],
41
41
  subtle,
@@ -5,10 +5,10 @@ import { JWSInvalid } from "../util/errors.js";
5
5
  import { concat, encode, encoder } from "./buffer_utils.js";
6
6
  import { prepareKey, rawKey, checkModulusLength } from "./key.js";
7
7
  async function createSignature(input, key, rejectUnencoded) {
8
- let [payload, protectedHeader, unprotectedHeader, crit] = input, protectedHeaderString = "";
8
+ let [payload, protectedHeader, unprotectedHeader, crit] = input, encodedProtectedHeader = "";
9
9
  if (protectedHeader !== void 0) {
10
10
  const normalized = serializeJoseHeader(JWSInvalid, protectedHeader);
11
- protectedHeader = normalized[0], protectedHeaderString = b64u(normalized[1]);
11
+ protectedHeader = normalized[0], encodedProtectedHeader = b64u(normalized[1]);
12
12
  }
13
13
  if (unprotectedHeader !== void 0 && (unprotectedHeader = serializeJoseHeader(JWSInvalid, unprotectedHeader)[0]), !protectedHeader && !unprotectedHeader)
14
14
  throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
@@ -22,19 +22,19 @@ async function createSignature(input, key, rejectUnencoded) {
22
22
  if (typeof alg != "string" || !alg)
23
23
  throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
24
24
  const entry = jwsAlgorithm(alg);
25
- let payloadS = "", payloadB = payload, data;
25
+ let encodedPayload = "", signingPayload = payload, signingInput;
26
26
  if (b64) {
27
- const encoded = input[4];
28
- encoded ? (payloadS = encoded[0] ??= b64u(payload), payloadB = encoded[1] ??= encode(payloadS)) : (payloadS = b64u(payload), data = encoder.encode(`${protectedHeaderString}.${payloadS}`));
27
+ const encodedPayloadCache = input[4];
28
+ encodedPayloadCache ? (encodedPayload = encodedPayloadCache[0] ??= b64u(payload), signingPayload = encodedPayloadCache[1] ??= encode(encodedPayload)) : (encodedPayload = b64u(payload), signingInput = encoder.encode(`${encodedProtectedHeader}.${encodedPayload}`));
29
29
  }
30
- data ??= concat(encode(protectedHeaderString), encode("."), payloadB);
31
- const k = await rawKey(await prepareKey(entry, key, "sign"), entry.subtle, "sign");
32
- entry.minRsaBits && checkModulusLength(entry.alg, k);
30
+ signingInput ??= concat(encode(encodedProtectedHeader), encode("."), signingPayload);
31
+ const signingKey = await rawKey(await prepareKey(entry, key, "sign"), entry.subtle, "sign");
32
+ entry.minRsaBits && checkModulusLength(entry.alg, signingKey);
33
33
  const jws = {
34
- signature: b64u(new Uint8Array(await crypto.subtle.sign(entry.signing, k, data))),
35
- payload: payloadS
34
+ signature: b64u(new Uint8Array(await crypto.subtle.sign(entry.signing, signingKey, signingInput))),
35
+ payload: encodedPayload
36
36
  };
37
- return protectedHeader && (jws.protected = protectedHeaderString), unprotectedHeader && (jws.header = unprotectedHeader), [jws, b64];
37
+ return protectedHeader && (jws.protected = encodedProtectedHeader), unprotectedHeader && (jws.header = unprotectedHeader), [jws, b64];
38
38
  }
39
39
  async function createCompactSignature(payload, protectedHeader, crit, key, rejectUnencoded) {
40
40
  const [jws] = await createSignature([payload, protectedHeader, void 0, crit], key, rejectUnencoded);
@@ -1,16 +1,16 @@
1
1
  import { jwsAlgorithm } from "./jws_algorithms.js";
2
2
  import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from "../util/errors.js";
3
3
  import { concat, decoder, encoder, encode } from "./buffer_utils.js";
4
- import { decodeBase64url, encodeBase64url, parseJoseHeader, isDisjoint, isObject, validateB64, validateCrit, validateAlgorithms, JWS_RECOGNIZED } from "./validate.js";
4
+ import { decodeBase64url, encodeAsciiMember, parseJoseHeader, isDisjoint, isObject, validateB64, validateCrit, validateAlgorithms, JWS_RECOGNIZED } from "./validate.js";
5
5
  import { prepareKey, rawKey, checkModulusLength } from "./key.js";
6
6
  function snapshotJws(jws, sharedPayload) {
7
- const encodedProtected = jws.protected, inputHeader = jws.header, header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
7
+ const encodedProtectedHeader = jws.protected, inputHeader = jws.header, header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
8
8
  let payload = sharedPayload ? sharedPayload[0] : jws.payload;
9
9
  !sharedPayload && payload instanceof Uint8Array && (payload = new Uint8Array(payload));
10
10
  const signature = jws.signature, snapshot = { payload, signature };
11
- if (encodedProtected !== void 0 && (snapshot.protected = encodedProtected), inputHeader !== void 0 && (snapshot.header = header), encodedProtected === void 0 && header === void 0)
11
+ if (encodedProtectedHeader !== void 0 && (snapshot.protected = encodedProtectedHeader), inputHeader !== void 0 && (snapshot.header = header), encodedProtectedHeader === void 0 && header === void 0)
12
12
  throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
13
- if (encodedProtected !== void 0 && typeof encodedProtected != "string")
13
+ if (encodedProtectedHeader !== void 0 && typeof encodedProtectedHeader != "string")
14
14
  throw new JWSInvalid("JWS Protected Header incorrect type");
15
15
  if (payload === void 0)
16
16
  throw new JWSInvalid("JWS Payload missing");
@@ -23,8 +23,8 @@ function snapshotJws(jws, sharedPayload) {
23
23
  function prepareVerify(options) {
24
24
  return [options && validateAlgorithms("algorithms", options.algorithms), options?.crit];
25
25
  }
26
- function parseProtectedHeader(encodedProtected) {
27
- return encodedProtected === void 0 ? {} : parseJoseHeader(encodedProtected, JWSInvalid, "JWS Protected Header is invalid");
26
+ function parseProtectedHeader(encodedProtectedHeader) {
27
+ return encodedProtectedHeader === void 0 ? {} : parseJoseHeader(encodedProtectedHeader, JWSInvalid, "JWS Protected Header is invalid");
28
28
  }
29
29
  function encodeJsonUnencodedPayload(payload) {
30
30
  const invalid = /[\p{Cs}\p{Cn}]/u.exec(payload)?.[0];
@@ -35,15 +35,17 @@ function encodeJsonUnencodedPayload(payload) {
35
35
  function encodeCompactUnencodedPayload(payload) {
36
36
  try {
37
37
  return encode(payload);
38
- } catch {
39
- throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters");
38
+ } catch (cause) {
39
+ throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters", {
40
+ cause
41
+ });
40
42
  }
41
43
  }
42
44
  async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedProtected) {
43
- const { protected: encodedProtected, header, payload: inputPayload } = jws, parsedProt = parsedProtected ?? parseProtectedHeader(encodedProtected);
44
- if (!isDisjoint(parsedProt, header))
45
+ const { protected: encodedProtectedHeader, header, payload: inputPayload } = jws, protectedHeader = parsedProtected ?? parseProtectedHeader(encodedProtectedHeader);
46
+ if (!isDisjoint(protectedHeader, header))
45
47
  throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
46
- const joseHeader = { ...parsedProt, ...header }, b64 = validateB64(parsedProt, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], parsedProt, joseHeader)), { alg } = joseHeader;
48
+ const joseHeader = { ...protectedHeader, ...header }, b64 = validateB64(protectedHeader, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], protectedHeader, joseHeader)), { alg } = joseHeader;
47
49
  if (typeof alg != "string" || !alg)
48
50
  throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
49
51
  if (shared[0] && !shared[0].has(alg))
@@ -55,18 +57,19 @@ async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedP
55
57
  throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
56
58
  const signingPayload = b64 || typeof inputPayload != "string" ? inputPayload : encodeUnencodedPayload(inputPayload);
57
59
  let resolvedKey = !1;
58
- typeof key == "function" && (key = await key(parsedProt, jws), resolvedKey = !0);
59
- const entry = jwsAlgorithm(alg), data = concat(encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array(), encode("."), typeof signingPayload == "string" ? shared[2] ??= encodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload), signature = decodeBase64url(jws.signature, "signature", JWSInvalid), k = await prepareKey(entry, key, "verify"), cryptoKey = await rawKey(k, entry.subtle, "verify");
60
+ typeof key == "function" && (key = await key(protectedHeader, jws), resolvedKey = !0);
61
+ const entry = jwsAlgorithm(alg), signingInput = concat(encodedProtectedHeader !== void 0 ? encode(encodedProtectedHeader) : new Uint8Array(), encode("."), typeof signingPayload == "string" ? shared[2] ??= encodeAsciiMember(signingPayload, "payload", JWSInvalid) : signingPayload), signature = decodeBase64url(jws.signature, "signature", JWSInvalid), verificationKey = await prepareKey(entry, key, "verify"), cryptoKey = await rawKey(verificationKey, entry.subtle, "verify");
60
62
  entry.minRsaBits && checkModulusLength(entry.alg, cryptoKey);
61
63
  let verified = !1;
62
64
  try {
63
- verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
64
- } catch {
65
+ verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature, signingInput);
66
+ } catch (cause) {
67
+ throw new JWSSignatureVerificationFailed(void 0, { cause });
65
68
  }
66
69
  if (!verified)
67
70
  throw new JWSSignatureVerificationFailed();
68
71
  const result = { payload: typeof signingPayload == "string" ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload };
69
- return encodedProtected !== void 0 && (result.protectedHeader = parsedProt), header !== void 0 && (result.unprotectedHeader = header), resolvedKey ? [{ ...result, key: k }, b64] : [result, b64];
72
+ return encodedProtectedHeader !== void 0 && (result.protectedHeader = protectedHeader), header !== void 0 && (result.unprotectedHeader = header), resolvedKey ? [{ ...result, key: verificationKey }, b64] : [result, b64];
70
73
  }
71
74
  async function verifyCompact(jws, shared, key) {
72
75
  if (jws instanceof Uint8Array && (jws = decoder.decode(jws)), typeof jws != "string")