trezor / python-trezor

:snake: Don't use this repo, use the new monorepo instead:
https://github.com/trezor/trezor-firmware
GNU Lesser General Public License v3.0
201 stars 194 forks source link

generate zpub for segwit address #291

Closed lsching17 closed 6 years ago

lsching17 commented 6 years ago

There is an example for generate segwit address

trezorctl get_address --coin Bitcoin --script-type segwit --address "m/84'/0'/0'/0/0"

There is another example to generate xpub

trezorctl get_public_node --coin Bitcoin --address "m/44'/0'/0'"

So, how to generate pub key for p2shsegwit and segwit (e.g. zpub)? if "m/84'/0'/0'/0/0" is passed, "zpub" is still returned.

prusnak commented 6 years ago

@matejcik Currently there is no way how to pass type of requested pubkey via GetPublicKey message. Wallet solves this for Segwit accounts (BIP-49) by deserializing xpub, changing it's version and serializing back to text.

Quick solution would to be to detect first two elements of the path and do the conversion from xpub prefix to another one (according to table here:) https://github.com/satoshilabs/slips/blob/master/slip-0132.md#registered-hd-version-bytes

matejcik commented 6 years ago

@prusnak that sounds about right. The key material is still the same, right? So basically it's only a matter of sticking the right word at start?

lsching17 commented 6 years ago

This is too difficult for bitcoin novice: how to convert xpub to zpub in bash or python?

prusnak commented 6 years ago

So basically it's only a matter of sticking the right word at start?

not sticking, deserializing, changing the version and serializing back

lsching17 commented 6 years ago

Can the library add support to generate xpub, ypub, zpub in the future?

prusnak commented 6 years ago

Yes, will update this in the future.

prusnak commented 6 years ago

Added script_type param to GetPublicKey in the following commit: https://github.com/trezor/trezor-common/commit/a01a9cef9e8690e998839be719880925c5991231

prusnak commented 6 years ago

Implemented in https://github.com/trezor/python-trezor/commit/555bb62e3f7f5a9fcaca301f10ab9f977c87a8dd

Next firmware release will contain this feature.

prusnak commented 6 years ago

T2 firmware implemented in https://github.com/trezor/trezor-core/commit/ebdd8c9b07537351c7dedec4db6e1fcbeb0426ef

prusnak commented 6 years ago

T1 firmware implemented in https://github.com/trezor/trezor-mcu/commit/efeedbe69b7fa9845462775c7a528c4f1838b7d8