@coinbase/cdp-sdk 1.1.2 → 1.3.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 +91 -0
- package/LICENSE +21 -0
- package/README.md +88 -1
- package/{dist → _cjs}/accounts/evm/toEvmServerAccount.js +1 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -0
- package/{dist → _cjs}/accounts/evm/toEvmSmartAccount.js +1 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -0
- package/{dist → _cjs}/accounts/types.js +1 -0
- package/_cjs/accounts/types.js.map +1 -0
- package/{dist → _cjs}/actions/evm/sendUserOperation.js +1 -0
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -0
- package/{dist → _cjs}/actions/evm/waitForUserOperation.js +10 -9
- package/_cjs/actions/evm/waitForUserOperation.js.map +1 -0
- package/{dist → _cjs}/analytics.js +32 -12
- package/_cjs/analytics.js.map +1 -0
- package/{dist → _cjs}/auth/errors.js +1 -0
- package/_cjs/auth/errors.js.map +1 -0
- package/{dist → _cjs}/auth/hooks/axios/index.js +2 -1
- package/_cjs/auth/hooks/axios/index.js.map +1 -0
- package/{dist → _cjs}/auth/hooks/axios/withAuth.js +4 -2
- package/_cjs/auth/hooks/axios/withAuth.js.map +1 -0
- package/{dist → _cjs}/auth/index.js +4 -3
- package/_cjs/auth/index.js.map +1 -0
- package/{dist → _cjs}/auth/utils/http.js +6 -5
- package/_cjs/auth/utils/http.js.map +1 -0
- package/{dist → _cjs}/auth/utils/index.js +3 -2
- package/_cjs/auth/utils/index.js.map +1 -0
- package/{dist → _cjs}/auth/utils/jwt.js +4 -3
- package/_cjs/auth/utils/jwt.js.map +1 -0
- package/_cjs/client/cdp.js +101 -0
- package/_cjs/client/cdp.js.map +1 -0
- package/_cjs/client/evm/evm.js +641 -0
- package/_cjs/client/evm/evm.js.map +1 -0
- package/{dist → _cjs}/client/evm/evm.types.js +1 -0
- package/_cjs/client/evm/evm.types.js.map +1 -0
- package/{dist → _cjs}/client/solana/index.js +3 -2
- package/_cjs/client/solana/index.js.map +1 -0
- package/{dist → _cjs}/client/solana/solana.js +9 -8
- package/_cjs/client/solana/solana.js.map +1 -0
- package/{dist → _cjs}/client/solana/solana.types.js +1 -0
- package/_cjs/client/solana/solana.types.js.map +1 -0
- package/{dist → _cjs}/constants.js +1 -0
- package/_cjs/constants.js.map +1 -0
- package/{dist → _cjs}/errors.js +1 -0
- package/_cjs/errors.js.map +1 -0
- package/{dist → _cjs}/index.js +4 -3
- package/_cjs/index.js.map +1 -0
- package/_cjs/openapi-client/cdpApiClient.js +116 -0
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -0
- package/{dist → _cjs}/openapi-client/errors.js +44 -3
- package/_cjs/openapi-client/errors.js.map +1 -0
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +66 -0
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +125 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +160 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +70 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +188 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js +15 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js +45 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/faucets/faucets.js +20 -14
- package/_cjs/openapi-client/generated/faucets/faucets.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/faucets/faucets.msw.js +16 -12
- package/_cjs/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/index.msw.js +6 -4
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.js +38 -35
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.msw.js +68 -35
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/index.js +16 -11
- package/_cjs/openapi-client/index.js.map +1 -0
- package/_cjs/package.json +1 -0
- package/{dist → _cjs}/types/calls.js +1 -0
- package/_cjs/types/calls.js.map +1 -0
- package/{dist → _cjs}/types/contract.js +1 -0
- package/_cjs/types/contract.js.map +1 -0
- package/{dist → _cjs}/types/misc.js +1 -0
- package/_cjs/types/misc.js.map +1 -0
- package/{dist → _cjs}/types/multicall.js +1 -0
- package/_cjs/types/multicall.js.map +1 -0
- package/{dist → _cjs}/types/utils.js +1 -0
- package/_cjs/types/utils.js.map +1 -0
- package/{dist → _cjs}/utils/wait.js +3 -2
- package/_cjs/utils/wait.js.map +1 -0
- package/_cjs/version.js +5 -0
- package/_cjs/version.js.map +1 -0
- package/_esm/accounts/evm/toEvmServerAccount.js +40 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js +22 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -0
- package/_esm/accounts/types.js +2 -0
- package/_esm/accounts/types.js.map +1 -0
- package/_esm/actions/evm/sendUserOperation.js +85 -0
- package/_esm/actions/evm/sendUserOperation.js.map +1 -0
- package/_esm/actions/evm/waitForUserOperation.js +58 -0
- package/_esm/actions/evm/waitForUserOperation.js.map +1 -0
- package/_esm/analytics.js +101 -0
- package/_esm/analytics.js.map +1 -0
- package/_esm/auth/errors.js +57 -0
- package/_esm/auth/errors.js.map +1 -0
- package/_esm/auth/hooks/axios/index.js +2 -0
- package/_esm/auth/hooks/axios/index.js.map +1 -0
- package/_esm/auth/hooks/axios/withAuth.js +72 -0
- package/_esm/auth/hooks/axios/withAuth.js.map +1 -0
- package/_esm/auth/index.js +5 -0
- package/_esm/auth/index.js.map +1 -0
- package/_esm/auth/utils/http.js +70 -0
- package/_esm/auth/utils/http.js.map +1 -0
- package/_esm/auth/utils/index.js +3 -0
- package/_esm/auth/utils/index.js.map +1 -0
- package/_esm/auth/utils/jwt.js +199 -0
- package/_esm/auth/utils/jwt.js.map +1 -0
- package/{dist → _esm}/client/cdp.js +16 -13
- package/_esm/client/cdp.js.map +1 -0
- package/{dist → _esm}/client/evm/evm.js +146 -30
- package/_esm/client/evm/evm.js.map +1 -0
- package/_esm/client/evm/evm.types.js +2 -0
- package/_esm/client/evm/evm.types.js.map +1 -0
- package/_esm/client/solana/index.js +2 -0
- package/_esm/client/solana/index.js.map +1 -0
- package/_esm/client/solana/solana.js +204 -0
- package/_esm/client/solana/solana.js.map +1 -0
- package/_esm/client/solana/solana.types.js +2 -0
- package/_esm/client/solana/solana.types.js.map +1 -0
- package/_esm/constants.js +5 -0
- package/_esm/constants.js.map +1 -0
- package/_esm/errors.js +18 -0
- package/_esm/errors.js.map +1 -0
- package/_esm/index.js +3 -0
- package/_esm/index.js.map +1 -0
- package/_esm/openapi-client/cdpApiClient.js +108 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -0
- package/_esm/openapi-client/errors.js +104 -0
- package/_esm/openapi-client/errors.js.map +1 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +63 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +114 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +140 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +61 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +172 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js +11 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js +39 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js.map +1 -0
- package/_esm/openapi-client/generated/faucets/faucets.js +52 -0
- package/_esm/openapi-client/generated/faucets/faucets.js.map +1 -0
- package/_esm/openapi-client/generated/faucets/faucets.msw.js +39 -0
- package/_esm/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
- package/_esm/openapi-client/generated/index.msw.js +6 -0
- package/_esm/openapi-client/generated/index.msw.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +73 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +116 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/index.js +31 -0
- package/_esm/openapi-client/index.js.map +1 -0
- package/_esm/package.json +1 -0
- package/_esm/types/calls.js +4 -0
- package/_esm/types/calls.js.map +1 -0
- package/_esm/types/contract.js +4 -0
- package/_esm/types/contract.js.map +1 -0
- package/_esm/types/misc.js +3 -0
- package/_esm/types/misc.js.map +1 -0
- package/_esm/types/multicall.js +2 -0
- package/_esm/types/multicall.js.map +1 -0
- package/_esm/types/utils.js +4 -0
- package/_esm/types/utils.js.map +1 -0
- package/_esm/utils/wait.js +32 -0
- package/_esm/utils/wait.js.map +1 -0
- package/_esm/version.js +2 -0
- package/_esm/version.js.map +1 -0
- package/{dist → _types}/accounts/evm/toEvmServerAccount.d.ts +3 -2
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -0
- package/{dist → _types}/accounts/evm/toEvmSmartAccount.d.ts +3 -2
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -0
- package/{dist → _types}/accounts/types.d.ts +3 -2
- package/_types/accounts/types.d.ts.map +1 -0
- package/{dist → _types}/actions/evm/sendUserOperation.d.ts +5 -5
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -0
- package/{dist → _types}/actions/evm/waitForUserOperation.d.ts +4 -3
- package/_types/actions/evm/waitForUserOperation.d.ts.map +1 -0
- package/{dist → _types}/analytics.d.ts +16 -0
- package/_types/analytics.d.ts.map +1 -0
- package/{dist → _types}/auth/errors.d.ts +1 -0
- package/_types/auth/errors.d.ts.map +1 -0
- package/_types/auth/hooks/axios/index.d.ts +2 -0
- package/_types/auth/hooks/axios/index.d.ts.map +1 -0
- package/{dist → _types}/auth/hooks/axios/withAuth.d.ts +1 -0
- package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -0
- package/_types/auth/index.d.ts +5 -0
- package/_types/auth/index.d.ts.map +1 -0
- package/{dist → _types}/auth/utils/http.d.ts +1 -0
- package/_types/auth/utils/http.d.ts.map +1 -0
- package/_types/auth/utils/index.d.ts +3 -0
- package/_types/auth/utils/index.d.ts.map +1 -0
- package/{dist → _types}/auth/utils/jwt.d.ts +1 -0
- package/_types/auth/utils/jwt.d.ts.map +1 -0
- package/{dist → _types}/client/cdp.d.ts +3 -2
- package/_types/client/cdp.d.ts.map +1 -0
- package/{dist → _types}/client/evm/evm.d.ts +86 -3
- package/_types/client/evm/evm.d.ts.map +1 -0
- package/{dist → _types}/client/evm/evm.types.d.ts +104 -7
- package/_types/client/evm/evm.types.d.ts.map +1 -0
- package/_types/client/solana/index.d.ts +2 -0
- package/_types/client/solana/index.d.ts.map +1 -0
- package/{dist → _types}/client/solana/solana.d.ts +2 -1
- package/_types/client/solana/solana.d.ts.map +1 -0
- package/{dist → _types}/client/solana/solana.types.d.ts +2 -1
- package/_types/client/solana/solana.types.d.ts.map +1 -0
- package/{dist → _types}/constants.d.ts +1 -0
- package/_types/constants.d.ts.map +1 -0
- package/{dist → _types}/errors.d.ts +1 -0
- package/_types/errors.d.ts.map +1 -0
- package/_types/index.d.ts +4 -0
- package/_types/index.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/cdpApiClient.d.ts +1 -0
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/errors.d.ts +30 -2
- package/_types/openapi-client/errors.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +100 -14
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +91 -0
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -2
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +22 -20
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +3 -2
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts +20 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.msw.d.ts +6 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/faucets/faucets.d.ts +11 -9
- package/_types/openapi-client/generated/faucets/faucets.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/faucets/faucets.msw.d.ts +3 -2
- package/_types/openapi-client/generated/faucets/faucets.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/index.msw.d.ts +6 -0
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.d.ts +21 -20
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +3 -2
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -0
- package/_types/openapi-client/index.d.ts +61 -0
- package/_types/openapi-client/index.d.ts.map +1 -0
- package/{dist → _types}/types/calls.d.ts +4 -3
- package/_types/types/calls.d.ts.map +1 -0
- package/{dist → _types}/types/contract.d.ts +3 -2
- package/_types/types/contract.d.ts.map +1 -0
- package/_types/types/misc.d.ts +41 -0
- package/_types/types/misc.d.ts.map +1 -0
- package/{dist → _types}/types/multicall.d.ts +2 -1
- package/_types/types/multicall.d.ts.map +1 -0
- package/{dist → _types}/types/utils.d.ts +1 -0
- package/_types/types/utils.d.ts.map +1 -0
- package/{dist → _types}/utils/wait.d.ts +1 -0
- package/_types/utils/wait.d.ts.map +1 -0
- package/_types/version.d.ts +2 -0
- package/_types/version.d.ts.map +1 -0
- package/accounts/evm/toEvmServerAccount.ts +60 -0
- package/accounts/evm/toEvmSmartAccount.ts +37 -0
- package/accounts/types.ts +53 -0
- package/actions/evm/sendUserOperation.ts +163 -0
- package/actions/evm/waitForUserOperation.ts +115 -0
- package/analytics.ts +142 -0
- package/auth/README.md +145 -0
- package/auth/errors.ts +59 -0
- package/auth/hooks/axios/index.ts +1 -0
- package/auth/hooks/axios/withAuth.ts +121 -0
- package/auth/index.ts +5 -0
- package/auth/utils/http.ts +146 -0
- package/auth/utils/index.ts +2 -0
- package/auth/utils/jwt.ts +324 -0
- package/client/cdp.ts +116 -0
- package/client/evm/evm.ts +739 -0
- package/client/evm/evm.types.ts +408 -0
- package/client/solana/index.ts +1 -0
- package/client/solana/solana.ts +237 -0
- package/client/solana/solana.types.ts +114 -0
- package/constants.ts +4 -0
- package/errors.ts +17 -0
- package/index.ts +4 -0
- package/openapi-client/cdpApiClient.ts +221 -0
- package/openapi-client/errors.ts +132 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +512 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +271 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +194 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +283 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +132 -0
- package/openapi-client/generated/evm-token-balances/evm-token-balances.msw.ts +57 -0
- package/openapi-client/generated/evm-token-balances/evm-token-balances.ts +37 -0
- package/openapi-client/generated/faucets/faucets.msw.ts +76 -0
- package/openapi-client/generated/faucets/faucets.ts +84 -0
- package/openapi-client/generated/index.msw.ts +5 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +219 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +143 -0
- package/openapi-client/index.ts +36 -0
- package/package.json +31 -66
- package/types/calls.ts +40 -0
- package/types/contract.ts +126 -0
- package/types/misc.ts +44 -0
- package/types/multicall.ts +29 -0
- package/types/utils.ts +288 -0
- package/utils/wait.ts +52 -0
- package/version.ts +1 -0
- package/dist/auth/hooks/axios/index.d.ts +0 -1
- package/dist/auth/index.d.ts +0 -4
- package/dist/auth/utils/index.d.ts +0 -2
- package/dist/client/evm/index.d.ts +0 -1
- package/dist/client/evm/index.js +0 -5
- package/dist/client/solana/index.d.ts +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/openapi-client/cdpApiClient.js +0 -146
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +0 -54
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +0 -62
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +0 -85
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +0 -113
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +0 -66
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +0 -99
- package/dist/openapi-client/generated/index.msw.d.ts +0 -4
- package/dist/openapi-client/index.d.ts +0 -55
- package/dist/types/misc.d.ts +0 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenApiSolanaMethods,
|
|
3
|
+
SolanaAccount as OpenAPISolanaAccount,
|
|
4
|
+
} from "../../openapi-client/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* The SolanaClient type, where all OpenApiSolanaMethods methods are wrapped.
|
|
7
|
+
*/
|
|
8
|
+
export type SolanaClientInterface = Omit<
|
|
9
|
+
typeof OpenApiSolanaMethods,
|
|
10
|
+
| "createSolanaAccount" // mapped to createAccount
|
|
11
|
+
| "getSolanaAccount" // mapped to getAccount
|
|
12
|
+
| "getSolanaAccountByName" // mapped to getAccount
|
|
13
|
+
| "listSolanaAccounts" // mapped to listAccounts
|
|
14
|
+
| "requestSolanaFaucet" // mapped to requestFaucet
|
|
15
|
+
| "signSolanaMessage" // mapped to signMessage
|
|
16
|
+
| "signSolanaTransaction" // mapped to signTransaction
|
|
17
|
+
> & {
|
|
18
|
+
createAccount: (options: CreateAccountOptions) => Promise<Account>;
|
|
19
|
+
getAccount: (options: GetAccountOptions) => Promise<Account>;
|
|
20
|
+
listAccounts: (options: ListAccountsOptions) => Promise<ListAccountsResult>;
|
|
21
|
+
requestFaucet: (options: RequestFaucetOptions) => Promise<SignatureResult>;
|
|
22
|
+
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
23
|
+
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A Solana account.
|
|
27
|
+
*/
|
|
28
|
+
export type Account = OpenAPISolanaAccount;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for creating a Solana account.
|
|
32
|
+
*/
|
|
33
|
+
export interface CreateAccountOptions {
|
|
34
|
+
/** The name of the account. */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** The idempotency key. */
|
|
37
|
+
idempotencyKey?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for getting a Solana account.
|
|
42
|
+
*/
|
|
43
|
+
export interface GetAccountOptions {
|
|
44
|
+
/** The address of the account. */
|
|
45
|
+
address?: string;
|
|
46
|
+
/** The name of the account. */
|
|
47
|
+
name?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Options for listing Solana accounts.
|
|
52
|
+
*/
|
|
53
|
+
export interface ListAccountsOptions {
|
|
54
|
+
/** The page size. */
|
|
55
|
+
pageSize?: number;
|
|
56
|
+
/** The page token. */
|
|
57
|
+
pageToken?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The result of listing Solana accounts.
|
|
62
|
+
*/
|
|
63
|
+
export interface ListAccountsResult {
|
|
64
|
+
/** The accounts. */
|
|
65
|
+
accounts: Account[];
|
|
66
|
+
/**
|
|
67
|
+
* The token for the next page of accounts, if any.
|
|
68
|
+
*/
|
|
69
|
+
nextPageToken?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Options for requesting funds from a Solana faucet.
|
|
74
|
+
*/
|
|
75
|
+
export interface RequestFaucetOptions {
|
|
76
|
+
/** The address of the account. */
|
|
77
|
+
address: string;
|
|
78
|
+
/** The token to request funds for. */
|
|
79
|
+
token: "sol" | "usdc";
|
|
80
|
+
/** The idempotency key. */
|
|
81
|
+
idempotencyKey?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Options for signing a Solana message.
|
|
86
|
+
*/
|
|
87
|
+
export interface SignMessageOptions {
|
|
88
|
+
/** The address of the account. */
|
|
89
|
+
address: string;
|
|
90
|
+
/** The message to sign. */
|
|
91
|
+
message: string;
|
|
92
|
+
/** The idempotency key. */
|
|
93
|
+
idempotencyKey?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options for signing a Solana transaction.
|
|
98
|
+
*/
|
|
99
|
+
export interface SignTransactionOptions {
|
|
100
|
+
/** The address of the account. */
|
|
101
|
+
address: string;
|
|
102
|
+
/** The base64 encoded transaction to sign. */
|
|
103
|
+
transaction: string;
|
|
104
|
+
/** The idempotency key. */
|
|
105
|
+
idempotencyKey?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A Solana signature result.
|
|
110
|
+
*/
|
|
111
|
+
export interface SignatureResult {
|
|
112
|
+
/** The signature. */
|
|
113
|
+
signature: string;
|
|
114
|
+
}
|
package/constants.ts
ADDED
package/errors.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeoutError is thrown when an operation times out.
|
|
3
|
+
*/
|
|
4
|
+
export class TimeoutError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Initializes a new TimeoutError instance.
|
|
7
|
+
*
|
|
8
|
+
* @param message - The error message.
|
|
9
|
+
*/
|
|
10
|
+
constructor(message: string = "Timeout Error") {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "TimeoutError";
|
|
13
|
+
if (Error.captureStackTrace) {
|
|
14
|
+
Error.captureStackTrace(this, TimeoutError);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
2
|
+
import Axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
3
|
+
|
|
4
|
+
import { withAuth } from "../auth/hooks/axios/index.js";
|
|
5
|
+
import { ERROR_DOCS_PAGE_URL } from "../constants.js";
|
|
6
|
+
import {
|
|
7
|
+
isOpenAPIError,
|
|
8
|
+
APIError,
|
|
9
|
+
HttpErrorType,
|
|
10
|
+
UnknownApiError,
|
|
11
|
+
UnknownError,
|
|
12
|
+
} from "./errors.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The options for the CDP API.
|
|
16
|
+
*/
|
|
17
|
+
export type CdpOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* The API key ID or the legacy API key name.
|
|
20
|
+
*
|
|
21
|
+
* Examples:
|
|
22
|
+
* ID format: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
23
|
+
* Legacy name format: 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
24
|
+
*/
|
|
25
|
+
apiKeyId: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The API key secret, using the Ed25519 or legacy EC key format.
|
|
29
|
+
*
|
|
30
|
+
* Examples:
|
|
31
|
+
* Ed25519 key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=='
|
|
32
|
+
* EC key: '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n'
|
|
33
|
+
*/
|
|
34
|
+
apiKeySecret: string;
|
|
35
|
+
|
|
36
|
+
/** The Wallet Secret. Only needed if calling certain Wallet APIs. */
|
|
37
|
+
walletSecret?: string;
|
|
38
|
+
|
|
39
|
+
/** If true, logs API requests and responses to the console. */
|
|
40
|
+
debugging?: boolean;
|
|
41
|
+
|
|
42
|
+
/** The base path for the API. */
|
|
43
|
+
basePath?: string;
|
|
44
|
+
|
|
45
|
+
/** The source for the API request, used for analytics. Defaults to `typescript-client`. */
|
|
46
|
+
source?: string;
|
|
47
|
+
|
|
48
|
+
/** The version of the source for the API request, used for analytics. */
|
|
49
|
+
sourceVersion?: string;
|
|
50
|
+
|
|
51
|
+
/** Optional expiration time in seconds (defaults to 120) */
|
|
52
|
+
expiresIn?: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
let axiosInstance: AxiosInstance;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Configures the CDP client with the given options.
|
|
59
|
+
*
|
|
60
|
+
* @param {CdpOptions} options - The CDP options.
|
|
61
|
+
*/
|
|
62
|
+
export const configure = (options: CdpOptions) => {
|
|
63
|
+
axiosInstance = Axios.create({
|
|
64
|
+
baseURL: options.basePath || "https://api.cdp.coinbase.com/platform",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
axiosInstance = withAuth(axiosInstance, {
|
|
68
|
+
apiKeyId: options.apiKeyId,
|
|
69
|
+
apiKeySecret: options.apiKeySecret,
|
|
70
|
+
source: options.source || "sdk-openapi-client",
|
|
71
|
+
sourceVersion: options.sourceVersion,
|
|
72
|
+
walletSecret: options.walletSecret,
|
|
73
|
+
expiresIn: options.expiresIn,
|
|
74
|
+
debug: options.debugging,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Adds an idempotency key to request config if provided
|
|
80
|
+
*
|
|
81
|
+
* @param config - The Axios request configuration.
|
|
82
|
+
* @param idempotencyKey - The idempotency key.
|
|
83
|
+
* @returns The Axios request configuration with the idempotency key.
|
|
84
|
+
*/
|
|
85
|
+
const addIdempotencyKey = (
|
|
86
|
+
config: AxiosRequestConfig,
|
|
87
|
+
idempotencyKey?: string,
|
|
88
|
+
): AxiosRequestConfig => {
|
|
89
|
+
if (!idempotencyKey) {
|
|
90
|
+
return config;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...config,
|
|
95
|
+
headers: {
|
|
96
|
+
...(config.headers || {}),
|
|
97
|
+
"X-Idempotency-Key": idempotencyKey,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Mutates the given Axios request configuration to add the CDP API key signature
|
|
104
|
+
* to the request headers.
|
|
105
|
+
*
|
|
106
|
+
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
107
|
+
* @param idempotencyKey - The idempotency key.
|
|
108
|
+
* @returns {Promise<T>} A promise that resolves to the response data.
|
|
109
|
+
* @throws {APIError} If the request fails.
|
|
110
|
+
*/
|
|
111
|
+
export const cdpApiClient = async <T>(
|
|
112
|
+
config: AxiosRequestConfig,
|
|
113
|
+
idempotencyKey?: string,
|
|
114
|
+
): Promise<T> => {
|
|
115
|
+
validateCall(config);
|
|
116
|
+
|
|
117
|
+
// Add idempotency key to the request headers if provided
|
|
118
|
+
const configWithIdempotencyKey = addIdempotencyKey(config, idempotencyKey);
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const response = await axiosInstance(configWithIdempotencyKey);
|
|
122
|
+
return response.data as T;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
125
|
+
if (Axios.isAxiosError(error) && !error.response) {
|
|
126
|
+
throw new UnknownApiError(
|
|
127
|
+
HttpErrorType.unknown,
|
|
128
|
+
error.cause instanceof Error ? error.cause.message : error.message,
|
|
129
|
+
error.cause,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
134
|
+
if (Axios.isAxiosError(error) && error.response) {
|
|
135
|
+
if (isOpenAPIError(error.response.data)) {
|
|
136
|
+
throw new APIError(
|
|
137
|
+
error.response.status,
|
|
138
|
+
error.response.data.errorType,
|
|
139
|
+
error.response.data.errorMessage,
|
|
140
|
+
error.response.data.correlationId,
|
|
141
|
+
error.response.data.errorLink,
|
|
142
|
+
error.cause,
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
const statusCode = error.response.status;
|
|
146
|
+
switch (statusCode) {
|
|
147
|
+
case 401:
|
|
148
|
+
throw new APIError(
|
|
149
|
+
statusCode,
|
|
150
|
+
HttpErrorType.unauthorized,
|
|
151
|
+
"Unauthorized.",
|
|
152
|
+
undefined,
|
|
153
|
+
`${ERROR_DOCS_PAGE_URL}#unauthorized`,
|
|
154
|
+
error.cause,
|
|
155
|
+
);
|
|
156
|
+
case 404:
|
|
157
|
+
throw new APIError(
|
|
158
|
+
statusCode,
|
|
159
|
+
HttpErrorType.not_found,
|
|
160
|
+
"API not found.",
|
|
161
|
+
undefined,
|
|
162
|
+
`${ERROR_DOCS_PAGE_URL}#not_found`,
|
|
163
|
+
error.cause,
|
|
164
|
+
);
|
|
165
|
+
case 502:
|
|
166
|
+
throw new APIError(
|
|
167
|
+
statusCode,
|
|
168
|
+
HttpErrorType.bad_gateway,
|
|
169
|
+
"Bad gateway.",
|
|
170
|
+
undefined,
|
|
171
|
+
`${ERROR_DOCS_PAGE_URL}`,
|
|
172
|
+
error.cause,
|
|
173
|
+
);
|
|
174
|
+
case 503:
|
|
175
|
+
throw new APIError(
|
|
176
|
+
statusCode,
|
|
177
|
+
HttpErrorType.service_unavailable,
|
|
178
|
+
"Service unavailable. Please try again later.",
|
|
179
|
+
undefined,
|
|
180
|
+
`${ERROR_DOCS_PAGE_URL}`,
|
|
181
|
+
error.cause,
|
|
182
|
+
);
|
|
183
|
+
default:
|
|
184
|
+
throw new APIError(
|
|
185
|
+
statusCode,
|
|
186
|
+
HttpErrorType.unexpected_error,
|
|
187
|
+
"An unexpected error occurred.",
|
|
188
|
+
undefined,
|
|
189
|
+
`${ERROR_DOCS_PAGE_URL}`,
|
|
190
|
+
error.cause,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
throw new UnknownError(
|
|
197
|
+
"Something went wrong. Please reach out at https://discord.com/channels/1220414409550336183/1271495764580896789 for help.",
|
|
198
|
+
error instanceof Error ? error : undefined,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Validates the call to the cdpApiClient.
|
|
205
|
+
*
|
|
206
|
+
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
207
|
+
* @throws {Error} If the call is not valid.
|
|
208
|
+
*/
|
|
209
|
+
const validateCall = (config: AxiosRequestConfig) => {
|
|
210
|
+
if (!axiosInstance.getUri() || axiosInstance.getUri() === "") {
|
|
211
|
+
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!config.url || config.url === "") {
|
|
215
|
+
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!config.method || config.method === "") {
|
|
219
|
+
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
220
|
+
}
|
|
221
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Error as OpenAPIError,
|
|
3
|
+
ErrorType as OpenAPIErrorType,
|
|
4
|
+
} from "./generated/coinbaseDeveloperPlatformAPIs.schemas.js";
|
|
5
|
+
|
|
6
|
+
export const HttpErrorType = {
|
|
7
|
+
unexpected_error: "unexpected_error",
|
|
8
|
+
unauthorized: "unauthorized",
|
|
9
|
+
not_found: "not_found",
|
|
10
|
+
bad_gateway: "bad_gateway",
|
|
11
|
+
service_unavailable: "service_unavailable",
|
|
12
|
+
unknown: "unknown",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export type HttpErrorType = (typeof HttpErrorType)[keyof typeof HttpErrorType];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extended error codes that include both OpenAPI errors and network errors
|
|
19
|
+
*/
|
|
20
|
+
export type APIErrorType = OpenAPIErrorType | HttpErrorType;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extended API error that encompasses both OpenAPI errors and other API-related errors
|
|
24
|
+
*/
|
|
25
|
+
export class APIError extends Error {
|
|
26
|
+
statusCode: number;
|
|
27
|
+
errorType: APIErrorType;
|
|
28
|
+
errorMessage: string;
|
|
29
|
+
correlationId?: string;
|
|
30
|
+
errorLink?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Constructor for the APIError class
|
|
34
|
+
*
|
|
35
|
+
* @param statusCode - The HTTP status code
|
|
36
|
+
* @param errorType - The type of error
|
|
37
|
+
* @param errorMessage - The error message
|
|
38
|
+
* @param correlationId - The correlation ID
|
|
39
|
+
* @param errorLink - URL to documentation about this error
|
|
40
|
+
* @param cause - The cause of the error
|
|
41
|
+
*/
|
|
42
|
+
constructor(
|
|
43
|
+
statusCode: number,
|
|
44
|
+
errorType: APIErrorType,
|
|
45
|
+
errorMessage: string,
|
|
46
|
+
correlationId?: string,
|
|
47
|
+
errorLink?: string,
|
|
48
|
+
cause?: Error,
|
|
49
|
+
) {
|
|
50
|
+
super(errorMessage, { cause });
|
|
51
|
+
this.name = "APIError";
|
|
52
|
+
this.statusCode = statusCode;
|
|
53
|
+
this.errorType = errorType;
|
|
54
|
+
this.errorMessage = errorMessage;
|
|
55
|
+
|
|
56
|
+
// Only set correlationId if it's defined
|
|
57
|
+
if (correlationId !== undefined) {
|
|
58
|
+
this.correlationId = correlationId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Only set errorLink if it's defined
|
|
62
|
+
if (errorLink !== undefined) {
|
|
63
|
+
this.errorLink = errorLink;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Convert the error to a JSON object, excluding undefined properties
|
|
69
|
+
*
|
|
70
|
+
* @returns The error as a JSON object
|
|
71
|
+
*/
|
|
72
|
+
toJSON() {
|
|
73
|
+
return {
|
|
74
|
+
name: this.name,
|
|
75
|
+
statusCode: this.statusCode,
|
|
76
|
+
errorType: this.errorType,
|
|
77
|
+
errorMessage: this.errorMessage,
|
|
78
|
+
...(this.correlationId && { correlationId: this.correlationId }),
|
|
79
|
+
...(this.errorLink && { errorLink: this.errorLink }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Error thrown when an Axios request is made but no response is received
|
|
86
|
+
*/
|
|
87
|
+
export class UnknownApiError extends APIError {
|
|
88
|
+
/**
|
|
89
|
+
* Constructor for the UnknownApiError class
|
|
90
|
+
*
|
|
91
|
+
* @param errorType - The type of error
|
|
92
|
+
* @param errorMessage - The error message
|
|
93
|
+
* @param cause - The cause of the error
|
|
94
|
+
*/
|
|
95
|
+
constructor(errorType: APIErrorType, errorMessage: string, cause?: Error) {
|
|
96
|
+
super(0, errorType, errorMessage, undefined, undefined, cause);
|
|
97
|
+
this.name = "UnknownApiError";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Error thrown when an error is not known
|
|
103
|
+
*/
|
|
104
|
+
export class UnknownError extends Error {
|
|
105
|
+
/**
|
|
106
|
+
* Constructor for the UnknownError class
|
|
107
|
+
*
|
|
108
|
+
* @param message - The error message
|
|
109
|
+
* @param cause - The cause of the error
|
|
110
|
+
*/
|
|
111
|
+
constructor(message: string, cause?: Error) {
|
|
112
|
+
super(message, { cause });
|
|
113
|
+
this.name = "UnknownError";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Type guard to check if an object is an OpenAPIError
|
|
119
|
+
*
|
|
120
|
+
* @param obj - The object to check
|
|
121
|
+
* @returns True if the object is an OpenAPIError
|
|
122
|
+
*/
|
|
123
|
+
export function isOpenAPIError(obj: unknown): obj is OpenAPIError {
|
|
124
|
+
return (
|
|
125
|
+
obj !== null &&
|
|
126
|
+
typeof obj === "object" &&
|
|
127
|
+
"errorType" in obj &&
|
|
128
|
+
typeof (obj as OpenAPIError).errorType === "string" &&
|
|
129
|
+
"errorMessage" in obj &&
|
|
130
|
+
typeof (obj as OpenAPIError).errorMessage === "string"
|
|
131
|
+
);
|
|
132
|
+
}
|