1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 21:48:13 +00:00

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

This commit is contained in:
Ioan Bizău 2024-04-24 12:30:53 +02:00 committed by Ioan Bizău
parent 3006224bff
commit 4afe42a57e
6 changed files with 25 additions and 40 deletions

View File

@ -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())

View File

@ -110,7 +110,8 @@ async def _show_confirmation_success(
num_of_shares: int | None = None,
group_index: int | None = None,
) -> None:
if share_index is None or num_of_shares is None: # it is a BIP39 backup
if share_index is None or num_of_shares is None:
# it is a BIP39 or a 1-of-1 SLIP39 backup
subheader = TR.reset__finished_verifying_seed
text = ""
@ -150,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:
@ -162,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()
@ -181,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(" ")
@ -204,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):

View File

@ -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,

View File

@ -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(

View File

@ -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)

View File

@ -1390,8 +1390,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()
@ -1403,8 +1401,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()
@ -1416,8 +1412,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()