From 810c24f827ae4cbf2a975a8867467a3cc0eea48b Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Tue, 4 Mar 2025 19:33:05 +0100 Subject: [PATCH] fix(python): revive trezorctl --script [no changelog] --- python/src/trezorlib/cli/__init__.py | 6 ++++-- python/src/trezorlib/client.py | 1 - python/src/trezorlib/ui.py | 17 ++++------------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/python/src/trezorlib/cli/__init__.py b/python/src/trezorlib/cli/__init__.py index 92de8014a3..e9697d9259 100644 --- a/python/src/trezorlib/cli/__init__.py +++ b/python/src/trezorlib/cli/__init__.py @@ -27,7 +27,7 @@ from contextlib import contextmanager import click from .. import exceptions, transport, ui -from ..client import ProtocolVersion, TrezorClient +from ..client import PASSPHRASE_ON_DEVICE, ProtocolVersion, TrezorClient from ..messages import Capability from ..transport import Transport from ..transport.session import Session, SessionV1 @@ -72,7 +72,7 @@ def get_passphrase( available_on_device: bool, passphrase_on_host: bool ) -> t.Union[str, object]: if available_on_device and not passphrase_on_host: - return ui.PASSPHRASE_ON_DEVICE + return PASSPHRASE_ON_DEVICE env_passphrase = os.getenv("PASSPHRASE") if env_passphrase is not None: @@ -158,6 +158,8 @@ class TrezorConnection: if empty_passphrase: passphrase = "" + elif self.script: + passphrase = None else: available_on_device = Capability.PassphraseEntry in features.capabilities passphrase = get_passphrase(available_on_device, self.passphrase_on_host) diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index 0f735c24b4..130b0888ec 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -202,7 +202,6 @@ def get_default_client( If path is specified, does a prefix-search for the specified device. Otherwise, uses the value of TREZOR_PATH env variable, or finds first connected Trezor. - If no UI is supplied, instantiates the default CLI UI. """ if path is None: diff --git a/python/src/trezorlib/ui.py b/python/src/trezorlib/ui.py index 7fc481a2bb..58c55bfd84 100644 --- a/python/src/trezorlib/ui.py +++ b/python/src/trezorlib/ui.py @@ -17,11 +17,10 @@ from __future__ import annotations import sys -from typing import Any, Callable, Optional, Union +import typing as t import click from mnemonic import Mnemonic -from typing_extensions import Protocol from . import device, messages from .client import MAX_PIN_LENGTH, PASSPHRASE_ON_DEVICE @@ -63,19 +62,11 @@ WIPE_CODE_CONFIRM = PinMatrixRequestType.WipeCodeSecond CAN_HANDLE_HIDDEN_INPUT = sys.stdin and sys.stdin.isatty() -class TrezorClientUI(Protocol): - def button_request(self, br: messages.ButtonRequest) -> None: ... - - def get_pin(self, code: Optional[PinMatrixRequestType]) -> str: ... - - def get_passphrase(self, available_on_device: bool) -> Union[str, object]: ... - - -def echo(*args: Any, **kwargs: Any) -> None: +def echo(*args: t.Any, **kwargs: t.Any) -> None: return click.echo(*args, err=True, **kwargs) -def prompt(text: str, *, hide_input: bool = False, **kwargs: Any) -> Any: +def prompt(text: str, *, hide_input: bool = False, **kwargs: t.Any) -> t.Any: # Disallowing hidden input and warning user when it would cause issues if not CAN_HANDLE_HIDDEN_INPUT and hide_input: hide_input = False @@ -200,7 +191,7 @@ class ScriptUI: def mnemonic_words( expand: bool = False, language: str = "english" -) -> Callable[[WordRequestType], str]: +) -> t.Callable[[WordRequestType], str]: if expand: wordlist = Mnemonic(language).wordlist else: