@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.
Files changed (106) hide show
  1. package/README.md +255 -0
  2. package/dist/esm/index.js +21 -0
  3. package/dist/esm/index10.js +119 -0
  4. package/dist/esm/index100.js +19 -0
  5. package/dist/esm/index101.js +83 -0
  6. package/dist/esm/index102.js +81 -0
  7. package/dist/esm/index11.js +8 -0
  8. package/dist/esm/index12.js +18 -0
  9. package/dist/esm/index13.js +174 -0
  10. package/dist/esm/index14.js +162 -0
  11. package/dist/esm/index15.js +50 -0
  12. package/dist/esm/index16.js +149 -0
  13. package/dist/esm/index17.js +58 -0
  14. package/dist/esm/index18.js +43 -0
  15. package/dist/esm/index19.js +19 -0
  16. package/dist/esm/index2.js +172 -0
  17. package/dist/esm/index20.js +7 -0
  18. package/dist/esm/index21.js +7 -0
  19. package/dist/esm/index22.js +11 -0
  20. package/dist/esm/index23.js +20 -0
  21. package/dist/esm/index24.js +48 -0
  22. package/dist/esm/index25.js +16 -0
  23. package/dist/esm/index26.js +58 -0
  24. package/dist/esm/index27.js +9 -0
  25. package/dist/esm/index28.js +24 -0
  26. package/dist/esm/index29.js +14 -0
  27. package/dist/esm/index3.js +109 -0
  28. package/dist/esm/index30.js +6 -0
  29. package/dist/esm/index31.js +6 -0
  30. package/dist/esm/index32.js +37 -0
  31. package/dist/esm/index33.js +15 -0
  32. package/dist/esm/index34.js +7 -0
  33. package/dist/esm/index35.js +31 -0
  34. package/dist/esm/index36.js +9 -0
  35. package/dist/esm/index37.js +27 -0
  36. package/dist/esm/index38.js +19 -0
  37. package/dist/esm/index39.js +57 -0
  38. package/dist/esm/index4.js +126 -0
  39. package/dist/esm/index40.js +26 -0
  40. package/dist/esm/index41.js +14 -0
  41. package/dist/esm/index42.js +30 -0
  42. package/dist/esm/index43.js +45 -0
  43. package/dist/esm/index44.js +58 -0
  44. package/dist/esm/index45.js +130 -0
  45. package/dist/esm/index46.js +15 -0
  46. package/dist/esm/index47.js +107 -0
  47. package/dist/esm/index48.js +9 -0
  48. package/dist/esm/index49.js +5 -0
  49. package/dist/esm/index5.js +194 -0
  50. package/dist/esm/index50.js +17 -0
  51. package/dist/esm/index51.js +45 -0
  52. package/dist/esm/index52.js +81 -0
  53. package/dist/esm/index53.js +4 -0
  54. package/dist/esm/index54.js +4 -0
  55. package/dist/esm/index55.js +15 -0
  56. package/dist/esm/index56.js +40 -0
  57. package/dist/esm/index57.js +9 -0
  58. package/dist/esm/index58.js +37 -0
  59. package/dist/esm/index59.js +11 -0
  60. package/dist/esm/index6.js +14 -0
  61. package/dist/esm/index60.js +13 -0
  62. package/dist/esm/index61.js +14 -0
  63. package/dist/esm/index62.js +16 -0
  64. package/dist/esm/index63.js +21 -0
  65. package/dist/esm/index64.js +8 -0
  66. package/dist/esm/index65.js +7 -0
  67. package/dist/esm/index66.js +13 -0
  68. package/dist/esm/index67.js +19 -0
  69. package/dist/esm/index68.js +25 -0
  70. package/dist/esm/index69.js +53 -0
  71. package/dist/esm/index7.js +14 -0
  72. package/dist/esm/index70.js +4 -0
  73. package/dist/esm/index71.js +23 -0
  74. package/dist/esm/index72.js +22 -0
  75. package/dist/esm/index73.js +82 -0
  76. package/dist/esm/index74.js +106 -0
  77. package/dist/esm/index75.js +35 -0
  78. package/dist/esm/index76.js +9 -0
  79. package/dist/esm/index77.js +12 -0
  80. package/dist/esm/index78.js +57 -0
  81. package/dist/esm/index79.js +13 -0
  82. package/dist/esm/index8.js +23 -0
  83. package/dist/esm/index80.js +4 -0
  84. package/dist/esm/index81.js +47 -0
  85. package/dist/esm/index82.js +16 -0
  86. package/dist/esm/index83.js +81 -0
  87. package/dist/esm/index84.js +7 -0
  88. package/dist/esm/index85.js +15 -0
  89. package/dist/esm/index86.js +38 -0
  90. package/dist/esm/index87.js +44 -0
  91. package/dist/esm/index88.js +23 -0
  92. package/dist/esm/index89.js +12 -0
  93. package/dist/esm/index9.js +17 -0
  94. package/dist/esm/index90.js +22 -0
  95. package/dist/esm/index91.js +96 -0
  96. package/dist/esm/index92.js +23 -0
  97. package/dist/esm/index93.js +120 -0
  98. package/dist/esm/index94.js +20 -0
  99. package/dist/esm/index95.js +30 -0
  100. package/dist/esm/index96.js +10 -0
  101. package/dist/esm/index97.js +13 -0
  102. package/dist/esm/index98.js +15 -0
  103. package/dist/esm/index99.js +12 -0
  104. package/dist/types/index.d.ts +287 -0
  105. package/package.json +69 -6
  106. package/index.js +0 -1
