From 3c0344304f5d472437af8e72d196c7027ed71824 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 19 Oct 2023 13:27:50 +0200 Subject: [PATCH] feat(python/trezorctl): notify user about PIN/passphrase entry in terminal (fixes #3203) --- python/.changelog.d/3203.changed | 1 + python/src/trezorlib/ui.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 python/.changelog.d/3203.changed diff --git a/python/.changelog.d/3203.changed b/python/.changelog.d/3203.changed new file mode 100644 index 0000000000..e7ca6b63e1 --- /dev/null +++ b/python/.changelog.d/3203.changed @@ -0,0 +1 @@ +ClickUI: notify user in terminal that they should enter PIN or passphrase on Trezor. diff --git a/python/src/trezorlib/ui.py b/python/src/trezorlib/ui.py index 9d955e6b85..457a0855c7 100644 --- a/python/src/trezorlib/ui.py +++ b/python/src/trezorlib/ui.py @@ -90,15 +90,24 @@ class ClickUI: self, always_prompt: bool = False, passphrase_on_host: bool = False ) -> None: self.pinmatrix_shown = False - self.prompt_shown = False + self.last_prompt_shown = "" self.always_prompt = always_prompt self.passphrase_on_host = passphrase_on_host - def button_request(self, _br: messages.ButtonRequest) -> None: - if not self.prompt_shown: - echo("Please confirm action on your Trezor device.") + def _prompt_for_button(self, br: messages.ButtonRequest) -> str: + if br.code == messages.ButtonRequestType.PassphraseEntry: + return "Please enter passphrase on your Trezor device." + if br.code == messages.ButtonRequestType.PinEntry: + return "Please enter PIN on your Trezor device." + + return "Please confirm action on your Trezor device." + + def button_request(self, br: messages.ButtonRequest) -> None: + prompt = self._prompt_for_button(br) + if prompt != self.last_prompt_shown: + echo(prompt) if not self.always_prompt: - self.prompt_shown = True + self.last_prompt_shown = prompt def get_pin(self, code: Optional[PinMatrixRequestType] = None) -> str: if code == PIN_CURRENT: