2017-01-23 178 views
0

我搜索了其他帖子,因为我不是唯一签署问题的人。我用几种语言尝试过,而且我总是遇到同样的问题。Coinbase.com无效签名

什么我错与API认证做与coinbase.com:

# 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不可用?

亲切的问候

+0

使用time.Now().Unix()或更好的方法是使用[library](https://developers.coinbase.com/docs/wallet/client-libraries) – Mark

+0

@Mark提到的golang库已经过时并仍然使用v1 – zio

回答

0

对bash /卷曲的问题是HMAC工具我echo使用。下面为我​​工作的,卷曲的请求:

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

关于golang的我相比,哈希款项,并得出结论的东西是腥与我使用的是当前库。

我自己写了一个图书馆(https://github.com/Zauberstuhl/go-coinbase),现在它像一个魅力。 我在做和上面一样的操作,只是我使用Sprintf作为最终编码,但应该是相同的。

无论如何,谢谢!