@coinbase/cdp-sdk 1.12.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 (122) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +20 -2
  3. package/_cjs/accounts/evm/toEvmServerAccount.js +6 -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 +24 -1
  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 +5 -5
  25. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  26. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +59 -1
  27. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  28. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +27 -1
  29. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  30. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +32 -1
  31. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  32. package/_cjs/policies/schema.js +59 -1
  33. package/_cjs/policies/schema.js.map +1 -1
  34. package/_cjs/version.js +1 -1
  35. package/_esm/accounts/evm/toEvmServerAccount.js +7 -1
  36. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  37. package/_esm/actions/evm/listTokenBalances.js +1 -1
  38. package/_esm/actions/evm/listTokenBalances.js.map +1 -1
  39. package/_esm/analytics.js +2 -2
  40. package/_esm/analytics.js.map +1 -1
  41. package/_esm/client/evm/evm.js +59 -2
  42. package/_esm/client/evm/evm.js.map +1 -1
  43. package/_esm/openapi-client/cdpApiClient.js +15 -2
  44. package/_esm/openapi-client/cdpApiClient.js.map +1 -1
  45. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +23 -0
  46. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  47. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
  48. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
  49. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +27 -0
  50. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  51. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +7 -0
  52. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
  53. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +20 -0
  54. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  55. package/_esm/openapi-client/generated/faucets/faucets.js +1 -1
  56. package/_esm/openapi-client/generated/index.msw.js +5 -5
  57. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  58. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +54 -0
  59. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  60. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +24 -0
  61. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  62. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +27 -0
  63. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  64. package/_esm/policies/schema.js +58 -0
  65. package/_esm/policies/schema.js.map +1 -1
  66. package/_esm/version.js +1 -1
  67. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  68. package/_types/actions/evm/listTokenBalances.d.ts +1 -1
  69. package/_types/actions/evm/swap/types.d.ts +40 -1
  70. package/_types/actions/evm/swap/types.d.ts.map +1 -1
  71. package/_types/client/evm/evm.d.ts +25 -2
  72. package/_types/client/evm/evm.d.ts.map +1 -1
  73. package/_types/client/evm/evm.types.d.ts +15 -2
  74. package/_types/client/evm/evm.types.d.ts.map +1 -1
  75. package/_types/client/solana/solana.types.d.ts +1 -1
  76. package/_types/client/solana/solana.types.d.ts.map +1 -1
  77. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
  78. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +108 -5
  79. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  80. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
  81. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
  82. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
  83. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
  84. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +6 -0
  85. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
  86. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +2 -0
  87. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
  88. package/_types/openapi-client/generated/faucets/faucets.d.ts +1 -1
  89. package/_types/openapi-client/generated/index.msw.d.ts +5 -5
  90. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  91. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
  92. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
  93. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +13 -1
  94. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
  95. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +5 -1
  96. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
  97. package/_types/openapi-client/index.d.ts +10 -0
  98. package/_types/openapi-client/index.d.ts.map +1 -1
  99. package/_types/policies/schema.d.ts +338 -0
  100. package/_types/policies/schema.d.ts.map +1 -1
  101. package/_types/version.d.ts +1 -1
  102. package/accounts/evm/toEvmServerAccount.ts +8 -3
  103. package/actions/evm/listTokenBalances.ts +2 -2
  104. package/actions/evm/swap/types.ts +44 -1
  105. package/analytics.ts +2 -2
  106. package/client/evm/evm.ts +59 -2
  107. package/client/evm/evm.types.ts +18 -1
  108. package/client/solana/solana.types.ts +2 -0
  109. package/openapi-client/cdpApiClient.ts +17 -2
  110. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +145 -5
  111. package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +61 -0
  112. package/openapi-client/generated/evm-accounts/evm-accounts.ts +46 -0
  113. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +38 -0
  114. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +16 -0
  115. package/openapi-client/generated/faucets/faucets.ts +1 -1
  116. package/openapi-client/generated/index.msw.ts +5 -5
  117. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +87 -0
  118. package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +61 -0
  119. package/openapi-client/generated/solana-accounts/solana-accounts.ts +48 -0
  120. package/package.json +1 -1
  121. package/policies/schema.ts +70 -0
  122. package/version.ts +1 -1
@@ -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
  }
@@ -727,6 +727,63 @@ export interface SendEvmTransactionRule {
727
727
  criteria: SendEvmTransactionCriteria;
728
728
  }
729
729
 
730
+ /**
731
+ * The type of criterion to use. This should be `evmMessage`.
732
+ */
733
+ export type EvmMessageCriterionType =
734
+ (typeof EvmMessageCriterionType)[keyof typeof EvmMessageCriterionType];
735
+
736
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
737
+ export const EvmMessageCriterionType = {
738
+ evmMessage: "evmMessage",
739
+ } as const;
740
+
741
+ /**
742
+ * A schema for specifying a criterion for the message being signed.
743
+ */
744
+ export interface EvmMessageCriterion {
745
+ /** The type of criterion to use. This should be `evmMessage`. */
746
+ type: EvmMessageCriterionType;
747
+ /** A regular expression the message is matched against. Accepts valid regular expression syntax described by [RE2](https://github.com/google/re2/wiki/Syntax). */
748
+ match: string;
749
+ }
750
+
751
+ /**
752
+ * A schema for specifying the rejection criteria for the SignEvmMessage operation.
753
+ */
754
+ export type SignEvmMessageCriteria = EvmMessageCriterion[];
755
+
756
+ /**
757
+ * Whether matching the rule will cause the request to be rejected or accepted.
758
+ */
759
+ export type SignEvmMessageRuleAction =
760
+ (typeof SignEvmMessageRuleAction)[keyof typeof SignEvmMessageRuleAction];
761
+
762
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
763
+ export const SignEvmMessageRuleAction = {
764
+ reject: "reject",
765
+ accept: "accept",
766
+ } as const;
767
+
768
+ /**
769
+ * The operation to which the rule applies. Every element of the `criteria` array must match the specified operation.
770
+ */
771
+ export type SignEvmMessageRuleOperation =
772
+ (typeof SignEvmMessageRuleOperation)[keyof typeof SignEvmMessageRuleOperation];
773
+
774
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
775
+ export const SignEvmMessageRuleOperation = {
776
+ signEvmMessage: "signEvmMessage",
777
+ } as const;
778
+
779
+ export interface SignEvmMessageRule {
780
+ /** Whether matching the rule will cause the request to be rejected or accepted. */
781
+ action: SignEvmMessageRuleAction;
782
+ /** The operation to which the rule applies. Every element of the `criteria` array must match the specified operation. */
783
+ operation: SignEvmMessageRuleOperation;
784
+ criteria: SignEvmMessageCriteria;
785
+ }
786
+
730
787
  /**
731
788
  * The type of criterion to use. This should be `solAddress`.
732
789
  */
