@coinbase/cdp-sdk 1.1.1 → 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 +30 -28
- 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,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a EvmSmartAccount instance from an existing EvmSmartAccount and owner.
|
|
3
|
+
* Use this to interact with previously deployed EvmSmartAccounts, rather than creating new ones.
|
|
4
|
+
*
|
|
5
|
+
* The owner must be the original owner of the evm smart account.
|
|
6
|
+
*
|
|
7
|
+
* @param {ToEvmSmartAccountOptions} options - Configuration options.
|
|
8
|
+
* @param {EvmSmartAccount} options.smartAccount - The deployed evm smart account.
|
|
9
|
+
* @param {EvmAccount} options.owner - The owner which signs for the smart account.
|
|
10
|
+
* @returns {EvmSmartAccount} A configured EvmSmartAccount instance ready for user operation submission.
|
|
11
|
+
* @throws {Error} If the account is not an original owner of the smart account.
|
|
12
|
+
*/
|
|
13
|
+
export function toEvmSmartAccount(options) {
|
|
14
|
+
const account = {
|
|
15
|
+
address: options.smartAccount.address,
|
|
16
|
+
owners: [options.owner],
|
|
17
|
+
name: options.smartAccount.name,
|
|
18
|
+
type: "evm-smart",
|
|
19
|
+
};
|
|
20
|
+
return account;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=toEvmSmartAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IACjE,MAAM,OAAO,GAAoB;QAC/B,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,OAAkB;QAChD,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../accounts/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a user operation to the network.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { sendUserOperation } from "@coinbase/cdp-sdk";
|
|
8
|
+
* import { parseEther } from "viem";
|
|
9
|
+
* import { CdpClient } from "@coinbase/cdp-sdk";
|
|
10
|
+
*
|
|
11
|
+
* const client = new CdpClient({
|
|
12
|
+
* apiKeyId: "your-api-key-id",
|
|
13
|
+
* apiKeySecret: "your-api-key-secret",
|
|
14
|
+
* walletSecret: "your-wallet-secret",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const ethAccount = await client.createEvmServerAccount()
|
|
18
|
+
* const smartAccount = await client.createEvmSmartAccount({ owner: ethAccount })
|
|
19
|
+
*
|
|
20
|
+
* const result = await sendUserOperation(client, smartAccount, {
|
|
21
|
+
* calls: [
|
|
22
|
+
* {
|
|
23
|
+
* abi: erc20Abi,
|
|
24
|
+
* functionName: "transfer",
|
|
25
|
+
* args: [to, amount],
|
|
26
|
+
* },
|
|
27
|
+
* {
|
|
28
|
+
* to: "0x1234567890123456789012345678901234567890",
|
|
29
|
+
* data: "0x",
|
|
30
|
+
* value: parseEther("0.0000005"),
|
|
31
|
+
* },
|
|
32
|
+
* ],
|
|
33
|
+
* network: "base-sepolia",
|
|
34
|
+
* paymasterUrl: "https://api.developer.coinbase.com/rpc/v1/base/someapikey",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param {CdpOpenApiClientType} client - The client to use to send the user operation.
|
|
39
|
+
* @param {EvmSmartAccount} smartAccount - The smart account to send the user operation from.
|
|
40
|
+
* @param {SendUserOperationOptions<T>} options - The options for the user operation.
|
|
41
|
+
* @returns {Promise<SendUserOperationReturnType>} The result of the user operation.
|
|
42
|
+
*/
|
|
43
|
+
export async function sendUserOperation(client, smartAccount, options) {
|
|
44
|
+
const { calls, network, paymasterUrl } = options;
|
|
45
|
+
if (calls.length === 0) {
|
|
46
|
+
throw new Error("Calls array is empty");
|
|
47
|
+
}
|
|
48
|
+
const encodedCalls = calls.map(call => {
|
|
49
|
+
const value = (call.value ?? BigInt(0)).toString();
|
|
50
|
+
if ("abi" in call && call.abi && "functionName" in call) {
|
|
51
|
+
return {
|
|
52
|
+
to: call.to,
|
|
53
|
+
data: encodeFunctionData({
|
|
54
|
+
abi: call.abi,
|
|
55
|
+
functionName: call.functionName,
|
|
56
|
+
args: call.args,
|
|
57
|
+
}),
|
|
58
|
+
value,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
to: call.to,
|
|
63
|
+
data: call.data ?? "0x",
|
|
64
|
+
value,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
const createOpResponse = await client.prepareUserOperation(smartAccount.address, {
|
|
68
|
+
network,
|
|
69
|
+
calls: encodedCalls,
|
|
70
|
+
paymasterUrl,
|
|
71
|
+
});
|
|
72
|
+
const owner = smartAccount.owners[0];
|
|
73
|
+
const signature = await owner.sign({
|
|
74
|
+
hash: createOpResponse.userOpHash,
|
|
75
|
+
});
|
|
76
|
+
const broadcastResponse = await client.sendUserOperation(smartAccount.address, createOpResponse.userOpHash, {
|
|
77
|
+
signature,
|
|
78
|
+
}, options.idempotencyKey);
|
|
79
|
+
return {
|
|
80
|
+
smartAccountAddress: smartAccount.address,
|
|
81
|
+
status: broadcastResponse.status,
|
|
82
|
+
userOpHash: createOpResponse.userOpHash,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sendUserOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendUserOperation.js","sourceRoot":"","sources":["../../../actions/evm/sendUserOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AA8D1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,YAA6B,EAC7B,OAAoC;IAEpC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACpC,MAAM,KAAK,GAAG,CAAC,IAAI,CA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Status, } from "../../openapi-client/index.js";
|
|
2
|
+
import { wait } from "../../utils/wait.js";
|
|
3
|
+
/**
|
|
4
|
+
* Waits for a user operation to complete or fail.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { waitForUserOperation } from "@coinbase/cdp-sdk";
|
|
9
|
+
*
|
|
10
|
+
* const result = await waitForUserOperation(client, {
|
|
11
|
+
* userOpHash: "0x1234567890123456789012345678901234567890",
|
|
12
|
+
* smartAccountAddress: "0x1234567890123456789012345678901234567890",
|
|
13
|
+
* waitOptions: {
|
|
14
|
+
* timeoutSeconds: 30,
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param {CdpOpenApiClientType} client - The client to use to wait for the user operation.
|
|
20
|
+
* @param {WaitForUserOperationOptions} options - The options for the wait operation.
|
|
21
|
+
* @returns {Promise<WaitForUserOperationReturnType>} The result of the user operation.
|
|
22
|
+
*/
|
|
23
|
+
export async function waitForUserOperation(client, options) {
|
|
24
|
+
const { userOpHash, smartAccountAddress } = options;
|
|
25
|
+
const reload = async () => {
|
|
26
|
+
const response = await client.getUserOperation(smartAccountAddress, userOpHash);
|
|
27
|
+
return response;
|
|
28
|
+
};
|
|
29
|
+
const transform = (operation) => {
|
|
30
|
+
if (operation.status === EvmUserOperationStatus.failed) {
|
|
31
|
+
return {
|
|
32
|
+
smartAccountAddress: smartAccountAddress,
|
|
33
|
+
status: EvmUserOperationStatus.failed,
|
|
34
|
+
userOpHash: operation.userOpHash,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else if (operation.status === EvmUserOperationStatus.complete) {
|
|
38
|
+
return {
|
|
39
|
+
smartAccountAddress: smartAccountAddress,
|
|
40
|
+
transactionHash: operation.transactionHash,
|
|
41
|
+
status: EvmUserOperationStatus.complete,
|
|
42
|
+
userOpHash: operation.userOpHash,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error("User operation is not terminal");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const waitOptions = options.waitOptions || {
|
|
50
|
+
timeoutSeconds: 30,
|
|
51
|
+
};
|
|
52
|
+
return await wait(reload, isTerminal, transform, waitOptions);
|
|
53
|
+
}
|
|
54
|
+
const isTerminal = (operation) => {
|
|
55
|
+
return (operation.status === EvmUserOperationStatus.complete ||
|
|
56
|
+
operation.status === EvmUserOperationStatus.failed);
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=waitForUserOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForUserOperation.js","sourceRoot":"","sources":["../../../actions/evm/waitForUserOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAGvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,IAAI,EAAe,MAAM,qBAAqB,CAAC;AA+CxD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA4B,EAC5B,OAAoC;IAEpC,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IAEpD,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;QACxB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;QAChF,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,SAA2B,EAAkC,EAAE;QAChF,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC,MAAM,EAAE,CAAC;YACvD,OAAO;gBACL,mBAAmB,EAAE,mBAAmB;gBACxC,MAAM,EAAE,sBAAsB,CAAC,MAAM;gBACrC,UAAU,EAAE,SAAS,CAAC,UAAiB;aACd,CAAC;QAC9B,CAAC;aAAM,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC,QAAQ,EAAE,CAAC;YAChE,OAAO;gBACL,mBAAmB,EAAE,mBAAmB;gBACxC,eAAe,EAAE,SAAS,CAAC,eAAgB;gBAC3C,MAAM,EAAE,sBAAsB,CAAC,QAAQ;gBACvC,UAAU,EAAE,SAAS,CAAC,UAAiB;aACX,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI;QACzC,cAAc,EAAE,EAAE;KACnB,CAAC;IAEF,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,SAA2B,EAAW,EAAE;IAC1D,OAAO,CACL,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC,QAAQ;QACpD,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC,MAAM,CACnD,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import md5 from "md5";
|
|
2
|
+
import { CdpClient } from "./client/cdp.js";
|
|
3
|
+
import { EvmClient } from "./client/evm/evm.js";
|
|
4
|
+
import { SolanaClient } from "./client/solana/solana.js";
|
|
5
|
+
/**
|
|
6
|
+
* Sends an analytics event to the default endpoint
|
|
7
|
+
*
|
|
8
|
+
* @param event - The event data containing event-specific fields
|
|
9
|
+
* @returns Promise that resolves when the event is sent
|
|
10
|
+
*/
|
|
11
|
+
export async function sendEvent(event) {
|
|
12
|
+
const timestamp = Date.now();
|
|
13
|
+
const enhancedEvent = {
|
|
14
|
+
event_type: event.name,
|
|
15
|
+
platform: "server",
|
|
16
|
+
event_properties: {
|
|
17
|
+
platform: "server",
|
|
18
|
+
project_name: "cdp-sdk",
|
|
19
|
+
time_start: timestamp,
|
|
20
|
+
cdp_sdk_language: "typescript",
|
|
21
|
+
...event,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const events = [enhancedEvent];
|
|
25
|
+
const stringifiedEventData = JSON.stringify(events);
|
|
26
|
+
const uploadTime = timestamp.toString();
|
|
27
|
+
const checksum = md5(stringifiedEventData + uploadTime);
|
|
28
|
+
const analyticsServiceData = {
|
|
29
|
+
e: stringifiedEventData,
|
|
30
|
+
checksum,
|
|
31
|
+
};
|
|
32
|
+
const apiEndpoint = "https://cca-lite.coinbase.com";
|
|
33
|
+
const eventPath = "/amp";
|
|
34
|
+
const eventEndPoint = `${apiEndpoint}${eventPath}`;
|
|
35
|
+
const response = await fetch(eventEndPoint, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
mode: "no-cors",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(analyticsServiceData),
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wraps all methods of a class with error tracking.
|
|
49
|
+
*
|
|
50
|
+
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
51
|
+
*/
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
function wrapClassWithErrorTracking(ClassToWrap) {
|
|
54
|
+
const methodNames = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
55
|
+
for (const methodName of methodNames) {
|
|
56
|
+
const originalMethod = ClassToWrap.prototype[methodName];
|
|
57
|
+
ClassToWrap.prototype[methodName] = async function (...args) {
|
|
58
|
+
try {
|
|
59
|
+
return await originalMethod.apply(this, args);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!(error instanceof Error)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const { message, stack } = error;
|
|
66
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
67
|
+
sendEvent({
|
|
68
|
+
method: String(methodName),
|
|
69
|
+
message,
|
|
70
|
+
stack,
|
|
71
|
+
name: "error",
|
|
72
|
+
}).catch(() => {
|
|
73
|
+
// ignore error
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
wrapClassWithErrorTracking(CdpClient);
|
|
82
|
+
wrapClassWithErrorTracking(EvmClient);
|
|
83
|
+
wrapClassWithErrorTracking(SolanaClient);
|
|
84
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../analytics.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AA0BzD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAgB;IAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,MAAM,aAAa,GAAG;QACpB,UAAU,EAAE,KAAK,CAAC,IAAI;QACtB,QAAQ,EAAE,QAAQ;QAClB,gBAAgB,EAAE;YAChB,QAAQ,EAAE,QAAQ;YAClB,YAAY,EAAE,SAAS;YACvB,UAAU,EAAE,SAAS;YACrB,gBAAgB,EAAE,YAAY;YAC9B,GAAG,KAAK;SACT;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,aAAa,CAAC,CAAC;IAC/B,MAAM,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpD,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EAAE,IAAI,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;oBAC9B,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;gBAEjC,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,EAAE,CAAC;oBACvD,SAAS,CAAC;wBACR,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;wBAC1B,OAAO;wBACP,KAAK;wBACL,IAAI,EAAE,OAAO;qBACd,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;wBACZ,eAAe;oBACjB,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,0BAA0B,CAAC,SAAS,CAAC,CAAC;AACtC,0BAA0B,CAAC,SAAS,CAAC,CAAC;AACtC,0BAA0B,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class of errors for capturing stack traces.
|
|
3
|
+
*/
|
|
4
|
+
class BaseError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Base error constructor.
|
|
7
|
+
*
|
|
8
|
+
* @param message - The message to display.
|
|
9
|
+
*/
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
if (Error.captureStackTrace) {
|
|
14
|
+
Error.captureStackTrace(this, this.constructor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An error for invalid API key format.
|
|
20
|
+
*/
|
|
21
|
+
export class InvalidAPIKeyFormatError extends BaseError {
|
|
22
|
+
/**
|
|
23
|
+
* Invalid API key format error constructor.
|
|
24
|
+
*
|
|
25
|
+
* @param message - The message to display.
|
|
26
|
+
*/
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super("Invalid API key format: " + message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* An error for invalid Wallet Secret format.
|
|
33
|
+
*/
|
|
34
|
+
export class InvalidWalletSecretFormatError extends BaseError {
|
|
35
|
+
/**
|
|
36
|
+
* Invalid Wallet Secret format error constructor.
|
|
37
|
+
*
|
|
38
|
+
* @param message - The message to display.
|
|
39
|
+
*/
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super("Invalid Wallet Secret format: " + message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An error for an undefined Wallet Secret.
|
|
46
|
+
*/
|
|
47
|
+
export class UndefinedWalletSecretError extends BaseError {
|
|
48
|
+
/**
|
|
49
|
+
* Undefined Wallet Secret error constructor.
|
|
50
|
+
*
|
|
51
|
+
* @param message - The message to display.
|
|
52
|
+
*/
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super("Undefined Wallet Secret: " + message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../auth/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,SAAU,SAAQ,KAAK;IAC3B;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IACrD;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,0BAA0B,GAAG,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,SAAS;IAC3D;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,gCAAgC,GAAG,OAAO,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,SAAS;IACvD;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,2BAA2B,GAAG,OAAO,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../auth/hooks/axios/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AxiosHeaders } from "axios";
|
|
2
|
+
import { getAuthHeaders } from "../../utils/http.js";
|
|
3
|
+
/**
|
|
4
|
+
* Axios interceptor for adding the JWT to the Authorization header.
|
|
5
|
+
*
|
|
6
|
+
* @param axiosClient - The Axios client instance to add the interceptor to
|
|
7
|
+
* @param options - Options for the request including API keys and debug flag
|
|
8
|
+
* @returns The modified request configuration with the Authorization header added
|
|
9
|
+
*/
|
|
10
|
+
export function withAuth(axiosClient, options) {
|
|
11
|
+
axiosClient.interceptors.request.use(async (axiosConfig) => {
|
|
12
|
+
const method = axiosConfig.method?.toString().toUpperCase() || "GET";
|
|
13
|
+
if (!axiosConfig.url) {
|
|
14
|
+
throw new Error("URL is required for authentication");
|
|
15
|
+
}
|
|
16
|
+
const fullyQualifiedURL = axiosClient.getUri() + axiosConfig.url;
|
|
17
|
+
// Parse URL to get host and path
|
|
18
|
+
const url = new URL(fullyQualifiedURL);
|
|
19
|
+
// Get authentication headers
|
|
20
|
+
const headers = await getAuthHeaders({
|
|
21
|
+
apiKeyId: options.apiKeyId,
|
|
22
|
+
apiKeySecret: options.apiKeySecret,
|
|
23
|
+
requestMethod: method,
|
|
24
|
+
requestHost: url.host,
|
|
25
|
+
requestPath: url.pathname,
|
|
26
|
+
requestBody: axiosConfig.data,
|
|
27
|
+
walletSecret: options.walletSecret,
|
|
28
|
+
source: options.source,
|
|
29
|
+
sourceVersion: options.sourceVersion,
|
|
30
|
+
expiresIn: options.expiresIn,
|
|
31
|
+
});
|
|
32
|
+
// Add headers to request config
|
|
33
|
+
axiosConfig.headers = new AxiosHeaders({
|
|
34
|
+
...axiosConfig.headers,
|
|
35
|
+
...headers,
|
|
36
|
+
});
|
|
37
|
+
if (options.debug) {
|
|
38
|
+
console.log("Request:", {
|
|
39
|
+
method,
|
|
40
|
+
url: fullyQualifiedURL,
|
|
41
|
+
headers: axiosConfig.headers,
|
|
42
|
+
data: axiosConfig.data,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return axiosConfig;
|
|
46
|
+
});
|
|
47
|
+
if (options.debug) {
|
|
48
|
+
axiosClient.interceptors.response.use(response => {
|
|
49
|
+
console.log("Response:", {
|
|
50
|
+
status: response.status,
|
|
51
|
+
statusText: response.statusText,
|
|
52
|
+
headers: response.headers,
|
|
53
|
+
data: response.data,
|
|
54
|
+
});
|
|
55
|
+
return response;
|
|
56
|
+
}, error => {
|
|
57
|
+
// Ensure we have access to the error response details
|
|
58
|
+
const errorDetails = {
|
|
59
|
+
status: error.response?.status,
|
|
60
|
+
statusText: error.response?.statusText,
|
|
61
|
+
headers: error.response?.headers,
|
|
62
|
+
data: error.response?.data,
|
|
63
|
+
message: error.message,
|
|
64
|
+
};
|
|
65
|
+
console.error("Response Error:", errorDetails);
|
|
66
|
+
return Promise.reject(error);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return axiosClient;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=withAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAuth.js","sourceRoot":"","sources":["../../../../auth/hoo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AO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { generateWalletJwt, generateJwt } from "./jwt.js";
|
|
2
|
+
import { version } from "../../version.js";
|
|
3
|
+
/**
|
|
4
|
+
* Gets authentication headers for a request.
|
|
5
|
+
*
|
|
6
|
+
* @param options - The configuration options for generating auth headers
|
|
7
|
+
* @returns Object containing the authentication headers
|
|
8
|
+
*/
|
|
9
|
+
export async function getAuthHeaders(options) {
|
|
10
|
+
const headers = {};
|
|
11
|
+
// Generate and add JWT token
|
|
12
|
+
const jwt = await generateJwt({
|
|
13
|
+
apiKeyId: options.apiKeyId,
|
|
14
|
+
apiKeySecret: options.apiKeySecret,
|
|
15
|
+
requestMethod: options.requestMethod,
|
|
16
|
+
requestHost: options.requestHost,
|
|
17
|
+
requestPath: options.requestPath,
|
|
18
|
+
expiresIn: options.expiresIn,
|
|
19
|
+
});
|
|
20
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
21
|
+
headers["Content-Type"] = "application/json";
|
|
22
|
+
// Add wallet auth if needed
|
|
23
|
+
if (requiresWalletAuth(options.requestMethod, options.requestPath)) {
|
|
24
|
+
if (!options.walletSecret) {
|
|
25
|
+
throw new Error("Wallet Secret not configured. Please set the CDP_WALLET_SECRET environment variable, or pass it as an option to the CdpClient constructor.");
|
|
26
|
+
}
|
|
27
|
+
const walletAuthToken = await generateWalletJwt({
|
|
28
|
+
walletSecret: options.walletSecret,
|
|
29
|
+
requestMethod: options.requestMethod,
|
|
30
|
+
requestHost: options.requestHost,
|
|
31
|
+
requestPath: options.requestPath,
|
|
32
|
+
requestData: options.requestBody || {},
|
|
33
|
+
});
|
|
34
|
+
headers["X-Wallet-Auth"] = walletAuthToken;
|
|
35
|
+
}
|
|
36
|
+
// Add correlation data
|
|
37
|
+
headers["Correlation-Context"] = getCorrelationData(options.source, options.sourceVersion);
|
|
38
|
+
return headers;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the request indicated by the method and URL requires wallet authentication.
|
|
42
|
+
*
|
|
43
|
+
* @param requestMethod - The HTTP method of the request
|
|
44
|
+
* @param requestPath - The URL path of the request
|
|
45
|
+
* @returns True if the request requires wallet authentication, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
function requiresWalletAuth(requestMethod, requestPath) {
|
|
48
|
+
return (requestPath?.includes("/accounts") && (requestMethod === "POST" || requestMethod === "DELETE"));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns encoded correlation data including the SDK version and language.
|
|
52
|
+
*
|
|
53
|
+
* @param source - The source identifier for the request
|
|
54
|
+
* @param sourceVersion - The version of the source making the request
|
|
55
|
+
* @returns Encoded correlation data as a query string
|
|
56
|
+
*/
|
|
57
|
+
function getCorrelationData(source, sourceVersion) {
|
|
58
|
+
const data = {
|
|
59
|
+
sdk_version: version,
|
|
60
|
+
sdk_language: "typescript",
|
|
61
|
+
source: source || "sdk-auth",
|
|
62
|
+
};
|
|
63
|
+
if (sourceVersion) {
|
|
64
|
+
data["source_version"] = sourceVersion;
|
|
65
|
+
}
|
|
66
|
+
return Object.keys(data)
|
|
67
|
+
.map(key => `${key}=${encodeURIComponent(data[key])}`)
|
|
68
|
+
.join(",");
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../auth/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAiE3C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA8B;IAE9B,MAAM,OAAO,GAA2B,EAAE,CA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