@coinbase/cdp-core 0.0.16 → 0.0.18
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/index2.js +50 -51
- package/dist/esm/index6.js +34 -35
- package/package.json +2 -2
package/dist/esm/index2.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { configureCdpApiClient as
|
|
2
|
-
import { AuthManager as
|
|
1
|
+
import { configureCdpApiClient as w, setAuthManager as h, initiateAuthentication as y, verifyEmailAuthentication as f, createEndUserEvmAccount as I, signEvmHashWithEndUserAccount as l, signEvmTransactionWithEndUserAccount as A, sendEvmTransactionWithEndUserAccount as v, signEvmMessageWithEndUserAccount as E, signEvmTypedDataWithEndUserAccount as k, exportEndUserEvmAccount as M } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { AuthManager as S } from "./index6.js";
|
|
3
3
|
import { toAuthState as u } from "./index7.js";
|
|
4
4
|
import { withAuth as i } from "./index8.js";
|
|
5
|
-
import { createExportKeyPair as
|
|
6
|
-
import { decryptWithPrivateKey as
|
|
7
|
-
import { MockAuthManager as
|
|
5
|
+
import { createExportKeyPair as U } from "./index9.js";
|
|
6
|
+
import { decryptWithPrivateKey as C } from "./index10.js";
|
|
7
|
+
import { MockAuthManager as T } from "./index11.js";
|
|
8
8
|
import { mockUser as d } from "./index12.js";
|
|
9
|
-
import { isChainSupportedForCDPSends as
|
|
10
|
-
import { getConfig as r, setCoreAuthManager as g, getCoreAuthManager as n, setConfig as
|
|
9
|
+
import { isChainSupportedForCDPSends as j } from "./index13.js";
|
|
10
|
+
import { getConfig as r, setCoreAuthManager as g, getCoreAuthManager as n, setConfig as P } from "./index14.js";
|
|
11
11
|
import "viem";
|
|
12
12
|
import { serializeTransaction as m } from "./index15.js";
|
|
13
|
-
const
|
|
13
|
+
const B = async (e) => {
|
|
14
14
|
if (!e.projectId)
|
|
15
15
|
throw new Error("Project ID is required");
|
|
16
16
|
let s;
|
|
@@ -19,19 +19,19 @@ const q = async (e) => {
|
|
|
19
19
|
} catch {
|
|
20
20
|
s = !0;
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
23
|
-
g(new
|
|
22
|
+
if (P(e), r().useMock) {
|
|
23
|
+
g(new T(r().projectId));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (w({
|
|
27
27
|
debugging: r().debugging,
|
|
28
28
|
basePath: r().basePath
|
|
29
29
|
}), s) {
|
|
30
|
-
const t = new
|
|
31
|
-
g(t),
|
|
30
|
+
const t = new S(r().projectId);
|
|
31
|
+
g(t), h(t);
|
|
32
32
|
}
|
|
33
33
|
await n().ensureInitialized();
|
|
34
|
-
},
|
|
34
|
+
}, V = async (e) => {
|
|
35
35
|
if (r().useMock)
|
|
36
36
|
return {
|
|
37
37
|
message: "Mock sign in initiated",
|
|
@@ -39,7 +39,7 @@ const q = async (e) => {
|
|
|
39
39
|
};
|
|
40
40
|
if (await n().isSignedIn())
|
|
41
41
|
throw new Error("User is already authenticated. Please sign out first.");
|
|
42
|
-
const t = await
|
|
42
|
+
const t = await y(r().projectId, {
|
|
43
43
|
email: e.email,
|
|
44
44
|
type: "email"
|
|
45
45
|
});
|
|
@@ -47,7 +47,7 @@ const q = async (e) => {
|
|
|
47
47
|
flowId: t.flowId,
|
|
48
48
|
message: t.message
|
|
49
49
|
};
|
|
50
|
-
},
|
|
50
|
+
}, G = async (e) => {
|
|
51
51
|
if (r().useMock)
|
|
52
52
|
return await n().setAuthState({
|
|
53
53
|
accessToken: "mock-access-token",
|
|
@@ -60,28 +60,27 @@ const q = async (e) => {
|
|
|
60
60
|
};
|
|
61
61
|
if (await n().isSignedIn())
|
|
62
62
|
throw new Error("User is already authenticated. Please sign out first.");
|
|
63
|
-
const t = await
|
|
63
|
+
const t = await f(r().projectId, {
|
|
64
64
|
flowId: e.flowId,
|
|
65
65
|
otp: e.otp
|
|
66
66
|
});
|
|
67
67
|
let a = u(t.accessToken, t.validUntil, t.endUser);
|
|
68
|
-
if (!a.user.evmAccounts || a.user.evmAccounts.length === 0)
|
|
68
|
+
if (await n().setAuthState(a), !a.user.evmAccounts || a.user.evmAccounts.length === 0)
|
|
69
69
|
try {
|
|
70
|
-
const o = await
|
|
71
|
-
walletSecretId:
|
|
70
|
+
const o = await n().getWalletSecretId(), p = await I(r().projectId, a.user.userId, {
|
|
71
|
+
walletSecretId: o
|
|
72
72
|
});
|
|
73
|
-
a = u(t.accessToken, t.validUntil,
|
|
73
|
+
a = u(t.accessToken, t.validUntil, p), await n().setAuthState(a);
|
|
74
74
|
} catch (o) {
|
|
75
75
|
throw new Error(`Failed to create EVM account: ${o}`);
|
|
76
76
|
}
|
|
77
|
-
await n().setAuthState(a);
|
|
78
77
|
const c = await n().getUser();
|
|
79
78
|
return {
|
|
80
79
|
message: t.message,
|
|
81
80
|
user: c,
|
|
82
81
|
isNewUser: t.isNewEndUser
|
|
83
82
|
};
|
|
84
|
-
},
|
|
83
|
+
}, J = async () => n().getUser(), L = async () => n().isSignedIn(), Q = async () => {
|
|
85
84
|
if (r().useMock) {
|
|
86
85
|
await n().signOut();
|
|
87
86
|
return;
|
|
@@ -89,18 +88,18 @@ const q = async (e) => {
|
|
|
89
88
|
if (!await n().isSignedIn())
|
|
90
89
|
throw new Error("User not signed in");
|
|
91
90
|
await n().signOut();
|
|
92
|
-
},
|
|
91
|
+
}, R = (e) => {
|
|
93
92
|
n().addAuthStateChangeCallback(e);
|
|
94
|
-
},
|
|
95
|
-
signature: (await
|
|
93
|
+
}, X = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
94
|
+
signature: (await l(r().projectId, s.userId, {
|
|
96
95
|
hash: e.hash,
|
|
97
96
|
address: e.evmAccount,
|
|
98
97
|
walletSecretId: t
|
|
99
98
|
})).signature
|
|
100
|
-
})),
|
|
99
|
+
})), Y = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
|
|
101
100
|
const a = m(e.transaction);
|
|
102
101
|
return {
|
|
103
|
-
signedTransaction: (await
|
|
102
|
+
signedTransaction: (await A(
|
|
104
103
|
r().projectId,
|
|
105
104
|
s.userId,
|
|
106
105
|
{
|
|
@@ -110,8 +109,8 @@ const q = async (e) => {
|
|
|
110
109
|
}
|
|
111
110
|
)).signedTransaction
|
|
112
111
|
};
|
|
113
|
-
}),
|
|
114
|
-
if (!
|
|
112
|
+
}), Z = async (e) => {
|
|
113
|
+
if (!j(e.network))
|
|
115
114
|
throw new Error(`Chain ${e.network} is not supported by the CDP Apis`);
|
|
116
115
|
if (r().useMock)
|
|
117
116
|
return { transactionHash: "0x0" };
|
|
@@ -128,32 +127,32 @@ const q = async (e) => {
|
|
|
128
127
|
}
|
|
129
128
|
)).transactionHash
|
|
130
129
|
}));
|
|
131
|
-
},
|
|
132
|
-
signature: (await
|
|
130
|
+
}, _ = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
131
|
+
signature: (await E(r().projectId, s.userId, {
|
|
133
132
|
message: e.message,
|
|
134
133
|
address: e.evmAccount,
|
|
135
134
|
walletSecretId: t
|
|
136
135
|
})).signature
|
|
137
|
-
})),
|
|
138
|
-
signature: (await
|
|
136
|
+
})), ee = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
137
|
+
signature: (await k(r().projectId, s.userId, {
|
|
139
138
|
typedData: e.typedData,
|
|
140
139
|
address: e.evmAccount,
|
|
141
140
|
walletSecretId: t
|
|
142
141
|
})).signature
|
|
143
|
-
})),
|
|
142
|
+
})), te = async (e) => {
|
|
144
143
|
if (r().useMock)
|
|
145
144
|
return {
|
|
146
145
|
privateKey: "mock-private-key"
|
|
147
146
|
};
|
|
148
|
-
const s = await
|
|
147
|
+
const s = await U();
|
|
149
148
|
return i(e, n(), async ({ user: t, walletSecretId: a }) => {
|
|
150
|
-
const c = await
|
|
149
|
+
const c = await M(r().projectId, t.userId, {
|
|
151
150
|
address: e.evmAccount,
|
|
152
151
|
walletSecretId: a,
|
|
153
152
|
exportEncryptionKey: s.publicKeyBase64
|
|
154
153
|
});
|
|
155
154
|
return {
|
|
156
|
-
privateKey: await
|
|
155
|
+
privateKey: await C(
|
|
157
156
|
s.privateKey,
|
|
158
157
|
c.encryptedPrivateKey
|
|
159
158
|
)
|
|
@@ -161,17 +160,17 @@ const q = async (e) => {
|
|
|
161
160
|
});
|
|
162
161
|
};
|
|
163
162
|
export {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
163
|
+
te as exportEvmAccount,
|
|
164
|
+
J as getCurrentUser,
|
|
165
|
+
B as initialize,
|
|
166
|
+
L as isSignedIn,
|
|
167
|
+
R as onAuthStateChange,
|
|
168
|
+
Z as sendEvmTransaction,
|
|
169
|
+
X as signEvmHash,
|
|
170
|
+
_ as signEvmMessage,
|
|
171
|
+
Y as signEvmTransaction,
|
|
172
|
+
ee as signEvmTypedData,
|
|
173
|
+
V as signInWithEmail,
|
|
174
|
+
Q as signOut,
|
|
175
|
+
G as verifyEmailOTP
|
|
177
176
|
};
|
package/dist/esm/index6.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { logOutEndUser as
|
|
2
|
-
import { SignJWT as
|
|
1
|
+
import { logOutEndUser as h, refreshAccessToken as l, registerTemporaryWalletSecret as c } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { SignJWT as o } from "./index17.js";
|
|
3
3
|
import "viem";
|
|
4
|
-
import { toAuthState as
|
|
5
|
-
import { createKeyPair as
|
|
6
|
-
import { generateRandomId as
|
|
7
|
-
import { hash as
|
|
8
|
-
import { sortKeys as
|
|
9
|
-
const
|
|
10
|
-
class
|
|
4
|
+
import { toAuthState as u } from "./index7.js";
|
|
5
|
+
import { createKeyPair as S } from "./index18.js";
|
|
6
|
+
import { generateRandomId as i } from "./index19.js";
|
|
7
|
+
import { hash as w } from "./index20.js";
|
|
8
|
+
import { sortKeys as f } from "./index13.js";
|
|
9
|
+
const n = 60 * 1e3;
|
|
10
|
+
class C {
|
|
11
11
|
projectId;
|
|
12
12
|
authState = null;
|
|
13
13
|
walletSecret = null;
|
|
@@ -43,7 +43,7 @@ class P {
|
|
|
43
43
|
*/
|
|
44
44
|
async signOut() {
|
|
45
45
|
try {
|
|
46
|
-
await
|
|
46
|
+
await h(this.projectId);
|
|
47
47
|
} catch {
|
|
48
48
|
} finally {
|
|
49
49
|
await this.clearAuthState();
|
|
@@ -69,12 +69,12 @@ class P {
|
|
|
69
69
|
/**
|
|
70
70
|
* Gets the currently registered wallet secret ID. Rejects if the user is not signed in.
|
|
71
71
|
*
|
|
72
|
-
* @param authState - The auth state to use. If not provided, the current auth state will be used.
|
|
73
|
-
*
|
|
74
72
|
* @returns The wallet secret ID.
|
|
75
73
|
*/
|
|
76
|
-
async getWalletSecretId(
|
|
77
|
-
|
|
74
|
+
async getWalletSecretId() {
|
|
75
|
+
if (!await this.isSignedIn())
|
|
76
|
+
throw new Error("Cannot get wallet secret ID if the user is not signed in");
|
|
77
|
+
return this.shouldRefreshWalletSecret() && await this.refreshWalletSecret(), this.walletSecret.walletSecretId;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Gets the X-Wallet-Auth header. Rejects if the user is not signed in.
|
|
@@ -87,15 +87,17 @@ class P {
|
|
|
87
87
|
* @returns The X-Wallet-Auth header.
|
|
88
88
|
*/
|
|
89
89
|
async getXWalletAuth(t) {
|
|
90
|
+
if (!await this.isSignedIn())
|
|
91
|
+
throw new Error("Cannot get X-Wallet-Auth header if the user is not signed in");
|
|
90
92
|
this.shouldRefreshWalletSecret() && await this.refreshWalletSecret();
|
|
91
93
|
const e = `${t.requestMethod} ${t.requestHost}${t.requestPath}`, a = Math.floor(Date.now() / 1e3), r = {
|
|
92
94
|
uris: [e]
|
|
93
95
|
};
|
|
94
96
|
if (t.requestData && Object.keys(t.requestData).length > 0) {
|
|
95
|
-
const s =
|
|
96
|
-
r.reqHash = await
|
|
97
|
+
const s = f(t.requestData);
|
|
98
|
+
r.reqHash = await w(new TextEncoder().encode(JSON.stringify(s)));
|
|
97
99
|
}
|
|
98
|
-
return await new
|
|
100
|
+
return await new o(r).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(a).setNotBefore(a).setJti(await i()).sign(this.walletSecret.keyPair.privateKey);
|
|
99
101
|
}
|
|
100
102
|
/**
|
|
101
103
|
* Sets the authentication state.
|
|
@@ -138,7 +140,7 @@ class P {
|
|
|
138
140
|
* @returns True if the token should be refreshed, false otherwise.
|
|
139
141
|
*/
|
|
140
142
|
shouldRefreshToken() {
|
|
141
|
-
return !(this.authState && this.authState.expiresAt > Date.now() +
|
|
143
|
+
return !(this.authState && this.authState.expiresAt > Date.now() + n);
|
|
142
144
|
}
|
|
143
145
|
/**
|
|
144
146
|
* Refreshes the access token and transitions the auth state accordingly.
|
|
@@ -148,9 +150,9 @@ class P {
|
|
|
148
150
|
*/
|
|
149
151
|
async refreshAccessToken() {
|
|
150
152
|
try {
|
|
151
|
-
const t = await
|
|
153
|
+
const t = await l(this.projectId, {
|
|
152
154
|
grantType: "refresh_token"
|
|
153
|
-
}), e =
|
|
155
|
+
}), e = u(
|
|
154
156
|
t.accessToken,
|
|
155
157
|
t.validUntil,
|
|
156
158
|
t.endUser
|
|
@@ -166,30 +168,27 @@ class P {
|
|
|
166
168
|
* @returns True if the wallet secret should be refreshed, false otherwise.
|
|
167
169
|
*/
|
|
168
170
|
shouldRefreshWalletSecret() {
|
|
169
|
-
return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() +
|
|
171
|
+
return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() + n);
|
|
170
172
|
}
|
|
171
173
|
/**
|
|
172
|
-
* Refreshes the wallet secret.
|
|
174
|
+
* Refreshes the wallet secret. Assumes the user is signed in.
|
|
173
175
|
*
|
|
174
|
-
* @param authState - The auth state to use. If not provided, the current auth state will be used.
|
|
175
176
|
* @returns The wallet secret.
|
|
176
177
|
*/
|
|
177
|
-
async refreshWalletSecret(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
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();
|
|
181
|
-
this.walletSecret = { walletSecretId: a, keyPair: r, expiresAt: s };
|
|
178
|
+
async refreshWalletSecret() {
|
|
179
|
+
const t = this.walletSecret?.walletSecretId ?? await i(), e = this.walletSecret?.keyPair ?? await S(), a = this.authState.expiresAt, r = new Date(a).toISOString();
|
|
180
|
+
this.walletSecret = { walletSecretId: t, keyPair: e, expiresAt: a };
|
|
182
181
|
try {
|
|
183
|
-
await
|
|
184
|
-
walletSecretId:
|
|
185
|
-
publicKey:
|
|
186
|
-
validUntil:
|
|
182
|
+
await c(this.projectId, this.authState.user.userId, {
|
|
183
|
+
walletSecretId: t,
|
|
184
|
+
publicKey: e.publicKeyBase64,
|
|
185
|
+
validUntil: r
|
|
187
186
|
});
|
|
188
|
-
} catch (
|
|
189
|
-
throw this.walletSecret = null,
|
|
187
|
+
} catch (s) {
|
|
188
|
+
throw this.walletSecret = null, s;
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
192
|
export {
|
|
194
|
-
|
|
193
|
+
C as AuthManager
|
|
195
194
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
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.18"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@size-limit/preset-big-lib": "^11.2.0",
|