bitpay / bitcore-mnemonic

BIP39 Mnemonics implemented for Bitcore
http://bitcore.io
MIT License
155 stars 212 forks source link

Can't instantiate Mnemonic in a web worker #24

Closed Giszmo closed 8 years ago

Giszmo commented 9 years ago

Mnemonic.prototype.toHDPrivateKey() takes 20s on my Anroid and thus I'd like to create it "in the background".

Putting it in a new Worker() yields Uncaught Error: Uncaught ReferenceError: window is not defined. Apparently this stems from bitcore:

if ((inBrowser && window._bitcore) || (!inBrowser && global._bitcore)) {.

I browserified Mnemonic and try to include it like this:

importScripts(e.data.url + '/lib/bundle2.browser.js') // in this line above error is thrown

(I would prefer to have bitcore to offer a promise-based way to do expensive stuff like this ;) )

maraoz commented 9 years ago

Please take a look at this: https://github.com/bitpay/bitcore/issues/1168

Hope it solves the problem. Report if it doesn't

braydonf commented 9 years ago

I wonder if there is a way that browserify or other can build for use in a web worker.

Giszmo commented 9 years ago

Thank you very much @maraoz ! Your link worked :)

I still wonder if it would not be possible to depend less on those environment things in this crypto library.

braydonf commented 8 years ago

This should be fixed with: https://github.com/bitpay/bitcore/pull/1322