Created
December 17, 2017 21:31
-
-
Save timpetri/eae353ef25af04e6ec1c6d2d42eb584d to your computer and use it in GitHub Desktop.
Use CryptoJS for CB-ACCESS-SIGN GDAX API header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code does the equivalent of the node code provided in the GDAX API docs | |
var secret = 'PYPd1Hv4J6/7x...'; | |
var timestamp = Date.now() / 1000; | |
var requestPath = '/orders'; | |
var body = JSON.stringify(""); // body goes here | |
// create the prehash string by concatenating required parts | |
var message = timestamp + method + requestPath + body; | |
// Base64 decode the alphanumeric secret string | |
var key = CryptoJS.enc.Base64.parse(secret); | |
// Use it as key for SHA 256 HMAC | |
var signedMessage = CryptoJS.HmacSHA256(message, key); | |
// base 64 encode the digest output before sending in header | |
var output = signedMessage.toString(CryptoJS.enc.Base64); | |
return output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment