0015 — Sensor access control: JavaScript crypto, native seed storage
Status: Accepted · Date: 2026-10-26
Context
The sensor access control (SAT v1, see BLE & sensors) needs Ed25519 (sign), X25519, HKDF-SHA256 and ChaCha20-Poly1305 in the app, and a protected place for the install key. The sensor protocol runs in shared TypeScript on web, iOS and Android; the native plugins only move GATT bytes.
Platform crypto does not cover the supported range:
- WebCrypto has Ed25519 only from iOS 17 (deployment target 16.6) and no ChaCha20-Poly1305 anywhere.
- The Android Keystore signs Ed25519 only from API 33 (minSdk 26).
Decision
- All protocol crypto runs in TypeScript with
@noble/curvesand@noble/ciphers(plus@noble/hashes, already in the lockfile): pure JS, no dependencies, publicly audited, about 52 KB minified / 21 KB gzip for what SAT uses. One implementation for all three platforms, tested in Vitest against the shared vector files. - The install key's 32-byte seed lives in native secure storage through the
EnodeBleplugin: iOS Keychain (after first unlock, this device only, not synchronised), Android an AES-256-GCM key in the Keystore that wraps the seed in private preferences. The web build keeps it in IndexedDB.
Consequences
- No crypto in the native plugins; the hot notification path (Android batching, data-vs-event ordering) is unchanged.
- The private key is in app memory while signing — as it would be with native code on these OS versions, where no hardware-backed Ed25519 exists.
- JavaScript crypto is not strictly constant-time; exploiting that needs code inside the app, and timing over BLE is not measurable.
- A restored backup has no usable seed: the app creates and registers a new key (the server answers 412 until it does).