refactor(core): make 1-of-1 SLIP39 backups use same messaging as BIP39

mmilata/ui-t3t1-preview
Ioan Bizău 1 month ago committed by obrusvit
parent 891927f6b3
commit a8d018e797

@ -123,10 +123,14 @@ async def _backup_slip39_basic(encrypted_master_secret: bytes) -> None:
await layout.slip39_show_checklist(1, BAK_T_SLIP39_BASIC)
share_threshold = await layout.slip39_prompt_threshold(share_count)
await backup_slip39_custom(
mnemonics = _get_slip39_mnemonics(
encrypted_master_secret, group_threshold, ((share_threshold, share_count),)
)
# show and confirm individual shares
await layout.slip39_show_checklist(2, BAK_T_SLIP39_BASIC)
await layout.slip39_basic_show_and_confirm_shares(mnemonics[0])
async def _backup_slip39_advanced(encrypted_master_secret: bytes) -> None:
# get number of groups
@ -145,7 +149,10 @@ async def _backup_slip39_advanced(encrypted_master_secret: bytes) -> None:
share_threshold = await layout.slip39_prompt_threshold(share_count, i)
groups.append((share_threshold, share_count))
await backup_slip39_custom(encrypted_master_secret, group_threshold, groups)
mnemonics = _get_slip39_mnemonics(encrypted_master_secret, group_threshold, groups)
# show and confirm individual shares
await layout.slip39_advanced_show_and_confirm_shares(mnemonics)
async def backup_slip39_custom(
@ -153,28 +160,21 @@ async def backup_slip39_custom(
group_threshold: int,
groups: Sequence[tuple[int, int]],
) -> None:
mnemonics = await _get_slip39_mnemonics(encrypted_master_secret, group_threshold, groups)
mnemonics = _get_slip39_mnemonics(encrypted_master_secret, group_threshold, groups)
# show and confirm individual shares
if len(groups) == 1 and groups[0][0] == 1 and groups[0][1] == 1:
# for a single 1-of-1 group, we use the same layouts as for BIP39
await layout.show_and_confirm_mnemonic(mnemonics[0][0])
else:
await confirm_action(
"warning_shamir_backup",
TR.reset__title_shamir_backup,
description=TR.reset__create_x_of_y_shamir_backup_template.format(
groups[0][0], groups[0][1]
),
verb=TR.buttons__continue,
)
# TODO: a confirmation screen will be shown: "do you want to create a -of- Shamir backup?"
if len(groups) == 1:
await layout.slip39_basic_show_and_confirm_shares(mnemonics[0])
else:
await layout.slip39_advanced_show_and_confirm_shares(mnemonics)
async def _get_slip39_mnemonics(
def _get_slip39_mnemonics(
encrypted_master_secret: bytes,
group_threshold: int,
groups: Sequence[tuple[int, int]],
@ -185,7 +185,7 @@ async def _get_slip39_mnemonics(
raise ValueError
# generate the mnemonics
mnemonics = slip39.split_ems(
return slip39.split_ems(
group_threshold,
groups,
identifier,
@ -193,13 +193,6 @@ async def _get_slip39_mnemonics(
encrypted_master_secret,
)
# show and confirm individual shares
if len(groups) == 1:
await layout.slip39_show_checklist(2, BAK_T_SLIP39_BASIC)
await layout.slip39_basic_show_and_confirm_shares(mnemonics[0])
else:
await layout.slip39_advanced_show_and_confirm_shares(mnemonics)
def _validate_reset_device(msg: ResetDevice) -> None:
from trezor.wire import UnexpectedMessage
@ -247,4 +240,4 @@ async def backup_seed(backup_type: BackupType, mnemonic_secret: bytes) -> None:
elif backup_type == BAK_T_SLIP39_ADVANCED:
await _backup_slip39_advanced(mnemonic_secret)
else:
await layout.bip39_show_and_confirm_mnemonic(mnemonic_secret.decode())
await layout.show_and_confirm_mnemonic(mnemonic_secret.decode())

@ -151,10 +151,10 @@ async def _show_confirmation_failure() -> None:
)
async def show_backup_warning(slip39: bool = False) -> None:
async def show_backup_warning() -> None:
from trezor.ui.layouts.reset import show_warning_backup
await show_warning_backup(slip39)
await show_warning_backup()
async def show_backup_success() -> None:
@ -163,11 +163,11 @@ async def show_backup_success() -> None:
await show_success_backup()
# BIP39
# Simple setups: BIP39 or SLIP39 1-of-1
# ===
async def bip39_show_and_confirm_mnemonic(mnemonic: str) -> None:
async def show_and_confirm_mnemonic(mnemonic: str) -> None:
# warn user about mnemonic safety
await show_backup_warning()
@ -182,13 +182,13 @@ async def bip39_show_and_confirm_mnemonic(mnemonic: str) -> None:
break # mnemonic is confirmed, go next
# SLIP39
# Complex setups: SLIP39, except 1-of-1
# ===
async def slip39_basic_show_and_confirm_shares(shares: Sequence[str]) -> None:
# warn user about mnemonic safety
await show_backup_warning(True)
await show_backup_warning()
for index, share in enumerate(shares):
share_words = share.split(" ")
@ -205,7 +205,7 @@ async def slip39_advanced_show_and_confirm_shares(
shares: Sequence[Sequence[str]],
) -> None:
# warn user about mnemonic safety
await show_backup_warning(True)
await show_backup_warning()
for group_index, group in enumerate(shares):
for share_index, share in enumerate(group):

@ -258,7 +258,7 @@ async def slip39_advanced_prompt_group_threshold(num_of_groups: int) -> int:
)
async def show_warning_backup(slip39: bool) -> None:
async def show_warning_backup() -> None:
await show_warning(
"backup_warning",
TR.words__title_remember,

@ -319,7 +319,7 @@ async def slip39_advanced_prompt_group_threshold(num_of_groups: int) -> int:
)
async def show_warning_backup(slip39: bool) -> None:
async def show_warning_backup() -> None:
result = await interact(
RustLayout(
trezorui2.show_info(

@ -75,9 +75,6 @@ def test_backup_slip39_custom(
groups=[(share_threshold, share_count)],
)
# confirm checklist
reset.confirm_read(debug)
# confirm backup warning
reset.confirm_read(debug, middle_r=True)

@ -1474,8 +1474,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
self.share_count = share_count
def input_flow_tt(self) -> BRGeneratorType:
yield # Checklist
self.debug.press_yes()
yield # Confirm show seeds
self.debug.press_yes()
@ -1487,8 +1485,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
yield # Checklist
self.debug.press_yes()
yield # Confirm show seeds
self.debug.press_yes()
@ -1500,8 +1496,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
yield # Checklist
self.debug.press_yes()
yield # Confirm show seeds
self.debug.press_yes()

Loading…
Cancel
Save