wip: move wipe_device to load_device

hackathon_input_flows
matejcik 12 months ago
parent 06eb7c7d5e
commit b4c5ef88d9

@ -6,20 +6,18 @@ if TYPE_CHECKING:
async def load_device(ctx: Context, msg: LoadDevice) -> Success:
import storage
import storage.device as storage_device
from trezor import config
from trezor.crypto import bip39, slip39
from trezor.enums import BackupType
from trezor.messages import Success
from apps.base import reload_settings_from_storage
from apps.management import backup_types
from trezor.wire import UnexpectedMessage, ProcessError
from trezor.ui.layouts import confirm_action
mnemonics = msg.mnemonics # local_cache_attribute
# _validate
if storage_device.is_initialized():
raise UnexpectedMessage("Already initialized")
if not mnemonics:
raise ProcessError("No mnemonic provided")
@ -41,11 +39,15 @@ async def load_device(ctx: Context, msg: LoadDevice) -> Success:
ctx,
"warn_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!",
hold_danger=True,
)
# END _warn
storage.wipe()
reload_settings_from_storage()
if not is_slip39: # BIP-39
secret = msg.mnemonics[0].encode()
backup_type = BackupType.Bip39

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

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

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

Loading…
Cancel
Save