1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-01 20:32:35 +00:00

python: support for multi-mnemonic load_device

This commit is contained in:
matejcik 2019-07-24 15:36:33 +02:00 committed by Tomas Susanka
parent accc33c8e6
commit bc7c16c562
2 changed files with 23 additions and 33 deletions

View File

@ -417,7 +417,7 @@ def wipe_device(connect, bootloader):
@cli.command(help="Load custom configuration to the device.") @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("-e", "--expand", is_flag=True)
@click.option("-x", "--xprv") @click.option("-x", "--xprv")
@click.option("-p", "--pin", default="") @click.option("-p", "--pin", default="")
@ -437,30 +437,30 @@ def load_device(
ignore_checksum, ignore_checksum,
slip0014, slip0014,
): ):
if not mnemonic and not xprv and not slip0014: n_args = sum(bool(a) for a in (mnemonic, xprv, slip0014))
raise tools.CallException( if n_args == 0:
proto.FailureType.DataError, "Please provide mnemonic or xprv" raise click.ClickException("Please provide a mnemonic or xprv")
) if n_args > 1:
raise click.ClickException("Cannot use mnemonic and xprv together")
client = connect() client = connect()
if mnemonic:
if xprv:
return debuglink.load_device_by_xprv(
client, xprv, pin, passphrase_protection, label, "english"
)
if slip0014:
mnemonic = [" ".join(["all"] * 12)]
return debuglink.load_device_by_mnemonic( return debuglink.load_device_by_mnemonic(
client, client,
mnemonic, list(mnemonic),
pin, pin,
passphrase_protection, passphrase_protection,
label, label,
"english", "english",
ignore_checksum, 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"
) )

View File

@ -408,21 +408,11 @@ def load_device_by_mnemonic(
label, label,
language="english", language="english",
skip_checksum=False, skip_checksum=False,
expand=False,
): ):
# Convert mnemonic to UTF8 NKFD if not isinstance(mnemonic, (list, tuple)):
mnemonic = Mnemonic.normalize_string(mnemonic) mnemonic = [mnemonic]
# Convert mnemonic to ASCII stream mnemonics = [Mnemonic.normalize_string(m) for m in mnemonic]
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")
if client.features.initialized: if client.features.initialized:
raise RuntimeError( raise RuntimeError(
@ -431,7 +421,7 @@ def load_device_by_mnemonic(
resp = client.call( resp = client.call(
proto.LoadDevice( proto.LoadDevice(
mnemonic=mnemonic, mnemonics=mnemonics,
pin=pin, pin=pin,
passphrase_protection=passphrase_protection, passphrase_protection=passphrase_protection,
language=language, language=language,