@coinbase/cdp-core 0.0.41 → 0.0.42

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 (61) hide show
  1. package/dist/esm/index.native101.js +10 -79
  2. package/dist/esm/index.native102.js +79 -10
  3. package/dist/esm/index.native13.js +1 -1
  4. package/dist/esm/index.native25.js +149 -940
  5. package/dist/esm/index.native26.js +48 -2
  6. package/dist/esm/index.native27.js +244 -43
  7. package/dist/esm/index.native28.js +55 -27
  8. package/dist/esm/index.native29.js +940 -149
  9. package/dist/esm/index.native30.js +2 -48
  10. package/dist/esm/index.native31.js +43 -243
  11. package/dist/esm/index.native32.js +27 -55
  12. package/dist/esm/index.native8.js +4 -4
  13. package/dist/esm/index.native9.js +49 -31
  14. package/dist/esm/index.native92.js +1 -1
  15. package/dist/esm/index.web100.js +9 -117
  16. package/dist/esm/index.web101.js +79 -10
  17. package/dist/esm/index.web26.js +156 -155
  18. package/dist/esm/index.web27.js +1 -1
  19. package/dist/esm/index.web8.js +49 -31
  20. package/dist/esm/index.web82.js +6 -6
  21. package/dist/esm/index.web91.js +1 -1
  22. package/dist/esm/index.web94.js +19 -77
  23. package/dist/esm/index.web95.js +10 -21
  24. package/dist/esm/index.web96.js +19 -9
  25. package/dist/esm/index.web97.js +89 -15
  26. package/dist/esm/index.web98.js +19 -92
  27. package/dist/esm/index.web99.js +115 -18
  28. package/dist/native/index.native101.js +10 -79
  29. package/dist/native/index.native102.js +79 -10
  30. package/dist/native/index.native13.js +1 -1
  31. package/dist/native/index.native25.js +149 -940
  32. package/dist/native/index.native26.js +48 -2
  33. package/dist/native/index.native27.js +244 -43
  34. package/dist/native/index.native28.js +55 -27
  35. package/dist/native/index.native29.js +940 -149
  36. package/dist/native/index.native30.js +2 -48
  37. package/dist/native/index.native31.js +43 -243
  38. package/dist/native/index.native32.js +27 -55
  39. package/dist/native/index.native8.js +4 -4
  40. package/dist/native/index.native9.js +49 -31
  41. package/dist/native/index.native92.js +1 -1
  42. package/dist/native-types/eip1193/errors.d.ts +6 -0
  43. package/dist/native-types/eip1193/internal.d.ts +3 -1
  44. package/dist/types/eip1193/errors.d.ts +6 -0
  45. package/dist/types/eip1193/internal.d.ts +3 -1
  46. package/dist/web/index.web100.js +9 -117
  47. package/dist/web/index.web101.js +79 -10
  48. package/dist/web/index.web26.js +156 -155
  49. package/dist/web/index.web27.js +1 -1
  50. package/dist/web/index.web8.js +49 -31
  51. package/dist/web/index.web82.js +6 -6
  52. package/dist/web/index.web91.js +1 -1
  53. package/dist/web/index.web94.js +19 -77
  54. package/dist/web/index.web95.js +10 -21
  55. package/dist/web/index.web96.js +19 -9
  56. package/dist/web/index.web97.js +89 -15
  57. package/dist/web/index.web98.js +19 -92
  58. package/dist/web/index.web99.js +115 -18
  59. package/dist/web-types/eip1193/errors.d.ts +6 -0
  60. package/dist/web-types/eip1193/internal.d.ts +3 -1
  61. package/package.json +2 -2
@@ -1,4 +1,50 @@
1
- var r = {};
1
+ class n {
2
+ events = {};
3
+ /**
4
+ * Add an event listener.
5
+ *
6
+ * @param event - The name of the event to listen for.
7
+ * @param listener - The function to call when the event is emitted.
8
+ */
9
+ on(e, s) {
10
+ this.events[e] || (this.events[e] = []), this.events[e].push(s);
11
+ }
12
+ /**
13
+ * Remove an event listener.
14
+ *
15
+ * @param event - The name of the event to remove the listener from.
16
+ * @param listener - The function to remove from the event listeners.
17
+ */
18
+ removeListener(e, s) {
19
+ if (!this.events[e])
20
+ return;
21
+ const t = this.events[e].indexOf(s);
22
+ t > -1 && this.events[e].splice(t, 1);
23
+ }
24
+ /**
25
+ * Emit an event.
26
+ *
27
+ * @param event - The name of the event to emit.
28
+ * @param args - The arguments to pass to the event listeners.
29
+ */
30
+ emit(e, ...s) {
31
+ this.events[e] && this.events[e].forEach((t) => {
32
+ try {
33
+ t(...s);
34
+ } catch (i) {
35
+ console.error(`Error in event listener for ${e}:`, i);
36
+ }
37
+ });
38
+ }
39
+ /**
40
+ * Remove all listeners for an event.
41
+ *
42
+ * @param event - The name of the event to remove all listeners from. If not provided, removes all listeners for all events.
43
+ */
44
+ removeAllListeners(e) {
45
+ e ? delete this.events[e] : this.events = {};
46
+ }
47
+ }
2
48
  export {
3
- r as __exports
49
+ n as EventEmitter
4
50
  };
