diff --git a/tools/encfs_aes_getpass.py b/tools/encfs_aes_getpass.py index ef67b55..64ba603 100755 --- a/tools/encfs_aes_getpass.py +++ b/tools/encfs_aes_getpass.py @@ -16,21 +16,15 @@ import hashlib import binascii from trezorlib.client import TrezorClient -from trezorlib.device import TrezorDevice - -# Python2 vs Python3 -try: - input = raw_input -except NameError: - pass +from trezorlib.transport import enumerate_devices def wait_for_devices(): - devices = TrezorDevice.enumerate() + devices = enumerate_devices() while not len(devices): sys.stderr.write("Please connect TREZOR to computer and press Enter...") input() - devices = TrezorDevice.enumerate() + devices = enumerate_devices() return devices diff --git a/tools/helloworld.py b/tools/helloworld.py index 9712a2b..c91e5d3 100755 --- a/tools/helloworld.py +++ b/tools/helloworld.py @@ -1,21 +1,11 @@ #!/usr/bin/env python3 -from __future__ import print_function - from trezorlib.client import TrezorClient -from trezorlib.device import TrezorDevice +from trezorlib.transport import get_transport def main(): - # List all connected TREZORs on USB/UDP - devices = TrezorDevice.enumerate() - - # Check whether we found any - if len(devices) == 0: - print('No TREZOR found') - return - # Use first connected device - transport = devices[0] + transport = get_transport() # Creates object for manipulating TREZOR client = TrezorClient(transport) diff --git a/tools/mem_flashblock.py b/tools/mem_flashblock.py index af8b15c..6de4f7a 100755 --- a/tools/mem_flashblock.py +++ b/tools/mem_flashblock.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 -from __future__ import print_function - from trezorlib.debuglink import DebugLink from trezorlib.client import TrezorClient -from trezorlib.transport_hid import HidTransport +from trezorlib.transport import enumerate_devices import binascii import sys @@ -16,8 +14,8 @@ sectorlens = [0x4000, 0x4000, 0x4000, 0x4000, def main(): - # List all connected TREZORs on USB - devices = HidTransport.enumerate() + # List all debuggable TREZORs + devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] # Check whether we found any if len(devices) == 0: diff --git a/tools/mem_read.py b/tools/mem_read.py index eafa205..c6a4a3a 100755 --- a/tools/mem_read.py +++ b/tools/mem_read.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 -from __future__ import print_function - from trezorlib.debuglink import DebugLink from trezorlib.client import TrezorClient -from trezorlib.transport_hid import HidTransport +from trezorlib.transport import enumerate_devices import sys # usage examples @@ -16,8 +14,8 @@ import sys def main(): - # List all connected TREZORs on USB - devices = HidTransport.enumerate() + # List all debuggable TREZORs + devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] # Check whether we found any if len(devices) == 0: diff --git a/tools/mem_write.py b/tools/mem_write.py index ae94a8b..f3f11ce 100755 --- a/tools/mem_write.py +++ b/tools/mem_write.py @@ -1,16 +1,14 @@ #!/usr/bin/env python3 -from __future__ import print_function - from trezorlib.debuglink import DebugLink from trezorlib.client import TrezorClient -from trezorlib.transport_hid import HidTransport +from trezorlib.transport import enumerate_devices import binascii import sys def main(): - # List all connected TREZORs on USB - devices = HidTransport.enumerate() + # List all debuggable TREZORs + devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] # Check whether we found any if len(devices) == 0: diff --git a/tools/mnemonic_check.py b/tools/mnemonic_check.py index 6c5c1fc..1dce3fe 100755 --- a/tools/mnemonic_check.py +++ b/tools/mnemonic_check.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -from __future__ import print_function import binascii import hashlib import mnemonic @@ -16,12 +15,6 @@ __doc__ = ''' without an internet connection). ''' -# Python2 vs Python3 -try: - input = raw_input -except NameError: - pass - def generate_entropy(strength, internal_entropy, external_entropy): ''' diff --git a/tools/pwd_reader.py b/tools/pwd_reader.py index 2c6c4bd..0aeb8e3 100755 --- a/tools/pwd_reader.py +++ b/tools/pwd_reader.py @@ -1,7 +1,4 @@ #!/usr/bin/env python3 - -from __future__ import print_function - from binascii import hexlify, unhexlify from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend @@ -9,14 +6,10 @@ import hmac import hashlib import json import os -try: - from urllib.parse import urlparse -except: - from urlparse import urlparse - input = raw_input +from urllib.parse import urlparse from trezorlib.client import TrezorClient -from trezorlib.transport_hid import HidTransport +from trezorlib.transport import get_transport # Return path by BIP-32 def getPath(client): @@ -124,12 +117,13 @@ def printEntries(entries): def main(): - devices = HidTransport.enumerate() - if not devices: - print('TREZOR is not plugged in. Please, connect TREZOR and retry.') + try: + transport = get_transport() + except Exception as e: + print(e) return - client = TrezorClient(devices[0]) + client = TrezorClient(transport) print() print('Confirm operation on TREZOR') diff --git a/tools/rng_entropy_collector.py b/tools/rng_entropy_collector.py index 2ae738a..1f4dcbc 100755 --- a/tools/rng_entropy_collector.py +++ b/tools/rng_entropy_collector.py @@ -8,21 +8,14 @@ from __future__ import print_function import io import sys from trezorlib.client import TrezorClient -from trezorlib.device import TrezorDevice - - -def get_client(): - devices = TrezorDevice.enumerate() # list all connected TREZORs on USB - if len(devices) == 0: # check whether we found any - return None - transport = devices[0] # use first connected device - return TrezorClient(transport) # creates object for communicating with TREZOR +from trezorlib.transport import get_transport def main(): - client = get_client() - if not client: - print('No TREZOR connected') + try: + client = TrezorClient(get_transport()) + except Exception as e: + print(e) return arg1 = sys.argv[1] # output file diff --git a/tools/signtest.py b/tools/signtest.py index 4cc6bde..7ec2f4f 100755 --- a/tools/signtest.py +++ b/tools/signtest.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function import binascii import os import random @@ -12,8 +11,7 @@ import hashlib from trezorlib.client import TrezorClient from trezorlib.tx_api import TxApiTestnet from trezorlib.tx_api import TxApiBitcoin -from trezorlib.transport_hid import HidTransport -from trezorlib.transport_bridge import BridgeTransport +from trezorlib.transport import get_transport def hash160(x): @@ -152,16 +150,13 @@ def main(): numinputs = 100 sizeinputtx = 10 - # List all connected TREZORs on USB - devices = HidTransport.enumerate() - - # Check whether we found any - if len(devices) == 0: - print('No TREZOR found') + # Use first connected device + try: + transport = get_transport() + except Exception as e: + print(e) return - # Use first connected device - transport = devices[0] print(transport) txstore = MyTxApiBitcoin()