2018-07-03 14:20:26 +00:00
|
|
|
from ubinascii import hexlify
|
|
|
|
|
2018-10-08 12:34:51 +00:00
|
|
|
from trezor.crypto.hashlib import blake256, sha256
|
2018-08-30 13:34:34 +00:00
|
|
|
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
|
2016-11-16 22:08:41 +00:00
|
|
|
|
2017-06-13 17:35:14 +00:00
|
|
|
|
2016-11-16 22:08:41 +00:00
|
|
|
def message_digest(coin, message):
|
2018-10-08 12:34:51 +00:00
|
|
|
if coin.decred:
|
2018-10-30 14:48:26 +00:00
|
|
|
h = HashWriter(blake256())
|
2018-10-08 12:34:51 +00:00
|
|
|
else:
|
2018-10-30 14:48:26 +00:00
|
|
|
h = HashWriter(sha256())
|
2016-11-16 22:08:41 +00:00
|
|
|
write_varint(h, len(coin.signed_message_header))
|
|
|
|
h.extend(coin.signed_message_header)
|
|
|
|
write_varint(h, len(message))
|
|
|
|
h.extend(message)
|
2018-07-01 14:22:52 +00:00
|
|
|
ret = h.get_digest()
|
|
|
|
if coin.sign_hash_double:
|
|
|
|
ret = sha256(ret).digest()
|
|
|
|
return ret
|
2018-02-06 13:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def split_message(message):
|
2018-02-27 01:35:20 +00:00
|
|
|
try:
|
|
|
|
m = bytes(message).decode()
|
2018-08-30 13:34:34 +00:00
|
|
|
words = m.split(" ")
|
2018-02-27 01:35:20 +00:00
|
|
|
except UnicodeError:
|
2018-09-19 17:19:52 +00:00
|
|
|
m = "hex(%s)" % hexlify(message).decode()
|
2018-08-30 13:34:34 +00:00
|
|
|
words = [m]
|
|
|
|
return words
|