Created
March 10, 2020 11:24
-
-
Save igotit-anything/70b0aa30a727f4e13972fbae2d9a795a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 잔액 조회하기 | |
// | |
var crypto = require('crypto'); | |
var request = require('request'); | |
// 발급받은 api키와 시크릿키를 입력한다 | |
var apikey = 'akdhfafheur'; | |
var secret = 'ausdufasffdkljieurueadfjklj'; | |
// nonce값 생성 | |
var nonce = Date.now() * 1000; | |
var method = 'GET'; | |
var requestPath = '/balances'; | |
// 필수 정보를 연결하여 prehash 문자열을 생성함 | |
var what = nonce + method + requestPath; | |
// base64로 secret을 디코딩함 | |
var key = Buffer(secret, 'base64'); | |
// secret으로 sha512 hmac을 생성함 | |
var hmac = crypto.createHmac('sha512', key); | |
// hmac으로 필수 메시지에 서명하고 | |
// 그 결과물을 base64로 인코딩함 | |
var sign = hmac.update(what).digest('base64'); | |
var host = 'api.gopax.co.kr'; | |
var options = { | |
method, | |
json: true, | |
url: `https://${host}${requestPath}`, | |
headers: { | |
'API-KEY': apikey, | |
Signature: sign, | |
Nonce: nonce, | |
}, | |
strictSSL: false, | |
}; | |
request(options, (err, response, b) => { | |
if (err) { | |
console.log('err:', err); | |
return; | |
} | |
console.log(b); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment