mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-06 12:51:21 +00:00
refactor(core): use confirm_blob instead of confirm_hex in apps
This commit is contained in:
parent
dcc38f5267
commit
ad6976e01f
@ -1,8 +1,6 @@
|
|||||||
from ubinascii import hexlify
|
|
||||||
|
|
||||||
from trezor import ui, wire
|
from trezor import ui, wire
|
||||||
from trezor.messages import GetOwnershipProof, OwnershipProof
|
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
|
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?",
|
description="Do you want to create a proof of ownership?",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await confirm_hex(
|
await confirm_blob(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_ownership_proof",
|
"confirm_ownership_proof",
|
||||||
title="Proof of ownership",
|
title="Proof of ownership",
|
||||||
description="Do you want to create a proof of ownership for:",
|
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=ui.ICON_CONFIG,
|
||||||
icon_color=ui.ORANGE_ICON,
|
icon_color=ui.ORANGE_ICON,
|
||||||
truncate=True, # commitment data, probably should show all
|
|
||||||
truncate_middle=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ownership_proof, signature = generate_proof(
|
ownership_proof, signature = generate_proof(
|
||||||
|
@ -50,13 +50,12 @@ async def confirm_output(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# generic OP_RETURN
|
# generic OP_RETURN
|
||||||
layout = layouts.confirm_hex(
|
layout = layouts.confirm_blob(
|
||||||
ctx,
|
ctx,
|
||||||
"op_return",
|
"op_return",
|
||||||
title="OP_RETURN",
|
title="OP_RETURN",
|
||||||
data=hexlify(data).decode(),
|
data=data,
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
truncate=True, # 80 bytes - not truncated 2 screens max
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
assert output.address is not None
|
assert output.address is not None
|
||||||
|
@ -469,6 +469,10 @@ async def show_warning_address_foreign_staking_key(
|
|||||||
staking_account_path: list[int],
|
staking_account_path: list[int],
|
||||||
staking_key_hash: bytes | None,
|
staking_key_hash: bytes | None,
|
||||||
) -> 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] = [
|
props: list[PropertyType] = [
|
||||||
(
|
(
|
||||||
"Stake rights associated with this address do not match your account %s:"
|
"Stake rights associated with this address do not match your account %s:"
|
||||||
|
@ -3,7 +3,12 @@ from ubinascii import hexlify
|
|||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.strings import format_amount
|
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 . import networks, tokens
|
||||||
from .address import address_from_bytes
|
from .address import address_from_bytes
|
||||||
@ -37,30 +42,24 @@ async def require_confirm_fee(
|
|||||||
|
|
||||||
async def require_confirm_unknown_token(ctx, address_bytes):
|
async def require_confirm_unknown_token(ctx, address_bytes):
|
||||||
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_unknown",
|
"Unknown token",
|
||||||
title="Unknown token",
|
contract_address_hex,
|
||||||
data=contract_address_hex,
|
|
||||||
truncate=True,
|
|
||||||
description="Contract:",
|
description="Contract:",
|
||||||
color_description=ui.GREY,
|
br_type="unknown_token",
|
||||||
icon_color=ui.ORANGE,
|
icon_color=ui.ORANGE,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_data(ctx, data, data_total):
|
async def require_confirm_data(ctx, data, data_total):
|
||||||
data_str = hexlify(data[:36]).decode()
|
await confirm_blob(
|
||||||
if data_total > 36:
|
|
||||||
data_str = data_str[:-2] + ".."
|
|
||||||
await confirm_hex(
|
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_data",
|
"confirm_data",
|
||||||
title="Confirm data",
|
title="Confirm data",
|
||||||
data=data_str,
|
description="Size: %d bytes" % data_total,
|
||||||
truncate=True,
|
data=data,
|
||||||
subtitle="Size: %d bytes" % data_total,
|
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import ubinascii
|
|
||||||
|
|
||||||
from trezor import ui, utils
|
from trezor import ui, utils
|
||||||
from trezor.crypto import random
|
from trezor.crypto import random
|
||||||
from trezor.enums import BackupType, ButtonRequestType
|
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.num_input import NumInput
|
||||||
from trezor.ui.components.tt.scroll import Paginated
|
from trezor.ui.components.tt.scroll import Paginated
|
||||||
from trezor.ui.components.tt.text import Text
|
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
|
from apps.common.confirm import confirm, require_hold_to_confirm
|
||||||
|
|
||||||
@ -21,16 +19,14 @@ if __debug__:
|
|||||||
|
|
||||||
|
|
||||||
async def show_internal_entropy(ctx, entropy: bytes):
|
async def show_internal_entropy(ctx, entropy: bytes):
|
||||||
await confirm_hex(
|
await confirm_blob(
|
||||||
ctx,
|
ctx,
|
||||||
"entropy",
|
"entropy",
|
||||||
"Internal entropy",
|
"Internal entropy",
|
||||||
data=ubinascii.hexlify(entropy).decode(),
|
data=entropy,
|
||||||
icon=ui.ICON_RESET,
|
icon=ui.ICON_RESET,
|
||||||
icon_color=ui.ORANGE_ICON,
|
icon_color=ui.ORANGE_ICON,
|
||||||
width=16,
|
|
||||||
br_code=ButtonRequestType.ResetDevice,
|
br_code=ButtonRequestType.ResetDevice,
|
||||||
truncate=True, # 32 bytes always fits
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from ustruct import pack, unpack
|
|||||||
from trezor import ui, wire
|
from trezor import ui, wire
|
||||||
from trezor.crypto.hashlib import sha256
|
from trezor.crypto.hashlib import sha256
|
||||||
from trezor.messages import ECDHSessionKey
|
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 import HARDENED
|
||||||
from apps.common.keychain import get_keychain
|
from apps.common.keychain import get_keychain
|
||||||
@ -46,14 +46,13 @@ async def require_confirm_ecdh_session_key(
|
|||||||
ctx: wire.Context, identity: IdentityType
|
ctx: wire.Context, identity: IdentityType
|
||||||
) -> None:
|
) -> None:
|
||||||
proto = identity.proto.upper() if identity.proto else "identity"
|
proto = identity.proto.upper() if identity.proto else "identity"
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
"ecdh_session_key",
|
|
||||||
"Decrypt %s" % proto,
|
"Decrypt %s" % proto,
|
||||||
serialize_identity_without_proto(identity),
|
serialize_identity_without_proto(identity),
|
||||||
|
description=None,
|
||||||
icon=ui.ICON_DEFAULT,
|
icon=ui.ICON_DEFAULT,
|
||||||
icon_color=ui.ORANGE_ICON,
|
icon_color=ui.ORANGE_ICON,
|
||||||
truncate=True, # uri without protocol, probably should show entire
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
from ubinascii import hexlify
|
|
||||||
|
|
||||||
from trezor import strings, ui
|
from trezor import strings, ui
|
||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.ui.layouts import (
|
from trezor.ui.layouts import (
|
||||||
confirm_action,
|
confirm_action,
|
||||||
confirm_hex,
|
confirm_blob,
|
||||||
confirm_metadata,
|
confirm_metadata,
|
||||||
confirm_output,
|
confirm_output,
|
||||||
)
|
)
|
||||||
@ -137,11 +135,11 @@ async def _require_confirm_output(
|
|||||||
|
|
||||||
|
|
||||||
async def _require_confirm_payment_id(ctx, payment_id: bytes):
|
async def _require_confirm_payment_id(ctx, payment_id: bytes):
|
||||||
await confirm_hex(
|
await confirm_blob(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_payment_id",
|
"confirm_payment_id",
|
||||||
title="Payment ID",
|
title="Payment ID",
|
||||||
data=hexlify(payment_id).decode(),
|
data=payment_id,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ from trezor import ui
|
|||||||
from trezor.crypto import nem
|
from trezor.crypto import nem
|
||||||
from trezor.enums import ButtonRequestType, NEMModificationType
|
from trezor.enums import ButtonRequestType, NEMModificationType
|
||||||
from trezor.messages import NEMAggregateModification, NEMSignTx, NEMTransactionCommon
|
from trezor.messages import NEMAggregateModification, NEMSignTx, NEMTransactionCommon
|
||||||
from trezor.ui.constants import MONO_ADDR_PER_LINE
|
from trezor.ui.layouts import confirm_address
|
||||||
from trezor.ui.layouts import confirm_hex
|
|
||||||
|
|
||||||
from ..layout import require_confirm_fee, require_confirm_final, require_confirm_text
|
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):
|
async def _require_confirm_address(ctx, action: str, address: str):
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
br_type="confirm_multisig",
|
br_type="confirm_multisig",
|
||||||
title="Confirm address",
|
title="Confirm address",
|
||||||
description=action,
|
description=action,
|
||||||
data=address,
|
address=address,
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
icon=ui.ICON_SEND,
|
icon=ui.ICON_SEND,
|
||||||
width=MONO_ADDR_PER_LINE,
|
|
||||||
truncate=True,
|
|
||||||
)
|
)
|
||||||
|
@ -7,7 +7,12 @@ from trezor.messages import (
|
|||||||
NEMTransfer,
|
NEMTransfer,
|
||||||
)
|
)
|
||||||
from trezor.strings import format_amount
|
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 (
|
from ..helpers import (
|
||||||
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE,
|
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE,
|
||||||
@ -145,13 +150,12 @@ async def _require_confirm_payload(ctx, payload: bytearray, encrypt=False):
|
|||||||
payload = bytes(payload).decode()
|
payload = bytes(payload).decode()
|
||||||
subtitle = "Encrypted:" if encrypt else "Unencrypted:"
|
subtitle = "Encrypted:" if encrypt else "Unencrypted:"
|
||||||
|
|
||||||
await confirm_properties(
|
await confirm_text(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_payload",
|
"confirm_payload",
|
||||||
title="Confirm payload",
|
title="Confirm payload",
|
||||||
props=[
|
description=subtitle,
|
||||||
(None, subtitle),
|
data=payload,
|
||||||
(payload, None),
|
|
||||||
],
|
|
||||||
icon_color=ui.GREEN if encrypt else ui.RED,
|
icon_color=ui.GREEN if encrypt else ui.RED,
|
||||||
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
)
|
)
|
||||||
|
@ -2,10 +2,10 @@ from trezor import ui
|
|||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.strings import format_amount
|
from trezor.strings import format_amount
|
||||||
from trezor.ui.layouts import (
|
from trezor.ui.layouts import (
|
||||||
confirm_hex,
|
confirm_address,
|
||||||
confirm_metadata,
|
confirm_metadata,
|
||||||
confirm_output,
|
confirm_output,
|
||||||
confirm_proposals_tezos,
|
confirm_properties,
|
||||||
confirm_total,
|
confirm_total,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,41 +35,38 @@ async def require_confirm_fee(ctx, value, fee):
|
|||||||
|
|
||||||
|
|
||||||
async def require_confirm_origination(ctx, address):
|
async def require_confirm_origination(ctx, address):
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_origination",
|
|
||||||
title="Confirm origination",
|
title="Confirm origination",
|
||||||
|
address=address,
|
||||||
description="Address:",
|
description="Address:",
|
||||||
data=address,
|
br_type="confirm_origination",
|
||||||
width=18,
|
|
||||||
truncate=True,
|
|
||||||
icon_color=ui.ORANGE,
|
icon_color=ui.ORANGE,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_origination_fee(ctx, balance, fee):
|
async def require_confirm_origination_fee(ctx, balance, fee):
|
||||||
await confirm_total(
|
await confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
title="Confirm origination",
|
title="Confirm origination",
|
||||||
total_amount=format_tezos_amount(balance),
|
props=(
|
||||||
total_label="Balance:\n",
|
("Balance:", format_tezos_amount(balance)),
|
||||||
fee_amount=format_tezos_amount(fee),
|
("Fee:", format_tezos_amount(fee)),
|
||||||
fee_label="\nFee:\n",
|
),
|
||||||
icon_color=ui.ORANGE,
|
icon_color=ui.ORANGE,
|
||||||
br_type="confirm_origination_final",
|
br_type="confirm_origination_final",
|
||||||
|
hold=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_delegation_baker(ctx, baker):
|
async def require_confirm_delegation_baker(ctx, baker):
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_delegation",
|
|
||||||
title="Confirm delegation",
|
title="Confirm delegation",
|
||||||
|
address=baker,
|
||||||
description="Baker address:",
|
description="Baker address:",
|
||||||
data=baker,
|
br_type="confirm_delegation",
|
||||||
width=18,
|
|
||||||
truncate=True,
|
|
||||||
icon_color=ui.BLUE,
|
icon_color=ui.BLUE,
|
||||||
br_code=ButtonRequestType.SignTx,
|
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):
|
async def require_confirm_register_delegate(ctx, address, fee):
|
||||||
await confirm_hex(
|
await confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_register_delegate",
|
"confirm_register_delegate",
|
||||||
title="Register delegate",
|
title="Register delegate",
|
||||||
subtitle="Fee: " + format_tezos_amount(fee),
|
props=(
|
||||||
description="Address:",
|
("Fee:", format_tezos_amount(fee)),
|
||||||
data=address,
|
("Address:", address),
|
||||||
width=18,
|
),
|
||||||
icon_color=ui.BLUE,
|
icon_color=ui.BLUE,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
@ -109,32 +106,44 @@ def format_tezos_amount(value):
|
|||||||
|
|
||||||
|
|
||||||
async def require_confirm_ballot(ctx, proposal, ballot):
|
async def require_confirm_ballot(ctx, proposal, ballot):
|
||||||
await confirm_hex(
|
await confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_ballot",
|
"confirm_ballot",
|
||||||
title="Submit ballot",
|
title="Submit ballot",
|
||||||
subtitle="Ballot: {}\nProposal:".format(ballot),
|
props=(
|
||||||
data=proposal,
|
("Ballot:", ballot),
|
||||||
width=17,
|
("Proposal:", proposal),
|
||||||
truncate=True,
|
),
|
||||||
icon_color=ui.PURPLE,
|
icon_color=ui.PURPLE,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_proposals(ctx, proposals):
|
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):
|
async def require_confirm_delegation_manager_withdraw(ctx, address):
|
||||||
await confirm_hex(
|
await confirm_address(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_undelegation",
|
|
||||||
title="Remove delegation",
|
title="Remove delegation",
|
||||||
subtitle="Delegator:",
|
address=address,
|
||||||
data=address,
|
description="Delegator:",
|
||||||
width=18,
|
br_type="confirm_undelegation",
|
||||||
truncate=True,
|
|
||||||
icon=ui.ICON_RECEIVE,
|
icon=ui.ICON_RECEIVE,
|
||||||
icon_color=ui.RED,
|
icon_color=ui.RED,
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
|
Loading…
Reference in New Issue
Block a user