core/recovery: remove group threshold from storage

pull/545/head
Tomas Susanka 5 years ago
parent 6731d1bbf2
commit 871e159bee

@ -16,7 +16,6 @@ _SLIP39_THRESHOLD = const(0x04) # int
_REMAINING = const(0x05) # int
_SLIP39_ITERATION_EXPONENT = const(0x06) # int
_SLIP39_GROUP_COUNT = const(0x07) # int
_SLIP39_GROUP_THRESHOLD = const(0x08) # int
# Deprecated Keys:
# _WORD_COUNT = const(0x02) # int
@ -95,15 +94,6 @@ def get_slip39_group_count() -> Optional[int]:
)
def set_slip39_group_threshold(group_threshold: int) -> None:
common.set_uint8(_NAMESPACE, _SLIP39_GROUP_THRESHOLD, group_threshold)
def get_slip39_group_threshold() -> Optional[int]:
_require_progress()
return common.get_uint8(_NAMESPACE, _SLIP39_GROUP_THRESHOLD)
def set_slip39_remaining_shares(shares_remaining: int, group_index: int) -> None:
"""
We store the remaining shares as a bytearray of length group_count.
@ -153,5 +143,4 @@ def end_progress() -> None:
common.delete(_NAMESPACE, _REMAINING)
common.delete(_NAMESPACE, _SLIP39_ITERATION_EXPONENT)
common.delete(_NAMESPACE, _SLIP39_GROUP_COUNT)
common.delete(_NAMESPACE, _SLIP39_GROUP_THRESHOLD)
recovery_shares.delete()

@ -1,6 +1,6 @@
from trezor import loop, utils, wire
from trezor.crypto import slip39
from trezor.crypto.hashlib import sha256
from trezor.crypto.slip39 import MAX_SHARE_COUNT
from trezor.errors import MnemonicError
from trezor.messages import BackupType
from trezor.messages.Success import Success
@ -209,14 +209,18 @@ async def _show_remaining_groups_and_shares(ctx: wire.Context) -> None:
identifiers = []
first_entered_index = -1
for i in range(len(shares_remaining)):
if shares_remaining[i] < MAX_SHARE_COUNT:
if shares_remaining[i] < slip39.MAX_SHARE_COUNT:
first_entered_index = i
share = None
for i, r in enumerate(shares_remaining):
if 0 < r < MAX_SHARE_COUNT:
identifier = storage.recovery_shares.fetch_group(i)[0].split(" ")[0:3]
if 0 < r < slip39.MAX_SHARE_COUNT:
if not share:
m = storage.recovery_shares.fetch_group(i)[0]
share = slip39.decode_mnemonic(m)
identifier = mnemonic.split(" ")[0:3]
identifiers.append([r, identifier])
elif r == MAX_SHARE_COUNT:
elif r == slip39.MAX_SHARE_COUNT:
identifier = storage.recovery_shares.fetch_group(first_entered_index)[
0
].split(" ")[0:2]
@ -226,4 +230,6 @@ async def _show_remaining_groups_and_shares(ctx: wire.Context) -> None:
except ValueError:
identifiers.append([r, identifier])
return await layout.show_remaining_shares(ctx, identifiers, shares_remaining)
return await layout.show_remaining_shares(
ctx, identifiers, shares_remaining, share.group_threshold
)

@ -154,8 +154,8 @@ async def show_remaining_shares(
ctx: wire.Context,
groups: List[int, List[str]], # remaining + list 3 words
shares_remaining: List[int],
group_threshold: int,
) -> None:
group_threshold = storage.recovery.get_slip39_group_threshold()
pages = []
for remaining, group in groups:
if 0 < remaining < MAX_SHARE_COUNT:

@ -35,7 +35,6 @@ def process_slip39(words: str) -> Tuple[Optional[bytes], slip39.Share]:
# if this is the first share, parse and store metadata
if not remaining:
storage.recovery.set_slip39_group_count(share.group_count)
storage.recovery.set_slip39_group_threshold(share.group_threshold)
storage.recovery.set_slip39_iteration_exponent(share.iteration_exponent)
storage.recovery.set_slip39_identifier(share.identifier)
storage.recovery.set_slip39_threshold(share.threshold)

Loading…
Cancel
Save