@coinbase/cdp-sdk 1.45.0 → 1.46.1
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 +20 -2
- package/README.md +47 -43
- package/_cjs/accounts/evm/eip6492.js +49 -0
- package/_cjs/accounts/evm/eip6492.js.map +1 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js +6 -2
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +31 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/solana/transfer.js.map +1 -1
- package/_cjs/actions/solana/utils.js +9 -9
- package/_cjs/actions/solana/utils.js.map +1 -1
- package/_cjs/auth/utils/http.js +1 -0
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/client/cdp.js +4 -1
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/end-user/endUser.js +385 -4
- package/_cjs/client/end-user/endUser.js.map +1 -1
- package/_cjs/client/end-user/toEndUserAccount.js +201 -23
- package/_cjs/client/end-user/toEndUserAccount.js.map +1 -1
- package/_cjs/client/solana/solana.js +39 -13
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +32 -0
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +52 -15
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js +261 -0
- package/_cjs/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +1 -0
- package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_cjs/openapi-client/generated/faucets/faucets.js +6 -5
- package/_cjs/openapi-client/generated/faucets/faucets.js.map +1 -1
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-token-balances/solana-token-balances.js.map +1 -1
- package/_cjs/openapi-client/generated/sql-api/sql-api.js +75 -0
- package/_cjs/openapi-client/generated/sql-api/sql-api.js.map +1 -0
- package/_cjs/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -1
- package/_cjs/openapi-client/index.js +4 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/utils/export.js +6 -5
- package/_cjs/utils/export.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/eip6492.js +46 -0
- package/_esm/accounts/evm/eip6492.js.map +1 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js +6 -2
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +31 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/actions/solana/transfer.js.map +1 -1
- package/_esm/actions/solana/utils.js +9 -9
- package/_esm/actions/solana/utils.js.map +1 -1
- package/_esm/auth/utils/http.js +1 -0
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/client/cdp.js +4 -1
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/end-user/endUser.js +385 -4
- package/_esm/client/end-user/endUser.js.map +1 -1
- package/_esm/client/end-user/toEndUserAccount.js +201 -23
- package/_esm/client/end-user/toEndUserAccount.js.map +1 -1
- package/_esm/client/solana/solana.js +39 -13
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/cdpApiClient.js +32 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +49 -12
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js +243 -0
- package/_esm/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +1 -0
- package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -1
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_esm/openapi-client/generated/faucets/faucets.js +6 -5
- package/_esm/openapi-client/generated/faucets/faucets.js.map +1 -1
- package/_esm/openapi-client/generated/onchain-data/onchain-data.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-token-balances/solana-token-balances.js.map +1 -1
- package/_esm/openapi-client/generated/sql-api/sql-api.js +70 -0
- package/_esm/openapi-client/generated/sql-api/sql-api.js.map +1 -0
- package/_esm/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -1
- package/_esm/openapi-client/index.js +4 -1
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/utils/export.js +6 -5
- package/_esm/utils/export.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/eip6492.d.ts +17 -0
- package/_types/accounts/evm/eip6492.d.ts.map +1 -0
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts +4 -4
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +3 -2
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/transfer.d.ts +3 -4
- package/_types/actions/solana/transfer.d.ts.map +1 -1
- package/_types/actions/solana/types.d.ts +79 -29
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +10 -9
- package/_types/actions/solana/utils.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +4 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/end-user/endUser.d.ts +272 -1
- package/_types/client/end-user/endUser.d.ts.map +1 -1
- package/_types/client/end-user/endUser.types.d.ts +491 -1
- package/_types/client/end-user/endUser.types.d.ts.map +1 -1
- package/_types/client/end-user/toEndUserAccount.d.ts +4 -1
- package/_types/client/end-user/toEndUserAccount.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +38 -12
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +487 -119
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts +163 -0
- package/_types/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts.map +1 -0
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts +9 -9
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +16 -16
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +14 -14
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts +3 -3
- package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts +2 -2
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts.map +1 -1
- package/_types/openapi-client/generated/faucets/faucets.d.ts +9 -8
- package/_types/openapi-client/generated/faucets/faucets.d.ts.map +1 -1
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts +3 -3
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +5 -5
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +6 -6
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +12 -12
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-token-balances/solana-token-balances.d.ts +2 -2
- package/_types/openapi-client/generated/solana-token-balances/solana-token-balances.d.ts.map +1 -1
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts +73 -0
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts.map +1 -0
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts +6 -6
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts.map +1 -1
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts +4 -4
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +19 -3
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +26 -78
- package/_types/policies/evmSchema.d.ts.map +1 -1
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/types/contract.d.ts.map +1 -1
- package/_types/utils/export.d.ts +1 -1
- package/_types/utils/export.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/eip6492.ts +60 -0
- package/accounts/evm/toEvmSmartAccount.ts +17 -4
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +44 -5
- package/accounts/evm/types.ts +8 -3
- package/actions/solana/transfer.ts +3 -3
- package/actions/solana/types.ts +79 -29
- package/actions/solana/utils.ts +13 -11
- package/auth/utils/http.ts +1 -0
- package/client/cdp.ts +6 -1
- package/client/end-user/endUser.ts +513 -4
- package/client/end-user/endUser.types.ts +598 -0
- package/client/end-user/toEndUserAccount.ts +330 -26
- package/client/evm/evm.types.ts +4 -2
- package/client/solana/solana.ts +39 -13
- package/index.ts +31 -1
- package/openapi-client/cdpApiClient.ts +34 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +566 -152
- package/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.ts +455 -0
- package/openapi-client/generated/end-user-accounts/end-user-accounts.ts +12 -9
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +19 -16
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +16 -16
- package/openapi-client/generated/evm-swaps/evm-swaps.ts +3 -3
- package/openapi-client/generated/evm-token-balances/evm-token-balances.ts +2 -2
- package/openapi-client/generated/faucets/faucets.ts +9 -8
- package/openapi-client/generated/onchain-data/onchain-data.ts +3 -3
- package/openapi-client/generated/onramp/onramp.ts +5 -5
- package/openapi-client/generated/policy-engine/policy-engine.ts +12 -6
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +12 -12
- package/openapi-client/generated/solana-token-balances/solana-token-balances.ts +2 -2
- package/openapi-client/generated/sql-api/sql-api.ts +92 -0
- package/openapi-client/generated/webhooks/webhooks.ts +6 -6
- package/openapi-client/generated/x402-facilitator/x402-facilitator.ts +6 -4
- package/openapi-client/index.ts +4 -1
- package/package.json +7 -8
- package/types/contract.ts +2 -4
- package/utils/export.ts +6 -5
- package/version.ts +1 -1
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +0 -55
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +0 -1
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +0 -50
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +0 -1
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts +0 -53
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts.map +0 -1
- package/openapi-client/generated/sql-api-alpha/sql-api-alpha.ts +0 -72
|
@@ -6,6 +6,32 @@ import type {
|
|
|
6
6
|
AddEndUserEvmSmartAccountResult,
|
|
7
7
|
AddEndUserSolanaAccountResult,
|
|
8
8
|
AddEvmSmartAccountOptions,
|
|
9
|
+
SignEvmHashResult,
|
|
10
|
+
SignEvmTransactionResult,
|
|
11
|
+
SignEvmMessageResult,
|
|
12
|
+
SignEvmTypedDataResult,
|
|
13
|
+
SendEvmTransactionResult,
|
|
14
|
+
SendEvmAssetResult,
|
|
15
|
+
SendUserOperationResult,
|
|
16
|
+
CreateEvmEip7702DelegationForEndUserResult,
|
|
17
|
+
SignSolanaHashResult,
|
|
18
|
+
SignSolanaMessageResult,
|
|
19
|
+
SignSolanaTransactionResult,
|
|
20
|
+
SendSolanaTransactionResult,
|
|
21
|
+
SendSolanaAssetResult,
|
|
22
|
+
AccountSignEvmHashOptions,
|
|
23
|
+
AccountSignEvmTransactionOptions,
|
|
24
|
+
AccountSignEvmMessageOptions,
|
|
25
|
+
AccountSignEvmTypedDataOptions,
|
|
26
|
+
AccountSendEvmTransactionOptions,
|
|
27
|
+
AccountSendEvmAssetOptions,
|
|
28
|
+
AccountSendUserOperationOptions,
|
|
29
|
+
AccountCreateEvmEip7702DelegationOptions,
|
|
30
|
+
AccountSignSolanaHashOptions,
|
|
31
|
+
AccountSignSolanaMessageOptions,
|
|
32
|
+
AccountSignSolanaTransactionOptions,
|
|
33
|
+
AccountSendSolanaTransactionOptions,
|
|
34
|
+
AccountSendSolanaAssetOptions,
|
|
9
35
|
} from "./endUser.types.js";
|
|
10
36
|
import type {
|
|
11
37
|
CdpOpenApiClientType,
|
|
@@ -18,11 +44,83 @@ import type {
|
|
|
18
44
|
export type ToEndUserAccountOptions = {
|
|
19
45
|
/** The end user from the API response. */
|
|
20
46
|
endUser: OpenAPIEndUser;
|
|
47
|
+
/** The CDP project ID. Required for delegation operations (signing, sending). */
|
|
48
|
+
projectId?: string;
|
|
21
49
|
};
|
|
22
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Returns the project ID or throws if not configured.
|
|
53
|
+
* Used by delegation operations that require a project ID.
|
|
54
|
+
*
|
|
55
|
+
* @param projectId - The project ID to validate.
|
|
56
|
+
* @returns The validated project ID.
|
|
57
|
+
*/
|
|
58
|
+
function requireProjectId(projectId: string | undefined): string {
|
|
59
|
+
if (!projectId) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Missing required project ID for delegation operation. " +
|
|
62
|
+
"Set the CDP_PROJECT_ID environment variable or pass projectId to the CdpClient constructor.",
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return projectId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the first EVM EOA address for this end user, or throws if none exist and no override was provided.
|
|
71
|
+
*
|
|
72
|
+
* @param endUser - The OpenAPI end user.
|
|
73
|
+
* @param override - An optional address override.
|
|
74
|
+
* @returns The resolved EVM address.
|
|
75
|
+
*/
|
|
76
|
+
function resolveEvmAddress(endUser: OpenAPIEndUser, override?: string): string {
|
|
77
|
+
const address = override ?? endUser.evmAccountObjects[0]?.address;
|
|
78
|
+
if (!address) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
"No EVM account found on this end user. Provide an explicit address or add an EVM account first.",
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return address;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the first EVM smart account address for this end user, or throws if none exist and no override was provided.
|
|
88
|
+
*
|
|
89
|
+
* @param endUser - The OpenAPI end user.
|
|
90
|
+
* @param override - An optional address override.
|
|
91
|
+
* @returns The resolved EVM smart account address.
|
|
92
|
+
*/
|
|
93
|
+
function resolveEvmSmartAccountAddress(endUser: OpenAPIEndUser, override?: string): string {
|
|
94
|
+
const address = override ?? endUser.evmSmartAccountObjects[0]?.address;
|
|
95
|
+
if (!address) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"No EVM smart account found on this end user. Provide an explicit address or add an EVM smart account first.",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return address;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Resolves the first Solana address for this end user, or throws if none exist and no override was provided.
|
|
105
|
+
*
|
|
106
|
+
* @param endUser - The OpenAPI end user.
|
|
107
|
+
* @param override - An optional address override.
|
|
108
|
+
* @returns The resolved Solana address.
|
|
109
|
+
*/
|
|
110
|
+
function resolveSolanaAddress(endUser: OpenAPIEndUser, override?: string): string {
|
|
111
|
+
const address = override ?? endUser.solanaAccountObjects[0]?.address;
|
|
112
|
+
if (!address) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"No Solana account found on this end user. Provide an explicit address or add a Solana account first.",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return address;
|
|
118
|
+
}
|
|
119
|
+
|
|
23
120
|
/**
|
|
24
121
|
* Creates an EndUserAccount instance with actions from an existing OpenAPI EndUser.
|
|
25
|
-
* This wraps the raw API response and adds convenience methods for adding accounts
|
|
122
|
+
* This wraps the raw API response and adds convenience methods for adding accounts
|
|
123
|
+
* and performing delegated signing/sending operations.
|
|
26
124
|
*
|
|
27
125
|
* @param apiClient - The API client.
|
|
28
126
|
* @param options - Configuration options.
|
|
@@ -33,46 +131,252 @@ export function toEndUserAccount(
|
|
|
33
131
|
apiClient: CdpOpenApiClientType,
|
|
34
132
|
options: ToEndUserAccountOptions,
|
|
35
133
|
): EndUserAccount {
|
|
134
|
+
const { endUser, projectId } = options;
|
|
135
|
+
|
|
36
136
|
const endUserAccount: EndUserAccount = {
|
|
37
137
|
// Pass through all properties from the OpenAPI EndUser
|
|
38
|
-
userId:
|
|
39
|
-
authenticationMethods:
|
|
40
|
-
mfaMethods:
|
|
41
|
-
evmAccounts:
|
|
42
|
-
evmAccountObjects:
|
|
43
|
-
evmSmartAccounts:
|
|
44
|
-
evmSmartAccountObjects:
|
|
45
|
-
solanaAccounts:
|
|
46
|
-
solanaAccountObjects:
|
|
47
|
-
createdAt:
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
async addEvmAccount(): Promise<AddEndUserEvmAccountResult> {
|
|
51
|
-
Analytics.trackAction({
|
|
52
|
-
action: "end_user_add_evm_account",
|
|
53
|
-
});
|
|
138
|
+
userId: endUser.userId,
|
|
139
|
+
authenticationMethods: endUser.authenticationMethods,
|
|
140
|
+
mfaMethods: endUser.mfaMethods,
|
|
141
|
+
evmAccounts: endUser.evmAccounts,
|
|
142
|
+
evmAccountObjects: endUser.evmAccountObjects,
|
|
143
|
+
evmSmartAccounts: endUser.evmSmartAccounts,
|
|
144
|
+
evmSmartAccountObjects: endUser.evmSmartAccountObjects,
|
|
145
|
+
solanaAccounts: endUser.solanaAccounts,
|
|
146
|
+
solanaAccountObjects: endUser.solanaAccountObjects,
|
|
147
|
+
createdAt: endUser.createdAt,
|
|
148
|
+
|
|
149
|
+
// ─── Account Management Methods ───
|
|
54
150
|
|
|
55
|
-
|
|
151
|
+
async addEvmAccount(): Promise<AddEndUserEvmAccountResult> {
|
|
152
|
+
Analytics.trackAction({ action: "end_user_add_evm_account" });
|
|
153
|
+
return apiClient.addEndUserEvmAccount(endUser.userId, {});
|
|
56
154
|
},
|
|
57
155
|
|
|
58
156
|
async addEvmSmartAccount(
|
|
59
157
|
smartAccountOptions: AddEvmSmartAccountOptions,
|
|
60
158
|
): Promise<AddEndUserEvmSmartAccountResult> {
|
|
61
|
-
Analytics.trackAction({
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return apiClient.addEndUserEvmSmartAccount(options.endUser.userId, {
|
|
159
|
+
Analytics.trackAction({ action: "end_user_add_evm_smart_account" });
|
|
160
|
+
return apiClient.addEndUserEvmSmartAccount(endUser.userId, {
|
|
66
161
|
enableSpendPermissions: smartAccountOptions.enableSpendPermissions,
|
|
67
162
|
});
|
|
68
163
|
},
|
|
69
164
|
|
|
70
165
|
async addSolanaAccount(): Promise<AddEndUserSolanaAccountResult> {
|
|
71
|
-
Analytics.trackAction({
|
|
72
|
-
|
|
166
|
+
Analytics.trackAction({ action: "end_user_add_solana_account" });
|
|
167
|
+
return apiClient.addEndUserSolanaAccount(endUser.userId, {});
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
async revokeDelegation(): Promise<void> {
|
|
171
|
+
Analytics.trackAction({ action: "end_user_revoke_delegation" });
|
|
172
|
+
await apiClient.revokeDelegationForEndUser(requireProjectId(projectId), endUser.userId, {});
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// ─── Delegated EVM Sign Methods ───
|
|
176
|
+
|
|
177
|
+
async signEvmHash(opts: AccountSignEvmHashOptions): Promise<SignEvmHashResult> {
|
|
178
|
+
Analytics.trackAction({ action: "end_user_sign_evm_hash" });
|
|
179
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
180
|
+
return apiClient.signEvmHashWithEndUserAccount(requireProjectId(projectId), endUser.userId, {
|
|
181
|
+
hash: opts.hash,
|
|
182
|
+
address,
|
|
73
183
|
});
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
async signEvmTransaction(
|
|
187
|
+
opts: AccountSignEvmTransactionOptions,
|
|
188
|
+
): Promise<SignEvmTransactionResult> {
|
|
189
|
+
Analytics.trackAction({ action: "end_user_sign_evm_transaction" });
|
|
190
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
191
|
+
return apiClient.signEvmTransactionWithEndUserAccount(
|
|
192
|
+
requireProjectId(projectId),
|
|
193
|
+
endUser.userId,
|
|
194
|
+
{
|
|
195
|
+
address,
|
|
196
|
+
transaction: opts.transaction,
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
async signEvmMessage(opts: AccountSignEvmMessageOptions): Promise<SignEvmMessageResult> {
|
|
202
|
+
Analytics.trackAction({ action: "end_user_sign_evm_message" });
|
|
203
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
204
|
+
return apiClient.signEvmMessageWithEndUserAccount(
|
|
205
|
+
requireProjectId(projectId),
|
|
206
|
+
endUser.userId,
|
|
207
|
+
{
|
|
208
|
+
address,
|
|
209
|
+
message: opts.message,
|
|
210
|
+
},
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
async signEvmTypedData(opts: AccountSignEvmTypedDataOptions): Promise<SignEvmTypedDataResult> {
|
|
215
|
+
Analytics.trackAction({ action: "end_user_sign_evm_typed_data" });
|
|
216
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
217
|
+
return apiClient.signEvmTypedDataWithEndUserAccount(
|
|
218
|
+
requireProjectId(projectId),
|
|
219
|
+
endUser.userId,
|
|
220
|
+
{
|
|
221
|
+
address,
|
|
222
|
+
typedData: opts.typedData,
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
// ─── Delegated EVM Send Methods ───
|
|
228
|
+
|
|
229
|
+
async sendEvmTransaction(
|
|
230
|
+
opts: AccountSendEvmTransactionOptions,
|
|
231
|
+
): Promise<SendEvmTransactionResult> {
|
|
232
|
+
Analytics.trackAction({ action: "end_user_send_evm_transaction" });
|
|
233
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
234
|
+
return apiClient.sendEvmTransactionWithEndUserAccount(
|
|
235
|
+
requireProjectId(projectId),
|
|
236
|
+
endUser.userId,
|
|
237
|
+
{
|
|
238
|
+
address,
|
|
239
|
+
transaction: opts.transaction,
|
|
240
|
+
network: opts.network,
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async sendEvmAsset(opts: AccountSendEvmAssetOptions): Promise<SendEvmAssetResult> {
|
|
246
|
+
Analytics.trackAction({ action: "end_user_send_evm_asset" });
|
|
247
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
248
|
+
const asset = opts.asset ?? "usdc";
|
|
249
|
+
return apiClient.sendEvmAssetWithEndUserAccount(
|
|
250
|
+
requireProjectId(projectId),
|
|
251
|
+
endUser.userId,
|
|
252
|
+
address,
|
|
253
|
+
asset,
|
|
254
|
+
{
|
|
255
|
+
to: opts.to,
|
|
256
|
+
amount: opts.amount,
|
|
257
|
+
network: opts.network,
|
|
258
|
+
useCdpPaymaster: opts.useCdpPaymaster,
|
|
259
|
+
paymasterUrl: opts.paymasterUrl,
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
async sendUserOperation(
|
|
265
|
+
opts: AccountSendUserOperationOptions,
|
|
266
|
+
): Promise<SendUserOperationResult> {
|
|
267
|
+
Analytics.trackAction({ action: "end_user_send_user_operation" });
|
|
268
|
+
const address = resolveEvmSmartAccountAddress(endUser, opts.address);
|
|
269
|
+
return apiClient.sendUserOperationWithEndUserAccount(
|
|
270
|
+
requireProjectId(projectId),
|
|
271
|
+
endUser.userId,
|
|
272
|
+
address,
|
|
273
|
+
{
|
|
274
|
+
network: opts.network,
|
|
275
|
+
calls: opts.calls,
|
|
276
|
+
useCdpPaymaster: opts.useCdpPaymaster,
|
|
277
|
+
paymasterUrl: opts.paymasterUrl,
|
|
278
|
+
dataSuffix: opts.dataSuffix,
|
|
279
|
+
},
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
// ─── Delegated EVM EIP-7702 Delegation Method ───
|
|
284
|
+
|
|
285
|
+
async createEvmEip7702Delegation(
|
|
286
|
+
opts: AccountCreateEvmEip7702DelegationOptions,
|
|
287
|
+
): Promise<CreateEvmEip7702DelegationForEndUserResult> {
|
|
288
|
+
Analytics.trackAction({ action: "end_user_create_evm_eip7702_delegation" });
|
|
289
|
+
const address = resolveEvmAddress(endUser, opts.address);
|
|
290
|
+
return apiClient.createEvmEip7702DelegationWithEndUserAccount(
|
|
291
|
+
requireProjectId(projectId),
|
|
292
|
+
endUser.userId,
|
|
293
|
+
{
|
|
294
|
+
address,
|
|
295
|
+
network: opts.network,
|
|
296
|
+
enableSpendPermissions: opts.enableSpendPermissions,
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
// ─── Delegated Solana Sign Methods ───
|
|
302
|
+
|
|
303
|
+
async signSolanaHash(opts: AccountSignSolanaHashOptions): Promise<SignSolanaHashResult> {
|
|
304
|
+
Analytics.trackAction({ action: "end_user_sign_solana_hash" });
|
|
305
|
+
const address = resolveSolanaAddress(endUser, opts.address);
|
|
306
|
+
return apiClient.signSolanaHashWithEndUserAccount(
|
|
307
|
+
requireProjectId(projectId),
|
|
308
|
+
endUser.userId,
|
|
309
|
+
{
|
|
310
|
+
hash: opts.hash,
|
|
311
|
+
address,
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
async signSolanaMessage(
|
|
317
|
+
opts: AccountSignSolanaMessageOptions,
|
|
318
|
+
): Promise<SignSolanaMessageResult> {
|
|
319
|
+
Analytics.trackAction({ action: "end_user_sign_solana_message" });
|
|
320
|
+
const address = resolveSolanaAddress(endUser, opts.address);
|
|
321
|
+
return apiClient.signSolanaMessageWithEndUserAccount(
|
|
322
|
+
requireProjectId(projectId),
|
|
323
|
+
endUser.userId,
|
|
324
|
+
{
|
|
325
|
+
address,
|
|
326
|
+
message: opts.message,
|
|
327
|
+
},
|
|
328
|
+
);
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
async signSolanaTransaction(
|
|
332
|
+
opts: AccountSignSolanaTransactionOptions,
|
|
333
|
+
): Promise<SignSolanaTransactionResult> {
|
|
334
|
+
Analytics.trackAction({ action: "end_user_sign_solana_transaction" });
|
|
335
|
+
const address = resolveSolanaAddress(endUser, opts.address);
|
|
336
|
+
return apiClient.signSolanaTransactionWithEndUserAccount(
|
|
337
|
+
requireProjectId(projectId),
|
|
338
|
+
endUser.userId,
|
|
339
|
+
{
|
|
340
|
+
address,
|
|
341
|
+
transaction: opts.transaction,
|
|
342
|
+
},
|
|
343
|
+
);
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
// ─── Delegated Solana Send Methods ───
|
|
347
|
+
|
|
348
|
+
async sendSolanaTransaction(
|
|
349
|
+
opts: AccountSendSolanaTransactionOptions,
|
|
350
|
+
): Promise<SendSolanaTransactionResult> {
|
|
351
|
+
Analytics.trackAction({ action: "end_user_send_solana_transaction" });
|
|
352
|
+
const address = resolveSolanaAddress(endUser, opts.address);
|
|
353
|
+
return apiClient.sendSolanaTransactionWithEndUserAccount(
|
|
354
|
+
requireProjectId(projectId),
|
|
355
|
+
endUser.userId,
|
|
356
|
+
{
|
|
357
|
+
address,
|
|
358
|
+
transaction: opts.transaction,
|
|
359
|
+
network: opts.network,
|
|
360
|
+
},
|
|
361
|
+
);
|
|
362
|
+
},
|
|
74
363
|
|
|
75
|
-
|
|
364
|
+
async sendSolanaAsset(opts: AccountSendSolanaAssetOptions): Promise<SendSolanaAssetResult> {
|
|
365
|
+
Analytics.trackAction({ action: "end_user_send_solana_asset" });
|
|
366
|
+
const address = resolveSolanaAddress(endUser, opts.address);
|
|
367
|
+
const asset = opts.asset ?? "usdc";
|
|
368
|
+
return apiClient.sendSolanaAssetWithEndUserAccount(
|
|
369
|
+
requireProjectId(projectId),
|
|
370
|
+
endUser.userId,
|
|
371
|
+
address,
|
|
372
|
+
asset,
|
|
373
|
+
{
|
|
374
|
+
to: opts.to,
|
|
375
|
+
amount: opts.amount,
|
|
376
|
+
network: opts.network,
|
|
377
|
+
createRecipientAta: opts.createRecipientAta,
|
|
378
|
+
},
|
|
379
|
+
);
|
|
76
380
|
},
|
|
77
381
|
};
|
|
78
382
|
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -468,8 +468,10 @@ export interface ListServerAccountsOptions {
|
|
|
468
468
|
/**
|
|
469
469
|
* A smart account that only contains the owner address.
|
|
470
470
|
*/
|
|
471
|
-
export interface ReadonlySmartAccount
|
|
472
|
-
|
|
471
|
+
export interface ReadonlySmartAccount extends Omit<
|
|
472
|
+
SmartAccount,
|
|
473
|
+
"owners" | keyof SmartAccountActions | "useNetwork"
|
|
474
|
+
> {
|
|
473
475
|
/** The owners of the smart account. */
|
|
474
476
|
owners: Address[];
|
|
475
477
|
}
|
package/client/solana/solana.ts
CHANGED
|
@@ -153,7 +153,7 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
153
153
|
})();
|
|
154
154
|
|
|
155
155
|
const decryptedPrivateKey = decryptWithPrivateKey(privateKey, encryptedPrivateKey);
|
|
156
|
-
return formatSolanaPrivateKey(decryptedPrivateKey);
|
|
156
|
+
return await formatSolanaPrivateKey(decryptedPrivateKey);
|
|
157
157
|
} catch (error) {
|
|
158
158
|
if (!(error instanceof UserInputValidationError)) {
|
|
159
159
|
Analytics.trackError(error, "exportAccount");
|
|
@@ -484,18 +484,44 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
484
484
|
* // Create a Solana account
|
|
485
485
|
* const account = await cdp.solana.createAccount();
|
|
486
486
|
*
|
|
487
|
-
* //
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
487
|
+
* // Build your transaction using @solana/kit
|
|
488
|
+
* import {
|
|
489
|
+
* address as solanaAddress,
|
|
490
|
+
* appendTransactionMessageInstructions,
|
|
491
|
+
* compileTransaction,
|
|
492
|
+
* createNoopSigner,
|
|
493
|
+
* createSolanaRpc,
|
|
494
|
+
* createTransactionMessage,
|
|
495
|
+
* getBase64EncodedWireTransaction,
|
|
496
|
+
* pipe,
|
|
497
|
+
* setTransactionMessageFeePayer,
|
|
498
|
+
* setTransactionMessageLifetimeUsingBlockhash,
|
|
499
|
+
* } from "@solana/kit";
|
|
500
|
+
* import { getTransferSolInstruction } from "@solana-program/system";
|
|
501
|
+
*
|
|
502
|
+
* const rpc = createSolanaRpc("https://api.devnet.solana.com");
|
|
503
|
+
* const { value: { blockhash, lastValidBlockHeight } } = await rpc.getLatestBlockhash().send();
|
|
504
|
+
*
|
|
505
|
+
* const txMsg = pipe(
|
|
506
|
+
* createTransactionMessage({ version: 0 }),
|
|
507
|
+
* (tx) => setTransactionMessageFeePayer(solanaAddress(account.address), tx),
|
|
508
|
+
* (tx) => setTransactionMessageLifetimeUsingBlockhash(
|
|
509
|
+
* { blockhash, lastValidBlockHeight },
|
|
510
|
+
* tx,
|
|
511
|
+
* ),
|
|
512
|
+
* (tx) => appendTransactionMessageInstructions([
|
|
513
|
+
* getTransferSolInstruction({
|
|
514
|
+
* source: createNoopSigner(solanaAddress(account.address)),
|
|
515
|
+
* destination: solanaAddress("3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE"),
|
|
516
|
+
* amount: 10000n,
|
|
517
|
+
* }),
|
|
518
|
+
* ], tx),
|
|
519
|
+
* );
|
|
520
|
+
*
|
|
521
|
+
* // Base64 encode the compiled transaction
|
|
522
|
+
* const transaction = getBase64EncodedWireTransaction(compileTransaction(txMsg));
|
|
523
|
+
*
|
|
524
|
+
* // Sign the transaction via the CDP API
|
|
499
525
|
* const signature = await cdp.solana.signTransaction({
|
|
500
526
|
* address: account.address,
|
|
501
527
|
* transaction,
|
package/index.ts
CHANGED
|
@@ -15,7 +15,37 @@ export {
|
|
|
15
15
|
export { NetworkError } from "./openapi-client/errors.js";
|
|
16
16
|
export type { SpendPermission, SpendPermissionInput } from "./spend-permissions/types.js";
|
|
17
17
|
export type { SpendPermissionNetwork, ListEndUsers200, EndUser } from "./openapi-client/index.js";
|
|
18
|
-
export type {
|
|
18
|
+
export type {
|
|
19
|
+
ListEndUsersOptions,
|
|
20
|
+
EndUserAccount,
|
|
21
|
+
RevokeDelegationForEndUserOptions,
|
|
22
|
+
SignEvmHashOptions,
|
|
23
|
+
SignEvmHashResult,
|
|
24
|
+
SignEvmTransactionOptions,
|
|
25
|
+
SignEvmTransactionResult,
|
|
26
|
+
SignEvmMessageOptions,
|
|
27
|
+
SignEvmMessageResult,
|
|
28
|
+
SignEvmTypedDataOptions,
|
|
29
|
+
SignEvmTypedDataResult,
|
|
30
|
+
SendEvmTransactionOptions,
|
|
31
|
+
SendEvmTransactionResult,
|
|
32
|
+
SendEvmAssetOptions,
|
|
33
|
+
SendEvmAssetResult,
|
|
34
|
+
SendUserOperationOptions,
|
|
35
|
+
SendUserOperationResult,
|
|
36
|
+
CreateEvmEip7702DelegationOptions as CreateEvmEip7702DelegationForEndUserOptions,
|
|
37
|
+
CreateEvmEip7702DelegationForEndUserResult,
|
|
38
|
+
SignSolanaHashOptions,
|
|
39
|
+
SignSolanaHashResult,
|
|
40
|
+
SignSolanaMessageOptions,
|
|
41
|
+
SignSolanaMessageResult,
|
|
42
|
+
SignSolanaTransactionOptions,
|
|
43
|
+
SignSolanaTransactionResult,
|
|
44
|
+
SendSolanaTransactionOptions,
|
|
45
|
+
SendSolanaTransactionResult,
|
|
46
|
+
SendSolanaAssetOptions,
|
|
47
|
+
SendSolanaAssetResult,
|
|
48
|
+
} from "./client/end-user/endUser.types.js";
|
|
19
49
|
export {
|
|
20
50
|
SPEND_PERMISSION_MANAGER_ABI as spendPermissionManagerAbi,
|
|
21
51
|
SPEND_PERMISSION_MANAGER_ADDRESS as spendPermissionManagerAddress,
|
|
@@ -85,6 +85,26 @@ export const configure = (options: CdpOptions) => {
|
|
|
85
85
|
expiresIn: options.expiresIn,
|
|
86
86
|
debug: options.debugging,
|
|
87
87
|
});
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Delegated routing interceptor.
|
|
91
|
+
* Embedded Wallet API's are exposed to the developer for delegated signing
|
|
92
|
+
* via the /delegated path, which properly forwards the Authorization and
|
|
93
|
+
* X-Wallet-Auth headers from the edge.
|
|
94
|
+
*
|
|
95
|
+
* Registered after withAuth so it runs BEFORE the auth interceptor (LIFO order).
|
|
96
|
+
* This rewrites the URL first, then the auth interceptor computes JWT headers
|
|
97
|
+
* (Authorization and X-Wallet-Auth) against the rewritten URL path, ensuring
|
|
98
|
+
* the `uris` claim matches the actual request URL.
|
|
99
|
+
* The API gateway validates the JWT, strips the /delegated prefix, and forwards
|
|
100
|
+
* to the backend.
|
|
101
|
+
*/
|
|
102
|
+
axiosInstance.interceptors.request.use(config => {
|
|
103
|
+
if (config.url && isDelegatedEndUserPath(config.url)) {
|
|
104
|
+
config.url = `/delegated${config.url}`;
|
|
105
|
+
}
|
|
106
|
+
return config;
|
|
107
|
+
});
|
|
88
108
|
};
|
|
89
109
|
|
|
90
110
|
/**
|
|
@@ -307,6 +327,20 @@ export const cdpApiClient = async <T>(
|
|
|
307
327
|
}
|
|
308
328
|
};
|
|
309
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Checks if the given request URL is a delegated end-user operation that should
|
|
332
|
+
* be routed through the /platform/delegated gateway prefix.
|
|
333
|
+
*
|
|
334
|
+
* These endpoints require both Authorization and X-Wallet-Auth headers to be
|
|
335
|
+
* forwarded by the API gateway, which the /delegated prefix enables.
|
|
336
|
+
*
|
|
337
|
+
* @param url - The request URL (relative, without base path).
|
|
338
|
+
* @returns True if the path should be routed through /platform/delegated.
|
|
339
|
+
*/
|
|
340
|
+
const isDelegatedEndUserPath = (url: string): boolean => {
|
|
341
|
+
return /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/end-users\//.test(url);
|
|
342
|
+
};
|
|
343
|
+
|
|
310
344
|
/**
|
|
311
345
|
* Validates the call to the cdpApiClient.
|
|
312
346
|
*
|