@coinbase/cdp-sdk 1.13.0 → 1.14.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 (105) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +10 -1
  3. package/_cjs/accounts/evm/toEvmServerAccount.js +5 -0
  4. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  5. package/_cjs/actions/evm/listTokenBalances.js +1 -1
  6. package/_cjs/actions/evm/listTokenBalances.js.map +1 -1
  7. package/_cjs/analytics.js +1 -1
  8. package/_cjs/analytics.js.map +1 -1
  9. package/_cjs/client/evm/evm.js +59 -2
  10. package/_cjs/client/evm/evm.js.map +1 -1
  11. package/_cjs/openapi-client/cdpApiClient.js +15 -2
  12. package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
  13. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +1 -0
  14. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  15. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
  16. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
  17. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +32 -1
  18. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  19. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +9 -1
  20. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
  21. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +23 -1
  22. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  23. package/_cjs/openapi-client/generated/faucets/faucets.js +1 -1
  24. package/_cjs/openapi-client/generated/index.msw.js +4 -4
  25. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  26. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +27 -1
  27. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  28. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +32 -1
  29. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  30. package/_cjs/version.js +1 -1
  31. package/_esm/accounts/evm/toEvmServerAccount.js +6 -1
  32. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  33. package/_esm/actions/evm/listTokenBalances.js +1 -1
  34. package/_esm/actions/evm/listTokenBalances.js.map +1 -1
  35. package/_esm/analytics.js +2 -2
  36. package/_esm/analytics.js.map +1 -1
  37. package/_esm/client/evm/evm.js +59 -2
  38. package/_esm/client/evm/evm.js.map +1 -1
  39. package/_esm/openapi-client/cdpApiClient.js +15 -2
  40. package/_esm/openapi-client/cdpApiClient.js.map +1 -1
  41. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +1 -0
  42. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  43. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
  44. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
  45. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +27 -0
  46. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  47. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +7 -0
  48. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
  49. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +20 -0
  50. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  51. package/_esm/openapi-client/generated/faucets/faucets.js +1 -1
  52. package/_esm/openapi-client/generated/index.msw.js +4 -4
  53. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  54. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +24 -0
  55. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  56. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +27 -0
  57. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  58. package/_esm/version.js +1 -1
  59. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  60. package/_types/actions/evm/listTokenBalances.d.ts +1 -1
  61. package/_types/client/evm/evm.d.ts +25 -2
  62. package/_types/client/evm/evm.d.ts.map +1 -1
  63. package/_types/client/evm/evm.types.d.ts +15 -2
  64. package/_types/client/evm/evm.types.d.ts.map +1 -1
  65. package/_types/client/solana/solana.types.d.ts +1 -1
  66. package/_types/client/solana/solana.types.d.ts.map +1 -1
  67. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
  68. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +44 -4
  69. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  70. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
  71. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
  72. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
  73. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
  74. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +6 -0
  75. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
  76. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +2 -0
  77. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
  78. package/_types/openapi-client/generated/faucets/faucets.d.ts +1 -1
  79. package/_types/openapi-client/generated/index.msw.d.ts +4 -4
  80. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  81. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +13 -1
  82. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
  83. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +5 -1
  84. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
  85. package/_types/openapi-client/index.d.ts +10 -0
  86. package/_types/openapi-client/index.d.ts.map +1 -1
  87. package/_types/version.d.ts +1 -1
  88. package/accounts/evm/toEvmServerAccount.ts +6 -1
  89. package/actions/evm/listTokenBalances.ts +2 -2
  90. package/analytics.ts +2 -2
  91. package/client/evm/evm.ts +59 -2
  92. package/client/evm/evm.types.ts +18 -1
  93. package/client/solana/solana.types.ts +2 -0
  94. package/openapi-client/cdpApiClient.ts +17 -2
  95. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +52 -4
  96. package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +61 -0
  97. package/openapi-client/generated/evm-accounts/evm-accounts.ts +46 -0
  98. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +38 -0
  99. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +16 -0
  100. package/openapi-client/generated/faucets/faucets.ts +1 -1
  101. package/openapi-client/generated/index.msw.ts +4 -4
  102. package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +61 -0
  103. package/openapi-client/generated/solana-accounts/solana-accounts.ts +48 -0
  104. package/package.json +1 -1
  105. package/version.ts +1 -1
