library: drop sdk/protocol edges to :library and :library:ui (#884)
- Commit
33bbd34ae1aaa09fb8b8e31653575e80ab1b2965- Author
- Vayun Mathur <[email protected]>
- When
- 2026-10-31 19:35 UTC (1 month ago)
- Parents
07abc46
Part of #884 (PDF Reader had a network permission leaked from a library). The owner's rule is that libraries should not depend on other libraries, and never on one that carries permissions. Two SDK-style modules pulled in whole libraries for a single helper each. Hkdf (HKDF-SHA256, ~30 lines) moves from :library to :library:e2ee-p2p (package com.vayunmathur.e2ee), next to the E2EE code that is its main user. :cast:protocol and :sdk:controller already depended on e2ee-p2p, so their :library edge disappears; backup and findfamily's UWB tracker keys just change the import. The class body is unchanged, so derived keys are byte-identical. ControllerPad (the phone-side gamepad Compose screen) moves out of :sdk:controller into its only host, :games:hub (ui/screens/ControllerPad.kt). :sdk:controller is now the headless contract/discovery/client-host layer with no :library:ui dependency, so games that embed the controller SDK (kart, voxels) no longer pull the UI shell through it. No user-visible change. Verified: compileDebugKotlin for :library, :library:e2ee-p2p, :sdk:controller, :cast:protocol and compileDevKotlin for :backup, :cast, :cast:tv, :findfamily, :games:hub all green.
Diff
backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt b/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.ktindex 863fe027ce..9e7907d4d7 100644--- a/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt+++ b/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt@@ -2,8 +2,8 @@ package com.vayunmathur.backup.platform.crypto import android.content.Context import android.util.Base64+import com.vayunmathur.e2ee.Hkdf import com.vayunmathur.library.util.DatabaseHelper-import com.vayunmathur.library.util.Hkdf /** * Persists the AES-256 master backup key, wrapped by an AndroidKeyStore key, reusing
cast/protocol/AGENTS.md
diff --git a/cast/protocol/AGENTS.md b/cast/protocol/AGENTS.mdindex 834934e827..68b6855698 100644--- a/cast/protocol/AGENTS.md+++ b/cast/protocol/AGENTS.md@@ -6,7 +6,7 @@ - Gradle: :cast:protocol / dir: cast/protocol/ - Package roots present: (pure-Kotlin protocol library — single package, no Android roots) - Entry files: HandshakeMessages.kt + Pairing.kt (no MainActivity/Route — library)-- Deps: :library, :library:e2ee-p2p+- Deps: :library:e2ee-p2p - Metadata: metadata_data/cast-protocol.md (absent — libraries have none by design) - Rust: no / screenshotTest: no
cast/protocol/build.gradle.kts
diff --git a/cast/protocol/build.gradle.kts b/cast/protocol/build.gradle.ktsindex 1df36b3774..c36dbeca45 100644--- a/cast/protocol/build.gradle.kts+++ b/cast/protocol/build.gradle.kts@@ -11,8 +11,8 @@ plugins { // literal in every build.gradle.kts it finds, and a library has no such properties. dependencies {- // Hkdf: the whole key schedule expands from one 32-byte session secret.- implementation(project(":library"))- // Pqc.encryptTo / PqcIdentity.decrypt, used only by SecretSealing.+ // Pqc.encryptTo / PqcIdentity.decrypt (SecretSealing) and Hkdf key derivation+ // (KeySchedule): crypto comes from one module, so this protocol SDK needs+ // no :library dependency (#884). implementation(project(":library:e2ee-p2p")) }
cast/protocol/src/main/java/com/vayunmathur/cast/protocol/KeySchedule.kt
diff --git a/cast/protocol/src/main/java/com/vayunmathur/cast/protocol/KeySchedule.kt b/cast/protocol/src/main/java/com/vayunmathur/cast/protocol/KeySchedule.ktindex 48f4a18970..ca276240fc 100644--- a/cast/protocol/src/main/java/com/vayunmathur/cast/protocol/KeySchedule.kt+++ b/cast/protocol/src/main/java/com/vayunmathur/cast/protocol/KeySchedule.kt@@ -1,6 +1,6 @@ package com.vayunmathur.cast.protocol -import com.vayunmathur.library.util.Hkdf+import com.vayunmathur.e2ee.Hkdf import java.security.MessageDigest import java.security.SecureRandom import javax.crypto.Mac
findfamily/src/main/java/com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/tracker/TrackerUwbKeys.ktindex 17dc255b4b..e1bb14b250 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt@@ -1,6 +1,6 @@ package com.vayunmathur.findfamily.tracker -import com.vayunmathur.library.util.Hkdf+import com.vayunmathur.e2ee.Hkdf /** * FiRa session material for phone↔tracker ranging, derived on both ends from the
games/hub/AGENTS.md
diff --git a/games/hub/AGENTS.md b/games/hub/AGENTS.mdindex 66ff7d755f..799174a316 100644--- a/games/hub/AGENTS.md+++ b/games/hub/AGENTS.md@@ -7,7 +7,8 @@ _Install: ./install games/hub (dev by default)._ - Gradle: :games:hub / dir: games/hub/ - Package roots present: ui, data, provider - Entry files: MainActivity.kt (no Route.kt — dashboard/list/detail/profile flow)-- Deps: :library, :library:ui, :library:room, :sdk:games+- Deps: :library, :library:ui, :library:room, :sdk:games, :sdk:controller, :library:e2ee-p2p+- Play on TV: the `:sdk:controller` pad screen lives here (`ui/screens/ControllerPad.kt`), not in the SDK (#884) - Metadata: metadata_data/games-hub.md (present) - Rust: no / screenshotTest: yes @@ -59,6 +60,7 @@ _Install: ./install games/hub (dev by default)._ - com/vayunmathur/games/hub/ui/screens/ProfileScreen.kt - com/vayunmathur/games/hub/ui/screens/ProfilePage.kt - com/vayunmathur/games/hub/ui/screens/SettingsScreen.kt+- com/vayunmathur/games/hub/ui/screens/ControllerPad.kt — phone-as-controller pad (moved from `:sdk:controller`, #884) - com/vayunmathur/games/hub/ui/components/GameCard.kt - com/vayunmathur/games/hub/ui/components/AchievementRow.kt - com/vayunmathur/games/hub/ui/components/ActivityItem.kt
games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.ktindex d80401d010..2d8e679742 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt@@ -10,11 +10,11 @@ import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.preferencesDataStore import com.vayunmathur.e2ee.Pqc import com.vayunmathur.library.log.Log+import com.vayunmathur.games.hub.ui.screens.ControllerPadState import com.vayunmathur.sdk.controller.ClientState import com.vayunmathur.sdk.controller.ControllerClient import com.vayunmathur.sdk.controller.ControllerDiscovery import com.vayunmathur.sdk.controller.ControllerHostInfo-import com.vayunmathur.sdk.controller.ControllerPadState import com.vayunmathur.sdk.controller.RumbleFeedback import java.util.UUID import kotlinx.coroutines.CoroutineScope
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ControllerPad.kt
diff --git a/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerPad.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ControllerPad.ktsimilarity index 94%rename from sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerPad.ktrename to games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ControllerPad.ktindex 9f19f63605..d09b3556d9 100644--- a/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerPad.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ControllerPad.kt@@ -1,4 +1,4 @@-package com.vayunmathur.sdk.controller+package com.vayunmathur.games.hub.ui.screens import androidx.compose.foundation.Canvas import androidx.compose.foundation.background@@ -36,14 +36,27 @@ import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text+import com.vayunmathur.sdk.controller.ClientState+import com.vayunmathur.sdk.controller.ControllerButton+import com.vayunmathur.sdk.controller.ControllerClient+import com.vayunmathur.sdk.controller.ControllerContract+import com.vayunmathur.sdk.controller.ControllerDiscovery+import com.vayunmathur.sdk.controller.ControllerHostInfo+import com.vayunmathur.sdk.controller.ControllerPairCode+import com.vayunmathur.sdk.controller.LobbyState+import com.vayunmathur.sdk.controller.RumbleFeedback import kotlinx.coroutines.delay import kotlin.math.hypot /** * Everything the pad screen needs, owned by the hosting app. *- * The hosting app (today: the games hub "Play on TV" screen) constructs a [ControllerDiscovery]- * and a [ControllerClient], collects their flows into this, and wires the callbacks back to them:+ * Lives here (not in `:sdk:controller`) so the SDK stays a headless+ * contract: SDK consumers gain no `:library:ui` dependency — and no+ * permissions — from it (#884).+ *+ * The hosting app constructs a [ControllerDiscovery] and a [ControllerClient],+ * collects their flows into this, and wires the callbacks back to them: * `onConnect` → `client.connect(host)`, `onProveCode` → `client.proveCode(code)`, * `onJoin` → `client.join(name)`, `onInput` → `client.sendInput(...)`, `onLeave` → `client.leave()`, * `onRescan` → re-collect `discovery.discover()`. Rumble arrives via `client.onRumble` and is
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/PlayOnTvScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/PlayOnTvScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/PlayOnTvScreen.ktindex eecc6dcc3f..5c89da7fa9 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/PlayOnTvScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/PlayOnTvScreen.kt@@ -15,14 +15,13 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.rememberPermissionRequest import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.sdk.controller.ControllerPad /** * "Play on TV": this phone as a controller for a TV-hosted game. * * The session owns discovery + client + rumble and reduces them to one- * [com.vayunmathur.sdk.controller.ControllerPadState]; this screen only binds- * it to the reusable SDK [ControllerPad] and tears the session down on leave.+ * [ControllerPadState]; this screen only binds+ * it to the reusable [ControllerPad] and tears the session down on leave. * The callbacks map one-to-one onto the session (`onConnect` → `connect`, * `onProveCode` → `proveCode`, …), exactly as the SDK's pad contract documents. *
library/e2ee-p2p/AGENTS.md
diff --git a/library/e2ee-p2p/AGENTS.md b/library/e2ee-p2p/AGENTS.mdindex 946c62bead..08717e1150 100644--- a/library/e2ee-p2p/AGENTS.md+++ b/library/e2ee-p2p/AGENTS.md@@ -24,6 +24,7 @@ - com/vayunmathur/e2ee/PqcNative.kt — Rust bridge - com/vayunmathur/e2ee/SecurityCode.kt - com/vayunmathur/e2ee/InviteFingerprint.kt+- com/vayunmathur/e2ee/Hkdf.kt — HKDF-SHA256 key derivation (moved from `:library`, #884) ## Verify (this module only) ```
library/e2ee-p2p/src/main/java/com/vayunmathur/e2ee/Hkdf.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/Hkdf.kt b/library/e2ee-p2p/src/main/java/com/vayunmathur/e2ee/Hkdf.ktsimilarity index 72%rename from library/src/main/java/com/vayunmathur/library/util/Hkdf.ktrename to library/e2ee-p2p/src/main/java/com/vayunmathur/e2ee/Hkdf.ktindex 4f23bffe7d..a9d6c2f062 100644--- a/library/src/main/java/com/vayunmathur/library/util/Hkdf.kt+++ b/library/e2ee-p2p/src/main/java/com/vayunmathur/e2ee/Hkdf.kt@@ -1,4 +1,4 @@-package com.vayunmathur.library.util+package com.vayunmathur.e2ee import javax.crypto.Mac import javax.crypto.spec.SecretKeySpec@@ -7,9 +7,13 @@ import javax.crypto.spec.SecretKeySpec * HKDF (RFC 5869) over HMAC-SHA256: derive several fixed-purpose sub-keys from one secret so * that compromising a key derived for one use says nothing about the others. *- * Shared rather than per-app because two features already need exactly this: `:backup` expands- * the BIP-0039 seed into the AES-256 master key, and `:cast:protocol` expands the paired session- * secret into the control-channel and per-stream media keys.+ * Lives in the E2EE module (not `:library`) so SDKs and apps can use key+ * derivation without depending on the whole base library (#884).+ *+ * Shared rather than per-app because several features need exactly this:+ * `:backup` expands the BIP-0039 seed into the AES-256 master key,+ * `:cast:protocol` expands the paired session secret into the control-channel+ * and per-stream media keys, and `:sdk:controller` expands its session secret. */ object Hkdf { private const val HMAC = "HmacSHA256"
sdk/controller/AGENTS.md
diff --git a/sdk/controller/AGENTS.md b/sdk/controller/AGENTS.mdindex ac9322544f..e202f12b0c 100644--- a/sdk/controller/AGENTS.md+++ b/sdk/controller/AGENTS.md@@ -6,7 +6,8 @@ - Gradle: :sdk:controller / dir: sdk/controller/ - Package roots present: (public controller SDK — one package) - Entry files: ControllerContract.kt + ControllerModels.kt (no MainActivity/Route — SDK)-- Deps: :library (Hkdf key schedule), :library:e2ee-p2p (E2ee AES-GCM; PQC sealing stays in the hosting app)+- Deps: :library:e2ee-p2p (Hkdf key schedule + E2ee AES-GCM; PQC sealing stays in the hosting app)+- UI: none — headless by design. The Compose pad screen lives in the hosting app (`:games:hub` `ui/screens/ControllerPad.kt`, #884) - Metadata: metadata_data/sdk-controller.md (absent — SDKs have none by design) - Rust: no / screenshotTest: no @@ -32,7 +33,6 @@ baked in so only `ControllerSocket` changes underneath. - com/vayunmathur/sdk/controller/ControllerAdvertiser.kt — mDNS register (TV side) - com/vayunmathur/sdk/controller/ControllerHost.kt — N player slots, replay window, rate limit - com/vayunmathur/sdk/controller/ControllerInputGate.kt — per-player replay + rate-limit policy (JVM-testable)-- com/vayunmathur/sdk/controller/ControllerPad.kt — reusable phone-as-controller UI (stick/buttons, PIN, lobby, rumble) - com/vayunmathur/sdk/controller/ControllerClient.kt — connect/pair/join/input emit ## Verify (this module only)
sdk/controller/build.gradle.kts
diff --git a/sdk/controller/build.gradle.kts b/sdk/controller/build.gradle.ktsindex 4beed3a206..6ec1253f4b 100644--- a/sdk/controller/build.gradle.kts+++ b/sdk/controller/build.gradle.kts@@ -3,10 +3,9 @@ plugins { } dependencies {- // Hkdf: the whole key schedule expands from one 32-byte session secret.- implementation(project(":library"))+ // Headless contract + discovery + client/host only: no UI module here, so SDK+ // consumers gain no UI-library dependency (and no permissions) from it. The+ // Compose pad screen lives in the hosting app (:games:hub). Hkdf key+ // derivation and the E2EE handshake come from :library:e2ee-p2p (#884). implementation(project(":library:e2ee-p2p"))- // ControllerPad is built from the shared wrappers (Text/Button/OutlinedTextField), so the- // phone UI restyles with everything else. Acyclic: :library:ui never depends back on SDKs.- implementation(project(":library:ui")) }
sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerKeys.kt
diff --git a/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerKeys.kt b/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerKeys.ktindex cb7c6a696c..5b8e0ad441 100644--- a/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerKeys.kt+++ b/sdk/controller/src/main/java/com/vayunmathur/sdk/controller/ControllerKeys.kt@@ -1,6 +1,6 @@ package com.vayunmathur.sdk.controller -import com.vayunmathur.library.util.Hkdf+import com.vayunmathur.e2ee.Hkdf import java.security.MessageDigest import java.security.SecureRandom import javax.crypto.Mac