1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 15:08:12 +00:00

fix(python): fallback for trezorctl device setup on older firmwares

fixes #3956
[no changelog] because the slip39-single feature was not yet released
This commit is contained in:
matejcik 2024-06-19 10:31:34 +02:00
parent 32d26933a6
commit d1981e745e

View File

@ -214,7 +214,7 @@ def recover(
@click.option("-u", "--u2f-counter", default=0)
@click.option("-s", "--skip-backup", is_flag=True)
@click.option("-n", "--no-backup", is_flag=True)
@click.option("-b", "--backup-type", type=ChoiceType(BACKUP_TYPE), default="single")
@click.option("-b", "--backup-type", type=ChoiceType(BACKUP_TYPE))
@with_client
def setup(
client: "TrezorClient",
@ -226,22 +226,33 @@ def setup(
u2f_counter: int,
skip_backup: bool,
no_backup: bool,
backup_type: messages.BackupType,
backup_type: messages.BackupType | None,
) -> str:
"""Perform device setup and generate new seed."""
if strength:
strength = int(strength)
BT = messages.BackupType
if backup_type is None:
if client.version >= (2, 7, 1):
# SLIP39 extendable was introduced in 2.7.1
backup_type = BT.Slip39_Single_Extendable
else:
# this includes both T1 and older trezor-cores
backup_type = BT.Bip39
if (
backup_type == messages.BackupType.Slip39_Basic
backup_type
in (BT.Slip39_Single_Extendable, BT.Slip39_Basic, BT.Slip39_Basic_Extendable)
and messages.Capability.Shamir not in client.features.capabilities
) or (
backup_type == messages.BackupType.Slip39_Advanced
backup_type in (BT.Slip39_Advanced, BT.Slip39_Advanced_Extendable)
and messages.Capability.ShamirGroups not in client.features.capabilities
):
click.echo(
"WARNING: Your Trezor device does not indicate support for the requested\n"
"backup type. Traditional single-seed backup may be generated instead."
"backup type. Traditional BIP39 backup may be generated instead."
)
return device.reset(