@@ -32,7 +32,7 @@ export interface EvmTokenAmount {
32
32
  /** The amount of the token in the smallest indivisible unit of the token. */
33
33
  amount: bigint;
34
34
  /** The number of decimals in the token. */
35
- decimals: bigint;
35
+ decimals: number;
36
36
  }
37
37
  /**
38
38
  * An EVM token balance.
@@ -95,7 +95,7 @@ export async function listTokenBalances(
95
95
  },
96
96
  amount: {
97
97
  amount: BigInt(balance.amount.amount),
98
- decimals: BigInt(balance.amount.decimals),
98
+ decimals: balance.amount.decimals,
99
99
  },
100
100
  };
101
101
  });
package/analytics.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import md5 from "md5";
2
2
 
3
- import { APIError } from "./openapi-client/errors.js";
3
+ import { APIError, HttpErrorType } from "./openapi-client/errors.js";
4
4
  import { version } from "./version.js";
5
5
 
6
6
  /**
@@ -184,7 +184,7 @@ function shouldTrackError(error: unknown): boolean {
184
184
  return false;
185
185
  }
186
186
 
187
- if (error instanceof APIError) {
187
+ if (error instanceof APIError && error.errorType !== HttpErrorType.unexpected_error) {
188
188
  return false;
189
189
  }
190
190
 
package/client/evm/evm.ts CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  GetSwapPriceResult,
33
33
  CreateSwapQuoteResult,
34
34
  SwapUnavailableResult,
35
+ GetOrCreateSmartAccountOptions,
35
36
  } from "./evm.types.js";
36
37
  import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
37
38
  import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
@@ -261,6 +262,7 @@ export class EvmClient implements EvmClientInterface {
261
262
  const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
262
263
  {
263
264
  owners: [options.owner.address],
265
+ name: options.name,
264
266
  },
265
267
  options.idempotencyKey,
266
268
  );
@@ -326,7 +328,10 @@ export class EvmClient implements EvmClientInterface {
326
328
  * Gets a CDP EVM smart account.
327
329
  *
328
330
  * @param {GetSmartAccountOptions} options - Parameters for getting the smart account.
329
- * @param {string} options.address - The address of the smart account to get.
331
+ * Either `address` or `name` must be provided.
332
+ * If both are provided, lookup will be done by `address` and `name` will be ignored.
333
+ * @param {string} [options.address] - The address of the smart account to get.
334
+ * @param {string} [options.name] - The name of the smart account to get.
330
335
  * @param {Account} options.owner - The owner of the smart account.
331
336
  * You must pass the signing-capable owner of the smart account so that the returned smart account
332
337
  * can be functional.
@@ -342,7 +347,14 @@ export class EvmClient implements EvmClientInterface {
342
347
  * ```
343
348
  */
344
349
  async getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount> {
345
- const openApiSmartAccount = await CdpOpenApiClient.getEvmSmartAccount(options.address);
350
+ const openApiSmartAccount = await (async () => {
351
+ if (options.address) {
352
+ return CdpOpenApiClient.getEvmSmartAccount(options.address);
353
+ } else if (options.name) {
354
+ return CdpOpenApiClient.getEvmSmartAccountByName(options.name);
355
+ }
356
+ throw new Error("Either address or name must be provided");
357
+ })();
346
358
 
347
359
  const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
348
360
  smartAccount: openApiSmartAccount,
@@ -395,6 +407,51 @@ export class EvmClient implements EvmClientInterface {
395
407
  }
396
408
  }
397
409
 
