微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Bitstamp Authenticated API hmac

如何解决Bitstamp Authenticated API hmac

我希望你在这方面比我有更多的运气。

正如标题所暗示的,我正在尝试访问 bitstamp.net 上的私有 API 端点。 https://www.bitstamp.net/api/#api-authentication 尽我所能我无法让签名有意义。我尽可能地关注文档,因为没有 JavaScript 示例,我花了几个小时尝试尽可能多地学习 Python 并解密文档。

签名应该是 API 秘密的 sha256 hmac 和消息变量,它是一个反斜杠分隔的字符串,我再也找不到任何问题了。

我使用下面的链接查询服务器,当一切正常时,apikey 和 secret 将在生产中被编码和解码。

http://localhost:3001/sha256/jorw1007/QGcJKrhenfqOML5copTsLOe9IbEPsJnN/bKXiqtYHawJ7DAUZIHviAPoRrp0zhfIv


const crypto = require('crypto');

app.get("/sha256/:id/:key/:secret",cors(),(request,response,next) => {
    const APIkey = "BITSTAMP" + " " + request.params.key;
    const APIsecret = request.params.secret;
    const urlHost = "192.168.0.120:3001"; // where is querying the API from bitstamp? in this case its the server localhost:3001
    const urlPath = "/api/v2/balance/";
    const urlQuery = "";
    const UTC = Date.Now().toString();
    const nonce = randomBytes(18).toString("hex").toLowerCase();
    const nonce2 = "f93c979d-b00d-43a9-9b9c-fd4cd9547fa6"
    const contentType = "application/x-www-form-urlencoded";
    const version = "v2";
    const payload = urlencoded({"offset": "1"})
    let message = `${APIkey}\\POST\\${urlHost}\\${urlPath}\\${urlQuery}\\${nonce}\\${UTC}\\${version}\\`
 
// const encodedMsg = encodeURI(message) ///why are we encoding? 
    // const signature = createHmac("sha256",APIsecret ).update(JSON.stringify(encodedMsg) );
    // const sigDigested = signature.digest('hex')
var signature = crypto.createHmac('sha256',APIsecret).update(encodeURI(message));

// to lowercase hexits
const digestedHash = signature.digest('hex');
console.log(message)

    const headers = {
        "X-Auth": APIkey,"X-Auth-Signature": digestedHash,"X-Auth-Nonce": nonce,"X-Auth-Timestamp": UTC,"X-Auth-Version": version,};

    fetch("https://www.bitstamp.net/api/v2/balance/",{
        headers,method: "POST",data : payload
    })
        .then((res) => res.json())
        .then((json) => response.send(json))
        .catch((err) => console.error(err));
});


我不断收到错误“API0005”,这意味着签名无效。

请问有人能指出我正确的方向吗?

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。