Created
January 29, 2015 21:15
-
-
Save jorilallo/1e61f3185ef75f00759b to your computer and use it in GitHub Desktop.
Coinbase Exchange signing with Node.js
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
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