1
0

hw plugins: Allow custom enumerate functions

trezor: Adding support for all supported transports (HID, WebUSB, UDP, Bridge)
This commit is contained in:
slush
2018-02-06 19:11:14 +01:00
parent d56dba8039
commit 460e88ee53
3 changed files with 24 additions and 29 deletions

View File

@@ -84,38 +84,22 @@ class TrezorCompatiblePlugin(HW_PluginBase):
def __init__(self, parent, config, name):
HW_PluginBase.__init__(self, parent, config, name)
self.main_thread = threading.current_thread()
# FIXME: move to base class when Ledger is fixed
if self.libraries_available:
self.device_manager().register_devices(self.DEVICE_IDS)
self.device_manager().register_enumerate_func(self.enumerate)
def _try_hid(self, device):
self.print_error("Trying to connect over USB...")
def create_client(self, device, handler):
try:
return self.hid_transport(device)
self.print_error("Trying to connect to TREZOR...")
transport = self.transport(device)
except BaseException as e:
# see fdb810ba622dc7dbe1259cbafb5b28e19d2ab114
# raise
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.bridge_transport({'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):
# disable bridge because it seems to never returns if keepkey is plugged
#transport = self._try_bridge(device) or self._try_hid(device)
transport = self._try_hid(device)
if not transport:
self.print_error("cannot connect to device")
self.print_error("cannot connect at", device.path)
return
self.print_error("connected to device at", device.path)
client = self.client_class(transport, handler, self)
# Try a ping for device sanity

View File

@@ -16,21 +16,22 @@ class TrezorPlugin(TrezorCompatiblePlugin):
from . import client
import trezorlib
import trezorlib.ckd_public
import trezorlib.transport_hid
import trezorlib.messages
import trezorlib.device
self.client_class = client.TrezorClient
self.ckd_public = trezorlib.ckd_public
self.types = trezorlib.messages
self.DEVICE_IDS = (trezorlib.transport_hid.DEV_TREZOR1, trezorlib.transport_hid.DEV_TREZOR2)
self.DEVICE_IDS = ('TREZOR',)
self.libraries_available = True
except ImportError:
self.libraries_available = False
TrezorCompatiblePlugin.__init__(self, *args)
def hid_transport(self, device):
from trezorlib.transport_hid import HidTransport
return HidTransport.find_by_path(device.path)
def enumerate(self):
from trezorlib.device import TrezorDevice
from electrum.plugins import Device
return [Device(str(d), -1, str(d), 'TREZOR', 0) for d in TrezorDevice.enumerate()]
def bridge_transport(self, d):
from trezorlib.transport_bridge import BridgeTransport
return BridgeTransport(d)
def transport(self, device):
from trezorlib.device import TrezorDevice
return TrezorDevice.find_by_path(device.path)