From b594248ac2978d250d2fe4143cdd30979f912002 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 20 Apr 2020 11:51:46 +0200 Subject: [PATCH] core: use new keychain decorators where appropriate --- core/src/apps/binance/__init__.py | 10 ++++------ core/src/apps/binance/get_address.py | 6 ++++-- core/src/apps/binance/get_public_key.py | 6 ++++-- core/src/apps/binance/sign_tx.py | 6 ++++-- core/src/apps/eos/__init__.py | 9 +++------ core/src/apps/eos/get_public_key.py | 7 ++++--- core/src/apps/eos/sign_tx.py | 11 ++++------- core/src/apps/lisk/__init__.py | 12 +++++------- core/src/apps/lisk/get_address.py | 6 ++++-- core/src/apps/lisk/get_public_key.py | 6 ++++-- core/src/apps/lisk/sign_message.py | 6 ++++-- core/src/apps/lisk/sign_tx.py | 6 ++++-- core/src/apps/monero/__init__.py | 18 +++++++----------- core/src/apps/monero/get_address.py | 4 +++- core/src/apps/monero/get_tx_keys.py | 4 +++- core/src/apps/monero/get_watch_only.py | 4 +++- core/src/apps/monero/key_image_sync.py | 4 +++- core/src/apps/monero/live_refresh.py | 4 +++- core/src/apps/monero/misc.py | 3 +-- core/src/apps/monero/sign_tx.py | 3 +++ core/src/apps/nem/__init__.py | 8 +++----- core/src/apps/nem/get_address.py | 6 ++++-- core/src/apps/nem/sign_tx.py | 6 ++++-- core/src/apps/ripple/__init__.py | 8 +++----- core/src/apps/ripple/get_address.py | 4 +++- core/src/apps/ripple/sign_tx.py | 4 +++- core/src/apps/stellar/__init__.py | 8 +++----- core/src/apps/stellar/get_address.py | 6 ++++-- core/src/apps/stellar/sign_tx.py | 6 ++++-- core/src/apps/tezos/__init__.py | 10 ++++------ core/src/apps/tezos/get_address.py | 6 ++++-- core/src/apps/tezos/get_public_key.py | 6 ++++-- core/src/apps/tezos/sign_tx.py | 6 ++++-- 33 files changed, 121 insertions(+), 98 deletions(-) diff --git a/core/src/apps/binance/__init__.py b/core/src/apps/binance/__init__.py index 8f8a93962..86e8814c3 100644 --- a/core/src/apps/binance/__init__.py +++ b/core/src/apps/binance/__init__.py @@ -1,13 +1,11 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "secp256k1" +SLIP44_ID = 714 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 714]] - wire.add(MessageType.BinanceGetAddress, __name__, "get_address", ns) - wire.add(MessageType.BinanceGetPublicKey, __name__, "get_public_key", ns) - wire.add(MessageType.BinanceSignTx, __name__, "sign_tx", ns) + wire.add(MessageType.BinanceGetAddress, __name__, "get_address") + wire.add(MessageType.BinanceGetPublicKey, __name__, "get_public_key") + wire.add(MessageType.BinanceSignTx, __name__, "sign_tx") diff --git a/core/src/apps/binance/get_address.py b/core/src/apps/binance/get_address.py index 9278f1bb2..8069450ef 100644 --- a/core/src/apps/binance/get_address.py +++ b/core/src/apps/binance/get_address.py @@ -1,12 +1,14 @@ from trezor.messages.BinanceAddress import BinanceAddress 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.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" await paths.validate_path( diff --git a/core/src/apps/binance/get_public_key.py b/core/src/apps/binance/get_public_key.py index bb201506b..fe203fb61 100644 --- a/core/src/apps/binance/get_public_key.py +++ b/core/src/apps/binance/get_public_key.py @@ -1,11 +1,13 @@ from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey 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.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( ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE ) diff --git a/core/src/apps/binance/sign_tx.py b/core/src/apps/binance/sign_tx.py index 39a132d2d..997e5cba8 100644 --- a/core/src/apps/binance/sign_tx.py +++ b/core/src/apps/binance/sign_tx.py @@ -8,11 +8,13 @@ from trezor.messages.BinanceSignedTx import BinanceSignedTx from trezor.messages.BinanceTransferMsg import BinanceTransferMsg 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.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 if envelope.msg_count > 1: raise wire.DataError("Multiple messages not supported.") diff --git a/core/src/apps/eos/__init__.py b/core/src/apps/eos/__init__.py index 4c53f4ec5..74183970a 100644 --- a/core/src/apps/eos/__init__.py +++ b/core/src/apps/eos/__init__.py @@ -1,13 +1,10 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "secp256k1" +SLIP44_ID = 194 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 194]] - - wire.add(MessageType.EosGetPublicKey, __name__, "get_public_key", ns) - wire.add(MessageType.EosSignTx, __name__, "sign_tx", ns) + wire.add(MessageType.EosGetPublicKey, __name__, "get_public_key") + wire.add(MessageType.EosSignTx, __name__, "sign_tx") diff --git a/core/src/apps/eos/get_public_key.py b/core/src/apps/eos/get_public_key.py index 47b0496b5..ea2461f83 100644 --- a/core/src/apps/eos/get_public_key.py +++ b/core/src/apps/eos/get_public_key.py @@ -4,14 +4,14 @@ from trezor.messages.EosGetPublicKey import EosGetPublicKey from trezor.messages.EosPublicKey import EosPublicKey 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.layout import require_get_public_key if False: from typing import Tuple from trezor.crypto import bip32 - from apps.common import seed 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 +@with_slip44_keychain(SLIP44_ID, CURVE) async def get_public_key( - ctx: wire.Context, msg: EosGetPublicKey, keychain: seed.Keychain + ctx: wire.Context, msg: EosGetPublicKey, keychain: Keychain ) -> EosPublicKey: await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) diff --git a/core/src/apps/eos/sign_tx.py b/core/src/apps/eos/sign_tx.py index e47bc23b5..55b24dbf1 100644 --- a/core/src/apps/eos/sign_tx.py +++ b/core/src/apps/eos/sign_tx.py @@ -8,18 +8,15 @@ from trezor.messages.EosTxActionRequest import EosTxActionRequest from trezor.utils import HashWriter 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.helpers import base58_encode, validate_full_path from apps.eos.layout import require_sign_tx -if False: - from apps.common import seed - -async def sign_tx( - ctx: wire.Context, msg: EosSignTx, keychain: seed.Keychain -) -> EosSignedTx: +@with_slip44_keychain(SLIP44_ID, CURVE) +async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosSignedTx: if msg.chain_id is None: raise wire.DataError("No chain id") if msg.header is None: diff --git a/core/src/apps/lisk/__init__.py b/core/src/apps/lisk/__init__.py index c525a5526..bb7ea974c 100644 --- a/core/src/apps/lisk/__init__.py +++ b/core/src/apps/lisk/__init__.py @@ -1,15 +1,13 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "ed25519" +SLIP44_ID = 134 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 134]] - wire.add(MessageType.LiskGetPublicKey, __name__, "get_public_key", ns) - wire.add(MessageType.LiskGetAddress, __name__, "get_address", ns) - wire.add(MessageType.LiskSignTx, __name__, "sign_tx", ns) - wire.add(MessageType.LiskSignMessage, __name__, "sign_message", ns) + wire.add(MessageType.LiskGetPublicKey, __name__, "get_public_key") + wire.add(MessageType.LiskGetAddress, __name__, "get_address") + wire.add(MessageType.LiskSignTx, __name__, "sign_tx") + wire.add(MessageType.LiskSignMessage, __name__, "sign_message") wire.add(MessageType.LiskVerifyMessage, __name__, "verify_message") diff --git a/core/src/apps/lisk/get_address.py b/core/src/apps/lisk/get_address.py index 94b06820f..5698013b3 100644 --- a/core/src/apps/lisk/get_address.py +++ b/core/src/apps/lisk/get_address.py @@ -4,13 +4,15 @@ from .helpers import get_address_from_public_key, validate_full_path from apps.common import paths 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): 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 = pubkey[1:] # skip ed25519 pubkey marker address = get_address_from_public_key(pubkey) diff --git a/core/src/apps/lisk/get_public_key.py b/core/src/apps/lisk/get_public_key.py index ad7a0864e..7833c58f8 100644 --- a/core/src/apps/lisk/get_public_key.py +++ b/core/src/apps/lisk/get_public_key.py @@ -1,14 +1,16 @@ from trezor.messages.LiskPublicKey import LiskPublicKey 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def get_public_key(ctx, msg, keychain): 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 = pubkey[1:] # skip ed25519 pubkey marker diff --git a/core/src/apps/lisk/sign_message.py b/core/src/apps/lisk/sign_message.py index 0293a1329..7d2abac03 100644 --- a/core/src/apps/lisk/sign_message.py +++ b/core/src/apps/lisk/sign_message.py @@ -4,8 +4,9 @@ from trezor.messages.LiskMessageSignature import LiskMessageSignature from trezor.utils import HashWriter from apps.common import paths +from apps.common.seed import with_slip44_keychain 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.wallet.sign_tx.writers import write_varint @@ -20,11 +21,12 @@ def message_digest(message): return sha256(h.get_digest()).digest() +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_message(ctx, msg, keychain): await paths.validate_path(ctx, validate_full_path, keychain, msg.address_n, CURVE) 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() pubkey = node.public_key() pubkey = pubkey[1:] # skip ed25519 pubkey marker diff --git a/core/src/apps/lisk/sign_tx.py b/core/src/apps/lisk/sign_tx.py index 05e729276..6fe7bf69e 100644 --- a/core/src/apps/lisk/sign_tx.py +++ b/core/src/apps/lisk/sign_tx.py @@ -8,10 +8,12 @@ from trezor.messages.LiskSignedTx import LiskSignedTx from trezor.utils import HashWriter 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, msg, keychain): 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): - node = keychain.derive(msg.address_n, CURVE) + node = keychain.derive(msg.address_n) seckey = node.private_key() pubkey = node.public_key() diff --git a/core/src/apps/monero/__init__.py b/core/src/apps/monero/__init__.py index 1eb8f0a18..c4f8e87ac 100644 --- a/core/src/apps/monero/__init__.py +++ b/core/src/apps/monero/__init__.py @@ -1,21 +1,17 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "ed25519" +SLIP44_ID = 128 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 128]] - wire.add(MessageType.MoneroGetAddress, __name__, "get_address", ns) - wire.add(MessageType.MoneroGetWatchKey, __name__, "get_watch_only", ns) - wire.add(MessageType.MoneroTransactionInitRequest, __name__, "sign_tx", ns) - wire.add( - MessageType.MoneroKeyImageExportInitRequest, __name__, "key_image_sync", ns - ) - wire.add(MessageType.MoneroGetTxKeyRequest, __name__, "get_tx_keys", ns) - wire.add(MessageType.MoneroLiveRefreshStartRequest, __name__, "live_refresh", ns) + wire.add(MessageType.MoneroGetAddress, __name__, "get_address") + wire.add(MessageType.MoneroGetWatchKey, __name__, "get_watch_only") + wire.add(MessageType.MoneroTransactionInitRequest, __name__, "sign_tx") + wire.add(MessageType.MoneroKeyImageExportInitRequest, __name__, "key_image_sync") + wire.add(MessageType.MoneroGetTxKeyRequest, __name__, "get_tx_keys") + wire.add(MessageType.MoneroLiveRefreshStartRequest, __name__, "live_refresh") if __debug__ and hasattr(MessageType, "DebugMoneroDiagRequest"): wire.add(MessageType.DebugMoneroDiagRequest, __name__, "diag") diff --git a/core/src/apps/monero/get_address.py b/core/src/apps/monero/get_address.py index e5cd4bf52..64787bb23 100644 --- a/core/src/apps/monero/get_address.py +++ b/core/src/apps/monero/get_address.py @@ -2,12 +2,14 @@ from trezor.messages.MoneroAddress import MoneroAddress from apps.common import paths 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.xmr import addresses, crypto, monero from apps.monero.xmr.networks import net_version +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def get_address(ctx, msg, keychain): await paths.validate_path( ctx, misc.validate_full_path, keychain, msg.address_n, CURVE diff --git a/core/src/apps/monero/get_tx_keys.py b/core/src/apps/monero/get_tx_keys.py index 7d690495b..98014e4e5 100644 --- a/core/src/apps/monero/get_tx_keys.py +++ b/core/src/apps/monero/get_tx_keys.py @@ -20,7 +20,8 @@ from trezor.messages.MoneroGetTxKeyAck import MoneroGetTxKeyAck from trezor.messages.MoneroGetTxKeyRequest import MoneroGetTxKeyRequest 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.xmr import crypto 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def get_tx_keys(ctx, msg: MoneroGetTxKeyRequest, keychain): await paths.validate_path( ctx, misc.validate_full_path, keychain, msg.address_n, CURVE diff --git a/core/src/apps/monero/get_watch_only.py b/core/src/apps/monero/get_watch_only.py index 5739fca24..b7264cace 100644 --- a/core/src/apps/monero/get_watch_only.py +++ b/core/src/apps/monero/get_watch_only.py @@ -2,11 +2,13 @@ from trezor.messages.MoneroGetWatchKey import MoneroGetWatchKey from trezor.messages.MoneroWatchKey import MoneroWatchKey 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.xmr import crypto +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def get_watch_only(ctx, msg: MoneroGetWatchKey, keychain): await paths.validate_path( ctx, misc.validate_full_path, keychain, msg.address_n, CURVE diff --git a/core/src/apps/monero/key_image_sync.py b/core/src/apps/monero/key_image_sync.py index 59031f398..93e2338d9 100644 --- a/core/src/apps/monero/key_image_sync.py +++ b/core/src/apps/monero/key_image_sync.py @@ -11,12 +11,14 @@ from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck from trezor.messages.MoneroKeyImageSyncStepRequest import MoneroKeyImageSyncStepRequest 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.xmr import crypto, key_image, monero 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): state = KeyImageSync() diff --git a/core/src/apps/monero/live_refresh.py b/core/src/apps/monero/live_refresh.py index 5e8f65c39..b13b1acde 100644 --- a/core/src/apps/monero/live_refresh.py +++ b/core/src/apps/monero/live_refresh.py @@ -10,12 +10,14 @@ from trezor.messages.MoneroLiveRefreshStepAck import MoneroLiveRefreshStepAck from trezor.messages.MoneroLiveRefreshStepRequest import MoneroLiveRefreshStepRequest 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.xmr import crypto, key_image, monero 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): state = LiveRefreshState() diff --git a/core/src/apps/monero/misc.py b/core/src/apps/monero/misc.py index fedec66e2..880af3e25 100644 --- a/core/src/apps/monero/misc.py +++ b/core/src/apps/monero/misc.py @@ -1,5 +1,4 @@ from apps.common import HARDENED -from apps.monero import CURVE if False: 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.credentials import AccountCreds - node = keychain.derive(address_n, CURVE) + node = keychain.derive(address_n) key_seed = node.private_key() spend_sec, _, view_sec, _ = monero.generate_monero_keys(key_seed) diff --git a/core/src/apps/monero/sign_tx.py b/core/src/apps/monero/sign_tx.py index 2e4e30f72..8f75302a8 100644 --- a/core/src/apps/monero/sign_tx.py +++ b/core/src/apps/monero/sign_tx.py @@ -3,9 +3,12 @@ import gc from trezor import log, utils, wire 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, received_msg, keychain): state = State(ctx) mods = utils.unimport_begin() diff --git a/core/src/apps/nem/__init__.py b/core/src/apps/nem/__init__.py index 2253845bc..679a698c7 100644 --- a/core/src/apps/nem/__init__.py +++ b/core/src/apps/nem/__init__.py @@ -1,12 +1,10 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "ed25519-keccak" +SLIP44_ID = 43 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 43], [CURVE, HARDENED | 44, HARDENED | 1]] - wire.add(MessageType.NEMGetAddress, __name__, "get_address", ns) - wire.add(MessageType.NEMSignTx, __name__, "sign_tx", ns) + wire.add(MessageType.NEMGetAddress, __name__, "get_address") + wire.add(MessageType.NEMSignTx, __name__, "sign_tx") diff --git a/core/src/apps/nem/get_address.py b/core/src/apps/nem/get_address.py index 4bdb1c4f3..9f988cf0c 100644 --- a/core/src/apps/nem/get_address.py +++ b/core/src/apps/nem/get_address.py @@ -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.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.validators import validate_network +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def get_address(ctx, msg, keychain): network = validate_network(msg.network) await validate_path( 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) if msg.show_display: diff --git a/core/src/apps/nem/sign_tx.py b/core/src/apps/nem/sign_tx.py index 83fa129c6..340b88ba6 100644 --- a/core/src/apps/nem/sign_tx.py +++ b/core/src/apps/nem/sign_tx.py @@ -5,11 +5,13 @@ from trezor.messages.NEMSignTx import NEMSignTx from apps.common import seed 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.validators import validate +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, msg: NEMSignTx, keychain): validate(msg) @@ -22,7 +24,7 @@ async def sign_tx(ctx, msg: NEMSignTx, keychain): network=msg.transaction.network, ) - node = keychain.derive(msg.transaction.address_n, CURVE) + node = keychain.derive(msg.transaction.address_n) if msg.multisig: public_key = msg.multisig.signer diff --git a/core/src/apps/ripple/__init__.py b/core/src/apps/ripple/__init__.py index f92768db2..9b2c244d1 100644 --- a/core/src/apps/ripple/__init__.py +++ b/core/src/apps/ripple/__init__.py @@ -1,12 +1,10 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "secp256k1" +SLIP44_ID = 144 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 144]] - wire.add(MessageType.RippleGetAddress, __name__, "get_address", ns) - wire.add(MessageType.RippleSignTx, __name__, "sign_tx", ns) + wire.add(MessageType.RippleGetAddress, __name__, "get_address") + wire.add(MessageType.RippleSignTx, __name__, "sign_tx") diff --git a/core/src/apps/ripple/get_address.py b/core/src/apps/ripple/get_address.py index cad770c4e..280fba457 100644 --- a/core/src/apps/ripple/get_address.py +++ b/core/src/apps/ripple/get_address.py @@ -3,9 +3,11 @@ from trezor.messages.RippleGetAddress import RippleGetAddress from apps.common import paths 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): await paths.validate_path( ctx, helpers.validate_full_path, keychain, msg.address_n, CURVE diff --git a/core/src/apps/ripple/sign_tx.py b/core/src/apps/ripple/sign_tx.py index 8a420b22e..1c58b69ff 100644 --- a/core/src/apps/ripple/sign_tx.py +++ b/core/src/apps/ripple/sign_tx.py @@ -6,10 +6,12 @@ from trezor.messages.RippleSignTx import RippleSignTx from trezor.wire import ProcessError 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, msg: RippleSignTx, keychain): validate(msg) diff --git a/core/src/apps/stellar/__init__.py b/core/src/apps/stellar/__init__.py index fe40b24a8..cd6edf2c4 100644 --- a/core/src/apps/stellar/__init__.py +++ b/core/src/apps/stellar/__init__.py @@ -1,12 +1,10 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "ed25519" +SLIP44_ID = 148 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 148]] - wire.add(MessageType.StellarGetAddress, __name__, "get_address", ns) - wire.add(MessageType.StellarSignTx, __name__, "sign_tx", ns) + wire.add(MessageType.StellarGetAddress, __name__, "get_address") + wire.add(MessageType.StellarSignTx, __name__, "sign_tx") diff --git a/core/src/apps/stellar/get_address.py b/core/src/apps/stellar/get_address.py index f91ac941f..cf834f2c0 100644 --- a/core/src/apps/stellar/get_address.py +++ b/core/src/apps/stellar/get_address.py @@ -3,15 +3,17 @@ from trezor.messages.StellarGetAddress import StellarGetAddress from apps.common import paths, seed 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): await paths.validate_path( 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()) address = helpers.address_from_public_key(pubkey) diff --git a/core/src/apps/stellar/sign_tx.py b/core/src/apps/stellar/sign_tx.py index 13e3ad121..c6637438e 100644 --- a/core/src/apps/stellar/sign_tx.py +++ b/core/src/apps/stellar/sign_tx.py @@ -8,16 +8,18 @@ from trezor.messages.StellarTxOpRequest import StellarTxOpRequest from trezor.wire import ProcessError 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 +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, msg: StellarSignTx, keychain): await paths.validate_path( 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()) if msg.num_operations == 0: diff --git a/core/src/apps/tezos/__init__.py b/core/src/apps/tezos/__init__.py index d0068be04..e57a24b1b 100644 --- a/core/src/apps/tezos/__init__.py +++ b/core/src/apps/tezos/__init__.py @@ -1,13 +1,11 @@ from trezor import wire from trezor.messages import MessageType -from apps.common import HARDENED - CURVE = "ed25519" +SLIP44_ID = 1729 def boot() -> None: - ns = [[CURVE, HARDENED | 44, HARDENED | 1729]] - wire.add(MessageType.TezosGetAddress, __name__, "get_address", ns) - wire.add(MessageType.TezosSignTx, __name__, "sign_tx", ns) - wire.add(MessageType.TezosGetPublicKey, __name__, "get_public_key", ns) + wire.add(MessageType.TezosGetAddress, __name__, "get_address") + wire.add(MessageType.TezosSignTx, __name__, "sign_tx") + wire.add(MessageType.TezosGetPublicKey, __name__, "get_public_key") diff --git a/core/src/apps/tezos/get_address.py b/core/src/apps/tezos/get_address.py index 0f1e8bd80..f08dbe6da 100644 --- a/core/src/apps/tezos/get_address.py +++ b/core/src/apps/tezos/get_address.py @@ -3,15 +3,17 @@ from trezor.messages.TezosAddress import TezosAddress from apps.common import paths, seed 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): await paths.validate_path( 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()) pkh = hashlib.blake2b(pk, outlen=20).digest() diff --git a/core/src/apps/tezos/get_public_key.py b/core/src/apps/tezos/get_public_key.py index d8e77927e..bfb3ad181 100644 --- a/core/src/apps/tezos/get_public_key.py +++ b/core/src/apps/tezos/get_public_key.py @@ -6,15 +6,17 @@ from trezor.utils import chunks from apps.common import paths, seed 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): await paths.validate_path( 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_prefixed = helpers.base58_encode_check(pk, prefix=helpers.TEZOS_PUBLICKEY_PREFIX) diff --git a/core/src/apps/tezos/sign_tx.py b/core/src/apps/tezos/sign_tx.py index 3fcb06ce4..65aa634ea 100644 --- a/core/src/apps/tezos/sign_tx.py +++ b/core/src/apps/tezos/sign_tx.py @@ -7,18 +7,20 @@ from trezor.messages import TezosBallotType, TezosContractType from trezor.messages.TezosSignedTx import TezosSignedTx 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.tezos import CURVE, helpers, layout +from apps.tezos import CURVE, SLIP44_ID, helpers, layout PROPOSAL_LENGTH = const(32) +@with_slip44_keychain(SLIP44_ID, CURVE, allow_testnet=True) async def sign_tx(ctx, msg, keychain): await paths.validate_path( 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 the tranasction oprtation is used to execute code on a smart contract