mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 20:08:12 +00:00
chore(trezorlib): Support payment requests and GetNonce command.
This commit is contained in:
parent
0e58218f5f
commit
f6154b311e
1
python/.changelog.d/1430.added
Normal file
1
python/.changelog.d/1430.added
Normal file
@ -0,0 +1 @@
|
|||||||
|
Support payment requests and GetNonce command.
|
@ -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,34 +355,40 @@ def sign_tx(
|
|||||||
else:
|
else:
|
||||||
current_tx = this_tx
|
current_tx = this_tx
|
||||||
|
|
||||||
msg = messages.TransactionType()
|
if res.request_type == R.TXPAYMENTREQ:
|
||||||
|
|
||||||
if res.request_type == R.TXMETA:
|
|
||||||
msg = copy_tx_meta(current_tx)
|
|
||||||
elif res.request_type in (R.TXINPUT, R.TXORIGINPUT):
|
|
||||||
assert res.details.request_index is not None
|
assert res.details.request_index is not None
|
||||||
msg.inputs = [current_tx.inputs[res.details.request_index]]
|
msg = payment_reqs[res.details.request_index]
|
||||||
elif res.request_type == R.TXOUTPUT:
|
res = client.call(msg)
|
||||||
assert res.details.request_index is not None
|
|
||||||
if res.details.tx_hash:
|
|
||||||
msg.bin_outputs = [current_tx.bin_outputs[res.details.request_index]]
|
|
||||||
else:
|
|
||||||
msg.outputs = [current_tx.outputs[res.details.request_index]]
|
|
||||||
elif res.request_type == R.TXORIGOUTPUT:
|
|
||||||
assert res.details.request_index is not None
|
|
||||||
msg.outputs = [current_tx.outputs[res.details.request_index]]
|
|
||||||
elif res.request_type == R.TXEXTRADATA:
|
|
||||||
assert res.details.extra_data_offset is not None
|
|
||||||
assert res.details.extra_data_len is not None
|
|
||||||
assert current_tx.extra_data is not None
|
|
||||||
o, l = res.details.extra_data_offset, res.details.extra_data_len
|
|
||||||
msg.extra_data = current_tx.extra_data[o : o + l]
|
|
||||||
else:
|
else:
|
||||||
raise exceptions.TrezorException(
|
msg = messages.TransactionType()
|
||||||
f"Unknown request type - {res.request_type}."
|
if res.request_type == R.TXMETA:
|
||||||
)
|
msg = copy_tx_meta(current_tx)
|
||||||
|
elif res.request_type in (R.TXINPUT, R.TXORIGINPUT):
|
||||||
|
assert res.details.request_index is not None
|
||||||
|
msg.inputs = [current_tx.inputs[res.details.request_index]]
|
||||||
|
elif res.request_type == R.TXOUTPUT:
|
||||||
|
assert res.details.request_index is not None
|
||||||
|
if res.details.tx_hash:
|
||||||
|
msg.bin_outputs = [
|
||||||
|
current_tx.bin_outputs[res.details.request_index]
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
msg.outputs = [current_tx.outputs[res.details.request_index]]
|
||||||
|
elif res.request_type == R.TXORIGOUTPUT:
|
||||||
|
assert res.details.request_index is not None
|
||||||
|
msg.outputs = [current_tx.outputs[res.details.request_index]]
|
||||||
|
elif res.request_type == R.TXEXTRADATA:
|
||||||
|
assert res.details.extra_data_offset is not None
|
||||||
|
assert res.details.extra_data_len is not None
|
||||||
|
assert current_tx.extra_data is not None
|
||||||
|
o, l = res.details.extra_data_offset, res.details.extra_data_len
|
||||||
|
msg.extra_data = current_tx.extra_data[o : o + l]
|
||||||
|
else:
|
||||||
|
raise exceptions.TrezorException(
|
||||||
|
f"Unknown request type - {res.request_type}."
|
||||||
|
)
|
||||||
|
|
||||||
res = client.call(messages.TxAck(tx=msg))
|
res = client.call(messages.TxAck(tx=msg))
|
||||||
|
|
||||||
if not isinstance(res, messages.TxRequest):
|
if not isinstance(res, messages.TxRequest):
|
||||||
raise exceptions.TrezorException("Unexpected message")
|
raise exceptions.TrezorException("Unexpected message")
|
||||||
|
@ -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())
|
||||||
|
Loading…
Reference in New Issue
Block a user