1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-20 00:59:02 +00:00

feat(core): Implement payment requests in Ripple signing.

This commit is contained in:
Andrew Kozlik 2025-04-18 16:39:50 +02:00
parent 9d3337de0d
commit 5b1aadaeca
2 changed files with 23 additions and 8 deletions

View File

@ -9,7 +9,7 @@ if TYPE_CHECKING:
# NOTE: it is one big function because that way it is the most flash-space-efficient
@auto_keychain(__name__)
@auto_keychain(__name__, slip21_namespaces=[[b"SLIP-0024"]])
async def sign_tx(msg: RippleSignTx, keychain: Keychain) -> RippleSignedTx:
from trezor.crypto import der
from trezor.crypto.curve import secp256k1
@ -19,7 +19,7 @@ async def sign_tx(msg: RippleSignTx, keychain: Keychain) -> RippleSignedTx:
from apps.common import paths
from . import helpers, layout
from . import SLIP44_ID, helpers, layout
from .serialize import serialize
payment = msg.payment # local_cache_attribute
@ -45,11 +45,24 @@ async def sign_tx(msg: RippleSignTx, keychain: Keychain) -> RippleSignedTx:
if msg.fee < helpers.MIN_FEE or msg.fee > helpers.MAX_FEE:
raise ProcessError("Fee must be in the range of 10 to 10,000 drops")
if payment.destination_tag is not None:
await layout.require_confirm_destination_tag(payment.destination_tag)
await layout.require_confirm_tx(
payment.destination, payment.amount, chunkify=bool(msg.chunkify)
)
if msg.payment_req:
from apps.common.payment_request import PaymentRequestVerifier
verifier = PaymentRequestVerifier(msg.payment_req, SLIP44_ID, keychain)
address = payment.destination
if payment.destination_tag:
address += f"?dt={payment.destination_tag}"
verifier.add_output(payment.amount, address)
verifier.verify()
# TODO Show payment request memos.
await layout.require_confirm_tx(msg.payment_req.recipient_name, payment.amount)
else:
if payment.destination_tag is not None:
await layout.require_confirm_destination_tag(payment.destination_tag)
await layout.require_confirm_tx(
payment.destination, payment.amount, chunkify=bool(msg.chunkify)
)
await layout.require_confirm_total(payment.amount + msg.fee, msg.fee)
# Signs and encodes signature into DER format

View File

@ -14,7 +14,7 @@
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Optional
from . import messages
from .protobuf import dict_to_proto
@ -51,9 +51,11 @@ def sign_tx(
address_n: "Address",
msg: messages.RippleSignTx,
chunkify: bool = False,
payment_req: Optional[messages.PaymentRequest] = None,
) -> messages.RippleSignedTx:
msg.address_n = address_n
msg.chunkify = chunkify
msg.payment_req = payment_req
return client.call(msg, expect=messages.RippleSignedTx)