refactor(cardano): use module imports for addresses, certs, aux data

pull/2374/head
David Misiak 2 years ago committed by matejcik
parent 2753faa7b0
commit 50ad00a3c0

@ -483,12 +483,12 @@ if not utils.BITCOIN_ONLY:
import apps.bitcoin.sign_tx.zcash_v4
apps.cardano
import apps.cardano
apps.cardano.address
import apps.cardano.address
apps.cardano.addresses
import apps.cardano.addresses
apps.cardano.auxiliary_data
import apps.cardano.auxiliary_data
apps.cardano.byron_address
import apps.cardano.byron_address
apps.cardano.byron_addresses
import apps.cardano.byron_addresses
apps.cardano.certificates
import apps.cardano.certificates
apps.cardano.get_address

@ -4,11 +4,10 @@ from trezor import messages, wire
from trezor.crypto import base58
from trezor.enums import CardanoAddressType
from .byron_address import derive_byron_address, validate_byron_address
from . import byron_addresses, seed
from .helpers import ADDRESS_KEY_HASH_SIZE, SCRIPT_HASH_SIZE, bech32, network_ids
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
from .helpers.utils import get_public_key_hash, variable_length_encode
from .seed import is_byron_path, is_shelley_path
ADDRESS_TYPES_SHELLEY = (
CardanoAddressType.BASE,
@ -45,10 +44,10 @@ def validate_address_parameters(
_validate_address_parameters_structure(parameters)
if parameters.address_type == CardanoAddressType.BYRON:
assert_address_params_cond(is_byron_path(parameters.address_n))
assert_address_params_cond(seed.is_byron_path(parameters.address_n))
elif parameters.address_type == CardanoAddressType.BASE:
assert_address_params_cond(is_shelley_path(parameters.address_n))
assert_address_params_cond(seed.is_shelley_path(parameters.address_n))
_validate_base_address_staking_info(
parameters.address_n_staking, parameters.staking_key_hash
)
@ -60,7 +59,7 @@ def validate_address_parameters(
)
elif parameters.address_type == CardanoAddressType.BASE_KEY_SCRIPT:
assert_address_params_cond(is_shelley_path(parameters.address_n))
assert_address_params_cond(seed.is_shelley_path(parameters.address_n))
_validate_script_hash(parameters.script_staking_hash)
elif parameters.address_type == CardanoAddressType.BASE_SCRIPT_SCRIPT:
@ -68,7 +67,7 @@ def validate_address_parameters(
_validate_script_hash(parameters.script_staking_hash)
elif parameters.address_type == CardanoAddressType.POINTER:
assert_address_params_cond(is_shelley_path(parameters.address_n))
assert_address_params_cond(seed.is_shelley_path(parameters.address_n))
assert_address_params_cond(parameters.certificate_pointer is not None)
elif parameters.address_type == CardanoAddressType.POINTER_SCRIPT:
@ -76,13 +75,13 @@ def validate_address_parameters(
assert_address_params_cond(parameters.certificate_pointer is not None)
elif parameters.address_type == CardanoAddressType.ENTERPRISE:
assert_address_params_cond(is_shelley_path(parameters.address_n))
assert_address_params_cond(seed.is_shelley_path(parameters.address_n))
elif parameters.address_type == CardanoAddressType.ENTERPRISE_SCRIPT:
_validate_script_hash(parameters.script_payment_hash)
elif parameters.address_type == CardanoAddressType.REWARD:
assert_address_params_cond(is_shelley_path(parameters.address_n_staking))
assert_address_params_cond(seed.is_shelley_path(parameters.address_n_staking))
assert_address_params_cond(
SCHEMA_STAKING_ANY_ACCOUNT.match(parameters.address_n_staking)
)
@ -236,7 +235,7 @@ def _validate_address_and_get_type(
address_type = get_address_type(address_bytes)
if address_type == CardanoAddressType.BYRON:
validate_byron_address(address_bytes, protocol_magic)
byron_addresses.validate_byron_address(address_bytes, protocol_magic)
elif address_type in ADDRESS_TYPES_SHELLEY:
_validate_shelley_address(address, address_bytes, network_id)
else:
@ -364,7 +363,9 @@ def derive_address_bytes(
is_byron_address = parameters.address_type == CardanoAddressType.BYRON
if is_byron_address:
address = derive_byron_address(keychain, parameters.address_n, protocol_magic)
address = byron_addresses.derive_byron_address(
keychain, parameters.address_n, protocol_magic
)
else:
address = _derive_shelley_address(keychain, parameters, network_id)

@ -7,13 +7,8 @@ from trezor.enums import CardanoAddressType, CardanoTxAuxiliaryDataSupplementTyp
from apps.common import cbor
from .address import (
derive_address_bytes,
derive_human_readable_address,
validate_address_parameters,
)
from . import addresses
from .helpers import bech32
from .helpers.bech32 import HRP_JORMUN_PUBLIC_KEY
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
from .helpers.utils import derive_public_key
from .layout import confirm_catalyst_registration, show_auxiliary_data_hash
@ -74,7 +69,7 @@ def _validate_catalyst_registration_parameters(
if address_parameters.address_type == CardanoAddressType.BYRON:
raise wire.ProcessError("Invalid auxiliary data")
validate_address_parameters(address_parameters)
addresses.validate_address_parameters(address_parameters)
async def show_auxiliary_data(
@ -106,9 +101,9 @@ async def _show_catalyst_registration(
network_id: int,
) -> None:
public_key = catalyst_registration_parameters.voting_public_key
encoded_public_key = bech32.encode(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 = derive_human_readable_address(
reward_address = addresses.derive_human_readable_address(
keychain,
catalyst_registration_parameters.reward_address_parameters,
protocol_magic,
@ -188,7 +183,7 @@ def _get_signed_catalyst_registration_payload(
payload: CatalystRegistrationPayload = {
1: catalyst_registration_parameters.voting_public_key,
2: staking_key,
3: derive_address_bytes(
3: addresses.derive_address_bytes(
keychain,
catalyst_registration_parameters.reward_address_parameters,
protocol_magic,

@ -5,7 +5,7 @@ from trezor.enums import CardanoCertificateType, CardanoPoolRelayType
from apps.common import cbor
from .address import get_address_bytes_unsafe, validate_reward_address
from . import addresses
from .helpers import ADDRESS_KEY_HASH_SIZE, LOVELACE_MAX_SUPPLY
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
from .helpers.utils import get_public_key_hash, validate_stake_credential
@ -155,7 +155,7 @@ def cborize_pool_registration_certificate_init(
),
# this relies on pool_parameters.reward_account being validated beforehand
# in _validate_pool_parameters
get_address_bytes_unsafe(pool_parameters.reward_account),
addresses.get_address_bytes_unsafe(pool_parameters.reward_account),
)
@ -180,7 +180,9 @@ def _validate_pool_parameters(
)
assert_certificate_cond(pool_parameters.owners_count > 0)
validate_reward_address(pool_parameters.reward_account, protocol_magic, network_id)
addresses.validate_reward_address(
pool_parameters.reward_account, protocol_magic, network_id
)
if pool_parameters.metadata:
_validate_pool_metadata(pool_parameters.metadata)

@ -1,7 +1,6 @@
from trezor import log, messages, wire
from . import seed
from .address import derive_human_readable_address, validate_address_parameters
from . import addresses, seed
from .helpers.credential import Credential, should_show_credentials
from .helpers.utils import validate_network_info
from .layout import show_cardano_address, show_credentials
@ -12,10 +11,10 @@ async def get_address(
ctx: wire.Context, msg: messages.CardanoGetAddress, keychain: seed.Keychain
) -> messages.CardanoAddress:
validate_network_info(msg.network_id, msg.protocol_magic)
validate_address_parameters(msg.address_parameters)
addresses.validate_address_parameters(msg.address_parameters)
try:
address = derive_human_readable_address(
address = addresses.derive_human_readable_address(
keychain, msg.address_parameters, msg.protocol_magic, msg.network_id
)
except ValueError as e:

@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
from trezor import wire
from ...common.paths import HARDENED
from ..seed import is_byron_path, is_minting_path, is_multisig_path, is_shelley_path
from .. import seed
from .paths import ACCOUNT_PATH_INDEX, ACCOUNT_PATH_LENGTH
from .utils import to_account_path
@ -31,7 +31,7 @@ class AccountPathChecker:
def _add(self, path: list[int], error: wire.ProcessError) -> None:
# multi-sig and minting paths are always shown and thus don't need to be checked
if is_multisig_path(path) or is_minting_path(path):
if seed.is_multisig_path(path) or seed.is_minting_path(path):
return
account_path = to_account_path(path)
@ -52,13 +52,13 @@ class AccountPathChecker:
accounts without being bothered by more screens.
"""
assert isinstance(self.account_path, list)
is_control_path_byron_or_shelley = is_byron_path(
is_control_path_byron_or_shelley = seed.is_byron_path(
self.account_path
) or is_shelley_path(self.account_path)
) or seed.is_shelley_path(self.account_path)
is_new_path_byron_or_shelley = is_byron_path(account_path) or is_shelley_path(
is_new_path_byron_or_shelley = seed.is_byron_path(
account_path
)
) or seed.is_shelley_path(account_path)
return (
is_control_path_byron_or_shelley

@ -3,8 +3,9 @@ from typing import TYPE_CHECKING
from trezor.enums import CardanoAddressType
from ...common.paths import address_n_to_str
from . import bech32
from .paths import CHAIN_STAKING_KEY, SCHEMA_PAYMENT, SCHEMA_STAKING
from .utils import bech32, to_account_path
from .utils import to_account_path
if TYPE_CHECKING:
from trezor import messages

@ -3,15 +3,16 @@ from typing import TYPE_CHECKING
from trezor import wire
from trezor.crypto import hashlib
from apps.cardano.helpers import network_ids, protocol_magics
from apps.cardano.helpers.paths import (
ACCOUNT_PATH_INDEX,
SCHEMA_STAKING_ANY_ACCOUNT,
unharden,
)
from apps.common.seed import remove_ed25519_prefix
from . import ADDRESS_KEY_HASH_SIZE, SCRIPT_HASH_SIZE, bech32
from . import (
ADDRESS_KEY_HASH_SIZE,
SCRIPT_HASH_SIZE,
bech32,
network_ids,
protocol_magics,
)
from .paths import ACCOUNT_PATH_INDEX, SCHEMA_STAKING_ANY_ACCOUNT, unharden
if TYPE_CHECKING:
from .. import seed

@ -21,8 +21,7 @@ from trezor.ui.layouts import (
from apps.common.paths import address_n_to_str
from . import seed
from .address import derive_human_readable_address, encode_human_readable_address
from . import addresses, seed
from .helpers import bech32, network_ids, protocol_magics
from .helpers.utils import (
format_account_number,
@ -31,7 +30,6 @@ from .helpers.utils import (
format_stake_pool_id,
to_account_path,
)
from .seed import is_minting_path, is_multisig_path
if TYPE_CHECKING:
from trezor import wire
@ -426,9 +424,9 @@ async def confirm_witness_request(
ctx: wire.Context,
witness_path: list[int],
) -> None:
if is_multisig_path(witness_path):
if seed.is_multisig_path(witness_path):
path_title = "multi-sig path"
elif is_minting_path(witness_path):
elif seed.is_minting_path(witness_path):
path_title = "token minting path"
else:
path_title = "path"
@ -545,7 +543,7 @@ async def confirm_stake_pool_owner(
props.append(("Pool owner:", address_n_to_str(owner.staking_key_path)))
props.append(
(
derive_human_readable_address(
addresses.derive_human_readable_address(
keychain,
messages.CardanoAddressParametersType(
address_type=CardanoAddressType.REWARD,
@ -562,7 +560,7 @@ async def confirm_stake_pool_owner(
props.append(
(
"Pool owner:",
derive_human_readable_address(
addresses.derive_human_readable_address(
keychain,
messages.CardanoAddressParametersType(
address_type=CardanoAddressType.REWARD,
@ -637,7 +635,7 @@ async def confirm_withdrawal(
network_id: int,
) -> None:
address_type_name = "script reward" if withdrawal.script_hash else "reward"
address = encode_human_readable_address(address_bytes)
address = addresses.encode_human_readable_address(address_bytes)
props: list[PropertyType] = [
(f"Confirm withdrawal for {address_type_name} address:", address),
]

@ -4,12 +4,12 @@ from trezor import messages, wire
from trezor.crypto import hashlib
from trezor.enums import CardanoNativeScriptType
from apps.cardano.helpers import ADDRESS_KEY_HASH_SIZE, SCRIPT_HASH_SIZE
from apps.common import cbor
from . import seed
from .helpers import ADDRESS_KEY_HASH_SIZE, SCRIPT_HASH_SIZE
from .helpers.paths import SCHEMA_MINT
from .helpers.utils import get_public_key_hash
from .seed import Keychain, is_multisig_path
if TYPE_CHECKING:
from typing import Any
@ -33,7 +33,7 @@ def validate_native_script(script: messages.CardanoNativeScript | None) -> None:
raise INVALID_NATIVE_SCRIPT
elif script.key_path:
is_minting = SCHEMA_MINT.match(script.key_path)
if not is_multisig_path(script.key_path) and not is_minting:
if not seed.is_multisig_path(script.key_path) and not is_minting:
raise INVALID_NATIVE_SCRIPT
else:
raise INVALID_NATIVE_SCRIPT

@ -3,7 +3,6 @@ from trezor.enums import CardanoCertificateType
from .. import layout, seed
from ..helpers.paths import SCHEMA_MINT
from ..seed import is_multisig_path
from .signer import Signer
@ -71,7 +70,7 @@ class MultisigSigner(Signer):
tx_has_token_minting = self.msg.minting_asset_groups_count > 0
if not (
is_multisig_path(witness_request.path)
seed.is_multisig_path(witness_request.path)
or (is_minting and tx_has_token_minting)
):
raise wire.ProcessError("Invalid witness request")

@ -8,7 +8,6 @@ from ..helpers.paths import (
SCHEMA_STAKING,
WITNESS_PATH_NAME,
)
from ..seed import is_byron_path, is_shelley_path
from .signer import Signer
@ -68,8 +67,8 @@ class OrdinarySigner(Signer):
tx_has_token_minting = self.msg.minting_asset_groups_count > 0
if not (
is_byron_path(witness_request.path)
or is_shelley_path(witness_request.path)
seed.is_byron_path(witness_request.path)
or seed.is_shelley_path(witness_request.path)
or (is_minting and tx_has_token_minting)
):
raise wire.ProcessError("Invalid witness request")

@ -4,7 +4,6 @@ from trezor.enums import CardanoCertificateType
from .. import layout, seed
from ..helpers.credential import Credential, should_show_credentials
from ..helpers.paths import SCHEMA_MINT
from ..seed import is_multisig_path, is_shelley_path
from .signer import Signer
@ -91,8 +90,8 @@ class PlutusSigner(Signer):
# In Plutus txs, we allow minting witnesses even when the tx doesn't have token minting.
if not (
is_shelley_path(witness_request.path)
or is_multisig_path(witness_request.path)
seed.is_shelley_path(witness_request.path)
or seed.is_multisig_path(witness_request.path)
or is_minting
):
raise wire.ProcessError("Invalid witness request")

@ -12,32 +12,7 @@ from trezor.enums import (
from apps.common import cbor, safety_checks
from .. import layout
from ..address import (
ADDRESS_TYPES_PAYMENT_SCRIPT,
derive_address_bytes,
derive_human_readable_address,
get_address_bytes_unsafe,
get_address_type,
validate_output_address,
validate_output_address_parameters,
)
from ..auxiliary_data import (
get_auxiliary_data_hash_and_supplement,
show_auxiliary_data,
validate_auxiliary_data,
)
from ..certificates import (
assert_certificate_cond,
cborize_certificate,
cborize_pool_metadata,
cborize_pool_owner,
cborize_pool_registration_certificate_init,
cborize_pool_relay,
validate_certificate,
validate_pool_owner,
validate_pool_relay,
)
from .. import addresses, auxiliary_data, certificates, layout, seed
from ..helpers import (
ADDRESS_KEY_HASH_SIZE,
INPUT_PREV_HASH_SIZE,
@ -61,14 +36,11 @@ from ..helpers.utils import (
validate_network_info,
validate_stake_credential,
)
from ..seed import is_byron_path, is_minting_path, is_multisig_path, is_shelley_path
if TYPE_CHECKING:
from typing import Any
from apps.common.paths import PathSchema
from .. import seed
CardanoTxResponseType = (
messages.CardanoTxItemAck | messages.CardanoTxWitnessResponse
)
@ -305,10 +277,10 @@ class Signer:
raise wire.ProcessError("Invalid output")
if output.address_parameters is not None:
validate_output_address_parameters(output.address_parameters)
addresses.validate_output_address_parameters(output.address_parameters)
self._fail_if_strict_and_unusual(output.address_parameters)
elif output.address is not None:
validate_output_address(
addresses.validate_output_address(
output.address, self.msg.protocol_magic, self.msg.network_id
)
else:
@ -318,7 +290,7 @@ class Signer:
if len(output.datum_hash) != OUTPUT_DATUM_HASH_SIZE:
raise wire.ProcessError("Invalid output datum hash")
address_type = self._get_output_address_type(output)
if address_type not in ADDRESS_TYPES_PAYMENT_SCRIPT:
if address_type not in addresses.ADDRESS_TYPES_PAYMENT_SCRIPT:
raise wire.ProcessError("Invalid output")
self.account_path_checker.add_output(output)
@ -331,14 +303,17 @@ class Signer:
await layout.warn_tx_output_contains_datum_hash(self.ctx, output.datum_hash)
address_type = self._get_output_address_type(output)
if output.datum_hash is None and address_type in ADDRESS_TYPES_PAYMENT_SCRIPT:
if (
output.datum_hash is None
and address_type in addresses.ADDRESS_TYPES_PAYMENT_SCRIPT
):
await layout.warn_tx_output_no_datum_hash(self.ctx)
if output.asset_groups_count > 0:
await layout.warn_tx_output_contains_tokens(self.ctx)
if output.address_parameters is not None:
address = derive_human_readable_address(
address = addresses.derive_human_readable_address(
self.keychain,
output.address_parameters,
self.msg.protocol_magic,
@ -377,7 +352,10 @@ class Signer:
return True
address_type = self._get_output_address_type(output)
if output.datum_hash is None and address_type in ADDRESS_TYPES_PAYMENT_SCRIPT:
if (
output.datum_hash is None
and address_type in addresses.ADDRESS_TYPES_PAYMENT_SCRIPT
):
# Plutus script address without a datum hash is unspendable, we must show a warning.
return True
@ -489,7 +467,9 @@ class Signer:
POOL_REGISTRATION_CERTIFICATE_ITEMS_COUNT
)
with certificates_list.append(pool_items_list):
for item in cborize_pool_registration_certificate_init(certificate):
for item in certificates.cborize_pool_registration_certificate_init(
certificate
):
pool_items_list.append(item)
pool_owners_list: HashBuilderList[bytes] = HashBuilderList(
@ -509,15 +489,15 @@ class Signer:
)
pool_items_list.append(
cborize_pool_metadata(pool_parameters.metadata)
certificates.cborize_pool_metadata(pool_parameters.metadata)
)
else:
certificates_list.append(
cborize_certificate(self.keychain, certificate)
certificates.cborize_certificate(self.keychain, certificate)
)
def _validate_certificate(self, certificate: messages.CardanoTxCertificate) -> None:
validate_certificate(
certificates.validate_certificate(
certificate,
self.msg.protocol_magic,
self.msg.network_id,
@ -553,14 +533,16 @@ class Signer:
owner: messages.CardanoPoolOwner = await self.ctx.call(
messages.CardanoTxItemAck(), messages.CardanoPoolOwner
)
validate_pool_owner(owner, self.account_path_checker)
certificates.validate_pool_owner(owner, self.account_path_checker)
await self._show_pool_owner(owner)
pool_owners_list.append(cborize_pool_owner(self.keychain, owner))
pool_owners_list.append(
certificates.cborize_pool_owner(self.keychain, owner)
)
if owner.staking_key_path:
owners_as_path_count += 1
assert_certificate_cond(owners_as_path_count == 1)
certificates.assert_certificate_cond(owners_as_path_count == 1)
async def _show_pool_owner(self, owner: messages.CardanoPoolOwner) -> None:
if owner.staking_key_path:
@ -583,8 +565,8 @@ class Signer:
relay: messages.CardanoPoolRelayParameters = await self.ctx.call(
messages.CardanoTxItemAck(), messages.CardanoPoolRelayParameters
)
validate_pool_relay(relay)
relays_list.append(cborize_pool_relay(relay))
certificates.validate_pool_relay(relay)
relays_list.append(certificates.cborize_pool_relay(relay))
# withdrawals
@ -618,22 +600,22 @@ class Signer:
# auxiliary data
async def _process_auxiliary_data(self) -> None:
auxiliary_data: messages.CardanoTxAuxiliaryData = await self.ctx.call(
data: messages.CardanoTxAuxiliaryData = await self.ctx.call(
messages.CardanoTxItemAck(), messages.CardanoTxAuxiliaryData
)
validate_auxiliary_data(auxiliary_data)
auxiliary_data.validate_auxiliary_data(data)
(
auxiliary_data_hash,
auxiliary_data_supplement,
) = get_auxiliary_data_hash_and_supplement(
self.keychain, auxiliary_data, self.msg.protocol_magic, self.msg.network_id
) = auxiliary_data.get_auxiliary_data_hash_and_supplement(
self.keychain, data, self.msg.protocol_magic, self.msg.network_id
)
await show_auxiliary_data(
await auxiliary_data.show_auxiliary_data(
self.ctx,
self.keychain,
auxiliary_data_hash,
auxiliary_data.catalyst_registration_parameters,
data.catalyst_registration_parameters,
self.msg.protocol_magic,
self.msg.network_id,
)
@ -750,9 +732,9 @@ class Signer:
raise INVALID_REQUIRED_SIGNER
elif required_signer.key_path:
if not (
is_shelley_path(required_signer.key_path)
or is_multisig_path(required_signer.key_path)
or is_minting_path(required_signer.key_path)
seed.is_shelley_path(required_signer.key_path)
or seed.is_multisig_path(required_signer.key_path)
or seed.is_minting_path(required_signer.key_path)
):
raise INVALID_REQUIRED_SIGNER
else:
@ -770,7 +752,7 @@ class Signer:
self._validate_witness_request(witness_request)
path = witness_request.path
await self._show_witness_request(path)
if is_byron_path(path):
if seed.is_byron_path(path):
response = self._get_byron_witness(path, tx_hash)
else:
response = self._get_shelley_witness(path, tx_hash)
@ -808,7 +790,7 @@ class Signer:
def _get_output_address(self, output: messages.CardanoTxOutput) -> bytes:
if output.address_parameters:
return derive_address_bytes(
return addresses.derive_address_bytes(
self.keychain,
output.address_parameters,
self.msg.protocol_magic,
@ -816,7 +798,7 @@ class Signer:
)
else:
assert output.address is not None # _validate_output
return get_address_bytes_unsafe(output.address)
return addresses.get_address_bytes_unsafe(output.address)
def _get_output_address_type(
self, output: messages.CardanoTxOutput
@ -824,7 +806,9 @@ class Signer:
if output.address_parameters:
return output.address_parameters.address_type
assert output.address is not None # _validate_output
return get_address_type(get_address_bytes_unsafe(output.address))
return addresses.get_address_type(
addresses.get_address_bytes_unsafe(output.address)
)
def _derive_withdrawal_address_bytes(
self, withdrawal: messages.CardanoTxWithdrawal
@ -834,7 +818,7 @@ class Signer:
if withdrawal.path or withdrawal.key_hash
else CardanoAddressType.REWARD_SCRIPT
)
return derive_address_bytes(
return addresses.derive_address_bytes(
self.keychain,
messages.CardanoAddressParametersType(
address_type=reward_address_type,

@ -9,8 +9,8 @@ from apps.common import seed
from apps.common.paths import HARDENED
if not utils.BITCOIN_ONLY:
from apps.cardano.address import derive_human_readable_address, validate_address_parameters
from apps.cardano.byron_address import _address_hash
from apps.cardano.addresses import derive_human_readable, validate_address_parameters
from apps.cardano.byron_addresses import _address_hash
from apps.cardano.helpers import network_ids, protocol_magics
from apps.cardano.seed import Keychain
@ -37,7 +37,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000 + i],
)
address = derive_human_readable_address(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
self.assertEqual(expected, address)
nodes = [
@ -81,7 +81,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i],
)
address = derive_human_readable_address(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
self.assertEqual(address, expected)
nodes = [
@ -119,7 +119,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815],
)
address = derive_human_readable_address(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
self.assertEqual(address, "Ae2tdPwUPEZ2FGHX3yCKPSbSgyuuTYgMxNq652zKopxT4TuWvEd8Utd92w3")
priv, ext, pub, chain = (
@ -202,7 +202,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i],
)
a = derive_human_readable_address(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
a = derive_human_readable(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i])
self.assertEqual(a, address)
self.assertEqual(hexlify(n.private_key()), priv)
@ -269,7 +269,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i],
)
a = derive_human_readable_address(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
a = derive_human_readable(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET)
n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i])
self.assertEqual(a, address)
self.assertEqual(hexlify(n.private_key()), priv)
@ -290,7 +290,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i],
)
address = derive_human_readable_address(self.keychain, address_parameters, protocol_magics.TESTNET, 0)
address = derive_human_readable(self.keychain, address_parameters, protocol_magics.TESTNET, 0)
self.assertEqual(expected, address)
def test_derive_address(self):
@ -411,7 +411,7 @@ class TestCardanoAddress(unittest.TestCase):
for network_id, address_type, address_parameters, expected_address in test_vectors:
validate_address_parameters(address_parameters)
actual_address = derive_human_readable_address(self.keychain, address_parameters, protocol_magics.MAINNET, network_id)
actual_address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_id)
self.assertEqual(actual_address, expected_address)

@ -6,7 +6,7 @@ from trezor.messages import CardanoTxCertificate, CardanoPoolParametersType
from apps.common.paths import HARDENED
if not utils.BITCOIN_ONLY:
from apps.cardano.certificates import validate_certificate
from apps.cardano import certificates
from apps.cardano.helpers import protocol_magics, network_ids
from apps.cardano.helpers.account_path_check import AccountPathChecker
@ -344,7 +344,7 @@ class TestCardanoCertificate(unittest.TestCase):
]
for certificate in valid_test_vectors:
validate_certificate(
certificates.validate(
certificate,
protocol_magics.MAINNET,
network_ids.MAINNET,
@ -353,7 +353,7 @@ class TestCardanoCertificate(unittest.TestCase):
for certificate in invalid_test_vectors:
with self.assertRaises(wire.ProcessError):
validate_certificate(
certificates.validate(
certificate,
protocol_magics.MAINNET,
network_ids.MAINNET,

Loading…
Cancel
Save