@coinbase/cdp-sdk 1.29.0 → 1.30.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/_cjs/accounts/evm/networkCapabilities.js +101 -0
- package/_cjs/accounts/evm/networkCapabilities.js.map +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +11 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +11 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +11 -1
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/getUserOperation.js +1 -0
- package/_cjs/actions/evm/getUserOperation.js.map +1 -1
- package/_cjs/actions/evm/spend-permissions/account.use.js +33 -0
- package/_cjs/actions/evm/spend-permissions/account.use.js.map +1 -0
- package/_cjs/actions/evm/spend-permissions/smartAccount.use.js +35 -0
- package/_cjs/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
- package/_cjs/actions/evm/spend-permissions/types.js +3 -0
- package/_cjs/actions/evm/spend-permissions/types.js.map +1 -0
- package/_cjs/actions/solana/sendTransaction.js +1 -0
- package/_cjs/actions/solana/sendTransaction.js.map +1 -1
- package/_cjs/actions/solana/signTransaction.js +1 -0
- package/_cjs/actions/solana/signTransaction.js.map +1 -1
- package/_cjs/auth/hooks/axios/withAuth.js +3 -0
- package/_cjs/auth/hooks/axios/withAuth.js.map +1 -1
- package/_cjs/auth/utils/http.js +2 -1
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/client/evm/evm.js +51 -1
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +5 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +41 -3
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +14 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +72 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +2 -0
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js +30 -0
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -0
- package/_cjs/openapi-client/generated/onramp/onramp.msw.js +98 -0
- package/_cjs/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js +15 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js +69 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js.map +1 -0
- package/_cjs/openapi-client/index.js +2 -0
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/spend-permissions/constants.js +716 -0
- package/_cjs/spend-permissions/constants.js.map +1 -0
- package/_cjs/spend-permissions/types.js +3 -0
- package/_cjs/spend-permissions/types.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/networkCapabilities.js +101 -0
- package/_esm/accounts/evm/networkCapabilities.js.map +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +11 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +11 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +11 -1
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/getUserOperation.js +1 -0
- package/_esm/actions/evm/getUserOperation.js.map +1 -1
- package/_esm/actions/evm/spend-permissions/account.use.js +30 -0
- package/_esm/actions/evm/spend-permissions/account.use.js.map +1 -0
- package/_esm/actions/evm/spend-permissions/smartAccount.use.js +32 -0
- package/_esm/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
- package/_esm/actions/evm/spend-permissions/types.js +2 -0
- package/_esm/actions/evm/spend-permissions/types.js.map +1 -0
- package/_esm/actions/solana/sendTransaction.js +1 -0
- package/_esm/actions/solana/sendTransaction.js.map +1 -1
- package/_esm/actions/solana/signTransaction.js +1 -0
- package/_esm/actions/solana/signTransaction.js.map +1 -1
- package/_esm/auth/hooks/axios/withAuth.js +3 -0
- package/_esm/auth/hooks/axios/withAuth.js.map +1 -1
- package/_esm/auth/utils/http.js +2 -1
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/client/evm/evm.js +51 -1
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/solana/solana.js +2 -2
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +2 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +39 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +12 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +69 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +2 -0
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js +25 -0
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -0
- package/_esm/openapi-client/generated/onramp/onramp.msw.js +90 -0
- package/_esm/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js +11 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js +63 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js.map +1 -0
- package/_esm/openapi-client/index.js +2 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/spend-permissions/constants.js +713 -0
- package/_esm/spend-permissions/constants.js.map +1 -0
- package/_esm/spend-permissions/types.js +2 -0
- package/_esm/spend-permissions/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/networkCapabilities.d.ts +101 -0
- package/_types/accounts/evm/networkCapabilities.d.ts.map +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/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -0
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/getUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/spend-permissions/account.use.d.ts +15 -0
- package/_types/actions/evm/spend-permissions/account.use.d.ts.map +1 -0
- package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts +15 -0
- package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts.map +1 -0
- package/_types/actions/evm/spend-permissions/types.d.ts +13 -0
- package/_types/actions/evm/spend-permissions/types.d.ts.map +1 -0
- package/_types/actions/evm/types.d.ts +75 -0
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/sendTransaction.d.ts +8 -2
- package/_types/actions/solana/sendTransaction.d.ts.map +1 -1
- package/_types/actions/solana/signTransaction.d.ts +8 -2
- package/_types/actions/solana/signTransaction.d.ts.map +1 -1
- package/_types/actions/solana/types.d.ts +38 -3
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +19 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +29 -2
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +5 -3
- package/_types/client/solana/solana.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 +333 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +2 -0
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +28 -0
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -0
- package/_types/openapi-client/generated/onramp/onramp.msw.d.ts +8 -0
- package/_types/openapi-client/generated/onramp/onramp.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts +20 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts.map +1 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.msw.d.ts +6 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.msw.d.ts.map +1 -0
- package/_types/openapi-client/index.d.ts +4 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/spend-permissions/constants.d.ts +1357 -0
- package/_types/spend-permissions/constants.d.ts.map +1 -0
- package/_types/spend-permissions/types.d.ts +30 -0
- package/_types/spend-permissions/types.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/networkCapabilities.ts +101 -0
- package/accounts/evm/toEvmServerAccount.ts +15 -0
- package/accounts/evm/toEvmSmartAccount.ts +19 -4
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +15 -0
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +15 -0
- package/accounts/evm/types.ts +18 -0
- package/accounts/solana/toSolanaAccount.ts +17 -3
- package/actions/evm/getUserOperation.ts +1 -0
- package/actions/evm/spend-permissions/account.use.ts +48 -0
- package/actions/evm/spend-permissions/smartAccount.use.ts +49 -0
- package/actions/evm/spend-permissions/types.ts +13 -0
- package/actions/evm/types.ts +81 -0
- package/actions/solana/sendTransaction.ts +10 -2
- package/actions/solana/signTransaction.ts +10 -2
- package/actions/solana/types.ts +44 -2
- package/auth/hooks/axios/withAuth.ts +3 -0
- package/auth/utils/http.ts +2 -1
- package/client/evm/evm.ts +61 -1
- package/client/evm/evm.types.ts +31 -0
- package/client/solana/solana.ts +10 -5
- package/index.ts +6 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +375 -1
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +85 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +23 -0
- package/openapi-client/generated/index.msw.ts +2 -0
- package/openapi-client/generated/onramp/onramp.msw.ts +135 -0
- package/openapi-client/generated/onramp/onramp.ts +54 -0
- package/openapi-client/generated/x402-facilitator/x402-facilitator.msw.ts +85 -0
- package/openapi-client/generated/x402-facilitator/x402-facilitator.ts +34 -0
- package/openapi-client/index.ts +2 -0
- package/package.json +1 -1
- package/spend-permissions/constants.ts +713 -0
- package/spend-permissions/types.ts +42 -0
- package/version.ts +1 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { SendTransactionOptions
|
|
1
|
+
import { SendTransactionOptions } from "../../client/solana/solana.types.js";
|
|
2
2
|
import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
3
3
|
|
|
4
|
+
export interface SendTransactionResult {
|
|
5
|
+
/** The signature of the transaction base58 encoded. */
|
|
6
|
+
transactionSignature: string;
|
|
7
|
+
/** @deprecated Use transactionSignature instead. */
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* Sends a Solana transaction using the Coinbase API.
|
|
6
13
|
*
|
|
@@ -23,7 +30,7 @@ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
|
23
30
|
export async function sendTransaction(
|
|
24
31
|
apiClient: CdpOpenApiClientType,
|
|
25
32
|
options: SendTransactionOptions,
|
|
26
|
-
): Promise<
|
|
33
|
+
): Promise<SendTransactionResult> {
|
|
27
34
|
const signature = await apiClient.sendSolanaTransaction(
|
|
28
35
|
{
|
|
29
36
|
network: options.network,
|
|
@@ -33,6 +40,7 @@ export async function sendTransaction(
|
|
|
33
40
|
);
|
|
34
41
|
|
|
35
42
|
return {
|
|
43
|
+
transactionSignature: signature.transactionSignature,
|
|
36
44
|
signature: signature.transactionSignature,
|
|
37
45
|
};
|
|
38
46
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { SignTransactionOptions
|
|
1
|
+
import { SignTransactionOptions } from "../../client/solana/solana.types.js";
|
|
2
2
|
import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
3
3
|
|
|
4
|
+
export interface SignTransactionResult {
|
|
5
|
+
/** The signature of the transaction base58 encoded. */
|
|
6
|
+
signedTransaction: string;
|
|
7
|
+
/** @deprecated Use signedTransaction instead. */
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* Signs a transaction.
|
|
6
13
|
*
|
|
@@ -38,7 +45,7 @@ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
|
38
45
|
export async function signTransaction(
|
|
39
46
|
apiClient: CdpOpenApiClientType,
|
|
40
47
|
options: SignTransactionOptions,
|
|
41
|
-
): Promise<
|
|
48
|
+
): Promise<SignTransactionResult> {
|
|
42
49
|
const signature = await apiClient.signSolanaTransaction(
|
|
43
50
|
options.address,
|
|
44
51
|
{
|
|
@@ -48,6 +55,7 @@ export async function signTransaction(
|
|
|
48
55
|
);
|
|
49
56
|
|
|
50
57
|
return {
|
|
58
|
+
signedTransaction: signature.signedTransaction,
|
|
51
59
|
signature: signature.signedTransaction,
|
|
52
60
|
};
|
|
53
61
|
}
|
package/actions/solana/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TransferOptions } from "./transfer.js";
|
|
2
2
|
import {
|
|
3
3
|
RequestFaucetOptions,
|
|
4
|
+
SendTransactionOptions,
|
|
4
5
|
SignatureResult,
|
|
5
6
|
SignMessageOptions,
|
|
6
7
|
SignTransactionOptions,
|
|
@@ -13,6 +14,9 @@ import {
|
|
|
13
14
|
} from "../waitForFundOperationReceipt.js";
|
|
14
15
|
import { SolanaFundOptions } from "./fund/fund.js";
|
|
15
16
|
import { SolanaQuoteFundOptions } from "./fund/quoteFund.js";
|
|
17
|
+
import { SendTransactionResult } from "./sendTransaction.js";
|
|
18
|
+
|
|
19
|
+
import type { SignTransactionResult } from "./signTransaction.js";
|
|
16
20
|
|
|
17
21
|
export type AccountActions = {
|
|
18
22
|
/**
|
|
@@ -87,12 +91,50 @@ export type AccountActions = {
|
|
|
87
91
|
* const transaction = Buffer.from(serializedTransaction).toString("base64");
|
|
88
92
|
*
|
|
89
93
|
* // When you want to sign a transaction, you can do so by address and base64 encoded transaction
|
|
90
|
-
* const {
|
|
94
|
+
* const { signedTransaction } = await account.signTransaction({
|
|
95
|
+
* transaction,
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
signTransaction: (
|
|
100
|
+
options: Omit<SignTransactionOptions, "address">,
|
|
101
|
+
) => Promise<SignTransactionResult>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Sends a transaction.
|
|
105
|
+
*
|
|
106
|
+
* @param {SendTransactionOptions} options - Parameters for sending the transaction.
|
|
107
|
+
* @param {string} options.address - The address to send the transaction for.
|
|
108
|
+
* @param {string} options.transaction - The transaction to send.
|
|
109
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
110
|
+
*
|
|
111
|
+
* @returns A promise that resolves to the transaction signature.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* // Create a Solana account
|
|
116
|
+
* const account = await cdp.solana.createAccount();
|
|
117
|
+
*
|
|
118
|
+
* // Add your transaction instructions here
|
|
119
|
+
* const transaction = new Transaction()
|
|
120
|
+
*
|
|
121
|
+
* // Make sure to set requireAllSignatures to false, since signing will be done through the API
|
|
122
|
+
* const serializedTransaction = transaction.serialize({
|
|
123
|
+
* requireAllSignatures: false,
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* // Base64 encode the serialized transaction
|
|
127
|
+
* const transaction = Buffer.from(serializedTransaction).toString("base64");
|
|
128
|
+
*
|
|
129
|
+
* // When you want to sign a transaction, you can do so by address and base64 encoded transaction
|
|
130
|
+
* const { transactionSignature } = await account.sendTransaction({
|
|
91
131
|
* transaction,
|
|
92
132
|
* });
|
|
93
133
|
* ```
|
|
94
134
|
*/
|
|
95
|
-
|
|
135
|
+
sendTransaction: (
|
|
136
|
+
options: Omit<SendTransactionOptions, "address">,
|
|
137
|
+
) => Promise<SendTransactionResult>;
|
|
96
138
|
|
|
97
139
|
/**
|
|
98
140
|
* Transfers SOL or SPL tokens between accounts
|
|
@@ -84,6 +84,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
if (options.debug) {
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
87
88
|
console.log("Request:", {
|
|
88
89
|
method,
|
|
89
90
|
url: fullyQualifiedURL,
|
|
@@ -98,6 +99,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
|
|
|
98
99
|
if (options.debug) {
|
|
99
100
|
axiosClient.interceptors.response.use(
|
|
100
101
|
response => {
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
101
103
|
console.log("Response:", {
|
|
102
104
|
status: response.status,
|
|
103
105
|
statusText: response.statusText,
|
|
@@ -117,6 +119,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
|
|
|
117
119
|
cause: error.cause,
|
|
118
120
|
};
|
|
119
121
|
|
|
122
|
+
// eslint-disable-next-line no-console
|
|
120
123
|
console.error("Response Error:", errorDetails);
|
|
121
124
|
return Promise.reject(error);
|
|
122
125
|
},
|
package/auth/utils/http.ts
CHANGED
|
@@ -126,7 +126,8 @@ export async function getAuthHeaders(
|
|
|
126
126
|
*/
|
|
127
127
|
function requiresWalletAuth(requestMethod: string, requestPath: string): boolean {
|
|
128
128
|
return (
|
|
129
|
-
requestPath?.includes("/accounts")
|
|
129
|
+
(requestPath?.includes("/accounts") || requestPath?.includes("/spend-permissions")) &&
|
|
130
|
+
(requestMethod === "POST" || requestMethod === "DELETE" || requestMethod === "PUT")
|
|
130
131
|
);
|
|
131
132
|
}
|
|
132
133
|
|
package/client/evm/evm.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type Address, getTypesForEIP712Domain } from "viem";
|
|
|
5
5
|
import {
|
|
6
6
|
CreateServerAccountOptions,
|
|
7
7
|
CreateSmartAccountOptions,
|
|
8
|
+
CreateSpendPermissionOptions,
|
|
8
9
|
CreateSwapQuoteOptions,
|
|
9
10
|
CreateSwapQuoteResult,
|
|
10
11
|
EvmClientInterface,
|
|
@@ -68,6 +69,7 @@ import {
|
|
|
68
69
|
CdpOpenApiClient,
|
|
69
70
|
EIP712Message as OpenAPIEIP712Message,
|
|
70
71
|
} from "../../openapi-client/index.js";
|
|
72
|
+
import { SPEND_PERMISSION_MANAGER_ADDRESS } from "../../spend-permissions/constants.js";
|
|
71
73
|
import { Hex } from "../../types/misc.js";
|
|
72
74
|
import { decryptWithPrivateKey, generateExportEncryptionKeyPair } from "../../utils/export.js";
|
|
73
75
|
|
|
@@ -341,9 +343,15 @@ export class EvmClient implements EvmClientInterface {
|
|
|
341
343
|
accountType: "evm_smart",
|
|
342
344
|
});
|
|
343
345
|
|
|
346
|
+
const owners = [options.owner.address];
|
|
347
|
+
|
|
348
|
+
if (options.__experimental_enableSpendPermission) {
|
|
349
|
+
owners.push(SPEND_PERMISSION_MANAGER_ADDRESS);
|
|
350
|
+
}
|
|
351
|
+
|
|
344
352
|
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
345
353
|
{
|
|
346
|
-
owners:
|
|
354
|
+
owners: owners,
|
|
347
355
|
name: options.name,
|
|
348
356
|
},
|
|
349
357
|
options.idempotencyKey,
|
|
@@ -359,6 +367,58 @@ export class EvmClient implements EvmClientInterface {
|
|
|
359
367
|
return smartAccount;
|
|
360
368
|
}
|
|
361
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Creates a spend permission for a smart account.
|
|
372
|
+
*
|
|
373
|
+
* @param {CreateSpendPermissionOptions} options - Parameters for creating the spend permission.
|
|
374
|
+
* @param {SpendPermission} options.spendPermission - The spend permission to create.
|
|
375
|
+
* @param {string} [options.idempotencyKey] - The idempotency key to use for the spend permission.
|
|
376
|
+
*
|
|
377
|
+
* @returns A promise that resolves to the spend permission.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```ts
|
|
381
|
+
* const userOperation = await cdp.evm.createSpendPermission({
|
|
382
|
+
* spendPermission,
|
|
383
|
+
* network: "base-sepolia",
|
|
384
|
+
* });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
async createSpendPermission(options: CreateSpendPermissionOptions): Promise<UserOperation> {
|
|
388
|
+
Analytics.trackAction({
|
|
389
|
+
action: "create_spend_permission",
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const userOperation = await CdpOpenApiClient.createSpendPermission(
|
|
393
|
+
options.spendPermission.account,
|
|
394
|
+
{
|
|
395
|
+
account: options.spendPermission.account,
|
|
396
|
+
spender: options.spendPermission.spender,
|
|
397
|
+
token: options.spendPermission.token,
|
|
398
|
+
allowance: options.spendPermission.allowance.toString(),
|
|
399
|
+
period: options.spendPermission.period.toString(),
|
|
400
|
+
start: options.spendPermission.start.toString(),
|
|
401
|
+
end: options.spendPermission.end.toString(),
|
|
402
|
+
salt: options.spendPermission.salt.toString(),
|
|
403
|
+
extraData: options.spendPermission.extraData,
|
|
404
|
+
network: options.network,
|
|
405
|
+
paymasterUrl: options.paymasterUrl,
|
|
406
|
+
},
|
|
407
|
+
options.idempotencyKey,
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
network: userOperation.network,
|
|
412
|
+
userOpHash: userOperation.userOpHash as Hex,
|
|
413
|
+
status: userOperation.status,
|
|
414
|
+
calls: userOperation.calls.map(call => ({
|
|
415
|
+
to: call.to as Address,
|
|
416
|
+
value: BigInt(call.value),
|
|
417
|
+
data: call.data as Hex,
|
|
418
|
+
})),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
362
422
|
/**
|
|
363
423
|
* Gets a CDP EVM account.
|
|
364
424
|
*
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SpendPermission } from "../../spend-permissions/types.js";
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
EvmAccount as Account,
|
|
3
5
|
EvmServerAccount as ServerAccount,
|
|
@@ -24,6 +26,7 @@ import type {
|
|
|
24
26
|
OpenApiEvmMethods,
|
|
25
27
|
UpdateEvmAccountBody as UpdateEvmAccount,
|
|
26
28
|
UpdateEvmSmartAccountBody as UpdateEvmSmartAccount,
|
|
29
|
+
UserOperationReceipt,
|
|
27
30
|
} from "../../openapi-client/index.js";
|
|
28
31
|
import type { Calls } from "../../types/calls.js";
|
|
29
32
|
import type { Address, EIP712Message, Hex } from "../../types/misc.js";
|
|
@@ -36,6 +39,7 @@ export type EvmClientInterface = Omit<
|
|
|
36
39
|
typeof OpenApiEvmMethods,
|
|
37
40
|
| "createEvmAccount" // mapped to createAccount
|
|
38
41
|
| "createEvmSmartAccount" // mapped to createSmartAccount
|
|
42
|
+
| "createSpendPermission" // mapped to createSpendPermission
|
|
39
43
|
| "importEvmAccount" // mapped to importAccount
|
|
40
44
|
| "exportEvmAccount" // mapped to exportAccount
|
|
41
45
|
| "exportEvmAccountByName" // mapped to exportAccount
|
|
@@ -256,6 +260,17 @@ export interface CreateSwapQuoteResult {
|
|
|
256
260
|
execute: (options?: ExecuteSwapQuoteOptions) => Promise<ExecuteSwapQuoteResult>;
|
|
257
261
|
}
|
|
258
262
|
|
|
263
|
+
export interface CreateSpendPermissionOptions {
|
|
264
|
+
/** The spend permission. */
|
|
265
|
+
spendPermission: SpendPermission;
|
|
266
|
+
/** The network. */
|
|
267
|
+
network: EvmUserOperationNetwork;
|
|
268
|
+
/** The paymaster URL. */
|
|
269
|
+
paymasterUrl?: string;
|
|
270
|
+
/** The idempotency key. */
|
|
271
|
+
idempotencyKey?: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
259
274
|
/**
|
|
260
275
|
* Options for getting a user operation.
|
|
261
276
|
*/
|
|
@@ -314,6 +329,10 @@ export interface UserOperation {
|
|
|
314
329
|
* The hash of the transaction that included this particular user operation. This gets set after the user operation is broadcasted and the transaction is included in a block.
|
|
315
330
|
*/
|
|
316
331
|
transactionHash?: Hex;
|
|
332
|
+
/**
|
|
333
|
+
* The receipts associated with the broadcasted user operation.
|
|
334
|
+
*/
|
|
335
|
+
receipts?: UserOperationReceipt[];
|
|
317
336
|
}
|
|
318
337
|
|
|
319
338
|
/**
|
|
@@ -392,6 +411,12 @@ export interface GetOrCreateSmartAccountOptions {
|
|
|
392
411
|
name: string;
|
|
393
412
|
/** The owner of the account. */
|
|
394
413
|
owner: Account;
|
|
414
|
+
/**
|
|
415
|
+
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
416
|
+
*
|
|
417
|
+
* The flag to enable spend permission.
|
|
418
|
+
*/
|
|
419
|
+
__experimental_enableSpendPermission?: boolean;
|
|
395
420
|
}
|
|
396
421
|
|
|
397
422
|
/**
|
|
@@ -487,6 +512,12 @@ export interface CreateSmartAccountOptions {
|
|
|
487
512
|
idempotencyKey?: string;
|
|
488
513
|
/** The name of the account. */
|
|
489
514
|
name?: string;
|
|
515
|
+
/**
|
|
516
|
+
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
517
|
+
*
|
|
518
|
+
* The flag to enable spend permission.
|
|
519
|
+
*/
|
|
520
|
+
__experimental_enableSpendPermission?: boolean;
|
|
490
521
|
}
|
|
491
522
|
|
|
492
523
|
/**
|
package/client/solana/solana.ts
CHANGED
|
@@ -18,15 +18,20 @@ import {
|
|
|
18
18
|
SignMessageOptions,
|
|
19
19
|
SignTransactionOptions,
|
|
20
20
|
SolanaClientInterface,
|
|
21
|
-
TransactionResult,
|
|
22
21
|
UpdateSolanaAccountOptions,
|
|
23
22
|
} from "./solana.types.js";
|
|
24
23
|
import { toSolanaAccount } from "../../accounts/solana/toSolanaAccount.js";
|
|
25
24
|
import { SolanaAccount } from "../../accounts/solana/types.js";
|
|
26
25
|
import { requestFaucet } from "../../actions/solana/requestFaucet.js";
|
|
27
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
sendTransaction,
|
|
28
|
+
type SendTransactionResult,
|
|
29
|
+
} from "../../actions/solana/sendTransaction.js";
|
|
28
30
|
import { signMessage } from "../../actions/solana/signMessage.js";
|
|
29
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
signTransaction,
|
|
33
|
+
type SignTransactionResult,
|
|
34
|
+
} from "../../actions/solana/signTransaction.js";
|
|
30
35
|
import { Analytics } from "../../analytics.js";
|
|
31
36
|
import { ImportAccountPublicRSAKey } from "../../constants.js";
|
|
32
37
|
import { UserInputValidationError } from "../../errors.js";
|
|
@@ -485,7 +490,7 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
485
490
|
* });
|
|
486
491
|
* ```
|
|
487
492
|
*/
|
|
488
|
-
async signTransaction(options: SignTransactionOptions): Promise<
|
|
493
|
+
async signTransaction(options: SignTransactionOptions): Promise<SignTransactionResult> {
|
|
489
494
|
Analytics.trackAction({
|
|
490
495
|
action: "sign_transaction",
|
|
491
496
|
accountType: "solana",
|
|
@@ -574,7 +579,7 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
574
579
|
* });
|
|
575
580
|
* ```
|
|
576
581
|
*/
|
|
577
|
-
async sendTransaction(options: SendTransactionOptions): Promise<
|
|
582
|
+
async sendTransaction(options: SendTransactionOptions): Promise<SendTransactionResult> {
|
|
578
583
|
Analytics.trackAction({
|
|
579
584
|
action: "send_transaction",
|
|
580
585
|
accountType: "solana",
|
package/index.ts
CHANGED
|
@@ -8,5 +8,10 @@ export {
|
|
|
8
8
|
type UpdatePolicyBody,
|
|
9
9
|
} from "./policies/schema.js";
|
|
10
10
|
export { NetworkError } from "./openapi-client/errors.js";
|
|
11
|
+
export type { SpendPermission } from "./spend-permissions/types.js";
|
|
12
|
+
export {
|
|
13
|
+
SPEND_PERMISSION_MANAGER_ABI as spendPermissionManagerAbi,
|
|
14
|
+
SPEND_PERMISSION_MANAGER_ADDRESS as spendPermissionManagerAddress,
|
|
15
|
+
} from "./spend-permissions/constants.js";
|
|
11
16
|
|
|
12
|
-
export { parseEther } from "viem";
|
|
17
|
+
export { parseEther, parseUnits } from "viem";
|