1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 22:18:13 +00:00

core: use new keychain decorators where appropriate

This commit is contained in:
matejcik 2020-04-20 11:51:46 +02:00 committed by matejcik
parent fd9e945308
commit b594248ac2
33 changed files with 121 additions and 98 deletions

View File

@ -1,13 +1,11 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "secp256k1" CURVE = "secp256k1"
SLIP44_ID = 714
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 714]] wire.add(MessageType.BinanceGetAddress, __name__, "get_address")
wire.add(MessageType.BinanceGetAddress, __name__, "get_address", ns) wire.add(MessageType.BinanceGetPublicKey, __name__, "get_public_key")
wire.add(MessageType.BinanceGetPublicKey, __name__, "get_public_key", ns) wire.add(MessageType.BinanceSignTx, __name__, "sign_tx")
wire.add(MessageType.BinanceSignTx, __name__, "sign_tx", ns)

View File

@ -1,12 +1,14 @@
from trezor.messages.BinanceAddress import BinanceAddress from trezor.messages.BinanceAddress import BinanceAddress
from trezor.messages.BinanceGetAddress import BinanceGetAddress from trezor.messages.BinanceGetAddress import BinanceGetAddress
from apps.binance import CURVE, helpers from apps.binance import CURVE, SLIP44_ID, helpers
from apps.common import paths from apps.common import paths
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.common.seed import Keychain, with_slip44_keychain
async def get_address(ctx, msg: BinanceGetAddress, keychain): @with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg: BinanceGetAddress, keychain: Keychain):
HRP = "bnb" HRP = "bnb"
await paths.validate_path( await paths.validate_path(

View File

@ -1,11 +1,13 @@
from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey
from trezor.messages.BinancePublicKey import BinancePublicKey from trezor.messages.BinancePublicKey import BinancePublicKey
from apps.binance import CURVE, helpers from apps.binance import CURVE, SLIP44_ID, helpers
from apps.common import layout, paths from apps.common import layout, paths
from apps.common.seed import Keychain, with_slip44_keychain
async def get_public_key(ctx, msg: BinanceGetPublicKey, keychain): @with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_public_key(ctx, msg: BinanceGetPublicKey, keychain: Keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )

View File

@ -8,11 +8,13 @@ from trezor.messages.BinanceSignedTx import BinanceSignedTx
from trezor.messages.BinanceTransferMsg import BinanceTransferMsg from trezor.messages.BinanceTransferMsg import BinanceTransferMsg
from trezor.messages.BinanceTxRequest import BinanceTxRequest from trezor.messages.BinanceTxRequest import BinanceTxRequest
from apps.binance import CURVE, helpers, layout from apps.binance import CURVE, SLIP44_ID, helpers, layout
from apps.common import paths from apps.common import paths
from apps.common.seed import Keychain, with_slip44_keychain
async def sign_tx(ctx, envelope, keychain): @with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, envelope, keychain: Keychain):
# create transaction message -> sign it -> create signature/pubkey message -> serialize all # create transaction message -> sign it -> create signature/pubkey message -> serialize all
if envelope.msg_count > 1: if envelope.msg_count > 1:
raise wire.DataError("Multiple messages not supported.") raise wire.DataError("Multiple messages not supported.")

View File

@ -1,13 +1,10 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "secp256k1" CURVE = "secp256k1"
SLIP44_ID = 194
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 194]] wire.add(MessageType.EosGetPublicKey, __name__, "get_public_key")
wire.add(MessageType.EosSignTx, __name__, "sign_tx")
wire.add(MessageType.EosGetPublicKey, __name__, "get_public_key", ns)
wire.add(MessageType.EosSignTx, __name__, "sign_tx", ns)

View File

@ -4,14 +4,14 @@ from trezor.messages.EosGetPublicKey import EosGetPublicKey
from trezor.messages.EosPublicKey import EosPublicKey from trezor.messages.EosPublicKey import EosPublicKey
from apps.common import paths from apps.common import paths
from apps.eos import CURVE from apps.common.seed import Keychain, with_slip44_keychain
from apps.eos import CURVE, SLIP44_ID
from apps.eos.helpers import public_key_to_wif, validate_full_path from apps.eos.helpers import public_key_to_wif, validate_full_path
from apps.eos.layout import require_get_public_key from apps.eos.layout import require_get_public_key
if False: if False:
from typing import Tuple from typing import Tuple
from trezor.crypto import bip32 from trezor.crypto import bip32
from apps.common import seed
def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]: def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]:
@ -21,8 +21,9 @@ def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]:
return wif, public_key return wif, public_key
@with_slip44_keychain(SLIP44_ID, CURVE)
async def get_public_key( async def get_public_key(
ctx: wire.Context, msg: EosGetPublicKey, keychain: seed.Keychain ctx: wire.Context, msg: EosGetPublicKey, keychain: Keychain
) -> EosPublicKey: ) -> EosPublicKey:
await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE)

View File

@ -8,18 +8,15 @@ from trezor.messages.EosTxActionRequest import EosTxActionRequest
from trezor.utils import HashWriter from trezor.utils import HashWriter
from apps.common import paths from apps.common import paths
from apps.eos import CURVE, writers from apps.common.seed import Keychain, with_slip44_keychain
from apps.eos import CURVE, SLIP44_ID, writers
from apps.eos.actions import process_action from apps.eos.actions import process_action
from apps.eos.helpers import base58_encode, validate_full_path from apps.eos.helpers import base58_encode, validate_full_path
from apps.eos.layout import require_sign_tx from apps.eos.layout import require_sign_tx
if False:
from apps.common import seed
@with_slip44_keychain(SLIP44_ID, CURVE)
async def sign_tx( async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosSignedTx:
ctx: wire.Context, msg: EosSignTx, keychain: seed.Keychain
) -> EosSignedTx:
if msg.chain_id is None: if msg.chain_id is None:
raise wire.DataError("No chain id") raise wire.DataError("No chain id")
if msg.header is None: if msg.header is None:

View File

@ -1,15 +1,13 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "ed25519" CURVE = "ed25519"
SLIP44_ID = 134
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 134]] wire.add(MessageType.LiskGetPublicKey, __name__, "get_public_key")
wire.add(MessageType.LiskGetPublicKey, __name__, "get_public_key", ns) wire.add(MessageType.LiskGetAddress, __name__, "get_address")
wire.add(MessageType.LiskGetAddress, __name__, "get_address", ns) wire.add(MessageType.LiskSignTx, __name__, "sign_tx")
wire.add(MessageType.LiskSignTx, __name__, "sign_tx", ns) wire.add(MessageType.LiskSignMessage, __name__, "sign_message")
wire.add(MessageType.LiskSignMessage, __name__, "sign_message", ns)
wire.add(MessageType.LiskVerifyMessage, __name__, "verify_message") wire.add(MessageType.LiskVerifyMessage, __name__, "verify_message")

View File

@ -4,13 +4,15 @@ from .helpers import get_address_from_public_key, validate_full_path
from apps.common import paths from apps.common import paths
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.lisk import CURVE from apps.common.seed import with_slip44_keychain
from apps.lisk import CURVE, SLIP44_ID
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg, keychain): async def get_address(ctx, msg, keychain):
await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE)
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pubkey = node.public_key() pubkey = node.public_key()
pubkey = pubkey[1:] # skip ed25519 pubkey marker pubkey = pubkey[1:] # skip ed25519 pubkey marker
address = get_address_from_public_key(pubkey) address = get_address_from_public_key(pubkey)

View File

