1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-28 10:52:32 +00:00

chore(cardano): replace governance by cvote

This commit is contained in:
David Misiak 2023-02-13 17:05:20 +01:00 committed by matejcik
parent 764e3c8d75
commit 2011ffe9c9
19 changed files with 198 additions and 201 deletions

View File

@ -66,10 +66,10 @@ enum CardanoPoolRelayType {
enum CardanoTxAuxiliaryDataSupplementType { enum CardanoTxAuxiliaryDataSupplementType {
NONE = 0; NONE = 0;
GOVERNANCE_REGISTRATION_SIGNATURE = 1; CVOTE_REGISTRATION_SIGNATURE = 1;
} }
enum CardanoGovernanceRegistrationFormat { enum CardanoCVoteRegistrationFormat {
CIP15 = 0; CIP15 = 0;
CIP36 = 1; CIP36 = 1;
} }
@ -360,7 +360,7 @@ message CardanoTxWithdrawal {
/** /**
* @embed * @embed
*/ */
message CardanoGovernanceRegistrationDelegation { message CardanoCVoteRegistrationDelegation {
required bytes voting_public_key = 1; required bytes voting_public_key = 1;
required uint32 weight = 2; required uint32 weight = 2;
} }
@ -368,13 +368,13 @@ message CardanoGovernanceRegistrationDelegation {
/** /**
* @embed * @embed
*/ */
message CardanoGovernanceRegistrationParametersType { message CardanoCVoteRegistrationParametersType {
optional bytes voting_public_key = 1; // mutually exclusive with delegations optional bytes voting_public_key = 1; // mutually exclusive with delegations
repeated uint32 staking_path = 2; repeated uint32 staking_path = 2;
optional CardanoAddressParametersType reward_address_parameters = 3; // mutually exclusive with reward_address optional CardanoAddressParametersType reward_address_parameters = 3; // mutually exclusive with reward_address
required uint64 nonce = 4; required uint64 nonce = 4;
optional CardanoGovernanceRegistrationFormat format = 5 [default=CIP15]; optional CardanoCVoteRegistrationFormat format = 5 [default=CIP15];
repeated CardanoGovernanceRegistrationDelegation delegations = 6; // mutually exclusive with voting_public_key; max 32 delegations repeated CardanoCVoteRegistrationDelegation delegations = 6; // mutually exclusive with voting_public_key; max 32 delegations
optional uint64 voting_purpose = 7; optional uint64 voting_purpose = 7;
optional string reward_address = 8; // mutually exclusive with reward_address_parameters optional string reward_address = 8; // mutually exclusive with reward_address_parameters
} }
@ -385,7 +385,7 @@ message CardanoGovernanceRegistrationParametersType {
* @next CardanoTxAuxiliaryDataSupplement * @next CardanoTxAuxiliaryDataSupplement
*/ */
message CardanoTxAuxiliaryData { message CardanoTxAuxiliaryData {
optional CardanoGovernanceRegistrationParametersType governance_registration_parameters = 1; optional CardanoCVoteRegistrationParametersType cvote_registration_parameters = 1;
optional bytes hash = 2; optional bytes hash = 2;
} }
@ -453,7 +453,7 @@ message CardanoTxItemAck {
message CardanoTxAuxiliaryDataSupplement { message CardanoTxAuxiliaryDataSupplement {
required CardanoTxAuxiliaryDataSupplementType type = 1; required CardanoTxAuxiliaryDataSupplementType type = 1;
optional bytes auxiliary_data_hash = 2; optional bytes auxiliary_data_hash = 2;
optional bytes governance_signature = 3; optional bytes cvote_registration_signature = 3;
} }
/** /**

View File

@ -1299,7 +1299,7 @@
} }
}, },
{ {
"description": "transaction with governance registration containing byron reward address", "description": "transaction with cvote registration containing byron reward address",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1309,7 +1309,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"voting_public_key": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7", "voting_public_key": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7",
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"nonce": 22634813, "nonce": 22634813,
@ -1348,7 +1348,7 @@
} }
}, },
{ {
"description": "transaction with both auxiliary data blob and governance registration", "description": "transaction with both auxiliary data blob and cvote registration",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1359,7 +1359,7 @@
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"hash": "ea4c91860dd5ec5449f8f985d227946ff39086b17f10b5afb93d12ee87050b6a", "hash": "ea4c91860dd5ec5449f8f985d227946ff39086b17f10b5afb93d12ee87050b6a",
"governance_registration_parameters": { "cvote_registration_parameters": {
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0", "voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
@ -1399,7 +1399,7 @@
} }
}, },
{ {
"description": "transaction with both voting public key and delegations in governance registration", "description": "transaction with both voting public key and delegations in cvote registration",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1409,7 +1409,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0", "voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {

View File

@ -1002,7 +1002,7 @@
} }
}, },
{ {
"description": "transaction with CIP15 governance registration", "description": "transaction with CIP15 registration",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1012,7 +1012,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", "voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
@ -1060,12 +1060,12 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "a943e9166f1bb6d767b175384d3bd7d23645170df36fc1861fbf344135d8e120", "auxiliary_data_hash": "a943e9166f1bb6d767b175384d3bd7d23645170df36fc1861fbf344135d8e120",
"governance_signature": "74f27d877bbb4a5fc4f7c56869905c11f70bad0af3de24b23afaa1d024e750930f434ecc4b73e5d1723c2cb8548e8bf6098ac876487b3a6ed0891cb76994d409" "cvote_registration_signature": "74f27d877bbb4a5fc4f7c56869905c11f70bad0af3de24b23afaa1d024e750930f434ecc4b73e5d1723c2cb8548e8bf6098ac876487b3a6ed0891cb76994d409"
} }
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and voting purpose not specified", "description": "transaction with CIP36 registration and voting purpose not specified",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1075,7 +1075,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
"addressType": 0, "addressType": 0,
@ -1133,12 +1133,12 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "9d4c00f5b5b67760931fd7ed9850ff8e14dcdf957685191ab4bc755c52f0ed56", "auxiliary_data_hash": "9d4c00f5b5b67760931fd7ed9850ff8e14dcdf957685191ab4bc755c52f0ed56",
"governance_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001" "cvote_registration_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001"
} }
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and OTHER voting purpose", "description": "transaction with CIP36 registration and OTHER voting purpose",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1148,7 +1148,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
"addressType": 0, "addressType": 0,
@ -1203,12 +1203,12 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "28b7ffa6800833bdfe5421739eaa21d4a49cde1d84e762b147001169f7c0a385", "auxiliary_data_hash": "28b7ffa6800833bdfe5421739eaa21d4a49cde1d84e762b147001169f7c0a385",
"governance_signature": "ebc00c615f988c6fc2e132d4419a719f04bbec56fe2569a00746a9e9b0d6e5bdd0809515cb2522c773c991c5ae39834403654d36b37e70b14897c0e98c8c0a0c" "cvote_registration_signature": "ebc00c615f988c6fc2e132d4419a719f04bbec56fe2569a00746a9e9b0d6e5bdd0809515cb2522c773c991c5ae39834403654d36b37e70b14897c0e98c8c0a0c"
} }
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and external reward address", "description": "transaction with CIP36 registration and external reward address",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1218,7 +1218,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"nonce": 22634813, "nonce": 22634813,
"format": 1, "format": 1,
@ -1268,12 +1268,12 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "3830a90f2c5dc23ddd478cefcb8642f0b36afa77769239146d9cba83ed196e41", "auxiliary_data_hash": "3830a90f2c5dc23ddd478cefcb8642f0b36afa77769239146d9cba83ed196e41",
"governance_signature": "ba05ac525e5dcc74e5a6cdbb7fb111d8e21163d79fe76777a5b730fe93512f09415f6f7b4904b12c6f12fe33b6c553d9889beb024299fa1256a0d3e98c8ff203" "cvote_registration_signature": "ba05ac525e5dcc74e5a6cdbb7fb111d8e21163d79fe76777a5b730fe93512f09415f6f7b4904b12c6f12fe33b6c553d9889beb024299fa1256a0d3e98c8ff203"
} }
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and non-payment reward address parameters", "description": "transaction with CIP36 registration and non-payment reward address parameters",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1283,7 +1283,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
"addressType": 14, "addressType": 14,
@ -1336,12 +1336,12 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "eb63742c2908aedcc6db3df903377f07302828c0e0eb4a01d38c9049845780c5", "auxiliary_data_hash": "eb63742c2908aedcc6db3df903377f07302828c0e0eb4a01d38c9049845780c5",
"governance_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d" "cvote_registration_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d"
} }
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and non-payment external reward address", "description": "transaction with CIP36 registration and non-payment external reward address",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -1351,7 +1351,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"nonce": 22634813, "nonce": 22634813,
"format": 1, "format": 1,
@ -1401,7 +1401,7 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "eb63742c2908aedcc6db3df903377f07302828c0e0eb4a01d38c9049845780c5", "auxiliary_data_hash": "eb63742c2908aedcc6db3df903377f07302828c0e0eb4a01d38c9049845780c5",
"governance_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d" "cvote_registration_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d"
} }
} }
}, },
@ -1932,7 +1932,7 @@
} }
], ],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
"addressType": 0, "addressType": 0,
@ -1992,7 +1992,7 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "544c9ae849c82e31224865ff936decc6160047409eee4a6b4178b729fe3d286c", "auxiliary_data_hash": "544c9ae849c82e31224865ff936decc6160047409eee4a6b4178b729fe3d286c",
"governance_signature": "3064949c9f186138f95e228075d0119dd5cb50e1b7e75d24d569fa547e018a597615da7c79a39ca8e394ee1ba8acb83e70be80f37e69aef3b86e7c4a6bd44903" "cvote_registration_signature": "3064949c9f186138f95e228075d0119dd5cb50e1b7e75d24d569fa547e018a597615da7c79a39ca8e394ee1ba8acb83e70be80f37e69aef3b86e7c4a6bd44903"
} }
} }
}, },

View File

@ -457,7 +457,7 @@
} }
}, },
{ {
"description": "transaction with CIP36 governance registration and voting purpose not specified", "description": "transaction with CIP36 registration and voting purpose not specified",
"parameters": { "parameters": {
"protocol_magic": 764824073, "protocol_magic": 764824073,
"network_id": 1, "network_id": 1,
@ -467,7 +467,7 @@
"certificates": [], "certificates": [],
"withdrawals": [], "withdrawals": [],
"auxiliary_data": { "auxiliary_data": {
"governance_registration_parameters": { "cvote_registration_parameters": {
"staking_path": "m/1852'/1815'/0'/2/0", "staking_path": "m/1852'/1815'/0'/2/0",
"reward_address_parameters": { "reward_address_parameters": {
"addressType": 0, "addressType": 0,
@ -525,7 +525,7 @@
"auxiliary_data_supplement": { "auxiliary_data_supplement": {
"type": 1, "type": 1,
"auxiliary_data_hash": "9d4c00f5b5b67760931fd7ed9850ff8e14dcdf957685191ab4bc755c52f0ed56", "auxiliary_data_hash": "9d4c00f5b5b67760931fd7ed9850ff8e14dcdf957685191ab4bc755c52f0ed56",
"governance_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001" "cvote_registration_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001"
} }
} }
} }

View File

@ -353,12 +353,12 @@ if not utils.BITCOIN_ONLY:
import trezor.enums.BinanceTimeInForce import trezor.enums.BinanceTimeInForce
trezor.enums.CardanoAddressType trezor.enums.CardanoAddressType
import trezor.enums.CardanoAddressType import trezor.enums.CardanoAddressType
trezor.enums.CardanoCVoteRegistrationFormat
import trezor.enums.CardanoCVoteRegistrationFormat
trezor.enums.CardanoCertificateType trezor.enums.CardanoCertificateType
import trezor.enums.CardanoCertificateType import trezor.enums.CardanoCertificateType
trezor.enums.CardanoDerivationType trezor.enums.CardanoDerivationType
import trezor.enums.CardanoDerivationType import trezor.enums.CardanoDerivationType
trezor.enums.CardanoGovernanceRegistrationFormat
import trezor.enums.CardanoGovernanceRegistrationFormat
trezor.enums.CardanoNativeScriptHashDisplayFormat trezor.enums.CardanoNativeScriptHashDisplayFormat
import trezor.enums.CardanoNativeScriptHashDisplayFormat import trezor.enums.CardanoNativeScriptHashDisplayFormat
trezor.enums.CardanoNativeScriptType trezor.enums.CardanoNativeScriptType

View File

@ -291,9 +291,9 @@ Each transaction may contain auxiliary data. Auxiliary data format can be found
Auxiliary data can be sent to Trezor as a hash or as an object with parameters. The hash will be included in the transaction body as is and will be shown to the user. Auxiliary data can be sent to Trezor as a hash or as an object with parameters. The hash will be included in the transaction body as is and will be shown to the user.
The only object currently supported is governance voting key registration (currently, this is used only by Catalyst, but there may be other governance use cases in the future). To be in compliance with the CDDL and other Cardano tools, governance voting key registration object is being wrapped in a tuple and an empty tuple follows it. The empty tuple represents `auxiliary_scripts` which are not yet supported on Trezor and are thus always empty. Byron addresses are not supported as governance reward addresses. The governance registration signature is returned in the form of `CardanoTxAuxiliaryDataSupplement` which also contains the auxiliary data hash calculated by Trezor. The only object currently supported is CIP-15/CIP-36 vote key registration (currently, this is used only by Catalyst, but there may be other voting use cases in the future). To be in compliance with the CDDL and other Cardano tools, vote key registration object is being wrapped in a tuple and an empty tuple follows it. The empty tuple represents `auxiliary_scripts` which are not yet supported on Trezor and are thus always empty. Byron addresses are not supported as the addresses to receive rewards. The registration signature is returned in the form of `CardanoTxAuxiliaryDataSupplement` which also contains the auxiliary data hash calculated by Trezor.
[Governance Registration Transaction Metadata Format](https://cips.cardano.org/cips/cip36/) [CIP-36 Vote Registration Transaction Metadata Format](https://cips.cardano.org/cips/cip36/)
### Native scripts ### Native scripts

View File

@ -233,13 +233,13 @@ def validate_output_address_parameters(
assert_params_cond(parameters.address_type in ADDRESS_TYPES_PAYMENT_KEY) assert_params_cond(parameters.address_type in ADDRESS_TYPES_PAYMENT_KEY)
def validate_governance_reward_address_parameters( def validate_cvote_reward_address_parameters(
parameters: messages.CardanoAddressParametersType, parameters: messages.CardanoAddressParametersType,
) -> None: ) -> None:
validate_address_parameters(parameters) validate_address_parameters(parameters)
# Despite the name, the address doesn't have to be a REWARD address. # Despite the name, the address doesn't have to be a REWARD address.
# see also validate_governance_reward_address # see also validate_cvote_reward_address
assert_params_cond(parameters.address_type in ADDRESS_TYPES_SHELLEY) assert_params_cond(parameters.address_type in ADDRESS_TYPES_SHELLEY)
@ -299,7 +299,7 @@ def validate_reward_address(address: str, protocol_magic: int, network_id: int)
) )
def validate_governance_reward_address( def validate_cvote_reward_address(
address: str, protocol_magic: int, network_id: int address: str, protocol_magic: int, network_id: int
) -> None: ) -> None:
address_type = _validate_and_get_type(address, protocol_magic, network_id) address_type = _validate_and_get_type(address, protocol_magic, network_id)

View File

@ -2,7 +2,7 @@ from micropython import const
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from trezor.crypto import hashlib from trezor.crypto import hashlib
from trezor.enums import CardanoAddressType, CardanoGovernanceRegistrationFormat from trezor.enums import CardanoAddressType, CardanoCVoteRegistrationFormat
from apps.common import cbor from apps.common import cbor
@ -12,8 +12,8 @@ from .helpers.utils import derive_public_key
if TYPE_CHECKING: if TYPE_CHECKING:
Delegations = list[tuple[bytes, int]] Delegations = list[tuple[bytes, int]]
GovernanceRegistrationPayload = dict[int, Delegations | bytes | int] CVoteRegistrationPayload = dict[int, Delegations | bytes | int]
SignedGovernanceRegistrationPayload = tuple[GovernanceRegistrationPayload, bytes] SignedCVoteRegistrationPayload = tuple[CVoteRegistrationPayload, bytes]
from trezor import messages from trezor import messages
from trezor.wire import Context from trezor.wire import Context
@ -21,11 +21,11 @@ if TYPE_CHECKING:
from . import seed from . import seed
_AUXILIARY_DATA_HASH_SIZE = const(32) _AUXILIARY_DATA_HASH_SIZE = const(32)
_GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH = const(32) _CVOTE_PUBLIC_KEY_LENGTH = const(32)
_GOVERNANCE_REGISTRATION_HASH_SIZE = const(32) _CVOTE_REGISTRATION_HASH_SIZE = const(32)
_METADATA_KEY_GOVERNANCE_REGISTRATION = const(61284) _METADATA_KEY_CVOTE_REGISTRATION = const(61284)
_METADATA_KEY_GOVERNANCE_REGISTRATION_SIGNATURE = const(61285) _METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE = const(61285)
_MAX_DELEGATION_COUNT = const(32) _MAX_DELEGATION_COUNT = const(32)
_DEFAULT_VOTING_PURPOSE = const(0) _DEFAULT_VOTING_PURPOSE = const(0)
@ -48,18 +48,18 @@ def validate(
fields_provided += 1 fields_provided += 1
# _validate_hash # _validate_hash
assert_cond(len(auxiliary_data.hash) == _AUXILIARY_DATA_HASH_SIZE) assert_cond(len(auxiliary_data.hash) == _AUXILIARY_DATA_HASH_SIZE)
if auxiliary_data.governance_registration_parameters: if auxiliary_data.cvote_registration_parameters:
fields_provided += 1 fields_provided += 1
_validate_governance_registration_parameters( _validate_cvote_registration_parameters(
auxiliary_data.governance_registration_parameters, auxiliary_data.cvote_registration_parameters,
protocol_magic, protocol_magic,
network_id, network_id,
) )
assert_cond(fields_provided == 1) assert_cond(fields_provided == 1)
def _validate_governance_registration_parameters( def _validate_cvote_registration_parameters(
parameters: messages.CardanoGovernanceRegistrationParametersType, parameters: messages.CardanoCVoteRegistrationParametersType,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
) -> None: ) -> None:
@ -69,7 +69,7 @@ def _validate_governance_registration_parameters(
_validate_voting_public_key(parameters.voting_public_key) _validate_voting_public_key(parameters.voting_public_key)
if parameters.delegations: if parameters.delegations:
voting_key_fields_provided += 1 voting_key_fields_provided += 1
assert_cond(parameters.format == CardanoGovernanceRegistrationFormat.CIP36) assert_cond(parameters.format == CardanoCVoteRegistrationFormat.CIP36)
_validate_delegations(parameters.delegations) _validate_delegations(parameters.delegations)
assert_cond(voting_key_fields_provided == 1) assert_cond(voting_key_fields_provided == 1)
@ -78,26 +78,26 @@ def _validate_governance_registration_parameters(
reward_address_fields_provided = 0 reward_address_fields_provided = 0
if parameters.reward_address is not None: if parameters.reward_address is not None:
reward_address_fields_provided += 1 reward_address_fields_provided += 1
addresses.validate_governance_reward_address( addresses.validate_cvote_reward_address(
parameters.reward_address, protocol_magic, network_id parameters.reward_address, protocol_magic, network_id
) )
if parameters.reward_address_parameters: if parameters.reward_address_parameters:
reward_address_fields_provided += 1 reward_address_fields_provided += 1
addresses.validate_governance_reward_address_parameters( addresses.validate_cvote_reward_address_parameters(
parameters.reward_address_parameters parameters.reward_address_parameters
) )
assert_cond(reward_address_fields_provided == 1) assert_cond(reward_address_fields_provided == 1)
if parameters.voting_purpose is not None: if parameters.voting_purpose is not None:
assert_cond(parameters.format == CardanoGovernanceRegistrationFormat.CIP36) assert_cond(parameters.format == CardanoCVoteRegistrationFormat.CIP36)
def _validate_voting_public_key(key: bytes) -> None: def _validate_voting_public_key(key: bytes) -> None:
assert_cond(len(key) == _GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH) assert_cond(len(key) == _CVOTE_PUBLIC_KEY_LENGTH)
def _validate_delegations( def _validate_delegations(
delegations: list[messages.CardanoGovernanceDelegation], delegations: list[messages.CardanoCVoteDelegation],
) -> None: ) -> None:
assert_cond(len(delegations) <= _MAX_DELEGATION_COUNT) assert_cond(len(delegations) <= _MAX_DELEGATION_COUNT)
for delegation in delegations: for delegation in delegations:
@ -105,9 +105,9 @@ def _validate_delegations(
def _get_voting_purpose_to_serialize( def _get_voting_purpose_to_serialize(
parameters: messages.CardanoGovernanceRegistrationParametersType, parameters: messages.CardanoCVoteRegistrationParametersType,
) -> int | None: ) -> int | None:
if parameters.format == CardanoGovernanceRegistrationFormat.CIP15: if parameters.format == CardanoCVoteRegistrationFormat.CIP15:
return None return None
if parameters.voting_purpose is None: if parameters.voting_purpose is None:
return _DEFAULT_VOTING_PURPOSE return _DEFAULT_VOTING_PURPOSE
@ -118,13 +118,13 @@ async def show(
ctx: Context, ctx: Context,
keychain: seed.Keychain, keychain: seed.Keychain,
auxiliary_data_hash: bytes, auxiliary_data_hash: bytes,
parameters: messages.CardanoGovernanceRegistrationParametersType | None, parameters: messages.CardanoCVoteRegistrationParametersType | None,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
should_show_details: bool, should_show_details: bool,
) -> None: ) -> None:
if parameters: if parameters:
await _show_governance_registration( await _show_cvote_registration(
ctx, ctx,
keychain, keychain,
parameters, parameters,
@ -138,17 +138,17 @@ async def show(
def _should_show_payment_warning(address_type: CardanoAddressType) -> bool: def _should_show_payment_warning(address_type: CardanoAddressType) -> bool:
# For non-payment governance reward addresses, we show a warning that the address is not # For non-payment cvote reward addresses, we show a warning that the address is not
# actually eligible for rewards. https://github.com/cardano-foundation/CIPs/pull/373 # actually eligible for rewards. https://github.com/cardano-foundation/CIPs/pull/373
# However, the registration is otherwise valid, so we allow such addresses since we don't # However, the registration is otherwise valid, so we allow such addresses since we don't
# want to prevent the user from voting just because they use an outdated SW wallet. # want to prevent the user from voting just because they use an outdated SW wallet.
return address_type not in addresses.ADDRESS_TYPES_PAYMENT return address_type not in addresses.ADDRESS_TYPES_PAYMENT
async def _show_governance_registration( async def _show_cvote_registration(
ctx: Context, ctx: Context,
keychain: seed.Keychain, keychain: seed.Keychain,
parameters: messages.CardanoGovernanceRegistrationParametersType, parameters: messages.CardanoCVoteRegistrationParametersType,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
should_show_details: bool, should_show_details: bool,
@ -158,9 +158,9 @@ async def _show_governance_registration(
for delegation in parameters.delegations: for delegation in parameters.delegations:
encoded_public_key = bech32.encode( encoded_public_key = bech32.encode(
bech32.HRP_GOVERNANCE_PUBLIC_KEY, delegation.voting_public_key bech32.HRP_CVOTE_PUBLIC_KEY, delegation.voting_public_key
) )
await layout.confirm_governance_registration_delegation( await layout.confirm_cvote_registration_delegation(
ctx, encoded_public_key, delegation.weight ctx, encoded_public_key, delegation.weight
) )
@ -168,17 +168,17 @@ async def _show_governance_registration(
show_payment_warning = _should_show_payment_warning( show_payment_warning = _should_show_payment_warning(
addresses.get_type(addresses.get_bytes_unsafe(parameters.reward_address)) addresses.get_type(addresses.get_bytes_unsafe(parameters.reward_address))
) )
await layout.confirm_governance_registration_reward_address( await layout.confirm_cvote_registration_reward_address(
ctx, parameters.reward_address, show_payment_warning ctx, parameters.reward_address, show_payment_warning
) )
else: else:
address_parameters = parameters.reward_address_parameters address_parameters = parameters.reward_address_parameters
assert address_parameters # _validate_governance_registration_parameters assert address_parameters # _validate_cvote_registration_parameters
show_both_credentials = should_show_credentials(address_parameters) show_both_credentials = should_show_credentials(address_parameters)
show_payment_warning = _should_show_payment_warning( show_payment_warning = _should_show_payment_warning(
address_parameters.address_type address_parameters.address_type
) )
await layout.show_governance_registration_reward_credentials( await layout.show_cvote_registration_reward_credentials(
ctx, ctx,
Credential.payment_credential(address_parameters), Credential.payment_credential(address_parameters),
Credential.stake_credential(address_parameters), Credential.stake_credential(address_parameters),
@ -189,14 +189,14 @@ async def _show_governance_registration(
encoded_public_key: str | None = None encoded_public_key: str | None = None
if parameters.voting_public_key: if parameters.voting_public_key:
encoded_public_key = bech32.encode( encoded_public_key = bech32.encode(
bech32.HRP_GOVERNANCE_PUBLIC_KEY, parameters.voting_public_key bech32.HRP_CVOTE_PUBLIC_KEY, parameters.voting_public_key
) )
voting_purpose: int | None = ( voting_purpose: int | None = (
_get_voting_purpose_to_serialize(parameters) if should_show_details else None _get_voting_purpose_to_serialize(parameters) if should_show_details else None
) )
await layout.confirm_governance_registration( await layout.confirm_cvote_registration(
ctx, ctx,
encoded_public_key, encoded_public_key,
parameters.staking_path, parameters.staking_path,
@ -214,20 +214,20 @@ def get_hash_and_supplement(
from trezor.enums import CardanoTxAuxiliaryDataSupplementType from trezor.enums import CardanoTxAuxiliaryDataSupplementType
from trezor import messages from trezor import messages
if parameters := auxiliary_data.governance_registration_parameters: if parameters := auxiliary_data.cvote_registration_parameters:
( (
governance_registration_payload, cvote_registration_payload,
governance_signature, cvote_registration_signature,
) = _get_signed_governance_registration_payload( ) = _get_signed_cvote_registration_payload(
keychain, parameters, protocol_magic, network_id keychain, parameters, protocol_magic, network_id
) )
auxiliary_data_hash = _get_governance_registration_hash( auxiliary_data_hash = _get_cvote_registration_hash(
governance_registration_payload, governance_signature cvote_registration_payload, cvote_registration_signature
) )
auxiliary_data_supplement = messages.CardanoTxAuxiliaryDataSupplement( auxiliary_data_supplement = messages.CardanoTxAuxiliaryDataSupplement(
type=CardanoTxAuxiliaryDataSupplementType.GOVERNANCE_REGISTRATION_SIGNATURE, type=CardanoTxAuxiliaryDataSupplementType.CVOTE_REGISTRATION_SIGNATURE,
auxiliary_data_hash=auxiliary_data_hash, auxiliary_data_hash=auxiliary_data_hash,
governance_signature=governance_signature, cvote_registration_signature=cvote_registration_signature,
) )
return auxiliary_data_hash, auxiliary_data_supplement return auxiliary_data_hash, auxiliary_data_supplement
else: else:
@ -237,15 +237,15 @@ def get_hash_and_supplement(
) )
def _get_governance_registration_hash( def _get_cvote_registration_hash(
governance_registration_payload: GovernanceRegistrationPayload, cvote_registration_payload: CVoteRegistrationPayload,
governance_registration_payload_signature: bytes, cvote_registration_payload_signature: bytes,
) -> bytes: ) -> bytes:
# _cborize_catalyst_registration # _cborize_catalyst_registration
governance_registration_signature = {1: governance_registration_payload_signature} cvote_registration_signature = {1: cvote_registration_payload_signature}
cborized_catalyst_registration = { cborized_catalyst_registration = {
_METADATA_KEY_GOVERNANCE_REGISTRATION: governance_registration_payload, _METADATA_KEY_CVOTE_REGISTRATION: cvote_registration_payload,
_METADATA_KEY_GOVERNANCE_REGISTRATION_SIGNATURE: governance_registration_signature, _METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE: cvote_registration_signature,
} }
# _get_hash # _get_hash
@ -262,12 +262,12 @@ def _get_governance_registration_hash(
).digest() ).digest()
def _get_signed_governance_registration_payload( def _get_signed_cvote_registration_payload(
keychain: seed.Keychain, keychain: seed.Keychain,
parameters: messages.CardanoGovernanceRegistrationParametersType, parameters: messages.CardanoCVoteRegistrationParametersType,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
) -> SignedGovernanceRegistrationPayload: ) -> SignedCVoteRegistrationPayload:
delegations_or_key: Delegations | bytes delegations_or_key: Delegations | bytes
if len(parameters.delegations) > 0: if len(parameters.delegations) > 0:
delegations_or_key = [ delegations_or_key = [
@ -277,7 +277,7 @@ def _get_signed_governance_registration_payload(
elif parameters.voting_public_key: elif parameters.voting_public_key:
delegations_or_key = parameters.voting_public_key delegations_or_key = parameters.voting_public_key
else: else:
raise RuntimeError # should not be reached - _validate_governance_registration_parameters raise RuntimeError # should not be reached - _validate_cvote_registration_parameters
staking_key = derive_public_key(keychain, parameters.staking_path) staking_key = derive_public_key(keychain, parameters.staking_path)
@ -285,7 +285,7 @@ def _get_signed_governance_registration_payload(
reward_address = addresses.get_bytes_unsafe(parameters.reward_address) reward_address = addresses.get_bytes_unsafe(parameters.reward_address)
else: else:
address_parameters = parameters.reward_address_parameters address_parameters = parameters.reward_address_parameters
assert address_parameters # _validate_governance_registration_parameters assert address_parameters # _validate_cvote_registration_parameters
reward_address = addresses.derive_bytes( reward_address = addresses.derive_bytes(
keychain, keychain,
address_parameters, address_parameters,
@ -295,7 +295,7 @@ def _get_signed_governance_registration_payload(
voting_purpose = _get_voting_purpose_to_serialize(parameters) voting_purpose = _get_voting_purpose_to_serialize(parameters)
payload: GovernanceRegistrationPayload = { payload: CVoteRegistrationPayload = {
1: delegations_or_key, 1: delegations_or_key,
2: staking_key, 2: staking_key,
3: reward_address, 3: reward_address,
@ -304,7 +304,7 @@ def _get_signed_governance_registration_payload(
if voting_purpose is not None: if voting_purpose is not None:
payload[5] = voting_purpose payload[5] = voting_purpose
signature = _create_governance_registration_payload_signature( signature = _create_cvote_registration_payload_signature(
keychain, keychain,
payload, payload,
parameters.staking_path, parameters.staking_path,
@ -313,24 +313,24 @@ def _get_signed_governance_registration_payload(
return payload, signature return payload, signature
def _create_governance_registration_payload_signature( def _create_cvote_registration_payload_signature(
keychain: seed.Keychain, keychain: seed.Keychain,
governance_registration_payload: GovernanceRegistrationPayload, cvote_registration_payload: CVoteRegistrationPayload,
path: list[int], path: list[int],
) -> bytes: ) -> bytes:
from trezor.crypto.curve import ed25519 from trezor.crypto.curve import ed25519
node = keychain.derive(path) node = keychain.derive(path)
encoded_governance_registration = cbor.encode( encoded_cvote_registration = cbor.encode(
{_METADATA_KEY_GOVERNANCE_REGISTRATION: governance_registration_payload} {_METADATA_KEY_CVOTE_REGISTRATION: cvote_registration_payload}
) )
governance_registration_hash = hashlib.blake2b( cvote_registration_hash = hashlib.blake2b(
data=encoded_governance_registration, data=encoded_cvote_registration,
outlen=_GOVERNANCE_REGISTRATION_HASH_SIZE, outlen=_CVOTE_REGISTRATION_HASH_SIZE,
).digest() ).digest()
return ed25519.sign_ext( return ed25519.sign_ext(
node.private_key(), node.private_key_ext(), governance_registration_hash node.private_key(), node.private_key_ext(), cvote_registration_hash
) )

View File

@ -7,7 +7,7 @@ HRP_ADDRESS = "addr"
HRP_TESTNET_ADDRESS = "addr_test" HRP_TESTNET_ADDRESS = "addr_test"
HRP_REWARD_ADDRESS = "stake" HRP_REWARD_ADDRESS = "stake"
HRP_TESTNET_REWARD_ADDRESS = "stake_test" HRP_TESTNET_REWARD_ADDRESS = "stake_test"
HRP_GOVERNANCE_PUBLIC_KEY = "cvote_vk" HRP_CVOTE_PUBLIC_KEY = "cvote_vk"
HRP_SCRIPT_HASH = "script" HRP_SCRIPT_HASH = "script"
HRP_KEY_HASH = "addr_vkh" HRP_KEY_HASH = "addr_vkh"
HRP_SHARED_KEY_HASH = "addr_shared_vkh" HRP_SHARED_KEY_HASH = "addr_shared_vkh"

View File

@ -68,7 +68,7 @@ CERTIFICATE_TYPE_NAMES = {
BRT_Other = ButtonRequestType.Other # global_import_cache BRT_Other = ButtonRequestType.Other # global_import_cache
GOVERNANCE_REWARD_ELIGIBILITY_WARNING = ( CVOTE_REWARD_ELIGIBILITY_WARNING = (
"Warning: The address is not a payment address, it is not eligible for rewards." "Warning: The address is not a payment address, it is not eligible for rewards."
) )
@ -357,26 +357,24 @@ async def show_device_owned_output_credentials(
await _show_credential(ctx, stake_credential, intro_text, purpose="output") await _show_credential(ctx, stake_credential, intro_text, purpose="output")
async def show_governance_registration_reward_credentials( async def show_cvote_registration_reward_credentials(
ctx: Context, ctx: Context,
payment_credential: Credential, payment_credential: Credential,
stake_credential: Credential, stake_credential: Credential,
show_both_credentials: bool, show_both_credentials: bool,
show_payment_warning: bool, show_payment_warning: bool,
) -> None: ) -> None:
intro_text = "The governance registration reward address is owned by this device. Its" intro_text = "The vote key registration reward address is owned by this device. Its"
await _show_credential( await _show_credential(
ctx, payment_credential, intro_text, purpose="gov_reg_reward_address" ctx, payment_credential, intro_text, purpose="cvote_reg_reward_address"
) )
if show_both_credentials or show_payment_warning: if show_both_credentials or show_payment_warning:
extra_text = ( extra_text = CVOTE_REWARD_ELIGIBILITY_WARNING if show_payment_warning else None
GOVERNANCE_REWARD_ELIGIBILITY_WARNING if show_payment_warning else None
)
await _show_credential( await _show_credential(
ctx, ctx,
stake_credential, stake_credential,
intro_text, intro_text,
purpose="gov_reg_reward_address", purpose="cvote_reg_reward_address",
extra_text=extra_text, extra_text=extra_text,
) )
@ -385,13 +383,13 @@ async def _show_credential(
ctx: Context, ctx: Context,
credential: Credential, credential: Credential,
intro_text: str, intro_text: str,
purpose: Literal["address", "output", "gov_reg_reward_address"], purpose: Literal["address", "output", "cvote_reg_reward_address"],
extra_text: str | None = None, extra_text: str | None = None,
) -> None: ) -> None:
title = { title = {
"address": f"{ADDRESS_TYPE_NAMES[credential.address_type]} address", "address": f"{ADDRESS_TYPE_NAMES[credential.address_type]} address",
"output": "Confirm transaction", "output": "Confirm transaction",
"gov_reg_reward_address": "Confirm transaction", "cvote_reg_reward_address": "Confirm transaction",
}[purpose] }[purpose]
props: list[PropertyType] = [] props: list[PropertyType] = []
@ -414,8 +412,8 @@ async def _show_credential(
append((None, "Path is unusual.")) append((None, "Path is unusual."))
if credential.is_mismatch: if credential.is_mismatch:
append((None, "Credential doesn't match payment credential.")) append((None, "Credential doesn't match payment credential."))
if credential.is_reward and purpose != "gov_reg_reward_address": if credential.is_reward and purpose != "cvote_reg_reward_address":
# for governance registrations, this is handled by extra_text at the end # for cvote registrations, this is handled by extra_text at the end
append(("Address is a reward address.", None)) append(("Address is a reward address.", None))
if credential.is_no_staking: if credential.is_no_staking:
append( append(
@ -775,13 +773,13 @@ def _format_stake_credential(
raise ValueError raise ValueError
async def confirm_governance_registration_delegation( async def confirm_cvote_registration_delegation(
ctx: Context, ctx: Context,
public_key: str, public_key: str,
weight: int, weight: int,
) -> None: ) -> None:
props: list[PropertyType] = [ props: list[PropertyType] = [
("Governance voting key registration", None), ("Vote key registration (CIP-36)", None),
("Delegating to:", public_key), ("Delegating to:", public_key),
] ]
if weight is not None: if weight is not None:
@ -789,41 +787,41 @@ async def confirm_governance_registration_delegation(
await confirm_properties( await confirm_properties(
ctx, ctx,
"confirm_governance_registration_delegation", "confirm_cvote_registration_delegation",
title="Confirm transaction", title="Confirm transaction",
props=props, props=props,
br_code=ButtonRequestType.Other, br_code=ButtonRequestType.Other,
) )
async def confirm_governance_registration_reward_address( async def confirm_cvote_registration_reward_address(
ctx: Context, ctx: Context,
reward_address: str, reward_address: str,
should_show_payment_warning: bool, should_show_payment_warning: bool,
) -> None: ) -> None:
props = [ props = [
("Governance voting key registration", None), ("Vote key registration (CIP-36)", None),
("Rewards go to:", reward_address), ("Rewards go to:", reward_address),
] ]
if should_show_payment_warning: if should_show_payment_warning:
props.append((GOVERNANCE_REWARD_ELIGIBILITY_WARNING, None)) props.append((CVOTE_REWARD_ELIGIBILITY_WARNING, None))
await confirm_properties( await confirm_properties(
ctx, ctx,
"confirm_governance_registration_reward_address", "confirm_cvote_registration_reward_address",
title="Confirm transaction", title="Confirm transaction",
props=props, props=props,
br_code=ButtonRequestType.Other, br_code=ButtonRequestType.Other,
) )
async def confirm_governance_registration( async def confirm_cvote_registration(
ctx: Context, ctx: Context,
public_key: str | None, public_key: str | None,
staking_path: list[int], staking_path: list[int],
nonce: int, nonce: int,
voting_purpose: int | None, voting_purpose: int | None,
) -> None: ) -> None:
props: list[PropertyType] = [("Governance voting key registration", None)] props: list[PropertyType] = [("Vote key registration (CIP-36)", None)]
if public_key is not None: if public_key is not None:
props.append(("Voting public key:", public_key)) props.append(("Voting public key:", public_key))
props.extend( props.extend(
@ -845,7 +843,7 @@ async def confirm_governance_registration(
await confirm_properties( await confirm_properties(
ctx, ctx,
"confirm_governance_registration", "confirm_cvote_registration",
title="Confirm transaction", title="Confirm transaction",
props=props, props=props,
br_code=ButtonRequestType.Other, br_code=ButtonRequestType.Other,

View File

@ -836,7 +836,7 @@ class Signer:
self.ctx, self.ctx,
self.keychain, self.keychain,
auxiliary_data_hash, auxiliary_data_hash,
data.governance_registration_parameters, data.cvote_registration_parameters,
msg.protocol_magic, msg.protocol_magic,
msg.network_id, msg.network_id,
self.should_show_details, self.should_show_details,

View File

@ -3,4 +3,4 @@
# isort:skip_file # isort:skip_file
NONE = 0 NONE = 0
GOVERNANCE_REGISTRATION_SIGNATURE = 1 CVOTE_REGISTRATION_SIGNATURE = 1

View File

@ -381,9 +381,9 @@ if TYPE_CHECKING:
class CardanoTxAuxiliaryDataSupplementType(IntEnum): class CardanoTxAuxiliaryDataSupplementType(IntEnum):
NONE = 0 NONE = 0
GOVERNANCE_REGISTRATION_SIGNATURE = 1 CVOTE_REGISTRATION_SIGNATURE = 1
class CardanoGovernanceRegistrationFormat(IntEnum): class CardanoCVoteRegistrationFormat(IntEnum):
CIP15 = 0 CIP15 = 0
CIP36 = 1 CIP36 = 1

View File

@ -24,9 +24,9 @@ if TYPE_CHECKING:
from trezor.enums import ButtonRequestType # noqa: F401 from trezor.enums import ButtonRequestType # noqa: F401
from trezor.enums import Capability # noqa: F401 from trezor.enums import Capability # noqa: F401
from trezor.enums import CardanoAddressType # noqa: F401 from trezor.enums import CardanoAddressType # noqa: F401
from trezor.enums import CardanoCVoteRegistrationFormat # noqa: F401
from trezor.enums import CardanoCertificateType # noqa: F401 from trezor.enums import CardanoCertificateType # noqa: F401
from trezor.enums import CardanoDerivationType # noqa: F401 from trezor.enums import CardanoDerivationType # noqa: F401
from trezor.enums import CardanoGovernanceRegistrationFormat # noqa: F401
from trezor.enums import CardanoNativeScriptHashDisplayFormat # noqa: F401 from trezor.enums import CardanoNativeScriptHashDisplayFormat # noqa: F401
from trezor.enums import CardanoNativeScriptType # noqa: F401 from trezor.enums import CardanoNativeScriptType # noqa: F401
from trezor.enums import CardanoPoolRelayType # noqa: F401 from trezor.enums import CardanoPoolRelayType # noqa: F401
@ -1638,7 +1638,7 @@ if TYPE_CHECKING:
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoTxWithdrawal"]: def is_type_of(cls, msg: Any) -> TypeGuard["CardanoTxWithdrawal"]:
return isinstance(msg, cls) return isinstance(msg, cls)
class CardanoGovernanceRegistrationDelegation(protobuf.MessageType): class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
voting_public_key: "bytes" voting_public_key: "bytes"
weight: "int" weight: "int"
@ -1651,16 +1651,16 @@ if TYPE_CHECKING:
pass pass
@classmethod @classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoGovernanceRegistrationDelegation"]: def is_type_of(cls, msg: Any) -> TypeGuard["CardanoCVoteRegistrationDelegation"]:
return isinstance(msg, cls) return isinstance(msg, cls)
class CardanoGovernanceRegistrationParametersType(protobuf.MessageType): class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
voting_public_key: "bytes | None" voting_public_key: "bytes | None"
staking_path: "list[int]" staking_path: "list[int]"
reward_address_parameters: "CardanoAddressParametersType | None" reward_address_parameters: "CardanoAddressParametersType | None"
nonce: "int" nonce: "int"
format: "CardanoGovernanceRegistrationFormat" format: "CardanoCVoteRegistrationFormat"
delegations: "list[CardanoGovernanceRegistrationDelegation]" delegations: "list[CardanoCVoteRegistrationDelegation]"
voting_purpose: "int | None" voting_purpose: "int | None"
reward_address: "str | None" reward_address: "str | None"
@ -1669,27 +1669,27 @@ if TYPE_CHECKING:
*, *,
nonce: "int", nonce: "int",
staking_path: "list[int] | None" = None, staking_path: "list[int] | None" = None,
delegations: "list[CardanoGovernanceRegistrationDelegation] | None" = None, delegations: "list[CardanoCVoteRegistrationDelegation] | None" = None,
voting_public_key: "bytes | None" = None, voting_public_key: "bytes | None" = None,
reward_address_parameters: "CardanoAddressParametersType | None" = None, reward_address_parameters: "CardanoAddressParametersType | None" = None,
format: "CardanoGovernanceRegistrationFormat | None" = None, format: "CardanoCVoteRegistrationFormat | None" = None,
voting_purpose: "int | None" = None, voting_purpose: "int | None" = None,
reward_address: "str | None" = None, reward_address: "str | None" = None,
) -> None: ) -> None:
pass pass
@classmethod @classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoGovernanceRegistrationParametersType"]: def is_type_of(cls, msg: Any) -> TypeGuard["CardanoCVoteRegistrationParametersType"]:
return isinstance(msg, cls) return isinstance(msg, cls)
class CardanoTxAuxiliaryData(protobuf.MessageType): class CardanoTxAuxiliaryData(protobuf.MessageType):
governance_registration_parameters: "CardanoGovernanceRegistrationParametersType | None" cvote_registration_parameters: "CardanoCVoteRegistrationParametersType | None"
hash: "bytes | None" hash: "bytes | None"
def __init__( def __init__(
self, self,
*, *,
governance_registration_parameters: "CardanoGovernanceRegistrationParametersType | None" = None, cvote_registration_parameters: "CardanoCVoteRegistrationParametersType | None" = None,
hash: "bytes | None" = None, hash: "bytes | None" = None,
) -> None: ) -> None:
pass pass
@ -1769,14 +1769,14 @@ if TYPE_CHECKING:
class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType): class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
type: "CardanoTxAuxiliaryDataSupplementType" type: "CardanoTxAuxiliaryDataSupplementType"
auxiliary_data_hash: "bytes | None" auxiliary_data_hash: "bytes | None"
governance_signature: "bytes | None" cvote_registration_signature: "bytes | None"
def __init__( def __init__(
self, self,
*, *,
type: "CardanoTxAuxiliaryDataSupplementType", type: "CardanoTxAuxiliaryDataSupplementType",
auxiliary_data_hash: "bytes | None" = None, auxiliary_data_hash: "bytes | None" = None,
governance_signature: "bytes | None" = None, cvote_registration_signature: "bytes | None" = None,
) -> None: ) -> None:
pass pass

View File

@ -61,11 +61,11 @@ REQUIRED_FIELDS_POOL_PARAMETERS = (
"owners", "owners",
) )
REQUIRED_FIELDS_TOKEN_GROUP = ("policy_id", "tokens") REQUIRED_FIELDS_TOKEN_GROUP = ("policy_id", "tokens")
REQUIRED_FIELDS_GOVERNANCE_REGISTRATION = ( REQUIRED_FIELDS_CVOTE_REGISTRATION = (
"staking_path", "staking_path",
"nonce", "nonce",
) )
REQUIRED_FIELDS_GOVERNANCE_DELEGATION = ("voting_public_key", "weight") REQUIRED_FIELDS_CVOTE_DELEGATION = ("voting_public_key", "weight")
INCOMPLETE_OUTPUT_ERROR_MESSAGE = "The output is missing some fields" INCOMPLETE_OUTPUT_ERROR_MESSAGE = "The output is missing some fields"
@ -562,58 +562,53 @@ def parse_auxiliary_data(
# include all provided fields so we can test validation in FW # include all provided fields so we can test validation in FW
hash = parse_optional_bytes(auxiliary_data.get("hash")) hash = parse_optional_bytes(auxiliary_data.get("hash"))
governance_registration_parameters = None cvote_registration_parameters = None
if "governance_registration_parameters" in auxiliary_data: if "cvote_registration_parameters" in auxiliary_data:
governance_registration = auxiliary_data["governance_registration_parameters"] cvote_registration = auxiliary_data["cvote_registration_parameters"]
if not all( if not all(k in cvote_registration for k in REQUIRED_FIELDS_CVOTE_REGISTRATION):
k in governance_registration
for k in REQUIRED_FIELDS_GOVERNANCE_REGISTRATION
):
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
serialization_format = governance_registration.get("format") serialization_format = cvote_registration.get("format")
delegations = [] delegations = []
for delegation in governance_registration.get("delegations", []): for delegation in cvote_registration.get("delegations", []):
if not all(k in delegation for k in REQUIRED_FIELDS_GOVERNANCE_DELEGATION): if not all(k in delegation for k in REQUIRED_FIELDS_CVOTE_DELEGATION):
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
delegations.append( delegations.append(
messages.CardanoGovernanceRegistrationDelegation( messages.CardanoCVoteRegistrationDelegation(
voting_public_key=bytes.fromhex(delegation["voting_public_key"]), voting_public_key=bytes.fromhex(delegation["voting_public_key"]),
weight=int(delegation["weight"]), weight=int(delegation["weight"]),
) )
) )
voting_purpose = None voting_purpose = None
if serialization_format == messages.CardanoGovernanceRegistrationFormat.CIP36: if serialization_format == messages.CardanoCVoteRegistrationFormat.CIP36:
voting_purpose = governance_registration.get("voting_purpose") voting_purpose = cvote_registration.get("voting_purpose")
governance_registration_parameters = ( cvote_registration_parameters = messages.CardanoCVoteRegistrationParametersType(
messages.CardanoGovernanceRegistrationParametersType( voting_public_key=parse_optional_bytes(
voting_public_key=parse_optional_bytes( cvote_registration.get("voting_public_key")
governance_registration.get("voting_public_key") ),
), staking_path=tools.parse_path(cvote_registration["staking_path"]),
staking_path=tools.parse_path(governance_registration["staking_path"]), nonce=cvote_registration["nonce"],
nonce=governance_registration["nonce"], reward_address=cvote_registration.get("reward_address"),
reward_address=governance_registration.get("reward_address"), reward_address_parameters=_parse_address_parameters(
reward_address_parameters=_parse_address_parameters( cvote_registration["reward_address_parameters"],
governance_registration["reward_address_parameters"], str(AUXILIARY_DATA_MISSING_FIELDS_ERROR),
str(AUXILIARY_DATA_MISSING_FIELDS_ERROR),
)
if "reward_address_parameters" in governance_registration
else None,
format=serialization_format,
delegations=delegations,
voting_purpose=voting_purpose,
) )
if "reward_address_parameters" in cvote_registration
else None,
format=serialization_format,
delegations=delegations,
voting_purpose=voting_purpose,
) )
if hash is None and governance_registration_parameters is None: if hash is None and cvote_registration_parameters is None:
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
return messages.CardanoTxAuxiliaryData( return messages.CardanoTxAuxiliaryData(
hash=hash, hash=hash,
governance_registration_parameters=governance_registration_parameters, cvote_registration_parameters=cvote_registration_parameters,
) )

View File

@ -162,11 +162,13 @@ def sign_tx(
auxiliary_data_supplement["auxiliary_data_hash"] = auxiliary_data_supplement[ auxiliary_data_supplement["auxiliary_data_hash"] = auxiliary_data_supplement[
"auxiliary_data_hash" "auxiliary_data_hash"
].hex() ].hex()
governance_signature = auxiliary_data_supplement.get("governance_signature") cvote_registration_signature = auxiliary_data_supplement.get(
if governance_signature: "cvote_registration_signature"
)
if cvote_registration_signature:
auxiliary_data_supplement[ auxiliary_data_supplement[
"governance_signature" "cvote_registration_signature"
] = governance_signature.hex() ] = cvote_registration_signature.hex()
sign_tx_response["auxiliary_data_supplement"] = auxiliary_data_supplement sign_tx_response["auxiliary_data_supplement"] = auxiliary_data_supplement
return sign_tx_response return sign_tx_response

View File

@ -405,10 +405,10 @@ class CardanoPoolRelayType(IntEnum):
class CardanoTxAuxiliaryDataSupplementType(IntEnum): class CardanoTxAuxiliaryDataSupplementType(IntEnum):
NONE = 0 NONE = 0
GOVERNANCE_REGISTRATION_SIGNATURE = 1 CVOTE_REGISTRATION_SIGNATURE = 1
class CardanoGovernanceRegistrationFormat(IntEnum): class CardanoCVoteRegistrationFormat(IntEnum):
CIP15 = 0 CIP15 = 0
CIP36 = 1 CIP36 = 1
@ -2636,7 +2636,7 @@ class CardanoTxWithdrawal(protobuf.MessageType):
self.key_hash = key_hash self.key_hash = key_hash
class CardanoGovernanceRegistrationDelegation(protobuf.MessageType): class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
MESSAGE_WIRE_TYPE = None MESSAGE_WIRE_TYPE = None
FIELDS = { FIELDS = {
1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=True), 1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=True),
@ -2653,15 +2653,15 @@ class CardanoGovernanceRegistrationDelegation(protobuf.MessageType):
self.weight = weight self.weight = weight
class CardanoGovernanceRegistrationParametersType(protobuf.MessageType): class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
MESSAGE_WIRE_TYPE = None MESSAGE_WIRE_TYPE = None
FIELDS = { FIELDS = {
1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=False, default=None), 1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=False, default=None),
2: protobuf.Field("staking_path", "uint32", repeated=True, required=False, default=None), 2: protobuf.Field("staking_path", "uint32", repeated=True, required=False, default=None),
3: protobuf.Field("reward_address_parameters", "CardanoAddressParametersType", repeated=False, required=False, default=None), 3: protobuf.Field("reward_address_parameters", "CardanoAddressParametersType", repeated=False, required=False, default=None),
4: protobuf.Field("nonce", "uint64", repeated=False, required=True), 4: protobuf.Field("nonce", "uint64", repeated=False, required=True),
5: protobuf.Field("format", "CardanoGovernanceRegistrationFormat", repeated=False, required=False, default=CardanoGovernanceRegistrationFormat.CIP15), 5: protobuf.Field("format", "CardanoCVoteRegistrationFormat", repeated=False, required=False, default=CardanoCVoteRegistrationFormat.CIP15),
6: protobuf.Field("delegations", "CardanoGovernanceRegistrationDelegation", repeated=True, required=False, default=None), 6: protobuf.Field("delegations", "CardanoCVoteRegistrationDelegation", repeated=True, required=False, default=None),
7: protobuf.Field("voting_purpose", "uint64", repeated=False, required=False, default=None), 7: protobuf.Field("voting_purpose", "uint64", repeated=False, required=False, default=None),
8: protobuf.Field("reward_address", "string", repeated=False, required=False, default=None), 8: protobuf.Field("reward_address", "string", repeated=False, required=False, default=None),
} }
@ -2671,15 +2671,15 @@ class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
*, *,
nonce: "int", nonce: "int",
staking_path: Optional[Sequence["int"]] = None, staking_path: Optional[Sequence["int"]] = None,
delegations: Optional[Sequence["CardanoGovernanceRegistrationDelegation"]] = None, delegations: Optional[Sequence["CardanoCVoteRegistrationDelegation"]] = None,
voting_public_key: Optional["bytes"] = None, voting_public_key: Optional["bytes"] = None,
reward_address_parameters: Optional["CardanoAddressParametersType"] = None, reward_address_parameters: Optional["CardanoAddressParametersType"] = None,
format: Optional["CardanoGovernanceRegistrationFormat"] = CardanoGovernanceRegistrationFormat.CIP15, format: Optional["CardanoCVoteRegistrationFormat"] = CardanoCVoteRegistrationFormat.CIP15,
voting_purpose: Optional["int"] = None, voting_purpose: Optional["int"] = None,
reward_address: Optional["str"] = None, reward_address: Optional["str"] = None,
) -> None: ) -> None:
self.staking_path: Sequence["int"] = staking_path if staking_path is not None else [] self.staking_path: Sequence["int"] = staking_path if staking_path is not None else []
self.delegations: Sequence["CardanoGovernanceRegistrationDelegation"] = delegations if delegations is not None else [] self.delegations: Sequence["CardanoCVoteRegistrationDelegation"] = delegations if delegations is not None else []
self.nonce = nonce self.nonce = nonce
self.voting_public_key = voting_public_key self.voting_public_key = voting_public_key
self.reward_address_parameters = reward_address_parameters self.reward_address_parameters = reward_address_parameters
@ -2691,17 +2691,17 @@ class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
class CardanoTxAuxiliaryData(protobuf.MessageType): class CardanoTxAuxiliaryData(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 327 MESSAGE_WIRE_TYPE = 327
FIELDS = { FIELDS = {
1: protobuf.Field("governance_registration_parameters", "CardanoGovernanceRegistrationParametersType", repeated=False, required=False, default=None), 1: protobuf.Field("cvote_registration_parameters", "CardanoCVoteRegistrationParametersType", repeated=False, required=False, default=None),
2: protobuf.Field("hash", "bytes", repeated=False, required=False, default=None), 2: protobuf.Field("hash", "bytes", repeated=False, required=False, default=None),
} }
def __init__( def __init__(
self, self,
*, *,
governance_registration_parameters: Optional["CardanoGovernanceRegistrationParametersType"] = None, cvote_registration_parameters: Optional["CardanoCVoteRegistrationParametersType"] = None,
hash: Optional["bytes"] = None, hash: Optional["bytes"] = None,
) -> None: ) -> None:
self.governance_registration_parameters = governance_registration_parameters self.cvote_registration_parameters = cvote_registration_parameters
self.hash = hash self.hash = hash
@ -2779,7 +2779,7 @@ class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
FIELDS = { FIELDS = {
1: protobuf.Field("type", "CardanoTxAuxiliaryDataSupplementType", repeated=False, required=True), 1: protobuf.Field("type", "CardanoTxAuxiliaryDataSupplementType", repeated=False, required=True),
2: protobuf.Field("auxiliary_data_hash", "bytes", repeated=False, required=False, default=None), 2: protobuf.Field("auxiliary_data_hash", "bytes", repeated=False, required=False, default=None),
3: protobuf.Field("governance_signature", "bytes", repeated=False, required=False, default=None), 3: protobuf.Field("cvote_registration_signature", "bytes", repeated=False, required=False, default=None),
} }
def __init__( def __init__(
@ -2787,11 +2787,11 @@ class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
*, *,
type: "CardanoTxAuxiliaryDataSupplementType", type: "CardanoTxAuxiliaryDataSupplementType",
auxiliary_data_hash: Optional["bytes"] = None, auxiliary_data_hash: Optional["bytes"] = None,
governance_signature: Optional["bytes"] = None, cvote_registration_signature: Optional["bytes"] = None,
) -> None: ) -> None:
self.type = type self.type = type
self.auxiliary_data_hash = auxiliary_data_hash self.auxiliary_data_hash = auxiliary_data_hash
self.governance_signature = governance_signature self.cvote_registration_signature = cvote_registration_signature
class CardanoTxWitnessRequest(protobuf.MessageType): class CardanoTxWitnessRequest(protobuf.MessageType):

View File

@ -159,8 +159,10 @@ def _transform_expected_result(result):
"type": supplement["type"], "type": supplement["type"],
"auxiliary_data_hash": bytes.fromhex(supplement["auxiliary_data_hash"]), "auxiliary_data_hash": bytes.fromhex(supplement["auxiliary_data_hash"]),
} }
if governance_signature := supplement.get("governance_signature"): if cvote_registration_signature := supplement.get(
"cvote_registration_signature"
):
transformed_result["auxiliary_data_supplement"][ transformed_result["auxiliary_data_supplement"][
"governance_signature" "cvote_registration_signature"
] = bytes.fromhex(governance_signature) ] = bytes.fromhex(cvote_registration_signature)
return transformed_result return transformed_result