Do not use side-effects of import to initialize hardware plugins
Call HidTransport in the context of a function
This commit is contained in:
@@ -11,11 +11,25 @@ class KeepKeyPlugin(TrezorCompatiblePlugin):
|
|||||||
libraries_URL = 'https://github.com/keepkey/python-keepkey'
|
libraries_URL = 'https://github.com/keepkey/python-keepkey'
|
||||||
minimum_firmware = (1, 0, 0)
|
minimum_firmware = (1, 0, 0)
|
||||||
keystore_class = KeepKey_KeyStore
|
keystore_class = KeepKey_KeyStore
|
||||||
try:
|
|
||||||
from .client import KeepKeyClient as client_class
|
def __init__(self, *args):
|
||||||
import keepkeylib.ckd_public as ckd_public
|
try:
|
||||||
from keepkeylib.client import types
|
import client
|
||||||
from keepkeylib.transport_hid import HidTransport, DEVICE_IDS
|
import keepkeylib
|
||||||
libraries_available = True
|
import keepkeylib.ckd_public
|
||||||
except ImportError:
|
import keepkeylib.transport_hid
|
||||||
libraries_available = False
|
self.client_class = client.KeepKeyClient
|
||||||
|
self.ckd_public = keepkeylib.ckd_public
|
||||||
|
self.types = keepkeylib.client.types
|
||||||
|
self.DEVICE_IDS = keepkeylib.transport_hid.DEVICE_IDS
|
||||||
|
self.libraries_available = True
|
||||||
|
except ImportError:
|
||||||
|
self.libraries_available = False
|
||||||
|
TrezorCompatiblePlugin.__init__(self, *args)
|
||||||
|
|
||||||
|
def hid_transport(self, pair):
|
||||||
|
from keepkeylib.transport_hid import HidTransport
|
||||||
|
return HidTransport(pair)
|
||||||
|
|
||||||
|
def bridge_transport(self, d):
|
||||||
|
raise NotImplementedError('')
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
pair = [device.path, None]
|
pair = [device.path, None]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.HidTransport(pair)
|
return self.hid_transport(pair)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
raise
|
raise
|
||||||
self.print_error("cannot connect at", device.path, str(e))
|
self.print_error("cannot connect at", device.path, str(e))
|
||||||
@@ -109,7 +109,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
self.print_error("Trying to connect over Trezor Bridge...")
|
self.print_error("Trying to connect over Trezor Bridge...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.BridgeTransport({'path': hexlify(device.path)})
|
return self.bridge_transport({'path': hexlify(device.path)})
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.print_error("cannot connect to bridge", str(e))
|
self.print_error("cannot connect to bridge", str(e))
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -10,12 +10,26 @@ class TrezorPlugin(TrezorCompatiblePlugin):
|
|||||||
libraries_URL = 'https://github.com/trezor/python-trezor'
|
libraries_URL = 'https://github.com/trezor/python-trezor'
|
||||||
minimum_firmware = (1, 3, 3)
|
minimum_firmware = (1, 3, 3)
|
||||||
keystore_class = TrezorKeyStore
|
keystore_class = TrezorKeyStore
|
||||||
try:
|
|
||||||
from .client import TrezorClient as client_class
|
def __init__(self, *args):
|
||||||
import trezorlib.ckd_public as ckd_public
|
try:
|
||||||
from trezorlib.client import types
|
import client
|
||||||
from trezorlib.transport_hid import HidTransport, DEVICE_IDS
|
import trezorlib
|
||||||
|
import trezorlib.ckd_public
|
||||||
|
import trezorlib.transport_hid
|
||||||
|
self.client_class = client.TrezorClient
|
||||||
|
self.ckd_public = trezorlib.ckd_public
|
||||||
|
self.types = trezorlib.client.types
|
||||||
|
self.DEVICE_IDS = trezorlib.transport_hid.DEVICE_IDS
|
||||||
|
self.libraries_available = True
|
||||||
|
except ImportError:
|
||||||
|
self.libraries_available = False
|
||||||
|
TrezorCompatiblePlugin.__init__(self, *args)
|
||||||
|
|
||||||
|
def hid_transport(self, pair):
|
||||||
|
from trezorlib.transport_hid import HidTransport
|
||||||
|
return HidTransport(pair)
|
||||||
|
|
||||||
|
def bridge_transport(self, d):
|
||||||
from trezorlib.transport_bridge import BridgeTransport
|
from trezorlib.transport_bridge import BridgeTransport
|
||||||
libraries_available = True
|
return BridgeTransport(d)
|
||||||
except ImportError:
|
|
||||||
libraries_available = False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user