diff --git a/core/src/apps/ripple/sign_tx.py b/core/src/apps/ripple/sign_tx.py index c8957bec4d..8d07fa40c3 100644 --- a/core/src/apps/ripple/sign_tx.py +++ b/core/src/apps/ripple/sign_tx.py @@ -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 diff --git a/python/src/trezorlib/ripple.py b/python/src/trezorlib/ripple.py index 7b0d988ca7..80e7be7215 100644 --- a/python/src/trezorlib/ripple.py +++ b/python/src/trezorlib/ripple.py @@ -14,7 +14,7 @@ # You should have received a copy of the License along with this library. # If not, see . -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)