diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py index 0205c624062..6858c2cb59c 100644 --- a/core/src/apps/cardano/layout.py +++ b/core/src/apps/cardano/layout.py @@ -5,6 +5,7 @@ ButtonRequestType, CardanoAddressType, CardanoCertificateType, + CardanoDRepType, CardanoNativeScriptType, ) from trezor.strings import format_amount @@ -559,6 +560,10 @@ async def confirm_certificate( assert certificate.deposit is not None # validate_certificate props.append(("Deposit:", format_coin_amount(certificate.deposit, network_id))) + elif certificate.type == CardanoCertificateType.VOTE_DELEGATION: + assert certificate.drep is not None # validate_certificate + props.append(_format_drep(certificate.drep)) + await confirm_properties( "confirm_certificate", "Confirm transaction", @@ -734,6 +739,28 @@ def _format_stake_credential( raise ValueError +def _format_drep(drep: messages.CardanoDRep) -> tuple[str, str]: + if drep.type == CardanoDRepType.KEY_HASH: + assert drep.key_hash is not None # validate_drep + return ( + "Delegating to key hash:", + bech32.encode(bech32.HRP_KEY_HASH, drep.key_hash), + ) + elif drep.type == CardanoDRepType.SCRIPT_HASH: + assert drep.script_hash is not None # validate_drep + return ( + "Delegating to script:", + bech32.encode(bech32.HRP_SCRIPT_HASH, drep.script_hash), + ) + elif drep.type == CardanoDRepType.ABSTAIN: + return ("Delegating to:", "Abstain") + elif drep.type == CardanoDRepType.NO_CONFIDENCE: + return ("Delegating to:", "No Confidence") + else: + # should be unreachable unless there's a bug in validation + raise ValueError + + async def confirm_cvote_registration_delegation( public_key: str, weight: int,