async def handle_DoPreauthorized(ctx: wire.Context, msg: DoPreauthorized) -> protobuf.MessageType: authorization: Authorization = storage.cache.get( storage.cache.APP_BASE_AUTHORIZATION) if not authorization: raise wire.ProcessError("No preauthorized operation") req = await ctx.call_any(PreauthorizedRequest(), *authorization.expected_wire_types()) handler = wire.find_registered_workflow_handler(ctx.iface, req.MESSAGE_WIRE_TYPE) if handler is None: return wire.unexpected_message() return await handler(ctx, req, authorization) # type: ignore
def get_pinlocked_handler(iface: wire.WireInterface, msg_type: int) -> Optional[wire.Handler[wire.Msg]]: orig_handler = wire.find_registered_workflow_handler(iface, msg_type) if orig_handler is None: return None if __debug__: import usb if iface is usb.iface_debug: return orig_handler if msg_type in ALLOW_WHILE_LOCKED: return orig_handler async def wrapper(ctx: wire.Context, msg: wire.Msg) -> protobuf.MessageType: # mypy limitation: orig_handler is not recognized as non-None assert orig_handler is not None await unlock_device(ctx) return await orig_handler(ctx, msg) return wrapper