@@ -798,10 +855,45 @@ export interface SignSolTransactionRule {
798
855
  criteria: SignSolTransactionCriteria;
799
856
  }
800
857
 
858
+ /**
859
+ * Whether any attempts to sign a hash will be accepted or rejected. This rule does not accept any criteria.
860
+ */
861
+ export type SignEvmHashRuleAction =
862
+ (typeof SignEvmHashRuleAction)[keyof typeof SignEvmHashRuleAction];
863
+
864
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
865
+ export const SignEvmHashRuleAction = {
866
+ reject: "reject",
867
+ accept: "accept",
868
+ } as const;
869
+
870
+ /**
871
+ * The operation to which the rule applies.
872
+ */
873
+ export type SignEvmHashRuleOperation =
874
+ (typeof SignEvmHashRuleOperation)[keyof typeof SignEvmHashRuleOperation];
875
+
876
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
877
+ export const SignEvmHashRuleOperation = {
878
+ signEvmHash: "signEvmHash",
879
+ } as const;
880
+
881
+ export interface SignEvmHashRule {
882
+ /** Whether any attempts to sign a hash will be accepted or rejected. This rule does not accept any criteria. */
883
+ action: SignEvmHashRuleAction;
884
+ /** The operation to which the rule applies. */
885
+ operation: SignEvmHashRuleOperation;
886
+ }
887
+
801
888
  /**
802
889
  * A rule that limits the behavior of an account.
803
890
  */
804
- export type Rule = SignEvmTransactionRule | SendEvmTransactionRule | SignSolTransactionRule;
891
+ export type Rule =
892
+ | SignEvmTransactionRule
893
+ | SendEvmTransactionRule
894
+ | SignEvmMessageRule
895
+ | SignSolTransactionRule
896
+ | SignEvmHashRule;
805
897
 
806
898
  /**
807
899
  * The scope of the policy. Only one project-level policy can exist at any time.
@@ -1166,8 +1258,8 @@ Account names must be unique across all EVM accounts in the developer's CDP Proj
1166
1258
  */
1167
1259
  name?: string;
1168
1260
  /**
1169
- * The ID of the account-level policy to apply to the account.
1170
- * @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}$)|(^$)
1171
1263
  */
1172
1264
  accountPolicy?: string;
1173
1265
  };
@@ -1252,6 +1344,13 @@ export type ListEvmSmartAccounts200 = ListEvmSmartAccounts200AllOf & ListRespons
1252
1344
  export type CreateEvmSmartAccountBody = {
1253
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. */
1254
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;
1255
1354
  };
1256
1355
 
1257
1356
  export type ImportEvmAccountBody = {
@@ -1266,6 +1365,26 @@ Account names must be unique across all EVM accounts in the developer's CDP Proj
1266
1365
  name?: string;
1267
1366
  };
1268
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
+
1269
1388
  /**
1270
1389
  * The network to prepare the user operation for.
1271
1390
  */
@@ -1371,6 +1490,7 @@ export type RequestEvmFaucetBodyNetwork =
1371
1490
  export const RequestEvmFaucetBodyNetwork = {
1372
1491
  "base-sepolia": "base-sepolia",
1373
1492
  "ethereum-sepolia": "ethereum-sepolia",
1493
+ "ethereum-hoodi": "ethereum-hoodi",
1374
1494
  } as const;
1375
1495
 
1376
1496
  /**
@@ -1512,12 +1632,32 @@ Account names must be unique across all Solana accounts in the developer's CDP P
1512
1632
  */
1513
1633
  name?: string;
1514
1634
  /**
1515
- * The ID of the account-level policy to apply to the account.
1516
- * @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}$)|(^$)
1517
1637
  */
1518
1638
  accountPolicy?: string;
1519
1639
  };
1520
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
+
1521
1661
  export type SignSolanaTransactionBody = {
1522
1662
  /** The base64 encoded transaction to sign. */
1523
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 "./payments-alpha/payments-alpha.msw.js";
2
- export * from "./solana-accounts/solana-accounts.msw.js";
3
- export * from "./evm-token-balances/evm-token-balances.msw.js";
4
- export * from "./policy-engine/policy-engine.msw.js";
5
1
  export * from "./evm-accounts/evm-accounts.msw.js";
6
- export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";
7
2
  export * from "./evm-swaps/evm-swaps.msw.js";
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";
8
6
  export * from "./faucets/faucets.msw.js";
7
+ export * from "./payments-alpha/payments-alpha.msw.js";
8
+ export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";