@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.
- package/CHANGELOG.md +12 -0
- package/README.md +26 -0
- package/_cjs/analytics.js +17 -41
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/auth/index.js +1 -0
- package/_cjs/auth/index.js.map +1 -1
- package/_cjs/auth/utils/http.js +2 -0
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/auth/utils/index.js +1 -0
- package/_cjs/auth/utils/index.js.map +1 -1
- package/_cjs/auth/utils/jwt.js +16 -6
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/auth/utils/ws.js +31 -0
- package/_cjs/auth/utils/ws.js.map +1 -0
- package/_cjs/client/cdp.js +5 -1
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/index.js +0 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/analytics.js +16 -39
- package/_esm/analytics.js.map +1 -1
- package/_esm/auth/index.js +1 -0
- package/_esm/auth/index.js.map +1 -1
- package/_esm/auth/utils/http.js +2 -1
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/auth/utils/index.js +1 -0
- package/_esm/auth/utils/index.js.map +1 -1
- package/_esm/auth/utils/jwt.js +16 -6
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/auth/utils/ws.js +28 -0
- package/_esm/auth/utils/ws.js.map +1 -0
- package/_esm/client/cdp.js +6 -2
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/index.js +0 -1
- package/_esm/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/analytics.d.ts +10 -16
- package/_types/analytics.d.ts.map +1 -1
- package/_types/auth/index.d.ts +1 -0
- package/_types/auth/index.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts +12 -0
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/auth/utils/index.d.ts +1 -0
- package/_types/auth/utils/index.d.ts.map +1 -1
- package/_types/auth/utils/jwt.d.ts +13 -7
- package/_types/auth/utils/jwt.d.ts.map +1 -1
- package/_types/auth/utils/ws.d.ts +45 -0
- package/_types/auth/utils/ws.d.ts.map +1 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/index.d.ts +0 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/analytics.ts +19 -44
- package/auth/README.md +18 -3
- package/auth/index.ts +1 -0
- package/auth/utils/http.ts +7 -1
- package/auth/utils/index.ts +1 -0
- package/auth/utils/jwt.ts +36 -13
- package/auth/utils/ws.ts +76 -0
- package/client/cdp.ts +6 -2
- package/index.ts +0 -2
- package/package.json +1 -1
- package/version.ts +1 -1
package/auth/utils/ws.ts
ADDED
|
@@ -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 {
|
|
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
|
-
|
|
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
package/package.json
CHANGED
package/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.4.0";
|