python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2021-11-26 14:50:43 +00:00
|
|
|
# Copyright (C) 2012-2022 SatoshiLabs and contributors
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
2024-06-19 08:22:46 +00:00
|
|
|
from __future__ import annotations
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
2023-12-08 11:32:23 +00:00
|
|
|
import logging
|
2023-08-24 07:30:40 +00:00
|
|
|
import secrets
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
import sys
|
2024-06-19 08:22:46 +00:00
|
|
|
import typing as t
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
import click
|
2024-06-20 13:26:33 +00:00
|
|
|
import requests
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
from .. import debuglink, device, exceptions, messages, ui
|
2024-11-15 16:31:22 +00:00
|
|
|
from . import ChoiceType, with_management_session
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
2024-06-19 08:22:46 +00:00
|
|
|
if t.TYPE_CHECKING:
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
from ..protobuf import MessageType
|
2024-11-15 16:31:22 +00:00
|
|
|
from ..transport.session import Session
|
2024-11-19 16:50:17 +00:00
|
|
|
from . import TrezorConnection
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
|
2024-05-23 14:09:16 +00:00
|
|
|
RECOVERY_DEVICE_INPUT_METHOD = {
|
|
|
|
"scrambled": messages.RecoveryDeviceInputMethod.ScrambledWords,
|
|
|
|
"matrix": messages.RecoveryDeviceInputMethod.Matrix,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BACKUP_TYPE = {
|
2024-06-05 11:04:33 +00:00
|
|
|
"bip39": messages.BackupType.Bip39,
|
|
|
|
"single": messages.BackupType.Slip39_Single_Extendable,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"shamir": messages.BackupType.Slip39_Basic,
|
|
|
|
"advanced": messages.BackupType.Slip39_Advanced,
|
|
|
|
}
|
|
|
|
|
|
|
|
SD_PROTECT_OPERATIONS = {
|
2022-02-11 13:11:43 +00:00
|
|
|
"on": messages.SdProtectOperationType.ENABLE,
|
|
|
|
"off": messages.SdProtectOperationType.DISABLE,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"refresh": messages.SdProtectOperationType.REFRESH,
|
|
|
|
}
|
|
|
|
|
2023-12-08 11:32:23 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
@click.group(name="device")
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def cli() -> None:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Device management commands - setup, recover seed, wipe, etc."""
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.option(
|
|
|
|
"-b",
|
|
|
|
"--bootloader",
|
|
|
|
help="Wipe device in bootloader mode. This also erases the firmware.",
|
|
|
|
is_flag=True,
|
|
|
|
)
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
|
|
|
def wipe(session: "Session", bootloader: bool) -> str:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Reset device to factory defaults and remove all private data."""
|
2024-11-15 16:31:22 +00:00
|
|
|
features = session.features
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
if bootloader:
|
2024-11-15 16:31:22 +00:00
|
|
|
if not features.bootloader_mode:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
click.echo("Please switch your device to bootloader mode.")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
click.echo("Wiping user data and firmware!")
|
|
|
|
else:
|
2024-11-15 16:31:22 +00:00
|
|
|
if features.bootloader_mode:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
click.echo(
|
|
|
|
"Your device is in bootloader mode. This operation would also erase firmware."
|
|
|
|
)
|
|
|
|
click.echo(
|
|
|
|
'Specify "--bootloader" if that is what you want, or disconnect and reconnect device in normal mode.'
|
|
|
|
)
|
|
|
|
click.echo("Aborting.")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
click.echo("Wiping user data!")
|
|
|
|
|
|
|
|
try:
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.wipe(
|
|
|
|
session
|
|
|
|
) # TODO decide where the wipe should happen - management or regular session
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
except exceptions.TrezorFailure as e:
|
|
|
|
click.echo("Action failed: {} {}".format(*e.args))
|
|
|
|
sys.exit(3)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.option("-m", "--mnemonic", multiple=True)
|
|
|
|
@click.option("-p", "--pin", default="")
|
|
|
|
@click.option("-r", "--passphrase-protection", is_flag=True)
|
|
|
|
@click.option("-l", "--label", default="")
|
|
|
|
@click.option("-i", "--ignore-checksum", is_flag=True)
|
|
|
|
@click.option("-s", "--slip0014", is_flag=True)
|
2024-10-29 14:16:28 +00:00
|
|
|
@click.option("-a", "--academic", is_flag=True)
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
@click.option("-b", "--needs-backup", is_flag=True)
|
|
|
|
@click.option("-n", "--no-backup", is_flag=True)
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
def load(
|
2024-11-15 16:31:22 +00:00
|
|
|
session: "Session",
|
2024-06-19 08:22:46 +00:00
|
|
|
mnemonic: t.Sequence[str],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
pin: str,
|
|
|
|
passphrase_protection: bool,
|
|
|
|
label: str,
|
|
|
|
ignore_checksum: bool,
|
|
|
|
slip0014: bool,
|
2024-10-29 14:16:28 +00:00
|
|
|
academic: bool,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
needs_backup: bool,
|
|
|
|
no_backup: bool,
|
|
|
|
) -> str:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Upload seed and custom configuration to the device.
|
|
|
|
|
|
|
|
This functionality is only available in debug mode.
|
|
|
|
"""
|
2024-10-29 14:16:28 +00:00
|
|
|
if sum((slip0014, academic, bool(mnemonic))) > 1:
|
|
|
|
raise click.ClickException("Cannot use the options -a, -m, and -s together.")
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
if slip0014:
|
|
|
|
mnemonic = [" ".join(["all"] * 12)]
|
|
|
|
if not label:
|
|
|
|
label = "SLIP-0014"
|
2024-10-29 14:16:28 +00:00
|
|
|
elif academic:
|
|
|
|
mnemonic = [
|
|
|
|
"academic again academic academic academic academic academic academic academic academic academic academic academic academic academic academic academic pecan provide remember"
|
|
|
|
]
|
|
|
|
if not label:
|
|
|
|
label = "ACADEMIC"
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
2022-06-21 13:40:31 +00:00
|
|
|
try:
|
|
|
|
return debuglink.load_device(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
2022-06-21 13:40:31 +00:00
|
|
|
mnemonic=list(mnemonic),
|
|
|
|
pin=pin,
|
|
|
|
passphrase_protection=passphrase_protection,
|
|
|
|
label=label,
|
|
|
|
skip_checksum=ignore_checksum,
|
|
|
|
needs_backup=needs_backup,
|
|
|
|
no_backup=no_backup,
|
|
|
|
)
|
|
|
|
except exceptions.TrezorFailure as e:
|
|
|
|
if e.code == messages.FailureType.UnexpectedMessage:
|
|
|
|
raise click.ClickException(
|
|
|
|
"Unrecognized message. Make sure your Trezor is using debug firmware."
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
raise
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.option("-w", "--words", type=click.Choice(["12", "18", "24"]), default="24")
|
|
|
|
@click.option("-e", "--expand", is_flag=True)
|
|
|
|
@click.option("-p", "--pin-protection", is_flag=True)
|
|
|
|
@click.option("-r", "--passphrase-protection", is_flag=True)
|
|
|
|
@click.option("-l", "--label")
|
2019-12-29 04:38:25 +00:00
|
|
|
@click.option("-u", "--u2f-counter", default=None, type=int)
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
@click.option(
|
2024-05-23 14:09:16 +00:00
|
|
|
"-i",
|
|
|
|
"--input_method",
|
|
|
|
"-t",
|
|
|
|
"--type",
|
|
|
|
type=ChoiceType(RECOVERY_DEVICE_INPUT_METHOD),
|
|
|
|
default="scrambled",
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
)
|
|
|
|
@click.option("-d", "--dry-run", is_flag=True)
|
2024-04-23 10:26:46 +00:00
|
|
|
@click.option("-b", "--unlock-repeated-backup", is_flag=True)
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
def recover(
|
2024-11-15 16:31:22 +00:00
|
|
|
session: "Session",
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
words: str,
|
|
|
|
expand: bool,
|
|
|
|
pin_protection: bool,
|
|
|
|
passphrase_protection: bool,
|
2024-06-19 08:22:46 +00:00
|
|
|
label: str | None,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
u2f_counter: int,
|
2024-05-23 14:09:16 +00:00
|
|
|
input_method: messages.RecoveryDeviceInputMethod,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
dry_run: bool,
|
2024-04-23 10:26:46 +00:00
|
|
|
unlock_repeated_backup: bool,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> "MessageType":
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Start safe recovery workflow."""
|
2024-05-23 14:09:16 +00:00
|
|
|
if input_method == messages.RecoveryDeviceInputMethod.ScrambledWords:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
input_callback = ui.mnemonic_words(expand)
|
|
|
|
else:
|
|
|
|
input_callback = ui.matrix_words
|
|
|
|
click.echo(ui.RECOVERY_MATRIX_DESCRIPTION)
|
|
|
|
|
2024-04-23 10:26:46 +00:00
|
|
|
if dry_run and unlock_repeated_backup:
|
|
|
|
raise click.ClickException("Cannot use -d and -b together.")
|
|
|
|
|
2024-05-23 14:09:16 +00:00
|
|
|
type = None
|
2024-04-23 10:26:46 +00:00
|
|
|
if dry_run:
|
2024-05-23 14:09:16 +00:00
|
|
|
type = messages.RecoveryType.DryRun
|
2024-04-23 10:26:46 +00:00
|
|
|
if unlock_repeated_backup:
|
2024-05-23 14:09:16 +00:00
|
|
|
type = messages.RecoveryType.UnlockRepeatedBackup
|
2024-04-23 10:26:46 +00:00
|
|
|
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
return device.recover(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
word_count=int(words),
|
|
|
|
passphrase_protection=passphrase_protection,
|
|
|
|
pin_protection=pin_protection,
|
|
|
|
label=label,
|
2019-12-29 04:38:25 +00:00
|
|
|
u2f_counter=u2f_counter,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
input_callback=input_callback,
|
2024-05-23 14:09:16 +00:00
|
|
|
input_method=input_method,
|
|
|
|
type=type,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.option("-t", "--strength", type=click.Choice(["128", "192", "256"]))
|
|
|
|
@click.option("-r", "--passphrase-protection", is_flag=True)
|
|
|
|
@click.option("-p", "--pin-protection", is_flag=True)
|
|
|
|
@click.option("-l", "--label")
|
|
|
|
@click.option("-u", "--u2f-counter", default=0)
|
|
|
|
@click.option("-s", "--skip-backup", is_flag=True)
|
|
|
|
@click.option("-n", "--no-backup", is_flag=True)
|
2024-06-19 08:31:34 +00:00
|
|
|
@click.option("-b", "--backup-type", type=ChoiceType(BACKUP_TYPE))
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
def setup(
|
2024-11-15 16:31:22 +00:00
|
|
|
session: "Session",
|
2024-06-19 08:22:46 +00:00
|
|
|
strength: int | None,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
passphrase_protection: bool,
|
|
|
|
pin_protection: bool,
|
2024-06-19 08:22:46 +00:00
|
|
|
label: str | None,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
u2f_counter: int,
|
|
|
|
skip_backup: bool,
|
|
|
|
no_backup: bool,
|
2024-06-19 08:31:34 +00:00
|
|
|
backup_type: messages.BackupType | None,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> str:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Perform device setup and generate new seed."""
|
|
|
|
if strength:
|
|
|
|
strength = int(strength)
|
|
|
|
|
2024-06-19 08:31:34 +00:00
|
|
|
BT = messages.BackupType
|
|
|
|
|
|
|
|
if backup_type is None:
|
2024-11-15 16:31:22 +00:00
|
|
|
if session.version >= (2, 7, 1):
|
2024-06-19 08:31:34 +00:00
|
|
|
# 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
|
|
|
|
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
if (
|
2024-06-19 08:31:34 +00:00
|
|
|
backup_type
|
|
|
|
in (BT.Slip39_Single_Extendable, BT.Slip39_Basic, BT.Slip39_Basic_Extendable)
|
2024-11-15 16:31:22 +00:00
|
|
|
and messages.Capability.Shamir not in session.features.capabilities
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
) or (
|
2024-06-19 08:31:34 +00:00
|
|
|
backup_type in (BT.Slip39_Advanced, BT.Slip39_Advanced_Extendable)
|
2024-11-15 16:31:22 +00:00
|
|
|
and messages.Capability.ShamirGroups not in session.features.capabilities
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
):
|
|
|
|
click.echo(
|
|
|
|
"WARNING: Your Trezor device does not indicate support for the requested\n"
|
2024-06-19 08:31:34 +00:00
|
|
|
"backup type. Traditional BIP39 backup may be generated instead."
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return device.reset(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
strength=strength,
|
|
|
|
passphrase_protection=passphrase_protection,
|
|
|
|
pin_protection=pin_protection,
|
|
|
|
label=label,
|
|
|
|
u2f_counter=u2f_counter,
|
|
|
|
skip_backup=skip_backup,
|
|
|
|
no_backup=no_backup,
|
|
|
|
backup_type=backup_type,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
2024-04-11 14:21:17 +00:00
|
|
|
@click.option("-t", "--group-threshold", type=int)
|
|
|
|
@click.option("-g", "--group", "groups", type=(int, int), multiple=True, metavar="T N")
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
2024-04-11 14:21:17 +00:00
|
|
|
def backup(
|
2024-11-15 16:31:22 +00:00
|
|
|
session: "Session",
|
2024-06-19 08:22:46 +00:00
|
|
|
group_threshold: int | None = None,
|
|
|
|
groups: t.Sequence[tuple[int, int]] = (),
|
2024-04-11 14:21:17 +00:00
|
|
|
) -> str:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Perform device seed backup."""
|
2024-04-11 14:21:17 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.backup(session, group_threshold, groups)
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.argument("operation", type=ChoiceType(SD_PROTECT_OPERATIONS))
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
|
|
|
def sd_protect(session: "Session", operation: messages.SdProtectOperationType) -> str:
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
"""Secure the device with SD card protection.
|
|
|
|
|
|
|
|
When SD card protection is enabled, a randomly generated secret is stored
|
|
|
|
on the SD card. During every PIN checking and unlocking operation this
|
|
|
|
secret is combined with the entered PIN value to decrypt data stored on
|
|
|
|
the device. The SD card will thus be needed every time you unlock the
|
|
|
|
device. The options are:
|
|
|
|
|
|
|
|
\b
|
2022-02-11 13:11:43 +00:00
|
|
|
on - Generate SD card secret and use it to protect the PIN and storage.
|
|
|
|
off - Remove SD card secret protection.
|
python/trezorctl: split trezorctl into separate modules
Instead of all commands (like `load-device`, `change-pin`,
`tezos-sign-tx`, `ethereum-verify-message`...) living in trezorctl.py,
each functional group is now defined in a separate file.
With that, better structuring of the trezorctl command becomes
available:
- instead of `trezorctl set-label`, use `trezorctl set label`
- instead of `trezorctl change-pin`, use `trezorctl set pin`
- instead of `trezorctl enable-passphrase`, use `trezorctl set
passphrase enabled`
For common commands, such as `sign-tx`, it is possible to use the
currency name or shortcut:
- `trezorctl btc sign-tx`
- `trezorctl ethereum sign-tx`
- `trezorctl xtz sign-tx`
- `trezorctl doge sign-tx`
etc.
Some aliases have been retained for better compatibility. For others,
refer to `trezorctl --help` and `trezorctl <command> --help`.
2019-09-10 13:00:27 +00:00
|
|
|
refresh - Replace the current SD card secret with a new one.
|
|
|
|
"""
|
2024-11-15 16:31:22 +00:00
|
|
|
if session.features.model == "1":
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
raise click.ClickException("Trezor One does not support SD card protection.")
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.sd_protect(session, operation)
|
2021-07-28 14:01:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.pass_obj
|
2024-11-19 16:50:17 +00:00
|
|
|
def reboot_to_bootloader(obj: "TrezorConnection") -> str:
|
2021-07-28 14:01:02 +00:00
|
|
|
"""Reboot device into bootloader mode.
|
|
|
|
|
|
|
|
Currently only supported on Trezor Model One.
|
|
|
|
"""
|
2024-11-15 16:31:22 +00:00
|
|
|
# avoid using @with_management_session because it closes the session afterwards,
|
2021-07-28 14:01:02 +00:00
|
|
|
# which triggers double prompt on device
|
|
|
|
with obj.client_context() as client:
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.reboot_to_bootloader(client.get_management_session())
|
2022-08-09 16:27:21 +00:00
|
|
|
|
|
|
|
|
2023-05-12 09:19:35 +00:00
|
|
|
@cli.command()
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
|
|
|
def tutorial(session: "Session") -> str:
|
2023-05-12 09:19:35 +00:00
|
|
|
"""Show on-device tutorial."""
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.show_device_tutorial(session)
|
2023-05-12 09:19:35 +00:00
|
|
|
|
|
|
|
|
2023-07-20 11:20:50 +00:00
|
|
|
@cli.command()
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
|
|
|
def unlock_bootloader(session: "Session") -> str:
|
2023-07-20 11:20:50 +00:00
|
|
|
"""Unlocks bootloader. Irreversible."""
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.unlock_bootloader(session)
|
2023-07-20 11:20:50 +00:00
|
|
|
|
|
|
|
|
2022-08-09 16:27:21 +00:00
|
|
|
@cli.command()
|
|
|
|
@click.argument("enable", type=ChoiceType({"on": True, "off": False}), required=False)
|
|
|
|
@click.option(
|
|
|
|
"-e",
|
|
|
|
"--expiry",
|
|
|
|
type=int,
|
|
|
|
help="Dialog expiry in seconds.",
|
|
|
|
)
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
|
|
|
def set_busy(session: "Session", enable: bool | None, expiry: int | None) -> str:
|
2022-08-09 16:27:21 +00:00
|
|
|
"""Show a "Do not disconnect" dialog."""
|
|
|
|
if enable is False:
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.set_busy(session, None)
|
2022-08-09 16:27:21 +00:00
|
|
|
|
|
|
|
if expiry is None:
|
|
|
|
raise click.ClickException("Missing option '-e' / '--expiry'.")
|
|
|
|
|
|
|
|
if expiry <= 0:
|
|
|
|
raise click.ClickException(
|
|
|
|
f"Invalid value for '-e' / '--expiry': '{expiry}' is not a positive integer."
|
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
return device.set_busy(session, expiry * 1000)
|
2023-08-24 07:30:40 +00:00
|
|
|
|
|
|
|
|
2024-06-20 13:26:33 +00:00
|
|
|
PUBKEY_WHITELIST_URL_TEMPLATE = (
|
|
|
|
"https://data.trezor.io/firmware/{model}/authenticity.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-08-24 07:30:40 +00:00
|
|
|
@cli.command()
|
|
|
|
@click.argument("hex_challenge", required=False)
|
2023-12-08 11:32:23 +00:00
|
|
|
@click.option("-R", "--root", type=click.File("rb"), help="Custom root certificate.")
|
|
|
|
@click.option(
|
|
|
|
"-r", "--raw", is_flag=True, help="Print raw cryptographic data and exit."
|
|
|
|
)
|
|
|
|
@click.option(
|
|
|
|
"-s",
|
|
|
|
"--skip-whitelist",
|
|
|
|
is_flag=True,
|
|
|
|
help="Do not check intermediate certificates against the whitelist.",
|
|
|
|
)
|
2024-11-15 16:31:22 +00:00
|
|
|
@with_management_session
|
2023-12-08 11:32:23 +00:00
|
|
|
def authenticate(
|
2024-11-15 16:31:22 +00:00
|
|
|
session: "Session",
|
2024-06-19 08:22:46 +00:00
|
|
|
hex_challenge: str | None,
|
|
|
|
root: t.BinaryIO | None,
|
|
|
|
raw: bool | None,
|
|
|
|
skip_whitelist: bool | None,
|
2023-12-08 11:32:23 +00:00
|
|
|
) -> None:
|
|
|
|
"""Verify the authenticity of the device.
|
|
|
|
|
|
|
|
Use the --raw option to get the raw challenge, signature, and certificate data.
|
|
|
|
|
|
|
|
Otherwise, trezorctl will attempt to decode the signatures and check their
|
2024-06-20 13:26:33 +00:00
|
|
|
authenticity. By default, it will also check the public keys against a whitelist
|
|
|
|
downloaded from Trezor servers. You can skip this check with the --skip-whitelist
|
|
|
|
option.
|
2023-12-08 11:32:23 +00:00
|
|
|
|
|
|
|
\b
|
|
|
|
When not using --raw, 'cryptography' library is required. You can install it via:
|
|
|
|
pip3 install trezor[authentication]
|
|
|
|
"""
|
2023-08-24 07:30:40 +00:00
|
|
|
if hex_challenge is None:
|
|
|
|
hex_challenge = secrets.token_hex(32)
|
2023-12-08 11:32:23 +00:00
|
|
|
|
2023-08-24 07:30:40 +00:00
|
|
|
challenge = bytes.fromhex(hex_challenge)
|
2023-12-08 11:32:23 +00:00
|
|
|
|
|
|
|
if raw:
|
2024-11-15 16:31:22 +00:00
|
|
|
msg = device.authenticate(session, challenge)
|
2023-12-08 11:32:23 +00:00
|
|
|
|
|
|
|
click.echo(f"Challenge: {hex_challenge}")
|
|
|
|
click.echo(f"Signature of challenge: {msg.signature.hex()}")
|
|
|
|
click.echo(f"Device certificate: {msg.certificates[0].hex()}")
|
|
|
|
for cert in msg.certificates[1:]:
|
|
|
|
click.echo(f"CA certificate: {cert.hex()}")
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
from .. import authentication
|
|
|
|
except ImportError as e:
|
|
|
|
click.echo("Failed to import the authentication module.")
|
|
|
|
click.echo(f"Error: {e}")
|
|
|
|
click.echo("Make sure you have the required dependencies:")
|
|
|
|
click.echo(" pip3 install trezor[authentication]")
|
|
|
|
sys.exit(4)
|
|
|
|
|
|
|
|
if root is not None:
|
|
|
|
root_bytes = root.read()
|
|
|
|
else:
|
|
|
|
root_bytes = None
|
|
|
|
|
|
|
|
class ColoredFormatter(logging.Formatter):
|
|
|
|
LEVELS = {
|
|
|
|
logging.ERROR: click.style("ERROR", fg="red"),
|
|
|
|
logging.WARNING: click.style("WARNING", fg="yellow"),
|
|
|
|
logging.INFO: click.style("INFO", fg="blue"),
|
|
|
|
logging.DEBUG: click.style("OK", fg="green"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def format(self, record: logging.LogRecord) -> str:
|
|
|
|
prefix = self.LEVELS[record.levelno]
|
|
|
|
bold_args = tuple(
|
|
|
|
click.style(str(arg), bold=True) for arg in record.args or ()
|
|
|
|
)
|
|
|
|
return f"[{prefix}] {record.msg}" % bold_args
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(ColoredFormatter())
|
|
|
|
authentication.LOG.addHandler(handler)
|
|
|
|
authentication.LOG.setLevel(logging.DEBUG)
|
|
|
|
|
2024-06-20 13:26:33 +00:00
|
|
|
if skip_whitelist:
|
|
|
|
whitelist = None
|
|
|
|
else:
|
|
|
|
whitelist_json = requests.get(
|
|
|
|
PUBKEY_WHITELIST_URL_TEMPLATE.format(
|
2024-11-15 16:31:22 +00:00
|
|
|
model=session.model.internal_name.lower()
|
2024-06-20 13:26:33 +00:00
|
|
|
)
|
|
|
|
).json()
|
|
|
|
whitelist = [bytes.fromhex(pk) for pk in whitelist_json["ca_pubkeys"]]
|
|
|
|
|
2023-12-08 11:32:23 +00:00
|
|
|
try:
|
2024-06-20 13:26:33 +00:00
|
|
|
authentication.authenticate_device(
|
2024-11-15 16:31:22 +00:00
|
|
|
session, challenge, root_pubkey=root_bytes, whitelist=whitelist
|
2024-06-20 13:26:33 +00:00
|
|
|
)
|
2023-12-08 11:32:23 +00:00
|
|
|
except authentication.DeviceNotAuthentic:
|
|
|
|
click.echo("Device is not authentic.")
|
|
|
|
sys.exit(5)
|