diff --git a/js/base/functions/crypto.js b/js/base/functions/crypto.js index ddbd56b0b623f..2a2f4fce22297 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..81fcc483a2bcc 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);