@ -1,14 +1,16 @@
from trezor.messages.LiskPublicKey import LiskPublicKey from trezor.messages.LiskPublicKey import LiskPublicKey
from apps.common import layout, paths from apps.common import layout, paths
from apps.lisk import CURVE from apps.common.seed import with_slip44_keychain
from apps.lisk import CURVE, SLIP44_ID
from apps.lisk.helpers import validate_full_path from apps.lisk.helpers import validate_full_path
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_public_key(ctx, msg, keychain): async def get_public_key(ctx, msg, keychain):
await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE)
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pubkey = node.public_key() pubkey = node.public_key()
pubkey = pubkey[1:] # skip ed25519 pubkey marker pubkey = pubkey[1:] # skip ed25519 pubkey marker

View File

@ -4,8 +4,9 @@ from trezor.messages.LiskMessageSignature import LiskMessageSignature
from trezor.utils import HashWriter from trezor.utils import HashWriter
from apps.common import paths from apps.common import paths
from apps.common.seed import with_slip44_keychain
from apps.common.signverify import require_confirm_sign_message from apps.common.signverify import require_confirm_sign_message
from apps.lisk import CURVE from apps.lisk import CURVE, SLIP44_ID
from apps.lisk.helpers import validate_full_path from apps.lisk.helpers import validate_full_path
from apps.wallet.sign_tx.writers import write_varint from apps.wallet.sign_tx.writers import write_varint
@ -20,11 +21,12 @@ def message_digest(message):
return sha256(h.get_digest()).digest() return sha256(h.get_digest()).digest()
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_message(ctx, msg, keychain): async def sign_message(ctx, msg, keychain):
await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE)
await require_confirm_sign_message(ctx, "Sign Lisk message", msg.message) await require_confirm_sign_message(ctx, "Sign Lisk message", msg.message)
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
seckey = node.private_key() seckey = node.private_key()
pubkey = node.public_key() pubkey = node.public_key()
pubkey = pubkey[1:] # skip ed25519 pubkey marker pubkey = pubkey[1:] # skip ed25519 pubkey marker

View File

@ -8,10 +8,12 @@ from trezor.messages.LiskSignedTx import LiskSignedTx
from trezor.utils import HashWriter from trezor.utils import HashWriter
from apps.common import paths from apps.common import paths
from apps.lisk import CURVE, layout from apps.common.seed import with_slip44_keychain
from apps.lisk import CURVE, SLIP44_ID, layout
from apps.lisk.helpers import get_address_from_public_key, validate_full_path from apps.lisk.helpers import get_address_from_public_key, validate_full_path
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, msg, keychain): async def sign_tx(ctx, msg, keychain):
await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE)
@ -37,7 +39,7 @@ async def sign_tx(ctx, msg, keychain):
def _get_keys(keychain, msg): def _get_keys(keychain, msg):
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
seckey = node.private_key() seckey = node.private_key()
pubkey = node.public_key() pubkey = node.public_key()

View File

@ -1,21 +1,17 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "ed25519" CURVE = "ed25519"
SLIP44_ID = 128
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 128]] wire.add(MessageType.MoneroGetAddress, __name__, "get_address")
wire.add(MessageType.MoneroGetAddress, __name__, "get_address", ns) wire.add(MessageType.MoneroGetWatchKey, __name__, "get_watch_only")
wire.add(MessageType.MoneroGetWatchKey, __name__, "get_watch_only", ns) wire.add(MessageType.MoneroTransactionInitRequest, __name__, "sign_tx")
wire.add(MessageType.MoneroTransactionInitRequest, __name__, "sign_tx", ns) wire.add(MessageType.MoneroKeyImageExportInitRequest, __name__, "key_image_sync")
wire.add( wire.add(MessageType.MoneroGetTxKeyRequest, __name__, "get_tx_keys")
MessageType.MoneroKeyImageExportInitRequest, __name__, "key_image_sync", ns wire.add(MessageType.MoneroLiveRefreshStartRequest, __name__, "live_refresh")
)
wire.add(MessageType.MoneroGetTxKeyRequest, __name__, "get_tx_keys", ns)
wire.add(MessageType.MoneroLiveRefreshStartRequest, __name__, "live_refresh", ns)
if __debug__ and hasattr(MessageType, "DebugMoneroDiagRequest"): if __debug__ and hasattr(MessageType, "DebugMoneroDiagRequest"):
wire.add(MessageType.DebugMoneroDiagRequest, __name__, "diag") wire.add(MessageType.DebugMoneroDiagRequest, __name__, "diag")

