11import zip from 'lodash.zipobject'
22import JSONbig from 'json-bigint'
3- import { createHmacSignature } from './signature'
3+ import { createHmacSignature , createAsymmetricSignature } from './signature'
44
55// Robust environment detection for Node.js vs Browser
66const isNode = ( ( ) => {
@@ -230,10 +230,21 @@ const keyCall =
230230 * @returns {object } The api response
231231 */
232232const privateCall =
233- ( { apiKey, apiSecret, proxy, endpoints, getTime = defaultGetTime , pubCall, testnet } ) =>
233+ ( {
234+ apiKey,
235+ apiSecret,
236+ privateKey,
237+ proxy,
238+ endpoints,
239+ getTime = defaultGetTime ,
240+ pubCall,
241+ testnet,
242+ } ) =>
234243 ( path , data = { } , method = 'GET' , noData , noExtra ) => {
235- if ( ! apiKey || ! apiSecret ) {
236- throw new Error ( 'You need to pass an API key and secret to make authenticated calls.' )
244+ if ( ! apiKey || ( ! apiSecret && ! privateKey ) ) {
245+ throw new Error (
246+ 'You need to pass an API key and secret/privateKey to make authenticated calls.' ,
247+ )
237248 }
238249
239250 return (
@@ -250,10 +261,22 @@ const privateCall =
250261 const dataToSign = queryString . substr ( 1 )
251262
252263 // Create signature (async in browser, sync in Node.js)
253- return createHmacSignature ( dataToSign , apiSecret ) . then ( signature => ( {
254- timestamp,
255- signature,
256- } ) )
264+ if ( apiSecret ) {
265+ return createHmacSignature ( dataToSign , apiSecret ) . then ( signature => ( {
266+ timestamp,
267+ signature,
268+ } ) )
269+ } else if ( privateKey ) {
270+ const sig = createAsymmetricSignature ( dataToSign , privateKey )
271+ // .then(signature => ({
272+ // timestamp,
273+ // signature,
274+ // }))
275+ return {
276+ timestamp,
277+ signature : sig ,
278+ }
279+ }
257280 } )
258281 . then ( ( { timestamp, signature } ) => {
259282 const newData = noExtra ? data : { ...data , timestamp, signature }
0 commit comments