mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-15 12:38:46 +00:00
feat(python): Support UnlockPath in trezorlib.
This commit is contained in:
parent
77be3653b4
commit
a394ac5bb4
1
python/.changelog.d/2289.added
Normal file
1
python/.changelog.d/2289.added
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add UnlockPath message.
|
@ -114,7 +114,21 @@ def get_public_node(
|
|||||||
coin_name: Optional[str] = None,
|
coin_name: Optional[str] = None,
|
||||||
script_type: messages.InputScriptType = messages.InputScriptType.SPENDADDRESS,
|
script_type: messages.InputScriptType = messages.InputScriptType.SPENDADDRESS,
|
||||||
ignore_xpub_magic: bool = False,
|
ignore_xpub_magic: bool = False,
|
||||||
|
preauthorized: bool = False,
|
||||||
|
unlock_path: Optional[List[int]] = None,
|
||||||
|
unlock_path_mac: Optional[bytes] = None,
|
||||||
) -> "MessageType":
|
) -> "MessageType":
|
||||||
|
if unlock_path:
|
||||||
|
res = client.call(
|
||||||
|
messages.UnlockPath(address_n=unlock_path, mac=unlock_path_mac)
|
||||||
|
)
|
||||||
|
if not isinstance(res, messages.UnlockedPathRequest):
|
||||||
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
elif preauthorized:
|
||||||
|
res = client.call(messages.DoPreauthorized())
|
||||||
|
if not isinstance(res, messages.PreauthorizedRequest):
|
||||||
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
|
||||||
return client.call(
|
return client.call(
|
||||||
messages.GetPublicKey(
|
messages.GetPublicKey(
|
||||||
address_n=n,
|
address_n=n,
|
||||||
@ -141,7 +155,21 @@ def get_authenticated_address(
|
|||||||
multisig: Optional[messages.MultisigRedeemScriptType] = None,
|
multisig: Optional[messages.MultisigRedeemScriptType] = None,
|
||||||
script_type: messages.InputScriptType = messages.InputScriptType.SPENDADDRESS,
|
script_type: messages.InputScriptType = messages.InputScriptType.SPENDADDRESS,
|
||||||
ignore_xpub_magic: bool = False,
|
ignore_xpub_magic: bool = False,
|
||||||
|
preauthorized: bool = False,
|
||||||
|
unlock_path: Optional[List[int]] = None,
|
||||||
|
unlock_path_mac: Optional[bytes] = None,
|
||||||
) -> "MessageType":
|
) -> "MessageType":
|
||||||
|
if unlock_path:
|
||||||
|
res = client.call(
|
||||||
|
messages.UnlockPath(address_n=unlock_path, mac=unlock_path_mac)
|
||||||
|
)
|
||||||
|
if not isinstance(res, messages.UnlockedPathRequest):
|
||||||
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
elif preauthorized:
|
||||||
|
res = client.call(messages.DoPreauthorized())
|
||||||
|
if not isinstance(res, messages.PreauthorizedRequest):
|
||||||
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
|
||||||
return client.call(
|
return client.call(
|
||||||
messages.GetAddress(
|
messages.GetAddress(
|
||||||
address_n=n,
|
address_n=n,
|
||||||
@ -257,6 +285,8 @@ def sign_tx(
|
|||||||
prev_txes: Optional["TxCacheType"] = None,
|
prev_txes: Optional["TxCacheType"] = None,
|
||||||
payment_reqs: Sequence[messages.TxAckPaymentRequest] = (),
|
payment_reqs: Sequence[messages.TxAckPaymentRequest] = (),
|
||||||
preauthorized: bool = False,
|
preauthorized: bool = False,
|
||||||
|
unlock_path: Optional[List[int]] = None,
|
||||||
|
unlock_path_mac: Optional[bytes] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Tuple[Sequence[Optional[bytes]], bytes]:
|
) -> Tuple[Sequence[Optional[bytes]], bytes]:
|
||||||
"""Sign a Bitcoin-like transaction.
|
"""Sign a Bitcoin-like transaction.
|
||||||
@ -294,7 +324,13 @@ def sign_tx(
|
|||||||
if hasattr(signtx, name):
|
if hasattr(signtx, name):
|
||||||
setattr(signtx, name, value)
|
setattr(signtx, name, value)
|
||||||
|
|
||||||
if preauthorized:
|
if unlock_path:
|
||||||
|
res = client.call(
|
||||||
|
messages.UnlockPath(address_n=unlock_path, mac=unlock_path_mac)
|
||||||
|
)
|
||||||
|
if not isinstance(res, messages.UnlockedPathRequest):
|
||||||
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
elif preauthorized:
|
||||||
res = client.call(messages.DoPreauthorized())
|
res = client.call(messages.DoPreauthorized())
|
||||||
if not isinstance(res, messages.PreauthorizedRequest):
|
if not isinstance(res, messages.PreauthorizedRequest):
|
||||||
raise exceptions.TrezorException("Unexpected message")
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
@ -19,8 +19,8 @@ import time
|
|||||||
from typing import TYPE_CHECKING, Callable, Optional
|
from typing import TYPE_CHECKING, Callable, Optional
|
||||||
|
|
||||||
from . import messages
|
from . import messages
|
||||||
from .exceptions import Cancelled
|
from .exceptions import Cancelled, TrezorException
|
||||||
from .tools import expect, session
|
from .tools import Address, expect, session
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
@ -220,6 +220,19 @@ def cancel_authorization(client: "TrezorClient") -> "MessageType":
|
|||||||
return client.call(messages.CancelAuthorization())
|
return client.call(messages.CancelAuthorization())
|
||||||
|
|
||||||
|
|
||||||
|
@expect(messages.UnlockedPathRequest, field="mac", ret_type=bytes)
|
||||||
|
def unlock_path(client: "TrezorClient", n: "Address") -> "MessageType":
|
||||||
|
resp = client.call(messages.UnlockPath(address_n=n))
|
||||||
|
|
||||||
|
# Cancel the UnlockPath workflow now that we have the authentication code.
|
||||||
|
try:
|
||||||
|
client.call(messages.Cancel())
|
||||||
|
except Cancelled:
|
||||||
|
return resp
|
||||||
|
else:
|
||||||
|
raise TrezorException("Unexpected response in UnlockPath flow")
|
||||||
|
|
||||||
|
|
||||||
@session
|
@session
|
||||||
@expect(messages.Success, field="message", ret_type=str)
|
@expect(messages.Success, field="message", ret_type=str)
|
||||||
def reboot_to_bootloader(client: "TrezorClient") -> "MessageType":
|
def reboot_to_bootloader(client: "TrezorClient") -> "MessageType":
|
||||||
|
Loading…
Reference in New Issue
Block a user