@coinbase/cdp-core 0.0.0 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +255 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index10.js +119 -0
- package/dist/esm/index100.js +19 -0
- package/dist/esm/index101.js +83 -0
- package/dist/esm/index102.js +81 -0
- package/dist/esm/index11.js +8 -0
- package/dist/esm/index12.js +18 -0
- package/dist/esm/index13.js +174 -0
- package/dist/esm/index14.js +162 -0
- package/dist/esm/index15.js +50 -0
- package/dist/esm/index16.js +149 -0
- package/dist/esm/index17.js +58 -0
- package/dist/esm/index18.js +43 -0
- package/dist/esm/index19.js +19 -0
- package/dist/esm/index2.js +172 -0
- package/dist/esm/index20.js +7 -0
- package/dist/esm/index21.js +7 -0
- package/dist/esm/index22.js +11 -0
- package/dist/esm/index23.js +20 -0
- package/dist/esm/index24.js +48 -0
- package/dist/esm/index25.js +16 -0
- package/dist/esm/index26.js +58 -0
- package/dist/esm/index27.js +9 -0
- package/dist/esm/index28.js +24 -0
- package/dist/esm/index29.js +14 -0
- package/dist/esm/index3.js +109 -0
- package/dist/esm/index30.js +6 -0
- package/dist/esm/index31.js +6 -0
- package/dist/esm/index32.js +37 -0
- package/dist/esm/index33.js +15 -0
- package/dist/esm/index34.js +7 -0
- package/dist/esm/index35.js +31 -0
- package/dist/esm/index36.js +9 -0
- package/dist/esm/index37.js +27 -0
- package/dist/esm/index38.js +19 -0
- package/dist/esm/index39.js +57 -0
- package/dist/esm/index4.js +126 -0
- package/dist/esm/index40.js +26 -0
- package/dist/esm/index41.js +14 -0
- package/dist/esm/index42.js +30 -0
- package/dist/esm/index43.js +45 -0
- package/dist/esm/index44.js +58 -0
- package/dist/esm/index45.js +130 -0
- package/dist/esm/index46.js +15 -0
- package/dist/esm/index47.js +107 -0
- package/dist/esm/index48.js +9 -0
- package/dist/esm/index49.js +5 -0
- package/dist/esm/index5.js +194 -0
- package/dist/esm/index50.js +17 -0
- package/dist/esm/index51.js +45 -0
- package/dist/esm/index52.js +81 -0
- package/dist/esm/index53.js +4 -0
- package/dist/esm/index54.js +4 -0
- package/dist/esm/index55.js +15 -0
- package/dist/esm/index56.js +40 -0
- package/dist/esm/index57.js +9 -0
- package/dist/esm/index58.js +37 -0
- package/dist/esm/index59.js +11 -0
- package/dist/esm/index6.js +14 -0
- package/dist/esm/index60.js +13 -0
- package/dist/esm/index61.js +14 -0
- package/dist/esm/index62.js +16 -0
- package/dist/esm/index63.js +21 -0
- package/dist/esm/index64.js +8 -0
- package/dist/esm/index65.js +7 -0
- package/dist/esm/index66.js +13 -0
- package/dist/esm/index67.js +19 -0
- package/dist/esm/index68.js +25 -0
- package/dist/esm/index69.js +53 -0
- package/dist/esm/index7.js +14 -0
- package/dist/esm/index70.js +4 -0
- package/dist/esm/index71.js +23 -0
- package/dist/esm/index72.js +22 -0
- package/dist/esm/index73.js +82 -0
- package/dist/esm/index74.js +106 -0
- package/dist/esm/index75.js +35 -0
- package/dist/esm/index76.js +9 -0
- package/dist/esm/index77.js +12 -0
- package/dist/esm/index78.js +57 -0
- package/dist/esm/index79.js +13 -0
- package/dist/esm/index8.js +23 -0
- package/dist/esm/index80.js +4 -0
- package/dist/esm/index81.js +47 -0
- package/dist/esm/index82.js +16 -0
- package/dist/esm/index83.js +81 -0
- package/dist/esm/index84.js +7 -0
- package/dist/esm/index85.js +15 -0
- package/dist/esm/index86.js +38 -0
- package/dist/esm/index87.js +44 -0
- package/dist/esm/index88.js +23 -0
- package/dist/esm/index89.js +12 -0
- package/dist/esm/index9.js +17 -0
- package/dist/esm/index90.js +22 -0
- package/dist/esm/index91.js +96 -0
- package/dist/esm/index92.js +23 -0
- package/dist/esm/index93.js +120 -0
- package/dist/esm/index94.js +20 -0
- package/dist/esm/index95.js +30 -0
- package/dist/esm/index96.js +10 -0
- package/dist/esm/index97.js +13 -0
- package/dist/esm/index98.js +15 -0
- package/dist/esm/index99.js +12 -0
- package/dist/types/index.d.ts +287 -0
- package/package.json +69 -6
- package/index.js +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { configureCdpApiClient as p, setAuthManager as h, initiateAuthentication as l, verifyEmailAuthentication as I, createEndUserEvmAccount as f, signEvmHashWithEndUserAccount as y, signEvmTransactionWithEndUserAccount as E, sendEvmTransactionWithEndUserAccount as v, signEvmMessageWithEndUserAccount as A, signEvmTypedDataWithEndUserAccount as k, exportEndUserEvmAccount as S } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { AuthManager as U } from "./index5.js";
|
|
3
|
+
import { toAuthState as g } from "./index6.js";
|
|
4
|
+
import { withAuth as o } from "./index7.js";
|
|
5
|
+
import { createExportKeyPair as M } from "./index8.js";
|
|
6
|
+
import { decryptWithPrivateKey as T } from "./index9.js";
|
|
7
|
+
import { MockAuthManager as j } from "./index10.js";
|
|
8
|
+
import { mockUser as m } from "./index11.js";
|
|
9
|
+
import { isChainSupportedForCDPSends as P } from "./index12.js";
|
|
10
|
+
import { serializeTransaction as w } from "./index13.js";
|
|
11
|
+
let i = null, u = null;
|
|
12
|
+
const q = async (e) => {
|
|
13
|
+
if (!e.projectId)
|
|
14
|
+
throw new Error("Project ID is required");
|
|
15
|
+
const s = i?.projectId !== e.projectId;
|
|
16
|
+
if (i = e, i.useMock) {
|
|
17
|
+
u = new j(i.projectId);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
p({
|
|
21
|
+
debugging: i.debugging,
|
|
22
|
+
basePath: i.basePath
|
|
23
|
+
}), s && (u = new U(i.projectId), h(u)), await n().ensureInitialized();
|
|
24
|
+
}, B = async (e) => {
|
|
25
|
+
if (r().useMock)
|
|
26
|
+
return {
|
|
27
|
+
message: "Mock sign in initiated",
|
|
28
|
+
flowId: "mock-flow-id"
|
|
29
|
+
};
|
|
30
|
+
if (await n().isSignedIn())
|
|
31
|
+
throw new Error("User is already authenticated. Please sign out first.");
|
|
32
|
+
const t = await l(r().projectId, {
|
|
33
|
+
email: e.email,
|
|
34
|
+
type: "email"
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
flowId: t.flowId,
|
|
38
|
+
message: t.message
|
|
39
|
+
};
|
|
40
|
+
}, F = async (e) => {
|
|
41
|
+
if (r().useMock)
|
|
42
|
+
return await n().setAuthState({
|
|
43
|
+
accessToken: "mock-access-token",
|
|
44
|
+
expiresAt: Date.now() + 1e3 * 60 * 60 * 24,
|
|
45
|
+
user: m
|
|
46
|
+
}), {
|
|
47
|
+
message: "Mock email OTP verified",
|
|
48
|
+
user: m,
|
|
49
|
+
isNewUser: !1
|
|
50
|
+
};
|
|
51
|
+
if (await n().isSignedIn())
|
|
52
|
+
throw new Error("User is already authenticated. Please sign out first.");
|
|
53
|
+
const t = await I(r().projectId, {
|
|
54
|
+
flowId: e.flowId,
|
|
55
|
+
otp: e.otp
|
|
56
|
+
});
|
|
57
|
+
let a = g(t.accessToken, t.validUntil, t.endUser);
|
|
58
|
+
if (t.isNewEndUser) {
|
|
59
|
+
const d = await f(r().projectId, a.user.userId, {
|
|
60
|
+
walletSecretId: await n().getWalletSecretId(a)
|
|
61
|
+
});
|
|
62
|
+
a = g(t.accessToken, t.validUntil, d);
|
|
63
|
+
}
|
|
64
|
+
await n().setAuthState(a);
|
|
65
|
+
const c = await n().getUser();
|
|
66
|
+
return {
|
|
67
|
+
message: t.message,
|
|
68
|
+
user: c,
|
|
69
|
+
isNewUser: t.isNewEndUser
|
|
70
|
+
};
|
|
71
|
+
}, $ = async () => n().getUser(), G = async () => n().isSignedIn(), J = async () => {
|
|
72
|
+
if (r().useMock) {
|
|
73
|
+
await n().signOut();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!await n().isSignedIn())
|
|
77
|
+
throw new Error("User not signed in");
|
|
78
|
+
await n().signOut();
|
|
79
|
+
}, L = (e) => {
|
|
80
|
+
n().addAuthStateChangeCallback(e);
|
|
81
|
+
}, Q = async (e) => r().useMock ? { signature: "0x0" } : o(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
82
|
+
signature: (await y(r().projectId, s.userId, {
|
|
83
|
+
hash: e.hash,
|
|
84
|
+
address: e.evmAccount,
|
|
85
|
+
walletSecretId: t
|
|
86
|
+
})).signature
|
|
87
|
+
})), R = async (e) => r().useMock ? { signedTransaction: "0x0" } : o(e, n(), async ({ user: s, walletSecretId: t }) => {
|
|
88
|
+
const a = w(e.transaction);
|
|
89
|
+
return {
|
|
90
|
+
signedTransaction: (await E(
|
|
91
|
+
r().projectId,
|
|
92
|
+
s.userId,
|
|
93
|
+
{
|
|
94
|
+
transaction: a,
|
|
95
|
+
address: e.evmAccount,
|
|
96
|
+
walletSecretId: t
|
|
97
|
+
}
|
|
98
|
+
)).signedTransaction
|
|
99
|
+
};
|
|
100
|
+
}), V = async (e) => {
|
|
101
|
+
if (!P(e.network))
|
|
102
|
+
throw new Error(`Chain ${e.network} is not supported by the CDP Apis`);
|
|
103
|
+
if (r().useMock)
|
|
104
|
+
return { transactionHash: "0x0" };
|
|
105
|
+
const s = w(e.transaction);
|
|
106
|
+
return o(e, n(), async ({ user: t, walletSecretId: a }) => ({
|
|
107
|
+
transactionHash: (await v(
|
|
108
|
+
r().projectId,
|
|
109
|
+
t.userId,
|
|
110
|
+
{
|
|
111
|
+
transaction: s,
|
|
112
|
+
address: e.evmAccount,
|
|
113
|
+
walletSecretId: a,
|
|
114
|
+
network: e.network
|
|
115
|
+
}
|
|
116
|
+
)).transactionHash
|
|
117
|
+
}));
|
|
118
|
+
}, X = async (e) => r().useMock ? { signature: "0x0" } : o(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
119
|
+
signature: (await A(r().projectId, s.userId, {
|
|
120
|
+
message: e.message,
|
|
121
|
+
address: e.evmAccount,
|
|
122
|
+
walletSecretId: t
|
|
123
|
+
})).signature
|
|
124
|
+
})), Y = async (e) => r().useMock ? { signature: "0x0" } : o(e, n(), async ({ user: s, walletSecretId: t }) => ({
|
|
125
|
+
signature: (await k(r().projectId, s.userId, {
|
|
126
|
+
typedData: e.typedData,
|
|
127
|
+
address: e.evmAccount,
|
|
128
|
+
walletSecretId: t
|
|
129
|
+
})).signature
|
|
130
|
+
})), Z = async (e) => {
|
|
131
|
+
if (r().useMock)
|
|
132
|
+
return {
|
|
133
|
+
privateKey: "mock-private-key"
|
|
134
|
+
};
|
|
135
|
+
const s = await M();
|
|
136
|
+
return o(e, n(), async ({ user: t, walletSecretId: a }) => {
|
|
137
|
+
const c = await S(r().projectId, t.userId, {
|
|
138
|
+
address: e.evmAccount,
|
|
139
|
+
walletSecretId: a,
|
|
140
|
+
exportEncryptionKey: s.publicKeyBase64
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
privateKey: await T(
|
|
144
|
+
s.privateKey,
|
|
145
|
+
c.encryptedPrivateKey
|
|
146
|
+
)
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}, r = () => {
|
|
150
|
+
if (!i)
|
|
151
|
+
throw new Error("SDK not initialized");
|
|
152
|
+
return i;
|
|
153
|
+
}, n = () => {
|
|
154
|
+
if (!u)
|
|
155
|
+
throw new Error("SDK not initialized");
|
|
156
|
+
return u;
|
|
157
|
+
};
|
|
158
|
+
export {
|
|
159
|
+
Z as exportEvmAccount,
|
|
160
|
+
$ as getCurrentUser,
|
|
161
|
+
q as initialize,
|
|
162
|
+
G as isSignedIn,
|
|
163
|
+
L as onAuthStateChange,
|
|
164
|
+
V as sendEvmTransaction,
|
|
165
|
+
Q as signEvmHash,
|
|
166
|
+
X as signEvmMessage,
|
|
167
|
+
R as signEvmTransaction,
|
|
168
|
+
Y as signEvmTypedData,
|
|
169
|
+
B as signInWithEmail,
|
|
170
|
+
J as signOut,
|
|
171
|
+
F as verifyEmailOTP
|
|
172
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { toHex as i } from "./index24.js";
|
|
2
|
+
import { toYParitySignatureArray as c } from "./index13.js";
|
|
3
|
+
function f(r) {
|
|
4
|
+
if (!r || r.length === 0)
|
|
5
|
+
return [];
|
|
6
|
+
const t = [];
|
|
7
|
+
for (const o of r) {
|
|
8
|
+
const { chainId: n, nonce: e, ...s } = o, a = o.address;
|
|
9
|
+
t.push([
|
|
10
|
+
n ? i(n) : "0x",
|
|
11
|
+
a,
|
|
12
|
+
e ? i(e) : "0x",
|
|
13
|
+
...c({}, s)
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
f as serializeAuthorizationList
|
|
20
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IntegerOutOfRangeError as x } from "./index46.js";
|
|
2
|
+
import { pad as s } from "./index32.js";
|
|
3
|
+
import { assertSize as c } from "./index40.js";
|
|
4
|
+
const b = /* @__PURE__ */ Array.from({ length: 256 }, (n, e) => e.toString(16).padStart(2, "0"));
|
|
5
|
+
function B(n, e = {}) {
|
|
6
|
+
return typeof n == "number" || typeof n == "bigint" ? y(n, e) : typeof n == "string" ? $(n, e) : typeof n == "boolean" ? z(n, e) : m(n, e);
|
|
7
|
+
}
|
|
8
|
+
function z(n, e = {}) {
|
|
9
|
+
const t = `0x${Number(n)}`;
|
|
10
|
+
return typeof e.size == "number" ? (c(t, { size: e.size }), s(t, { size: e.size })) : t;
|
|
11
|
+
}
|
|
12
|
+
function m(n, e = {}) {
|
|
13
|
+
let t = "";
|
|
14
|
+
for (let i = 0; i < n.length; i++)
|
|
15
|
+
t += b[n[i]];
|
|
16
|
+
const r = `0x${t}`;
|
|
17
|
+
return typeof e.size == "number" ? (c(r, { size: e.size }), s(r, { dir: "right", size: e.size })) : r;
|
|
18
|
+
}
|
|
19
|
+
function y(n, e = {}) {
|
|
20
|
+
const { signed: t, size: r } = e, i = BigInt(n);
|
|
21
|
+
let o;
|
|
22
|
+
r ? t ? o = (1n << BigInt(r) * 8n - 1n) - 1n : o = 2n ** (BigInt(r) * 8n) - 1n : typeof n == "number" && (o = BigInt(Number.MAX_SAFE_INTEGER));
|
|
23
|
+
const g = typeof o == "bigint" && t ? -o - 1n : 0;
|
|
24
|
+
if (o && i > o || i < g) {
|
|
25
|
+
const f = typeof n == "bigint" ? "n" : "";
|
|
26
|
+
throw new x({
|
|
27
|
+
max: o ? `${o}${f}` : void 0,
|
|
28
|
+
min: `${g}${f}`,
|
|
29
|
+
signed: t,
|
|
30
|
+
size: r,
|
|
31
|
+
value: `${n}${f}`
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const u = `0x${(t && i < 0 ? (1n << BigInt(r * 8)) + BigInt(i) : i).toString(16)}`;
|
|
35
|
+
return r ? s(u, { size: r }) : u;
|
|
36
|
+
}
|
|
37
|
+
const d = /* @__PURE__ */ new TextEncoder();
|
|
38
|
+
function $(n, e = {}) {
|
|
39
|
+
const t = d.encode(n);
|
|
40
|
+
return m(t, e);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
z as boolToHex,
|
|
44
|
+
m as bytesToHex,
|
|
45
|
+
y as numberToHex,
|
|
46
|
+
$ as stringToHex,
|
|
47
|
+
B as toHex
|
|
48
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { stringToBytes as p } from "./index26.js";
|
|
2
|
+
import { keccak256 as f } from "./index27.js";
|
|
3
|
+
import { LruMap as m } from "./index28.js";
|
|
4
|
+
const r = /* @__PURE__ */ new m(8192);
|
|
5
|
+
function a(s, o) {
|
|
6
|
+
if (r.has(`${s}.${o}`))
|
|
7
|
+
return r.get(`${s}.${o}`);
|
|
8
|
+
const c = s.substring(2).toLowerCase(), n = f(p(c)), e = c.split("");
|
|
9
|
+
for (let t = 0; t < 40; t += 2)
|
|
10
|
+
n[t >> 1] >> 4 >= 8 && e[t] && (e[t] = e[t].toUpperCase()), (n[t >> 1] & 15) >= 8 && e[t + 1] && (e[t + 1] = e[t + 1].toUpperCase());
|
|
11
|
+
const i = `0x${e.join("")}`;
|
|
12
|
+
return r.set(`${s}.${o}`, i), i;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
a as checksumAddress
|
|
16
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BaseError as g } from "./index44.js";
|
|
2
|
+
import { isHex as x } from "./index31.js";
|
|
3
|
+
import { pad as s } from "./index32.js";
|
|
4
|
+
import { assertSize as u } from "./index40.js";
|
|
5
|
+
import { numberToHex as h } from "./index24.js";
|
|
6
|
+
const A = /* @__PURE__ */ new TextEncoder();
|
|
7
|
+
function F(e, n = {}) {
|
|
8
|
+
return typeof e == "number" || typeof e == "bigint" ? T(e, n) : typeof e == "boolean" ? B(e, n) : x(e) ? y(e, n) : l(e, n);
|
|
9
|
+
}
|
|
10
|
+
function B(e, n = {}) {
|
|
11
|
+
const r = new Uint8Array(1);
|
|
12
|
+
return r[0] = Number(e), typeof n.size == "number" ? (u(r, { size: n.size }), s(r, { size: n.size })) : r;
|
|
13
|
+
}
|
|
14
|
+
const t = {
|
|
15
|
+
zero: 48,
|
|
16
|
+
nine: 57,
|
|
17
|
+
A: 65,
|
|
18
|
+
F: 70,
|
|
19
|
+
a: 97,
|
|
20
|
+
f: 102
|
|
21
|
+
};
|
|
22
|
+
function m(e) {
|
|
23
|
+
if (e >= t.zero && e <= t.nine)
|
|
24
|
+
return e - t.zero;
|
|
25
|
+
if (e >= t.A && e <= t.F)
|
|
26
|
+
return e - (t.A - 10);
|
|
27
|
+
if (e >= t.a && e <= t.f)
|
|
28
|
+
return e - (t.a - 10);
|
|
29
|
+
}
|
|
30
|
+
function y(e, n = {}) {
|
|
31
|
+
let r = e;
|
|
32
|
+
n.size && (u(r, { size: n.size }), r = s(r, { dir: "right", size: n.size }));
|
|
33
|
+
let i = r.slice(2);
|
|
34
|
+
i.length % 2 && (i = `0${i}`);
|
|
35
|
+
const z = i.length / 2, d = new Uint8Array(z);
|
|
36
|
+
for (let f = 0, o = 0; f < z; f++) {
|
|
37
|
+
const b = m(i.charCodeAt(o++)), c = m(i.charCodeAt(o++));
|
|
38
|
+
if (b === void 0 || c === void 0)
|
|
39
|
+
throw new g(`Invalid byte sequence ("${i[o - 2]}${i[o - 1]}" in "${i}").`);
|
|
40
|
+
d[f] = b * 16 + c;
|
|
41
|
+
}
|
|
42
|
+
return d;
|
|
43
|
+
}
|
|
44
|
+
function T(e, n) {
|
|
45
|
+
const r = h(e, n);
|
|
46
|
+
return y(r);
|
|
47
|
+
}
|
|
48
|
+
function l(e, n = {}) {
|
|
49
|
+
const r = A.encode(e);
|
|
50
|
+
return typeof n.size == "number" ? (u(r, { size: n.size }), s(r, { dir: "right", size: n.size })) : r;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
B as boolToBytes,
|
|
54
|
+
y as hexToBytes,
|
|
55
|
+
T as numberToBytes,
|
|
56
|
+
l as stringToBytes,
|
|
57
|
+
F as toBytes
|
|
58
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class r extends Map {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
super(), Object.defineProperty(this, "maxSize", {
|
|
4
|
+
enumerable: !0,
|
|
5
|
+
configurable: !0,
|
|
6
|
+
writable: !0,
|
|
7
|
+
value: void 0
|
|
8
|
+
}), this.maxSize = e;
|
|
9
|
+
}
|
|
10
|
+
get(e) {
|
|
11
|
+
const t = super.get(e);
|
|
12
|
+
return super.has(e) && t !== void 0 && (this.delete(e), super.set(e, t)), t;
|
|
13
|
+
}
|
|
14
|
+
set(e, t) {
|
|
15
|
+
if (super.set(e, t), this.maxSize && this.size > this.maxSize) {
|
|
16
|
+
const s = this.keys().next().value;
|
|
17
|
+
s && this.delete(s);
|
|
18
|
+
}
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
r as LruMap
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LruMap as u } from "./index28.js";
|
|
2
|
+
import { checksumAddress as c } from "./index25.js";
|
|
3
|
+
const i = /^0x[a-fA-F0-9]{40}$/, r = /* @__PURE__ */ new u(8192);
|
|
4
|
+
function h(t, s) {
|
|
5
|
+
const { strict: n = !0 } = s ?? {}, e = `${t}.${n}`;
|
|
6
|
+
if (r.has(e))
|
|
7
|
+
return r.get(e);
|
|
8
|
+
const o = i.test(t) ? t.toLowerCase() === t ? !0 : n ? c(t) === t : !0 : !1;
|
|
9
|
+
return r.set(e, o), o;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
h as isAddress,
|
|
13
|
+
r as isAddressCache
|
|
14
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Provider as m } from "ox";
|
|
2
|
+
import { http as l } from "viem";
|
|
3
|
+
import { create as p } from "zustand";
|
|
4
|
+
import { subscribeWithSelector as f, persist as g } from "./index14.js";
|
|
5
|
+
import { validateRequest as I, EIP1193ProviderError as S, STANDARD_ERROR_CODES as w } from "./index4.js";
|
|
6
|
+
import { EventEmitter as b } from "./index15.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 "./index16.js";
|
|
8
|
+
import { onAuthStateChange as q } from "./index2.js";
|
|
9
|
+
import { baseSepolia as h } from "./index17.js";
|
|
10
|
+
function y(e, r, a) {
|
|
11
|
+
r.subscribe(
|
|
12
|
+
(n) => n.chainId,
|
|
13
|
+
(n, t) => {
|
|
14
|
+
n !== t && e.emit("chainChanged", n);
|
|
15
|
+
}
|
|
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");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (n && n.evmAccounts?.length && (!t || t.evmAccounts?.length === 0)) {
|
|
25
|
+
const u = r.getState().chainId;
|
|
26
|
+
e.emit("connect", { chainId: u });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
);
|
|
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) {
|
|
38
|
+
case "eth_accounts":
|
|
39
|
+
return T();
|
|
40
|
+
case "eth_requestAccounts":
|
|
41
|
+
return E(e, r);
|
|
42
|
+
case "personal_sign":
|
|
43
|
+
return R(t.params);
|
|
44
|
+
case "eth_sendTransaction":
|
|
45
|
+
return P(t.params, r, a.transports);
|
|
46
|
+
case "wallet_disconnect":
|
|
47
|
+
return D(e);
|
|
48
|
+
case "wallet_switchEthereumChain":
|
|
49
|
+
return v(t.params, r);
|
|
50
|
+
case "eth_sign":
|
|
51
|
+
return _(t.params);
|
|
52
|
+
case "eth_signTypedData_v4":
|
|
53
|
+
return C(t.params);
|
|
54
|
+
case "eth_chainId":
|
|
55
|
+
return A(r);
|
|
56
|
+
// Catch-all for any unknown method
|
|
57
|
+
default:
|
|
58
|
+
throw new S(
|
|
59
|
+
w.provider.unsupportedMethod,
|
|
60
|
+
`Method ${t.method} not supported`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
// Event emitter methods - only the ones required by the interface
|
|
65
|
+
on: e.on.bind(e),
|
|
66
|
+
removeListener: e.removeListener.bind(e)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const d = {
|
|
70
|
+
chains: [h],
|
|
71
|
+
transports: {
|
|
72
|
+
[h.id]: l()
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function z(e) {
|
|
76
|
+
if (e?.chains.length === 0)
|
|
77
|
+
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)
|
|
80
|
+
throw new Error("No chains found in configuration");
|
|
81
|
+
const s = new b(), i = p()(
|
|
82
|
+
f(
|
|
83
|
+
g(
|
|
84
|
+
(o) => ({
|
|
85
|
+
chainId: r[0].id,
|
|
86
|
+
setChainId: (n) => o({ chainId: n }),
|
|
87
|
+
chains: r,
|
|
88
|
+
user: null,
|
|
89
|
+
setUser: (n) => o({ user: n })
|
|
90
|
+
}),
|
|
91
|
+
{
|
|
92
|
+
name: "cdp-provider-store"
|
|
93
|
+
// localStorage key
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
return q((o) => {
|
|
99
|
+
i.getState().setUser(o);
|
|
100
|
+
}), {
|
|
101
|
+
provider: y(s, i, {
|
|
102
|
+
chains: r,
|
|
103
|
+
transports: a
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
z as createCDPEmbeddedWallet
|
|
109
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SizeExceedsPaddingSizeError as d } from "./index33.js";
|
|
2
|
+
function f(n, { dir: r, size: t = 32 } = {}) {
|
|
3
|
+
return typeof n == "string" ? p(n, { dir: r, size: t }) : i(n, { dir: r, size: t });
|
|
4
|
+
}
|
|
5
|
+
function p(n, { dir: r, size: t = 32 } = {}) {
|
|
6
|
+
if (t === null)
|
|
7
|
+
return n;
|
|
8
|
+
const e = n.replace("0x", "");
|
|
9
|
+
if (e.length > t * 2)
|
|
10
|
+
throw new d({
|
|
11
|
+
size: Math.ceil(e.length / 2),
|
|
12
|
+
targetSize: t,
|
|
13
|
+
type: "hex"
|
|
14
|
+
});
|
|
15
|
+
return `0x${e[r === "right" ? "padEnd" : "padStart"](t * 2, "0")}`;
|
|
16
|
+
}
|
|
17
|
+
function i(n, { dir: r, size: t = 32 } = {}) {
|
|
18
|
+
if (t === null)
|
|
19
|
+
return n;
|
|
20
|
+
if (n.length > t)
|
|
21
|
+
throw new d({
|
|
22
|
+
size: n.length,
|
|
23
|
+
targetSize: t,
|
|
24
|
+
type: "bytes"
|
|
25
|
+
});
|
|
26
|
+
const e = new Uint8Array(t);
|
|
27
|
+
for (let a = 0; a < t; a++) {
|
|
28
|
+
const o = r === "right";
|
|
29
|
+
e[o ? a : t - a - 1] = n[o ? a : n.length - a - 1];
|
|
30
|
+
}
|
|
31
|
+
return e;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
f as pad,
|
|
35
|
+
i as padBytes,
|
|
36
|
+
p as padHex
|
|
37
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError as o } from "./index44.js";
|
|
2
|
+
class d extends o {
|
|
3
|
+
constructor({ offset: r, position: s, size: e }) {
|
|
4
|
+
super(`Slice ${s === "start" ? "starting" : "ending"} at offset "${r}" is out-of-bounds (size: ${e}).`, { name: "SliceOffsetOutOfBoundsError" });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class n extends o {
|
|
8
|
+
constructor({ size: r, targetSize: s, type: e }) {
|
|
9
|
+
super(`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()} size (${r}) exceeds padding size (${s}).`, { name: "SizeExceedsPaddingSizeError" });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
n as SizeExceedsPaddingSizeError,
|
|
14
|
+
d as SliceOffsetOutOfBoundsError
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SliceOffsetOutOfBoundsError as n } from "./index33.js";
|
|
2
|
+
import { isHex as c } from "./index31.js";
|
|
3
|
+
import { size as s } from "./index34.js";
|
|
4
|
+
function O(e, f, i, { strict: o } = {}) {
|
|
5
|
+
return c(e, { strict: !1 }) ? l(e, f, i, {
|
|
6
|
+
strict: o
|
|
7
|
+
}) : u(e, f, i, {
|
|
8
|
+
strict: o
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function t(e, f, i) {
|
|
12
|
+
if (s(e) !== i - f)
|
|
13
|
+
throw new n({
|
|
14
|
+
offset: i,
|
|
15
|
+
position: "end",
|
|
16
|
+
size: s(e)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function u(e, f, i, { strict: o } = {}) {
|
|
20
|
+
const r = e.slice(f, i);
|
|
21
|
+
return o && t(r, f, i), r;
|
|
22
|
+
}
|
|
23
|
+
function l(e, f, i, { strict: o } = {}) {
|
|
24
|
+
const r = `0x${e.replace("0x", "").slice(f * 2, i * 2)}`;
|
|
25
|
+
return o && t(r, f, i), r;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
O as slice,
|
|
29
|
+
u as sliceBytes,
|
|
30
|
+
l as sliceHex
|
|
31
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function f(e, { dir: n = "left" } = {}) {
|
|
2
|
+
let t = typeof e == "string" ? e.replace("0x", "") : e, i = 0;
|
|
3
|
+
for (let l = 0; l < t.length - 1 && t[n === "left" ? l : t.length - l - 1].toString() === "0"; l++)
|
|
4
|
+
i++;
|
|
5
|
+
return t = n === "left" ? t.slice(i) : t.slice(0, t.length - i), typeof e == "string" ? (t.length === 1 && n === "right" && (t = `${t}0`), `0x${t.length % 2 === 1 ? `0${t}` : t}`) : t;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
f as trim
|
|
9
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineFormatter as s } from "./index38.js";
|
|
2
|
+
import { formatTransaction as t } from "./index39.js";
|
|
3
|
+
function a(e) {
|
|
4
|
+
const i = (e.transactions ?? []).map((n) => typeof n == "string" ? n : t(n));
|
|
5
|
+
return {
|
|
6
|
+
...e,
|
|
7
|
+
baseFeePerGas: e.baseFeePerGas ? BigInt(e.baseFeePerGas) : null,
|
|
8
|
+
blobGasUsed: e.blobGasUsed ? BigInt(e.blobGasUsed) : void 0,
|
|
9
|
+
difficulty: e.difficulty ? BigInt(e.difficulty) : void 0,
|
|
10
|
+
excessBlobGas: e.excessBlobGas ? BigInt(e.excessBlobGas) : void 0,
|
|
11
|
+
gasLimit: e.gasLimit ? BigInt(e.gasLimit) : void 0,
|
|
12
|
+
gasUsed: e.gasUsed ? BigInt(e.gasUsed) : void 0,
|
|
13
|
+
hash: e.hash ? e.hash : null,
|
|
14
|
+
logsBloom: e.logsBloom ? e.logsBloom : null,
|
|
15
|
+
nonce: e.nonce ? e.nonce : null,
|
|
16
|
+
number: e.number ? BigInt(e.number) : null,
|
|
17
|
+
size: e.size ? BigInt(e.size) : void 0,
|
|
18
|
+
timestamp: e.timestamp ? BigInt(e.timestamp) : void 0,
|
|
19
|
+
transactions: i,
|
|
20
|
+
totalDifficulty: e.totalDifficulty ? BigInt(e.totalDifficulty) : null
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const d = /* @__PURE__ */ s("block", a);
|
|
24
|
+
export {
|
|
25
|
+
d as defineBlock,
|
|
26
|
+
a as formatBlock
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function a(e, f) {
|
|
2
|
+
return ({ exclude: t, format: n }) => ({
|
|
3
|
+
exclude: t,
|
|
4
|
+
format: (r) => {
|
|
5
|
+
const o = f(r);
|
|
6
|
+
if (t)
|
|
7
|
+
for (const m of t)
|
|
8
|
+
delete o[m];
|
|
9
|
+
return {
|
|
10
|
+
...o,
|
|
11
|
+
...n(r)
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
type: e
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
a as defineFormatter
|
|
19
|
+
};
|