1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00
trezor-firmware/core/src/apps/common/signverify.py

32 lines
778 B
Python
Raw Normal View History

2018-07-03 14:20:26 +00:00
from ubinascii import hexlify
from trezor.crypto.hashlib import blake256, sha256
from trezor.utils import HashWriter
2018-07-03 14:20:26 +00:00
2018-11-06 14:45:02 +00:00
from apps.wallet.sign_tx.writers import write_varint
2017-06-13 17:35:14 +00:00
def message_digest(coin, message):
if coin.decred:
2018-10-30 14:48:26 +00:00
h = HashWriter(blake256())
else:
2018-10-30 14:48:26 +00:00
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):
try:
m = bytes(message).decode()
words = m.split(" ")
except UnicodeError:
m = "hex(%s)" % hexlify(message).decode()
words = [m]
return words