1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 05:03:07 +00:00
trezor-firmware/src/apps/wallet/sign_message.py

33 lines
1.0 KiB
Python
Raw Normal View History

2016-11-23 13:51:05 +00:00
from trezor import ui
from trezor.crypto.curve import secp256k1
from trezor.messages.MessageSignature import MessageSignature
from trezor.ui.text import Text
from apps.common import coins, seed
from apps.common.confirm import require_confirm
from apps.common.signverify import message_digest, split_message
2016-06-09 15:34:43 +00:00
async def sign_message(ctx, msg):
message = msg.message
address_n = msg.address_n
2016-11-23 13:51:05 +00:00
coin_name = msg.coin_name or 'Bitcoin'
2016-11-16 20:28:27 +00:00
coin = coins.by_name(coin_name)
2016-09-26 11:07:53 +00:00
await confirm_sign_message(ctx, message)
2016-12-12 14:19:51 +00:00
node = await seed.get_root(ctx)
node.derive_path(address_n)
2016-11-16 20:28:27 +00:00
seckey = node.private_key()
address = node.address(coin.address_type)
digest = message_digest(coin, message)
2016-11-16 20:28:27 +00:00
signature = secp256k1.sign(seckey, digest)
return MessageSignature(address=address, signature=signature)
async def confirm_sign_message(ctx, message):
message = split_message(message)
content = Text('Sign message', ui.ICON_CONFIRM, ui.MONO, *message)
await require_confirm(ctx, content)