1b9855796d1d

feat: B3 RecoveryWordsScreen — 12-word glass-card grid, copy-all + save-as-txt (SAF), 5s countdown, 3-position confirm (3/7/11) storing BLAKE3 hash; auto-routed after vault creation + Settings→Protection 'View recovery words' (v2.1.22)

time
2026-06-09 02:12 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
peach gap implementation
parent
f9e5f1539ecc
7 files app/build.gradle+2 −2app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+14 −0app/src/main/java/com/peachpasswords/ui/PeachNav.kt+2 −0app/src/main/java/com/peachpasswords/ui/lock/LockScreen.kt+6 −1app/src/main/java/com/peachpasswords/ui/lock/LockViewModel.kt+3 −1app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+7 −2app/src/main/java/com/peachpasswords/ui/vault/RecoveryWordsScreen.kt+296 −0
app/build.gradle+2 −2
@@ -16,8 +16,8 @@1616         applicationId "com.peachpasswords"1717         minSdk 261818         targetSdk 3519-        versionCode 20102120-        versionName "2.1.21"19+        versionCode 20102220+        versionName "2.1.22"2121 2222         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323         vectorDrawables {

view file

app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+14 −0
@@ -23,6 +23,7 @@2323 import com.peachpasswords.ui.theme.PeachMotion2424 import com.peachpasswords.ui.vault.EntryDetailScreen2525 import com.peachpasswords.ui.vault.EntryEditScreen26+import com.peachpasswords.ui.vault.RecoveryWordsScreen2627 import com.peachpasswords.ui.vault.TrashScreen2728 import com.peachpasswords.ui.vault.VaultListScreen2829 @@ -112,6 +113,19 @@112113                     }113114                 },114115             )116+        }117+        composable(PeachNav.RecoverySetup.route) {118+            RecoveryWordsScreen(119+                requireConfirm = true,120+                onDone = {121+                    navController.navigate(PeachNav.VaultList.route) {122+                        popUpTo(PeachNav.Lock.route) { inclusive = true }123+                    }124+                },125+            )126+        }127+        composable(PeachNav.RecoveryView.route) {128+            RecoveryWordsScreen(requireConfirm = false, onDone = back)115129         }116130     }117131 }

view file

app/src/main/java/com/peachpasswords/ui/PeachNav.kt+2 −0
@@ -37,4 +37,6 @@3737     data object Import : PeachNav("import")3838     data object Export : PeachNav("export")3939     data object Panic : PeachNav("panic")40+    data object RecoverySetup : PeachNav("recovery/setup")41+    data object RecoveryView : PeachNav("recovery/view")4042 }

view file

