bithumb-pro / bithumb.pro-official-api-docs

rest and websocket api doc
22 stars 26 forks source link

issue with 'verifySignature failed' #39

Open biemsday opened 4 years ago

biemsday commented 4 years ago

hi there, I have a issue when I try to make POST request to (https://global-openapi.bithumb.pro/openapi/v1) using JavaScript

first of all I get some params

var api = "3e552699dccebd747936c50a7***"
var msgNo = Math.floor(Math.random() * 100)
var timestamp = Date.now()
var secret = "42720b96a97dfdd2c582ba34f5f8cefe1f48329860***"

then I make ugly-handy string like this

var presignature = 'api=' + api + '&msgNo=' + msgNo + '&timestamp=' + timestamp + '&version=v1.0.0'

then I generate HmacSHA256 hash, for this part I use this thing https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#js

var hash = CryptoJS.HmacSHA256(presignature, secret);
var signature = CryptoJS.enc.Base64.stringify(hash).toLowerCase();

in the end I make request

const rawResponse = await fetch('https://global-openapi.bithumb.pro/openapi/v1/spot/assetList?assetType=wallet' , {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        apiKey: api,
        msgNo: msgNo,
        timestamp: timestamp,
        version: "v1.0.0",
        signature: signature
    })
});
const content = await rawResponse.json();

after all of this moves I'll get error in response

{"data":null,"code":"9002","msg":"verifySignature failed","timestamp":1590096941474,"startTime":null}

help me please %_%

godlikers commented 4 years ago

hi, i found your request is about 'assetList', 'assetType=wallet' also must add in presignature for final signature.

biemsday commented 4 years ago

hi, thank you for answer! I do changes, and code does not work again I create github rep. - https://github.com/biemsday/test-api-bthmb @godlikers can you help me and validate my code? I'm really don't understand what I do wrong %_%

godlikers commented 4 years ago

you can find error code in doc (https://github.com/bithumb-pro/bithumb.pro-official-api-docs/blob/master/rest-api.md#code-list)

biemsday commented 4 years ago

Yeah, I check it, my error is

9002 | verifySignature failed

But I don't understand, what I do wrong in JS..

godlikers commented 4 years ago

i had checked the api of "Get your wallet statement" in (https://biemsday.github.io/test-api-bthmb/ ) by use my apiKey, and i found the error is "9007", may be your local time exist delay with the server.

godlikers commented 4 years ago

image