1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00
trezor-firmware/src/apps/common/signverify.py

33 lines
895 B
Python
Raw Normal View History

from trezor import ui
2018-02-27 15:35:21 +00:00
from trezor.crypto.hashlib import sha256
from trezor.ui.text import TEXT_MARGIN_LEFT
2018-02-27 15:35:21 +00:00
from trezor.utils import HashWriter, chunks, split_words
from ubinascii import hexlify
from apps.wallet.sign_tx.signing import write_varint
2017-06-13 17:35:14 +00:00
def message_digest(coin, message):
h = HashWriter(sha256)
write_varint(h, len(coin.signed_message_header))
h.extend(coin.signed_message_header)
write_varint(h, len(message))
h.extend(message)
ret = h.get_digest()
if coin.sign_hash_double:
ret = sha256(ret).digest()
return ret
def split_message(message):
2018-02-27 15:35:21 +00:00
def measure(s):
return ui.display.text_width(s, ui.NORMAL)
try:
m = bytes(message).decode()
2018-02-27 15:35:21 +00:00
lines = split_words(m, ui.WIDTH - 2 * TEXT_MARGIN_LEFT, metric=measure)
except UnicodeError:
m = hexlify(message)
lines = chunks(m, 16)
return lines