【发布时间】:2017-06-08 03:34:33
【问题描述】:
我搜索了其他帖子,因为我不是唯一有签名问题的人。我尝试了几种语言,但总是遇到同样的问题。
我在使用 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"
我正在尝试做类似的事情:
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 不可用,似乎不再支持沙盒?!
亲切的问候
【问题讨论】:
-
使用 time.Now().Unix(),或者更好,使用library
-
@Mark 提到的 golang 库已经过时,仍然使用 v1
标签: bash curl go signature coinbase-api