1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-10 14:42:44 +00:00
trezor-firmware/src/apps/homescreen/__init__.py

67 lines
2.2 KiB
Python
Raw Normal View History

from trezor import config
from trezor.utils import unimport, symbol, model
2018-02-27 15:35:21 +00:00
from trezor.wire import register, protobuf_workflow
from trezor.messages import wire_types
from trezor.messages.Features import Features
from trezor.messages.Success import Success
from apps.common import storage, coins, cache
2017-08-15 13:09:09 +00:00
async def respond_Features(ctx, msg):
if msg.__qualname__ == 'Initialize':
2018-03-01 02:06:33 +00:00
if msg.state is None or bytes(msg.state) != cache.get_state(state=bytes(msg.state)):
cache.clear()
f = Features()
2017-01-10 15:31:30 +00:00
f.vendor = 'trezor.io'
f.major_version = symbol('VERSION_MAJOR')
f.minor_version = symbol('VERSION_MINOR')
f.patch_version = symbol('VERSION_PATCH')
f.device_id = storage.get_device_id()
f.pin_protection = config.has_pin()
f.passphrase_protection = storage.has_passphrase()
f.language = 'english'
f.label = storage.get_label()
f.coins = coins.COINS
f.initialized = storage.is_initialized()
f.revision = symbol('GITREV')
f.pin_cached = config.has_pin()
f.passphrase_cached = cache.has_passphrase()
f.needs_backup = storage.needs_backup()
f.flags = storage.get_flags()
if model() in ['T', 'EMU']: # emulator currently emulates model T
f.model = 'T'
2016-11-15 10:51:28 +00:00
return f
2016-04-28 21:43:34 +00:00
2018-02-27 15:35:21 +00:00
async def respond_ClearSession(ctx, msg):
cache.clear()
return Success(message='Session cleared')
2016-12-15 11:48:33 +00:00
@unimport
2017-08-15 13:09:09 +00:00
async def respond_Pong(ctx, msg):
if msg.button_protection:
from apps.common.confirm import require_confirm
from trezor.messages.ButtonRequestType import ProtectCall
from trezor.ui.text import Text
from trezor import ui
await require_confirm(ctx, Text('Confirm', ui.ICON_DEFAULT), ProtectCall)
if msg.passphrase_protection:
from apps.common.request_passphrase import protect_by_passphrase
2017-08-15 13:09:09 +00:00
await protect_by_passphrase(ctx)
return Success(message=msg.message)
2016-04-28 21:43:34 +00:00
def boot():
2018-02-27 15:35:21 +00:00
register(wire_types.Initialize, protobuf_workflow, respond_Features)
register(wire_types.GetFeatures, protobuf_workflow, respond_Features)
register(wire_types.ClearSession, protobuf_workflow, respond_ClearSession)
register(wire_types.Ping, protobuf_workflow, respond_Pong)