dan-da / hd-wallet-derive

A command-line tool that derives bip32 addresses and private keys.
GNU General Public License v3.0
220 stars 77 forks source link

Electrum 2.0+ inconsistency between zpub derivation and mnemonic derivation. #52

Open FreePower opened 1 year ago

FreePower commented 1 year ago

Hello everybody.

Let me expose to you this topic ; this is probably not an issue, but a parameter missing.

Notice : the given example is a not funded wallet :)

Directly from Electrum, is can catch both zpub key and associated mnemonic from the creation :

zpub : zpub6myh1oJc7E2KJVAdMfSPcPYpp4ZMaCWczoY1JPbrQ5PvkN43kpYEyjhmzcGd3GAdyVYNLVWXwF8ft14mWb9f7VskRXYKHxcgqrVVRnMR7E4

mnemonic : achieve blanket access middle box lady gain era office depth joy rival

Using the key directly give good addresses derivation, compliant with Electrum :

./hd-wallet-derive.php -g --key=zpub6myh1oJc7E2KJVAdMfSPcPYpp4ZMaCWczoY1JPbrQ5PvkN43kpYEyjhmzcGd3GAdyVYNLVWXwF8ft14mWb9f7VskRXYKHxcgqrVVRnMR7E4 --numderive=3 --path="m/0" --cols=path,address --loglevel=debug 2023-09-13T05:52:33+00:00 [pid: 20549] [info] -- Deriving keys 2023-09-13T05:52:33+00:00 [lastlog: 0.040738 secs] [pid: 20549] [info] -- Derived 3 keys

+-------+--------------------------------------------+ | path | address | +-------+--------------------------------------------+ | m/0/0 | bc1qmmmal9gs3sy7k30deyrgqwjhv4pwvhqw44t6s0 | | m/0/1 | bc1qc7x9g660t4yg6t9c7eftdunpfxu53uw2rarvfv | | m/0/2 | bc1qw4u3svtu6ut44xus6gc4lu5glx8tluf3kc6qtp | +-------+--------------------------------------------+

However, using the mnemonic give NOT compliant results :

./hd-wallet-derive.php -g --mnemonic="achieve blanket access middle box lady gain era office depth joy rival" --numderive=3 --path="m/0" --cols=path,address --loglevel=debug 2023-09-13T05:55:00+00:00 [pid: 20555] [info] -- Deriving keys 2023-09-13T05:55:00+00:00 [lastlog: 0.053811 secs] [pid: 20555] [info] -- Derived 3 keys

+-------+------------------------------------+ | path | address | +-------+------------------------------------+ | m/0/0 | 169RK1Gjv93RGiucptUhF2xzMBv4SuMSfV | | m/0/1 | 1Dry68xmoLTZcXNLveA6EavLYEYutFZfZt | | m/0/2 | 1GznvpYFSMXpPnCVqcfKh4V9asptRmPada | +-------+------------------------------------+

I guess I have to add the --mnemonic-pw parameter ; I was doing dozen of tries and even look inside the electrum source software, it is unclear to me (sometimes it is related to hard coded 'Bitcoin seed', 'Electrum seed', a version number, a version tag...)

Someone have an idea ?

Thank you.

dan-da commented 1 month ago

Electrum mnemonic are not presently supported by hd-wallet-derive as electrum uses its own mechanism rather than bip39.

See: http://docs.electrum.org/en/latest/seedphrase.html

I will keep this open for now. Maybe we eventually add support for electrum mnemonics. And/or at least should document it in the readme.