@coinbase/cdp-core 0.0.18 → 0.0.20

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.
Files changed (86) hide show
  1. package/README.md +13 -5
  2. package/dist/esm/index.js +24 -21
  3. package/dist/esm/index103.js +1 -1
  4. package/dist/esm/index13.js +9 -3
  5. package/dist/esm/index15.js +8 -8
  6. package/dist/esm/index16.js +2 -2
  7. package/dist/esm/index17.js +158 -39
  8. package/dist/esm/index18.js +47 -16
  9. package/dist/esm/index19.js +152 -4
  10. package/dist/esm/index2.js +138 -124
  11. package/dist/esm/index20.js +56 -5
  12. package/dist/esm/index21.js +39 -158
  13. package/dist/esm/index22.js +16 -47
  14. package/dist/esm/index23.js +4 -152
  15. package/dist/esm/index24.js +5 -56
  16. package/dist/esm/index25.js +12 -8
  17. package/dist/esm/index26.js +11 -17
  18. package/dist/esm/index27.js +8 -45
  19. package/dist/esm/index28.js +17 -13
  20. package/dist/esm/index29.js +40 -50
  21. package/dist/esm/index3.js +4 -4
  22. package/dist/esm/index30.js +13 -6
  23. package/dist/esm/index31.js +54 -20
  24. package/dist/esm/index32.js +6 -11
  25. package/dist/esm/index33.js +21 -3
  26. package/dist/esm/index34.js +3 -3
  27. package/dist/esm/index35.js +3 -34
  28. package/dist/esm/index36.js +32 -10
  29. package/dist/esm/index37.js +12 -4
  30. package/dist/esm/index38.js +4 -28
  31. package/dist/esm/index39.js +28 -6
  32. package/dist/esm/index40.js +6 -24
  33. package/dist/esm/index41.js +24 -16
  34. package/dist/esm/index42.js +16 -54
  35. package/dist/esm/index43.js +53 -22
  36. package/dist/esm/index44.js +23 -11
  37. package/dist/esm/index45.js +10 -26
  38. package/dist/esm/index46.js +26 -41
  39. package/dist/esm/index47.js +41 -54
  40. package/dist/esm/index48.js +54 -126
  41. package/dist/esm/index49.js +126 -11
  42. package/dist/esm/index50.js +9 -101
  43. package/dist/esm/index51.js +104 -6
  44. package/dist/esm/index52.js +7 -3
  45. package/dist/esm/index53.js +3 -15
  46. package/dist/esm/index54.js +14 -42
  47. package/dist/esm/index55.js +38 -74
  48. package/dist/esm/index56.js +79 -2
  49. package/dist/esm/index57.js +2 -2
  50. package/dist/esm/index58.js +2 -13
  51. package/dist/esm/index59.js +2 -2
  52. package/dist/esm/index6.js +4 -4
  53. package/dist/esm/index60.js +1 -1
  54. package/dist/esm/index61.js +1 -1
  55. package/dist/esm/index62.js +2 -2
  56. package/dist/esm/index63.js +2 -2
  57. package/dist/esm/index64.js +1 -1
  58. package/dist/esm/index65.js +1 -1
  59. package/dist/esm/index66.js +3 -3
  60. package/dist/esm/index70.js +1 -1
  61. package/dist/esm/index72.js +4 -4
  62. package/dist/esm/index73.js +104 -2
  63. package/dist/esm/index74.js +75 -17
  64. package/dist/esm/index75.js +80 -20
  65. package/dist/esm/index76.js +2 -80
  66. package/dist/esm/index77.js +17 -100
  67. package/dist/esm/index78.js +18 -31
  68. package/dist/esm/index79.js +32 -6
  69. package/dist/esm/index80.js +6 -78
  70. package/dist/esm/index81.js +10 -55
  71. package/dist/esm/index82.js +54 -10
  72. package/dist/esm/index83.js +11 -2
  73. package/dist/esm/index84.js +2 -45
  74. package/dist/esm/index85.js +44 -13
  75. package/dist/esm/index86.js +13 -9
  76. package/dist/esm/index88.js +12 -20
  77. package/dist/esm/index89.js +35 -9
  78. package/dist/esm/index90.js +41 -19
  79. package/dist/esm/index91.js +20 -93
  80. package/dist/esm/index92.js +9 -20
  81. package/dist/esm/index93.js +16 -114
  82. package/dist/esm/index94.js +92 -11
  83. package/dist/esm/index95.js +20 -35
  84. package/dist/esm/index96.js +117 -41
  85. package/dist/types/index.d.ts +32 -2
  86. package/package.json +3 -3
