-
-
Notifications
You must be signed in to change notification settings - Fork 773
Expand file tree
/
Copy pathrecovery_helpers.py
More file actions
29 lines (21 loc) · 889 Bytes
/
recovery_helpers.py
File metadata and controls
29 lines (21 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from trezorlib.debuglink import DebugLink, LayoutContent
KEYBOARD_COMPONENTS = ("MnemonicKeyboard", "Slip39Keyboard")
MAX_ATTEMPTS = 10
def layout_has_keyboard(layout: "LayoutContent") -> bool:
components = layout.all_components()
if any(name in components for name in KEYBOARD_COMPONENTS):
return True
return any(name in layout.json_str for name in KEYBOARD_COMPONENTS)
def navigate_to_keyboard(debug: "DebugLink") -> "LayoutContent":
layout = debug.read_layout()
for _ in range(MAX_ATTEMPTS):
if layout_has_keyboard(layout):
return layout
debug.click(debug.screen_buttons.ok())
layout = debug.read_layout()
raise RuntimeError(
f"Keyboard not found after {MAX_ATTEMPTS} attempts. "
f"Expected one of: {', '.join(KEYBOARD_COMPONENTS)}"
)