@@ -4,6 +4,7 @@ import request from 'request';
44import CryptoJS from 'crypto' ;
55import codes from './codes' ;
66import log from './log' ;
7+ import { keyVersion2 } from './utils' ;
78
89const IS_PRODUCT = global . _USE_KUMEX_ONLINE_ || process . env . PRODUCTION === 'true' ;
910const baseUrl = IS_PRODUCT ? 'https://api.kumex.com' : 'https://sandbox-api.kumex.com' ;
@@ -34,6 +35,8 @@ class Http {
3435 //
3536 static auth ( configs , data = '' , secret = '' ) {
3637
38+ const isKeyVersion2 = keyVersion2 ( HttpConfig . signatureConfig . keyVersion ) ;
39+
3740 const timestamp = Date . now ( ) ;
3841
3942 const signature = Http . sign ( timestamp + configs . method . toUpperCase ( ) + configs . url + data , secret ) ;
@@ -44,14 +47,21 @@ class Http {
4447 if ( ! HttpConfig . signatureConfig . passphrase ) {
4548 log ( 'KC-API-PASSPHRASE is not specified' ) ;
4649 }
47- return {
50+ const headers = {
4851 // ...(configs.headers || {}),
4952 'KC-API-KEY' : HttpConfig . signatureConfig . key || '' ,
5053 'KC-API-SIGN' : signature ,
5154 'KC-API-TIMESTAMP' : timestamp ,
5255 'KC-API-PASSPHRASE' : HttpConfig . signatureConfig . passphrase || '' ,
5356 'Content-Type' : 'application/json' ,
5457 } ;
58+
59+ if ( isKeyVersion2 ) {
60+ headers [ 'KC-API-PASSPHRASE' ] = Http . sign ( HttpConfig . signatureConfig . passphrase || '' , secret ) ;
61+ headers [ 'KC-API-KEY-VERSION' ] = HttpConfig . signatureConfig . keyVersion ;
62+ } ;
63+
64+ return headers ;
5565 }
5666
5767
0 commit comments