mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-24 02:59:03 +00:00
fix(python): revive trezorctl --script
[no changelog]
This commit is contained in:
parent
cba7fc5c63
commit
d8a6b68111
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user