简体   繁体   中英

XMLHttpRequest, SHA512 and BTC - E

I am making an XMLHttpRequest to BTC - E. API documentation can be seen here: https://btc-e.com/api/documentation

var apiKey;
var apiSec;
var response;
var nonce;
var sign;

function signMessage() {
    nonce = (new Date()).getTime().toString();
    var hash = CryptoJS.HmacSHA512("?method=getInfo&nonce=" + nonce, apiSec);
    sign = hash.toString(CryptoJS.enc.Hex);
}

function getPrice() {
var req = new XMLHttpRequest();
req.open("POST","https://btc-e.com/tapi", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Key", apiKey);
req.setRequestHeader("Sign", sign);
req.send("method=getInfo&nonce=" + nonce);
req.onload = function() {
    response = JSON.parse(req.responseText);
};
}
signMessage();
getPrice();
console.log(responce);

It seems that the hashing is done correctly or at least getting a correct looking string back. Server response: {"success":0,"error":"invalid nonce parameter; on key:0, you sent:1389814528941"}

Have struggled for hours and can't figure out what's wrong.

Btc-e is capped at 4294967294 for nonces. https://www.npmjs.org/package/btc-e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM