Skip to content

Instantly share code, notes, and snippets.

@jorilallo
Created January 29, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorilallo/1e61f3185ef75f00759b to your computer and use it in GitHub Desktop.
Save jorilallo/1e61f3185ef75f00759b to your computer and use it in GitHub Desktop.
Coinbase Exchange signing with Node.js
var crypto = require('crypto');
var secret = 'PYPd1Hv4J6/7x...';
var timestamp = Date.now() / 1000;
var req_url = '/orders';
var body = JSON.stringify({
price: '1.0',
size: '1.0',
side: 'buy',
product_id: 'BTC-USD'
});
var method = 'POST';
// create the prehash string by concatenating required parts
var what = timestamp + method + req_url + body;
// decode the base64 secret
var key = Buffer(secret, 'base64');
// create a sha256 hmac with the secret
var hmac = crypto.createHmac('sha256', key);
// sign the require message with the hmac
// and finally base64 encode the result
return hmac.update(what).digest('base64');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment