src/apps/management: implement dry_run in recovery_device

This commit is contained in:
Pavol Rusnak 2018-02-28 21:13:37 +01:00
parent 1269a0239d
commit 01bb1e34fa
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
1 changed files with 8 additions and 4 deletions

View File

@ -24,7 +24,7 @@ async def recovery_device(ctx, msg):
4. Optionally ask for the PIN, with confirmation.
5. Save into storage.
'''
if storage.is_initialized():
if not msg.dry_run and storage.is_initialized():
raise wire.FailureError(UnexpectedMessage, 'Already initialized')
# ask for the number of words
@ -34,7 +34,7 @@ async def recovery_device(ctx, msg):
mnemonic = await request_mnemonic(ctx, wordcount)
# check mnemonic validity
if msg.enforce_wordlist:
if msg.enforce_wordlist or msg.dry_run:
if not bip39.check(mnemonic):
raise wire.FailureError(ProcessError, 'Mnemonic is not valid')
@ -50,8 +50,12 @@ async def recovery_device(ctx, msg):
label=msg.label, use_passphrase=msg.passphrase_protection)
storage.load_mnemonic(
mnemonic=mnemonic, needs_backup=False)
return Success()
return Success(message='Device recovered')
else:
if storage.get_mnemonic() == mnemonic:
return Success(message='The seed is valid and matches the one in the device')
else:
raise wire.FailureError(ProcessError, 'The seed is valid but does not match the one in the device')
@ui.layout