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
|
|
|
|
2017-06-14 15:41:45 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-06-09 09:24:06 +00:00
|
|
|
def init(
|
2021-03-18 09:48:50 +00:00
|
|
|
ui_wait_callback: Callable[[int, int, str], bool] | None = None
|
2019-06-09 09:24:06 +00:00
|
|
|
) -> None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2018-01-26 13:28:49 +00:00
|
|
|
Initializes the storage. Must be called before any other method is
|
|
|
|
called from this module!
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2017-06-14 15:41:45 +00:00
|
|
|
|
2018-03-09 10:37:06 +00:00
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2021-03-18 09:48:50 +00:00
|
|
|
def unlock(pin: str, ext_salt: bytes | None) -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-08-09 20:52:09 +00:00
|
|
|
Attempts to unlock the storage with the given PIN and external salt.
|
|
|
|
Returns True on success, False on failure.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2021-03-18 09:48:50 +00:00
|
|
|
def check_pin(pin: str, ext_salt: bytes | None) -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-08-09 20:52:09 +00:00
|
|
|
Check the given PIN with the given external salt.
|
|
|
|
Returns True on success, False on failure.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
|
|
|
def lock() -> None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-02-27 10:30:58 +00:00
|
|
|
Locks the storage.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
|
2020-04-21 08:23:01 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
|
|
|
def is_unlocked() -> bool:
|
|
|
|
"""
|
|
|
|
Returns True if storage is unlocked, False otherwise.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
|
|
|
def has_pin() -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2018-01-26 13:28:49 +00:00
|
|
|
Returns True if storage has a configured PIN, False otherwise.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-02-27 10:30:58 +00:00
|
|
|
def get_pin_rem() -> int:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-02-27 10:30:58 +00:00
|
|
|
Returns the number of remaining PIN entry attempts.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-08-09 20:52:09 +00:00
|
|
|
def change_pin(
|
2020-08-13 21:29:50 +00:00
|
|
|
oldpin: str,
|
|
|
|
newpin: str,
|
2021-03-18 09:48:50 +00:00
|
|
|
old_ext_salt: bytes | None,
|
|
|
|
new_ext_salt: bytes | None,
|
2019-08-09 20:52:09 +00:00
|
|
|
) -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-08-09 20:52:09 +00:00
|
|
|
Change PIN and external salt. Returns True on success, False on failure.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
|
2020-03-16 22:38:48 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2020-08-13 21:29:50 +00:00
|
|
|
def ensure_not_wipe_code(pin: str) -> None:
|
2020-03-16 22:38:48 +00:00
|
|
|
"""
|
|
|
|
Wipes the device if the entered PIN is the wipe code.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-10-29 14:58:53 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
|
|
|
def has_wipe_code() -> bool:
|
|
|
|
"""
|
|
|
|
Returns True if storage has a configured wipe code, False otherwise.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-10-18 18:12:17 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
|
|
|
def change_wipe_code(
|
2020-08-13 21:29:50 +00:00
|
|
|
pin: str,
|
2021-03-18 09:48:50 +00:00
|
|
|
ext_salt: bytes | None,
|
2020-08-13 21:29:50 +00:00
|
|
|
wipe_code: str,
|
2019-10-18 18:12:17 +00:00
|
|
|
) -> bool:
|
|
|
|
"""
|
|
|
|
Change wipe code. Returns True on success, False on failure.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2018-01-26 13:28:49 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2021-03-18 09:48:50 +00:00
|
|
|
def get(app: int, key: int, public: bool = False) -> bytes | None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-02-27 10:30:58 +00:00
|
|
|
Gets the value of the given key for the given app (or None if not set).
|
2019-05-17 12:22:36 +00:00
|
|
|
Raises a RuntimeError if decryption or authentication of the stored
|
|
|
|
value fails.
|
|
|
|
"""
|
|
|
|
|
2017-06-14 15:41:45 +00:00
|
|
|
|
2017-06-20 11:24:12 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-05-17 12:22:36 +00:00
|
|
|
def set(app: int, key: int, value: bytes, public: bool = False) -> None:
|
|
|
|
"""
|
2017-06-20 11:24:12 +00:00
|
|
|
Sets a value of given key for given app.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2017-06-14 15:41:45 +00:00
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2021-03-10 13:43:21 +00:00
|
|
|
def delete(
|
|
|
|
app: int, key: int, public: bool = False, writable_locked: bool = False
|
|
|
|
) -> bool:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-02-27 10:30:58 +00:00
|
|
|
Deletes the given key of the given app.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-05-17 12:22:36 +00:00
|
|
|
def set_counter(
|
|
|
|
app: int, key: int, count: int, writable_locked: bool = False
|
2021-03-10 13:43:21 +00:00
|
|
|
) -> None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2019-02-27 10:30:58 +00:00
|
|
|
Sets the given key of the given app as a counter with the given value.
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
|
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2019-07-09 12:05:14 +00:00
|
|
|
def next_counter(
|
|
|
|
app: int, key: int, writable_locked: bool = False,
|
2021-03-10 13:43:21 +00:00
|
|
|
) -> int:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
|
|
|
Increments the counter stored under the given key of the given app and
|
|
|
|
returns the new value.
|
|
|
|
"""
|
|
|
|
|
2019-02-27 10:30:58 +00:00
|
|
|
|
2017-06-20 11:24:12 +00:00
|
|
|
# extmod/modtrezorconfig/modtrezorconfig.c
|
2018-01-26 13:28:49 +00:00
|
|
|
def wipe() -> None:
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|
2017-06-20 11:24:12 +00:00
|
|
|
Erases the whole config. Use with caution!
|
2019-05-17 12:22:36 +00:00
|
|
|
"""
|