From 1b8217ca669338cec9c1c8149a206d2d4d0c37d0 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 5 Mar 2018 17:58:28 +0100 Subject: [PATCH] src/apps/wallet: finish GetPublicKey UI --- src/apps/wallet/get_public_key.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/apps/wallet/get_public_key.py b/src/apps/wallet/get_public_key.py index 2ff144ac5..34dd69589 100644 --- a/src/apps/wallet/get_public_key.py +++ b/src/apps/wallet/get_public_key.py @@ -1,12 +1,22 @@ from trezor.messages.HDNodeType import HDNodeType from trezor.messages.PublicKey import PublicKey +from trezor import ui +from trezor.messages import ButtonRequestType +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 ubinascii import hexlify async def get_public_key(ctx, msg): coin_name = msg.coin_name or 'Bitcoin' - node = await seed.derive_node(ctx, msg.address_n) + curve_name = msg.ecdsa_curve_name + if not curve_name: + node = await seed.derive_node(ctx, msg.address_n) + else: + node = await seed.derive_node(ctx, msg.address_n, curve_name=curve_name) coin = coins.by_name(coin_name) node_xpub = node.serialize_public(coin.xpub_magic) @@ -16,4 +26,17 @@ async def get_public_key(ctx, msg): fingerprint=node.fingerprint(), chain_code=node.chain_code(), public_key=node.public_key()) + + if msg.show_display: + await _show_pubkey(ctx, node.public_key()) + return PublicKey(node=node_type, xpub=node_xpub) + + +async def _show_pubkey(ctx, pubkey: bytes): + lines = chunks(hexlify(pubkey).decode(), 18) + content = Text('Confirm public key', ui.ICON_RECEIVE, ui.MONO, *lines, icon_color=ui.GREEN) + return await require_confirm( + ctx, + content, + code=ButtonRequestType.PublicKey)