tiagosiebler / ftx-api

Node.js connector for the FTX.com & FTX.us APIs and WebSockets, with TypeScript & browser support.
https://www.npmjs.com/package/ftx-api
MIT License
123 stars 47 forks source link

react/preact: TypeError: crypto_1.createHmac is not a function #34

Closed for04 closed 3 years ago

for04 commented 3 years ago

Same issue produced as https://github.com/tiagosiebler/binance/issues/141.

So i follwed your binance edit. Is this gonna work?

https://github.com/for04/ftx-api/blob/edffe1ce97deedc563a0c16a34c0da6549e5d40e/src/util/node-support.ts#L2-L10

node-support.ts

import { createHmac } from 'crypto';
import * as browserMethods from './browser-support';

export async function signMessage(message: string, secret: string): Promise<string> {
   if (typeof createHmac === 'function') { 
  return createHmac('sha256', secret)
    .update(message)
    .digest('hex');
}
};

export async function signWsAuthenticate(timestamp: number, secret: string): Promise<string> {
  return signMessage(timestamp + 'websocket_login', secret);
};
tiagosiebler commented 3 years ago

It should work there too, just remember to call browserMethods.createHmac if createHmac is not a function: https://github.com/tiagosiebler/ftx-api/blob/master/src/util/node-support.ts

Would you mind doing making a pull request with the change? Thanks!

for04 commented 3 years ago

@tiagosiebler sent pull, can you release an npm update soon, looking forward to using it? thanks

tiagosiebler commented 3 years ago

@tiagosiebler sent pull, can you release an npm update soon, looking forward to using it? thanks

Published with v1.0.15 on npm. Thanks!