mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-24 12:05:44 +00:00
refactor(core): convert apps.misc.* to layouts
This commit is contained in:
parent
0b5d17bf49
commit
c09a142e2a
@ -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())
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user