410
+ /**
411
+ * Gets a CDP EVM smart account, or creates one if it doesn't exist.
412
+ * This method first attempts to retrieve an existing smart account with the given parameters.
413
+ * If no account exists, it creates a new one with the specified owner.
414
+ *
415
+ * @param {GetOrCreateSmartAccountOptions} options - Configuration options for getting or creating the smart account.
416
+ * @param {string} [options.name] - The name of the smart account to get or create.
417
+ * @param {Account} options.owner - The owner of the smart account.
418
+ *
419
+ * @returns {Promise<SmartAccount>} A promise that resolves to the retrieved or newly created smart account.
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * const smartAccount = await cdp.evm.getOrCreateSmartAccount({
424
+ * name: "MySmartAccount",
425
+ * owner: account,
426
+ * });
427
+ * ```
428
+ */
429
+ async getOrCreateSmartAccount(options: GetOrCreateSmartAccountOptions): Promise<SmartAccount> {
430
+ try {
431
+ const account = await this.getSmartAccount(options);
432
+ return account;
433
+ } catch (error) {
434
+ // If it failed because the account doesn't exist, create it
435
+ const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
436
+ if (doesAccountNotExist) {
437
+ try {
438
+ const account = await this.createSmartAccount(options);
439
+ return account;
440
+ } catch (error) {
441
+ // If it failed because the account already exists, throw an error
442
+ const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
443
+ if (doesAccountAlreadyExist) {
444
+ const account = await this.getSmartAccount(options);
445
+ return account;
446
+ }
447
+ throw error;
448
+ }
449
+ }
450
+
451
+ throw error;
452
+ }
453
+ }
454
+
398
455
  /**
399
456
  * Gets the price for a swap between two tokens on an EVM network.
400
457
  *
@@ -39,6 +39,7 @@ export type EvmClientInterface = Omit<
39
39
  | "getEvmAccount" // mapped to getAccount
40
40
  | "getEvmAccountByName" // mapped to getAccount
41
41
  | "getEvmSmartAccount" // mapped to getSmartAccount
42
+ | "getEvmSmartAccountByName" // mapped to getSmartAccount
42
43
  | "getEvmSwapPrice" // mapped to getSwapPrice
43
44
  | "createEvmSwapQuote" // mapped to createSwapQuote
44
45
  | "getUserOperation"
@@ -56,6 +57,8 @@ export type EvmClientInterface = Omit<
56
57
  | "sendEvmTransaction" // mapped to sendTransaction
57
58
  | "signEvmTypedData" // mapped to signTypedData
58
59
  | "updateEvmAccount" // mapped to updateAccount
60
+ | "exportEvmAccount"
61
+ | "exportEvmAccountByName"
59
62
  > & {
60
63
  createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
61
64
  createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
@@ -336,9 +339,11 @@ export interface GetServerAccountOptions {
336
339
  */
337
340
  export interface GetSmartAccountOptions {
338
341
  /** The address of the account. */
339
- address: Address;
342
+ address?: Address;
340
343
  /** The owner of the account. */
341
344
  owner: Account;
345
+ /** The name of the account. */
346
+ name?: string;
342
347
  }
343
348
 
344
349
  /**
@@ -349,6 +354,16 @@ export interface GetOrCreateServerAccountOptions {
349
354
  name: string;
350
355
  }
351
356
 
357
+ /**
358
+ * Options for getting an EVM account, or creating one if it doesn't exist.
359
+ */
360
+ export interface GetOrCreateSmartAccountOptions {
361
+ /** The name of the account. */
362
+ name: string;
363
+ /** The owner of the account. */
364
+ owner: Account;
365
+ }
366
+
352
367
  /**
353
368
  * Options for listing EVM accounts.
354
369
  */
@@ -426,6 +441,8 @@ export interface CreateSmartAccountOptions {
426
441
  owner: Account;
427
442
  /** The idempotency key. */
428
443
  idempotencyKey?: string;
444
+ /** The name of the account. */
445
+ name?: string;
429
446
  }
430
447
 
431
448
  /**
@@ -15,6 +15,8 @@ export type SolanaClientInterface = Omit<
15
15
  | "signSolanaMessage" // mapped to signMessage
16
16
  | "signSolanaTransaction" // mapped to signTransaction
17
17
  | "updateSolanaAccount" // mapped to updateAccount
18
+ | "exportSolanaAccount"
19
+ | "exportSolanaAccountByName"
18
20
  > & {
19
21
  createAccount: (options: CreateAccountOptions) => Promise<Account>;
20
22
  getAccount: (options: GetAccountOptions) => Promise<Account>;
@@ -180,15 +180,30 @@ export const cdpApiClient = async <T>(
180
180
  `${ERROR_DOCS_PAGE_URL}`,
181
181
  error.cause,
182
182
  );
183
- default:
183
+ default: {
184
+ let errorText = "";
185
+
186
+ if (error.response.data) {
187
+ try {
188
+ errorText = JSON.stringify(error.response.data);
189
+ } catch {
190
+ errorText = String(error.response.data);
191
+ }
192
+ }
193
+
194
+ const errorMessage = errorText
195
+ ? `An unexpected error occurred: ${errorText}`
196
+ : "An unexpected error occurred.";
197
+
184
198
  throw new APIError(
185
199
  statusCode,
186
200
  HttpErrorType.unexpected_error,
187
- "An unexpected error occurred.",
201
+ errorMessage,
188
202
  undefined,
189
203
  `${ERROR_DOCS_PAGE_URL}`,
190
204
  error.cause,
191
205
  );
206
+ }
192
207
  }
193
208
  }
194
209
  }
@@ -1258,8 +1258,8 @@ Account names must be unique across all EVM accounts in the developer's CDP Proj
1258
1258
  */
