@coinbase/cdp-core 0.0.8 → 0.0.10

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 (95) hide show
  1. package/dist/esm/index100.js +7 -14
  2. package/dist/esm/index101.js +16 -80
  3. package/dist/esm/index102.js +72 -70
  4. package/dist/esm/index103.js +81 -0
  5. package/dist/esm/index13.js +18 -172
  6. package/dist/esm/index14.js +169 -157
  7. package/dist/esm/index15.js +157 -45
  8. package/dist/esm/index16.js +44 -142
  9. package/dist/esm/index17.js +144 -54
  10. package/dist/esm/index18.js +56 -41
  11. package/dist/esm/index19.js +40 -16
  12. package/dist/esm/index2.js +72 -68
  13. package/dist/esm/index20.js +16 -4
  14. package/dist/esm/index21.js +5 -5
  15. package/dist/esm/index22.js +5 -9
  16. package/dist/esm/index23.js +8 -17
  17. package/dist/esm/index24.js +16 -44
  18. package/dist/esm/index25.js +45 -13
  19. package/dist/esm/index26.js +13 -55
  20. package/dist/esm/index27.js +55 -6
  21. package/dist/esm/index28.js +6 -21
  22. package/dist/esm/index29.js +21 -11
  23. package/dist/esm/index3.js +4 -4
  24. package/dist/esm/index30.js +11 -3
  25. package/dist/esm/index31.js +3 -3
  26. package/dist/esm/index32.js +3 -34
  27. package/dist/esm/index33.js +32 -10
  28. package/dist/esm/index34.js +12 -4
  29. package/dist/esm/index35.js +4 -28
  30. package/dist/esm/index36.js +28 -6
  31. package/dist/esm/index37.js +6 -24
  32. package/dist/esm/index38.js +24 -16
  33. package/dist/esm/index39.js +16 -54
  34. package/dist/esm/index40.js +53 -22
  35. package/dist/esm/index41.js +23 -11
  36. package/dist/esm/index42.js +10 -26
  37. package/dist/esm/index43.js +26 -41
  38. package/dist/esm/index44.js +41 -54
  39. package/dist/esm/index45.js +54 -126
  40. package/dist/esm/index46.js +126 -11
  41. package/dist/esm/index47.js +9 -101
  42. package/dist/esm/index48.js +104 -6
  43. package/dist/esm/index49.js +7 -3
  44. package/dist/esm/index5.js +4 -4
  45. package/dist/esm/index50.js +3 -15
  46. package/dist/esm/index51.js +14 -42
  47. package/dist/esm/index52.js +38 -74
  48. package/dist/esm/index53.js +79 -2
  49. package/dist/esm/index54.js +2 -2
  50. package/dist/esm/index55.js +2 -13
  51. package/dist/esm/index56.js +8 -33
  52. package/dist/esm/index57.js +36 -5
  53. package/dist/esm/index58.js +5 -33
  54. package/dist/esm/index59.js +34 -8
  55. package/dist/esm/index60.js +8 -10
  56. package/dist/esm/index61.js +10 -11
  57. package/dist/esm/index62.js +11 -13
  58. package/dist/esm/index63.js +13 -18
  59. package/dist/esm/index64.js +18 -5
  60. package/dist/esm/index65.js +6 -5
  61. package/dist/esm/index66.js +5 -11
  62. package/dist/esm/index67.js +10 -16
  63. package/dist/esm/index68.js +15 -21
  64. package/dist/esm/index69.js +21 -49
  65. package/dist/esm/index70.js +51 -2
  66. package/dist/esm/index71.js +2 -21
  67. package/dist/esm/index72.js +18 -17
  68. package/dist/esm/index73.js +20 -80
  69. package/dist/esm/index74.js +79 -103
  70. package/dist/esm/index75.js +101 -30
  71. package/dist/esm/index76.js +32 -6
  72. package/dist/esm/index77.js +7 -10
  73. package/dist/esm/index78.js +10 -55
  74. package/dist/esm/index79.js +54 -10
  75. package/dist/esm/index80.js +11 -2
  76. package/dist/esm/index81.js +2 -45
  77. package/dist/esm/index82.js +44 -13
  78. package/dist/esm/index83.js +13 -78
  79. package/dist/esm/index84.js +79 -5
  80. package/dist/esm/index85.js +5 -13
  81. package/dist/esm/index86.js +12 -35
  82. package/dist/esm/index87.js +35 -41
  83. package/dist/esm/index88.js +40 -19
  84. package/dist/esm/index89.js +21 -10
  85. package/dist/esm/index90.js +9 -19
  86. package/dist/esm/index91.js +15 -89
  87. package/dist/esm/index92.js +92 -19
  88. package/dist/esm/index93.js +18 -115
  89. package/dist/esm/index94.js +118 -18
  90. package/dist/esm/index95.js +18 -28
  91. package/dist/esm/index96.js +26 -6
  92. package/dist/esm/index97.js +6 -9
  93. package/dist/esm/index98.js +11 -13
  94. package/dist/esm/index99.js +11 -8
  95. package/package.json +3 -3