app/src/main/java/com/peachpasswords/ui/lock/LockScreen.kt+6 −1
@@ -69,7 +69,12 @@6969     var password by remember { mutableStateOf("") }7070     var confirm by remember { mutableStateOf("") }7171 72-    LaunchedEffect(state.unlocked) { if (state.unlocked) onUnlocked() }72+    LaunchedEffect(state.unlocked) {73+        if (state.unlocked) {74+            // A freshly created vault routes through recovery-word setup before the list.75+            if (state.created) onNavigate(PeachNav.RecoverySetup) else onUnlocked()76+        }77+    }7378 7479     // Shake the panel on each failed unlock (brief Phase 4: 0→−12→10→−8→6→0 over ~400ms).7580     val shake = remember { Animatable(0f) }

view file

app/src/main/java/com/peachpasswords/ui/lock/LockViewModel.kt+3 −1
@@ -18,6 +18,8 @@1818     val loading: Boolean = false,1919     val error: String? = null,2020     val unlocked: Boolean = false,21+    /** True when this session just created a new vault (routes through recovery-word setup). */22+    val created: Boolean = false,2123     /** Increments on each failed unlock so the screen can fire its shake animation. */2224     val shakeNonce: Int = 0,2325 )@@ -58,7 +60,7 @@5860         _state.update { it.copy(loading = true, error = null) }5961         viewModelScope.launch {6062             when (val r = vault.createVault(password)) {61-                is CreateVaultResult.Success -> _state.update { it.copy(loading = false, unlocked = true) }63+                is CreateVaultResult.Success -> _state.update { it.copy(loading = false, unlocked = true, created = true) }6264                 is CreateVaultResult.Error -> _state.update { it.copy(loading = false, error = r.reason) }6365             }6466         }

view file

app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+7 −2
@@ -69,7 +69,7 @@6969 ) {7070     when (id) {7171         CardId.Appearance -> AppearanceBody(fg, vm, settings)72-        CardId.Protection -> ProtectionBody(fg, vm, settings)72+        CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)7373         CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)7474         CardId.Sync -> SyncBody(fg, onNavigate)7575         CardId.Shortcuts -> ShortcutsBody(fg)@@ -224,7 +224,7 @@224224 /* ──────────────────────────────  Protection  ─────────────────────────────── */225225 226226 @Composable227-private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {227+private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {228228     val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")229229     val current = s.autoLockMinutes ?: 0230230 @@ -241,6 +241,11 @@241241     RowLine(fg) {242242         Name("Unlock with biometrics", fg)243243         Toggle(s.biometricsEnabled, fg) { vm.setBiometrics(it) }244+    }245+    SubLabel("RECOVERY", fg)246+    RowLine(fg) {247+        Name("View recovery words", fg)248+        SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }244249     }245250     SubLabel("BREACH PROTECTION", fg)246251     RowLine(fg) {

view file

app/src/main/java/com/peachpasswords/ui/vault/RecoveryWordsScreen.kt+296 −0
@@ -0,0 +1,296 @@1+package com.peachpasswords.ui.vault2+3+import android.content.ClipData4+import android.content.ClipboardManager5+import android.content.Context6+import androidx.activity.compose.rememberLauncherForActivityResult7+import androidx.activity.result.contract.ActivityResultContracts8+import androidx.compose.foundation.background9+import androidx.compose.foundation.border10+import androidx.compose.foundation.clickable11+import androidx.compose.foundation.layout.Arrangement12+import androidx.compose.foundation.layout.Box13+import androidx.compose.foundation.layout.Column14+import androidx.compose.foundation.layout.Row15+import androidx.compose.foundation.layout.Spacer16+import androidx.compose.foundation.layout.fillMaxSize17+import androidx.compose.foundation.layout.fillMaxWidth18+import androidx.compose.foundation.layout.padding19+import androidx.compose.foundation.layout.size20+import androidx.compose.foundation.layout.width21+import androidx.compose.foundation.layout.systemBarsPadding22+import androidx.compose.foundation.rememberScrollState23+import androidx.compose.foundation.shape.RoundedCornerShape24+import androidx.compose.foundation.text.BasicTextField25+import androidx.compose.foundation.verticalScroll26+import androidx.compose.material3.Text27+import androidx.compose.runtime.Composable28+import androidx.compose.runtime.LaunchedEffect29+import androidx.compose.runtime.getValue30+import androidx.compose.runtime.mutableStateListOf31+import androidx.compose.runtime.mutableStateOf32+import androidx.compose.runtime.remember33+import androidx.compose.runtime.setValue34+import androidx.compose.ui.Alignment35+import androidx.compose.ui.Modifier36+import androidx.compose.ui.draw.clip37+import androidx.compose.ui.graphics.Color38+import androidx.compose.ui.graphics.SolidColor39+import androidx.compose.ui.platform.LocalContext40+import androidx.compose.ui.text.TextStyle41+import androidx.compose.ui.text.font.FontStyle42+import androidx.compose.ui.text.style.TextAlign43+import androidx.compose.ui.unit.dp44+import androidx.compose.ui.unit.sp45+import androidx.hilt.navigation.compose.hiltViewModel46+import androidx.lifecycle.ViewModel47+import androidx.lifecycle.viewModelScope48+import com.peachpasswords.ui.theme.LocalPeachAccent49+import com.peachpasswords.ui.theme.PeachColors50+import com.peachpasswords.ui.theme.PeachType51+import com.peachpasswords.ui.theme.ShellBackground52+import com.peachpasswords.vault.VaultCrypto53+import com.peachpasswords.vault.VaultRepository54+import com.peachpasswords.vault.rootKeyToWords55+import dagger.hilt.android.lifecycle.HiltViewModel56+import kotlinx.coroutines.delay57+import kotlinx.coroutines.launch58+import javax.inject.Inject59+60+@HiltViewModel61+class RecoveryWordsViewModel @Inject constructor(62+    private val vault: VaultRepository,63+) : ViewModel() {64+    /** The 12 recovery words derived from the vault's stable sync root key. */65+    val words: List<String> = vault.syncMasterKey()?.let { key ->66+        try { rootKeyToWords(key) } finally { VaultCrypto.zero(key) }67+    } ?: emptyList()68+69+    val alreadySet: Boolean get() = vault.isRecoveryWordsSet()70+71+    /** Mark recovery words confirmed (stores their BLAKE3 hash), then continue. */72+    fun confirmAndComplete(onDone: () -> Unit) = viewModelScope.launch {73+        vault.setRecoveryWords(words)74+        onDone()75+    }76+}77+78+/**79+ * Recovery-word display + confirmation. [requireConfirm] true is the post-vault-creation80+ * flow (countdown → confirm 3 positions → [onDone] into the vault). False is the read-only81+ * "view recovery words" path from Settings ([onDone] returns to settings).82+ */83+@Composable84+fun RecoveryWordsScreen(85+    requireConfirm: Boolean,86+    onDone: () -> Unit,87+    vm: RecoveryWordsViewModel = hiltViewModel(),88+) {89+    var phase by remember { mutableStateOf(Phase.SHOW) }90+    val words = vm.words91+92+    ShellBackground {93+        Column(94+            modifier = Modifier95+                .fillMaxSize()96+                .systemBarsPadding()97+                .padding(horizontal = 22.dp, vertical = 18.dp)98+                .verticalScroll(rememberScrollState()),99+        ) {100+            Text(101+                "recovery words",102+                color = PeachColors.T1,103+                style = TextStyle(fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp),104+                textAlign = TextAlign.Center,105+                modifier = Modifier.fillMaxWidth(),106+            )107+            Spacer(Modifier.size(18.dp))108+            when (phase) {109+                Phase.SHOW -> ShowPhase(110+                    words = words,111+                    requireConfirm = requireConfirm,112+                    onContinue = { if (requireConfirm) phase = Phase.CONFIRM else onDone() },113+                )114+                Phase.CONFIRM -> ConfirmPhase(115+                    words = words,116+                    onConfirm = { vm.confirmAndComplete(onDone) },117+                )118+            }119+        }120+    }121+}122+123+private enum class Phase { SHOW, CONFIRM }124+125+@Composable126+private fun ShowPhase(words: List<String>, requireConfirm: Boolean, onContinue: () -> Unit) {127+    val accent = LocalPeachAccent.current128+    val context = LocalContext.current129+    val joined = remember(words) { words.joinToString(" ") }130+131+    val saveLauncher = rememberLauncherForActivityResult(132+        ActivityResultContracts.CreateDocument("text/plain"),133+    ) { uri ->134+        if (uri != null) runCatching {135+            context.contentResolver.openOutputStream(uri)?.use { it.write(joined.toByteArray()) }136+        }137+    }138+139+    GlassCard {140+        Text(141+            "keep these\nsafe.",142+            color = PeachColors.T0,143+            style = TextStyle(fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp, lineHeight = 26.sp),144+        )145+        Divider()146+        Text(147+            "These 12 words can restore your vault if you forget your master password. Write them down somewhere safe.",148+            color = PeachColors.T1, style = PeachType.body,149+        )150+        Spacer(Modifier.size(16.dp))151+        // 12-word grid, two columns.152+        Column {153+            for (rowStart in 0 until words.size step 2) {154+                Row(Modifier.fillMaxWidth().padding(vertical = 5.dp)) {155+                    WordCell(rowStart + 1, words.getOrElse(rowStart) { "" }, Modifier.weight(1f))156+                    if (rowStart + 1 < words.size) {157+                        WordCell(rowStart + 2, words[rowStart + 1], Modifier.weight(1f))158+                    } else {159+                        Spacer(Modifier.weight(1f))160+                    }161+                }162+            }163+        }164+        Divider()165+        GhostButton("copy all words", accent) {166+            val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager167+            cm.setPrimaryClip(ClipData.newPlainText("peach recovery", joined))168+        }169+        Spacer(Modifier.size(8.dp))170+        GhostButton("save as text file", PeachColors.T1) { saveLauncher.launch("peach-recovery.txt") }171+    }172+173+    Spacer(Modifier.size(18.dp))174+    if (requireConfirm) {175+        var remaining by remember { mutableStateOf(5) }176+        LaunchedEffect(Unit) {177+            while (remaining > 0) { delay(1000); remaining -= 1 }178+        }179+        if (remaining > 0) {180+            Text(181+                "continue in ${remaining}s",182+                color = PeachColors.T2, style = PeachType.tinyMono.copy(fontSize = 9.sp),183+                textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth(),184+            )185+        } else {186+            AccentButton("I've saved my recovery words", onContinue)187+        }188+    } else {189+        AccentButton("Done", onContinue)190+    }191+}192+193+@Composable194+private fun ConfirmPhase(words: List<String>, onConfirm: () -> Unit) {195+    val accent = LocalPeachAccent.current196+    val positions = listOf(3, 7, 11) // 1-indexed197+    val inputs = remember { mutableStateListOf("", "", "") }198+    fun correct(i: Int) = inputs[i].trim().lowercase() == words.getOrElse(positions[i] - 1) { "" }199+    val allCorrect = positions.indices.all { correct(it) }200+201+    GlassCard {202+        Text(203+            "let's check.",204+            color = PeachColors.T0,205+            style = TextStyle(fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp),206+        )207+        Divider()208+        Text("Enter the words at positions 3, 7, and 11.", color = PeachColors.T1, style = PeachType.body)209+        Spacer(Modifier.size(14.dp))210+        positions.forEachIndexed { i, pos ->211+            val ok = correct(i)212+            val tint = when {213+                inputs[i].isBlank() -> PeachColors.T2214+                ok -> accent215+                else -> PeachColors.Breach216+            }217+            Text("Word #$pos", color = PeachColors.T2, style = PeachType.labelMono, modifier = Modifier.padding(top = 12.dp))218+            Row(verticalAlignment = Alignment.CenterVertically) {219+                BasicTextField(220+                    value = inputs[i],221+                    onValueChange = { inputs[i] = it },222+                    singleLine = true,223+                    textStyle = PeachType.bodyMono.copy(color = PeachColors.T0),224+                    cursorBrush = SolidColor(accent),225+                    modifier = Modifier.weight(1f),226+                )227+                if (ok) Text("✓", color = accent, style = PeachType.bodyMono)228+            }229+            Box(Modifier.fillMaxWidth().padding(top = 4.dp).size(1.dp).background(tint.copy(alpha = 0.5f)))230+        }231+    }232+    Spacer(Modifier.size(18.dp))233+    AccentButton("Confirm", onConfirm, enabled = allCorrect)234+}235+236+@Composable237+private fun WordCell(number: Int, word: String, modifier: Modifier = Modifier) {238+    Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically) {239+        Text(240+            "$number",241+            color = LocalPeachAccent.current,242+            style = PeachType.recoveryNumeral,243+            modifier = Modifier.width(28.dp),244+        )245+        Text(word, color = PeachColors.T0, style = PeachType.recoveryWord)246+    }247+}248+249+@Composable250+private fun GlassCard(content: @Composable () -> Unit) {251+    Column(252+        modifier = Modifier253+            .fillMaxWidth()254+            .clip(RoundedCornerShape(18.dp))255+            .background(PeachColors.SurfaceElevated)256+            .border(1.dp, PeachColors.T3, RoundedCornerShape(18.dp))257+            .padding(20.dp),258+        content = { content() },259+    )260+}261+262+@Composable263+private fun Divider() {264+    Box(Modifier.fillMaxWidth().padding(vertical = 14.dp).size(1.dp).background(PeachColors.T3))265+}266+267+@Composable268+private fun GhostButton(label: String, color: Color, onClick: () -> Unit) {269+    Box(270+        modifier = Modifier271+            .fillMaxWidth()272+            .clip(RoundedCornerShape(12.dp))273+            .border(1.dp, color.copy(alpha = 0.4f), RoundedCornerShape(12.dp))274+            .clickable(onClick = onClick)275+            .padding(vertical = 12.dp),276+        contentAlignment = Alignment.Center,277+    ) {278+        Text(label, color = color, style = PeachType.bodyMono)279+    }280+}281+282+@Composable283+private fun AccentButton(label: String, onClick: () -> Unit, enabled: Boolean = true) {284+    val accent = LocalPeachAccent.current285+    Box(286+        modifier = Modifier287+            .fillMaxWidth()288+            .clip(RoundedCornerShape(12.dp))289+            .background(if (enabled) accent else accent.copy(alpha = 0.3f))290+            .clickable(enabled = enabled, onClick = onClick)291+            .padding(vertical = 14.dp),292+        contentAlignment = Alignment.Center,293+    ) {294+        Text(label, color = Color(0xFF0C0A06), style = PeachType.bodyMono)295+    }296+}

view file