@@ -1,15 +1,96 @@
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 { withAlg as n } from "./index101.js";
2
+ import c from "./index102.js";
3
+ import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index103.js";
4
+ const s = (r) => r?.[Symbol.toStringTag], o = (r, e, t) => {
5
+ if (e.use !== void 0) {
6
+ let i;
7
+ switch (t) {
8
+ case "sign":
9
+ case "verify":
10
+ i = "sig";
11
+ break;
12
+ case "encrypt":
13
+ case "decrypt":
14
+ i = "enc";
15
+ break;
16
+ }
17
+ if (e.use !== i)
18
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
11
19
  }
20
+ if (e.alg !== void 0 && e.alg !== r)
21
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);
22
+ if (Array.isArray(e.key_ops)) {
23
+ let i;
24
+ switch (!0) {
25
+ case t === "sign":
26
+ case r === "dir":
27
+ case r.includes("CBC-HS"):
28
+ i = t;
29
+ break;
30
+ case r.startsWith("PBES2"):
31
+ i = "deriveBits";
32
+ break;
33
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(r):
34
+ !r.includes("GCM") && r.endsWith("KW") ? i = "unwrapKey" : i = t;
35
+ break;
36
+ case t === "encrypt":
37
+ i = "wrapKey";
38
+ break;
39
+ case t === "decrypt":
40
+ i = r.startsWith("RSA") ? "unwrapKey" : "deriveBits";
41
+ break;
42
+ }
43
+ if (i && e.key_ops?.includes?.(i) === !1)
44
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
45
+ }
46
+ return !0;
47
+ }, h = (r, e, t) => {
48
+ if (!(e instanceof Uint8Array)) {
49
+ if (p(e)) {
50
+ if (a(e) && o(r, e, t))
51
+ return;
52
+ throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
53
+ }
54
+ if (!c(e))
55
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
56
+ if (e.type !== "secret")
57
+ throw new TypeError(`${s(e)} instances for symmetric algorithms must be of type "secret"`);
58
+ }
59
+ }, m = (r, e, t) => {
60
+ if (p(e))
61
+ switch (t) {
62
+ case "decrypt":
63
+ case "sign":
64
+ if (f(e) && o(r, e, t))
65
+ return;
66
+ throw new TypeError("JSON Web Key for this operation be a private JWK");
67
+ case "encrypt":
68
+ case "verify":
69
+ if (y(e) && o(r, e, t))
70
+ return;
71
+ throw new TypeError("JSON Web Key for this operation be a public JWK");
72
+ }
73
+ if (!c(e))
74
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key"));
75
+ if (e.type === "secret")
76
+ throw new TypeError(`${s(e)} instances for asymmetric algorithms must not be of type "secret"`);
77
+ if (e.type === "public")
78
+ switch (t) {
79
+ case "sign":
80
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm signing must be of type "private"`);
81
+ case "decrypt":
82
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm decryption must be of type "private"`);
83
+ }
84
+ if (e.type === "private")
85
+ switch (t) {
86
+ case "verify":
87
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm verifying must be of type "public"`);
88
+ case "encrypt":
89
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm encryption must be of type "public"`);
90
+ }
91
+ }, d = (r, e, t) => {
92
+ r.startsWith("HS") || r === "dir" || r.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(r) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(r) ? h(r, e, t) : m(r, e, t);
12
93
  };
13
94
  export {
14
- s as contracts
95
+ d as default
15
96
  };
@@ -1,38 +1,23 @@
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 { JOSENotSupported as f } from "./index71.js";
2
+ const w = (n, r, a, e, s) => {
3
+ if (s.crit !== void 0 && e?.crit === void 0)
4
+ throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');
5
+ if (!e || e.crit === void 0)
6
+ return /* @__PURE__ */ new Set();
7
+ if (!Array.isArray(e.crit) || e.crit.length === 0 || e.crit.some((i) => typeof i != "string" || i.length === 0))
8
+ throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
9
+ let t;
10
+ a !== void 0 ? t = new Map([...Object.entries(a), ...r.entries()]) : t = r;
11
+ for (const i of e.crit) {
12
+ if (!t.has(i))
13
+ throw new f(`Extension Header Parameter "${i}" is not recognized`);
14
+ if (s[i] === void 0)
15
+ throw new n(`Extension Header Parameter "${i}" is missing`);
16
+ if (t.get(i) && e[i] === void 0)
17
+ throw new n(`Extension Header Parameter "${i}" MUST be integrity protected`);
18
+ }
19
+ return new Set(e.crit);
35
20
  };
