diff --git a/libagent/device/interface.py b/libagent/device/interface.py index 3a72ac7..8d83d3b 100644 --- a/libagent/device/interface.py +++ b/libagent/device/interface.py @@ -114,6 +114,11 @@ class Device: raise NotImplementedError() def close(self): + """Close connection to device. + + By default, close the underlying connection. Overriding classes + can perform their own cleanup. + """ self.conn.close() def __enter__(self): diff --git a/libagent/device/trezor_defs.py b/libagent/device/trezor_defs.py index b295637..e3d337a 100644 --- a/libagent/device/trezor_defs.py +++ b/libagent/device/trezor_defs.py @@ -1,6 +1,6 @@ """TREZOR-related definitions.""" -# pylint: disable=unused-import,import-error +# pylint: disable=unused-import,import-error,no-name-in-module,no-member import os import logging @@ -21,8 +21,8 @@ if semver.match(trezorlib.__version__, ">=0.11.0"): from trezorlib.misc import sign_identity, get_ecdh_session_key else: - from trezorlib.client import (TrezorClient, CallException as TrezorFailure, - PinException) + from trezorlib.client import (TrezorClient, PinException, + CallException as TrezorFailure) from trezorlib.messages import IdentityType from trezorlib import messages from trezorlib.transport import get_transport @@ -32,11 +32,19 @@ else: get_ecdh_session_key = TrezorClient.get_ecdh_session_key class Client(TrezorClient): + """Compatibility wrapper for older TrezorClient type. + + This class redirects callback_* style methods to the UI implementation, + and stores state so that we can reuse it. + """ + def __init__(self, transport, ui, state=None): + """C-tor.""" super().__init__(transport, state=state) self.ui = ui def callback_PinMatrixRequest(self, msg): + """Redirect PinMatrixRequest to UI.""" try: pin = self.ui.get_pin(msg.type) if not pin.isdigit(): @@ -48,6 +56,7 @@ else: raise def callback_PassphraseRequest(self, msg): + """Redirect PassphraseRequest to UI.""" try: if msg.on_device is True: return messages.PassphraseAck() @@ -66,7 +75,8 @@ else: raise def callback_PassphraseStateRequest(self, msg): - self.state = msg.state + """Store state provided by device so that we can reuse it later.""" + self.state = msg.state # pylint: disable=attribute-defined-outside-init return messages.PassphraseStateAck() diff --git a/libagent/device/ui.py b/libagent/device/ui.py index 61a4f6b..525c4e8 100644 --- a/libagent/device/ui.py +++ b/libagent/device/ui.py @@ -49,8 +49,8 @@ class UI: options=self.options_getter()) def button_request(self, _code=None): + """Called by TrezorClient when device interaction is required.""" # XXX: show notification to the user? - pass def create_default_options_getter():