1259
1259
  name?: string;
1260
1260
  /**
1261
- * The ID of the account-level policy to apply to the account.
1262
- * @pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
1261
+ * The ID of the account-level policy to apply to the account, or an empty string to unset attached policy.
1262
+ * @pattern (^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)|(^$)
1263
1263
  */
1264
1264
  accountPolicy?: string;
1265
1265
  };
@@ -1344,6 +1344,13 @@ export type ListEvmSmartAccounts200 = ListEvmSmartAccounts200AllOf & ListRespons
1344
1344
  export type CreateEvmSmartAccountBody = {
1345
1345
  /** Today, only a single owner can be set for a Smart Account, but this is an array to allow setting multiple owners in the future. */
1346
1346
  owners: string[];
1347
+ /**
1348
+ * An optional name for the account.
1349
+ Account names can consist of alphanumeric characters and hyphens, and be between 2 and 36 characters long.
1350
+ Account names must be unique across all EVM accounts in the developer's CDP Project.
1351
+ * @pattern ^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$
1352
+ */
1353
+ name?: string;
1347
1354
  };
1348
1355
 
1349
1356
  export type ImportEvmAccountBody = {
@@ -1358,6 +1365,26 @@ Account names must be unique across all EVM accounts in the developer's CDP Proj
1358
1365
  name?: string;
1359
1366
  };
1360
1367
 
1368
+ export type ExportEvmAccountBody = {
1369
+ /** The base64-encoded, public part of the RSA key in DER format used to encrypt the account private key. */
1370
+ exportEncryptionKey: string;
1371
+ };
1372
+
1373
+ export type ExportEvmAccount200 = {
1374
+ /** The base64-encoded, encrypted private key of the EVM account which is a 32 byte raw private key. The private key is encrypted in transport using the exportEncryptionKey in the request. */
1375
+ encryptedPrivateKey: string;
1376
+ };
1377
+
1378
+ export type ExportEvmAccountByNameBody = {
1379
+ /** The base64-encoded, public part of the RSA key in DER format used to encrypt the account private key. */
1380
+ exportEncryptionKey: string;
1381
+ };
1382
+
1383
+ export type ExportEvmAccountByName200 = {
1384
+ /** The base64-encoded, encrypted private key of the EVM account which is a 32 byte raw private key. The private key is encrypted in transport using the exportEncryptionKey in the request. */
1385
+ encryptedPrivateKey: string;
1386
+ };
1387
+
1361
1388
  /**
1362
1389
  * The network to prepare the user operation for.
1363
1390
  */
@@ -1463,6 +1490,7 @@ export type RequestEvmFaucetBodyNetwork =
1463
1490
  export const RequestEvmFaucetBodyNetwork = {
1464
1491
  "base-sepolia": "base-sepolia",
1465
1492
  "ethereum-sepolia": "ethereum-sepolia",
1493
+ "ethereum-hoodi": "ethereum-hoodi",
1466
1494
  } as const;
1467
1495
 
1468
1496
  /**
@@ -1604,12 +1632,32 @@ Account names must be unique across all Solana accounts in the developer's CDP P
1604
1632
  */
1605
1633
  name?: string;
1606
1634
  /**
1607
- * The ID of the account-level policy to apply to the account.
1608
- * @pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
1635
+ * The ID of the account-level policy to apply to the account, or an empty string to unset attached policy.
1636
+ * @pattern (^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)|(^$)
1609
1637
  */
1610
1638
  accountPolicy?: string;
1611
1639
  };
1612
1640
 