36
21
  export {
37
- p as formatters
22
+ w as default
38
23
  };
@@ -1,44 +1,120 @@
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
+ import { isJWK as p } from "./index103.js";
2
+ import { decode as m } from "./index91.js";
3
+ import y from "./index104.js";
4
+ import { isCryptoKey as S, isKeyObject as K } from "./index102.js";
5
+ let c;
6
+ const f = async (e, r, s, i = !1) => {
7
+ c ||= /* @__PURE__ */ new WeakMap();
8
+ let n = c.get(e);
9
+ if (n?.[s])
10
+ return n[s];
11
+ const t = await y({ ...r, alg: s });
12
+ return i && Object.freeze(e), n ? n[s] = t : c.set(e, { [s]: t }), t;
13
+ }, E = (e, r) => {
14
+ c ||= /* @__PURE__ */ new WeakMap();
15
+ let s = c.get(e);
16
+ if (s?.[r])
17
+ return s[r];
18
+ const i = e.type === "public", n = !!i;
19
+ let t;
20
+ if (e.asymmetricKeyType === "x25519") {
21
+ switch (r) {
22
+ case "ECDH-ES":
23
+ case "ECDH-ES+A128KW":
24
+ case "ECDH-ES+A192KW":
25
+ case "ECDH-ES+A256KW":
26
+ break;
27
+ default:
28
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
29
+ }
30
+ t = e.toCryptoKey(e.asymmetricKeyType, n, i ? [] : ["deriveBits"]);
31
+ }
32
+ if (e.asymmetricKeyType === "ed25519") {
33
+ if (r !== "EdDSA" && r !== "Ed25519")
34
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
35
+ t = e.toCryptoKey(e.asymmetricKeyType, n, [
36
+ i ? "verify" : "sign"
37
+ ]);
38
+ }
39
+ if (e.asymmetricKeyType === "rsa") {
40
+ let a;
41
+ switch (r) {
42
+ case "RSA-OAEP":
43
+ a = "SHA-1";
44
+ break;
45
+ case "RS256":
46
+ case "PS256":
47
+ case "RSA-OAEP-256":
48
+ a = "SHA-256";
49
+ break;
50
+ case "RS384":
51
+ case "PS384":
52
+ case "RSA-OAEP-384":
53
+ a = "SHA-384";
54
+ break;
55
+ case "RS512":
56
+ case "PS512":
57
+ case "RSA-OAEP-512":
58
+ a = "SHA-512";
59
+ break;
60
+ default:
61
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
62
+ }
63
+ if (r.startsWith("RSA-OAEP"))
64
+ return e.toCryptoKey({
65
+ name: "RSA-OAEP",
66
+ hash: a
67
+ }, n, i ? ["encrypt"] : ["decrypt"]);
68
+ t = e.toCryptoKey({
69
+ name: r.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
70
+ hash: a
71
+ }, n, [i ? "verify" : "sign"]);
72
+ }
73
+ if (e.asymmetricKeyType === "ec") {
74
+ const o = (/* @__PURE__ */ new Map([
75
+ ["prime256v1", "P-256"],
76
+ ["secp384r1", "P-384"],
77
+ ["secp521r1", "P-521"]
78
+ ])).get(e.asymmetricKeyDetails?.namedCurve);
79
+ if (!o)
80
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
81
+ r === "ES256" && o === "P-256" && (t = e.toCryptoKey({
82
+ name: "ECDSA",
83
+ namedCurve: o
84
+ }, n, [i ? "verify" : "sign"])), r === "ES384" && o === "P-384" && (t = e.toCryptoKey({
85
+ name: "ECDSA",
86
+ namedCurve: o
87
+ }, n, [i ? "verify" : "sign"])), r === "ES512" && o === "P-521" && (t = e.toCryptoKey({
88
+ name: "ECDSA",
89
+ namedCurve: o
90
+ }, n, [i ? "verify" : "sign"])), r.startsWith("ECDH-ES") && (t = e.toCryptoKey({
91
+ name: "ECDH",
92
+ namedCurve: o
93
+ }, n, i ? [] : ["deriveBits"]));
94
+ }
95
+ if (!t)
96
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
97
+ return s ? s[r] = t : c.set(e, { [r]: t }), t;
98
+ }, d = async (e, r) => {
99
+ if (e instanceof Uint8Array || S(e))
100
+ return e;
101
+ if (K(e)) {
102
+ if (e.type === "secret")
103
+ return e.export();
104
+ if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
105
+ try {
106
+ return E(e, r);
107
+ } catch (i) {
108
+ if (i instanceof TypeError)
109
+ throw i;
110
+ }
111
+ let s = e.export({ format: "jwk" });
112
+ return f(e, s, r);
113
+ }
114
+ if (p(e))
115
+ return e.k ? m(e.k) : f(e, e, r, !0);
116
+ throw new Error("unreachable");
12
117
  };
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
118
  export {
41
- w as assertTransactionDeposit,
42
- T as serializeTransaction,
43
- E as serializers
119
+ d as default
44
120
  };