@@ -1,52 +1,253 @@
1
- import { __exports as F } from "./index.native36.js";
2
- var A;
3
- function _() {
4
- if (A) return F;
5
- A = 1, F.byteLength = y, F.toByteArray = C, F.fromByteArray = B;
6
- for (var c = [], n = [], l = typeof Uint8Array < "u" ? Uint8Array : Array, d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", s = 0, p = d.length; s < p; ++s)
7
- c[s] = d[s], n[d.charCodeAt(s)] = s;
8
- n[45] = 62, n[95] = 63;
9
- function x(r) {
10
- var e = r.length;
11
- if (e % 4 > 0)
12
- throw new Error("Invalid string. Length must be a multiple of 4");
13
- var a = r.indexOf("=");
14
- a === -1 && (a = e);
15
- var o = a === e ? 0 : 4 - a % 4;
16
- return [a, o];
17
- }
18
- function y(r) {
19
- var e = x(r), a = e[0], o = e[1];
20
- return (a + o) * 3 / 4 - o;
1
+ import { Hex as E } from "ox";
2
+ import { toHex as T, createWalletClient as P } from "viem";
3
+ import { getUserOperation as R, sendUserOperation as b, signEvmTypedData as U, signEvmHash as x, getCurrentUser as w, signOut as H, sendEvmTransaction as O, signEvmTransaction as D, signEvmMessage as N } from "./index.native6.js";
4
+ import "@coinbase/cdp-api-client";
5
+ import "./index.native8.js";
6
+ import { validateUserConnected as v, validateUserHasEvmSmartAccount as S, RPCRequestError as u, STANDARD_ERROR_CODES as o, validateIsUsingEOA as h, validateUserOwnsAddress as p, EIP1193ProviderError as g } from "./index.native9.js";
7
+ import "zustand";
8
+ import { userOperationChainIdToNameMapping as m, isChainIdSupportedForCDPUserOps as I, isChainIdSupportedForCDPSends as F, sendTransactionChainIdToNameMapping as j, userOperationNameToChainIdMapping as k } from "./index.native18.js";
9
+ function f(t) {
10
+ return {
11
+ to: t.to,
12
+ data: t.data,
13
+ value: t.value ? BigInt(t.value) : void 0,
14
+ nonce: t.nonce ? Number(t.nonce) : void 0,
15
+ gas: t.gas ? BigInt(t.gas) : void 0,
16
+ maxFeePerGas: t.maxFeePerGas ? BigInt(t.maxFeePerGas) : void 0,
17
+ maxPriorityFeePerGas: t.maxPriorityFeePerGas ? BigInt(t.maxPriorityFeePerGas) : void 0,
18
+ type: "eip1559"
19
+ };
20
+ }
21
+ function q(t) {
22
+ return t.map((e) => ({
23
+ to: e.to,
24
+ data: e.data,
25
+ value: e.value ? BigInt(e.value) : void 0
26
+ }));
27
+ }
28
+ function B(t) {
29
+ return {
30
+ atomic: !0,
31
+ chainId: k[t.network] ?? 0,
32
+ receipts: t.receipts?.map((e) => ({
33
+ transactionHash: e.transactionHash,
34
+ blockHash: e.blockHash,
35
+ blockNumber: BigInt(e.blockNumber ?? 0),
36
+ gasUsed: BigInt(e.gasUsed ?? 0),
37
+ logs: [],
38
+ status: ""
39
+ })),
40
+ id: t.userOpHash,
41
+ status: G(t.status),
42
+ version: "1"
43
+ };
44
+ }
45
+ function G(t) {
46
+ switch (t) {
47
+ case "dropped":
48
+ case "failed":
49
+ return 400;
50
+ case "complete":
51
+ return 200;
52
+ default:
53
+ return 100;
21
54
  }
22
- function i(r, e, a) {
23
- return (e + a) * 3 / 4 - a;
55
+ }
56
+ async function Q() {
57
+ const t = await w();
58
+ return t?.evmSmartAccounts && t.evmSmartAccounts.length > 0 ? t.evmSmartAccounts : t?.evmAccounts || [];
59
+ }
60
+ async function X(t, e) {
61
+ const a = await v();
62
+ return t.emit("connect", {
63
+ chainId: E.fromNumber(e.getState().chainId)
64
+ }), a.evmSmartAccounts && a.evmSmartAccounts.length > 0 ? a.evmSmartAccounts : a.evmAccounts || [];
65
+ }
66
+ async function Y(t) {
67
+ await h();
68
+ const [e, a] = t;
69
+ await p(a);
70
+ const r = Buffer.from(e.slice(2), "hex").toString();
71
+ try {
72
+ return (await N({
73
+ evmAccount: a,
74
+ message: r
75
+ })).signature;
76
+ } catch (n) {
77
+ throw new g(
78
+ o.provider.userRejectedRequest,
79
+ n instanceof Error ? n.message : "Signing failed"
80
+ );
24
81
  }
25
- function C(r) {
26
- var e, a = x(r), o = a[0], v = a[1], t = new l(i(r, o, v)), h = 0, u = v > 0 ? o - 4 : o, f;
27
- for (f = 0; f < u; f += 4)
28
- e = n[r.charCodeAt(f)] << 18 | n[r.charCodeAt(f + 1)] << 12 | n[r.charCodeAt(f + 2)] << 6 | n[r.charCodeAt(f + 3)], t[h++] = e >> 16 & 255, t[h++] = e >> 8 & 255, t[h++] = e & 255;
29
- return v === 2 && (e = n[r.charCodeAt(f)] << 2 | n[r.charCodeAt(f + 1)] >> 4, t[h++] = e & 255), v === 1 && (e = n[r.charCodeAt(f)] << 10 | n[r.charCodeAt(f + 1)] << 4 | n[r.charCodeAt(f + 2)] >> 2, t[h++] = e >> 8 & 255, t[h++] = e & 255), t;
82
+ }
83
+ async function Z(t) {
84
+ await h();
85
+ const [e, a] = t;
86
+ await p(e);
87
+ try {
88
+ return (await U({
89
+ evmAccount: e,
90
+ typedData: JSON.parse(a)
91
+ })).signature;
92
+ } catch (r) {
93
+ throw new g(
94
+ o.provider.userRejectedRequest,
95
+ r instanceof Error ? r.message : "Signing failed"
96
+ );
30
97
  }
31
- function L(r) {
32
- return c[r >> 18 & 63] + c[r >> 12 & 63] + c[r >> 6 & 63] + c[r & 63];
98
+ }
99
+ async function tt(t, e, a) {
100
+ const r = await h({
101
+ errorMessage: "sendTransaction with a smart account is not supported. Use sendCalls instead."
102
+ }), [n] = t;
103
+ if (!n || typeof n != "object")
104
+ throw new u(
105
+ o.rpc.invalidParams,
106
+ "Transaction parameter must be an object"
107
+ );
108
+ if (!n.to)
109
+ throw new u(
110
+ o.rpc.invalidParams,
111
+ "Transaction must include 'to' field"
112
+ );
113
+ const d = r.evmAccounts?.[0], i = e.getState(), s = n.chainId ? Number(n.chainId) : i.chainId;
114
+ if (!d)
115
+ throw new u(
116
+ o.rpc.invalidParams,
117
+ "User does not have an EVM account"
118
+ );
119
+ if (F(s))
120
+ try {
121
+ return (await O({
122
+ evmAccount: d,
123
+ transaction: { ...f(n), chainId: s },
124
+ network: j[s]
125
+ })).transactionHash;
126
+ } catch (c) {
127
+ throw console.log("Transaction failed", c), new u(
128
+ o.rpc.transactionRejected,
129
+ c instanceof Error ? c.message : "Transaction failed"
130
+ );
131
+ }
132
+ else
133
+ try {
134
+ const c = P({
135
+ // Safe as we check before calling this handler that chainId is configured
136
+ chain: i.chains.find((l) => l.id === s),
137
+ transport: a[s],
138
+ account: d
139
+ }), y = i.chains.find((l) => l.id === s), A = await c.prepareTransactionRequest({
140
+ ...f(n),
141
+ chain: y
142
+ }), C = await D({
143
+ evmAccount: d,
144
+ transaction: {
145
+ ...A,
146
+ type: "eip1559"
147
+ }
148
+ });
149
+ return await c.sendRawTransaction({
150
+ serializedTransaction: C.signedTransaction
151
+ });
152
+ } catch (c) {
153
+ throw new u(
154
+ o.rpc.transactionRejected,
155
+ c instanceof Error ? c.message : "Transaction failed"
156
+ );
157
+ }
158
+ }
159
+ async function et(t) {
160
+ await h();
161
+ const [e, a] = t;
162
+ await p(a);
163
+ try {
164
+ return (await x({
165
+ evmAccount: a,
166
+ hash: e
167
+ })).signature;
168
+ } catch (r) {
169
+ throw new g(
170
+ o.provider.userRejectedRequest,
171
+ r instanceof Error ? r.message : "Signing failed"
172
+ );
33
173
  }
34
- function g(r, e, a) {
35
- for (var o, v = [], t = e; t < a; t += 3)
36
- o = (r[t] << 16 & 16711680) + (r[t + 1] << 8 & 65280) + (r[t + 2] & 255), v.push(L(o));
37
- return v.join("");
174
+ }
175
+ async function at(t) {
176
+ return `0x${t.getState().chainId.toString(16)}`;
177
+ }
178
+ async function nt() {
179
+ await w() && await H();
180
+ }
181
+ function rt(t, e) {
182
+ const a = Number.parseInt(t[0].chainId, 16);
183
+ e.getState().setChainId(a);
184
+ }
185
+ async function st(t, e) {
186
+ const a = t[0].calls, n = (await S()).evmSmartAccounts?.[0], i = e.getState().chainId;
187
+ if (!I(i))
188
+ throw new u(
189
+ o.rpc.invalidParams,
190
+ "Chain ID is not supported for user operations"
191
+ );
192
+ try {
193
+ return (await b({
194
+ evmSmartAccount: n,
195
+ calls: q(a),
196
+ network: m[i]
197
+ })).userOperationHash;
198
+ } catch (s) {
199
+ throw console.log("User operation failed", s), new u(
200
+ o.rpc.transactionRejected,
201
+ s instanceof Error ? s.message : "User operation failed"
202
+ );
38
203
  }
39
- function B(r) {
40
- for (var e, a = r.length, o = a % 3, v = [], t = 16383, h = 0, u = a - o; h < u; h += t)
41
- v.push(g(r, h, h + t > u ? u : h + t));
42
- return o === 1 ? (e = r[a - 1], v.push(
43
- c[e >> 2] + c[e << 4 & 63] + "=="
44
- )) : o === 2 && (e = (r[a - 2] << 8) + r[a - 1], v.push(
45
- c[e >> 10] + c[e >> 4 & 63] + c[e << 2 & 63] + "="
46
- )), v.join("");
204
+ }
205
+ async function ot(t, e) {
206
+ const a = t[0], n = (await S()).evmSmartAccounts?.[0], i = e.getState().chainId;
207
+ if (!I(i) || !m[i])
208
+ throw new u(
209
+ o.rpc.invalidParams,
210
+ "Chain ID is not supported for user operations"
211
+ );
212
+ try {
213
+ const s = await R({
214
+ userOperationHash: a,
215
+ evmSmartAccount: n,
216
+ network: m[i]
217
+ });
218
+ return B(s);
219
+ } catch (s) {
220
+ throw console.log("Failed to get user operation status", s), new u(
221
+ o.rpc.internal,
222
+ "Failed to get user operation status"
223
+ );
47
224
  }
48
- return F;
225
+ }
226
+ async function it() {
227
+ return !(await v()).evmSmartAccounts?.length ? {} : Object.keys(m).reduce(
228
+ (r, n) => {
229
+ const d = T(Number(n));
230
+ return r[d] = {
231
+ atomic: { status: "supported" },
232
+ paymasterService: { supported: !0 }
233
+ }, r;
234
+ },
235
+ {}
236
+ );
49
237
  }
50
238
  export {
51
- _ as __require
239
+ Q as handleAccounts,
240
+ at as handleChainId,
241
+ nt as handleDisconnect,
242
+ et as handleEthSign,
243
+ ot as handleGetCallsStatus,
244
+ it as handleGetCapabilities,
245
+ Y as handlePersonalSign,
246
+ X as handleRequestAccounts,
247
+ st as handleSendCalls,
248
+ tt as handleSendTransaction,
249
+ Z as handleSignTypedData,
250
+ rt as handleSwitchEthereumChain,
251
+ q as shimProviderCallsRequest,
252
+ f as shimProviderTxRequest
52
253
  };
@@ -1,30 +1,58 @@
1
- import { __exports as n } from "./index.native37.js";
2
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3
- var d;
4
- function q() {
5
- return d ? n : (d = 1, n.read = function(s, a, N, w, M) {
6
- var t, r, h = M * 8 - w - 1, e = (1 << h) - 1, f = e >> 1, i = -7, o = N ? M - 1 : 0, x = N ? -1 : 1, p = s[a + o];
7
- for (o += x, t = p & (1 << -i) - 1, p >>= -i, i += h; i > 0; t = t * 256 + s[a + o], o += x, i -= 8)
8
- ;
9
- for (r = t & (1 << -i) - 1, t >>= -i, i += w; i > 0; r = r * 256 + s[a + o], o += x, i -= 8)
10
- ;
11
- if (t === 0)
12
- t = 1 - f;
13
- else {
14
- if (t === e)
15
- return r ? NaN : (p ? -1 : 1) * (1 / 0);
16
- r = r + Math.pow(2, w), t = t - f;
1
+ import { chainConfig as a } from "./index.native101.js";
2
+ import { defineChain as t } from "./index.native38.js";
3
+ const e = 11155111, r = /* @__PURE__ */ t({
4
+ ...a,
5
+ id: 84532,
6
+ network: "base-sepolia",
7
+ name: "Base Sepolia",
8
+ nativeCurrency: { name: "Sepolia Ether", symbol: "ETH", decimals: 18 },
9
+ rpcUrls: {
10
+ default: {
11
+ http: ["https://sepolia.base.org"]
17
12
  }
18
- return (p ? -1 : 1) * r * Math.pow(2, t - w);
19
- }, n.write = function(s, a, N, w, M, t) {
20
- var r, h, e, f = t * 8 - M - 1, i = (1 << f) - 1, o = i >> 1, x = M === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, p = w ? 0 : t - 1, c = w ? 1 : -1, I = a < 0 || a === 0 && 1 / a < 0 ? 1 : 0;
21
- for (a = Math.abs(a), isNaN(a) || a === 1 / 0 ? (h = isNaN(a) ? 1 : 0, r = i) : (r = Math.floor(Math.log(a) / Math.LN2), a * (e = Math.pow(2, -r)) < 1 && (r--, e *= 2), r + o >= 1 ? a += x / e : a += x * Math.pow(2, 1 - o), a * e >= 2 && (r++, e /= 2), r + o >= i ? (h = 0, r = i) : r + o >= 1 ? (h = (a * e - 1) * Math.pow(2, M), r = r + o) : (h = a * Math.pow(2, o - 1) * Math.pow(2, M), r = 0)); M >= 8; s[N + p] = h & 255, p += c, h /= 256, M -= 8)
22
- ;
23
- for (r = r << M | h, f += M; f > 0; s[N + p] = r & 255, p += c, r /= 256, f -= 8)
24
- ;
25
- s[N + p - c] |= I * 128;
26
- }, n);
27
- }
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: "Basescan",
17
+ url: "https://sepolia.basescan.org",
18
+ apiUrl: "https://api-sepolia.basescan.org/api"
19
+ }
20
+ },
21
+ contracts: {
22
+ ...a.contracts,
23
+ disputeGameFactory: {
24
+ [e]: {
25
+ address: "0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"
26
+ }
27
+ },
28
+ l2OutputOracle: {
29
+ [e]: {
30
+ address: "0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"
31
+ }
32
+ },
33
+ portal: {
34
+ [e]: {
35
+ address: "0x49f53e41452c74589e85ca1677426ba426459e85",
36
+ blockCreated: 4446677
37
+ }
38
+ },
39
+ l1StandardBridge: {
40
+ [e]: {
41
+ address: "0xfd0Bf71F60660E2f608ed56e1659C450eB113120",
42
+ blockCreated: 4446677
43
+ }
44
+ },
45
+ multicall3: {
46
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
47
+ blockCreated: 1059647
48
+ }
49
+ },
50
+ testnet: !0,
51
+ sourceId: e
52
+ });
53
+ ({
54
+ ...r
55
+ });
28
56
  export {
29
- q as __require
57
+ r as baseSepolia
30
58
  };