@coinbase/cdp-sdk 1.8.0 → 1.10.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 (142) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +190 -105
  3. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  4. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  5. package/_cjs/accounts/solana/toSolanaAccount.js +7 -0
  6. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
  7. package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
  8. package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  9. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
  10. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  11. package/_cjs/actions/evm/transfer/transfer.js +2 -39
  12. package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
  13. package/_cjs/actions/evm/transfer/utils.js +0 -12
  14. package/_cjs/actions/evm/transfer/utils.js.map +1 -1
  15. package/_cjs/actions/solana/constants.js +9 -0
  16. package/_cjs/actions/solana/constants.js.map +1 -0
  17. package/_cjs/actions/solana/transfer.js +117 -0
  18. package/_cjs/actions/solana/transfer.js.map +1 -0
  19. package/_cjs/actions/solana/utils.js +66 -0
  20. package/_cjs/actions/solana/utils.js.map +1 -0
  21. package/_cjs/analytics.js +2 -0
  22. package/_cjs/analytics.js.map +1 -1
  23. package/_cjs/client/evm/constants.js +21 -0
  24. package/_cjs/client/evm/constants.js.map +1 -0
  25. package/_cjs/client/evm/evm.js +75 -0
  26. package/_cjs/client/evm/evm.js.map +1 -1
  27. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +35 -4
  28. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  29. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +14 -1
  30. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
  31. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +26 -1
  32. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  33. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
  34. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  35. package/_cjs/policies/schema.js +60 -1
  36. package/_cjs/policies/schema.js.map +1 -1
  37. package/_cjs/version.js +1 -1
  38. package/_cjs/version.js.map +1 -1
  39. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  40. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  41. package/_esm/accounts/solana/toSolanaAccount.js +7 -0
  42. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
  43. package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
  44. package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  45. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
  46. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  47. package/_esm/actions/evm/transfer/transfer.js +2 -39
  48. package/_esm/actions/evm/transfer/transfer.js.map +1 -1
  49. package/_esm/actions/evm/transfer/utils.js +0 -11
  50. package/_esm/actions/evm/transfer/utils.js.map +1 -1
  51. package/_esm/actions/solana/constants.js +6 -0
  52. package/_esm/actions/solana/constants.js.map +1 -0
  53. package/_esm/actions/solana/transfer.js +114 -0
  54. package/_esm/actions/solana/transfer.js.map +1 -0
  55. package/_esm/actions/solana/utils.js +61 -0
  56. package/_esm/actions/solana/utils.js.map +1 -0
  57. package/_esm/analytics.js +2 -0
  58. package/_esm/analytics.js.map +1 -1
  59. package/_esm/client/evm/constants.js +18 -0
  60. package/_esm/client/evm/constants.js.map +1 -0
  61. package/_esm/client/evm/evm.js +75 -0
  62. package/_esm/client/evm/evm.js.map +1 -1
  63. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +34 -3
  64. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  65. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +12 -0
  66. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
  67. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +23 -0
  68. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  69. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
  70. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  71. package/_esm/policies/schema.js +59 -0
  72. package/_esm/policies/schema.js.map +1 -1
  73. package/_esm/version.js +1 -1
  74. package/_esm/version.js.map +1 -1
  75. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  76. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  77. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
  78. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +2 -2
  79. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
  80. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
  81. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
  82. package/_types/actions/evm/transfer/transfer.d.ts +6 -4
  83. package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
  84. package/_types/actions/evm/transfer/types.d.ts +7 -52
  85. package/_types/actions/evm/transfer/types.d.ts.map +1 -1
  86. package/_types/actions/evm/transfer/utils.d.ts +0 -619
  87. package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
  88. package/_types/actions/evm/types.d.ts +140 -68
  89. package/_types/actions/evm/types.d.ts.map +1 -1
  90. package/_types/actions/solana/constants.d.ts +6 -0
  91. package/_types/actions/solana/constants.d.ts.map +1 -0
  92. package/_types/actions/solana/transfer.d.ts +36 -0
  93. package/_types/actions/solana/transfer.d.ts.map +1 -0
  94. package/_types/actions/solana/types.d.ts +27 -0
  95. package/_types/actions/solana/types.d.ts.map +1 -1
  96. package/_types/actions/solana/utils.d.ts +34 -0
  97. package/_types/actions/solana/utils.d.ts.map +1 -0
  98. package/_types/analytics.d.ts.map +1 -1
  99. package/_types/client/evm/constants.d.ts +5 -0
  100. package/_types/client/evm/constants.d.ts.map +1 -0
  101. package/_types/client/evm/evm.d.ts +44 -1
  102. package/_types/client/evm/evm.d.ts.map +1 -1
  103. package/_types/client/evm/evm.types.d.ts +13 -1
  104. package/_types/client/evm/evm.types.d.ts.map +1 -1
  105. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +106 -17
  106. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  107. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +7 -1
  108. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
  109. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +2 -0
  110. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
  111. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
  112. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
  113. package/_types/openapi-client/index.d.ts +2 -0
  114. package/_types/openapi-client/index.d.ts.map +1 -1
  115. package/_types/policies/schema.d.ts +630 -0
  116. package/_types/policies/schema.d.ts.map +1 -1
  117. package/_types/version.d.ts +1 -1
  118. package/_types/version.d.ts.map +1 -1
  119. package/accounts/evm/toEvmServerAccount.ts +7 -6
  120. package/accounts/evm/toEvmSmartAccount.ts +1 -2
  121. package/accounts/solana/toSolanaAccount.ts +7 -0
  122. package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
  123. package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
  124. package/actions/evm/transfer/transfer.ts +10 -51
  125. package/actions/evm/transfer/types.ts +8 -66
  126. package/actions/evm/transfer/utils.ts +0 -13
  127. package/actions/evm/types.ts +143 -78
  128. package/actions/solana/constants.ts +6 -0
  129. package/actions/solana/transfer.ts +219 -0
  130. package/actions/solana/types.ts +28 -0
  131. package/actions/solana/utils.ts +79 -0
  132. package/analytics.ts +2 -0
  133. package/client/evm/constants.ts +17 -0
  134. package/client/evm/evm.ts +90 -0
  135. package/client/evm/evm.types.ts +14 -0
  136. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +146 -18
  137. package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +41 -0
  138. package/openapi-client/generated/evm-accounts/evm-accounts.ts +20 -0
  139. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
  140. package/package.json +2 -1
  141. package/policies/schema.ts +83 -0
  142. package/version.ts +1 -1
