diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 393549ba..6cafefea 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -111,6 +111,10 @@
This group was disbanded. Nothing more can be sent into it, and nobody can rejoin.
Ends the group for everyone. Nobody can rejoin; a new conversation is a new group.
Removal sent; it takes effect once a relay accepts it
+ Rotate shares without them?
+ They are out of the room, but their share of the group key still helps sign until the shares are rotated without them. Rotating asks every remaining member to take part. Shares held before the rotation stop working once every device has deleted them.
+ Rotate shares
+ Share rotation proposed; every remaining member is asked to take part
Library
Lightning invoice
Open in a wallet app
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
index ca74f6b3..c7c28652 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
@@ -40,6 +40,7 @@ import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
import mobi.giza.compose.database.model.types.MarmotReindexReport
import mobi.giza.compose.identity.Identity
import mobi.giza.compose.identity.toKeyPair
+import mobi.giza.compose.managers.ShareRefreshManager
import mobi.giza.compose.managers.ChronicleManager
import mobi.giza.compose.managers.FrostSigningManager
import mobi.giza.compose.managers.GroupKeyStateManager
@@ -631,6 +632,17 @@ class DatabaseChatRepository(
database.marmotOutboundDao().removeMember(localChatRoom, memberPublicKey)
}
+ override suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean =
+ runCatching { ShareRefreshManager.liveIdOf(database, localChatRoom, memberPublicKey) != null }.getOrDefault(false)
+
+ override suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? {
+ val identity = activeIdentity.value ?: return "No identity is signed in"
+ val nostrPrivateKey = identity.toKeyPair().privKey ?: return "This identity cannot sign"
+ return runCatching {
+ ShareRefreshManager.proposeWithout(database, localChatRoom, identity.nostrPublicKey, nostrPrivateKey, memberPublicKey)
+ }.exceptionOrNull()?.let { it.message ?: it::class.simpleName ?: "Unknown error" }
+ }
+
override suspend fun disbandChatRoom(localChatRoom: LocalChatRoom) {
database.marmotOutboundDao().disband(localChatRoom)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt
index 6befea3c..160ff004 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt
@@ -86,7 +86,8 @@ object ShareRefreshManager {
}
if (withheld.values.any { it == ShareStanding.LIVE }) return "a withheld participant cannot stay live"
if (recipients.size < key.threshold) {
- return "${recipients.size} recipients cannot carry a ${key.threshold}-of-${key.participantCount} key"
+ return "it would leave ${recipients.size} members holding shares, fewer than the ${key.threshold} it takes to sign; " +
+ "the group could not sign at all, and only a new ceremony goes on from there"
}
if (recipients.size * 2 <= notRetired.size) {
return "${recipients.size} of ${notRetired.size} is not a majority, so two such refreshes could both complete"
@@ -165,6 +166,41 @@ object ShareRefreshManager {
return session
}
+ /**
+ * The participant id [memberPublicKey] holds a live share of [localChatRoom]'s
+ * key under, or null when they hold none -- the question a removal asks
+ * before offering to rotate without them (docs/frost-share-refresh.md, Phase 9).
+ */
+ suspend fun liveIdOf(database: GizaDatabase, localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Int? {
+ val key = FrostSigningManager.completedKey(database, localChatRoom.chatRoom.id) ?: return null
+ if (!isKeysRoom(database, localChatRoom, key)) return null
+ return ShareGenerations.active(database, key).signerIds[memberPublicKey]
+ }
+
+ /**
+ * Opens a refresh that withholds [memberPublicKey] for good, after they were
+ * removed from the room (docs/frost-share-refresh.md, Phase 9). The removal is
+ * one admin's commit; this needs every remaining holder, so it is a second
+ * act, never folded into the first.
+ *
+ * Refused, with a reason, when it would leave fewer than t live ids -- the
+ * group could not sign at all, and only a new ceremony goes on from there --
+ * or when the remaining recipients are not a majority (remove fewer at a time).
+ */
+ suspend fun proposeWithout(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ userPublicKey: HexKey,
+ nostrPrivateKey: ByteArray,
+ memberPublicKey: HexKey,
+ ): ShareRefreshSession {
+ val key = FrostSigningManager.completedKey(database, localChatRoom.chatRoom.id)
+ ?: throw IllegalStateException("This group has no shared key this device can rotate")
+ val id = ShareGenerations.active(database, key).signerIds[memberPublicKey]
+ ?: throw IllegalStateException("They hold no share of the group's key")
+ return proposeRefresh(database, localChatRoom, userPublicKey, nostrPrivateKey, key, mapOf(id to ShareStanding.RETIRED))
+ }
+
/** A refresh of [key] still running on this device, if there is one. One at a time per key. */
private suspend fun running(database: GizaDatabase, key: DkgSession): ShareRefreshSession? =
database.shareRefreshDao().getSessionsForKey(key.id).firstOrNull {
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
index c50ba407..0cc98225 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
@@ -259,6 +259,19 @@ interface ChatRepository {
*/
suspend fun removeMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey)
+ /**
+ * Whether [memberPublicKey] holds a live share of the room's key, and so
+ * whether a removal leaves them able to help sign until the shares are
+ * rotated without them (docs/frost-share-refresh.md, Phase 9).
+ */
+ suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean
+
+ /**
+ * Proposes rotating the room's shares without [memberPublicKey], withheld for
+ * good. Returns null when the proposal went out, or why it could not.
+ */
+ suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String?
+
/**
* Disbands a current-profile room this device administers. Absorbing: once the
* disband commit is applied nobody rejoins, and a replacement conversation is a
@@ -447,6 +460,10 @@ interface ChatRepository {
override suspend fun removeMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) = Unit
+ override suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean = false
+
+ override suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? = null
+
override suspend fun disbandChatRoom(localChatRoom: LocalChatRoom) = Unit
override suspend fun softDeleteChatRoom(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
index 472db605..204e780e 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
@@ -102,6 +102,12 @@ import mobi.giza.compose.resources.direct_message_functionality_will_be_here
import mobi.giza.compose.resources.invite_new_member
import mobi.giza.compose.resources.leave_group
import mobi.giza.compose.resources.remove_from_group
+import mobi.giza.compose.resources.share_rotation_requested
+import mobi.giza.compose.resources.not_now
+import mobi.giza.compose.resources.rotate_shares
+import mobi.giza.compose.resources.rotate_shares_without_body
+import mobi.giza.compose.resources.rotate_shares_without_title
+import androidx.compose.material3.AlertDialog
import mobi.giza.compose.resources.disband_group
import mobi.giza.compose.resources.disband_group_explainer
import mobi.giza.compose.resources.group_disbanded
@@ -160,6 +166,28 @@ fun ChatRoomDetailScreen(
// composable, and a lambda passed to onClick is not.
val notify = rememberNotifier(rememberCoroutineScope())
val removalRequested = stringResource(Res.string.member_removal_requested)
+ val rotationRequested = stringResource(Res.string.share_rotation_requested)
+
+ // Offered after removing a member who still holds a share of the room's key:
+ // the removal took them out of the room, not out of the key
+ // (docs/frost-share-refresh.md, Phase 9).
+ chatRoomDetailViewModel.rotationOffer?.let { offer ->
+ AlertDialog(
+ onDismissRequest = { chatRoomDetailViewModel.dismissRotationOffer() },
+ title = { Text(stringResource(Res.string.rotate_shares_without_title)) },
+ text = { Text(stringResource(Res.string.rotate_shares_without_body)) },
+ confirmButton = {
+ TextButton(onClick = { chatRoomDetailViewModel.rotateSharesWithout(offer) { failure -> notify(failure ?: rotationRequested) } }) {
+ Text(stringResource(Res.string.rotate_shares))
+ }
+ },
+ dismissButton = {
+ TextButton(onClick = { chatRoomDetailViewModel.dismissRotationOffer() }) {
+ Text(stringResource(Res.string.not_now))
+ }
+ },
+ )
+ }
ScreenStateTransition(chatRoomDetailViewModel.chatRoomDetailUIState) { uiState ->
when (val chatRoomDetailUIState = uiState) {
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
index d66e38b5..f67a7b78 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
@@ -118,10 +118,38 @@ class ChatRoomDetailViewModel(
*/
fun removeMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey, onDone: (String?) -> Unit = {}) {
viewModelScope.launch(Dispatchers.IO) {
+ // Asked before the removal, while they are still in the room's roster.
+ val heldShare = chatRepository.holdsShare(localChatRoom, memberPublicKey)
val failure = runCatching { chatRepository.removeMember(localChatRoom, memberPublicKey) }
.exceptionOrNull()
initiateChatRoomDetail()
- viewModelScope.launch(Dispatchers.Main) { onDone(failure?.message) }
+ viewModelScope.launch(Dispatchers.Main) {
+ onDone(failure?.message)
+ // The removal takes them out of the room, not out of the key: they
+ // can still help sign until the shares are rotated without them.
+ // A second act, offered rather than folded in -- it needs every
+ // remaining holder (docs/frost-share-refresh.md, Phase 9).
+ if (failure == null && heldShare) rotationOffer = RotationOffer(localChatRoom, memberPublicKey)
+ }
+ }
+ }
+
+ /** A removed member who still holds a share of the room's key, for the offer to rotate without them. */
+ data class RotationOffer(val localChatRoom: LocalChatRoom, val memberPublicKey: HexKey)
+
+ var rotationOffer: RotationOffer? by mutableStateOf(null)
+ private set
+
+ fun dismissRotationOffer() {
+ rotationOffer = null
+ }
+
+ /** Proposes the rotation [rotationOffer] offered. [onDone] gets null on success, or why it could not. */
+ fun rotateSharesWithout(offer: RotationOffer, onDone: (String?) -> Unit) {
+ rotationOffer = null
+ viewModelScope.launch(Dispatchers.IO) {
+ val failure = chatRepository.rotateSharesWithout(offer.localChatRoom, offer.memberPublicKey)
+ viewModelScope.launch(Dispatchers.Main) { onDone(failure) }
}
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ShareRefreshRitualJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ShareRefreshRitualJvmTest.kt
index a514781c..0e048a54 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ShareRefreshRitualJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ShareRefreshRitualJvmTest.kt
@@ -396,4 +396,76 @@ class ShareRefreshRitualJvmTest {
assertEquals(1, dao.replace(older).generation)
assertEquals(1, dao.getByChatRoomId(group.roomId)?.generation)
}
+
+ // ---- Phase 9: rotating without a removed member --------------------------------------------------------------
+
+ /**
+ * A removed member is out of the room but still holds a share. Rotating
+ * without them, withheld for good, leaves the other two signing at the new
+ * generation -- and the removed member's share, which their device still has,
+ * combines with nothing of it.
+ */
+ @Test
+ fun `rotating without a removed member leaves their share useless`() = runBlocking {
+ val group = Group(3, 2)
+ val all = devicesFor(group)
+ val (alice, bob, carol) = all
+ val carolId = group.idOf[2]
+ assertEquals(carolId, ShareRefreshManager.liveIdOf(alice.db, alice.room, carol.publicKey))
+
+ val refresh = ShareRefreshManager.proposeWithout(alice.db, alice.room, alice.publicKey, alice.privateKey, carol.publicKey)
+ assertEquals(mapOf(carolId to ShareStanding.RETIRED), refresh.withheldStandings())
+ pump(all)
+ approveAll(all, refresh.id)
+ approveSigning(all)
+
+ listOf(alice, bob).forEach { device ->
+ val active = device.active()
+ assertEquals(1, active.generation)
+ assertEquals(ShareStanding.RETIRED, active.roster.single { it.participantId == carolId }.standing)
+ assertNull(active.signerIds[carol.publicKey], "carol must not be a signer")
+ assertNull(ShareRefreshManager.liveIdOf(device.db, device.room, carol.publicKey))
+ }
+ // Retired is not stale: carol's id is gone from the ids that count.
+ assertNull(alice.active().participantIds[carol.publicKey])
+
+ // Alice and Bob sign at generation 1.
+ val session = FrostSigningManager.proposeSigning(alice.db, alice.room, alice.publicKey, kind = 1, tags = arrayOf(), content = "Without carol")
+ assertEquals(1, session.generation)
+ pump(all)
+ approveSigning(all)
+ assertEquals(FrostSigningStage.COMPLETE, alice.db.frostSigningSessionDao().getSessionById(session.id)?.stage)
+
+ // Carol's old share and Alice's new one: no signature.
+ val table = alice.active().publicShares!!
+ val aliceId = group.idOf[0]
+ val mixed = (0 until 3).map { id ->
+ when (id) {
+ carolId -> group.keyMaterial.secretShares[carolId]
+ aliceId -> alice.active().secretShare!!
+ else -> bob.active().secretShare!!
+ }
+ }
+ val km = KeyMaterial(group.keyMaterial.thresholdPublicKey, mixed, table, 2)
+ val signers = listOf(aliceId, carolId).sorted().map { it.toUInt() }
+ val msg = ByteVector32("5a".repeat(32))
+ val signs = runCatching {
+ val nonces = signers.map { id -> Frost.generateNonce(ByteVector32("0${id}".padEnd(64, '7')), km.secretShares[id.toInt()], km.publicShares[id.toInt()], km.tweakCache().tweakedPublicKey, msg, null) }
+ val publicNonces = nonces.map { it.second }
+ val partials = signers.mapIndexed { i, id -> Frost.sign(km.secretShares[id.toInt()], nonces[i].first, id, msg, signers, km, publicNonces).right!! }
+ val sig = Frost.aggregatePartialSignatures(partials, msg, signers, km, publicNonces).right!!
+ fr.acinq.bitcoin.Crypto.verifySignatureSchnorr(msg, sig, km.tweakCache().tweakedPublicKey)
+ }.getOrDefault(false)
+ assertTrue(!signs, "a removed member's old share must not sign with a new one")
+ }
+
+ @Test
+ fun `rotating without a member is refused when too few would be left to sign`() = runBlocking {
+ val group = Group(2, 2)
+ val (alice, bob) = devicesFor(group)
+ val error = assertFailsWith {
+ ShareRefreshManager.proposeWithout(alice.db, alice.room, alice.publicKey, alice.privateKey, bob.publicKey)
+ }
+ assertTrue(error.message!!.contains("fewer than the 2 it takes to sign"), error.message)
+ }
}
diff --git a/docs/frost-share-refresh.md b/docs/frost-share-refresh.md
index b6f246ca..99b5f70f 100644
--- a/docs/frost-share-refresh.md
+++ b/docs/frost-share-refresh.md
@@ -20,7 +20,8 @@ ceremony they describe and the rule that a room's id *is* the key it signs with.
| 3 | bitcoin-kmp `d2e15b8`, `3cd82d1` | `jvmTest` 274/274, including withheld → repaired with `FrostReducedEnrollment` → signs |
| 4 | lightning-kmp `2043f254`, lightning-kmp-app `3794eb8`, Giza Phase 4 | lightning-kmp `crypto` tests 104/104; Giza `compileDebugKotlinAndroid`, `jvmTest` 1183/1183, audits |
| 7 | `f8974aec` | `ShareRefreshRitualJvmTest` (7: three devices with real host keys refresh through the real zkp module and then sign at generation 1 as the same room; nothing published before approval; a withheld member follows to the new table with no share and declines to sign; a minority refused; one confirmation per generation; a second proposal hands back the first; a redelivered transcript changes nothing); `jvmTest` 1190/1190; `compileDebugKotlinAndroid`; audits |
-| 8 | Phase 8 | three more in `ShareRefreshRitualJvmTest`: once the group signs the generation-1 key state every device deletes the ceremony's share and its randomness and still signs; a gen-0 session left open fails with "This share was rotated before the session finished"; a key state at an older generation loses whatever its timestamp. `jvmTest` 1193/1193; `compileDebugKotlinAndroid`; audits |
+| 8 | `51615992` | three more in `ShareRefreshRitualJvmTest`: once the group signs the generation-1 key state every device deletes the ceremony's share and its randomness and still signs; a gen-0 session left open fails with "This share was rotated before the session finished"; a key state at an older generation loses whatever its timestamp. `jvmTest` 1193/1193; `compileDebugKotlinAndroid`; audits |
+| 9 | Phase 9 | two more in `ShareRefreshRitualJvmTest`: rotating without a removed member of a 2-of-3 leaves the other two signing at generation 1 and the removed member's old share signing nothing with a new one; a 2-of-2 is refused with "fewer than the 2 it takes to sign". `jvmTest` 1195/1195; `compileDebugKotlinAndroid`; audits. The dialog has not been seen on a device |
| 5 | `4040ae74` | `SecureDeleteJvmTest` (5, two of them controls that fail without the fix); `jvmTest` 1176/1176; `compileDebugKotlinAndroid`, `processDebugResources` |
| 6 | `fce51e20` | `ShareGenerationsJvmTest` (7: a real 2-of-3 signature with hand-refreshed shares verifying as the unchanged room, a decline from a device without the generation, a withheld member who is not a signer); every existing signing test unedited; `jvmTest` 1183/1183; `compileDebugKotlinAndroid`; the M3, brand and wallet audits |
@@ -46,6 +47,7 @@ Where the build chose differently from the plan:
| Phase 8: any recipient proposes the new key state | the coordinator does, automatically, the moment its refresh completes; anyone can again. That races the certificate to the other devices, and lost in the first test run: a device still holding the generation as pending declined. A proposal at a generation this device has confirmed and is waiting on the certificate for now waits instead, and the refresh resumes it on activation (`FrostSigningManager.resumeAt`) |
| Phase 8: `ShareRefreshCutoverJvmTest` | the cutover tests live in `ShareRefreshRitualJvmTest`, which has the multi-device harness. The bytes-on-disk check is `SecureDeleteJvmTest`'s, against a file; these devices are in memory. A device that disagrees with the group's table keeps its share and logs it, untested |
| Phase 8: gen-0's randomness nulled | emptied: `round1Random` and `round2AuxRandom` are not nullable, and a complete ceremony never reads them again |
+| Phase 9: an action on the members screen | a dialog the room detail screen raises after a removal succeeds, when the member held a live share (asked before the removal, while they are still in the roster). "Not now" leaves it; nothing offers it again yet -- Phase 11's Shares section is where a rotation can be started at any time. `MemberRemovalRefreshJvmTest` is two tests in the ritual harness |
| Phase 5: `dataExtractionRules` or `allowBackup="false"` | both. From Android 12 `allowBackup="false"` stops cloud backup but not a device-to-device transfer |
## The headline: enrollment cannot rotate a share