mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
chore(cardano): replace governance by cvote
This commit is contained in:
parent
764e3c8d75
commit
2011ffe9c9
@ -66,10 +66,10 @@ enum CardanoPoolRelayType {
|
||||
|
||||
enum CardanoTxAuxiliaryDataSupplementType {
|
||||
NONE = 0;
|
||||
GOVERNANCE_REGISTRATION_SIGNATURE = 1;
|
||||
CVOTE_REGISTRATION_SIGNATURE = 1;
|
||||
}
|
||||
|
||||
enum CardanoGovernanceRegistrationFormat {
|
||||
enum CardanoCVoteRegistrationFormat {
|
||||
CIP15 = 0;
|
||||
CIP36 = 1;
|
||||
}
|
||||
@ -360,7 +360,7 @@ message CardanoTxWithdrawal {
|
||||
/**
|
||||
* @embed
|
||||
*/
|
||||
message CardanoGovernanceRegistrationDelegation {
|
||||
message CardanoCVoteRegistrationDelegation {
|
||||
required bytes voting_public_key = 1;
|
||||
required uint32 weight = 2;
|
||||
}
|
||||
@ -368,13 +368,13 @@ message CardanoGovernanceRegistrationDelegation {
|
||||
/**
|
||||
* @embed
|
||||
*/
|
||||
message CardanoGovernanceRegistrationParametersType {
|
||||
message CardanoCVoteRegistrationParametersType {
|
||||
optional bytes voting_public_key = 1; // mutually exclusive with delegations
|
||||
repeated uint32 staking_path = 2;
|
||||
optional CardanoAddressParametersType reward_address_parameters = 3; // mutually exclusive with reward_address
|
||||
required uint64 nonce = 4;
|
||||
optional CardanoGovernanceRegistrationFormat format = 5 [default=CIP15];
|
||||
repeated CardanoGovernanceRegistrationDelegation delegations = 6; // mutually exclusive with voting_public_key; max 32 delegations
|
||||
optional CardanoCVoteRegistrationFormat format = 5 [default=CIP15];
|
||||
repeated CardanoCVoteRegistrationDelegation delegations = 6; // mutually exclusive with voting_public_key; max 32 delegations
|
||||
optional uint64 voting_purpose = 7;
|
||||
optional string reward_address = 8; // mutually exclusive with reward_address_parameters
|
||||
}
|
||||
@ -385,7 +385,7 @@ message CardanoGovernanceRegistrationParametersType {
|
||||
* @next CardanoTxAuxiliaryDataSupplement
|
||||
*/
|
||||
message CardanoTxAuxiliaryData {
|
||||
optional CardanoGovernanceRegistrationParametersType governance_registration_parameters = 1;
|
||||
optional CardanoCVoteRegistrationParametersType cvote_registration_parameters = 1;
|
||||
optional bytes hash = 2;
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ message CardanoTxItemAck {
|
||||
message CardanoTxAuxiliaryDataSupplement {
|
||||
required CardanoTxAuxiliaryDataSupplementType type = 1;
|
||||
optional bytes auxiliary_data_hash = 2;
|
||||
optional bytes governance_signature = 3;
|
||||
optional bytes cvote_registration_signature = 3;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1299,7 +1299,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "transaction with governance registration containing byron reward address",
|
||||
"description": "transaction with cvote registration containing byron reward address",
|
||||
"parameters": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1309,7 +1309,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"voting_public_key": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7",
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1359,7 +1359,7 @@
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"hash": "ea4c91860dd5ec5449f8f985d227946ff39086b17f10b5afb93d12ee87050b6a",
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1409,7 +1409,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
|
40
common/tests/fixtures/cardano/sign_tx.json
vendored
40
common/tests/fixtures/cardano/sign_tx.json
vendored
@ -1002,7 +1002,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "transaction with CIP15 governance registration",
|
||||
"description": "transaction with CIP15 registration",
|
||||
"parameters": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1012,7 +1012,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
@ -1060,12 +1060,12 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1075,7 +1075,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
"addressType": 0,
|
||||
@ -1133,12 +1133,12 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1148,7 +1148,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
"addressType": 0,
|
||||
@ -1203,12 +1203,12 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1218,7 +1218,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"nonce": 22634813,
|
||||
"format": 1,
|
||||
@ -1268,12 +1268,12 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1283,7 +1283,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
"addressType": 14,
|
||||
@ -1336,12 +1336,12 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -1351,7 +1351,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"nonce": 22634813,
|
||||
"format": 1,
|
||||
@ -1401,7 +1401,7 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"auxiliary_data_hash": "eb63742c2908aedcc6db3df903377f07302828c0e0eb4a01d38c9049845780c5",
|
||||
"governance_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d"
|
||||
"cvote_registration_signature": "97e7fd23473f984454ea6d17f8f3f4c7019fa63b87596356db89f7906bb1ce6e51c7d0efe68772d6a6cd83011b1777912cae2cc94661148af51d8f1ba791fe0d"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1932,7 +1932,7 @@
|
||||
}
|
||||
],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
"addressType": 0,
|
||||
@ -1992,7 +1992,7 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"auxiliary_data_hash": "544c9ae849c82e31224865ff936decc6160047409eee4a6b4178b729fe3d286c",
|
||||
"governance_signature": "3064949c9f186138f95e228075d0119dd5cb50e1b7e75d24d569fa547e018a597615da7c79a39ca8e394ee1ba8acb83e70be80f37e69aef3b86e7c4a6bd44903"
|
||||
"cvote_registration_signature": "3064949c9f186138f95e228075d0119dd5cb50e1b7e75d24d569fa547e018a597615da7c79a39ca8e394ee1ba8acb83e70be80f37e69aef3b86e7c4a6bd44903"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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": {
|
||||
"protocol_magic": 764824073,
|
||||
"network_id": 1,
|
||||
@ -467,7 +467,7 @@
|
||||
"certificates": [],
|
||||
"withdrawals": [],
|
||||
"auxiliary_data": {
|
||||
"governance_registration_parameters": {
|
||||
"cvote_registration_parameters": {
|
||||
"staking_path": "m/1852'/1815'/0'/2/0",
|
||||
"reward_address_parameters": {
|
||||
"addressType": 0,
|
||||
@ -525,7 +525,7 @@
|
||||
"auxiliary_data_supplement": {
|
||||
"type": 1,
|
||||
"auxiliary_data_hash": "9d4c00f5b5b67760931fd7ed9850ff8e14dcdf957685191ab4bc755c52f0ed56",
|
||||
"governance_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001"
|
||||
"cvote_registration_signature": "2671b8e668ffce235647ac89deda6cc222e7b31a3d44606c2723fcf711b29f9af1e30b0c6b4f87ba37ddf9f6adf0226c39c09e655255890644a3dc4e64c3a001"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,12 +353,12 @@ if not utils.BITCOIN_ONLY:
|
||||
import trezor.enums.BinanceTimeInForce
|
||||
trezor.enums.CardanoAddressType
|
||||
import trezor.enums.CardanoAddressType
|
||||
trezor.enums.CardanoCVoteRegistrationFormat
|
||||
import trezor.enums.CardanoCVoteRegistrationFormat
|
||||
trezor.enums.CardanoCertificateType
|
||||
import trezor.enums.CardanoCertificateType
|
||||
trezor.enums.CardanoDerivationType
|
||||
import trezor.enums.CardanoDerivationType
|
||||
trezor.enums.CardanoGovernanceRegistrationFormat
|
||||
import trezor.enums.CardanoGovernanceRegistrationFormat
|
||||
trezor.enums.CardanoNativeScriptHashDisplayFormat
|
||||
import trezor.enums.CardanoNativeScriptHashDisplayFormat
|
||||
trezor.enums.CardanoNativeScriptType
|
||||
|
@ -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.
|
||||
|
||||
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
|
||||
|
||||
|
@ -233,13 +233,13 @@ def validate_output_address_parameters(
|
||||
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,
|
||||
) -> None:
|
||||
validate_address_parameters(parameters)
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
@ -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
|
||||
) -> None:
|
||||
address_type = _validate_and_get_type(address, protocol_magic, network_id)
|
||||
|
@ -2,7 +2,7 @@ from micropython import const
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from trezor.crypto import hashlib
|
||||
from trezor.enums import CardanoAddressType, CardanoGovernanceRegistrationFormat
|
||||
from trezor.enums import CardanoAddressType, CardanoCVoteRegistrationFormat
|
||||
|
||||
from apps.common import cbor
|
||||
|
||||
@ -12,8 +12,8 @@ from .helpers.utils import derive_public_key
|
||||
|
||||
if TYPE_CHECKING:
|
||||
Delegations = list[tuple[bytes, int]]
|
||||
GovernanceRegistrationPayload = dict[int, Delegations | bytes | int]
|
||||
SignedGovernanceRegistrationPayload = tuple[GovernanceRegistrationPayload, bytes]
|
||||
CVoteRegistrationPayload = dict[int, Delegations | bytes | int]
|
||||
SignedCVoteRegistrationPayload = tuple[CVoteRegistrationPayload, bytes]
|
||||
|
||||
from trezor import messages
|
||||
from trezor.wire import Context
|
||||
@ -21,11 +21,11 @@ if TYPE_CHECKING:
|
||||
from . import seed
|
||||
|
||||
_AUXILIARY_DATA_HASH_SIZE = const(32)
|
||||
_GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH = const(32)
|
||||
_GOVERNANCE_REGISTRATION_HASH_SIZE = const(32)
|
||||
_CVOTE_PUBLIC_KEY_LENGTH = const(32)
|
||||
_CVOTE_REGISTRATION_HASH_SIZE = const(32)
|
||||
|
||||
_METADATA_KEY_GOVERNANCE_REGISTRATION = const(61284)
|
||||
_METADATA_KEY_GOVERNANCE_REGISTRATION_SIGNATURE = const(61285)
|
||||
_METADATA_KEY_CVOTE_REGISTRATION = const(61284)
|
||||
_METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE = const(61285)
|
||||
|
||||
_MAX_DELEGATION_COUNT = const(32)
|
||||
_DEFAULT_VOTING_PURPOSE = const(0)
|
||||
@ -48,18 +48,18 @@ def validate(
|
||||
fields_provided += 1
|
||||
# _validate_hash
|
||||
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
|
||||
_validate_governance_registration_parameters(
|
||||
auxiliary_data.governance_registration_parameters,
|
||||
_validate_cvote_registration_parameters(
|
||||
auxiliary_data.cvote_registration_parameters,
|
||||
protocol_magic,
|
||||
network_id,
|
||||
)
|
||||
assert_cond(fields_provided == 1)
|
||||
|
||||
|
||||
def _validate_governance_registration_parameters(
|
||||
parameters: messages.CardanoGovernanceRegistrationParametersType,
|
||||
def _validate_cvote_registration_parameters(
|
||||
parameters: messages.CardanoCVoteRegistrationParametersType,
|
||||
protocol_magic: int,
|
||||
network_id: int,
|
||||
) -> None:
|
||||
@ -69,7 +69,7 @@ def _validate_governance_registration_parameters(
|
||||
_validate_voting_public_key(parameters.voting_public_key)
|
||||
if parameters.delegations:
|
||||
voting_key_fields_provided += 1
|
||||
assert_cond(parameters.format == CardanoGovernanceRegistrationFormat.CIP36)
|
||||
assert_cond(parameters.format == CardanoCVoteRegistrationFormat.CIP36)
|
||||
_validate_delegations(parameters.delegations)
|
||||
assert_cond(voting_key_fields_provided == 1)
|
||||
|
||||
@ -78,26 +78,26 @@ def _validate_governance_registration_parameters(
|
||||
reward_address_fields_provided = 0
|
||||
if parameters.reward_address is not None:
|
||||
reward_address_fields_provided += 1
|
||||
addresses.validate_governance_reward_address(
|
||||
addresses.validate_cvote_reward_address(
|
||||
parameters.reward_address, protocol_magic, network_id
|
||||
)
|
||||
if parameters.reward_address_parameters:
|
||||
reward_address_fields_provided += 1
|
||||
addresses.validate_governance_reward_address_parameters(
|
||||
addresses.validate_cvote_reward_address_parameters(
|
||||
parameters.reward_address_parameters
|
||||
)
|
||||
assert_cond(reward_address_fields_provided == 1)
|
||||
|
||||
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:
|
||||
assert_cond(len(key) == _GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH)
|
||||
assert_cond(len(key) == _CVOTE_PUBLIC_KEY_LENGTH)
|
||||
|
||||
|
||||
def _validate_delegations(
|
||||
delegations: list[messages.CardanoGovernanceDelegation],
|
||||
delegations: list[messages.CardanoCVoteDelegation],
|
||||
) -> None:
|
||||
assert_cond(len(delegations) <= _MAX_DELEGATION_COUNT)
|
||||
for delegation in delegations:
|
||||
@ -105,9 +105,9 @@ def _validate_delegations(
|
||||
|
||||
|
||||
def _get_voting_purpose_to_serialize(
|
||||
parameters: messages.CardanoGovernanceRegistrationParametersType,
|
||||
parameters: messages.CardanoCVoteRegistrationParametersType,
|
||||
) -> int | None:
|
||||
if parameters.format == CardanoGovernanceRegistrationFormat.CIP15:
|
||||
if parameters.format == CardanoCVoteRegistrationFormat.CIP15:
|
||||
return None
|
||||
if parameters.voting_purpose is None:
|
||||
return _DEFAULT_VOTING_PURPOSE
|
||||
@ -118,13 +118,13 @@ async def show(
|
||||
ctx: Context,
|
||||
keychain: seed.Keychain,
|
||||
auxiliary_data_hash: bytes,
|
||||
parameters: messages.CardanoGovernanceRegistrationParametersType | None,
|
||||
parameters: messages.CardanoCVoteRegistrationParametersType | None,
|
||||
protocol_magic: int,
|
||||
network_id: int,
|
||||
should_show_details: bool,
|
||||
) -> None:
|
||||
if parameters:
|
||||
await _show_governance_registration(
|
||||
await _show_cvote_registration(
|
||||
ctx,
|
||||
keychain,
|
||||
parameters,
|
||||
@ -138,17 +138,17 @@ async def show(
|
||||
|
||||
|
||||
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
|
||||
# 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.
|
||||
return address_type not in addresses.ADDRESS_TYPES_PAYMENT
|
||||
|
||||
|
||||
async def _show_governance_registration(
|
||||
async def _show_cvote_registration(
|
||||
ctx: Context,
|
||||
keychain: seed.Keychain,
|
||||
parameters: messages.CardanoGovernanceRegistrationParametersType,
|
||||
parameters: messages.CardanoCVoteRegistrationParametersType,
|
||||
protocol_magic: int,
|
||||
network_id: int,
|
||||
should_show_details: bool,
|
||||
@ -158,9 +158,9 @@ async def _show_governance_registration(
|
||||
|
||||
for delegation in parameters.delegations:
|
||||
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
|
||||
)
|
||||
|
||||
@ -168,17 +168,17 @@ async def _show_governance_registration(
|
||||
show_payment_warning = _should_show_payment_warning(
|
||||
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
|
||||
)
|
||||
else:
|
||||
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_payment_warning = _should_show_payment_warning(
|
||||
address_parameters.address_type
|
||||
)
|
||||
await layout.show_governance_registration_reward_credentials(
|
||||
await layout.show_cvote_registration_reward_credentials(
|
||||
ctx,
|
||||
Credential.payment_credential(address_parameters),
|
||||
Credential.stake_credential(address_parameters),
|
||||
@ -189,14 +189,14 @@ async def _show_governance_registration(
|
||||
encoded_public_key: str | None = None
|
||||
if parameters.voting_public_key:
|
||||
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 = (
|
||||
_get_voting_purpose_to_serialize(parameters) if should_show_details else None
|
||||
)
|
||||
|
||||
await layout.confirm_governance_registration(
|
||||
await layout.confirm_cvote_registration(
|
||||
ctx,
|
||||
encoded_public_key,
|
||||
parameters.staking_path,
|
||||
@ -214,20 +214,20 @@ def get_hash_and_supplement(
|
||||
from trezor.enums import CardanoTxAuxiliaryDataSupplementType
|
||||
from trezor import messages
|
||||
|
||||
if parameters := auxiliary_data.governance_registration_parameters:
|
||||
if parameters := auxiliary_data.cvote_registration_parameters:
|
||||
(
|
||||
governance_registration_payload,
|
||||
governance_signature,
|
||||
) = _get_signed_governance_registration_payload(
|
||||
cvote_registration_payload,
|
||||
cvote_registration_signature,
|
||||
) = _get_signed_cvote_registration_payload(
|
||||
keychain, parameters, protocol_magic, network_id
|
||||
)
|
||||
auxiliary_data_hash = _get_governance_registration_hash(
|
||||
governance_registration_payload, governance_signature
|
||||
auxiliary_data_hash = _get_cvote_registration_hash(
|
||||
cvote_registration_payload, cvote_registration_signature
|
||||
)
|
||||
auxiliary_data_supplement = messages.CardanoTxAuxiliaryDataSupplement(
|
||||
type=CardanoTxAuxiliaryDataSupplementType.GOVERNANCE_REGISTRATION_SIGNATURE,
|
||||
type=CardanoTxAuxiliaryDataSupplementType.CVOTE_REGISTRATION_SIGNATURE,
|
||||
auxiliary_data_hash=auxiliary_data_hash,
|
||||
governance_signature=governance_signature,
|
||||
cvote_registration_signature=cvote_registration_signature,
|
||||
)
|
||||
return auxiliary_data_hash, auxiliary_data_supplement
|
||||
else:
|
||||
@ -237,15 +237,15 @@ def get_hash_and_supplement(
|
||||
)
|
||||
|
||||
|
||||
def _get_governance_registration_hash(
|
||||
governance_registration_payload: GovernanceRegistrationPayload,
|
||||
governance_registration_payload_signature: bytes,
|
||||
def _get_cvote_registration_hash(
|
||||
cvote_registration_payload: CVoteRegistrationPayload,
|
||||
cvote_registration_payload_signature: bytes,
|
||||
) -> bytes:
|
||||
# _cborize_catalyst_registration
|
||||
governance_registration_signature = {1: governance_registration_payload_signature}
|
||||
cvote_registration_signature = {1: cvote_registration_payload_signature}
|
||||
cborized_catalyst_registration = {
|
||||
_METADATA_KEY_GOVERNANCE_REGISTRATION: governance_registration_payload,
|
||||
_METADATA_KEY_GOVERNANCE_REGISTRATION_SIGNATURE: governance_registration_signature,
|
||||
_METADATA_KEY_CVOTE_REGISTRATION: cvote_registration_payload,
|
||||
_METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE: cvote_registration_signature,
|
||||
}
|
||||
|
||||
# _get_hash
|
||||
@ -262,12 +262,12 @@ def _get_governance_registration_hash(
|
||||
).digest()
|
||||
|
||||
|
||||
def _get_signed_governance_registration_payload(
|
||||
def _get_signed_cvote_registration_payload(
|
||||
keychain: seed.Keychain,
|
||||
parameters: messages.CardanoGovernanceRegistrationParametersType,
|
||||
parameters: messages.CardanoCVoteRegistrationParametersType,
|
||||
protocol_magic: int,
|
||||
network_id: int,
|
||||
) -> SignedGovernanceRegistrationPayload:
|
||||
) -> SignedCVoteRegistrationPayload:
|
||||
delegations_or_key: Delegations | bytes
|
||||
if len(parameters.delegations) > 0:
|
||||
delegations_or_key = [
|
||||
@ -277,7 +277,7 @@ def _get_signed_governance_registration_payload(
|
||||
elif parameters.voting_public_key:
|
||||
delegations_or_key = parameters.voting_public_key
|
||||
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)
|
||||
|
||||
@ -285,7 +285,7 @@ def _get_signed_governance_registration_payload(
|
||||
reward_address = addresses.get_bytes_unsafe(parameters.reward_address)
|
||||
else:
|
||||
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(
|
||||
keychain,
|
||||
address_parameters,
|
||||
@ -295,7 +295,7 @@ def _get_signed_governance_registration_payload(
|
||||
|
||||
voting_purpose = _get_voting_purpose_to_serialize(parameters)
|
||||
|
||||
payload: GovernanceRegistrationPayload = {
|
||||
payload: CVoteRegistrationPayload = {
|
||||
1: delegations_or_key,
|
||||
2: staking_key,
|
||||
3: reward_address,
|
||||
@ -304,7 +304,7 @@ def _get_signed_governance_registration_payload(
|
||||
if voting_purpose is not None:
|
||||
payload[5] = voting_purpose
|
||||
|
||||
signature = _create_governance_registration_payload_signature(
|
||||
signature = _create_cvote_registration_payload_signature(
|
||||
keychain,
|
||||
payload,
|
||||
parameters.staking_path,
|
||||
@ -313,24 +313,24 @@ def _get_signed_governance_registration_payload(
|
||||
return payload, signature
|
||||
|
||||
|
||||
def _create_governance_registration_payload_signature(
|
||||
def _create_cvote_registration_payload_signature(
|
||||
keychain: seed.Keychain,
|
||||
governance_registration_payload: GovernanceRegistrationPayload,
|
||||
cvote_registration_payload: CVoteRegistrationPayload,
|
||||
path: list[int],
|
||||
) -> bytes:
|
||||
from trezor.crypto.curve import ed25519
|
||||
|
||||
node = keychain.derive(path)
|
||||
|
||||
encoded_governance_registration = cbor.encode(
|
||||
{_METADATA_KEY_GOVERNANCE_REGISTRATION: governance_registration_payload}
|
||||
encoded_cvote_registration = cbor.encode(
|
||||
{_METADATA_KEY_CVOTE_REGISTRATION: cvote_registration_payload}
|
||||
)
|
||||
|
||||
governance_registration_hash = hashlib.blake2b(
|
||||
data=encoded_governance_registration,
|
||||
outlen=_GOVERNANCE_REGISTRATION_HASH_SIZE,
|
||||
cvote_registration_hash = hashlib.blake2b(
|
||||
data=encoded_cvote_registration,
|
||||
outlen=_CVOTE_REGISTRATION_HASH_SIZE,
|
||||
).digest()
|
||||
|
||||
return ed25519.sign_ext(
|
||||
node.private_key(), node.private_key_ext(), governance_registration_hash
|
||||
node.private_key(), node.private_key_ext(), cvote_registration_hash
|
||||
)
|
||||
|
@ -7,7 +7,7 @@ HRP_ADDRESS = "addr"
|
||||
HRP_TESTNET_ADDRESS = "addr_test"
|
||||
HRP_REWARD_ADDRESS = "stake"
|
||||
HRP_TESTNET_REWARD_ADDRESS = "stake_test"
|
||||
HRP_GOVERNANCE_PUBLIC_KEY = "cvote_vk"
|
||||
HRP_CVOTE_PUBLIC_KEY = "cvote_vk"
|
||||
HRP_SCRIPT_HASH = "script"
|
||||
HRP_KEY_HASH = "addr_vkh"
|
||||
HRP_SHARED_KEY_HASH = "addr_shared_vkh"
|
||||
|
@ -68,7 +68,7 @@ CERTIFICATE_TYPE_NAMES = {
|
||||
|
||||
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."
|
||||
)
|
||||
|
||||
@ -357,26 +357,24 @@ async def show_device_owned_output_credentials(
|
||||
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,
|
||||
payment_credential: Credential,
|
||||
stake_credential: Credential,
|
||||
show_both_credentials: bool,
|
||||
show_payment_warning: bool,
|
||||
) -> 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(
|
||||
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:
|
||||
extra_text = (
|
||||
GOVERNANCE_REWARD_ELIGIBILITY_WARNING if show_payment_warning else None
|
||||
)
|
||||
extra_text = CVOTE_REWARD_ELIGIBILITY_WARNING if show_payment_warning else None
|
||||
await _show_credential(
|
||||
ctx,
|
||||
stake_credential,
|
||||
intro_text,
|
||||
purpose="gov_reg_reward_address",
|
||||
purpose="cvote_reg_reward_address",
|
||||
extra_text=extra_text,
|
||||
)
|
||||
|
||||
@ -385,13 +383,13 @@ async def _show_credential(
|
||||
ctx: Context,
|
||||
credential: Credential,
|
||||
intro_text: str,
|
||||
purpose: Literal["address", "output", "gov_reg_reward_address"],
|
||||
purpose: Literal["address", "output", "cvote_reg_reward_address"],
|
||||
extra_text: str | None = None,
|
||||
) -> None:
|
||||
title = {
|
||||
"address": f"{ADDRESS_TYPE_NAMES[credential.address_type]} address",
|
||||
"output": "Confirm transaction",
|
||||
"gov_reg_reward_address": "Confirm transaction",
|
||||
"cvote_reg_reward_address": "Confirm transaction",
|
||||
}[purpose]
|
||||
|
||||
props: list[PropertyType] = []
|
||||
@ -414,8 +412,8 @@ async def _show_credential(
|
||||
append((None, "Path is unusual."))
|
||||
if credential.is_mismatch:
|
||||
append((None, "Credential doesn't match payment credential."))
|
||||
if credential.is_reward and purpose != "gov_reg_reward_address":
|
||||
# for governance registrations, this is handled by extra_text at the end
|
||||
if credential.is_reward and purpose != "cvote_reg_reward_address":
|
||||
# for cvote registrations, this is handled by extra_text at the end
|
||||
append(("Address is a reward address.", None))
|
||||
if credential.is_no_staking:
|
||||
append(
|
||||
@ -775,13 +773,13 @@ def _format_stake_credential(
|
||||
raise ValueError
|
||||
|
||||
|
||||
async def confirm_governance_registration_delegation(
|
||||
async def confirm_cvote_registration_delegation(
|
||||
ctx: Context,
|
||||
public_key: str,
|
||||
weight: int,
|
||||
) -> None:
|
||||
props: list[PropertyType] = [
|
||||
("Governance voting key registration", None),
|
||||
("Vote key registration (CIP-36)", None),
|
||||
("Delegating to:", public_key),
|
||||
]
|
||||
if weight is not None:
|
||||
@ -789,41 +787,41 @@ async def confirm_governance_registration_delegation(
|
||||
|
||||
await confirm_properties(
|
||||
ctx,
|
||||
"confirm_governance_registration_delegation",
|
||||
"confirm_cvote_registration_delegation",
|
||||
title="Confirm transaction",
|
||||
props=props,
|
||||
br_code=ButtonRequestType.Other,
|
||||
)
|
||||
|
||||
|
||||
async def confirm_governance_registration_reward_address(
|
||||
async def confirm_cvote_registration_reward_address(
|
||||
ctx: Context,
|
||||
reward_address: str,
|
||||
should_show_payment_warning: bool,
|
||||
) -> None:
|
||||
props = [
|
||||
("Governance voting key registration", None),
|
||||
("Vote key registration (CIP-36)", None),
|
||||
("Rewards go to:", reward_address),
|
||||
]
|
||||
if should_show_payment_warning:
|
||||
props.append((GOVERNANCE_REWARD_ELIGIBILITY_WARNING, None))
|
||||
props.append((CVOTE_REWARD_ELIGIBILITY_WARNING, None))
|
||||
await confirm_properties(
|
||||
ctx,
|
||||
"confirm_governance_registration_reward_address",
|
||||
"confirm_cvote_registration_reward_address",
|
||||
title="Confirm transaction",
|
||||
props=props,
|
||||
br_code=ButtonRequestType.Other,
|
||||
)
|
||||
|
||||
|
||||
async def confirm_governance_registration(
|
||||
async def confirm_cvote_registration(
|
||||
ctx: Context,
|
||||
public_key: str | None,
|
||||
staking_path: list[int],
|
||||
nonce: int,
|
||||
voting_purpose: int | 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:
|
||||
props.append(("Voting public key:", public_key))
|
||||
props.extend(
|
||||
@ -845,7 +843,7 @@ async def confirm_governance_registration(
|
||||
|
||||
await confirm_properties(
|
||||
ctx,
|
||||
"confirm_governance_registration",
|
||||
"confirm_cvote_registration",
|
||||
title="Confirm transaction",
|
||||
props=props,
|
||||
br_code=ButtonRequestType.Other,
|
||||
|
@ -836,7 +836,7 @@ class Signer:
|
||||
self.ctx,
|
||||
self.keychain,
|
||||
auxiliary_data_hash,
|
||||
data.governance_registration_parameters,
|
||||
data.cvote_registration_parameters,
|
||||
msg.protocol_magic,
|
||||
msg.network_id,
|
||||
self.should_show_details,
|
||||
|
@ -3,4 +3,4 @@
|
||||
# isort:skip_file
|
||||
|
||||
NONE = 0
|
||||
GOVERNANCE_REGISTRATION_SIGNATURE = 1
|
||||
CVOTE_REGISTRATION_SIGNATURE = 1
|
||||
|
@ -381,9 +381,9 @@ if TYPE_CHECKING:
|
||||
|
||||
class CardanoTxAuxiliaryDataSupplementType(IntEnum):
|
||||
NONE = 0
|
||||
GOVERNANCE_REGISTRATION_SIGNATURE = 1
|
||||
CVOTE_REGISTRATION_SIGNATURE = 1
|
||||
|
||||
class CardanoGovernanceRegistrationFormat(IntEnum):
|
||||
class CardanoCVoteRegistrationFormat(IntEnum):
|
||||
CIP15 = 0
|
||||
CIP36 = 1
|
||||
|
||||
|
@ -24,9 +24,9 @@ if TYPE_CHECKING:
|
||||
from trezor.enums import ButtonRequestType # noqa: F401
|
||||
from trezor.enums import Capability # 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 CardanoDerivationType # noqa: F401
|
||||
from trezor.enums import CardanoGovernanceRegistrationFormat # noqa: F401
|
||||
from trezor.enums import CardanoNativeScriptHashDisplayFormat # noqa: F401
|
||||
from trezor.enums import CardanoNativeScriptType # 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"]:
|
||||
return isinstance(msg, cls)
|
||||
|
||||
class CardanoGovernanceRegistrationDelegation(protobuf.MessageType):
|
||||
class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
|
||||
voting_public_key: "bytes"
|
||||
weight: "int"
|
||||
|
||||
@ -1651,16 +1651,16 @@ if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoGovernanceRegistrationDelegation"]:
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoCVoteRegistrationDelegation"]:
|
||||
return isinstance(msg, cls)
|
||||
|
||||
class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
|
||||
class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
|
||||
voting_public_key: "bytes | None"
|
||||
staking_path: "list[int]"
|
||||
reward_address_parameters: "CardanoAddressParametersType | None"
|
||||
nonce: "int"
|
||||
format: "CardanoGovernanceRegistrationFormat"
|
||||
delegations: "list[CardanoGovernanceRegistrationDelegation]"
|
||||
format: "CardanoCVoteRegistrationFormat"
|
||||
delegations: "list[CardanoCVoteRegistrationDelegation]"
|
||||
voting_purpose: "int | None"
|
||||
reward_address: "str | None"
|
||||
|
||||
@ -1669,27 +1669,27 @@ if TYPE_CHECKING:
|
||||
*,
|
||||
nonce: "int",
|
||||
staking_path: "list[int] | None" = None,
|
||||
delegations: "list[CardanoGovernanceRegistrationDelegation] | None" = None,
|
||||
delegations: "list[CardanoCVoteRegistrationDelegation] | None" = None,
|
||||
voting_public_key: "bytes | None" = None,
|
||||
reward_address_parameters: "CardanoAddressParametersType | None" = None,
|
||||
format: "CardanoGovernanceRegistrationFormat | None" = None,
|
||||
format: "CardanoCVoteRegistrationFormat | None" = None,
|
||||
voting_purpose: "int | None" = None,
|
||||
reward_address: "str | None" = None,
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoGovernanceRegistrationParametersType"]:
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["CardanoCVoteRegistrationParametersType"]:
|
||||
return isinstance(msg, cls)
|
||||
|
||||
class CardanoTxAuxiliaryData(protobuf.MessageType):
|
||||
governance_registration_parameters: "CardanoGovernanceRegistrationParametersType | None"
|
||||
cvote_registration_parameters: "CardanoCVoteRegistrationParametersType | None"
|
||||
hash: "bytes | None"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
governance_registration_parameters: "CardanoGovernanceRegistrationParametersType | None" = None,
|
||||
cvote_registration_parameters: "CardanoCVoteRegistrationParametersType | None" = None,
|
||||
hash: "bytes | None" = None,
|
||||
) -> None:
|
||||
pass
|
||||
@ -1769,14 +1769,14 @@ if TYPE_CHECKING:
|
||||
class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
|
||||
type: "CardanoTxAuxiliaryDataSupplementType"
|
||||
auxiliary_data_hash: "bytes | None"
|
||||
governance_signature: "bytes | None"
|
||||
cvote_registration_signature: "bytes | None"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
type: "CardanoTxAuxiliaryDataSupplementType",
|
||||
auxiliary_data_hash: "bytes | None" = None,
|
||||
governance_signature: "bytes | None" = None,
|
||||
cvote_registration_signature: "bytes | None" = None,
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
|
@ -61,11 +61,11 @@ REQUIRED_FIELDS_POOL_PARAMETERS = (
|
||||
"owners",
|
||||
)
|
||||
REQUIRED_FIELDS_TOKEN_GROUP = ("policy_id", "tokens")
|
||||
REQUIRED_FIELDS_GOVERNANCE_REGISTRATION = (
|
||||
REQUIRED_FIELDS_CVOTE_REGISTRATION = (
|
||||
"staking_path",
|
||||
"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"
|
||||
|
||||
@ -562,58 +562,53 @@ def parse_auxiliary_data(
|
||||
# include all provided fields so we can test validation in FW
|
||||
hash = parse_optional_bytes(auxiliary_data.get("hash"))
|
||||
|
||||
governance_registration_parameters = None
|
||||
if "governance_registration_parameters" in auxiliary_data:
|
||||
governance_registration = auxiliary_data["governance_registration_parameters"]
|
||||
if not all(
|
||||
k in governance_registration
|
||||
for k in REQUIRED_FIELDS_GOVERNANCE_REGISTRATION
|
||||
):
|
||||
cvote_registration_parameters = None
|
||||
if "cvote_registration_parameters" in auxiliary_data:
|
||||
cvote_registration = auxiliary_data["cvote_registration_parameters"]
|
||||
if not all(k in cvote_registration for k in REQUIRED_FIELDS_CVOTE_REGISTRATION):
|
||||
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
|
||||
|
||||
serialization_format = governance_registration.get("format")
|
||||
serialization_format = cvote_registration.get("format")
|
||||
|
||||
delegations = []
|
||||
for delegation in governance_registration.get("delegations", []):
|
||||
if not all(k in delegation for k in REQUIRED_FIELDS_GOVERNANCE_DELEGATION):
|
||||
for delegation in cvote_registration.get("delegations", []):
|
||||
if not all(k in delegation for k in REQUIRED_FIELDS_CVOTE_DELEGATION):
|
||||
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
|
||||
delegations.append(
|
||||
messages.CardanoGovernanceRegistrationDelegation(
|
||||
messages.CardanoCVoteRegistrationDelegation(
|
||||
voting_public_key=bytes.fromhex(delegation["voting_public_key"]),
|
||||
weight=int(delegation["weight"]),
|
||||
)
|
||||
)
|
||||
|
||||
voting_purpose = None
|
||||
if serialization_format == messages.CardanoGovernanceRegistrationFormat.CIP36:
|
||||
voting_purpose = governance_registration.get("voting_purpose")
|
||||
if serialization_format == messages.CardanoCVoteRegistrationFormat.CIP36:
|
||||
voting_purpose = cvote_registration.get("voting_purpose")
|
||||
|
||||
governance_registration_parameters = (
|
||||
messages.CardanoGovernanceRegistrationParametersType(
|
||||
voting_public_key=parse_optional_bytes(
|
||||
governance_registration.get("voting_public_key")
|
||||
),
|
||||
staking_path=tools.parse_path(governance_registration["staking_path"]),
|
||||
nonce=governance_registration["nonce"],
|
||||
reward_address=governance_registration.get("reward_address"),
|
||||
reward_address_parameters=_parse_address_parameters(
|
||||
governance_registration["reward_address_parameters"],
|
||||
str(AUXILIARY_DATA_MISSING_FIELDS_ERROR),
|
||||
)
|
||||
if "reward_address_parameters" in governance_registration
|
||||
else None,
|
||||
format=serialization_format,
|
||||
delegations=delegations,
|
||||
voting_purpose=voting_purpose,
|
||||
cvote_registration_parameters = messages.CardanoCVoteRegistrationParametersType(
|
||||
voting_public_key=parse_optional_bytes(
|
||||
cvote_registration.get("voting_public_key")
|
||||
),
|
||||
staking_path=tools.parse_path(cvote_registration["staking_path"]),
|
||||
nonce=cvote_registration["nonce"],
|
||||
reward_address=cvote_registration.get("reward_address"),
|
||||
reward_address_parameters=_parse_address_parameters(
|
||||
cvote_registration["reward_address_parameters"],
|
||||
str(AUXILIARY_DATA_MISSING_FIELDS_ERROR),
|
||||
)
|
||||
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
|
||||
|
||||
return messages.CardanoTxAuxiliaryData(
|
||||
hash=hash,
|
||||
governance_registration_parameters=governance_registration_parameters,
|
||||
cvote_registration_parameters=cvote_registration_parameters,
|
||||
)
|
||||
|
||||
|
||||
|
@ -162,11 +162,13 @@ def sign_tx(
|
||||
auxiliary_data_supplement["auxiliary_data_hash"] = auxiliary_data_supplement[
|
||||
"auxiliary_data_hash"
|
||||
].hex()
|
||||
governance_signature = auxiliary_data_supplement.get("governance_signature")
|
||||
if governance_signature:
|
||||
cvote_registration_signature = auxiliary_data_supplement.get(
|
||||
"cvote_registration_signature"
|
||||
)
|
||||
if cvote_registration_signature:
|
||||
auxiliary_data_supplement[
|
||||
"governance_signature"
|
||||
] = governance_signature.hex()
|
||||
"cvote_registration_signature"
|
||||
] = cvote_registration_signature.hex()
|
||||
sign_tx_response["auxiliary_data_supplement"] = auxiliary_data_supplement
|
||||
return sign_tx_response
|
||||
|
||||
|
@ -405,10 +405,10 @@ class CardanoPoolRelayType(IntEnum):
|
||||
|
||||
class CardanoTxAuxiliaryDataSupplementType(IntEnum):
|
||||
NONE = 0
|
||||
GOVERNANCE_REGISTRATION_SIGNATURE = 1
|
||||
CVOTE_REGISTRATION_SIGNATURE = 1
|
||||
|
||||
|
||||
class CardanoGovernanceRegistrationFormat(IntEnum):
|
||||
class CardanoCVoteRegistrationFormat(IntEnum):
|
||||
CIP15 = 0
|
||||
CIP36 = 1
|
||||
|
||||
@ -2636,7 +2636,7 @@ class CardanoTxWithdrawal(protobuf.MessageType):
|
||||
self.key_hash = key_hash
|
||||
|
||||
|
||||
class CardanoGovernanceRegistrationDelegation(protobuf.MessageType):
|
||||
class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = None
|
||||
FIELDS = {
|
||||
1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=True),
|
||||
@ -2653,15 +2653,15 @@ class CardanoGovernanceRegistrationDelegation(protobuf.MessageType):
|
||||
self.weight = weight
|
||||
|
||||
|
||||
class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
|
||||
class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = None
|
||||
FIELDS = {
|
||||
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),
|
||||
3: protobuf.Field("reward_address_parameters", "CardanoAddressParametersType", repeated=False, required=False, default=None),
|
||||
4: protobuf.Field("nonce", "uint64", repeated=False, required=True),
|
||||
5: protobuf.Field("format", "CardanoGovernanceRegistrationFormat", repeated=False, required=False, default=CardanoGovernanceRegistrationFormat.CIP15),
|
||||
6: protobuf.Field("delegations", "CardanoGovernanceRegistrationDelegation", repeated=True, required=False, default=None),
|
||||
5: protobuf.Field("format", "CardanoCVoteRegistrationFormat", repeated=False, required=False, default=CardanoCVoteRegistrationFormat.CIP15),
|
||||
6: protobuf.Field("delegations", "CardanoCVoteRegistrationDelegation", repeated=True, 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),
|
||||
}
|
||||
@ -2671,15 +2671,15 @@ class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
|
||||
*,
|
||||
nonce: "int",
|
||||
staking_path: Optional[Sequence["int"]] = None,
|
||||
delegations: Optional[Sequence["CardanoGovernanceRegistrationDelegation"]] = None,
|
||||
delegations: Optional[Sequence["CardanoCVoteRegistrationDelegation"]] = None,
|
||||
voting_public_key: Optional["bytes"] = None,
|
||||
reward_address_parameters: Optional["CardanoAddressParametersType"] = None,
|
||||
format: Optional["CardanoGovernanceRegistrationFormat"] = CardanoGovernanceRegistrationFormat.CIP15,
|
||||
format: Optional["CardanoCVoteRegistrationFormat"] = CardanoCVoteRegistrationFormat.CIP15,
|
||||
voting_purpose: Optional["int"] = None,
|
||||
reward_address: Optional["str"] = None,
|
||||
) -> None:
|
||||
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.voting_public_key = voting_public_key
|
||||
self.reward_address_parameters = reward_address_parameters
|
||||
@ -2691,17 +2691,17 @@ class CardanoGovernanceRegistrationParametersType(protobuf.MessageType):
|
||||
class CardanoTxAuxiliaryData(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 327
|
||||
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),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
governance_registration_parameters: Optional["CardanoGovernanceRegistrationParametersType"] = None,
|
||||
cvote_registration_parameters: Optional["CardanoCVoteRegistrationParametersType"] = None,
|
||||
hash: Optional["bytes"] = None,
|
||||
) -> None:
|
||||
self.governance_registration_parameters = governance_registration_parameters
|
||||
self.cvote_registration_parameters = cvote_registration_parameters
|
||||
self.hash = hash
|
||||
|
||||
|
||||
@ -2779,7 +2779,7 @@ class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
|
||||
FIELDS = {
|
||||
1: protobuf.Field("type", "CardanoTxAuxiliaryDataSupplementType", repeated=False, required=True),
|
||||
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__(
|
||||
@ -2787,11 +2787,11 @@ class CardanoTxAuxiliaryDataSupplement(protobuf.MessageType):
|
||||
*,
|
||||
type: "CardanoTxAuxiliaryDataSupplementType",
|
||||
auxiliary_data_hash: Optional["bytes"] = None,
|
||||
governance_signature: Optional["bytes"] = None,
|
||||
cvote_registration_signature: Optional["bytes"] = None,
|
||||
) -> None:
|
||||
self.type = type
|
||||
self.auxiliary_data_hash = auxiliary_data_hash
|
||||
self.governance_signature = governance_signature
|
||||
self.cvote_registration_signature = cvote_registration_signature
|
||||
|
||||
|
||||
class CardanoTxWitnessRequest(protobuf.MessageType):
|
||||
|
@ -159,8 +159,10 @@ def _transform_expected_result(result):
|
||||
"type": supplement["type"],
|
||||
"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"][
|
||||
"governance_signature"
|
||||
] = bytes.fromhex(governance_signature)
|
||||
"cvote_registration_signature"
|
||||
] = bytes.fromhex(cvote_registration_signature)
|
||||
return transformed_result
|
||||
|
Loading…
Reference in New Issue
Block a user