1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-09 06:50:58 +00:00

refactor(cardano): shorten catalyst parameters variable name

This commit is contained in:
David Misiak 2022-09-12 14:30:31 +02:00 committed by matejcik
parent 40a405abea
commit 02dad0225b

View File

@ -52,20 +52,15 @@ def _validate_hash(auxiliary_data_hash: bytes) -> None:
def _validate_catalyst_registration_parameters( def _validate_catalyst_registration_parameters(
catalyst_registration_parameters: messages.CardanoCatalystRegistrationParametersType, parameters: messages.CardanoCatalystRegistrationParametersType,
) -> None: ) -> None:
if ( if len(parameters.voting_public_key) != CATALYST_VOTING_PUBLIC_KEY_LENGTH:
len(catalyst_registration_parameters.voting_public_key)
!= CATALYST_VOTING_PUBLIC_KEY_LENGTH
):
raise wire.ProcessError("Invalid auxiliary data") raise wire.ProcessError("Invalid auxiliary data")
if not SCHEMA_STAKING_ANY_ACCOUNT.match( if not SCHEMA_STAKING_ANY_ACCOUNT.match(parameters.staking_path):
catalyst_registration_parameters.staking_path
):
raise wire.ProcessError("Invalid auxiliary data") raise wire.ProcessError("Invalid auxiliary data")
address_parameters = catalyst_registration_parameters.reward_address_parameters address_parameters = parameters.reward_address_parameters
if address_parameters.address_type == CardanoAddressType.BYRON: if address_parameters.address_type == CardanoAddressType.BYRON:
raise wire.ProcessError("Invalid auxiliary data") raise wire.ProcessError("Invalid auxiliary data")
@ -76,17 +71,16 @@ async def show(
ctx: wire.Context, ctx: wire.Context,
keychain: seed.Keychain, keychain: seed.Keychain,
auxiliary_data_hash: bytes, auxiliary_data_hash: bytes,
catalyst_registration_parameters: messages.CardanoCatalystRegistrationParametersType parameters: messages.CardanoCatalystRegistrationParametersType | None,
| None,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
should_show_details: bool, should_show_details: bool,
) -> None: ) -> None:
if catalyst_registration_parameters: if parameters:
await _show_catalyst_registration( await _show_catalyst_registration(
ctx, ctx,
keychain, keychain,
catalyst_registration_parameters, parameters,
protocol_magic, protocol_magic,
network_id, network_id,
) )
@ -98,23 +92,25 @@ async def show(
async def _show_catalyst_registration( async def _show_catalyst_registration(
ctx: wire.Context, ctx: wire.Context,
keychain: seed.Keychain, keychain: seed.Keychain,
catalyst_registration_parameters: messages.CardanoCatalystRegistrationParametersType, parameters: messages.CardanoCatalystRegistrationParametersType,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
) -> None: ) -> None:
public_key = catalyst_registration_parameters.voting_public_key public_key = parameters.voting_public_key
encoded_public_key = bech32.encode(bech32.HRP_JORMUN_PUBLIC_KEY, public_key) encoded_public_key = bech32.encode(bech32.HRP_JORMUN_PUBLIC_KEY, public_key)
staking_path = catalyst_registration_parameters.staking_path
reward_address = addresses.derive_human_readable( reward_address = addresses.derive_human_readable(
keychain, keychain,
catalyst_registration_parameters.reward_address_parameters, parameters.reward_address_parameters,
protocol_magic, protocol_magic,
network_id, network_id,
) )
nonce = catalyst_registration_parameters.nonce
await confirm_catalyst_registration( await confirm_catalyst_registration(
ctx, encoded_public_key, staking_path, reward_address, nonce ctx,
encoded_public_key,
parameters.staking_path,
reward_address,
parameters.nonce,
) )
@ -172,30 +168,28 @@ def _cborize_catalyst_registration(
def _get_signed_catalyst_registration_payload( def _get_signed_catalyst_registration_payload(
keychain: seed.Keychain, keychain: seed.Keychain,
catalyst_registration_parameters: messages.CardanoCatalystRegistrationParametersType, parameters: messages.CardanoCatalystRegistrationParametersType,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
) -> SignedCatalystRegistrationPayload: ) -> SignedCatalystRegistrationPayload:
staking_key = derive_public_key( staking_key = derive_public_key(keychain, parameters.staking_path)
keychain, catalyst_registration_parameters.staking_path
)
payload: CatalystRegistrationPayload = { payload: CatalystRegistrationPayload = {
1: catalyst_registration_parameters.voting_public_key, 1: parameters.voting_public_key,
2: staking_key, 2: staking_key,
3: addresses.derive_bytes( 3: addresses.derive_bytes(
keychain, keychain,
catalyst_registration_parameters.reward_address_parameters, parameters.reward_address_parameters,
protocol_magic, protocol_magic,
network_id, network_id,
), ),
4: catalyst_registration_parameters.nonce, 4: parameters.nonce,
} }
signature = _create_catalyst_registration_payload_signature( signature = _create_catalyst_registration_payload_signature(
keychain, keychain,
payload, payload,
catalyst_registration_parameters.staking_path, parameters.staking_path,
) )
return payload, signature return payload, signature