From a25444efd15e0f8946c7dc80edec29f9705cfbe0 Mon Sep 17 00:00:00 2001 From: gabrielkerekes Date: Mon, 27 Jul 2020 10:32:31 +0200 Subject: [PATCH] Move to_account_path() to utils --- core/src/apps/cardano/address.py | 7 ------- core/src/apps/cardano/get_address.py | 3 ++- core/src/apps/cardano/helpers/staking_use_cases.py | 3 ++- core/src/apps/cardano/helpers/utils.py | 8 ++++++++ core/src/apps/cardano/sign_tx.py | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/apps/cardano/address.py b/core/src/apps/cardano/address.py index e8f9ce32a4..dcb1e9fe4e 100644 --- a/core/src/apps/cardano/address.py +++ b/core/src/apps/cardano/address.py @@ -1,5 +1,3 @@ -from micropython import const - from trezor import wire from trezor.crypto import base58, hashlib from trezor.messages import CardanoAddressParametersType, CardanoAddressType @@ -331,8 +329,3 @@ def _derive_reward_address( staking_key_hash = get_public_key_hash(keychain, path) return header + staking_key_hash - - -def to_account_path(path: List[int]) -> List[int]: - ACCOUNT_PATH_LENGTH = const(3) - return path[:ACCOUNT_PATH_LENGTH] diff --git a/core/src/apps/cardano/get_address.py b/core/src/apps/cardano/get_address.py index b4ded740f3..622569f6d6 100644 --- a/core/src/apps/cardano/get_address.py +++ b/core/src/apps/cardano/get_address.py @@ -5,8 +5,9 @@ from apps.common import paths from apps.common.layout import address_n_to_str, show_qr from . import CURVE, seed -from .address import derive_human_readable_address, to_account_path, validate_full_path +from .address import derive_human_readable_address, validate_full_path from .helpers import protocol_magics, staking_use_cases +from .helpers.utils import to_account_path from .layout import ( show_address, show_warning_address_foreign_staking_key, diff --git a/core/src/apps/cardano/helpers/staking_use_cases.py b/core/src/apps/cardano/helpers/staking_use_cases.py index 10a23d2cc6..e489388505 100644 --- a/core/src/apps/cardano/helpers/staking_use_cases.py +++ b/core/src/apps/cardano/helpers/staking_use_cases.py @@ -1,7 +1,8 @@ from trezor.messages import CardanoAddressType -from ..address import get_public_key_hash, to_account_path, validate_full_path +from ..address import get_public_key_hash, validate_full_path from ..seed import is_shelley_path +from .utils import to_account_path if False: from typing import List diff --git a/core/src/apps/cardano/helpers/utils.py b/core/src/apps/cardano/helpers/utils.py index f0e8727653..dd4b1378da 100644 --- a/core/src/apps/cardano/helpers/utils.py +++ b/core/src/apps/cardano/helpers/utils.py @@ -1,3 +1,6 @@ +from micropython import const + + def variable_length_encode(number: int) -> bytes: """ Used for pointer encoding in pointer address. @@ -18,3 +21,8 @@ def variable_length_encode(number: int) -> bytes: encoded.insert(0, (number & 127) + 128) return bytes(encoded) + + +def to_account_path(path: List[int]) -> List[int]: + ACCOUNT_PATH_LENGTH = const(3) + return path[:ACCOUNT_PATH_LENGTH] diff --git a/core/src/apps/cardano/sign_tx.py b/core/src/apps/cardano/sign_tx.py index eae078467c..820e1d36e9 100644 --- a/core/src/apps/cardano/sign_tx.py +++ b/core/src/apps/cardano/sign_tx.py @@ -15,12 +15,12 @@ from .address import ( derive_address_bytes, derive_human_readable_address, get_address_bytes_unsafe, - to_account_path, validate_full_path, validate_output_address, ) from .byron_address import get_address_attributes from .helpers import network_ids, protocol_magics, staking_use_cases +from .helpers.utils import to_account_path from .layout import ( confirm_sending, confirm_transaction,