From 1ccd8c7f0958a7e34202a6b707b849999ae403aa Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Fri, 20 Nov 2026 09:28:47 +0200 Subject: [PATCH] feat: a keyed room is born needing the group's signature; the switch is gone The rule that a keyed room's changes need the group's signature was switched on after founding, once every member's device had said it could follow signed commits. That protected Bennu members and older Giza builds from being left behind by the first signed change. Giza is in development and keeps compatibility with neither, so the switch protected nobody, and it kept an invited member from ever being made an admin. MarmotGroupCreation.createFor now writes GovernanceMarker's line, with the floor the ceremony's quorum sets, into the room's epoch-0 description. Founding still needs no signature: the founding invite is the creator's commit while it is the only member, which no other device processes. Removed: GovernanceSupport and its event (30372), the announcements on joining, at start and in answer, the automatic switch and requireSignatures, and the screen's waiting and ready states. Co-Authored-By: Claude Opus 5.5 --- .../composeResources/values/strings.xml | 4 - .../compose/database/dao/MarmotOutboundDao.kt | 37 ---- .../giza/compose/database/dao/NostrDao.kt | 21 --- .../repository/DatabaseChatRepository.kt | 13 +- .../managers/GovernanceFollowThrough.kt | 12 +- .../giza/compose/managers/GovernanceMarker.kt | 8 +- .../compose/managers/GovernanceSupport.kt | 171 ----------------- .../compose/managers/MarmotGroupCreation.kt | 13 ++ .../compose/nostr/frost/GovernanceEvents.kt | 20 +- .../giza/compose/repository/ChatRepository.kt | 12 -- .../ui/composable/ChatRoomDetailScreen.kt | 7 +- .../ui/composable/MemberAdminControls.kt | 72 ++------ .../ui/view/model/SynchronizationViewModel.kt | 6 - .../compose/ui/view/state/GovernanceStatus.kt | 20 +- .../compose/managers/AdminChangesJvmTest.kt | 8 +- .../compose/managers/GovernanceGateJvmTest.kt | 174 ------------------ .../compose/managers/GroupLifecycleJvmTest.kt | 2 +- .../managers/MarmotGroupCreationJvmTest.kt | 17 +- .../managers/PublishBeforeApplyJvmTest.kt | 2 +- .../managers/RobustGroupAdminsJvmTest.kt | 33 ++++ docs/member-admin-promotion.md | 8 +- docs/remove-convenient-groups.md | 102 ++++------ 22 files changed, 138 insertions(+), 624 deletions(-) delete mode 100644 composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 9d7d98ca..20f55003 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -125,10 +125,6 @@ Make admin and leave Disband group instead Changes to who is in this group need the group's signature. It always keeps at least %1$d admins. - Turning on the group's signature for changes. - Changes will need the group's signature as soon as %1$s's Giza is next online. - From then on, adding or removing a member, or changing who the admins are, is proposed and has to be signed by the group before it happens. - Waiting for %1$s to open an up-to-date Giza. Until then, this group can't require its signature on changes, and nobody else can be made an admin. They'll be asked to accept, then the group signs it, and they'll hold a share of the group's key and be asked to approve its changes. Once the group signs it, they stay in the group as a member and their share of the group's key is rotated away. Asked; they become an admin once they accept and the group signs it diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt index 46479132..4ff8f458 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt @@ -69,7 +69,6 @@ import mobi.giza.compose.ExperimentalFeatures import mobi.giza.compose.managers.GovernanceGate import mobi.giza.compose.managers.GovernanceManager import mobi.giza.compose.managers.GovernanceMarker -import mobi.giza.compose.managers.GovernanceSupport import mobi.giza.compose.managers.ChronicleManager import mobi.giza.compose.managers.MarmotGroupFactory import mobi.giza.compose.managers.MarmotInboundManager @@ -1060,42 +1059,6 @@ abstract class MarmotOutboundDao( } } - /** - * Makes a keyed room's changes need the group's signature from the next epoch: - * one ordinary commit adding [GovernanceMarker]'s line to the profile - * description, with the floor the room's quorum sets. It is the room's last bare - * commit, and every device that applies it enforces the rule from the state it - * just applied. docs/member-admin-promotion.md, D4 and Phase 4b. - * - * Refused while any member has not said their device can follow signed commits - * -- they would be left in a different group by the first change -- and while - * the room has fewer admins than the floor it would set. - */ - @Transaction - open suspend fun requireSignatures(localChatRoom: LocalChatRoom) { - val group = governedGroup(localChatRoom) - val roomId = localChatRoom.chatRoom.id - check(AdminGovernance.isKeyedRoom(group)) { "Only a group with a shared key can require its signature" } - if (GovernanceGate.isGoverned(group)) return - val missing = GovernanceSupport.missing(database, roomId, group) - if (missing.isNotEmpty()) { - throw IllegalStateException("Waiting for ${missing.map { memberName(it) }.sorted().joinToString()} to open an up-to-date Giza") - } - val floor = AdminGovernance.adminFloor(database, roomId, group) - val admins = group.currentAdminIdentities() intersect AdminGovernance.members(group) - check(admins.size >= floor) { "A group with a shared key needs at least $floor admins first" } - - publishGatedCommit(localChatRoom) { manager, id -> - val live = manager.getGroup(id) ?: throw MarmotMissingChatGroupException("No live group for $id") - val profile = live.currentGroupState().profile ?: throw IllegalStateException("The group has no profile to record the rule in") - manager.stageAppDataUpdate( - id, - GroupProfileV1.COMPONENT_ID, - GroupProfileV1(profile.name, GovernanceMarker.describe(profile.description, floor)).encode(), - ) - } - } - /** Whether [memberPublicKey] holds a live share of the room's key, with rotation on. */ private suspend fun holdsLiveShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean = ExperimentalFeatures.shareRefresh && diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt index 85a6da10..b18d349a 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt @@ -7,8 +7,6 @@ import com.vitorpamplona.marmot.GroupEventResult import com.vitorpamplona.marmot.groups.MarmotGroupPolicy import com.vitorpamplona.marmot.groups.currentAdminIdentities import mobi.giza.compose.managers.GovernanceGate -import mobi.giza.compose.managers.GovernanceSupport -import mobi.giza.compose.nostr.frost.GovernanceSupportEvent import mobi.giza.compose.nostr.frost.GovernanceEvents import mobi.giza.compose.nostr.frost.GovernanceCarrierEvent import mobi.giza.compose.nostr.frost.OwnCommitEvent @@ -921,15 +919,6 @@ abstract class NostrDao( mlsGroup = group, ) - // That this device follows signed commits, said on - // joining. It cannot read the others saying it -- that - // was before its epoch -- so it would never answer, and - // the room would wait on it until its screen was opened. - // docs/remove-convenient-groups.md, "After the build". - if (group.currentGroupState().isCurrentProfile) { - GovernanceSupport.announce(database, nostrGroupId, group, userPublicKey) - } - // Save ChatRoom Relays... participants.filter { it.participantPublicKey != userPublicKey }.forEach { participant -> val publicKey = participant.participantPublicKey @@ -1705,16 +1694,6 @@ abstract class NostrDao( // A change to a governed room, inside the group's signature or, // for a member's own leave, its committer's. Checked, and its // commit applied, only here (docs/member-admin-promotion.md). - // Another member says their device follows signed commits: - // this one says so back, once, so that a member who never - // opens the room's screen is still counted (Phase 4b). - innerEvent.kind == GovernanceSupportEvent.KIND -> - if (localChatRoom.chatRoom.marmotProfile() == MarmotProfile.CURRENT) { - database.marmotEngine.groupFor(localChatRoom.routingId)?.let { group -> - GovernanceSupport.announce(database, localChatRoom.chatRoom.id, group, activeKeyPair.pubKey.toHex()) - } - } - innerEvent.kind == OwnCommitEvent.KIND -> admitEnvelopedCommit(localChatRoom, innerEvent, activeKeyPair) innerEvent.kind == GovernanceCarrierEvent.KIND -> 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 c97a2c1a..0ecce1c0 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 @@ -14,7 +14,6 @@ import mobi.giza.compose.managers.AdminGovernance import mobi.giza.compose.managers.GovernanceGate import mobi.giza.compose.managers.PromotionManager import mobi.giza.compose.managers.GovernanceFollowThrough -import mobi.giza.compose.managers.GovernanceSupport import mobi.giza.compose.managers.MarmotInboundManager import mobi.giza.compose.managers.AdminFlags import mobi.giza.compose.managers.FoundingAdmins @@ -145,8 +144,6 @@ class DatabaseChatRepository( override suspend fun reconcileAdminFlags(): Int = AdminFlags.reconcileAll(database) - override suspend fun announceGovernanceSupport(): Int = GovernanceSupport.announceAll(database) - override suspend fun followThroughCeremonies(keyPair: KeyPair) = kotlinx.coroutines.coroutineScope { launch { CeremonyFollowThrough.observe(database = database, chatRepository = this@DatabaseChatRepository, keyPair = keyPair) } // What a governed room's signed changes need after they land: a rotation @@ -720,15 +717,7 @@ class DatabaseChatRepository( if (room.chatRoom.marmotProfile() != MarmotProfile.CURRENT) return null val group = database.marmotEngine.groupFor(room.routingId) ?: return null if (!AdminGovernance.isKeyedRoom(group)) return null - GovernanceGate.minimumAdmins(group)?.let { return GovernanceStatus.Governed(it) } - if (room.chatRoom.leftGroupAt == null) GovernanceSupport.announce(database, chatRoomId, group, room.chatRoom.userPublicKey) - val missing = GovernanceSupport.missing(database, chatRoomId, group) - return if (missing.isEmpty()) GovernanceStatus.Ready(AdminGovernance.adminFloor(database, chatRoomId, group), GovernanceSupport.switcherOf(group)) - else GovernanceStatus.Waiting(missing) - } - - override suspend fun requireSignatures(localChatRoom: LocalChatRoom) { - database.marmotOutboundDao().requireSignatures(localChatRoom) + return GovernanceGate.minimumAdmins(group)?.let { GovernanceStatus.Governed(it) } } override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) { diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt index d04e75aa..9bdf87a7 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt @@ -11,7 +11,6 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.conflate import mobi.giza.compose.ExperimentalFeatures import mobi.giza.compose.nostr.frost.GroupKeyStateEvent -import mobi.giza.compose.nostr.frost.GovernanceSupportEvent import mobi.giza.compose.nostr.frost.PromotionEvents import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -38,11 +37,7 @@ object GovernanceFollowThrough { suspend fun observe(database: GizaDatabase, keyPair: KeyPair) { combine( database.governanceProposalDao().observeAll(), - // A member saying their device follows signed commits may be the last one - // a room was waiting on before its rule can be switched on. - database.marmotInnerEventDao().observeCountByKinds( - listOf(PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER, GovernanceSupportEvent.KIND) - ), + database.marmotInnerEventDao().observeCountByKinds(listOf(PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER)), database.groupSignedEventDao().observeByKind(GroupKeyStateEvent.KIND), ) { _, _, _ -> Unit } .conflate() @@ -60,11 +55,8 @@ object GovernanceFollowThrough { /** One pass over everything owed. */ suspend fun pass(database: GizaDatabase, keyPair: KeyPair) = mutex.withLock { rotationsOwed(database).forEach { proposal -> rotateAway(database, keyPair, proposal) } - val me = keyPair.pubKey.toHexKey() - // A keyed room's rule, switched on once every member can follow it, by the one - // device whose it is to switch. docs/remove-convenient-groups.md, "After the build". - GovernanceSupport.switchWhereOwed(database, me) if (!ExperimentalFeatures.shareRefresh) return@withLock + val me = keyPair.pubKey.toHexKey() val privateKey = keyPair.privKey ?: return@withLock // Phase 8, the device that offered: an accepted offer is proposed for the diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt index 90453b3a..3c3c0ef9 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt @@ -5,8 +5,12 @@ package mobi.giza.compose.managers * group's signature, and how few admins it may ever have. docs/member-admin-promotion.md, * D4 and D8. * - * In the group's state, so every device that applies the commit adding it enforces - * the rule from the same epoch, and reads the same floor: a floor each device worked + * Written into a keyed room's epoch-0 description when it is made + * (`MarmotGroupCreation.createFor`), so there is no later moment it is switched on + * and nobody it waits for; docs/remove-convenient-groups.md, "After the build". + * + * In the group's state, so every device enforces the rule from the same epoch, and + * reads the same floor: a floor each device worked * out for itself from the ceremony it happens to hold would differ between a founder * and a member welcomed later, and the two would disagree about a commit. The * description is the one free text the current profile offers, which is why diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt deleted file mode 100644 index 5dbe3d24..00000000 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt +++ /dev/null @@ -1,171 +0,0 @@ -package mobi.giza.compose.managers - -import co.touchlab.kermit.Logger -import com.vitorpamplona.marmot.groups.currentAdminIdentities -import com.vitorpamplona.marmot.groups.currentGroupState -import com.vitorpamplona.mls.group.MlsGroup -import com.vitorpamplona.mls.tree.Credential -import com.vitorpamplona.quartz.nip01Core.core.HexKey -import com.vitorpamplona.quartz.nip01Core.core.toHexKey -import kotlinx.coroutines.CancellationException -import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher -import kotlin.time.Clock -import kotlin.time.Instant -import mobi.giza.compose.database.GizaDatabase -import mobi.giza.compose.nostr.MarmotProfile -import mobi.giza.compose.database.model.MarmotInnerEvent -import mobi.giza.compose.database.model.intermdiate.LocalChatRoom -import mobi.giza.compose.nostr.frost.GovernanceSupportEvent - -/** - * Who in a keyed room has said their device follows signed commits, and this - * device saying it. docs/member-admin-promotion.md, D4 and Phase 4b. - * - * The rule cannot be switched on while anybody in the room would be left behind - * by it: a device that does not know it applies the bare commits Giza drops and - * reads none of the envelopes, and is in a different group from the first change. - * Once everybody has, one device switches the rule on by itself ([switchWhereOwed]); - * nobody opens a screen or presses anything. - * - * So each device says, once per room, that it can follow: when it is welcomed in, - * when it starts, when the room's screen is opened, and back when it hears another - * say it. - * - * Joining has to be one of them. A member invited after the others said it cannot - * read what they said -- it was sent at an epoch before theirs -- so it never hears - * anybody to answer, and nobody says it again. Until it opened the room's screen - * the room waited on it, and nobody could be made an admin. See - * docs/remove-convenient-groups.md, "After the build". - */ -object GovernanceSupport { - - /** The accounts that have said, in [chatRoomId], that they follow signed commits. */ - suspend fun supporters(database: GizaDatabase, chatRoomId: String): Set = - database.marmotInnerEventDao().getByChatRoomAndKinds(chatRoomId, listOf(GovernanceSupportEvent.KIND)) - .filter { row -> row.tags.any { it.size >= 2 && it[0] == GovernanceSupportEvent.VERSION_TAG && it[1] == GovernanceSupportEvent.VERSION } } - .map { it.publicKey } - .toSet() - - /** The members of [group] who have not said it yet. */ - suspend fun missing(database: GizaDatabase, chatRoomId: String, group: MlsGroup): Set = - AdminGovernance.members(group) - supporters(database, chatRoomId) - - /** - * Says, for [me], that this device follows signed commits in [chatRoomId] -- once: - * nothing happens when it already has. Only in a keyed room, which is the only - * kind the rule can be switched on in. Returns whether it said it now. - */ - suspend fun announce(database: GizaDatabase, chatRoomId: String, group: MlsGroup, me: HexKey): Boolean { - if (!AdminGovernance.isKeyedRoom(group)) return false - if (me in supporters(database, chatRoomId)) return false - val tags = GovernanceSupportEvent.assembleTags(chatRoomId) - val createdAt = Clock.System.now().epochSeconds - val id = EventHasher.hashId(pubKey = me, createdAt = createdAt, kind = GovernanceSupportEvent.KIND, tags = tags, content = "") - // Unsent: the outbound worker puts an inner event with no group event behind - // it into the room, as it does for every manager's messages. - database.marmotInnerEventDao().upsert( - MarmotInnerEvent( - id = id, - publicKey = me, - kind = GovernanceSupportEvent.KIND, - createdAt = Instant.fromEpochSeconds(createdAt), - tags = tags, - content = "", - chatRoomId = chatRoomId, - ) - ) - return true - } - - /** - * [announce] for every room this device is in, for the members who joined - * before joining was one of the times it is said. Once per start, and a read - * with no write for a room that has it already. One room that will not open is - * logged and passed over. - * - * @return how many rooms it was said in now. - */ - suspend fun announceAll(database: GizaDatabase): Int = - database.chatRoomDao().getChatRoomIdsWithMlsState().count { chatRoomId -> - runCatching { - val room = database.chatRoomDao().findChatRoomById(chatRoomId) ?: return@runCatching false - if (room.chatRoom.leftGroupAt != null || room.chatRoom.marmotProfile() != MarmotProfile.CURRENT) return@runCatching false - val group = database.marmotEngine.groupFor(room.routingId) ?: return@runCatching false - announce(database, chatRoomId, group, room.chatRoom.userPublicKey) - }.getOrElse { - logger.e("Could not say $chatRoomId follows signed commits", it) - false - } - } - - /** - * The one device that switches [group]'s rule on: the admin in its lowest leaf -- - * in a room as it was made, its creator. Null when no admin holds a leaf. - * - * One, because the library settles two commits made at the same epoch for every - * device that only watched them, but not for the two that made them: those swap - * branches and stay apart (docs/marmot-v2.md, Phase 8). Every admin switching the - * moment the last member said it would be exactly that race. The lowest leaf is - * read off the group's state, so every device names the same one without a word - * between them. - */ - fun switcherOf(group: MlsGroup): HexKey? { - val admins = group.currentAdminIdentities() - return group.members() - .sortedBy { (leafIndex, _) -> leafIndex } - .firstNotNullOfOrNull { (_, leaf) -> - (leaf.credential as? Credential.Basic)?.identity?.toHexKey()?.takeIf { it in admins } - } - } - - /** - * Whether this device owes [room] the switch now: a keyed room on the current - * profile, open, not yet requiring the group's signature, whose [switcherOf] is - * this device's account, where every member has said they follow signed commits - * and enough of them are admins. The checks `requireSignatures` makes, read first - * so a room that is not ready is passed over rather than refused. - */ - suspend fun switchOwed(database: GizaDatabase, room: LocalChatRoom, group: MlsGroup): Boolean { - val me = room.chatRoom.userPublicKey - if (room.chatRoom.leftGroupAt != null || room.chatRoom.marmotProfile() != MarmotProfile.CURRENT) return false - if (!AdminGovernance.isKeyedRoom(group) || GovernanceGate.isGoverned(group)) return false - if (group.currentGroupState().isDisbanded) return false - if (switcherOf(group) != me) return false - if (missing(database, room.chatRoom.id, group).isNotEmpty()) return false - val admins = group.currentAdminIdentities() intersect AdminGovernance.members(group) - return admins.size >= AdminGovernance.adminFloor(database, room.chatRoom.id, group) - } - - /** - * Switches the rule on in every room of [me]'s that is owed it -- [switchOwed] -- - * saying first, where it has not, that this device follows signed commits, since - * it is a member too. Run by `GovernanceFollowThrough` whenever a member says it, - * and when it starts, so the switch needs nobody to open a screen or press - * anything. A switch still waiting for a relay is not sent twice; one that fails - * is logged and tried again on the next pass. - * - * @return how many rooms a switch was sent in. - */ - suspend fun switchWhereOwed(database: GizaDatabase, me: HexKey): Int = - database.chatRoomDao().getChatRoomIdsWithMlsState().count { chatRoomId -> - runCatching { - val room = database.chatRoomDao().findChatRoomById(chatRoomId) ?: return@runCatching false - if (room.chatRoom.userPublicKey != me) return@runCatching false - val engine = database.marmotEngine - val group = engine.groupFor(room.routingId) ?: return@runCatching false - if (switcherOf(group) != me) return@runCatching false - announce(database, chatRoomId, group, me) - if (!switchOwed(database, room, group)) return@runCatching false - if (!engine.gate.canPrepareLocalCommit(room.routingId)) return@runCatching false - database.marmotOutboundDao().requireSignatures(room) - logger.i("Switched on the group's signature for changes in $chatRoomId") - true - }.getOrElse { - if (it is CancellationException) throw it - logger.w("Couldn't switch on the group's signature in $chatRoomId: ${it.message}") - false - } - } - - private val logger = Logger.withTag("GovernanceSupport") -} diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt index 08663efc..77b933e3 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt @@ -109,6 +109,7 @@ object MarmotGroupCreation { name: String, purpose: String, adminPublicKeys: Set, + minimumAdmins: Int?, userPublicKey: HexKey, keyPair: KeyPair, path: List = SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH, @@ -133,7 +134,18 @@ object MarmotGroupCreation { keyPackage?.let { publicKey to it } } + // Born needing the group's signature for every change, with the floor of + // admins it may never go under: there is no later moment to switch the rule + // on, and nobody it waits for. Founding comes before it in effect -- the + // founding invite is the creator's commit while it is the room's only member, + // which no other device ever processes. docs/remove-convenient-groups.md, + // "After the build", and docs/member-admin-promotion.md, D7 and D8. + // + // [minimumAdmins] null is a room without the rule: one made before every keyed + // room was born with it, which tests of a group's mechanics still model. + // [createFor], the app's one caller, always passes the ceremony's. val description = SharedKeyDerivation.describe(purpose = purpose, path = path) + .let { if (minimumAdmins == null) it else GovernanceMarker.describe(it, minimumAdmins) } // On whichever profile new rooms are on. The room id is the derived key // either way; on the current profile the group's routing address is minted @@ -259,6 +271,7 @@ object MarmotGroupCreation { name = CeremonyFollowThrough.roomName(ceremony), purpose = CeremonyFollowThrough.roomPurpose(ceremony), adminPublicKeys = founders, + minimumAdmins = Quorum.minimumAdmins(ceremony.threshold), userPublicKey = ceremony.userPublicKey, keyPair = keyPair, parentChatRoomId = parentChatRoomId, diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt index f3b6dae0..b6b16dfe 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt @@ -27,7 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.dTag.DTag */ object GovernanceEvents { val ALL: Set = setOf( - GovernanceStatementEvent.KIND, OwnCommitEvent.KIND, GovernanceSupportEvent.KIND, GovernanceCarrierEvent.KIND, + GovernanceStatementEvent.KIND, OwnCommitEvent.KIND, GovernanceCarrierEvent.KIND, PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER, ) @@ -66,24 +66,6 @@ object OwnCommitEvent { arrayOf(DTag.assemble(chatRoomId), arrayOf(GovernanceEvents.EPOCH_TAG, epoch.toString())) } -/** - * A member's word that their device applies signed commits, said once per room so - * the room can tell when the rule can be switched on without leaving anybody behind. - * Signed by the member's account. docs/member-admin-promotion.md, Phase 4b. - */ -object GovernanceSupportEvent { - val KIND: Kind = 30372 - - const val VERSION_TAG = "governance" - const val VERSION = "signed-commits/v1" - - fun assembleTags(chatRoomId: HexKey): Array> = - arrayOf(DTag.assemble(chatRoomId), arrayOf(VERSION_TAG, VERSION)) - - fun supports(event: Event): Boolean = - event.kind == KIND && event.tags.any { it.size >= 2 && it[0] == VERSION_TAG && it[1] == VERSION } -} - /** * A member sending the group's signed statement into the room: its content is the * statement, as signed. The carrier vouches for nothing -- the statement inside is 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 ce1e3d83..e77a08d1 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -256,13 +256,6 @@ interface ChatRepository { */ suspend fun reconcileAdminFlags(): Int - /** - * Says, in every keyed room this device is in, that it follows signed commits, - * for the rooms joined before joining said it. Once per start. See - * `GovernanceSupport.announceAll`. - */ - suspend fun announceGovernanceSupport(): Int - /** * Takes every key ceremony [keyPair] coordinated from a key to a working room, * until cancelled: asks the group to sign its key state (a subgroup's parent to @@ -325,8 +318,6 @@ interface ChatRepository { */ suspend fun governanceStatus(chatRoomId: String): GovernanceStatus? - /** Makes a keyed room's changes need the group's signature. Throws with words a person can act on. */ - suspend fun requireSignatures(localChatRoom: LocalChatRoom) /** * Removes [memberPublicKey] from a current-profile room this device administers: @@ -595,8 +586,6 @@ interface ChatRepository { override suspend fun reconcileAdminFlags(): Int = 0 - override suspend fun announceGovernanceSupport(): Int = 0 - override suspend fun sendChatMessage( text: String, @@ -635,7 +624,6 @@ interface ChatRepository { override suspend fun governanceStatus(chatRoomId: String): GovernanceStatus? = null - override suspend fun requireSignatures(localChatRoom: LocalChatRoom) = Unit override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) = Unit 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 319166fe..4cabda03 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 @@ -1182,12 +1182,7 @@ fun ChatRoomDetailScreen( chatRoomDetailUIState.governance?.let { governance -> item { - GovernanceSection( - governance = governance, - canGovern = chatRoomDetailUIState.canGovern, - nameOf = nameOf, - me = chatRoomDetailUIState.localChatRoom.chatRoom.userPublicKey, - ) + GovernanceSection(governance = governance) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt index 6b9abaf1..45bf54ba 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt @@ -33,10 +33,6 @@ import mobi.giza.compose.resources.Res import mobi.giza.compose.resources.cancel import mobi.giza.compose.resources.disband_group_instead import mobi.giza.compose.resources.governance_on -import mobi.giza.compose.resources.governance_waiting -import mobi.giza.compose.resources.governance_switch_waits_for -import mobi.giza.compose.resources.governance_switching -import mobi.giza.compose.resources.require_signatures_explainer import mobi.giza.compose.resources.make_admin import mobi.giza.compose.resources.make_admin_and_leave import mobi.giza.compose.resources.make_admin_body @@ -203,61 +199,25 @@ internal fun LeaveAsAdminDialog( } /** - * Whether a keyed room's changes need the group's signature. Once they do, a line - * saying so; before, for an admin, whose device is switching it on -- or who it is - * still waiting on, since switching it on with a member whose device cannot follow - * would leave them in a different group from the first change. - * docs/member-admin-promotion.md, Phase 4b. - * - * Nothing to press: one device switches it on by itself once everybody can follow. + * That a keyed room's changes need the group's signature, and how few admins it may + * have. Every keyed room is born that way, so there is nothing to switch on and + * nobody to wait for. docs/member-admin-promotion.md, R2 and D8, and * docs/remove-convenient-groups.md, "After the build". */ @Composable -internal fun GovernanceSection( - governance: GovernanceStatus, - canGovern: Boolean, - nameOf: (HexKey) -> String, - me: HexKey, -) { - val explainer = Modifier.padding( - horizontal = MaterialTheme.spacing.containerPadding, - vertical = MaterialTheme.spacing.compactPadding, - ) - Column(modifier = Modifier.fillMaxWidth()) { - when (governance) { - is GovernanceStatus.Governed -> Text( - text = stringResource(Res.string.governance_on, governance.minimumAdmins), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = explainer, - ) - is GovernanceStatus.Ready -> if (canGovern && governance.switcher != null) { - Text( - text = if (governance.switcher == me) { - stringResource(Res.string.governance_switching) - } else { - stringResource(Res.string.governance_switch_waits_for, nameOf(governance.switcher)) - }, - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = explainer, - ) - Text( - text = stringResource(Res.string.require_signatures_explainer), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = explainer, - ) - } - is GovernanceStatus.Waiting -> if (canGovern) { - Text( - text = stringResource(Res.string.governance_waiting, governance.missing.map(nameOf).sorted().joinToString()), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = explainer, - ) - } - } +internal fun GovernanceSection(governance: GovernanceStatus) { + when (governance) { + is GovernanceStatus.Governed -> Text( + text = stringResource(Res.string.governance_on, governance.minimumAdmins), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .fillMaxWidth() + .padding( + horizontal = MaterialTheme.spacing.containerPadding, + vertical = MaterialTheme.spacing.compactPadding, + ), + ) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt index ec8383ce..0cb4d9b5 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt @@ -255,12 +255,6 @@ class SynchronizationViewModel( // written. docs/robust-group-admins.md, Phase 6. runCatching { chatRepository.reconcileAdminFlags() } .onFailure { logger.e("Could not bring admin flags in line", it) } - // A member who joined a keyed room before joining said it - // follows signed commits, and never opened its screen, holds - // the room back from requiring them -- and so from making - // anyone an admin. docs/remove-convenient-groups.md. - runCatching { chatRepository.announceGovernanceSupport() } - .onFailure { logger.e("Could not say which rooms this device follows", it) } launch(Dispatchers.IO) { observePendingBroadcastNostrEventRequests(keyPair) } // Runs until cancelled rather than draining a queue, but it // belongs here for the same reason the pumps do: it needs the diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt index 412024ce..cee24d8d 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt @@ -1,22 +1,12 @@ package mobi.giza.compose.ui.view.state -import com.vitorpamplona.quartz.nip01Core.core.HexKey - /** - * Where a keyed room stands on needing the group's signature for its changes. - * docs/member-admin-promotion.md, R2 and Phase 4b. + * How a keyed room needs the group's signature for its changes. Every keyed room + * Giza makes is born needing it (docs/remove-convenient-groups.md, "After the + * build"); a room with no state saying so -- one made before that -- has none. + * docs/member-admin-promotion.md, R2. */ sealed interface GovernanceStatus { - /** It does: every change is proposed, signed by the group, and only then applied. */ + /** Every change is proposed, signed by the group, and only then applied. */ data class Governed(val minimumAdmins: Int) : GovernanceStatus - - /** - * It does not yet, and every member's device could follow: [switcher]'s device - * switches it on by itself, the next time it is online. Null [switcher] when no - * admin holds a leaf. docs/remove-convenient-groups.md, "After the build". - */ - data class Ready(val minimumAdmins: Int, val switcher: HexKey?) : GovernanceStatus - - /** It does not yet, and these members have not said their device could follow. */ - data class Waiting(val missing: Set) : GovernanceStatus } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt index 9d0c2aaf..7774fea7 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt @@ -308,14 +308,16 @@ class AdminChangesJvmTest { assertIs( MarmotGroupCreation.create( database = db, chatRepository = chatRepository, groupId = keyedRoomId, name = "#keyed", - purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair, - profile = MarmotProfile.CURRENT, + purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, + userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT, ) ) val keyedRoom = db.chatRoomDao().findChatRoomById(keyedRoomId)!! + // Born needing the group's signature, so an admin's own step-down is refused + // outright: another admin proposes it, and the group signs. val refusal = assertFailsWith { chatRepository.demoteMember(keyedRoom, user) } - assertEquals(mobi.giza.compose.database.dao.MarmotOutboundDao.KEYED_ROOM_REFUSAL, refusal.message) + assertTrue("another admin removes you as admin" in refusal.message.orEmpty(), refusal.message) assertTrue(db.marmotPublishObligationDao().getAll().isEmpty()) val keyedGroup = db.marmotEngine.groupFor(keyedRoom.routingId)!! assertEquals(AdminLeave.CANNOT, AdminGovernance.adminLeave(keyedGroup, user)) diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt index 240f8138..ba61c85b 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt @@ -14,7 +14,6 @@ import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync import kotlin.test.AfterTest import mobi.giza.compose.extensions.toHex import mobi.giza.compose.ui.view.state.GovernanceStatus -import mobi.giza.compose.nostr.frost.GovernanceSupportEvent import mobi.giza.compose.database.repository.DatabaseNostrRepository import mobi.giza.compose.database.repository.DatabaseChatRepository import kotlin.test.assertIs @@ -217,41 +216,8 @@ class GovernanceGateJvmTest { assertEquals(setOf(dana.hex, userHex), appGroup().currentAdminIdentities()) } - // --- Phase 4b: who can follow, and the switch --------------------------------- - private val erin = MarmotStandIn() - /** Erin joins Dana's room, by Dana's bare commit; the app applies it. */ - private suspend fun erinJoins() { - MarmotStandIn.seedProfile(db, erin.hex, "Erin") - erin.makeBundle() - val add = dana.commitLocally(routingId) { dana.manager.addMember(routingId, erin.bundle.keyPackage.toTlsBytes()) } - erin.manager.processWelcome(assertNotNull(add.welcomeBytes), erin.bundle) - erin.inbound.trackGroup(routingId) - MarmotStandIn.storeInApp(db, user, commitEvent(add)) - } - - /** Dana makes [admins] the admin list by a bare commit, which Erin and the app apply. */ - private suspend fun danaSetsAdminsBare(admins: List) { - val commit = dana.commitLocally(routingId) { - val staged = dana.manager.stageAppDataUpdate(routingId, AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(admins).encode()) - dana.manager.installState(routingId, staged.pendingState) - staged.result - } - val event = commitEvent(commit) - erin.inbound.processGroupEvent(event) - MarmotStandIn.storeInApp(db, user, event) - } - - /** [member] says, in the room, that their device follows signed commits. */ - private suspend fun says(member: MarmotStandIn) { - val payload = MarmotAppEvent.build( - pubKey = member.hex, kind = GovernanceSupportEvent.KIND, content = "", createdAt = 1_700_000_002, - tags = GovernanceSupportEvent.assembleTags(roomId), - ).encodeToPayload() - MarmotStandIn.storeInApp(db, user, member.outbound.buildGroupEventFromBytes(routingId, payload).signedEvent) - } - private suspend fun room() = db.chatRoomDao().findChatRoomById(roomId)!! /** The relay's OK on the newest commit this device put on the wire. */ @@ -264,146 +230,6 @@ class GovernanceGateJvmTest { return event.toGroupEvent(userHex)!! } - /** Takes back what this device said, as a device that joined before joining said it. */ - private suspend fun forgetOurSupport() { - db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(GovernanceSupportEvent.KIND)) - .filter { it.publicKey == userHex } - .forEach { db.marmotInnerEventDao().deleteById(it.id) } - assertFalse(userHex in GovernanceSupport.supporters(db, roomId)) - } - - @Test - fun `a member welcomed into a keyed room says it on joining`() = runBlocking { - // Nobody else says anything after the Welcome: what the others said before it - // is at an epoch this device cannot read. docs/remove-convenient-groups.md. - governedRoom(governed = false) - - assertTrue(userHex in GovernanceSupport.supporters(db, roomId), "joining did not say it") - assertEquals(setOf(dana.hex), GovernanceSupport.missing(db, roomId, appGroup())) - } - - @Test - fun `a device that joined before joining said it says it when it starts`() = runBlocking { - governedRoom(governed = false) - forgetOurSupport() - - assertEquals(1, chatRepository.announceGovernanceSupport()) - assertTrue(userHex in GovernanceSupport.supporters(db, roomId)) - assertEquals(0, chatRepository.announceGovernanceSupport(), "said twice") - } - - private val frank = MarmotStandIn() - - /** Frank joins Dana's room after Erin, by Dana's bare commit; Erin and the app apply it. */ - private suspend fun frankJoins() { - MarmotStandIn.seedProfile(db, frank.hex, "Frank") - frank.makeBundle() - val add = dana.commitLocally(routingId) { dana.manager.addMember(routingId, frank.bundle.keyPackage.toTlsBytes()) } - frank.manager.processWelcome(assertNotNull(add.welcomeBytes), frank.bundle) - frank.inbound.trackGroup(routingId) - val event = commitEvent(add) - erin.inbound.processGroupEvent(event) - MarmotStandIn.storeInApp(db, user, event) - } - - @Test - fun `the first admin's device switches the rule on by itself once everyone has said it`() = runBlocking { - // Dana made the room and holds its first leaf; once she is no admin, the app's - // leaf is the lowest an admin holds, and the switch is the app's to make. - governedRoom(governed = false) - erinJoins() - frankJoins() - val admins = listOf(userHex, erin.hex, frank.hex) - val commit = dana.commitLocally(routingId) { - val staged = dana.manager.stageAppDataUpdate(routingId, AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(admins).encode()) - dana.manager.installState(routingId, staged.pendingState) - staged.result - } - val event = commitEvent(commit) - erin.inbound.processGroupEvent(event) - frank.inbound.processGroupEvent(event) - MarmotStandIn.storeInApp(db, user, event) - assertEquals(userHex, GovernanceSupport.switcherOf(appGroup())) - - says(dana) - says(erin) - GovernanceFollowThrough.pass(db, user) - assertFalse(GovernanceGate.isGoverned(appGroup()), "switched on before Frank said it") - - says(frank) - GovernanceFollowThrough.pass(db, user) - okTheLatestCommit() - - assertTrue(GovernanceGate.isGoverned(appGroup()), "nobody pressed anything, and nothing happened") - assertEquals(0, GovernanceSupport.switchWhereOwed(db, userHex), "switched twice") - } - - @Test - fun `a device that is not the first admin leaves the switch to it`() = runBlocking { - // Every admin's device switching the moment the last member said it would be two - // commits at one epoch, which the library cannot settle for their authors. - governedRoom(governed = false) - erinJoins() - danaSetsAdminsBare(listOf(dana.hex, userHex, erin.hex)) - says(dana) - says(erin) - assertEquals(GovernanceStatus.Ready(minimumAdmins = 3, switcher = dana.hex), chatRepository.governanceStatus(roomId)) - - GovernanceFollowThrough.pass(db, user) - - assertEquals(0, GovernanceSupport.switchWhereOwed(db, userHex)) - assertFalse(GovernanceGate.isGoverned(appGroup())) - assertTrue(db.marmotCommitResultDao().let { dao -> - db.nostrEventDao().getMLSGroupEvents(since = kotlin.time.Instant.fromEpochSeconds(0), limit = 50) - .none { it.kind == GroupEvent.KIND && dao.getMarmotCommitRequestById(it.id) != null } - }, "the app sent a commit of its own") - } - - @Test - fun `hearing another member say it, this device says it back`() = runBlocking { - governedRoom(governed = false) - forgetOurSupport() - - says(dana) - - assertTrue(userHex in GovernanceSupport.supporters(db, roomId), "the app did not answer") - assertTrue(dana.hex in GovernanceSupport.supporters(db, roomId)) - } - - @Test - fun `the switch waits for every member, then turns the rule on for everyone`() = runBlocking { - governedRoom(governed = false) - erinJoins() - danaSetsAdminsBare(listOf(dana.hex, userHex, erin.hex)) - says(dana) - - val waiting = assertIs(chatRepository.governanceStatus(roomId)) - assertEquals(setOf(erin.hex), waiting.missing) - val refusal = assertFailsWith { chatRepository.requireSignatures(room()) } - assertTrue("Erin" in refusal.message.orEmpty(), refusal.message) - - says(erin) - assertEquals(GovernanceStatus.Ready(minimumAdmins = 3, switcher = dana.hex), chatRepository.governanceStatus(roomId)) - - chatRepository.requireSignatures(room()) - val switch = okTheLatestCommit() - - assertEquals(3, GovernanceGate.minimumAdmins(appGroup()), "the rule is not on here") - dana.inbound.processGroupEvent(switch) - assertEquals(3, GovernanceMarker.minimumAdmins(dana.manager.getGroup(routingId)!!.roomDescription()), "the rule did not reach Dana") - assertEquals(GovernanceStatus.Governed(3), chatRepository.governanceStatus(roomId)) - - // And from here, Dana's bare commit is refused. - val epoch = appGroup().epoch - val bare = dana.commitLocally(routingId) { - val staged = dana.manager.stageAppDataUpdate(routingId, AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(listOf(dana.hex, userHex)).encode()) - dana.manager.installState(routingId, staged.pendingState) - staged.result - } - MarmotStandIn.storeInApp(db, user, commitEvent(bare)) - assertEquals(epoch, appGroup().epoch, "a bare commit landed after the switch") - } - // --- Phase 5: this device proposes, the group signs, this device publishes ------ /** The app made an admin beside Dana, inside the group's signature. */ diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt index 90cfeba2..3fb25f99 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt @@ -84,7 +84,7 @@ class GroupLifecycleJvmTest { assertIs( MarmotGroupCreation.create( database = db, chatRepository = chatRepository, groupId = roomId, name = "#room", - purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair, + purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = null, userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT, ) ) diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt index 3fc1c19d..2b2dacb0 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt @@ -83,7 +83,7 @@ class MarmotGroupCreationJvmTest { purpose = "Admins of Ekklesia.", // A group of one, so nothing has to be invited and no key package has // to be found. The flag is the whole of what is being tested. - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, ) @@ -112,7 +112,7 @@ class MarmotGroupCreationJvmTest { groupId = groupId, name = "#Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, ) @@ -148,7 +148,7 @@ class MarmotGroupCreationJvmTest { // so a caller that forgot would mark the room on no device at all. name = "Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, ) @@ -176,7 +176,7 @@ class MarmotGroupCreationJvmTest { groupId = groupId, name = "#Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, ) @@ -274,6 +274,9 @@ class MarmotGroupCreationJvmTest { val group = assertNotNull(created.room.chatRoom.toMlsGroup()) assertEquals(founders, group.currentAdminIdentities(), "${owner.pubKey.toHexKey().take(8)}'s room") + // Born needing the group's signature, with the floor its 2-of-3 quorum + // sets: nothing to switch on later. docs/remove-convenient-groups.md. + assertEquals(Quorum.minimumAdmins(threshold = 2), GovernanceGate.minimumAdmins(group), "the room was born without the rule") } } finally { alicesDb.close() @@ -332,7 +335,7 @@ class MarmotGroupCreationJvmTest { groupId = groupId, name = "#Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT, @@ -368,7 +371,7 @@ class MarmotGroupCreationJvmTest { groupId = groupId, name = "#Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.LEGACY, @@ -396,7 +399,7 @@ class MarmotGroupCreationJvmTest { groupId = groupId, name = "#Ekklesia", purpose = "Admins of Ekklesia.", - adminPublicKeys = setOf(user), + adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT, diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt index b1eaafda..cb66e7be 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt @@ -73,7 +73,7 @@ class PublishBeforeApplyJvmTest { seedProfile(user) val outcome = MarmotGroupCreation.create( database = db, chatRepository = chatRepository, groupId = roomId, name = "#room", - purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair, + purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = null, userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT, ) assertIs(outcome) diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt index c48ec120..ab4888af 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt @@ -1,5 +1,6 @@ package mobi.giza.compose.managers +import mobi.giza.compose.ui.view.state.GovernanceStatus import androidx.room3.Room import com.vitorpamplona.marmot.groups.currentAdminIdentities import com.vitorpamplona.marmot.groups.isLocalAdmin @@ -14,6 +15,7 @@ import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent import kotlin.test.Test +import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertEquals import kotlin.test.assertIs @@ -115,6 +117,7 @@ class RobustGroupAdminsJvmTest { name = "Ekklesia", purpose = "Admins of Ekklesia.", adminPublicKeys = phones.map { it.publicKey }.toSet(), + minimumAdmins = Quorum.MINIMUM_GROUP_SIZE, userPublicKey = creator.publicKey, keyPair = creator.keyPair, keyPackageLookupTimeout = 2_000L, @@ -217,6 +220,18 @@ class RobustGroupAdminsJvmTest { later.ready() (phones + later).forEach { phone -> (phones + later).forEach { MarmotStandIn.seedProfile(phone.db, it.publicKey) } } + if (profile == MarmotProfile.CURRENT) { + // Born needing the group's signature: a later invite is a proposal the + // group signs, never a commit of the creator's own -- which is also what + // proves it did not take the founding path. These phones hold no share + // of a real key, so it stops there. docs/remove-convenient-groups.md. + val refusal = assertFailsWith { + creator.chatRepository.inviteMember(creator.room(), later.publicKey, later.keyPackage) + } + assertEquals("This group has no shared key to sign with", refusal.message) + assertTrue(creator.db.marmotPublishObligationDao().getAll().isEmpty(), "a bare commit went out") + return@use + } creator.chatRepository.inviteMember(creator.room(), later.publicKey, later.keyPackage) creator.okTheLatestCommit() welcome(from = creator, to = later) @@ -400,6 +415,23 @@ class RobustGroupAdminsJvmTest { // ---- A group run by one person ------------------------------------------------ + /** + * The rule is in the state the founders are welcomed into, so a joiner's phone + * enforces it from its first epoch -- there is no switch for anybody to wait on, + * press, or miss. docs/remove-convenient-groups.md, "After the build". + */ + @Test + fun `a group is born needing its signature, on every founder's phone`() = + onEveryProfile(listOf(MarmotProfile.CURRENT)) { _, phones -> + phones.forEach { phone -> + assertEquals( + GovernanceStatus.Governed(minimumAdmins = Quorum.MINIMUM_GROUP_SIZE), + phone.chatRepository.governanceStatus(roomId), + "$phone's room", + ) + } + } + /** * Giza stops making groups its creator runs alone, and does not stop joining * them. docs/remove-convenient-groups.md, D4: a Bennu member still makes them, @@ -426,6 +458,7 @@ class RobustGroupAdminsJvmTest { name = "Checkers", purpose = "Run by its creator.", adminPublicKeys = setOf(creator.publicKey), + minimumAdmins = 1, userPublicKey = creator.publicKey, keyPair = creator.keyPair, keyPackageLookupTimeout = 2_000L, diff --git a/docs/member-admin-promotion.md b/docs/member-admin-promotion.md index 2baea9e3..1e67c2d2 100644 --- a/docs/member-admin-promotion.md +++ b/docs/member-admin-promotion.md @@ -196,6 +196,9 @@ being invited. ### D4. The commit rides inside the signature, and the rule lives in the group's state (R2) +*Since built further: the rule is no longer switched on. A keyed room is born with it +([remove-convenient-groups.md](./remove-convenient-groups.md), "After the build").* + Two choices here decide whether R2 holds at all. **The commit inside the signature, not beside it.** The group signs an event whose @@ -461,8 +464,9 @@ does not; nothing changes in a room without the marker. - **Require signatures for changes**, on a keyed room's detail screen, for an admin, once every current member has said it. It is one bare commit adding the marker line to the profile description. Until every member has, the screen names who has not. (Since - made automatic -- one device, the admin in the lowest leaf, sends it once everybody has - said it, and the button is gone; [remove-convenient-groups.md](./remove-convenient-groups.md), + removed, with the support event: a keyed room is born governed, its floor in its + epoch-0 description, because Giza no longer keeps compatibility with Bennu or older + builds, which were all the switch protected; [remove-convenient-groups.md](./remove-convenient-groups.md), "After the build".) - An invite into a governed room is refused for an account that has not said it, with words that say why, once it is in the room (it says so from its own device on joining). diff --git a/docs/remove-convenient-groups.md b/docs/remove-convenient-groups.md index d004c08a..29baf335 100644 --- a/docs/remove-convenient-groups.md +++ b/docs/remove-convenient-groups.md @@ -389,81 +389,53 @@ detail screen, and a Bennu peer's convenient group still reaches them. they were written. Add a parenthetical saying it was removed here. - [README.md](./README.md): the table row, which this commit adds, says "built". -### After the build: an invited member holds the group back +### After the build: a group is born needing its signature Found on a device, with this plan merged alongside member-admin-promotion. A robust group's founders were admins holding shares; a member invited afterwards (D7 lets a -keyed room take one) was a plain member, as designed. But nobody could make them an -admin: the ⋮ on their row offered only **Remove from group**, and the room said it was -waiting for them to update Giza when they already had. +keyed room take one) was a plain member, as designed -- but nobody could make them an +admin. The ⋮ on their row offered only **Remove from group**. Making a member of a keyed room an admin needs the room to require the group's -signature (`AdminGovernance.keyedChangesAllowed`), and that can be switched on only -once every member's device has said it follows signed commits -(`GovernanceSupport.missing`). A device said it when its room's screen was opened, and -back when it heard another member say it. The founders had all said it before the -invite, and an invited member cannot read anything sent at an epoch before its own -- -so it never heard one to answer, nobody said it again, and the room waited on a -screen the member had no reason to open. +signature for its changes (`AdminGovernance.keyedChangesAllowed`). That rule was +switched on after founding by an admin pressing **Require the group's signature for +changes**, and only once every member's device had said, in the room, that it could +follow signed commits (member-admin-promotion, D4 and Phase 4b). The founders said it +before the invite, at an epoch the new member could not read, so the new member's +device never heard anybody to answer and the room waited on it for good. -- **A device says it on joining.** The Welcome path in `NostrDao`, beside - `AdminFlags.reconcile`, for a current-profile room. -- **And once each start** (`GovernanceSupport.announceAll`, from - `SynchronizationViewModel` beside `reconcileAdminFlags`), for the members who joined - before joining said it. A room that has it already is a read and no write. -- **The notice** (`governance_waiting`) names who the room is waiting on and what for -- - "Waiting for Alice to open an up-to-date Giza. Until then, this group can't require - its signature on changes, and nobody else can be made an admin." -- instead of - telling them to update, which they often had, with a verb that did not agree with - one name. +That was fixed twice over -- a device said it on joining and at each start, then the +switch was made by one device on its own -- before the question underneath was asked: +what was the switch for? Only to keep a Bennu member, or one on an older Giza, from +being left in a different group by the first signed change. Giza is in development and +keeps compatibility with neither, so the switch protected nobody. It is gone, and so is +everything that fed it: -Pinned in `GovernanceGateJvmTest`: a welcomed member has said it before anybody else -speaks, and a device whose saying is taken back says it again at start, once. +- **A keyed room is born governed.** `MarmotGroupCreation.createFor` writes + `GovernanceMarker`'s line into the room's epoch-0 description, with the floor its + ceremony's quorum sets (`Quorum.minimumAdmins`). Every founder is welcomed into a + state that already enforces the rule; a member added later is added by the group's + signature, like every other change. +- **Founding still needs no signature.** The founding invite, and finishing one that + failed (robust-group-admins, Phase 4), are the creator's commits while it is the + room's only member. No other device ever processes them -- joiners start from the + Welcome -- so there is nobody to refuse them. member-admin-promotion's D7 holds as + written. +- **Removed:** `GovernanceSupport` and its event (kind 30372), the announcement on + joining, at start and in answer to another member, the switch and + `requireSignatures`, the button, and the screen's *waiting* and *ready* states. The + room's details say only that changes need the group's signature, and the floor. -#### The switch is nobody's to press +Pinned by `MarmotGroupCreationJvmTest` (the room `createFor` makes carries the floor its +2-of-3 ceremony sets) and `RobustGroupAdminsJvmTest` (every founder's phone, after a +real Welcome, reads the room as governed with three admins at least; a later invite is +a proposal for the group to sign, never the creator's own commit). -Even then an admin had to find **Require the group's signature for changes** on the -room's screen and tap it. Nothing about the switch is a decision: the two conditions it -waits on -- every member can follow, enough of them are admins -- are already checked in -code, and a group whose point is a key its members hold together is a group that means -to sign its changes. So the button is gone, and one device switches the rule on by -itself. +A keyed room made before this has no marker, and nothing will ever add one: its +admins cannot be changed. Make the group again. -- **Which device.** The admin in the room's lowest leaf (`GovernanceSupport.switcherOf`) - -- in a room as it was made, its creator. Not every admin's: two commits at one epoch - are settled for every device that watched them but not for the two that made them, - which swap branches and stay apart ([marmot-v2.md](./marmot-v2.md), Phase 8). Every - device reads the same leaf off the same state, so they agree on one without a word - between them. -- **When.** `GovernanceFollowThrough`, which already runs while the app is open and - reads everything again on each pass, now passes whenever a member says it follows - signed commits, and on start. A room that is owed the switch (`switchOwed`) gets the - commit `requireSignatures` always sent; one still waiting for a relay is not sent - twice. -- **The screen** says which device it is waiting on: "Turning on the group's signature - for changes." on that device, "Changes will need the group's signature as soon as - Bob's Giza is next online." on the others. - -*Not at creation*, though that was the first preference. A room born governed -- -the marker in its epoch-0 description -- would need no switch, but: - -- a Bennu founder, or one on an older Giza build, takes part in the ceremony like - anyone else, and would apply the bare commits Giza drops: in a different group from - the first change, with nobody told. The support check is the only thing that knows, - and it can only be asked once the room exists; -- a founder whose founding invite has to be finished later (robust-group-admins, - Phase 4) is added by a bare commit, which the founders already in a governed room - would refuse. - -Switching once everybody has joined and said it costs the seconds it takes the -founders' devices to process their Welcomes, and costs nothing when one of them cannot -follow -- the room simply stays as it is. - -Pinned in `GovernanceGateJvmTest`: the first admin's device switches by itself once the -last member says it, and not before; any other admin's device sends nothing. - -Then the member's row offers **Make admin** -- with the room's share rotation on, which -is a development build for now -- and the member accepts on their own device. +Promoting a member still needs the room's share rotation on -- a development build, +for now -- and the member accepts on their own device. ## Out of scope