Skip to content
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

Invalid Entropy with 24 words - BIP39 #5

Closed
tloriato opened this issue Oct 5, 2017 · 11 comments
Closed

Invalid Entropy with 24 words - BIP39 #5

tloriato opened this issue Oct 5, 2017 · 11 comments

Comments

@tloriato
Copy link

tloriato commented Oct 5, 2017

I've found out that bip39 new version 2.4.0 breaks this module when working with 24 words.

You can change your package.json to download the 2.3.0 version and it should work fine.

[Related #3 ]

@oed
Copy link
Owner

oed commented Oct 6, 2017

Thanks for pointing this out. Do you know why there is a breaking change in bip39?

@coop555
Copy link

coop555 commented Mar 8, 2018

I can confirm the same error with clean install latest MacOS + Homebrew even though I changed package.json to require v2.3.0 bip39 but does not help.

readline.js:1029
throw err;
^

TypeError: Invalid entropy

Note: All 4 tests pass when running 'npm test'

I can test more if someone wants me to try something, otherwise i am at a loss.

EDIT:
I also just installed it on a clean Ubuntu 17.10. Same error there. 15 words work. But 24 words still fail with the Entropy error.

In Ubuntu, can't get it to pass the 4 npm tests. On MacOS, I was able to resolve the errors, but in Ubuntu, I can't. Not sure what logs might be helpful.

@oed
Copy link
Owner

oed commented Mar 9, 2018

@coop555 I suppose you get the same error when just using bip39 by itself?

@coop555
Copy link

coop555 commented Mar 10, 2018

Hi. Thanks for getting back. I need help running BIP39 as a standalone node app. Not sure how to do it. I made some half hearted attempts at it today but failed.

I assume you want me to directly run
bip39.mnemonicToEntropy("24 word seed")
or
bip39.mnemonicToSeedHex('24 word seed')

and see if it also fails, right?

@oed
Copy link
Owner

oed commented Mar 10, 2018

@coop555 yepp, that's right. In the seedsplit directory (if you cloned the git repo) just run this in your terminal:

$ node
> let bip39 = require('bip39')
> bip39.mnemonicToEntropy("20 word seed")

@coop555
Copy link

coop555 commented Mar 10, 2018

OK thanks. It works.

Both the 21 word seed and longer 24 word seed returned appropriate entropy hex strings.

Then I used both resultant entropy strings in the reverse bip39.entropyToMnemonic function, and they each returned the appropriate seed. The 24 word seed worked.

Then I reran seedsplit -t 2 -s 3 with the same 24 word seed to confirm I got the same error:

Enter seed mnemonic:
readline.js:1029
throw err;
^

TypeError: Invalid entropy
at Object.entropyToMnemonic (/usr/local/lib/node_modules/seedsplit/node_modules/bip39/index.js:99:34)
at shards.map.shard (/usr/local/lib/node_modules/seedsplit/lib/seedsplit.js:16:18)
at Array.map ()
at Object.split (/usr/local/lib/node_modules/seedsplit/lib/seedsplit.js:14:31)
at result (/usr/local/lib/node_modules/seedsplit/bin/cli.js:29:36)
at prompt.get (/usr/local/lib/node_modules/seedsplit/bin/cli.js:60:7)
at /usr/local/lib/node_modules/seedsplit/node_modules/prompt/lib/prompt.js:336:32
at /usr/local/lib/node_modules/seedsplit/node_modules/async/lib/async.js:154:25
at assembler (/usr/local/lib/node_modules/seedsplit/node_modules/prompt/lib/prompt.js:333:9)
at /usr/local/lib/node_modules/seedsplit/node_modules/prompt/lib/prompt.js:342:32

Anything you'd like me to try?

@oed
Copy link
Owner

oed commented Mar 12, 2018

Oh, I see where the issue is. I'm padding the resulting split entopy with zeros to get the right length to do entropyToMnemonic. The resulting string might get the wrong length for some reason. I'd have to look more closely at this next week when I'm less busy :)

@coop555
Copy link

coop555 commented Mar 13, 2018

Awesome. I am glad you figured it. Let me know if there's anything else I can do to help.

@mifunetoshiro
Copy link

mifunetoshiro commented Apr 7, 2018

It's not because of padding with zeroes, this is because secrets.js (unmaintained and has bugs anyway) returns shards with Buffer.from(shard, 'hex').length 34, and bip39 returns an "Invalid entropy" for length > 32: https://github.com/bitcoinjs/bip39/blob/master/index.js#L99

If you change line 99 and 83 of bip39 to > 36 it works, but this is just a dirty workaround, because according to BIP-39 the entropy should be between 128-256 bits (16-32 bytes). And this also raises this issue then: #6.

All in all, this is not an issue with seedsplit, but in the way secrets.js creates shares not compatible with bip39, and therefore making seedsplit not compatible with 24 seed words. Should change the readme to say it doesn't work with 24 word seeds.

@oed
Copy link
Owner

oed commented Apr 9, 2018

@mifunetoshiro thanks! I think it worked in an older version though :/

@mifunetoshiro
Copy link

Yes, until bitcoinjs enforced the entropy to 128-256 bits in bip39, 2.4.0 it seems.

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

No branches or pull requests

4 participants