@coinbase/cdp-core 0.0.38 → 0.0.39

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 (87) hide show
  1. package/dist/esm/index.native100.js +115 -18
  2. package/dist/esm/index.native101.js +9 -117
  3. package/dist/esm/index.native104.js +18 -13
  4. package/dist/esm/index.native105.js +27 -35
  5. package/dist/esm/index.native106.js +7 -41
  6. package/dist/esm/index.native107.js +11 -18
  7. package/dist/esm/index.native108.js +13 -28
  8. package/dist/esm/index.native109.js +10 -8
  9. package/dist/esm/index.native110.js +17 -11
  10. package/dist/esm/index.native111.js +80 -12
  11. package/dist/esm/index.native112.js +13 -10
  12. package/dist/esm/index.native113.js +36 -17
  13. package/dist/esm/index.native114.js +40 -79
  14. package/dist/esm/index.native32.js +1 -1
  15. package/dist/esm/index.native83.js +6 -6
  16. package/dist/esm/index.native95.js +21 -10
  17. package/dist/esm/index.native96.js +10 -21
  18. package/dist/esm/index.native97.js +19 -9
  19. package/dist/esm/index.native98.js +89 -15
  20. package/dist/esm/index.native99.js +19 -92
  21. package/dist/esm/index.web100.js +73 -112
  22. package/dist/esm/index.web12.js +1 -1
  23. package/dist/esm/index.web24.js +940 -149
  24. package/dist/esm/index.web25.js +2 -48
  25. package/dist/esm/index.web26.js +43 -243
  26. package/dist/esm/index.web27.js +27 -55
  27. package/dist/esm/index.web28.js +149 -940
  28. package/dist/esm/index.web29.js +48 -2
  29. package/dist/esm/index.web30.js +243 -43
  30. package/dist/esm/index.web31.js +55 -27
  31. package/dist/esm/index.web59.js +1 -1
  32. package/dist/esm/index.web60.js +1 -1
  33. package/dist/esm/index.web7.js +4 -4
  34. package/dist/esm/index.web82.js +6 -6
  35. package/dist/esm/index.web87.js +21 -2
  36. package/dist/esm/index.web88.js +2 -21
  37. package/dist/esm/index.web91.js +1 -1
  38. package/dist/esm/index.web94.js +19 -77
  39. package/dist/esm/index.web95.js +10 -21
  40. package/dist/esm/index.web96.js +19 -9
  41. package/dist/esm/index.web97.js +89 -15
  42. package/dist/esm/index.web98.js +19 -92
  43. package/dist/esm/index.web99.js +115 -18
  44. package/dist/native/index.native100.js +115 -18
  45. package/dist/native/index.native101.js +9 -117
  46. package/dist/native/index.native104.js +18 -13
  47. package/dist/native/index.native105.js +27 -35
  48. package/dist/native/index.native106.js +7 -41
  49. package/dist/native/index.native107.js +11 -18
  50. package/dist/native/index.native108.js +13 -28
  51. package/dist/native/index.native109.js +10 -8
  52. package/dist/native/index.native110.js +17 -11
  53. package/dist/native/index.native111.js +80 -12
  54. package/dist/native/index.native112.js +13 -10
  55. package/dist/native/index.native113.js +36 -17
  56. package/dist/native/index.native114.js +40 -79
  57. package/dist/native/index.native32.js +1 -1
  58. package/dist/native/index.native83.js +6 -6
  59. package/dist/native/index.native95.js +21 -10
  60. package/dist/native/index.native96.js +10 -21
  61. package/dist/native/index.native97.js +19 -9
  62. package/dist/native/index.native98.js +89 -15
  63. package/dist/native/index.native99.js +19 -92
  64. package/dist/web/index.web100.js +73 -112
  65. package/dist/web/index.web12.js +1 -1
  66. package/dist/web/index.web24.js +940 -149
  67. package/dist/web/index.web25.js +2 -48
  68. package/dist/web/index.web26.js +43 -243
  69. package/dist/web/index.web27.js +27 -55
  70. package/dist/web/index.web28.js +149 -940
  71. package/dist/web/index.web29.js +48 -2
  72. package/dist/web/index.web30.js +243 -43
  73. package/dist/web/index.web31.js +55 -27
  74. package/dist/web/index.web59.js +1 -1
  75. package/dist/web/index.web60.js +1 -1
  76. package/dist/web/index.web7.js +4 -4
  77. package/dist/web/index.web82.js +6 -6
  78. package/dist/web/index.web87.js +21 -2
  79. package/dist/web/index.web88.js +2 -21
  80. package/dist/web/index.web91.js +1 -1
  81. package/dist/web/index.web94.js +19 -77
  82. package/dist/web/index.web95.js +10 -21
  83. package/dist/web/index.web96.js +19 -9
  84. package/dist/web/index.web97.js +89 -15
  85. package/dist/web/index.web98.js +19 -92
  86. package/dist/web/index.web99.js +115 -18
  87. package/package.json +2 -2
