From 084f1205f16baa2597893f208b7068d6a9dace45 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 17 Nov 2016 13:40:05 +0100 Subject: [PATCH] apps.wallet: cleanup sign/verify message --- src/apps/wallet/layout_sign_message.py | 10 +++------- src/apps/wallet/layout_verify_message.py | 21 +++++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/apps/wallet/layout_sign_message.py b/src/apps/wallet/layout_sign_message.py index bcd6ff7a5b..0b5ad4f756 100644 --- a/src/apps/wallet/layout_sign_message.py +++ b/src/apps/wallet/layout_sign_message.py @@ -6,8 +6,7 @@ from trezor.utils import unimport async def layout_sign_message(msg, session_id): from trezor.messages.MessageSignature import MessageSignature from trezor.crypto.curve import secp256k1 - from ..common.signtx import node_derive - from ..common.seed import get_root_node + from ..common.seed import get_node from ..common import coins from ..common.signverify import message_digest @@ -16,17 +15,14 @@ async def layout_sign_message(msg, session_id): ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) ui.display.text(10, 60, msg.message, ui.MONO, ui.WHITE, ui.BLACK) - address_n = msg.address_n - message = msg.message coin_name = getattr(msg, 'coin_name', 'Bitcoin') coin = coins.by_name(coin_name) - root = await get_root_node(session_id) - node = node_derive(root, address_n) + node = await get_node(session_id, msg.address_n) seckey = node.private_key() address = node.address(coin.address_type) - digest = message_digest(coin, message) + digest = message_digest(coin, msg.message) signature = secp256k1.sign(seckey, digest) diff --git a/src/apps/wallet/layout_verify_message.py b/src/apps/wallet/layout_verify_message.py index bfbbe2c325..df8ded3812 100644 --- a/src/apps/wallet/layout_verify_message.py +++ b/src/apps/wallet/layout_verify_message.py @@ -11,29 +11,26 @@ async def layout_verify_message(msg, session_id): from ..common import coins from ..common.signverify import message_digest - address = msg.address - message = msg.message - signature = msg.signature coin_name = getattr(msg, 'coin_name', 'Bitcoin') coin = coins.by_name(coin_name) - ui.display.clear() - ui.display.text(10, 30, 'Verifying message', - ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) - ui.display.text(10, 60, message, ui.MONO, ui.WHITE, ui.BLACK) - ui.display.text(10, 80, address, ui.MONO, ui.WHITE, ui.BLACK) - - digest = message_digest(coin, message) - pubkey = secp256k1.verify_recover(signature, digest) + digest = message_digest(coin, msg.message) + pubkey = secp256k1.verify_recover(msg.signature, digest) if not pubkey: raise ValueError('Invalid signature') - raw_address = base58.decode_check(address) + raw_address = base58.decode_check(msg.address) at, pkh = address_type.split(coin, raw_address) pkh2 = ripemd160(sha256(pubkey).digest()).digest() if pkh != pkh2: raise ValueError('Invalid signature') + ui.display.clear() + ui.display.text(10, 30, 'Verifying message', + ui.BOLD, ui.LIGHT_GREEN, ui.BLACK) + ui.display.text(10, 60, msg.message, ui.MONO, ui.WHITE, ui.BLACK) + ui.display.text(10, 80, msg.address, ui.MONO, ui.WHITE, ui.BLACK) + return Success(message='Message verified')