-
Notifications
You must be signed in to change notification settings - Fork 445
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
feat: defer/lazy load word lists #95
Comments
We've been throwing around similar ideas for a while, but it's low priority right now. I was thinking of making it more generic and making an npm package for each wordlist. |
@dcousens I wonder if a lazy loading Proxy might be good... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
That way, a person looking to add bip39 with English only to their app will do
Then in their app: const bip39 = require('bip39')
// bip39 currently has not loaded any wordlists into memory
bip39.mnemonicToSeed(mn, pass)
// doesn't throw an error and still no wordlist in bip39.wordlists. since it doesn't use wordlists.
bip39.entropyToMnemonic(crypto.randomBytes(16))
// this will perform wordlist = wordlist || bip39.wordlists.english
// which will have the Proxy of wordlists do require('@bip39/english') and return that. storing it within bip39.wordlists
// if the require fails, return undefined. hmmm... I'll have to test it out. |
I don't think many packages is necessary. The only issue is the bundle burden, not npm. |
I made a PR with one idea... |
currently word lists are loaded all at start-up, while realistically the user only ever needs to use one at a time. The suggestion is to make word-lists initialize lazily, and only after the language choice has been made. This abstraction could be hidden in a separate js file to make the main file less verbose. (Imho 154 lines is verbose. You might have taller screens / bigger heads than me, YMMW :-p)
The text was updated successfully, but these errors were encountered: