bitcoin-core / HWI

Bitcoin Hardware Wallet Interface
MIT License
487 stars 193 forks source link

getmasterxpub bad result for --testnet ? #309

Closed tka85 closed 3 years ago

tka85 commented 4 years ago

On Trezor 1, with one legacy account (BIP44) and one wrapped segwit account (BIP49).

./hwi.py  --testnet --debug --device-type trezor --device-path webusb:003:1:3:4  getmasterxpub

returns same results as:

./hwi.py  --testnet --device-type trezor --device-path webusb:003:1:3:4  getxpub m/44h/0h/0h

I was under the impression that given the --testnet param, it should actually return as per BIP44 the node at m/44h/1h/0h and not m/44h/0h/0h.

I used the wallet's mnemonic to get the seed and from there I re-evaluated the xpub using bitcoinjs-lib and the correct one is indeed at node m/44h/1h/0h and not m/44h/0h/0h. By correct I mean it coincides with what Trezor displays on page in the browser under Account public keys.

Also master to my understanding refers to the node of the seed i.e. depth == 0. Anything else is not a master xpub. I find the name getmasterxpub a bit confusing given it actually returns a node at depth 3.

achow101 commented 4 years ago

The naming of master was that it originally was going to be the actual master xpub, but not all devices support exporting that. So instead it returns an xpub that some other wallets refer to as master (I remember seeing m/44'/0'/0' referred to as master because that's what would be exported for a watch only wallet).

But yes, we should have it respect the --testnet switch and also add --sh_wpkh and --wpkh options too to get the "master" xpubs for BIPs 49/84.