@coinbase/cdp-sdk 1.18.0 → 1.19.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 +12 -0
- package/_cjs/accounts/evm/resolveViemClients.js +39 -2
- package/_cjs/accounts/evm/resolveViemClients.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +5 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/auth/hooks/axios/withAuth.js +5 -0
- package/_cjs/auth/hooks/axios/withAuth.js.map +1 -1
- package/_cjs/auth/utils/jwt.js +4 -1
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +8 -2
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +2 -0
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +4 -4
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/utils/bigint.js +24 -0
- package/_cjs/utils/bigint.js.map +1 -0
- package/_cjs/utils/hash.js +7 -0
- package/_cjs/utils/hash.js.map +1 -0
- package/_cjs/utils/sortKeys.js +26 -0
- package/_cjs/utils/sortKeys.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/resolveViemClients.js +39 -2
- package/_esm/accounts/evm/resolveViemClients.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +5 -0
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/auth/hooks/axios/withAuth.js +5 -0
- package/_esm/auth/hooks/axios/withAuth.js.map +1 -1
- package/_esm/auth/utils/jwt.js +4 -1
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/cdpApiClient.js +7 -1
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +2 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +4 -4
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/utils/bigint.js +20 -0
- package/_esm/utils/bigint.js.map +1 -0
- package/_esm/utils/hash.js +3 -0
- package/_esm/utils/hash.js.map +1 -0
- package/_esm/utils/sortKeys.js +22 -0
- package/_esm/utils/sortKeys.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/resolveViemClients.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +1 -1
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -1
- package/_types/auth/utils/jwt.d.ts.map +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts +4 -0
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +2 -0
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +4 -4
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/utils/bigint.d.ts +8 -0
- package/_types/utils/bigint.d.ts.map +1 -0
- package/_types/utils/hash.d.ts +2 -0
- package/_types/utils/hash.d.ts.map +1 -0
- package/_types/utils/sortKeys.d.ts +8 -0
- package/_types/utils/sortKeys.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/resolveViemClients.ts +46 -2
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +10 -2
- package/accounts/evm/types.ts +1 -1
- package/auth/hooks/axios/withAuth.ts +6 -0
- package/auth/utils/jwt.ts +4 -1
- package/index.ts +2 -0
- package/openapi-client/cdpApiClient.ts +13 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +2 -0
- package/openapi-client/generated/index.msw.ts +4 -4
- package/package.json +1 -1
- package/utils/bigint.ts +19 -0
- package/utils/hash.ts +3 -0
- package/utils/sortKeys.ts +26 -0
- package/version.ts +1 -1
package/accounts/evm/types.ts
CHANGED
|
@@ -85,7 +85,7 @@ type NetworkScopedAccountActions = Prettify<{
|
|
|
85
85
|
options: Omit<SendTransactionOptions, "address" | "network">,
|
|
86
86
|
) => Promise<TransactionResult>;
|
|
87
87
|
waitForTransactionReceipt: (
|
|
88
|
-
options: WaitForTransactionReceiptParameters,
|
|
88
|
+
options: WaitForTransactionReceiptParameters | TransactionResult,
|
|
89
89
|
) => Promise<TransactionReceipt>;
|
|
90
90
|
}>;
|
|
91
91
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosHeaders } from "axios";
|
|
2
2
|
|
|
3
|
+
import { convertBigIntsToStrings } from "../../../utils/bigint.js";
|
|
3
4
|
import { getAuthHeaders } from "../../utils/http.js";
|
|
4
5
|
|
|
5
6
|
export interface AuthInterceptorOptions {
|
|
@@ -57,6 +58,11 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
|
|
|
57
58
|
// Parse URL to get host and path
|
|
58
59
|
const url = new URL(fullyQualifiedURL);
|
|
59
60
|
|
|
61
|
+
// Convert bigints in request body to strings for safe serialization
|
|
62
|
+
if (axiosConfig.data) {
|
|
63
|
+
axiosConfig.data = convertBigIntsToStrings(axiosConfig.data);
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
// Get authentication headers
|
|
61
67
|
const headers = await getAuthHeaders({
|
|
62
68
|
apiKeyId: options.apiKeyId,
|
package/auth/utils/jwt.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { createPrivateKey } from "crypto";
|
|
|
3
3
|
|
|
4
4
|
import { SignJWT, importPKCS8, importJWK, JWTPayload } from "jose";
|
|
5
5
|
|
|
6
|
+
import { hash } from "../../utils/hash.js";
|
|
7
|
+
import { sortKeys } from "../../utils/sortKeys.js";
|
|
6
8
|
import { InvalidWalletSecretFormatError, UndefinedWalletSecretError } from "../errors.js";
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -190,7 +192,8 @@ export async function generateWalletJwt(options: WalletJwtOptions): Promise<stri
|
|
|
190
192
|
};
|
|
191
193
|
|
|
192
194
|
if (Object.keys(options.requestData).length > 0) {
|
|
193
|
-
|
|
195
|
+
const sortedData = sortKeys(options.requestData);
|
|
196
|
+
claims.reqHash = hash(Buffer.from(JSON.stringify(sortedData)));
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
try {
|
package/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
UnknownError,
|
|
12
12
|
} from "./errors.js";
|
|
13
13
|
|
|
14
|
+
import type { Prettify } from "../types/utils.js";
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* The options for the CDP API.
|
|
16
18
|
*/
|
|
@@ -54,14 +56,24 @@ export type CdpOptions = {
|
|
|
54
56
|
|
|
55
57
|
let axiosInstance: AxiosInstance;
|
|
56
58
|
|
|
59
|
+
export let config: Prettify<Omit<CdpOptions, "basePath"> & { basePath: string }> | undefined =
|
|
60
|
+
undefined;
|
|
61
|
+
|
|
57
62
|
/**
|
|
58
63
|
* Configures the CDP client with the given options.
|
|
59
64
|
*
|
|
60
65
|
* @param {CdpOptions} options - The CDP options.
|
|
61
66
|
*/
|
|
62
67
|
export const configure = (options: CdpOptions) => {
|
|
68
|
+
const baseURL = options.basePath || "https://api.cdp.coinbase.com/platform";
|
|
69
|
+
|
|
70
|
+
config = {
|
|
71
|
+
...options,
|
|
72
|
+
basePath: baseURL,
|
|
73
|
+
};
|
|
74
|
+
|
|
63
75
|
axiosInstance = Axios.create({
|
|
64
|
-
baseURL
|
|
76
|
+
baseURL,
|
|
65
77
|
});
|
|
66
78
|
|
|
67
79
|
axiosInstance = withAuth(axiosInstance, {
|
|
@@ -56,6 +56,7 @@ export const ErrorType = {
|
|
|
56
56
|
unauthorized: "unauthorized",
|
|
57
57
|
policy_violation: "policy_violation",
|
|
58
58
|
policy_in_use: "policy_in_use",
|
|
59
|
+
account_limit_exceeded: "account_limit_exceeded",
|
|
59
60
|
} as const;
|
|
60
61
|
|
|
61
62
|
/**
|
|
@@ -487,6 +488,7 @@ export type ListEvmTokenBalancesNetwork =
|
|
|
487
488
|
export const ListEvmTokenBalancesNetwork = {
|
|
488
489
|
base: "base",
|
|
489
490
|
"base-sepolia": "base-sepolia",
|
|
491
|
+
ethereum: "ethereum",
|
|
490
492
|
} as const;
|
|
491
493
|
|
|
492
494
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export * from "./evm-swaps/evm-swaps.msw.js";
|
|
1
2
|
export * from "./evm-token-balances/evm-token-balances.msw.js";
|
|
2
3
|
export * from "./evm-accounts/evm-accounts.msw.js";
|
|
3
|
-
export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";
|
|
4
|
-
export * from "./faucets/faucets.msw.js";
|
|
5
|
-
export * from "./evm-swaps/evm-swaps.msw.js";
|
|
6
|
-
export * from "./payments-alpha/payments-alpha.msw.js";
|
|
7
4
|
export * from "./policy-engine/policy-engine.msw.js";
|
|
5
|
+
export * from "./faucets/faucets.msw.js";
|
|
6
|
+
export * from "./evm-smart-accounts/evm-smart-accounts.msw.js";
|
|
8
7
|
export * from "./solana-accounts/solana-accounts.msw.js";
|
|
8
|
+
export * from "./payments-alpha/payments-alpha.msw.js";
|
package/package.json
CHANGED
package/utils/bigint.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* Converts bigint values in an object to strings for safe serialization
|
|
4
|
+
*
|
|
5
|
+
* @param obj - The object to convert
|
|
6
|
+
* @returns A new object with bigint values converted to strings
|
|
7
|
+
*/
|
|
8
|
+
export const convertBigIntsToStrings = (obj: any): any => {
|
|
9
|
+
if (typeof obj === "bigint") {
|
|
10
|
+
return obj.toString();
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(obj)) {
|
|
13
|
+
return obj.map(convertBigIntsToStrings);
|
|
14
|
+
}
|
|
15
|
+
if (obj && typeof obj === "object") {
|
|
16
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, convertBigIntsToStrings(v)]));
|
|
17
|
+
}
|
|
18
|
+
return obj;
|
|
19
|
+
};
|
package/utils/hash.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* Recursively sorts object keys to ensure consistent JSON stringification
|
|
4
|
+
*
|
|
5
|
+
* @param obj - The object to sort
|
|
6
|
+
* @returns A new object with sorted keys
|
|
7
|
+
*/
|
|
8
|
+
export const sortKeys = (obj: any): any => {
|
|
9
|
+
if (!obj || typeof obj !== "object") {
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (Array.isArray(obj)) {
|
|
14
|
+
return obj.map(sortKeys);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Object.keys(obj)
|
|
18
|
+
.sort()
|
|
19
|
+
.reduce(
|
|
20
|
+
(acc, key) => {
|
|
21
|
+
acc[key] = sortKeys(obj[key]);
|
|
22
|
+
return acc;
|
|
23
|
+
},
|
|
24
|
+
{} as Record<string, any>,
|
|
25
|
+
);
|
|
26
|
+
};
|
package/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.19.0";
|