@coinbase/cdp-sdk 1.7.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 +10 -0
- package/README.md +222 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +1 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- 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 +133 -15
- 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 +76 -19
- 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.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 +1 -1
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- 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 +6 -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/policies/types.js.map +1 -0
- 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/solana/toSolanaAccount.js +1 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- 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 +133 -15
- 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 +76 -19
- 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.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 +1 -1
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- 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 +5 -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/policies/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -3
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +1 -2
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- 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 +33 -3
- 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 +43 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +14 -2
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +81 -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 +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- 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 +18 -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 +6 -3
- package/accounts/evm/types.ts +6 -8
- package/accounts/solana/toSolanaAccount.ts +1 -0
- package/actions/evm/transfer/types.ts +1 -1
- package/analytics.ts +84 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +159 -17
- package/client/evm/evm.types.ts +38 -1
- 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 +94 -20
- package/client/solana/solana.types.ts +16 -1
- package/index.ts +7 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +86 -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 +1 -1
- 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 +6 -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/client/evm/evm.types.ts
CHANGED
|
@@ -21,9 +21,10 @@ 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
|
|
|
@@ -187,6 +194,18 @@ export interface ReadonlySmartAccount
|
|
|
187
194
|
owners: Address[];
|
|
188
195
|
}
|
|
189
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
|
+
|
|
190
209
|
/**
|
|
191
210
|
* The result of listing EVM smart accounts.
|
|
192
211
|
*/
|
|
@@ -259,6 +278,24 @@ export interface SignMessageOptions {
|
|
|
259
278
|
idempotencyKey?: string;
|
|
260
279
|
}
|
|
261
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
|
+
|
|
262
299
|
/**
|
|
263
300
|
* Options for signing an EVM transaction.
|
|
264
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
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { OpenApiPoliciesMethods } from "../../openapi-client/index.js";
|
|
2
|
+
import { CreatePolicyBody, PolicyScope, UpdatePolicyBody } from "../../policies/schema.js";
|
|
3
|
+
import { Policy } from "../../policies/types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The PoliciesClient type, where all OpenApiPoliciesMethods methods are wrapped.
|
|
7
|
+
*/
|
|
8
|
+
export type PoliciesClientInterface = Omit<
|
|
9
|
+
typeof OpenApiPoliciesMethods,
|
|
10
|
+
| "createPolicy" // mapped to createPolicy
|
|
11
|
+
| "listPolicies" // mapped to listPolicies
|
|
12
|
+
| "getPolicyById" // mapped to getPolicyById
|
|
13
|
+
| "deletePolicy" // mapped to deletePolicy
|
|
14
|
+
| "updatePolicy" // mapped to updatePolicy
|
|
15
|
+
> & {
|
|
16
|
+
listPolicies: (options: ListPoliciesOptions) => Promise<ListPoliciesResult>;
|
|
17
|
+
createPolicy: (options: CreatePolicyOptions) => Promise<Policy>;
|
|
18
|
+
getPolicyById: (options: GetPolicyByIdOptions) => Promise<Policy>;
|
|
19
|
+
deletePolicy: (options: DeletePolicyOptions) => Promise<void>;
|
|
20
|
+
updatePolicy: (options: UpdatePolicyOptions) => Promise<Policy>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export interface ListPoliciesOptions {
|
|
24
|
+
/** The page size to paginate through the accounts. */
|
|
25
|
+
pageSize?: number;
|
|
26
|
+
/** The page token to paginate through the accounts. */
|
|
27
|
+
pageToken?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The scope of the policies to return. If `project`, the response will include exactly one policy, which is the project-level policy. If `account`, the response will include all account-level policies for the developer's CDP Project.
|
|
30
|
+
*/
|
|
31
|
+
scope?: PolicyScope;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The result of listing policies.
|
|
36
|
+
*/
|
|
37
|
+
export interface ListPoliciesResult {
|
|
38
|
+
/** The list of policies matching the query parameters. */
|
|
39
|
+
policies: Policy[];
|
|
40
|
+
/**
|
|
41
|
+
* The next page token to paginate through the policies.
|
|
42
|
+
* If undefined, there are no more policies to paginate through.
|
|
43
|
+
*/
|
|
44
|
+
nextPageToken?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Options for creating a Policy.
|
|
49
|
+
*/
|
|
50
|
+
export interface CreatePolicyOptions {
|
|
51
|
+
/**
|
|
52
|
+
* The idempotency key to ensure the request is processed exactly once.
|
|
53
|
+
* Used to safely retry requests without accidentally performing the same operation twice.
|
|
54
|
+
*/
|
|
55
|
+
idempotencyKey?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The policy definition to create.
|
|
58
|
+
* Contains the scope, description, and rules for the policy.
|
|
59
|
+
*/
|
|
60
|
+
policy: CreatePolicyBody;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Options for retrieving a Policy by ID.
|
|
65
|
+
*/
|
|
66
|
+
export interface GetPolicyByIdOptions {
|
|
67
|
+
/**
|
|
68
|
+
* The unique identifier of the policy to retrieve.
|
|
69
|
+
* This is a UUID that's generated when the policy is created.
|
|
70
|
+
*/
|
|
71
|
+
id: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Options for deleting a Policy.
|
|
76
|
+
*/
|
|
77
|
+
export interface DeletePolicyOptions {
|
|
78
|
+
/**
|
|
79
|
+
* The unique identifier of the policy to delete.
|
|
80
|
+
* This is a UUID that's generated when the policy is created.
|
|
81
|
+
*/
|
|
82
|
+
id: string;
|
|
83
|
+
/**
|
|
84
|
+
* The idempotency key to ensure the request is processed exactly once.
|
|
85
|
+
* Used to safely retry requests without accidentally performing the same operation twice.
|
|
86
|
+
*/
|
|
87
|
+
idempotencyKey?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Options for updating a Policy.
|
|
92
|
+
*/
|
|
93
|
+
export interface UpdatePolicyOptions {
|
|
94
|
+
/**
|
|
95
|
+
* The unique identifier of the policy to update.
|
|
96
|
+
* This is a UUID that's generated when the policy is created.
|
|
97
|
+
*/
|
|
98
|
+
id: string;
|
|
99
|
+
/**
|
|
100
|
+
* The updated policy definition.
|
|
101
|
+
* Contains the description and rules for the policy.
|
|
102
|
+
*/
|
|
103
|
+
policy: UpdatePolicyBody;
|
|
104
|
+
/**
|
|
105
|
+
* The idempotency key to ensure the request is processed exactly once.
|
|
106
|
+
* Used to safely retry requests without accidentally performing the same operation twice.
|
|
107
|
+
*/
|
|
108
|
+
idempotencyKey?: string;
|
|
109
|
+
}
|
package/client/solana/solana.ts
CHANGED
|
@@ -9,12 +9,14 @@ import {
|
|
|
9
9
|
SignMessageOptions,
|
|
10
10
|
SignTransactionOptions,
|
|
11
11
|
SolanaClientInterface,
|
|
12
|
+
UpdateSolanaAccountOptions,
|
|
12
13
|
} from "./solana.types.js";
|
|
13
14
|
import { toSolanaAccount } from "../../accounts/solana/toSolanaAccount.js";
|
|
14
15
|
import { SolanaAccount } from "../../accounts/solana/types.js";
|
|
15
16
|
import { requestFaucet } from "../../actions/solana/requestFaucet.js";
|
|
16
17
|
import { signMessage } from "../../actions/solana/signMessage.js";
|
|
17
18
|
import { signTransaction } from "../../actions/solana/signTransaction.js";
|
|
19
|
+
import { Analytics } from "../../analytics.js";
|
|
18
20
|
import { APIError } from "../../openapi-client/errors.js";
|
|
19
21
|
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
20
22
|
|
|
@@ -53,11 +55,18 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
53
55
|
* ```
|
|
54
56
|
*/
|
|
55
57
|
async createAccount(options: CreateAccountOptions = {}): Promise<SolanaAccount> {
|
|
56
|
-
const
|
|
58
|
+
const openApiAccount = await CdpOpenApiClient.createSolanaAccount(
|
|
59
|
+
options,
|
|
60
|
+
options.idempotencyKey,
|
|
61
|
+
);
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
account,
|
|
63
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
64
|
+
account: openApiAccount,
|
|
60
65
|
});
|
|
66
|
+
|
|
67
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
68
|
+
|
|
69
|
+
return account;
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
@@ -86,21 +95,25 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
86
95
|
* ```
|
|
87
96
|
*/
|
|
88
97
|
async getAccount(options: GetAccountOptions): Promise<SolanaAccount> {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
}
|
|
98
|
+
const openApiAccount = await (() => {
|
|
99
|
+
if (options.address) {
|
|
100
|
+
return CdpOpenApiClient.getSolanaAccount(options.address);
|
|
101
|
+
}
|
|
95
102
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
103
|
+
if (options.name) {
|
|
104
|
+
return CdpOpenApiClient.getSolanaAccountByName(options.name);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
throw new Error("Either address or name must be provided");
|
|
108
|
+
})();
|
|
109
|
+
|
|
110
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
111
|
+
account: openApiAccount,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
102
115
|
|
|
103
|
-
|
|
116
|
+
return account;
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
/**
|
|
@@ -179,11 +192,15 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
179
192
|
});
|
|
180
193
|
|
|
181
194
|
return {
|
|
182
|
-
accounts: solAccounts.accounts.map(account =>
|
|
183
|
-
toSolanaAccount(CdpOpenApiClient, {
|
|
195
|
+
accounts: solAccounts.accounts.map(account => {
|
|
196
|
+
const solanaAccount = toSolanaAccount(CdpOpenApiClient, {
|
|
184
197
|
account,
|
|
185
|
-
})
|
|
186
|
-
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
Analytics.wrapObjectMethodsWithErrorTracking(solanaAccount);
|
|
201
|
+
|
|
202
|
+
return solanaAccount;
|
|
203
|
+
}),
|
|
187
204
|
nextPageToken: solAccounts.nextPageToken,
|
|
188
205
|
};
|
|
189
206
|
}
|
|
@@ -272,4 +289,61 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
272
289
|
async signTransaction(options: SignTransactionOptions): Promise<SignatureResult> {
|
|
273
290
|
return signTransaction(CdpOpenApiClient, options);
|
|
274
291
|
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Updates a CDP Solana account.
|
|
295
|
+
*
|
|
296
|
+
* @param {UpdateSolanaAccountOptions} [options] - Optional parameters for creating the account.
|
|
297
|
+
* @param {string} options.address - The address of the account to update
|
|
298
|
+
* @param {UpdateSolanaAccountBody} options.update - An object containing account fields to update.
|
|
299
|
+
* @param {string} [options.update.name] - The new name for the account.
|
|
300
|
+
* @param {string} [options.update.accountPolicy] - The ID of a Policy to apply to the account.
|
|
301
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
302
|
+
*
|
|
303
|
+
* @returns A promise that resolves to the updated account.
|
|
304
|
+
*
|
|
305
|
+
* @example **With a name**
|
|
306
|
+
* ```ts
|
|
307
|
+
* const account = await cdp.sol.updateAccount({ address: "...", update: { name: "New Name" } });
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @example **With an account policy**
|
|
311
|
+
* ```ts
|
|
312
|
+
* const account = await cdp.sol.updateAccount({ address: "...", update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" } });
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @example **With an idempotency key**
|
|
316
|
+
* ```ts
|
|
317
|
+
* const idempotencyKey = uuidv4();
|
|
318
|
+
*
|
|
319
|
+
* // First call
|
|
320
|
+
* await cdp.sol.updateAccount({
|
|
321
|
+
* address: "0x...",
|
|
322
|
+
* update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" },
|
|
323
|
+
* idempotencyKey,
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* // Second call with the same idempotency key will not update
|
|
327
|
+
* await cdp.sol.updateAccount({
|
|
328
|
+
* address: '0x...',
|
|
329
|
+
* update: { name: "" },
|
|
330
|
+
* idempotencyKey,
|
|
331
|
+
* });
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
async updateAccount(options: UpdateSolanaAccountOptions): Promise<SolanaAccount> {
|
|
335
|
+
const openApiAccount = await CdpOpenApiClient.updateSolanaAccount(
|
|
336
|
+
options.address,
|
|
337
|
+
options.update,
|
|
338
|
+
options.idempotencyKey,
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
342
|
+
account: openApiAccount,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
346
|
+
|
|
347
|
+
return account;
|
|
348
|
+
}
|
|
275
349
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account, SolanaAccount } from "../../accounts/solana/types.js";
|
|
2
|
-
import { OpenApiSolanaMethods } from "../../openapi-client/index.js";
|
|
2
|
+
import { OpenApiSolanaMethods, UpdateSolanaAccountBody } from "../../openapi-client/index.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The SolanaClient type, where all OpenApiSolanaMethods methods are wrapped.
|
|
@@ -9,14 +9,17 @@ export type SolanaClientInterface = Omit<
|
|
|
9
9
|
| "createSolanaAccount" // mapped to createAccount
|
|
10
10
|
| "getSolanaAccount" // mapped to getAccount
|
|
11
11
|
| "getSolanaAccountByName" // mapped to getAccount
|
|
12
|
+
| "updateSolanaAccount" // mapped to updateAccount
|
|
12
13
|
| "listSolanaAccounts" // mapped to listAccounts
|
|
13
14
|
| "requestSolanaFaucet" // mapped to requestFaucet
|
|
14
15
|
| "signSolanaMessage" // mapped to signMessage
|
|
15
16
|
| "signSolanaTransaction" // mapped to signTransaction
|
|
17
|
+
| "updateSolanaAccount" // mapped to updateAccount
|
|
16
18
|
> & {
|
|
17
19
|
createAccount: (options: CreateAccountOptions) => Promise<Account>;
|
|
18
20
|
getAccount: (options: GetAccountOptions) => Promise<Account>;
|
|
19
21
|
getOrCreateAccount: (options: GetOrCreateAccountOptions) => Promise<Account>;
|
|
22
|
+
updateAccount: (options: UpdateSolanaAccountOptions) => Promise<Account>;
|
|
20
23
|
listAccounts: (options: ListAccountsOptions) => Promise<ListAccountsResult>;
|
|
21
24
|
requestFaucet: (options: RequestFaucetOptions) => Promise<SignatureResult>;
|
|
22
25
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
@@ -59,6 +62,18 @@ export interface GetOrCreateAccountOptions {
|
|
|
59
62
|
name: string;
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Options for creating a SOL server account.
|
|
67
|
+
*/
|
|
68
|
+
export interface UpdateSolanaAccountOptions {
|
|
69
|
+
/** The address of the account. */
|
|
70
|
+
address: string;
|
|
71
|
+
/** The updates to apply to the account */
|
|
72
|
+
update: UpdateSolanaAccountBody;
|
|
73
|
+
/** The idempotency key. */
|
|
74
|
+
idempotencyKey?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
/**
|
|
63
78
|
* Options for listing Solana accounts.
|
|
64
79
|
*/
|
package/index.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export { CdpClient } from "./client/cdp.js";
|
|
2
2
|
export type { EvmServerAccount, EvmSmartAccount } from "./accounts/evm/types.js";
|
|
3
|
+
export type { Policy } from "./policies/types.js";
|
|
4
|
+
export {
|
|
5
|
+
CreatePolicyBodySchema,
|
|
6
|
+
UpdatePolicyBodySchema,
|
|
7
|
+
type CreatePolicyBody,
|
|
8
|
+
type UpdatePolicyBody,
|
|
9
|
+
} from "./policies/schema.js";
|