View File

@ -2,12 +2,14 @@ from trezor.messages.MoneroAddress import MoneroAddress
from apps.common import paths from apps.common import paths
from apps.common.layout import address_n_to_str, show_qr from apps.common.layout import address_n_to_str, show_qr
from apps.monero import CURVE, misc from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import addresses, crypto, monero from apps.monero.xmr import addresses, crypto, monero
from apps.monero.xmr.networks import net_version from apps.monero.xmr.networks import net_version
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg, keychain): async def get_address(ctx, msg, keychain):
await paths.validate_path( await paths.validate_path(
ctx, misc.validate_full_path, keychain, msg.address_n, CURVE ctx, misc.validate_full_path, keychain, msg.address_n, CURVE

View File

@ -20,7 +20,8 @@ from trezor.messages.MoneroGetTxKeyAck import MoneroGetTxKeyAck
from trezor.messages.MoneroGetTxKeyRequest import MoneroGetTxKeyRequest from trezor.messages.MoneroGetTxKeyRequest import MoneroGetTxKeyRequest
from apps.common import paths from apps.common import paths
from apps.monero import CURVE, misc from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import crypto from apps.monero.xmr import crypto
from apps.monero.xmr.crypto import chacha_poly from apps.monero.xmr.crypto import chacha_poly
@ -29,6 +30,7 @@ _GET_TX_KEY_REASON_TX_KEY = 0
_GET_TX_KEY_REASON_TX_DERIVATION = 1 _GET_TX_KEY_REASON_TX_DERIVATION = 1
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_tx_keys(ctx, msg: MoneroGetTxKeyRequest, keychain): async def get_tx_keys(ctx, msg: MoneroGetTxKeyRequest, keychain):
await paths.validate_path( await paths.validate_path(
ctx, misc.validate_full_path, keychain, msg.address_n, CURVE ctx, misc.validate_full_path, keychain, msg.address_n, CURVE

View File

@ -2,11 +2,13 @@ from trezor.messages.MoneroGetWatchKey import MoneroGetWatchKey
from trezor.messages.MoneroWatchKey import MoneroWatchKey from trezor.messages.MoneroWatchKey import MoneroWatchKey
from apps.common import paths from apps.common import paths
from apps.monero import CURVE, misc from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import crypto from apps.monero.xmr import crypto
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_watch_only(ctx, msg: MoneroGetWatchKey, keychain): async def get_watch_only(ctx, msg: MoneroGetWatchKey, keychain):
await paths.validate_path( await paths.validate_path(
ctx, misc.validate_full_path, keychain, msg.address_n, CURVE ctx, misc.validate_full_path, keychain, msg.address_n, CURVE

View File

@ -11,12 +11,14 @@ from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck
from trezor.messages.MoneroKeyImageSyncStepRequest import MoneroKeyImageSyncStepRequest from trezor.messages.MoneroKeyImageSyncStepRequest import MoneroKeyImageSyncStepRequest
from apps.common import paths from apps.common import paths
from apps.monero import CURVE, misc from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import crypto, key_image, monero from apps.monero.xmr import crypto, key_image, monero
from apps.monero.xmr.crypto import chacha_poly from apps.monero.xmr.crypto import chacha_poly
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def key_image_sync(ctx, msg, keychain): async def key_image_sync(ctx, msg, keychain):
state = KeyImageSync() state = KeyImageSync()

View File

@ -10,12 +10,14 @@ from trezor.messages.MoneroLiveRefreshStepAck import MoneroLiveRefreshStepAck
from trezor.messages.MoneroLiveRefreshStepRequest import MoneroLiveRefreshStepRequest from trezor.messages.MoneroLiveRefreshStepRequest import MoneroLiveRefreshStepRequest
from apps.common import paths from apps.common import paths
from apps.monero import CURVE, misc from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import crypto, key_image, monero from apps.monero.xmr import crypto, key_image, monero
from apps.monero.xmr.crypto import chacha_poly from apps.monero.xmr.crypto import chacha_poly
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def live_refresh(ctx, msg: MoneroLiveRefreshStartRequest, keychain): async def live_refresh(ctx, msg: MoneroLiveRefreshStartRequest, keychain):
state = LiveRefreshState() state = LiveRefreshState()

View File

@ -1,5 +1,4 @@
from apps.common import HARDENED from apps.common import HARDENED
from apps.monero import CURVE
if False: if False:
from typing import Tuple from typing import Tuple
@ -10,7 +9,7 @@ def get_creds(keychain, address_n=None, network_type=None):
from apps.monero.xmr import monero from apps.monero.xmr import monero
from apps.monero.xmr.credentials import AccountCreds from apps.monero.xmr.credentials import AccountCreds
node = keychain.derive(address_n, CURVE) node = keychain.derive(address_n)
key_seed = node.private_key() key_seed = node.private_key()
spend_sec, _, view_sec, _ = monero.generate_monero_keys(key_seed) spend_sec, _, view_sec, _ = monero.generate_monero_keys(key_seed)

View File

@ -3,9 +3,12 @@ import gc
from trezor import log, utils, wire from trezor import log, utils, wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common.seed import with_slip44_keychain
from apps.monero import CURVE, SLIP44_ID
from apps.monero.signing.state import State from apps.monero.signing.state import State
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, received_msg, keychain): async def sign_tx(ctx, received_msg, keychain):
state = State(ctx) state = State(ctx)
mods = utils.unimport_begin() mods = utils.unimport_begin()

View File

@ -1,12 +1,10 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "ed25519-keccak" CURVE = "ed25519-keccak"
SLIP44_ID = 43
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 43], [CURVE, HARDENED | 44, HARDENED | 1]] wire.add(MessageType.NEMGetAddress, __name__, "get_address")
wire.add(MessageType.NEMGetAddress, __name__, "get_address", ns) wire.add(MessageType.NEMSignTx, __name__, "sign_tx")
wire.add(MessageType.NEMSignTx, __name__, "sign_tx", ns)

View File

@ -2,18 +2,20 @@ from trezor.messages.NEMAddress import NEMAddress
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.common.paths import validate_path from apps.common.paths import validate_path
from apps.nem import CURVE from apps.common.seed import with_slip44_keychain
from apps.nem import CURVE, SLIP44_ID
from apps.nem.helpers import check_path, get_network_str from apps.nem.helpers import check_path, get_network_str
from apps.nem.validators import validate_network from apps.nem.validators import validate_network
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg, keychain): async def get_address(ctx, msg, keychain):
network = validate_network(msg.network) network = validate_network(msg.network)
await validate_path( await validate_path(
ctx, check_path, keychain, msg.address_n, CURVE, network=network ctx, check_path, keychain, msg.address_n, CURVE, network=network
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
address = node.nem_address(network) address = node.nem_address(network)
if msg.show_display: if msg.show_display:

View File

@ -5,11 +5,13 @@ from trezor.messages.NEMSignTx import NEMSignTx
from apps.common import seed from apps.common import seed
from apps.common.paths import validate_path from apps.common.paths import validate_path
from apps.nem import CURVE, mosaic, multisig, namespace, transfer from apps.common.seed import with_slip44_keychain
from apps.nem import CURVE, SLIP44_ID, mosaic, multisig, namespace, transfer
from apps.nem.helpers import NEM_HASH_ALG, check_path from apps.nem.helpers import NEM_HASH_ALG, check_path
from apps.nem.validators import validate from apps.nem.validators import validate
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, msg: NEMSignTx, keychain): async def sign_tx(ctx, msg: NEMSignTx, keychain):
validate(msg) validate(msg)
@ -22,7 +24,7 @@ async def sign_tx(ctx, msg: NEMSignTx, keychain):
network=msg.transaction.network, network=msg.transaction.network,
) )
node = keychain.derive(msg.transaction.address_n, CURVE) node = keychain.derive(msg.transaction.address_n)
if msg.multisig: if msg.multisig:
public_key = msg.multisig.signer public_key = msg.multisig.signer

View File

@ -1,12 +1,10 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "secp256k1" CURVE = "secp256k1"
SLIP44_ID = 144
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 144]] wire.add(MessageType.RippleGetAddress, __name__, "get_address")
wire.add(MessageType.RippleGetAddress, __name__, "get_address", ns) wire.add(MessageType.RippleSignTx, __name__, "sign_tx")
wire.add(MessageType.RippleSignTx, __name__, "sign_tx", ns)

