@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 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
  };
@@ -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 $ = async (e) => {
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
- }, q = async (e) => {
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
- }, B = async (e) => {
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
- }, V = async () => n().getUser(), G = async () => n().isSignedIn(), J = async () => {
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
- }, L = (e) => {
92
+ }, Q = (e) => {
92
93
  n().addAuthStateChangeCallback(e);
93
- }, Q = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
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
- })), R = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
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
- }), X = async (e) => {
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
- }, Y = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
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
- })), Z = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
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
- })), _ = async (e) => {
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
- _ 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
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
  };
@@ -1,9 +1,11 @@
1
- import { Provider as y, Hex as I } from "ox";
2
- import { createWalletClient as E } from "viem";
3
- import { signEvmTypedData as P, signEvmHash as S, getCurrentUser as f, signOut as R, sendEvmTransaction as T, signEvmTransaction as A, signEvmMessage as x } from "./index2.js";
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 C, validateUserConnected as D } from "./index4.js";
6
- import { isChainIdSupportedForCDPSends as b, chainIdToNameMapping as j } from "./index13.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";
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 H() {
21
+ async function M() {
20
22
  return (await f())?.evmAccounts || [];
21
23
  }
22
- async function M(e, n) {
23
- const a = await D();
24
+ async function _(e, n) {
25
+ const a = await C();
24
26
  return e.emit("connect", {
25
- chainId: I.fromNumber(n.getState().chainId)
27
+ chainId: y.fromNumber(n.getState().chainId)
26
28
  }), a.evmAccounts || [];
27
29
  }
28
- async function _(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();
32
34
  try {
33
- return (await x({
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 k(e) {
46
+ async function z(e) {
45
47
  const [n, a] = e;
46
48
  await m(n);
47
49
  try {
48
- return (await P({
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 z(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(
@@ -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 C()).evmAccounts?.[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
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 (b(i))
79
+ if (D(i))
78
80
  try {
79
- return (await T({
81
+ return (await R({
80
82
  evmAccount: d,
81
83
  transaction: { ...g(t), chainId: i },
82
- network: j[i]
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 = E({
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
- }), w = u.chains.find((h) => h.id === i), p = await r.prepareTransactionRequest({
99
+ }), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
98
100
  ...g(t),
99
- chain: w
100
- }), v = await A({
101
+ chain: p
102
+ }), v = await T({
101
103
  evmAccount: d,
102
104
  transaction: {
103
- ...p,
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 J(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 J(e) {
129
131
  );
130
132
  }
131
133
  }
132
- async function V(e) {
134
+ async function W(e) {
133
135
  return `0x${e.getState().chainId.toString(16)}`;
134
136
  }
135
- async function W(e) {
136
- await f() && await R(), e.emit("disconnect", new y.DisconnectedError());
137
+ async function $() {
138
+ await f() && await P();
137
139
  }
138
- function $(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
- H as handleAccounts,
144
- V as handleChainId,
145
- W as handleDisconnect,
146
- J as handleEthSign,
147
- _ as handlePersonalSign,
148
- M as handleRequestAccounts,
149
- z as handleSendTransaction,
150
- k as handleSignTypedData,
151
- $ 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,92 +1,93 @@
1
- import { Provider as m } from "ox";
2
- import { http as l } from "viem";
3
- import { create as p } from "zustand";
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 I, EIP1193ProviderError as S, STANDARD_ERROR_CODES as w } from "./index4.js";
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 { handleChainId as A, handleSignTypedData as C, handleEthSign as _, handleSwitchEthereumChain as v, handleDisconnect as D, handleSendTransaction as P, handlePersonalSign as R, handleRequestAccounts as E, handleAccounts as T } from "./index23.js";
8
- import { onAuthStateChange as q } from "./index2.js";
9
- import { baseSepolia as h } from "./index24.js";
10
- function y(e, r, a) {
11
- r.subscribe(
12
- (n) => n.chainId,
13
- (n, t) => {
14
- n !== t && e.emit("chainChanged", n);
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
- ), r.subscribe(
17
- (n) => n.user,
18
- (n, t) => {
19
- if (!(n?.userId === t?.userId && n?.evmAccounts?.length === t?.evmAccounts?.length)) {
20
- if (!n && t) {
21
- e.emit("disconnect");
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 (n && n.evmAccounts?.length && (!t || t.evmAccounts?.length === 0)) {
25
- const u = r.getState().chainId;
26
- e.emit("connect", { chainId: u });
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: s, setChainId: i } = r.getState(), c = s || a.chains[0].id;
33
- return s || i(c), m.from({
34
- request: async (n) => {
35
- I(n, a);
36
- const t = n;
37
- switch (t.method) {
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 T();
40
+ return y();
40
41
  case "eth_requestAccounts":
41
- return E(e, r);
42
+ return R(r, e);
42
43
  case "personal_sign":
43
- return R(t.params);
44
+ return P(n.params);
44
45
  case "eth_sendTransaction":
45
- return P(t.params, r, a.transports);
46
+ return E(n.params, e, a.transports);
46
47
  case "wallet_disconnect":
47
- return D(e);
48
+ return D();
48
49
  case "wallet_switchEthereumChain":
49
- return v(t.params, r);
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
- return A(r);
56
+ return A(e);
56
57
  // Catch-all for any unknown method
57
58
  default:
58
- throw new S(
59
- w.provider.unsupportedMethod,
60
- `Method ${t.method} not supported`
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: e.on.bind(e),
66
- removeListener: e.removeListener.bind(e)
66
+ on: r.on.bind(r),
67
+ removeListener: r.removeListener.bind(r)
67
68
  });
68
69
  }
69
- const d = {
70
- chains: [h],
70
+ const u = {
71
+ chains: [d],
71
72
  transports: {
72
- [h.id]: l()
73
+ [d.id]: p()
73
74
  }
74
75
  };
75
- function z(e) {
76
- if (e?.chains.length === 0)
76
+ function B(r) {
77
+ if (r?.chains.length === 0)
77
78
  throw new Error("At least one chain must be configured");
78
- const r = e?.chains ?? d.chains, a = e?.transports ?? d.transports;
79
- if (r.length === 0)
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 s = new b(), i = p()(
82
+ const i = new b(), o = l()(
82
83
  f(
83
84
  g(
84
- (o) => ({
85
- chainId: r[0].id,
86
- setChainId: (n) => o({ chainId: n }),
87
- chains: r,
85
+ (s) => ({
86
+ chainId: e[0].id,
87
+ setChainId: (t) => s({ chainId: t }),
88
+ chains: e,
88
89
  user: null,
89
- setUser: (n) => o({ user: n })
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 q((o) => {
99
- i.getState().setUser(o);
99
+ return o.persist.rehydrate(), T((s) => {
100
+ o.getState().setUser(s);
100
101
  }), {
101
- provider: y(s, i, {
102
- chains: r,
102
+ provider: q(i, o, {
103
+ chains: e,
103
104
  transports: a
104
105
  })
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
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 E {
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.clearAuthState();
160
+ await this.signOut();
160
161
  }
161
162
  }
162
163
  /**
@@ -190,5 +191,5 @@ class E {
190
191
  }
191
192
  }
192
193
  export {
193
- E as AuthManager
194
+ P as AuthManager
194
195
  };
@@ -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.14",
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.14"
20
+ "@coinbase/cdp-api-client": "^0.0.16"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@size-limit/preset-big-lib": "^11.2.0",