Skip to content

Instantly share code, notes, and snippets.

@funador
Created January 6, 2018 18:56
Show Gist options
  • Save funador/9d2bf138e7953b6ede78ad99eefa73dd to your computer and use it in GitHub Desktop.
Save funador/9d2bf138e7953b6ede78ad99eefa73dd to your computer and use it in GitHub Desktop.
const request = require('request')
const hmacSha384 = require('crypto-js/hmac-sha384')
const btoa = require('btoa')
const pubKey = 'my-pub-key'
const priKey = 'my-pri-key'
const data = JSON.stringify({'hello': 'world'})
// Hash the data with the private key then Base64 encode
const priKeyHash = hmacSha384(data, priKey)
const priKeyBase64 = btoa(priKeyHash)
// also tried this:
// const priKeyBase64 = Buffer.from(JSON.stringify(priKeyHash)).toString('base64')
const options = {
url: 'https://icobench.com/api/v1/other/stats',
headers: {
'Content-Type': 'application/json',
'X-ICObench-Key': pubKey,
'X-ICObench-Sig': priKeyBase64
}
};
request.post(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
const info = JSON.parse(body);
console.log(info)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment