@coinbase/cdp-sdk 1.3.1 → 1.4.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 (63) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +26 -0
  3. package/_cjs/analytics.js +17 -41
  4. package/_cjs/analytics.js.map +1 -1
  5. package/_cjs/auth/index.js +1 -0
  6. package/_cjs/auth/index.js.map +1 -1
  7. package/_cjs/auth/utils/http.js +2 -0
  8. package/_cjs/auth/utils/http.js.map +1 -1
  9. package/_cjs/auth/utils/index.js +1 -0
  10. package/_cjs/auth/utils/index.js.map +1 -1
  11. package/_cjs/auth/utils/jwt.js +16 -6
  12. package/_cjs/auth/utils/jwt.js.map +1 -1
  13. package/_cjs/auth/utils/ws.js +31 -0
  14. package/_cjs/auth/utils/ws.js.map +1 -0
  15. package/_cjs/client/cdp.js +5 -1
  16. package/_cjs/client/cdp.js.map +1 -1
  17. package/_cjs/index.js +0 -1
  18. package/_cjs/index.js.map +1 -1
  19. package/_cjs/version.js +1 -1
  20. package/_esm/analytics.js +16 -39
  21. package/_esm/analytics.js.map +1 -1
  22. package/_esm/auth/index.js +1 -0
  23. package/_esm/auth/index.js.map +1 -1
  24. package/_esm/auth/utils/http.js +2 -1
  25. package/_esm/auth/utils/http.js.map +1 -1
  26. package/_esm/auth/utils/index.js +1 -0
  27. package/_esm/auth/utils/index.js.map +1 -1
  28. package/_esm/auth/utils/jwt.js +16 -6
  29. package/_esm/auth/utils/jwt.js.map +1 -1
  30. package/_esm/auth/utils/ws.js +28 -0
  31. package/_esm/auth/utils/ws.js.map +1 -0
  32. package/_esm/client/cdp.js +6 -2
  33. package/_esm/client/cdp.js.map +1 -1
  34. package/_esm/index.js +0 -1
  35. package/_esm/index.js.map +1 -1
  36. package/_esm/version.js +1 -1
  37. package/_types/analytics.d.ts +10 -16
  38. package/_types/analytics.d.ts.map +1 -1
  39. package/_types/auth/index.d.ts +1 -0
  40. package/_types/auth/index.d.ts.map +1 -1
  41. package/_types/auth/utils/http.d.ts +12 -0
  42. package/_types/auth/utils/http.d.ts.map +1 -1
  43. package/_types/auth/utils/index.d.ts +1 -0
  44. package/_types/auth/utils/index.d.ts.map +1 -1
  45. package/_types/auth/utils/jwt.d.ts +13 -7
  46. package/_types/auth/utils/jwt.d.ts.map +1 -1
  47. package/_types/auth/utils/ws.d.ts +45 -0
  48. package/_types/auth/utils/ws.d.ts.map +1 -0
  49. package/_types/client/cdp.d.ts.map +1 -1
  50. package/_types/index.d.ts +0 -1
  51. package/_types/index.d.ts.map +1 -1
  52. package/_types/version.d.ts +1 -1
  53. package/analytics.ts +19 -44
  54. package/auth/README.md +18 -3
  55. package/auth/index.ts +1 -0
  56. package/auth/utils/http.ts +7 -1
  57. package/auth/utils/index.ts +1 -0
  58. package/auth/utils/jwt.ts +36 -13
  59. package/auth/utils/ws.ts +76 -0
  60. package/client/cdp.ts +6 -2
  61. package/index.ts +0 -2
  62. package/package.json +1 -1
  63. package/version.ts +1 -1
@@ -0,0 +1,76 @@
1
+ import { getCorrelationData } from "./http.js";
2
+ import { generateJwt } from "./jwt.js";
3
+
4
+ /**
5
+ * Options for generating WebSocket authentication headers.
6
+ */
7
+ export interface GetWebSocketAuthHeadersOptions {
8
+ /**
9
+ * The API key ID
10
+ *
11
+ * Examples:
12
+ * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
13
+ * 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
14
+ */
15
+ apiKeyId: string;
16
+
17
+ /**
18
+ * The API key secret
19
+ *
20
+ * Examples:
21
+ * 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
22
+ * '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
23
+ */
24
+ apiKeySecret: string;
25
+
26
+ /**
27
+ * The source identifier for the request
28
+ */
29
+ source?: string;
30
+
31
+ /**
32
+ * The version of the source making the request
33
+ */
34
+ sourceVersion?: string;
35
+
36
+ /**
37
+ * Optional expiration time in seconds (defaults to 120)
38
+ */
39
+ expiresIn?: number;
40
+
41
+ /**
42
+ * Optional audience claim for the JWT
43
+ */
44
+ audience?: string[];
45
+ }
46
+
47
+ /**
48
+ * Gets authentication headers for a WebSocket connection.
49
+ *
50
+ * @param options - The configuration options for generating WebSocket auth headers
51
+ * @returns Object containing the authentication headers
52
+ */
53
+ export async function getWebSocketAuthHeaders(
54
+ options: GetWebSocketAuthHeadersOptions,
55
+ ): Promise<Record<string, string>> {
56
+ const headers: Record<string, string> = {};
57
+
58
+ // Generate and add JWT token without request parameters for WebSocket
59
+ const jwt = await generateJwt({
60
+ apiKeyId: options.apiKeyId,
61
+ apiKeySecret: options.apiKeySecret,
62
+ // All request parameters are null for WebSocket
63
+ requestMethod: null,
64
+ requestHost: null,
65
+ requestPath: null,
66
+ expiresIn: options.expiresIn,
67
+ audience: options.audience,
68
+ });
69
+ headers["Authorization"] = `Bearer ${jwt}`;
70
+ headers["Content-Type"] = "application/json";
71
+
72
+ // Add correlation data
73
+ headers["Correlation-Context"] = getCorrelationData(options.source, options.sourceVersion);
74
+
75
+ return headers;
76
+ }
package/client/cdp.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnalyticsConfig } from "../analytics.js";
1
+ import { wrapClassWithErrorTracking } from "../analytics.js";
2
2
  import { CdpOpenApiClient } from "../openapi-client/index.js";
3
3
  import { version } from "../version.js";
4
4
  import { EvmClient } from "./evm/evm.js";
@@ -108,7 +108,11 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
108
108
  sourceVersion: version,
109
109
  });
110
110
 
111
- AnalyticsConfig.set(apiKeyId);
111
+ if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
112
+ wrapClassWithErrorTracking(CdpClient, apiKeyId);
113
+ wrapClassWithErrorTracking(EvmClient, apiKeyId);
114
+ wrapClassWithErrorTracking(SolanaClient, apiKeyId);
115
+ }
112
116
 
113
117
  this.evm = new EvmClient();
114
118
  this.solana = new SolanaClient();
package/index.ts CHANGED
@@ -1,4 +1,2 @@
1
- import "./analytics.js";
2
-
3
1
  export { CdpClient } from "./client/cdp.js";
4
2
  export type { EvmServerAccount, EvmSmartAccount } from "./accounts/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cdp-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.4.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",
package/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "1.3.1";
1
+ export const version = "1.4.0";