UNPKG

@arkhamintelligence/sdk

Version:
35 lines (28 loc) 926 B
import crypto from "crypto"; /** * Arkham Exchange KeyPair */ export class KeyPair { private apiKey?: string | null; private secretBytes?: Buffer | null; constructor(apiKey?: string | null, apiSecret?: string | null) { this.apiKey = apiKey ?? null; this.secretBytes = apiSecret ? Buffer.from(apiSecret, "base64") : null; } signRequest(method: string, path: string, body = ""): Record<string, string> { if (!this.apiKey || !this.secretBytes) { return {}; } const expires = String(Math.floor((Date.now() / 1000 + 300) * 1_000_000)); const signatureString = `${this.apiKey}${expires}${method}${path}${body}`; const signature = crypto .createHmac("sha256", this.secretBytes) .update(signatureString, "utf8") .digest("base64"); return { "Arkham-Api-Key": this.apiKey, "Arkham-Expires": expires, "Arkham-Signature": signature, }; } }