mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
python: support for multi-mnemonic load_device
This commit is contained in:
parent
accc33c8e6
commit
bc7c16c562
@ -417,7 +417,7 @@ def wipe_device(connect, bootloader):
|
||||
|
||||
|
||||
@cli.command(help="Load custom configuration to the device.")
|
||||
@click.option("-m", "--mnemonic")
|
||||
@click.option("-m", "--mnemonic", multiple=True)
|
||||
@click.option("-e", "--expand", is_flag=True)
|
||||
@click.option("-x", "--xprv")
|
||||
@click.option("-p", "--pin", default="")
|
||||
@ -437,31 +437,31 @@ def load_device(
|
||||
ignore_checksum,
|
||||
slip0014,
|
||||
):
|
||||
if not mnemonic and not xprv and not slip0014:
|
||||
raise tools.CallException(
|
||||
proto.FailureType.DataError, "Please provide mnemonic or xprv"
|
||||
)
|
||||
n_args = sum(bool(a) for a in (mnemonic, xprv, slip0014))
|
||||
if n_args == 0:
|
||||
raise click.ClickException("Please provide a mnemonic or xprv")
|
||||
if n_args > 1:
|
||||
raise click.ClickException("Cannot use mnemonic and xprv together")
|
||||
|
||||
client = connect()
|
||||
if mnemonic:
|
||||
return debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
mnemonic,
|
||||
pin,
|
||||
passphrase_protection,
|
||||
label,
|
||||
"english",
|
||||
ignore_checksum,
|
||||
expand,
|
||||
)
|
||||
|
||||
if xprv:
|
||||
return debuglink.load_device_by_xprv(
|
||||
client, xprv, pin, passphrase_protection, label, "english"
|
||||
)
|
||||
|
||||
if slip0014:
|
||||
return debuglink.load_device_by_mnemonic(
|
||||
client, " ".join(["all"] * 12), pin, passphrase_protection, "SLIP-0014"
|
||||
)
|
||||
mnemonic = [" ".join(["all"] * 12)]
|
||||
|
||||
return debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
list(mnemonic),
|
||||
pin,
|
||||
passphrase_protection,
|
||||
label,
|
||||
"english",
|
||||
ignore_checksum,
|
||||
)
|
||||
|
||||
|
||||
@cli.command(help="Start safe recovery workflow.")
|
||||
|
@ -408,21 +408,11 @@ def load_device_by_mnemonic(
|
||||
label,
|
||||
language="english",
|
||||
skip_checksum=False,
|
||||
expand=False,
|
||||
):
|
||||
# Convert mnemonic to UTF8 NKFD
|
||||
mnemonic = Mnemonic.normalize_string(mnemonic)
|
||||
if not isinstance(mnemonic, (list, tuple)):
|
||||
mnemonic = [mnemonic]
|
||||
|
||||
# Convert mnemonic to ASCII stream
|
||||
mnemonic = mnemonic.encode()
|
||||
|
||||
m = Mnemonic("english")
|
||||
|
||||
if expand:
|
||||
mnemonic = m.expand(mnemonic)
|
||||
|
||||
if not skip_checksum and not m.check(mnemonic):
|
||||
raise ValueError("Invalid mnemonic checksum")
|
||||
mnemonics = [Mnemonic.normalize_string(m) for m in mnemonic]
|
||||
|
||||
if client.features.initialized:
|
||||
raise RuntimeError(
|
||||
@ -431,7 +421,7 @@ def load_device_by_mnemonic(
|
||||
|
||||
resp = client.call(
|
||||
proto.LoadDevice(
|
||||
mnemonic=mnemonic,
|
||||
mnemonics=mnemonics,
|
||||
pin=pin,
|
||||
passphrase_protection=passphrase_protection,
|
||||
language=language,
|
||||
|
Loading…
Reference in New Issue
Block a user