Browse Source

Merge pull request #5460 from SomberNight/keepkey_enum_20190626

keepkey: use libusb to enumerate devices instead of hid
hard-fail-on-bad-server-string
ghost43 5 years ago
committed by GitHub
parent
commit
3716594331
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      contrib/deterministic-build/requirements-hw.txt
  2. 2
      contrib/requirements/requirements-hw.txt
  3. 32
      electrum/plugins/keepkey/keepkey.py

8
contrib/deterministic-build/requirements-hw.txt

@ -32,10 +32,10 @@ hidapi==0.7.99.post21 \
idna==2.8 \
--hash=sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407 \
--hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c
keepkey==6.1.0 \
--hash=sha256:058548e733e1df8d1879ea747eef167c84cb04cdd685240e50d599f48d08e5c6 \
--hash=sha256:2e1623409307c86f709054ad191bc7707c4feeacae2e497bd933f2f0054c6eb0 \
--hash=sha256:54ef1b134657d3d14ef24c0c98e29d0276ad8f0e053d5e50d836ba8a520230e7
keepkey==6.3.0 \
--hash=sha256:69ce42ef55aaf0428a5cbc35ce5eaccf0eb96d14445e692f3583eaab5408a4af \
--hash=sha256:738ca3a5ec3a5b5b91da314d426ddd4648bba9cffc20e3e754582816415df51c \
--hash=sha256:e1b2f5a7612fcbbf7f6673339dfade1f8ff4a82873279de73496e2ed53c5cd2f
libusb1==1.7.1 \
--hash=sha256:adf64a4f3f5c94643a1286f8153bcf4bc787c348b38934aacd7fe17fbeebc571
mnemonic==0.19 \

2
contrib/requirements/requirements-hw.txt

@ -1,6 +1,6 @@
trezor[hidapi]>=0.11.5
safet[hidapi]>=0.1.0
keepkey>=6.0.3
keepkey>=6.3.0
btchip-python>=0.1.26
ckcc-protocol>=0.7.7
hidapi

32
electrum/plugins/keepkey/keepkey.py

@ -9,6 +9,7 @@ from electrum import constants
from electrum.i18n import _
from electrum.transaction import Transaction, PartialTransaction, PartialTxInput, PartialTxOutput
from electrum.keystore import Hardware_KeyStore
from electrum.plugin import Device
from electrum.base_wizard import ScriptTypeNotSupported
from ..hw_wallet import HW_PluginBase
@ -16,8 +17,10 @@ from ..hw_wallet.plugin import (is_any_tx_output_on_change_branch, trezor_valida
get_xpubs_and_der_suffixes_from_txinout)
if TYPE_CHECKING:
import usb1
from .client import KeepKeyClient
# TREZOR initialization methods
TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4)
@ -84,21 +87,40 @@ class KeepKeyPlugin(HW_PluginBase):
self.types = keepkeylib.client.types
self.DEVICE_IDS = (keepkeylib.transport_hid.DEVICE_IDS +
keepkeylib.transport_webusb.DEVICE_IDS)
self.device_manager().register_devices(self.DEVICE_IDS)
# only "register" hid device id:
self.device_manager().register_devices(keepkeylib.transport_hid.DEVICE_IDS)
# for webusb transport, use custom enumerate function:
self.device_manager().register_enumerate_func(self.enumerate)
self.libraries_available = True
except ImportError:
self.libraries_available = False
def enumerate(self):
from keepkeylib.transport_webusb import WebUsbTransport
results = []
for dev in WebUsbTransport.enumerate():
path = self._dev_to_str(dev)
results.append(Device(path=path,
interface_number=-1,
id_=path,
product_key=(dev.getVendorID(), dev.getProductID()),
usage_page=0,
transport_ui_string=f"webusb:{path}"))
return results
@staticmethod
def _dev_to_str(dev: "usb1.USBDevice") -> str:
return ":".join(str(x) for x in ["%03i" % (dev.getBusNumber(),)] + dev.getPortNumberList())
def hid_transport(self, pair):
from keepkeylib.transport_hid import HidTransport
return HidTransport(pair)
def webusb_transport(self, device):
from keepkeylib.transport_webusb import WebUsbTransport
for d in WebUsbTransport.enumerate():
if device.id_.startswith(d.getSerialNumber()):
return WebUsbTransport(d)
return WebUsbTransport(device)
for dev in WebUsbTransport.enumerate():
if device.path == self._dev_to_str(dev):
return WebUsbTransport(dev)
def _try_hid(self, device):
self.logger.info("Trying to connect over USB...")

Loading…
Cancel
Save