mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-06 17:09:11 +00:00
feat(core): Implement payment requests in Ripple signing.
This commit is contained in:
parent
a46dc2f91a
commit
a94d2bd1f9
@ -9,7 +9,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
# NOTE: it is one big function because that way it is the most flash-space-efficient
|
# 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:
|
async def sign_tx(msg: RippleSignTx, keychain: Keychain) -> RippleSignedTx:
|
||||||
from trezor.crypto import der
|
from trezor.crypto import der
|
||||||
from trezor.crypto.curve import secp256k1
|
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 apps.common import paths
|
||||||
|
|
||||||
from . import helpers, layout
|
from . import SLIP44_ID, helpers, layout
|
||||||
from .serialize import serialize
|
from .serialize import serialize
|
||||||
|
|
||||||
payment = msg.payment # local_cache_attribute
|
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:
|
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")
|
raise ProcessError("Fee must be in the range of 10 to 10,000 drops")
|
||||||
|
|
||||||
if payment.destination_tag is not None:
|
if msg.payment_req:
|
||||||
await layout.require_confirm_destination_tag(payment.destination_tag)
|
from apps.common.payment_request import PaymentRequestVerifier
|
||||||
await layout.require_confirm_tx(
|
|
||||||
payment.destination, payment.amount, chunkify=bool(msg.chunkify)
|
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)
|
await layout.require_confirm_total(payment.amount + msg.fee, msg.fee)
|
||||||
|
|
||||||
# Signs and encodes signature into DER format
|
# Signs and encodes signature into DER format
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# 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>.
|
# 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 . import messages
|
||||||
from .protobuf import dict_to_proto
|
from .protobuf import dict_to_proto
|
||||||
@ -51,9 +51,11 @@ def sign_tx(
|
|||||||
address_n: "Address",
|
address_n: "Address",
|
||||||
msg: messages.RippleSignTx,
|
msg: messages.RippleSignTx,
|
||||||
chunkify: bool = False,
|
chunkify: bool = False,
|
||||||
|
payment_req: Optional[messages.PaymentRequest] = None,
|
||||||
) -> messages.RippleSignedTx:
|
) -> messages.RippleSignedTx:
|
||||||
msg.address_n = address_n
|
msg.address_n = address_n
|
||||||
msg.chunkify = chunkify
|
msg.chunkify = chunkify
|
||||||
|
msg.payment_req = payment_req
|
||||||
return client.call(msg, expect=messages.RippleSignedTx)
|
return client.call(msg, expect=messages.RippleSignedTx)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user