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

mnemonicToEntropy not returning correct entropy #70

Closed
cgcardona opened this issue Mar 16, 2018 · 4 comments
Closed

mnemonicToEntropy not returning correct entropy #70

cgcardona opened this issue Mar 16, 2018 · 4 comments

Comments

@cgcardona
Copy link

cgcardona commented Mar 16, 2018

I found a call to mnemonicToEntropy which isn't returning the correct entropy. To reproduce:

let entropy = "ea9d80e70b08bbfb6b7f2bca56c88ddb2c2d003e675a855779d81e11f3009346a";
let mnemonic = bip39.entropyToMnemonic(entropy);
// 'tunnel ugly degree bid merry world pupil tornado ski rent casino rent security length wet twice luxury rookie invite destroy busy leopard escape shoe'

let rand = bip39.mnemonicToEntropy(mnemonic);
// 'ea9d80e70b08bbfb6b7f2bca56c88ddb2c2d003e675a855779d81e11f3009346'

The returned entropy is missing an a at the end. This is the only case where I've found that mnemonicToEntropy doesn't return the correct entropy.

Thanks for a great library!

@dcousens
Copy link
Contributor

Interesting, but, this actually isn't our fault!

let buffer = Buffer.from('ea9d80e70b08bbfb6b7f2bca56c88ddb2c2d003e675a855779d81e11f3009346a', 'hex')
// <Buffer ea 9d 80 e7 0b 08 bb fb 6b 7f 2b ca 56 c8 8d db 2c 2d 00 3e 67 5a 85 57 79 d8 1e 11 f3 00 93 46>

You passed a 65-byte hex string, and a 32-byte Buffer is parsed.
Why does Node not throw? Ask them, but, alas.

@dcousens
Copy link
Contributor

dcousens commented Mar 16, 2018

Keeping open for now, as I'd like to hear your opinion, this is certainly a confusing (and unfortunate) result.

@cgcardona
Copy link
Author

Looking back through my console I see the issue. TLDR adding the a on the end was a typo in my test suite.

Both the 64 and 65 char entropy strings produce the same mnemonic

let a = bip39.entropyToMnemonic('ea9d80e70b08bbfb6b7f2bca56c88ddb2c2d003e675a855779d81e11f3009346')
// 'tunnel ugly degree bid merry world pupil tornado ski rent casino rent security length wet twice luxury rookie invite destroy busy leopard escape shoe'

let b = bip39.entropyToMnemonic('ea9d80e70b08bbfb6b7f2bca56c88ddb2c2d003e675a855779d81e11f3009346a')
// 'tunnel ugly degree bid merry world pupil tornado ski rent casino rent security length wet twice luxury rookie invite destroy busy leopard escape shoe'

Node's Crypto.randomBytes correctly returned a 64 character hex encoded string but when I manually copied the 64 char string to my fixtures JSON I added an a due to my vim workflow.

So my entropyToMnemonic tests passed but the mnemonicToEntropy tests failed because my assertion was for the 65 character string.

Apologies for the false flag. Again, thanks for a great lib. 🎩

@lp12ucw
Copy link

lp12ucw commented Mar 16, 2018 via email

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

No branches or pull requests

3 participants