mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-18 03:10:58 +00:00
src/apps: some import refactoring
This commit is contained in:
parent
cfa73b276e
commit
b22f0aad86
@ -0,0 +1,4 @@
|
||||
from micropython import const
|
||||
|
||||
HARDENED = const(0x80000000)
|
||||
OVERWINTERED = const(0x80000000)
|
@ -5,7 +5,7 @@ async def ethereum_get_address(ctx, msg):
|
||||
from trezor.messages.EthereumAddress import EthereumAddress
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.crypto.hashlib import sha3_256
|
||||
from ..common import seed
|
||||
from apps.common import seed
|
||||
|
||||
address_n = msg.address_n or ()
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
from apps.common.confirm import *
|
||||
from apps.ethereum import tokens
|
||||
from ubinascii import hexlify
|
||||
|
||||
from trezor import ui
|
||||
from trezor.utils import chunks, format_amount
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.ui.text import Text
|
||||
from ubinascii import hexlify
|
||||
from . import networks
|
||||
from .get_address import _ethereum_address_hex
|
||||
|
||||
from apps.common.confirm import require_confirm, require_hold_to_confirm
|
||||
from apps.ethereum import networks, tokens
|
||||
from apps.ethereum.get_address import _ethereum_address_hex
|
||||
|
||||
|
||||
async def require_confirm_tx(ctx, to, value, chain_id, token=None, tx_type=None):
|
||||
|
@ -104,7 +104,7 @@ async def send_request_chunk(ctx, data_left: int):
|
||||
|
||||
async def send_signature(ctx, msg: EthereumSignTx, digest):
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from ..common import seed
|
||||
from apps.common import seed
|
||||
|
||||
address_n = msg.address_n or ()
|
||||
node = await seed.derive_node(ctx, address_n)
|
||||
|
@ -15,7 +15,7 @@ from trezor.crypto import hashlib
|
||||
from trezor.crypto import hmac
|
||||
from trezor.crypto import random
|
||||
from trezor.crypto.curve import nist256p1
|
||||
from apps.common import storage
|
||||
from apps.common import storage, HARDENED
|
||||
|
||||
|
||||
_HID_RPT_SIZE = const(64)
|
||||
@ -418,7 +418,7 @@ class ConfirmContent(ui.Widget):
|
||||
def boot(self) -> None:
|
||||
from ubinascii import hexlify
|
||||
from trezor import res
|
||||
from . import knownapps
|
||||
from apps.fido_u2f import knownapps
|
||||
|
||||
app_id = bytes(self.app_id) # could be bytearray, which doesn't have __hash__
|
||||
|
||||
@ -563,7 +563,7 @@ def msg_register_sign(challenge: bytes, app_id: bytes) -> bytes:
|
||||
from apps.common import seed
|
||||
|
||||
# derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r'
|
||||
keypath = [0x80000000 | random.uniform(0xf0000000) for _ in range(0, 8)]
|
||||
keypath = [HARDENED | random.uniform(0xf0000000) for _ in range(0, 8)]
|
||||
nodepath = [_U2F_KEY_PATH] + keypath
|
||||
|
||||
# prepare signing key from random path, compute decompressed public key
|
||||
@ -679,7 +679,7 @@ def msg_authenticate_genkey(app_id: bytes, keyhandle: bytes):
|
||||
|
||||
# check high bit for hardened keys
|
||||
for i in keypath:
|
||||
if not i & 0x80000000:
|
||||
if not i & HARDENED:
|
||||
if __debug__:
|
||||
log.warning(__name__, 'invalid key path')
|
||||
return None
|
||||
|
@ -1,7 +1,7 @@
|
||||
from trezor import config, loop, ui, wire
|
||||
from trezor.messages import wire_types
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.ButtonRequest import ButtonRequest
|
||||
from trezor.messages.ButtonRequestType import Other
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.pin import pin_to_int, show_pin_timeout
|
||||
from trezor.ui.text import Text
|
||||
@ -71,7 +71,7 @@ async def request_pin_confirm(ctx, *args, **kwargs):
|
||||
|
||||
async def request_pin_ack(ctx, *args, **kwargs):
|
||||
try:
|
||||
await ctx.call(ButtonRequest(code=Other), wire_types.ButtonAck)
|
||||
await ctx.call(ButtonRequest(code=ButtonRequestType.Other), wire_types.ButtonAck)
|
||||
return await ctx.wait(request_pin(*args, **kwargs))
|
||||
except PinCancelled:
|
||||
raise wire.ActionCancelled('Cancelled')
|
||||
|
@ -7,7 +7,7 @@ from apps.common.confirm import require_confirm
|
||||
from apps.wallet.sign_identity import serialize_identity, serialize_identity_without_proto
|
||||
from trezor.ui.text import Text
|
||||
|
||||
from ..common import seed
|
||||
from apps.common import seed, HARDENED
|
||||
|
||||
|
||||
async def get_ecdh_session_key(ctx, msg):
|
||||
@ -39,7 +39,7 @@ def get_ecdh_path(identity: str, index: int):
|
||||
identity_hash = sha256(pack('<I', index) + identity).digest()
|
||||
|
||||
address_n = (17, ) + unpack('<IIII', identity_hash[:16])
|
||||
address_n = [0x80000000 | x for x in address_n]
|
||||
address_n = [HARDENED | x for x in address_n]
|
||||
|
||||
return address_n
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
from ustruct import pack, unpack
|
||||
|
||||
from trezor import ui
|
||||
from trezor.crypto.hashlib import sha256
|
||||
from trezor.messages.SignedIdentity import SignedIdentity
|
||||
from ustruct import pack, unpack
|
||||
from trezor.utils import chunks
|
||||
from apps.common.confirm import require_confirm
|
||||
from trezor.ui.text import Text
|
||||
|
||||
from ..common import coins, seed
|
||||
from apps.common import coins, seed, HARDENED
|
||||
from apps.common.confirm import require_confirm
|
||||
|
||||
|
||||
async def sign_identity(ctx, msg):
|
||||
@ -84,7 +85,7 @@ def get_identity_path(identity: str, index: int):
|
||||
identity_hash = sha256(pack('<I', index) + identity).digest()
|
||||
|
||||
address_n = (13, ) + unpack('<IIII', identity_hash[:16])
|
||||
address_n = [0x80000000 | x for x in address_n]
|
||||
address_n = [HARDENED | x for x in address_n]
|
||||
|
||||
return address_n
|
||||
|
||||
@ -101,7 +102,7 @@ def sign_challenge(seckey: bytes,
|
||||
from trezor.crypto.curve import nist256p1
|
||||
elif curve == 'ed25519':
|
||||
from trezor.crypto.curve import ed25519
|
||||
from ..common.signverify import message_digest
|
||||
from apps.common.signverify import message_digest
|
||||
|
||||
if sigtype == 'gpg':
|
||||
data = challenge_hidden
|
||||
|
@ -1,7 +1,9 @@
|
||||
from trezor import ui, wire
|
||||
from trezor.messages.wire_types import TxAck
|
||||
from trezor.messages.TxRequest import TxRequest
|
||||
from trezor.messages.RequestType import TXFINISHED
|
||||
from apps.common import seed
|
||||
from apps.wallet.sign_tx.helpers import *
|
||||
from apps.wallet.sign_tx.helpers import UiConfirmOutput, UiConfirmTotal, UiConfirmFeeOverThreshold
|
||||
|
||||
|
||||
@ui.layout
|
||||
|
@ -9,8 +9,8 @@ from trezor.messages import InputScriptType
|
||||
|
||||
from apps.common.coininfo import CoinInfo
|
||||
from apps.common.address_type import addrtype_bytes
|
||||
from apps.wallet.sign_tx.scripts import *
|
||||
from apps.wallet.sign_tx.multisig import *
|
||||
from apps.wallet.sign_tx.scripts import output_script_multisig, sha256_ripemd160_digest, output_script_native_p2wpkh_or_p2wsh
|
||||
from apps.wallet.sign_tx.multisig import multisig_pubkey_index, multisig_get_pubkeys
|
||||
|
||||
# supported witness version for bech32 addresses
|
||||
_BECH32_WITVER = const(0x00)
|
||||
|
@ -6,7 +6,7 @@ from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
|
||||
from trezor.messages.HDNodePathType import HDNodePathType
|
||||
from trezor.messages import FailureType
|
||||
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from apps.wallet.sign_tx.writers import write_bytes, write_uint32
|
||||
|
||||
|
||||
class MultisigError(ValueError):
|
||||
|
@ -1,6 +1,7 @@
|
||||
from trezor.crypto.hashlib import ripemd160, sha256
|
||||
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
|
||||
from apps.wallet.sign_tx.multisig import multisig_get_pubkeys
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from apps.wallet.sign_tx.writers import bytearray_with_cap, write_bytes, write_varint, write_op_push
|
||||
|
||||
|
||||
class ScriptsError(ValueError):
|
||||
|
@ -1,10 +1,13 @@
|
||||
from trezor.crypto.hashlib import sha256
|
||||
from trezor.messages.SignTx import SignTx
|
||||
from trezor.messages.TxInputType import TxInputType
|
||||
from trezor.messages.TxOutputBinType import TxOutputBinType
|
||||
from trezor.messages import InputScriptType, FailureType
|
||||
from trezor.utils import HashWriter
|
||||
|
||||
from apps.common.coininfo import CoinInfo
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from apps.common import OVERWINTERED
|
||||
from apps.wallet.sign_tx.writers import write_bytes, write_bytes_rev, write_uint32, write_uint64, write_varint, write_tx_output, get_tx_hash
|
||||
from apps.wallet.sign_tx.scripts import output_script_p2pkh, output_script_multisig
|
||||
from apps.wallet.sign_tx.multisig import multisig_get_pubkeys
|
||||
|
||||
@ -43,7 +46,7 @@ class Bip143:
|
||||
h_preimage = HashWriter(sha256)
|
||||
|
||||
if tx.overwintered:
|
||||
write_uint32(h_preimage, tx.version | 0x80000000) # nVersion | fOverwintered
|
||||
write_uint32(h_preimage, tx.version | OVERWINTERED) # nVersion | fOverwintered
|
||||
write_uint32(h_preimage, coin.version_group_id) # nVersionGroupId
|
||||
else:
|
||||
write_uint32(h_preimage, tx.version) # nVersion
|
||||
|
@ -9,10 +9,11 @@ from trezor.messages import OutputScriptType
|
||||
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
|
||||
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
|
||||
|
||||
from apps.common import address_type, coins
|
||||
from apps.common import address_type, coins, OVERWINTERED
|
||||
from apps.common.coininfo import CoinInfo
|
||||
from apps.wallet.sign_tx.addresses import *
|
||||
from apps.wallet.sign_tx.helpers import *
|
||||
from apps.wallet.sign_tx.multisig import *
|
||||
from apps.wallet.sign_tx.scripts import *
|
||||
from apps.wallet.sign_tx.segwit_bip143 import *
|
||||
from apps.wallet.sign_tx.tx_weight_calculator import *
|
||||
@ -243,7 +244,7 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode):
|
||||
h_second = HashWriter(sha256)
|
||||
|
||||
if tx.overwintered:
|
||||
write_uint32(h_sign, tx.version | 0x80000000) # nVersion | fOverwintered
|
||||
write_uint32(h_sign, tx.version | OVERWINTERED) # nVersion | fOverwintered
|
||||
write_uint32(h_sign, coin.version_group_id) # nVersionGroupId
|
||||
else:
|
||||
write_uint32(h_sign, tx.version) # nVersion
|
||||
@ -394,7 +395,7 @@ async def get_prevtx_output_value(coin: CoinInfo, tx_req: TxRequest, prev_hash:
|
||||
txh = HashWriter(sha256)
|
||||
|
||||
if tx.overwintered:
|
||||
write_uint32(txh, tx.version | 0x80000000) # nVersion | fOverwintered
|
||||
write_uint32(txh, tx.version | OVERWINTERED) # nVersion | fOverwintered
|
||||
write_uint32(txh, coin.version_group_id) # nVersionGroupId
|
||||
else:
|
||||
write_uint32(txh, tx.version) # nVersion
|
||||
@ -450,7 +451,7 @@ def get_hash_type(coin: CoinInfo) -> int:
|
||||
def get_tx_header(coin: CoinInfo, tx: SignTx, segwit: bool = False):
|
||||
w_txi = bytearray()
|
||||
if tx.overwintered:
|
||||
write_uint32(w_txi, tx.version | 0x80000000) # nVersion | fOverwintered
|
||||
write_uint32(w_txi, tx.version | OVERWINTERED) # nVersion | fOverwintered
|
||||
write_uint32(w_txi, coin.version_group_id) # nVersionGroupId
|
||||
else:
|
||||
write_uint32(w_txi, tx.version) # nVersion
|
||||
|
@ -1,6 +1,6 @@
|
||||
from trezor.crypto.hashlib import sha256
|
||||
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from trezor.messages.TxInputType import TxInputType
|
||||
from trezor.messages.TxOutputBinType import TxOutputBinType
|
||||
|
||||
|
||||
# TX Serialization
|
||||
|
Loading…
Reference in New Issue
Block a user