@coinbase/cdp-sdk 0.0.0 → 1.0.1
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/README.md +165 -0
- package/dist/accounts/evm/toEvmServerAccount.d.ts +19 -0
- package/dist/accounts/evm/toEvmServerAccount.js +42 -0
- package/dist/accounts/evm/toEvmSmartAccount.d.ts +24 -0
- package/dist/accounts/evm/toEvmSmartAccount.js +24 -0
- package/dist/accounts/types.d.ts +45 -0
- package/dist/accounts/types.js +2 -0
- package/dist/actions/evm/sendUserOperation.d.ts +95 -0
- package/dist/actions/evm/sendUserOperation.js +87 -0
- package/dist/actions/evm/waitForUserOperation.d.ts +63 -0
- package/dist/actions/evm/waitForUserOperation.js +60 -0
- package/dist/analytics.d.ts +30 -0
- package/dist/analytics.js +89 -0
- package/dist/auth/errors.d.ts +45 -0
- package/dist/auth/errors.js +62 -0
- package/dist/auth/hooks/axios/index.d.ts +1 -0
- package/dist/auth/hooks/axios/index.js +17 -0
- package/dist/auth/hooks/axios/withAuth.d.ts +37 -0
- package/dist/auth/hooks/axios/withAuth.js +73 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +43 -0
- package/dist/auth/utils/http.d.ts +60 -0
- package/dist/auth/utils/http.js +72 -0
- package/dist/auth/utils/index.d.ts +2 -0
- package/dist/auth/utils/index.js +18 -0
- package/dist/auth/utils/jwt.d.ts +88 -0
- package/dist/auth/utils/jwt.js +235 -0
- package/dist/client/cdp.d.ts +43 -0
- package/dist/client/cdp.js +40 -0
- package/dist/client/evm/evm.d.ts +387 -0
- package/dist/client/evm/evm.js +520 -0
- package/dist/client/evm/evm.types.d.ts +254 -0
- package/dist/client/evm/evm.types.js +2 -0
- package/dist/client/evm/index.d.ts +1 -0
- package/dist/client/evm/index.js +5 -0
- package/dist/client/solana/index.d.ts +1 -0
- package/dist/client/solana/index.js +5 -0
- package/dist/client/solana/solana.d.ts +168 -0
- package/dist/client/solana/solana.js +207 -0
- package/dist/client/solana/solana.types.d.ts +94 -0
- package/dist/client/solana/solana.types.js +2 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +7 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/openapi-client/cdpApiClient.d.ts +50 -0
- package/dist/openapi-client/cdpApiClient.js +146 -0
- package/dist/openapi-client/errors.d.ts +53 -0
- package/dist/openapi-client/errors.js +70 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +345 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +54 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +62 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +85 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +17 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +113 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +48 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +66 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +99 -0
- package/dist/openapi-client/generated/faucets/faucets.d.ts +48 -0
- package/dist/openapi-client/generated/faucets/faucets.js +51 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.d.ts +7 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.js +43 -0
- package/dist/openapi-client/generated/index.msw.d.ts +4 -0
- package/dist/openapi-client/generated/index.msw.js +20 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.d.ts +61 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.js +79 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.js +99 -0
- package/dist/openapi-client/index.d.ts +55 -0
- package/dist/openapi-client/index.js +65 -0
- package/dist/types/calls.d.ts +13 -0
- package/dist/types/calls.js +4 -0
- package/dist/types/contract.d.ts +30 -0
- package/dist/types/contract.js +4 -0
- package/dist/types/misc.d.ts +3 -0
- package/dist/types/misc.js +3 -0
- package/dist/types/multicall.d.ts +9 -0
- package/dist/types/multicall.js +2 -0
- package/dist/types/utils.d.ts +196 -0
- package/dist/types/utils.js +4 -0
- package/dist/utils/wait.d.ts +28 -0
- package/dist/utils/wait.js +34 -0
- package/package.json +72 -5
- package/index.js +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendEvent = sendEvent;
|
|
7
|
+
const md5_1 = __importDefault(require("md5"));
|
|
8
|
+
const cdp_1 = require("./client/cdp");
|
|
9
|
+
const evm_1 = require("./client/evm");
|
|
10
|
+
const solana_1 = require("./client/solana");
|
|
11
|
+
/**
|
|
12
|
+
* Sends an analytics event to the default endpoint
|
|
13
|
+
*
|
|
14
|
+
* @param event - The event data containing event-specific fields
|
|
15
|
+
* @returns Promise that resolves when the event is sent
|
|
16
|
+
*/
|
|
17
|
+
async function sendEvent(event) {
|
|
18
|
+
const timestamp = Date.now();
|
|
19
|
+
const enhancedEvent = {
|
|
20
|
+
event_type: event.name,
|
|
21
|
+
platform: "server",
|
|
22
|
+
event_properties: {
|
|
23
|
+
platform: "server",
|
|
24
|
+
project_name: "cdp-sdk",
|
|
25
|
+
time_start: timestamp,
|
|
26
|
+
cdp_sdk_language: "typescript",
|
|
27
|
+
...event,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const events = [enhancedEvent];
|
|
31
|
+
const stringifiedEventData = JSON.stringify(events);
|
|
32
|
+
const uploadTime = timestamp.toString();
|
|
33
|
+
const checksum = (0, md5_1.default)(stringifiedEventData + uploadTime);
|
|
34
|
+
const analyticsServiceData = {
|
|
35
|
+
e: stringifiedEventData,
|
|
36
|
+
checksum,
|
|
37
|
+
};
|
|
38
|
+
const apiEndpoint = "https://cca-lite.coinbase.com";
|
|
39
|
+
const eventPath = "/amp";
|
|
40
|
+
const eventEndPoint = `${apiEndpoint}${eventPath}`;
|
|
41
|
+
const response = await fetch(eventEndPoint, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
mode: "no-cors",
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(analyticsServiceData),
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Wraps all methods of a class with error tracking.
|
|
55
|
+
*
|
|
56
|
+
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
57
|
+
*/
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
function wrapClassWithErrorTracking(ClassToWrap) {
|
|
60
|
+
const methodNames = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
61
|
+
for (const methodName of methodNames) {
|
|
62
|
+
const originalMethod = ClassToWrap.prototype[methodName];
|
|
63
|
+
ClassToWrap.prototype[methodName] = async function (...args) {
|
|
64
|
+
try {
|
|
65
|
+
return await originalMethod.apply(this, args);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (!(error instanceof Error)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const { message, stack } = error;
|
|
72
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
73
|
+
sendEvent({
|
|
74
|
+
method: String(methodName),
|
|
75
|
+
message,
|
|
76
|
+
stack,
|
|
77
|
+
name: "error",
|
|
78
|
+
}).catch(() => {
|
|
79
|
+
// ignore error
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
wrapClassWithErrorTracking(cdp_1.CdpClient);
|
|
88
|
+
wrapClassWithErrorTracking(evm_1.EvmClient);
|
|
89
|
+
wrapClassWithErrorTracking(solana_1.SolanaClient);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class of errors for capturing stack traces.
|
|
3
|
+
*/
|
|
4
|
+
declare class BaseError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Base error constructor.
|
|
7
|
+
*
|
|
8
|
+
* @param message - The message to display.
|
|
9
|
+
*/
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An error for invalid API key format.
|
|
14
|
+
*/
|
|
15
|
+
export declare class InvalidAPIKeyFormatError extends BaseError {
|
|
16
|
+
/**
|
|
17
|
+
* Invalid API key format error constructor.
|
|
18
|
+
*
|
|
19
|
+
* @param message - The message to display.
|
|
20
|
+
*/
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An error for invalid Wallet Secret format.
|
|
25
|
+
*/
|
|
26
|
+
export declare class InvalidWalletSecretFormatError extends BaseError {
|
|
27
|
+
/**
|
|
28
|
+
* Invalid Wallet Secret format error constructor.
|
|
29
|
+
*
|
|
30
|
+
* @param message - The message to display.
|
|
31
|
+
*/
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An error for an undefined Wallet Secret.
|
|
36
|
+
*/
|
|
37
|
+
export declare class UndefinedWalletSecretError extends BaseError {
|
|
38
|
+
/**
|
|
39
|
+
* Undefined Wallet Secret error constructor.
|
|
40
|
+
*
|
|
41
|
+
* @param message - The message to display.
|
|
42
|
+
*/
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UndefinedWalletSecretError = exports.InvalidWalletSecretFormatError = exports.InvalidAPIKeyFormatError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A class of errors for capturing stack traces.
|
|
6
|
+
*/
|
|
7
|
+
class BaseError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Base error constructor.
|
|
10
|
+
*
|
|
11
|
+
* @param message - The message to display.
|
|
12
|
+
*/
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
if (Error.captureStackTrace) {
|
|
17
|
+
Error.captureStackTrace(this, this.constructor);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An error for invalid API key format.
|
|
23
|
+
*/
|
|
24
|
+
class InvalidAPIKeyFormatError extends BaseError {
|
|
25
|
+
/**
|
|
26
|
+
* Invalid API key format error constructor.
|
|
27
|
+
*
|
|
28
|
+
* @param message - The message to display.
|
|
29
|
+
*/
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super("Invalid API key format: " + message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InvalidAPIKeyFormatError = InvalidAPIKeyFormatError;
|
|
35
|
+
/**
|
|
36
|
+
* An error for invalid Wallet Secret format.
|
|
37
|
+
*/
|
|
38
|
+
class InvalidWalletSecretFormatError extends BaseError {
|
|
39
|
+
/**
|
|
40
|
+
* Invalid Wallet Secret format error constructor.
|
|
41
|
+
*
|
|
42
|
+
* @param message - The message to display.
|
|
43
|
+
*/
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super("Invalid Wallet Secret format: " + message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.InvalidWalletSecretFormatError = InvalidWalletSecretFormatError;
|
|
49
|
+
/**
|
|
50
|
+
* An error for an undefined Wallet Secret.
|
|
51
|
+
*/
|
|
52
|
+
class UndefinedWalletSecretError extends BaseError {
|
|
53
|
+
/**
|
|
54
|
+
* Undefined Wallet Secret error constructor.
|
|
55
|
+
*
|
|
56
|
+
* @param message - The message to display.
|
|
57
|
+
*/
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super("Undefined Wallet Secret: " + message);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.UndefinedWalletSecretError = UndefinedWalletSecretError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./withAuth";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./withAuth"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
export interface AuthInterceptorOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The API key ID
|
|
5
|
+
*
|
|
6
|
+
* Examples:
|
|
7
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
8
|
+
* 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
9
|
+
*/
|
|
10
|
+
apiKeyId: string;
|
|
11
|
+
/**
|
|
12
|
+
* The API key secret
|
|
13
|
+
*
|
|
14
|
+
* Examples:
|
|
15
|
+
* 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
|
|
16
|
+
* '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
|
|
17
|
+
*/
|
|
18
|
+
apiKeySecret: string;
|
|
19
|
+
/** The Wallet Secret */
|
|
20
|
+
walletSecret?: string;
|
|
21
|
+
/** The source of the request */
|
|
22
|
+
source?: string;
|
|
23
|
+
/** The version of the source of the request */
|
|
24
|
+
sourceVersion?: string;
|
|
25
|
+
/** Optional expiration time in seconds (defaults to 120) */
|
|
26
|
+
expiresIn?: number;
|
|
27
|
+
/** Whether to log request/response details */
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Axios interceptor for adding the JWT to the Authorization header.
|
|
32
|
+
*
|
|
33
|
+
* @param axiosClient - The Axios client instance to add the interceptor to
|
|
34
|
+
* @param options - Options for the request including API keys and debug flag
|
|
35
|
+
* @returns The modified request configuration with the Authorization header added
|
|
36
|
+
*/
|
|
37
|
+
export declare function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOptions): AxiosInstance;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withAuth = withAuth;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const http_1 = require("../../utils/http");
|
|
6
|
+
/**
|
|
7
|
+
* Axios interceptor for adding the JWT to the Authorization header.
|
|
8
|
+
*
|
|
9
|
+
* @param axiosClient - The Axios client instance to add the interceptor to
|
|
10
|
+
* @param options - Options for the request including API keys and debug flag
|
|
11
|
+
* @returns The modified request configuration with the Authorization header added
|
|
12
|
+
*/
|
|
13
|
+
function withAuth(axiosClient, options) {
|
|
14
|
+
axiosClient.interceptors.request.use(async (axiosConfig) => {
|
|
15
|
+
const method = axiosConfig.method?.toString().toUpperCase() || "GET";
|
|
16
|
+
if (!axiosConfig.url) {
|
|
17
|
+
throw new Error("URL is required for authentication");
|
|
18
|
+
}
|
|
19
|
+
const fullyQualifiedURL = axiosClient.getUri() + axiosConfig.url;
|
|
20
|
+
// Parse URL to get host and path
|
|
21
|
+
const url = new URL(fullyQualifiedURL);
|
|
22
|
+
// Get authentication headers
|
|
23
|
+
const headers = await (0, http_1.getAuthHeaders)({
|
|
24
|
+
apiKeyId: options.apiKeyId,
|
|
25
|
+
apiKeySecret: options.apiKeySecret,
|
|
26
|
+
requestMethod: method,
|
|
27
|
+
requestHost: url.host,
|
|
28
|
+
requestPath: url.pathname,
|
|
29
|
+
requestBody: axiosConfig.data,
|
|
30
|
+
walletSecret: options.walletSecret,
|
|
31
|
+
source: options.source,
|
|
32
|
+
sourceVersion: options.sourceVersion,
|
|
33
|
+
expiresIn: options.expiresIn,
|
|
34
|
+
});
|
|
35
|
+
// Add headers to request config
|
|
36
|
+
axiosConfig.headers = new axios_1.AxiosHeaders({
|
|
37
|
+
...axiosConfig.headers,
|
|
38
|
+
...headers,
|
|
39
|
+
});
|
|
40
|
+
if (options.debug) {
|
|
41
|
+
console.log("Request:", {
|
|
42
|
+
method,
|
|
43
|
+
url: fullyQualifiedURL,
|
|
44
|
+
headers: axiosConfig.headers,
|
|
45
|
+
data: axiosConfig.data,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return axiosConfig;
|
|
49
|
+
});
|
|
50
|
+
if (options.debug) {
|
|
51
|
+
axiosClient.interceptors.response.use(response => {
|
|
52
|
+
console.log("Response:", {
|
|
53
|
+
status: response.status,
|
|
54
|
+
statusText: response.statusText,
|
|
55
|
+
headers: response.headers,
|
|
56
|
+
data: response.data,
|
|
57
|
+
});
|
|
58
|
+
return response;
|
|
59
|
+
}, error => {
|
|
60
|
+
// Ensure we have access to the error response details
|
|
61
|
+
const errorDetails = {
|
|
62
|
+
status: error.response?.status,
|
|
63
|
+
statusText: error.response?.statusText,
|
|
64
|
+
headers: error.response?.headers,
|
|
65
|
+
data: error.response?.data,
|
|
66
|
+
message: error.message,
|
|
67
|
+
};
|
|
68
|
+
console.error("Response Error:", errorDetails);
|
|
69
|
+
return Promise.reject(error);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return axiosClient;
|
|
73
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.axiosHooks = void 0;
|
|
40
|
+
const axiosHooks = __importStar(require("./hooks/axios"));
|
|
41
|
+
exports.axiosHooks = axiosHooks;
|
|
42
|
+
__exportStar(require("./utils/http"), exports);
|
|
43
|
+
__exportStar(require("./utils/jwt"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for generating authentication headers for API requests.
|
|
3
|
+
*/
|
|
4
|
+
export interface GetAuthHeadersOptions {
|
|
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 HTTP method for the request (e.g. 'GET', 'POST')
|
|
23
|
+
*/
|
|
24
|
+
requestMethod: string;
|
|
25
|
+
/**
|
|
26
|
+
* The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
27
|
+
*/
|
|
28
|
+
requestHost: string;
|
|
29
|
+
/**
|
|
30
|
+
* The path for the request (e.g. '/platform/v1/wallets')
|
|
31
|
+
*/
|
|
32
|
+
requestPath: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional request body data
|
|
35
|
+
*/
|
|
36
|
+
requestBody?: unknown;
|
|
37
|
+
/**
|
|
38
|
+
* The Wallet Secret for wallet authentication
|
|
39
|
+
*/
|
|
40
|
+
walletSecret?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The source identifier for the request
|
|
43
|
+
*/
|
|
44
|
+
source?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The version of the source making the request
|
|
47
|
+
*/
|
|
48
|
+
sourceVersion?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional expiration time in seconds (defaults to 120)
|
|
51
|
+
*/
|
|
52
|
+
expiresIn?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets authentication headers for a request.
|
|
56
|
+
*
|
|
57
|
+
* @param options - The configuration options for generating auth headers
|
|
58
|
+
* @returns Object containing the authentication headers
|
|
59
|
+
*/
|
|
60
|
+
export declare function getAuthHeaders(options: GetAuthHeadersOptions): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthHeaders = getAuthHeaders;
|
|
4
|
+
const jwt_1 = require("./jwt");
|
|
5
|
+
const package_json_1 = require("../../../package.json");
|
|
6
|
+
/**
|
|
7
|
+
* Gets authentication headers for a request.
|
|
8
|
+
*
|
|
9
|
+
* @param options - The configuration options for generating auth headers
|
|
10
|
+
* @returns Object containing the authentication headers
|
|
11
|
+
*/
|
|
12
|
+
async function getAuthHeaders(options) {
|
|
13
|
+
const headers = {};
|
|
14
|
+
// Generate and add JWT token
|
|
15
|
+
const jwt = await (0, jwt_1.generateJwt)({
|
|
16
|
+
apiKeyId: options.apiKeyId,
|
|
17
|
+
apiKeySecret: options.apiKeySecret,
|
|
18
|
+
requestMethod: options.requestMethod,
|
|
19
|
+
requestHost: options.requestHost,
|
|
20
|
+
requestPath: options.requestPath,
|
|
21
|
+
expiresIn: options.expiresIn,
|
|
22
|
+
});
|
|
23
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
24
|
+
headers["Content-Type"] = "application/json";
|
|
25
|
+
// Add wallet auth if needed
|
|
26
|
+
if (requiresWalletAuth(options.requestMethod, options.requestPath)) {
|
|
27
|
+
if (!options.walletSecret) {
|
|
28
|
+
throw new Error("Wallet Secret not configured. Call configure() first.");
|
|
29
|
+
}
|
|
30
|
+
const walletAuthToken = await (0, jwt_1.generateWalletJwt)({
|
|
31
|
+
walletSecret: options.walletSecret,
|
|
32
|
+
requestMethod: options.requestMethod,
|
|
33
|
+
requestHost: options.requestHost,
|
|
34
|
+
requestPath: options.requestPath,
|
|
35
|
+
requestData: options.requestBody || {},
|
|
36
|
+
});
|
|
37
|
+
headers["X-Wallet-Auth"] = walletAuthToken;
|
|
38
|
+
}
|
|
39
|
+
// Add correlation data
|
|
40
|
+
headers["Correlation-Context"] = getCorrelationData(options.source, options.sourceVersion);
|
|
41
|
+
return headers;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns true if the request indicated by the method and URL requires wallet authentication.
|
|
45
|
+
*
|
|
46
|
+
* @param requestMethod - The HTTP method of the request
|
|
47
|
+
* @param requestPath - The URL path of the request
|
|
48
|
+
* @returns True if the request requires wallet authentication, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
function requiresWalletAuth(requestMethod, requestPath) {
|
|
51
|
+
return (requestPath?.includes("/accounts") && (requestMethod === "POST" || requestMethod === "DELETE"));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns encoded correlation data including the SDK version and language.
|
|
55
|
+
*
|
|
56
|
+
* @param source - The source identifier for the request
|
|
57
|
+
* @param sourceVersion - The version of the source making the request
|
|
58
|
+
* @returns Encoded correlation data as a query string
|
|
59
|
+
*/
|
|
60
|
+
function getCorrelationData(source, sourceVersion) {
|
|
61
|
+
const data = {
|
|
62
|
+
sdk_version: package_json_1.version,
|
|
63
|
+
sdk_language: "typescript",
|
|
64
|
+
source: source || "sdk-auth",
|
|
65
|
+
};
|
|
66
|
+
if (sourceVersion) {
|
|
67
|
+
data["source_version"] = sourceVersion;
|
|
68
|
+
}
|
|
69
|
+
return Object.keys(data)
|
|
70
|
+
.map(key => `${key}=${encodeURIComponent(data[key])}`)
|
|
71
|
+
.join(",");
|
|
72
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./http"), exports);
|
|
18
|
+
__exportStar(require("./jwt"), exports);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JwtOptions contains configuration for JWT generation.
|
|
3
|
+
*
|
|
4
|
+
* This interface holds all necessary parameters for generating a JWT token
|
|
5
|
+
* for authenticating with Coinbase's REST APIs. It supports both EC (ES256)
|
|
6
|
+
* and Ed25519 (EdDSA) keys.
|
|
7
|
+
*/
|
|
8
|
+
export interface JwtOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The API key ID
|
|
11
|
+
*
|
|
12
|
+
* Examples:
|
|
13
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
14
|
+
* 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
15
|
+
*/
|
|
16
|
+
apiKeyId: string;
|
|
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
|
+
* The HTTP method for the request (e.g. 'GET', 'POST')
|
|
27
|
+
*/
|
|
28
|
+
requestMethod: string;
|
|
29
|
+
/**
|
|
30
|
+
* The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
31
|
+
*/
|
|
32
|
+
requestHost: string;
|
|
33
|
+
/**
|
|
34
|
+
* The path for the request (e.g. '/platform/v1/wallets')
|
|
35
|
+
*/
|
|
36
|
+
requestPath: string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional expiration time in seconds (defaults to 120)
|
|
39
|
+
*/
|
|
40
|
+
expiresIn?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* WalletJwtOptions contains configuration for Wallet Auth JWT generation.
|
|
44
|
+
*
|
|
45
|
+
* This interface holds all necessary parameters for generating a Wallet Auth JWT
|
|
46
|
+
* for authenticating with endpoints that require wallet authentication.
|
|
47
|
+
*/
|
|
48
|
+
export interface WalletJwtOptions {
|
|
49
|
+
/**
|
|
50
|
+
* - The Wallet Secret
|
|
51
|
+
*/
|
|
52
|
+
walletSecret: string;
|
|
53
|
+
/**
|
|
54
|
+
* - The HTTP method for the request (e.g. 'GET', 'POST')
|
|
55
|
+
*/
|
|
56
|
+
requestMethod: string;
|
|
57
|
+
/**
|
|
58
|
+
* - The host for the request (e.g. 'api.cdp.coinbase.com')
|
|
59
|
+
*/
|
|
60
|
+
requestHost: string;
|
|
61
|
+
/**
|
|
62
|
+
* - The path for the request (e.g. '/platform/v1/wallets/{wallet_id}/addresses')
|
|
63
|
+
*/
|
|
64
|
+
requestPath: string;
|
|
65
|
+
/**
|
|
66
|
+
* - The request data for the request (e.g. { "wallet_id": "1234567890" })
|
|
67
|
+
*/
|
|
68
|
+
requestData: Record<string, any>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 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.
|
|
73
|
+
*
|
|
74
|
+
* @param options - The configuration options for generating the JWT
|
|
75
|
+
* @returns The generated JWT (Bearer token) string
|
|
76
|
+
* @throws {Error} If required parameters are missing, invalid, or if JWT signing fails
|
|
77
|
+
*/
|
|
78
|
+
export declare function generateJwt(options: JwtOptions): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Generates a wallet authentication JWT for the given API endpoint URL.
|
|
81
|
+
* Used for authenticating with specific endpoints that require wallet authentication.
|
|
82
|
+
*
|
|
83
|
+
* @param options - The configuration options for generating the JWT
|
|
84
|
+
* @returns The generated JWT (Bearer token) string
|
|
85
|
+
* @throws {UndefinedWalletSecretError} If the Wallet Secret is not defined.
|
|
86
|
+
* @throws {InvalidWalletSecretFormatError} If the private key is not in the correct format or signing fails.
|
|
87
|
+
*/
|
|
88
|
+
export declare function generateWalletJwt(options: WalletJwtOptions): Promise<string>;
|