mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 22:40:59 +00:00
src/apps: use require_confirm where possible, introduce require_hold_to_confirm
This commit is contained in:
parent
4f98f02ff9
commit
1269a0239d
@ -44,3 +44,9 @@ async def require_confirm(*args, **kwargs):
|
||||
confirmed = await confirm(*args, **kwargs)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
|
||||
|
||||
async def require_hold_to_confirm(*args, **kwargs):
|
||||
confirmed = await hold_to_confirm(*args, **kwargs)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
|
@ -8,7 +8,7 @@ from . import networks
|
||||
from .get_address import _ethereum_address_hex
|
||||
|
||||
|
||||
async def confirm_tx(ctx, to, value, chain_id, token=None):
|
||||
async def require_confirm_tx(ctx, to, value, chain_id, token=None):
|
||||
if to:
|
||||
str_to = _ethereum_address_hex(to)
|
||||
else:
|
||||
@ -18,10 +18,10 @@ async def confirm_tx(ctx, to, value, chain_id, token=None):
|
||||
ui.NORMAL, 'to',
|
||||
ui.MONO, *split_address(str_to),
|
||||
icon_color=ui.GREEN)
|
||||
return await confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
await require_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
|
||||
|
||||
async def confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None):
|
||||
async def require_confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None):
|
||||
content = Text('Confirm transaction', ui.ICON_SEND,
|
||||
ui.BOLD, format_ethereum_amount(spending, token, chain_id),
|
||||
ui.NORMAL, 'Gas:',
|
||||
@ -29,14 +29,14 @@ async def confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None)
|
||||
ui.NORMAL, 'Limit:',
|
||||
ui.BOLD, format_ethereum_amount(gas_limit, token, chain_id),
|
||||
icon_color=ui.GREEN)
|
||||
return await hold_to_confirm(ctx, content, ButtonRequestType.SignTx)
|
||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx)
|
||||
|
||||
|
||||
def split_data(data):
|
||||
return chunks(data, 18)
|
||||
|
||||
|
||||
async def confirm_data(ctx, data, data_total):
|
||||
async def require_confirm_data(ctx, data, data_total):
|
||||
str_data = hexlify(data[:36]).decode()
|
||||
if data_total > 36:
|
||||
str_data = str_data[:-2] + '..'
|
||||
@ -44,7 +44,7 @@ async def confirm_data(ctx, data, data_total):
|
||||
ui.BOLD, 'Size: %d bytes' % data_total,
|
||||
ui.MONO, *split_data(str_data),
|
||||
icon_color=ui.GREEN)
|
||||
return await confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
await require_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
|
||||
|
||||
def split_address(address):
|
||||
|
@ -3,8 +3,8 @@ from trezor.messages.EthereumTxRequest import EthereumTxRequest
|
||||
from trezor.messages import FailureType
|
||||
from trezor.utils import HashWriter
|
||||
from trezor.crypto import rlp
|
||||
from trezor import wire
|
||||
from apps.ethereum import tokens, layout
|
||||
from apps.ethereum import tokens
|
||||
from apps.ethereum.layout import require_confirm_tx, require_confirm_data, require_confirm_fee
|
||||
|
||||
# maximum supported chain id
|
||||
MAX_CHAIN_ID = 2147483630
|
||||
@ -28,22 +28,14 @@ async def ethereum_sign_tx(ctx, msg):
|
||||
token = tokens.token_by_chain_address(msg.chain_id, msg.to)
|
||||
|
||||
if token is None:
|
||||
confirmed = await layout.confirm_tx(ctx, msg.to, msg.value, msg.chain_id)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
await require_confirm_tx(ctx, msg.to, msg.value, msg.chain_id)
|
||||
else:
|
||||
confirmed = await layout.confirm_tx(ctx, msg.data_initial_chunk[16:36], msg.data_initial_chunk[36:68], msg.chain_id, token)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
await require_confirm_tx(ctx, msg.data_initial_chunk[16:36], msg.data_initial_chunk[36:68], msg.chain_id, token)
|
||||
|
||||
if token is None and msg.data_length > 0:
|
||||
confirmed = await layout.confirm_data(ctx, msg.data_initial_chunk, data_total)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
await require_confirm_data(ctx, msg.data_initial_chunk, data_total)
|
||||
|
||||
confirmed = await layout.confirm_fee(ctx, msg.value, msg.gas_price, msg.gas_limit, msg.chain_id, token)
|
||||
if not confirmed:
|
||||
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
|
||||
await require_confirm_fee(ctx, msg.value, msg.gas_price, msg.gas_limit, msg.chain_id, token)
|
||||
|
||||
data = bytearray()
|
||||
data += msg.data_initial_chunk
|
||||
|
@ -14,7 +14,7 @@ from apps.common.request_pin import request_pin, PinCancelled
|
||||
async def change_pin(ctx, msg):
|
||||
|
||||
# confirm that user wants to change the pin
|
||||
await confirm_change_pin(ctx, msg)
|
||||
await require_confirm_change_pin(ctx, msg)
|
||||
|
||||
# get current pin, return failure if invalid
|
||||
if config.has_pin():
|
||||
@ -40,7 +40,7 @@ async def change_pin(ctx, msg):
|
||||
return Failure(code=FailureType.PinInvalid, message='PIN invalid')
|
||||
|
||||
|
||||
def confirm_change_pin(ctx, msg):
|
||||
def require_confirm_change_pin(ctx, msg):
|
||||
has_pin = config.has_pin()
|
||||
|
||||
if msg.remove and has_pin: # removing pin
|
||||
|
@ -3,12 +3,12 @@ from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.ui.text import Text
|
||||
from apps.common import storage
|
||||
from apps.common.confirm import hold_to_confirm
|
||||
from apps.common.confirm import require_hold_to_confirm
|
||||
|
||||
|
||||
async def wipe_device(ctx, msg):
|
||||
|
||||
await hold_to_confirm(ctx, Text(
|
||||
await require_hold_to_confirm(ctx, Text(
|
||||
'Wipe device',
|
||||
ui.ICON_WIPE,
|
||||
ui.NORMAL, 'Do you really want to', 'wipe the device?',
|
||||
|
@ -15,7 +15,7 @@ async def sign_identity(ctx, msg):
|
||||
|
||||
identity = serialize_identity(msg.identity)
|
||||
|
||||
await confirm_sign_identity(ctx, identity, msg.challenge_visual)
|
||||
await require_confirm_sign_identity(ctx, identity, msg.challenge_visual)
|
||||
|
||||
address_n = get_identity_path(identity, msg.identity.index or 0)
|
||||
node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name)
|
||||
@ -43,7 +43,7 @@ async def sign_identity(ctx, msg):
|
||||
return SignedIdentity(address=address, public_key=pubkey, signature=signature)
|
||||
|
||||
|
||||
async def confirm_sign_identity(ctx, identity, challenge_visual):
|
||||
async def require_confirm_sign_identity(ctx, identity, challenge_visual):
|
||||
lines = chunks(identity, 18)
|
||||
content = Text('Sign identity', ui.ICON_DEFAULT,
|
||||
challenge_visual,
|
||||
|
@ -18,7 +18,7 @@ async def sign_message(ctx, msg):
|
||||
script_type = msg.script_type or 0
|
||||
coin = coins.by_name(coin_name)
|
||||
|
||||
await confirm_sign_message(ctx, message)
|
||||
await require_confirm_sign_message(ctx, message)
|
||||
|
||||
node = await seed.derive_node(ctx, address_n)
|
||||
seckey = node.private_key()
|
||||
@ -39,7 +39,7 @@ async def sign_message(ctx, msg):
|
||||
return MessageSignature(address=address, signature=signature)
|
||||
|
||||
|
||||
async def confirm_sign_message(ctx, message):
|
||||
async def require_confirm_sign_message(ctx, message):
|
||||
message = split_message(message)
|
||||
content = Text('Sign message', ui.ICON_DEFAULT, max_lines=5, *message)
|
||||
await require_confirm(ctx, content)
|
||||
|
@ -50,12 +50,12 @@ async def verify_message(ctx, msg):
|
||||
if addr != address:
|
||||
raise wire.FailureError(ProcessError, 'Invalid signature')
|
||||
|
||||
await confirm_verify_message(ctx, address, message)
|
||||
await require_confirm_verify_message(ctx, address, message)
|
||||
|
||||
return Success(message='Message verified')
|
||||
|
||||
|
||||
async def confirm_verify_message(ctx, address, message):
|
||||
async def require_confirm_verify_message(ctx, address, message):
|
||||
lines = _split_address(address)
|
||||
content = Text('Confirm address', ui.ICON_DEFAULT, ui.MONO, *lines)
|
||||
await require_confirm(ctx, content)
|
||||
|
Loading…
Reference in New Issue
Block a user