mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-13 18:18:08 +00:00
refactor(core): make 1-of-1 SLIP39 backups use same messaging as BIP39
This commit is contained in:
parent
3006224bff
commit
4afe42a57e
@ -123,10 +123,14 @@ async def _backup_slip39_basic(encrypted_master_secret: bytes) -> None:
|
|||||||
await layout.slip39_show_checklist(1, BAK_T_SLIP39_BASIC)
|
await layout.slip39_show_checklist(1, BAK_T_SLIP39_BASIC)
|
||||||
share_threshold = await layout.slip39_prompt_threshold(share_count)
|
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),)
|
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:
|
async def _backup_slip39_advanced(encrypted_master_secret: bytes) -> None:
|
||||||
# get number of groups
|
# 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)
|
share_threshold = await layout.slip39_prompt_threshold(share_count, i)
|
||||||
groups.append((share_threshold, share_count))
|
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(
|
async def backup_slip39_custom(
|
||||||
@ -153,28 +160,21 @@ async def backup_slip39_custom(
|
|||||||
group_threshold: int,
|
group_threshold: int,
|
||||||
groups: Sequence[tuple[int, int]],
|
groups: Sequence[tuple[int, int]],
|
||||||
) -> None:
|
) -> 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
|
# show and confirm individual shares
|
||||||
if len(groups) == 1 and groups[0][0] == 1 and groups[0][1] == 1:
|
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
|
# for a single 1-of-1 group, we use the same layouts as for BIP39
|
||||||
await layout.show_and_confirm_mnemonic(mnemonics[0][0])
|
await layout.show_and_confirm_mnemonic(mnemonics[0][0])
|
||||||
else:
|
else:
|
||||||
await confirm_action(
|
# TODO: a confirmation screen will be shown: "do you want to create a -of- Shamir backup?"
|
||||||
"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,
|
|
||||||
)
|
|
||||||
if len(groups) == 1:
|
if len(groups) == 1:
|
||||||
await layout.slip39_basic_show_and_confirm_shares(mnemonics[0])
|
await layout.slip39_basic_show_and_confirm_shares(mnemonics[0])
|
||||||
else:
|
else:
|
||||||
await layout.slip39_advanced_show_and_confirm_shares(mnemonics)
|
await layout.slip39_advanced_show_and_confirm_shares(mnemonics)
|
||||||
|
|
||||||
|
|
||||||
async def _get_slip39_mnemonics(
|
def _get_slip39_mnemonics(
|
||||||
encrypted_master_secret: bytes,
|
encrypted_master_secret: bytes,
|
||||||
group_threshold: int,
|
group_threshold: int,
|
||||||
groups: Sequence[tuple[int, int]],
|
groups: Sequence[tuple[int, int]],
|
||||||
@ -185,7 +185,7 @@ async def _get_slip39_mnemonics(
|
|||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
# generate the mnemonics
|
# generate the mnemonics
|
||||||
mnemonics = slip39.split_ems(
|
return slip39.split_ems(
|
||||||
group_threshold,
|
group_threshold,
|
||||||
groups,
|
groups,
|
||||||
identifier,
|
identifier,
|
||||||
@ -193,13 +193,6 @@ async def _get_slip39_mnemonics(
|
|||||||
encrypted_master_secret,
|
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:
|
def _validate_reset_device(msg: ResetDevice) -> None:
|
||||||
from trezor.wire import UnexpectedMessage
|
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:
|
elif backup_type == BAK_T_SLIP39_ADVANCED:
|
||||||
await _backup_slip39_advanced(mnemonic_secret)
|
await _backup_slip39_advanced(mnemonic_secret)
|
||||||
else:
|
else:
|
||||||
await layout.bip39_show_and_confirm_mnemonic(mnemonic_secret.decode())
|
await layout.show_and_confirm_mnemonic(mnemonic_secret.decode())
|
||||||
|
@ -110,7 +110,8 @@ async def _show_confirmation_success(
|
|||||||
num_of_shares: int | None = None,
|
num_of_shares: int | None = None,
|
||||||
group_index: int | None = None,
|
group_index: int | None = 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
|
subheader = TR.reset__finished_verifying_seed
|
||||||
text = ""
|
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
|
from trezor.ui.layouts.reset import show_warning_backup
|
||||||
|
|
||||||
await show_warning_backup(slip39)
|
await show_warning_backup()
|
||||||
|
|
||||||
|
|
||||||
async def show_backup_success() -> None:
|
async def show_backup_success() -> None:
|
||||||
@ -162,11 +163,11 @@ async def show_backup_success() -> None:
|
|||||||
await show_success_backup()
|
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
|
# warn user about mnemonic safety
|
||||||
await show_backup_warning()
|
await show_backup_warning()
|
||||||
|
|
||||||
@ -181,13 +182,13 @@ async def bip39_show_and_confirm_mnemonic(mnemonic: str) -> None:
|
|||||||
break # mnemonic is confirmed, go next
|
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:
|
async def slip39_basic_show_and_confirm_shares(shares: Sequence[str]) -> None:
|
||||||
# warn user about mnemonic safety
|
# warn user about mnemonic safety
|
||||||
await show_backup_warning(True)
|
await show_backup_warning()
|
||||||
|
|
||||||
for index, share in enumerate(shares):
|
for index, share in enumerate(shares):
|
||||||
share_words = share.split(" ")
|
share_words = share.split(" ")
|
||||||
@ -204,7 +205,7 @@ async def slip39_advanced_show_and_confirm_shares(
|
|||||||
shares: Sequence[Sequence[str]],
|
shares: Sequence[Sequence[str]],
|
||||||
) -> None:
|
) -> None:
|
||||||
# warn user about mnemonic safety
|
# warn user about mnemonic safety
|
||||||
await show_backup_warning(True)
|
await show_backup_warning()
|
||||||
|
|
||||||
for group_index, group in enumerate(shares):
|
for group_index, group in enumerate(shares):
|
||||||
for share_index, share in enumerate(group):
|
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(
|
await show_warning(
|
||||||
"backup_warning",
|
"backup_warning",
|
||||||
TR.words__title_remember,
|
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(
|
result = await interact(
|
||||||
RustLayout(
|
RustLayout(
|
||||||
trezorui2.show_info(
|
trezorui2.show_info(
|
||||||
|
@ -75,9 +75,6 @@ def test_backup_slip39_custom(
|
|||||||
groups=[(share_threshold, share_count)],
|
groups=[(share_threshold, share_count)],
|
||||||
)
|
)
|
||||||
|
|
||||||
# confirm checklist
|
|
||||||
reset.confirm_read(debug)
|
|
||||||
|
|
||||||
# confirm backup warning
|
# confirm backup warning
|
||||||
reset.confirm_read(debug, middle_r=True)
|
reset.confirm_read(debug, middle_r=True)
|
||||||
|
|
||||||
|
@ -1390,8 +1390,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
|
|||||||
self.share_count = share_count
|
self.share_count = share_count
|
||||||
|
|
||||||
def input_flow_tt(self) -> BRGeneratorType:
|
def input_flow_tt(self) -> BRGeneratorType:
|
||||||
yield # Checklist
|
|
||||||
self.debug.press_yes()
|
|
||||||
yield # Confirm show seeds
|
yield # Confirm show seeds
|
||||||
self.debug.press_yes()
|
self.debug.press_yes()
|
||||||
|
|
||||||
@ -1403,8 +1401,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
|
|||||||
self.debug.press_yes()
|
self.debug.press_yes()
|
||||||
|
|
||||||
def input_flow_tr(self) -> BRGeneratorType:
|
def input_flow_tr(self) -> BRGeneratorType:
|
||||||
yield # Checklist
|
|
||||||
self.debug.press_yes()
|
|
||||||
yield # Confirm show seeds
|
yield # Confirm show seeds
|
||||||
self.debug.press_yes()
|
self.debug.press_yes()
|
||||||
|
|
||||||
@ -1416,8 +1412,6 @@ class InputFlowSlip39CustomBackup(InputFlowBase):
|
|||||||
self.debug.press_yes()
|
self.debug.press_yes()
|
||||||
|
|
||||||
def input_flow_t3t1(self) -> BRGeneratorType:
|
def input_flow_t3t1(self) -> BRGeneratorType:
|
||||||
yield # Checklist
|
|
||||||
self.debug.press_yes()
|
|
||||||
yield # Confirm show seeds
|
yield # Confirm show seeds
|
||||||
self.debug.press_yes()
|
self.debug.press_yes()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user