UNPKG

@okx-dex/okx-dex-sdk

Version:
28 lines (27 loc) 1.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHeaders = getHeaders; const crypto_js_1 = __importDefault(require("crypto-js")); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config(); function getHeaders(timestamp, method, requestPath, queryString = "", requestBody = "") { const apiKey = process.env.OKX_API_KEY; const secretKey = process.env.OKX_SECRET_KEY; const apiPassphrase = process.env.OKX_API_PASSPHRASE; const projectId = process.env.OKX_PROJECT_ID; if (!apiKey || !secretKey || !apiPassphrase || !projectId) { throw new Error("Missing required environment variables"); } const stringToSign = timestamp + method + requestPath + queryString; return { "Content-Type": "application/json", "OK-ACCESS-KEY": apiKey, "OK-ACCESS-SIGN": crypto_js_1.default.enc.Base64.stringify(crypto_js_1.default.HmacSHA256(stringToSign, secretKey)), "OK-ACCESS-TIMESTAMP": timestamp, "OK-ACCESS-PASSPHRASE": apiPassphrase, "OK-ACCESS-PROJECT": projectId, }; }