@@ -1,148 +1,50 @@
1
- import { Provider as y, Hex as I } from "ox";
2
- import { createWalletClient as E } from "viem";
3
- import { signEvmTypedData as S, signEvmHash as P, getCurrentUser as f, signOut as R, sendEvmTransaction as T, signEvmTransaction as A, signEvmMessage as x } from "./index2.js";
4
- import "./index3.js";
5
- import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as c, validateUserHasEvmAccount as C, validateUserConnected as D } from "./index4.js";
6
- import { isChainIdSupportedForCDPSends as b, chainIdToNameMapping as j } from "./index12.js";
7
- function g(e) {
8
- return {
9
- to: e.to,
10
- data: e.data,
11
- value: e.value ? BigInt(e.value) : void 0,
12
- nonce: e.nonce ? Number(e.nonce) : void 0,
13
- gas: e.gas ? BigInt(e.gas) : void 0,
14
- maxFeePerGas: e.maxFeePerGas ? BigInt(e.maxFeePerGas) : void 0,
15
- maxPriorityFeePerGas: e.maxPriorityFeePerGas ? BigInt(e.maxPriorityFeePerGas) : void 0,
16
- type: "eip1559"
17
- };
18
- }
19
- async function U() {
20
- return (await f())?.evmAccounts || [];
21
- }
22
- async function M(e, n) {
23
- const a = await D();
24
- return e.emit("connect", {
25
- chainId: I.fromNumber(n.getState().chainId)
26
- }), a.evmAccounts;
27
- }
28
- async function _(e) {
29
- const [n, a] = e;
30
- await m(a);
31
- const t = Buffer.from(n.slice(2), "hex").toString();
32
- try {
33
- return (await x({
34
- evmAccount: a,
35
- message: t
36
- })).signature;
37
- } catch (o) {
38
- throw new l(
39
- s.provider.userRejectedRequest,
40
- o instanceof Error ? o.message : "Signing failed"
41
- );
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);
42
11
  }
43
- }
44
- async function k(e) {
45
- const [n, a] = e;
46
- await m(n);
47
- try {
48
- return (await S({
49
- evmAccount: n,
50
- typedData: JSON.parse(a)
51
- })).signature;
52
- } catch (t) {
53
- throw new l(
54
- s.provider.userRejectedRequest,
55
- t instanceof Error ? t.message : "Signing failed"
56
- );
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);
57
23
  }
