From 18b7337aeaa96af20b4440eb1d203dae4c0124f7 Mon Sep 17 00:00:00 2001 From: slush0 Date: Fri, 6 May 2016 05:44:23 +0200 Subject: [PATCH] Use Bridge transport if available; implementing #1139 Bumping required TREZOR firmware to 1.3.3 (includes important fixes) --- plugins/trezor/plugin.py | 23 +++++++++++++++++++---- plugins/trezor/trezor.py | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index f2a9b4d5f..27fc65688 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -2,7 +2,7 @@ import base64 import re import threading -from binascii import unhexlify +from binascii import hexlify, unhexlify from functools import partial from electrum.account import BIP32_Account @@ -98,18 +98,33 @@ class TrezorCompatiblePlugin(HW_PluginBase): if self.libraries_available: self.device_manager().register_devices(self.DEVICE_IDS) - def create_client(self, device, handler): + def _try_hid(self, device): + self.print_error("Trying to connect over USB...") if device.interface_number == 1: pair = [None, device.path] else: pair = [device.path, None] try: - transport = self.HidTransport(pair) + return self.HidTransport(pair) except BaseException as e: - # We were probably just disconnected; never mind self.print_error("cannot connect at", device.path, str(e)) return None + + def _try_bridge(self, device): + self.print_error("Trying to connect over Trezor Bridge...") + try: + return self.BridgeTransport({'path': hexlify(device.path)}) + except BaseException as e: + self.print_error("cannot connect to bridge", str(e)) + return None + + def create_client(self, device, handler): + transport = self._try_bridge(device) or self._try_hid(device) + if not transport: + self.print_error("cannot connect to device") + return + self.print_error("connected to device at", device.path) client = self.client_class(transport, handler, self) diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py index 15b869f1d..d1bb19d39 100644 --- a/plugins/trezor/trezor.py +++ b/plugins/trezor/trezor.py @@ -9,13 +9,14 @@ class TrezorWallet(TrezorCompatibleWallet): class TrezorPlugin(TrezorCompatiblePlugin): firmware_URL = 'https://www.mytrezor.com' libraries_URL = 'https://github.com/trezor/python-trezor' - minimum_firmware = (1, 2, 1) + minimum_firmware = (1, 3, 3) wallet_class = TrezorWallet try: from .client import TrezorClient as client_class import trezorlib.ckd_public as ckd_public from trezorlib.client import types from trezorlib.transport_hid import HidTransport, DEVICE_IDS + from trezorlib.transport_bridge import BridgeTransport libraries_available = True except ImportError: libraries_available = False