1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-17 19:00:58 +00:00

refactor(core): use confirm_blob instead of confirm_hex in apps

This commit is contained in:
matejcik 2021-07-16 15:07:50 +02:00 committed by matejcik
parent dcc38f5267
commit ad6976e01f
10 changed files with 87 additions and 86 deletions

View File

@ -1,8 +1,6 @@
from ubinascii import hexlify
from trezor import ui, wire
from trezor.messages import GetOwnershipProof, OwnershipProof
from trezor.ui.layouts import confirm_action, confirm_hex
from trezor.ui.layouts import confirm_action, confirm_blob
from apps.common.paths import validate_path
@ -70,16 +68,14 @@ async def get_ownership_proof(
description="Do you want to create a proof of ownership?",
)
else:
await confirm_hex(
await confirm_blob(
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(),
data=msg.commitment_data,
icon=ui.ICON_CONFIG,
icon_color=ui.ORANGE_ICON,
truncate=True, # commitment data, probably should show all
truncate_middle=True,
)
ownership_proof, signature = generate_proof(

View File

@ -50,13 +50,12 @@ async def confirm_output(
)
else:
# generic OP_RETURN
layout = layouts.confirm_hex(
layout = layouts.confirm_blob(
ctx,
"op_return",
title="OP_RETURN",
data=hexlify(data).decode(),
data=data,
br_code=ButtonRequestType.ConfirmOutput,
truncate=True, # 80 bytes - not truncated 2 screens max
)
else:
assert output.address is not None

View File

@ -469,6 +469,10 @@ async def show_warning_address_foreign_staking_key(
staking_account_path: list[int],
staking_key_hash: bytes | None,
) -> None:
# TODO: confirm_properties not appropriate here
# instead, presumably, this should be a flow:
# 1. show_warning: Mismatch! continue?
# 2. confirm_blob(mismatched_value)
props: list[PropertyType] = [
(
"Stake rights associated with this address do not match your account %s:"

View File

@ -3,7 +3,12 @@ from ubinascii import hexlify
from trezor import ui
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.layouts import confirm_hex, confirm_output, confirm_total_ethereum
from trezor.ui.layouts import (
confirm_address,
confirm_blob,
confirm_output,
confirm_total_ethereum,
)
from . import networks, tokens
from .address import address_from_bytes
@ -37,30 +42,24 @@ async def require_confirm_fee(
async def require_confirm_unknown_token(ctx, address_bytes):
contract_address_hex = "0x" + hexlify(address_bytes).decode()
await confirm_hex(
await confirm_address(
ctx,
"confirm_unknown",
title="Unknown token",
data=contract_address_hex,
truncate=True,
"Unknown token",
contract_address_hex,
description="Contract:",
color_description=ui.GREY,
br_type="unknown_token",
icon_color=ui.ORANGE,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_data(ctx, data, data_total):
data_str = hexlify(data[:36]).decode()
if data_total > 36:
data_str = data_str[:-2] + ".."
await confirm_hex(
await confirm_blob(
ctx,
"confirm_data",
title="Confirm data",
data=data_str,
truncate=True,
subtitle="Size: %d bytes" % data_total,
description="Size: %d bytes" % data_total,
data=data,
br_code=ButtonRequestType.SignTx,
)

View File

@ -1,5 +1,3 @@
import ubinascii
from trezor import ui, utils
from trezor.crypto import random
from trezor.enums import BackupType, ButtonRequestType
@ -9,7 +7,7 @@ from trezor.ui.components.tt.info import InfoConfirm
from trezor.ui.components.tt.num_input import NumInput
from trezor.ui.components.tt.scroll import Paginated
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import confirm_action, confirm_hex, show_success, show_warning
from trezor.ui.layouts import confirm_action, confirm_blob, show_success, show_warning
from apps.common.confirm import confirm, require_hold_to_confirm
@ -21,16 +19,14 @@ if __debug__:
async def show_internal_entropy(ctx, entropy: bytes):
await confirm_hex(
await confirm_blob(
ctx,
"entropy",
"Internal entropy",
data=ubinascii.hexlify(entropy).decode(),
data=entropy,
icon=ui.ICON_RESET,
icon_color=ui.ORANGE_ICON,
width=16,
br_code=ButtonRequestType.ResetDevice,
truncate=True, # 32 bytes always fits
)

View File

@ -3,7 +3,7 @@ from ustruct import pack, unpack
from trezor import ui, wire
from trezor.crypto.hashlib import sha256
from trezor.messages import ECDHSessionKey
from trezor.ui.layouts import confirm_hex
from trezor.ui.layouts import confirm_address
from apps.common import HARDENED
from apps.common.keychain import get_keychain
@ -46,14 +46,13 @@ async def require_confirm_ecdh_session_key(
ctx: wire.Context, identity: IdentityType
) -> None:
proto = identity.proto.upper() if identity.proto else "identity"
await confirm_hex(
await confirm_address(
ctx,
"ecdh_session_key",
"Decrypt %s" % proto,
serialize_identity_without_proto(identity),
description=None,
icon=ui.ICON_DEFAULT,
icon_color=ui.ORANGE_ICON,
truncate=True, # uri without protocol, probably should show entire
)

View File

@ -1,10 +1,8 @@
from ubinascii import hexlify
from trezor import strings, ui
from trezor.enums import ButtonRequestType
from trezor.ui.layouts import (
confirm_action,
confirm_hex,
confirm_blob,
confirm_metadata,
confirm_output,
)
@ -137,11 +135,11 @@ async def _require_confirm_output(
async def _require_confirm_payment_id(ctx, payment_id: bytes):
await confirm_hex(
await confirm_blob(
ctx,
"confirm_payment_id",
title="Payment ID",
data=hexlify(payment_id).decode(),
data=payment_id,
br_code=ButtonRequestType.SignTx,
)

View File

@ -2,8 +2,7 @@ from trezor import ui
from trezor.crypto import nem
from trezor.enums import ButtonRequestType, NEMModificationType
from trezor.messages import NEMAggregateModification, NEMSignTx, NEMTransactionCommon
from trezor.ui.constants import MONO_ADDR_PER_LINE
from trezor.ui.layouts import confirm_hex
from trezor.ui.layouts import confirm_address
from ..layout import require_confirm_fee, require_confirm_final, require_confirm_text
@ -42,14 +41,12 @@ async def ask_aggregate_modification(
async def _require_confirm_address(ctx, action: str, address: str):
await confirm_hex(
await confirm_address(
ctx,
br_type="confirm_multisig",
title="Confirm address",
description=action,
data=address,
address=address,
br_code=ButtonRequestType.ConfirmOutput,
icon=ui.ICON_SEND,
width=MONO_ADDR_PER_LINE,
truncate=True,
)

View File

@ -7,7 +7,12 @@ from trezor.messages import (
NEMTransfer,
)
from trezor.strings import format_amount
from trezor.ui.layouts import confirm_action, confirm_output, confirm_properties
from trezor.ui.layouts import (
confirm_action,
confirm_output,
confirm_properties,
confirm_text,
)
from ..helpers import (
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE,
@ -145,13 +150,12 @@ async def _require_confirm_payload(ctx, payload: bytearray, encrypt=False):
payload = bytes(payload).decode()
subtitle = "Encrypted:" if encrypt else "Unencrypted:"
await confirm_properties(
await confirm_text(
ctx,
"confirm_payload",
title="Confirm payload",
props=[
(None, subtitle),
(payload, None),
],
description=subtitle,
data=payload,
icon_color=ui.GREEN if encrypt else ui.RED,
br_code=ButtonRequestType.ConfirmOutput,
)

View File

@ -2,10 +2,10 @@ from trezor import ui
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.layouts import (
confirm_hex,
confirm_address,
confirm_metadata,
confirm_output,
confirm_proposals_tezos,
confirm_properties,
confirm_total,
)
@ -35,41 +35,38 @@ async def require_confirm_fee(ctx, value, fee):
async def require_confirm_origination(ctx, address):
await confirm_hex(
await confirm_address(
ctx,
"confirm_origination",
title="Confirm origination",
address=address,
description="Address:",
data=address,
width=18,
truncate=True,
br_type="confirm_origination",
icon_color=ui.ORANGE,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_origination_fee(ctx, balance, fee):
await confirm_total(
await confirm_properties(
ctx,
title="Confirm origination",
total_amount=format_tezos_amount(balance),
total_label="Balance:\n",
fee_amount=format_tezos_amount(fee),
fee_label="\nFee:\n",
props=(
("Balance:", format_tezos_amount(balance)),
("Fee:", format_tezos_amount(fee)),
),
icon_color=ui.ORANGE,
br_type="confirm_origination_final",
hold=True,
)
async def require_confirm_delegation_baker(ctx, baker):
await confirm_hex(
await confirm_address(
ctx,
"confirm_delegation",
title="Confirm delegation",
address=baker,
description="Baker address:",
data=baker,
width=18,
truncate=True,
br_type="confirm_delegation",
icon_color=ui.BLUE,
br_code=ButtonRequestType.SignTx,
)
@ -90,14 +87,14 @@ async def require_confirm_set_delegate(ctx, fee):
async def require_confirm_register_delegate(ctx, address, fee):
await confirm_hex(
await confirm_properties(
ctx,
"confirm_register_delegate",
title="Register delegate",
subtitle="Fee: " + format_tezos_amount(fee),
description="Address:",
data=address,
width=18,
props=(
("Fee:", format_tezos_amount(fee)),
("Address:", address),
),
icon_color=ui.BLUE,
br_code=ButtonRequestType.SignTx,
)
@ -109,32 +106,44 @@ def format_tezos_amount(value):
async def require_confirm_ballot(ctx, proposal, ballot):
await confirm_hex(
await confirm_properties(
ctx,
"confirm_ballot",
title="Submit ballot",
subtitle="Ballot: {}\nProposal:".format(ballot),
data=proposal,
width=17,
truncate=True,
props=(
("Ballot:", ballot),
("Proposal:", proposal),
),
icon_color=ui.PURPLE,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_proposals(ctx, proposals):
await confirm_proposals_tezos(ctx, proposals)
if len(proposals) > 1:
title = "Submit proposals"
else:
title = "Submit proposal"
await confirm_properties(
ctx,
"confirm_proposals",
title=title,
props=[
("Proposal " + str(i), proposal) for i, proposal in enumerate(proposals, 1)
],
icon_color=ui.PURPLE,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_delegation_manager_withdraw(ctx, address):
await confirm_hex(
await confirm_address(
ctx,
"confirm_undelegation",
title="Remove delegation",
subtitle="Delegator:",
data=address,
width=18,
truncate=True,
address=address,
description="Delegator:",
br_type="confirm_undelegation",
icon=ui.ICON_RECEIVE,
icon_color=ui.RED,
br_code=ButtonRequestType.SignTx,