@@ -24,10 +24,9 @@ export { APIError }
24
24
 
25
25
  export { APIErrorType }
26
26
 
27
- export declare type AuthenticationMethod = EmailAuthentication;
28
-
29
27
  export declare type AuthenticationMethods = {
30
28
  email?: EmailAuthentication;
29
+ sms?: SmsAuthentication;
31
30
  };
32
31
 
33
32
  export declare type CDPEmbeddedWallet = {
@@ -115,6 +114,8 @@ export declare type ExportEvmAccountResult = {
115
114
  privateKey: string;
116
115
  };
117
116
 
117
+ export declare const getAccessToken: () => Promise<string | null>;
118
+
118
119
  export declare const getCurrentUser: () => Promise<User | null>;
119
120
 
120
121
  export declare type Hex = `0x${string}`;
@@ -245,6 +246,17 @@ export declare type SignInWithEmailResult = {
245
246
  flowId: string;
246
247
  };
247
248
 
249
+ export declare const signInWithSms: (options: SignInWithSmsOptions) => Promise<SignInWithSmsResult>;
250
+
251
+ export declare type SignInWithSmsOptions = {
252
+ phoneNumber: string;
253
+ };
254
+
255
+ export declare type SignInWithSmsResult = {
256
+ message: string;
257
+ flowId: string;
258
+ };
259
+
248
260
  export declare const signOut: () => Promise<void>;
249
261
 
250
262
  export declare type SignTypedDataRequest = {
@@ -252,6 +264,11 @@ export declare type SignTypedDataRequest = {
252
264
  params: [EvmAddress, string];
253
265
  };
254
266
 
267
+ export declare type SmsAuthentication = {
268
+ type: "sms";
269
+ phoneNumber: string;
270
+ };
271
+
255
272
  export declare const STANDARD_ERROR_CODES: {
256
273
  rpc: {
257
274
  invalidInput: -32000;
@@ -309,6 +326,19 @@ export declare type VerifyEmailOTPResult = {
309
326
  isNewUser: boolean;
310
327
  };
311
328
 
329
+ export declare const verifySmsOTP: (options: VerifySmsOTPOptions) => Promise<VerifySmsOTPResult>;
330
+
331
+ export declare type VerifySmsOTPOptions = {
332
+ flowId: string;
333
+ otp: string;
334
+ };
335
+
336
+ export declare type VerifySmsOTPResult = {
337
+ user: User;
338
+ message: string;
339
+ isNewUser: boolean;
340
+ };
341
+
312
342
  export declare type WalletDisconnectRequest = {
313
343
  method: "wallet_disconnect";
314
344
  params: [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cdp-core",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
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.18"
20
+ "@coinbase/cdp-api-client": "^0.0.20"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@size-limit/preset-big-lib": "^11.2.0",
@@ -52,7 +52,7 @@
52
52
  "path": "./dist/esm/index.js",
53
53
  "running": false,
54
54
  "import": "{ exportEvmAccount }",
55
- "limit": "25 KB"
55
+ "limit": "30 KB"
56
56
  },
57
57
  {
58
58
  "name": "provider-only",