From 8ef02129addea4b29ffcec6fae9ad6e62497d076 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Mon, 23 Nov 2026 14:22:04 +0200 Subject: [PATCH] test: a confederation formed over its groups' rooms and inboxes end to end, and the record (confederation-dkg-inboxes, Phase 8) ConfederationNetworkJvmTest forms a confederation on three groups of three, each with a real inbox and a real MLS room, with one group's first admin never carrying. All nine devices reach one key, and none holds a NIP-17 room or a ceremony gift wrap. ConfederationTestGroups.pumpConfederation takes devices that do not carry. The record: the plan's progress and where the build chose differently, the report marked as implemented, the README rows, and since notes in the coordinator-free, profile and room-removal plans. Nothing has run on a device or a real relay. Co-Authored-By: Claude Opus 5.5 --- .../managers/ConfederationNetworkJvmTest.kt | 34 +++++++++++ .../managers/ConfederationTestGroups.kt | 9 +-- docs/README.md | 4 +- docs/confederation-dkg-inboxes.md | 57 ++++++++++++++----- docs/confederation-dkg-without-nip17-room.md | 2 +- docs/confederation-profile.md | 4 ++ docs/confederation-room-removal.md | 3 +- docs/confederation-without-coordinator.md | 2 + 8 files changed, 93 insertions(+), 22 deletions(-) diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationNetworkJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationNetworkJvmTest.kt index e5f8b947..2d3e8b99 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationNetworkJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationNetworkJvmTest.kt @@ -14,6 +14,7 @@ import mobi.giza.compose.database.model.ChatMessage import mobi.giza.compose.nostr.confederation.ConfederationKinds import mobi.giza.compose.nostr.confederation.ConfederationProposalState import kotlin.time.Clock +import kotlin.time.Duration.Companion.minutes /** * Three groups agreeing, or not, to form a confederation, end to end, with nobody coordinating it @@ -153,4 +154,37 @@ class ConfederationNetworkJvmTest { withoutInbox.close() } } + + // ---- docs/confederation-dkg-inboxes.md, Phase 8: forming it with no NIP-17 room ---------------- + + @Test + fun `the groups form the confederation over their own rooms and inboxes, with one group's first admin never carrying`() = runBlocking { + val proposalId = proposeAtlas() + network.signed(polis) { ConfederationManager.proposeAcceptance(it.db, it.room(), it.publicKey, proposalId).id } + network.signed(ekklesia) { ConfederationManager.proposeAcceptance(it.db, it.room(), it.publicKey, proposalId).id } + assertEquals(setOf(ConfederationProposalState.ACCEPTED), states(proposalId)) + + val idle = polis.devices.minBy { it.publicKey } + val owedBefore = idle.db.groupInboxDao().getPublicationsForRoom(polis.roomId).size + network.everyDevice.forEach { ConfederationRitualManager.join(it.db, proposalId, it.publicKey, it.secret) } + network.pumpConfederation(at = Clock.System.now() + 10.minutes, noCarry = setOf(idle)) + + val ceremonies = network.everyDevice.associateWith { it.db.confederationCeremonyDao().getLatestForProposal(proposalId) } + ceremonies.forEach { (device, ceremony) -> + assertEquals(mobi.giza.compose.database.model.ConfederationCeremonyStage.COMPLETE, ceremony?.stage, "${device.name}: ${ceremony?.failureReason}") + } + assertEquals(1, ceremonies.values.map { it!!.confederationPublicKey }.toSet().size, "one key on all nine devices") + network.everyDevice.forEach { device -> + val formed = assertNotNull(device.db.confederationCeremonyDao().getConfederationForProposal(proposalId), "${device.name} holds the record") + assertTrue(ConfederationFormation.verifies(formed)) + } + + // No NIP-17 room, and nothing as a gift wrap: the rounds went through the groups. + val people = network.everyDevice.map { it.publicKey }.toSet() + network.everyDevice.forEach { device -> + kotlin.test.assertNull(device.db.chatRoomDao().findChatRoomById(mobi.giza.compose.database.model.ChatRoom.deriveChatRoomId(people)), "${device.name}") + assertEquals(emptyList(), device.db.giftWrapPayloadDao().getByKinds(mobi.giza.compose.nostr.confederation.ConfederationRitualEvents.ALL.toList())) + } + assertEquals(owedBefore, idle.db.groupInboxDao().getPublicationsForRoom(polis.roomId).size, "Polis's first admin carried nothing; its next admins did") + } } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationTestGroups.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationTestGroups.kt index 84dfb1b6..cd063df5 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationTestGroups.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationTestGroups.kt @@ -120,13 +120,14 @@ class ConfederationTestGroups( } /** - * A confederation's signing between these groups, until nothing moves: each group's room, every - * admin's turn at carrying at [at], and the inboxes (docs/confederation-room-removal.md, D4). + * A confederation's signing, or its key ceremony (docs/confederation-dkg-inboxes.md), between these + * groups, until nothing moves: each group's room, every admin's turn at carrying at [at], and the + * inboxes (docs/confederation-room-removal.md, D4). [noCarry] devices take part but never carry. */ - suspend fun pumpConfederation(at: Instant? = null) { + suspend fun pumpConfederation(at: Instant? = null, noCarry: Set = emptySet()) { do { groups.forEach { it.harness.pump() } - val carried = everyDevice.sumOf { ConfederationBridge.sweep(it.db, it.publicKey, it.secret, at ?: Clock.System.now()) } + val carried = everyDevice.filter { it !in noCarry }.sumOf { ConfederationBridge.sweep(it.db, it.publicKey, it.secret, at ?: Clock.System.now()) } val moved = deliver() } while (carried > 0 || moved > 0) groups.forEach { it.harness.pump() } diff --git a/docs/README.md b/docs/README.md index 70215a05..1a8e6a01 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,8 +19,8 @@ the [retired](./retired/) notes now. | [confederation-without-coordinator.md](./confederation-without-coordinator.md) | a confederation nobody coordinates: a phased plan, built but for its device run and behind flags that are off in release. The proposal and every answer travel as NIP-17 messages between the groups' NIP-4E inboxes, each sealed by its group's quorum, so every admin of every group reads every admin list and computes the outcome, and the key ceremony derives its room and session seed and computes the coordinator's broadcast on every device. Covers why a group could be the DKG's coordinator and does not need to be, why the admin lists stop being a payload encrypted to one person, why a confederation names at most twelve groups, how a group that says different things to different groups is caught, and who makes the confederation's room when nobody is in charge | | [confederation-profile.md](./confederation-profile.md) | a formed confederation's nostr profile, decided by its groups: a phased plan, built but for its device run and behind flags that are off in release. The confederation gets its own screen, reached from each member group's screen, and an edit there is a statement by the editing group, sealed by its quorum and sent to every member group's inbox, which the others endorse or object to by their own quorums. Once `T` groups have endorsed, each group's signed voucher is a role holder's consent, so the confederation signs and publishes the profile with nobody asked again. Covers why the rule is `T` of `N`, why a transferable voucher is needed beside the non-transferable seals, who starts the signing, and how the confederation's room and the key ceremony's room come to say what they are | | [confederation-room-removal.md](./confederation-room-removal.md) | taking away the confederation's own Marmot room: a phased plan, built but for its device run and behind flags that are off in release. A role holder's signing messages go into their own group's room, each group's admins carry them between groups through the inboxes, one at a time in order, and the posts, charter and signing attempts the room offered move to the confederation's screen. Covers why the nested signing still has to cross between groups every round, why each message becomes a signed event so it can be carried, why a demoted founder keeps signing and a removed one stops, and dropping the rooms already on devices while refusing a Welcome back into one | -| [confederation-dkg-without-nip17-room.md](./confederation-dkg-without-nip17-room.md) | a report, not built: whether a confederation can be formed without the NIP-17 room its key ceremony runs in, with the rounds carried between the groups' inboxes and each group's admins coordinating in their own room. Finds that it can, over the bridge signing already uses, since every person in the ceremony is an admin who reads their group's inbox and every step is rebuilt from stored messages. Covers why a group can carry its admins' dealings but never combine them, the three ways to move a round and what each costs, the size of a dealings round against NIP-44's and a relay's limits, the fallback when a group's carriers are away, and a founders' chat that shares the ceremony room's id | -| [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md) | the phased plan for the report above, not built, behind flags that are off in release: the confederation's key ceremony moves off its NIP-17 room onto the groups' rooms and inboxes, carried by each group's admins as signing already is. Covers the ceremony envelope (30379) and why it is its own kind, the bridge's second scope keyed by proposal so carriers need not have joined, envelopes split by bytes, schema 54, the join that needs the group's inbox key, and a migration that removes ceremony rooms without taking a founders' chat that shares their id | +| [confederation-dkg-without-nip17-room.md](./confederation-dkg-without-nip17-room.md) | a report, since implemented by the plan below: whether a confederation can be formed without the NIP-17 room its key ceremony runs in, with the rounds carried between the groups' inboxes and each group's admins coordinating in their own room. Finds that it can, over the bridge signing already uses, since every person in the ceremony is an admin who reads their group's inbox and every step is rebuilt from stored messages. Covers why a group can carry its admins' dealings but never combine them, the three ways to move a round and what each costs, the size of a dealings round against NIP-44's and a relay's limits, the fallback when a group's carriers are away, and a founders' chat that shares the ceremony room's id | +| [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md) | the phased plan for the report above, built but for its device run and behind flags that are off in release: the confederation's key ceremony moves off its NIP-17 room onto the groups' rooms and inboxes, carried by each group's admins as signing already is. Covers the ceremony envelope (30379) and why it is its own kind, the bridge's second scope keyed by proposal so carriers need not have joined, envelopes split by bytes, schema 54, the join that needs the group's inbox key, and a migration that removes ceremony rooms without taking a founders' chat that shares their id | | [confederation-proposals.md](./confederation-proposals.md) | everything a formed confederation signs -- its profile, its posts, its charter -- decided by its groups the way its profile already was, behind flags that are off in release. A post or the charter is a 9435 like a profile change, endorsed or objected to by each group's quorum, and signed with nobody asked once `T` groups have vouched; the per-person approve and decline, and the Signing screen, are gone. The confederation's screen lists them all as Proposals | | [confederation-upstream.md](./confederation-upstream.md) | the work below Giza that unblocks the confederation's Parts B and C: a phased plan, not built, across secp256k1-zkp, secp256k1-kmp and bitcoin-kmp. Covers why the one-process DKG and signing cannot simply be exposed step by step (the coordinator derives everyone's key state, acknowledgment is signed before the share is stored, nonce randomness is derived from the session id), why every DKG step can stay stateless, the storage contract a device follows, and Prefractal as an all-groups-must-sign path that needs no upstream work | | [automatic-key-ceremony.md](./automatic-key-ceremony.md) | joining is the only approval: a phased plan, built but for its device session, that makes a key ceremony run by itself after a member joins. Covers why contributing and confirming were never decisions a person could add to, the resume sweep that replaces the tap, the coordinator's follow-up steps and the one key state a device can sign without asking, and why abandon stays | diff --git a/docs/confederation-dkg-inboxes.md b/docs/confederation-dkg-inboxes.md index 3ef17348..4f587c7b 100644 --- a/docs/confederation-dkg-inboxes.md +++ b/docs/confederation-dkg-inboxes.md @@ -18,22 +18,41 @@ Read [confederation-without-coordinator.md](./confederation-without-coordinator. ceremony as it runs, and [confederation-room-removal.md](./confederation-room-removal.md) D2 to D4 for the bridge. -Written against `24991e1c`, on 2026-11-23. **Not built.** Behind `ExperimentalFeatures.confederation` -and `ExperimentalFeatures.groupInbox`, both off in release. Paths starting `K/` are under -`composeApp/src/commonMain/kotlin/mobi/giza/compose/`, and test paths starting `T/` are under +Written against `24991e1c`, on 2026-11-23. **Built, Phases 0 to 8, but for the device run**, one commit +a phase, behind `ExperimentalFeatures.confederation` and `ExperimentalFeatures.groupInbox`, both off in +release. Nothing here has run on a phone, a desktop client or a real relay. Paths starting `K/` are +under `composeApp/src/commonMain/kotlin/mobi/giza/compose/`, and test paths starting `T/` are under `composeApp/src/jvmTest/kotlin/mobi/giza/compose/`. -| phase | what | leaves the NIP-17 room | -|---|---|---| -| 0 | this document, and six checks | working | -| 1 | pin today | working | -| 2 | storage, schema 54: what was heard, and the bridge's second scope | working | -| 3 | every ceremony message signed, in an envelope | working | -| 4 | the bridge carries ceremonies; messages go into seat groups' rooms as well | working, beside the new path | -| 5 | **the switch**: no NIP-17 room is made | gone from new ceremonies | -| 6 | the screens and the lines | gone from the screens | -| 7 | the ceremony rooms already on devices | gone from devices | -| 8 | the network run, the record, and devices | — | +**Development devices.** Schema 54 changed while it was built (Phases 5 and 7 folded into it), so a +device that ran a build from between the phases holds a 54 Room will not open; clear its data. A +device at 53 upgrades. + +| phase | commit | what | the NIP-17 room | +|---|---|---|---| +| 0 | `6a6ce006` | the report, this plan, and six checks: **the budget is 26,000 bytes, not 32,000** | working | +| 1 | `c117995f` | five pins of today | working | +| 2 | `58442efd` | `ConfederationCeremonyHeard` and the carry's scope, schema 54 | working | +| 3 | `2be378cc` | every ceremony message signed, in a 30379 envelope; equivocation named with both events | working | +| 4 | `8bf7145f` | the bridge carries ceremonies, envelopes split by bytes; messages into seat groups' rooms as well | working, beside the new path | +| 5 | `266bee2a` | **the switch**: no NIP-17 room; the join's checks; lines into the seat groups' rooms | gone from new ceremonies | +| 6 | `1fd13942` | the lines open the ceremony; the banner goes; "waiting to be passed on" | gone from the screens | +| 7 | `1a857e6d` | the ceremony rooms on devices go, and a founders' chat that was one stays | gone from devices | +| 8 | this commit | the network run and the record. **No device run** | — | + +| what the plan said | what it turned out to be | +|---|---| +| a byte budget of 32,000 | **26,000**: NIP-44 pads each layer to a step, and a wrap passes 64 KiB once its rumor pads past 28,672 | +| Phase 3: `record` keeps its rules | it also fails a ceremony on a second, different, signed message of one step from one person, naming them and both events | +| Phase 4: a new `ConfederationBridgeJvmTest` | the split is a case in `ConfederationCeremonyJvmTest`, where the Phase 1 pin it flips was | +| Phase 4: `GroupSealRoutingJvmTest` gains a case | nothing to add: it routes FROST seal batches, and the envelope is a rumor `GroupInboxManager.open` routes | +| Phase 5: lines in Phase 6 | in Phase 5: the room `announce` wrote into was gone | +| Phase 5: the form refuses a roster too large | refused at join and in `joinable`: the form cannot know who sits in several groups until the acceptances say | +| Phase 5: a 120-role round | a 30-role round split in two; the 120-role refusal on one device's statements alone | +| Phase 6: three strings | one: the two refusals stay sentences from the manager, as every reason a join is refused is | +| Phase 6: the lines' clicks tested in the transcript | checked where they are written: no test renders `ChatTranscript`, here or before | +| Phase 7: delete payloads, then the room if empty | **and first clear `ChatRoom.initialGiftWrapPayloadId`**, a key onto the payload that would have cascaded a founders' chat away | +| — | `ConfederationTestGroups.Group` became a nested class: a clean compile left the inner one without the Compose `$stable` field its users read | --- @@ -515,6 +534,16 @@ It opens at 54 with: 4. a development device that ran a ceremony before this plan upgrades, its ceremony room goes, and a plain chat among the same people stays. +**The record done; the device run not.** `ConfederationNetworkJvmTest` gains the end-to-end case on +three groups of three, each with a real inbox ceremony and a real MLS room: Agora proposes, Polis and +Ekklesia accept, all nine admins join, and the confederation forms with Polis's first admin never +taking a turn at carrying. All nine devices reach one key and hold the record; no device holds a +NIP-17 room over the people or a ceremony gift wrap; Polis's first admin owed nothing. The profile and +the post signed with nobody asked are `ConfederationProfileNetworkJvmTest`'s, which forms its +confederation the same way since Phase 5. `ConfederationNetworkJvmTest` 8/8; full `jvmTest` 2,037, all passing; `compileDebugKotlinAndroid` builds. Brand, wallet, Magpie and +M3 audits pass. Nothing has crossed a real relay, and twenty seconds a place is still a guess for the +ceremony as it was for signing. + --- ## Who is asked what diff --git a/docs/confederation-dkg-without-nip17-room.md b/docs/confederation-dkg-without-nip17-room.md index 57ef90f9..34094ea5 100644 --- a/docs/confederation-dkg-without-nip17-room.md +++ b/docs/confederation-dkg-without-nip17-room.md @@ -24,7 +24,7 @@ group's admins producing one combined contribution for the group. Upstream's DKG on its own, under its own host key, and every device needs every dealing whole. What a group's admins can do together is move their group's messages. They cannot merge them. See *The constraint*, below. -Written against `24991e1c`, on 2026-11-23. **A report. Nothing here is built.** It proposes phases at +Written against `24991e1c`, on 2026-11-23. **A report, since implemented** by [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md), Phases 0 to 8 but for the device run. Where the build chose differently it says so there; the budget is 26,000 bytes, not 32 KB. It proposes phases at the end in the repository's usual shape, for the owner to take up or not. The phased plan that implements it is [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md). Paths starting `K/` are under `composeApp/src/commonMain/kotlin/mobi/giza/compose/`. diff --git a/docs/confederation-profile.md b/docs/confederation-profile.md index dfc90da2..22c6ab01 100644 --- a/docs/confederation-profile.md +++ b/docs/confederation-profile.md @@ -361,6 +361,8 @@ On a confederation's room, `ChatRoomDetailScreen`: ### D10. The ceremony's room is closed once the ceremony ends +> **Since [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md):** the key ceremony has no NIP-17 room. Each person's rounds are signed events written into their own groups' rooms and carried between the groups' inboxes by their admins, and what this section says of the ceremony's room no longer holds. + The NIP-17 room the ceremony ran in stays on the device. Its messages are the evidence the genesis was built from, and a later attempt over the same roster meets there. After `ConfederationFormation.onComplete`: @@ -650,6 +652,8 @@ above: ### Phase 7: rooms that say what they are (D9, D10) +> **Since [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md):** the key ceremony's room, and the banner that said what it was, are gone; its lines are written into each of a person's groups' rooms. + > **Since [confederation-room-removal.md](./confederation-room-removal.md):** a confederation has no room of its own. Its signing runs in each member group's own room, carried between the groups' inboxes by their admins, so this phase's half about the confederation's room is gone; the ceremony room's half stands. - The confederation's room: members labelled by group, the **Groups** card, and the sentence about diff --git a/docs/confederation-room-removal.md b/docs/confederation-room-removal.md index 909c55f6..1dc059dc 100644 --- a/docs/confederation-room-removal.md +++ b/docs/confederation-room-removal.md @@ -616,7 +616,8 @@ Tests: ## Out of scope - Anything about the key ceremony and its NIP-17 room, which stays as confederation-profile.md D10 - left it. + left it. *Since [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md): the ceremony runs over + this plan's bridge too, and has no room.* - Re-seating admins, and removing a seat. - Threshold-ECDH member groups, as in the earlier plans. diff --git a/docs/confederation-without-coordinator.md b/docs/confederation-without-coordinator.md index 61d0220d..5f7b1367 100644 --- a/docs/confederation-without-coordinator.md +++ b/docs/confederation-without-coordinator.md @@ -336,6 +336,8 @@ the public events gave them, and the charter is still how they learn the confede ### D8. The ceremony has no coordinator +> **Since [confederation-dkg-inboxes.md](./confederation-dkg-inboxes.md):** the key ceremony has no NIP-17 room. Each person's rounds are signed events written into their own groups' rooms and carried between the groups' inboxes by their admins, and what this section says of the ceremony's room no longer holds. + The ceremony's rounds are unchanged but for the two that had a sender with authority: | kind | today | this plan |