def get_slip39_remaining_shares(group_index: int) -> int | None: _require_progress() remaining = common.get(_NAMESPACE, _REMAINING) if remaining is None or remaining[group_index] == slip39.MAX_SHARE_COUNT: return None else: return remaining[group_index]
def get_sd_salt_auth_key() -> bytes | None: """ The key used to check the authenticity of the SD card salt. """ auth_key = common.get(_NAMESPACE, _SD_SALT_AUTH_KEY, public=True) if auth_key is not None and len(auth_key) != SD_SALT_AUTH_KEY_LEN_BYTES: raise ValueError return auth_key
def get_passphrase_source() -> int: b = common.get(_NAMESPACE, _PASSPHRASE_SOURCE) if b == b"\x01": return 1 elif b == b"\x02": return 2 else: return 0
def _migrate_from_version_01() -> None: # Make the U2F counter public and writable even when storage is locked. # U2F counter wasn't public, so we are intentionally not using storage.device module. counter = common.get(common.APP_DEVICE, device.U2F_COUNTER) if counter is not None: device.set_u2f_counter(int.from_bytes(counter, "big")) # Delete the old, non-public U2F_COUNTER. common.delete(common.APP_DEVICE, device.U2F_COUNTER) set_current_version()
def set_flags(flags: int) -> None: b = common.get(_NAMESPACE, _FLAGS) if b is None: i = 0 else: i = int.from_bytes(b, "big") flags = (flags | i) & 0xFFFF_FFFF if flags != i: common.set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
def get_slip39_remaining_shares(group_index: int) -> int | None: from trezor.crypto.slip39 import MAX_SHARE_COUNT _require_progress() remaining = common.get(_NAMESPACE, _REMAINING) if remaining is None or remaining[group_index] == MAX_SHARE_COUNT: return None else: return remaining[group_index]
def fetch_slip39_remaining_shares() -> list[int] | None: _require_progress() remaining = common.get(_NAMESPACE, _REMAINING) if not remaining: return None group_count = get_slip39_group_count() if not group_count: raise RuntimeError return list(remaining[:group_count])
def set_slip39_remaining_shares(shares_remaining: int, group_index: int) -> None: """ We store the remaining shares as a bytearray of length group_count. Each byte represents share remaining for group of that group_index. 0x10 (16) was chosen as the default value because it's the max share count for a group. """ _require_progress() remaining = common.get(_NAMESPACE, _REMAINING) group_count = get_slip39_group_count() if not group_count: raise RuntimeError if remaining is None: remaining = bytearray([slip39.MAX_SHARE_COUNT] * group_count) remaining = bytearray(remaining) remaining[group_index] = shares_remaining common.set(_NAMESPACE, _REMAINING, remaining)
def get_flags() -> int: b = common.get(_NAMESPACE, _FLAGS) if b is None: return 0 else: return int.from_bytes(b, "big")
def get_homescreen() -> bytes | None: return common.get(_NAMESPACE, _HOMESCREEN, public=True)
def get_mnemonic_secret() -> bytes | None: return common.get(_NAMESPACE, _MNEMONIC_SECRET)
def get_label() -> str | None: label = common.get(_NAMESPACE, _LABEL, True) # public if label is None: return None return label.decode()
def get(index: int) -> Optional[bytes]: if not (0 <= index < MAX_RESIDENT_CREDENTIALS): raise ValueError # invalid credential index return common.get(common.APP_WEBAUTHN, index + _RESIDENT_CREDENTIAL_START_KEY)
def get(index: int) -> bytes | None: if not 0 <= index < MAX_RESIDENT_CREDENTIALS: raise ValueError # invalid credential index return common.get(common.APP_WEBAUTHN, index + _RESIDENT_CREDENTIAL_START_KEY)
def is_version_stored() -> bool: return bool(common.get(_NAMESPACE, _VERSION))
def get_mnemonic_secret() -> Optional[bytes]: return common.get(_NAMESPACE, _MNEMONIC_SECRET)
def get_autolock_delay_ms() -> int: b = common.get(_NAMESPACE, _AUTOLOCK_DELAY_MS) if b is None: return 10 * 60 * 1000 else: return int.from_bytes(b, "big")
def get_autolock_delay_ms() -> int: b = common.get(_NAMESPACE, _AUTOLOCK_DELAY_MS) if b is None: return AUTOLOCK_DELAY_DEFAULT else: return _normalize_autolock_delay(int.from_bytes(b, "big"))
def get_homescreen() -> Optional[bytes]: return common.get(_NAMESPACE, _HOMESCREEN, public=True)
def get_device_id() -> str: dev_id = common.get(_NAMESPACE, DEVICE_ID, public=True) if not dev_id: dev_id = _new_device_id().encode() common.set(_NAMESPACE, DEVICE_ID, dev_id, public=True) return dev_id.decode()
def get_version() -> bytes | None: return common.get(_NAMESPACE, _VERSION)
def get_version() -> Optional[bytes]: return common.get(_NAMESPACE, _VERSION)
def get_rotation() -> int: rotation = common.get(_NAMESPACE, _ROTATION, public=True) if not rotation: return 0 return int.from_bytes(rotation, "big")
def get(index: int, group_index: int) -> str | None: m = common.get(common.APP_RECOVERY_SHARES, index + group_index * slip39.MAX_SHARE_COUNT) if m: return m.decode() return None