1641
+ export type ExportSolanaAccountBody = {
1642
+ /** The base64-encoded, public part of the RSA key in DER format used to encrypt the account private key. */
1643
+ exportEncryptionKey: string;
1644
+ };
1645
+
1646
+ export type ExportSolanaAccount200 = {
1647
+ /** The base64-encoded, encrypted private key of the Solana account which is a 32 byte raw private key. The private key is encrypted in transport using the exportEncryptionKey in the request. */
1648
+ encryptedPrivateKey: string;
1649
+ };
1650
+
1651
+ export type ExportSolanaAccountByNameBody = {
1652
+ /** The base64-encoded, public part of the RSA key in DER format used to encrypt the account private key. */
1653
+ exportEncryptionKey: string;
1654
+ };
1655
+
1656
+ export type ExportSolanaAccountByName200 = {
1657
+ /** The base64-encoded, encrypted private key of the Solana account which is a 32 byte raw private key. The private key is encrypted in transport using the exportEncryptionKey in the request. */
1658
+ encryptedPrivateKey: string;
1659
+ };
1660
+
1613
1661
  export type SignSolanaTransactionBody = {
1614
1662
  /** The base64 encoded transaction to sign. */
1615
1663
  transaction: string;
@@ -11,6 +11,8 @@ import { HttpResponse, delay, http } from "msw";
11
11
 
12
12
  import type {
13
13
  EvmAccount,
14
+ ExportEvmAccount200,
15
+ ExportEvmAccountByName200,
14
16
  ListEvmAccounts200,
15
17
  SendEvmTransaction200,
16
18
  SignEvmHash200,
@@ -157,6 +159,17 @@ export const getImportEvmAccountResponseMock = (
157
159
  ...overrideResponse,
158
160
  });
159
161
 
162
+ export const getExportEvmAccountResponseMock = (
163
+ overrideResponse: Partial<ExportEvmAccount200> = {},
164
+ ): ExportEvmAccount200 => ({ encryptedPrivateKey: faker.string.alpha(20), ...overrideResponse });
165
+
166
+ export const getExportEvmAccountByNameResponseMock = (
167
+ overrideResponse: Partial<ExportEvmAccountByName200> = {},
168
+ ): ExportEvmAccountByName200 => ({
169
+ encryptedPrivateKey: faker.string.alpha(20),
170
+ ...overrideResponse,
171
+ });
172
+
160
173
  export const getListEvmAccountsMockHandler = (
161
174
  overrideResponse?:
162
175
  | ListEvmAccounts200
@@ -399,6 +412,52 @@ export const getImportEvmAccountMockHandler = (
399
412
  );
400
413
  });
401
414
  };
