Case study

ThetaMask: one system, from device to cloud

Animation of the ThetaMask system assembling: the contract, then the phone app and mask firmware it defines, then the program creator, study tooling, backend and researcher portal, with a program moving to the mask and status and study data moving back.
The six parts and the contract, assembling. Programs move from authoring to the mask; status and study data come back.

ThetaMask is a light-based mask built for research studies. The first version, a sleep mask, was used in a study at the Donders Institute (Radboud University). v2 is a new device, developed for research with TNO.

I am one of three co-founders. I lead software and firmware. For v2 I designed and built the whole technical platform: the firmware on the mask, the phone app, the backend, a portal for researchers and the tool used to create light programs. This page is about how those parts fit together, and why they are built the way they are.

The system at a glance

Six running parts and one contract.

Program creator browser tool Study tooling sign + publish Backend Supabase: Postgres + edge functions pseudonymous and identifying data apart Researcher portal Next.js Contract one versioned spec Phone app Expo, BLE central Mask firmware Nordic nRF52, MCUboot program publish Postgres study bundle answers, sessions program status program format + BLE protocol
Programs flow from authoring to the mask; study data flows back from the phone to the backend. The portal never talks to the phone or the mask directly.

Why one contract. The app and the firmware are written in different languages and run on different devices, so nothing forces them to agree. The contract does: with one specification and shared test vectors, a mismatch fails a test on one side before it ever reaches a device. The app can also run against a simulated mask, so app work never waits on hardware.

Flow 1: a program's life

A light program goes from the creator, through signing and publishing, to the backend, to the phone, to the mask. Session data comes back the other way, and only the portal reads it out.

Program creator composes Study tooling signs, checks Backend stores, serves Phone app validates, sends Mask verifies, runs Portal exports Researcher piece publish bundle BLE live status answers, sessions reads CSV
The program only reaches the mask through the phone. The phone checks it before sending, and the mask has the final say.

Flow 2: how changes reach devices

App Firmware App code one profile per variant EAS Build variant baked in EAS Update OTA, per channel TestFlight iOS Android build APK or app bundle Phone app four build variants profile JS update iOS Android install install OTA: never participant builds Firmware code release build Signed image image signing key First flash before encasing Bluetooth DFU with rollback USB-C recovery the route back Mask bootloader checks every image build package image image debug cable BLE USB-C
Two independent release lanes. Firmware arrives by one of three routes, and all of them end at the same bootloader signature check.

Flow 3: the trust chain

enforced on the mask Program key private, outside the repo Study tooling signs Test key bench only Publish check full signature check Database Phone app sanity check Mask firmware the security boundary signs signed program test-signed Image signing key private, outside the repo Firmware build refuses wrong keys MCUboot checks every image key signed image Researcher portal mints token, keeps hash Phone app token, this device only Edge functions match the hash QR code bearer token
Three separate chains of trust: programs, firmware images and participants.

Flow 4: the privacy split

names stay out of research data stays on the participant's devices pseudonymous identifying Consent form carries the name Researcher holds the form Researcher portal two-factor + allowlist Mask session log only Phone app token, bundle, queue Research data pseudonym, sessions, answers Identity side consent records, audits status uploads consent recorded writes reads, pseudonymous only
Names are kept out of the research data. The research side holds only pseudonymous data, and the export path cannot cross into the identity side.

Beyond the software

ThetaMask has three co-founders: Hauk leads hardware and Erlend leads research and study design. Leading software and firmware means owning more than code.

Status

v2 is a pre-beta research device. ThetaMask is not a medical device and makes no medical claims.