From f25119e44d237879e8cda467c16afa703176ea49 Mon Sep 17 00:00:00 2001 From: grdddj Date: Thu, 15 Sep 2022 18:30:05 +0200 Subject: [PATCH] chore(core): import trezor.messages in TYPE_CHECKING branch - saving 1kb --- core/src/apps/binance/get_address.py | 3 ++- core/src/apps/binance/get_public_key.py | 3 ++- core/src/apps/binance/helpers.py | 9 ++----- core/src/apps/binance/layout.py | 12 ++++----- core/src/apps/binance/sign_tx.py | 6 ++++- core/src/apps/bitcoin/addresses.py | 2 +- core/src/apps/bitcoin/authorize_coinjoin.py | 26 +++++++++++-------- core/src/apps/bitcoin/get_address.py | 3 +-- core/src/apps/bitcoin/get_ownership_id.py | 3 ++- core/src/apps/bitcoin/get_ownership_proof.py | 3 ++- core/src/apps/bitcoin/multisig.py | 6 ++++- core/src/apps/bitcoin/sign_tx/approvers.py | 6 +---- core/src/apps/bitcoin/sign_tx/bitcoinlike.py | 2 +- core/src/apps/bitcoin/sign_tx/helpers.py | 16 +++++++----- core/src/apps/bitcoin/sign_tx/sig_hasher.py | 2 +- core/src/apps/bitcoin/sign_tx/zcash_v4.py | 2 +- core/src/apps/debug/load_device.py | 7 ++++- core/src/apps/eos/get_public_key.py | 3 ++- core/src/apps/eos/helpers.py | 6 ++++- core/src/apps/eos/sign_tx.py | 7 ++++- core/src/apps/ethereum/helpers.py | 2 +- core/src/apps/ethereum/layout.py | 2 +- core/src/apps/ethereum/sign_tx.py | 3 ++- core/src/apps/ethereum/sign_typed_data.py | 3 ++- .../apps/management/get_next_u2f_counter.py | 7 ++++- core/src/apps/management/get_nonce.py | 7 ++++- .../apps/management/reboot_to_bootloader.py | 5 ++-- core/src/apps/management/set_u2f_counter.py | 7 ++++- core/src/apps/misc/get_firmware_hash.py | 3 ++- core/src/apps/monero/get_tx_keys.py | 3 ++- core/src/apps/nem/mosaic/__init__.py | 11 ++++---- core/src/apps/nem/mosaic/layout.py | 12 ++++----- core/src/apps/nem/mosaic/serialize.py | 11 ++++---- core/src/apps/nem/multisig/__init__.py | 7 +++-- core/src/apps/nem/multisig/layout.py | 6 ++++- core/src/apps/nem/multisig/serialize.py | 2 +- core/src/apps/nem/namespace/__init__.py | 3 +-- core/src/apps/nem/namespace/layout.py | 3 +-- core/src/apps/nem/namespace/serialize.py | 5 +++- core/src/apps/nem/sign_tx.py | 3 ++- core/src/apps/nem/transfer/__init__.py | 3 +-- core/src/apps/nem/transfer/layout.py | 12 ++++----- core/src/apps/nem/validators.py | 24 ++++++++++------- core/src/apps/nem/writers.py | 3 +-- core/src/apps/ripple/get_address.py | 3 ++- core/src/apps/ripple/serialize.py | 3 +-- core/src/apps/ripple/sign_tx.py | 3 ++- core/src/apps/tezos/get_address.py | 3 ++- core/src/apps/tezos/get_public_key.py | 3 ++- .../apps/webauthn/add_resident_credential.py | 7 ++++- .../webauthn/list_resident_credentials.py | 11 ++++---- .../webauthn/remove_resident_credential.py | 7 ++++- core/tests/test_apps.nem.mosaic_creation.py | 4 +-- .../test_apps.nem.mosaic_supply_change.py | 4 +-- core/tests/test_apps.nem.multisig.py | 6 +---- core/tests/test_apps.nem.namespace.py | 2 +- core/tests/test_apps.ripple.serializer.py | 19 +++----------- 57 files changed, 197 insertions(+), 152 deletions(-) diff --git a/core/src/apps/binance/get_address.py b/core/src/apps/binance/get_address.py index 202e64863e..88f4434375 100644 --- a/core/src/apps/binance/get_address.py +++ b/core/src/apps/binance/get_address.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from trezor.messages import BinanceAddress, BinanceGetAddress +from trezor.messages import BinanceAddress from trezor.ui.layouts import show_address from apps.common import paths @@ -9,6 +9,7 @@ from apps.common.keychain import Keychain, auto_keychain from .helpers import address_from_public_key if TYPE_CHECKING: + from trezor.messages import BinanceGetAddress from trezor.wire import Context diff --git a/core/src/apps/binance/get_public_key.py b/core/src/apps/binance/get_public_key.py index 350b694c8c..9690740740 100644 --- a/core/src/apps/binance/get_public_key.py +++ b/core/src/apps/binance/get_public_key.py @@ -1,13 +1,14 @@ from typing import TYPE_CHECKING from ubinascii import hexlify -from trezor.messages import BinanceGetPublicKey, BinancePublicKey +from trezor.messages import BinancePublicKey from trezor.ui.layouts import show_pubkey from apps.common import paths from apps.common.keychain import Keychain, auto_keychain if TYPE_CHECKING: + from trezor.messages import BinanceGetPublicKey from trezor.wire import Context diff --git a/core/src/apps/binance/helpers.py b/core/src/apps/binance/helpers.py index 742e675f0d..5223b4c60f 100644 --- a/core/src/apps/binance/helpers.py +++ b/core/src/apps/binance/helpers.py @@ -4,15 +4,10 @@ from typing import TYPE_CHECKING from trezor import wire from trezor.crypto import bech32 from trezor.crypto.scripts import sha256_ripemd160 -from trezor.messages import ( - BinanceCancelMsg, - BinanceInputOutput, - BinanceOrderMsg, - BinanceSignTx, - BinanceTransferMsg, -) +from trezor.messages import BinanceCancelMsg, BinanceOrderMsg, BinanceTransferMsg if TYPE_CHECKING: + from trezor.messages import BinanceInputOutput, BinanceSignTx from trezor.protobuf import MessageType ENVELOPE_BLUEPRINT = '{{"account_number":"{account_number}","chain_id":"{chain_id}","data":null,"memo":"{memo}","msgs":[{msgs}],"sequence":"{sequence}","source":"{source}"}}' diff --git a/core/src/apps/binance/layout.py b/core/src/apps/binance/layout.py index eddd545d8c..897fe4725b 100644 --- a/core/src/apps/binance/layout.py +++ b/core/src/apps/binance/layout.py @@ -1,12 +1,6 @@ from typing import TYPE_CHECKING from trezor.enums import BinanceOrderSide, ButtonRequestType -from trezor.messages import ( - BinanceCancelMsg, - BinanceInputOutput, - BinanceOrderMsg, - BinanceTransferMsg, -) from trezor.strings import format_amount from trezor.ui.layouts import confirm_properties from trezor.ui.layouts.altcoin import confirm_transfer_binance @@ -14,6 +8,12 @@ from trezor.ui.layouts.altcoin import confirm_transfer_binance from . import helpers if TYPE_CHECKING: + from trezor.messages import ( + BinanceCancelMsg, + BinanceInputOutput, + BinanceOrderMsg, + BinanceTransferMsg, + ) from trezor.wire import Context diff --git a/core/src/apps/binance/sign_tx.py b/core/src/apps/binance/sign_tx.py index b1230de101..4c699a1a6a 100644 --- a/core/src/apps/binance/sign_tx.py +++ b/core/src/apps/binance/sign_tx.py @@ -1,3 +1,5 @@ +from typing import TYPE_CHECKING + from trezor import wire from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha256 @@ -6,7 +8,6 @@ from trezor.messages import ( BinanceCancelMsg, BinanceOrderMsg, BinanceSignedTx, - BinanceSignTx, BinanceTransferMsg, BinanceTxRequest, ) @@ -16,6 +17,9 @@ from apps.common.keychain import Keychain, auto_keychain from . import helpers, layout +if TYPE_CHECKING: + from trezor.messages import BinanceSignTx + @auto_keychain(__name__) async def sign_tx( diff --git a/core/src/apps/bitcoin/addresses.py b/core/src/apps/bitcoin/addresses.py index 59a8624fcf..ffa564463d 100644 --- a/core/src/apps/bitcoin/addresses.py +++ b/core/src/apps/bitcoin/addresses.py @@ -5,7 +5,6 @@ from trezor.crypto import base58, cashaddr from trezor.crypto.curve import bip340 from trezor.crypto.hashlib import sha256 from trezor.enums import InputScriptType -from trezor.messages import MultisigRedeemScriptType from trezor.utils import HashWriter from apps.common import address_type @@ -16,6 +15,7 @@ from .multisig import multisig_get_pubkeys, multisig_pubkey_index from .scripts import output_script_native_segwit, write_output_script_multisig if TYPE_CHECKING: + from trezor.messages import MultisigRedeemScriptType from trezor.crypto import bip32 diff --git a/core/src/apps/bitcoin/authorize_coinjoin.py b/core/src/apps/bitcoin/authorize_coinjoin.py index 99668fde1e..0b71a05181 100644 --- a/core/src/apps/bitcoin/authorize_coinjoin.py +++ b/core/src/apps/bitcoin/authorize_coinjoin.py @@ -1,22 +1,14 @@ from micropython import const from typing import TYPE_CHECKING -from trezor import wire -from trezor.enums import ButtonRequestType -from trezor.messages import AuthorizeCoinJoin, Success -from trezor.ui.layouts import confirm_coinjoin, confirm_metadata - -from apps.common import authorization, safety_checks -from apps.common.keychain import FORBIDDEN_KEY_PATH -from apps.common.paths import SLIP25_PURPOSE, validate_path - from .authorization import FEE_RATE_DECIMALS -from .common import BIP32_WALLET_DEPTH, format_fee_rate -from .keychain import validate_path_against_script_type, with_keychain +from .keychain import with_keychain if TYPE_CHECKING: + from trezor.messages import AuthorizeCoinJoin, Success from apps.common.coininfo import CoinInfo from apps.common.keychain import Keychain + from trezor import wire _MAX_COORDINATOR_LEN = const(36) _MAX_ROUNDS = const(500) @@ -27,6 +19,18 @@ _MAX_COORDINATOR_FEE_RATE = 5 * pow(10, FEE_RATE_DECIMALS) # 5 % async def authorize_coinjoin( ctx: wire.Context, msg: AuthorizeCoinJoin, keychain: Keychain, coin: CoinInfo ) -> Success: + from trezor import wire + from trezor.enums import ButtonRequestType + from trezor.messages import Success + from trezor.ui.layouts import confirm_coinjoin, confirm_metadata + + from apps.common import authorization, safety_checks + from apps.common.keychain import FORBIDDEN_KEY_PATH + from apps.common.paths import SLIP25_PURPOSE, validate_path + + from .keychain import validate_path_against_script_type + from .common import BIP32_WALLET_DEPTH, format_fee_rate + if len(msg.coordinator) > _MAX_COORDINATOR_LEN or not all( 32 <= ord(x) <= 126 for x in msg.coordinator ): diff --git a/core/src/apps/bitcoin/get_address.py b/core/src/apps/bitcoin/get_address.py index 315e43c4d6..7c7f9dd965 100644 --- a/core/src/apps/bitcoin/get_address.py +++ b/core/src/apps/bitcoin/get_address.py @@ -13,8 +13,7 @@ from .keychain import validate_path_against_script_type, with_keychain from .multisig import multisig_pubkey_index if TYPE_CHECKING: - from trezor.messages import GetAddress - from trezor.messages import HDNodeType + from trezor.messages import GetAddress, HDNodeType from trezor import wire from apps.common.keychain import Keychain from apps.common.coininfo import CoinInfo diff --git a/core/src/apps/bitcoin/get_ownership_id.py b/core/src/apps/bitcoin/get_ownership_id.py index d251bc0822..4d34c27626 100644 --- a/core/src/apps/bitcoin/get_ownership_id.py +++ b/core/src/apps/bitcoin/get_ownership_id.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING from trezor import wire from trezor.enums import InputScriptType -from trezor.messages import GetOwnershipId, OwnershipId +from trezor.messages import OwnershipId from apps.common.paths import validate_path @@ -11,6 +11,7 @@ from .keychain import validate_path_against_script_type, with_keychain from .ownership import get_identifier if TYPE_CHECKING: + from trezor.messages import GetOwnershipId from apps.common.coininfo import CoinInfo from apps.common.keychain import Keychain diff --git a/core/src/apps/bitcoin/get_ownership_proof.py b/core/src/apps/bitcoin/get_ownership_proof.py index 76b1bce92a..20edadfd46 100644 --- a/core/src/apps/bitcoin/get_ownership_proof.py +++ b/core/src/apps/bitcoin/get_ownership_proof.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING from trezor import ui, wire from trezor.enums import InputScriptType -from trezor.messages import GetOwnershipProof, OwnershipProof +from trezor.messages import OwnershipProof from trezor.ui.layouts import confirm_action, confirm_blob from apps.common.paths import validate_path @@ -12,6 +12,7 @@ from .keychain import validate_path_against_script_type, with_keychain from .ownership import generate_proof, get_identifier if TYPE_CHECKING: + from trezor.messages import GetOwnershipProof from apps.common.coininfo import CoinInfo from apps.common.keychain import Keychain from .authorization import CoinJoinAuthorization diff --git a/core/src/apps/bitcoin/multisig.py b/core/src/apps/bitcoin/multisig.py index b3ba48e989..17eab0be70 100644 --- a/core/src/apps/bitcoin/multisig.py +++ b/core/src/apps/bitcoin/multisig.py @@ -1,13 +1,17 @@ +from typing import TYPE_CHECKING + from trezor import wire from trezor.crypto import bip32 from trezor.crypto.hashlib import sha256 -from trezor.messages import HDNodeType, MultisigRedeemScriptType from trezor.utils import HashWriter from apps.common import paths from .writers import write_bytes_fixed, write_uint32 +if TYPE_CHECKING: + from trezor.messages import HDNodeType, MultisigRedeemScriptType + def multisig_fingerprint(multisig: MultisigRedeemScriptType) -> bytes: if multisig.nodes: diff --git a/core/src/apps/bitcoin/sign_tx/approvers.py b/core/src/apps/bitcoin/sign_tx/approvers.py index 2297c41f9a..54010680ce 100644 --- a/core/src/apps/bitcoin/sign_tx/approvers.py +++ b/core/src/apps/bitcoin/sign_tx/approvers.py @@ -21,11 +21,7 @@ from .tx_info import OriginalTxInfo, TxInfo if TYPE_CHECKING: from trezor.crypto import bip32 - - from trezor.messages import SignTx - from trezor.messages import TxInput - from trezor.messages import TxOutput - from trezor.messages import TxAckPaymentRequest + from trezor.messages import SignTx, TxInput, TxOutput, TxAckPaymentRequest from apps.common.coininfo import CoinInfo from apps.common.keychain import Keychain diff --git a/core/src/apps/bitcoin/sign_tx/bitcoinlike.py b/core/src/apps/bitcoin/sign_tx/bitcoinlike.py index dfa347301f..5e4f62de59 100644 --- a/core/src/apps/bitcoin/sign_tx/bitcoinlike.py +++ b/core/src/apps/bitcoin/sign_tx/bitcoinlike.py @@ -1,7 +1,6 @@ from typing import TYPE_CHECKING from trezor import wire -from trezor.messages import PrevTx, SignTx, TxInput from apps.common.writers import write_compact_size @@ -12,6 +11,7 @@ from .bitcoin import Bitcoin if TYPE_CHECKING: from typing import Sequence + from trezor.messages import PrevTx, SignTx, TxInput from .tx_info import OriginalTxInfo, TxInfo diff --git a/core/src/apps/bitcoin/sign_tx/helpers.py b/core/src/apps/bitcoin/sign_tx/helpers.py index e1277d5111..ebd79230f0 100644 --- a/core/src/apps/bitcoin/sign_tx/helpers.py +++ b/core/src/apps/bitcoin/sign_tx/helpers.py @@ -3,10 +3,6 @@ from typing import TYPE_CHECKING from trezor import utils, wire from trezor.enums import InputScriptType, OutputScriptType, RequestType from trezor.messages import ( - PrevInput, - PrevOutput, - PrevTx, - SignTx, TxAckInput, TxAckOutput, TxAckPaymentRequest, @@ -14,9 +10,6 @@ from trezor.messages import ( TxAckPrevInput, TxAckPrevMeta, TxAckPrevOutput, - TxInput, - TxOutput, - TxRequest, ) from apps.common import paths @@ -30,6 +23,15 @@ if TYPE_CHECKING: from typing import Any, Awaitable from trezor.enums import AmountUnit + from trezor.messages import ( + PrevInput, + PrevOutput, + PrevTx, + SignTx, + TxInput, + TxOutput, + TxRequest, + ) # Machine instructions # === diff --git a/core/src/apps/bitcoin/sign_tx/sig_hasher.py b/core/src/apps/bitcoin/sign_tx/sig_hasher.py index bdb8d3daae..5a41704e14 100644 --- a/core/src/apps/bitcoin/sign_tx/sig_hasher.py +++ b/core/src/apps/bitcoin/sign_tx/sig_hasher.py @@ -1,7 +1,6 @@ from typing import TYPE_CHECKING from trezor.crypto.hashlib import sha256 -from trezor.messages import PrevTx, SignTx, TxInput, TxOutput from trezor.utils import HashWriter from apps.common import coininfo @@ -12,6 +11,7 @@ from ..common import tagged_hashwriter if TYPE_CHECKING: from typing import Protocol, Sequence from ..common import SigHashType + from trezor.messages import PrevTx, SignTx, TxInput, TxOutput class SigHasher(Protocol): def add_input(self, txi: TxInput, script_pubkey: bytes) -> None: diff --git a/core/src/apps/bitcoin/sign_tx/zcash_v4.py b/core/src/apps/bitcoin/sign_tx/zcash_v4.py index f1d5034f43..ce683f104b 100644 --- a/core/src/apps/bitcoin/sign_tx/zcash_v4.py +++ b/core/src/apps/bitcoin/sign_tx/zcash_v4.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING from trezor import wire from trezor.crypto.hashlib import blake2b -from trezor.messages import PrevTx, SignTx, TxInput, TxOutput from trezor.utils import HashWriter, ensure from apps.common.coininfo import CoinInfo @@ -25,6 +24,7 @@ from . import approvers, helpers from .bitcoinlike import Bitcoinlike if TYPE_CHECKING: + from trezor.messages import PrevTx, SignTx, TxInput, TxOutput from typing import Sequence from apps.common import coininfo from .sig_hasher import SigHasher diff --git a/core/src/apps/debug/load_device.py b/core/src/apps/debug/load_device.py index 4f1cfc9f28..cf07f69b45 100644 --- a/core/src/apps/debug/load_device.py +++ b/core/src/apps/debug/load_device.py @@ -1,13 +1,18 @@ +from typing import TYPE_CHECKING + import storage import storage.device from trezor import config, wire from trezor.crypto import bip39, slip39 from trezor.enums import BackupType -from trezor.messages import LoadDevice, Success +from trezor.messages import Success from trezor.ui.layouts import confirm_action from apps.management import backup_types +if TYPE_CHECKING: + from trezor.messages import LoadDevice + async def load_device(ctx: wire.Context, msg: LoadDevice) -> Success: word_count = _validate(msg) diff --git a/core/src/apps/eos/get_public_key.py b/core/src/apps/eos/get_public_key.py index 75d3776d31..0a1d1a60a4 100644 --- a/core/src/apps/eos/get_public_key.py +++ b/core/src/apps/eos/get_public_key.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING from trezor import wire from trezor.crypto.curve import secp256k1 -from trezor.messages import EosGetPublicKey, EosPublicKey +from trezor.messages import EosPublicKey from apps.common import paths from apps.common.keychain import Keychain, auto_keychain @@ -11,6 +11,7 @@ from .helpers import public_key_to_wif from .layout import require_get_public_key if TYPE_CHECKING: + from trezor.messages import EosGetPublicKey from trezor.crypto import bip32 diff --git a/core/src/apps/eos/helpers.py b/core/src/apps/eos/helpers.py index c3870c50f6..a4ddd0c515 100644 --- a/core/src/apps/eos/helpers.py +++ b/core/src/apps/eos/helpers.py @@ -1,6 +1,10 @@ +from typing import TYPE_CHECKING + from trezor import wire from trezor.crypto import base58 -from trezor.messages import EosAsset + +if TYPE_CHECKING: + from trezor.messages import EosAsset def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str: diff --git a/core/src/apps/eos/sign_tx.py b/core/src/apps/eos/sign_tx.py index 9070acad84..990b6bb535 100644 --- a/core/src/apps/eos/sign_tx.py +++ b/core/src/apps/eos/sign_tx.py @@ -1,7 +1,9 @@ +from typing import TYPE_CHECKING + from trezor import wire from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha256 -from trezor.messages import EosSignedTx, EosSignTx, EosTxActionAck, EosTxActionRequest +from trezor.messages import EosSignedTx, EosTxActionAck, EosTxActionRequest from trezor.utils import HashWriter from apps.common import paths @@ -12,6 +14,9 @@ from .actions import process_action from .helpers import base58_encode from .layout import require_sign_tx +if TYPE_CHECKING: + from trezor.messages import EosSignTx + @auto_keychain(__name__) async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosSignedTx: diff --git a/core/src/apps/ethereum/helpers.py b/core/src/apps/ethereum/helpers.py index de53c71470..116e35d5d4 100644 --- a/core/src/apps/ethereum/helpers.py +++ b/core/src/apps/ethereum/helpers.py @@ -3,9 +3,9 @@ from ubinascii import hexlify, unhexlify from trezor import wire from trezor.enums import EthereumDataType -from trezor.messages import EthereumFieldType if TYPE_CHECKING: + from trezor.messages import EthereumFieldType from .networks import NetworkInfo diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 5018323cd5..56ecf83baa 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -3,7 +3,6 @@ from ubinascii import hexlify from trezor import ui from trezor.enums import ButtonRequestType, EthereumDataType -from trezor.messages import EthereumFieldType, EthereumStructMember from trezor.strings import format_amount, format_plural from trezor.ui.layouts import ( confirm_action, @@ -23,6 +22,7 @@ from .helpers import address_from_bytes, decode_typed_data, get_type_name if TYPE_CHECKING: from typing import Awaitable, Iterable + from trezor.messages import EthereumFieldType, EthereumStructMember from trezor.wire import Context diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index f40a334849..b4b42930ae 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -4,7 +4,7 @@ from trezor import wire from trezor.crypto import rlp from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha3_256 -from trezor.messages import EthereumSignTx, EthereumTxAck, EthereumTxRequest +from trezor.messages import EthereumTxAck, EthereumTxRequest from trezor.utils import HashWriter from apps.common import paths @@ -21,6 +21,7 @@ from .layout import ( if TYPE_CHECKING: from apps.common.keychain import Keychain + from trezor.messages import EthereumSignTx from .keychain import EthereumSignTxAny diff --git a/core/src/apps/ethereum/sign_typed_data.py b/core/src/apps/ethereum/sign_typed_data.py index fa8b8331a0..9109cd261d 100644 --- a/core/src/apps/ethereum/sign_typed_data.py +++ b/core/src/apps/ethereum/sign_typed_data.py @@ -7,7 +7,6 @@ from trezor.crypto.hashlib import sha3_256 from trezor.enums import EthereumDataType from trezor.messages import ( EthereumFieldType, - EthereumSignTypedData, EthereumTypedDataSignature, EthereumTypedDataStructAck, EthereumTypedDataStructRequest, @@ -33,6 +32,8 @@ if TYPE_CHECKING: from apps.common.keychain import Keychain from trezor.wire import Context + from trezor.messages import EthereumSignTypedData + # Maximum data size we support _MAX_VALUE_BYTE_SIZE = const(1024) diff --git a/core/src/apps/management/get_next_u2f_counter.py b/core/src/apps/management/get_next_u2f_counter.py index d6eb1752be..fba46429bb 100644 --- a/core/src/apps/management/get_next_u2f_counter.py +++ b/core/src/apps/management/get_next_u2f_counter.py @@ -1,9 +1,14 @@ +from typing import TYPE_CHECKING + import storage.device from trezor import ui, wire from trezor.enums import ButtonRequestType -from trezor.messages import GetNextU2FCounter, NextU2FCounter +from trezor.messages import NextU2FCounter from trezor.ui.layouts import confirm_action +if TYPE_CHECKING: + from trezor.messages import GetNextU2FCounter + async def get_next_u2f_counter( ctx: wire.Context, msg: GetNextU2FCounter diff --git a/core/src/apps/management/get_nonce.py b/core/src/apps/management/get_nonce.py index 3f255975ff..30ff20463c 100644 --- a/core/src/apps/management/get_nonce.py +++ b/core/src/apps/management/get_nonce.py @@ -1,7 +1,12 @@ +from typing import TYPE_CHECKING + from storage import cache from trezor import wire from trezor.crypto import random -from trezor.messages import GetNonce, Nonce +from trezor.messages import Nonce + +if TYPE_CHECKING: + from trezor.messages import GetNonce async def get_nonce(ctx: wire.Context, msg: GetNonce) -> Nonce: diff --git a/core/src/apps/management/reboot_to_bootloader.py b/core/src/apps/management/reboot_to_bootloader.py index 1a6367728e..0e4bbe3be4 100644 --- a/core/src/apps/management/reboot_to_bootloader.py +++ b/core/src/apps/management/reboot_to_bootloader.py @@ -2,14 +2,13 @@ from typing import TYPE_CHECKING import storage.device from trezor import io, loop, utils, wire -from trezor.messages import RebootToBootloader, Success +from trezor.messages import Success from trezor.ui.layouts import confirm_action if TYPE_CHECKING: + from trezor.messages import RebootToBootloader from typing import NoReturn - pass - async def reboot_to_bootloader(ctx: wire.Context, msg: RebootToBootloader) -> NoReturn: if not storage.device.get_experimental_features(): diff --git a/core/src/apps/management/set_u2f_counter.py b/core/src/apps/management/set_u2f_counter.py index 4897b06192..76da2a2a7d 100644 --- a/core/src/apps/management/set_u2f_counter.py +++ b/core/src/apps/management/set_u2f_counter.py @@ -1,9 +1,14 @@ +from typing import TYPE_CHECKING + import storage.device from trezor import ui, wire from trezor.enums import ButtonRequestType -from trezor.messages import SetU2FCounter, Success +from trezor.messages import Success from trezor.ui.layouts import confirm_action +if TYPE_CHECKING: + from trezor.messages import SetU2FCounter + async def set_u2f_counter(ctx: wire.Context, msg: SetU2FCounter) -> Success: if not storage.device.is_initialized(): diff --git a/core/src/apps/misc/get_firmware_hash.py b/core/src/apps/misc/get_firmware_hash.py index ecc197ceba..4f88f127ad 100644 --- a/core/src/apps/misc/get_firmware_hash.py +++ b/core/src/apps/misc/get_firmware_hash.py @@ -1,11 +1,12 @@ from typing import TYPE_CHECKING from trezor import ui, wire, workflow -from trezor.messages import FirmwareHash, GetFirmwareHash +from trezor.messages import FirmwareHash from trezor.ui.layouts import draw_simple_text from trezor.utils import DISABLE_ANIMATION, firmware_hash if TYPE_CHECKING: + from trezor.messages import GetFirmwareHash from trezor.wire import Context diff --git a/core/src/apps/monero/get_tx_keys.py b/core/src/apps/monero/get_tx_keys.py index 5c385fbc27..7747532ee1 100644 --- a/core/src/apps/monero/get_tx_keys.py +++ b/core/src/apps/monero/get_tx_keys.py @@ -18,7 +18,7 @@ from micropython import const from typing import TYPE_CHECKING from trezor import utils, wire -from trezor.messages import MoneroGetTxKeyAck, MoneroGetTxKeyRequest +from trezor.messages import MoneroGetTxKeyAck from apps.common import paths from apps.common.keychain import auto_keychain @@ -28,6 +28,7 @@ from apps.monero.xmr import chacha_poly, crypto, crypto_helpers _GET_TX_KEY_REASON_TX_DERIVATION = const(1) if TYPE_CHECKING: + from trezor.messages import MoneroGetTxKeyRequest from apps.common.keychain import Keychain diff --git a/core/src/apps/nem/mosaic/__init__.py b/core/src/apps/nem/mosaic/__init__.py index 216835188e..17bbbba62a 100644 --- a/core/src/apps/nem/mosaic/__init__.py +++ b/core/src/apps/nem/mosaic/__init__.py @@ -1,14 +1,13 @@ from typing import TYPE_CHECKING -from trezor.messages import ( - NEMMosaicCreation, - NEMMosaicSupplyChange, - NEMTransactionCommon, -) - from . import layout, serialize if TYPE_CHECKING: + from trezor.messages import ( + NEMMosaicCreation, + NEMMosaicSupplyChange, + NEMTransactionCommon, + ) from trezor.wire import Context diff --git a/core/src/apps/nem/mosaic/layout.py b/core/src/apps/nem/mosaic/layout.py index 00acabfe16..0b40dd3ff5 100644 --- a/core/src/apps/nem/mosaic/layout.py +++ b/core/src/apps/nem/mosaic/layout.py @@ -2,12 +2,6 @@ from typing import TYPE_CHECKING from trezor import ui from trezor.enums import NEMMosaicLevy, NEMSupplyChangeType -from trezor.messages import ( - NEMMosaicCreation, - NEMMosaicDefinition, - NEMMosaicSupplyChange, - NEMTransactionCommon, -) from trezor.ui.layouts import confirm_properties from ..layout import ( @@ -18,6 +12,12 @@ from ..layout import ( ) if TYPE_CHECKING: + from trezor.messages import ( + NEMMosaicCreation, + NEMMosaicDefinition, + NEMMosaicSupplyChange, + NEMTransactionCommon, + ) from trezor.wire import Context diff --git a/core/src/apps/nem/mosaic/serialize.py b/core/src/apps/nem/mosaic/serialize.py index a043e815af..c6c2d617d1 100644 --- a/core/src/apps/nem/mosaic/serialize.py +++ b/core/src/apps/nem/mosaic/serialize.py @@ -1,11 +1,5 @@ from typing import TYPE_CHECKING -from trezor.messages import ( - NEMMosaicCreation, - NEMMosaicSupplyChange, - NEMTransactionCommon, -) - from ..helpers import ( NEM_TRANSACTION_TYPE_MOSAIC_CREATION, NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE, @@ -18,6 +12,11 @@ from ..writers import ( ) if TYPE_CHECKING: + from trezor.messages import ( + NEMMosaicCreation, + NEMMosaicSupplyChange, + NEMTransactionCommon, + ) from trezor.utils import Writer diff --git a/core/src/apps/nem/multisig/__init__.py b/core/src/apps/nem/multisig/__init__.py index 417b4736e5..51c67241fa 100644 --- a/core/src/apps/nem/multisig/__init__.py +++ b/core/src/apps/nem/multisig/__init__.py @@ -1,10 +1,13 @@ from typing import TYPE_CHECKING -from trezor.messages import NEMAggregateModification, NEMSignTx, NEMTransactionCommon - from . import layout, serialize if TYPE_CHECKING: + from trezor.messages import ( + NEMAggregateModification, + NEMSignTx, + NEMTransactionCommon, + ) from trezor.wire import Context diff --git a/core/src/apps/nem/multisig/layout.py b/core/src/apps/nem/multisig/layout.py index 13b747276f..507bc5010b 100644 --- a/core/src/apps/nem/multisig/layout.py +++ b/core/src/apps/nem/multisig/layout.py @@ -3,12 +3,16 @@ from typing import TYPE_CHECKING from trezor import ui from trezor.crypto import nem from trezor.enums import ButtonRequestType, NEMModificationType -from trezor.messages import NEMAggregateModification, NEMSignTx, NEMTransactionCommon from trezor.ui.layouts import confirm_address from ..layout import require_confirm_fee, require_confirm_final, require_confirm_text if TYPE_CHECKING: + from trezor.messages import ( + NEMAggregateModification, + NEMSignTx, + NEMTransactionCommon, + ) from trezor.wire import Context diff --git a/core/src/apps/nem/multisig/serialize.py b/core/src/apps/nem/multisig/serialize.py index c2039f8fd6..e02f203eaf 100644 --- a/core/src/apps/nem/multisig/serialize.py +++ b/core/src/apps/nem/multisig/serialize.py @@ -1,7 +1,6 @@ from typing import TYPE_CHECKING from trezor.crypto import hashlib, nem -from trezor.messages import NEMAggregateModification, NEMTransactionCommon from ..helpers import ( NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION, @@ -11,6 +10,7 @@ from ..helpers import ( from ..writers import serialize_tx_common, write_bytes_with_len, write_uint32_le if TYPE_CHECKING: + from trezor.messages import NEMAggregateModification, NEMTransactionCommon from trezor.utils import Writer diff --git a/core/src/apps/nem/namespace/__init__.py b/core/src/apps/nem/namespace/__init__.py index 85c3c63641..46125b625e 100644 --- a/core/src/apps/nem/namespace/__init__.py +++ b/core/src/apps/nem/namespace/__init__.py @@ -1,10 +1,9 @@ from typing import TYPE_CHECKING -from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon - from . import layout, serialize if TYPE_CHECKING: + from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon from trezor.wire import Context diff --git a/core/src/apps/nem/namespace/layout.py b/core/src/apps/nem/namespace/layout.py index ceef79bf1c..400e29a4eb 100644 --- a/core/src/apps/nem/namespace/layout.py +++ b/core/src/apps/nem/namespace/layout.py @@ -1,10 +1,9 @@ from typing import TYPE_CHECKING -from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon - from ..layout import require_confirm_content, require_confirm_fee, require_confirm_final if TYPE_CHECKING: + from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon from trezor.wire import Context diff --git a/core/src/apps/nem/namespace/serialize.py b/core/src/apps/nem/namespace/serialize.py index abdf6c4056..f4c8e7cba0 100644 --- a/core/src/apps/nem/namespace/serialize.py +++ b/core/src/apps/nem/namespace/serialize.py @@ -1,4 +1,4 @@ -from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon +from typing import TYPE_CHECKING from ..helpers import NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE from ..writers import ( @@ -8,6 +8,9 @@ from ..writers import ( write_uint64_le, ) +if TYPE_CHECKING: + from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon + def serialize_provision_namespace( common: NEMTransactionCommon, namespace: NEMProvisionNamespace, public_key: bytes diff --git a/core/src/apps/nem/sign_tx.py b/core/src/apps/nem/sign_tx.py index c2551743e7..6be98987ca 100644 --- a/core/src/apps/nem/sign_tx.py +++ b/core/src/apps/nem/sign_tx.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING from trezor import wire from trezor.crypto.curve import ed25519 -from trezor.messages import NEMSignedTx, NEMSignTx +from trezor.messages import NEMSignedTx from apps.common import seed from apps.common.keychain import with_slip44_keychain @@ -13,6 +13,7 @@ from .helpers import NEM_HASH_ALG, check_path from .validators import validate if TYPE_CHECKING: + from trezor.messages import NEMSignTx from apps.common.keychain import Keychain diff --git a/core/src/apps/nem/transfer/__init__.py b/core/src/apps/nem/transfer/__init__.py index 5ff1ca5598..06aa5982c5 100644 --- a/core/src/apps/nem/transfer/__init__.py +++ b/core/src/apps/nem/transfer/__init__.py @@ -1,10 +1,9 @@ from typing import TYPE_CHECKING -from trezor.messages import NEMImportanceTransfer, NEMTransactionCommon, NEMTransfer - from . import layout, serialize if TYPE_CHECKING: + from trezor.messages import NEMImportanceTransfer, NEMTransactionCommon, NEMTransfer from trezor.wire import Context from trezor.crypto import bip32 diff --git a/core/src/apps/nem/transfer/layout.py b/core/src/apps/nem/transfer/layout.py index 4e0d0bd033..b279b21e77 100644 --- a/core/src/apps/nem/transfer/layout.py +++ b/core/src/apps/nem/transfer/layout.py @@ -2,12 +2,6 @@ from typing import TYPE_CHECKING from trezor import ui from trezor.enums import ButtonRequestType, NEMImportanceTransferMode, NEMMosaicLevy -from trezor.messages import ( - NEMImportanceTransfer, - NEMMosaic, - NEMTransactionCommon, - NEMTransfer, -) from trezor.strings import format_amount from trezor.ui.layouts import ( confirm_action, @@ -25,6 +19,12 @@ from ..layout import require_confirm_final, require_confirm_text from ..mosaic.helpers import get_mosaic_definition, is_nem_xem_mosaic if TYPE_CHECKING: + from trezor.messages import ( + NEMImportanceTransfer, + NEMMosaic, + NEMTransactionCommon, + NEMTransfer, + ) from trezor.wire import Context from ..mosaic.nem_mosaics import MosaicLevy diff --git a/core/src/apps/nem/validators.py b/core/src/apps/nem/validators.py index f9d0c8aee7..9aa65b2c0c 100644 --- a/core/src/apps/nem/validators.py +++ b/core/src/apps/nem/validators.py @@ -1,15 +1,7 @@ +from typing import TYPE_CHECKING + from trezor.crypto import nem from trezor.enums import NEMModificationType -from trezor.messages import ( - NEMAggregateModification, - NEMImportanceTransfer, - NEMMosaicCreation, - NEMMosaicSupplyChange, - NEMProvisionNamespace, - NEMSignTx, - NEMTransactionCommon, - NEMTransfer, -) from trezor.wire import ProcessError from .helpers import ( @@ -23,6 +15,18 @@ from .helpers import ( NEM_PUBLIC_KEY_SIZE, ) +if TYPE_CHECKING: + from trezor.messages import ( + NEMAggregateModification, + NEMImportanceTransfer, + NEMMosaicCreation, + NEMMosaicSupplyChange, + NEMProvisionNamespace, + NEMSignTx, + NEMTransactionCommon, + NEMTransfer, + ) + def validate(msg: NEMSignTx) -> None: _validate_single_tx(msg) diff --git a/core/src/apps/nem/writers.py b/core/src/apps/nem/writers.py index 555581deb1..3498c46005 100644 --- a/core/src/apps/nem/writers.py +++ b/core/src/apps/nem/writers.py @@ -1,10 +1,9 @@ from typing import TYPE_CHECKING -from trezor.messages import NEMTransactionCommon - from apps.common.writers import write_bytes_unchecked, write_uint32_le, write_uint64_le if TYPE_CHECKING: + from trezor.messages import NEMTransactionCommon from trezor.utils import Writer diff --git a/core/src/apps/ripple/get_address.py b/core/src/apps/ripple/get_address.py index 6fe0c401ec..7b80f80189 100644 --- a/core/src/apps/ripple/get_address.py +++ b/core/src/apps/ripple/get_address.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from trezor.messages import RippleAddress, RippleGetAddress +from trezor.messages import RippleAddress from trezor.ui.layouts import show_address from apps.common import paths @@ -9,6 +9,7 @@ from apps.common.keychain import auto_keychain from .helpers import address_from_public_key if TYPE_CHECKING: + from trezor.messages import RippleGetAddress from apps.common.keychain import Keychain from trezor.wire import Context diff --git a/core/src/apps/ripple/serialize.py b/core/src/apps/ripple/serialize.py index 964bea7423..47a2f69ac4 100644 --- a/core/src/apps/ripple/serialize.py +++ b/core/src/apps/ripple/serialize.py @@ -11,11 +11,10 @@ from micropython import const from typing import TYPE_CHECKING -from trezor.messages import RippleSignTx - from . import helpers if TYPE_CHECKING: + from trezor.messages import RippleSignTx from trezor.utils import Writer diff --git a/core/src/apps/ripple/sign_tx.py b/core/src/apps/ripple/sign_tx.py index 88551cf1df..7c5188724a 100644 --- a/core/src/apps/ripple/sign_tx.py +++ b/core/src/apps/ripple/sign_tx.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING from trezor.crypto import der from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha512 -from trezor.messages import RippleSignedTx, RippleSignTx +from trezor.messages import RippleSignedTx from trezor.wire import ProcessError from apps.common import paths @@ -13,6 +13,7 @@ from . import helpers, layout from .serialize import serialize if TYPE_CHECKING: + from trezor.messages import RippleSignTx from apps.common.keychain import Keychain from trezor.wire import Context diff --git a/core/src/apps/tezos/get_address.py b/core/src/apps/tezos/get_address.py index 1c0b22f09e..fcfd165070 100644 --- a/core/src/apps/tezos/get_address.py +++ b/core/src/apps/tezos/get_address.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING from trezor.crypto import hashlib -from trezor.messages import TezosAddress, TezosGetAddress +from trezor.messages import TezosAddress from trezor.ui.layouts import show_address from apps.common import paths, seed @@ -10,6 +10,7 @@ from apps.common.keychain import with_slip44_keychain from . import CURVE, PATTERNS, SLIP44_ID, helpers if TYPE_CHECKING: + from trezor.messages import TezosGetAddress from apps.common.keychain import Keychain from trezor.wire import Context diff --git a/core/src/apps/tezos/get_public_key.py b/core/src/apps/tezos/get_public_key.py index be36c710bf..077ae9c66a 100644 --- a/core/src/apps/tezos/get_public_key.py +++ b/core/src/apps/tezos/get_public_key.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from trezor.messages import TezosGetPublicKey, TezosPublicKey +from trezor.messages import TezosPublicKey from trezor.ui.layouts import show_pubkey from apps.common import paths, seed @@ -9,6 +9,7 @@ from apps.common.keychain import with_slip44_keychain from . import CURVE, PATTERNS, SLIP44_ID, helpers if TYPE_CHECKING: + from trezor.messages import TezosGetPublicKey from apps.common.keychain import Keychain from trezor.wire import Context diff --git a/core/src/apps/webauthn/add_resident_credential.py b/core/src/apps/webauthn/add_resident_credential.py index 4ef4d4f584..9c505359f0 100644 --- a/core/src/apps/webauthn/add_resident_credential.py +++ b/core/src/apps/webauthn/add_resident_credential.py @@ -1,6 +1,8 @@ +from typing import TYPE_CHECKING + import storage.device from trezor import wire -from trezor.messages import Success, WebAuthnAddResidentCredential +from trezor.messages import Success from trezor.ui.components.common.webauthn import ConfirmInfo from trezor.ui.layouts import show_error_and_raise from trezor.ui.layouts.webauthn import confirm_webauthn @@ -8,6 +10,9 @@ from trezor.ui.layouts.webauthn import confirm_webauthn from .credential import Fido2Credential from .resident_credentials import store_resident_credential +if TYPE_CHECKING: + from trezor.messages import WebAuthnAddResidentCredential + class ConfirmAddCredential(ConfirmInfo): def __init__(self, cred: Fido2Credential): diff --git a/core/src/apps/webauthn/list_resident_credentials.py b/core/src/apps/webauthn/list_resident_credentials.py index 9140d6a1b9..bbcfe6ea92 100644 --- a/core/src/apps/webauthn/list_resident_credentials.py +++ b/core/src/apps/webauthn/list_resident_credentials.py @@ -1,13 +1,14 @@ +from typing import TYPE_CHECKING + from trezor import wire -from trezor.messages import ( - WebAuthnCredential, - WebAuthnCredentials, - WebAuthnListResidentCredentials, -) +from trezor.messages import WebAuthnCredential, WebAuthnCredentials from trezor.ui.layouts import confirm_action from . import resident_credentials +if TYPE_CHECKING: + from trezor.messages import WebAuthnListResidentCredentials + async def list_resident_credentials( ctx: wire.Context, msg: WebAuthnListResidentCredentials diff --git a/core/src/apps/webauthn/remove_resident_credential.py b/core/src/apps/webauthn/remove_resident_credential.py index b36e5b0c2d..33de0d3409 100644 --- a/core/src/apps/webauthn/remove_resident_credential.py +++ b/core/src/apps/webauthn/remove_resident_credential.py @@ -1,13 +1,18 @@ +from typing import TYPE_CHECKING + import storage.device import storage.resident_credentials from trezor import wire -from trezor.messages import Success, WebAuthnRemoveResidentCredential +from trezor.messages import Success from trezor.ui.components.common.webauthn import ConfirmInfo from trezor.ui.layouts.webauthn import confirm_webauthn from .credential import Fido2Credential from .resident_credentials import get_resident_credential +if TYPE_CHECKING: + from trezor.messages import WebAuthnRemoveResidentCredential + class ConfirmRemoveCredential(ConfirmInfo): def __init__(self, cred: Fido2Credential): diff --git a/core/tests/test_apps.nem.mosaic_creation.py b/core/tests/test_apps.nem.mosaic_creation.py index c058496104..f4833d1351 100644 --- a/core/tests/test_apps.nem.mosaic_creation.py +++ b/core/tests/test_apps.nem.mosaic_creation.py @@ -3,9 +3,7 @@ from common import * from trezor.crypto import hashlib if not utils.BITCOIN_ONLY: - from trezor.messages import NEMSignTx - from trezor.messages import NEMMosaicCreation - from trezor.messages import NEMMosaicDefinition + from trezor.messages import NEMSignTx, NEMMosaicCreation, NEMMosaicDefinition, NEMTransactionCommon from apps.nem.helpers import * from apps.nem.mosaic import * from apps.nem.mosaic.serialize import * diff --git a/core/tests/test_apps.nem.mosaic_supply_change.py b/core/tests/test_apps.nem.mosaic_supply_change.py index 4ee9ac366f..b179f34b0a 100644 --- a/core/tests/test_apps.nem.mosaic_supply_change.py +++ b/core/tests/test_apps.nem.mosaic_supply_change.py @@ -6,9 +6,7 @@ if not utils.BITCOIN_ONLY: from apps.nem.helpers import * from apps.nem.mosaic import * from apps.nem.mosaic.serialize import * - from trezor.messages import NEMSignTx - from trezor.messages import NEMMosaicSupplyChange - + from trezor.messages import NEMSignTx, NEMMosaicSupplyChange, NEMTransactionCommon @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaicSupplyChange(unittest.TestCase): diff --git a/core/tests/test_apps.nem.multisig.py b/core/tests/test_apps.nem.multisig.py index af2255a0a8..07f9b41724 100644 --- a/core/tests/test_apps.nem.multisig.py +++ b/core/tests/test_apps.nem.multisig.py @@ -6,11 +6,7 @@ if not utils.BITCOIN_ONLY: from apps.nem.multisig.serialize import * from apps.nem.namespace import * from apps.nem.namespace.serialize import * - from trezor.messages import NEMSignTx - from trezor.messages import NEMAggregateModification - from trezor.messages import NEMProvisionNamespace - from trezor.messages import NEMCosignatoryModification - + from trezor.messages import NEMSignTx, NEMAggregateModification, NEMProvisionNamespace, NEMCosignatoryModification, NEMTransactionCommon @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMultisig(unittest.TestCase): diff --git a/core/tests/test_apps.nem.namespace.py b/core/tests/test_apps.nem.namespace.py index 0cd9ddf1bc..bcfa72c5be 100644 --- a/core/tests/test_apps.nem.namespace.py +++ b/core/tests/test_apps.nem.namespace.py @@ -6,7 +6,7 @@ if not utils.BITCOIN_ONLY: from apps.nem.helpers import * from apps.nem.namespace import * from apps.nem.namespace.serialize import * - from trezor.messages import NEMProvisionNamespace + from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon from trezor.messages import NEMSignTx diff --git a/core/tests/test_apps.ripple.serializer.py b/core/tests/test_apps.ripple.serializer.py index 2a8272c567..30899d019b 100644 --- a/core/tests/test_apps.ripple.serializer.py +++ b/core/tests/test_apps.ripple.serializer.py @@ -3,24 +3,12 @@ from common import * if not utils.BITCOIN_ONLY: from trezor.messages import RipplePayment from trezor.messages import RippleSignTx - from apps.ripple.serialize import serialize, serialize_amount - from apps.ripple.sign_tx import get_network_prefix + from apps.ripple.serialize import serialize + from apps.ripple import helpers @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestRippleSerializer(unittest.TestCase): - def test_amount(self): - # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L2494 - self.assertEqual(serialize_amount(0), unhexlify("4000000000000000")) - self.assertEqual(serialize_amount(1), unhexlify("4000000000000001")) - self.assertEqual(serialize_amount(93493429243), unhexlify("40000015c4a483fb")) - with self.assertRaises(ValueError): - serialize_amount(1000000000000000000) # too large - with self.assertRaises(ValueError): - serialize_amount(-1) # negative not supported - with self.assertRaises(Exception): - serialize_amount(1.1) # float numbers not supported - def test_transactions(self): # from https://github.com/miracle2k/ripple-python source_address = "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi" @@ -146,7 +134,8 @@ class TestRippleSerializer(unittest.TestCase): "ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a" ), ) - tx = get_network_prefix() + tx + network_prefix = helpers.HASH_TX_SIGN.to_bytes(4, "big") + tx = network_prefix + tx self.assertEqual(tx[0:4], unhexlify("53545800")) # signing prefix self.assertEqual(tx[4:7], unhexlify("120000")) # transaction type