trezor / hd-wallet

:moneybag: High-performance Bitcoin HD Wallet in Javascript
GNU Lesser General Public License v3.0
58 stars 32 forks source link

fastxpub in browser #18

Closed dylanseago closed 6 years ago

dylanseago commented 6 years ago

When using webpack worker-loader with fastxpub.js the following error message comes up during the build:

ERROR in ./node_modules/hd-wallet/lib/fastxpub/fastxpub.js
Module not found: Error: Can't resolve 'fs' in './node_modules/hd-wallet/lib/fastxpub'
@ ./node_modules/hd-wallet/lib/fastxpub/fastxpub.js 15:417-430

It looks like something that uses both fs and path is being included in the browserified output

karelbilek commented 6 years ago

Yeah, that is some magic from emscripten that I could not remove when I tried

I remember I had some problems with that too, but then I solved it - I don't load fastxpub by worker loader at all, because worker-loader parses the .js and tries to put it through babel etc; in web wallet I just copy the file and use the worker directly (new Worker("./fastxpub.js"))

I also do some terrible hacking here - https://github.com/trezor/hd-wallet/blob/master/test/discovery.js#L44 (I was glad I got it working in both node and karma)

Maybe it is possible to tell workerLoader to not do parsing of the js and just use it as is?

karelbilek commented 6 years ago

setting up emscripten + webworkers + wepack is hell

If it didn't add significant performance boost for the xpub generation, I would remove it, but it makes the math really fast :/

dylanseago commented 6 years ago

I was able to get rid of the error by adding this to my webpack config :)

node: {
  fs: "empty"
}
dylanseago commented 6 years ago

Here's what I did to get this all working with webpack:

karelbilek commented 6 years ago

NICE! Thx for info