bash - Coinbase.com 签名无效

标签 bash curl go signature coinbase-api

我搜索了其他帖子,因为我不是唯一有签名问题的人。我尝试了几种语言,但我总是遇到同样的问题。

我在使用 coinbase.com 进行 API 身份验证时做错了什么:

# normally I fetch the timestamp from https://api.coinbase.com/v2/time
TIMESTAMP=$(date +%s)
SIG=$(echo -n "${TIMESTAMP}GET/v2/accounts" | hmac256 --stdkey $COINBASE_SECRET)

curl https://api.coinbase.com/v2/accounts \
  --header "CB-ACCESS-KEY: $COINBASE_KEY" \
  --header "CB-ACCESS-SIGN: $SIG" \
  --header "CB-ACCESS-TIMESTAMP: $TIMESTAMP" \
  --header "CB-VERSION: 2016-03-08"

在 go 中,我正在尝试做类似的事情:

nonce := strconv.FormatInt(int64(time.Data.Epoch), 10)
message := nonce + req.Method + endpoint // endpoint "/v2/accounts"
req.Header.Set("CB-ACCESS-KEY", a.Key)
h := hmac.New(sha256.New, []byte(a.Secret))
h.Write([]byte(message))

signature := hex.EncodeToString(h.Sum(nil))

req.Header.Set("CB-ACCESS-SIGN", signature)
req.Header.Set("CB-ACCESS-TIMESTAMP", nonce)
req.Header.Set("CB-VERSION", "2016-03-08")

此外,由于 api.sandbox.coinbase.com 不可用,沙盒似乎不再受支持?!

亲切的问候

最佳答案

对于 bash/curl,问题是我与 echo 一起使用的 hmac 工具。以下为我处理 curl 请求:

SIG=$(echo -n "${TIMESTAMP}GET/v2/accounts" | openssl dgst -sha256 -hmac "$COINBASE_SECRET" |cut -d' ' -f2);

关于 golang,我比较了哈希总和并得出结论,我正在使用的当前库有些可疑。

我自己编写了一个库 ( https://github.com/Zauberstuhl/go-coinbase ),现在它就像一个魅力。 除了我使用 Sprintf 进行最终编码外,我正在做与上面相同的事情,但这应该是相同的。

谢谢!

关于bash - Coinbase.com 签名无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41809503/

相关文章:

java - 如何将curl调用转换为java HttpPost : curl --form "archive=@test.pdf;type=application/pdf"

go - 向 exec.Cmd.StdinPipe() 写入超过 4K 字节

golang 系统日志故障 : Unix syslog delivery error

http - 在 Go 中检测断开连接的正确方法是什么?

linux - 如何将目录变成隐藏目录

linux - crontab中运行脚本--reboot : command not found

bash - 将分区和分割(A.1 和 A.1.1)分配给文件中的数据

c - 程序不显示下载速度和文件大小 (curl)

bash - 如何使用数组元素的参数执行 bash 命令?

PHP:检查图像是否存在(方法)