-
-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react/preact: TypeError: crypto_1.createHmac is not a function #141
Comments
Are you using webpack? You can swap out a dependency to one that works in browsers, though I'm not sure if you can do this if you're importing this module: The signing process relies on createHmac(), but in the browser you can use |
I'm using vite/preact setup which uses esbuild and rollup. Could this be an outcome, if |
it shouldn't be but I'm not sure why it's undefined in that scenario. Do esbuild/rollup have something to swap out module dependencies, like webpack does in the link I shared above? Not sure if that works for imported modules though... otherwise it may be necessary to expose a way to pass your own createHmac function. Btw you will be using this frontend, right? Do you have a solution planned for CORS? Binance's APIs aren't configured for it, so most requests will fail the browser's preflight CORS check, preventing you from making API calls to binance. |
There's official support for resolve.alias plugin-alias though syntax looks different from webpack's.
If above wont work how can i do that without making a conflict?
Yes. I'm also figuring out how to use your other repo Ftx-Api for a frontend UI. Both throws Hmac error. Currently I'm bypassing CORS with browser plugin (excuse me for newbie stuff :D) but Planning to serve files with nginx for prod. Even though Binance pulls non-auth server data after `hmac error but Ftx-api doesn't. |
Not sure how to approach it... we could expose an optional property in the constructor parameters, where you could provide a callback function to generate the hmac your own way. Then this part of the library could use the provided hmac function instead of the native one, if it's provided. Seems hacky though. Open to other ideas to enhance this.
Glad both my libraries are helpful! Not sure why you're seeing a difference between both, are you providing API credentials in one but not the other? In the ftx client I only try to sign if there are credentials provided (lazily signing every request): In the binance client I only sign if the endpoint is a private one, in which case the key & secret are checked for presence. |
That would be awesome if hmac can be some multiple ways, specially for people who are using frameworks and if hmac func can be applied plug and play. A basic documentation can be bonus as well, i'd do this myself but i'm still learning and its overwhelming me at this time. Also I think, you should consider about compatibility with preact/vue/svelete (vite is crazy fast dev server) for those frameworks. I might contribute with a boilerplate if i can get it working.
Yes. both libraries shows me Hmac is not a function on PreactJS after providing api keys. |
@for04 I had a simpler idea given how easy it is to detect the issue in your scenario. Please try the latest release. This is the PR if you're curious - it's just a simple fallback if createHmac is not a function.
If it universally makes integration easier for other devs, I'd love to improve compatibility but I also don't have the bandwidth to cover every use case. Contributions are therefore very welcome. |
@tiagosiebler
And it's understandable. |
Nice! Glad to hear. I'll close this for now as the main issue seems resolved. |
getBalance error: TypeError: crypto_1.createHmac is not a function
The text was updated successfully, but these errors were encountered: