Skip to content

Commit

Permalink
chore(cardano): rename voting public key to vote public key
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmisiak committed Feb 21, 2023
1 parent 133e70e commit eb836f2
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 334 deletions.
6 changes: 3 additions & 3 deletions common/protob/messages-cardano.proto
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,20 @@ message CardanoTxWithdrawal {
* @embed
*/
message CardanoCVoteRegistrationDelegation {
required bytes voting_public_key = 1;
required bytes vote_public_key = 1;
required uint32 weight = 2;
}

/**
* @embed
*/
message CardanoCVoteRegistrationParametersType {
optional bytes voting_public_key = 1; // mutually exclusive with delegations
optional bytes vote_public_key = 1; // mutually exclusive with delegations
repeated uint32 staking_path = 2;
optional CardanoAddressParametersType payment_address_parameters = 3; // mutually exclusive with payment_address
required uint64 nonce = 4;
optional CardanoCVoteRegistrationFormat format = 5 [default=CIP15];
repeated CardanoCVoteRegistrationDelegation delegations = 6; // mutually exclusive with voting_public_key; max 32 delegations
repeated CardanoCVoteRegistrationDelegation delegations = 6; // mutually exclusive with vote_public_key; max 32 delegations
optional uint64 voting_purpose = 7;
optional string payment_address = 8; // mutually exclusive with payment_address_parameters
}
Expand Down
10 changes: 5 additions & 5 deletions common/tests/fixtures/cardano/sign_tx.failed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@
"withdrawals": [],
"auxiliary_data": {
"cvote_registration_parameters": {
"voting_public_key": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7",
"vote_public_key": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7",
"staking_path": "m/1852'/1815'/0'/2/0",
"nonce": 22634813,
"payment_address_parameters": {
Expand Down Expand Up @@ -1360,7 +1360,7 @@
"auxiliary_data": {
"hash": "ea4c91860dd5ec5449f8f985d227946ff39086b17f10b5afb93d12ee87050b6a",
"cvote_registration_parameters": {
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"vote_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"staking_path": "m/1852'/1815'/0'/2/0",
"payment_address_parameters": {
"addressType": 0,
Expand Down Expand Up @@ -1399,7 +1399,7 @@
}
},
{
"description": "transaction with both voting public key and delegations in cvote registration",
"description": "transaction with both vote public key and delegations in cvote registration",
"parameters": {
"protocol_magic": 764824073,
"network_id": 1,
Expand All @@ -1410,7 +1410,7 @@
"withdrawals": [],
"auxiliary_data": {
"cvote_registration_parameters": {
"voting_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"vote_public_key": "38DA0B509D45BF6C87BD55594B92F97081D3923B8C1334B9B8D0BF13FC1C12D0",
"staking_path": "m/1852'/1815'/0'/2/0",
"payment_address_parameters": {
"addressType": 0,
Expand All @@ -1421,7 +1421,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
]
Expand Down
16 changes: 8 additions & 8 deletions common/tests/fixtures/cardano/sign_tx.json
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
"withdrawals": [],
"auxiliary_data": {
"cvote_registration_parameters": {
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"staking_path": "m/1852'/1815'/0'/2/0",
"payment_address_parameters": {
"addressType": 0,
Expand Down Expand Up @@ -1086,11 +1086,11 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
},
{
"voting_public_key": "2af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "2af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 2
}
]
Expand Down Expand Up @@ -1159,7 +1159,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
],
Expand Down Expand Up @@ -1224,7 +1224,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
],
Expand Down Expand Up @@ -1293,7 +1293,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
]
Expand Down Expand Up @@ -1357,7 +1357,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
],
Expand Down Expand Up @@ -1943,7 +1943,7 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
}
],
Expand Down
6 changes: 3 additions & 3 deletions common/tests/fixtures/cardano/sign_tx.show_details.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
}
},
{
"description": "transaction with CIP36 registration and voting purpose not specified",
"description": "transaction with CIP36 registration and vote purpose not specified",
"parameters": {
"protocol_magic": 764824073,
"network_id": 1,
Expand All @@ -478,11 +478,11 @@
"format": 1,
"delegations": [
{
"voting_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 1
},
{
"voting_public_key": "2af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"vote_public_key": "2af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc",
"weight": 2
}
]
Expand Down
28 changes: 14 additions & 14 deletions core/src/apps/cardano/auxiliary_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def _validate_cvote_registration_parameters(
protocol_magic: int,
network_id: int,
) -> None:
voting_key_fields_provided = 0
if parameters.voting_public_key is not None:
voting_key_fields_provided += 1
_validate_voting_public_key(parameters.voting_public_key)
vote_key_fields_provided = 0
if parameters.vote_public_key is not None:
vote_key_fields_provided += 1
_validate_vote_public_key(parameters.vote_public_key)
if parameters.delegations:
voting_key_fields_provided += 1
vote_key_fields_provided += 1
assert_cond(parameters.format == CardanoCVoteRegistrationFormat.CIP36)
_validate_delegations(parameters.delegations)
assert_cond(voting_key_fields_provided == 1)
assert_cond(vote_key_fields_provided == 1)

assert_cond(SCHEMA_STAKING_ANY_ACCOUNT.match(parameters.staking_path))

Expand All @@ -92,7 +92,7 @@ def _validate_cvote_registration_parameters(
assert_cond(parameters.format == CardanoCVoteRegistrationFormat.CIP36)


def _validate_voting_public_key(key: bytes) -> None:
def _validate_vote_public_key(key: bytes) -> None:
assert_cond(len(key) == _CVOTE_PUBLIC_KEY_LENGTH)


Expand All @@ -101,7 +101,7 @@ def _validate_delegations(
) -> None:
assert_cond(len(delegations) <= _MAX_DELEGATION_COUNT)
for delegation in delegations:
_validate_voting_public_key(delegation.voting_public_key)
_validate_vote_public_key(delegation.vote_public_key)


def _get_voting_purpose_to_serialize(
Expand Down Expand Up @@ -158,7 +158,7 @@ async def _show_cvote_registration(

for delegation in parameters.delegations:
encoded_public_key = bech32.encode(
bech32.HRP_CVOTE_PUBLIC_KEY, delegation.voting_public_key
bech32.HRP_CVOTE_PUBLIC_KEY, delegation.vote_public_key
)
await layout.confirm_cvote_registration_delegation(
ctx, encoded_public_key, delegation.weight
Expand Down Expand Up @@ -187,9 +187,9 @@ async def _show_cvote_registration(
)

encoded_public_key: str | None = None
if parameters.voting_public_key:
if parameters.vote_public_key:
encoded_public_key = bech32.encode(
bech32.HRP_CVOTE_PUBLIC_KEY, parameters.voting_public_key
bech32.HRP_CVOTE_PUBLIC_KEY, parameters.vote_public_key
)

voting_purpose: int | None = (
Expand Down Expand Up @@ -271,11 +271,11 @@ def _get_signed_cvote_registration_payload(
delegations_or_key: Delegations | bytes
if len(parameters.delegations) > 0:
delegations_or_key = [
(delegation.voting_public_key, delegation.weight)
(delegation.vote_public_key, delegation.weight)
for delegation in parameters.delegations
]
elif parameters.voting_public_key:
delegations_or_key = parameters.voting_public_key
elif parameters.vote_public_key:
delegations_or_key = parameters.vote_public_key
else:
raise RuntimeError # should not be reached - _validate_cvote_registration_parameters

Expand Down
6 changes: 3 additions & 3 deletions core/src/apps/cardano/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,14 @@ async def confirm_cvote_registration_payment_address(

async def confirm_cvote_registration(
ctx: Context,
public_key: str | None,
vote_public_key: str | None,
staking_path: list[int],
nonce: int,
voting_purpose: int | None,
) -> None:
props: list[PropertyType] = [("Vote key registration (CIP-36)", None)]
if public_key is not None:
props.append(("Voting public key:", public_key))
if vote_public_key is not None:
props.append(("Vote public key:", vote_public_key))
props.extend(
[
(
Expand Down
8 changes: 4 additions & 4 deletions core/src/trezor/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,13 +1639,13 @@ def is_type_of(cls, msg: Any) -> TypeGuard["CardanoTxWithdrawal"]:
return isinstance(msg, cls)

class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
voting_public_key: "bytes"
vote_public_key: "bytes"
weight: "int"

def __init__(
self,
*,
voting_public_key: "bytes",
vote_public_key: "bytes",
weight: "int",
) -> None:
pass
Expand All @@ -1655,7 +1655,7 @@ def is_type_of(cls, msg: Any) -> TypeGuard["CardanoCVoteRegistrationDelegation"]
return isinstance(msg, cls)

class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
voting_public_key: "bytes | None"
vote_public_key: "bytes | None"
staking_path: "list[int]"
payment_address_parameters: "CardanoAddressParametersType | None"
nonce: "int"
Expand All @@ -1670,7 +1670,7 @@ def __init__(
nonce: "int",
staking_path: "list[int] | None" = None,
delegations: "list[CardanoCVoteRegistrationDelegation] | None" = None,
voting_public_key: "bytes | None" = None,
vote_public_key: "bytes | None" = None,
payment_address_parameters: "CardanoAddressParametersType | None" = None,
format: "CardanoCVoteRegistrationFormat | None" = None,
voting_purpose: "int | None" = None,
Expand Down
8 changes: 4 additions & 4 deletions python/src/trezorlib/cardano.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"staking_path",
"nonce",
)
REQUIRED_FIELDS_CVOTE_DELEGATION = ("voting_public_key", "weight")
REQUIRED_FIELDS_CVOTE_DELEGATION = ("vote_public_key", "weight")

INCOMPLETE_OUTPUT_ERROR_MESSAGE = "The output is missing some fields"

Expand Down Expand Up @@ -576,7 +576,7 @@ def parse_auxiliary_data(
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
delegations.append(
messages.CardanoCVoteRegistrationDelegation(
voting_public_key=bytes.fromhex(delegation["voting_public_key"]),
vote_public_key=bytes.fromhex(delegation["vote_public_key"]),
weight=int(delegation["weight"]),
)
)
Expand All @@ -586,8 +586,8 @@ def parse_auxiliary_data(
voting_purpose = cvote_registration.get("voting_purpose")

cvote_registration_parameters = messages.CardanoCVoteRegistrationParametersType(
voting_public_key=parse_optional_bytes(
cvote_registration.get("voting_public_key")
vote_public_key=parse_optional_bytes(
cvote_registration.get("vote_public_key")
),
staking_path=tools.parse_path(cvote_registration["staking_path"]),
nonce=cvote_registration["nonce"],
Expand Down
12 changes: 6 additions & 6 deletions python/src/trezorlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,24 +2639,24 @@ def __init__(
class CardanoCVoteRegistrationDelegation(protobuf.MessageType):
MESSAGE_WIRE_TYPE = None
FIELDS = {
1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=True),
1: protobuf.Field("vote_public_key", "bytes", repeated=False, required=True),
2: protobuf.Field("weight", "uint32", repeated=False, required=True),
}

def __init__(
self,
*,
voting_public_key: "bytes",
vote_public_key: "bytes",
weight: "int",
) -> None:
self.voting_public_key = voting_public_key
self.vote_public_key = vote_public_key
self.weight = weight


class CardanoCVoteRegistrationParametersType(protobuf.MessageType):
MESSAGE_WIRE_TYPE = None
FIELDS = {
1: protobuf.Field("voting_public_key", "bytes", repeated=False, required=False, default=None),
1: protobuf.Field("vote_public_key", "bytes", repeated=False, required=False, default=None),
2: protobuf.Field("staking_path", "uint32", repeated=True, required=False, default=None),
3: protobuf.Field("payment_address_parameters", "CardanoAddressParametersType", repeated=False, required=False, default=None),
4: protobuf.Field("nonce", "uint64", repeated=False, required=True),
Expand All @@ -2672,7 +2672,7 @@ def __init__(
nonce: "int",
staking_path: Optional[Sequence["int"]] = None,
delegations: Optional[Sequence["CardanoCVoteRegistrationDelegation"]] = None,
voting_public_key: Optional["bytes"] = None,
vote_public_key: Optional["bytes"] = None,
payment_address_parameters: Optional["CardanoAddressParametersType"] = None,
format: Optional["CardanoCVoteRegistrationFormat"] = CardanoCVoteRegistrationFormat.CIP15,
voting_purpose: Optional["int"] = None,
Expand All @@ -2681,7 +2681,7 @@ def __init__(
self.staking_path: Sequence["int"] = staking_path if staking_path 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.vote_public_key = vote_public_key
self.payment_address_parameters = payment_address_parameters
self.format = format
self.voting_purpose = voting_purpose
Expand Down
Loading

0 comments on commit eb836f2

Please sign in to comment.