diff --git a/src/apps/management/layout_load_device.py b/src/apps/management/layout_load_device.py index 2329b9b659..202588dd43 100644 --- a/src/apps/management/layout_load_device.py +++ b/src/apps/management/layout_load_device.py @@ -4,6 +4,7 @@ from trezor.utils import unimport @unimport async def layout_load_device(message, session_id): + from trezor.crypto import bip39 from trezor.messages.Storage import Storage from trezor.messages.Success import Success from trezor.messages.FailureType import UnexpectedMessage, Other @@ -13,6 +14,15 @@ async def layout_load_device(message, session_id): if get_storage(session_id): raise wire.FailureError(UnexpectedMessage, 'Already initialized') + storage = Storage() + storage.imported = True + + if hasattr(message, 'node'): + storage.node = message.node + elif hasattr(message, 'mnemonic'): + if not message.skip_checksum and not bip39.check(message.mnemonic): + raise wire.FailureError(Other, 'Mnemonic is not valid') + storage.mnemonic = message.mnemonic ui.display.clear() @@ -21,18 +31,12 @@ async def layout_load_device(message, session_id): ui.BOLD, 'Loading private seed', 'is not recommended.', ui.NORMAL, 'Continue only if you', 'know what you are doing!')) - node = getattr(message, 'node', None) - mnemonic = getattr(message, 'mnemonic', None) + storage.version = 1 + storage.pin = message.pin + storage.passphrase_protection = message.passphrase_protection, + storage.language = message.language + storage.label = message.label - # if node is not None: - # raise wire.FailureError(Other, 'XPRV import is not implemented') - # if mnemonic is not None and not message.skip_checksum: - # raise wire.FailureError(Other, 'Mnemonic checksum is not implemented') - - storage = Storage( - version=1, imported=1, mnemonic=mnemonic, node=node, - pin=message.pin, passphrase_protection=message.passphrase_protection, - language=message.language, label=message.label) set_storage(session_id, await storage.dumps()) return Success(message='Device loaded')