UNPKG

mexc-futures-sdk

Version:

Unofficial TypeScript SDK for MEXC Futures trading with maintenance bypass. Uses browser session tokens to work 24/7 even during API downtime.

59 lines 2.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateHeaders = generateHeaders; const constants_1 = require("./constants"); const md5_1 = __importDefault(require("md5")); /** * Generate MEXC crypto signature using MD5 algorithm * Based on GitHub code: https://github.com/user/repo * @param key WEB authentication key * @param obj Request object to sign * @returns Object with timestamp and signature */ function mexcCrypto(key, obj) { const dateNow = String(Date.now()); const g = (0, md5_1.default)(key + dateNow).substring(7); const s = JSON.stringify(obj); const sign = (0, md5_1.default)(dateNow + s + g); return { time: dateNow, sign: sign }; } /** * Generate HTTP headers for API requests * @param options SDK configuration options * @param includeAuth Whether to include authentication headers * @param requestBody Request body for signature (optional) * @returns Record of HTTP headers */ function generateHeaders(options, includeAuth = true, requestBody) { const headers = { ...constants_1.DEFAULT_HEADERS, }; // Override user agent if provided if (options.userAgent) { headers["user-agent"] = options.userAgent; } // Add custom headers if provided if (options.customHeaders) { Object.assign(headers, options.customHeaders); } // Add authentication headers for private endpoints if (includeAuth) { // Use WEB token for authentication headers["authorization"] = options.authToken; // Add MEXC signature for POST requests with body if (requestBody) { const signature = mexcCrypto(options.authToken, requestBody); headers["x-mxc-nonce"] = signature.time; headers["x-mxc-sign"] = signature.sign; console.log("🔐 MEXC signature debug:"); console.log(` Timestamp: ${signature.time}`); console.log(` Signature: ${signature.sign}`); console.log(` Request body: ${JSON.stringify(requestBody)}`); } } return headers; } //# sourceMappingURL=headers.js.map