From b68412e89b9f3bdbab9922445530c311026b9d3e Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 18 Oct 2023 16:15:59 +0200 Subject: [PATCH] style(python): use 'h' for hardening in descriptors too --- python/.changelog.d/3037.changed.1 | 1 + python/src/trezorlib/cli/btc.py | 6 +-- python/tests/test_tools.py | 61 ++++++++++++++++-------------- 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 python/.changelog.d/3037.changed.1 diff --git a/python/.changelog.d/3037.changed.1 b/python/.changelog.d/3037.changed.1 new file mode 100644 index 000000000..2ded4f6d0 --- /dev/null +++ b/python/.changelog.d/3037.changed.1 @@ -0,0 +1 @@ +trezorctl: Use 'h' character in generated descriptors. diff --git a/python/src/trezorlib/cli/btc.py b/python/src/trezorlib/cli/btc.py index ad02a1f1b..6776409b4 100644 --- a/python/src/trezorlib/cli/btc.py +++ b/python/src/trezorlib/cli/btc.py @@ -233,7 +233,7 @@ def get_address( @cli.command() @click.option("-c", "--coin", default=DEFAULT_COIN) -@click.option("-n", "--address", required=True, help="BIP-32 path, e.g. m/44'/0'/0'") +@click.option("-n", "--address", required=True, help="BIP-32 path, e.g. m/44h/0h/0h") @click.option("-e", "--curve") @click.option("-t", "--script-type", type=ChoiceType(INPUT_SCRIPTS)) @click.option("-d", "--show-display", is_flag=True) @@ -313,10 +313,10 @@ def _get_descriptor( else: raise ValueError("Unsupported coin") - path = f"m/{purpose}'/{coin_type}'/{account}'" + path = f"m/{purpose}h/{coin_type}h/{account}h" if purpose == PURPOSE_SLIP25: if script_type == messages.InputScriptType.SPENDTAPROOT: - path += "/1'" + path += "/1h" else: raise ValueError("Unsupported SLIP25 script type") diff --git a/python/tests/test_tools.py b/python/tests/test_tools.py index 4edb2b393..3a0325ea8 100644 --- a/python/tests/test_tools.py +++ b/python/tests/test_tools.py @@ -14,35 +14,38 @@ # You should have received a copy of the License along with this library. # If not, see . +import pytest + from trezorlib import tools +VECTORS = ( # descriptor, checksum + ( + "pkh([5c9e228d/44h/0h/0h]xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/0/*)", + "lnrxp640", + ), + ( + "pkh([5c9e228d/44h/0h/0h]xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/1/*)", + "w8x8u09h", + ), + ( + "sh(wpkh([5c9e228d/49h/0h/0h]xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/0/*))", + "kx6mu23v", + ), + ( + "sh(wpkh([5c9e228d/49h/0h/0h]xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/1/*))", + "r85dy4yn", + ), + ( + "wpkh([5c9e228d/84h/0h/0h]xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/0/*)", + "vyj8qz0q", + ), + ( + "wpkh([5c9e228d/84h/0h/0h]xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/1/*)", + "ashxahlc", + ), +) -def test_descriptor_checksum(): - VECTOR = [ - ( - "pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/0/*)", - "vzuemqzv", - ), - ( - "pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/1/*)", - "akecx4j5", - ), - ( - "sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/0/*))", - "jkfqtdfw", - ), - ( - "sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/1/*))", - "8h8knju3", - ), - ( - "wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/0/*)", - "l4dc6ccr", - ), - ( - "wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/1/*)", - "wpge8dgm", - ), - ] - for d, c in VECTOR: - assert tools.descriptor_checksum(d) == c + +@pytest.mark.parametrize("descriptor, checksum", VECTORS) +def test_descriptor_checksum(descriptor, checksum): + assert tools.descriptor_checksum(descriptor) == checksum