@coinbase/cdp-core 0.0.11 → 0.0.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.
Files changed (108) hide show
  1. package/README.md +24 -1
  2. package/dist/esm/index.js +19 -17
  3. package/dist/esm/index10.js +13 -115
  4. package/dist/esm/index100.js +11 -10
  5. package/dist/esm/index101.js +11 -15
  6. package/dist/esm/index102.js +9 -80
  7. package/dist/esm/index103.js +13 -75
  8. package/dist/esm/index104.js +83 -0
  9. package/dist/esm/index105.js +81 -0
  10. package/dist/esm/index11.js +117 -6
  11. package/dist/esm/index12.js +6 -16
  12. package/dist/esm/index13.js +16 -18
  13. package/dist/esm/index14.js +18 -172
  14. package/dist/esm/index15.js +170 -39
  15. package/dist/esm/index16.js +25 -16
  16. package/dist/esm/index17.js +40 -4
  17. package/dist/esm/index18.js +17 -5
  18. package/dist/esm/index19.js +4 -159
  19. package/dist/esm/index2.js +10 -10
  20. package/dist/esm/index20.js +5 -48
  21. package/dist/esm/index21.js +154 -140
  22. package/dist/esm/index22.js +47 -55
  23. package/dist/esm/index23.js +143 -6
  24. package/dist/esm/index24.js +56 -18
  25. package/dist/esm/index25.js +8 -45
  26. package/dist/esm/index26.js +17 -13
  27. package/dist/esm/index27.js +40 -50
  28. package/dist/esm/index28.js +13 -6
  29. package/dist/esm/index29.js +54 -20
  30. package/dist/esm/index3.js +4 -4
  31. package/dist/esm/index30.js +6 -11
  32. package/dist/esm/index31.js +21 -3
  33. package/dist/esm/index32.js +11 -3
  34. package/dist/esm/index33.js +3 -34
  35. package/dist/esm/index34.js +3 -12
  36. package/dist/esm/index35.js +34 -4
  37. package/dist/esm/index36.js +11 -27
  38. package/dist/esm/index37.js +4 -6
  39. package/dist/esm/index38.js +28 -24
  40. package/dist/esm/index39.js +6 -16
  41. package/dist/esm/index4.js +5 -4
  42. package/dist/esm/index40.js +22 -52
  43. package/dist/esm/index41.js +16 -23
  44. package/dist/esm/index42.js +53 -10
  45. package/dist/esm/index43.js +23 -27
  46. package/dist/esm/index44.js +9 -40
  47. package/dist/esm/index45.js +26 -54
  48. package/dist/esm/index46.js +42 -127
  49. package/dist/esm/index47.js +53 -10
  50. package/dist/esm/index48.js +125 -102
  51. package/dist/esm/index49.js +12 -6
  52. package/dist/esm/index5.js +92 -190
  53. package/dist/esm/index50.js +105 -3
  54. package/dist/esm/index51.js +6 -14
  55. package/dist/esm/index52.js +3 -43
  56. package/dist/esm/index53.js +14 -78
  57. package/dist/esm/index54.js +43 -2
  58. package/dist/esm/index55.js +79 -2
  59. package/dist/esm/index56.js +2 -13
  60. package/dist/esm/index57.js +2 -38
  61. package/dist/esm/index58.js +11 -5
  62. package/dist/esm/index59.js +32 -29
  63. package/dist/esm/index6.js +192 -12
  64. package/dist/esm/index60.js +6 -8
  65. package/dist/esm/index61.js +33 -9
  66. package/dist/esm/index62.js +8 -11
  67. package/dist/esm/index63.js +10 -13
  68. package/dist/esm/index64.js +11 -18
  69. package/dist/esm/index65.js +13 -5
  70. package/dist/esm/index66.js +19 -5
  71. package/dist/esm/index67.js +5 -10
  72. package/dist/esm/index68.js +5 -17
  73. package/dist/esm/index69.js +10 -22
  74. package/dist/esm/index7.js +12 -12
  75. package/dist/esm/index70.js +2 -51
  76. package/dist/esm/index71.js +21 -2
  77. package/dist/esm/index72.js +13 -17
  78. package/dist/esm/index73.js +21 -18
  79. package/dist/esm/index74.js +48 -77
  80. package/dist/esm/index75.js +18 -102
  81. package/dist/esm/index76.js +79 -32
  82. package/dist/esm/index77.js +103 -6
  83. package/dist/esm/index78.js +31 -53
  84. package/dist/esm/index79.js +6 -10
  85. package/dist/esm/index8.js +11 -20
  86. package/dist/esm/index80.js +79 -2
  87. package/dist/esm/index81.js +9 -44
  88. package/dist/esm/index82.js +54 -13
  89. package/dist/esm/index83.js +11 -10
  90. package/dist/esm/index84.js +2 -79
  91. package/dist/esm/index85.js +45 -5
  92. package/dist/esm/index86.js +13 -20
  93. package/dist/esm/index87.js +5 -10
  94. package/dist/esm/index88.js +11 -18
  95. package/dist/esm/index89.js +32 -90
  96. package/dist/esm/index9.js +20 -14
  97. package/dist/esm/index90.js +41 -20
  98. package/dist/esm/index91.js +20 -117
  99. package/dist/esm/index92.js +9 -12
  100. package/dist/esm/index93.js +17 -33
  101. package/dist/esm/index94.js +93 -41
  102. package/dist/esm/index95.js +21 -18
  103. package/dist/esm/index96.js +116 -26
  104. package/dist/esm/index97.js +18 -8
  105. package/dist/esm/index98.js +26 -9
  106. package/dist/esm/index99.js +8 -13
  107. package/dist/types/index.d.ts +4 -0
  108. package/package.json +2 -2
