From 2482f5e127b4e190e849c5882843552d07296852 Mon Sep 17 00:00:00 2001 From: Hanyuan Dong Date: Thu, 12 Jul 2018 00:10:31 -0700 Subject: [PATCH 1/2] huobi new signature --- js/base/functions/crypto.js | 8 ++++++++ js/huobipro.js | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/js/base/functions/crypto.js b/js/base/functions/crypto.js index ddbd56b0b623f..734d60f75788d 100644 --- a/js/base/functions/crypto.js +++ b/js/base/functions/crypto.js @@ -2,6 +2,7 @@ /* ------------------------------------------------------------------------ */ +const Crypto = require ('crypto'); const CryptoJS = require ('crypto-js') const { capitalize } = require ('./string') const { stringToBase64, utf16ToBase64, urlencodeBase64 } = require ('./encode') @@ -34,10 +35,17 @@ const jwt = function JSON_web_token (request, secret, alg = 'HS256', hash = 'sha return [ token, signature ].join ('.') } +const ecdsa = (signature, privateKey, hash = 'sha256', digest = 'hex') => { + const sign = Crypto.createSign (hash); + sign.update(signature); + return sign.sign (privateKey, digest); +} + /* ------------------------------------------------------------------------ */ module.exports = { + ecdsa, hash, hmac, jwt diff --git a/js/huobipro.js b/js/huobipro.js index 6bec4cc343e5a..d964a848eaa23 100644 --- a/js/huobipro.js +++ b/js/huobipro.js @@ -50,6 +50,11 @@ module.exports = class huobipro extends Exchange { 'doc': 'https://github.com/huobiapi/API_Docs/wiki/REST_api_reference', 'fees': 'https://www.huobi.pro/about/fee/', }, + 'requiredCredentials': { + 'apiKey': true, + 'secret': true, + 'password': true, + }, 'api': { 'market': { 'get': [ @@ -724,7 +729,9 @@ module.exports = class huobipro extends Exchange { // eslint-disable-next-line quotes let payload = [ method, this.hostname, url, auth ].join ("\n"); let signature = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); + const privateSignature = this.ecdsa (signature, this.password, 'sha256', 'base64') auth += '&' + this.urlencode ({ 'Signature': signature }); + auth += '&' + this.urlencode ({ 'PrivateSignature': privateSignature }); url += '?' + auth; if (method === 'POST') { body = this.json (query); From 070025218303110b53b2e472b6ff814e0a7cdda2 Mon Sep 17 00:00:00 2001 From: Hanyuan Dong Date: Thu, 12 Jul 2018 00:12:16 -0700 Subject: [PATCH 2/2] fixed small issue --- js/base/functions/crypto.js | 2 +- js/huobipro.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/base/functions/crypto.js b/js/base/functions/crypto.js index 734d60f75788d..2a2f4fce22297 100644 --- a/js/base/functions/crypto.js +++ b/js/base/functions/crypto.js @@ -37,7 +37,7 @@ const jwt = function JSON_web_token (request, secret, alg = 'HS256', hash = 'sha const ecdsa = (signature, privateKey, hash = 'sha256', digest = 'hex') => { const sign = Crypto.createSign (hash); - sign.update(signature); + sign.update (signature); return sign.sign (privateKey, digest); } diff --git a/js/huobipro.js b/js/huobipro.js index d964a848eaa23..81fcc483a2bcc 100644 --- a/js/huobipro.js +++ b/js/huobipro.js @@ -729,7 +729,7 @@ module.exports = class huobipro extends Exchange { // eslint-disable-next-line quotes let payload = [ method, this.hostname, url, auth ].join ("\n"); let signature = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); - const privateSignature = this.ecdsa (signature, this.password, 'sha256', 'base64') + const privateSignature = this.ecdsa (signature, this.password, 'sha256', 'base64'); auth += '&' + this.urlencode ({ 'Signature': signature }); auth += '&' + this.urlencode ({ 'PrivateSignature': privateSignature }); url += '?' + auth;