415
+
416
+ export const getExportEvmAccountMockHandler = (
417
+ overrideResponse?:
418
+ | ExportEvmAccount200
419
+ | ((
420
+ info: Parameters<Parameters<typeof http.post>[1]>[0],
421
+ ) => Promise<ExportEvmAccount200> | ExportEvmAccount200),
422
+ ) => {
423
+ return http.post("*/v2/evm/accounts/:address/export", async info => {
424
+ await delay(0);
425
+
426
+ return new HttpResponse(
427
+ JSON.stringify(
428
+ overrideResponse !== undefined
429
+ ? typeof overrideResponse === "function"
430
+ ? await overrideResponse(info)
431
+ : overrideResponse
432
+ : getExportEvmAccountResponseMock(),
433
+ ),
434
+ { status: 200, headers: { "Content-Type": "application/json" } },
435
+ );
436
+ });
437
+ };
438
+
439
+ export const getExportEvmAccountByNameMockHandler = (
440
+ overrideResponse?:
441
+ | ExportEvmAccountByName200
442
+ | ((
443
+ info: Parameters<Parameters<typeof http.post>[1]>[0],
444
+ ) => Promise<ExportEvmAccountByName200> | ExportEvmAccountByName200),
445
+ ) => {
446
+ return http.post("*/v2/evm/accounts/export/by-name/:name", async info => {
447
+ await delay(0);
448
+
449
+ return new HttpResponse(
450
+ JSON.stringify(
451
+ overrideResponse !== undefined
452
+ ? typeof overrideResponse === "function"
453
+ ? await overrideResponse(info)
454
+ : overrideResponse
455
+ : getExportEvmAccountByNameResponseMock(),
456
+ ),
457
+ { status: 200, headers: { "Content-Type": "application/json" } },
458
+ );
459
+ });
460
+ };
402
461
  export const getEvmAccountsMock = () => [
403
462
  getListEvmAccountsMockHandler(),
404
463
  getCreateEvmAccountMockHandler(),
@@ -411,4 +470,6 @@ export const getEvmAccountsMock = () => [
411
470
  getSignEvmMessageMockHandler(),
412
471
  getSignEvmTypedDataMockHandler(),
413
472
  getImportEvmAccountMockHandler(),
473
+ getExportEvmAccountMockHandler(),
474
+ getExportEvmAccountByNameMockHandler(),
414
475
  ];
@@ -9,6 +9,10 @@ import type {
9
9
  CreateEvmAccountBody,
10
10
  EIP712Message,
11
11
  EvmAccount,
12
+ ExportEvmAccount200,
13
+ ExportEvmAccountBody,
14
+ ExportEvmAccountByName200,
15
+ ExportEvmAccountByNameBody,
12
16
  ImportEvmAccountBody,
13
17
  ListEvmAccounts200,
14
18
  ListEvmAccountsParams,
@@ -242,6 +246,44 @@ export const importEvmAccount = (
242
246
  options,
243
247
  );
244
248
  };
249
+ /**
250
+ * Export an existing EVM account's private key. It is important to store the private key in a secure place after it's exported.
251
+ * @summary Export an EVM account
252
+ */
253
+ export const exportEvmAccount = (
254
+ address: string,
255
+ exportEvmAccountBody: ExportEvmAccountBody,
256
+ options?: SecondParameter<typeof cdpApiClient>,
257
+ ) => {
258
+ return cdpApiClient<ExportEvmAccount200>(
259
+ {
260
+ url: `/v2/evm/accounts/${address}/export`,
261
+ method: "POST",
262
+ headers: { "Content-Type": "application/json" },
263
+ data: exportEvmAccountBody,
264
+ },
265
+ options,
266
+ );
267
+ };
268
+ /**
269
+ * Export an existing EVM account's private key by its name. It is important to store the private key in a secure place after it's exported.
270
+ * @summary Export an EVM account by name
271
+ */
272
+ export const exportEvmAccountByName = (
273
+ name: string,
274
+ exportEvmAccountByNameBody: ExportEvmAccountByNameBody,
275
+ options?: SecondParameter<typeof cdpApiClient>,
276
+ ) => {
277
+ return cdpApiClient<ExportEvmAccountByName200>(
278
+ {
279
+ url: `/v2/evm/accounts/export/by-name/${name}`,
280
+ method: "POST",
281
+ headers: { "Content-Type": "application/json" },
282
+ data: exportEvmAccountByNameBody,
283
+ },
284
+ options,
285
+ );
286
+ };
245
287
  export type ListEvmAccountsResult = NonNullable<Awaited<ReturnType<typeof listEvmAccounts>>>;
246
288
  export type CreateEvmAccountResult = NonNullable<Awaited<ReturnType<typeof createEvmAccount>>>;
247
289
  export type GetEvmAccountResult = NonNullable<Awaited<ReturnType<typeof getEvmAccount>>>;
@@ -255,3 +297,7 @@ export type SignEvmHashResult = NonNullable<Awaited<ReturnType<typeof signEvmHas
255
297
  export type SignEvmMessageResult = NonNullable<Awaited<ReturnType<typeof signEvmMessage>>>;
256
298
  export type SignEvmTypedDataResult = NonNullable<Awaited<ReturnType<typeof signEvmTypedData>>>;
257
299
  export type ImportEvmAccountResult = NonNullable<Awaited<ReturnType<typeof importEvmAccount>>>;
300
+ export type ExportEvmAccountResult = NonNullable<Awaited<ReturnType<typeof exportEvmAccount>>>;
301
+ export type ExportEvmAccountByNameResult = NonNullable<
302
+ Awaited<ReturnType<typeof exportEvmAccountByName>>
303
+ >;
@@ -47,6 +47,20 @@ export const getCreateEvmSmartAccountResponseMock = (
47
47
  ...overrideResponse,
48
48
  });
49
49
 
50
+ export const getGetEvmSmartAccountByNameResponseMock = (
51
+ overrideResponse: Partial<EvmSmartAccount> = {},
52
+ ): EvmSmartAccount => ({
53
+ address: faker.helpers.fromRegExp("^0x[0-9a-fA-F]{40}$"),
54
+ owners: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() =>
55
+ faker.helpers.fromRegExp("^0x[0-9a-fA-F]{40}$"),
56
+ ),
57
+ name: faker.helpers.arrayElement([
58
+ faker.helpers.fromRegExp("^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$"),
59
+ undefined,
60
+ ]),
61
+ ...overrideResponse,
62
+ });
63
+
50
64
  export const getGetEvmSmartAccountResponseMock = (
51
65
  overrideResponse: Partial<EvmSmartAccount> = {},
52
66
  ): EvmSmartAccount => ({
@@ -179,6 +193,29 @@ export const getCreateEvmSmartAccountMockHandler = (
179
193
  });
180
194
  };