@@ -1,194 +1,96 @@
1
- import { logOutEndUser as c, refreshAccessToken as o, registerTemporaryWalletSecret as u } from "@coinbase/cdp-api-client";
2
- import { SignJWT as S } from "./index15.js";
3
- import { toAuthState as w } from "./index6.js";
4
- import { createKeyPair as f } from "./index16.js";
5
- import { generateRandomId as n } from "./index17.js";
6
- import { hash as d } from "./index18.js";
7
- import { sortKeys as y } from "./index12.js";
8
- const h = 60 * 1e3;
9
- class E {
10
- projectId;
11
- authState = null;
12
- walletSecret = null;
13
- authStateChangeCallbacks = [];
14
- initPromise = null;
15
- /**
16
- * Initializes the token manager.
17
- *
18
- * @param projectId - The project ID.
19
- */
20
- constructor(t) {
21
- this.projectId = t, this.initPromise = this._doInitialize();
22
- }
23
- /**
24
- * Gets the current user, or null if there is no user signed in.
25
- *
26
- * @returns The current user.
27
- */
28
- async getUser() {
29
- return this.authState?.user ?? null;
30
- }
31
- /**
32
- * Returns whether the user is signed in - i.e., whether there is an unexpired
33
- * access token and user.
34
- *
35
- * @returns True if the user is signed in, false otherwise.
36
- */
37
- async isSignedIn() {
38
- return this.authState ? Promise.resolve(this.authState.expiresAt > Date.now()) : Promise.resolve(!1);
39
- }
40
- /**
41
- * Signs out the user, clearing all authentication state.
42
- */
43
- async signOut() {
44
- try {
45
- await c(this.projectId);
46
- } catch {
47
- } finally {
48
- await this.clearAuthState();
1
+ import { getTypesForEIP712Domain as a } from "viem";
2
+ import { getCurrentUser as s, signEvmHash as i, signEvmTypedData as c, signEvmTransaction as u, signEvmMessage as m } from "./index2.js";
3
+ import { toAccount as g } from "./index16.js";
4
+ async function w(n) {
5
+ const r = await s();
6
+ if (!r || !r.evmAccounts || r.evmAccounts.length === 0)
7
+ throw new Error(
8
+ "No accounts found - user must be authenticated and have at least one EVM account"
9
+ );
10
+ if (!r.evmAccounts.includes(n))
11
+ throw new Error(`Cannot sign for address ${n} - not authorized for this account`);
12
+ return g({
13
+ address: n,
14
+ /**
15
+ * Signs a message using CDP's message signing functionality.
16
+ * Supports string messages, hex strings, and byte arrays.
17
+ *
18
+ * @param root0 - The parameters object
19
+ * @param root0.message - The message to sign, can be a string, hex string, or byte array
20
+ * @returns The signature as a hex string
21
+ */
22
+ async signMessage({ message: e }) {
23
+ let t;
24
+ if (typeof e == "string")
25
+ t = e;
26
+ else if ("raw" in e)
27
+ typeof e.raw == "string" ? t = e.raw : t = new TextDecoder().decode(e.raw);
28
+ else
29
+ throw new Error("Unsupported message format");
30
+ return (await m({
31
+ evmAccount: n,
32
+ message: t
33
+ })).signature;
34
+ },
35
+ /**
36
+ * Signs a transaction using CDP's transaction signing functionality.
37
+ * Converts Viem's transaction format to CDP's AllowedEvmTransactionType.
38
+ *
39
+ * @param transaction - The transaction to sign in Viem's format
40
+ * @returns The signature as a hex string
41
+ */
42
+ async signTransaction(e) {
43
+ const t = {
44
+ to: e.to,
45
+ value: e.value,
46
+ data: e.data,
47
+ nonce: e.nonce,
48
+ gas: e.gas,
49
+ chainId: e.chainId ?? 1
50
+ };
51
+ return e.gasPrice !== void 0 ? (t.maxFeePerGas = e.gasPrice, t.maxPriorityFeePerGas = e.gasPrice) : (t.maxFeePerGas = e.maxFeePerGas, t.maxPriorityFeePerGas = e.maxPriorityFeePerGas), (await u({
52
+ evmAccount: n,
53
+ transaction: t
54
+ })).signedTransaction;
55
+ },
56
+ /**
57
+ * Signs EIP-712 typed data using CDP's typed data signing functionality.
58
+ * Handles domain separation and type encoding according to the EIP-712 specification.
59
+ *
60
+ * @param params - The typed data parameters following the EIP-712 specification
61
+ * @returns The signature as a hex string
62
+ */
63
+ async signTypedData(e) {
64
+ const t = {
65
+ domain: e.domain,
66
+ types: {
67
+ EIP712Domain: a({
68
+ domain: e.domain
69
+ }),
70
+ ...e.types
71
+ },
72
+ primaryType: e.primaryType,
73
+ message: e.message
74
+ };
75
+ return (await c({
76
+ evmAccount: n,
77
+ typedData: t
78
+ })).signature;
79
+ },
80
+ /**
81
+ * Signs a raw message hash using CDP's message signing functionality.
82
+ *
83
+ * @param message - The message hash to sign
84
+ * @returns The signature as a hex string
85
+ */
86
+ async sign(e) {
87
+ return (await i({
88
+ evmAccount: n,
89
+ hash: e.hash
90
+ })).signature;
49
91
  }
50
- }
51
- /**
52
- * Adds a callback to be called when the auth state changes.
53
- *
54
- * @param callback - The function to call when the auth state changes.
55
- */
56
- addAuthStateChangeCallback(t) {
57
- this.authStateChangeCallbacks.push(t), t(this.authState?.user ?? null);
58
- }
59
- /**
60
- * Gets the access token, refreshing it if it is expired. Returns null if the user is not
61
- * signed in.
62
- *
63
- * @returns The access token.
64
- */
65
- async getToken() {
66
- return this.shouldRefreshToken() && await this.refreshAccessToken(), this.authState?.accessToken ?? null;
67
- }
68
- /**
69
- * Gets the currently registered wallet secret ID. Rejects if the user is not signed in.
70
- *
71
- * @param authState - The auth state to use. If not provided, the current auth state will be used.
72
- *
73
- * @returns The wallet secret ID.
74
- */
75
- async getWalletSecretId(t) {
76
- return this.shouldRefreshWalletSecret() && await this.refreshWalletSecret(t), this.walletSecret.walletSecretId;
77
- }
78
- /**
79
- * Gets the X-Wallet-Auth header. Rejects if the user is not signed in.
80
- *
81
- * @param options - The options for the request.
82
- * @param options.requestMethod - The HTTP method of the request.
83
- * @param options.requestHost - The host of the request.
84
- * @param options.requestPath - The path of the request.
85
- * @param options.requestData - The data of the request.
86
- * @returns The X-Wallet-Auth header.
87
- */
88
- async getXWalletAuth(t) {
89
- this.shouldRefreshWalletSecret() && await this.refreshWalletSecret();
90
- const e = `${t.requestMethod} ${t.requestHost}${t.requestPath}`, a = Math.floor(Date.now() / 1e3), r = {
91
- uris: [e]
92
- };
93
- if (t.requestData && Object.keys(t.requestData).length > 0) {
94
- const s = y(t.requestData);
95
- r.reqHash = await d(new TextEncoder().encode(JSON.stringify(s)));
96
- }
97
- return await new S(r).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(a).setNotBefore(a).setJti(await n()).sign(this.walletSecret.keyPair.privateKey);
98
- }
99
- /**
100
- * Sets the authentication state.
101
- *
102
- * @param authState - The authentication state.
103
- */
104
- async setAuthState(t) {
105
- this.authState = t, this.authStateChangeCallbacks.forEach((e) => e(this.authState?.user ?? null));
106
- }
107
- /**
108
- * Clears the authentication state.
109
- */
110
- async clearAuthState() {
111
- this.authState = null, this.walletSecret = null, this.authStateChangeCallbacks.forEach((t) => t(null));
112
- }
113
- /**
114
- * Ensures the AuthManager is initialized before proceeding.
115
- * If initialization is already in progress, waits for it to complete.
116
- */
117
- async ensureInitialized() {
118
- if (this.initPromise) {
119
- await this.initPromise;
120
- return;
121
- }
122
- throw new Error("AuthManager not initialized");
123
- }
124
- /**
125
- * Internal async initialization logic.
126
- */
127
- async _doInitialize() {
128
- try {
129
- await this.refreshAccessToken();
130
- } catch (t) {
131
- console.warn("Failed to refresh access token during initialization:", t);
132
- }
133
- }
134
- /**
135
- * Returns whether the token should be refreshed.
136
- *
137
- * @returns True if the token should be refreshed, false otherwise.
138
- */
139
- shouldRefreshToken() {
140
- return !(this.authState && this.authState.expiresAt > Date.now() + h);
141
- }
142
- /**
143
- * Refreshes the access token and transitions the auth state accordingly.
144
- * If a refresh is already in progress, it will wait for that refresh to complete.
145
- *
146
- * @returns The new access token.
147
- */
148
- async refreshAccessToken() {
149
- try {
150
- const t = await o(this.projectId, {
151
- grantType: "refresh_token"
152
- }), e = w(
153
- t.accessToken,
154
- t.validUntil,
155
- t.endUser
156
- );
157
- await this.setAuthState(e);
158
- } catch {
159
- await this.clearAuthState();
160
- }
161
- }
162
- /**
163
- * Returns whether the wallet secret should be refreshed.
164
- *
165
- * @returns True if the wallet secret should be refreshed, false otherwise.
166
- */
167
- shouldRefreshWalletSecret() {
168
- return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() + h);
169
- }
170
- /**
171
- * Refreshes the wallet secret.
172
- *
173
- * @param authState - The auth state to use. If not provided, the current auth state will be used.
174
- * @returns The wallet secret.
175
- */
176
- async refreshWalletSecret(t) {
177
- if (!t && !await this.isSignedIn())
178
- throw new Error("Cannot refresh wallet secret if the auth state is not present or expired");
179
- const e = t ?? this.authState, a = this.walletSecret?.walletSecretId ?? await n(), r = this.walletSecret?.keyPair ?? await f(), s = e.expiresAt, l = new Date(s).toISOString();
180
- this.walletSecret = { walletSecretId: a, keyPair: r, expiresAt: s };
181
- try {
182
- await u(this.projectId, e.user.userId, {
183
- walletSecretId: a,
184
- publicKey: r.publicKeyBase64,
185
- validUntil: l
186
- });
187
- } catch (i) {
188
- throw this.walletSecret = null, i;
189
- }
190
- }
92
+ });
191
93
  }
192
94
  export {
193
- E as AuthManager
95
+ w as toViemAccount
194
96
  };
@@ -1,5 +1,107 @@
1
- import { sha256 as s } from "./index75.js";
2
- const o = s;
1
+ import { split as L, rotlSH as T, rotlSL as S, rotlBH as m, rotlBL as F } from "./index75.js";
2
+ import { createHasher as X, Hash as E, anumber as d, u32 as U, swap32IfBE as I, aexists as x, toBytes as P, abytes as k, aoutput as M, clean as y } from "./index76.js";
3
+ const R = BigInt(0), f = BigInt(1), j = BigInt(2), q = BigInt(7), v = BigInt(256), z = BigInt(113), _ = [], g = [], B = [];
4
+ for (let n = 0, t = f, s = 1, i = 0; n < 24; n++) {
5
+ [s, i] = [i, (2 * s + 3 * i) % 5], _.push(2 * (5 * i + s)), g.push((n + 1) * (n + 2) / 2 % 64);
6
+ let o = R;
7
+ for (let r = 0; r < 7; r++)
8
+ t = (t << f ^ (t >> q) * z) % v, t & j && (o ^= f << (f << /* @__PURE__ */ BigInt(r)) - f);
9
+ B.push(o);
10
+ }
11
+ const A = L(B, !0), C = A[0], D = A[1], O = (n, t, s) => s > 32 ? m(n, t, s) : T(n, t, s), w = (n, t, s) => s > 32 ? F(n, t, s) : S(n, t, s);
12
+ function G(n, t = 24) {
13
+ const s = new Uint32Array(10);
14
+ for (let i = 24 - t; i < 24; i++) {
15
+ for (let e = 0; e < 10; e++)
16
+ s[e] = n[e] ^ n[e + 10] ^ n[e + 20] ^ n[e + 30] ^ n[e + 40];
17
+ for (let e = 0; e < 10; e += 2) {
18
+ const h = (e + 8) % 10, l = (e + 2) % 10, u = s[l], c = s[l + 1], b = O(u, c, 1) ^ s[h], H = w(u, c, 1) ^ s[h + 1];
19
+ for (let a = 0; a < 50; a += 10)
20
+ n[e + a] ^= b, n[e + a + 1] ^= H;
21
+ }
22
+ let o = n[2], r = n[3];
23
+ for (let e = 0; e < 24; e++) {
24
+ const h = g[e], l = O(o, r, h), u = w(o, r, h), c = _[e];
25
+ o = n[c], r = n[c + 1], n[c] = l, n[c + 1] = u;
26
+ }
27
+ for (let e = 0; e < 50; e += 10) {
28
+ for (let h = 0; h < 10; h++)
29
+ s[h] = n[e + h];
30
+ for (let h = 0; h < 10; h++)
31
+ n[e + h] ^= ~s[(h + 2) % 10] & s[(h + 4) % 10];
32
+ }
33
+ n[0] ^= C[i], n[1] ^= D[i];
34
+ }
35
+ y(s);
36
+ }
37
+ class p extends E {
38
+ // NOTE: we accept arguments in bytes instead of bits here.
39
+ constructor(t, s, i, o = !1, r = 24) {
40
+ if (super(), this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, this.enableXOF = !1, this.blockLen = t, this.suffix = s, this.outputLen = i, this.enableXOF = o, this.rounds = r, d(i), !(0 < t && t < 200))
41
+ throw new Error("only keccak-f1600 function is supported");
42
+ this.state = new Uint8Array(200), this.state32 = U(this.state);
43
+ }
44
+ clone() {
45
+ return this._cloneInto();
46
+ }
47
+ keccak() {
48
+ I(this.state32), G(this.state32, this.rounds), I(this.state32), this.posOut = 0, this.pos = 0;
49
+ }
50
+ update(t) {
51
+ x(this), t = P(t), k(t);
52
+ const { blockLen: s, state: i } = this, o = t.length;
53
+ for (let r = 0; r < o; ) {
54
+ const e = Math.min(s - this.pos, o - r);
55
+ for (let h = 0; h < e; h++)
56
+ i[this.pos++] ^= t[r++];
57
+ this.pos === s && this.keccak();
58
+ }
59
+ return this;
60
+ }
61
+ finish() {
62
+ if (this.finished)
63
+ return;
64
+ this.finished = !0;
65
+ const { state: t, suffix: s, pos: i, blockLen: o } = this;
66
+ t[i] ^= s, (s & 128) !== 0 && i === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
67
+ }
68
+ writeInto(t) {
69
+ x(this, !1), k(t), this.finish();
70
+ const s = this.state, { blockLen: i } = this;
71
+ for (let o = 0, r = t.length; o < r; ) {
72
+ this.posOut >= i && this.keccak();
73
+ const e = Math.min(i - this.posOut, r - o);
74
+ t.set(s.subarray(this.posOut, this.posOut + e), o), this.posOut += e, o += e;
75
+ }
76
+ return t;
77
+ }
78
+ xofInto(t) {
79
+ if (!this.enableXOF)
80
+ throw new Error("XOF is not possible for this instance");
81
+ return this.writeInto(t);
82
+ }
83
+ xof(t) {
84
+ return d(t), this.xofInto(new Uint8Array(t));
85
+ }
86
+ digestInto(t) {
87
+ if (M(t, this), this.finished)
88
+ throw new Error("digest() was already called");
89
+ return this.writeInto(t), this.destroy(), t;
90
+ }
91
+ digest() {
92
+ return this.digestInto(new Uint8Array(this.outputLen));
93
+ }
94
+ destroy() {
95
+ this.destroyed = !0, y(this.state);
96
+ }
97
+ _cloneInto(t) {
98
+ const { blockLen: s, suffix: i, outputLen: o, rounds: r, enableXOF: e } = this;
99
+ return t || (t = new p(s, i, o, e, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = i, t.outputLen = o, t.enableXOF = e, t.destroyed = this.destroyed, t;
100
+ }
101
+ }
102
+ const J = (n, t, s) => X(() => new p(t, n, s)), Q = J(1, 136, 256 / 8);
3
103
  export {
4
- o as sha256
104
+ p as Keccak,
105
+ G as keccakP,
106
+ Q as keccak_256
5
107
  };
@@ -1,17 +1,9 @@
1
- import { InvalidSerializableTransactionError as f } from "./index52.js";
2
- function d(e) {
3
- if (e.type)
4
- return e.type;
5
- if (typeof e.authorizationList < "u")
6
- return "eip7702";
7
- if (typeof e.blobs < "u" || typeof e.blobVersionedHashes < "u" || typeof e.maxFeePerBlobGas < "u" || typeof e.sidecars < "u")
8
- return "eip4844";
9
- if (typeof e.maxFeePerGas < "u" || typeof e.maxPriorityFeePerGas < "u")
10
- return "eip1559";
11
- if (typeof e.gasPrice < "u")
12
- return typeof e.accessList < "u" ? "eip2930" : "legacy";
13
- throw new f({ transaction: e });
1
+ import { sha256 as o } from "./index52.js";
2
+ import { isHex as s } from "./index34.js";
3
+ import { toBytes as r } from "./index29.js";
4
+ function p(t, i) {
5
+ return o(s(t, { strict: !1 }) ? r(t) : t);
14
6
  }
15
7
  export {
16
- d as getTransactionType
8
+ p as sha256
17
9
  };
@@ -1,45 +1,5 @@
1
- import { BaseError as t } from "./index45.js";
2
- function i(n) {
3
- const r = Object.entries(n).map(([a, e]) => e === void 0 || e === !1 ? null : [a, e]).filter(Boolean), o = r.reduce((a, [e]) => Math.max(a, e.length), 0);
4
- return r.map(([a, e]) => ` ${`${a}:`.padEnd(o + 1)} ${e}`).join(`
5
- `);
6
- }
7
- class c extends t {
8
- constructor({ v: r }) {
9
- super(`Invalid \`v\` value "${r}". Expected 27 or 28.`, {
10
- name: "InvalidLegacyVError"
11
- });
12
- }
13
- }
14
- class d extends t {
15
- constructor({ transaction: r }) {
16
- super("Cannot infer a transaction type from provided transaction.", {
17
- metaMessages: [
18
- "Provided Transaction:",
19
- "{",
20
- i(r),
21
- "}",
22
- "",
23
- "To infer the type, either provide:",
24
- "- a `type` to the Transaction, or",
25
- "- an EIP-1559 Transaction with `maxFeePerGas`, or",
26
- "- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
27
- "- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or",
28
- "- an EIP-7702 Transaction with `authorizationList`, or",
29
- "- a Legacy Transaction with `gasPrice`"
30
- ],
31
- name: "InvalidSerializableTransactionError"
32
- });
33
- }
34
- }
35
- class l extends t {
36
- constructor({ storageKey: r }) {
37
- super(`Size for storage key "${r}" is invalid. Expected 32 bytes. Got ${Math.floor((r.length - 2) / 2)} bytes.`, { name: "InvalidStorageKeySizeError" });
38
- }
39
- }
1
+ import { sha256 as s } from "./index77.js";
2
+ const o = s;
40
3
  export {
41
- c as InvalidLegacyVError,
42
- d as InvalidSerializableTransactionError,
43
- l as InvalidStorageKeySizeError,
44
- i as prettyPrint
4
+ o as sha256
45
5
  };
@@ -1,81 +1,17 @@
1
- import { versionedHashVersionKzg as c } from "./index54.js";
2
- import { maxUint256 as m } from "./index55.js";
3
- import { InvalidAddressError as s } from "./index56.js";
4
- import { BaseError as h } from "./index45.js";
5
- import { EmptyBlobError as P, InvalidVersionedHashSizeError as p, InvalidVersionedHashVersionError as x } from "./index57.js";
6
- import { InvalidChainIdError as n } from "./index58.js";
7
- import { FeeCapTooHighError as w, TipAboveFeeCapError as E } from "./index59.js";
8
- import { isAddress as f } from "./index30.js";
9
- import { size as F } from "./index35.js";
10
- import { slice as I } from "./index36.js";
11
- import { hexToNumber as G } from "./index41.js";
12
- function C(t) {
13
- const { authorizationList: e } = t;
14
- if (e)
15
- for (const o of e) {
16
- const { chainId: r } = o, i = o.address;
17
- if (!f(i))
18
- throw new s({ address: i });
19
- if (r < 0)
20
- throw new n({ chainId: r });
21
- }
22
- d(t);
23
- }
24
- function L(t) {
25
- const { blobVersionedHashes: e } = t;
26
- if (e) {
27
- if (e.length === 0)
28
- throw new P();
29
- for (const o of e) {
30
- const r = F(o), i = G(I(o, 0, 1));
31
- if (r !== 32)
32
- throw new p({ hash: o, size: r });
33
- if (i !== c)
34
- throw new x({
35
- hash: o,
36
- version: i
37
- });
38
- }
39
- }
40
- d(t);
41
- }
42
- function d(t) {
43
- const { chainId: e, maxPriorityFeePerGas: o, maxFeePerGas: r, to: i } = t;
44
- if (e <= 0)
45
- throw new n({ chainId: e });
46
- if (i && !f(i))
47
- throw new s({ address: i });
48
- if (r && r > m)
49
- throw new w({ maxFeePerGas: r });
50
- if (o && r && o > r)
51
- throw new E({ maxFeePerGas: r, maxPriorityFeePerGas: o });
52
- }
53
- function B(t) {
54
- const { chainId: e, maxPriorityFeePerGas: o, gasPrice: r, maxFeePerGas: i, to: a } = t;
55
- if (e <= 0)
56
- throw new n({ chainId: e });
57
- if (a && !f(a))
58
- throw new s({ address: a });
59
- if (o || i)
60
- throw new h("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");
61
- if (r && r > m)
62
- throw new w({ maxFeePerGas: r });
63
- }
64
- function K(t) {
65
- const { chainId: e, maxPriorityFeePerGas: o, gasPrice: r, maxFeePerGas: i, to: a } = t;
66
- if (a && !f(a))
67
- throw new s({ address: a });
68
- if (typeof e < "u" && e <= 0)
69
- throw new n({ chainId: e });
70
- if (o || i)
71
- throw new h("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");
72
- if (r && r > m)
73
- throw new w({ maxFeePerGas: r });
1
+ import { InvalidSerializableTransactionError as f } from "./index54.js";
2
+ function d(e) {
3
+ if (e.type)
4
+ return e.type;
5
+ if (typeof e.authorizationList < "u")
6
+ return "eip7702";
7
+ if (typeof e.blobs < "u" || typeof e.blobVersionedHashes < "u" || typeof e.maxFeePerBlobGas < "u" || typeof e.sidecars < "u")
8
+ return "eip4844";
9
+ if (typeof e.maxFeePerGas < "u" || typeof e.maxPriorityFeePerGas < "u")
10
+ return "eip1559";
11
+ if (typeof e.gasPrice < "u")
12
+ return typeof e.accessList < "u" ? "eip2930" : "legacy";
13
+ throw new f({ transaction: e });
74
14
  }
75
15
  export {
76
- d as assertTransactionEIP1559,
77
- B as assertTransactionEIP2930,
78
- L as assertTransactionEIP4844,
79
- C as assertTransactionEIP7702,
80
- K as assertTransactionLegacy
16
+ d as getTransactionType
81
17
  };
@@ -1,4 +1,45 @@
1
- const e = 1;
1
+ import { BaseError as t } from "./index47.js";
2
+ function i(n) {
3
+ const r = Object.entries(n).map(([a, e]) => e === void 0 || e === !1 ? null : [a, e]).filter(Boolean), o = r.reduce((a, [e]) => Math.max(a, e.length), 0);
4
+ return r.map(([a, e]) => ` ${`${a}:`.padEnd(o + 1)} ${e}`).join(`
5
+ `);
6
+ }
7
+ class c extends t {
8
+ constructor({ v: r }) {
9
+ super(`Invalid \`v\` value "${r}". Expected 27 or 28.`, {
10
+ name: "InvalidLegacyVError"
11
+ });
12
+ }
13
+ }
14
+ class d extends t {
15
+ constructor({ transaction: r }) {
16
+ super("Cannot infer a transaction type from provided transaction.", {
17
+ metaMessages: [
18
+ "Provided Transaction:",
19
+ "{",
20
+ i(r),
21
+ "}",
22
+ "",
23
+ "To infer the type, either provide:",
24
+ "- a `type` to the Transaction, or",
25
+ "- an EIP-1559 Transaction with `maxFeePerGas`, or",
26
+ "- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
27
+ "- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or",
28
+ "- an EIP-7702 Transaction with `authorizationList`, or",
29
+ "- a Legacy Transaction with `gasPrice`"
30
+ ],
31
+ name: "InvalidSerializableTransactionError"
32
+ });
33
+ }
34
+ }
35
+ class l extends t {
36
+ constructor({ storageKey: r }) {
37
+ super(`Size for storage key "${r}" is invalid. Expected 32 bytes. Got ${Math.floor((r.length - 2) / 2)} bytes.`, { name: "InvalidStorageKeySizeError" });
38
+ }
39
+ }
2
40
  export {
3
- e as versionedHashVersionKzg
41
+ c as InvalidLegacyVError,
42
+ d as InvalidSerializableTransactionError,
43
+ l as InvalidStorageKeySizeError,
44
+ i as prettyPrint
4
45
  };