@coinbase/cdp-core 0.0.15 → 0.0.17

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 CHANGED
@@ -1,23 +1,31 @@
1
- import { exportEvmAccount as t, getCurrentUser as i, initialize as n, isSignedIn as o, onAuthStateChange as a, sendEvmTransaction as m, signEvmHash as s, signEvmMessage as E, signEvmTransaction as g, signEvmTypedData as v, signInWithEmail as c, signOut as d, verifyEmailOTP as p } from "./index2.js";
2
- import { createCDPEmbeddedWallet as l } from "./index3.js";
3
- import { EIP1193ProviderError as x, STANDARD_ERROR_CODES as A } from "./index4.js";
4
- import { toViemAccount as T } from "./index5.js";
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 EIP1193ProviderError,
7
- A as STANDARD_ERROR_CODES,
8
- l as createCDPEmbeddedWallet,
9
- t as exportEvmAccount,
10
- i as getCurrentUser,
11
- n as initialize,
12
- o as isSignedIn,
13
- a as onAuthStateChange,
14
- m as sendEvmTransaction,
15
- s as signEvmHash,
16
- E as signEvmMessage,
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
- c as signInWithEmail,
20
- d as signOut,
21
- T as toViemAccount,
22
- p as verifyEmailOTP
27
+ T as signInWithEmail,
28
+ A as signOut,
29
+ R as toViemAccount,
30
+ f as verifyEmailOTP
23
31
  };
@@ -1,5 +1,7 @@
1
+ import "@coinbase/cdp-api-client";
2
+ import "viem";
1
3
  import { mockUser as e } from "./index12.js";
2
- class h {
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
- h as MockAuthManager
120
+ r as MockAuthManager
119
121
  };
