mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-17 21:48:47 +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 micropython import const
|
||||||
from trezor.crypto.hashlib import sha256
|
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.common.hash_writer import HashWriter
|
||||||
from apps.wallet.sign_tx.signing import write_varint
|
from apps.wallet.sign_tx.signing import write_varint
|
||||||
|
|
||||||
@ -15,12 +16,10 @@ def message_digest(coin, message):
|
|||||||
|
|
||||||
|
|
||||||
def split_message(message):
|
def split_message(message):
|
||||||
chars_per_line = const(18)
|
try:
|
||||||
message = stringify_message(message)
|
m = bytes(message).decode()
|
||||||
lines = chunks(message, chars_per_line)
|
lines = split_words(m, 18)
|
||||||
|
except UnicodeError:
|
||||||
|
m = hexlify(message)
|
||||||
|
lines = chunks(m, 16)
|
||||||
return lines
|
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 import ui
|
||||||
|
from trezor.wire import FailureError
|
||||||
from trezor.crypto.curve import secp256k1
|
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.messages.MessageSignature import MessageSignature
|
||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
from apps.common import coins, seed
|
from apps.common import coins, seed
|
||||||
@ -11,8 +14,12 @@ async def sign_message(ctx, msg):
|
|||||||
message = msg.message
|
message = msg.message
|
||||||
address_n = msg.address_n
|
address_n = msg.address_n
|
||||||
coin_name = msg.coin_name or 'Bitcoin'
|
coin_name = msg.coin_name or 'Bitcoin'
|
||||||
|
script_type = msg.script_type or 0
|
||||||
coin = coins.by_name(coin_name)
|
coin = coins.by_name(coin_name)
|
||||||
|
|
||||||
|
if script_type != SPENDADDRESS:
|
||||||
|
raise FailureError(ProcessError, 'Unsupported script type')
|
||||||
|
|
||||||
await confirm_sign_message(ctx, message)
|
await confirm_sign_message(ctx, message)
|
||||||
|
|
||||||
node = await seed.derive_node(ctx, address_n)
|
node = await seed.derive_node(ctx, address_n)
|
||||||
|
@ -18,14 +18,30 @@ def unimport(genfunc):
|
|||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
|
def ensure(cond):
|
||||||
|
if not cond:
|
||||||
|
raise AssertionError()
|
||||||
|
|
||||||
|
|
||||||
def chunks(items, size):
|
def chunks(items, size):
|
||||||
for i in range(0, len(items), size):
|
for i in range(0, len(items), size):
|
||||||
yield items[i:i + size]
|
yield items[i:i + size]
|
||||||
|
|
||||||
|
|
||||||
def ensure(cond):
|
def split_words(sentence, width, metric=len):
|
||||||
if not cond:
|
line = ''
|
||||||
raise AssertionError()
|
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):
|
def format_amount(amount, decimals):
|
||||||
|
Loading…
Reference in New Issue
Block a user