@coinbase/cdp-core 0.0.15 → 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.
@@ -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
- import { SignJWT as S } from "./index21.js";
2
+ import { SignJWT as S } from "./index17.js";
3
+ import "viem";
3
4
  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";
5
+ import { createKeyPair as f } from "./index18.js";
6
+ import { generateRandomId as n } from "./index19.js";
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,4 +1,4 @@
1
- import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index86.js";
1
+ import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index80.js";
2
2
  import { createHasher as u, clean as C, rotr as i } from "./index76.js";
3
3
  const B = /* @__PURE__ */ Uint32Array.from([
4
4
  1116352408,
@@ -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,12 +1,81 @@
1
- import { contracts as o } from "./index88.js";
2
- import { formatters as r } from "./index89.js";
3
- import { serializers as t } from "./index90.js";
4
- const e = {
5
- blockTime: 2e3,
6
- contracts: o,
7
- formatters: r,
8
- serializers: t
9
- };
1
+ import { Hash as g, createView as l, aexists as b, toBytes as a, abytes as d, aoutput as x, clean as w } from "./index76.js";
2
+ function y(o, t, s, n) {
3
+ if (typeof o.setBigUint64 == "function")
4
+ return o.setBigUint64(t, s, n);
5
+ const i = BigInt(32), h = BigInt(4294967295), e = Number(s >> i & h), r = Number(s & h), c = n ? 4 : 0, u = n ? 0 : 4;
6
+ o.setUint32(t + c, e, n), o.setUint32(t + u, r, n);
7
+ }
8
+ function U(o, t, s) {
9
+ return o & t ^ ~o & s;
10
+ }
11
+ function _(o, t, s) {
12
+ return o & t ^ o & s ^ t & s;
13
+ }
14
+ class m extends g {
15
+ constructor(t, s, n, i) {
16
+ super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = i, this.buffer = new Uint8Array(t), this.view = l(this.buffer);
17
+ }
18
+ update(t) {
19
+ b(this), t = a(t), d(t);
20
+ const { view: s, buffer: n, blockLen: i } = this, h = t.length;
21
+ for (let e = 0; e < h; ) {
22
+ const r = Math.min(i - this.pos, h - e);
23
+ if (r === i) {
24
+ const c = l(t);
25
+ for (; i <= h - e; e += i)
26
+ this.process(c, e);
27
+ continue;
28
+ }
29
+ n.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === i && (this.process(s, 0), this.pos = 0);
30
+ }
31
+ return this.length += t.length, this.roundClean(), this;
32
+ }
33
+ digestInto(t) {
34
+ b(this), x(t, this), this.finished = !0;
35
+ const { buffer: s, view: n, blockLen: i, isLE: h } = this;
36
+ let { pos: e } = this;
37
+ s[e++] = 128, w(this.buffer.subarray(e)), this.padOffset > i - e && (this.process(n, 0), e = 0);
38
+ for (let f = e; f < i; f++)
39
+ s[f] = 0;
40
+ y(n, i - 8, BigInt(this.length * 8), h), this.process(n, 0);
41
+ const r = l(t), c = this.outputLen;
42
+ if (c % 4)
43
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
44
+ const u = c / 4, p = this.get();
45
+ if (u > p.length)
46
+ throw new Error("_sha2: outputLen bigger than state");
47
+ for (let f = 0; f < u; f++)
48
+ r.setUint32(4 * f, p[f], h);
49
+ }
50
+ digest() {
51
+ const { buffer: t, outputLen: s } = this;
52
+ this.digestInto(t);
53
+ const n = t.slice(0, s);
54
+ return this.destroy(), n;
55
+ }
56
+ _cloneInto(t) {
57
+ t || (t = new this.constructor()), t.set(...this.get());
58
+ const { blockLen: s, buffer: n, length: i, finished: h, destroyed: e, pos: r } = this;
59
+ return t.destroyed = e, t.finished = h, t.length = i, t.pos = r, i % s && t.buffer.set(n), t;
60
+ }
61
+ clone() {
62
+ return this._cloneInto();
63
+ }
64
+ }
65
+ const B = /* @__PURE__ */ Uint32Array.from([
66
+ 1779033703,
67
+ 3144134277,
68
+ 1013904242,
69
+ 2773480762,
70
+ 1359893119,
71
+ 2600822924,
72
+ 528734635,
73
+ 1541459225
74
+ ]);
10
75
  export {
11
- e as chainConfig
76
+ U as Chi,
77
+ m as HashMD,
78
+ _ as Maj,
79
+ B as SHA256_IV,
80
+ y as setBigUint64
12
81
  };
@@ -1,11 +1,11 @@
1
- import { encode as d } from "./index91.js";
2
- import y from "./index92.js";
3
- import b from "./index93.js";
1
+ import { encode as d } from "./index88.js";
2
+ import y from "./index89.js";
3
+ import b from "./index90.js";
4
4
  import { JWSInvalid as r } from "./index71.js";
5
5
  import { encoder as s, concat as u, decoder as h } from "./index82.js";
6
- import g from "./index94.js";
7
- import H from "./index95.js";
8
- import P from "./index96.js";
6
+ import g from "./index91.js";
7
+ import H from "./index92.js";
8
+ import P from "./index93.js";
9
9
  class x {
10
10
  #r;
11
11
  #e;
@@ -1,81 +1,12 @@
1
- import { Hash as g, createView as l, aexists as b, toBytes as a, abytes as d, aoutput as x, clean as w } from "./index76.js";
2
- function y(o, t, s, n) {
3
- if (typeof o.setBigUint64 == "function")
4
- return o.setBigUint64(t, s, n);
5
- const i = BigInt(32), h = BigInt(4294967295), e = Number(s >> i & h), r = Number(s & h), c = n ? 4 : 0, u = n ? 0 : 4;
6
- o.setUint32(t + c, e, n), o.setUint32(t + u, r, n);
7
- }
8
- function U(o, t, s) {
9
- return o & t ^ ~o & s;
10
- }
11
- function _(o, t, s) {
12
- return o & t ^ o & s ^ t & s;
13
- }
14
- class m extends g {
15
- constructor(t, s, n, i) {
16
- super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = i, this.buffer = new Uint8Array(t), this.view = l(this.buffer);
17
- }
18
- update(t) {
19
- b(this), t = a(t), d(t);
20
- const { view: s, buffer: n, blockLen: i } = this, h = t.length;
21
- for (let e = 0; e < h; ) {
22
- const r = Math.min(i - this.pos, h - e);
23
- if (r === i) {
24
- const c = l(t);
25
- for (; i <= h - e; e += i)
26
- this.process(c, e);
27
- continue;
28
- }
29
- n.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === i && (this.process(s, 0), this.pos = 0);
30
- }
31
- return this.length += t.length, this.roundClean(), this;
32
- }
33
- digestInto(t) {
34
- b(this), x(t, this), this.finished = !0;
35
- const { buffer: s, view: n, blockLen: i, isLE: h } = this;
36
- let { pos: e } = this;
37
- s[e++] = 128, w(this.buffer.subarray(e)), this.padOffset > i - e && (this.process(n, 0), e = 0);
38
- for (let f = e; f < i; f++)
39
- s[f] = 0;
40
- y(n, i - 8, BigInt(this.length * 8), h), this.process(n, 0);
41
- const r = l(t), c = this.outputLen;
42
- if (c % 4)
43
- throw new Error("_sha2: outputLen should be aligned to 32bit");
44
- const u = c / 4, p = this.get();
45
- if (u > p.length)
46
- throw new Error("_sha2: outputLen bigger than state");
47
- for (let f = 0; f < u; f++)
48
- r.setUint32(4 * f, p[f], h);
49
- }
50
- digest() {
51
- const { buffer: t, outputLen: s } = this;
52
- this.digestInto(t);
53
- const n = t.slice(0, s);
54
- return this.destroy(), n;
55
- }
56
- _cloneInto(t) {
57
- t || (t = new this.constructor()), t.set(...this.get());
58
- const { blockLen: s, buffer: n, length: i, finished: h, destroyed: e, pos: r } = this;
59
- return t.destroyed = e, t.finished = h, t.length = i, t.pos = r, i % s && t.buffer.set(n), t;
60
- }
61
- clone() {
62
- return this._cloneInto();
63
- }
64
- }
65
- const B = /* @__PURE__ */ Uint32Array.from([
66
- 1779033703,
67
- 3144134277,
68
- 1013904242,
69
- 2773480762,
70
- 1359893119,
71
- 2600822924,
72
- 528734635,
73
- 1541459225
74
- ]);
1
+ import { contracts as o } from "./index94.js";
2
+ import { formatters as r } from "./index95.js";
3
+ import { serializers as t } from "./index96.js";
4
+ const e = {
5
+ blockTime: 2e3,
6
+ contracts: o,
7
+ formatters: r,
8
+ serializers: t
9
+ };
75
10
  export {
76
- U as Chi,
77
- m as HashMD,
78
- _ as Maj,
79
- B as SHA256_IV,
80
- y as setBigUint64
11
+ e as chainConfig
81
12
  };
@@ -1,15 +1,23 @@
1
- const s = {
2
- gasPriceOracle: { address: "0x420000000000000000000000000000000000000F" },
3
- l1Block: { address: "0x4200000000000000000000000000000000000015" },
4
- l2CrossDomainMessenger: {
5
- address: "0x4200000000000000000000000000000000000007"
6
- },
7
- l2Erc721Bridge: { address: "0x4200000000000000000000000000000000000014" },
8
- l2StandardBridge: { address: "0x4200000000000000000000000000000000000010" },
9
- l2ToL1MessagePasser: {
10
- address: "0x4200000000000000000000000000000000000016"
1
+ import { encoder as t, decoder as o } from "./index82.js";
2
+ import { encodeBase64 as c, decodeBase64 as a } from "./index97.js";
3
+ function i(r) {
4
+ if (Uint8Array.fromBase64)
5
+ return Uint8Array.fromBase64(typeof r == "string" ? r : o.decode(r), {
6
+ alphabet: "base64url"
7
+ });
8
+ let e = r;
9
+ e instanceof Uint8Array && (e = o.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
10
+ try {
11
+ return a(e);
12
+ } catch {
13
+ throw new TypeError("The input to be decoded is not correctly encoded.");
11
14
  }
12
- };
15
+ }
16
+ function p(r) {
17
+ let e = r;
18
+ return typeof e == "string" && (e = t.encode(e)), Uint8Array.prototype.toBase64 ? e.toBase64({ alphabet: "base64url", omitPadding: !0 }) : c(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
19
+ }
13
20
  export {
14
- s as contracts
21
+ i as decode,
22
+ p as encode
15
23
  };
@@ -1,38 +1,12 @@
1
- import { hexToBigInt as n } from "./index43.js";
2
- import { defineBlock as r } from "./index40.js";
3
- import { defineTransaction as s, formatTransaction as m } from "./index42.js";
4
- import { defineTransactionReceipt as l } from "./index45.js";
5
- const p = {
6
- block: /* @__PURE__ */ r({
7
- format(e) {
8
- return {
9
- transactions: e.transactions?.map((t) => {
10
- if (typeof t == "string")
11
- return t;
12
- const i = m(t);
13
- return i.typeHex === "0x7e" && (i.isSystemTx = t.isSystemTx, i.mint = t.mint ? n(t.mint) : void 0, i.sourceHash = t.sourceHash, i.type = "deposit"), i;
14
- }),
15
- stateRoot: e.stateRoot
16
- };
17
- }
18
- }),
19
- transaction: /* @__PURE__ */ s({
20
- format(e) {
21
- const o = {};
22
- return e.type === "0x7e" && (o.isSystemTx = e.isSystemTx, o.mint = e.mint ? n(e.mint) : void 0, o.sourceHash = e.sourceHash, o.type = "deposit"), o;
23
- }
24
- }),
25
- transactionReceipt: /* @__PURE__ */ l({
26
- format(e) {
27
- return {
28
- l1GasPrice: e.l1GasPrice ? n(e.l1GasPrice) : null,
29
- l1GasUsed: e.l1GasUsed ? n(e.l1GasUsed) : null,
30
- l1Fee: e.l1Fee ? n(e.l1Fee) : null,
31
- l1FeeScalar: e.l1FeeScalar ? Number(e.l1FeeScalar) : null
32
- };
33
- }
34
- })
1
+ import n from "./index98.js";
2
+ import s from "./index99.js";
3
+ import a from "./index100.js";
4
+ const y = async (t, o, e) => {
5
+ const r = await a(t, o, "sign");
6
+ s(t, r);
7
+ const i = await crypto.subtle.sign(n(t, r.algorithm), r, e);
8
+ return new Uint8Array(i);
35
9
  };
36
10
  export {
37
- p as formatters
11
+ y as default
38
12
  };
@@ -1,44 +1,22 @@
1
- import { InvalidAddressError as a } from "./index58.js";
2
- import { isAddress as f } from "./index32.js";
3
- import { concatHex as p } from "./index33.js";
4
- import { toHex as i } from "./index27.js";
5
- import { toRlp as x } from "./index46.js";
6
- import { serializeTransaction as l } from "./index15.js";
7
- function T(r, e) {
8
- return h(r) ? z(r) : l(r, e);
9
- }
10
- const E = {
11
- transaction: T
1
+ const a = (...o) => {
2
+ const t = o.filter(Boolean);
3
+ if (t.length === 0 || t.length === 1)
4
+ return !0;
5
+ let e;
6
+ for (const s of t) {
7
+ const r = Object.keys(s);
8
+ if (!e || e.size === 0) {
9
+ e = new Set(r);
10
+ continue;
11
+ }
12
+ for (const n of r) {
13
+ if (e.has(n))
14
+ return !1;
15
+ e.add(n);
16
+ }
17
+ }
18
+ return !0;
12
19
  };
13
- function z(r) {
14
- w(r);
15
- const { sourceHash: e, data: o, from: m, gas: t, isSystemTx: u, mint: s, to: c, value: n } = r, d = [
16
- e,
17
- m,
18
- c ?? "0x",
19
- s ? i(s) : "0x",
20
- n ? i(n) : "0x",
21
- t ? i(t) : "0x",
22
- u ? "0x1" : "0x",
23
- o ?? "0x"
24
- ];
25
- return p([
26
- "0x7e",
27
- x(d)
28
- ]);
29
- }
30
- function h(r) {
31
- return r.type === "deposit" || typeof r.sourceHash < "u";
32
- }
33
- function w(r) {
34
- const { from: e, to: o } = r;
35
- if (e && !f(e))
36
- throw new a({ address: e });
37
- if (o && !f(o))
38
- throw new a({ address: o });
39
- }
40
20
  export {
41
- w as assertTransactionDeposit,
42
- T as serializeTransaction,
43
- E as serializers
21
+ a as default
44
22
  };