From 962f689e8a2bbe856f2c45c066f206afd7989333 Mon Sep 17 00:00:00 2001 From: David Misiak Date: Mon, 14 Feb 2022 11:16:31 +0100 Subject: [PATCH] feat(cardano): display tx id for plutus txs --- core/src/apps/cardano/layout.py | 4 ++++ core/src/apps/cardano/sign_tx.py | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py index 2763a0e8c0..b03b93a24b 100644 --- a/core/src/apps/cardano/layout.py +++ b/core/src/apps/cardano/layout.py @@ -445,6 +445,7 @@ async def confirm_transaction( ttl: int | None, validity_interval_start: int | None, is_network_id_verifiable: bool, + tx_hash: bytes | None, ) -> None: props: list[PropertyType] = [ ("Transaction fee:", format_coin_amount(fee)), @@ -456,6 +457,9 @@ async def confirm_transaction( props.append((f"Valid since: {format_optional_int(validity_interval_start)}", None)) props.append((f"TTL: {format_optional_int(ttl)}", None)) + if tx_hash: + props.append(("Transaction ID:", tx_hash)) + await confirm_properties( ctx, "confirm_total", diff --git a/core/src/apps/cardano/sign_tx.py b/core/src/apps/cardano/sign_tx.py index a99674cbe2..9525fa1afe 100644 --- a/core/src/apps/cardano/sign_tx.py +++ b/core/src/apps/cardano/sign_tx.py @@ -189,10 +189,10 @@ async def sign_tx( with tx_dict: await _process_transaction(ctx, msg, keychain, tx_dict, account_path_checker) - await _confirm_transaction(ctx, msg, is_network_id_verifiable) + tx_hash = hash_fn.digest() + await _confirm_transaction(ctx, msg, is_network_id_verifiable, tx_hash) try: - tx_hash = hash_fn.digest() response_after_witness_requests = await _process_witness_requests( ctx, keychain, @@ -362,11 +362,11 @@ async def _confirm_transaction( ctx: wire.Context, msg: CardanoSignTxInit, is_network_id_verifiable: bool, + tx_hash: bytes, ) -> None: if msg.signing_mode in ( CardanoTxSigningMode.ORDINARY_TRANSACTION, CardanoTxSigningMode.MULTISIG_TRANSACTION, - CardanoTxSigningMode.PLUTUS_TRANSACTION, ): await confirm_transaction( ctx, @@ -375,6 +375,20 @@ async def _confirm_transaction( msg.ttl, msg.validity_interval_start, is_network_id_verifiable, + tx_hash=None, + ) + elif msg.signing_mode == CardanoTxSigningMode.PLUTUS_TRANSACTION: + # we display tx hash so that experienced users can compare it to the tx hash computed by + # a trusted device (in case the tx contains many items which are tedious to check one by + # one on the Trezor screen) + await confirm_transaction( + ctx, + msg.fee, + msg.protocol_magic, + msg.ttl, + msg.validity_interval_start, + is_network_id_verifiable, + tx_hash, ) elif msg.signing_mode == CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER: await confirm_stake_pool_registration_final(