mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-16 08:06:05 +00:00
src/apps/common: raise on unsupported script type, change layout
This commit is contained in:
parent
323714dc61
commit
2be0a4d31a
@ -1,6 +1,7 @@
|
||||
from ubinascii import hexlify
|
||||
from micropython import const
|
||||
from trezor.crypto.hashlib import sha256
|
||||
from trezor.utils import chunks
|
||||
from trezor.utils import chunks, split_words
|
||||
from apps.common.hash_writer import HashWriter
|
||||
from apps.wallet.sign_tx.signing import write_varint
|
||||
|
||||
@ -15,12 +16,10 @@ def message_digest(coin, message):
|
||||
|
||||
|
||||
def split_message(message):
|
||||
chars_per_line = const(18)
|
||||
message = stringify_message(message)
|
||||
lines = chunks(message, chars_per_line)
|
||||
try:
|
||||
m = bytes(message).decode()
|
||||
lines = split_words(m, 18)
|
||||
except UnicodeError:
|
||||
m = hexlify(message)
|
||||
lines = chunks(m, 16)
|
||||
return lines
|
||||
|
||||
|
||||
def stringify_message(message):
|
||||
# TODO: account for invalid UTF-8 sequences
|
||||
return str(message, 'utf-8')
|
||||
|
@ -1,5 +1,8 @@
|
||||
from trezor import ui
|
||||
from trezor.wire import FailureError
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.messages.InputScriptType import SPENDADDRESS
|
||||
from trezor.messages.FailureType import ProcessError
|
||||
from trezor.messages.MessageSignature import MessageSignature
|
||||
from trezor.ui.text import Text
|
||||
from apps.common import coins, seed
|
||||
@ -11,8 +14,12 @@ async def sign_message(ctx, msg):
|
||||
message = msg.message
|
||||
address_n = msg.address_n
|
||||
coin_name = msg.coin_name or 'Bitcoin'
|
||||
script_type = msg.script_type or 0
|
||||
coin = coins.by_name(coin_name)
|
||||
|
||||
if script_type != SPENDADDRESS:
|
||||
raise FailureError(ProcessError, 'Unsupported script type')
|
||||
|
||||
await confirm_sign_message(ctx, message)
|
||||
|
||||
node = await seed.derive_node(ctx, address_n)
|
||||
|
@ -18,14 +18,30 @@ def unimport(genfunc):
|
||||
return inner
|
||||
|
||||
|
||||
def ensure(cond):
|
||||
if not cond:
|
||||
raise AssertionError()
|
||||
|
||||
|
||||
def chunks(items, size):
|
||||
for i in range(0, len(items), size):
|
||||
yield items[i:i + size]
|
||||
|
||||
|
||||
def ensure(cond):
|
||||
if not cond:
|
||||
raise AssertionError()
|
||||
def split_words(sentence, width, metric=len):
|
||||
line = ''
|
||||
for c in sentence:
|
||||
line += c
|
||||
if metric(line) >= width:
|
||||
c = line[-1]
|
||||
if c == ' ':
|
||||
yield line
|
||||
line = ''
|
||||
else:
|
||||
yield line[:-1] + '-'
|
||||
line = c
|
||||
if line != '':
|
||||
yield line
|
||||
|
||||
|
||||
def format_amount(amount, decimals):
|
||||
|
Loading…
Reference in New Issue
Block a user