Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layouts: simple confirmations and warnings #1480

Merged
merged 13 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions core/src/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ async def handle_EndSession(ctx: wire.Context, msg: EndSession) -> Success:

async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
if msg.button_protection:
from trezor.ui.layouts import require, confirm_action
from trezor.ui.layouts import confirm_action
from trezor.messages.ButtonRequestType import ProtectCall

await require(
confirm_action(ctx, "ping", "Confirm", "ping", br_code=ProtectCall)
)
await confirm_action(ctx, "ping", "Confirm", "ping", br_code=ProtectCall)
return Success(message=msg.message)


Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/binance/get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey
from trezor.messages.BinancePublicKey import BinancePublicKey
from trezor.ui.layouts import require, show_pubkey
from trezor.ui.layouts import show_pubkey

from apps.common import paths
from apps.common.keychain import Keychain, auto_keychain
Expand All @@ -15,6 +15,6 @@ async def get_public_key(ctx, msg: BinanceGetPublicKey, keychain: Keychain):
pubkey = node.public_key()

if msg.show_display:
await require(show_pubkey(ctx, hexlify(pubkey).decode()))
await show_pubkey(ctx, hexlify(pubkey).decode())

return BinancePublicKey(public_key=pubkey)
39 changes: 17 additions & 22 deletions core/src/apps/bitcoin/authorize_coinjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin
from trezor.messages.Success import Success
from trezor.strings import format_amount
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import confirm_action, confirm_coinjoin

from apps.base import set_authorization
from apps.common.confirm import require_confirm, require_hold_to_confirm
from apps.common.paths import validate_path

from .authorization import FEE_PER_ANONYMITY_DECIMALS, CoinJoinAuthorization
Expand Down Expand Up @@ -46,30 +45,26 @@ async def authorize_coinjoin(ctx: wire.Context, msg: AuthorizeCoinJoin) -> Succe
),
)

text = Text("Authorize CoinJoin", ui.ICON_RECOVERY)
text.normal("Do you really want to")
text.normal("take part in a CoinJoin")
text.normal("transaction at:")
text.mono(msg.coordinator)
await require_confirm(ctx, text)
await confirm_action(
ctx,
"coinjoin_coordinator",
title="Authorize CoinJoin",
description="Do you really want to take part in a CoinJoin transaction at:\n{}",
description_param=msg.coordinator,
description_param_font=ui.MONO,
icon=ui.ICON_RECOVERY,
)