@@ -1,12 +1,15 @@
1
- function e(t) {
2
- return t?.[Symbol.toStringTag] === "CryptoKey";
3
- }
4
- function r(t) {
5
- return t?.[Symbol.toStringTag] === "KeyObject";
6
- }
7
- const n = (t) => e(t) || r(t);
1
+ const s = {
2
+ gasPriceOracle: { address: "0x420000000000000000000000000000000000000F" },
3
+ l1Block: { address: "0x4200000000000000000000000000000000000015" },
4
+ l2CrossDomainMessenger: {
5
+ address: "0x4200000000000000000000000000000000000007"
6
+ },
7
+ l2Erc721Bridge: { address: "0x4200000000000000000000000000000000000014" },
8
+ l2StandardBridge: { address: "0x4200000000000000000000000000000000000010" },
9
+ l2ToL1MessagePasser: {
10
+ address: "0x4200000000000000000000000000000000000016"
11
+ }
12
+ };
8
13
  export {
9
- n as default,
10
- e as isCryptoKey,
11
- r as isKeyObject
14
+ s as contracts
12
15
  };
@@ -1,19 +1,38 @@
1
- import n from "./index.native87.js";
2
- function r(t) {
3
- return n(t) && typeof t.kty == "string";
4
- }
5
- function o(t) {
6
- return t.kty !== "oct" && typeof t.d == "string";
7
- }
8
- function e(t) {
9
- return t.kty !== "oct" && typeof t.d > "u";
10
- }
11
- function c(t) {
12
- return t.kty === "oct" && typeof t.k == "string";
13
- }
1
+ import { hexToBigInt as n } from "./index.native56.js";
2
+ import { defineBlock as r } from "./index.native53.js";
3
+ import { defineTransaction as s, formatTransaction as m } from "./index.native55.js";
4
+ import { defineTransactionReceipt as l } from "./index.native58.js";
5
+ const p = {
6
+ block: /* @__PURE__ */ r({
7
+ format(e) {
8
+ return {
9
+ transactions: e.transactions?.map((t) => {
10
+ if (typeof t == "string")
11
+ return t;
12
+ const i = m(t);
13
+ return i.typeHex === "0x7e" && (i.isSystemTx = t.isSystemTx, i.mint = t.mint ? n(t.mint) : void 0, i.sourceHash = t.sourceHash, i.type = "deposit"), i;
14
+ }),
15
+ stateRoot: e.stateRoot
16
+ };
17
+ }
18
+ }),
19
+ transaction: /* @__PURE__ */ s({
20
+ format(e) {
21
+ const o = {};
22
+ return e.type === "0x7e" && (o.isSystemTx = e.isSystemTx, o.mint = e.mint ? n(e.mint) : void 0, o.sourceHash = e.sourceHash, o.type = "deposit"), o;
23
+ }
24
+ }),
25
+ transactionReceipt: /* @__PURE__ */ l({
26
+ format(e) {
27
+ return {
28
+ l1GasPrice: e.l1GasPrice ? n(e.l1GasPrice) : null,
29
+ l1GasUsed: e.l1GasUsed ? n(e.l1GasUsed) : null,
30
+ l1Fee: e.l1Fee ? n(e.l1Fee) : null,
31
+ l1FeeScalar: e.l1FeeScalar ? Number(e.l1FeeScalar) : null
32
+ };
33
+ }
34
+ })
35
+ };
14
36
  export {
15
- r as isJWK,
16
- o as isPrivateJWK,
17
- e as isPublicJWK,
18
- c as isSecretJWK
37
+ p as formatters
19
38
  };
