1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 16:48:09 +00:00
trezor-firmware/src/apps/common/request_passphrase.py

29 lines
856 B
Python
Raw Normal View History

2016-10-20 13:04:54 +00:00
from trezor import ui, wire
2017-08-15 13:09:09 +00:00
async def request_passphrase(ctx):
2017-01-24 13:10:36 +00:00
from trezor.messages.FailureType import ActionCancelled
2016-10-20 13:04:54 +00:00
from trezor.messages.PassphraseRequest import PassphraseRequest
2017-01-24 13:10:36 +00:00
from trezor.messages.wire_types import PassphraseAck, Cancel
2016-10-20 13:04:54 +00:00
from trezor.ui.text import Text
ui.display.clear()
text = Text('Enter passphrase', ui.ICON_RESET,
'Please enter passphrase', 'on your computer.')
text.render()
2017-08-15 13:09:09 +00:00
ack = await ctx.call(PassphraseRequest(), PassphraseAck, Cancel)
2017-01-24 13:10:36 +00:00
if ack.MESSAGE_WIRE_TYPE == Cancel:
raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
2016-10-20 13:04:54 +00:00
return ack.passphrase
2017-01-24 13:10:36 +00:00
2017-08-15 13:09:09 +00:00
async def protect_by_passphrase(ctx):
2017-01-24 13:10:36 +00:00
from apps.common import storage
if storage.is_protected_by_passphrase():
2017-08-15 13:09:09 +00:00
return await request_passphrase(ctx)
2017-01-24 13:10:36 +00:00
else:
return ''