mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-26 16:18:22 +00:00
refactor(core): turn show_address, show_pubkey, show_xpub into layouts
This commit is contained in:
parent
03699f5639
commit
391602ae99
@ -1,9 +1,10 @@
|
||||
from trezor.messages.BinanceAddress import BinanceAddress
|
||||
from trezor.messages.BinanceGetAddress import BinanceGetAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import Keychain, auto_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from .helpers import address_from_public_key
|
||||
|
||||
@ -19,10 +20,6 @@ async def get_address(ctx, msg: BinanceGetAddress, keychain: Keychain):
|
||||
address = address_from_public_key(pubkey, HRP)
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address, desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address, desc=desc)
|
||||
|
||||
return BinanceAddress(address=address)
|
||||
|
@ -1,7 +1,10 @@
|
||||
from ubinascii import hexlify
|
||||
|
||||
from trezor.messages.BinanceGetPublicKey import BinanceGetPublicKey
|
||||
from trezor.messages.BinancePublicKey import BinancePublicKey
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
|
||||
from apps.common import layout, paths
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import Keychain, auto_keychain
|
||||
|
||||
|
||||
@ -12,6 +15,6 @@ async def get_public_key(ctx, msg: BinanceGetPublicKey, keychain: Keychain):
|
||||
pubkey = node.public_key()
|
||||
|
||||
if msg.show_display:
|
||||
await layout.show_pubkey(ctx, pubkey)
|
||||
await require(show_pubkey(ctx, hexlify(pubkey).decode()))
|
||||
|
||||
return BinancePublicKey(public_key=pubkey)
|
||||
|
@ -2,8 +2,9 @@ from trezor import wire
|
||||
from trezor.messages import InputScriptType
|
||||
from trezor.messages.HDNodeType import HDNodeType
|
||||
from trezor.messages.PublicKey import PublicKey
|
||||
from trezor.ui.layouts import require, show_xpub
|
||||
|
||||
from apps.common import coins, layout, paths
|
||||
from apps.common import coins, paths
|
||||
from apps.common.keychain import get_keychain
|
||||
|
||||
if False:
|
||||
@ -58,7 +59,7 @@ async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:
|
||||
)
|
||||
|
||||
if msg.show_display:
|
||||
await layout.show_xpub(ctx, node_xpub, "XPUB", "Cancel")
|
||||
await require(show_xpub(ctx, node_xpub, "XPUB", "Cancel"))
|
||||
|
||||
return PublicKey(
|
||||
node=node_type,
|
||||
|
@ -3,8 +3,9 @@ from ubinascii import hexlify
|
||||
from trezor import log, wire
|
||||
from trezor.messages.CardanoPublicKey import CardanoPublicKey
|
||||
from trezor.messages.HDNodeType import HDNodeType
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
|
||||
from apps.common import layout, paths
|
||||
from apps.common import paths
|
||||
from apps.common.seed import remove_ed25519_prefix
|
||||
|
||||
from . import seed
|
||||
@ -35,7 +36,7 @@ async def get_public_key(
|
||||
raise wire.ProcessError("Deriving public key failed")
|
||||
|
||||
if msg.show_display:
|
||||
await layout.show_pubkey(ctx, key.node.public_key)
|
||||
await require(show_pubkey(ctx, hexlify(key.node.public_key).decode()))
|
||||
return key
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
from micropython import const
|
||||
from ubinascii import hexlify
|
||||
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType
|
||||
@ -11,34 +10,13 @@ from trezor.ui.qr import Qr
|
||||
from trezor.utils import chunks
|
||||
|
||||
from apps.common import HARDENED
|
||||
from apps.common.confirm import confirm, require_confirm
|
||||
from apps.common.confirm import confirm
|
||||
|
||||
if False:
|
||||
from typing import Iterable, Iterator, List, Union
|
||||
from trezor import wire
|
||||
|
||||
|
||||
async def show_address(
|
||||
ctx: wire.Context,
|
||||
address: str,
|
||||
desc: str = "Confirm address",
|
||||
cancel: str = "QR",
|
||||
network: str = None,
|
||||
) -> bool:
|
||||
text = Text(desc, ui.ICON_RECEIVE, ui.GREEN)
|
||||
if network is not None:
|
||||
text.normal("%s network" % network)
|
||||
text.mono(*split_address(address))
|
||||
|
||||
return await confirm(
|
||||
ctx,
|
||||
text,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel=cancel,
|
||||
cancel_style=ButtonDefault,
|
||||
)
|
||||
|
||||
|
||||
async def show_qr(
|
||||
ctx: wire.Context,
|
||||
address: str,
|
||||
@ -62,13 +40,6 @@ async def show_qr(
|
||||
)
|
||||
|
||||
|
||||
async def show_pubkey(ctx: wire.Context, pubkey: bytes) -> None:
|
||||
lines = chunks(hexlify(pubkey).decode(), 18)
|
||||
text = Text("Confirm public key", ui.ICON_RECEIVE, ui.GREEN)
|
||||
text.mono(*lines)
|
||||
await require_confirm(ctx, text, ButtonRequestType.PublicKey)
|
||||
|
||||
|
||||
def split_address(address: str) -> Iterator[str]:
|
||||
return chunks(address, 17)
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.crypto.hashlib import sha3_256
|
||||
from trezor.messages.EthereumAddress import EthereumAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from . import networks
|
||||
from .address import address_from_bytes
|
||||
@ -27,10 +28,6 @@ async def get_address(ctx, msg, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address, desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address, desc=desc)
|
||||
|
||||
return EthereumAddress(address=address)
|
||||
|
@ -1,7 +1,10 @@
|
||||
from ubinascii import hexlify
|
||||
|
||||
from trezor.messages.EthereumPublicKey import EthereumPublicKey
|
||||
from trezor.messages.HDNodeType import HDNodeType
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
|
||||
from apps.common import coins, layout, paths
|
||||
from apps.common import coins, paths
|
||||
|
||||
from .keychain import with_keychain_from_path
|
||||
|
||||
@ -27,6 +30,6 @@ async def get_public_key(ctx, msg, keychain):
|
||||
)
|
||||
|
||||
if msg.show_display:
|
||||
await layout.show_pubkey(ctx, pubkey)
|
||||
await require(show_pubkey(ctx, hexlify(pubkey).decode()))
|
||||
|
||||
return EthereumPublicKey(node=node_type, xpub=node_xpub)
|
||||
|
@ -1,8 +1,9 @@
|
||||
from trezor.messages.LiskAddress import LiskAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import auto_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from .helpers import get_address_from_public_key
|
||||
|
||||
@ -18,10 +19,6 @@ async def get_address(ctx, msg, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address, desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address, desc=desc)
|
||||
|
||||
return LiskAddress(address=address)
|
||||
|
@ -1,6 +1,9 @@
|
||||
from trezor.messages.LiskPublicKey import LiskPublicKey
|
||||
from ubinascii import hexlify
|
||||
|
||||
from apps.common import layout, paths
|
||||
from trezor.messages.LiskPublicKey import LiskPublicKey
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import auto_keychain
|
||||
|
||||
|
||||
@ -13,6 +16,6 @@ async def get_public_key(ctx, msg, keychain):
|
||||
pubkey = pubkey[1:] # skip ed25519 pubkey marker
|
||||
|
||||
if msg.show_display:
|
||||
await layout.show_pubkey(ctx, pubkey)
|
||||
await require(show_pubkey(ctx, hexlify(pubkey).decode()))
|
||||
|
||||
return LiskPublicKey(public_key=pubkey)
|
||||
|
@ -1,11 +1,14 @@
|
||||
from ubinascii import hexlify
|
||||
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.strings import format_amount
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
from trezor.utils import chunks
|
||||
|
||||
from apps.common.confirm import require_confirm, require_hold_to_confirm
|
||||
from apps.common.layout import show_pubkey, split_address
|
||||
from apps.common.layout import split_address
|
||||
|
||||
from .helpers import get_vote_tx_text
|
||||
|
||||
@ -33,7 +36,7 @@ async def require_confirm_vote_tx(ctx, votes):
|
||||
|
||||
|
||||
async def require_confirm_public_key(ctx, public_key):
|
||||
return await show_pubkey(ctx, public_key)
|
||||
return await require(show_pubkey(ctx, hexlify(public_key).decode()))
|
||||
|
||||
|
||||
async def require_confirm_multisig(ctx, multisignature):
|
||||
|
@ -1,7 +1,8 @@
|
||||
from trezor.messages.NEMAddress import NEMAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common.keychain import with_slip44_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
from apps.common.paths import validate_path
|
||||
|
||||
from . import CURVE, PATTERNS, SLIP44_ID
|
||||
@ -21,12 +22,12 @@ async def get_address(ctx, msg, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(
|
||||
ctx, address, desc=desc, network=get_network_str(network)
|
||||
):
|
||||
break
|
||||
if await show_qr(ctx, address.upper(), desc=desc):
|
||||
break
|
||||
await show_address(
|
||||
ctx,
|
||||
address=address,
|
||||
address_qr=address.upper(),
|
||||
desc=desc,
|
||||
network=get_network_str(network),
|
||||
)
|
||||
|
||||
return NEMAddress(address=address)
|
||||
|
@ -11,7 +11,8 @@ from trezor.messages import (
|
||||
from trezor.ui.components.tt.scroll import Paginated
|
||||
from trezor.ui.components.tt.text import Text
|
||||
|
||||
from apps.common.layout import require_confirm, split_address
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.layout import split_address
|
||||
|
||||
from ..layout import (
|
||||
require_confirm_content,
|
||||
|
@ -1,9 +1,10 @@
|
||||
from trezor.messages.RippleAddress import RippleAddress
|
||||
from trezor.messages.RippleGetAddress import RippleGetAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import auto_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from .helpers import address_from_public_key
|
||||
|
||||
@ -18,10 +19,6 @@ async def get_address(ctx, msg: RippleGetAddress, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address, desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address, desc=desc)
|
||||
|
||||
return RippleAddress(address=address)
|
||||
|
@ -1,9 +1,10 @@
|
||||
from trezor.messages.StellarAddress import StellarAddress
|
||||
from trezor.messages.StellarGetAddress import StellarGetAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths, seed
|
||||
from apps.common.keychain import auto_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from . import helpers
|
||||
|
||||
@ -18,10 +19,6 @@ async def get_address(ctx, msg: StellarGetAddress, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address.upper(), desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address.upper(), desc=desc)
|
||||
|
||||
return StellarAddress(address=address)
|
||||
|
@ -1,9 +1,10 @@
|
||||
from trezor.crypto import hashlib
|
||||
from trezor.messages.TezosAddress import TezosAddress
|
||||
from trezor.ui.layouts import show_address
|
||||
|
||||
from apps.common import paths, seed
|
||||
from apps.common.keychain import with_slip44_keychain
|
||||
from apps.common.layout import address_n_to_str, show_address, show_qr
|
||||
from apps.common.layout import address_n_to_str
|
||||
|
||||
from . import CURVE, PATTERNS, SLIP44_ID, helpers
|
||||
|
||||
@ -22,10 +23,6 @@ async def get_address(ctx, msg, keychain):
|
||||
|
||||
if msg.show_display:
|
||||
desc = address_n_to_str(msg.address_n)
|
||||
while True:
|
||||
if await show_address(ctx, address, desc=desc):
|
||||
break
|
||||
if await show_qr(ctx, address, desc=desc):
|
||||
break
|
||||
await show_address(ctx, address=address, address_qr=address, desc=desc)
|
||||
|
||||
return TezosAddress(address=address)
|
||||
|
@ -1,11 +1,7 @@
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.TezosPublicKey import TezosPublicKey
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.utils import chunks
|
||||
from trezor.ui.layouts import require, show_pubkey
|
||||
|
||||
from apps.common import paths, seed
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.keychain import with_slip44_keychain
|
||||
|
||||
from . import CURVE, PATTERNS, SLIP44_ID, helpers
|
||||
@ -20,13 +16,6 @@ async def get_public_key(ctx, msg, keychain):
|
||||
pk_prefixed = helpers.base58_encode_check(pk, prefix=helpers.TEZOS_PUBLICKEY_PREFIX)
|
||||
|
||||
if msg.show_display:
|
||||
await _show_tezos_pubkey(ctx, pk_prefixed)
|
||||
await require(show_pubkey(ctx, pk_prefixed))
|
||||
|
||||
return TezosPublicKey(public_key=pk_prefixed)
|
||||
|
||||
|
||||
async def _show_tezos_pubkey(ctx, pubkey):
|
||||
lines = chunks(pubkey, 18)
|
||||
text = Text("Confirm public key", ui.ICON_RECEIVE, ui.GREEN)
|
||||
text.mono(*lines)
|
||||
await require_confirm(ctx, text, code=ButtonRequestType.PublicKey)
|
||||
|
@ -39,7 +39,9 @@ __all__ = (
|
||||
"confirm_backup",
|
||||
"confirm_path_warning",
|
||||
"show_address",
|
||||
"show_pubkey",
|
||||
"show_success",
|
||||
"show_xpub",
|
||||
"show_warning",
|
||||
"confirm_output",
|
||||
"confirm_hex",
|
||||
@ -199,6 +201,14 @@ def _show_xpub(xpub: str, desc: str, cancel: str) -> Paginated:
|
||||
return content
|
||||
|
||||
|
||||
def show_xpub(
|
||||
ctx: wire.GenericContext, xpub: str, desc: str, cancel: str
|
||||
) -> LayoutType:
|
||||
return interact(
|
||||
ctx, _show_xpub(xpub, desc, cancel), "show_xpub", ButtonRequestType.PublicKey
|
||||
)
|
||||
|
||||
|
||||
async def show_address(
|
||||
ctx: wire.GenericContext,
|
||||
address: str,
|
||||
@ -252,6 +262,16 @@ async def show_address(
|
||||
return
|
||||
|
||||
|
||||
# FIXME: this is basically same as confirm_hex
|
||||
# TODO: pagination for long keys
|
||||
def show_pubkey(
|
||||
ctx: wire.Context, pubkey: str, title: str = "Confirm public key"
|
||||
) -> LayoutType:
|
||||
text = Text(title, ui.ICON_RECEIVE, ui.GREEN)
|
||||
text.mono(*_hex_lines(pubkey))
|
||||
return interact(ctx, Confirm(text), "show_pubkey", ButtonRequestType.PublicKey)
|
||||
|
||||
|
||||
def show_warning(
|
||||
ctx: wire.GenericContext,
|
||||
br_type: str,
|
||||
|
Loading…
Reference in New Issue
Block a user