@coinbase/cdp-sdk 1.1.2 → 1.2.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 +79 -0
- package/LICENSE +21 -0
- 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 +7 -6
- 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 +3 -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/{dist → _cjs}/client/cdp.js +13 -8
- package/_cjs/client/cdp.js.map +1 -0
- package/{dist → _cjs}/client/evm/evm.js +26 -25
- 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/{dist → _cjs}/openapi-client/cdpApiClient.js +18 -14
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -0
- package/{dist → _cjs}/openapi-client/errors.js +6 -0
- package/_cjs/openapi-client/errors.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +31 -30
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/evm-accounts/evm-accounts.js +46 -41
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/evm-accounts/evm-accounts.msw.js +73 -40
- 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 +69 -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/{dist → _cjs}/openapi-client/generated/faucets/faucets.js +18 -13
- 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 +5 -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 +12 -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 +84 -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 +71 -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/_esm/client/cdp.js +95 -0
- package/_esm/client/cdp.js.map +1 -0
- package/_esm/client/evm/evm.js +518 -0
- 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 +112 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -0
- package/_esm/openapi-client/errors.js +71 -0
- package/_esm/openapi-client/errors.js.map +1 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +52 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +80 -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 +128 -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 +60 -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/faucets/faucets.js +51 -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 +5 -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 +27 -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 +1 -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 +4 -3
- package/_types/client/evm/evm.d.ts.map +1 -0
- package/{dist → _types}/client/evm/evm.types.d.ts +7 -6
- 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 +2 -1
- package/_types/openapi-client/errors.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +13 -12
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-accounts/evm-accounts.d.ts +24 -23
- 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 +3 -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 +21 -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/{dist → _types}/openapi-client/generated/faucets/faucets.d.ts +9 -8
- 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 +5 -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 +56 -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/{dist → _types}/types/misc.d.ts +1 -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 +123 -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 +120 -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 +113 -0
- package/client/evm/evm.ts +606 -0
- package/client/evm/evm.types.ts +303 -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 +214 -0
- package/openapi-client/errors.ts +96 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +411 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +242 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +150 -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 +131 -0
- package/openapi-client/generated/faucets/faucets.msw.ts +76 -0
- package/openapi-client/generated/faucets/faucets.ts +83 -0
- package/openapi-client/generated/index.msw.ts +4 -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 +32 -0
- package/package.json +31 -66
- package/types/calls.ts +40 -0
- package/types/contract.ts +126 -0
- package/types/misc.ts +5 -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/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
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
import { createPrivateKey } from "crypto";
|
|
3
|
+
|
|
4
|
+
import { SignJWT, importPKCS8, importJWK, JWTPayload } from "jose";
|
|
5
|
+
|
|
6
|
+
import { InvalidWalletSecretFormatError, UndefinedWalletSecretError } from "../errors.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* JwtOptions contains configuration for JWT generation.
|
|
10
|
+
*
|
|
11
|
+
* This interface holds all necessary parameters for generating a JWT token
|
|
12
|
+
* for authenticating with Coinbase's REST APIs. It supports both EC (ES256)
|
|
13
|
+
* and Ed25519 (EdDSA) keys.
|
|
14
|
+
*/
|
|
15
|
+
export interface JwtOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The API key ID
|
|
18
|
+
*
|
|
19
|
+
* Examples:
|
|
20
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
21
|
+
* 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
22
|
+
*/
|
|
23
|
+
apiKeyId: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The API key secret
|
|
27
|
+
*
|
|
28
|
+
* Examples:
|
|
29
|
+
* 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
|
|
30
|
+
* '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
|
|
31
|
+
*/
|
|
32
|
+
apiKeySecret: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The HTTP method for the request (e.g. 'GET', 'POST')
|
|
36
|
+
*/
|
|
37
|
+
requestMethod: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
41
|
+
*/
|
|
42
|
+
requestHost: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The path for the request (e.g. '/platform/v1/wallets')
|
|
46
|
+
*/
|
|
47
|
+
requestPath: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Optional expiration time in seconds (defaults to 120)
|
|
51
|
+
*/
|
|
52
|
+
expiresIn?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* WalletJwtOptions contains configuration for Wallet Auth JWT generation.
|
|
57
|
+
*
|
|
58
|
+
* This interface holds all necessary parameters for generating a Wallet Auth JWT
|
|
59
|
+
* for authenticating with endpoints that require wallet authentication.
|
|
60
|
+
*/
|
|
61
|
+
export interface WalletJwtOptions {
|
|
62
|
+
/**
|
|
63
|
+
* - The Wallet Secret
|
|
64
|
+
*/
|
|
65
|
+
walletSecret: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* - The HTTP method for the request (e.g. 'GET', 'POST')
|
|
69
|
+
*/
|
|
70
|
+
requestMethod: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* - The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
74
|
+
*/
|
|
75
|
+
requestHost: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* - The path for the request (e.g. '/platform/v1/wallets/{wallet_id}/addresses')
|
|
79
|
+
*/
|
|
80
|
+
requestPath: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* - The request data for the request (e.g. { "wallet_id": "1234567890" })
|
|
84
|
+
*/
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
requestData: Record<string, any>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generates a JWT (also known as a Bearer token) for authenticating with Coinbase's REST APIs.
|
|
91
|
+
* Supports both EC (ES256) and Ed25519 (EdDSA) keys.
|
|
92
|
+
*
|
|
93
|
+
* @param options - The configuration options for generating the JWT
|
|
94
|
+
* @returns The generated JWT (Bearer token) string
|
|
95
|
+
* @throws {Error} If required parameters are missing, invalid, or if JWT signing fails
|
|
96
|
+
*/
|
|
97
|
+
export async function generateJwt(options: JwtOptions): Promise<string> {
|
|
98
|
+
// Validate required parameters
|
|
99
|
+
if (!options.apiKeyId) {
|
|
100
|
+
throw new Error("Key name is required");
|
|
101
|
+
}
|
|
102
|
+
if (!options.apiKeySecret) {
|
|
103
|
+
throw new Error("Private key is required");
|
|
104
|
+
}
|
|
105
|
+
if (!options.requestMethod || !options.requestHost || !options.requestPath) {
|
|
106
|
+
throw new Error("Request details (method, host, path) are required");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const now = Math.floor(Date.now() / 1000);
|
|
110
|
+
const expiresIn = options.expiresIn || 120; // Default to 120 seconds if not specified
|
|
111
|
+
const uri = `${options.requestMethod} ${options.requestHost}${options.requestPath}`;
|
|
112
|
+
|
|
113
|
+
// Prepare the JWT payload
|
|
114
|
+
const claims = {
|
|
115
|
+
sub: options.apiKeyId,
|
|
116
|
+
iss: "cdp",
|
|
117
|
+
aud: ["cdp_service"],
|
|
118
|
+
uris: [uri],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// Generate random nonce for the header
|
|
122
|
+
const randomNonce = nonce();
|
|
123
|
+
|
|
124
|
+
// Determine if we're using EC or Edwards key based on the key format
|
|
125
|
+
if (isValidECKey(options.apiKeySecret)) {
|
|
126
|
+
return await buildECJWT(
|
|
127
|
+
options.apiKeySecret,
|
|
128
|
+
options.apiKeyId,
|
|
129
|
+
claims,
|
|
130
|
+
now,
|
|
131
|
+
expiresIn,
|
|
132
|
+
randomNonce,
|
|
133
|
+
);
|
|
134
|
+
} else if (isValidEd25519Key(options.apiKeySecret)) {
|
|
135
|
+
return await buildEdwardsJWT(
|
|
136
|
+
options.apiKeySecret,
|
|
137
|
+
options.apiKeyId,
|
|
138
|
+
claims,
|
|
139
|
+
now,
|
|
140
|
+
expiresIn,
|
|
141
|
+
randomNonce,
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error("Invalid key format - must be either PEM EC key or base64 Ed25519 key");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Generates a wallet authentication JWT for the given API endpoint URL.
|
|
150
|
+
* Used for authenticating with specific endpoints that require wallet authentication.
|
|
151
|
+
*
|
|
152
|
+
* @param options - The configuration options for generating the JWT
|
|
153
|
+
* @returns The generated JWT (Bearer token) string
|
|
154
|
+
* @throws {UndefinedWalletSecretError} If the Wallet Secret is not defined.
|
|
155
|
+
* @throws {InvalidWalletSecretFormatError} If the private key is not in the correct format or signing fails.
|
|
156
|
+
*/
|
|
157
|
+
export async function generateWalletJwt(options: WalletJwtOptions): Promise<string> {
|
|
158
|
+
if (!options.walletSecret) {
|
|
159
|
+
throw new UndefinedWalletSecretError("Wallet Secret is not defined");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const uri = `${options.requestMethod} ${options.requestHost}${options.requestPath}`;
|
|
163
|
+
const now = Math.floor(Date.now() / 1000);
|
|
164
|
+
|
|
165
|
+
const claims: JWTPayload = {
|
|
166
|
+
uris: [uri],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
if (Object.keys(options.requestData).length > 0) {
|
|
170
|
+
claims.req = options.requestData;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const ecKey = createPrivateKey({
|
|
175
|
+
key: options.walletSecret,
|
|
176
|
+
format: "der",
|
|
177
|
+
type: "pkcs8",
|
|
178
|
+
encoding: "base64",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return await new SignJWT(claims)
|
|
182
|
+
.setProtectedHeader({ alg: "ES256", typ: "JWT" })
|
|
183
|
+
.setIssuedAt(now)
|
|
184
|
+
.setNotBefore(now)
|
|
185
|
+
.setJti(nonce())
|
|
186
|
+
.sign(ecKey);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw new InvalidWalletSecretFormatError("Could not create the EC key: " + error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Determines if a string could be a valid Ed25519 key
|
|
194
|
+
*
|
|
195
|
+
* @param str - The string to test
|
|
196
|
+
* @returns True if the string could be a valid Ed25519 key, false otherwise
|
|
197
|
+
*/
|
|
198
|
+
function isValidEd25519Key(str: string): boolean {
|
|
199
|
+
try {
|
|
200
|
+
const decoded = Buffer.from(str, "base64");
|
|
201
|
+
return decoded.length === 64;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Determines if a string is a valid EC private key in PEM format
|
|
209
|
+
*
|
|
210
|
+
* @param str - The string to test
|
|
211
|
+
* @returns True if the string is a valid EC private key in PEM format
|
|
212
|
+
*/
|
|
213
|
+
function isValidECKey(str: string): boolean {
|
|
214
|
+
try {
|
|
215
|
+
// Attempt to create a private key object - will throw if invalid
|
|
216
|
+
const key = createPrivateKey(str);
|
|
217
|
+
// Check if it's an EC key by examining its asymmetric key type
|
|
218
|
+
return key.asymmetricKeyType === "ec";
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Builds a JWT using an EC key.
|
|
226
|
+
*
|
|
227
|
+
* @param privateKey - The EC private key in PEM format
|
|
228
|
+
* @param keyName - The key name/ID
|
|
229
|
+
* @param claims - The JWT claims
|
|
230
|
+
* @param now - Current timestamp in seconds
|
|
231
|
+
* @param expiresIn - Number of seconds until the token expires
|
|
232
|
+
* @param nonce - Random nonce for the JWT header
|
|
233
|
+
* @returns A JWT token signed with an EC key
|
|
234
|
+
* @throws {Error} If key conversion, import, or signing fails
|
|
235
|
+
*/
|
|
236
|
+
async function buildECJWT(
|
|
237
|
+
privateKey: string,
|
|
238
|
+
keyName: string,
|
|
239
|
+
claims: JWTPayload,
|
|
240
|
+
now: number,
|
|
241
|
+
expiresIn: number,
|
|
242
|
+
nonce: string,
|
|
243
|
+
): Promise<string> {
|
|
244
|
+
try {
|
|
245
|
+
// Convert to PKCS8 format
|
|
246
|
+
const keyObj = createPrivateKey(privateKey);
|
|
247
|
+
const pkcs8Key = keyObj.export({ type: "pkcs8", format: "pem" }).toString();
|
|
248
|
+
|
|
249
|
+
// Import the key for signing
|
|
250
|
+
const ecKey = await importPKCS8(pkcs8Key, "ES256");
|
|
251
|
+
|
|
252
|
+
// Sign and return the JWT
|
|
253
|
+
return await new SignJWT(claims)
|
|
254
|
+
.setProtectedHeader({ alg: "ES256", kid: keyName, typ: "JWT", nonce })
|
|
255
|
+
.setIssuedAt(Math.floor(now))
|
|
256
|
+
.setNotBefore(Math.floor(now))
|
|
257
|
+
.setExpirationTime(Math.floor(now + expiresIn))
|
|
258
|
+
.sign(ecKey);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw new Error(`Failed to generate EC JWT: ${(error as Error).message}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Builds a JWT using an Ed25519 key.
|
|
266
|
+
*
|
|
267
|
+
* @param privateKey - The Ed25519 private key in base64 format
|
|
268
|
+
* @param keyName - The key name/ID
|
|
269
|
+
* @param claims - The JWT claims
|
|
270
|
+
* @param now - Current timestamp in seconds
|
|
271
|
+
* @param expiresIn - Number of seconds until the token expires
|
|
272
|
+
* @param nonce - Random nonce for the JWT header
|
|
273
|
+
* @returns A JWT token using an Ed25519 key
|
|
274
|
+
* @throws {Error} If key parsing, import, or signing fails
|
|
275
|
+
*/
|
|
276
|
+
async function buildEdwardsJWT(
|
|
277
|
+
privateKey: string,
|
|
278
|
+
keyName: string,
|
|
279
|
+
claims: JWTPayload,
|
|
280
|
+
now: number,
|
|
281
|
+
expiresIn: number,
|
|
282
|
+
nonce: string,
|
|
283
|
+
): Promise<string> {
|
|
284
|
+
try {
|
|
285
|
+
// Decode the base64 key (expecting 64 bytes: 32 for seed + 32 for public key)
|
|
286
|
+
const decoded = Buffer.from(privateKey, "base64");
|
|
287
|
+
if (decoded.length !== 64) {
|
|
288
|
+
throw new Error("Invalid Ed25519 key length");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const seed = decoded.subarray(0, 32);
|
|
292
|
+
const publicKey = decoded.subarray(32);
|
|
293
|
+
|
|
294
|
+
// Create JWK from the key components
|
|
295
|
+
const jwk = {
|
|
296
|
+
kty: "OKP",
|
|
297
|
+
crv: "Ed25519",
|
|
298
|
+
d: seed.toString("base64url"),
|
|
299
|
+
x: publicKey.toString("base64url"),
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// Import the key for signing
|
|
303
|
+
const key = await importJWK(jwk, "EdDSA");
|
|
304
|
+
|
|
305
|
+
// Sign and return the JWT
|
|
306
|
+
return await new SignJWT(claims)
|
|
307
|
+
.setProtectedHeader({ alg: "EdDSA", kid: keyName, typ: "JWT", nonce })
|
|
308
|
+
.setIssuedAt(Math.floor(now))
|
|
309
|
+
.setNotBefore(Math.floor(now))
|
|
310
|
+
.setExpirationTime(Math.floor(now + expiresIn))
|
|
311
|
+
.sign(key);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
throw new Error(`Failed to generate Ed25519 JWT: ${(error as Error).message}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Generates a random nonce for the JWT.
|
|
319
|
+
*
|
|
320
|
+
* @returns {string} The generated nonce.
|
|
321
|
+
*/
|
|
322
|
+
function nonce(): string {
|
|
323
|
+
return crypto.randomBytes(16).toString("hex");
|
|
324
|
+
}
|
package/client/cdp.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { CdpOpenApiClient } from "../openapi-client/index.js";
|
|
2
|
+
import { version } from "../version.js";
|
|
3
|
+
import { EvmClient } from "./evm/evm.js";
|
|
4
|
+
import { SolanaClient } from "./solana/solana.js";
|
|
5
|
+
|
|
6
|
+
interface CdpClientOptions {
|
|
7
|
+
/** The API key ID. */
|
|
8
|
+
apiKeyId?: string;
|
|
9
|
+
/** The API key secret. */
|
|
10
|
+
apiKeySecret?: string;
|
|
11
|
+
/** The wallet secret. */
|
|
12
|
+
walletSecret?: string;
|
|
13
|
+
/** Whether to enable debugging. */
|
|
14
|
+
debugging?: boolean;
|
|
15
|
+
/** The host URL to connect to. */
|
|
16
|
+
basePath?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The main client for interacting with the CDP API.
|
|
21
|
+
*/
|
|
22
|
+
export class CdpClient {
|
|
23
|
+
/** Namespace containing all EVM methods. */
|
|
24
|
+
public evm: EvmClient;
|
|
25
|
+
|
|
26
|
+
/** Namespace containing all Solana methods. */
|
|
27
|
+
public solana: SolanaClient;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The CdpClient is the main class for interacting with the CDP API.
|
|
31
|
+
*
|
|
32
|
+
* There are a few required parameters that are configured in the [CDP Portal](https://portal.cdp.coinbase.com/projects/api-keys):
|
|
33
|
+
* - **CDP Secret API Key** (`apiKeyId` & `apiKeySecret`): These are used to authenticate requests to the entire suite of
|
|
34
|
+
* APIs offered on Coinbase Developer Platform.
|
|
35
|
+
* [Read more about CDP API keys](https://docs.cdp.coinbase.com/get-started/docs/cdp-api-keys).
|
|
36
|
+
* - **Wallet Secret** (`walletSecret`): This secret is used specifically to authenticate requests to `POST`, and `DELETE`
|
|
37
|
+
* endpoints in the EVM and Solana Account APIs.
|
|
38
|
+
*
|
|
39
|
+
* These parameters can be set as environment variables:
|
|
40
|
+
* ```
|
|
41
|
+
* CDP_API_KEY_ID=your-api-key-id
|
|
42
|
+
* CDP_API_KEY_SECRET=your-api-key-secret
|
|
43
|
+
* CDP_WALLET_SECRET=your-wallet-secret
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Or passed as options to the constructor:
|
|
47
|
+
*
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const cdp = new CdpClient({
|
|
50
|
+
* apiKeyId: "your-api-key-id",
|
|
51
|
+
* apiKeySecret: "your-api-key-secret",
|
|
52
|
+
* walletSecret: "your-wallet-secret",
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* The CdpClient is namespaced by chain type: `evm` or `solana`.
|
|
57
|
+
*
|
|
58
|
+
* As an example, to create a new EVM account, use `cdp.evm.createAccount()`.
|
|
59
|
+
*
|
|
60
|
+
* To create a new Solana account, use `cdp.solana.createAccount()`.
|
|
61
|
+
*
|
|
62
|
+
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
63
|
+
*/
|
|
64
|
+
constructor(options: CdpClientOptions = {}) {
|
|
65
|
+
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_ID ?? process.env.CDP_API_KEY_NAME;
|
|
66
|
+
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
67
|
+
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
|
68
|
+
|
|
69
|
+
if (!apiKeyId || !apiKeySecret) {
|
|
70
|
+
throw new Error(`
|
|
71
|
+
\nMissing required CDP Secret API Key configuration parameters.
|
|
72
|
+
|
|
73
|
+
You can set them as environment variables:
|
|
74
|
+
|
|
75
|
+
CDP_API_KEY_ID=your-api-key-id
|
|
76
|
+
CDP_API_KEY_SECRET=your-api-key-secret
|
|
77
|
+
|
|
78
|
+
You can also pass them as options to the constructor:
|
|
79
|
+
|
|
80
|
+
const cdp = new CdpClient({
|
|
81
|
+
apiKeyId: "your-api-key-id",
|
|
82
|
+
apiKeySecret: "your-api-key-secret",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
If you're performing write operations, make sure to also set your wallet secret:
|
|
86
|
+
|
|
87
|
+
CDP_WALLET_SECRET=your-wallet-secret
|
|
88
|
+
|
|
89
|
+
This is also available as an option to the constructor:
|
|
90
|
+
|
|
91
|
+
const cdp = new CdpClient({
|
|
92
|
+
apiKeyId: "your-api-key-id",
|
|
93
|
+
apiKeySecret: "your-api-key-secret",
|
|
94
|
+
walletSecret: "your-wallet-secret",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescript/README.md#api-keys.
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
CdpOpenApiClient.configure({
|
|
102
|
+
...options,
|
|
103
|
+
apiKeyId,
|
|
104
|
+
apiKeySecret,
|
|
105
|
+
walletSecret,
|
|
106
|
+
source: "sdk",
|
|
107
|
+
sourceVersion: version,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
this.evm = new EvmClient();
|
|
111
|
+
this.solana = new SolanaClient();
|
|
112
|
+
}
|
|
113
|
+
}
|