Skip to content

Instantly share code, notes, and snippets.

@tmm
tmm / gdax.js
Last active February 11, 2021 08:44 — forked from timpetri/gdax.js
Use CryptoJS for `CB-ACCESS-SIGN` GDAX API header
import CryptoJS from 'crypto-js'
const GDAX_SECRET = 'PYPd1Hv4J6/7x...';
const getGdaxSignature = (endpoint, body = '') => {
const timestamp = Date.now() / 1000;
const body = JSON.stringify(body);
const message = timestamp + method + endpoint + body; // create prehash string by concatenating required parts
const key = CryptoJS.enc.Base64.parse(GDAX_SECRET); // Base64 decode the alphanumeric secret string
const signedMessage = CryptoJS.HmacSHA256(message, key); // use it as key for SHA 256 HMAC