Closed itsMikeLowrey closed 6 years ago
I was able to find it on this page https://github.com/bitcoinjs/bip39/blob/v2.5.0/index.js#L50-L59. I am not sure why this functionality isn't well documented on the read me page. I will close this issue.
It seems that mnemonicToSeed()
returns a Buffer that contains "too much" entropy? https://github.com/bitcoinjs/bip39/blob/v2.5.0/index.js#L99 will then throw an Exception when I try to feed that entropy seed back into entropyToMnemonic()
Below I share the code with which I tried to create a password derived mnemonic with a passphrase based on the optional BIP39 spec with the bip39.js library. I also add a code snippet of how to achieve the encryption using bitcore-mnemonic
// bip39.js
var mnemonic = bip39.generateMnemonic(256);
var seedFromFirstMnemonic = bip39.mnemonicToSeed(mnemonic, "password");
// next line throws
var encryptedSecondMnemonic = bip39.entropyToMnemonic(seedFromFirstMnemonic);
// bitcore-mnemonic
var mnemonic = new Mnemonic(256, Mnemonic.Words.ENGLISH);
var seed = mnemonic.toSeed("password");
var encryptedMnemonic = Mnemonic.fromSeed(seed, Mnemonic.Words.ENGLISH);
The Exception thrown is
lacksfish@computer:~/tmp/path$ node mnemonic-crypt.js
/tmp/path/bip39/index.js:99
if (entropy.length > 32) throw new TypeError(INVALID_ENTROPY)
^
TypeError: Invalid entropy
at Object.entropyToMnemonic (/tmp/path/bip39/index.js:99:34)
at Object.<anonymous> (/tmp/path/mnemonic-crypt.js:7:37)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
Most likely I'm doing something wrong. Although what is confusing is that bitcore-mnemonic
seems to be using the seed/entropy Buffer the way I'd have expected... ( see https://github.com/bitpay/bitcore-mnemonic/blob/master/lib/mnemonic.js#L71)
@lacksfish this is probably a new issue. What environment are you using?
Ok. Opened a new issue (please excuse the copypasta) and included my environment in #89
Added a README note in https://github.com/bitcoinjs/bip39/pull/90
I was wondering if this library supported passphrase protecting mnemonic phrases. It is described in the "From mnemonic to seed" section of the bip39 white paper. I am looking for the type of functionality found in Ian Coleman Web Wallet , BIP39 Passphrase (optional) section. Thank you for the help.