@coinbase/cdp-sdk 0.0.0 → 1.0.0

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 (87) hide show
  1. package/README.md +165 -0
  2. package/dist/accounts/evm/toEvmServerAccount.d.ts +19 -0
  3. package/dist/accounts/evm/toEvmServerAccount.js +42 -0
  4. package/dist/accounts/evm/toEvmSmartAccount.d.ts +24 -0
  5. package/dist/accounts/evm/toEvmSmartAccount.js +24 -0
  6. package/dist/accounts/types.d.ts +45 -0
  7. package/dist/accounts/types.js +2 -0
  8. package/dist/actions/evm/sendUserOperation.d.ts +95 -0
  9. package/dist/actions/evm/sendUserOperation.js +87 -0
  10. package/dist/actions/evm/waitForUserOperation.d.ts +63 -0
  11. package/dist/actions/evm/waitForUserOperation.js +60 -0
  12. package/dist/analytics.d.ts +30 -0
  13. package/dist/analytics.js +89 -0
  14. package/dist/auth/errors.d.ts +45 -0
  15. package/dist/auth/errors.js +62 -0
  16. package/dist/auth/hooks/axios/index.d.ts +1 -0
  17. package/dist/auth/hooks/axios/index.js +17 -0
  18. package/dist/auth/hooks/axios/withAuth.d.ts +37 -0
  19. package/dist/auth/hooks/axios/withAuth.js +73 -0
  20. package/dist/auth/index.d.ts +4 -0
  21. package/dist/auth/index.js +43 -0
  22. package/dist/auth/utils/http.d.ts +60 -0
  23. package/dist/auth/utils/http.js +72 -0
  24. package/dist/auth/utils/index.d.ts +2 -0
  25. package/dist/auth/utils/index.js +18 -0
  26. package/dist/auth/utils/jwt.d.ts +88 -0
  27. package/dist/auth/utils/jwt.js +235 -0
  28. package/dist/client/cdp.d.ts +43 -0
  29. package/dist/client/cdp.js +40 -0
  30. package/dist/client/evm/evm.d.ts +387 -0
  31. package/dist/client/evm/evm.js +520 -0
  32. package/dist/client/evm/evm.types.d.ts +254 -0
  33. package/dist/client/evm/evm.types.js +2 -0
  34. package/dist/client/evm/index.d.ts +1 -0
  35. package/dist/client/evm/index.js +5 -0
  36. package/dist/client/solana/index.d.ts +1 -0
  37. package/dist/client/solana/index.js +5 -0
  38. package/dist/client/solana/solana.d.ts +168 -0
  39. package/dist/client/solana/solana.js +207 -0
  40. package/dist/client/solana/solana.types.d.ts +94 -0
  41. package/dist/client/solana/solana.types.js +2 -0
  42. package/dist/constants.d.ts +4 -0
  43. package/dist/constants.js +7 -0
  44. package/dist/errors.d.ts +11 -0
  45. package/dist/errors.js +21 -0
  46. package/dist/index.d.ts +3 -0
  47. package/dist/index.js +6 -0
  48. package/dist/openapi-client/cdpApiClient.d.ts +50 -0
  49. package/dist/openapi-client/cdpApiClient.js +146 -0
  50. package/dist/openapi-client/errors.d.ts +53 -0
  51. package/dist/openapi-client/errors.js +70 -0
  52. package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +345 -0
  53. package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +54 -0
  54. package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +62 -0
  55. package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +85 -0
  56. package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +17 -0
  57. package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +113 -0
  58. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +48 -0
  59. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +66 -0
  60. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +15 -0
  61. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +99 -0
  62. package/dist/openapi-client/generated/faucets/faucets.d.ts +48 -0
  63. package/dist/openapi-client/generated/faucets/faucets.js +51 -0
  64. package/dist/openapi-client/generated/faucets/faucets.msw.d.ts +7 -0
  65. package/dist/openapi-client/generated/faucets/faucets.msw.js +43 -0
  66. package/dist/openapi-client/generated/index.msw.d.ts +4 -0
  67. package/dist/openapi-client/generated/index.msw.js +20 -0
  68. package/dist/openapi-client/generated/solana-accounts/solana-accounts.d.ts +61 -0
  69. package/dist/openapi-client/generated/solana-accounts/solana-accounts.js +79 -0
  70. package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +15 -0
  71. package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.js +99 -0
  72. package/dist/openapi-client/index.d.ts +55 -0
  73. package/dist/openapi-client/index.js +65 -0
  74. package/dist/types/calls.d.ts +13 -0
  75. package/dist/types/calls.js +4 -0
  76. package/dist/types/contract.d.ts +30 -0
  77. package/dist/types/contract.js +4 -0
  78. package/dist/types/misc.d.ts +3 -0
  79. package/dist/types/misc.js +3 -0
  80. package/dist/types/multicall.d.ts +9 -0
  81. package/dist/types/multicall.js +2 -0
  82. package/dist/types/utils.d.ts +196 -0
  83. package/dist/types/utils.js +4 -0
  84. package/dist/utils/wait.d.ts +28 -0
  85. package/dist/utils/wait.js +34 -0
  86. package/package.json +72 -5
  87. package/index.js +0 -1