@@ -1,6 +1,8 @@
1
- const e = "0x0000000000000000000000000000000000000000", t = {
1
+ import "@coinbase/cdp-api-client";
2
+ import "viem";
3
+ const t = "0x0000000000000000000000000000000000000000", s = {
2
4
  userId: "mock-user-id",
3
- evmAccounts: [e],
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
- e as mockAddress,
13
- t as mockUser
14
+ t as mockAddress,
15
+ s as mockUser
14
16
  };
@@ -1,20 +1,22 @@
1
- let n = null, e = null;
2
- const r = (t) => {
1
+ import "@coinbase/cdp-api-client";
2
+ import "viem";
3
+ let n = null, r = null;
4
+ const i = (t) => {
3
5
  n = t;
4
- }, o = () => {
6
+ }, a = () => {
5
7
  if (!n)
6
8
  throw new Error("SDK not initialized");
7
9
  return n;
8
- }, i = (t) => {
9
- e = t;
10
- }, a = () => {
11
- if (!e)
10
+ }, g = (t) => {
11
+ r = t;
12
+ }, l = () => {
13
+ if (!r)
12
14
  throw new Error("SDK not initialized");
13
- return e;
15
+ return r;
14
16
  };
15
17
  export {
16
- o as getConfig,
17
- a as getCoreAuthManager,
18
- r as setConfig,
19
- i as setCoreAuthManager
18
+ a as getConfig,
19
+ l as getCoreAuthManager,
20
+ i as setConfig,
21
+ g as setCoreAuthManager
20
22
  };
@@ -1,8 +1,10 @@
1
1
  import { Hex as y } from "ox";
2
2
  import { createWalletClient as I } from "viem";
3
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
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";
6
8
  import { isChainIdSupportedForCDPSends as D, chainIdToNameMapping as b } from "./index13.js";
7
9
  function g(e) {
8
10
  return {
@@ -16,16 +18,16 @@ function g(e) {
16
18
  type: "eip1559"
17
19
  };
18
20
  }
19
- async function U() {
21
+ async function M() {
20
22
  return (await f())?.evmAccounts || [];
21
23
  }
22
- async function H(e, n) {
24
+ async function _(e, n) {
23
25
  const a = await C();
24
26
  return e.emit("connect", {
25
27
  chainId: y.fromNumber(n.getState().chainId)
26
28
  }), a.evmAccounts || [];
27
29
  }
28
- async function M(e) {
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();
@@ -41,7 +43,7 @@ async function M(e) {
41
43
  );
42
44
  }
43
45
  }
44
- async function _(e) {
46
+ async function z(e) {
45
47
  const [n, a] = e;
46
48
  await m(n);
47
49
  try {
@@ -56,7 +58,7 @@ async function _(e) {
56
58
  );
57
59
  }
58
60
  }
59
- async function k(e, n, a) {
61
+ async function J(e, n, a) {
60
62
  const [t] = e;
61
63
  if (!t || typeof t != "object")
62
64
  throw new o(
@@ -114,7 +116,7 @@ async function k(e, n, a) {
114
116
  );
115
117
  }
116
118
  }
117
- async function z(e) {
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 z(e) {
129
131
  );
130
132
  }
131
133
  }
132
- async function J(e) {
134
+ async function W(e) {
133
135
  return `0x${e.getState().chainId.toString(16)}`;
134
136
  }
135
- async function V() {
137
+ async function $() {
136
138
  await f() && await P();
137
139
  }
138
- function W(e, n) {
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
- U as handleAccounts,
144
- J as handleChainId,
145
- V as handleDisconnect,
146
- z as handleEthSign,
147
- M as handlePersonalSign,
148
- H as handleRequestAccounts,
149
- k as handleSendTransaction,
150
- _ as handleSignTypedData,
151
- W as handleSwitchEthereumChain,
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
  };
@@ -1,15 +1,16 @@
1
- import { configureCdpApiClient as p, setAuthManager as w, initiateAuthentication as h, verifyEmailAuthentication as y, createEndUserEvmAccount as f, signEvmHashWithEndUserAccount as I, signEvmTransactionWithEndUserAccount as l, sendEvmTransactionWithEndUserAccount as v, signEvmMessageWithEndUserAccount as A, signEvmTypedDataWithEndUserAccount as E, exportEndUserEvmAccount as k } from "@coinbase/cdp-api-client";
2
- import { AuthManager as M } from "./index6.js";
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 S } from "./index9.js";
6
- import { decryptWithPrivateKey as U } from "./index10.js";
7
- import { MockAuthManager as C } from "./index11.js";
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 T } from "./index13.js";
10
- import { getConfig as r, setCoreAuthManager as g, getCoreAuthManager as n, setConfig as j } from "./index14.js";
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
+ import "viem";
11
12
  import { serializeTransaction as m } from "./index15.js";
12
- const $ = async (e) => {
13
+ const B = async (e) => {
13
14
  if (!e.projectId)
14
15
  throw new Error("Project ID is required");
15
16
  let s;
@@ -18,19 +19,19 @@ const $ = async (e) => {
18
19
  } catch {
19
20
  s = !0;
20
21
  }
21
- if (j(e), r().useMock) {
22
- g(new C(r().projectId));
22
+ if (P(e), r().useMock) {
23
+ g(new T(r().projectId));
23
24
  return;
24
25
  }
25
- if (p({
26
+ if (w({
26
27
  debugging: r().debugging,
27
28
  basePath: r().basePath
28
29
  }), s) {
29
- const t = new M(r().projectId);
30
- g(t), w(t);
30
+ const t = new S(r().projectId);
31
+ g(t), h(t);
31
32
  }
32
33
  await n().ensureInitialized();
33
- }, q = async (e) => {
34
+ }, V = async (e) => {
34
35
  if (r().useMock)
35
36
  return {
36
37
  message: "Mock sign in initiated",
@@ -38,7 +39,7 @@ const $ = async (e) => {
38
39
  };
39
40
  if (await n().isSignedIn())
40
41
  throw new Error("User is already authenticated. Please sign out first.");
41
- const t = await h(r().projectId, {
42
+ const t = await y(r().projectId, {
42
43
  email: e.email,
43
44
  type: "email"
44
45
  });
@@ -46,7 +47,7 @@ const $ = async (e) => {
46
47
  flowId: t.flowId,
47
48
  message: t.message
48
49
  };
49
- }, B = async (e) => {
50
+ }, G = async (e) => {
50
51
  if (r().useMock)
51
52
  return await n().setAuthState({
52
53
  accessToken: "mock-access-token",
@@ -59,28 +60,27 @@ const $ = async (e) => {
59
60
  };
60
61
  if (await n().isSignedIn())
61
62
  throw new Error("User is already authenticated. Please sign out first.");
62
- const t = await y(r().projectId, {
63
+ const t = await f(r().projectId, {
63
64
  flowId: e.flowId,
64
65
  otp: e.otp
65
66
  });
66
67
  let a = u(t.accessToken, t.validUntil, t.endUser);
67
- if (!a.user.evmAccounts || a.user.evmAccounts.length === 0)
68
+ if (await n().setAuthState(a), !a.user.evmAccounts || a.user.evmAccounts.length === 0)
68
69
  try {
69
- const o = await f(r().projectId, a.user.userId, {
70
- walletSecretId: await n().getWalletSecretId(a)
70
+ const o = await n().getWalletSecretId(), p = await I(r().projectId, a.user.userId, {
71
+ walletSecretId: o
71
72
  });
72
- a = u(t.accessToken, t.validUntil, o);
73
+ a = u(t.accessToken, t.validUntil, p), await n().setAuthState(a);
73
74
  } catch (o) {
74
75
  throw new Error(`Failed to create EVM account: ${o}`);
75
76
  }
76
- await n().setAuthState(a);
77
77
  const c = await n().getUser();
78
78
  return {
79
79
  message: t.message,
80
80
  user: c,
81
81
  isNewUser: t.isNewEndUser
82
82
  };
83
- }, V = async () => n().getUser(), G = async () => n().isSignedIn(), J = async () => {
83
+ }, J = async () => n().getUser(), L = async () => n().isSignedIn(), Q = async () => {
84
84
  if (r().useMock) {
85
85
  await n().signOut();
86
86
  return;
@@ -88,18 +88,18 @@ const $ = async (e) => {
88
88
  if (!await n().isSignedIn())
89
89
  throw new Error("User not signed in");
90
90
  await n().signOut();
91
- }, L = (e) => {
91
+ }, R = (e) => {
92
92
  n().addAuthStateChangeCallback(e);
93
- }, Q = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
94
- signature: (await I(r().projectId, s.userId, {
93
+ }, X = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
94
+ signature: (await l(r().projectId, s.userId, {
95
95
  hash: e.hash,
96
96
  address: e.evmAccount,
97
97
  walletSecretId: t
98
98
  })).signature
99
- })), R = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
99
+ })), Y = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
100
100
  const a = m(e.transaction);
101
101
  return {
102
- signedTransaction: (await l(
102
+ signedTransaction: (await A(
103
103
  r().projectId,
104
104
  s.userId,
105
105
  {
@@ -109,8 +109,8 @@ const $ = async (e) => {
109
109
  }
110
110
  )).signedTransaction
111
111
  };
112
- }), X = async (e) => {
113
- if (!T(e.network))
112
+ }), Z = async (e) => {
113
+ if (!j(e.network))
114
114
  throw new Error(`Chain ${e.network} is not supported by the CDP Apis`);
115
115
  if (r().useMock)
116
116
  return { transactionHash: "0x0" };
@@ -127,32 +127,32 @@ const $ = async (e) => {
127
127
  }
128
128
  )).transactionHash
129
129
  }));
130
- }, Y = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
131
- signature: (await A(r().projectId, s.userId, {
130
+ }, _ = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
131
+ signature: (await E(r().projectId, s.userId, {
132
132
  message: e.message,
133
133
  address: e.evmAccount,
134
134
  walletSecretId: t
135
135
  })).signature
136
- })), Z = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
137
- signature: (await E(r().projectId, s.userId, {
136
+ })), ee = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
137
+ signature: (await k(r().projectId, s.userId, {
138
138
  typedData: e.typedData,
139
139
  address: e.evmAccount,
140
140
  walletSecretId: t
141
141
  })).signature
142
- })), _ = async (e) => {
142
+ })), te = async (e) => {
143
143
  if (r().useMock)
144
144
  return {
145
145
  privateKey: "mock-private-key"
146
146
  };
147
- const s = await S();
147
+ const s = await U();
148
148
  return i(e, n(), async ({ user: t, walletSecretId: a }) => {
149
- const c = await k(r().projectId, t.userId, {
149
+ const c = await M(r().projectId, t.userId, {
150
150
  address: e.evmAccount,
151
151
  walletSecretId: a,
152
152
  exportEncryptionKey: s.publicKeyBase64
153
153
  });
154
154
  return {
155
- privateKey: await U(
155
+ privateKey: await C(
156
156
  s.privateKey,
157
157
  c.encryptedPrivateKey
158
158
  )
@@ -160,17 +160,17 @@ const $ = async (e) => {
160
160
  });
161
161
  };
162
162
  export {
163
- _ as exportEvmAccount,
164
- V as getCurrentUser,
165
- $ as initialize,
166
- G as isSignedIn,
167
- L as onAuthStateChange,
168
- X as sendEvmTransaction,
169
- Q as signEvmHash,
170
- Y as signEvmMessage,
171
- R as signEvmTransaction,
172
- Z as signEvmTypedData,
173
- q as signInWithEmail,
174
- J as signOut,
175
- B as verifyEmailOTP
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
176
176
  };
@@ -4,24 +4,25 @@ import { create as l } from "zustand";
4
4
  import { subscribeWithSelector as f, persist as g } from "./index17.js";
5
5
  import { validateRequest as w, EIP1193ProviderError as I, STANDARD_ERROR_CODES as S } from "./index4.js";
6
6
  import { EventEmitter as b } from "./index18.js";
7
+ import "@coinbase/cdp-api-client";
7
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 "./index19.js";
8
9
  import { onAuthStateChange as T } from "./index2.js";
9
10
  import { baseSepolia as d } from "./index20.js";
10
11
  function q(r, e, a) {
11
12
  e.subscribe(
12
- (n) => n.chainId,
13
- (n, t) => {
14
- n !== t && r.emit("chainChanged", n);
13
+ (t) => t.chainId,
14
+ (t, n) => {
15
+ t !== n && r.emit("chainChanged", t);
15
16
  }
16
17
  ), e.subscribe(
17
- (n) => n.user,
18
- (n, t) => {
19
- if (!(n?.userId === t?.userId && n?.evmAccounts?.length === t?.evmAccounts?.length)) {
20
- if (!n && t) {
18
+ (t) => t.user,
19
+ (t, n) => {
20
+ if (!(t?.userId === n?.userId && t?.evmAccounts?.length === n?.evmAccounts?.length)) {
21
+ if (!t && n) {
21
22
  r.emit("disconnect", new h.DisconnectedError());
22
23
  return;
23
24
  }
24
- if (n && n.evmAccounts?.length && (!t || t.evmAccounts?.length === 0)) {
25
+ if (t && t.evmAccounts?.length && (!n || n.evmAccounts?.length === 0)) {
25
26
  const m = e.getState().chainId;
26
27
  r.emit("connect", { chainId: m });
27
28
  return;
@@ -31,33 +32,33 @@ function q(r, e, a) {
31
32
  );
32
33
  const { chainId: i, setChainId: o } = e.getState(), c = i || a.chains[0].id;
33
34
  return i || o(c), h.from({
34
- request: async (n) => {
35
- w(n, a);
36
- const t = n;
37
- switch (t.method) {
35
+ request: async (t) => {
36
+ w(t, a);
37
+ const n = t;
38
+ switch (n.method) {
38
39
  case "eth_accounts":
39
40
  return y();
40
41
  case "eth_requestAccounts":
41
42
  return R(r, e);
42
43
  case "personal_sign":
43
- return P(t.params);
44
+ return P(n.params);
44
45
  case "eth_sendTransaction":
45
- return E(t.params, e, a.transports);
46
+ return E(n.params, e, a.transports);
46
47
  case "wallet_disconnect":
47
48
  return D();
48
49
  case "wallet_switchEthereumChain":
49
- return v(t.params, e);
50
+ return v(n.params, e);
50
51
  case "eth_sign":
51
- return _(t.params);
52
+ return _(n.params);
52
53
  case "eth_signTypedData_v4":
53
- return C(t.params);
54
+ return C(n.params);
54
55
  case "eth_chainId":
55
56
  return A(e);
56
57
  // Catch-all for any unknown method
57
58
  default:
58
59
  throw new I(
59
60
  S.provider.unsupportedMethod,
60
- `Method ${t.method} not supported`
61
+ `Method ${n.method} not supported`
61
62
  );
62
63
  }
63
64
  },
@@ -72,7 +73,7 @@ const u = {
72
73
  [d.id]: p()
73
74
  }
74
75
  };
75
- function z(r) {
76
+ function B(r) {
76
77
  if (r?.chains.length === 0)
77
78
  throw new Error("At least one chain must be configured");
78
79
  const e = r?.chains ?? u.chains, a = r?.transports ?? u.transports;
@@ -83,10 +84,10 @@ function z(r) {
83
84
  g(
84
85
  (s) => ({
85
86
  chainId: e[0].id,
86
- setChainId: (n) => s({ chainId: n }),
87
+ setChainId: (t) => s({ chainId: t }),
87
88
  chains: e,
88
89
  user: null,
89
- setUser: (n) => s({ user: n })
90
+ setUser: (t) => s({ user: t })
90
91
  }),
91
92
  {
92
93
  name: "cdp-provider-store"
@@ -105,5 +106,5 @@ function z(r) {
105
106
  };
106
107
  }
107
108
  export {
108
- z as createCDPEmbeddedWallet
109
+ B as createCDPEmbeddedWallet
109
110
  };
@@ -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 h = /* @__PURE__ */ new Set([
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 l(e, { chains: t }) {
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 (!h.has(r))
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 w(e) {
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 f() {
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
- l as validateRequest,
126
+ E as validateRequest,
124
127
  d as validateUserConnected,
125
- f as validateUserHasEvmAccount,
126
- w as validateUserOwnsAddress
128
+ R as validateUserHasEvmAccount,
129
+ _ as validateUserOwnsAddress
127
130
  };
@@ -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(n) {
5
- const r = await s();
6
- if (!r || !r.evmAccounts || r.evmAccounts.length === 0)
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 (!r.evmAccounts.includes(n))
11
- throw new Error(`Cannot sign for address ${n} - not authorized for this account`);
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: n,
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: n,
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: n,
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: n,
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: n,
89
+ evmAccount: r,
89
90
  hash: e.hash
90
91
  })).signature;
91
92
  }
@@ -1,12 +1,13 @@
1
- import { logOutEndUser as c, refreshAccessToken as o, registerTemporaryWalletSecret as u } from "@coinbase/cdp-api-client";
2
- import { SignJWT as S } from "./index21.js";
3
- import { toAuthState as w } from "./index7.js";
4
- import { createKeyPair as f } from "./index22.js";
5
- import { generateRandomId as n } from "./index23.js";
6
- import { hash as d } from "./index24.js";
7
- import { sortKeys as y } from "./index13.js";
8
- const h = 60 * 1e3;
9
- class E {
1
+ import { logOutEndUser as h, refreshAccessToken as l, registerTemporaryWalletSecret as c } from "@coinbase/cdp-api-client";
2
+ import { SignJWT as o } from "./index21.js";
3
+ import "viem";
4
+ import { toAuthState as u } from "./index7.js";
5
+ import { createKeyPair as S } from "./index22.js";
6
+ import { generateRandomId as i } from "./index23.js";
7
+ import { hash as w } from "./index24.js";
8
+ import { sortKeys as f } from "./index13.js";
9
+ const n = 60 * 1e3;
10
+ class C {
10
11
  projectId;
11
12
  authState = null;
12
13
  walletSecret = null;
@@ -42,7 +43,7 @@ class E {
42
43
  */
43
44
  async signOut() {
44
45
  try {
45
- await c(this.projectId);
46
+ await h(this.projectId);
46
47
  } catch {
47
48
  } finally {
48
49
  await this.clearAuthState();
@@ -68,12 +69,12 @@ class E {
68
69
  /**
69
70
  * Gets the currently registered wallet secret ID. Rejects if the user is not signed in.
70
71
  *
71
- * @param authState - The auth state to use. If not provided, the current auth state will be used.
72
- *
73
72
  * @returns The wallet secret ID.
74
73
  */
75
- async getWalletSecretId(t) {
76
- return this.shouldRefreshWalletSecret() && await this.refreshWalletSecret(t), this.walletSecret.walletSecretId;
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;
77
78
  }
78
79
  /**
79
80
  * Gets the X-Wallet-Auth header. Rejects if the user is not signed in.
@@ -86,15 +87,17 @@ class E {
86
87
  * @returns The X-Wallet-Auth header.
87
88
  */
88
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");
89
92
  this.shouldRefreshWalletSecret() && await this.refreshWalletSecret();
90
93
  const e = `${t.requestMethod} ${t.requestHost}${t.requestPath}`, a = Math.floor(Date.now() / 1e3), r = {
91
94
  uris: [e]
92
95
  };
93
96
  if (t.requestData && Object.keys(t.requestData).length > 0) {
94
- const s = y(t.requestData);
95
- r.reqHash = await d(new TextEncoder().encode(JSON.stringify(s)));
97
+ const s = f(t.requestData);
98
+ r.reqHash = await w(new TextEncoder().encode(JSON.stringify(s)));
96
99
  }
97
- return await new S(r).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(a).setNotBefore(a).setJti(await n()).sign(this.walletSecret.keyPair.privateKey);
100
+ return await new o(r).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(a).setNotBefore(a).setJti(await i()).sign(this.walletSecret.keyPair.privateKey);
98
101
  }
99
102
  /**
100
103
  * Sets the authentication state.
@@ -137,7 +140,7 @@ class E {
137
140
  * @returns True if the token should be refreshed, false otherwise.
138
141
  */
139
142
  shouldRefreshToken() {
140
- return !(this.authState && this.authState.expiresAt > Date.now() + h);
143
+ return !(this.authState && this.authState.expiresAt > Date.now() + n);
141
144
  }
142
145
  /**
143
146
  * Refreshes the access token and transitions the auth state accordingly.
@@ -147,16 +150,16 @@ class E {
147
150
  */
148
151
  async refreshAccessToken() {
149
152
  try {
150
- const t = await o(this.projectId, {
153
+ const t = await l(this.projectId, {
151
154
  grantType: "refresh_token"
152
- }), e = w(
155
+ }), e = u(
153
156
  t.accessToken,
154
157
  t.validUntil,
155
158
  t.endUser
156
159
  );
157
160
  await this.setAuthState(e);
158
161
  } catch {
159
- await this.clearAuthState();
162
+ await this.signOut();
160
163
  }
161
164
  }
162
165
  /**
@@ -165,30 +168,27 @@ class E {
165
168
  * @returns True if the wallet secret should be refreshed, false otherwise.
166
169
  */
167
170
  shouldRefreshWalletSecret() {
168
- return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() + h);
171
+ return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() + n);
169
172
  }
170
173
  /**
171
- * Refreshes the wallet secret.
174
+ * Refreshes the wallet secret. Assumes the user is signed in.
172
175
  *
173
- * @param authState - The auth state to use. If not provided, the current auth state will be used.
174
176
  * @returns The wallet secret.
175
177
  */
176
- async refreshWalletSecret(t) {
177
- if (!t && !await this.isSignedIn())
178
- throw new Error("Cannot refresh wallet secret if the auth state is not present or expired");
179
- 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();
180
- 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 };
181
181
  try {
182
- await u(this.projectId, e.user.userId, {
183
- walletSecretId: a,
184
- publicKey: r.publicKeyBase64,
185
- validUntil: l
182
+ await c(this.projectId, this.authState.user.userId, {
183
+ walletSecretId: t,
184
+ publicKey: e.publicKeyBase64,
185
+ validUntil: r
186
186
  });
187
- } catch (i) {
188
- throw this.walletSecret = null, i;
187
+ } catch (s) {
188
+ throw this.walletSecret = null, s;
189
189
  }
190
190
  }
191
191
  }
192
192
  export {
193
- E as AuthManager
193
+ C as AuthManager
194
194
  };
@@ -1,12 +1,13 @@
1
- const c = (u, n, e) => {
2
- const o = new Date(n).getTime(), r = {
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, s) => (t[s.type] = s, t), {})
6
+ authenticationMethods: e.authenticationMethods.reduce((t, o) => (t[o.type] = o, t), {})
6
7
  };
7
8
  return {
8
- accessToken: u,
9
- expiresAt: o,
9
+ accessToken: s,
10
+ expiresAt: n,
10
11
  user: r
11
12
  };
12
13
  };
@@ -1,14 +1,16 @@
1
- const o = async (t) => await t.isSignedIn();
2
- async function s(t, n, r) {
3
- if (!await o(n))
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((i) => i === t.evmAccount))
8
+ if (!e.evmAccounts?.find((o) => o === t.evmAccount))
7
9
  throw new Error("EVM account not found");
8
- const c = await n.getWalletSecretId();
9
- return r({ ...t, user: e, walletSecretId: c });
10
+ const i = await n.getWalletSecretId();
11
+ return r({ ...t, user: e, walletSecretId: i });
10
12
  }
11
13
  export {
12
- o as isSignedIn,
13
- s as withAuth
14
+ c as isSignedIn,
15
+ a as withAuth
14
16
  };
@@ -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.15",
3
+ "version": "0.0.17",
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.15"
20
+ "@coinbase/cdp-api-client": "^0.0.17"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@size-limit/preset-big-lib": "^11.2.0",