181
195
 
196
+ export const getGetEvmSmartAccountByNameMockHandler = (
197
+ overrideResponse?:
198
+ | EvmSmartAccount
199
+ | ((
200
+ info: Parameters<Parameters<typeof http.get>[1]>[0],
201
+ ) => Promise<EvmSmartAccount> | EvmSmartAccount),
202
+ ) => {
203
+ return http.get("*/v2/evm/smart-accounts/by-name/:name", async info => {
204
+ await delay(0);
205
+
206
+ return new HttpResponse(
207
+ JSON.stringify(
208
+ overrideResponse !== undefined
209
+ ? typeof overrideResponse === "function"
210
+ ? await overrideResponse(info)
211
+ : overrideResponse
212
+ : getGetEvmSmartAccountByNameResponseMock(),
213
+ ),
214
+ { status: 200, headers: { "Content-Type": "application/json" } },
215
+ );
216
+ });
217
+ };
218
+
182
219
  export const getGetEvmSmartAccountMockHandler = (
183
220
  overrideResponse?:
184
221
  | EvmSmartAccount
@@ -276,6 +313,7 @@ export const getSendUserOperationMockHandler = (
276
313
  export const getEvmSmartAccountsMock = () => [
277
314
  getListEvmSmartAccountsMockHandler(),
278
315
  getCreateEvmSmartAccountMockHandler(),
316
+ getGetEvmSmartAccountByNameMockHandler(),
279
317
  getGetEvmSmartAccountMockHandler(),
280
318
  getPrepareUserOperationMockHandler(),
281
319
  getGetUserOperationMockHandler(),
@@ -51,6 +51,19 @@ export const createEvmSmartAccount = (
51
51
  options,
52
52
  );
53
53
  };
54
+ /**
55
+ * Gets a Smart Account by its name.
56
+ * @summary Get a Smart Account by name
57
+ */
58
+ export const getEvmSmartAccountByName = (
59
+ name: string,
60
+ options?: SecondParameter<typeof cdpApiClient>,
61
+ ) => {
62
+ return cdpApiClient<EvmSmartAccount>(
63
+ { url: `/v2/evm/smart-accounts/by-name/${name}`, method: "GET" },
64
+ options,
65
+ );
66
+ };
54
67
  /**
55
68
  * Gets a Smart Account by its address.
56
69
  * @summary Get a Smart Account by address
@@ -126,6 +139,9 @@ export type ListEvmSmartAccountsResult = NonNullable<
126
139
  export type CreateEvmSmartAccountResult = NonNullable<
127
140
  Awaited<ReturnType<typeof createEvmSmartAccount>>
128
141
  >;
142
+ export type GetEvmSmartAccountByNameResult = NonNullable<
143
+ Awaited<ReturnType<typeof getEvmSmartAccountByName>>
144
+ >;
129
145
  export type GetEvmSmartAccountResult = NonNullable<Awaited<ReturnType<typeof getEvmSmartAccount>>>;
130
146
  export type PrepareUserOperationResult = NonNullable<
131
147
  Awaited<ReturnType<typeof prepareUserOperation>>
@@ -19,7 +19,7 @@ type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
19
19
  /**
20
20
  * Request funds from the CDP Faucet on supported EVM test networks.
21
21
 
22
- Faucets are available for ETH, USDC, EURC, and cbBTC on Base Sepolia and Ethereum Sepolia.
22
+ Faucets are available for ETH, USDC, EURC, and cbBTC on Base Sepolia and Ethereum Sepolia, and for ETH only on Ethereum Hoodi.
23
23
 
24
24
  To prevent abuse, we enforce rate limits within a rolling 24-hour window to control the amount of funds that can be requested.
25
25
  These limits are applied at both the CDP User level and the blockchain address level.
@@ -1,8 +1,8 @@
1
- export * from "./faucets/faucets.msw.js";
2
1
  export * from "./evm-accounts/evm-accounts.msw.js";
3
- export * from "./evm-token-balances/evm-token-balances.msw.js";
4
- export * from "./policy-engine/policy-engine.msw.js";
5
- export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";
6
2
  export * from "./evm-swaps/evm-swaps.msw.js";
7
3
  export * from "./solana-accounts/solana-accounts.msw.js";
4
+ export * from "./policy-engine/policy-engine.msw.js";
5
+ export * from "./evm-token-balances/evm-token-balances.msw.js";
6
+ export * from "./faucets/faucets.msw.js";
8
7
  export * from "./payments-alpha/payments-alpha.msw.js";
8
+ export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";
@@ -10,6 +10,8 @@ import { faker } from "@faker-js/faker";
10
10
  import { HttpResponse, delay, http } from "msw";
11
11
 
12
12
  import type {
13
+ ExportSolanaAccount200,
14
+ ExportSolanaAccountByName200,
13
15
  ListSolanaAccounts200,
14
16
  SignSolanaMessage200,
15
17
  SignSolanaTransaction200,
@@ -115,6 +117,17 @@ export const getGetSolanaAccountByNameResponseMock = (
115
117
  ...overrideResponse,
116
118
  });
117
119
 
120
+ export const getExportSolanaAccountResponseMock = (
121
+ overrideResponse: Partial<ExportSolanaAccount200> = {},
122
+ ): ExportSolanaAccount200 => ({ encryptedPrivateKey: faker.string.alpha(20), ...overrideResponse });
123
+
124
+ export const getExportSolanaAccountByNameResponseMock = (
125
+ overrideResponse: Partial<ExportSolanaAccountByName200> = {},
126
+ ): ExportSolanaAccountByName200 => ({
127
+ encryptedPrivateKey: faker.string.alpha(20),
128
+ ...overrideResponse,
129
+ });
130
+
118
131
  export const getSignSolanaTransactionResponseMock = (
119
132
  overrideResponse: Partial<SignSolanaTransaction200> = {},
120
133
  ): SignSolanaTransaction200 => ({ signedTransaction: faker.string.alpha(20), ...overrideResponse });
@@ -238,6 +251,52 @@ export const getGetSolanaAccountByNameMockHandler = (
238
251
  });
239
252
  };
240
253
 
254
+ export const getExportSolanaAccountMockHandler = (
255
+ overrideResponse?:
256
+ | ExportSolanaAccount200
257
+ | ((
258
+ info: Parameters<Parameters<typeof http.post>[1]>[0],
259
+ ) => Promise<ExportSolanaAccount200> | ExportSolanaAccount200),
260
+ ) => {
261
+ return http.post("*/v2/solana/accounts/:address/export", async info => {
262
+ await delay(0);
263
+
264
+ return new HttpResponse(
265
+ JSON.stringify(
266
+ overrideResponse !== undefined
267
+ ? typeof overrideResponse === "function"
268
+ ? await overrideResponse(info)
269
+ : overrideResponse
270
+ : getExportSolanaAccountResponseMock(),
271
+ ),
272
+ { status: 200, headers: { "Content-Type": "application/json" } },
273
+ );
274
+ });
275
+ };
276
+
277
+ export const getExportSolanaAccountByNameMockHandler = (
278
+ overrideResponse?:
279
+ | ExportSolanaAccountByName200
280
+ | ((
281
+ info: Parameters<Parameters<typeof http.post>[1]>[0],
282
+ ) => Promise<ExportSolanaAccountByName200> | ExportSolanaAccountByName200),
283
+ ) => {
284
+ return http.post("*/v2/solana/accounts/export/by-name/:name", async info => {
285
+ await delay(0);
286
+
287
+ return new HttpResponse(
288
+ JSON.stringify(
289
+ overrideResponse !== undefined
290
+ ? typeof overrideResponse === "function"
291
+ ? await overrideResponse(info)
292
+ : overrideResponse
293
+ : getExportSolanaAccountByNameResponseMock(),
294
+ ),
295
+ { status: 200, headers: { "Content-Type": "application/json" } },
296
+ );
297
+ });
298
+ };
299
+
241
300
  export const getSignSolanaTransactionMockHandler = (
242
301
  overrideResponse?:
243
302
  | SignSolanaTransaction200
@@ -289,6 +348,8 @@ export const getSolanaAccountsMock = () => [
289
348
  getGetSolanaAccountMockHandler(),
290
349
  getUpdateSolanaAccountMockHandler(),
291
350
  getGetSolanaAccountByNameMockHandler(),
351
+ getExportSolanaAccountMockHandler(),
352
+ getExportSolanaAccountByNameMockHandler(),
292
353
  getSignSolanaTransactionMockHandler(),
293
354
  getSignSolanaMessageMockHandler(),
294
355
  ];