From e13a3a70c871eb9dc16c817a39b04d7b8b978959 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Tue, 21 Aug 2018 10:21:39 +0200 Subject: [PATCH] common: show pubkey moved to common --- src/apps/common/display_address.py | 9 +++++++++ src/apps/lisk/get_public_key.py | 5 ++--- src/apps/lisk/layout.py | 4 ++-- src/apps/wallet/get_public_key.py | 18 ++---------------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/apps/common/display_address.py b/src/apps/common/display_address.py index 195e8a37b0..cdb7eae753 100644 --- a/src/apps/common/display_address.py +++ b/src/apps/common/display_address.py @@ -1,4 +1,5 @@ from micropython import const +from ubinascii import hexlify from trezor import ui from trezor.messages import ButtonRequestType @@ -8,6 +9,7 @@ from trezor.ui.text import Text from trezor.utils import chunks from apps.common.confirm import confirm +from apps.common.confirm import require_confirm async def show_address(ctx, address: str): @@ -38,3 +40,10 @@ async def show_qr(ctx, address: str): def split_address(address: str): return chunks(address, 17) + + +async def show_pubkey(ctx, pubkey: bytes): + lines = chunks(hexlify(pubkey).decode(), 18) + text = Text("Confirm public key", ui.ICON_RECEIVE, icon_color=ui.GREEN) + text.mono(*lines) + return await require_confirm(ctx, text, code=ButtonRequestType.PublicKey) diff --git a/src/apps/lisk/get_public_key.py b/src/apps/lisk/get_public_key.py index 7fa55e49aa..66b97c27c7 100644 --- a/src/apps/lisk/get_public_key.py +++ b/src/apps/lisk/get_public_key.py @@ -2,8 +2,7 @@ from trezor.messages.LiskPublicKey import LiskPublicKey from .helpers import LISK_CURVE -from apps.common import seed -from apps.wallet.get_public_key import _show_pubkey +from apps.common import seed, display_address async def lisk_get_public_key(ctx, msg): @@ -14,6 +13,6 @@ async def lisk_get_public_key(ctx, msg): pubkey = pubkey[1:] # skip ed25519 pubkey marker if msg.show_display: - await _show_pubkey(ctx, pubkey) + await display_address.show_pubkey(ctx, pubkey) return LiskPublicKey(public_key=pubkey) diff --git a/src/apps/lisk/layout.py b/src/apps/lisk/layout.py index 359a8b8d00..14b55ba57e 100644 --- a/src/apps/lisk/layout.py +++ b/src/apps/lisk/layout.py @@ -6,7 +6,7 @@ from trezor.utils import chunks from .helpers import get_vote_tx_text from apps.common.confirm import require_confirm, require_hold_to_confirm -from apps.wallet.get_public_key import _show_pubkey +from apps.common.display_address import show_pubkey async def require_confirm_tx(ctx, to, value): @@ -32,7 +32,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 show_pubkey(ctx, public_key) async def require_confirm_multisig(ctx, multisignature): diff --git a/src/apps/wallet/get_public_key.py b/src/apps/wallet/get_public_key.py index 2b948dcaa8..ed590b22d0 100644 --- a/src/apps/wallet/get_public_key.py +++ b/src/apps/wallet/get_public_key.py @@ -1,14 +1,7 @@ -from ubinascii import hexlify - -from trezor import ui -from trezor.messages import ButtonRequestType from trezor.messages.HDNodeType import HDNodeType from trezor.messages.PublicKey import PublicKey -from trezor.ui.text import Text -from trezor.utils import chunks -from apps.common import coins, seed -from apps.common.confirm import require_confirm +from apps.common import coins, seed, display_address async def get_public_key(ctx, msg): @@ -33,13 +26,6 @@ async def get_public_key(ctx, msg): ) if msg.show_display: - await _show_pubkey(ctx, pubkey) + await display_address.show_pubkey(ctx, pubkey) return PublicKey(node=node_type, xpub=node_xpub) - - -async def _show_pubkey(ctx, pubkey: bytes): - lines = chunks(hexlify(pubkey).decode(), 18) - text = Text("Confirm public key", ui.ICON_RECEIVE, icon_color=ui.GREEN) - text.mono(*lines) - return await require_confirm(ctx, text, code=ButtonRequestType.PublicKey)