package/client/evm/evm.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import { publicEncrypt, constants } from "crypto";
2
+
1
3
  import { Address } from "viem";
2
4
 
5
+ import { ImportEvmAccountPublicRSAKey } from "./constants.js";
3
6
  import {
4
7
  CreateServerAccountOptions,
5
8
  GetServerAccountOptions,
@@ -23,6 +26,7 @@ import {
23
26
  GetOrCreateServerAccountOptions,
24
27
  SignTypedDataOptions,
25
28
  UpdateEvmAccountOptions,
29
+ ImportServerAccountOptions,
26
30
  } from "./evm.types.js";
27
31
  import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
28
32
  import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
@@ -112,6 +116,92 @@ export class EvmClient implements EvmClientInterface {
112
116
  return account;
113
117
  }
114
118
 
119
+ /**
120
+ * Imports a CDP EVM account from an external source.
121
+ *
122
+ * @param {ImportServerAccountOptions} options - Parameters for importing the account.
123
+ * @param {string} options.privateKey - The private key of the account to import.
124
+ * @param {string} [options.name] - A name for the account to import.
125
+ * @param {string} [options.idempotencyKey] - An idempotency key.
126
+ *
127
+ * @returns A promise that resolves to the imported account.
128
+ *
129
+ * @example **Without arguments**
130
+ * ```ts
131
+ * const account = await cdp.evm.importAccount({
132
+ * privateKey: "0x123456"
133
+ * });
134
+ * ```
135
+ *
136
+ * @example **With a name**
137
+ * ```ts
138
+ * const account = await cdp.evm.importAccount({
139
+ * privateKey: "0x123456",
140
+ * name: "MyAccount"
141
+ * });
142
+ * ```
143
+ *
144
+ * @example **With an idempotency key**
145
+ * ```ts
146
+ * const idempotencyKey = uuidv4();
147
+ *
148
+ * // First call
149
+ * await cdp.evm.importAccount({
150
+ * privateKey: "0x123456",
151
+ * idempotencyKey,
152
+ * });
153
+ *
154
+ * // Second call with the same idempotency key will return the same account
155
+ * await cdp.evm.importAccount({
156
+ * privateKey: "0x123456"
157
+ * idempotencyKey,
158
+ * });
159
+ * ```
160
+ */
161
+ async importAccount(options: ImportServerAccountOptions): Promise<ServerAccount> {
162
+ const privateKeyHex = options.privateKey.startsWith("0x")
163
+ ? options.privateKey.slice(2)
164
+ : options.privateKey;
165
+
166
+ if (!/^[0-9a-fA-F]+$/.test(privateKeyHex)) {
167
+ throw new Error("Private key must be a valid hexadecimal string");
168
+ }
169
+
170
+ try {
171
+ const privateKeyBytes = Buffer.from(privateKeyHex, "hex");
172
+
173
+ const encryptedPrivateKey = publicEncrypt(
174
+ {
175
+ key: ImportEvmAccountPublicRSAKey,
176
+ padding: constants.RSA_PKCS1_OAEP_PADDING,
177
+ oaepHash: "sha256",
178
+ },
179
+ privateKeyBytes,
180
+ );
181
+
182
+ const openApiAccount = await CdpOpenApiClient.importEvmAccount(
183
+ {
184
+ name: options.name,
185
+ encryptedPrivateKey: encryptedPrivateKey.toString("base64"),
186
+ },
187
+ options.idempotencyKey,
188
+ );
189
+
190
+ const account = toEvmServerAccount(CdpOpenApiClient, {
191
+ account: openApiAccount,
192
+ });
193
+
194
+ Analytics.wrapObjectMethodsWithErrorTracking(account);
195
+
196
+ return account;
197
+ } catch (error) {
198
+ if (error instanceof APIError) {
199
+ throw error;
200
+ }
201
+ throw new Error(`Failed to import account: ${String(error)}`);
202
+ }
203
+ }
204
+
115
205
  /**
116
206
  * Creates a new CDP EVM smart account.
117
207
  *
@@ -34,6 +34,7 @@ export type EvmClientInterface = Omit<
34
34
  typeof OpenApiEvmMethods,
35
35
  | "createEvmAccount" // mapped to createAccount
36
36
  | "createEvmSmartAccount" // mapped to createSmartAccount
37
+ | "importEvmAccount" // mapped to importAccount
37
38
  | "getEvmAccount" // mapped to getAccount
38
39
  | "getEvmAccountByName" // mapped to getAccount
39
40
  | "getEvmSmartAccount" // mapped to getSmartAccount
@@ -55,6 +56,7 @@ export type EvmClientInterface = Omit<
55
56
  > & {
56
57
  createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
57
58
  createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
59
+ importAccount: (options: ImportServerAccountOptions) => Promise<ServerAccount>;
58
60
  getAccount: (options: GetServerAccountOptions) => Promise<ServerAccount>;
59
61
  getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
60
62
  getOrCreateAccount: (options: GetOrCreateServerAccountOptions) => Promise<ServerAccount>;
@@ -147,6 +149,18 @@ export interface CreateServerAccountOptions {
147
149
  idempotencyKey?: string;
148
150
  }
149
151
 
152
+ /**
153
+ * Options for importing an EVM server account.
154
+ */
155
+ export interface ImportServerAccountOptions {
156
+ /** The name of the account. */
157
+ name?: string;
158
+ /** The idempotency key. */
159
+ idempotencyKey?: string;
160
+ /** The private key of the account. */
161
+ privateKey: Hex;
162
+ }
163
+
150
164
  /**
151
165
  * Options for getting an EVM account.
152
166
  */
@@ -333,6 +333,125 @@ export type SignEvmTransactionCriteriaItem = EthValueCriterion | EvmAddressCrite
333
333
  */
334
334
  export type SignEvmTransactionCriteria = SignEvmTransactionCriteriaItem[];
335
335
 
336
+ /**
337
+ * Whether matching the rule will cause the request to be rejected or accepted.
338
+ */
339
+ export type SignEvmTransactionRuleAction =
340
+ (typeof SignEvmTransactionRuleAction)[keyof typeof SignEvmTransactionRuleAction];
341
+
342
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
343
+ export const SignEvmTransactionRuleAction = {
344
+ reject: "reject",
345
+ accept: "accept",
346
+ } as const;
347
+
348
+ /**
349
+ * The operation to which the rule applies. Every element of the `criteria` array must match the specified operation.
350
+ */
351
+ export type SignEvmTransactionRuleOperation =
352
+ (typeof SignEvmTransactionRuleOperation)[keyof typeof SignEvmTransactionRuleOperation];
353
+
354
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
355
+ export const SignEvmTransactionRuleOperation = {
356
+ signEvmTransaction: "signEvmTransaction",
357
+ } as const;
358
+
359
+ export interface SignEvmTransactionRule {
360
+ /** Whether matching the rule will cause the request to be rejected or accepted. */
361
+ action: SignEvmTransactionRuleAction;
362
+ /** The operation to which the rule applies. Every element of the `criteria` array must match the specified operation. */
363
+ operation: SignEvmTransactionRuleOperation;
364
+ criteria: SignEvmTransactionCriteria;
365
+ }
366
+
367
+ /**
368
+ * The type of criterion to use. This should be `evmNetwork`.
369
+ */
370
+ export type EvmNetworkCriterionType =
371
+ (typeof EvmNetworkCriterionType)[keyof typeof EvmNetworkCriterionType];
372
+
373
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
374
+ export const EvmNetworkCriterionType = {
375
+ evmNetwork: "evmNetwork",
376
+ } as const;
377
+
378
+ /**
379
+ * The network the transaction is for.
380
+ */
381
+ export type EvmNetworkCriterionNetworksItem =
382
+ (typeof EvmNetworkCriterionNetworksItem)[keyof typeof EvmNetworkCriterionNetworksItem];
383
+
384
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
385
+ export const EvmNetworkCriterionNetworksItem = {
386
+ "base-sepolia": "base-sepolia",
387
+ base: "base",
388
+ } as const;
389
+
390
+ /**
391
+ * The operator to use for the comparison. The transaction's intended `network` will be on the left-hand side of the operator, and the `networks` field will be on the right-hand side.
392
+ */
393
+ export type EvmNetworkCriterionOperator =
394
+ (typeof EvmNetworkCriterionOperator)[keyof typeof EvmNetworkCriterionOperator];
395
+
396
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
397
+ export const EvmNetworkCriterionOperator = {
398
+ in: "in",
399
+ not_in: "not in",
400
+ } as const;
401
+
402
+ /**
403
+ * A schema for specifying a criterion for the intended `network` of an EVM transaction.
404
+ */
405
+ export interface EvmNetworkCriterion {
406
+ /** The type of criterion to use. This should be `evmNetwork`. */
407
+ type: EvmNetworkCriterionType;
408
+ /** A list of EVM network identifiers that the transaction's intended `network` should be compared to. */
409
+ networks: EvmNetworkCriterionNetworksItem[];
410
+ /** The operator to use for the comparison. The transaction's intended `network` will be on the left-hand side of the operator, and the `networks` field will be on the right-hand side. */
411
+ operator: EvmNetworkCriterionOperator;
412
+ }
413
+
414
+ export type SendEvmTransactionCriteriaItem =
415
+ | EthValueCriterion
416
+ | EvmAddressCriterion
417
+ | EvmNetworkCriterion;
418
+
419
+ /**
420
+ * A schema for specifying the rejection criteria for the SignEvmTransaction operation.
421
+ */
422
+ export type SendEvmTransactionCriteria = SendEvmTransactionCriteriaItem[];
423
+
424
+ /**
425
+ * Whether matching the rule will cause the request to be rejected or accepted.
426
+ */
427
+ export type SendEvmTransactionRuleAction =
428
+ (typeof SendEvmTransactionRuleAction)[keyof typeof SendEvmTransactionRuleAction];
429
+
430
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
431
+ export const SendEvmTransactionRuleAction = {
432
+ reject: "reject",
433
+ accept: "accept",
434
+ } as const;
435
+
436
+ /**
437
+ * The operation to which the rule applies. Every element of the `criteria` array must match the specified operation.
438
+ */
439
+ export type SendEvmTransactionRuleOperation =
440
+ (typeof SendEvmTransactionRuleOperation)[keyof typeof SendEvmTransactionRuleOperation];
441
+
442
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
443
+ export const SendEvmTransactionRuleOperation = {
444
+ sendEvmTransaction: "sendEvmTransaction",
445
+ } as const;
446
+
447
+ export interface SendEvmTransactionRule {
448
+ /** Whether matching the rule will cause the request to be rejected or accepted. */
449
+ action: SendEvmTransactionRuleAction;
450
+ /** The operation to which the rule applies. Every element of the `criteria` array must match the specified operation. */
451
+ operation: SendEvmTransactionRuleOperation;
452
+ criteria: SendEvmTransactionCriteria;
453
+ }
454
+
336
455
  /**
337
456
  * The type of criterion to use. This should be `solAddress`.
338
457
  */
@@ -376,10 +495,11 @@ export type SignSolTransactionCriteria = SolAddressCriterion[];
376
495
  /**
377
496
  * Whether matching the rule will cause the request to be rejected or accepted.
378
497
  */
379
- export type RuleAction = (typeof RuleAction)[keyof typeof RuleAction];
498
+ export type SignSolTransactionRuleAction =
499
+ (typeof SignSolTransactionRuleAction)[keyof typeof SignSolTransactionRuleAction];
380
500
 
381
501
  // eslint-disable-next-line @typescript-eslint/no-redeclare
382
- export const RuleAction = {
502
+ export const SignSolTransactionRuleAction = {
383
503
  reject: "reject",
384
504
  accept: "accept",
385
505
  } as const;
@@ -387,30 +507,26 @@ export const RuleAction = {
387
507
  /**
388
508
  * The operation to which the rule applies. Every element of the `criteria` array must match the specified operation.
389
509
  */
390
- export type RuleOperation = (typeof RuleOperation)[keyof typeof RuleOperation];
510
+ export type SignSolTransactionRuleOperation =
511
+ (typeof SignSolTransactionRuleOperation)[keyof typeof SignSolTransactionRuleOperation];
391
512
 
392
513
  // eslint-disable-next-line @typescript-eslint/no-redeclare
393
- export const RuleOperation = {
394
- signEvmTransaction: "signEvmTransaction",
514
+ export const SignSolTransactionRuleOperation = {
395
515
  signSolTransaction: "signSolTransaction",
396
516
  } as const;
397
517
 
398
- /**
399
- * The set of criteria for the rule. There is a limit of 10 criteria per rule.
400
- */
401
- export type RuleCriteria = SignEvmTransactionCriteria | SignSolTransactionCriteria;
518
+ export interface SignSolTransactionRule {
519
+ /** Whether matching the rule will cause the request to be rejected or accepted. */
520
+ action: SignSolTransactionRuleAction;
521
+ /** The operation to which the rule applies. Every element of the `criteria` array must match the specified operation. */
522
+ operation: SignSolTransactionRuleOperation;
523
+ criteria: SignSolTransactionCriteria;
524
+ }
402
525
 
403
526
  /**
404
527
  * A rule that limits the behavior of an account.
405
528
  */
406
- export interface Rule {
407
- /** Whether matching the rule will cause the request to be rejected or accepted. */
408
- action: RuleAction;
409
- /** The operation to which the rule applies. Every element of the `criteria` array must match the specified operation. */
410
- operation: RuleOperation;
411
- /** The set of criteria for the rule. There is a limit of 10 criteria per rule. */
412
- criteria: RuleCriteria;
413
- }
529
+ export type Rule = SignEvmTransactionRule | SendEvmTransactionRule | SignSolTransactionRule;
414
530
 
415
531
  /**
416
532
  * The scope of the policy. Only one project-level policy can exist at any time.
@@ -430,7 +546,7 @@ export interface Policy {
430
546
  */
431
547
  id: string;
432
548
  /**
433
- * An optional human-readable description of the policy.
549
+ * An optional human-readable description of the policy.
434
550
  Policy descriptions can consist of alphanumeric characters, spaces, commas, and periods, and be 50 characters or less.
435
551
  * @pattern ^[A-Za-z0-9 ,.]{1,50}$
436
552
  */
@@ -628,6 +744,18 @@ export type CreateEvmSmartAccountBody = {
628
744
  owners: string[];
629
745
  };
630
746
 
747
+ export type ImportEvmAccountBody = {
748
+ /** The base64-encoded, encrypted private key of the EVM account. The private key must be encrypted using the CDP SDK's encryption scheme. */
749
+ encryptedPrivateKey: string;
750
+ /**
751
+ * An optional name for the account.
752
+ Account names can consist of alphanumeric characters and hyphens, and be between 2 and 36 characters long.
753
+ Account names must be unique across all EVM accounts in the developer's CDP Project.
754
+ * @pattern ^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$
755
+ */
756
+ name?: string;
757
+ };
758
+
631
759
  /**
632
760
  * The network to prepare the user operation for.
633
761
  */
@@ -138,6 +138,25 @@ export const getSignEvmTypedDataResponseMock = (
138
138
  overrideResponse: Partial<SignEvmTypedData200> = {},
139
139
  ): SignEvmTypedData200 => ({ signature: faker.string.alpha(20), ...overrideResponse });
140
140
 
141
+ export const getImportEvmAccountResponseMock = (
142
+ overrideResponse: Partial<EvmAccount> = {},
143
+ ): EvmAccount => ({
144
+ address: faker.helpers.fromRegExp("^0x[0-9a-fA-F]{40}$"),
145
+ name: faker.helpers.arrayElement([
146
+ faker.helpers.fromRegExp("^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$"),
147
+ undefined,
148
+ ]),
149
+ policies: faker.helpers.arrayElement([
150
+ Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() =>
151
+ faker.helpers.fromRegExp(
152
+ "^[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}$",
153
+ ),
154
+ ),
155
+ undefined,
156
+ ]),
157
+ ...overrideResponse,
158
+ });
159
+
141
160
  export const getListEvmAccountsMockHandler = (
142
161
  overrideResponse?:
143
162
  | ListEvmAccounts200
@@ -359,6 +378,27 @@ export const getSignEvmTypedDataMockHandler = (
359
378
  );
360
379
  });
361
380
  };
381
+
382
+ export const getImportEvmAccountMockHandler = (
383
+ overrideResponse?:
384
+ | EvmAccount
385
+ | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<EvmAccount> | EvmAccount),
386
+ ) => {
387
+ return http.post("*/v2/evm/accounts/import", async info => {
388
+ await delay(0);
389
+
390
+ return new HttpResponse(
391
+ JSON.stringify(
392
+ overrideResponse !== undefined
393
+ ? typeof overrideResponse === "function"
394
+ ? await overrideResponse(info)
395
+ : overrideResponse
396
+ : getImportEvmAccountResponseMock(),
397
+ ),
398
+ { status: 201, headers: { "Content-Type": "application/json" } },
399
+ );
400
+ });
401
+ };
362
402
  export const getEvmAccountsMock = () => [
363
403
  getListEvmAccountsMockHandler(),
364
404
  getCreateEvmAccountMockHandler(),
@@ -370,4 +410,5 @@ export const getEvmAccountsMock = () => [
370
410
  getSignEvmHashMockHandler(),
371
411
  getSignEvmMessageMockHandler(),
372
412
  getSignEvmTypedDataMockHandler(),
413
+ getImportEvmAccountMockHandler(),
373
414
  ];
@@ -9,6 +9,7 @@ import type {
9
9
  CreateEvmAccountBody,
10
10
  EIP712Message,
11
11
  EvmAccount,
12
+ ImportEvmAccountBody,
12
13
  ListEvmAccounts200,
13
14
  ListEvmAccountsParams,
14
15
  SendEvmTransaction200,
@@ -223,6 +224,24 @@ export const signEvmTypedData = (
223
224
  options,
224
225
  );
225
226
  };
227
+ /**
228
+ * Import an existing EVM account into the developer's CDP Project. This API should be called from the [CDP SDK](https://github.com/coinbase/cdp-sdk) to ensure that the associated private key is properly encrypted.
229
+ * @summary Import an EVM account
230
+ */
231
+ export const importEvmAccount = (
232
+ importEvmAccountBody: ImportEvmAccountBody,
233
+ options?: SecondParameter<typeof cdpApiClient>,
234
+ ) => {
235
+ return cdpApiClient<EvmAccount>(
236
+ {
237
+ url: `/v2/evm/accounts/import`,
238
+ method: "POST",
239
+ headers: { "Content-Type": "application/json" },
240
+ data: importEvmAccountBody,
241
+ },
242
+ options,
243
+ );
244
+ };
226
245
  export type ListEvmAccountsResult = NonNullable<Awaited<ReturnType<typeof listEvmAccounts>>>;
227
246
  export type CreateEvmAccountResult = NonNullable<Awaited<ReturnType<typeof createEvmAccount>>>;
228
247
  export type GetEvmAccountResult = NonNullable<Awaited<ReturnType<typeof getEvmAccount>>>;
@@ -235,3 +254,4 @@ export type SignEvmTransactionResult = NonNullable<Awaited<ReturnType<typeof sig
235
254
  export type SignEvmHashResult = NonNullable<Awaited<ReturnType<typeof signEvmHash>>>;
236
255
  export type SignEvmMessageResult = NonNullable<Awaited<ReturnType<typeof signEvmMessage>>>;
237
256
  export type SignEvmTypedDataResult = NonNullable<Awaited<ReturnType<typeof signEvmTypedData>>>;
257
+ export type ImportEvmAccountResult = NonNullable<Awaited<ReturnType<typeof importEvmAccount>>>;