-
-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trezorlib API improvements #4490
base: main
Are you sure you want to change the base?
Conversation
|
6450448
to
de9174a
Compare
[no changelog]
it's a Python class that emits a DeprecationWarning if you try to use it for almost anything (two exceptions that can't be overriden from the wrapper: * isinstance(depr, SomeOtherClass) * depr is None) we will return instances of this class to indicate that a return value of something will be going away
this deprecates `device.reset()`, and moves the new arguments to `device.setup()`. Also it changes default backup type on core devices to SLIP39-single, same as Suite, and randomizes the number of entropy check rounds, if not provided from outside.
de9174a
to
f787013
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, added some questions and suggestions:
else: | ||
# - for other types (we assume it's MessageType so a user-defined class) | ||
# assign __class__ directly | ||
elif isinstance(value, MessageType): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from .protobuf import MessageType
should be moved outside of if TYPE_CHECKING:
, right?
https://github.com/trezor/trezor-firmware/actions/runs/12768808281/job/35590249650?pr=4490#step:6:473
trezor-firmware/python/src/trezorlib/tools.py
Lines 43 to 52 in f99c9f4
if TYPE_CHECKING: | |
# Needed to enforce a return value from decorators | |
# More details: https://www.python.org/dev/peps/pep-0612/ | |
from typing import TypeVar | |
from typing_extensions import Concatenate, ParamSpec | |
from . import client | |
from .messages import Success | |
from .protobuf import MessageType |
fixes #4464
the following have been implemented in trezorlib:
UnexpectedMessageError
to raise when Trezor sends a, well, unexpected messageclient.call(msg, expect=SomeType)
will raiseUnexpectedMessageError
wheneverexpect
is not met, analogous tocontext.call()
in core@expect
decorator, so that has been deprecated & all usages removed from trezorlibtrezorlib.device
, which were returning the string fromSuccess(message="...")
have been changed to returnstr | None
, and emit a deprecation warning when someone so much as peeks at the resulting str. We'll change them to-> None
in v0.14 or maybe v0.15.trezorlib.device.recover
was returning aSuccess
instance!! 🙄 got the same treatment, still returns an object that kind of looks like aSuccess
but emits deprecation warnings if you touch it.required
device.reset
to a deprecated kind-of-like-an-alias to newly introduceddevice.setup
.reset
andreset_entropy_check
: the entropy check is an integral part ofdevice.setup
, and by default the function will pick a random number of entropy check roundsdevice.setup
accepts a private argument_get_entropy()
which makes it easier to supply external entropy when needed (such as in tests)expected_responses
for the entropy check flow