async def _finish_recovery_dry_run(ctx: wire.GenericContext, secret: bytes, backup_type: EnumTypeBackupType) -> Success: if backup_type is None: raise RuntimeError digest_input = sha256(secret).digest() stored = mnemonic.get_secret() digest_stored = sha256(stored).digest() result = utils.consteq(digest_stored, digest_input) is_slip39 = backup_types.is_slip39_backup_type(backup_type) # Check that the identifier and iteration exponent match as well if is_slip39: result &= (storage_device.get_slip39_identifier() == storage_recovery.get_slip39_identifier()) result &= (storage_device.get_slip39_iteration_exponent() == storage_recovery.get_slip39_iteration_exponent()) await layout.show_dry_run_result(ctx, result, is_slip39) storage_recovery.end_progress() if result: return Success("The seed is valid and matches the one in the device") else: raise wire.ProcessError( "The seed does not match the one in the device")
async def backup_slip39_advanced( ctx: wire.Context, encrypted_master_secret: bytes ) -> None: # get number of groups await layout.slip39_show_checklist(ctx, 0, BackupType.Slip39_Advanced) groups_count = await layout.slip39_advanced_prompt_number_of_groups(ctx) # get group threshold await layout.slip39_show_checklist(ctx, 1, BackupType.Slip39_Advanced) group_threshold = await layout.slip39_advanced_prompt_group_threshold( ctx, groups_count ) # get shares and thresholds await layout.slip39_show_checklist(ctx, 2, BackupType.Slip39_Advanced) groups = [] for i in range(groups_count): share_count = await layout.slip39_prompt_number_of_shares(ctx, i) share_threshold = await layout.slip39_prompt_threshold(ctx, share_count, i) groups.append((share_threshold, share_count)) # generate the mnemonics mnemonics = slip39.generate_mnemonics_from_data( encrypted_master_secret=encrypted_master_secret, identifier=storage_device.get_slip39_identifier(), group_threshold=group_threshold, groups=groups, iteration_exponent=storage_device.get_slip39_iteration_exponent(), ) # show and confirm individual shares await layout.slip39_advanced_show_and_confirm_shares(ctx, mnemonics)
def get_seed(passphrase: str = "", progress_bar: bool = True) -> bytes: mnemonic_secret = get_secret() if mnemonic_secret is None: raise ValueError("Mnemonic not set") render_func = None if progress_bar: _start_progress() render_func = _render_progress if is_bip39(): seed = bip39.seed(mnemonic_secret.decode(), passphrase, render_func) else: # SLIP-39 identifier = storage_device.get_slip39_identifier() iteration_exponent = storage_device.get_slip39_iteration_exponent() if identifier is None or iteration_exponent is None: # Identifier or exponent expected but not found raise RuntimeError seed = slip39.decrypt(identifier, iteration_exponent, mnemonic_secret, passphrase.encode()) return seed
async def backup_slip39_basic( ctx: wire.Context, encrypted_master_secret: bytes ) -> None: # get number of shares await layout.slip39_show_checklist(ctx, 0, BackupType.Slip39_Basic) shares_count = await layout.slip39_prompt_number_of_shares(ctx) # get threshold await layout.slip39_show_checklist(ctx, 1, BackupType.Slip39_Basic) threshold = await layout.slip39_prompt_threshold(ctx, shares_count) # generate the mnemonics mnemonics = slip39.generate_mnemonics_from_data( encrypted_master_secret, storage_device.get_slip39_identifier(), 1, # Single Group threshold [(threshold, shares_count)], # Single Group threshold/count storage_device.get_slip39_iteration_exponent(), )[0] # show and confirm individual shares await layout.slip39_show_checklist(ctx, 2, BackupType.Slip39_Basic) await layout.slip39_basic_show_and_confirm_shares(ctx, mnemonics)