bitaps-com / pybtc

Python bitcoin library
GNU General Public License v3.0
86 stars 37 forks source link

Mnemonic split - pybtc vs. jsbtc #18

Closed avsync closed 3 years ago

avsync commented 4 years ago

I've been trying to get the combine/split mnemonic in pybtc to play nicely and match https://bitaps.com/mnemonic but the implementation must be different. I've tried to understand how the pybtc mnemonic combine/split differs from jsbtc but my understanding of js is pretty much non existent. Any pointers would be appreciated.

avsync commented 4 years ago

I managed to figure out some basic javascript, just enough to get a test vectors from jsbtc and now I've found that I can get the output from pybtc to match jsbtc. Neither of them produce a split mnemonic that is recoverable on https://bitaps.com/mnemonic though. What's up with that, what I am doing wrong?

let m = 'monkey weird office glove olympic tank vote raven never punch diesel hobby';
console.log("Mnemonic:", m);
let s = btc.splitMnemonic(2, 2, m);
console.log("Split Mnemonic 2/2", s);
console.log("Recovered Mnemonic:", btc.combineMnemonic(s));

_Mnemonic: monkey weird office glove olympic tank vote raven never punch diesel hobby

Split Mnemonic 2/2 {"181":"humble owner damage purse verb under sail deputy skin clap exotic problem","254":"room elegant vintage quick culture brown type shallow ignore culture whip spell"}

Recovered Mnemonic: monkey weird office glove olympic tank vote raven never punch diesel hobby_

restorefs

avsync commented 4 years ago

And the same thing in pybtc. I must be missing something...

mnemonic = "monkey weird office glove olympic tank vote raven never punch diesel hobby"
print("Mnemonic: ", mnemonic)
split = split_mnemonic(mnemonic, 2, 2)
print("Split Mnemonic: ", split)
combine = combine_mnemonic(split)
print("Recovered Mnemonic: ", combine)

Mnemonic: monkey weird office glove olympic tank vote raven never punch diesel hobby Split Mnemonic: {1: 'curve size try mesh lock pair detail ordinary display flower candy degree', 2: 'tragic obvious divide lyrics rifle fetch grit until surface night series session'} Recovered Mnemonic: monkey weird office glove olympic tank vote raven never punch diesel hobby

restorefsp

4tochka commented 4 years ago

Please try this branch. https://github.com/bitaps-com/pybtc/tree/new_block_tx

I not yet finished test coverage and no merge in master

Implementation reference https://github.com/bitaps-com/mnemonic-offline-tool/blob/master/BIP/mnemonic-improvement.md

4tochka commented 4 years ago
Снимок экрана 2020-09-02 в 22 26 56

this. branch https://github.com/bitaps-com/pybtc/tree/new_block_tx implemented according BIP

4tochka commented 4 years ago

tests https://github.com/bitaps-com/pybtc/blob/new_block_tx/tests/test_bip39_mnemonic_functions.py#L111

avsync commented 4 years ago

Thank you for looking into this, much appreciated! I can confirm combine is working as expected in this branch.

4tochka commented 4 years ago

Hope to finish work on latest version of pybtc soon!

4tochka commented 3 years ago

merged to master