Node JS - help in sign message for cryptofacilities API
- or -
Post a project like this$$
- Posted:
- Proposals: 7
- Remote
- #2025507
- Expired
AI & Data Science Engineer | Nodejs | Ruby On Rails | AWS | GCP | Python | React | Angular |
Auckland
20674350613910886811242585152075619142572118187
Description
Experience Level: Intermediate
Hi,
I am working on a personal script for the crypto facilities website (https://www.cryptofacilities.com/resources/hc/en-us/articles/360000642493-Sign-Challenge-Web-Socket-API-).
I am though struggling to get the sign challenge authenticating using NodeJS. There are github examples for other languages. I have the following script and would like someone to provide me with a confirmed working and authenticated sign challenge script:
// Returns a unique nonce
function createNonce() {
nonce += 1;
var timestamp = (new Date()).getTime();
var n = timestamp + "" + pad(nonce, 4);
return n;
}
// Signs a message
function signMessage(endpoint, nonce, postData) {
//nonce = "15268066395990002";
// orderType=lmt&symbol=FI_XBTUSD_180928&side=buy&size=1.0&limitPrice=1.015268066395990002/api/v3/sendorder
// Step 1: concatenate postData, nonce + endpoint
var message = postData + nonce + endpoint;
console.log(message);
// Step 2: hash the result of step 1 with SHA256
var hash = crypto.createHash("sha256");
hash = hash.update(message);
// step 3: base64 decode apiPrivateKey
var secretDecoded = new Buffer(cryptoSecretLive, 'base64'); // Ta-da
// step 4: use result of step 3 to hash the resultof step 2 with
// HMAC-SHA512
var hmac = crypto.createHmac("sha512", secretDecoded);
var hash2 = hmac.update(hash.digest());
var buff = new Buffer(hash2.digest());
var signed = buff.toString('base64');
return signed;
I am working on a personal script for the crypto facilities website (https://www.cryptofacilities.com/resources/hc/en-us/articles/360000642493-Sign-Challenge-Web-Socket-API-).
I am though struggling to get the sign challenge authenticating using NodeJS. There are github examples for other languages. I have the following script and would like someone to provide me with a confirmed working and authenticated sign challenge script:
// Returns a unique nonce
function createNonce() {
nonce += 1;
var timestamp = (new Date()).getTime();
var n = timestamp + "" + pad(nonce, 4);
return n;
}
// Signs a message
function signMessage(endpoint, nonce, postData) {
//nonce = "15268066395990002";
// orderType=lmt&symbol=FI_XBTUSD_180928&side=buy&size=1.0&limitPrice=1.015268066395990002/api/v3/sendorder
// Step 1: concatenate postData, nonce + endpoint
var message = postData + nonce + endpoint;
console.log(message);
// Step 2: hash the result of step 1 with SHA256
var hash = crypto.createHash("sha256");
hash = hash.update(message);
// step 3: base64 decode apiPrivateKey
var secretDecoded = new Buffer(cryptoSecretLive, 'base64'); // Ta-da
// step 4: use result of step 3 to hash the resultof step 2 with
// HMAC-SHA512
var hmac = crypto.createHmac("sha512", secretDecoded);
var hash2 = hmac.update(hash.digest());
var buff = new Buffer(hash2.digest());
var signed = buff.toString('base64');
return signed;
Matthew O.
100% (18)Projects Completed
25
Freelancers worked with
23
Projects awarded
60%
Last project
25 Mar 2022
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
Please let me know if still available?
654684
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies