refactor(core): fix imports and use new protobuf API in apps

pull/1557/head
Jan Pochyla 3 years ago committed by matejcik
parent 72557614c4
commit a8623c4b59

@ -1,23 +1,25 @@
import storage.cache
import storage.device
from trezor import config, utils, wire, workflow
from trezor.messages import MessageType
from trezor.messages.Success import Success
from trezor.enums import MessageType
from trezor.messages import Success
from . import workflow_handlers
if False:
import protobuf
from trezor import protobuf
from typing import NoReturn
from trezor.messages.Features import Features
from trezor.messages.Initialize import Initialize
from trezor.messages.EndSession import EndSession
from trezor.messages.GetFeatures import GetFeatures
from trezor.messages.Cancel import Cancel
from trezor.messages.LockDevice import LockDevice
from trezor.messages.Ping import Ping
from trezor.messages.DoPreauthorized import DoPreauthorized
from trezor.messages.CancelAuthorization import CancelAuthorization
from trezor.messages import (
Features,
Initialize,
EndSession,
GetFeatures,
Cancel,
LockDevice,
Ping,
DoPreauthorized,
CancelAuthorization,
)
def get_features() -> Features:
@ -25,8 +27,8 @@ def get_features() -> Features:
import storage.sd_salt
from trezor import sdcard
from trezor.messages import Capability
from trezor.messages.Features import Features
from trezor.enums import Capability
from trezor.messages import Features
from apps.common import mnemonic, safety_checks
@ -125,16 +127,16 @@ async def handle_EndSession(ctx: wire.Context, msg: EndSession) -> Success:
async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
if msg.button_protection:
from trezor.ui.layouts import confirm_action
from trezor.messages.ButtonRequestType import ProtectCall
from trezor.enums import ButtonRequestType as B
await confirm_action(ctx, "ping", "Confirm", "ping", br_code=ProtectCall)
await confirm_action(ctx, "ping", "Confirm", "ping", br_code=B.ProtectCall)
return Success(message=msg.message)
async def handle_DoPreauthorized(
ctx: wire.Context, msg: DoPreauthorized
) -> protobuf.MessageType:
from trezor.messages.PreauthorizedRequest import PreauthorizedRequest
from trezor.messages import PreauthorizedRequest
from apps.common import authorization
if not authorization.is_set():

@ -1,5 +1,4 @@
from trezor.messages.BinanceAddress import BinanceAddress
from trezor.messages.BinanceGetAddress import BinanceGetAddress
from trezor.messages import BinanceAddress, BinanceGetAddress
from trezor.ui.layouts import show_address
from apps.common import paths

@ -1,7 +1,6 @@
from ubinascii import hexlify
from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey
from trezor.messages.BinancePublicKey import BinancePublicKey
from trezor.messages import BinanceGetPublicKey, BinancePublicKey
from trezor.ui.layouts import show_pubkey
from apps.common import paths

@ -2,11 +2,13 @@ from micropython import const
from trezor.crypto import bech32
from trezor.crypto.scripts import sha256_ripemd160_digest
from trezor.messages.BinanceCancelMsg import BinanceCancelMsg
from trezor.messages.BinanceInputOutput import BinanceInputOutput
from trezor.messages.BinanceOrderMsg import BinanceOrderMsg
from trezor.messages.BinanceSignTx import BinanceSignTx
from trezor.messages.BinanceTransferMsg import BinanceTransferMsg
from trezor.messages import (
BinanceCancelMsg,
BinanceInputOutput,
BinanceOrderMsg,
BinanceSignTx,
BinanceTransferMsg,
)
ENVELOPE_BLUEPRINT = '{{"account_number":"{account_number}","chain_id":"{chain_id}","data":null,"memo":"{memo}","msgs":[{msgs}],"sequence":"{sequence}","source":"{source}"}}'
MSG_TRANSFER_BLUEPRINT = '{{"inputs":[{inputs}],"outputs":[{outputs}]}}'
@ -20,11 +22,11 @@ DECIMALS = const(8)
def produce_json_for_signing(envelope: BinanceSignTx, msg) -> str:
if isinstance(msg, BinanceTransferMsg):
if BinanceTransferMsg.is_type_of(msg):
json_msg = produce_transfer_json(msg)
elif isinstance(msg, BinanceOrderMsg):
elif BinanceOrderMsg.is_type_of(msg):
json_msg = produce_neworder_json(msg)
elif isinstance(msg, BinanceCancelMsg):
elif BinanceCancelMsg.is_type_of(msg):
json_msg = produce_cancel_json(msg)
else:
raise ValueError("input message unrecognized, is of type " + type(msg).__name__)

@ -1,11 +1,10 @@
from trezor import ui
from trezor.enums import BinanceOrderSide, ButtonRequestType
from trezor.messages import (
BinanceCancelMsg,
BinanceInputOutput,
BinanceOrderMsg,
BinanceOrderSide,
BinanceTransferMsg,
ButtonRequestType,
)
from trezor.strings import format_amount
from trezor.ui.components.tt.scroll import Paginated

@ -1,12 +1,14 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha256
from trezor.messages import MessageType
from trezor.messages.BinanceCancelMsg import BinanceCancelMsg
from trezor.messages.BinanceOrderMsg import BinanceOrderMsg
from trezor.messages.BinanceSignedTx import BinanceSignedTx
from trezor.messages.BinanceTransferMsg import BinanceTransferMsg
from trezor.messages.BinanceTxRequest import BinanceTxRequest
from trezor.enums import MessageType
from trezor.messages import (
BinanceCancelMsg,
BinanceOrderMsg,
BinanceSignedTx,
BinanceTransferMsg,
BinanceTxRequest,
)
from apps.common import paths
from apps.common.keychain import Keychain, auto_keychain
@ -37,11 +39,11 @@ async def sign_tx(ctx, envelope, keychain: Keychain):
msg_json = helpers.produce_json_for_signing(envelope, msg)
if isinstance(msg, BinanceTransferMsg):
if BinanceTransferMsg.is_type_of(msg):
await layout.require_confirm_transfer(ctx, msg)
elif isinstance(msg, BinanceOrderMsg):
elif BinanceOrderMsg.is_type_of(msg):
await layout.require_confirm_order(ctx, msg)
elif isinstance(msg, BinanceCancelMsg):
elif BinanceCancelMsg.is_type_of(msg):
await layout.require_confirm_cancel(ctx, msg)
else:
raise ValueError("input message unrecognized, is of type " + type(msg).__name__)

@ -1,8 +1,8 @@
from trezor import wire
from trezor.crypto import base58, cashaddr
from trezor.crypto.hashlib import sha256
from trezor.messages import InputScriptType
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.enums import InputScriptType
from trezor.messages import MultisigRedeemScriptType
from apps.common import address_type
from apps.common.coininfo import CoinInfo
@ -13,11 +13,10 @@ from .scripts import output_script_multisig, output_script_native_p2wpkh_or_p2ws
if False:
from trezor.crypto import bip32
from trezor.messages.TxInputType import EnumTypeInputScriptType
def get_address(
script_type: EnumTypeInputScriptType,
script_type: InputScriptType,
coin: CoinInfo,
node: bip32.HDNode,
multisig: MultisigRedeemScriptType | None = None,

@ -1,17 +1,19 @@
from micropython import const
from trezor import wire
from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin
from trezor.messages import AuthorizeCoinJoin
from apps.common import authorization
from .common import BIP32_WALLET_DEPTH
if False:
import protobuf
from trezor.messages.GetOwnershipProof import GetOwnershipProof
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages import (
GetOwnershipProof,
SignTx,
TxInput,
)
from trezor.protobuf import MessageType
from apps.common.coininfo import CoinInfo
@ -52,8 +54,8 @@ class CoinJoinAuthorization:
return True
def from_cached_message(auth_msg: protobuf.MessageType) -> CoinJoinAuthorization:
if not isinstance(auth_msg, AuthorizeCoinJoin):
def from_cached_message(auth_msg: MessageType) -> CoinJoinAuthorization:
if not AuthorizeCoinJoin.is_type_of(auth_msg):
raise wire.ProcessError("Appropriate params was not found")
return CoinJoinAuthorization(auth_msg)

@ -1,8 +1,7 @@
from micropython import const
from trezor import ui, wire
from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin
from trezor.messages.Success import Success
from trezor import ui
from trezor.messages import AuthorizeCoinJoin, Success
from trezor.strings import format_amount
from trezor.ui.layouts import confirm_action, confirm_coinjoin
@ -15,6 +14,7 @@ from .keychain import validate_path_against_script_type, with_keychain
from .sign_tx.layout import format_coin_amount
if False:
from trezor import wire
from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain

@ -3,13 +3,12 @@ from micropython import const
from trezor import wire
from trezor.crypto import bech32, bip32, der
from trezor.crypto.curve import secp256k1
from trezor.messages import InputScriptType, OutputScriptType
from trezor.enums import InputScriptType, OutputScriptType
from trezor.utils import ensure
if False:
from apps.common.coininfo import CoinInfo
from trezor.messages.TxInput import EnumTypeInputScriptType, TxInput
from trezor.messages.TxOutput import EnumTypeOutputScriptType
from trezor.messages import TxInput
BITCOIN_NAMES = ("Bitcoin", "Regtest", "Testnet")
@ -34,9 +33,7 @@ MULTISIG_OUTPUT_SCRIPT_TYPES = (
OutputScriptType.PAYTOWITNESS,
)
CHANGE_OUTPUT_TO_INPUT_SCRIPT_TYPES: dict[
EnumTypeOutputScriptType, EnumTypeInputScriptType
] = {
CHANGE_OUTPUT_TO_INPUT_SCRIPT_TYPES: dict[OutputScriptType, InputScriptType] = {
OutputScriptType.PAYTOADDRESS: InputScriptType.SPENDADDRESS,
OutputScriptType.PAYTOMULTISIG: InputScriptType.SPENDMULTISIG,
OutputScriptType.PAYTOP2SHWITNESS: InputScriptType.SPENDP2SHWITNESS,

@ -1,6 +1,6 @@
from trezor.crypto import bip32
from trezor.messages import InputScriptType
from trezor.messages.Address import Address
from trezor.enums import InputScriptType
from trezor.messages import Address
from trezor.ui.layouts import show_address
from apps.common.layout import address_n_to_str
@ -11,8 +11,8 @@ from .keychain import validate_path_against_script_type, with_keychain
from .multisig import multisig_pubkey_index
if False:
from trezor.messages.GetAddress import GetAddress
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages import GetAddress
from trezor.messages import HDNodeType
from trezor import wire
from apps.common.keychain import Keychain
from apps.common.coininfo import CoinInfo

@ -1,6 +1,5 @@
from trezor import wire
from trezor.messages.GetOwnershipId import GetOwnershipId
from trezor.messages.OwnershipId import OwnershipId
from trezor.messages import GetOwnershipId, OwnershipId
from apps.common.paths import validate_path

@ -1,8 +1,7 @@
from ubinascii import hexlify
from trezor import ui, wire
from trezor.messages.GetOwnershipProof import GetOwnershipProof
from trezor.messages.OwnershipProof import OwnershipProof
from trezor.messages import GetOwnershipProof, OwnershipProof
from trezor.ui.layouts import confirm_action, confirm_hex
from apps.common.paths import validate_path

@ -1,13 +1,12 @@
from trezor import wire
from trezor.messages import InputScriptType
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages.PublicKey import PublicKey
from trezor.enums import InputScriptType
from trezor.messages import HDNodeType, PublicKey
from apps.common import coininfo, paths
from apps.common.keychain import get_keychain
if False:
from trezor.messages.GetPublicKey import GetPublicKey
from trezor.messages import GetPublicKey
async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:

@ -1,7 +1,7 @@
import gc
from trezor import wire
from trezor.messages import InputScriptType as I
from trezor.enums import InputScriptType
from apps.common import coininfo
from apps.common.keychain import get_keychain
@ -14,9 +14,7 @@ if False:
from typing import Awaitable, Callable, Iterable, TypeVar
from typing_extensions import Protocol
from protobuf import MessageType
from trezor.messages.TxInputType import EnumTypeInputScriptType
from trezor.protobuf import MessageType
from apps.common.keychain import Keychain, MsgOut, Handler
from apps.common.paths import Bip32Path
@ -27,7 +25,7 @@ if False:
class MsgWithAddressScriptType(Protocol):
# XXX should be Bip32Path but that fails
address_n: list[int] = ...
script_type: EnumTypeInputScriptType = ...
script_type: InputScriptType = ...
MsgIn = TypeVar("MsgIn", bound=MsgWithCoinName)
HandlerWithCoinInfo = Callable[..., Awaitable[MsgOut]]
@ -68,7 +66,7 @@ def validate_path_against_script_type(
coin: coininfo.CoinInfo,
msg: MsgWithAddressScriptType | None = None,
address_n: Bip32Path | None = None,
script_type: EnumTypeInputScriptType | None = None,
script_type: InputScriptType | None = None,
multisig: bool = False,
) -> bool:
patterns = []
@ -76,19 +74,22 @@ def validate_path_against_script_type(
if msg is not None:
assert address_n is None and script_type is None
address_n = msg.address_n
script_type = msg.script_type or I.SPENDADDRESS
script_type = msg.script_type or InputScriptType.SPENDADDRESS
multisig = bool(getattr(msg, "multisig", False))
else:
assert address_n is not None and script_type is not None
if script_type == I.SPENDADDRESS and not multisig:
if script_type == InputScriptType.SPENDADDRESS and not multisig:
patterns.append(PATTERN_BIP44)
if coin.coin_name in BITCOIN_NAMES:
patterns.append(PATTERN_GREENADDRESS_A)
patterns.append(PATTERN_GREENADDRESS_B)
elif script_type in (I.SPENDADDRESS, I.SPENDMULTISIG) and multisig:
elif (
script_type in (InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG)
and multisig
):
patterns.append(PATTERN_BIP45)
patterns.append(PATTERN_PURPOSE48_RAW)
if coin.coin_name in BITCOIN_NAMES:
@ -98,7 +99,7 @@ def validate_path_against_script_type(
patterns.append(PATTERN_UNCHAINED_UNHARDENED)
patterns.append(PATTERN_UNCHAINED_DEPRECATED)
elif coin.segwit and script_type == I.SPENDP2SHWITNESS:
elif coin.segwit and script_type == InputScriptType.SPENDP2SHWITNESS:
patterns.append(PATTERN_BIP49)
if multisig:
patterns.append(PATTERN_PURPOSE48_P2SHSEGWIT)
@ -107,7 +108,7 @@ def validate_path_against_script_type(
patterns.append(PATTERN_GREENADDRESS_B)
patterns.append(PATTERN_CASA)
elif coin.segwit and script_type == I.SPENDWITNESS:
elif coin.segwit and script_type == InputScriptType.SPENDWITNESS:
patterns.append(PATTERN_BIP84)
if multisig:
patterns.append(PATTERN_PURPOSE48_SEGWIT)

@ -1,8 +1,7 @@
from trezor import wire
from trezor.crypto import bip32
from trezor.crypto.hashlib import sha256
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.messages import HDNodeType, MultisigRedeemScriptType
from trezor.utils import HashWriter
from apps.common import paths

@ -10,8 +10,8 @@ from .scripts import read_bip322_signature_proof, write_bip322_signature_proof
from .verification import SignatureVerifier
if False:
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.messages.TxInputType import EnumTypeInputScriptType
from trezor.enums import InputScriptType
from trezor.messages import MultisigRedeemScriptType
from apps.common.coininfo import CoinInfo
# This module implements the SLIP-0019 proof of ownership format, see
@ -26,7 +26,7 @@ _OWNERSHIP_ID_KEY_PATH = [b"SLIP-0019", b"Ownership identification key"]
def generate_proof(
node: bip32.HDNode,
script_type: EnumTypeInputScriptType,
script_type: InputScriptType,
multisig: MultisigRedeemScriptType | None,
coin: CoinInfo,
user_confirmed: bool,

@ -1,7 +1,7 @@
from trezor import utils, wire
from trezor.crypto import base58, cashaddr
from trezor.crypto.hashlib import sha256
from trezor.messages import InputScriptType
from trezor.enums import InputScriptType
from apps.common import address_type
from apps.common.readers import read_bitcoin_varint
@ -22,9 +22,7 @@ from .writers import (
)
if False:
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.messages.TxInput import TxInput
from trezor.messages.TxInput import EnumTypeInputScriptType
from trezor.messages import MultisigRedeemScriptType, TxInput
from apps.common.coininfo import CoinInfo
@ -32,7 +30,7 @@ if False:
def input_derive_script(
script_type: EnumTypeInputScriptType,
script_type: InputScriptType,
multisig: MultisigRedeemScriptType | None,
coin: CoinInfo,
hash_type: int,
@ -521,7 +519,7 @@ def output_script_paytoopreturn(data: bytes) -> bytearray:
def write_bip322_signature_proof(
w: Writer,
script_type: EnumTypeInputScriptType,
script_type: InputScriptType,
multisig: MultisigRedeemScriptType | None,
coin: CoinInfo,
public_key: bytes,

@ -1,7 +1,7 @@
from trezor import utils, wire
from trezor.crypto import base58
from trezor.crypto.base58 import blake256d_32
from trezor.messages import InputScriptType
from trezor.enums import InputScriptType
from apps.common.writers import write_bytes_fixed, write_uint64_le
@ -15,14 +15,13 @@ from .scripts import ( # noqa: F401
from .writers import write_op_push
if False:
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.messages.TxInput import EnumTypeInputScriptType
from trezor.messages import MultisigRedeemScriptType
from apps.common.coininfo import CoinInfo
def input_derive_script(
script_type: EnumTypeInputScriptType,
script_type: InputScriptType,
multisig: MultisigRedeemScriptType | None,
coin: CoinInfo,
hash_type: int,

@ -1,7 +1,7 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.messages.InputScriptType import SPENDADDRESS, SPENDP2SHWITNESS, SPENDWITNESS
from trezor.messages.MessageSignature import MessageSignature
from trezor.enums import InputScriptType
from trezor.messages import MessageSignature
from trezor.ui.layouts import confirm_signverify
from apps.common.paths import validate_path
@ -11,7 +11,7 @@ from .addresses import get_address
from .keychain import with_keychain
if False:
from trezor.messages.SignMessage import SignMessage
from trezor.messages import SignMessage
from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain
@ -23,7 +23,7 @@ async def sign_message(
) -> MessageSignature:
message = msg.message
address_n = msg.address_n
script_type = msg.script_type or 0
script_type = msg.script_type or InputScriptType.SPENDADDRESS
await validate_path(ctx, keychain, address_n)
await confirm_signverify(ctx, coin.coin_shortcut, decode_message(message))
@ -35,11 +35,11 @@ async def sign_message(
digest = message_digest(coin, message)
signature = secp256k1.sign(seckey, digest)
if script_type == SPENDADDRESS:
if script_type == InputScriptType.SPENDADDRESS:
pass
elif script_type == SPENDP2SHWITNESS:
elif script_type == InputScriptType.SPENDP2SHWITNESS:
signature = bytes([signature[0] + 4]) + signature[1:]
elif script_type == SPENDWITNESS:
elif script_type == InputScriptType.SPENDWITNESS:
signature = bytes([signature[0] + 8]) + signature[1:]
else:
raise wire.ProcessError("Unsupported script type")

@ -1,15 +1,6 @@
import gc
from trezor import utils, wire
from trezor.messages.RequestType import TXFINISHED
from trezor.messages.SignTx import SignTx
from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckPrevExtraData import TxAckPrevExtraData
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxRequest import TxRequest
from trezor.enums import RequestType
from trezor.messages import TxRequest
from ..common import BITCOIN_NAMES
from ..keychain import with_keychain
@ -21,7 +12,15 @@ if not utils.BITCOIN_ONLY:
if False:
from typing import Protocol, Union
from protobuf import FieldCache
from trezor.messages import (
SignTx,
TxAckInput,
TxAckOutput,
TxAckPrevMeta,
TxAckPrevInput,
TxAckPrevOutput,
TxAckPrevExtraData,
)
from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain
@ -76,26 +75,14 @@ async def sign_tx(
signer = signer_class(msg, keychain, coin, approver).signer()
res: TxAckType | bool | None = None
gc.collect()
field_cache: FieldCache = {}
TxRequest.cache_subordinate_types(field_cache)
SignTx.cache_subordinate_types(field_cache)
TxAckInput.cache_subordinate_types(field_cache)
TxAckOutput.cache_subordinate_types(field_cache)
TxAckPrevExtraData.cache_subordinate_types(field_cache)
TxAckPrevInput.cache_subordinate_types(field_cache)
TxAckPrevMeta.cache_subordinate_types(field_cache)
TxAckPrevOutput.cache_subordinate_types(field_cache)
while True:
req = signer.send(res)
if isinstance(req, tuple):
request_class, req = req
assert isinstance(req, TxRequest)
if req.request_type == TXFINISHED:
assert TxRequest.is_type_of(req)
if req.request_type == RequestType.TXFINISHED:
return req
res = await ctx.call(req, request_class, field_cache)
res = await ctx.call(req, request_class)
elif isinstance(req, helpers.UiConfirm):
res = await req.confirm_dialog(ctx)
progress.report_init()

@ -1,7 +1,7 @@
from micropython import const
from trezor import wire
from trezor.messages import OutputScriptType
from trezor.enums import OutputScriptType
from apps.common import safety_checks
@ -11,9 +11,9 @@ from . import helpers, tx_weight
from .tx_info import OriginalTxInfo, TxInfo
if False:
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages import SignTx
from trezor.messages import TxInput
from trezor.messages import TxOutput
from apps.common.coininfo import CoinInfo

@ -2,10 +2,8 @@ from micropython import const
from trezor import wire
from trezor.crypto.hashlib import sha256
from trezor.messages import InputScriptType, OutputScriptType
from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
from trezor.enums import InputScriptType, OutputScriptType
from trezor.messages import TxRequest, TxRequestDetailsType, TxRequestSerializedType
from trezor.utils import HashWriter, empty_bytearray, ensure
from apps.common.writers import write_bitcoin_varint
@ -21,12 +19,14 @@ from .tx_info import OriginalTxInfo, TxInfo
if False:
from trezor.crypto import bip32
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages.PrevTx import PrevTx
from trezor.messages.PrevInput import PrevInput
from trezor.messages.PrevOutput import PrevOutput
from trezor.messages import (
PrevInput,
PrevOutput,
PrevTx,
SignTx,
TxInput,
TxOutput,
)
from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain

@ -1,9 +1,7 @@
from micropython import const
from trezor import wire
from trezor.messages.PrevTx import PrevTx
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages import PrevTx, SignTx, TxInput
from apps.common.writers import write_bitcoin_varint

@ -2,8 +2,8 @@ from micropython import const
from trezor import wire
from trezor.crypto.hashlib import blake256
from trezor.messages import DecredStakingSpendType, InputScriptType
from trezor.messages.PrevOutput import PrevOutput
from trezor.enums import DecredStakingSpendType, InputScriptType
from trezor.messages import PrevOutput
from trezor.utils import HashWriter, ensure
from apps.common.writers import write_bitcoin_varint
@ -24,11 +24,13 @@ OUTPUT_SCRIPT_NULL_SSTXCHANGE = (
)
if False:
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages.PrevTx import PrevTx
from trezor.messages.PrevInput import PrevInput
from trezor.messages import (
SignTx,
TxInput,
TxOutput,
PrevTx,
PrevInput,
)
from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain
@ -226,7 +228,7 @@ class Decred(Bitcoin):
script_pubkey: bytes,
) -> None:
writers.write_uint64(w, txo.amount)
if isinstance(txo, PrevOutput):
if PrevOutput.is_type_of(txo):
if txo.decred_script_version is None:
raise wire.DataError("Script version must be provided")
writers.write_uint16(w, txo.decred_script_version)

@ -1,8 +1,5 @@
from trezor.crypto.hashlib import sha256
from trezor.messages.PrevTx import PrevTx
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
from trezor.utils import HashWriter
from apps.common import coininfo

@ -1,27 +1,20 @@
from trezor import utils, wire
from trezor.messages import InputScriptType, OutputScriptType
from trezor.messages.PrevInput import PrevInput
from trezor.messages.PrevOutput import PrevOutput
from trezor.messages.PrevTx import PrevTx
from trezor.messages.RequestType import (
TXEXTRADATA,
TXFINISHED,
TXINPUT,
TXMETA,
TXORIGINPUT,
TXORIGOUTPUT,
TXOUTPUT,
from trezor.enums import InputScriptType, OutputScriptType, RequestType
from trezor.messages import (
PrevInput,
PrevOutput,
PrevTx,
SignTx,
TxAckInput,
TxAckOutput,
TxAckPrevExtraData,
TxAckPrevInput,
TxAckPrevMeta,
TxAckPrevOutput,
TxInput,
TxOutput,
TxRequest,
)
from trezor.messages.SignTx import SignTx
from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckPrevExtraData import TxAckPrevExtraData
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages.TxRequest import TxRequest
from apps.common import paths
from apps.common.coininfo import CoinInfo
@ -32,7 +25,7 @@ from . import layout
if False:
from typing import Any, Awaitable
from trezor.messages.SignTx import EnumTypeAmountUnit
from trezor.enums import AmountUnit
# Machine instructions
@ -45,9 +38,7 @@ class UiConfirm:
class UiConfirmOutput(UiConfirm):
def __init__(
self, output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
):
def __init__(self, output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit):
self.output = output
self.coin = coin
self.amount_unit = amount_unit
@ -59,9 +50,7 @@ class UiConfirmOutput(UiConfirm):
class UiConfirmDecredSSTXSubmission(UiConfirm):
def __init__(
self, output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
):
def __init__(self, output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit):
self.output = output
self.coin = coin
self.amount_unit = amount_unit
@ -91,7 +80,7 @@ class UiConfirmModifyOutput(UiConfirm):
txo: TxOutput,
orig_txo: TxOutput,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
):
self.txo = txo
self.orig_txo = orig_txo
@ -112,7 +101,7 @@ class UiConfirmModifyFee(UiConfirm):
user_fee_change: int,
total_fee_new: int,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
):
self.user_fee_change = user_fee_change
self.total_fee_new = total_fee_new
@ -129,7 +118,7 @@ class UiConfirmModifyFee(UiConfirm):
class UiConfirmTotal(UiConfirm):
def __init__(
self, spending: int, fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
self, spending: int, fee: int, coin: CoinInfo, amount_unit: AmountUnit
):
self.spending = spending
self.fee = fee
@ -146,7 +135,7 @@ class UiConfirmTotal(UiConfirm):
class UiConfirmJointTotal(UiConfirm):
def __init__(
self, spending: int, total: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
self, spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit
):
self.spending = spending
self.total = total
@ -162,7 +151,7 @@ class UiConfirmJointTotal(UiConfirm):
class UiConfirmFeeOverThreshold(UiConfirm):
def __init__(self, fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit):
def __init__(self, fee: int, coin: CoinInfo, amount_unit: AmountUnit):
self.fee = fee
self.coin = coin
self.amount_unit = amount_unit
@ -208,11 +197,11 @@ class UiConfirmNonDefaultLocktime(UiConfirm):
__eq__ = utils.obj_eq
def confirm_output(output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[None]: # type: ignore
def confirm_output(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore
return (yield UiConfirmOutput(output, coin, amount_unit))
def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[None]: # type: ignore
def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore
return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit))
@ -220,23 +209,23 @@ def confirm_replacement(description: str, txid: bytes) -> Awaitable[Any]: # typ
return (yield UiConfirmReplacement(description, txid))
def confirm_modify_output(txo: TxOutput, orig_txo: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[Any]: # type: ignore
def confirm_modify_output(txo: TxOutput, orig_txo: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore
return (yield UiConfirmModifyOutput(txo, orig_txo, coin, amount_unit))
def confirm_modify_fee(user_fee_change: int, total_fee_new: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[Any]: # type: ignore
def confirm_modify_fee(user_fee_change: int, total_fee_new: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore
return (yield UiConfirmModifyFee(user_fee_change, total_fee_new, coin, amount_unit))
def confirm_total(spending: int, fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[None]: # type: ignore
def confirm_total(spending: int, fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore
return (yield UiConfirmTotal(spending, fee, coin, amount_unit))
def confirm_joint_total(spending: int, total: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[Any]: # type: ignore
def confirm_joint_total(spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore
return (yield UiConfirmJointTotal(spending, total, coin, amount_unit))
def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit) -> Awaitable[Any]: # type: ignore
def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore
return (yield UiConfirmFeeOverThreshold(fee, coin, amount_unit))
@ -254,7 +243,7 @@ def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> Awa
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevTx]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXMETA
tx_req.request_type = RequestType.TXMETA
tx_req.details.tx_hash = tx_hash
ack = yield TxAckPrevMeta, tx_req
_clear_tx_request(tx_req)
@ -265,7 +254,7 @@ def request_tx_extra_data( # type: ignore
tx_req: TxRequest, offset: int, size: int, tx_hash: bytes | None = None
) -> Awaitable[bytearray]:
assert tx_req.details is not None
tx_req.request_type = TXEXTRADATA
tx_req.request_type = RequestType.TXEXTRADATA
tx_req.details.extra_data_offset = offset
tx_req.details.extra_data_len = size
tx_req.details.tx_hash = tx_hash
@ -277,10 +266,10 @@ def request_tx_extra_data( # type: ignore
def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxInput]: # type: ignore
assert tx_req.details is not None
if tx_hash:
tx_req.request_type = TXORIGINPUT
tx_req.request_type = RequestType.TXORIGINPUT
tx_req.details.tx_hash = tx_hash
else:
tx_req.request_type = TXINPUT
tx_req.request_type = RequestType.TXINPUT
tx_req.details.request_index = i
ack = yield TxAckInput, tx_req
_clear_tx_request(tx_req)
@ -289,7 +278,7 @@ def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes |
def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevInput]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXINPUT
tx_req.request_type = RequestType.TXINPUT
tx_req.details.request_index = i
tx_req.details.tx_hash = tx_hash
ack = yield TxAckPrevInput, tx_req
@ -300,10 +289,10 @@ def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: by
def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxOutput]: # type: ignore
assert tx_req.details is not None
if tx_hash:
tx_req.request_type = TXORIGOUTPUT
tx_req.request_type = RequestType.TXORIGOUTPUT
tx_req.details.tx_hash = tx_hash
else:
tx_req.request_type = TXOUTPUT
tx_req.request_type = RequestType.TXOUTPUT
tx_req.details.request_index = i
ack = yield TxAckOutput, tx_req
_clear_tx_request(tx_req)
@ -312,7 +301,7 @@ def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes
def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevOutput]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXOUTPUT
tx_req.request_type = RequestType.TXOUTPUT
tx_req.details.request_index = i
tx_req.details.tx_hash = tx_hash
ack = yield TxAckPrevOutput, tx_req
@ -322,7 +311,7 @@ def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: b
def request_tx_finish(tx_req: TxRequest) -> Awaitable[None]: # type: ignore
tx_req.request_type = TXFINISHED
tx_req.request_type = RequestType.TXFINISHED
yield None, tx_req
_clear_tx_request(tx_req)

@ -1,7 +1,7 @@
from micropython import const
from ubinascii import hexlify
from trezor.messages import AmountUnit, ButtonRequestType, OutputScriptType
from trezor.enums import AmountUnit, ButtonRequestType, OutputScriptType
from trezor.strings import format_amount
from trezor.ui import layouts
@ -10,8 +10,7 @@ from . import omni
if False:
from trezor import wire
from trezor.messages.SignTx import EnumTypeAmountUnit
from trezor.messages.TxOutput import TxOutput
from trezor.messages import TxOutput
from trezor.ui.layouts import LayoutType
from apps.common.coininfo import CoinInfo
@ -19,9 +18,7 @@ if False:
_LOCKTIME_TIMESTAMP_MIN_VALUE = const(500_000_000)
def format_coin_amount(
amount: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
) -> str:
def format_coin_amount(amount: int, coin: CoinInfo, amount_unit: AmountUnit) -> str:
decimals, shortcut = coin.decimals, coin.coin_shortcut
if amount_unit == AmountUnit.SATOSHI:
decimals = 0
@ -37,7 +34,7 @@ def format_coin_amount(
async def confirm_output(
ctx: wire.Context, output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
ctx: wire.Context, output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit
) -> None:
if output.script_type == OutputScriptType.PAYTOOPRETURN:
data = output.op_return_data
@ -71,7 +68,7 @@ async def confirm_output(
async def confirm_decred_sstx_submission(
ctx: wire.Context, output: TxOutput, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
ctx: wire.Context, output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit
) -> None:
assert output.address is not None
address_short = addresses.address_short(coin, output.address)
@ -94,7 +91,7 @@ async def confirm_modify_output(
txo: TxOutput,
orig_txo: TxOutput,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
) -> None:
assert txo.address is not None
address_short = addresses.address_short(coin, txo.address)
@ -113,7 +110,7 @@ async def confirm_modify_fee(
user_fee_change: int,
total_fee_new: int,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
) -> None:
await layouts.confirm_modify_fee(
ctx,
@ -128,7 +125,7 @@ async def confirm_joint_total(
spending: int,
total: int,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
) -> None:
await layouts.confirm_joint_total(
ctx,
@ -142,7 +139,7 @@ async def confirm_total(
spending: int,
fee: int,
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
amount_unit: AmountUnit,
) -> None:
await layouts.confirm_total(
ctx,
@ -152,7 +149,7 @@ async def confirm_total(
async def confirm_feeoverthreshold(
ctx: wire.Context, fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
ctx: wire.Context, fee: int, coin: CoinInfo, amount_unit: AmountUnit
) -> None:
fee_amount = format_coin_amount(fee, coin, amount_unit)
await layouts.confirm_metadata(

@ -7,8 +7,7 @@ from ..common import BIP32_WALLET_DEPTH
if False:
from typing import Any, Generic, TypeVar
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages import TxInput, TxOutput
T = TypeVar("T")
else:

@ -10,12 +10,14 @@ from .matchcheck import MultisigFingerprintChecker, WalletPathChecker
if False:
from typing import Protocol
from trezor.messages.SignTx import SignTx
from trezor.messages.PrevTx import PrevTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages.PrevInput import PrevInput
from trezor.messages.PrevOutput import PrevOutput
from trezor.messages import (
PrevInput,
PrevOutput,
PrevTx,
SignTx,
TxInput,
TxOutput,
)
from .hash143 import Hash143
from apps.common.coininfo import CoinInfo

@ -7,10 +7,10 @@
from micropython import const
from trezor.messages import InputScriptType
from trezor.enums import InputScriptType
if False:
from trezor.messages.TxInput import TxInput
from trezor.messages import TxInput
# transaction header size: 4 byte version
_TXSIZE_HEADER = const(4)

@ -3,11 +3,8 @@ from micropython import const
from trezor import wire
from trezor.crypto.hashlib import blake2b
from trezor.messages import InputScriptType
from trezor.messages.PrevTx import PrevTx
from trezor.messages.SignTx import SignTx
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.enums import InputScriptType
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
from trezor.utils import HashWriter, ensure
from apps.common.coininfo import CoinInfo

@ -1,7 +1,7 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.messages.InputScriptType import SPENDADDRESS, SPENDP2SHWITNESS, SPENDWITNESS
from trezor.messages.Success import Success
from trezor.enums import InputScriptType
from trezor.messages import Success
from trezor.ui.layouts import confirm_signverify
from apps.common import coins
@ -16,8 +16,7 @@ from .addresses import (
)
if False:
from trezor.messages.VerifyMessage import VerifyMessage
from trezor.messages.TxInputType import EnumTypeInputScriptType
from trezor.messages import VerifyMessage
async def verify_message(ctx: wire.Context, msg: VerifyMessage) -> Success:
@ -32,14 +31,14 @@ async def verify_message(ctx: wire.Context, msg: VerifyMessage) -> Success:
recid = signature[0]
if recid >= 27 and recid <= 34:
# p2pkh
script_type: EnumTypeInputScriptType = SPENDADDRESS
script_type = InputScriptType.SPENDADDRESS
elif recid >= 35 and recid <= 38:
# segwit-in-p2sh
script_type = SPENDP2SHWITNESS
script_type = InputScriptType.SPENDP2SHWITNESS
signature = bytes([signature[0] - 4]) + signature[1:]
elif recid >= 39 and recid <= 42:
# native segwit
script_type = SPENDWITNESS
script_type = InputScriptType.SPENDWITNESS
signature = bytes([signature[0] - 8]) + signature[1:]
else:
raise wire.ProcessError("Invalid signature")
@ -49,13 +48,13 @@ async def verify_message(ctx: wire.Context, msg: VerifyMessage) -> Success:
if not pubkey:
raise wire.ProcessError("Invalid signature")
if script_type == SPENDADDRESS:
if script_type == InputScriptType.SPENDADDRESS:
addr = address_pkh(pubkey, coin)
if coin.cashaddr_prefix is not None:
addr = address_to_cashaddr(addr, coin)
elif script_type == SPENDP2SHWITNESS:
elif script_type == InputScriptType.SPENDP2SHWITNESS:
addr = address_p2wpkh_in_p2sh(pubkey, coin)
elif script_type == SPENDWITNESS:
elif script_type == InputScriptType.SPENDWITNESS:
addr = address_p2wpkh(pubkey, coin)
else:
raise wire.ProcessError("Invalid signature")

@ -15,10 +15,12 @@ from apps.common.writers import ( # noqa: F401
)
if False:
from trezor.messages.TxInput import TxInput
from trezor.messages.TxOutput import TxOutput
from trezor.messages.PrevInput import PrevInput
from trezor.messages.PrevOutput import PrevOutput
from trezor.messages import (
PrevInput,
PrevOutput,
TxInput,
TxOutput,
)
from trezor.utils import HashWriter
from apps.common.writers import Writer

@ -1,6 +1,6 @@
from trezor import wire
from trezor.crypto import base58, hashlib
from trezor.messages import CardanoAddressType
from trezor.enums import CardanoAddressType
from .byron_address import derive_byron_address, validate_byron_address
from .helpers import INVALID_ADDRESS, NETWORK_MISMATCH, bech32, network_ids
@ -9,12 +9,9 @@ from .helpers.utils import derive_public_key, variable_length_encode
from .seed import is_byron_path, is_shelley_path
if False:
from trezor.messages.CardanoBlockchainPointerType import (
from trezor.messages import (
CardanoBlockchainPointerType,
)
from trezor.messages.CardanoAddressParametersType import (
CardanoAddressParametersType,
EnumTypeCardanoAddressType,
)
from . import seed
@ -86,7 +83,7 @@ def get_address_bytes_unsafe(address: str) -> bytes:
return address_bytes
def _get_address_type(address: bytes) -> EnumTypeCardanoAddressType:
def _get_address_type(address: bytes) -> CardanoAddressType:
return address[0] >> 4 # type: ignore
@ -106,7 +103,7 @@ def _validate_address_size(address_bytes: bytes) -> None:
def _validate_address_bech32_hrp(
address_str: str, address_type: EnumTypeCardanoAddressType, network_id: int
address_str: str, address_type: CardanoAddressType, network_id: int
) -> None:
valid_hrp = _get_bech32_hrp_for_address(address_type, network_id)
bech32_hrp = bech32.get_hrp(address_str)
@ -116,7 +113,7 @@ def _validate_address_bech32_hrp(
def _get_bech32_hrp_for_address(
address_type: EnumTypeCardanoAddressType, network_id: int
address_type: CardanoAddressType, network_id: int
) -> str:
if address_type == CardanoAddressType.BYRON:
# Byron address uses base58 encoding
@ -235,10 +232,8 @@ def _derive_shelley_address(
return address
def _create_address_header(
address_type: EnumTypeCardanoAddressType, network_id: int
) -> bytes:
header = address_type << 4 | network_id
def _create_address_header(address_type: CardanoAddressType, network_id: int) -> bytes:
header: int = address_type << 4 | network_id
return header.to_bytes(1, "little")

@ -1,6 +1,6 @@
from trezor.crypto import hashlib
from trezor.crypto.curve import ed25519
from trezor.messages import CardanoAddressType
from trezor.enums import CardanoAddressType
from apps.common import cbor
@ -15,10 +15,10 @@ if False:
from typing import Union
from trezor import wire
from trezor.messages.CardanoCatalystRegistrationParametersType import (
from trezor.messages import (
CardanoCatalystRegistrationParametersType,
CardanoTxAuxiliaryDataType,
)
from trezor.messages.CardanoTxAuxiliaryDataType import CardanoTxAuxiliaryDataType
CatalystRegistrationPayload = dict[int, Union[bytes, int]]
CatalystRegistrationSignature = dict[int, bytes]

@ -1,4 +1,4 @@
from trezor.messages import CardanoCertificateType, CardanoPoolRelayType
from trezor.enums import CardanoCertificateType, CardanoPoolRelayType
from apps.common import cbor
@ -11,13 +11,13 @@ from .helpers import INVALID_CERTIFICATE, LOVELACE_MAX_SUPPLY
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
if False:
from trezor.messages.CardanoTxCertificateType import CardanoTxCertificateType
from trezor.messages.CardanoPoolParametersType import CardanoPoolParametersType
from trezor.messages.CardanoPoolRelayParametersType import (
from trezor.messages import (
CardanoPoolMetadataType,
CardanoPoolOwnerType,
CardanoPoolParametersType,
CardanoPoolRelayParametersType,
CardanoTxCertificateType,
)
from trezor.messages.CardanoPoolOwnerType import CardanoPoolOwnerType
from trezor.messages.CardanoPoolMetadataType import CardanoPoolMetadataType
from apps.common.cbor import CborSequence

@ -1,5 +1,5 @@
from trezor import log, wire
from trezor.messages.CardanoAddress import CardanoAddress
from trezor.messages import CardanoAddress
from apps.common import paths
from apps.common.layout import address_n_to_str, show_qr
@ -17,10 +17,10 @@ from .layout import (
from .sign_tx import validate_network_info
if False:
from trezor.messages.CardanoAddressParametersType import (
from trezor.messages import (
CardanoAddressParametersType,
CardanoGetAddress,
)
from trezor.messages.CardanoGetAddress import CardanoGetAddress
@seed.with_keychain

@ -1,8 +1,7 @@
from ubinascii import hexlify
from trezor import log, wire
from trezor.messages.CardanoPublicKey import CardanoPublicKey
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages import CardanoPublicKey, HDNodeType
from trezor.ui.layouts import show_pubkey
from apps.common import paths
@ -12,7 +11,7 @@ from .helpers.paths import SCHEMA_PUBKEY
from .helpers.utils import derive_public_key
if False:
from trezor.messages.CardanoGetPublicKey import CardanoGetPublicKey
from trezor.messages import CardanoGetPublicKey
@seed.with_keychain

@ -1,13 +1,11 @@
from trezor.messages import CardanoAddressType
from trezor.enums import CardanoAddressType
from ..address import get_public_key_hash
from ..seed import is_shelley_path
from .utils import to_account_path
if False:
from trezor.messages.CardanoAddressParametersType import (
CardanoAddressParametersType,
)
from trezor.messages import CardanoAddressParametersType
from ..seed import Keychain

@ -2,11 +2,7 @@ import math
from ubinascii import hexlify
from trezor import ui
from trezor.messages import (
ButtonRequestType,
CardanoAddressType,
CardanoCertificateType,
)
from trezor.enums import ButtonRequestType, CardanoAddressType, CardanoCertificateType
from trezor.strings import format_amount
from trezor.ui.components.tt.button import ButtonDefault
from trezor.ui.components.tt.scroll import Paginated
@ -33,16 +29,15 @@ from .helpers.utils import (
if False:
from trezor import wire
from trezor.messages.CardanoBlockchainPointerType import (
from trezor.messages import (
CardanoBlockchainPointerType,
CardanoTxCertificateType,
CardanoTxWithdrawalType,
CardanoPoolParametersType,
CardanoPoolOwnerType,
CardanoPoolMetadataType,
CardanoAssetGroupType,
)
from trezor.messages.CardanoTxCertificateType import CardanoTxCertificateType
from trezor.messages.CardanoTxWithdrawalType import CardanoTxWithdrawalType
from trezor.messages.CardanoPoolParametersType import CardanoPoolParametersType
from trezor.messages.CardanoPoolOwnerType import CardanoPoolOwnerType
from trezor.messages.CardanoPoolMetadataType import CardanoPoolMetadataType
from trezor.messages.CardanoAssetGroupType import CardanoAssetGroupType
from trezor.messages.CardanoAddressParametersType import EnumTypeCardanoAddressType
ADDRESS_TYPE_NAMES = {
@ -137,7 +132,7 @@ async def show_warning_path(ctx: wire.Context, path: list[int], title: str) -> N
async def show_warning_tx_no_staking_info(
ctx: wire.Context, address_type: EnumTypeCardanoAddressType, amount: int
ctx: wire.Context, address_type: CardanoAddressType, amount: int
) -> None:
page1 = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
page1.normal("Change " + ADDRESS_TYPE_NAMES[address_type].lower())
@ -441,7 +436,7 @@ async def show_auxiliary_data_hash(
async def show_address(
ctx: wire.Context,
address: str,
address_type: EnumTypeCardanoAddressType,
address_type: CardanoAddressType,
path: list[int],
network: str | None = None,
) -> bool:

@ -1,11 +1,13 @@
from trezor import log, wire
from trezor.crypto import hashlib
from trezor.crypto.curve import ed25519
from trezor.messages import CardanoAddressType, CardanoCertificateType
from trezor.messages.CardanoAddressParametersType import CardanoAddressParametersType
from trezor.messages.CardanoSignedTx import CardanoSignedTx
from trezor.messages.CardanoSignedTxChunk import CardanoSignedTxChunk
from trezor.messages.CardanoSignedTxChunkAck import CardanoSignedTxChunkAck
from trezor.enums import CardanoAddressType, CardanoCertificateType
from trezor.messages import (
CardanoAddressParametersType,
CardanoSignedTx,
CardanoSignedTxChunk,
CardanoSignedTxChunkAck,
)
from apps.common import cbor, safety_checks
from apps.common.paths import validate_path
@ -72,12 +74,14 @@ from .seed import is_byron_path, is_shelley_path
if False:
from typing import Any, Optional, Union
from trezor.messages.CardanoSignTx import CardanoSignTx
from trezor.messages.CardanoTxCertificateType import CardanoTxCertificateType
from trezor.messages.CardanoTxInputType import CardanoTxInputType
from trezor.messages.CardanoTxOutputType import CardanoTxOutputType
from trezor.messages.CardanoTxWithdrawalType import CardanoTxWithdrawalType
from trezor.messages.CardanoAssetGroupType import CardanoAssetGroupType
from trezor.messages import (
CardanoAssetGroupType,
CardanoSignTx,
CardanoTxCertificateType,
CardanoTxInputType,
CardanoTxOutputType,
CardanoTxWithdrawalType,
)
from apps.common.cbor import CborSequence
from apps.common.paths import PathSchema

@ -1,19 +1,17 @@
from micropython import const
from trezor import workflow
from trezor.messages import ButtonRequestType
from trezor.messages.ButtonAck import ButtonAck
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.enums import ButtonRequestType
from trezor.messages import ButtonAck, ButtonRequest
if False:
from trezor import wire
from trezor.messages.ButtonRequest import EnumTypeButtonRequestType
HARDENED = const(0x8000_0000)
async def button_request(
ctx: wire.GenericContext, code: EnumTypeButtonRequestType = ButtonRequestType.Other
ctx: wire.GenericContext, code: ButtonRequestType = ButtonRequestType.Other
) -> None:
workflow.close_others()
await ctx.call(ButtonRequest(code=code), ButtonAck)

@ -1,4 +1,3 @@
import protobuf
import storage.cache
from trezor import protobuf
from trezor.enums import MessageType

@ -1,5 +1,5 @@
from trezor import wire
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.confirm import (
CONFIRMED,
INFO,
@ -19,13 +19,12 @@ if False:
from trezor import ui
from trezor.ui.components.tt.confirm import ButtonContent, ButtonStyleType
from trezor.ui.loader import LoaderStyleType
from trezor.messages.ButtonRequest import EnumTypeButtonRequestType
async def confirm(
ctx: wire.GenericContext,
content: ui.Component,
code: EnumTypeButtonRequestType = ButtonRequestType.Other,
code: ButtonRequestType = ButtonRequestType.Other,
confirm: ButtonContent | None = Confirm.DEFAULT_CONFIRM,
confirm_style: ButtonStyleType = Confirm.DEFAULT_CONFIRM_STYLE,
cancel: ButtonContent | None = Confirm.DEFAULT_CANCEL,
@ -60,7 +59,7 @@ async def info_confirm(
ctx: wire.GenericContext,
content: ui.Component,
info_func: Callable,
code: EnumTypeButtonRequestType = ButtonRequestType.Other,
code: ButtonRequestType = ButtonRequestType.Other,
confirm: ButtonContent = InfoConfirm.DEFAULT_CONFIRM,
confirm_style: ButtonStyleType = InfoConfirm.DEFAULT_CONFIRM_STYLE,
cancel: ButtonContent = InfoConfirm.DEFAULT_CANCEL,
@ -87,7 +86,7 @@ async def info_confirm(
async def hold_to_confirm(
ctx: wire.GenericContext,
content: ui.Component,
code: EnumTypeButtonRequestType = ButtonRequestType.Other,
code: ButtonRequestType = ButtonRequestType.Other,
confirm: str = HoldToConfirm.DEFAULT_CONFIRM,
confirm_style: ButtonStyleType = HoldToConfirm.DEFAULT_CONFIRM_STYLE,
loader_style: LoaderStyleType = HoldToConfirm.DEFAULT_LOADER_STYLE,

@ -16,7 +16,7 @@ if False:
)
from typing_extensions import Protocol
from protobuf import MessageType
from trezor.protobuf import MessageType
T = TypeVar("T")

@ -1,7 +1,7 @@
from micropython import const
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.button import ButtonDefault
from trezor.ui.components.tt.text import Text
from trezor.ui.container import Container

@ -1,9 +1,6 @@
import storage.device
from trezor import ui, utils, workflow
from trezor.messages import BackupType
if False:
from trezor.messages.ResetDevice import EnumTypeBackupType
from trezor.enums import BackupType
def get() -> tuple[bytes | None, int]:
@ -14,7 +11,7 @@ def get_secret() -> bytes | None:
return storage.device.get_mnemonic_secret()
def get_type() -> EnumTypeBackupType:
def get_type() -> BackupType:
return storage.device.get_backup_type()

@ -2,7 +2,7 @@ from micropython import const
import storage.device
from trezor import wire, workflow
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from . import button_request
@ -35,8 +35,7 @@ async def _request_from_user(ctx: wire.Context) -> str:
async def _request_on_host(ctx: wire.Context) -> str:
from trezor.messages.PassphraseAck import PassphraseAck
from trezor.messages.PassphraseRequest import PassphraseRequest
from trezor.messages import PassphraseAck, PassphraseRequest
from trezor.ui import ICON_CONFIG
from trezor.ui.components.tt.text import Text

@ -3,7 +3,7 @@ import utime
import storage.cache
import storage.sd_salt
from trezor import config, ui, wire
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.popup import Popup
from . import button_request

@ -2,13 +2,10 @@ import storage.cache
import storage.device
from storage.cache import APP_COMMON_SAFETY_CHECKS_TEMPORARY
from storage.device import SAFETY_CHECK_LEVEL_PROMPT, SAFETY_CHECK_LEVEL_STRICT
from trezor.messages import SafetyCheckLevel
from trezor.enums import SafetyCheckLevel
if False:
from trezor.messages.ApplySettings import EnumTypeSafetyCheckLevel
def read_setting() -> EnumTypeSafetyCheckLevel:
def read_setting() -> SafetyCheckLevel:
"""
Returns the effective safety check level.
"""
@ -25,7 +22,7 @@ def read_setting() -> EnumTypeSafetyCheckLevel:
raise ValueError("Unknown SafetyCheckLevel")
def apply_setting(level: EnumTypeSafetyCheckLevel) -> None:
def apply_setting(level: SafetyCheckLevel) -> None:
"""
Changes the safety level settings.
"""

@ -8,21 +8,25 @@ if __debug__:
from trezor import log, loop, wire
from trezor.ui import display
from trezor.messages import MessageType
from trezor.messages.DebugLinkLayout import DebugLinkLayout
from trezor.messages.Success import Success
from trezor.enums import MessageType
from trezor.messages import (
DebugLinkLayout,
Success,
)
from apps import workflow_handlers
if False:
from trezor.ui import Layout
from trezor.messages.DebugLinkDecision import DebugLinkDecision
from trezor.messages.DebugLinkGetState import DebugLinkGetState
from trezor.messages.DebugLinkRecordScreen import DebugLinkRecordScreen
from trezor.messages.DebugLinkReseedRandom import DebugLinkReseedRandom
from trezor.messages.DebugLinkState import DebugLinkState
from trezor.messages.DebugLinkEraseSdCard import DebugLinkEraseSdCard
from trezor.messages.DebugLinkWatchLayout import DebugLinkWatchLayout
from trezor.messages import (
DebugLinkDecision,
DebugLinkEraseSdCard,
DebugLinkGetState,
DebugLinkRecordScreen,
DebugLinkReseedRandom,
DebugLinkState,
DebugLinkWatchLayout,
)
reset_current_words = loop.chan()
reset_word_index = loop.chan()
@ -56,7 +60,7 @@ if __debug__:
layout_change_chan.publish(storage.current_content)
async def dispatch_debuglink_decision(msg: DebugLinkDecision) -> None:
from trezor.messages import DebugSwipeDirection
from trezor.enums import DebugSwipeDirection
from trezor.ui import Result
from trezor.ui.components.tt import confirm, swipe
@ -87,7 +91,7 @@ if __debug__:
if storage.layout_watcher is LAYOUT_WATCHER_LAYOUT:
await DEBUG_CONTEXT.write(DebugLinkLayout(lines=content))
else:
from trezor.messages.DebugLinkState import DebugLinkState
from trezor.messages import DebugLinkState
await DEBUG_CONTEXT.write(DebugLinkState(layout_lines=content))
storage.layout_watcher = LAYOUT_WATCHER_NONE
@ -137,7 +141,7 @@ if __debug__:
async def dispatch_DebugLinkGetState(
ctx: wire.Context, msg: DebugLinkGetState
) -> DebugLinkState | None:
from trezor.messages.DebugLinkState import DebugLinkState
from trezor.messages import DebugLinkState
from apps.common import mnemonic, passphrase
m = DebugLinkState()

@ -2,8 +2,8 @@ import storage
import storage.device
from trezor import config, wire
from trezor.crypto import bip39, slip39
from trezor.messages import BackupType
from trezor.messages.Success import Success
from trezor.enums import BackupType
from trezor.messages import Success
from trezor.ui.layouts import confirm_action
from apps.management import backup_types

@ -1,6 +1,5 @@
from trezor.crypto.hashlib import sha256
from trezor.messages.EosTxActionAck import EosTxActionAck
from trezor.messages.EosTxActionRequest import EosTxActionRequest
from trezor.messages import EosTxActionAck, EosTxActionRequest
from trezor.utils import HashWriter
from .. import helpers, writers

@ -2,7 +2,7 @@ from micropython import const
from ubinascii import hexlify
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.scroll import Paginated
from trezor.ui.components.tt.text import Text
from trezor.utils import chunks
@ -12,21 +12,23 @@ from ..layout import require_confirm
if False:
from trezor import wire
from trezor.messages.EosAuthorization import EosAuthorization
from trezor.messages.EosActionBuyRam import EosActionBuyRam
from trezor.messages.EosActionBuyRamBytes import EosActionBuyRamBytes
from trezor.messages.EosActionCommon import EosActionCommon
from trezor.messages.EosActionDelegate import EosActionDelegate
from trezor.messages.EosActionDeleteAuth import EosActionDeleteAuth
from trezor.messages.EosActionLinkAuth import EosActionLinkAuth
from trezor.messages.EosActionNewAccount import EosActionNewAccount
from trezor.messages.EosActionRefund import EosActionRefund
from trezor.messages.EosActionSellRam import EosActionSellRam
from trezor.messages.EosActionTransfer import EosActionTransfer
from trezor.messages.EosActionUndelegate import EosActionUndelegate
from trezor.messages.EosActionUnlinkAuth import EosActionUnlinkAuth
from trezor.messages.EosActionUpdateAuth import EosActionUpdateAuth
from trezor.messages.EosActionVoteProducer import EosActionVoteProducer
from trezor.messages import (
EosActionBuyRam,
EosActionBuyRamBytes,
EosActionCommon,
EosActionDelegate,
EosActionDeleteAuth,
EosActionLinkAuth,
EosActionNewAccount,
EosActionRefund,
EosActionSellRam,
EosActionTransfer,
EosActionUndelegate,
EosActionUnlinkAuth,
EosActionUpdateAuth,
EosActionVoteProducer,
EosAuthorization,
)
_LINE_LENGTH = const(17)
_LINE_PLACEHOLDER = "{:<" + str(_LINE_LENGTH) + "}"

@ -1,7 +1,6 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.messages.EosGetPublicKey import EosGetPublicKey
from trezor.messages.EosPublicKey import EosPublicKey
from trezor.messages import EosGetPublicKey, EosPublicKey
from apps.common import paths
from apps.common.keychain import Keychain, auto_keychain

@ -1,6 +1,6 @@
from trezor import wire
from trezor.crypto import base58
from trezor.messages.EosAsset import EosAsset
from trezor.messages import EosAsset
def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str:

@ -1,5 +1,5 @@
from trezor import ui, wire
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.text import Text
from apps.common.confirm import require_confirm

@ -1,10 +1,7 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha256
from trezor.messages.EosSignedTx import EosSignedTx
from trezor.messages.EosSignTx import EosSignTx
from trezor.messages.EosTxActionAck import EosTxActionAck
from trezor.messages.EosTxActionRequest import EosTxActionRequest
from trezor.messages import EosSignedTx, EosSignTx, EosTxActionAck, EosTxActionRequest
from trezor.utils import HashWriter
from apps.common import paths

@ -10,22 +10,24 @@ from apps.common.writers import (
)
if False:
from trezor.messages.EosActionBuyRam import EosActionBuyRam
from trezor.messages.EosActionBuyRamBytes import EosActionBuyRamBytes
from trezor.messages.EosActionCommon import EosActionCommon
from trezor.messages.EosActionDelegate import EosActionDelegate
from trezor.messages.EosActionDeleteAuth import EosActionDeleteAuth
from trezor.messages.EosActionLinkAuth import EosActionLinkAuth
from trezor.messages.EosActionNewAccount import EosActionNewAccount
from trezor.messages.EosActionRefund import EosActionRefund
from trezor.messages.EosActionSellRam import EosActionSellRam
from trezor.messages.EosActionTransfer import EosActionTransfer
from trezor.messages.EosActionUndelegate import EosActionUndelegate
from trezor.messages.EosActionUpdateAuth import EosActionUpdateAuth
from trezor.messages.EosActionVoteProducer import EosActionVoteProducer
from trezor.messages.EosAsset import EosAsset
from trezor.messages.EosAuthorization import EosAuthorization
from trezor.messages.EosTxHeader import EosTxHeader
from trezor.messages import (
EosActionBuyRam,
EosActionBuyRamBytes,
EosActionCommon,
EosActionDelegate,
EosActionDeleteAuth,
EosActionLinkAuth,
EosActionNewAccount,
EosActionRefund,
EosActionSellRam,
EosActionTransfer,
EosActionUndelegate,
EosActionUpdateAuth,
EosActionVoteProducer,
EosAsset,
EosAuthorization,
EosTxHeader,
)
from trezor.utils import Writer

@ -1,6 +1,6 @@
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha3_256
from trezor.messages.EthereumAddress import EthereumAddress
from trezor.messages import EthereumAddress
from trezor.ui.layouts import show_address
from apps.common import paths

@ -1,7 +1,6 @@
from ubinascii import hexlify
from trezor.messages.EthereumPublicKey import EthereumPublicKey
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages import EthereumPublicKey, HDNodeType
from trezor.ui.layouts import show_pubkey
from apps.common import coins, paths

@ -11,7 +11,7 @@ if False:
from protobuf import MessageType
from trezor.messages.EthereumSignTx import EthereumSignTx
from trezor.messages import EthereumSignTx
from apps.common.keychain import MsgOut, Handler, HandlerWithKeychain

@ -1,7 +1,7 @@
from ubinascii import hexlify
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.components.tt.text import Text
from trezor.utils import chunks

@ -1,6 +1,6 @@
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha3_256
from trezor.messages.EthereumMessageSignature import EthereumMessageSignature
from trezor.messages import EthereumMessageSignature
from trezor.ui.layouts import confirm_signverify
from trezor.utils import HashWriter

@ -2,9 +2,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.EthereumSignTx import EthereumSignTx
from trezor.messages.EthereumTxAck import EthereumTxAck
from trezor.messages.EthereumTxRequest import EthereumTxRequest
from trezor.messages import EthereumSignTx, EthereumTxAck, EthereumTxRequest
from trezor.utils import HashWriter
from apps.common import paths

@ -1,7 +1,7 @@
from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha3_256
from trezor.messages.Success import Success
from trezor.messages import Success
from trezor.ui.layouts import confirm_signverify
from apps.common.signverify import decode_message

@ -1,4 +1,4 @@
from trezor.messages.LiskAddress import LiskAddress
from trezor.messages import LiskAddress
from trezor.ui.layouts import show_address
from apps.common import paths

@ -1,6 +1,6 @@
from ubinascii import hexlify
from trezor.messages.LiskPublicKey import LiskPublicKey
from trezor.messages import LiskPublicKey
from trezor.ui.layouts import show_pubkey
from apps.common import paths

@ -1,7 +1,7 @@
from ubinascii import hexlify
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import show_pubkey

@ -1,6 +1,6 @@
from trezor.crypto.curve import ed25519
from trezor.crypto.hashlib import sha256
from trezor.messages.LiskMessageSignature import LiskMessageSignature
from trezor.messages import LiskMessageSignature
from trezor.ui.layouts import confirm_signverify
from trezor.utils import HashWriter

@ -3,8 +3,8 @@ import ustruct
from trezor import wire
from trezor.crypto.curve import ed25519
from trezor.crypto.hashlib import sha256
from trezor.messages import LiskTransactionType
from trezor.messages.LiskSignedTx import LiskSignedTx
from trezor.enums import LiskTransactionType
from trezor.messages import LiskSignedTx
from trezor.utils import HashWriter
from apps.common import paths

@ -1,6 +1,6 @@
from trezor import wire
from trezor.crypto.curve import ed25519
from trezor.messages.Success import Success
from trezor.messages import Success
from trezor.ui.layouts import confirm_signverify
from apps.common.signverify import decode_message

@ -1,7 +1,7 @@
import storage.device
from storage.device import set_flags
from trezor import wire
from trezor.messages.Success import Success
from trezor.messages import Success
async def apply_flags(ctx, msg):

@ -1,7 +1,7 @@
import storage.device
from trezor import ui, wire
from trezor.messages import ButtonRequestType, SafetyCheckLevel
from trezor.messages.Success import Success
from trezor.enums import ButtonRequestType, SafetyCheckLevel
from trezor.messages import Success
from trezor.strings import format_duration_ms
from trezor.ui.layouts import confirm_action
@ -9,7 +9,7 @@ from apps.base import reload_settings_from_storage
from apps.common import safety_checks
if False:
from trezor.messages.ApplySettings import ApplySettings, EnumTypeSafetyCheckLevel
from trezor.messages import ApplySettings
def validate_homescreen(homescreen: bytes) -> None:
@ -182,7 +182,7 @@ async def require_confirm_change_autolock_delay(ctx, delay_ms):
)
async def require_confirm_safety_checks(ctx, level: EnumTypeSafetyCheckLevel) -> None:
async def require_confirm_safety_checks(ctx, level: SafetyCheckLevel) -> None:
if level == SafetyCheckLevel.PromptAlways:
await confirm_action(
ctx,

@ -1,7 +1,7 @@
import storage
import storage.device
from trezor import wire
from trezor.messages.Success import Success
from trezor.messages import Success
from apps.common import mnemonic

@ -1,9 +1,5 @@
from trezor.crypto.slip39 import Share
from trezor.messages import BackupType
if False:
from trezor.messages.ResetDevice import EnumTypeBackupType
from trezor.enums import BackupType
_BIP39_WORD_COUNTS = (12, 18, 24)
_SLIP39_WORD_COUNTS = (20, 33)
@ -22,13 +18,11 @@ def is_slip39_word_count(word_count: int) -> bool:
raise RuntimeError
def is_slip39_backup_type(backup_type: EnumTypeBackupType) -> bool:
def is_slip39_backup_type(backup_type: BackupType) -> bool:
return backup_type in (BackupType.Slip39_Basic, BackupType.Slip39_Advanced)
def infer_backup_type(
is_slip39: bool, share: Share | None = None
) -> EnumTypeBackupType:
def infer_backup_type(is_slip39: bool, share: Share | None = None) -> BackupType:
if not is_slip39: # BIP-39
return BackupType.Bip39
elif not share or share.group_count < 1: # invalid parameters

@ -1,6 +1,6 @@
from storage.device import is_initialized
from trezor import config, wire
from trezor.messages.Success import Success
from trezor.messages import Success
from trezor.ui.layouts import confirm_action, show_success
from apps.common.request_pin import (
@ -11,7 +11,7 @@ from apps.common.request_pin import (
)
if False:
from trezor.messages.ChangePin import ChangePin
from trezor.messages import ChangePin
async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:

@ -1,6 +1,6 @@
from storage.device import is_initialized
from trezor import config, ui, wire
from trezor.messages.Success import Success
from trezor.messages import Success
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import show_success
from trezor.ui.popup import Popup
@ -13,7 +13,7 @@ from apps.common.request_pin import (
)
if False:
from trezor.messages.ChangeWipeCode import ChangeWipeCode
from trezor.messages import ChangeWipeCode
async def change_wipe_code(ctx: wire.Context, msg: ChangeWipeCode) -> Success:

@ -1,8 +1,7 @@
import storage.device
from trezor import ui, wire
from trezor.messages import ButtonRequestType
from trezor.messages.GetNextU2FCounter import GetNextU2FCounter
from trezor.messages.NextU2FCounter import NextU2FCounter
from trezor.enums import ButtonRequestType
from trezor.messages import GetNextU2FCounter, NextU2FCounter
from trezor.ui.components.tt.text import Text
from apps.common.confirm import require_confirm

@ -2,8 +2,8 @@ import storage
import storage.device
import storage.recovery
from trezor import config, ui, wire, workflow
from trezor.messages import ButtonRequestType
from trezor.messages.Success import Success
from trezor.enums import ButtonRequestType
from trezor.messages import Success
from trezor.ui.components.tt.text import Text
from apps.common.confirm import require_confirm
@ -16,7 +16,7 @@ from apps.common.request_pin import (
from .homescreen import recovery_homescreen, recovery_process
if False:
from trezor.messages.RecoveryDevice import RecoveryDevice
from trezor.messages import RecoveryDevice
# List of RecoveryDevice fields that can be set when doing dry-run recovery.
@ -91,10 +91,7 @@ def _validate(msg: RecoveryDevice) -> None:
async def _continue_dialog(ctx: wire.Context, msg: RecoveryDevice) -> None:
if not msg.dry_run:
text = Text("Recovery mode", ui.ICON_RECOVERY, new_lines=False)
text.bold("Do you really want to")
text.br()
text.bold("recover a wallet?")
text.bold("Do you really want to recover a wallet?")
text.br()
text.br_half()
text.normal("By continuing you agree")

@ -5,9 +5,9 @@ import storage.recovery_shares
from trezor import strings, utils, wire, workflow
from trezor.crypto import slip39
from trezor.crypto.hashlib import sha256
from trezor.enums import BackupType, MessageType
from trezor.errors import MnemonicError
from trezor.messages import BackupType, MessageType
from trezor.messages.Success import Success
from trezor.messages import Success
from trezor.ui.layouts import show_success
from apps.common import mnemonic
@ -16,9 +16,6 @@ from apps.homescreen.homescreen import homescreen
from .. import backup_types
from . import layout, recover
if False:
from trezor.messages.ResetDevice import EnumTypeBackupType
async def recovery_homescreen() -> None:
if not storage.recovery.is_in_progress():
@ -94,7 +91,7 @@ async def _continue_recovery_process(ctx: wire.GenericContext) -> Success:
async def _finish_recovery_dry_run(
ctx: wire.GenericContext, secret: bytes, backup_type: EnumTypeBackupType
ctx: wire.GenericContext, secret: bytes, backup_type: BackupType
) -> Success:
if backup_type is None:
raise RuntimeError
@ -127,7 +124,7 @@ async def _finish_recovery_dry_run(
async def _finish_recovery(
ctx: wire.GenericContext, secret: bytes, backup_type: EnumTypeBackupType
ctx: wire.GenericContext, secret: bytes, backup_type: BackupType
) -> Success:
if backup_type is None:
raise RuntimeError
@ -162,7 +159,7 @@ async def _request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int:
async def _process_words(
ctx: wire.GenericContext, words: str
) -> tuple[bytes | None, EnumTypeBackupType]:
) -> tuple[bytes | None, BackupType]:
word_count = len(words.split(" "))
is_slip39 = backup_types.is_slip39_word_count(word_count)

@ -1,7 +1,7 @@
import storage.recovery
from trezor import strings, ui, wire
from trezor.crypto.slip39 import MAX_SHARE_COUNT
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.scroll import Paginated
from trezor.ui.components.tt.text import Text
from trezor.ui.components.tt.word_select import WordSelector
@ -18,7 +18,7 @@ from .recover import RecoveryAborted
if False:
from typing import Callable, Iterable
from trezor.messages.ResetDevice import EnumTypeBackupType
from trezor.enums import BackupType
async def confirm_abort(ctx: wire.GenericContext, dry_run: bool = False) -> None:
@ -61,7 +61,7 @@ async def request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int:
async def request_mnemonic(
ctx: wire.GenericContext, word_count: int, backup_type: EnumTypeBackupType | None
ctx: wire.GenericContext, word_count: int, backup_type: BackupType | None
) -> str | None:
await button_request(ctx, code=ButtonRequestType.MnemonicInput)

@ -6,7 +6,7 @@ from trezor.errors import MnemonicError
from .. import backup_types
if False:
from trezor.messages.ResetDevice import EnumTypeBackupType
from trezor.enums import BackupType
from typing import Union
@ -92,7 +92,7 @@ def process_slip39(words: str) -> tuple[bytes | None, slip39.Share]:
if False:
Slip39State = Union[tuple[int, EnumTypeBackupType], tuple[None, None]]
Slip39State = Union[tuple[int, BackupType], tuple[None, None]]
def load_slip39_state() -> Slip39State:

@ -1,11 +1,8 @@
import storage.recovery
from trezor.messages import BackupType
from trezor.enums import BackupType
from . import recover
if False:
from trezor.messages.ResetDevice import EnumTypeBackupType
class WordValidityResult(Exception):
pass
@ -23,7 +20,7 @@ class ThresholdReached(WordValidityResult):
pass
def check(backup_type: EnumTypeBackupType | None, partial_mnemonic: list[str]) -> None:
def check(backup_type: BackupType | None, partial_mnemonic: list[str]) -> None:
# we can't perform any checks if the backup type was not yet decided
if backup_type is None:
return

@ -2,10 +2,8 @@ import storage
import storage.device
from trezor import config, wire
from trezor.crypto import bip39, hashlib, random, slip39
from trezor.messages import BackupType
from trezor.messages.EntropyAck import EntropyAck
from trezor.messages.EntropyRequest import EntropyRequest
from trezor.messages.Success import Success
from trezor.enums import BackupType
from trezor.messages import EntropyAck, EntropyRequest, Success
from trezor.ui.layouts import confirm_backup, confirm_reset_device
from trezor.ui.loader import LoadingAnimation
@ -17,7 +15,7 @@ if __debug__:
import storage.debug
if False:
from trezor.messages.ResetDevice import ResetDevice
from trezor.messages import ResetDevice
_DEFAULT_BACKUP_TYPE = BackupType.Bip39

@ -2,7 +2,7 @@ import ubinascii
from trezor import ui, utils
from trezor.crypto import random
from trezor.messages import BackupType, ButtonRequestType
from trezor.enums import BackupType, ButtonRequestType
from trezor.ui.components.tt.button import Button, ButtonDefault
from trezor.ui.components.tt.checklist import Checklist
from trezor.ui.components.tt.info import InfoConfirm

@ -2,8 +2,8 @@ import storage.device
import storage.sd_salt
from trezor import config, wire
from trezor.crypto import random
from trezor.messages import SdProtectOperationType
from trezor.messages.Success import Success
from trezor.enums import SdProtectOperationType
from trezor.messages import Success
from trezor.ui.layouts import confirm_action, show_success
from apps.common.request_pin import (
@ -15,7 +15,7 @@ from apps.common.sdcard import confirm_retry_sd, ensure_sdcard
if False:
from typing import Awaitable
from trezor.messages.SdProtect import SdProtect
from trezor.messages import SdProtect
def _make_salt() -> tuple[bytes, bytes, bytes]:

@ -1,8 +1,7 @@
import storage.device
from trezor import ui, wire
from trezor.messages import ButtonRequestType
from trezor.messages.SetU2FCounter import SetU2FCounter
from trezor.messages.Success import Success
from trezor.enums import ButtonRequestType
from trezor.messages import SetU2FCounter, Success
from trezor.ui.components.tt.text import Text
from apps.common.confirm import require_confirm

@ -1,7 +1,7 @@
import storage
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.messages.Success import Success
from trezor.enums import ButtonRequestType
from trezor.messages import Success
from trezor.ui.layouts import confirm_action
from .apply_settings import reload_settings_from_storage

@ -1,15 +1,16 @@
from trezor import wire
from trezor.crypto import aes, hmac
from trezor.messages.CipheredKeyValue import CipheredKeyValue
from trezor.messages import CipheredKeyValue
from trezor.ui.layouts import confirm_action
from apps.common.keychain import get_keychain
from apps.common.paths import AlwaysMatchingSchema
if False:
from trezor.messages.CipherKeyValue import CipherKeyValue
from trezor.wire import Context
from trezor.messages import CipherKeyValue
# This module implements the SLIP-0011 symmetric encryption of key-value pairs using a
# deterministic hierarchy, see https://github.com/satoshilabs/slips/blob/master/slip-0011.md.

@ -2,7 +2,7 @@ from ustruct import pack, unpack
from trezor import ui, wire
from trezor.crypto.hashlib import sha256
from trezor.messages.ECDHSessionKey import ECDHSessionKey
from trezor.messages import ECDHSessionKey
from trezor.ui.layouts import confirm_hex
from apps.common import HARDENED
@ -12,8 +12,7 @@ from apps.common.paths import AlwaysMatchingSchema
from .sign_identity import serialize_identity, serialize_identity_without_proto
if False:
from trezor.messages.GetECDHSessionKey import GetECDHSessionKey
from trezor.messages.IdentityType import IdentityType
from trezor.messages import GetECDHSessionKey, IdentityType
from apps.common.paths import Bip32Path

@ -1,11 +1,11 @@
from trezor.crypto import random
from trezor.messages import ButtonRequestType
from trezor.messages.Entropy import Entropy
from trezor.enums import ButtonRequestType
from trezor.messages import Entropy
from trezor.ui.layouts import confirm_action
if False:
from trezor.wire import Context
from trezor.messages.GetEntropy import GetEntropy
from trezor.messages import GetEntropy
async def get_entropy(ctx: Context, msg: GetEntropy) -> Entropy:

@ -2,7 +2,7 @@ from ustruct import pack, unpack
from trezor import wire
from trezor.crypto.hashlib import sha256
from trezor.messages.SignedIdentity import SignedIdentity
from trezor.messages import SignedIdentity
from trezor.ui.layouts import confirm_sign_identity
from apps.common import HARDENED, coininfo
@ -10,8 +10,7 @@ from apps.common.keychain import get_keychain
from apps.common.paths import AlwaysMatchingSchema
if False:
from trezor.messages.IdentityType import IdentityType
from trezor.messages.SignIdentity import SignIdentity
from trezor.messages import IdentityType, SignIdentity
from apps.common.paths import Bip32Path

@ -36,7 +36,7 @@ if __debug__:
PREV_MEM = free
def retit(**kwargs):
from trezor.messages.Failure import Failure
from trezor.messages import Failure
return Failure(**kwargs)

@ -1,4 +1,4 @@
from trezor.messages.MoneroAddress import MoneroAddress
from trezor.messages import MoneroAddress
from apps.common import paths
from apps.common.keychain import auto_keychain

@ -16,8 +16,7 @@ using the view key, which the host possess.
"""
from trezor import utils
from trezor.messages.MoneroGetTxKeyAck import MoneroGetTxKeyAck
from trezor.messages.MoneroGetTxKeyRequest import MoneroGetTxKeyRequest
from trezor.messages import MoneroGetTxKeyAck, MoneroGetTxKeyRequest
from apps.common import paths
from apps.common.keychain import auto_keychain

@ -1,5 +1,4 @@
from trezor.messages.MoneroGetWatchKey import MoneroGetWatchKey
from trezor.messages.MoneroWatchKey import MoneroWatchKey
from trezor.messages import MoneroGetWatchKey, MoneroWatchKey
from apps.common import paths
from apps.common.keychain import auto_keychain

@ -1,14 +1,14 @@
import gc
from trezor import log, wire
from trezor.messages.MoneroExportedKeyImage import MoneroExportedKeyImage
from trezor.messages.MoneroKeyImageExportInitAck import MoneroKeyImageExportInitAck
from trezor.messages.MoneroKeyImageSyncFinalAck import MoneroKeyImageSyncFinalAck
from trezor.messages.MoneroKeyImageSyncFinalRequest import (
from trezor.messages import (
MoneroExportedKeyImage,
MoneroKeyImageExportInitAck,
MoneroKeyImageSyncFinalAck,
MoneroKeyImageSyncFinalRequest,
MoneroKeyImageSyncStepAck,
MoneroKeyImageSyncStepRequest,
)
from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck
from trezor.messages.MoneroKeyImageSyncStepRequest import MoneroKeyImageSyncStepRequest
from apps.common import paths
from apps.common.keychain import auto_keychain

@ -1,5 +1,5 @@
from trezor import strings, ui, utils
from trezor.messages import ButtonRequestType
from trezor.enums import ButtonRequestType
from trezor.ui.components.tt.text import Text
from apps.common import button_request

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save