@coinbase/cdp-sdk 1.6.0 → 1.8.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.
- package/CHANGELOG.md +23 -0
- package/README.md +284 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +7 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/types.js.map +1 -0
- package/_cjs/accounts/solana/toSolanaAccount.js +42 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -0
- package/_cjs/accounts/solana/types.js +3 -0
- package/_cjs/accounts/solana/types.js.map +1 -0
- package/_cjs/actions/evm/getUserOperation.js +36 -0
- package/_cjs/actions/evm/getUserOperation.js.map +1 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +11 -7
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +7 -3
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/solana/requestFaucet.js +29 -0
- package/_cjs/actions/solana/requestFaucet.js.map +1 -0
- package/_cjs/actions/solana/signMessage.js +29 -0
- package/_cjs/actions/solana/signMessage.js.map +1 -0
- package/_cjs/actions/solana/signTransaction.js +46 -0
- package/_cjs/actions/solana/signTransaction.js.map +1 -0
- package/_cjs/actions/solana/types.js +3 -0
- package/_cjs/actions/solana/types.js.map +1 -0
- package/_cjs/analytics.js +68 -8
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +9 -3
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +135 -27
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/index.js +6 -0
- package/_cjs/client/policies/index.js.map +1 -0
- package/_cjs/client/policies/policies.js +232 -0
- package/_cjs/client/policies/policies.js.map +1 -0
- package/_cjs/client/policies/policies.types.js +3 -0
- package/_cjs/client/policies/policies.types.js.map +1 -0
- package/_cjs/client/solana/solana.js +84 -22
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +4 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +59 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +56 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +3 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js +56 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +284 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +14 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +42 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +7 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +186 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/{accounts → policies}/types.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +4 -2
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +7 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/types.js.map +1 -0
- package/_esm/accounts/solana/toSolanaAccount.js +39 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -0
- package/_esm/accounts/solana/types.js +2 -0
- package/_esm/accounts/solana/types.js.map +1 -0
- package/_esm/actions/evm/getUserOperation.js +33 -0
- package/_esm/actions/evm/getUserOperation.js.map +1 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +11 -7
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +7 -3
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/solana/requestFaucet.js +26 -0
- package/_esm/actions/solana/requestFaucet.js.map +1 -0
- package/_esm/actions/solana/signMessage.js +26 -0
- package/_esm/actions/solana/signMessage.js.map +1 -0
- package/_esm/actions/solana/signTransaction.js +43 -0
- package/_esm/actions/solana/signTransaction.js.map +1 -0
- package/_esm/actions/solana/types.js +2 -0
- package/_esm/actions/solana/types.js.map +1 -0
- package/_esm/analytics.js +68 -7
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +10 -4
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +135 -27
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/index.js +2 -0
- package/_esm/client/policies/index.js.map +1 -0
- package/_esm/client/policies/policies.js +228 -0
- package/_esm/client/policies/policies.js.map +1 -0
- package/_esm/client/policies/policies.types.js +2 -0
- package/_esm/client/policies/policies.types.js.map +1 -0
- package/_esm/client/solana/solana.js +84 -22
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +58 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +51 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +3 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js +48 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +259 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +12 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +39 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +6 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +183 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/{accounts → policies}/types.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/{types.d.ts → evm/types.d.ts} +10 -7
- package/_types/accounts/evm/types.d.ts.map +1 -0
- package/_types/accounts/solana/toSolanaAccount.d.ts +20 -0
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -0
- package/_types/accounts/solana/types.d.ts +12 -0
- package/_types/accounts/solana/types.d.ts.map +1 -0
- package/_types/actions/evm/getUserOperation.d.ts +22 -0
- package/_types/actions/evm/getUserOperation.d.ts.map +1 -0
- package/_types/actions/evm/sendUserOperation.d.ts +1 -1
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +3 -3
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +39 -6
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +28 -5
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/requestFaucet.d.ts +23 -0
- package/_types/actions/solana/requestFaucet.d.ts.map +1 -0
- package/_types/actions/solana/signMessage.d.ts +23 -0
- package/_types/actions/solana/signMessage.d.ts.map +1 -0
- package/_types/actions/solana/signTransaction.d.ts +38 -0
- package/_types/actions/solana/signTransaction.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +80 -0
- package/_types/actions/solana/types.d.ts.map +1 -0
- package/_types/analytics.d.ts +14 -5
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +3 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +89 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +36 -6
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/index.d.ts +2 -0
- package/_types/client/policies/index.d.ts.map +1 -0
- package/_types/client/policies/policies.d.ts +216 -0
- package/_types/client/policies/policies.d.ts.map +1 -0
- package/_types/client/policies/policies.types.d.ts +96 -0
- package/_types/client/policies/policies.types.d.ts.map +1 -0
- package/_types/client/solana/solana.d.ts +47 -4
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +21 -12
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +299 -0
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +3 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +3 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +43 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +25 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +19 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +922 -0
- package/_types/policies/schema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +19 -0
- package/_types/policies/types.d.ts.map +1 -0
- package/_types/types/misc.d.ts +39 -0
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +7 -4
- package/accounts/evm/toEvmSmartAccount.ts +11 -1
- package/accounts/{types.ts → evm/types.ts} +10 -12
- package/accounts/solana/toSolanaAccount.ts +60 -0
- package/accounts/solana/types.ts +13 -0
- package/actions/evm/getUserOperation.ts +40 -0
- package/actions/evm/sendUserOperation.ts +1 -1
- package/actions/evm/transfer/accountTransferStrategy.ts +12 -8
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +10 -7
- package/actions/evm/transfer/transfer.ts +17 -6
- package/actions/evm/transfer/types.ts +54 -11
- package/actions/evm/types.ts +37 -5
- package/actions/solana/requestFaucet.ts +35 -0
- package/actions/solana/signMessage.ts +36 -0
- package/actions/solana/signTransaction.ts +53 -0
- package/actions/solana/types.ts +87 -0
- package/analytics.ts +84 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +162 -33
- package/client/evm/evm.types.ts +42 -4
- package/client/policies/index.ts +1 -0
- package/client/policies/policies.ts +246 -0
- package/client/policies/policies.types.ts +109 -0
- package/client/solana/solana.ts +107 -38
- package/client/solana/solana.types.ts +25 -15
- package/index.ts +8 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +360 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +102 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +43 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -1
- package/openapi-client/generated/index.msw.ts +3 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +404 -0
- package/openapi-client/generated/policy-engine/policy-engine.ts +95 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +75 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +23 -0
- package/openapi-client/index.ts +7 -0
- package/package.json +3 -2
- package/policies/schema.ts +266 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
- package/_types/accounts/types.d.ts.map +0 -1
- /package/_cjs/accounts/{types.js → evm/types.js} +0 -0
- /package/_esm/accounts/{types.js → evm/types.js} +0 -0
package/client/evm/evm.ts
CHANGED
|
@@ -21,9 +21,12 @@ import {
|
|
|
21
21
|
ListSmartAccountResult,
|
|
22
22
|
ListSmartAccountsOptions,
|
|
23
23
|
GetOrCreateServerAccountOptions,
|
|
24
|
+
SignTypedDataOptions,
|
|
25
|
+
UpdateEvmAccountOptions,
|
|
24
26
|
} from "./evm.types.js";
|
|
25
27
|
import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
|
|
26
28
|
import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
|
|
29
|
+
import { getUserOperation } from "../../actions/evm/getUserOperation.js";
|
|
27
30
|
import {
|
|
28
31
|
listTokenBalances,
|
|
29
32
|
ListTokenBalancesResult,
|
|
@@ -44,6 +47,7 @@ import {
|
|
|
44
47
|
waitForUserOperation,
|
|
45
48
|
WaitForUserOperationReturnType,
|
|
46
49
|
} from "../../actions/evm/waitForUserOperation.js";
|
|
50
|
+
import { Analytics } from "../../analytics.js";
|
|
47
51
|
import { APIError } from "../../openapi-client/errors.js";
|
|
48
52
|
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
49
53
|
import { Hex } from "../../types/misc.js";
|
|
@@ -52,6 +56,7 @@ import type {
|
|
|
52
56
|
TransactionResult,
|
|
53
57
|
SendTransactionOptions,
|
|
54
58
|
} from "../../actions/evm/sendTransaction.js";
|
|
59
|
+
|
|
55
60
|
/**
|
|
56
61
|
* The namespace containing all EVM methods.
|
|
57
62
|
*/
|
|
@@ -91,16 +96,20 @@ export class EvmClient implements EvmClientInterface {
|
|
|
91
96
|
* ```
|
|
92
97
|
*/
|
|
93
98
|
async createAccount(options: CreateServerAccountOptions = {}): Promise<ServerAccount> {
|
|
94
|
-
const
|
|
99
|
+
const openApiAccount = await CdpOpenApiClient.createEvmAccount(
|
|
95
100
|
{
|
|
96
101
|
name: options.name,
|
|
97
102
|
},
|
|
98
103
|
options.idempotencyKey,
|
|
99
104
|
);
|
|
100
105
|
|
|
101
|
-
|
|
102
|
-
account,
|
|
106
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
107
|
+
account: openApiAccount,
|
|
103
108
|
});
|
|
109
|
+
|
|
110
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
111
|
+
|
|
112
|
+
return account;
|
|
104
113
|
}
|
|
105
114
|
|
|
106
115
|
/**
|
|
@@ -149,17 +158,21 @@ export class EvmClient implements EvmClientInterface {
|
|
|
149
158
|
* ```
|
|
150
159
|
*/
|
|
151
160
|
async createSmartAccount(options: CreateSmartAccountOptions): Promise<SmartAccount> {
|
|
152
|
-
const
|
|
161
|
+
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
153
162
|
{
|
|
154
163
|
owners: [options.owner.address],
|
|
155
164
|
},
|
|
156
165
|
options.idempotencyKey,
|
|
157
166
|
);
|
|
158
167
|
|
|
159
|
-
|
|
160
|
-
smartAccount,
|
|
168
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
169
|
+
smartAccount: openApiSmartAccount,
|
|
161
170
|
owner: options.owner,
|
|
162
171
|
});
|
|
172
|
+
|
|
173
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
174
|
+
|
|
175
|
+
return smartAccount;
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
/**
|
|
@@ -188,7 +201,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
188
201
|
* ```
|
|
189
202
|
*/
|
|
190
203
|
async getAccount(options: GetServerAccountOptions): Promise<ServerAccount> {
|
|
191
|
-
const
|
|
204
|
+
const openApiAccount = await (() => {
|
|
192
205
|
if (options.address) {
|
|
193
206
|
return CdpOpenApiClient.getEvmAccount(options.address);
|
|
194
207
|
}
|
|
@@ -200,9 +213,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
200
213
|
throw new Error("Either address or name must be provided");
|
|
201
214
|
})();
|
|
202
215
|
|
|
203
|
-
|
|
204
|
-
account,
|
|
216
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
217
|
+
account: openApiAccount,
|
|
205
218
|
});
|
|
219
|
+
|
|
220
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
221
|
+
|
|
222
|
+
return account;
|
|
206
223
|
}
|
|
207
224
|
|
|
208
225
|
/**
|
|
@@ -225,12 +242,16 @@ export class EvmClient implements EvmClientInterface {
|
|
|
225
242
|
* ```
|
|
226
243
|
*/
|
|
227
244
|
async getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount> {
|
|
228
|
-
const
|
|
245
|
+
const openApiSmartAccount = await CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
229
246
|
|
|
230
|
-
|
|
231
|
-
smartAccount,
|
|
247
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
248
|
+
smartAccount: openApiSmartAccount,
|
|
232
249
|
owner: options.owner,
|
|
233
250
|
});
|
|
251
|
+
|
|
252
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
253
|
+
|
|
254
|
+
return smartAccount;
|
|
234
255
|
}
|
|
235
256
|
|
|
236
257
|
/**
|
|
@@ -292,22 +313,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
292
313
|
* ```
|
|
293
314
|
*/
|
|
294
315
|
async getUserOperation(options: GetUserOperationOptions): Promise<UserOperation> {
|
|
295
|
-
|
|
296
|
-
options.smartAccount.address,
|
|
297
|
-
options.userOpHash,
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
return {
|
|
301
|
-
calls: userOp.calls.map(call => ({
|
|
302
|
-
to: call.to as Address,
|
|
303
|
-
value: BigInt(call.value),
|
|
304
|
-
data: call.data as Hex,
|
|
305
|
-
})),
|
|
306
|
-
network: userOp.network,
|
|
307
|
-
status: userOp.status,
|
|
308
|
-
transactionHash: userOp.transactionHash as Hex | undefined,
|
|
309
|
-
userOpHash: userOp.userOpHash as Hex,
|
|
310
|
-
};
|
|
316
|
+
return getUserOperation(CdpOpenApiClient, options);
|
|
311
317
|
}
|
|
312
318
|
|
|
313
319
|
/**
|
|
@@ -341,11 +347,15 @@ export class EvmClient implements EvmClientInterface {
|
|
|
341
347
|
});
|
|
342
348
|
|
|
343
349
|
return {
|
|
344
|
-
accounts: ethAccounts.accounts.map(account =>
|
|
345
|
-
toEvmServerAccount(CdpOpenApiClient, {
|
|
346
|
-
account
|
|
347
|
-
})
|
|
348
|
-
|
|
350
|
+
accounts: ethAccounts.accounts.map(account => {
|
|
351
|
+
const evmAccount = toEvmServerAccount(CdpOpenApiClient, {
|
|
352
|
+
account,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
Analytics.wrapObjectMethodsWithErrorTracking(evmAccount);
|
|
356
|
+
|
|
357
|
+
return evmAccount;
|
|
358
|
+
}),
|
|
349
359
|
nextPageToken: ethAccounts.nextPageToken,
|
|
350
360
|
};
|
|
351
361
|
}
|
|
@@ -660,6 +670,68 @@ export class EvmClient implements EvmClientInterface {
|
|
|
660
670
|
};
|
|
661
671
|
}
|
|
662
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Signs an EIP-712 message.
|
|
675
|
+
*
|
|
676
|
+
* @param {SignTypedDataOptions} options - Parameters for signing the EIP-712 message.
|
|
677
|
+
* @returns A promise that resolves to the signature.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* const signature = await cdp.evm.signTypedData({
|
|
682
|
+
* address: account.address,
|
|
683
|
+
* domain: {
|
|
684
|
+
* name: "Permit2",
|
|
685
|
+
* chainId: 1,
|
|
686
|
+
* verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
687
|
+
* },
|
|
688
|
+
* types: {
|
|
689
|
+
* EIP712Domain: [
|
|
690
|
+
* { name: "name", type: "string" },
|
|
691
|
+
* { name: "chainId", type: "uint256" },
|
|
692
|
+
* { name: "verifyingContract", type: "address" },
|
|
693
|
+
* ],
|
|
694
|
+
* PermitTransferFrom: [
|
|
695
|
+
* { name: "permitted", type: "TokenPermissions" },
|
|
696
|
+
* { name: "spender", type: "address" },
|
|
697
|
+
* { name: "nonce", type: "uint256" },
|
|
698
|
+
* { name: "deadline", type: "uint256" },
|
|
699
|
+
* ],
|
|
700
|
+
* TokenPermissions: [
|
|
701
|
+
* { name: "token", type: "address" },
|
|
702
|
+
* { name: "amount", type: "uint256" },
|
|
703
|
+
* ],
|
|
704
|
+
* },
|
|
705
|
+
* primaryType: "PermitTransferFrom",
|
|
706
|
+
* message: {
|
|
707
|
+
* permitted: {
|
|
708
|
+
* token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
709
|
+
* amount: "1000000",
|
|
710
|
+
* },
|
|
711
|
+
* spender: "0xFfFfFfFFfFFfFFfFFfFFFFFffFFFffffFfFFFfFf",
|
|
712
|
+
* nonce: "0",
|
|
713
|
+
* deadline: "1717123200",
|
|
714
|
+
* },
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
async signTypedData(options: SignTypedDataOptions): Promise<SignatureResult> {
|
|
719
|
+
const signature = await CdpOpenApiClient.signEvmTypedData(
|
|
720
|
+
options.address,
|
|
721
|
+
{
|
|
722
|
+
domain: options.domain,
|
|
723
|
+
types: options.types,
|
|
724
|
+
primaryType: options.primaryType,
|
|
725
|
+
message: options.message,
|
|
726
|
+
},
|
|
727
|
+
options.idempotencyKey,
|
|
728
|
+
);
|
|
729
|
+
|
|
730
|
+
return {
|
|
731
|
+
signature: signature.signature as Hex,
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
663
735
|
/**
|
|
664
736
|
* Signs an EVM transaction.
|
|
665
737
|
*
|
|
@@ -704,6 +776,63 @@ export class EvmClient implements EvmClientInterface {
|
|
|
704
776
|
};
|
|
705
777
|
}
|
|
706
778
|
|
|
779
|
+
/**
|
|
780
|
+
* Updates a CDP EVM account.
|
|
781
|
+
*
|
|
782
|
+
* @param {UpdateEvmAccountOptions} [options] - Optional parameters for creating the account.
|
|
783
|
+
* @param {string} options.address - The address of the account to update
|
|
784
|
+
* @param {UpdateEvmAccountBody} options.update - An object containing account fields to update.
|
|
785
|
+
* @param {string} [options.update.name] - The new name for the account.
|
|
786
|
+
* @param {string} [options.update.accountPolicy] - The ID of a Policy to apply to the account.
|
|
787
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
788
|
+
*
|
|
789
|
+
* @returns A promise that resolves to the updated account.
|
|
790
|
+
*
|
|
791
|
+
* @example **With a name**
|
|
792
|
+
* ```ts
|
|
793
|
+
* const account = await cdp.evm.updateAccount({ address: "0x...", update: { name: "New Name" } });
|
|
794
|
+
* ```
|
|
795
|
+
*
|
|
796
|
+
* @example **With an account policy**
|
|
797
|
+
* ```ts
|
|
798
|
+
* const account = await cdp.evm.updateAccount({ address: "0x...", update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" } });
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @example **With an idempotency key**
|
|
802
|
+
* ```ts
|
|
803
|
+
* const idempotencyKey = uuidv4();
|
|
804
|
+
*
|
|
805
|
+
* // First call
|
|
806
|
+
* await cdp.evm.updateAccount({
|
|
807
|
+
* address: "0x...",
|
|
808
|
+
* update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" },
|
|
809
|
+
* idempotencyKey,
|
|
810
|
+
* });
|
|
811
|
+
*
|
|
812
|
+
* // Second call with the same idempotency key will not update
|
|
813
|
+
* await cdp.evm.updateAccount({
|
|
814
|
+
* address: '0x...',
|
|
815
|
+
* update: { name: "" },
|
|
816
|
+
* idempotencyKey,
|
|
817
|
+
* });
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
async updateAccount(options: UpdateEvmAccountOptions): Promise<ServerAccount> {
|
|
821
|
+
const openApiAccount = await CdpOpenApiClient.updateEvmAccount(
|
|
822
|
+
options.address,
|
|
823
|
+
options.update,
|
|
824
|
+
options.idempotencyKey,
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
828
|
+
account: openApiAccount,
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
832
|
+
|
|
833
|
+
return account;
|
|
834
|
+
}
|
|
835
|
+
|
|
707
836
|
/**
|
|
708
837
|
* Waits for a user operation to complete or fail.
|
|
709
838
|
*
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
EvmAccount as Account,
|
|
3
3
|
EvmServerAccount as ServerAccount,
|
|
4
4
|
EvmSmartAccount as SmartAccount,
|
|
5
|
-
} from "../../accounts/types.js";
|
|
5
|
+
} from "../../accounts/evm/types.js";
|
|
6
6
|
import type {
|
|
7
7
|
ListTokenBalancesOptions,
|
|
8
8
|
ListTokenBalancesResult,
|
|
@@ -16,14 +16,15 @@ import type {
|
|
|
16
16
|
SendUserOperationOptions,
|
|
17
17
|
SendUserOperationReturnType,
|
|
18
18
|
} from "../../actions/evm/sendUserOperation.js";
|
|
19
|
-
import type {
|
|
19
|
+
import type { SmartAccountActions } from "../../actions/evm/types.js";
|
|
20
20
|
import type {
|
|
21
21
|
EvmUserOperationNetwork,
|
|
22
22
|
EvmUserOperationStatus,
|
|
23
23
|
OpenApiEvmMethods,
|
|
24
|
+
UpdateEvmAccountBody,
|
|
24
25
|
} from "../../openapi-client/index.js";
|
|
25
26
|
import type { Calls } from "../../types/calls.js";
|
|
26
|
-
import type { Address, Hex } from "../../types/misc.js";
|
|
27
|
+
import type { Address, EIP712Message, Hex } from "../../types/misc.js";
|
|
27
28
|
import type { WaitOptions } from "../../utils/wait.js";
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -37,6 +38,7 @@ export type EvmClientInterface = Omit<
|
|
|
37
38
|
| "getEvmAccountByName" // mapped to getAccount
|
|
38
39
|
| "getEvmSmartAccount" // mapped to getSmartAccount
|
|
39
40
|
| "getUserOperation"
|
|
41
|
+
| "updateEvmAccount" // mapped to updateAccount
|
|
40
42
|
| "listEvmAccounts" // mapped to listAccounts
|
|
41
43
|
| "listEvmSmartAccounts" // mapped to listSmartAccounts
|
|
42
44
|
| "listEvmTokenBalances" // mapped to listTokenBalances
|
|
@@ -46,7 +48,10 @@ export type EvmClientInterface = Omit<
|
|
|
46
48
|
| "signEvmHash" // mapped to signHash
|
|
47
49
|
| "signEvmMessage" // mapped to signMessage
|
|
48
50
|
| "signEvmTransaction" // mapped to signTransaction
|
|
51
|
+
| "signEvmTypedData" // mapped to signTypedData
|
|
49
52
|
| "sendEvmTransaction" // mapped to sendTransaction
|
|
53
|
+
| "signEvmTypedData" // mapped to signTypedData
|
|
54
|
+
| "updateEvmAccount" // mapped to updateAccount
|
|
50
55
|
> & {
|
|
51
56
|
createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
|
|
52
57
|
createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
|
|
@@ -54,6 +59,7 @@ export type EvmClientInterface = Omit<
|
|
|
54
59
|
getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
|
|
55
60
|
getOrCreateAccount: (options: GetOrCreateServerAccountOptions) => Promise<ServerAccount>;
|
|
56
61
|
getUserOperation: (options: GetUserOperationOptions) => Promise<UserOperation>;
|
|
62
|
+
updateAccount: (options: UpdateEvmAccountOptions) => Promise<ServerAccount>;
|
|
57
63
|
listAccounts: (options: ListServerAccountsOptions) => Promise<ListServerAccountResult>;
|
|
58
64
|
listSmartAccounts: (options: ListSmartAccountsOptions) => Promise<ListSmartAccountResult>;
|
|
59
65
|
listTokenBalances: (options: ListTokenBalancesOptions) => Promise<ListTokenBalancesResult>;
|
|
@@ -65,6 +71,7 @@ export type EvmClientInterface = Omit<
|
|
|
65
71
|
) => Promise<SendUserOperationReturnType>;
|
|
66
72
|
signHash: (options: SignHashOptions) => Promise<SignatureResult>;
|
|
67
73
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
74
|
+
signTypedData: (options: SignTypedDataOptions) => Promise<SignatureResult>;
|
|
68
75
|
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
69
76
|
};
|
|
70
77
|
|
|
@@ -181,11 +188,24 @@ export interface ListServerAccountsOptions {
|
|
|
181
188
|
/**
|
|
182
189
|
* A smart account that only contains the owner address.
|
|
183
190
|
*/
|
|
184
|
-
export interface ReadonlySmartAccount
|
|
191
|
+
export interface ReadonlySmartAccount
|
|
192
|
+
extends Omit<SmartAccount, "owners" | keyof SmartAccountActions> {
|
|
185
193
|
/** The owners of the smart account. */
|
|
186
194
|
owners: Address[];
|
|
187
195
|
}
|
|
188
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Options for creating an EVM server account.
|
|
199
|
+
*/
|
|
200
|
+
export interface UpdateEvmAccountOptions {
|
|
201
|
+
/** The address of the account. */
|
|
202
|
+
address: string;
|
|
203
|
+
/** The updates to apply to the account */
|
|
204
|
+
update: UpdateEvmAccountBody;
|
|
205
|
+
/** The idempotency key. */
|
|
206
|
+
idempotencyKey?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
189
209
|
/**
|
|
190
210
|
* The result of listing EVM smart accounts.
|
|
191
211
|
*/
|
|
@@ -258,6 +278,24 @@ export interface SignMessageOptions {
|
|
|
258
278
|
idempotencyKey?: string;
|
|
259
279
|
}
|
|
260
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Options for signing an EVM message.
|
|
283
|
+
*/
|
|
284
|
+
export interface SignTypedDataOptions {
|
|
285
|
+
/** The address of the account. */
|
|
286
|
+
address: Address;
|
|
287
|
+
/** The domain of the message. */
|
|
288
|
+
domain: EIP712Message["domain"];
|
|
289
|
+
/** The types of the message. */
|
|
290
|
+
types: EIP712Message["types"];
|
|
291
|
+
/** The primary type of the message. This is the name of the struct in the `types` object that is the root of the message. */
|
|
292
|
+
primaryType: EIP712Message["primaryType"];
|
|
293
|
+
/** The message to sign. The structure of this message must match the `primaryType` struct in the `types` object. */
|
|
294
|
+
message: EIP712Message["message"];
|
|
295
|
+
/** The idempotency key. */
|
|
296
|
+
idempotencyKey?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
261
299
|
/**
|
|
262
300
|
* Options for signing an EVM transaction.
|
|
263
301
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PoliciesClient } from "./policies.js";
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoliciesClientInterface,
|
|
3
|
+
CreatePolicyOptions,
|
|
4
|
+
ListPoliciesOptions,
|
|
5
|
+
ListPoliciesResult,
|
|
6
|
+
GetPolicyByIdOptions,
|
|
7
|
+
DeletePolicyOptions,
|
|
8
|
+
UpdatePolicyOptions,
|
|
9
|
+
} from "./policies.types.js";
|
|
10
|
+
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
11
|
+
import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "../../policies/schema.js";
|
|
12
|
+
import { Policy } from "../../policies/types.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The namespace containing all Policy methods.
|
|
16
|
+
*/
|
|
17
|
+
export class PoliciesClient implements PoliciesClientInterface {
|
|
18
|
+
/**
|
|
19
|
+
* Lists policies belonging to the developer's CDP Project.
|
|
20
|
+
* Can be filtered by scope (project or account).
|
|
21
|
+
*
|
|
22
|
+
* @param {ListPoliciesOptions} [options] - Options for filtering and paginating the results
|
|
23
|
+
* @param {string} [options.scope] - Filter policies by scope ('project' or 'account')
|
|
24
|
+
* @param {number} [options.pageSize] - Maximum number of policies to return
|
|
25
|
+
* @param {string} [options.pageToken] - Pagination cursor for fetching next page of results
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<ListPoliciesResult>} A paginated list of policies
|
|
28
|
+
*
|
|
29
|
+
* @example **List all policies**
|
|
30
|
+
* ```ts
|
|
31
|
+
* const { policies } = await cdp.policies.listPolicies();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example **Filter by scope**
|
|
35
|
+
* ```ts
|
|
36
|
+
* const { policies } = await cdp.policies.listPolicies({
|
|
37
|
+
* scope: 'project'
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example **With pagination**
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Get first page
|
|
44
|
+
* const firstPage = await cdp.policies.listPolicies({
|
|
45
|
+
* pageSize: 10
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Get next page using cursor
|
|
49
|
+
* const nextPage = await cdp.policies.listPolicies({
|
|
50
|
+
* pageSize: 10,
|
|
51
|
+
* pageToken: firstPage.pageToken
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
async listPolicies(options: ListPoliciesOptions = {}): Promise<ListPoliciesResult> {
|
|
56
|
+
return CdpOpenApiClient.listPolicies(options) as Promise<ListPoliciesResult>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new policy that can be used to govern the behavior of projects and accounts.
|
|
61
|
+
*
|
|
62
|
+
* @param {CreatePolicyOptions} options - Options for creating the policy
|
|
63
|
+
* @param {CreatePolicyBody} options.policy - The policy configuration to create
|
|
64
|
+
* @param {string} [options.policy.description] - Description of the policy's purpose
|
|
65
|
+
* @param {Rule[]} options.policy.rules - Rules that define the policy behavior
|
|
66
|
+
* @param {string} [options.idempotencyKey] - An idempotency key to prevent duplicate policy creation
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<Policy>} The created policy
|
|
69
|
+
* @throws {ZodError<typeof CreatePolicyBodySchema>} When the policy is invalid
|
|
70
|
+
*
|
|
71
|
+
* @example **Creating a new policy**
|
|
72
|
+
* ```ts
|
|
73
|
+
* const policy = await cdp.policies.createPolicy({
|
|
74
|
+
* policy: {
|
|
75
|
+
* scope: "account",
|
|
76
|
+
* description: "Limits the amount of ETH in transaction",
|
|
77
|
+
* rules: [
|
|
78
|
+
* {
|
|
79
|
+
* action: "reject",
|
|
80
|
+
* operation: "signEvmTransaction",
|
|
81
|
+
* criteria: [
|
|
82
|
+
* {
|
|
83
|
+
* type: "ethValue",
|
|
84
|
+
* ethValue: "1000000000000000000",
|
|
85
|
+
* operator: ">",
|
|
86
|
+
* },
|
|
87
|
+
* ],
|
|
88
|
+
* },
|
|
89
|
+
* ],
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example **With idempotency key**
|
|
95
|
+
* ```ts
|
|
96
|
+
* const idempotencyKey = uuidv4();
|
|
97
|
+
*
|
|
98
|
+
* // First call creates the policy
|
|
99
|
+
* const policy = await cdp.policies.createPolicy({
|
|
100
|
+
* policy: {
|
|
101
|
+
* scope: "account",
|
|
102
|
+
* description: "Limits the amount of ETH in transaction",
|
|
103
|
+
* rules: [
|
|
104
|
+
* {
|
|
105
|
+
* action: "reject",
|
|
106
|
+
* operation: "signEvmTransaction",
|
|
107
|
+
* criteria: [
|
|
108
|
+
* {
|
|
109
|
+
* type: "ethValue",
|
|
110
|
+
* ethValue: "1000000000000000000",
|
|
111
|
+
* operator: ">",
|
|
112
|
+
* },
|
|
113
|
+
* ],
|
|
114
|
+
* },
|
|
115
|
+
* ],
|
|
116
|
+
* },
|
|
117
|
+
* idempotencyKey
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Second call with same key returns the same policy
|
|
121
|
+
* const samePolicy = await cdp.policies.createPolicy({
|
|
122
|
+
* policy: { ... },
|
|
123
|
+
* idempotencyKey
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
async createPolicy(options: CreatePolicyOptions): Promise<Policy> {
|
|
128
|
+
CreatePolicyBodySchema.parse(options.policy);
|
|
129
|
+
return CdpOpenApiClient.createPolicy(options.policy, options.idempotencyKey) as Promise<Policy>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves a policy by its unique identifier.
|
|
134
|
+
*
|
|
135
|
+
* @param {GetPolicyByIdOptions} options - Options containing the policy ID to retrieve
|
|
136
|
+
* @param {string} options.id - The unique identifier of the policy to retrieve
|
|
137
|
+
*
|
|
138
|
+
* @returns {Promise<Policy>} The requested policy
|
|
139
|
+
*
|
|
140
|
+
* @example **Retrieving a policy by ID**
|
|
141
|
+
* ```ts
|
|
142
|
+
* const policy = await cdp.policies.getPolicyById({
|
|
143
|
+
* id: "__ID__"
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* console.log(policy.name);
|
|
147
|
+
* console.log(policy.rules);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async getPolicyById(options: GetPolicyByIdOptions): Promise<Policy> {
|
|
151
|
+
return CdpOpenApiClient.getPolicyById(options.id) as Promise<Policy>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Deletes a policy by its unique identifier.
|
|
156
|
+
* If a policy is referenced by an active project or account, this operation will fail.
|
|
157
|
+
*
|
|
158
|
+
* @param {DeletePolicyOptions} options - Options containing the policy ID to delete
|
|
159
|
+
* @param {string} options.id - The unique identifier of the policy to delete
|
|
160
|
+
* @param {string} [options.idempotencyKey] - An idempotency key to prevent duplicate deletion
|
|
161
|
+
*
|
|
162
|
+
* @returns {Promise<void>} Void on successful deletion
|
|
163
|
+
*
|
|
164
|
+
* @example **Deleting a policy**
|
|
165
|
+
* ```ts
|
|
166
|
+
* await cdp.policies.deletePolicy({
|
|
167
|
+
* id: "__ID__"
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example **With idempotency key**
|
|
172
|
+
* ```ts
|
|
173
|
+
* const idempotencyKey = uuidv4();
|
|
174
|
+
*
|
|
175
|
+
* // This operation is idempotent with the key
|
|
176
|
+
* await cdp.policies.deletePolicy({
|
|
177
|
+
* id: "__ID__",
|
|
178
|
+
* idempotencyKey
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
async deletePolicy(options: DeletePolicyOptions): Promise<void> {
|
|
183
|
+
return CdpOpenApiClient.deletePolicy(options.id, options.idempotencyKey);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Updates an existing policy by its unique identifier.
|
|
188
|
+
* This will apply the updated policy to any project or accounts that are currently using it.
|
|
189
|
+
*
|
|
190
|
+
* @param {UpdatePolicyOptions} options - Options containing the policy ID and updated policy data
|
|
191
|
+
* @param {string} options.id - The unique identifier of the policy to update
|
|
192
|
+
* @param {UpdatePolicyBody} options.policy - The updated policy configuration
|
|
193
|
+
* @param {string} [options.policy.description] - Updated description of the policy's purpose
|
|
194
|
+
* @param {Rule[]} [options.policy.rules] - Updated rules that define the policy behavior
|
|
195
|
+
* @param {string} [options.idempotencyKey] - An idempotency key to prevent duplicate updates
|
|
196
|
+
*
|
|
197
|
+
* @returns {Promise<Policy>} The updated policy
|
|
198
|
+
* @throws {ZodError<typeof UpdatePolicyBodySchema>} When the updated policy is invalid
|
|
199
|
+
*
|
|
200
|
+
* @example **Updating a policy**
|
|
201
|
+
* ```ts
|
|
202
|
+
* const updatedPolicy = await cdp.policies.updatePolicy({
|
|
203
|
+
* id: "__ID__",
|
|
204
|
+
* policy: {
|
|
205
|
+
* description: "Now with lower transaction limits",
|
|
206
|
+
* rules: [
|
|
207
|
+
* {
|
|
208
|
+
* action: "reject",
|
|
209
|
+
* operation: "signEvmTransaction",
|
|
210
|
+
* criteria: [
|
|
211
|
+
* {
|
|
212
|
+
* type: "ethValue",
|
|
213
|
+
* ethValue: "1000000000",
|
|
214
|
+
* operator: ">",
|
|
215
|
+
* },
|
|
216
|
+
* ],
|
|
217
|
+
* },
|
|
218
|
+
* ],
|
|
219
|
+
* },
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example **With idempotency key**
|
|
224
|
+
* ```ts
|
|
225
|
+
* const idempotencyKey = uuidv4();
|
|
226
|
+
*
|
|
227
|
+
* // This operation is idempotent with the key
|
|
228
|
+
* await cdp.policies.updatePolicy({
|
|
229
|
+
* id: "__ID__",
|
|
230
|
+
* policy: {
|
|
231
|
+
* description: "Modified Policy",
|
|
232
|
+
* rules: { ... }
|
|
233
|
+
* },
|
|
234
|
+
* idempotencyKey
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
async updatePolicy(options: UpdatePolicyOptions): Promise<Policy> {
|
|
239
|
+
UpdatePolicyBodySchema.parse(options.policy);
|
|
240
|
+
return CdpOpenApiClient.updatePolicy(
|
|
241
|
+
options.id,
|
|
242
|
+
options.policy,
|
|
243
|
+
options.idempotencyKey,
|
|
244
|
+
) as Promise<Policy>;
|
|
245
|
+
}
|
|
246
|
+
}
|