@@ -0,0 +1,387 @@
1
+ import { SendUserOperationReturnType } from "../../actions/evm/sendUserOperation";
2
+ import { WaitForUserOperationReturnType } from "../../actions/evm/waitForUserOperation";
3
+ import { CreateServerAccountOptions, GetServerAccountOptions, ListServerAccountsOptions, CreateSmartAccountOptions, RequestFaucetOptions, SendUserOperationOptions, WaitForUserOperationOptions, RequestFaucetResult, SignHashOptions, SignatureResult, SignMessageOptions, SignTransactionOptions, GetSmartAccountOptions, SmartAccount, ServerAccount, EvmClientInterface, ListServerAccountResult, PrepareUserOperationOptions, UserOperation, GetUserOperationOptions, ListSmartAccountResult, ListSmartAccountsOptions } from "./evm.types";
4
+ /**
5
+ * The namespace containing all EVM methods.
6
+ */
7
+ export declare class EvmClient implements EvmClientInterface {
8
+ /**
9
+ * Creates a new CDP EVM account.
10
+ *
11
+ * @param {CreateServerAccountOptions} [options] - Optional parameters for creating the account.
12
+ * @param {string} [options.name] - A name for the account to create.
13
+ * @param {string} [options.idempotencyKey] - An idempotency key.
14
+ *
15
+ * @returns A promise that resolves to the newly created account.
16
+ *
17
+ * @example **Without arguments**
18
+ * ```ts
19
+ * const account = await cdp.evm.createAccount();
20
+ * ```
21
+ *
22
+ * @example **With a name**
23
+ * ```ts
24
+ * const account = await cdp.evm.createAccount({ name: "MyAccount" });
25
+ * ```
26
+ *
27
+ * @example **With an idempotency key**
28
+ * ```ts
29
+ * const idempotencyKey = uuidv4();
30
+ *
31
+ * // First call
32
+ * await cdp.evm.createAccount({
33
+ * idempotencyKey,
34
+ * });
35
+ *
36
+ * // Second call with the same idempotency key will return the same account
37
+ * await cdp.evm.createAccount({
38
+ * idempotencyKey,
39
+ * });
40
+ * ```
41
+ */
42
+ createAccount(options?: CreateServerAccountOptions): Promise<ServerAccount>;
43
+ /**
44
+ * Creates a new CDP EVM smart account.
45
+ *
46
+ * @param {CreateSmartAccountOptions} options - Parameters for creating the smart account.
47
+ * @param {Account} options.owner - The owner of the smart account.
48
+ * The owner can be any Ethereum account with signing capabilities,
49
+ * such as a CDP EVM account or a Viem LocalAccount.
50
+ * @param {string} [options.idempotencyKey] - An idempotency key.
51
+ *
52
+ * @returns A promise that resolves to the newly created smart account.
53
+ *
54
+ * @example **With a CDP EVM Account as the owner**
55
+ * ```ts
56
+ * const account = await cdp.evm.createAccount();
57
+ * const smartAccount = await cdp.evm.createSmartAccount({
58
+ * owner: account,
59
+ * });
60
+ * ```
61
+ *
62
+ * @example **With a Viem LocalAccount as the owner**
63
+ * ```ts
64
+ * // See https://viem.sh/docs/accounts/local/privateKeyToAccount
65
+ * const privateKey = generatePrivateKey();
66
+ * const account = privateKeyToAccount(privateKey);
67
+ * const smartAccount = await client.evm.createSmartAccount({
68
+ * owner: account,
69
+ * });
70
+ * ```
71
+ *
72
+ * @example **With an idempotency key**
73
+ * ```ts
74
+ * const idempotencyKey = uuidv4();
75
+ *
76
+ * // First call
77
+ * await cdp.evm.createSmartAccount({
78
+ * owner: account,
79
+ * idempotencyKey,
80
+ * });
81
+ *
82
+ * // Second call with the same idempotency key will return the same smart account
83
+ * await cdp.evm.createSmartAccount({
84
+ * owner: account,
85
+ * idempotencyKey,
86
+ * ```
87
+ */
88
+ createSmartAccount(options: CreateSmartAccountOptions): Promise<SmartAccount>;
89
+ /**
90
+ * Gets a CDP EVM account.
91
+ *
92
+ * @param {GetServerAccountOptions} options - Parameters for getting the account.
93
+ * Either `address` or `name` must be provided.
94
+ * If both are provided, lookup will be done by `address` and `name` will be ignored.
95
+ * @param {string} [options.address] - The address of the account to get.
96
+ * @param {string} [options.name] - The name of the account to get.
97
+ *
98
+ * @returns A promise that resolves to the account.
99
+ *
100
+ * @example **Get an account by address**
101
+ * ```ts
102
+ * const account = await cdp.evm.getAccount({
103
+ * address: "0x1234567890123456789012345678901234567890",
104
+ * });
105
+ * ```
106
+ *
107
+ * @example **Get an account by name**
108
+ * ```ts
109
+ * const account = await cdp.evm.getAccount({
110
+ * name: "MyAccount",
111
+ * });
112
+ * ```
113
+ */
114
+ getAccount(options: GetServerAccountOptions): Promise<ServerAccount>;
115
+ /**
116
+ * Gets a CDP EVM smart account.
117
+ *
118
+ * @param {GetSmartAccountOptions} options - Parameters for getting the smart account.
119
+ * @param {string} options.address - The address of the smart account to get.
120
+ * @param {Account} options.owner - The owner of the smart account.
121
+ * You must pass the signing-capable owner of the smart account so that the returned smart account
122
+ * can be functional.
123
+ *
124
+ * @returns A promise that resolves to the smart account.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const smartAccount = await cdp.evm.getSmartAccount({
129
+ * address: "0x1234567890123456789012345678901234567890",
130
+ * owner: account,
131
+ * });
132
+ * ```
133
+ */
134
+ getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount>;
135
+ /**
136
+ * Gets a user operation for a smart account by user operation hash.
137
+ *
138
+ * @param {GetUserOperationOptions} options - Parameters for getting the user operation.
139
+ * @param {SmartAccount} options.smartAccount - The smart account signing the user operation.
140
+ * @param {string} options.userOpHash - The user operation hash.
141
+ *
142
+ * @returns A promise that resolves to the user operation.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const userOp = await cdp.evm.getUserOperation({
147
+ * smartAccount,
148
+ * userOpHash: "0x1234567890123456789012345678901234567890123456789012345678901234",
149
+ * });
150
+ * ```
151
+ */
152
+ getUserOperation(options: GetUserOperationOptions): Promise<UserOperation>;
153
+ /**
154
+ * Lists CDP EVM accounts.
155
+ *
156
+ * @param {ListServerAccountsOptions} [options] - Optional parameters for listing the accounts.
157
+ * @param {number} [options.pageSize] - The number of accounts to return.
158
+ * @param {string} [options.pageToken] - The page token to begin listing from.
159
+ * This is obtained by previous calls to this method.
160
+ *
161
+ * @returns A promise that resolves to an array of accounts, and a token to paginate through the accounts.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * const accounts = await cdp.evm.listAccounts();
166
+ * ```
167
+ *
168
+ * @example **With pagination**
169
+ * ```ts
170
+ * let page = await cdp.evm.listAccounts();
171
+ *
172
+ * while (page.nextPageToken) {
173
+ * page = await cdp.evm.listAccounts({ pageToken: page.nextPageToken });
174
+ * }
175
+ * ```
176
+ */
177
+ listAccounts(options?: ListServerAccountsOptions): Promise<ListServerAccountResult>;
178
+ /**
179
+ * Lists CDP EVM smart accounts.
180
+ *
181
+ * @param {ListSmartAccountsOptions} options - Parameters for listing the smart accounts.
182
+ * @param {number} [options.pageSize] - The number of smart accounts to return.
183
+ * @param {string} [options.pageToken] - The page token to begin listing from.
184
+ * This is obtained by previous calls to this method.
185
+ *
186
+ * @returns A promise that resolves to an array of smart accounts, and a token to paginate through the smart accounts.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const smartAccounts = await cdp.evm.listSmartAccounts();
191
+ * ```
192
+ *
193
+ * @example **With pagination**
194
+ * ```ts
195
+ * let page = await cdp.evm.listSmartAccounts();
196
+ *
197
+ * while (page.nextPageToken) {
198
+ * page = await cdp.evm.listSmartAccounts({ pageToken: page.nextPageToken });
199
+ * }
200
+ */
201
+ listSmartAccounts(options?: ListSmartAccountsOptions): Promise<ListSmartAccountResult>;
202
+ /**
203
+ * Prepares a user operation for a smart account.
204
+ *
205
+ * @param {PrepareUserOperationOptions} options - Parameters for preparing the user operation.
206
+ * @param {SmartAccount} options.smartAccount - The smart account signing the user operation.
207
+ * @param {string} options.network - The network to prepare the user operation for.
208
+ * @param {EvmCall[]} options.calls - The calls to include in the user operation.
209
+ * @param {string} [options.paymasterUrl] - The optional paymaster URL to use for the user operation.
210
+ *
211
+ * @returns A promise that resolves to the user operation hash.
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * const userOp = await cdp.evm.prepareUserOperation({
216
+ * smartAccount,
217
+ * network: "base-sepolia",
218
+ * calls: [
219
+ * {
220
+ * to: "0x1234567890123456789012345678901234567890",
221
+ * value: parseEther("0.000001"),
222
+ * data: "0x",
223
+ * },
224
+ * ],
225
+ * });
226
+ * ```
227
+ */
228
+ prepareUserOperation(options: PrepareUserOperationOptions): Promise<UserOperation>;
229
+ /**
230
+ * Requests funds from an EVM faucet.
231
+ *
232
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the EVM faucet.
233
+ * @param {string} options.address - The address to request funds for.
234
+ * @param {string} options.network - The network to request funds from.
235
+ * @param {string} options.token - The token to request funds for.
236
+ * @param {string} [options.idempotencyKey] - An idempotency key.
237
+ *
238
+ * @returns A promise that resolves to the transaction hash.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * const result = await cdp.evm.requestFaucet({
243
+ * address: "0x1234567890123456789012345678901234567890",
244
+ * network: "base-sepolia",
245
+ * token: "eth",
246
+ * });
247
+ * ```
248
+ */
249
+ requestFaucet(options: RequestFaucetOptions): Promise<RequestFaucetResult>;
250
+ /**
251
+ * Sends a user operation.
252
+ *
253
+ * @param {SendUserOperationOptions} options - Parameters for sending the user operation.
254
+ * @param {SmartAccount} options.smartAccount - The smart account sending the user operation.
255
+ * @param {string} options.network - The network to send the user operation on.
256
+ * @param {EvmCall[]} options.calls - The calls to include in the user operation.
257
+ * @param {string} [options.paymasterUrl] - The optional paymaster URL to use for the user operation.
258
+ * @param {string} [options.idempotencyKey] - An idempotency key.
259
+ *
260
+ * @returns A promise that resolves to an object containing the smart account address,
261
+ * the user operation hash, and the status of the user operation.
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * const userOp = await cdp.evm.sendUserOperation({
266
+ * smartAccount,
267
+ * network: "base-sepolia",
268
+ * calls: [
269
+ * {
270
+ * to: "0x1234567890123456789012345678901234567890",
271
+ * value: parseEther("0.000001"),
272
+ * data: "0x",
273
+ * },
274
+ * ],
275
+ * });
276
+ * ```
277
+ */
278
+ sendUserOperation(options: SendUserOperationOptions): Promise<SendUserOperationReturnType>;
279
+ /**
280
+ * Signs an EVM hash.
281
+ *
282
+ * @param {SignHashOptions} options - Parameters for signing the hash.
283
+ * @param {string} options.address - The address to sign the hash for.
284
+ * @param {string} options.hash - The hash to sign.
285
+ * @param {string} [options.idempotencyKey] - An idempotency key.
286
+ *
287
+ * @returns A promise that resolves to the signature.
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * // Create a new EVM server account to sign with
292
+ * const ethAccount = await cdp.createEvmServerAccount({});
293
+ *
294
+ * const signature = await cdp.evm.signHash({
295
+ * address: ethAccount.address,
296
+ * hash: "0x1234567890123456789012345678901234567890123456789012345678901234",
297
+ * });
298
+ * ```
299
+ */
300
+ signHash(options: SignHashOptions): Promise<SignatureResult>;
301
+ /**
302
+ * Signs an EVM message.
303
+ *
304
+ * @param {SignMessageOptions} options - Parameters for signing the message.
305
+ * @param {string} options.address - The address to sign the message for.
306
+ * @param {string} options.message - The message to sign.
307
+ * @param {string} [options.idempotencyKey] - An idempotency key.
308
+ *
309
+ * @returns A promise that resolves to the signature.
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * // Create a new EVM server account to sign with
314
+ * const ethAccount = await cdp.createEvmServerAccount({});
315
+ *
316
+ * const signature = await cdp.evm.signMessage({
317
+ * address: ethAccount.address,
318
+ * message: "Hello, world!",
319
+ * });
320
+ * ```
321
+ */
322
+ signMessage(options: SignMessageOptions): Promise<SignatureResult>;
323
+ /**
324
+ * Signs an EVM transaction.
325
+ *
326
+ * @param {SignTransactionOptions} options - Configuration options for signing the transaction.
327
+ * @returns A promise that resolves to the signature.
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * import { parseEther, serializeTransaction } from "viem";
332
+ * import { baseSepolia } from "viem/chains";
333
+ *
334
+ * // Create a new EVM server account to sign with
335
+ * const ethAccount = await cdp.createEvmServerAccount({});
336
+ *
337
+ * const serializedTx = serializeTransaction(
338
+ * {
339
+ * chainId: baseSepolia.id,
340
+ * data: "0x",
341
+ * to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
342
+ * type: "eip1559",
343
+ * value: parseEther("0.000001"),
344
+ * },
345
+ * );
346
+ *
347
+ * const signature = await cdp.evm.signTransaction({
348
+ * address: ethAccount.address,
349
+ * transaction: serializedTx,
350
+ * });
351
+ * ```
352
+ */
353
+ signTransaction(options: SignTransactionOptions): Promise<SignatureResult>;
354
+ /**
355
+ * Waits for a user operation to complete or fail.
356
+ *
357
+ * @param {WaitForUserOperationOptions} options - Parameters for waiting for the user operation.
358
+ * @param {string} options.smartAccountAddress - The address of the smart account.
359
+ * @param {string} options.userOpHash - The user operation hash.
360
+ * @param {WaitOptions} [options.waitOptions] - Optional parameters for the wait operation.
361
+ *
362
+ * @returns A promise that resolves to the transaction receipt.
363
+ *
364
+ * @example
365
+ * ```ts
366
+ * // Send a user operation and get the user operation hash
367
+ * const { userOpHash } = await cdp.evm.sendUserOperation({
368
+ * smartAccount,
369
+ * network: "base-sepolia",
370
+ * calls: [
371
+ * {
372
+ * to: "0x0000000000000000000000000000000000000000",
373
+ * value: parseEther("0.000001"),
374
+ * data: "0x",
375
+ * },
376
+ * ],
377
+ * });
378
+ *
379
+ * // Wait for the user operation to complete or fail
380
+ * const result = await cdp.evm.waitForUserOperation({
381
+ * smartAccountAddress: smartAccount.address,
382
+ * userOpHash: userOp.userOpHash,
383
+ * });
384
+ * ```
385
+ */
386
+ waitForUserOperation(options: WaitForUserOperationOptions): Promise<WaitForUserOperationReturnType>;
387
+ }