58
- }
59
- async function z(e, n, a) {
60
- const [t] = e;
61
- if (!t || typeof t != "object")
62
- throw new c(
63
- s.rpc.invalidParams,
64
- "Transaction parameter must be an object"
65
- );
66
- if (!t.to)
67
- throw new c(
68
- s.rpc.invalidParams,
69
- "Transaction must include 'to' field"
70
- );
71
- const d = (await C()).evmAccounts[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
72
- if (b(i))
73
- try {
74
- return (await T({
75
- evmAccount: d,
76
- transaction: { ...g(t), chainId: i },
77
- network: j[i]
78
- })).transactionHash;
79
- } catch (r) {
80
- throw console.log("Transaction failed", r), new c(
81
- s.rpc.transactionRejected,
82
- r instanceof Error ? r.message : "Transaction failed"
83
- );
84
- }
85
- else
86
- try {
87
- const r = E({
88
- // Safe as we check before calling this handler that chainId is configured
89
- chain: u.chains.find((h) => h.id === i),
90
- transport: a[i],
91
- account: d
92
- }), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
93
- ...g(t),
94
- chain: p
95
- }), v = await A({
96
- evmAccount: d,
97
- transaction: {
98
- ...w,
99
- type: "eip1559"
100
- }
101
- });
102
- return await r.sendRawTransaction({
103
- serializedTransaction: v.signedTransaction
104
- });
105
- } catch (r) {
106
- throw new c(
107
- s.rpc.transactionRejected,
108
- r instanceof Error ? r.message : "Transaction failed"
109
- );
110
- }
111
- }
112
- async function J(e) {
113
- const [n, a] = e;
114
- await m(a);
115
- try {
116
- return (await P({
117
- evmAccount: a,
118
- hash: n
119
- })).signature;
120
- } catch (t) {
121
- throw new l(
122
- s.provider.userRejectedRequest,
123
- t instanceof Error ? t.message : "Signing failed"
124
- );
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 = {};
125
46
  }
126
- }
127
- async function W(e) {
128
- return `0x${e.getState().chainId.toString(16)}`;
129
- }
130
- async function $(e) {
131
- await f() && await R(), e.emit("disconnect", new y.DisconnectedError());
132
- }
133
- function K(e, n) {
134
- const a = Number.parseInt(e[0].chainId, 16);
135
- n.getState().setChainId(a);
136
47
  }
137
48
  export {
138
- U as handleAccounts,
139
- W as handleChainId,
140
- $ as handleDisconnect,
141
- J as handleEthSign,
142
- _ as handlePersonalSign,
143
- M as handleRequestAccounts,
144
- z as handleSendTransaction,
145
- k as handleSignTypedData,
146
- K as handleSwitchEthereumChain,
147
- g as shimProviderTxRequest
49
+ n as EventEmitter
148
50
  };
