From 84101518101f3411fe6d7a9add3d1310d13a5cc8 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 28 May 2018 15:47:57 +0200 Subject: [PATCH] remove remaining usages of expand_path --- tools/helloworld.py | 3 ++- tools/pwd_reader.py | 8 ++++---- tools/signtest.py | 7 +++++++ .../tests/device_tests/test_msg_nem_signtx_transfers.py | 6 +++--- .../tests/device_tests/test_msg_signtx_segwit_native.py | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/helloworld.py b/tools/helloworld.py index c91e5d392a..c851baca36 100755 --- a/tools/helloworld.py +++ b/tools/helloworld.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from trezorlib.client import TrezorClient from trezorlib.transport import get_transport +from trezorlib.tools import parse_path def main(): @@ -15,7 +16,7 @@ def main(): # Get the first address of first BIP44 account # (should be the same address as shown in wallet.trezor.io) - bip32_path = client.expand_path("44'/0'/0'/0/0") + bip32_path = parse_path("44'/0'/0'/0/0") address = client.get_address('Bitcoin', bip32_path) print('Bitcoin address:', address) diff --git a/tools/pwd_reader.py b/tools/pwd_reader.py index a979bd5279..58c9b5fe45 100755 --- a/tools/pwd_reader.py +++ b/tools/pwd_reader.py @@ -10,16 +10,16 @@ from urllib.parse import urlparse from trezorlib.client import TrezorClient from trezorlib.transport import get_transport +from trezorlib.tools import parse_path # Return path by BIP-32 -def getPath(client): - return client.expand_path("10016'/0") +BIP32_PATH = parse_path("10016h/0") # Deriving master key def getMasterKey(client): - bip32_path = getPath(client) + bip32_path = BIP32_PATH ENC_KEY = 'Activate TREZOR Password Manager?' ENC_VALUE = unhexlify('2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee') key = hexlify(client.encrypt_keyvalue( @@ -99,7 +99,7 @@ def getDecryptedNonce(client, entry): ENC_KEY = 'Unlock %s for user %s?' % (item, entry['username']) ENC_VALUE = entry['nonce'] decrypted_nonce = hexlify(client.decrypt_keyvalue( - getPath(client), + BIP32_PATH, ENC_KEY, unhexlify(ENC_VALUE), False, diff --git a/tools/signtest.py b/tools/signtest.py index 1fbdd6e2e3..90feb7a4aa 100755 --- a/tools/signtest.py +++ b/tools/signtest.py @@ -14,6 +14,13 @@ from trezorlib.tx_api import TxApiBitcoin from trezorlib.transport import get_transport +# This script has survived unmodified through several significant changes +# of the trezorlib library. While we want to have something like this, +# we're waiting on a couple more changes in order to implement this a little more cleanly. +# Wait for trezorlib v1.0. +raise Exception("This code is too old to run. Sorry.") + + def hash160(x): h = hashlib.new("ripemd160") h.update(hashlib.sha256(x).digest()) diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py index d1ac704b85..94ea1182d4 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py @@ -162,7 +162,7 @@ class TestMsgNEMSignTx(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() - tx = self.client.nem_sign_tx(self.client.expand_path("m/44'/1'/0'/0'/0'"), { + tx = self.client.nem_sign_tx(parse_path("m/44'/1'/0'/0'/0'"), { "timeStamp": 76809215, "amount": 3000000, "fee": 1000000, @@ -191,7 +191,7 @@ class TestMsgNEMSignTx(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() - tx = self.client.nem_sign_tx(self.client.expand_path("m/44'/1'/0'/0'/0'"), { + tx = self.client.nem_sign_tx(parse_path("m/44'/1'/0'/0'/0'"), { "timeStamp": 76809215, "amount": 2000000, "fee": 1000000, @@ -219,7 +219,7 @@ class TestMsgNEMSignTx(TrezorTest): def test_nem_signtx_multiple_mosaics(self): self.setup_mnemonic_nopin_nopassphrase() - tx = self.client.nem_sign_tx(self.client.expand_path("m/44'/1'/0'/0'/0'"), { + tx = self.client.nem_sign_tx(parse_path("m/44'/1'/0'/0'/0'"), { "timeStamp": 76809215, "amount": 2000000, "fee": 1000000, diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py index 304c7f0022..a5081c6b5d 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py @@ -207,7 +207,7 @@ class TestMsgSigntxSegwitNative(TrezorTest): script_type=proto.OutputScriptType.PAYTOADDRESS, ) out2 = proto.TxOutputType( - # address_n=self.client.expand_path("44'/1'/0'/0/0"), + # address_n=parse_path("44'/1'/0'/0/0"), # script_type=proto.OutputScriptType.PAYTOP2SHWITNESS, address='2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc', script_type=proto.OutputScriptType.PAYTOADDRESS,