From 85cf79169ce94d27ee98b7ee88ba95f879acc728 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 16 Jul 2020 19:17:43 +0200 Subject: [PATCH] python: Support preauthorized operations in trezorlib. --- python/src/trezorlib/btc.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 149da9c43..6ccf5b0e2 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -118,7 +118,13 @@ def get_ownership_proof( user_confirmation=False, ownership_ids=None, commitment_data=None, + preauthorized=False, ): + if preauthorized: + res = client.call(messages.DoPreauthorized()) + if not isinstance(res, messages.PreauthorizedRequest): + raise exceptions.TrezorException("Unexpected message") + res = client.call( messages.GetOwnershipProof( address_n=n, @@ -130,6 +136,7 @@ def get_ownership_proof( commitment_data=commitment_data, ) ) + if not isinstance(res, messages.OwnershipProof): raise exceptions.TrezorException("Unexpected message") @@ -165,7 +172,15 @@ def verify_message(client, coin_name, address, signature, message): @session -def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None): +def sign_tx( + client, + coin_name, + inputs, + outputs, + details=None, + prev_txes=None, + preauthorized=False, +): this_tx = messages.TransactionType(inputs=inputs, outputs=outputs) if details is None: @@ -177,6 +192,11 @@ def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None): signtx.inputs_count = len(inputs) signtx.outputs_count = len(outputs) + if preauthorized: + res = client.call(messages.DoPreauthorized()) + if not isinstance(res, messages.PreauthorizedRequest): + raise exceptions.TrezorException("Unexpected message") + res = client.call(signtx) # Prepare structure for signatures