@@ -1,58 +1,148 @@
1
- import { chainConfig as a } from "./index77.js";
2
- import { defineChain as t } from "./index22.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"]
1
+ import { Provider as y, Hex as I } from "ox";
2
+ import { createWalletClient as E } from "viem";
3
+ import { signEvmTypedData as S, signEvmHash as P, getCurrentUser as f, signOut as R, sendEvmTransaction as T, signEvmTransaction as A, signEvmMessage as x } from "./index2.js";
4
+ import "./index3.js";
5
+ import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as c, validateUserHasEvmAccount as C, validateUserConnected as D } from "./index4.js";
6
+ import { isChainIdSupportedForCDPSends as b, chainIdToNameMapping as j } from "./index12.js";
7
+ function g(e) {
8
+ return {
9
+ to: e.to,
10
+ data: e.data,
11
+ value: e.value ? BigInt(e.value) : void 0,
12
+ nonce: e.nonce ? Number(e.nonce) : void 0,
13
+ gas: e.gas ? BigInt(e.gas) : void 0,
14
+ maxFeePerGas: e.maxFeePerGas ? BigInt(e.maxFeePerGas) : void 0,
15
+ maxPriorityFeePerGas: e.maxPriorityFeePerGas ? BigInt(e.maxPriorityFeePerGas) : void 0,
16
+ type: "eip1559"
17
+ };
18
+ }
19
+ async function U() {
20
+ return (await f())?.evmAccounts || [];
21
+ }
22
+ async function M(e, n) {
23
+ const a = await D();
24
+ return e.emit("connect", {
25
+ chainId: I.fromNumber(n.getState().chainId)
26
+ }), a.evmAccounts;
27
+ }
28
+ async function _(e) {
29
+ const [n, a] = e;
30
+ await m(a);
31
+ const t = Buffer.from(n.slice(2), "hex").toString();
32
+ try {
33
+ return (await x({
34
+ evmAccount: a,
35
+ message: t
36
+ })).signature;
37
+ } catch (o) {
38
+ throw new l(
39
+ s.provider.userRejectedRequest,
40
+ o instanceof Error ? o.message : "Signing failed"
41
+ );
42
+ }
43
+ }
44
+ async function k(e) {
45
+ const [n, a] = e;
46
+ await m(n);
47
+ try {
48
+ return (await S({
49
+ evmAccount: n,
50
+ typedData: JSON.parse(a)
51
+ })).signature;
52
+ } catch (t) {
53
+ throw new l(
54
+ s.provider.userRejectedRequest,
55
+ t instanceof Error ? t.message : "Signing failed"
56
+ );
57
+ }
58
+ }
59
+ async function z(e, n, a) {
60
+ const [t] = e;
61
+ if (!t || typeof t != "object")
62
+ throw new c(
63
+ s.rpc.invalidParams,
64
+ "Transaction parameter must be an object"
65
+ );
66
+ if (!t.to)
67
+ throw new c(
68
+ s.rpc.invalidParams,
69
+ "Transaction must include 'to' field"
70
+ );
71
+ const d = (await C()).evmAccounts[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
72
+ if (b(i))
73
+ try {
74
+ return (await T({
75
+ evmAccount: d,
76
+ transaction: { ...g(t), chainId: i },
77
+ network: j[i]
78
+ })).transactionHash;
79
+ } catch (r) {
80
+ throw console.log("Transaction failed", r), new c(
81
+ s.rpc.transactionRejected,
82
+ r instanceof Error ? r.message : "Transaction failed"
83
+ );
12
84
  }
13
- },
14
- blockExplorers: {
15
- default: {
16
- name: "Basescan",
17
- url: "https://sepolia.basescan.org",
18
- apiUrl: "https://api-sepolia.basescan.org/api"
85
+ else
86
+ try {
87
+ const r = E({
88
+ // Safe as we check before calling this handler that chainId is configured
89
+ chain: u.chains.find((h) => h.id === i),
90
+ transport: a[i],
91
+ account: d
92
+ }), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
93
+ ...g(t),
94
+ chain: p
95
+ }), v = await A({
96
+ evmAccount: d,
97
+ transaction: {
98
+ ...w,
99
+ type: "eip1559"
100
+ }
101
+ });
102
+ return await r.sendRawTransaction({
103
+ serializedTransaction: v.signedTransaction
104
+ });
105
+ } catch (r) {
106
+ throw new c(
107
+ s.rpc.transactionRejected,
108
+ r instanceof Error ? r.message : "Transaction failed"
109
+ );
19
110
  }
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
- });
111
+ }
112
+ async function J(e) {
113
+ const [n, a] = e;
114
+ await m(a);
115
+ try {
116
+ return (await P({
117
+ evmAccount: a,
118
+ hash: n
119
+ })).signature;
120
+ } catch (t) {
121
+ throw new l(
122
+ s.provider.userRejectedRequest,
123
+ t instanceof Error ? t.message : "Signing failed"
124
+ );
125
+ }
126
+ }
127
+ async function W(e) {
128
+ return `0x${e.getState().chainId.toString(16)}`;
129
+ }
130
+ async function $(e) {
131
+ await f() && await R(), e.emit("disconnect", new y.DisconnectedError());
132
+ }
133
+ function K(e, n) {
134
+ const a = Number.parseInt(e[0].chainId, 16);
135
+ n.getState().setChainId(a);
136
+ }
56
137
  export {
57
- r as baseSepolia
138
+ U as handleAccounts,
139
+ W as handleChainId,
140
+ $ as handleDisconnect,
141
+ J as handleEthSign,
142
+ _ as handlePersonalSign,
143
+ M as handleRequestAccounts,
144
+ z as handleSendTransaction,
145
+ k as handleSignTypedData,
146
+ K as handleSwitchEthereumChain,
147
+ g as shimProviderTxRequest
58
148
  };
