feat(python): propagate method to choose backup handler
What changed, and why it matters
This commit adds a new command-line option to the Trezor Python library that lets users choose between two backup methods (display on device screen, or a new 'N4W1' method) when setting up or backing up a hardware wallet. It is a feature addition, not a security fix.
No security action required; review as part of normal feature release.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change propagates a new BackupMethod enum value through the trezorlib Python client. It adds CLI flags --backup-method/-m to setup and backup commands, and forwards the value in ResetDevice and BackupDevice Protobuf messages. The default behavior remains Display. No validation, parsing, or protocol logic is altered beyond plumbing the new field.
Changed components
python/src/trezorlib/cli/device.pypython/src/trezorlib/device.pyInspect captured patch +15 / −1
diff --git a/python/src/trezorlib/cli/device.py b/python/src/trezorlib/cli/device.py
index bd51d883..c43dc894 100644
--- a/python/src/trezorlib/cli/device.py
+++ b/python/src/trezorlib/cli/device.py
@@ -44,6 +44,11 @@ BACKUP_TYPE = {
"advanced": messages.BackupType.Slip39_Advanced,
}
+BACKUP_METHOD = {
+ "display": messages.BackupMethod.Display,
+ "n4w1": messages.BackupMethod.N4W1,
+}
+
SD_PROTECT_OPERATIONS = {
"on": messages.SdProtectOperationType.ENABLE,
"off": messages.SdProtectOperationType.DISABLE,
@@ -231,6 +236,7 @@ def recover(
@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))
+@click.option("-m", "--backup-method", type=ChoiceType(BACKUP_METHOD))
@click.option("-e", "--entropy-check-count", type=click.IntRange(0))
@with_session(seedless=True)
def setup(
@@ -243,6 +249,7 @@ def setup(
skip_backup: bool,
no_backup: bool,
backup_type: messages.BackupType | None,
+ backup_method: messages.BackupMethod | None,
entropy_check_count: int | None,
) -> None:
"""Perform device setup and generate new seed."""
@@ -274,6 +281,7 @@ def setup(
skip_backup=skip_backup,
no_backup=no_backup,
backup_type=backup_type,
+ backup_method=backup_method,
entropy_check_count=entropy_check_count,
)
@@ -286,15 +294,17 @@ def setup(
@cli.command()
@click.option("-t", "--group-threshold", type=int)
@click.option("-g", "--group", "groups", type=(int, int), multiple=True, metavar="T N")
+@click.option("-m", "--method", "method", type=ChoiceType(BACKUP_METHOD))
@with_session(seedless=True)
def backup(
session: "Session",
group_threshold: int | None = None,
groups: t.Sequence[tuple[int, int]] = (),
+ method: messages.BackupMethod = messages.BackupMethod.Display,
) -> None:
"""Perform device seed backup."""
- device.backup(session, group_threshold, groups)
+ device.backup(session, group_threshold, groups, method)
@cli.command()
diff --git a/python/src/trezorlib/device.py b/python/src/trezorlib/device.py
index f0a8cf2e..508d1d8a 100644
--- a/python/src/trezorlib/device.py
+++ b/python/src/trezorlib/device.py
@@ -322,6 +322,7 @@ def setup(
skip_backup: bool = False,
no_backup: bool = False,
backup_type: Optional[messages.BackupType] = None,
+ backup_method: Optional[messages.BackupMethod] = None,
entropy_check_count: Optional[int] = None,
paths: Iterable[Address] = [],
_get_entropy: Callable[[], bytes] = _get_external_entropy,
@@ -407,6 +408,7 @@ def setup(
no_backup=bool(no_backup),
backup_type=backup_type,
entropy_check=entropy_check_count > 0,
+ backup_method=backup_method,
)
if entropy_check_count > 0:
xpubs = _reset_with_entropycheck(
@@ -553,6 +555,7 @@ def backup(
session: "Session",
group_threshold: Optional[int] = None,
groups: Iterable[tuple[int, int]] = (),
+ backup_method: Optional[messages.BackupMethod] = None,
) -> None:
session.call(
messages.BackupDevice(
@@ -561,6 +564,7 @@ def backup(
messages.Slip39Group(member_threshold=t, member_count=c)
for t, c in groups
],
+ backup_method=backup_method,
),
expect=messages.Success,
)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.