@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.
Files changed (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/accounts/evm/resolveViemClients.js +39 -2
  3. package/_cjs/accounts/evm/resolveViemClients.js.map +1 -1
  4. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +5 -0
  5. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  6. package/_cjs/auth/hooks/axios/withAuth.js +5 -0
  7. package/_cjs/auth/hooks/axios/withAuth.js.map +1 -1
  8. package/_cjs/auth/utils/jwt.js +4 -1
  9. package/_cjs/auth/utils/jwt.js.map +1 -1
  10. package/_cjs/index.js +3 -1
  11. package/_cjs/index.js.map +1 -1
  12. package/_cjs/openapi-client/cdpApiClient.js +8 -2
  13. package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
  14. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +2 -0
  15. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  16. package/_cjs/openapi-client/generated/index.msw.js +4 -4
  17. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  18. package/_cjs/utils/bigint.js +24 -0
  19. package/_cjs/utils/bigint.js.map +1 -0
  20. package/_cjs/utils/hash.js +7 -0
  21. package/_cjs/utils/hash.js.map +1 -0
  22. package/_cjs/utils/sortKeys.js +26 -0
  23. package/_cjs/utils/sortKeys.js.map +1 -0
  24. package/_cjs/version.js +1 -1
  25. package/_esm/accounts/evm/resolveViemClients.js +39 -2
  26. package/_esm/accounts/evm/resolveViemClients.js.map +1 -1
  27. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +5 -0
  28. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  29. package/_esm/auth/hooks/axios/withAuth.js +5 -0
  30. package/_esm/auth/hooks/axios/withAuth.js.map +1 -1
  31. package/_esm/auth/utils/jwt.js +4 -1
  32. package/_esm/auth/utils/jwt.js.map +1 -1
  33. package/_esm/index.js +1 -0
  34. package/_esm/index.js.map +1 -1
  35. package/_esm/openapi-client/cdpApiClient.js +7 -1
  36. package/_esm/openapi-client/cdpApiClient.js.map +1 -1
  37. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +2 -0
  38. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  39. package/_esm/openapi-client/generated/index.msw.js +4 -4
  40. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  41. package/_esm/utils/bigint.js +20 -0
  42. package/_esm/utils/bigint.js.map +1 -0
  43. package/_esm/utils/hash.js +3 -0
  44. package/_esm/utils/hash.js.map +1 -0
  45. package/_esm/utils/sortKeys.js +22 -0
  46. package/_esm/utils/sortKeys.js.map +1 -0
  47. package/_esm/version.js +1 -1
  48. package/_types/accounts/evm/resolveViemClients.d.ts.map +1 -1
  49. package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
  50. package/_types/accounts/evm/types.d.ts +1 -1
  51. package/_types/accounts/evm/types.d.ts.map +1 -1
  52. package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -1
  53. package/_types/auth/utils/jwt.d.ts.map +1 -1
  54. package/_types/index.d.ts +1 -0
  55. package/_types/index.d.ts.map +1 -1
  56. package/_types/openapi-client/cdpApiClient.d.ts +4 -0
  57. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
  58. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +2 -0
  59. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  60. package/_types/openapi-client/generated/index.msw.d.ts +4 -4
  61. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  62. package/_types/utils/bigint.d.ts +8 -0
  63. package/_types/utils/bigint.d.ts.map +1 -0
  64. package/_types/utils/hash.d.ts +2 -0
  65. package/_types/utils/hash.d.ts.map +1 -0
  66. package/_types/utils/sortKeys.d.ts +8 -0
  67. package/_types/utils/sortKeys.d.ts.map +1 -0
  68. package/_types/version.d.ts +1 -1
  69. package/accounts/evm/resolveViemClients.ts +46 -2
  70. package/accounts/evm/toNetworkScopedEvmServerAccount.ts +10 -2
  71. package/accounts/evm/types.ts +1 -1
  72. package/auth/hooks/axios/withAuth.ts +6 -0
  73. package/auth/utils/jwt.ts +4 -1
  74. package/index.ts +2 -0
  75. package/openapi-client/cdpApiClient.ts +13 -1
  76. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +2 -0
  77. package/openapi-client/generated/index.msw.ts +4 -4
  78. package/package.json +1 -1
  79. package/utils/bigint.ts +19 -0
  80. package/utils/hash.ts +3 -0
  81. package/utils/sortKeys.ts +26 -0
  82. package/version.ts +1 -1
@@ -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
- claims.req = options.requestData;
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
@@ -7,3 +7,5 @@ export {
7
7
  type CreatePolicyBody,
8
8
  type UpdatePolicyBody,
9
9
  } from "./policies/schema.js";
10
+
11
+ export { parseEther } from "viem";
@@ -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: options.basePath || "https://api.cdp.coinbase.com/platform",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cdp-sdk",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "SDK for interacting with the Coinbase Developer Platform Wallet API",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -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,3 @@
1
+ import { createHash } from "crypto";
2
+
3
+ export const hash = (data: Buffer) => createHash("sha256").update(data).digest("hex");
@@ -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.18.0";
1
+ export const version = "1.19.0";