diff --git a/core/src/apps/misc/cipher_key_value.py b/core/src/apps/misc/cipher_key_value.py index b88d5055df..83d65a67e3 100644 --- a/core/src/apps/misc/cipher_key_value.py +++ b/core/src/apps/misc/cipher_key_value.py @@ -1,9 +1,8 @@ from trezor import wire from trezor.crypto import aes, hmac from trezor.messages.CipheredKeyValue import CipheredKeyValue -from trezor.ui.components.tt.text import Text +from trezor.ui.layouts import confirm_action, require -from apps.common.confirm import require_confirm from apps.common.keychain import get_keychain from apps.common.paths import AlwaysMatchingSchema @@ -28,9 +27,9 @@ async def cipher_key_value(ctx: Context, msg: CipherKeyValue) -> CipheredKeyValu title = "Encrypt value" else: title = "Decrypt value" - text = Text(title) - text.normal(msg.key) - await require_confirm(ctx, text) + await require( + confirm_action(ctx, "cipher_key_value", title, description=msg.key) + ) node = keychain.derive(msg.address_n) value = compute_cipher_key_value(msg, node.private_key()) diff --git a/core/src/apps/misc/get_ecdh_session_key.py b/core/src/apps/misc/get_ecdh_session_key.py index da6692797e..06f76379cb 100644 --- a/core/src/apps/misc/get_ecdh_session_key.py +++ b/core/src/apps/misc/get_ecdh_session_key.py @@ -1,13 +1,11 @@ from ustruct import pack, unpack -from trezor import wire +from trezor import ui, wire from trezor.crypto.hashlib import sha256 from trezor.messages.ECDHSessionKey import ECDHSessionKey -from trezor.ui.components.tt.text import Text -from trezor.utils import chunks +from trezor.ui.layouts import confirm_hex, require from apps.common import HARDENED -from apps.common.confirm import require_confirm from apps.common.keychain import get_keychain from apps.common.paths import AlwaysMatchingSchema @@ -48,11 +46,17 @@ async def get_ecdh_session_key( async def require_confirm_ecdh_session_key( ctx: wire.Context, identity: IdentityType ) -> None: - lines = chunks(serialize_identity_without_proto(identity), 18) proto = identity.proto.upper() if identity.proto else "identity" - text = Text("Decrypt %s" % proto) - text.mono(*lines) - await require_confirm(ctx, text) + await require( + confirm_hex( + ctx, + "ecdh_session_key", + "Decrypt %s" % proto, + serialize_identity_without_proto(identity), + icon=ui.ICON_DEFAULT, + icon_color=ui.ORANGE_ICON, + ) + ) def get_ecdh_path(identity: str, index: int) -> Bip32Path: diff --git a/core/src/apps/misc/get_entropy.py b/core/src/apps/misc/get_entropy.py index 11d1b6346f..86dfa76e83 100644 --- a/core/src/apps/misc/get_entropy.py +++ b/core/src/apps/misc/get_entropy.py @@ -1,9 +1,7 @@ from trezor.crypto import random from trezor.messages import ButtonRequestType from trezor.messages.Entropy import Entropy -from trezor.ui.components.tt.text import Text - -from apps.common.confirm import require_confirm +from trezor.ui.layouts import confirm_action, require if False: from trezor.wire import Context @@ -11,10 +9,16 @@ if False: async def get_entropy(ctx: Context, msg: GetEntropy) -> Entropy: - text = Text("Confirm entropy") - text.bold("Do you really want", "to send entropy?") - text.normal("Continue only if you", "know what you are doing!") - await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall) + await require( + confirm_action( + ctx, + "get_entropy", + "Confirm entropy", + action="Do you really want\nto send entropy?", + description="Continue only if you\nknow what you are doing!", + br_code=ButtonRequestType.ProtectCall, + ) + ) size = min(msg.size, 1024) entropy = random.bytes(size) diff --git a/core/src/apps/misc/sign_identity.py b/core/src/apps/misc/sign_identity.py index fc8945b0d8..80f74270b7 100644 --- a/core/src/apps/misc/sign_identity.py +++ b/core/src/apps/misc/sign_identity.py @@ -1,22 +1,19 @@ from ustruct import pack, unpack -from trezor import ui, wire +from trezor import wire from trezor.crypto.hashlib import sha256 from trezor.messages.SignedIdentity import SignedIdentity -from trezor.ui.components.tt.text import Text -from trezor.utils import chunks +from trezor.ui.layouts import confirm_sign_identity, require from apps.common import HARDENED, coininfo -from apps.common.confirm import require_confirm from apps.common.keychain import get_keychain from apps.common.paths import AlwaysMatchingSchema if False: - from typing import List, Optional, Union + from typing import Optional, Union from trezor.messages.IdentityType import IdentityType from trezor.messages.SignIdentity import SignIdentity - from trezor.ui.components.common.text import TextContent from apps.common.paths import Bip32Path @@ -86,17 +83,12 @@ async def sign_identity(ctx: wire.Context, msg: SignIdentity) -> SignedIdentity: async def require_confirm_sign_identity( ctx: wire.Context, identity: IdentityType, challenge_visual: Optional[str] ) -> None: - lines: List[TextContent] = [] - if challenge_visual: - lines.append(challenge_visual) - - lines.append(ui.MONO) - lines.extend(chunks(serialize_identity_without_proto(identity), 18)) - proto = identity.proto.upper() if identity.proto else "identity" - text = Text("Sign %s" % proto) - text.normal(*lines) - await require_confirm(ctx, text) + await require( + confirm_sign_identity( + ctx, proto, serialize_identity_without_proto(identity), challenge_visual + ) + ) def serialize_identity(identity: IdentityType) -> str: diff --git a/core/src/trezor/ui/layouts/tt.py b/core/src/trezor/ui/layouts/tt.py index cff99796fd..019ef88306 100644 --- a/core/src/trezor/ui/layouts/tt.py +++ b/core/src/trezor/ui/layouts/tt.py @@ -29,6 +29,7 @@ if False: from trezor import wire from trezor.messages.ButtonRequest import EnumTypeButtonRequestType + from ..components.common.text import TextContent __all__ = ( "confirm_action", @@ -36,6 +37,7 @@ __all__ = ( "confirm_reset_device", "confirm_backup", "confirm_path_warning", + "confirm_sign_identity", "show_address", "show_error", "show_pubkey", @@ -567,3 +569,21 @@ async def confirm_modify_fee( return is_confirmed( await interact(ctx, HoldToConfirm(text), "modify_fee", ButtonRequestType.SignTx) ) + + +# TODO cleanup @ redesign +async def confirm_sign_identity( + ctx: wire.GenericContext, proto: str, identity: str, challenge_visual: Optional[str] +) -> bool: + lines: List[TextContent] = [] + if challenge_visual: + lines.append(challenge_visual) + + lines.append(ui.MONO) + lines.extend(chunks(identity, 18)) + + text = Text("Sign %s" % proto) + text.normal(*lines) + return is_confirmed( + await interact(ctx, Confirm(text), "sign_identity", ButtonRequestType.Other) + )