mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-15 11:08:08 +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 import wire
|
||||||
from trezor.crypto import aes, hmac
|
from trezor.crypto import aes, hmac
|
||||||
from trezor.messages.CipheredKeyValue import CipheredKeyValue
|
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.keychain import get_keychain
|
||||||
from apps.common.paths import AlwaysMatchingSchema
|
from apps.common.paths import AlwaysMatchingSchema
|
||||||
|
|
||||||
@ -28,9 +27,9 @@ async def cipher_key_value(ctx: Context, msg: CipherKeyValue) -> CipheredKeyValu
|
|||||||
title = "Encrypt value"
|
title = "Encrypt value"
|
||||||
else:
|
else:
|
||||||
title = "Decrypt value"
|
title = "Decrypt value"
|
||||||
text = Text(title)
|
await require(
|
||||||
text.normal(msg.key)
|
confirm_action(ctx, "cipher_key_value", title, description=msg.key)
|
||||||
await require_confirm(ctx, text)
|
)
|
||||||
|
|
||||||
node = keychain.derive(msg.address_n)
|
node = keychain.derive(msg.address_n)
|
||||||
value = compute_cipher_key_value(msg, node.private_key())
|
value = compute_cipher_key_value(msg, node.private_key())
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
from ustruct import pack, unpack
|
from ustruct import pack, unpack
|
||||||
|
|
||||||
from trezor import wire
|
from trezor import ui, wire
|
||||||
from trezor.crypto.hashlib import sha256
|
from trezor.crypto.hashlib import sha256
|
||||||
from trezor.messages.ECDHSessionKey import ECDHSessionKey
|
from trezor.messages.ECDHSessionKey import ECDHSessionKey
|
||||||
from trezor.ui.components.tt.text import Text
|
from trezor.ui.layouts import confirm_hex, require
|
||||||
from trezor.utils import chunks
|
|
||||||
|
|
||||||
from apps.common import HARDENED
|
from apps.common import HARDENED
|
||||||
from apps.common.confirm import require_confirm
|
|
||||||
from apps.common.keychain import get_keychain
|
from apps.common.keychain import get_keychain
|
||||||
from apps.common.paths import AlwaysMatchingSchema
|
from apps.common.paths import AlwaysMatchingSchema
|
||||||
|
|
||||||
@ -48,11 +46,17 @@ async def get_ecdh_session_key(
|
|||||||
async def require_confirm_ecdh_session_key(
|
async def require_confirm_ecdh_session_key(
|
||||||
ctx: wire.Context, identity: IdentityType
|
ctx: wire.Context, identity: IdentityType
|
||||||
) -> None:
|
) -> None:
|
||||||
lines = chunks(serialize_identity_without_proto(identity), 18)
|
|
||||||
proto = identity.proto.upper() if identity.proto else "identity"
|
proto = identity.proto.upper() if identity.proto else "identity"
|
||||||
text = Text("Decrypt %s" % proto)
|
await require(
|
||||||
text.mono(*lines)
|
confirm_hex(
|
||||||
await require_confirm(ctx, text)
|
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:
|
def get_ecdh_path(identity: str, index: int) -> Bip32Path:
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
from trezor.crypto import random
|
from trezor.crypto import random
|
||||||
from trezor.messages import ButtonRequestType
|
from trezor.messages import ButtonRequestType
|
||||||
from trezor.messages.Entropy import Entropy
|
from trezor.messages.Entropy import Entropy
|
||||||
from trezor.ui.components.tt.text import Text
|
from trezor.ui.layouts import confirm_action, require
|
||||||
|
|
||||||
from apps.common.confirm import require_confirm
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from trezor.wire import Context
|
from trezor.wire import Context
|
||||||
@ -11,10 +9,16 @@ if False:
|
|||||||
|
|
||||||
|
|
||||||
async def get_entropy(ctx: Context, msg: GetEntropy) -> Entropy:
|
async def get_entropy(ctx: Context, msg: GetEntropy) -> Entropy:
|
||||||
text = Text("Confirm entropy")
|
await require(
|
||||||
text.bold("Do you really want", "to send entropy?")
|
confirm_action(
|
||||||
text.normal("Continue only if you", "know what you are doing!")
|
ctx,
|
||||||
await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall)
|
"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)
|
size = min(msg.size, 1024)
|
||||||
entropy = random.bytes(size)
|
entropy = random.bytes(size)
|
||||||
|
@ -1,22 +1,19 @@
|
|||||||
from ustruct import pack, unpack
|
from ustruct import pack, unpack
|
||||||
|
|
||||||
from trezor import ui, wire
|
from trezor import wire
|
||||||
from trezor.crypto.hashlib import sha256
|
from trezor.crypto.hashlib import sha256
|
||||||
from trezor.messages.SignedIdentity import SignedIdentity
|
from trezor.messages.SignedIdentity import SignedIdentity
|
||||||
from trezor.ui.components.tt.text import Text
|
from trezor.ui.layouts import confirm_sign_identity, require
|
||||||
from trezor.utils import chunks
|
|
||||||
|
|
||||||
from apps.common import HARDENED, coininfo
|
from apps.common import HARDENED, coininfo
|
||||||
from apps.common.confirm import require_confirm
|
|
||||||
from apps.common.keychain import get_keychain
|
from apps.common.keychain import get_keychain
|
||||||
from apps.common.paths import AlwaysMatchingSchema
|
from apps.common.paths import AlwaysMatchingSchema
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import List, Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
from trezor.messages.IdentityType import IdentityType
|
from trezor.messages.IdentityType import IdentityType
|
||||||
from trezor.messages.SignIdentity import SignIdentity
|
from trezor.messages.SignIdentity import SignIdentity
|
||||||
from trezor.ui.components.common.text import TextContent
|
|
||||||
|
|
||||||
from apps.common.paths import Bip32Path
|
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(
|
async def require_confirm_sign_identity(
|
||||||
ctx: wire.Context, identity: IdentityType, challenge_visual: Optional[str]
|
ctx: wire.Context, identity: IdentityType, challenge_visual: Optional[str]
|
||||||
) -> None:
|
) -> 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"
|
proto = identity.proto.upper() if identity.proto else "identity"
|
||||||
text = Text("Sign %s" % proto)
|
await require(
|
||||||
text.normal(*lines)
|
confirm_sign_identity(
|
||||||
await require_confirm(ctx, text)
|
ctx, proto, serialize_identity_without_proto(identity), challenge_visual
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def serialize_identity(identity: IdentityType) -> str:
|
def serialize_identity(identity: IdentityType) -> str:
|
||||||
|
@ -29,6 +29,7 @@ if False:
|
|||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor.messages.ButtonRequest import EnumTypeButtonRequestType
|
from trezor.messages.ButtonRequest import EnumTypeButtonRequestType
|
||||||
|
|
||||||
|
from ..components.common.text import TextContent
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
"confirm_action",
|
"confirm_action",
|
||||||
@ -36,6 +37,7 @@ __all__ = (
|
|||||||
"confirm_reset_device",
|
"confirm_reset_device",
|
||||||
"confirm_backup",
|
"confirm_backup",
|
||||||
"confirm_path_warning",
|
"confirm_path_warning",
|
||||||
|
"confirm_sign_identity",
|
||||||
"show_address",
|
"show_address",
|
||||||
"show_error",
|
"show_error",
|
||||||
"show_pubkey",
|
"show_pubkey",
|
||||||
@ -567,3 +569,21 @@ async def confirm_modify_fee(
|
|||||||
return is_confirmed(
|
return is_confirmed(
|
||||||
await interact(ctx, HoldToConfirm(text), "modify_fee", ButtonRequestType.SignTx)
|
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