mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-29 13:39:05 +00:00
fix(python): revive trezorctl --script
[no changelog]
This commit is contained in:
parent
941a07ae72
commit
bc2a4ef3ef
@ -27,7 +27,7 @@ from contextlib import contextmanager
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from .. import exceptions, transport, ui
|
from .. import exceptions, transport, ui
|
||||||
from ..client import ProtocolVersion, TrezorClient
|
from ..client import PASSPHRASE_ON_DEVICE, ProtocolVersion, TrezorClient
|
||||||
from ..messages import Capability
|
from ..messages import Capability
|
||||||
from ..transport import Transport
|
from ..transport import Transport
|
||||||
from ..transport.session import Session, SessionV1
|
from ..transport.session import Session, SessionV1
|
||||||
@ -72,7 +72,7 @@ def get_passphrase(
|
|||||||
available_on_device: bool, passphrase_on_host: bool
|
available_on_device: bool, passphrase_on_host: bool
|
||||||
) -> t.Union[str, object]:
|
) -> t.Union[str, object]:
|
||||||
if available_on_device and not passphrase_on_host:
|
if available_on_device and not passphrase_on_host:
|
||||||
return ui.PASSPHRASE_ON_DEVICE
|
return PASSPHRASE_ON_DEVICE
|
||||||
|
|
||||||
env_passphrase = os.getenv("PASSPHRASE")
|
env_passphrase = os.getenv("PASSPHRASE")
|
||||||
if env_passphrase is not None:
|
if env_passphrase is not None:
|
||||||
@ -158,6 +158,8 @@ class TrezorConnection:
|
|||||||
|
|
||||||
if empty_passphrase:
|
if empty_passphrase:
|
||||||
passphrase = ""
|
passphrase = ""
|
||||||
|
elif self.script:
|
||||||
|
passphrase = None
|
||||||
else:
|
else:
|
||||||
available_on_device = Capability.PassphraseEntry in features.capabilities
|
available_on_device = Capability.PassphraseEntry in features.capabilities
|
||||||
passphrase = get_passphrase(available_on_device, self.passphrase_on_host)
|
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
|
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.
|
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:
|
if path is None:
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Callable, Optional, Union
|
import typing as t
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
from typing_extensions import Protocol
|
|
||||||
|
|
||||||
from . import device, messages
|
from . import device, messages
|
||||||
from .client import MAX_PIN_LENGTH, PASSPHRASE_ON_DEVICE
|
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()
|
CAN_HANDLE_HIDDEN_INPUT = sys.stdin and sys.stdin.isatty()
|
||||||
|
|
||||||
|
|
||||||
class TrezorClientUI(Protocol):
|
def echo(*args: t.Any, **kwargs: t.Any) -> None:
|
||||||
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:
|
|
||||||
return click.echo(*args, err=True, **kwargs)
|
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
|
# Disallowing hidden input and warning user when it would cause issues
|
||||||
if not CAN_HANDLE_HIDDEN_INPUT and hide_input:
|
if not CAN_HANDLE_HIDDEN_INPUT and hide_input:
|
||||||
hide_input = False
|
hide_input = False
|
||||||
@ -200,7 +191,7 @@ class ScriptUI:
|
|||||||
|
|
||||||
def mnemonic_words(
|
def mnemonic_words(
|
||||||
expand: bool = False, language: str = "english"
|
expand: bool = False, language: str = "english"
|
||||||
) -> Callable[[WordRequestType], str]:
|
) -> t.Callable[[WordRequestType], str]:
|
||||||
if expand:
|
if expand:
|
||||||
wordlist = Mnemonic(language).wordlist
|
wordlist = Mnemonic(language).wordlist
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user