2017-06-14 17:27:02 +00:00
|
|
|
from typing import *
|
2017-06-14 15:41:45 +00:00
|
|
|
|
2019-05-17 12:22:36 +00:00
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils-meminfo.h
|
2020-06-17 12:24:57 +00:00
|
|
|
def meminfo(filename: str) -> None:
|
|
|
|
"""Dumps map of micropython GC arena to a file.
|
|
|
|
The JSON file can be decoded by analyze.py
|
|
|
|
Only available in the emulator.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2018-01-26 13:28:49 +00:00
|
|
|
def consteq(sec: bytes, pub: bytes) -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2018-01-26 13:28:49 +00:00
|
|
|
Compares the private information in `sec` with public, user-provided
|
|
|
|
information in `pub`. Runs in constant time, corresponding to a length
|
|
|
|
of `pub`. Can access memory behind valid length of `sec`, caller is
|
|
|
|
expected to avoid any invalid memory access.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2019-05-17 12:22:36 +00:00
|
|
|
def memcpy(
|
2021-03-18 09:48:50 +00:00
|
|
|
dst: bytearray | memoryview,
|
2020-06-30 13:10:11 +00:00
|
|
|
dst_ofs: int,
|
|
|
|
src: bytes,
|
|
|
|
src_ofs: int,
|
2021-03-18 09:48:50 +00:00
|
|
|
n: int | None = None,
|
2019-05-17 12:22:36 +00:00
|
|
|
) -> int:
|
|
|
|
"""
|
2017-06-14 15:41:45 +00:00
|
|
|
Copies at most `n` bytes from `src` at offset `src_ofs` to
|
2020-06-26 10:30:12 +00:00
|
|
|
`dst` at offset `dst_ofs`. Returns the number of actually
|
|
|
|
copied bytes. If `n` is not specified, tries to copy
|
|
|
|
as much as possible.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2017-06-14 15:41:45 +00:00
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2021-03-18 09:48:50 +00:00
|
|
|
def halt(msg: str | None = None) -> None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2017-06-14 15:41:45 +00:00
|
|
|
Halts execution.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2022-04-22 22:18:13 +00:00
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2022-05-02 22:55:49 +00:00
|
|
|
def firmware_hash(
|
|
|
|
challenge: bytes | None = None,
|
|
|
|
callback: Callable[[int, int], None] | None = None,
|
|
|
|
) -> bytes:
|
2022-04-22 22:18:13 +00:00
|
|
|
"""
|
|
|
|
Computes the Blake2s hash of the firmware with an optional challenge as
|
|
|
|
the key.
|
|
|
|
"""
|
2022-05-02 22:16:38 +00:00
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2022-05-02 22:16:38 +00:00
|
|
|
def firmware_vendor() -> str:
|
|
|
|
"""
|
|
|
|
Returns the firmware vendor string from the vendor header.
|
|
|
|
"""
|
2022-05-03 09:34:34 +00:00
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-04-14 15:18:03 +00:00
|
|
|
def unit_color() -> int | None:
|
|
|
|
"""
|
|
|
|
Returns the color of the unit.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-04-14 15:18:03 +00:00
|
|
|
def unit_btconly() -> bool | None:
|
|
|
|
"""
|
|
|
|
Returns True if the unit is BTConly.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2024-04-11 14:35:50 +00:00
|
|
|
def unit_packaging() -> int | None:
|
|
|
|
"""
|
|
|
|
Returns the packaging version of the unit.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2024-01-12 14:42:01 +00:00
|
|
|
def sd_hotswap_enabled() -> bool:
|
|
|
|
"""
|
|
|
|
Returns True if SD card hot swapping is enabled
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-10-20 12:58:32 +00:00
|
|
|
def reboot_to_bootloader(
|
|
|
|
boot_command : int = 0,
|
|
|
|
boot_args : bytes | None = None,
|
|
|
|
) -> None:
|
2022-04-11 11:27:48 +00:00
|
|
|
"""
|
|
|
|
Reboots to bootloader.
|
|
|
|
"""
|
2023-08-11 15:57:32 +00:00
|
|
|
VersionTuple = Tuple[int, int, int, int]
|
2023-09-13 13:36:06 +00:00
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-08-11 15:57:32 +00:00
|
|
|
class FirmwareHeaderInfo(NamedTuple):
|
|
|
|
version: VersionTuple
|
|
|
|
vendor: str
|
|
|
|
fingerprint: bytes
|
|
|
|
hash: bytes
|
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-08-11 15:57:32 +00:00
|
|
|
def check_firmware_header(header : bytes) -> FirmwareHeaderInfo:
|
|
|
|
"""Parses incoming firmware header and returns information about it."""
|
2023-10-20 12:58:32 +00:00
|
|
|
|
|
|
|
|
2024-11-15 09:07:01 +00:00
|
|
|
# upymod/modtrezorutils/modtrezorutils.c
|
2023-09-13 13:36:06 +00:00
|
|
|
def bootloader_locked() -> bool | None:
|
|
|
|
"""
|
|
|
|
Returns True/False if the the bootloader is locked/unlocked and None if
|
|
|
|
the feature is not supported.
|
|
|
|
"""
|
2021-05-21 09:35:43 +00:00
|
|
|
SCM_REVISION: bytes
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Git commit hash of the firmware."""
|
2023-08-11 15:57:32 +00:00
|
|
|
VERSION: VersionTuple
|
|
|
|
"""Firmware version as a tuple (major, minor, patch, build)."""
|
2023-03-27 14:44:01 +00:00
|
|
|
USE_SD_CARD: bool
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Whether the hardware supports SD card."""
|
2023-06-23 10:07:18 +00:00
|
|
|
USE_BACKLIGHT: bool
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Whether the hardware supports backlight brightness control."""
|
2024-05-07 13:46:15 +00:00
|
|
|
USE_HAPTIC: bool
|
|
|
|
"""Whether the hardware supports haptic feedback."""
|
2023-08-23 08:00:41 +00:00
|
|
|
USE_OPTIGA: bool
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Whether the hardware supports Optiga secure element."""
|
2023-04-25 20:44:59 +00:00
|
|
|
USE_TOUCH: bool
|
|
|
|
"""Whether the hardware supports touch screen."""
|
|
|
|
USE_BUTTON: bool
|
|
|
|
"""Whether the hardware supports two-button input."""
|
2019-06-09 09:24:06 +00:00
|
|
|
MODEL: str
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Model name."""
|
|
|
|
MODEL_FULL_NAME: str
|
|
|
|
"""Full name including Trezor prefix."""
|
2024-05-03 12:57:55 +00:00
|
|
|
MODEL_USB_MANUFACTURER: str
|
|
|
|
"""USB Manufacturer name."""
|
|
|
|
MODEL_USB_PRODUCT: str
|
|
|
|
"""USB Product name."""
|
2023-06-01 12:21:51 +00:00
|
|
|
INTERNAL_MODEL: str
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Internal model code."""
|
2019-06-09 09:24:06 +00:00
|
|
|
EMULATOR: bool
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Whether the firmware is running in the emulator."""
|
2020-04-20 14:38:50 +00:00
|
|
|
BITCOIN_ONLY: bool
|
2023-09-29 10:25:58 +00:00
|
|
|
"""Whether the firmware is Bitcoin-only."""
|
2023-08-24 10:46:10 +00:00
|
|
|
UI_LAYOUT: str
|
2023-09-29 10:25:58 +00:00
|
|
|
"""UI layout identifier ("tt" for model T, "tr" for models One and R)."""
|
2024-04-02 14:51:01 +00:00
|
|
|
USE_THP: bool
|
2024-11-13 18:38:31 +00:00
|
|
|
"""Whether the firmware supports Trezor-Host Protocol (version 2)."""
|