如何使Bitfinex api v1签名?



我正在尝试从bitfinex身份验证的端点获取响应,但我总是收到错误401:"无效的X-BFX签名。我不确定 base64 编码或创建 hmac。谢谢你的帮助。 Bitfinex 示例:https://docs.bitfinex.com/docs/rest-auth

这是我的代码: ` 请求数据 =

({
...request.data,
request: request.url,
nonce: Date.now().toString()
})
request.headers = {
'Content-Type': 'application/json',
'X-BFX-APIKEY': config.bitfinex.apiKey,
'X-BFX-PAYLOAD':     Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(JSON.stringify(request.data))),
'X-BFX-SIGNATURE': Crypto.HmacSHA384(config.bitfinex.secretKey,      Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(JSON.stringify(request.data)))).toString()      
}`

我找到了有效的解决方案,我必须编辑随机数和签名:

request.data = JSON.stringify({
...request.data,
request: request.url,
nonce: (1000 * new Date().getTime()).toString()
})
request.headers = {
'Content-Type': 'application/json',
'X-BFX-APIKEY': config.bitfinex.apiKey,
'X-BFX-PAYLOAD': Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(request.data)),
'X-BFX-SIGNATURE': Crypto.HmacSHA384(Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(request.data)),
config.bitfinex.secretKey)
}

最新更新