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

38 lines
1.2 KiB
Python
Raw Normal View History

2016-11-23 13:51:05 +00:00
from trezor import ui
2016-11-16 21:55:11 +00:00
from trezor.utils import unimport
2016-11-23 13:51:05 +00:00
2016-11-16 21:55:11 +00:00
@unimport
2016-12-08 15:18:12 +00:00
async def layout_verify_message(session_id, msg):
2016-11-16 21:55:11 +00:00
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
2016-11-23 13:51:05 +00:00
coin_name = msg.coin_name or 'Bitcoin'
2016-11-16 21:55:11 +00:00
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')