View File

@ -3,9 +3,11 @@ from trezor.messages.RippleGetAddress import RippleGetAddress
from apps.common import paths from apps.common import paths
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.ripple import CURVE, helpers from apps.common.seed import with_slip44_keychain
from apps.ripple import CURVE, SLIP44_ID, helpers
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg: RippleGetAddress, keychain): async def get_address(ctx, msg: RippleGetAddress, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE

View File

@ -6,10 +6,12 @@ from trezor.messages.RippleSignTx import RippleSignTx
from trezor.wire import ProcessError from trezor.wire import ProcessError
from apps.common import paths from apps.common import paths
from apps.ripple import CURVE, helpers, layout from apps.common.seed import with_slip44_keychain
from apps.ripple import CURVE, SLIP44_ID, helpers, layout
from apps.ripple.serialize import serialize from apps.ripple.serialize import serialize
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, msg: RippleSignTx, keychain): async def sign_tx(ctx, msg: RippleSignTx, keychain):
validate(msg) validate(msg)

View File

@ -1,12 +1,10 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "ed25519" CURVE = "ed25519"
SLIP44_ID = 148
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 148]] wire.add(MessageType.StellarGetAddress, __name__, "get_address")
wire.add(MessageType.StellarGetAddress, __name__, "get_address", ns) wire.add(MessageType.StellarSignTx, __name__, "sign_tx")
wire.add(MessageType.StellarSignTx, __name__, "sign_tx", ns)

