1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

python: Support preauthorized operations in trezorlib.

This commit is contained in:
Andrew Kozlik 2020-07-16 19:17:43 +02:00 committed by Andrew Kozlik
parent 84c1324290
commit 85cf79169c

View File

@ -118,7 +118,13 @@ def get_ownership_proof(
user_confirmation=False, user_confirmation=False,
ownership_ids=None, ownership_ids=None,
commitment_data=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( res = client.call(
messages.GetOwnershipProof( messages.GetOwnershipProof(
address_n=n, address_n=n,
@ -130,6 +136,7 @@ def get_ownership_proof(
commitment_data=commitment_data, commitment_data=commitment_data,
) )
) )
if not isinstance(res, messages.OwnershipProof): if not isinstance(res, messages.OwnershipProof):
raise exceptions.TrezorException("Unexpected message") raise exceptions.TrezorException("Unexpected message")
@ -165,7 +172,15 @@ def verify_message(client, coin_name, address, signature, message):
@session @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) this_tx = messages.TransactionType(inputs=inputs, outputs=outputs)
if details is None: 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.inputs_count = len(inputs)
signtx.outputs_count = len(outputs) 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) res = client.call(signtx)
# Prepare structure for signatures # Prepare structure for signatures