@coinbase/cdp-core 0.0.14 → 0.0.16
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/dist/esm/index.js +27 -19
- package/dist/esm/index11.js +4 -2
- package/dist/esm/index12.js +6 -4
- package/dist/esm/index14.js +14 -12
- package/dist/esm/index2.js +25 -24
- package/dist/esm/index23.js +39 -37
- package/dist/esm/index3.js +60 -59
- package/dist/esm/index4.js +12 -9
- package/dist/esm/index5.js +11 -10
- package/dist/esm/index6.js +4 -3
- package/dist/esm/index7.js +6 -5
- package/dist/esm/index8.js +10 -8
- package/dist/types/index.d.ts +14 -0
- package/package.json +2 -2
package/dist/esm/index.js
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import { exportEvmAccount as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { exportEvmAccount as n, getCurrentUser as m, initialize as E, isSignedIn as a, onAuthStateChange as s, sendEvmTransaction as p, signEvmHash as c, signEvmMessage as d, signEvmTransaction as g, signEvmTypedData as v, signInWithEmail as T, signOut as A, verifyEmailOTP as f } from "./index2.js";
|
|
2
|
+
import { APIError as x, ErrorType as h, HttpErrorType as l, SendEvmTransactionWithEndUserAccountBodyNetwork as y } from "@coinbase/cdp-api-client";
|
|
3
|
+
import "viem";
|
|
4
|
+
import { createCDPEmbeddedWallet as P } from "./index3.js";
|
|
5
|
+
import { EIP1193ProviderError as C, STANDARD_ERROR_CODES as I } from "./index4.js";
|
|
6
|
+
import "ox";
|
|
7
|
+
import "zustand";
|
|
8
|
+
import { toViemAccount as R } from "./index5.js";
|
|
5
9
|
export {
|
|
6
|
-
x as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
m as
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
x as APIError,
|
|
11
|
+
C as EIP1193ProviderError,
|
|
12
|
+
h as ErrorType,
|
|
13
|
+
l as HttpErrorType,
|
|
14
|
+
I as STANDARD_ERROR_CODES,
|
|
15
|
+
y as SendEvmTransactionWithEndUserAccountBodyNetwork,
|
|
16
|
+
P as createCDPEmbeddedWallet,
|
|
17
|
+
n as exportEvmAccount,
|
|
18
|
+
m as getCurrentUser,
|
|
19
|
+
E as initialize,
|
|
20
|
+
a as isSignedIn,
|
|
21
|
+
s as onAuthStateChange,
|
|
22
|
+
p as sendEvmTransaction,
|
|
23
|
+
c as signEvmHash,
|
|
24
|
+
d as signEvmMessage,
|
|
17
25
|
g as signEvmTransaction,
|
|
18
26
|
v as signEvmTypedData,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
T as signInWithEmail,
|
|
28
|
+
A as signOut,
|
|
29
|
+
R as toViemAccount,
|
|
30
|
+
f as verifyEmailOTP
|
|
23
31
|
};
|
package/dist/esm/index11.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import "@coinbase/cdp-api-client";
|
|
2
|
+
import "viem";
|
|
1
3
|
import { mockUser as e } from "./index12.js";
|
|
2
|
-
class
|
|
4
|
+
class r {
|
|
3
5
|
authState = null;
|
|
4
6
|
authStateChangeCallback = null;
|
|
5
7
|
/**
|
|
@@ -115,5 +117,5 @@ class h {
|
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
export {
|
|
118
|
-
|
|
120
|
+
r as MockAuthManager
|
|
119
121
|
};
|
package/dist/esm/index12.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import "@coinbase/cdp-api-client";
|
|
2
|
+
import "viem";
|
|
3
|
+
const t = "0x0000000000000000000000000000000000000000", s = {
|
|
2
4
|
userId: "mock-user-id",
|
|
3
|
-
evmAccounts: [
|
|
5
|
+
evmAccounts: [t],
|
|
4
6
|
authenticationMethods: {
|
|
5
7
|
email: {
|
|
6
8
|
type: "email",
|
|
@@ -9,6 +11,6 @@ const e = "0x0000000000000000000000000000000000000000", t = {
|
|
|
9
11
|
}
|
|
10
12
|
};
|
|
11
13
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
t as mockAddress,
|
|
15
|
+
s as mockUser
|
|
14
16
|
};
|
package/dist/esm/index14.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import "@coinbase/cdp-api-client";
|
|
2
|
+
import "viem";
|
|
3
|
+
let n = null, r = null;
|
|
4
|
+
const i = (t) => {
|
|
3
5
|
n = t;
|
|
4
|
-
},
|
|
6
|
+
}, a = () => {
|
|
5
7
|
if (!n)
|
|
6
8
|
throw new Error("SDK not initialized");
|
|
7
9
|
return n;
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
if (!
|
|
10
|
+
}, g = (t) => {
|
|
11
|
+
r = t;
|
|
12
|
+
}, l = () => {
|
|
13
|
+
if (!r)
|
|
12
14
|
throw new Error("SDK not initialized");
|
|
13
|
-
return
|
|
15
|
+
return r;
|
|
14
16
|
};
|
|
15
17
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
a as getConfig,
|
|
19
|
+
l as getCoreAuthManager,
|
|
20
|
+
i as setConfig,
|
|
21
|
+
g as setCoreAuthManager
|
|
20
22
|
};
|
package/dist/esm/index2.js
CHANGED
|
@@ -8,8 +8,9 @@ import { MockAuthManager as C } from "./index11.js";
|
|
|
8
8
|
import { mockUser as d } from "./index12.js";
|
|
9
9
|
import { isChainSupportedForCDPSends as T } from "./index13.js";
|
|
10
10
|
import { getConfig as r, setCoreAuthManager as g, getCoreAuthManager as n, setConfig as j } from "./index14.js";
|
|
11
|
+
import "viem";
|
|
11
12
|
import { serializeTransaction as m } from "./index15.js";
|
|
12
|
-
const
|
|
13
|
+
const q = async (e) => {
|
|
13
14
|
if (!e.projectId)
|
|
14
15
|
throw new Error("Project ID is required");
|
|
15
16
|
let s;
|
|
@@ -30,7 +31,7 @@ const $ = async (e) => {
|
|
|
30
31
|
g(t), w(t);
|
|
31
32
|
}
|
|
32
33
|
await n().ensureInitialized();
|
|
33
|
-
},
|
|
34
|
+
}, B = async (e) => {
|
|
34
35
|
if (r().useMock)
|
|
35
36
|
return {
|
|
36
37
|
message: "Mock sign in initiated",
|
|
@@ -46,7 +47,7 @@ const $ = async (e) => {
|
|
|
46
47
|
flowId: t.flowId,
|
|
47
48
|
message: t.message
|
|
48
49
|
};
|
|
49
|
-
},
|
|
50
|
+
}, V = async (e) => {
|
|
50
51
|
if (r().useMock)
|
|
51
52
|
return await n().setAuthState({
|
|
52
53
|
accessToken: "mock-access-token",
|
|
@@ -80,7 +81,7 @@ const $ = async (e) => {
|
|
|
80
81
|
user: c,
|
|
81
82
|
isNewUser: t.isNewEndUser
|
|
82
83
|
};
|
|
83
|
-
},
|
|
84
|
+
}, G = async () => n().getUser(), J = async () => n().isSignedIn(), L = async () => {
|
|
84
85
|
if (r().useMock) {
|
|
85
86
|
await n().signOut();
|
|
86
87
|
return;
|
|
@@ -88,15 +89,15 @@ const $ = async (e) => {
|
|
|
88
89
|
if (!await n().isSignedIn())
|
|
89
90
|
throw new Error("User not signed in");
|
|
90
91
|
await n().signOut();
|
|
91
|
-
},
|
|
92
|
+
}, Q = (e) => {
|
|
92
93
|
n().addAuthStateChangeCallback(e);
|
|
93
|
-
},
|
|
94
|
+
}, R = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
94
95
|
signature: (await I(r().projectId, s.userId, {
|
|
95
96
|
hash: e.hash,
|
|
96
97
|
address: e.evmAccount,
|
|
97
98
|
walletSecretId: t
|
|
98
99
|
})).signature
|
|
99
|
-
})),
|
|
100
|
+
})), X = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
|
|
100
101
|
const a = m(e.transaction);
|
|
101
102
|
return {
|
|
102
103
|
signedTransaction: (await l(
|
|
@@ -109,7 +110,7 @@ const $ = async (e) => {
|
|
|
109
110
|
}
|
|
110
111
|
)).signedTransaction
|
|
111
112
|
};
|
|
112
|
-
}),
|
|
113
|
+
}), Y = async (e) => {
|
|
113
114
|
if (!T(e.network))
|
|
114
115
|
throw new Error(`Chain ${e.network} is not supported by the CDP Apis`);
|
|
115
116
|
if (r().useMock)
|
|
@@ -127,19 +128,19 @@ const $ = async (e) => {
|
|
|
127
128
|
}
|
|
128
129
|
)).transactionHash
|
|
129
130
|
}));
|
|
130
|
-
},
|
|
131
|
+
}, Z = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
131
132
|
signature: (await A(r().projectId, s.userId, {
|
|
132
133
|
message: e.message,
|
|
133
134
|
address: e.evmAccount,
|
|
134
135
|
walletSecretId: t
|
|
135
136
|
})).signature
|
|
136
|
-
})),
|
|
137
|
+
})), _ = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
137
138
|
signature: (await E(r().projectId, s.userId, {
|
|
138
139
|
typedData: e.typedData,
|
|
139
140
|
address: e.evmAccount,
|
|
140
141
|
walletSecretId: t
|
|
141
142
|
})).signature
|
|
142
|
-
})),
|
|
143
|
+
})), ee = async (e) => {
|
|
143
144
|
if (r().useMock)
|
|
144
145
|
return {
|
|
145
146
|
privateKey: "mock-private-key"
|
|
@@ -160,17 +161,17 @@ const $ = async (e) => {
|
|
|
160
161
|
});
|
|
161
162
|
};
|
|
162
163
|
export {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
164
|
+
ee as exportEvmAccount,
|
|
165
|
+
G as getCurrentUser,
|
|
166
|
+
q as initialize,
|
|
167
|
+
J as isSignedIn,
|
|
168
|
+
Q as onAuthStateChange,
|
|
169
|
+
Y as sendEvmTransaction,
|
|
170
|
+
R as signEvmHash,
|
|
171
|
+
Z as signEvmMessage,
|
|
172
|
+
X as signEvmTransaction,
|
|
173
|
+
_ as signEvmTypedData,
|
|
174
|
+
B as signInWithEmail,
|
|
175
|
+
L as signOut,
|
|
176
|
+
V as verifyEmailOTP
|
|
176
177
|
};
|
package/dist/esm/index23.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createWalletClient as
|
|
3
|
-
import { signEvmTypedData as
|
|
1
|
+
import { Hex as y } from "ox";
|
|
2
|
+
import { createWalletClient as I } from "viem";
|
|
3
|
+
import { signEvmTypedData as E, signEvmHash as S, getCurrentUser as f, signOut as P, sendEvmTransaction as R, signEvmTransaction as T, signEvmMessage as A } from "./index2.js";
|
|
4
|
+
import "@coinbase/cdp-api-client";
|
|
4
5
|
import "./index3.js";
|
|
5
|
-
import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as o, validateUserHasEvmAccount as
|
|
6
|
-
import
|
|
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";
|
|
7
9
|
function g(e) {
|
|
8
10
|
return {
|
|
9
11
|
to: e.to,
|
|
@@ -16,21 +18,21 @@ function g(e) {
|
|
|
16
18
|
type: "eip1559"
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
|
-
async function
|
|
21
|
+
async function M() {
|
|
20
22
|
return (await f())?.evmAccounts || [];
|
|
21
23
|
}
|
|
22
|
-
async function
|
|
23
|
-
const a = await
|
|
24
|
+
async function _(e, n) {
|
|
25
|
+
const a = await C();
|
|
24
26
|
return e.emit("connect", {
|
|
25
|
-
chainId:
|
|
27
|
+
chainId: y.fromNumber(n.getState().chainId)
|
|
26
28
|
}), a.evmAccounts || [];
|
|
27
29
|
}
|
|
28
|
-
async function
|
|
30
|
+
async function k(e) {
|
|
29
31
|
const [n, a] = e;
|
|
30
32
|
await m(a);
|
|
31
33
|
const t = Buffer.from(n.slice(2), "hex").toString();
|
|
32
34
|
try {
|
|
33
|
-
return (await
|
|
35
|
+
return (await A({
|
|
34
36
|
evmAccount: a,
|
|
35
37
|
message: t
|
|
36
38
|
})).signature;
|
|
@@ -41,11 +43,11 @@ async function _(e) {
|
|
|
41
43
|
);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
|
-
async function
|
|
46
|
+
async function z(e) {
|
|
45
47
|
const [n, a] = e;
|
|
46
48
|
await m(n);
|
|
47
49
|
try {
|
|
48
|
-
return (await
|
|
50
|
+
return (await E({
|
|
49
51
|
evmAccount: n,
|
|
50
52
|
typedData: JSON.parse(a)
|
|
51
53
|
})).signature;
|
|
@@ -56,7 +58,7 @@ async function k(e) {
|
|
|
56
58
|
);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
async function
|
|
61
|
+
async function J(e, n, a) {
|
|
60
62
|
const [t] = e;
|
|
61
63
|
if (!t || typeof t != "object")
|
|
62
64
|
throw new o(
|
|
@@ -68,18 +70,18 @@ async function z(e, n, a) {
|
|
|
68
70
|
s.rpc.invalidParams,
|
|
69
71
|
"Transaction must include 'to' field"
|
|
70
72
|
);
|
|
71
|
-
const d = (await
|
|
73
|
+
const d = (await x()).evmAccounts?.[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
|
|
72
74
|
if (!d)
|
|
73
75
|
throw new o(
|
|
74
76
|
s.rpc.invalidParams,
|
|
75
77
|
"User does not have an EVM account"
|
|
76
78
|
);
|
|
77
|
-
if (
|
|
79
|
+
if (D(i))
|
|
78
80
|
try {
|
|
79
|
-
return (await
|
|
81
|
+
return (await R({
|
|
80
82
|
evmAccount: d,
|
|
81
83
|
transaction: { ...g(t), chainId: i },
|
|
82
|
-
network:
|
|
84
|
+
network: b[i]
|
|
83
85
|
})).transactionHash;
|
|
84
86
|
} catch (r) {
|
|
85
87
|
throw console.log("Transaction failed", r), new o(
|
|
@@ -89,18 +91,18 @@ async function z(e, n, a) {
|
|
|
89
91
|
}
|
|
90
92
|
else
|
|
91
93
|
try {
|
|
92
|
-
const r =
|
|
94
|
+
const r = I({
|
|
93
95
|
// Safe as we check before calling this handler that chainId is configured
|
|
94
96
|
chain: u.chains.find((h) => h.id === i),
|
|
95
97
|
transport: a[i],
|
|
96
98
|
account: d
|
|
97
|
-
}),
|
|
99
|
+
}), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
|
|
98
100
|
...g(t),
|
|
99
|
-
chain:
|
|
100
|
-
}), v = await
|
|
101
|
+
chain: p
|
|
102
|
+
}), v = await T({
|
|
101
103
|
evmAccount: d,
|
|
102
104
|
transaction: {
|
|
103
|
-
...
|
|
105
|
+
...w,
|
|
104
106
|
type: "eip1559"
|
|
105
107
|
}
|
|
106
108
|
});
|
|
@@ -114,7 +116,7 @@ async function z(e, n, a) {
|
|
|
114
116
|
);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
async function
|
|
119
|
+
async function V(e) {
|
|
118
120
|
const [n, a] = e;
|
|
119
121
|
await m(a);
|
|
120
122
|
try {
|
|
@@ -129,25 +131,25 @@ async function J(e) {
|
|
|
129
131
|
);
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
|
-
async function
|
|
134
|
+
async function W(e) {
|
|
133
135
|
return `0x${e.getState().chainId.toString(16)}`;
|
|
134
136
|
}
|
|
135
|
-
async function
|
|
136
|
-
await f() && await
|
|
137
|
+
async function $() {
|
|
138
|
+
await f() && await P();
|
|
137
139
|
}
|
|
138
|
-
function
|
|
140
|
+
function K(e, n) {
|
|
139
141
|
const a = Number.parseInt(e[0].chainId, 16);
|
|
140
142
|
n.getState().setChainId(a);
|
|
141
143
|
}
|
|
142
144
|
export {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
M as handleAccounts,
|
|
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,
|
|
152
154
|
g as shimProviderTxRequest
|
|
153
155
|
};
|
package/dist/esm/index3.js
CHANGED
|
@@ -1,92 +1,93 @@
|
|
|
1
|
-
import { Provider as
|
|
2
|
-
import { http as
|
|
3
|
-
import { create as
|
|
1
|
+
import { Provider as h } from "ox";
|
|
2
|
+
import { http as p } from "viem";
|
|
3
|
+
import { create as l } from "zustand";
|
|
4
4
|
import { subscribeWithSelector as f, persist as g } from "./index21.js";
|
|
5
|
-
import { validateRequest as
|
|
5
|
+
import { validateRequest as w, EIP1193ProviderError as I, STANDARD_ERROR_CODES as S } from "./index4.js";
|
|
6
6
|
import { EventEmitter as b } from "./index22.js";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(
|
|
14
|
-
|
|
7
|
+
import "@coinbase/cdp-api-client";
|
|
8
|
+
import { handleChainId as A, handleSignTypedData as C, handleEthSign as _, handleSwitchEthereumChain as v, handleDisconnect as D, handleSendTransaction as E, handlePersonalSign as P, handleRequestAccounts as R, handleAccounts as y } from "./index23.js";
|
|
9
|
+
import { onAuthStateChange as T } from "./index2.js";
|
|
10
|
+
import { baseSepolia as d } from "./index24.js";
|
|
11
|
+
function q(r, e, a) {
|
|
12
|
+
e.subscribe(
|
|
13
|
+
(t) => t.chainId,
|
|
14
|
+
(t, n) => {
|
|
15
|
+
t !== n && r.emit("chainChanged", t);
|
|
15
16
|
}
|
|
16
|
-
),
|
|
17
|
-
(
|
|
18
|
-
(
|
|
19
|
-
if (!(
|
|
20
|
-
if (!
|
|
21
|
-
|
|
17
|
+
), e.subscribe(
|
|
18
|
+
(t) => t.user,
|
|
19
|
+
(t, n) => {
|
|
20
|
+
if (!(t?.userId === n?.userId && t?.evmAccounts?.length === n?.evmAccounts?.length)) {
|
|
21
|
+
if (!t && n) {
|
|
22
|
+
r.emit("disconnect", new h.DisconnectedError());
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
if (t && t.evmAccounts?.length && (!n || n.evmAccounts?.length === 0)) {
|
|
26
|
+
const m = e.getState().chainId;
|
|
27
|
+
r.emit("connect", { chainId: m });
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
);
|
|
32
|
-
const { chainId:
|
|
33
|
-
return
|
|
34
|
-
request: async (
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
switch (
|
|
33
|
+
const { chainId: i, setChainId: o } = e.getState(), c = i || a.chains[0].id;
|
|
34
|
+
return i || o(c), h.from({
|
|
35
|
+
request: async (t) => {
|
|
36
|
+
w(t, a);
|
|
37
|
+
const n = t;
|
|
38
|
+
switch (n.method) {
|
|
38
39
|
case "eth_accounts":
|
|
39
|
-
return
|
|
40
|
+
return y();
|
|
40
41
|
case "eth_requestAccounts":
|
|
41
|
-
return
|
|
42
|
+
return R(r, e);
|
|
42
43
|
case "personal_sign":
|
|
43
|
-
return
|
|
44
|
+
return P(n.params);
|
|
44
45
|
case "eth_sendTransaction":
|
|
45
|
-
return
|
|
46
|
+
return E(n.params, e, a.transports);
|
|
46
47
|
case "wallet_disconnect":
|
|
47
|
-
return D(
|
|
48
|
+
return D();
|
|
48
49
|
case "wallet_switchEthereumChain":
|
|
49
|
-
return v(
|
|
50
|
+
return v(n.params, e);
|
|
50
51
|
case "eth_sign":
|
|
51
|
-
return _(
|
|
52
|
+
return _(n.params);
|
|
52
53
|
case "eth_signTypedData_v4":
|
|
53
|
-
return C(
|
|
54
|
+
return C(n.params);
|
|
54
55
|
case "eth_chainId":
|
|
55
|
-
return A(
|
|
56
|
+
return A(e);
|
|
56
57
|
// Catch-all for any unknown method
|
|
57
58
|
default:
|
|
58
|
-
throw new
|
|
59
|
-
|
|
60
|
-
`Method ${
|
|
59
|
+
throw new I(
|
|
60
|
+
S.provider.unsupportedMethod,
|
|
61
|
+
`Method ${n.method} not supported`
|
|
61
62
|
);
|
|
62
63
|
}
|
|
63
64
|
},
|
|
64
65
|
// Event emitter methods - only the ones required by the interface
|
|
65
|
-
on:
|
|
66
|
-
removeListener:
|
|
66
|
+
on: r.on.bind(r),
|
|
67
|
+
removeListener: r.removeListener.bind(r)
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
-
chains: [
|
|
70
|
+
const u = {
|
|
71
|
+
chains: [d],
|
|
71
72
|
transports: {
|
|
72
|
-
[
|
|
73
|
+
[d.id]: p()
|
|
73
74
|
}
|
|
74
75
|
};
|
|
75
|
-
function
|
|
76
|
-
if (
|
|
76
|
+
function B(r) {
|
|
77
|
+
if (r?.chains.length === 0)
|
|
77
78
|
throw new Error("At least one chain must be configured");
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
79
|
+
const e = r?.chains ?? u.chains, a = r?.transports ?? u.transports;
|
|
80
|
+
if (e.length === 0)
|
|
80
81
|
throw new Error("No chains found in configuration");
|
|
81
|
-
const
|
|
82
|
+
const i = new b(), o = l()(
|
|
82
83
|
f(
|
|
83
84
|
g(
|
|
84
|
-
(
|
|
85
|
-
chainId:
|
|
86
|
-
setChainId: (
|
|
87
|
-
chains:
|
|
85
|
+
(s) => ({
|
|
86
|
+
chainId: e[0].id,
|
|
87
|
+
setChainId: (t) => s({ chainId: t }),
|
|
88
|
+
chains: e,
|
|
88
89
|
user: null,
|
|
89
|
-
setUser: (
|
|
90
|
+
setUser: (t) => s({ user: t })
|
|
90
91
|
}),
|
|
91
92
|
{
|
|
92
93
|
name: "cdp-provider-store"
|
|
@@ -95,15 +96,15 @@ function z(e) {
|
|
|
95
96
|
)
|
|
96
97
|
)
|
|
97
98
|
);
|
|
98
|
-
return
|
|
99
|
-
|
|
99
|
+
return o.persist.rehydrate(), T((s) => {
|
|
100
|
+
o.getState().setUser(s);
|
|
100
101
|
}), {
|
|
101
|
-
provider:
|
|
102
|
-
chains:
|
|
102
|
+
provider: q(i, o, {
|
|
103
|
+
chains: e,
|
|
103
104
|
transports: a
|
|
104
105
|
})
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
export {
|
|
108
|
-
|
|
109
|
+
B as createCDPEmbeddedWallet
|
|
109
110
|
};
|
package/dist/esm/index4.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import "ox";
|
|
2
|
+
import "viem";
|
|
3
|
+
import "zustand";
|
|
4
|
+
import "@coinbase/cdp-api-client";
|
|
1
5
|
import { getCurrentUser as u } from "./index2.js";
|
|
2
6
|
import "./index3.js";
|
|
3
|
-
import "viem";
|
|
4
7
|
const n = {
|
|
5
8
|
rpc: {
|
|
6
9
|
invalidInput: -32e3,
|
|
@@ -54,7 +57,7 @@ class a extends Error {
|
|
|
54
57
|
super(r), this.code = t;
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
const
|
|
60
|
+
const p = /* @__PURE__ */ new Set([
|
|
58
61
|
"eth_accounts",
|
|
59
62
|
"eth_requestAccounts",
|
|
60
63
|
"personal_sign",
|
|
@@ -65,7 +68,7 @@ const h = /* @__PURE__ */ new Set([
|
|
|
65
68
|
"wallet_disconnect",
|
|
66
69
|
"wallet_switchEthereumChain"
|
|
67
70
|
]);
|
|
68
|
-
function
|
|
71
|
+
function E(e, { chains: t }) {
|
|
69
72
|
const { method: r, params: s } = e;
|
|
70
73
|
if (typeof r != "string" || r.length === 0)
|
|
71
74
|
throw new a(
|
|
@@ -83,7 +86,7 @@ function l(e, { chains: t }) {
|
|
|
83
86
|
n.rpc.invalidParams,
|
|
84
87
|
"'params' must be an array if provided."
|
|
85
88
|
);
|
|
86
|
-
if (!
|
|
89
|
+
if (!p.has(r))
|
|
87
90
|
throw new o(
|
|
88
91
|
n.provider.unsupportedMethod,
|
|
89
92
|
`Method ${e.method} not supported`
|
|
@@ -98,7 +101,7 @@ async function d() {
|
|
|
98
101
|
);
|
|
99
102
|
return e;
|
|
100
103
|
}
|
|
101
|
-
async function
|
|
104
|
+
async function _(e) {
|
|
102
105
|
const t = await d();
|
|
103
106
|
if (!t.evmAccounts?.includes(e))
|
|
104
107
|
throw new o(
|
|
@@ -107,7 +110,7 @@ async function w(e) {
|
|
|
107
110
|
);
|
|
108
111
|
return t;
|
|
109
112
|
}
|
|
110
|
-
async function
|
|
113
|
+
async function R() {
|
|
111
114
|
const e = await d();
|
|
112
115
|
if (!e.evmAccounts?.[0])
|
|
113
116
|
throw new o(
|
|
@@ -120,8 +123,8 @@ export {
|
|
|
120
123
|
o as EIP1193ProviderError,
|
|
121
124
|
a as RPCRequestError,
|
|
122
125
|
n as STANDARD_ERROR_CODES,
|
|
123
|
-
|
|
126
|
+
E as validateRequest,
|
|
124
127
|
d as validateUserConnected,
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
R as validateUserHasEvmAccount,
|
|
129
|
+
_ as validateUserOwnsAddress
|
|
127
130
|
};
|
package/dist/esm/index5.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { getTypesForEIP712Domain as a } from "viem";
|
|
2
2
|
import { getCurrentUser as s, signEvmHash as i, signEvmTypedData as c, signEvmTransaction as u, signEvmMessage as m } from "./index2.js";
|
|
3
|
+
import "@coinbase/cdp-api-client";
|
|
3
4
|
import { toAccount as g } from "./index16.js";
|
|
4
|
-
async function w(
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
5
|
+
async function w(r) {
|
|
6
|
+
const n = await s();
|
|
7
|
+
if (!n || !n.evmAccounts || n.evmAccounts.length === 0)
|
|
7
8
|
throw new Error(
|
|
8
9
|
"No accounts found - user must be authenticated and have at least one EVM account"
|
|
9
10
|
);
|
|
10
|
-
if (!
|
|
11
|
-
throw new Error(`Cannot sign for address ${
|
|
11
|
+
if (!n.evmAccounts.includes(r))
|
|
12
|
+
throw new Error(`Cannot sign for address ${r} - not authorized for this account`);
|
|
12
13
|
return g({
|
|
13
|
-
address:
|
|
14
|
+
address: r,
|
|
14
15
|
/**
|
|
15
16
|
* Signs a message using CDP's message signing functionality.
|
|
16
17
|
* Supports string messages, hex strings, and byte arrays.
|
|
@@ -28,7 +29,7 @@ async function w(n) {
|
|
|
28
29
|
else
|
|
29
30
|
throw new Error("Unsupported message format");
|
|
30
31
|
return (await m({
|
|
31
|
-
evmAccount:
|
|
32
|
+
evmAccount: r,
|
|
32
33
|
message: t
|
|
33
34
|
})).signature;
|
|
34
35
|
},
|
|
@@ -49,7 +50,7 @@ async function w(n) {
|
|
|
49
50
|
chainId: e.chainId ?? 1
|
|
50
51
|
};
|
|
51
52
|
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:
|
|
53
|
+
evmAccount: r,
|
|
53
54
|
transaction: t
|
|
54
55
|
})).signedTransaction;
|
|
55
56
|
},
|
|
@@ -73,7 +74,7 @@ async function w(n) {
|
|
|
73
74
|
message: e.message
|
|
74
75
|
};
|
|
75
76
|
return (await c({
|
|
76
|
-
evmAccount:
|
|
77
|
+
evmAccount: r,
|
|
77
78
|
typedData: t
|
|
78
79
|
})).signature;
|
|
79
80
|
},
|
|
@@ -85,7 +86,7 @@ async function w(n) {
|
|
|
85
86
|
*/
|
|
86
87
|
async sign(e) {
|
|
87
88
|
return (await i({
|
|
88
|
-
evmAccount:
|
|
89
|
+
evmAccount: r,
|
|
89
90
|
hash: e.hash
|
|
90
91
|
})).signature;
|
|
91
92
|
}
|
package/dist/esm/index6.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { logOutEndUser as c, refreshAccessToken as o, registerTemporaryWalletSecret as u } from "@coinbase/cdp-api-client";
|
|
2
2
|
import { SignJWT as S } from "./index17.js";
|
|
3
|
+
import "viem";
|
|
3
4
|
import { toAuthState as w } from "./index7.js";
|
|
4
5
|
import { createKeyPair as f } from "./index18.js";
|
|
5
6
|
import { generateRandomId as n } from "./index19.js";
|
|
6
7
|
import { hash as d } from "./index20.js";
|
|
7
8
|
import { sortKeys as y } from "./index13.js";
|
|
8
9
|
const h = 60 * 1e3;
|
|
9
|
-
class
|
|
10
|
+
class P {
|
|
10
11
|
projectId;
|
|
11
12
|
authState = null;
|
|
12
13
|
walletSecret = null;
|
|
@@ -156,7 +157,7 @@ class E {
|
|
|
156
157
|
);
|
|
157
158
|
await this.setAuthState(e);
|
|
158
159
|
} catch {
|
|
159
|
-
await this.
|
|
160
|
+
await this.signOut();
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
/**
|
|
@@ -190,5 +191,5 @@ class E {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
export {
|
|
193
|
-
|
|
194
|
+
P as AuthManager
|
|
194
195
|
};
|
package/dist/esm/index7.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import "@coinbase/cdp-api-client";
|
|
2
|
+
const c = (s, u, e) => {
|
|
3
|
+
const n = new Date(u).getTime(), r = {
|
|
3
4
|
userId: e.userId,
|
|
4
5
|
evmAccounts: e.evmAccounts?.map((t) => t) ?? [],
|
|
5
|
-
authenticationMethods: e.authenticationMethods.reduce((t,
|
|
6
|
+
authenticationMethods: e.authenticationMethods.reduce((t, o) => (t[o.type] = o, t), {})
|
|
6
7
|
};
|
|
7
8
|
return {
|
|
8
|
-
accessToken:
|
|
9
|
-
expiresAt:
|
|
9
|
+
accessToken: s,
|
|
10
|
+
expiresAt: n,
|
|
10
11
|
user: r
|
|
11
12
|
};
|
|
12
13
|
};
|
package/dist/esm/index8.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "@coinbase/cdp-api-client";
|
|
2
|
+
import "viem";
|
|
3
|
+
const c = async (t) => await t.isSignedIn();
|
|
4
|
+
async function a(t, n, r) {
|
|
5
|
+
if (!await c(n))
|
|
4
6
|
throw new Error("User not signed in");
|
|
5
7
|
const e = await n.getUser();
|
|
6
|
-
if (!e.evmAccounts?.find((
|
|
8
|
+
if (!e.evmAccounts?.find((o) => o === t.evmAccount))
|
|
7
9
|
throw new Error("EVM account not found");
|
|
8
|
-
const
|
|
9
|
-
return r({ ...t, user: e, walletSecretId:
|
|
10
|
+
const i = await n.getWalletSecretId();
|
|
11
|
+
return r({ ...t, user: e, walletSecretId: i });
|
|
10
12
|
}
|
|
11
13
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
c as isSignedIn,
|
|
15
|
+
a as withAuth
|
|
14
16
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Address } from 'viem';
|
|
2
|
+
import { APIError } from '@coinbase/cdp-api-client';
|
|
3
|
+
import { APIErrorType } from '@coinbase/cdp-api-client';
|
|
2
4
|
import { Chain } from 'viem/chains';
|
|
3
5
|
import { Chain as Chain_2 } from 'viem';
|
|
6
|
+
import { ErrorType } from '@coinbase/cdp-api-client';
|
|
7
|
+
import { HttpErrorType } from '@coinbase/cdp-api-client';
|
|
4
8
|
import { LocalAccount } from 'viem';
|
|
5
9
|
import { Mutate } from 'zustand';
|
|
6
10
|
import { Provider } from 'ox';
|
|
@@ -16,6 +20,10 @@ export declare type AccountsRequest = {
|
|
|
16
20
|
|
|
17
21
|
export declare type AllowedEvmTransactionType = TransactionSerializableEIP1559;
|
|
18
22
|
|
|
23
|
+
export { APIError }
|
|
24
|
+
|
|
25
|
+
export { APIErrorType }
|
|
26
|
+
|
|
19
27
|
export declare type AuthenticationMethod = EmailAuthentication;
|
|
20
28
|
|
|
21
29
|
export declare type AuthenticationMethods = {
|
|
@@ -84,6 +92,8 @@ export declare type EmailAuthentication = {
|
|
|
84
92
|
email: string;
|
|
85
93
|
};
|
|
86
94
|
|
|
95
|
+
export { ErrorType }
|
|
96
|
+
|
|
87
97
|
export declare type EthSignRequest = {
|
|
88
98
|
method: "eth_sign";
|
|
89
99
|
params: [Hex, EvmAddress];
|
|
@@ -109,6 +119,8 @@ export declare const getCurrentUser: () => Promise<User | null>;
|
|
|
109
119
|
|
|
110
120
|
export declare type Hex = `0x${string}`;
|
|
111
121
|
|
|
122
|
+
export { HttpErrorType }
|
|
123
|
+
|
|
112
124
|
export declare const initialize: (cfg: Config) => Promise<void>;
|
|
113
125
|
|
|
114
126
|
export declare const isSignedIn: () => Promise<boolean>;
|
|
@@ -156,6 +168,8 @@ export declare type SendEvmTransactionResult = {
|
|
|
156
168
|
transactionHash: Hex;
|
|
157
169
|
};
|
|
158
170
|
|
|
171
|
+
export { SendEvmTransactionWithEndUserAccountBodyNetwork }
|
|
172
|
+
|
|
159
173
|
export declare type SendTransactionRequest = {
|
|
160
174
|
method: "eth_sendTransaction";
|
|
161
175
|
params: SendTransactionRequestParams;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"ox": "0.8.1",
|
|
18
18
|
"viem": "^2.33.0",
|
|
19
19
|
"zustand": "^5.0.6",
|
|
20
|
-
"@coinbase/cdp-api-client": "^0.0.
|
|
20
|
+
"@coinbase/cdp-api-client": "^0.0.16"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@size-limit/preset-big-lib": "^11.2.0",
|