@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getCorrelationData } from "./http.js";
|
|
2
|
+
import { generateJwt } from "./jwt.js";
|
|
3
|
+
/**
|
|
4
|
+
* Gets authentication headers for a WebSocket connection.
|
|
5
|
+
*
|
|
6
|
+
* @param options - The configuration options for generating WebSocket auth headers
|
|
7
|
+
* @returns Object containing the authentication headers
|
|
8
|
+
*/
|
|
9
|
+
export async function getWebSocketAuthHeaders(options) {
|
|
10
|
+
const headers = {};
|
|
11
|
+
// Generate and add JWT token without request parameters for WebSocket
|
|
12
|
+
const jwt = await generateJwt({
|
|
13
|
+
apiKeyId: options.apiKeyId,
|
|
14
|
+
apiKeySecret: options.apiKeySecret,
|
|
15
|
+
// All request parameters are null for WebSocket
|
|
16
|
+
requestMethod: null,
|
|
17
|
+
requestHost: null,
|
|
18
|
+
requestPath: null,
|
|
19
|
+
expiresIn: options.expiresIn,
|
|
20
|
+
audience: options.audience,
|
|
21
|
+
});
|
|
22
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
23
|
+
headers["Content-Type"] = "application/json";
|
|
24
|
+
// Add correlation data
|
|
25
|
+
headers["Correlation-Context"] = getCorrelationData(options.source, options.sourceVersion);
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../../auth/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA6CvC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAuC;IAEvC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,sEAAsE;IACtE,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC;QAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,gDAAgD;QAChD,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC,CAAC;IACH,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,GAAG,EAAE,CAAC;IAC3C,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;IAE7C,uBAAuB;IACvB,OAAO,CAAC,qBAAqB,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAE3F,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/_esm/client/cdp.js
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";
|
|
@@ -89,7 +89,11 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
89
89
|
source: "sdk",
|
|
90
90
|
sourceVersion: version,
|
|
91
91
|
});
|
|
92
|
-
|
|
92
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
93
|
+
wrapClassWithErrorTracking(CdpClient, apiKeyId);
|
|
94
|
+
wrapClassWithErrorTracking(EvmClient, apiKeyId);
|
|
95
|
+
wrapClassWithErrorTracking(SolanaClient, apiKeyId);
|
|
96
|
+
}
|
|
93
97
|
this.evm = new EvmClient();
|
|
94
98
|
this.solana = new SolanaClient();
|
|
95
99
|
}
|
package/_esm/client/cdp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAelD;;GAEG;AACH,MAAM,OAAO,SAAS;IACpB,4CAA4C;IACrC,GAAG,CAAY;IAEtB,+CAA+C;IACxC,MAAM,CAAe;IAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,YAAY,UAA4B,EAAE;QACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAChG,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC5E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAE3E,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BrB,CAAC,CAAC;QACC,CAAC;QAED,gBAAgB,CAAC,SAAS,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,MAAM,EAAE,KAAK;YACb,aAAa,EAAE,OAAO;SACvB,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,EAAE,CAAC;YACvD,0BAA0B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAChD,0BAA0B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAChD,0BAA0B,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;IACnC,CAAC;CACF"}
|
package/_esm/index.js
CHANGED
package/_esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/_esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.4.0";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/_types/analytics.d.ts
CHANGED
|
@@ -19,22 +19,9 @@ type ErrorEventData = {
|
|
|
19
19
|
*/
|
|
20
20
|
name: "error";
|
|
21
21
|
};
|
|
22
|
-
type EventData = ErrorEventData
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
export declare class AnalyticsConfig {
|
|
27
|
-
/**
|
|
28
|
-
* The API key ID
|
|
29
|
-
*/
|
|
30
|
-
static apiKeyId: string;
|
|
31
|
-
/**
|
|
32
|
-
* Sets the API key ID
|
|
33
|
-
*
|
|
34
|
-
* @param apiKeyId - The API key ID
|
|
35
|
-
*/
|
|
36
|
-
static set(apiKeyId: string): void;
|
|
37
|
-
}
|
|
22
|
+
type EventData = ErrorEventData & {
|
|
23
|
+
apiKeyId: string;
|
|
24
|
+
};
|
|
38
25
|
/**
|
|
39
26
|
* Sends an analytics event to the default endpoint
|
|
40
27
|
*
|
|
@@ -42,5 +29,12 @@ export declare class AnalyticsConfig {
|
|
|
42
29
|
* @returns Promise that resolves when the event is sent
|
|
43
30
|
*/
|
|
44
31
|
export declare function sendEvent(event: EventData): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Wraps all methods of a class with error tracking.
|
|
34
|
+
*
|
|
35
|
+
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
36
|
+
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
37
|
+
*/
|
|
38
|
+
export declare function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string): void;
|
|
45
39
|
export {};
|
|
46
40
|
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../analytics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../analytics.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,KAAK,cAAc,GAAG;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,KAAK,SAAS,GAAG,cAAc,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAKF;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC/D;AAED;;;;;GAKG;AAEH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CA+BnF"}
|
package/_types/auth/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -50,6 +50,10 @@ export interface GetAuthHeadersOptions {
|
|
|
50
50
|
* Optional expiration time in seconds (defaults to 120)
|
|
51
51
|
*/
|
|
52
52
|
expiresIn?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Optional audience claim for the JWT
|
|
55
|
+
*/
|
|
56
|
+
audience?: string[];
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
59
|
* Gets authentication headers for a request.
|
|
@@ -58,4 +62,12 @@ export interface GetAuthHeadersOptions {
|
|
|
58
62
|
* @returns Object containing the authentication headers
|
|
59
63
|
*/
|
|
60
64
|
export declare function getAuthHeaders(options: GetAuthHeadersOptions): Promise<Record<string, string>>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns encoded correlation data including the SDK version and language.
|
|
67
|
+
*
|
|
68
|
+
* @param source - The source identifier for the request
|
|
69
|
+
* @param sourceVersion - The version of the source making the request
|
|
70
|
+
* @returns Encoded correlation data as a query string
|
|
71
|
+
*/
|
|
72
|
+
export declare function getCorrelationData(source?: string, sourceVersion?: string): string;
|
|
61
73
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../auth/utils/http.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../auth/utils/http.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAsCjC;AAeD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAYlF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../auth/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../auth/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -23,21 +23,25 @@ export interface JwtOptions {
|
|
|
23
23
|
*/
|
|
24
24
|
apiKeySecret: string;
|
|
25
25
|
/**
|
|
26
|
-
* The HTTP method for the request (e.g. 'GET', 'POST')
|
|
26
|
+
* The HTTP method for the request (e.g. 'GET', 'POST'), or null for JWTs intended for websocket connections
|
|
27
27
|
*/
|
|
28
|
-
requestMethod
|
|
28
|
+
requestMethod?: string | null;
|
|
29
29
|
/**
|
|
30
|
-
* The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
30
|
+
* The host for the request (e.g. 'api.cdp.coinbase.com'), or null for JWTs intended for websocket connections
|
|
31
31
|
*/
|
|
32
|
-
requestHost
|
|
32
|
+
requestHost?: string | null;
|
|
33
33
|
/**
|
|
34
|
-
* The path for the request (e.g. '/platform/v1/wallets')
|
|
34
|
+
* The path for the request (e.g. '/platform/v1/wallets'), or null for JWTs intended for websocket connections
|
|
35
35
|
*/
|
|
36
|
-
requestPath
|
|
36
|
+
requestPath?: string | null;
|
|
37
37
|
/**
|
|
38
38
|
* Optional expiration time in seconds (defaults to 120)
|
|
39
39
|
*/
|
|
40
40
|
expiresIn?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Optional audience claim for the JWT
|
|
43
|
+
*/
|
|
44
|
+
audience?: string[];
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* WalletJwtOptions contains configuration for Wallet Auth JWT generation.
|
|
@@ -69,7 +73,9 @@ export interface WalletJwtOptions {
|
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
75
|
* Generates a JWT (also known as a Bearer token) for authenticating with Coinbase's REST APIs.
|
|
72
|
-
* Supports both EC (ES256) and Ed25519 (EdDSA) keys.
|
|
76
|
+
* Supports both EC (ES256) and Ed25519 (EdDSA) keys. Also supports JWTs meant for
|
|
77
|
+
* websocket connections by allowing requestMethod, requestHost, and requestPath to all be
|
|
78
|
+
* null, in which case the 'uris' claim is omitted from the JWT.
|
|
73
79
|
*
|
|
74
80
|
* @param options - The configuration options for generating the JWT
|
|
75
81
|
* @returns The generated JWT (Bearer token) string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IAEH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAiEtE;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiClF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for generating WebSocket authentication headers.
|
|
3
|
+
*/
|
|
4
|
+
export interface GetWebSocketAuthHeadersOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The API key ID
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
10
|
+
* 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
11
|
+
*/
|
|
12
|
+
apiKeyId: string;
|
|
13
|
+
/**
|
|
14
|
+
* The API key secret
|
|
15
|
+
*
|
|
16
|
+
* Examples:
|
|
17
|
+
* 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
|
|
18
|
+
* '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
|
|
19
|
+
*/
|
|
20
|
+
apiKeySecret: string;
|
|
21
|
+
/**
|
|
22
|
+
* The source identifier for the request
|
|
23
|
+
*/
|
|
24
|
+
source?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The version of the source making the request
|
|
27
|
+
*/
|
|
28
|
+
sourceVersion?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional expiration time in seconds (defaults to 120)
|
|
31
|
+
*/
|
|
32
|
+
expiresIn?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Optional audience claim for the JWT
|
|
35
|
+
*/
|
|
36
|
+
audience?: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets authentication headers for a WebSocket connection.
|
|
40
|
+
*
|
|
41
|
+
* @param options - The configuration options for generating WebSocket auth headers
|
|
42
|
+
* @returns Object containing the authentication headers
|
|
43
|
+
*/
|
|
44
|
+
export declare function getWebSocketAuthHeaders(options: GetWebSocketAuthHeadersOptions): Promise<Record<string, string>>;
|
|
45
|
+
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../../auth/utils/ws.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqBjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,UAAU,gBAAgB;IACxB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,EAAE,SAAS,CAAC;IAEtB,+CAA+C;IACxC,MAAM,EAAE,YAAY,CAAC;IAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;gBACS,OAAO,GAAE,gBAAqB;
|
|
1
|
+
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,UAAU,gBAAgB;IACxB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,EAAE,SAAS,CAAC;IAEtB,+CAA+C;IACxC,MAAM,EAAE,YAAY,CAAC;IAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;gBACS,OAAO,GAAE,gBAAqB;CAuD3C"}
|
package/_types/index.d.ts
CHANGED
package/_types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/_types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.4.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/analytics.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import md5 from "md5";
|
|
2
2
|
|
|
3
|
-
import { CdpClient } from "./client/cdp.js";
|
|
4
|
-
import { EvmClient } from "./client/evm/evm.js";
|
|
5
|
-
import { SolanaClient } from "./client/solana/solana.js";
|
|
6
|
-
|
|
7
3
|
/**
|
|
8
4
|
* The data in an error event
|
|
9
5
|
*/
|
|
@@ -26,30 +22,13 @@ type ErrorEventData = {
|
|
|
26
22
|
name: "error";
|
|
27
23
|
};
|
|
28
24
|
|
|
29
|
-
type EventData = ErrorEventData
|
|
25
|
+
type EventData = ErrorEventData & {
|
|
26
|
+
apiKeyId: string;
|
|
27
|
+
};
|
|
30
28
|
|
|
31
29
|
// This is a public client id for the analytics service
|
|
32
30
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
33
31
|
|
|
34
|
-
/**
|
|
35
|
-
* AnalyticsConfig singleton class for holding the API key ID
|
|
36
|
-
*/
|
|
37
|
-
export class AnalyticsConfig {
|
|
38
|
-
/**
|
|
39
|
-
* The API key ID
|
|
40
|
-
*/
|
|
41
|
-
public static apiKeyId: string;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Sets the API key ID
|
|
45
|
-
*
|
|
46
|
-
* @param apiKeyId - The API key ID
|
|
47
|
-
*/
|
|
48
|
-
public static set(apiKeyId: string): void {
|
|
49
|
-
AnalyticsConfig.apiKeyId = apiKeyId;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
32
|
/**
|
|
54
33
|
* Sends an analytics event to the default endpoint
|
|
55
34
|
*
|
|
@@ -60,7 +39,7 @@ export async function sendEvent(event: EventData): Promise<void> {
|
|
|
60
39
|
const timestamp = Date.now();
|
|
61
40
|
|
|
62
41
|
const enhancedEvent = {
|
|
63
|
-
user_id:
|
|
42
|
+
user_id: event.apiKeyId,
|
|
64
43
|
event_type: event.name,
|
|
65
44
|
platform: "server",
|
|
66
45
|
timestamp,
|
|
@@ -101,16 +80,17 @@ export async function sendEvent(event: EventData): Promise<void> {
|
|
|
101
80
|
* Wraps all methods of a class with error tracking.
|
|
102
81
|
*
|
|
103
82
|
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
83
|
+
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
104
84
|
*/
|
|
105
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
function wrapClassWithErrorTracking(ClassToWrap: any): void {
|
|
107
|
-
const
|
|
86
|
+
export function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string): void {
|
|
87
|
+
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(
|
|
108
88
|
name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function",
|
|
109
89
|
);
|
|
110
90
|
|
|
111
|
-
for (const
|
|
112
|
-
const originalMethod = ClassToWrap.prototype[
|
|
113
|
-
ClassToWrap.prototype[
|
|
91
|
+
for (const method of methods) {
|
|
92
|
+
const originalMethod = ClassToWrap.prototype[method];
|
|
93
|
+
ClassToWrap.prototype[method] = async function (...args: unknown[]) {
|
|
114
94
|
try {
|
|
115
95
|
return await originalMethod.apply(this, args);
|
|
116
96
|
} catch (error) {
|
|
@@ -120,23 +100,18 @@ function wrapClassWithErrorTracking(ClassToWrap: any): void {
|
|
|
120
100
|
|
|
121
101
|
const { message, stack } = error;
|
|
122
102
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
103
|
+
sendEvent({
|
|
104
|
+
apiKeyId,
|
|
105
|
+
method,
|
|
106
|
+
message,
|
|
107
|
+
stack,
|
|
108
|
+
name: "error",
|
|
109
|
+
}).catch(() => {
|
|
110
|
+
// ignore error
|
|
111
|
+
});
|
|
133
112
|
|
|
134
113
|
throw error;
|
|
135
114
|
}
|
|
136
115
|
};
|
|
137
116
|
}
|
|
138
117
|
}
|
|
139
|
-
|
|
140
|
-
wrapClassWithErrorTracking(CdpClient);
|
|
141
|
-
wrapClassWithErrorTracking(EvmClient);
|
|
142
|
-
wrapClassWithErrorTracking(SolanaClient);
|
package/auth/README.md
CHANGED
|
@@ -25,6 +25,7 @@ npm install @coinbase/cdp-sdk
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { generateJwt } from "@coinbase/cdp-sdk/auth";
|
|
27
27
|
|
|
28
|
+
// For REST (HTTP) requests
|
|
28
29
|
const jwt = await generateJwt({
|
|
29
30
|
apiKeyId: "YOUR_API_KEY_ID",
|
|
30
31
|
apiKeySecret: "YOUR_API_KEY_SECRET",
|
|
@@ -35,6 +36,18 @@ const jwt = await generateJwt({
|
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
console.log(jwt);
|
|
39
|
+
|
|
40
|
+
// For websocket connections
|
|
41
|
+
const websocketJwt = await generateJwt({
|
|
42
|
+
apiKeyId: "YOUR_API_KEY_ID",
|
|
43
|
+
apiKeySecret: "YOUR_API_KEY_SECRET",
|
|
44
|
+
requestMethod: null,
|
|
45
|
+
requestHost: null,
|
|
46
|
+
requestPath: null,
|
|
47
|
+
expiresIn: 120, // optional (defaults to 120 seconds)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(websocketJwt);
|
|
38
51
|
```
|
|
39
52
|
|
|
40
53
|
For information about the above parameters, please refer to the [Authentication parameters](#authentication-parameters) section.
|
|
@@ -138,8 +151,10 @@ The following table provides more context of many of the authentication paramete
|
|
|
138
151
|
| :-- | :-- | :-- |
|
|
139
152
|
| `apiKeyId` | true | The unique identifier for your API key. Supported formats are:<br/>- `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`<br/>- `organizations/{orgId}/apiKeys/{keyId}` |
|
|
140
153
|
| `apiKeySecret` | true | Your API key secret. Supported formats are:<br/>- Edwards key (Ed25519): `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==`<br/>- Elliptic Curve key (ES256): `-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n` |
|
|
141
|
-
| `requestMethod` | true | The HTTP method for the API request you're authenticating (ie, `GET`, `POST`, `PUT`, `DELETE`). |
|
|
142
|
-
| `requestHost` | true | The API host you're calling (ie, `api.cdp.coinbase.com`). |
|
|
143
|
-
| `requestPath` | true | The path of the specific API endpoint you're calling (ie, `/platform/v1/wallets`). |
|
|
154
|
+
| `requestMethod` | true* | The HTTP method for the API request you're authenticating (ie, `GET`, `POST`, `PUT`, `DELETE`). Can be `null` for JWTs intended for websocket connections. |
|
|
155
|
+
| `requestHost` | true* | The API host you're calling (ie, `api.cdp.coinbase.com`). Can be `null` for JWTs intended for websocket connections. |
|
|
156
|
+
| `requestPath` | true* | The path of the specific API endpoint you're calling (ie, `/platform/v1/wallets`). Can be `null` for JWTs intended for websocket connections. |
|
|
144
157
|
| `requestBody` | false | Optional request body data. |
|
|
145
158
|
| `expiresIn` | false | The JWT expiration time in seconds. After this time, the JWT will no longer be valid, and a new one must be generated. Defaults to `120` (ie, 2 minutes) if not specified. |
|
|
159
|
+
|
|
160
|
+
\* Either all three request parameters (`requestMethod`, `requestHost`, and `requestPath`) must be provided for REST API requests, or all three must be `null` for JWTs intended for websocket connections.
|
package/auth/index.ts
CHANGED
package/auth/utils/http.ts
CHANGED
|
@@ -62,6 +62,11 @@ export interface GetAuthHeadersOptions {
|
|
|
62
62
|
* Optional expiration time in seconds (defaults to 120)
|
|
63
63
|
*/
|
|
64
64
|
expiresIn?: number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Optional audience claim for the JWT
|
|
68
|
+
*/
|
|
69
|
+
audience?: string[];
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/**
|
|
@@ -83,6 +88,7 @@ export async function getAuthHeaders(
|
|
|
83
88
|
requestHost: options.requestHost,
|
|
84
89
|
requestPath: options.requestPath,
|
|
85
90
|
expiresIn: options.expiresIn,
|
|
91
|
+
audience: options.audience,
|
|
86
92
|
});
|
|
87
93
|
headers["Authorization"] = `Bearer ${jwt}`;
|
|
88
94
|
headers["Content-Type"] = "application/json";
|
|
@@ -131,7 +137,7 @@ function requiresWalletAuth(requestMethod: string, requestPath: string): boolean
|
|
|
131
137
|
* @param sourceVersion - The version of the source making the request
|
|
132
138
|
* @returns Encoded correlation data as a query string
|
|
133
139
|
*/
|
|
134
|
-
function getCorrelationData(source?: string, sourceVersion?: string): string {
|
|
140
|
+
export function getCorrelationData(source?: string, sourceVersion?: string): string {
|
|
135
141
|
const data = {
|
|
136
142
|
sdk_version: version,
|
|
137
143
|
sdk_language: "typescript",
|
package/auth/utils/index.ts
CHANGED
package/auth/utils/jwt.ts
CHANGED
|
@@ -32,24 +32,29 @@ export interface JwtOptions {
|
|
|
32
32
|
apiKeySecret: string;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* The HTTP method for the request (e.g. 'GET', 'POST')
|
|
35
|
+
* The HTTP method for the request (e.g. 'GET', 'POST'), or null for JWTs intended for websocket connections
|
|
36
36
|
*/
|
|
37
|
-
requestMethod
|
|
37
|
+
requestMethod?: string | null;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
40
|
+
* The host for the request (e.g. 'api.cdp.coinbase.com'), or null for JWTs intended for websocket connections
|
|
41
41
|
*/
|
|
42
|
-
requestHost
|
|
42
|
+
requestHost?: string | null;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* The path for the request (e.g. '/platform/v1/wallets')
|
|
45
|
+
* The path for the request (e.g. '/platform/v1/wallets'), or null for JWTs intended for websocket connections
|
|
46
46
|
*/
|
|
47
|
-
requestPath
|
|
47
|
+
requestPath?: string | null;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Optional expiration time in seconds (defaults to 120)
|
|
51
51
|
*/
|
|
52
52
|
expiresIn?: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional audience claim for the JWT
|
|
56
|
+
*/
|
|
57
|
+
audience?: string[];
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
/**
|
|
@@ -88,7 +93,9 @@ export interface WalletJwtOptions {
|
|
|
88
93
|
|
|
89
94
|
/**
|
|
90
95
|
* Generates a JWT (also known as a Bearer token) for authenticating with Coinbase's REST APIs.
|
|
91
|
-
* Supports both EC (ES256) and Ed25519 (EdDSA) keys.
|
|
96
|
+
* Supports both EC (ES256) and Ed25519 (EdDSA) keys. Also supports JWTs meant for
|
|
97
|
+
* websocket connections by allowing requestMethod, requestHost, and requestPath to all be
|
|
98
|
+
* null, in which case the 'uris' claim is omitted from the JWT.
|
|
92
99
|
*
|
|
93
100
|
* @param options - The configuration options for generating the JWT
|
|
94
101
|
* @returns The generated JWT (Bearer token) string
|
|
@@ -102,22 +109,38 @@ export async function generateJwt(options: JwtOptions): Promise<string> {
|
|
|
102
109
|
if (!options.apiKeySecret) {
|
|
103
110
|
throw new Error("Private key is required");
|
|
104
111
|
}
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
|
|
113
|
+
// Check if we have a REST API request or a websocket connection
|
|
114
|
+
const hasAllRequestParams = Boolean(
|
|
115
|
+
options.requestMethod && options.requestHost && options.requestPath,
|
|
116
|
+
);
|
|
117
|
+
const hasNoRequestParams =
|
|
118
|
+
(options.requestMethod === undefined || options.requestMethod === null) &&
|
|
119
|
+
(options.requestHost === undefined || options.requestHost === null) &&
|
|
120
|
+
(options.requestPath === undefined || options.requestPath === null);
|
|
121
|
+
|
|
122
|
+
// Ensure we either have all request parameters or none (for websocket)
|
|
123
|
+
if (!hasAllRequestParams && !hasNoRequestParams) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"Either all request details (method, host, path) must be provided, or all must be null for JWTs intended for websocket connections",
|
|
126
|
+
);
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
const now = Math.floor(Date.now() / 1000);
|
|
110
130
|
const expiresIn = options.expiresIn || 120; // Default to 120 seconds if not specified
|
|
111
|
-
const uri = `${options.requestMethod} ${options.requestHost}${options.requestPath}`;
|
|
112
131
|
|
|
113
132
|
// Prepare the JWT payload
|
|
114
|
-
const claims = {
|
|
133
|
+
const claims: JWTPayload = {
|
|
115
134
|
sub: options.apiKeyId,
|
|
116
135
|
iss: "cdp",
|
|
117
|
-
aud: ["cdp_service"],
|
|
118
|
-
uris: [uri],
|
|
136
|
+
aud: options.audience || ["cdp_service"],
|
|
119
137
|
};
|
|
120
138
|
|
|
139
|
+
// Add the uris claim only for REST API requests
|
|
140
|
+
if (hasAllRequestParams) {
|
|
141
|
+
claims.uris = [`${options.requestMethod} ${options.requestHost}${options.requestPath}`];
|
|
142
|
+
}
|
|
143
|
+
|
|
121
144
|
// Generate random nonce for the header
|
|
122
145
|
const randomNonce = nonce();
|
|
123
146
|
|