Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Minimal browser builds #8

Closed
kumavis opened this issue Aug 25, 2016 · 6 comments
Closed

Minimal browser builds #8

kumavis opened this issue Aug 25, 2016 · 6 comments

Comments

@kumavis
Copy link
Member

kumavis commented Aug 25, 2016

by supplying our own more minimal version of https://github.com/crypto-browserify/crypto-browserify
we can drop the following deps:

require('diffie-hellman')
require('browserify-sign')
require('create-ecdh')
require('public-encrypt')

bc we are only using

crypto.randomBytes
crypto.pbkdf2Sync
crypto.createCipheriv
crypto.createDecipheriv

we just need to make a more minimal crypto entrypoint https://github.com/crypto-browserify/crypto-browserify/blob/master/index.js
and sub it out with the browser field https://github.com/substack/node-browserify#browser-field

@chiro-hiro
Copy link

@kumavis I have tried to build my own browser version by using browserify. It's working damn slow.

@IstoraMandiri
Copy link

@tad88dev same experience; toV3 is taking around 20 seconds in Chromium

@axic
Copy link
Member

axic commented Dec 4, 2016

@tad88dev @hitchcott I'm afraid that is an intentional parameter of using scrypt. The point of scrypt is to be CPU and memory hard. Using the C scrypt implementation it is >10 times faster though.

In the browser it should be run in a worker.

Alternatively you can try tweaking the scrypt parameters (https://github.com/ethereumjs/ethereumjs-wallet#remarks-about-tov3) with the risk of reducing security significantly. Some wallets (such as keythereum) use much lower iteration count and thus they are faster. etheruemjs-wallet uses the default settings used by geth.

@chiro-hiro
Copy link

@axic Agree, scrypt.js is slow down whole process. I have some "cheats" to speed up without change the scrypt parameters.
I have a table to lookup computed scrypt hash:
sha-256(x) ----> scrypt(x)

@IstoraMandiri
Copy link

IstoraMandiri commented Dec 6, 2016

Thanks @axic, the webworker solution should be good enough. Perhaps it's worth adding to the docs.

Perhaps even webworker could be used automatically if that feature is detected.

@connectdotz
Copy link

has this problem ever resolved? can this library actually run in the browser with reasonable performance? According to browserify:

Get browser versions of the node core libraries events, stream, path, url, assert, buffer, util, querystring, http, vm, and crypto when you require() them

Looks like the code is still using the node.js crypto, therefore wondering if this ever resolved?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants