1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 11:28:14 +00:00

src/app/wallet: sign identity ui

This commit is contained in:
Pavol Rusnak 2018-02-28 15:12:00 +01:00
parent ba870fbf9b
commit a38e57a31f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -2,6 +2,9 @@ from trezor import ui
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 ustruct import pack, unpack from ustruct import pack, unpack
from trezor.utils import chunks
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
from ..common import coins, seed from ..common import coins, seed
@ -11,7 +14,8 @@ async def sign_identity(ctx, msg):
msg.ecdsa_curve_name = 'secp256k1' msg.ecdsa_curve_name = 'secp256k1'
identity = serialize_identity(msg.identity) identity = serialize_identity(msg.identity)
display_identity(identity, msg.challenge_visual)
await confirm_sign_identity(ctx, identity, msg.challenge_visual)
address_n = get_identity_path(identity, msg.identity.index or 0) address_n = get_identity_path(identity, msg.identity.index or 0)
node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name) node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name)
@ -39,6 +43,14 @@ async def sign_identity(ctx, msg):
return SignedIdentity(address=address, public_key=pubkey, signature=signature) return SignedIdentity(address=address, public_key=pubkey, signature=signature)
async def confirm_sign_identity(ctx, identity, challenge_visual):
lines = chunks(identity, 18)
content = Text('Sign identity', ui.ICON_DEFAULT,
challenge_visual,
ui.MONO, *lines, max_lines=5)
await require_confirm(ctx, content)
def serialize_identity(identity): def serialize_identity(identity):
s = '' s = ''
if identity.proto: if identity.proto:
@ -54,14 +66,6 @@ def serialize_identity(identity):
return s return s
def display_identity(identity: str, challenge_visual: str):
ui.display.clear()
ui.display.text(10, 30, 'Identity:',
ui.BOLD, ui.LIGHT_GREEN, ui.BG)
ui.display.text(10, 60, challenge_visual, ui.MONO, ui.FG, ui.BG)
ui.display.text(10, 80, identity, ui.MONO, ui.FG, ui.BG)
def get_identity_path(identity: str, index: int): def get_identity_path(identity: str, index: int):
identity_hash = sha256(pack('<I', index) + identity).digest() identity_hash = sha256(pack('<I', index) + identity).digest()