text = Text("Authorize CoinJoin", ui.ICON_RECOVERY)
fee_per_anonymity = None
if msg.fee_per_anonymity is not None:
text.normal("Fee per anonymity set:")
text.bold(
"{} %".format(
format_amount(msg.fee_per_anonymity, FEE_PER_ANONYMITY_DECIMALS)
)
)
text.normal("Maximum total fees:")
text.bold(
format_coin_amount(
msg.max_total_fee,
coin,
msg.amount_unit,
fee_per_anonymity = format_amount(
msg.fee_per_anonymity, FEE_PER_ANONYMITY_DECIMALS
)
await confirm_coinjoin(
ctx,
fee_per_anonymity,
format_coin_amount(msg.max_total_fee, coin, msg.amount_unit),
)
await require_hold_to_confirm(ctx, text)

set_authorization(CoinJoinAuthorization(msg, keychain, coin))

Expand Down
36 changes: 17 additions & 19 deletions core/src/apps/bitcoin/get_ownership_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from trezor import ui, wire
from trezor.messages.GetOwnershipProof import GetOwnershipProof
from trezor.messages.OwnershipProof import OwnershipProof
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import confirm_action, confirm_hex

from apps.common.confirm import require_confirm
from apps.common.paths import validate_path

from . import addresses, common, scripts
Expand Down Expand Up @@ -65,25 +64,24 @@ async def get_ownership_proof(

# In order to set the "user confirmation" bit in the proof, the user must actually confirm.
if msg.user_confirmation and not authorization:
text = Text("Proof of ownership", ui.ICON_CONFIG)
text.normal("Do you want to create a")
if not msg.commitment_data:
text.normal("proof of ownership?")
await confirm_action(
ctx,
"confirm_ownership_proof",
title="Proof of ownership",
description="Do you want to create a proof of ownership?",
)
else:
hex_data = hexlify(msg.commitment_data).decode()
text.normal("proof of ownership for:")
if len(hex_data) > 3 * _MAX_MONO_LINE:
text.mono(hex_data[0:_MAX_MONO_LINE])
text.mono(
hex_data[_MAX_MONO_LINE : 3 * _MAX_MONO_LINE // 2 - 1]
+ "..."
+ hex_data[-3 * _MAX_MONO_LINE // 2 + 2 : -_MAX_MONO_LINE]
)
text.mono(hex_data[-_MAX_MONO_LINE:])
else:
text.mono(hex_data)

await require_confirm(ctx, text)
await confirm_hex(
ctx,
"confirm_ownership_proof",
title="Proof of ownership",
description="Do you want to create a proof of ownership for:",
data=hexlify(msg.commitment_data).decode(),
icon=ui.ICON_CONFIG,
icon_color=ui.ORANGE_ICON,
truncate_middle=True,
)

ownership_proof, signature = generate_proof(
node,
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/bitcoin/get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from trezor.messages import InputScriptType
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages.PublicKey import PublicKey
from trezor.ui.layouts import require, show_xpub
from trezor.ui.layouts import show_xpub

from apps.common import coins, paths
from apps.common.keychain import get_keychain
Expand Down Expand Up @@ -59,7 +59,7 @@ async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:
)

if msg.show_display:
await require(show_xpub(ctx, node_xpub, "XPUB", "Cancel"))
await show_xpub(ctx, node_xpub, "XPUB", "Cancel")

return PublicKey(
node=node_type,
Expand Down
5 changes: 3 additions & 2 deletions core/src/apps/bitcoin/sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from trezor.crypto.curve import secp256k1
from trezor.messages.InputScriptType import SPENDADDRESS, SPENDP2SHWITNESS, SPENDWITNESS
from trezor.messages.MessageSignature import MessageSignature
from trezor.ui.layouts import confirm_signverify

from apps.common.paths import validate_path
from apps.common.signverify import message_digest, require_confirm_sign_message
from apps.common.signverify import decode_message, message_digest

from .addresses import get_address
from .keychain import with_keychain
Expand All @@ -25,7 +26,7 @@ async def sign_message(
script_type = msg.script_type or 0

await validate_path(ctx, keychain, address_n)
await require_confirm_sign_message(ctx, coin.coin_shortcut, message)
await confirm_signverify(ctx, coin.coin_shortcut, decode_message(message))

node = keychain.derive(address_n)
seckey = node.private_key()
Expand Down
119 changes: 50 additions & 69 deletions core/src/apps/bitcoin/sign_tx/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from trezor.messages import AmountUnit, ButtonRequestType, OutputScriptType
from trezor.strings import format_amount
from trezor.ui import layouts
from trezor.ui.layouts import require

from .. import addresses
from . import omni
Expand Down Expand Up @@ -59,9 +58,9 @@ async def confirm_output(
layout = layouts.confirm_hex(
ctx,
"op_return",
"OP_RETURN",
hexlify(data).decode(),
ButtonRequestType.ConfirmOutput,
title="OP_RETURN",
data=hexlify(data).decode(),
br_code=ButtonRequestType.ConfirmOutput,
)
else:
assert output.address is not None
Expand All @@ -70,7 +69,7 @@ async def confirm_output(
ctx, address_short, format_coin_amount(output.amount, coin, amount_unit)
)

await require(layout)
await layout


async def confirm_decred_sstx_submission(
Expand All @@ -79,20 +78,16 @@ async def confirm_decred_sstx_submission(
assert output.address is not None
address_short = addresses.address_short(coin, output.address)

await require(
layouts.confirm_decred_sstx_submission(
ctx, address_short, format_coin_amount(output.amount, coin, amount_unit)
)
await layouts.confirm_decred_sstx_submission(
ctx, address_short, format_coin_amount(output.amount, coin, amount_unit)
)


async def confirm_replacement(ctx: wire.Context, description: str, txid: bytes) -> None:
await require(
layouts.confirm_replacement(
ctx,
description,
hexlify(txid).decode(),
)
await layouts.confirm_replacement(
ctx,
description,
hexlify(txid).decode(),
)


Expand All @@ -106,14 +101,12 @@ async def confirm_modify_output(
assert txo.address is not None
address_short = addresses.address_short(coin, txo.address)
amount_change = txo.amount - orig_txo.amount
await require(
layouts.confirm_modify_output(
ctx,
address_short,
amount_change,
format_coin_amount(abs(amount_change), coin, amount_unit),
format_coin_amount(txo.amount, coin, amount_unit),
)
await layouts.confirm_modify_output(
ctx,
address_short,
amount_change,
format_coin_amount(abs(amount_change), coin, amount_unit),
format_coin_amount(txo.amount, coin, amount_unit),
)


Expand All @@ -124,13 +117,11 @@ async def confirm_modify_fee(
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
) -> None:
await require(
layouts.confirm_modify_fee(
ctx,
user_fee_change,
format_coin_amount(abs(user_fee_change), coin, amount_unit),
format_coin_amount(total_fee_new, coin, amount_unit),
)
await layouts.confirm_modify_fee(
ctx,
user_fee_change,
format_coin_amount(abs(user_fee_change), coin, amount_unit),
format_coin_amount(total_fee_new, coin, amount_unit),
)


Expand All @@ -141,12 +132,10 @@ async def confirm_joint_total(
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
) -> None:
await require(
layouts.confirm_joint_total(
ctx,
spending_amount=format_coin_amount(spending, coin, amount_unit),
total_amount=format_coin_amount(total, coin, amount_unit),
),
await layouts.confirm_joint_total(
ctx,
spending_amount=format_coin_amount(spending, coin, amount_unit),
total_amount=format_coin_amount(total, coin, amount_unit),
)


Expand All @@ -157,43 +146,37 @@ async def confirm_total(
coin: CoinInfo,
amount_unit: EnumTypeAmountUnit,
) -> None:
await require(
layouts.confirm_total(
ctx,
total_amount=format_coin_amount(spending, coin, amount_unit),
fee_amount=format_coin_amount(fee, coin, amount_unit),
),
await layouts.confirm_total(
ctx,
total_amount=format_coin_amount(spending, coin, amount_unit),
fee_amount=format_coin_amount(fee, coin, amount_unit),
)


async def confirm_feeoverthreshold(
ctx: wire.Context, fee: int, coin: CoinInfo, amount_unit: EnumTypeAmountUnit
) -> None:
fee_amount = format_coin_amount(fee, coin, amount_unit)
await require(
layouts.confirm_metadata(
ctx,
"fee_over_threshold",
"High fee",
"The fee of\n{}is unexpectedly high.",
fee_amount,
ButtonRequestType.FeeOverThreshold,
)
await layouts.confirm_metadata(
ctx,
"fee_over_threshold",
"High fee",
"The fee of\n{}is unexpectedly high.",
fee_amount,
ButtonRequestType.FeeOverThreshold,
)


async def confirm_change_count_over_threshold(
ctx: wire.Context, change_count: int
) -> None:
await require(
layouts.confirm_metadata(
ctx,
"change_count_over_threshold",
"Warning",
"There are {}\nchange-outputs.\n",
str(change_count),
ButtonRequestType.SignTx,
)
await layouts.confirm_metadata(
ctx,
"change_count_over_threshold",
"Warning",
"There are {}\nchange-outputs.\n",
str(change_count),
ButtonRequestType.SignTx,
)


Expand All @@ -213,13 +196,11 @@ async def confirm_nondefault_locktime(
text = "Locktime for this\ntransaction is set to\ntimestamp:\n{}"
param = str(lock_time)

await require(
layouts.confirm_metadata(
ctx,
"nondefault_locktime",
title,
text,
param,
br_code=ButtonRequestType.SignTx,
)
await layouts.confirm_metadata(
ctx,
"nondefault_locktime",
title,
text,
param,
br_code=ButtonRequestType.SignTx,
)
Loading