package/README.md ADDED
@@ -0,0 +1,255 @@
1
+ This package contains core business logic for the CDP Frontend SDK.
2
+ It is intended for non-React applications that use pure Typescript.
3
+
4
+ ## Quickstart
5
+
6
+ This guide will help you get started with `@coinbase/cdp-core`. You'll learn how to install the package,
7
+ initialize the SDK, and make your first API call.
8
+
9
+ ### Installation
10
+
11
+ First, add the package to your project using your preferred package manager.
12
+
13
+ ```bash
14
+ # With pnpm
15
+ pnpm add @coinbase/cdp-core
16
+
17
+ # With yarn
18
+ yarn add @coinbase/cdp-core
19
+
20
+ # With npm
21
+ npm install @coinbase/cdp-core
22
+ ```
23
+
24
+ ### Gather your CDP Project information
25
+
26
+ 1. Sign in or create an account on the [CDP Portal](https://portal.cdp.coinbase.com)
27
+ 2. On your dashboard, select a project from the dropdown at the at the top, and copy the Project ID
28
+
29
+ ### Initialize the SDK
30
+
31
+ Before calling any methods in the SDK, you must first initialize it:
32
+
33
+ ```ts
34
+ import { Config, initialize } from "@coinbase/cdp-core";
35
+
36
+ const config: Config = {
37
+ // Copy and paste your project ID here.
38
+ projectId: "your-project-id",
39
+ }
40
+
41
+ await initialize(config);
42
+ ```
43
+
44
+ ### Sign In a User
45
+
46
+ You're now ready to start calling the APIs provided by the package!
47
+ The following code signs in an end user:
48
+
49
+ ```ts
50
+ import { signInWithEmail, verifyEmailOTP } from "@coinbase/cdp-core";
51
+
52
+ // Send an email to user@example.com with a One Time Password (OTP).
53
+ const authResult = await signInWithEmail({
54
+ email: "user@example.com"
55
+ });
56
+
57
+ // Input the OTP sent to user@example.com.
58
+ const verifyResult = await verifyEmailOTP({
59
+ flowId: authResult.flowId,
60
+ otp: "123456", // Hardcoded for convenience here.
61
+ });
62
+
63
+ // Get the authenticated end user.
64
+ const user = verifyResult.user;
65
+ ```
66
+
67
+ ### View User Information
68
+ Once the end user has signed in, you can display their information in your application:
69
+
70
+ ```typescript
71
+ import { getCurrentUser, isSignedIn } from "@coinbase/cdp-core";
72
+
73
+ // Check if user is signed in
74
+ const signedIn = await isSignedIn();
75
+
76
+ if (signedIn) {
77
+ // Get the user's information
78
+ const user = await getCurrentUser();
79
+ console.log("User ID:", user.userId);
80
+ console.log("EVM Accounts:", user.evmAccounts);
81
+ }
82
+ ```
83
+
84
+ ### Send a Transaction
85
+ We support signing and sending a Blockchain transaction in a single call on Base or Base Sepolia:
86
+
87
+ ```typescript
88
+ import { sendEvmTransaction, getCurrentUser } from "@coinbase/cdp-core";
89
+
90
+ const user = await getCurrentUser();
91
+ const evmAccount = user.evmAccounts[0];
92
+
93
+ const result = await sendEvmTransaction({
94
+ evmAccount,
95
+ transaction: {
96
+ to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
97
+ value: 100000000000000n, // 0.0001 ETH in wei
98
+ nonce: 0,
99
+ gas: 21000n,
100
+ maxFeePerGas: 30000000000n,
101
+ maxPriorityFeePerGas: 1000000000n,
102
+ chainId: 84532, // Base Sepolia
103
+ type: "eip1559",
104
+ }
105
+ });
106
+
107
+ console.log("Transaction Hash:", result.transactionHash);
108
+ ```
109
+
110
+ For networks other than Base or Base Sepolia, your end user must sign the transaction, and then
111
+ you must broadcast the transaction yourself. This example uses the public client from `viem` to broadcast the transaction.
112
+
113
+ ```typescript
114
+ import { signEvmTransaction, getCurrentUser } from "@coinbase/cdp-core";
115
+ import { http, createPublicClient } from "viem";
116
+ import { sepolia } from "viem/chains";
117
+
118
+ const user = await getCurrentUser();
119
+ const evmAccount = user.evmAccounts[0];
120
+
121
+ // Sign the transaction
122
+ const { signedTransaction } = await signEvmTransaction({
123
+ evmAccount,
124
+ transaction: {
125
+ to: "0x...",
126
+ value: 100000000000000n,
127
+ nonce: 0,
128
+ gas: 21000n,
129
+ maxFeePerGas: 30000000000n,
130
+ maxPriorityFeePerGas: 1000000000n,
131
+ chainId: 11155111, // Sepolia
132
+ type: "eip1559",
133
+ }
134
+ });
135
+
136
+ // Broadcast signed transaction to non-Base chain
137
+ const client = createPublicClient({
138
+ chain: sepolia,
139
+ transport: http()
140
+ });
141
+
142
+ const hash = await client.sendRawTransaction({
143
+ serializedTransaction: signedTransaction
144
+ });
145
+ ```
146
+
147
+ ### Sign Messages and Typed Data
148
+
149
+ End users can sign EVM messages, hashes, and typed data to generate signatures for various onchain applications.
150
+
151
+ ```typescript
152
+ import { signEvmMessage, signEvmTypedData, getCurrentUser } from "@coinbase/cdp-core";
153
+
154
+ const user = await getCurrentUser();
155
+ const evmAccount = user.evmAccounts[0];
156
+
157
+ // Sign a message
158
+ const messageResult = await signEvmMessage({
159
+ evmAccount,
160
+ message: "Hello World"
161
+ });
162
+
163
+ // Sign typed data (EIP-712)
164
+ const typedDataResult = await signEvmTypedData({
165
+ evmAccount,
166
+ typedData: {
167
+ domain: {
168
+ name: "Example DApp",
169
+ version: "1",
170
+ chainId: 84532,
171
+ },
172
+ types: {
173
+ Person: [
174
+ { name: "name", type: "string" },
175
+ { name: "wallet", type: "address" }
176
+ ]
177
+ },
178
+ primaryType: "Person",
179
+ message: {
180
+ name: "Bob",
181
+ wallet: evmAccount
182
+ }
183
+ }
184
+ });
185
+ ```
186
+
187
+ ### Export Private Key
188
+
189
+ End users can export their private keys from their embedded wallet, allowing them to import it into an EVM-compatible wallet of their choice.
190
+
191
+ ```typescript
192
+ import { exportEvmAccount, getCurrentUser } from "@coinbase/cdp-core";
193
+
194
+ const user = await getCurrentUser();
195
+ const evmAccount = user.evmAccounts[0];
196
+
197
+ const { privateKey } = await exportEvmAccount({
198
+ evmAccount
199
+ });
200
+
201
+ // WARNING: Handle private keys with extreme care!
202
+ console.log("Private Key:", privateKey);
203
+ ```
204
+
205
+ ### EIP-1193 Provider
206
+
207
+ The core package includes an EIP-1193 compatible provider. This provider can be used to sign and send transactions.
208
+
209
+ The provider is created by calling `createCDPEmbeddedWallet`, which exposes a `.provider` attribute. `createCDPEmbeddedWallet` must be called with the desired chains to support as well as the transports for these chains.
210
+
211
+ The provider will initially connect to the first chain in the `chains` array. The transports are typically HTTP RPC endpoints, which are used internally for broadcasting non-Base transactions. For more information on transports, see [Wagmi's `createConfig` setup](https://wagmi.sh/react/api/createConfig).
212
+ ```typescript
213
+ import { base, mainnet } from "viem/chains";
214
+ import { http } from "viem"
215
+
216
+ // Basic usage with default configuration
217
+ const wallet = createCDPEmbeddedWallet({
218
+ chains:[base, mainnet],
219
+ transports: {
220
+ [base.id]: http(),
221
+ [mainnet.id]: http()
222
+ }
223
+ });
224
+ const provider = wallet.provider;
225
+
226
+ // Request account access
227
+ const accounts = await provider.request({
228
+ method: "eth_requestAccounts"
229
+ });
230
+
231
+ // Sign a message
232
+ const signature = await provider.request({
233
+ method: "personal_sign",
234
+ params: ["Hello, World!", accounts[0]]
235
+ });
236
+
237
+ // Send a transaction
238
+ const txHash = await provider.request({
239
+ method: "eth_sendTransaction",
240
+ params: [{
241
+ from: accounts[0],
242
+ to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
243
+ value: "0x1000000000000000000"
244
+ }]
245
+ });
246
+
247
+ // Listen for connection events
248
+ provider.on("connect", (connectInfo) => {
249
+ console.log("Connected to chain:", connectInfo.chainId);
250
+ });
251
+
252
+ provider.on("disconnect", () => {
253
+ console.log("Disconnected from wallet");
254
+ });
255
+ ```
@@ -0,0 +1,21 @@
1
+ import { exportEvmAccount as n, getCurrentUser as r, initialize as t, isSignedIn as a, onAuthStateChange as s, sendEvmTransaction as o, signEvmHash as E, signEvmMessage as m, signEvmTransaction as g, signEvmTypedData as v, signInWithEmail as d, signOut as c, verifyEmailOTP as l } from "./index2.js";
2
+ import { createCDPEmbeddedWallet as D } from "./index3.js";
3
+ import { EIP1193ProviderError as f, STANDARD_ERROR_CODES as h } from "./index4.js";
4
+ export {
5
+ f as EIP1193ProviderError,
6
+ h as STANDARD_ERROR_CODES,
7
+ D as createCDPEmbeddedWallet,
8
+ n as exportEvmAccount,
9
+ r as getCurrentUser,
10
+ t as initialize,
11
+ a as isSignedIn,
12
+ s as onAuthStateChange,
13
+ o as sendEvmTransaction,
14
+ E as signEvmHash,
15
+ m as signEvmMessage,
16
+ g as signEvmTransaction,
17
+ v as signEvmTypedData,
18
+ d as signInWithEmail,
19
+ c as signOut,
20
+ l as verifyEmailOTP
21
+ };
@@ -0,0 +1,119 @@
1
+ import { mockUser as e } from "./index11.js";
2
+ class h {
3
+ authState = null;
4
+ authStateChangeCallback = null;
5
+ /**
6
+ * Initializes the mock auth manager.
7
+ *
8
+ * @param _projectId - The project ID (unused in mock implementation).
9
+ */
10
+ constructor(t) {
11
+ }
12
+ /**
13
+ * Awaitable method whose promise only resolves when the auth manager is ready to be used.
14
+ *
15
+ * @returns A promise that resolves when the auth manager is ready to be used.
16
+ */
17
+ async ensureInitialized() {
18
+ return Promise.resolve();
19
+ }
20
+ /**
21
+ * Gets the current user, or null if there is no user signed in.
22
+ *
23
+ * @returns The current mock user if signed in, null otherwise.
24
+ */
25
+ async getUser() {
26
+ return this.authState?.user ?? null;
27
+ }
28
+ /**
29
+ * Returns whether the user is signed in - i.e., whether there is an unexpired
30
+ * access token and user.
31
+ *
32
+ * @returns True if the mock user is signed in and token is not expired, false otherwise.
33
+ */
34
+ async isSignedIn() {
35
+ return this.authState ? Promise.resolve(this.authState.expiresAt > Date.now()) : Promise.resolve(!1);
36
+ }
37
+ /**
38
+ * Signs out the user, clearing all authentication state.
39
+ * In the mock implementation, this simply clears the local auth state.
40
+ */
41
+ async signOut() {
42
+ await this.clearAuthState();
43
+ }
44
+ /**
45
+ * Sets a callback to be called when the auth state changes.
46
+ * The callback is immediately called with the current auth state.
47
+ *
48
+ * @param callback - The function to call when the auth state changes.
49
+ * Will be called with the current user or null.
50
+ */
51
+ addAuthStateChangeCallback(t) {
52
+ this.authStateChangeCallback = t, t(this.authState?.user ?? null);
53
+ }
54
+ /**
55
+ * Gets the access token. For mock, this always returns a valid token if signed in.
56
+ * If the current token is expired, it will be refreshed automatically.
57
+ *
58
+ * @returns The mock access token if signed in, null otherwise.
59
+ */
60
+ async getToken() {
61
+ return this.authState ? (this.authState.expiresAt <= Date.now() && await this.refreshToken(), this.authState?.accessToken ?? null) : null;
62
+ }
63
+ /**
64
+ * Gets the currentlly registered wallet secret ID.
65
+ *
66
+ * @returns The wallet secret ID.
67
+ */
68
+ async getWalletSecretId() {
69
+ return "mock-wallet-secret-id";
70
+ }
71
+ /**
72
+ * Gets the X-Wallet-Auth header value.
73
+ *
74
+ * @param _options - The options for the request.
75
+ * @param _options.requestMethod - The HTTP method of the request.
76
+ * @param _options.requestHost - The host of the request.
77
+ * @param _options.requestPath - The path of the request.
78
+ * @param _options.requestData - The data of the request.
79
+ * @returns The X-Wallet-Auth header value.
80
+ */
81
+ async getXWalletAuth(t) {
82
+ if (!this.authState)
83
+ throw new Error("User not signed in");
84
+ return "x-wallet-auth";
85
+ }
86
+ /**
87
+ * Sets the authentication state.
88
+ * This will trigger the auth state change callback if one is registered.
89
+ *
90
+ * @param authState - The new authentication state to set.
91
+ */
92
+ async setAuthState(t) {
93
+ this.authState = t, this.authStateChangeCallback && this.authStateChangeCallback(this.authState?.user ?? null);
94
+ }
95
+ /**
96
+ * Clears the authentication state.
97
+ * This will trigger the auth state change callback if one is registered.
98
+ */
99
+ async clearAuthState() {
100
+ this.authState = null, this.authStateChangeCallback && this.authStateChangeCallback(null);
101
+ }
102
+ /**
103
+ * Refreshes the mock token.
104
+ * Only refreshes if there is an existing auth state (user is signed in).
105
+ * Sets a new mock token with a 24-hour expiration.
106
+ *
107
+ * @private
108
+ */
109
+ async refreshToken() {
110
+ this.authState && await this.setAuthState({
111
+ accessToken: "mock-access-token",
112
+ expiresAt: Date.now() + 1e3 * 60 * 60 * 24,
113
+ user: e
114
+ });
115
+ }
116
+ }
117
+ export {
118
+ h as MockAuthManager
119
+ };
@@ -0,0 +1,19 @@
1
+ import n from "./index82.js";
2
+ function r(t) {
3
+ return n(t) && typeof t.kty == "string";
4
+ }
5
+ function o(t) {
6
+ return t.kty !== "oct" && typeof t.d == "string";
7
+ }
8
+ function e(t) {
9
+ return t.kty !== "oct" && typeof t.d > "u";
10
+ }
11
+ function c(t) {
12
+ return t.kty === "oct" && typeof t.k == "string";
13
+ }
14
+ export {
15
+ r as isJWK,
16
+ o as isPrivateJWK,
17
+ e as isPublicJWK,
18
+ c as isSecretJWK
19
+ };
@@ -0,0 +1,83 @@
1
+ import { JOSENotSupported as s } from "./index68.js";
2
+ function n(e) {
3
+ let a, r;
4
+ switch (e.kty) {
5
+ case "RSA": {
6
+ switch (e.alg) {
7
+ case "PS256":
8
+ case "PS384":
9
+ case "PS512":
10
+ a = { name: "RSA-PSS", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
11
+ break;
12
+ case "RS256":
13
+ case "RS384":
14
+ case "RS512":
15
+ a = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
16
+ break;
17
+ case "RSA-OAEP":
18
+ case "RSA-OAEP-256":
19
+ case "RSA-OAEP-384":
20
+ case "RSA-OAEP-512":
21
+ a = {
22
+ name: "RSA-OAEP",
23
+ hash: `SHA-${parseInt(e.alg.slice(-3), 10) || 1}`
24
+ }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
25
+ break;
26
+ default:
27
+ throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
28
+ }
29
+ break;
30
+ }
31
+ case "EC": {
32
+ switch (e.alg) {
33
+ case "ES256":
34
+ a = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
35
+ break;
36
+ case "ES384":
37
+ a = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
38
+ break;
39
+ case "ES512":
40
+ a = { name: "ECDSA", namedCurve: "P-521" }, r = e.d ? ["sign"] : ["verify"];
41
+ break;
42
+ case "ECDH-ES":
43
+ case "ECDH-ES+A128KW":
44
+ case "ECDH-ES+A192KW":
45
+ case "ECDH-ES+A256KW":
46
+ a = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
47
+ break;
48
+ default:
49
+ throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
50
+ }
51
+ break;
52
+ }
53
+ case "OKP": {
54
+ switch (e.alg) {
55
+ case "Ed25519":
56
+ case "EdDSA":
57
+ a = { name: "Ed25519" }, r = e.d ? ["sign"] : ["verify"];
58
+ break;
59
+ case "ECDH-ES":
60
+ case "ECDH-ES+A128KW":
61
+ case "ECDH-ES+A192KW":
62
+ case "ECDH-ES+A256KW":
63
+ a = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
64
+ break;
65
+ default:
66
+ throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
67
+ }
68
+ break;
69
+ }
70
+ default:
71
+ throw new s('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
72
+ }
73
+ return { algorithm: a, keyUsages: r };
74
+ }
75
+ const i = async (e) => {
76
+ if (!e.alg)
77
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
78
+ const { algorithm: a, keyUsages: r } = n(e), t = { ...e };
79
+ return delete t.alg, delete t.use, crypto.subtle.importKey("jwk", t, a, e.ext ?? !e.d, e.key_ops ?? r);
80
+ };
81
+ export {
82
+ i as default
83
+ };
@@ -0,0 +1,81 @@
1
+ function r(t, e = "algorithm.name") {
2
+ return new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);
3
+ }
4
+ function o(t, e) {
5
+ return t.name === e;
6
+ }
7
+ function c(t) {
8
+ return parseInt(t.name.slice(4), 10);
9
+ }
10
+ function h(t) {
11
+ switch (t) {
12
+ case "ES256":
13
+ return "P-256";
14
+ case "ES384":
15
+ return "P-384";
16
+ case "ES512":
17
+ return "P-521";
18
+ default:
19
+ throw new Error("unreachable");
20
+ }
21
+ }
22
+ function i(t, e) {
23
+ if (!t.usages.includes(e))
24
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`);
25
+ }
26
+ function u(t, e, n) {
27
+ switch (e) {
28
+ case "HS256":
29
+ case "HS384":
30
+ case "HS512": {
31
+ if (!o(t.algorithm, "HMAC"))
32
+ throw r("HMAC");
33
+ const a = parseInt(e.slice(2), 10);
34
+ if (c(t.algorithm.hash) !== a)
35
+ throw r(`SHA-${a}`, "algorithm.hash");
36
+ break;
37
+ }
38
+ case "RS256":
39
+ case "RS384":
40
+ case "RS512": {
41
+ if (!o(t.algorithm, "RSASSA-PKCS1-v1_5"))
42
+ throw r("RSASSA-PKCS1-v1_5");
43
+ const a = parseInt(e.slice(2), 10);
44
+ if (c(t.algorithm.hash) !== a)
45
+ throw r(`SHA-${a}`, "algorithm.hash");
46
+ break;
47
+ }
48
+ case "PS256":
49
+ case "PS384":
50
+ case "PS512": {
51
+ if (!o(t.algorithm, "RSA-PSS"))
52
+ throw r("RSA-PSS");
53
+ const a = parseInt(e.slice(2), 10);
54
+ if (c(t.algorithm.hash) !== a)
55
+ throw r(`SHA-${a}`, "algorithm.hash");
56
+ break;
57
+ }
58
+ case "Ed25519":
59
+ case "EdDSA": {
60
+ if (!o(t.algorithm, "Ed25519"))
61
+ throw r("Ed25519");
62
+ break;
63
+ }
64
+ case "ES256":
65
+ case "ES384":
66
+ case "ES512": {
67
+ if (!o(t.algorithm, "ECDSA"))
68
+ throw r("ECDSA");
69
+ const a = h(e);
70
+ if (t.algorithm.namedCurve !== a)
71
+ throw r(a, "algorithm.namedCurve");
72
+ break;
73
+ }
74
+ default:
75
+ throw new TypeError("CryptoKey does not support this operation");
76
+ }
77
+ i(t, n);
78
+ }
79
+ export {
80
+ u as checkSigCryptoKey
81
+ };
@@ -0,0 +1,8 @@
1
+ const s = "0x0000000000000000000000000000000000000000", c = {
2
+ userId: "mock-user-id",
3
+ evmAccounts: [s]
4
+ };
5
+ export {
6
+ s as mockAddress,
7
+ c as mockUser
8
+ };
@@ -0,0 +1,18 @@
1
+ import { SendEvmTransactionWithEndUserAccountBodyNetwork as i } from "@coinbase/cdp-api-client";
2
+ const n = (e) => !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(n) : Object.keys(e).sort().reduce(
3
+ (r, t) => (r[t] = n(e[t]), r),
4
+ {}
5
+ ), o = (e) => Object.values(i).includes(
6
+ e
7
+ ), s = {
8
+ "base-sepolia": 84532,
9
+ base: 8453
10
+ }, c = Object.fromEntries(
11
+ Object.entries(s).map(([e, r]) => [r, e])
12
+ ), p = (e) => Object.values(s).includes(e);
13
+ export {
14
+ c as chainIdToNameMapping,
15
+ p as isChainIdSupportedForCDPSends,
16
+ o as isChainSupportedForCDPSends,
17
+ n as sortKeys
18
+ };