1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00
trezor-firmware/src/apps/common/request_pin.py

38 lines
1.1 KiB
Python
Raw Normal View History

2016-06-09 14:28:34 +00:00
from trezor import ui
from trezor import wire
from trezor.utils import unimport
@unimport
async def request_pin(session_id, *args, **kwargs):
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import ProtectCall
from trezor.messages.FailureType import PinCancelled
from trezor.messages.wire_types import ButtonAck
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
from trezor.ui.pin import PinMatrix
2016-06-09 14:28:34 +00:00
await wire.reply_message(session_id,
ButtonRequest(code=ProtectCall),
ButtonAck)
2016-06-09 14:28:34 +00:00
ui.display.clear()
2016-06-09 14:28:34 +00:00
matrix = PinMatrix(*args, **kwargs)
dialog = ConfirmDialog(matrix)
if await dialog != CONFIRMED:
raise wire.FailureError(PinCancelled, 'PIN cancelled')
2016-06-09 14:28:34 +00:00
return matrix.pin
2016-06-09 14:28:34 +00:00
@unimport
async def request_pin_twice(session_id):
2016-06-09 14:28:34 +00:00
from trezor.messages.FailureType import PinInvalid
pin_first = await request_pin(session_id)
pin_again = await request_pin(session_id, 'Enter PIN again')
if pin_first != pin_again:
raise wire.FailureError(PinInvalid, 'PIN invalid')
return pin_first