1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

PinDialog -> PinMatrix, shuffle digits

This commit is contained in:
Jan Pochyla 2016-06-01 19:31:22 +02:00 committed by Pavol Rusnak
parent 35b26651ba
commit 9232c77529
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 49 additions and 49 deletions

View File

@ -1,7 +1,6 @@
from trezor import loop from trezor import loop
from trezor import ui from trezor import ui
from trezor import msg from trezor import msg
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
from trezor.utils import unimport_gen from trezor.utils import unimport_gen
from trezor.res import loadres from trezor.res import loadres
@ -45,7 +44,7 @@ def layout_tap_to_confirm(address, amount, currency):
from trezor.messages.PublicKey import PublicKey from trezor.messages.PublicKey import PublicKey
from trezor.messages.HDNodeType import HDNodeType from trezor.messages.HDNodeType import HDNodeType
m = yield from msg.read_msg(Initialize) m = yield from msg.read(Initialize)
print('Initialize') print('Initialize')
m = Features() m = Features()

View File

@ -1,25 +1,43 @@
from trezor import wire from trezor import wire
from trezor import ui
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
from trezor.utils import unimport_gen from trezor.utils import unimport_gen
@unimport_gen
def request_pin():
from trezor.ui.pin import PinMatrix
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import ProtectCall
from trezor.messages.ButtonAck import ButtonAck
matrix = PinMatrix()
dialog = ConfirmDialog(matrix)
dialog.render()
ack = yield from wire.call(ButtonRequest(code=ProtectCall), ButtonAck)
res = yield from dialog.wait()
return matrix.pin if res == CONFIRMED else None
@unimport_gen @unimport_gen
def layout_get_public_key(message): def layout_get_public_key(message):
confirm = Button((0, 0, 240, 240), 'Export public key?', pin = yield from request_pin()
normal_style=CONFIRM_BUTTON,
active_style=CONFIRM_BUTTON_ACTIVE)
yield from confirm.wait()
from trezor.messages.PublicKey import PublicKey if pin is not None:
from trezor.messages.HDNodeType import HDNodeType from trezor.messages.PublicKey import PublicKey
from trezor.messages.HDNodeType import HDNodeType
pubkey = PublicKey()
pubkey.node = HDNodeType()
pubkey.node.depth = 0
pubkey.node.child_num = 0
pubkey.node.fingerprint = 0
pubkey.node.chain_code = 'deadbeef'
pubkey.node.public_key = 'deadbeef'
wire.write(pubkey)
pubkey = PublicKey() else:
pubkey.node = HDNodeType() from trezor.messages.Failure import Failure
pubkey.node.depth = 0 from trezor.messages.FailureType import ActionCancelled
pubkey.node.child_num = 0 wire.write(Failure(message='Cancelled', code=ActionCancelled))
pubkey.node.fingerprint = 0
pubkey.node.chain_code = 'deadbeef'
pubkey.node.public_key = 'deadbeef'
wire.write_msg(pubkey)

View File

@ -1,53 +1,36 @@
from trezor import loop
from trezor.crypto import random
from .button import Button, BTN_CLICKED from .button import Button, BTN_CLICKED
from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE
from trezor import loop
def digit_area(d): def digit_area(i):
width = const(80) width = const(80)
height = const(60) height = const(60)
x = ((d - 1) % 3) * width x = (i % 3) * width
y = ((d - 1) // 3) * height y = (i // 3) * height
return (x, y, width, height) return (x, y, width, height)
PIN_CONFIRMED = const(1) def generate_digits():
PIN_CANCELLED = const(2) digits = list(range(1, 10)) # 1-9
random.shuffle(digits)
return digits
class PinDialog(): class PinMatrix():
def __init__(self, pin=''): def __init__(self, pin=''):
self.pin = pin self.pin = pin
self.confirm_button = Button((0, 240 - 60, 120, 60), 'Confirm', self.buttons = [Button(digit_area(i), str(d))
normal_style=CONFIRM_BUTTON, for i, d in enumerate(generate_digits())]
active_style=CONFIRM_BUTTON_ACTIVE)
self.cancel_button = Button((120, 240 - 60, 120, 60), 'Cancel',
normal_style=CANCEL_BUTTON,
active_style=CANCEL_BUTTON_ACTIVE)
self.pin_buttons = [Button(digit_area(dig), str(dig))
for dig in range(1, 10)]
def render(self): def render(self):
for btn in self.pin_buttons: for btn in self.buttons:
btn.render() btn.render()
self.confirm_button.render()
self.cancel_button.render()
def send(self, event, pos): def send(self, event, pos):
for btn in self.pin_buttons: for btn in self.buttons:
if btn.send(event, pos) == BTN_CLICKED: if btn.send(event, pos) == BTN_CLICKED:
self.pin += btn.text self.pin += btn.text
if self.confirm_button.send(event, pos) == BTN_CLICKED:
return PIN_CONFIRMED
if self.cancel_button.send(event, pos) == BTN_CLICKED:
return PIN_CANCELLED
def wait(self):
while True:
self.render()
event, *pos = yield loop.Select(loop.TOUCH)
result = self.send(event, pos)
if result is not None:
return result