mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
PinDialog -> PinMatrix, shuffle digits
This commit is contained in:
parent
35b26651ba
commit
9232c77529
@ -1,7 +1,6 @@
|
||||
from trezor import loop
|
||||
from trezor import ui
|
||||
from trezor import msg
|
||||
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
|
||||
from trezor.utils import unimport_gen
|
||||
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.HDNodeType import HDNodeType
|
||||
|
||||
m = yield from msg.read_msg(Initialize)
|
||||
m = yield from msg.read(Initialize)
|
||||
print('Initialize')
|
||||
|
||||
m = Features()
|
||||
|
@ -1,25 +1,43 @@
|
||||
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
|
||||
|
||||
|
||||
@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
|
||||
def layout_get_public_key(message):
|
||||
|
||||
confirm = Button((0, 0, 240, 240), 'Export public key?',
|
||||
normal_style=CONFIRM_BUTTON,
|
||||
active_style=CONFIRM_BUTTON_ACTIVE)
|
||||
yield from confirm.wait()
|
||||
pin = yield from request_pin()
|
||||
|
||||
from trezor.messages.PublicKey import PublicKey
|
||||
from trezor.messages.HDNodeType import HDNodeType
|
||||
if pin is not None:
|
||||
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()
|
||||
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_msg(pubkey)
|
||||
else:
|
||||
from trezor.messages.Failure import Failure
|
||||
from trezor.messages.FailureType import ActionCancelled
|
||||
wire.write(Failure(message='Cancelled', code=ActionCancelled))
|
||||
|
@ -1,53 +1,36 @@
|
||||
from trezor import loop
|
||||
from trezor.crypto import random
|
||||
from .button import Button, BTN_CLICKED
|
||||
from .button import CONFIRM_BUTTON, CONFIRM_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)
|
||||
height = const(60)
|
||||
x = ((d - 1) % 3) * width
|
||||
y = ((d - 1) // 3) * height
|
||||
x = (i % 3) * width
|
||||
y = (i // 3) * height
|
||||
return (x, y, width, height)
|
||||
|
||||
|
||||
PIN_CONFIRMED = const(1)
|
||||
PIN_CANCELLED = const(2)
|
||||
def generate_digits():
|
||||
digits = list(range(1, 10)) # 1-9
|
||||
random.shuffle(digits)
|
||||
return digits
|
||||
|
||||
|
||||
class PinDialog():
|
||||
class PinMatrix():
|
||||
|
||||
def __init__(self, pin=''):
|
||||
self.pin = pin
|
||||
self.confirm_button = Button((0, 240 - 60, 120, 60), 'Confirm',
|
||||
normal_style=CONFIRM_BUTTON,
|
||||
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)]
|
||||
self.buttons = [Button(digit_area(i), str(d))
|
||||
for i, d in enumerate(generate_digits())]
|
||||
|
||||
def render(self):
|
||||
for btn in self.pin_buttons:
|
||||
for btn in self.buttons:
|
||||
btn.render()
|
||||
self.confirm_button.render()
|
||||
self.cancel_button.render()
|
||||
|
||||
def send(self, event, pos):
|
||||
for btn in self.pin_buttons:
|
||||
for btn in self.buttons:
|
||||
if btn.send(event, pos) == BTN_CLICKED:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user