Created
January 6, 2018 18:56
-
-
Save funador/9d2bf138e7953b6ede78ad99eefa73dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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