2016-06-09 14:28:34 +00:00
|
|
|
from trezor import ui
|
2016-06-06 12:10:36 +00:00
|
|
|
from trezor import wire
|
2016-09-21 12:24:12 +00:00
|
|
|
from trezor.utils import unimport
|
2016-06-06 12:10:36 +00:00
|
|
|
|
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
@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
|
2016-06-06 12:10:36 +00:00
|
|
|
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
|
2016-09-25 14:00:21 +00:00
|
|
|
from trezor.ui.pin import PinMatrix
|
2016-06-09 14:28:34 +00:00
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
await wire.reply_message(session_id,
|
|
|
|
ButtonRequest(code=ProtectCall),
|
|
|
|
ButtonAck)
|
2016-06-09 14:28:34 +00:00
|
|
|
|
2016-10-06 10:31:03 +00:00
|
|
|
ui.display.clear()
|
2016-06-09 14:28:34 +00:00
|
|
|
matrix = PinMatrix(*args, **kwargs)
|
|
|
|
dialog = ConfirmDialog(matrix)
|
2016-09-25 14:00:21 +00:00
|
|
|
if await dialog != CONFIRMED:
|
|
|
|
raise wire.FailureError(PinCancelled, 'PIN cancelled')
|
2016-06-09 14:28:34 +00:00
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
return matrix.pin
|
2016-06-09 14:28:34 +00:00
|
|
|
|
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
@unimport
|
2016-09-26 14:11:38 +00:00
|
|
|
async def request_pin_twice(session_id):
|
2016-06-09 14:28:34 +00:00
|
|
|
from trezor.messages.FailureType import PinInvalid
|
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
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')
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2016-09-25 14:00:21 +00:00
|
|
|
return pin_first
|