@@ -1,43 +1,58 @@
1
- import { CompactSign as i } from "./index67.js";
2
- import { JWTInvalid as r } from "./index68.js";
3
- import { JWTClaimsBuilder as n } from "./index69.js";
4
- class d {
5
- #s;
6
- #t;
7
- constructor(t = {}) {
8
- this.#t = new n(t);
9
- }
10
- setIssuer(t) {
11
- return this.#t.iss = t, this;
12
- }
13
- setSubject(t) {
14
- return this.#t.sub = t, this;
15
- }
16
- setAudience(t) {
17
- return this.#t.aud = t, this;
18
- }
19
- setJti(t) {
20
- return this.#t.jti = t, this;
21
- }
22
- setNotBefore(t) {
23
- return this.#t.nbf = t, this;
24
- }
25
- setExpirationTime(t) {
26
- return this.#t.exp = t, this;
27
- }
28
- setIssuedAt(t) {
29
- return this.#t.iat = t, this;
30
- }
31
- setProtectedHeader(t) {
32
- return this.#s = t, this;
33
- }
34
- async sign(t, e) {
35
- const s = new i(this.#t.data());
36
- if (s.setProtectedHeader(this.#s), Array.isArray(this.#s?.crit) && this.#s.crit.includes("b64") && this.#s.b64 === !1)
37
- throw new r("JWTs MUST NOT use unencoded payload");
38
- return s.sign(t, e);
39
- }
40
- }
1
+ import { chainConfig as a } from "./index78.js";
2
+ import { defineChain as t } from "./index23.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"]
12
+ }
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
+ });
41
56
  export {
42
- d as SignJWT
57
+ r as baseSepolia
43
58
  };
@@ -1,19 +1,43 @@
1
- async function n() {
2
- const e = await window.crypto.subtle.generateKey(
3
- {
4
- name: "ECDSA",
5
- namedCurve: "P-256"
6
- // secp256r1
7
- },
8
- !1,
9
- // Do not allow key export.
10
- ["sign", "verify"]
11
- // Key usages
12
- ), r = await window.crypto.subtle.exportKey("spki", e.publicKey), t = new Uint8Array(r), a = btoa(
13
- Array.from(t).map((i) => String.fromCharCode(i)).join("")
14
- );
15
- return { privateKey: e.privateKey, publicKeyBase64: a };
1
+ import { CompactSign as i } from "./index68.js";
2
+ import { JWTInvalid as r } from "./index69.js";
3
+ import { JWTClaimsBuilder as n } from "./index70.js";
4
+ class d {
5
+ #s;
6
+ #t;
7
+ constructor(t = {}) {
8
+ this.#t = new n(t);
9
+ }
10
+ setIssuer(t) {
11
+ return this.#t.iss = t, this;
12
+ }
13
+ setSubject(t) {
14
+ return this.#t.sub = t, this;
15
+ }
16
+ setAudience(t) {
17
+ return this.#t.aud = t, this;
18
+ }
19
+ setJti(t) {
20
+ return this.#t.jti = t, this;
21
+ }
22
+ setNotBefore(t) {
23
+ return this.#t.nbf = t, this;
24
+ }
25
+ setExpirationTime(t) {
26
+ return this.#t.exp = t, this;
27
+ }
28
+ setIssuedAt(t) {
29
+ return this.#t.iat = t, this;
30
+ }
31
+ setProtectedHeader(t) {
32
+ return this.#s = t, this;
33
+ }
34
+ async sign(t, e) {
35
+ const s = new i(this.#t.data());
36
+ if (s.setProtectedHeader(this.#s), Array.isArray(this.#s?.crit) && this.#s.crit.includes("b64") && this.#s.b64 === !1)
37
+ throw new r("JWTs MUST NOT use unencoded payload");
38
+ return s.sign(t, e);
39
+ }
16
40
  }
17
41
  export {
18
- n as createKeyPair
42
+ d as SignJWT
19
43
  };