@@ -1,83 +1,44 @@
1
- import { JOSENotSupported as s } from "./index.native34.js";
2
- function n(e) {
3
- let a, r;
4
- switch (e.kty) {
5
- case "RSA": {
6
- switch (e.alg) {
7
- case "PS256":
8
- case "PS384":
9
- case "PS512":
10
- a = { name: "RSA-PSS", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
11
- break;
12
- case "RS256":
13
- case "RS384":
14
- case "RS512":
15
- a = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
16
- break;
17
- case "RSA-OAEP":
18
- case "RSA-OAEP-256":
19
- case "RSA-OAEP-384":
20
- case "RSA-OAEP-512":
21
- a = {
22
- name: "RSA-OAEP",
23
- hash: `SHA-${parseInt(e.alg.slice(-3), 10) || 1}`
24
- }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
25
- break;
26
- default:
27
- throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
28
- }
29
- break;
30
- }
31
- case "EC": {
32
- switch (e.alg) {
33
- case "ES256":
34
- a = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
35
- break;
36
- case "ES384":
37
- a = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
38
- break;
39
- case "ES512":
40
- a = { name: "ECDSA", namedCurve: "P-521" }, r = e.d ? ["sign"] : ["verify"];
41
- break;
42
- case "ECDH-ES":
43
- case "ECDH-ES+A128KW":
44
- case "ECDH-ES+A192KW":
45
- case "ECDH-ES+A256KW":
46
- a = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
47
- break;
48
- default:
49
- throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
50
- }
51
- break;
52
- }
53
- case "OKP": {
54
- switch (e.alg) {
55
- case "Ed25519":
56
- case "EdDSA":
57
- a = { name: "Ed25519" }, r = e.d ? ["sign"] : ["verify"];
58
- break;
59
- case "ECDH-ES":
60
- case "ECDH-ES+A128KW":
61
- case "ECDH-ES+A192KW":
62
- case "ECDH-ES+A256KW":
63
- a = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
64
- break;
65
- default:
66
- throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
67
- }
68
- break;
69
- }
70
- default:
71
- throw new s('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
72
- }
73
- return { algorithm: a, keyUsages: r };
1
+ import { InvalidAddressError as a } from "./index.native71.js";
2
+ import { isAddress as f } from "./index.native45.js";
3
+ import { concatHex as p } from "./index.native46.js";
4
+ import { toHex as i } from "./index.native40.js";
5
+ import { toRlp as x } from "./index.native59.js";
6
+ import { serializeTransaction as l } from "./index.native20.js";
7
+ function T(r, e) {
8
+ return h(r) ? z(r) : l(r, e);
74
9
  }
75
- const i = async (e) => {
76
- if (!e.alg)
77
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
78
- const { algorithm: a, keyUsages: r } = n(e), t = { ...e };
79
- return delete t.alg, delete t.use, crypto.subtle.importKey("jwk", t, a, e.ext ?? !e.d, e.key_ops ?? r);
10
+ const E = {
11
+ transaction: T
80
12
  };
13
+ function z(r) {
14
+ w(r);
15
+ const { sourceHash: e, data: o, from: m, gas: t, isSystemTx: u, mint: s, to: c, value: n } = r, d = [
16
+ e,
17
+ m,
18
+ c ?? "0x",
19
+ s ? i(s) : "0x",
20
+ n ? i(n) : "0x",
21
+ t ? i(t) : "0x",
22
+ u ? "0x1" : "0x",
23
+ o ?? "0x"
24
+ ];
25
+ return p([
26
+ "0x7e",
27
+ x(d)
28
+ ]);
29
+ }
30
+ function h(r) {
31
+ return r.type === "deposit" || typeof r.sourceHash < "u";
32
+ }
33
+ function w(r) {
34
+ const { from: e, to: o } = r;
35
+ if (e && !f(e))
36
+ throw new a({ address: e });
37
+ if (o && !f(o))
38
+ throw new a({ address: o });
39
+ }
81
40
  export {
82
- i as default
41
+ w as assertTransactionDeposit,
42
+ T as serializeTransaction,
43
+ E as serializers
83
44
  };
@@ -1,4 +1,4 @@
1
- import { chainConfig as a } from "./index.native95.js";
1
+ import { chainConfig as a } from "./index.native101.js";
2
2
  import { defineChain as t } from "./index.native38.js";
3
3
  const e = 11155111, r = /* @__PURE__ */ t({
4
4
  ...a,
@@ -1,11 +1,11 @@
1
- import { encode as d } from "./index.native96.js";
2
- import y from "./index.native97.js";
3
- import b from "./index.native98.js";
1
+ import { encode as d } from "./index.native95.js";
2
+ import y from "./index.native96.js";
3
+ import b from "./index.native97.js";
4
4
  import { JWSInvalid as r } from "./index.native34.js";
5
5
  import { encoder as s, concat as u, decoder as h } from "./index.native84.js";
6
- import g from "./index.native99.js";
7
- import H from "./index.native100.js";
8
- import P from "./index.native101.js";
6
+ import g from "./index.native98.js";
7
+ import H from "./index.native99.js";
8
+ import P from "./index.native100.js";
9
9
  class x {
10
10
  #r;
11
11
  #e;
@@ -1,12 +1,23 @@
1
- import { contracts as o } from "./index.native104.js";
2
- import { formatters as r } from "./index.native105.js";
3
- import { serializers as t } from "./index.native106.js";
4
- const e = {
5
- blockTime: 2e3,
6
- contracts: o,
7
- formatters: r,
8
- serializers: t
9
- };
1
+ import { encoder as t, decoder as o } from "./index.native84.js";
2
+ import { encodeBase64 as c, decodeBase64 as a } from "./index.native104.js";
3
+ function i(r) {
4
+ if (Uint8Array.fromBase64)
5
+ return Uint8Array.fromBase64(typeof r == "string" ? r : o.decode(r), {
6
+ alphabet: "base64url"
7
+ });
8
+ let e = r;
9
+ e instanceof Uint8Array && (e = o.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
10
+ try {
11
+ return a(e);
12
+ } catch {
13
+ throw new TypeError("The input to be decoded is not correctly encoded.");
14
+ }
15
+ }
16
+ function p(r) {
17
+ let e = r;
18
+ return typeof e == "string" && (e = t.encode(e)), Uint8Array.prototype.toBase64 ? e.toBase64({ alphabet: "base64url", omitPadding: !0 }) : c(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
19
+ }
10
20
  export {
11
- e as chainConfig
21
+ i as decode,
22
+ p as encode
12
23
  };
@@ -1,23 +1,12 @@
1
- import { encoder as t, decoder as o } from "./index.native84.js";
2
- import { encodeBase64 as c, decodeBase64 as a } from "./index.native107.js";
3
- function i(r) {
4
- if (Uint8Array.fromBase64)
5
- return Uint8Array.fromBase64(typeof r == "string" ? r : o.decode(r), {
6
- alphabet: "base64url"
7
- });
8
- let e = r;
9
- e instanceof Uint8Array && (e = o.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
10
- try {
11
- return a(e);
12
- } catch {
13
- throw new TypeError("The input to be decoded is not correctly encoded.");
14
- }
15
- }
16
- function p(r) {
17
- let e = r;
18
- return typeof e == "string" && (e = t.encode(e)), Uint8Array.prototype.toBase64 ? e.toBase64({ alphabet: "base64url", omitPadding: !0 }) : c(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
19
- }
1
+ import n from "./index.native105.js";
2
+ import s from "./index.native106.js";
3
+ import a from "./index.native107.js";
4
+ const y = async (t, o, e) => {
5
+ const r = await a(t, o, "sign");
6
+ s(t, r);
7
+ const i = await crypto.subtle.sign(n(t, r.algorithm), r, e);
8
+ return new Uint8Array(i);
9
+ };
20
10
  export {
21
- i as decode,
22
- p as encode
11
+ y as default
23
12
  };
@@ -1,12 +1,22 @@
1
- import n from "./index.native108.js";
2
- import s from "./index.native109.js";
3
- import a from "./index.native110.js";
4
- const y = async (t, o, e) => {
5
- const r = await a(t, o, "sign");
6
- s(t, r);
7
- const i = await crypto.subtle.sign(n(t, r.algorithm), r, e);
8
- return new Uint8Array(i);
1
+ const a = (...o) => {
2
+ const t = o.filter(Boolean);
3
+ if (t.length === 0 || t.length === 1)
4
+ return !0;
5
+ let e;
6
+ for (const s of t) {
7
+ const r = Object.keys(s);
8
+ if (!e || e.size === 0) {
9
+ e = new Set(r);
10
+ continue;
11
+ }
12
+ for (const n of r) {
13
+ if (e.has(n))
14
+ return !1;
15
+ e.add(n);
16
+ }
17
+ }
18
+ return !0;
9
19
  };
10
20
  export {
11
- y as default
21
+ a as default
12
22
  };
@@ -1,22 +1,96 @@
1
- const a = (...o) => {
2
- const t = o.filter(Boolean);
3
- if (t.length === 0 || t.length === 1)
4
- return !0;
5
- let e;
6
- for (const s of t) {
7
- const r = Object.keys(s);
8
- if (!e || e.size === 0) {
9
- e = new Set(r);
10
- continue;
1
+ import { withAlg as n } from "./index.native108.js";
2
+ import c from "./index.native109.js";
3
+ import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index.native110.js";
4
+ const s = (r) => r?.[Symbol.toStringTag], o = (r, e, t) => {
5
+ if (e.use !== void 0) {
6
+ let i;
7
+ switch (t) {
8
+ case "sign":
9
+ case "verify":
10
+ i = "sig";
11
+ break;
12
+ case "encrypt":
13
+ case "decrypt":
14
+ i = "enc";
15
+ break;
11
16
  }
12
- for (const n of r) {
13
- if (e.has(n))
14
- return !1;
15
- e.add(n);
17
+ if (e.use !== i)
18
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
19
+ }
20
+ if (e.alg !== void 0 && e.alg !== r)
21
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);
22
+ if (Array.isArray(e.key_ops)) {
23
+ let i;
24
+ switch (!0) {
25
+ case t === "sign":
26
+ case r === "dir":
27
+ case r.includes("CBC-HS"):
28
+ i = t;
29
+ break;
30
+ case r.startsWith("PBES2"):
31
+ i = "deriveBits";
32
+ break;
33
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(r):
34
+ !r.includes("GCM") && r.endsWith("KW") ? i = "unwrapKey" : i = t;
35
+ break;
36
+ case t === "encrypt":
37
+ i = "wrapKey";
38
+ break;
39
+ case t === "decrypt":
40
+ i = r.startsWith("RSA") ? "unwrapKey" : "deriveBits";
41
+ break;
16
42
  }
43
+ if (i && e.key_ops?.includes?.(i) === !1)
44
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
17
45
  }
18
46
  return !0;
47
+ }, h = (r, e, t) => {
48
+ if (!(e instanceof Uint8Array)) {
49
+ if (p(e)) {
50
+ if (a(e) && o(r, e, t))
51
+ return;
52
+ throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
53
+ }
54
+ if (!c(e))
55
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
56
+ if (e.type !== "secret")
57
+ throw new TypeError(`${s(e)} instances for symmetric algorithms must be of type "secret"`);
58
+ }
59
+ }, m = (r, e, t) => {
60
+ if (p(e))
61
+ switch (t) {
62
+ case "decrypt":
63
+ case "sign":
64
+ if (f(e) && o(r, e, t))
65
+ return;
66
+ throw new TypeError("JSON Web Key for this operation be a private JWK");
67
+ case "encrypt":
68
+ case "verify":
69
+ if (y(e) && o(r, e, t))
70
+ return;
71
+ throw new TypeError("JSON Web Key for this operation be a public JWK");
72
+ }
73
+ if (!c(e))
74
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key"));
75
+ if (e.type === "secret")
76
+ throw new TypeError(`${s(e)} instances for asymmetric algorithms must not be of type "secret"`);
77
+ if (e.type === "public")
78
+ switch (t) {
79
+ case "sign":
80
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm signing must be of type "private"`);
81
+ case "decrypt":
82
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm decryption must be of type "private"`);
83
+ }
84
+ if (e.type === "private")
85
+ switch (t) {
86
+ case "verify":
87
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm verifying must be of type "public"`);
88
+ case "encrypt":
89
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm encryption must be of type "public"`);
90
+ }
91
+ }, d = (r, e, t) => {
92
+ r.startsWith("HS") || r === "dir" || r.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(r) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(r) ? h(r, e, t) : m(r, e, t);
19
93
  };
20
94
  export {
21
- a as default
95
+ d as default
22
96
  };
@@ -1,96 +1,23 @@
1
- import { withAlg as n } from "./index.native111.js";
2
- import c from "./index.native112.js";
3
- import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index.native113.js";
4
- const s = (r) => r?.[Symbol.toStringTag], o = (r, e, t) => {
5
- if (e.use !== void 0) {
6
- let i;
7
- switch (t) {
8
- case "sign":
9
- case "verify":
10
- i = "sig";
11
- break;
12
- case "encrypt":
13
- case "decrypt":
14
- i = "enc";
15
- break;
16
- }
17
- if (e.use !== i)
18
- throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
1
+ import { JOSENotSupported as f } from "./index.native34.js";
2
+ const w = (n, r, a, e, s) => {
3
+ if (s.crit !== void 0 && e?.crit === void 0)
4
+ throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');
5
+ if (!e || e.crit === void 0)
6
+ return /* @__PURE__ */ new Set();
7
+ if (!Array.isArray(e.crit) || e.crit.length === 0 || e.crit.some((i) => typeof i != "string" || i.length === 0))
8
+ throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
9
+ let t;
10
+ a !== void 0 ? t = new Map([...Object.entries(a), ...r.entries()]) : t = r;
11
+ for (const i of e.crit) {
12
+ if (!t.has(i))
13
+ throw new f(`Extension Header Parameter "${i}" is not recognized`);
14
+ if (s[i] === void 0)
15
+ throw new n(`Extension Header Parameter "${i}" is missing`);
16
+ if (t.get(i) && e[i] === void 0)
17
+ throw new n(`Extension Header Parameter "${i}" MUST be integrity protected`);
19
18
  }
20
- if (e.alg !== void 0 && e.alg !== r)
21
- throw new TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);
22
- if (Array.isArray(e.key_ops)) {
23
- let i;
24
- switch (!0) {
25
- case t === "sign":
26
- case r === "dir":
27
- case r.includes("CBC-HS"):
28
- i = t;
29
- break;
30
- case r.startsWith("PBES2"):
31
- i = "deriveBits";
32
- break;
33
- case /^A\d{3}(?:GCM)?(?:KW)?$/.test(r):
34
- !r.includes("GCM") && r.endsWith("KW") ? i = "unwrapKey" : i = t;
35
- break;
36
- case t === "encrypt":
37
- i = "wrapKey";
38
- break;
39
- case t === "decrypt":
40
- i = r.startsWith("RSA") ? "unwrapKey" : "deriveBits";
41
- break;
42
- }
43
- if (i && e.key_ops?.includes?.(i) === !1)
44
- throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
45
- }
46
- return !0;
47
- }, h = (r, e, t) => {
48
- if (!(e instanceof Uint8Array)) {
49
- if (p(e)) {
50
- if (a(e) && o(r, e, t))
51
- return;
52
- throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
53
- }
54
- if (!c(e))
55
- throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
56
- if (e.type !== "secret")
57
- throw new TypeError(`${s(e)} instances for symmetric algorithms must be of type "secret"`);
58
- }
59
- }, m = (r, e, t) => {
60
- if (p(e))
61
- switch (t) {
62
- case "decrypt":
63
- case "sign":
64
- if (f(e) && o(r, e, t))
65
- return;
66
- throw new TypeError("JSON Web Key for this operation be a private JWK");
67
- case "encrypt":
68
- case "verify":
69
- if (y(e) && o(r, e, t))
70
- return;
71
- throw new TypeError("JSON Web Key for this operation be a public JWK");
72
- }
73
- if (!c(e))
74
- throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key"));
75
- if (e.type === "secret")
76
- throw new TypeError(`${s(e)} instances for asymmetric algorithms must not be of type "secret"`);
77
- if (e.type === "public")
78
- switch (t) {
79
- case "sign":
80
- throw new TypeError(`${s(e)} instances for asymmetric algorithm signing must be of type "private"`);
81
- case "decrypt":
82
- throw new TypeError(`${s(e)} instances for asymmetric algorithm decryption must be of type "private"`);
83
- }
84
- if (e.type === "private")
85
- switch (t) {
86
- case "verify":
87
- throw new TypeError(`${s(e)} instances for asymmetric algorithm verifying must be of type "public"`);
88
- case "encrypt":
89
- throw new TypeError(`${s(e)} instances for asymmetric algorithm encryption must be of type "public"`);
90
- }
91
- }, d = (r, e, t) => {
92
- r.startsWith("HS") || r === "dir" || r.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(r) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(r) ? h(r, e, t) : m(r, e, t);
19
+ return new Set(e.crit);
93
20
  };
94
21
  export {
95
- d as default
22
+ w as default
96
23
  };