1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-16 10:20:57 +00:00
trezor-firmware/src/apps/wallet/layout_verify_message.py

37 lines
1.2 KiB
Python
Raw Normal View History

2016-11-16 21:55:11 +00:00
from trezor import wire, ui
from trezor.utils import unimport
@unimport
async def layout_verify_message(msg, session_id):
from trezor.messages.Success import Success
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import ripemd160, sha256
from trezor.crypto import base58
from ..common import address_type
from ..common import coins
from ..common.signverify import message_digest
2016-11-16 21:55:11 +00:00
coin_name = getattr(msg, 'coin_name', 'Bitcoin')
coin = coins.by_name(coin_name)
digest = message_digest(coin, msg.message)
pubkey = secp256k1.verify_recover(msg.signature, digest)
2016-11-16 21:55:11 +00:00
if not pubkey:
raise ValueError('Invalid signature')
raw_address = base58.decode_check(msg.address)
2016-11-16 21:55:11 +00:00
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)
2016-11-16 21:55:11 +00:00
return Success(message='Message verified')