1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

apps.wallet: cleanup sign/verify message

This commit is contained in:
Pavol Rusnak 2016-11-17 13:40:05 +01:00
parent 5be6a82682
commit 084f1205f1
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 12 additions and 19 deletions

View File

@ -6,8 +6,7 @@ from trezor.utils import unimport
async def layout_sign_message(msg, session_id): async def layout_sign_message(msg, session_id):
from trezor.messages.MessageSignature import MessageSignature from trezor.messages.MessageSignature import MessageSignature
from trezor.crypto.curve import secp256k1 from trezor.crypto.curve import secp256k1
from ..common.signtx import node_derive from ..common.seed import get_node
from ..common.seed import get_root_node
from ..common import coins from ..common import coins
from ..common.signverify import message_digest 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.BOLD, ui.LIGHT_GREEN, ui.BLACK)
ui.display.text(10, 60, msg.message, ui.MONO, ui.WHITE, 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_name = getattr(msg, 'coin_name', 'Bitcoin')
coin = coins.by_name(coin_name) coin = coins.by_name(coin_name)
root = await get_root_node(session_id) node = await get_node(session_id, msg.address_n)
node = node_derive(root, address_n)
seckey = node.private_key() seckey = node.private_key()
address = node.address(coin.address_type) address = node.address(coin.address_type)
digest = message_digest(coin, message) digest = message_digest(coin, msg.message)
signature = secp256k1.sign(seckey, digest) signature = secp256k1.sign(seckey, digest)

View File

@ -11,29 +11,26 @@ async def layout_verify_message(msg, session_id):
from ..common import coins from ..common import coins
from ..common.signverify import message_digest from ..common.signverify import message_digest
address = msg.address
message = msg.message
signature = msg.signature
coin_name = getattr(msg, 'coin_name', 'Bitcoin') coin_name = getattr(msg, 'coin_name', 'Bitcoin')
coin = coins.by_name(coin_name) coin = coins.by_name(coin_name)
ui.display.clear() digest = message_digest(coin, msg.message)
ui.display.text(10, 30, 'Verifying message', pubkey = secp256k1.verify_recover(msg.signature, digest)
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)
if not pubkey: if not pubkey:
raise ValueError('Invalid signature') 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) at, pkh = address_type.split(coin, raw_address)
pkh2 = ripemd160(sha256(pubkey).digest()).digest() pkh2 = ripemd160(sha256(pubkey).digest()).digest()
if pkh != pkh2: if pkh != pkh2:
raise ValueError('Invalid signature') 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') return Success(message='Message verified')