wip: move wipe_device to load_device

hackathon_input_flows
matejcik 1 year ago
parent 06eb7c7d5e
commit b4c5ef88d9

@ -6,20 +6,18 @@ if TYPE_CHECKING:
async def load_device(ctx: Context, msg: LoadDevice) -> Success: async def load_device(ctx: Context, msg: LoadDevice) -> Success:
import storage
import storage.device as storage_device import storage.device as storage_device
from trezor import config from trezor import config
from trezor.crypto import bip39, slip39 from trezor.crypto import bip39, slip39
from trezor.enums import BackupType from trezor.enums import BackupType
from trezor.messages import Success from trezor.messages import Success
from apps.base import reload_settings_from_storage
from apps.management import backup_types from apps.management import backup_types
from trezor.wire import UnexpectedMessage, ProcessError from trezor.wire import UnexpectedMessage, ProcessError
from trezor.ui.layouts import confirm_action from trezor.ui.layouts import confirm_action
mnemonics = msg.mnemonics # local_cache_attribute mnemonics = msg.mnemonics # local_cache_attribute
# _validate
if storage_device.is_initialized():
raise UnexpectedMessage("Already initialized")
if not mnemonics: if not mnemonics:
raise ProcessError("No mnemonic provided") raise ProcessError("No mnemonic provided")
@ -41,11 +39,15 @@ async def load_device(ctx: Context, msg: LoadDevice) -> Success:
ctx, ctx,
"warn_loading_seed", "warn_loading_seed",
"Loading seed", "Loading seed",
"Loading private seed is not recommended.", "Wipe the device and set up seed from host?",
"Continue only if you know what you are doing!", "Continue only if you know what you are doing!",
hold_danger=True,
) )
# END _warn # END _warn
storage.wipe()
reload_settings_from_storage()
if not is_slip39: # BIP-39 if not is_slip39: # BIP-39
secret = msg.mnemonics[0].encode() secret = msg.mnemonics[0].encode()
backup_type = BackupType.Bip39 backup_type = BackupType.Bip39

@ -281,7 +281,7 @@ void fsm_msgGetEntropy(const GetEntropy *msg) {
void fsm_msgLoadDevice(const LoadDevice *msg) { void fsm_msgLoadDevice(const LoadDevice *msg) {
CHECK_PIN CHECK_PIN
CHECK_NOT_INITIALIZED config_wipe();
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("I take the risk"), NULL, layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("I take the risk"), NULL,
_("Loading private seed"), _("is not recommended."), _("Loading private seed"), _("is not recommended."),

@ -44,7 +44,7 @@ from typing import (
from mnemonic import Mnemonic from mnemonic import Mnemonic
from typing_extensions import Literal from typing_extensions import Literal
from . import mapping, messages, protobuf from . import device, mapping, messages, protobuf
from .client import TrezorClient from .client import TrezorClient
from .exceptions import TrezorFailure from .exceptions import TrezorFailure
from .log import DUMP_BYTES from .log import DUMP_BYTES
@ -1199,9 +1199,7 @@ def load_device(
mnemonics = [Mnemonic.normalize_string(m) for m in mnemonic] mnemonics = [Mnemonic.normalize_string(m) for m in mnemonic]
if client.features.initialized: if client.features.initialized:
raise RuntimeError( device.wipe(client)
"Device is initialized already. Call device.wipe() and try again."
)
resp = client.call( resp = client.call(
messages.LoadDevice( messages.LoadDevice(

@ -222,8 +222,6 @@ def client(
should_format = sd_marker.kwargs.get("formatted", True) should_format = sd_marker.kwargs.get("formatted", True)
_raw_client.debug.erase_sd_card(format=should_format) _raw_client.debug.erase_sd_card(format=should_format)
wipe_device(_raw_client)
setup_params = dict( setup_params = dict(
uninitialized=False, uninitialized=False,
mnemonic=" ".join(["all"] * 12), mnemonic=" ".join(["all"] * 12),
@ -241,7 +239,10 @@ def client(
setup_params["passphrase"], str setup_params["passphrase"], str
) )
if not setup_params["uninitialized"]: if setup_params["uninitialized"]:
wipe_device(_raw_client)
else:
debuglink.load_device( debuglink.load_device(
_raw_client, _raw_client,
mnemonic=setup_params["mnemonic"], # type: ignore mnemonic=setup_params["mnemonic"], # type: ignore

Loading…
Cancel
Save