1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-16 03:28:09 +00:00
trezor-firmware/core/src/storage/recovery_shares.py
matejcik 5c93ecd53a core: create top-level storage module
This is to avoid including app-specific functionality in storage and
avoid circular imports. The following policy is now in effect: modules
from `storage` namespace must not import from `apps` namespace.

In most files, the change only involves changing import paths.

A minor refactor was needed in case of webauthn: basic get/set/delete
functionality was left in storage.webauthn, and more advanced logic on
top of it was moved to apps.webauthn.resident_credentials.

A significant refactor was needed for sd_salt, where application (and
UI) logic was tightly coupled with the IO code. This is now separated,
and storage.sd_salt deals exclusively with the IO side, while the app/UI
logic is implemented on top of it in apps.common.sd_salt and
apps.management.sd_protect.
2019-10-31 16:21:56 +01:00

41 lines
1002 B
Python

from storage import common
from trezor.crypto import slip39
if False:
from typing import List, Optional
# Mnemonics stored during SLIP-39 recovery process.
# Each mnemonic is stored under key = index.
def set(index: int, group_index: int, mnemonic: str) -> None:
common.set(
common.APP_RECOVERY_SHARES,
index + group_index * slip39.MAX_SHARE_COUNT,
mnemonic.encode(),
)
def get(index: int, group_index: int) -> Optional[str]:
m = common.get(
common.APP_RECOVERY_SHARES, index + group_index * slip39.MAX_SHARE_COUNT
)
if m:
return m.decode()
return None
def fetch_group(group_index: int) -> List[str]:
mnemonics = []
for index in range(slip39.MAX_SHARE_COUNT):
m = get(index, group_index)
if m:
mnemonics.append(m)
return mnemonics
def delete() -> None:
for index in range(slip39.MAX_SHARE_COUNT * slip39.MAX_GROUP_COUNT):
common.delete(common.APP_RECOVERY_SHARES, index)