You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bitfinex API v2签名无效报错:如何通过JS获取比特币存款地址?

Bitfinex API签名无效(10112)问题解决

你的代码缺少Bitfinex私有API必需的签名和随机数(nonce),这是触发signature: invalid错误的核心原因。Bitfinex所有需要身份验证的接口都要求通过签名校验,以下是修正后的完整代码:

const CryptoJS = require('crypto-js')
const fetch = require('node-fetch')

const apiKey = 'xxxxxxxxx'
const apiSecret = 'xxxxxxxxxx'
const apiPath = 'v2/auth/w/deposit/address'

// 1. 生成唯一nonce(用当前毫秒时间戳,确保每次请求唯一)
const nonce = Date.now().toString()
// 2. 提前定义请求体,避免重复序列化导致内容不一致
const body = JSON.stringify({
  wallet: 'trading',
  method: 'bitcoin',
  op_renew: 0
})
// 3. 按规则生成签名:路径+nonce+请求体拼接后,用HMAC-SHA384加密转Base64
const signaturePayload = apiPath + nonce + body
const signature = CryptoJS.HmacSHA384(signaturePayload, apiSecret).toString(CryptoJS.enc.Base64)

fetch(`https://api.bitfinex.com/${apiPath}`, {
  method: 'POST',
  body: body,
  headers: {
    'Content-Type': 'application/json',
    'bfx-apikey': apiKey,
    'bfx-nonce': nonce, // 新增nonce请求头
    'bfx-signature': signature // 新增签名请求头
  }
})
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.log(err))

关键改动说明:

  • nonce生成:用Date.now()生成毫秒级时间戳作为nonce,必须保证每个请求的nonce唯一,这是Bitfinex签名验证的基础要求。
  • 签名生成逻辑:严格按照Bitfinex规则,将接口路径、nonce、请求体拼接成字符串,以API Secret为密钥,通过HMAC-SHA384算法加密后转成Base64格式,作为签名头的值。
  • 补充认证头:请求头必须同时携带bfx-nonce和bfx-signature,二者缺一都会导致签名验证失败。

内容的提问来源于stack exchange,提问作者Nafisa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 03:15:02