@coinbase/cdp-core 0.0.20 → 0.0.21
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.
- package/README.md +75 -1
- package/dist/esm/index.js +29 -27
- package/dist/esm/index103.js +1 -1
- package/dist/esm/index15.js +8 -8
- package/dist/esm/index16.js +2 -2
- package/dist/esm/index17.js +39 -158
- package/dist/esm/index18.js +16 -47
- package/dist/esm/index19.js +4 -152
- package/dist/esm/index2.js +154 -87
- package/dist/esm/index20.js +5 -56
- package/dist/esm/index21.js +158 -39
- package/dist/esm/index22.js +47 -16
- package/dist/esm/index23.js +152 -4
- package/dist/esm/index24.js +56 -5
- package/dist/esm/index25.js +8 -12
- package/dist/esm/index26.js +17 -11
- package/dist/esm/index27.js +45 -8
- package/dist/esm/index28.js +13 -17
- package/dist/esm/index29.js +50 -40
- package/dist/esm/index3.js +4 -4
- package/dist/esm/index30.js +6 -13
- package/dist/esm/index31.js +20 -54
- package/dist/esm/index32.js +11 -6
- package/dist/esm/index33.js +3 -21
- package/dist/esm/index34.js +3 -3
- package/dist/esm/index35.js +34 -3
- package/dist/esm/index36.js +10 -32
- package/dist/esm/index37.js +4 -12
- package/dist/esm/index38.js +28 -4
- package/dist/esm/index39.js +6 -28
- package/dist/esm/index40.js +24 -6
- package/dist/esm/index41.js +16 -24
- package/dist/esm/index42.js +54 -16
- package/dist/esm/index43.js +22 -53
- package/dist/esm/index44.js +11 -23
- package/dist/esm/index45.js +26 -10
- package/dist/esm/index46.js +41 -26
- package/dist/esm/index47.js +54 -41
- package/dist/esm/index48.js +126 -54
- package/dist/esm/index49.js +11 -126
- package/dist/esm/index50.js +101 -9
- package/dist/esm/index51.js +6 -104
- package/dist/esm/index52.js +3 -7
- package/dist/esm/index53.js +15 -3
- package/dist/esm/index54.js +42 -14
- package/dist/esm/index55.js +74 -38
- package/dist/esm/index56.js +2 -79
- package/dist/esm/index57.js +2 -2
- package/dist/esm/index58.js +13 -2
- package/dist/esm/index59.js +2 -2
- package/dist/esm/index6.js +4 -4
- package/dist/esm/index60.js +1 -1
- package/dist/esm/index61.js +1 -1
- package/dist/esm/index62.js +2 -2
- package/dist/esm/index63.js +2 -2
- package/dist/esm/index64.js +1 -1
- package/dist/esm/index65.js +1 -1
- package/dist/esm/index66.js +3 -3
- package/dist/esm/index7.js +7 -6
- package/dist/esm/index70.js +1 -1
- package/dist/esm/index72.js +4 -4
- package/dist/esm/index73.js +2 -104
- package/dist/esm/index74.js +17 -75
- package/dist/esm/index75.js +20 -80
- package/dist/esm/index76.js +80 -2
- package/dist/esm/index77.js +100 -17
- package/dist/esm/index78.js +31 -18
- package/dist/esm/index79.js +6 -32
- package/dist/esm/index8.js +10 -8
- package/dist/esm/index80.js +54 -6
- package/dist/esm/index81.js +11 -10
- package/dist/esm/index82.js +2 -55
- package/dist/esm/index83.js +45 -11
- package/dist/esm/index84.js +14 -2
- package/dist/esm/index85.js +9 -44
- package/dist/esm/index86.js +78 -13
- package/dist/esm/index88.js +20 -12
- package/dist/esm/index89.js +9 -35
- package/dist/esm/index90.js +19 -41
- package/dist/esm/index91.js +93 -20
- package/dist/esm/index92.js +20 -9
- package/dist/esm/index93.js +114 -16
- package/dist/esm/index94.js +11 -92
- package/dist/esm/index95.js +35 -20
- package/dist/esm/index96.js +41 -117
- package/dist/types/index.d.ts +33 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -48,6 +48,24 @@ const config: Config = {
|
|
|
48
48
|
await initialize(config);
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
#### Smart Account Configuration
|
|
52
|
+
|
|
53
|
+
You can configure the SDK to automatically create Smart Accounts for new users by setting `createAccountOnLogin` to `"evm-smart"`:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const config: Config = {
|
|
57
|
+
projectId: "your-project-id",
|
|
58
|
+
createAccountOnLogin: "evm-smart", // Creates Smart Accounts instead of EOAs
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await initialize(config);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When `createAccountOnLogin` is set to `"evm-smart"`, the SDK will:
|
|
65
|
+
1. Create an EOA (Externally Owned Account) first
|
|
66
|
+
2. Use that EOA as the owner to create a Smart Account
|
|
67
|
+
3. Both accounts will be available on the user object
|
|
68
|
+
|
|
51
69
|
### Sign In a User
|
|
52
70
|
|
|
53
71
|
You're now ready to start calling the APIs provided by the package!
|
|
@@ -84,7 +102,8 @@ if (signedIn) {
|
|
|
84
102
|
// Get the user's information
|
|
85
103
|
const user = await getCurrentUser();
|
|
86
104
|
console.log("User ID:", user.userId);
|
|
87
|
-
console.log("EVM Accounts:", user.evmAccounts);
|
|
105
|
+
console.log("EVM Accounts (EOAs):", user.evmAccounts);
|
|
106
|
+
console.log("EVM Smart Accounts:", user.evmSmartAccounts);
|
|
88
107
|
|
|
89
108
|
// Find the user's email address (if they logged in with email/otp)
|
|
90
109
|
const email = user.authenticationMethods.email?.email;
|
|
@@ -163,6 +182,61 @@ const hash = await client.sendRawTransaction({
|
|
|
163
182
|
});
|
|
164
183
|
```
|
|
165
184
|
|
|
185
|
+
### Smart Account Operations
|
|
186
|
+
|
|
187
|
+
Smart Accounts provide advanced account abstraction features, including user operations and paymaster support.
|
|
188
|
+
|
|
189
|
+
#### Send User Operations
|
|
190
|
+
|
|
191
|
+
Send user operations from a Smart Account:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { sendUserOperation, getCurrentUser } from "@coinbase/cdp-core";
|
|
195
|
+
|
|
196
|
+
const user = await getCurrentUser();
|
|
197
|
+
const smartAccount = user.evmSmartAccounts[0];
|
|
198
|
+
|
|
199
|
+
const result = await sendUserOperation({
|
|
200
|
+
evmSmartAccount: smartAccount,
|
|
201
|
+
network: "base-sepolia",
|
|
202
|
+
calls: [
|
|
203
|
+
{
|
|
204
|
+
to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
205
|
+
value: 1000000000000000000n, // 1 ETH in wei
|
|
206
|
+
data: "0x", // Optional contract interaction data
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
// Optional paymaster for gas sponsorship. Get your free Base paymaster URL [from the CDP Portal](https://portal.cdp.coinbase.com/products/node).
|
|
210
|
+
paymasterUrl: "https://paymaster.example.com",
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
console.log("User Operation Hash:", result.userOperationHash);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### Get User Operation Status
|
|
217
|
+
|
|
218
|
+
After sending a user operation, you can get its status and retrieve the result:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { getUserOperation } from "@coinbase/cdp-core";
|
|
222
|
+
|
|
223
|
+
// Get the status of a user operation
|
|
224
|
+
const userOperationResult = await getUserOperation({
|
|
225
|
+
userOperationHash: result.userOperationHash,
|
|
226
|
+
evmSmartAccount: smartAccount,
|
|
227
|
+
network: "base-sepolia"
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
console.log("Status:", userOperationResult.status); // "pending", "complete", or "failed"
|
|
231
|
+
|
|
232
|
+
if (userOperationResult.status === "complete") {
|
|
233
|
+
console.log("Transaction Hash:", userOperationResult.transactionHash);
|
|
234
|
+
console.log("Block Number:", userOperationResult.receipts?.[0]?.blockNumber);
|
|
235
|
+
} else if (userOperationResult.status === "failed") {
|
|
236
|
+
console.log("Failure reason:", userOperationResult.receipts?.[0]?.revert?.message);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
166
240
|
### Sign Messages and Typed Data
|
|
167
241
|
|
|
168
242
|
End users can sign EVM messages, hashes, and typed data to generate signatures for various onchain applications.
|
package/dist/esm/index.js
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import { exportEvmAccount as
|
|
2
|
-
import { APIError as
|
|
1
|
+
import { exportEvmAccount as i, getAccessToken as s, getCurrentUser as m, getUserOperation as a, initialize as E, isSignedIn as p, onAuthStateChange as g, sendEvmTransaction as c, sendUserOperation as d, signEvmHash as v, signEvmMessage as T, signEvmTransaction as A, signEvmTypedData as f, signInWithEmail as O, signInWithSms as S, signOut as h, verifyEmailOTP as u, verifySmsOTP as x } from "./index2.js";
|
|
2
|
+
import { APIError as P, ErrorType as l, HttpErrorType as D, SendEvmTransactionWithEndUserAccountBodyNetwork as I } from "@coinbase/cdp-api-client";
|
|
3
3
|
import "viem";
|
|
4
|
-
import { createCDPEmbeddedWallet as
|
|
5
|
-
import { EIP1193ProviderError as
|
|
4
|
+
import { createCDPEmbeddedWallet as R } from "./index3.js";
|
|
5
|
+
import { EIP1193ProviderError as W, STANDARD_ERROR_CODES as k } from "./index4.js";
|
|
6
6
|
import "ox";
|
|
7
7
|
import "zustand";
|
|
8
|
-
import { toViemAccount as
|
|
8
|
+
import { toViemAccount as N } from "./index5.js";
|
|
9
9
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
P as APIError,
|
|
11
|
+
W as EIP1193ProviderError,
|
|
12
|
+
l as ErrorType,
|
|
13
|
+
D as HttpErrorType,
|
|
14
|
+
k as STANDARD_ERROR_CODES,
|
|
15
|
+
I as SendEvmTransactionWithEndUserAccountBodyNetwork,
|
|
16
|
+
R as createCDPEmbeddedWallet,
|
|
17
|
+
i as exportEvmAccount,
|
|
18
|
+
s as getAccessToken,
|
|
19
|
+
m as getCurrentUser,
|
|
20
|
+
a as getUserOperation,
|
|
20
21
|
E as initialize,
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
p as isSignedIn,
|
|
23
|
+
g as onAuthStateChange,
|
|
23
24
|
c as sendEvmTransaction,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
S as
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
u as
|
|
25
|
+
d as sendUserOperation,
|
|
26
|
+
v as signEvmHash,
|
|
27
|
+
T as signEvmMessage,
|
|
28
|
+
A as signEvmTransaction,
|
|
29
|
+
f as signEvmTypedData,
|
|
30
|
+
O as signInWithEmail,
|
|
31
|
+
S as signInWithSms,
|
|
32
|
+
h as signOut,
|
|
33
|
+
N as toViemAccount,
|
|
34
|
+
u as verifyEmailOTP,
|
|
35
|
+
x as verifySmsOTP
|
|
34
36
|
};
|
package/dist/esm/index103.js
CHANGED
package/dist/esm/index15.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { InvalidLegacyVError as H } from "./
|
|
2
|
-
import { serializeAuthorizationList as g } from "./
|
|
1
|
+
import { InvalidLegacyVError as H } from "./index54.js";
|
|
2
|
+
import { serializeAuthorizationList as g } from "./index26.js";
|
|
3
3
|
import { blobsToCommitments as B } from "./index62.js";
|
|
4
4
|
import { blobsToProofs as V } from "./index63.js";
|
|
5
5
|
import { commitmentsToVersionedHashes as C } from "./index64.js";
|
|
6
6
|
import { toBlobSidecars as k } from "./index65.js";
|
|
7
|
-
import { concatHex as h } from "./
|
|
8
|
-
import { trim as T } from "./
|
|
9
|
-
import { numberToHex as o, bytesToHex as w } from "./
|
|
10
|
-
import { toRlp as b } from "./
|
|
11
|
-
import { assertTransactionEIP1559 as S, assertTransactionEIP2930 as _, assertTransactionEIP4844 as R, assertTransactionEIP7702 as Y, assertTransactionLegacy as j } from "./
|
|
12
|
-
import { getTransactionType as q } from "./
|
|
7
|
+
import { concatHex as h } from "./index33.js";
|
|
8
|
+
import { trim as T } from "./index39.js";
|
|
9
|
+
import { numberToHex as o, bytesToHex as w } from "./index27.js";
|
|
10
|
+
import { toRlp as b } from "./index46.js";
|
|
11
|
+
import { assertTransactionEIP1559 as S, assertTransactionEIP2930 as _, assertTransactionEIP4844 as R, assertTransactionEIP7702 as Y, assertTransactionLegacy as j } from "./index55.js";
|
|
12
|
+
import { getTransactionType as q } from "./index53.js";
|
|
13
13
|
import { serializeAccessList as v } from "./index66.js";
|
|
14
14
|
function te(e, r) {
|
|
15
15
|
const i = q(e);
|
package/dist/esm/index16.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InvalidAddressError as s } from "./
|
|
2
|
-
import { isAddress as a } from "./
|
|
1
|
+
import { InvalidAddressError as s } from "./index58.js";
|
|
2
|
+
import { isAddress as a } from "./index32.js";
|
|
3
3
|
function r(n) {
|
|
4
4
|
if (typeof n == "string") {
|
|
5
5
|
if (!a(n, { strict: !1 }))
|
package/dist/esm/index17.js
CHANGED
|
@@ -1,162 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const u = c(f);
|
|
10
|
-
if (!g(v, u)) {
|
|
11
|
-
const y = v;
|
|
12
|
-
i(v = u, y);
|
|
13
|
-
}
|
|
14
|
-
}, a?.fireImmediately && i(v, v);
|
|
15
|
-
}
|
|
16
|
-
return s(l);
|
|
17
|
-
}, m(h, n, r);
|
|
18
|
-
}, R = H;
|
|
19
|
-
function F(m, h) {
|
|
20
|
-
let n;
|
|
21
|
-
try {
|
|
22
|
-
n = m();
|
|
23
|
-
} catch {
|
|
24
|
-
return;
|
|
1
|
+
import { CompactSign as i } from "./index70.js";
|
|
2
|
+
import { JWTInvalid as r } from "./index71.js";
|
|
3
|
+
import { JWTClaimsBuilder as n } from "./index72.js";
|
|
4
|
+
class d {
|
|
5
|
+
#s;
|
|
6
|
+
#t;
|
|
7
|
+
constructor(t = {}) {
|
|
8
|
+
this.#t = new n(t);
|
|
25
9
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
then(r) {
|
|
41
|
-
return p(r)(n);
|
|
42
|
-
},
|
|
43
|
-
catch(r) {
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
} catch (n) {
|
|
48
|
-
return {
|
|
49
|
-
then(r) {
|
|
50
|
-
return this;
|
|
51
|
-
},
|
|
52
|
-
catch(r) {
|
|
53
|
-
return p(r)(n);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
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;
|
|
56
24
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.warn(
|
|
74
|
-
`[zustand persist middleware] Unable to update item '${e.name}', the given storage is currently unavailable.`
|
|
75
|
-
), n(...t);
|
|
76
|
-
},
|
|
77
|
-
r,
|
|
78
|
-
s
|
|
79
|
-
);
|
|
80
|
-
const g = () => {
|
|
81
|
-
const t = e.partialize({ ...r() });
|
|
82
|
-
return l.setItem(e.name, {
|
|
83
|
-
state: t,
|
|
84
|
-
version: e.version
|
|
85
|
-
});
|
|
86
|
-
}, v = s.setState;
|
|
87
|
-
s.setState = (t, S) => {
|
|
88
|
-
v(t, S), g();
|
|
89
|
-
};
|
|
90
|
-
const f = m(
|
|
91
|
-
(...t) => {
|
|
92
|
-
n(...t), g();
|
|
93
|
-
},
|
|
94
|
-
r,
|
|
95
|
-
s
|
|
96
|
-
);
|
|
97
|
-
s.getInitialState = () => f;
|
|
98
|
-
let u;
|
|
99
|
-
const y = () => {
|
|
100
|
-
var t, S;
|
|
101
|
-
if (!l) return;
|
|
102
|
-
c = !1, i.forEach((o) => {
|
|
103
|
-
var d;
|
|
104
|
-
return o((d = r()) != null ? d : f);
|
|
105
|
-
});
|
|
106
|
-
const b = ((S = e.onRehydrateStorage) == null ? void 0 : S.call(e, (t = r()) != null ? t : f)) || void 0;
|
|
107
|
-
return p(l.getItem.bind(l))(e.name).then((o) => {
|
|
108
|
-
if (o)
|
|
109
|
-
if (typeof o.version == "number" && o.version !== e.version) {
|
|
110
|
-
if (e.migrate) {
|
|
111
|
-
const d = e.migrate(
|
|
112
|
-
o.state,
|
|
113
|
-
o.version
|
|
114
|
-
);
|
|
115
|
-
return d instanceof Promise ? d.then((I) => [!0, I]) : [!0, d];
|
|
116
|
-
}
|
|
117
|
-
console.error(
|
|
118
|
-
"State loaded from storage couldn't be migrated since no migrate function was provided"
|
|
119
|
-
);
|
|
120
|
-
} else
|
|
121
|
-
return [!1, o.state];
|
|
122
|
-
return [!1, void 0];
|
|
123
|
-
}).then((o) => {
|
|
124
|
-
var d;
|
|
125
|
-
const [I, _] = o;
|
|
126
|
-
if (u = e.merge(
|
|
127
|
-
_,
|
|
128
|
-
(d = r()) != null ? d : f
|
|
129
|
-
), n(u, !0), I)
|
|
130
|
-
return g();
|
|
131
|
-
}).then(() => {
|
|
132
|
-
b?.(u, void 0), u = r(), c = !0, a.forEach((o) => o(u));
|
|
133
|
-
}).catch((o) => {
|
|
134
|
-
b?.(void 0, o);
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
return s.persist = {
|
|
138
|
-
setOptions: (t) => {
|
|
139
|
-
e = {
|
|
140
|
-
...e,
|
|
141
|
-
...t
|
|
142
|
-
}, t.storage && (l = t.storage);
|
|
143
|
-
},
|
|
144
|
-
clearStorage: () => {
|
|
145
|
-
l?.removeItem(e.name);
|
|
146
|
-
},
|
|
147
|
-
getOptions: () => e,
|
|
148
|
-
rehydrate: () => y(),
|
|
149
|
-
hasHydrated: () => c,
|
|
150
|
-
onHydrate: (t) => (i.add(t), () => {
|
|
151
|
-
i.delete(t);
|
|
152
|
-
}),
|
|
153
|
-
onFinishHydration: (t) => (a.add(t), () => {
|
|
154
|
-
a.delete(t);
|
|
155
|
-
})
|
|
156
|
-
}, e.skipHydration || y(), u || f;
|
|
157
|
-
}, w = O;
|
|
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
|
+
}
|
|
158
41
|
export {
|
|
159
|
-
|
|
160
|
-
w as persist,
|
|
161
|
-
R as subscribeWithSelector
|
|
42
|
+
d as SignJWT
|
|
162
43
|
};
|
package/dist/esm/index18.js
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
}
|
|
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 };
|
|
47
16
|
}
|
|
48
17
|
export {
|
|
49
|
-
n as
|
|
18
|
+
n as createKeyPair
|
|
50
19
|
};
|
package/dist/esm/index19.js
CHANGED
|
@@ -1,155 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "@coinbase/cdp-api-client";
|
|
5
|
-
import "./index3.js";
|
|
6
|
-
import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as o, validateUserHasEvmAccount as x, validateUserConnected as C } from "./index4.js";
|
|
7
|
-
import "zustand";
|
|
8
|
-
import { isChainIdSupportedForCDPSends as D, chainIdToNameMapping as b } from "./index13.js";
|
|
9
|
-
function g(e) {
|
|
10
|
-
return {
|
|
11
|
-
to: e.to,
|
|
12
|
-
data: e.data,
|
|
13
|
-
value: e.value ? BigInt(e.value) : void 0,
|
|
14
|
-
nonce: e.nonce ? Number(e.nonce) : void 0,
|
|
15
|
-
gas: e.gas ? BigInt(e.gas) : void 0,
|
|
16
|
-
maxFeePerGas: e.maxFeePerGas ? BigInt(e.maxFeePerGas) : void 0,
|
|
17
|
-
maxPriorityFeePerGas: e.maxPriorityFeePerGas ? BigInt(e.maxPriorityFeePerGas) : void 0,
|
|
18
|
-
type: "eip1559"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
async function M() {
|
|
22
|
-
return (await f())?.evmAccounts || [];
|
|
23
|
-
}
|
|
24
|
-
async function _(e, n) {
|
|
25
|
-
const a = await C();
|
|
26
|
-
return e.emit("connect", {
|
|
27
|
-
chainId: y.fromNumber(n.getState().chainId)
|
|
28
|
-
}), a.evmAccounts || [];
|
|
29
|
-
}
|
|
30
|
-
async function k(e) {
|
|
31
|
-
const [n, a] = e;
|
|
32
|
-
await m(a);
|
|
33
|
-
const t = Buffer.from(n.slice(2), "hex").toString();
|
|
34
|
-
try {
|
|
35
|
-
return (await A({
|
|
36
|
-
evmAccount: a,
|
|
37
|
-
message: t
|
|
38
|
-
})).signature;
|
|
39
|
-
} catch (c) {
|
|
40
|
-
throw new l(
|
|
41
|
-
s.provider.userRejectedRequest,
|
|
42
|
-
c instanceof Error ? c.message : "Signing failed"
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async function z(e) {
|
|
47
|
-
const [n, a] = e;
|
|
48
|
-
await m(n);
|
|
49
|
-
try {
|
|
50
|
-
return (await E({
|
|
51
|
-
evmAccount: n,
|
|
52
|
-
typedData: JSON.parse(a)
|
|
53
|
-
})).signature;
|
|
54
|
-
} catch (t) {
|
|
55
|
-
throw new l(
|
|
56
|
-
s.provider.userRejectedRequest,
|
|
57
|
-
t instanceof Error ? t.message : "Signing failed"
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function J(e, n, a) {
|
|
62
|
-
const [t] = e;
|
|
63
|
-
if (!t || typeof t != "object")
|
|
64
|
-
throw new o(
|
|
65
|
-
s.rpc.invalidParams,
|
|
66
|
-
"Transaction parameter must be an object"
|
|
67
|
-
);
|
|
68
|
-
if (!t.to)
|
|
69
|
-
throw new o(
|
|
70
|
-
s.rpc.invalidParams,
|
|
71
|
-
"Transaction must include 'to' field"
|
|
72
|
-
);
|
|
73
|
-
const d = (await x()).evmAccounts?.[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
|
|
74
|
-
if (!d)
|
|
75
|
-
throw new o(
|
|
76
|
-
s.rpc.invalidParams,
|
|
77
|
-
"User does not have an EVM account"
|
|
78
|
-
);
|
|
79
|
-
if (D(i))
|
|
80
|
-
try {
|
|
81
|
-
return (await R({
|
|
82
|
-
evmAccount: d,
|
|
83
|
-
transaction: { ...g(t), chainId: i },
|
|
84
|
-
network: b[i]
|
|
85
|
-
})).transactionHash;
|
|
86
|
-
} catch (r) {
|
|
87
|
-
throw console.log("Transaction failed", r), new o(
|
|
88
|
-
s.rpc.transactionRejected,
|
|
89
|
-
r instanceof Error ? r.message : "Transaction failed"
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
else
|
|
93
|
-
try {
|
|
94
|
-
const r = I({
|
|
95
|
-
// Safe as we check before calling this handler that chainId is configured
|
|
96
|
-
chain: u.chains.find((h) => h.id === i),
|
|
97
|
-
transport: a[i],
|
|
98
|
-
account: d
|
|
99
|
-
}), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
|
|
100
|
-
...g(t),
|
|
101
|
-
chain: p
|
|
102
|
-
}), v = await T({
|
|
103
|
-
evmAccount: d,
|
|
104
|
-
transaction: {
|
|
105
|
-
...w,
|
|
106
|
-
type: "eip1559"
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return await r.sendRawTransaction({
|
|
110
|
-
serializedTransaction: v.signedTransaction
|
|
111
|
-
});
|
|
112
|
-
} catch (r) {
|
|
113
|
-
throw new o(
|
|
114
|
-
s.rpc.transactionRejected,
|
|
115
|
-
r instanceof Error ? r.message : "Transaction failed"
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async function V(e) {
|
|
120
|
-
const [n, a] = e;
|
|
121
|
-
await m(a);
|
|
122
|
-
try {
|
|
123
|
-
return (await S({
|
|
124
|
-
evmAccount: a,
|
|
125
|
-
hash: n
|
|
126
|
-
})).signature;
|
|
127
|
-
} catch (t) {
|
|
128
|
-
throw new l(
|
|
129
|
-
s.provider.userRejectedRequest,
|
|
130
|
-
t instanceof Error ? t.message : "Signing failed"
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function W(e) {
|
|
135
|
-
return `0x${e.getState().chainId.toString(16)}`;
|
|
136
|
-
}
|
|
137
|
-
async function $() {
|
|
138
|
-
await f() && await P();
|
|
139
|
-
}
|
|
140
|
-
function K(e, n) {
|
|
141
|
-
const a = Number.parseInt(e[0].chainId, 16);
|
|
142
|
-
n.getState().setChainId(a);
|
|
1
|
+
async function t() {
|
|
2
|
+
const r = new Uint8Array(16);
|
|
3
|
+
return window.crypto.getRandomValues(r), Array.from(r, (n) => n.toString(16).padStart(2, "0")).join("");
|
|
143
4
|
}
|
|
144
5
|
export {
|
|
145
|
-
|
|
146
|
-
W as handleChainId,
|
|
147
|
-
$ as handleDisconnect,
|
|
148
|
-
V as handleEthSign,
|
|
149
|
-
k as handlePersonalSign,
|
|
150
|
-
_ as handleRequestAccounts,
|
|
151
|
-
J as handleSendTransaction,
|
|
152
|
-
z as handleSignTypedData,
|
|
153
|
-
K as handleSwitchEthereumChain,
|
|
154
|
-
g as shimProviderTxRequest
|
|
6
|
+
t as generateRandomId
|
|
155
7
|
};
|