View File

@ -3,15 +3,17 @@ from trezor.messages.StellarGetAddress import StellarGetAddress
from apps.common import paths, seed from apps.common import paths, seed
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.stellar import CURVE, helpers from apps.common.seed import with_slip44_keychain
from apps.stellar import CURVE, SLIP44_ID, helpers
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg: StellarGetAddress, keychain): async def get_address(ctx, msg: StellarGetAddress, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pubkey = seed.remove_ed25519_prefix(node.public_key()) pubkey = seed.remove_ed25519_prefix(node.public_key())
address = helpers.address_from_public_key(pubkey) address = helpers.address_from_public_key(pubkey)

View File

@ -8,16 +8,18 @@ from trezor.messages.StellarTxOpRequest import StellarTxOpRequest
from trezor.wire import ProcessError from trezor.wire import ProcessError
from apps.common import paths, seed from apps.common import paths, seed
from apps.stellar import CURVE, consts, helpers, layout, writers from apps.common.seed import with_slip44_keychain
from apps.stellar import CURVE, SLIP44_ID, consts, helpers, layout, writers
from apps.stellar.operations import process_operation from apps.stellar.operations import process_operation
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, msg: StellarSignTx, keychain): async def sign_tx(ctx, msg: StellarSignTx, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pubkey = seed.remove_ed25519_prefix(node.public_key()) pubkey = seed.remove_ed25519_prefix(node.public_key())
if msg.num_operations == 0: if msg.num_operations == 0:

View File

@ -1,13 +1,11 @@
from trezor import wire from trezor import wire
from trezor.messages import MessageType from trezor.messages import MessageType
from apps.common import HARDENED
CURVE = "ed25519" CURVE = "ed25519"
SLIP44_ID = 1729
def boot() -> None: def boot() -> None:
ns = [[CURVE, HARDENED | 44, HARDENED | 1729]] wire.add(MessageType.TezosGetAddress, __name__, "get_address")
wire.add(MessageType.TezosGetAddress, __name__, "get_address", ns) wire.add(MessageType.TezosSignTx, __name__, "sign_tx")
wire.add(MessageType.TezosSignTx, __name__, "sign_tx", ns) wire.add(MessageType.TezosGetPublicKey, __name__, "get_public_key")
wire.add(MessageType.TezosGetPublicKey, __name__, "get_public_key", ns)

View File

@ -3,15 +3,17 @@ from trezor.messages.TezosAddress import TezosAddress
from apps.common import paths, seed from apps.common import paths, seed
from apps.common.layout import address_n_to_str, show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.tezos import CURVE, helpers from apps.common.seed import with_slip44_keychain
from apps.tezos import CURVE, SLIP44_ID, helpers
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_address(ctx, msg, keychain): async def get_address(ctx, msg, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pk = seed.remove_ed25519_prefix(node.public_key()) pk = seed.remove_ed25519_prefix(node.public_key())
pkh = hashlib.blake2b(pk, outlen=20).digest() pkh = hashlib.blake2b(pk, outlen=20).digest()

View File

@ -6,15 +6,17 @@ from trezor.utils import chunks
from apps.common import paths, seed from apps.common import paths, seed
from apps.common.confirm import require_confirm from apps.common.confirm import require_confirm
from apps.tezos import CURVE, helpers from apps.common.seed import with_slip44_keychain
from apps.tezos import CURVE, SLIP44_ID, helpers
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def get_public_key(ctx, msg, keychain): async def get_public_key(ctx, msg, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
pk = seed.remove_ed25519_prefix(node.public_key()) pk = seed.remove_ed25519_prefix(node.public_key())
pk_prefixed = helpers.base58_encode_check(pk, prefix=helpers.TEZOS_PUBLICKEY_PREFIX) pk_prefixed = helpers.base58_encode_check(pk, prefix=helpers.TEZOS_PUBLICKEY_PREFIX)

View File

@ -7,18 +7,20 @@ from trezor.messages import TezosBallotType, TezosContractType
from trezor.messages.TezosSignedTx import TezosSignedTx from trezor.messages.TezosSignedTx import TezosSignedTx
from apps.common import paths from apps.common import paths
from apps.common.seed import with_slip44_keychain
from apps.common.writers import write_bytes_unchecked, write_uint8, write_uint32_be from apps.common.writers import write_bytes_unchecked, write_uint8, write_uint32_be
from apps.tezos import CURVE, helpers, layout from apps.tezos import CURVE, SLIP44_ID, helpers, layout
PROPOSAL_LENGTH = const(32) PROPOSAL_LENGTH = const(32)
@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True)
async def sign_tx(ctx, msg, keychain): async def sign_tx(ctx, msg, keychain):
await paths.validate_path( await paths.validate_path(
ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE
) )
node = keychain.derive(msg.address_n, CURVE) node = keychain.derive(msg.address_n)
if msg.transaction is not None: if msg.transaction is not None:
# if the tranasction oprtation is used to execute code on a smart contract # if the tranasction oprtation is used to execute code on a smart contract