1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

chore(trezorlib): Support payment requests and GetNonce command.

This commit is contained in:
Andrew Kozlik 2021-01-20 16:22:07 +01:00 committed by Andrew Kozlik
parent 0e58218f5f
commit f6154b311e
3 changed files with 38 additions and 25 deletions

View File

@ -0,0 +1 @@
Support payment requests and GetNonce command.

View File

@ -255,6 +255,7 @@ def sign_tx(
outputs: Sequence[messages.TxOutputType], outputs: Sequence[messages.TxOutputType],
details: Optional[messages.SignTx] = None, details: Optional[messages.SignTx] = None,
prev_txes: Optional["TxCacheType"] = None, prev_txes: Optional["TxCacheType"] = None,
payment_reqs: Sequence[messages.TxAckPaymentRequest] = (),
preauthorized: bool = False, preauthorized: bool = False,
**kwargs: Any, **kwargs: Any,
) -> Tuple[Sequence[Optional[bytes]], bytes]: ) -> Tuple[Sequence[Optional[bytes]], bytes]:
@ -354,8 +355,12 @@ def sign_tx(
else: else:
current_tx = this_tx current_tx = this_tx
if res.request_type == R.TXPAYMENTREQ:
assert res.details.request_index is not None
msg = payment_reqs[res.details.request_index]
res = client.call(msg)
else:
msg = messages.TransactionType() msg = messages.TransactionType()
if res.request_type == R.TXMETA: if res.request_type == R.TXMETA:
msg = copy_tx_meta(current_tx) msg = copy_tx_meta(current_tx)
elif res.request_type in (R.TXINPUT, R.TXORIGINPUT): elif res.request_type in (R.TXINPUT, R.TXORIGINPUT):
@ -364,7 +369,9 @@ def sign_tx(
elif res.request_type == R.TXOUTPUT: elif res.request_type == R.TXOUTPUT:
assert res.details.request_index is not None assert res.details.request_index is not None
if res.details.tx_hash: if res.details.tx_hash:
msg.bin_outputs = [current_tx.bin_outputs[res.details.request_index]] msg.bin_outputs = [
current_tx.bin_outputs[res.details.request_index]
]
else: else:
msg.outputs = [current_tx.outputs[res.details.request_index]] msg.outputs = [current_tx.outputs[res.details.request_index]]
elif res.request_type == R.TXORIGOUTPUT: elif res.request_type == R.TXORIGOUTPUT:

View File

@ -108,3 +108,8 @@ def decrypt_keyvalue(
iv=iv, iv=iv,
) )
) )
@expect(messages.Nonce, field="nonce", ret_type=bytes)
def get_nonce(client: "TrezorClient"):
return client.call(messages.GetNonce())