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:
parent
5be6a82682
commit
084f1205f1
@ -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)
|
||||
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user