diff --git a/docs/README.md b/docs/README.md index dce5ded4..0fba6cd7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,6 +18,7 @@ the [retired](./retired/) notes now. | [confederation.md](./confederation.md) | a group made of groups: a phased plan, built behind a flag that is off in release but for its device run and the room's governance. Agreeing to form (Part A), the key ceremony and room (Part B), and the confederation signing its profile, posts and charter (Part C). Groups with a public nostr profile propose, accept or reject a confederation in public, an acceptance carries the group's admins sealed to the coordinator in a way every signer recomputes, and the confederation's DKG and Marmot room follow. Covers why the public events are regular kinds, why nothing can be encrypted from or to a group's npub, how the coordinator is kept from substituting a roster, and why everything after the agreement waits on upstream publishing the distributed rounds. Its coordinator and its public statements have since been replaced (confederation-without-coordinator.md) | | [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, not built. 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-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 | | [ceremony-creation.md](./ceremony-creation.md) | one place to start a key ceremony — how joining a subgroup's ceremony opened a second one for the parent room, the screen that showed a ceremony and offered to start one in the same button, and the removal of the nip30303 documents, whose kinds collided with the ceremony's, leaving the member chronicle with nothing to carry and nothing to say | diff --git a/docs/confederation-room-removal.md b/docs/confederation-room-removal.md new file mode 100644 index 00000000..71ba81bc --- /dev/null +++ b/docs/confederation-room-removal.md @@ -0,0 +1,640 @@ +# The confederation without a room of its own + +A plan to remove the confederation's own Marmot room: the MLS group, with id `marmotGroupId(02‖X)`, +that one founder's device makes once the key ceremony has formed. People already reach a +formed confederation from the place they understand it, the **Member of …** row on their +group's screen, which opens `ConfederationScreen`. Everything a role holder still does in the +confederation's room moves there, and the confederation's signing moves onto two channels that +already exist: + +- **within a group**, that group's own Marmot room, where its role holders already are; +- **between groups**, the groups' inboxes, which already carry every statement between them. + +Each group's admins are the bridge between the two. When this plan is done, no device holds a room +for a confederation, and a confederation is what it always was underneath: a key, a record, +and the groups that hold it. + +Read [confederation.md](./confederation.md) (Part C: the nested signing, Phases 13 to 15), +[confederation-without-coordinator.md](./confederation-without-coordinator.md) (D11, who makes the +room), and [confederation-profile.md](./confederation-profile.md), whose D5 to D9 are the parts +of the room this plan takes apart. Read [group-inbox.md](./group-inbox.md) for the inbox the bridge +writes to. + +Written against `9db986c1`, on 2026-11-23. **Not built.** Paths starting `K/` are under +`composeApp/src/commonMain/kotlin/mobi/giza/compose/`. + +--- + +## What the room does today + +Traced through the code at `9db986c1`. + +**One value, three jobs.** `Confederation.id` is `ConfederationFormation.roomIdOf(X)` = +`SharedKeyDerivation.marmotGroupId(02‖X)` (`K/managers/ConfederationFormation.kt:25,44`). It is: + +- the confederation's npub, the key it signs as; +- the key everything about the confederation is stored under; +- the room's `ChatRoom.id`. + +No column marks a room as a confederation's. A room is the confederation's because a +`Confederation` row has the same id. Only the third job goes. + +**Making the room.** `ConfederationFollowThrough` (`K/managers/ConfederationFollowThrough.kt`) exists +for nothing else: + +- the first person in the roster's order makes the room through `MarmotGroupCreation.create`; +- the `k`-th person makes it after `k` hours if no Welcome has arrived; +- it retries on a ten-minute tick and whenever a key package arrives; +- a Welcome from someone earlier in the order replaces the room a device holds + (`welcomeReplaces`, called from `K/database/dao/NostrDao.kt:856-865`); +- it records who made the room in `Confederation.roomCreator`. + +`DatabaseChatRepository.followThroughCeremonies` launches it (`:207-210`). + +**Signing runs entirely in it.** `ConfederationSigningManager` sends kinds 30390–30399 as +`MarmotInnerEvent`s into the room (`broadcast`, `:655-677`) and reads them back from it +(`replayStoredMessages`, `:679-687`). `NostrDao.kt:1718-1735` routes them in from MLS. Every entry +point needs the `ChatRoom` row. `propose` takes a `LocalChatRoom`, and `approve`, `decline`, +`resumeRunning`, `postVoucher` and `ConfederationProfileFollowThrough.takeNextStep` all return +**silently** without one. Remove the room and nothing fails out loud: an endorsed profile change +stays at "Endorsed, being signed" for good. + +**Its rows hang off it.** Three tables have a foreign key to `ChatRoom(id)` with `ON DELETE CASCADE`, +and all three hold rows under the confederation's id: + +- `ConfederationSigningAttempt.confederationId`; +- `GroupSignedEvent.chatRoomId`, which holds every event the confederation signed; +- `ChatMessage.chatRoomId`, which holds the signing's lines. + +Deleting the room deletes the confederation's **posts**. They exist nowhere else: kind:0 and the +charter are also in `ConfederationEvent`, but kind:1 is not. + +**Only the room offers these.** The charter is proposed from the room's card on +`ChatRoomDetailScreen` (`:865-883`). Posts are read and added through the room's `GroupPostsScreen` +and `AddGroupPostScreen`, and broadcast from `BroadcastGroupSignedEventScreen`. A signing attempt is +reached only from its line in the room's transcript. `ConfederationScreen` has none of these. Its +one link to the room is **Open the confederation's room** (`:229-233`). + +**It is the wrong set of people.** The room is fixed at the people who held roles at formation, as +people (confederation-profile.md, "What is wrong today"). Admins who joined their group later are +not in it, and founders who have since been demoted still are. + +--- + +## The constraint that shapes the plan + +The confederation's nested signing does not let a group sign in private and hand over its +result. `ConfederationSigning.transcript(session, nonces)` is built over **every selected role's +nonce in every group**. Each role confirms that whole transcript with its host key +(`ConfederationSigning.confirm`), and `ConfederationSigning.sign` takes the full transcript and +the full confirmation certificate. Only the last step is per group: `aggregateGroup` adds up one +group's partials before `aggregate` combines the groups. + +So every round has to reach every selected signer in every group. No channel inside a group can +make that cross-group traffic go away. What a channel inside a group can do is: + +- carry each group's part of a round to one place, so that it crosses as **one batch per group** + rather than one message per person; +- carry the other groups' batches back to role holders who cannot read the inbox. + +That is the job this plan gives each group's own room. + +--- + +## What changes, in one table + +| | today | this plan | +|---|---|---| +| the confederation's Marmot room | made by the first founder in order, every role holder a member | **never made.** Rooms already held are dropped on each device (D11) | +| where a role holder's signing message goes | the confederation's room | **their group's own room**, for each group they hold a seat in (D2) | +| how it reaches the other groups | everyone is in the one room | a **bundle per group per round**, carried by one of the group's admins to every member group's inbox (D4) | +| how the other groups' messages reach a role holder | the one room | an admin reads them in their group's inbox; for role holders who are not admins, an admin also carries them into the group's room (D4) | +| a signing message | a rumor, authenticated by MLS | a **signed event** from its author, so whoever carries it cannot change it (D3) | +| a founder demoted since formation | in the room, signs | in their group's room, **still signs** (D5) | +| a voucher (9438) | wrapped in a 30396 by a role holder and posted into the room | **carried as itself** in its group's bundle. 30396 retires (D7) | +| where the confederation's signed events live | `GroupSignedEvent` under the room | `ConfederationEvent`, beside its charter and profile (D8) | +| posts, charter, signing attempts | reached through the room | on the **confederation's screen** (D9) | +| a request to sign | a line in the confederation's room | a line in the group's room for each of the person's seats, which opens the signing screen (D9) | +| a signed post | broadcast by hand from the room | **owed to relays** by every device that signed it, as the profile is (D10) | + +--- + +## Decisions + +### D1. A confederation is a key and a record, not a room + +The confederation's id stays `marmotGroupId(02‖X)`. It is the npub the confederation signs as, +and every signed kind:0, post and charter, every `#p` filter and every relay copy names it. +Changing the derivation would give the confederation a new npub. confederation.md's D10 still +explains why the derivation is the room's: every reader of a group-signed event (`isSignedByRoom`, +`GroupSignedEvent.verifies`, `signingPath`) already knows it. That reason does not depend on a +room existing. + +What changes is the vocabulary in the code. `ConfederationFormation.roomIdOf` becomes `idOf`, +`Held.roomKey` becomes `key`, and every KDoc that says "the confederation's room" about the id +says "the confederation's id". Phase 7 makes these renames once nothing reads the room. Making +them earlier would hide which phase removed which dependency. + +### D2. Two channels: the group's room within a group, the inboxes between groups + +A role holder writes each signing message **only into the Marmot room of a group they hold a seat +in**, as `FrostSigningManager` already writes a group's own FROST rounds. A person with seats in two +groups writes it into both rooms. It is the same signed event, so the copies are one message +(D3). Nothing a role holder sends goes to an inbox directly. + +Messages cross between groups only through the groups' inboxes, carried by admins (D4). The +inboxes already carry every statement between the groups, and every member group has one, which +confederation-without-coordinator.md D5 made a precondition. + +**Why not everything through the inboxes.** A role holder can write to another group's inbox as a +person, since `GroupInboxManager.open` accepts a seal from any sender. That costs one wrap per +group for every message from every person. It also cuts off every founder who has since been +demoted, because `GroupInboxManager.forgetIfNotAdmin` wipes the inbox key from their device. +The plan would then have to choose between dropping those seats and sending personal copies to +the whole roster. + +**Why not the key ceremony's NIP-17 room.** It is a room over the founders as people, which +confederation-profile.md set out to stop. It costs one wrap per person in the roster for every +message, and D10 of that plan closed its composer once the ceremony ended. + +**Why not keep the confederation's room.** It is the wrong set of people (above). It is also one +more room in everyone's chat list for something they already reach from their group. + +**Why the group's room.** Every role holder of a group is in it, admin or not, as long as they +are still in the group. It is already the channel for the group's own signing rounds, so a +confederation round looks to every device like what it already handles. The one cost is a hop: +each round now travels from a role holder's room to an admin's inbox, and in some groups back +into a room. + +### D3. Every signing message is a signed event, so it can be carried + +Today a 30390–30399 message is a rumor. MLS says who sent it, and the confederation's room is +where it was sent. Once messages are carried from room to inbox to room, the carrier is not the +author. So each message becomes a **signed event**: kind, tags and content as today, signed with +the author's own nostr key, verified on arrival against a person in the confederation's roster, +and **never published**. This is the pattern the voucher already follows (confederation-profile.md +D5). + +The protocol would catch a carrier who swapped a nonce even without this. The swapped nonce +changes the transcript the other groups build, the real signer's confirmation does not match it, +and the certificate fails. But that failure names nobody, and it costs the attempt. With +signatures, a changed message is dropped on arrival, and the carrier can only delay or withhold. +A carrier could withhold before this plan too, by not answering. + +`ConfederationSigningManager.record` keeps its rules: one message per person per round, an +availability that covers every seat, later rounds naming only the sender's own seats +(`139f5192`). They now apply to `event.pubKey` once its signature verifies, not to the MLS sender. + +### D4. Each group's admins are its bridge, one at a time, in order + +**Out.** For each confederation and each round, an admin of group A collects the signing +messages from A's room that have not yet crossed. It puts them in a **bundle**: a rumor of a new +kind, **30398** (`ConfederationSigningEvents.CARRIED`), whose content is a JSON array of the signed +events. The admin seals the bundle as a person, wraps it to every member group's inbox (A's own +included), and owes the wraps through `GroupInboxPublication` under A's room. A's own copy +coming back through A's inbox is how A's other admins know the bundle got out. + +**In.** An admin of A who reads another group's bundle in A's inbox processes it at once. If A +has a seated member who is not an admin of A, the admin also carries that bundle's events into +A's room as one MLS message of kind 30398. That seated member is the D5 case, and they cannot +read the inbox. A group whose seated members are all admins needs no carrying in, and gets none. + +**Who carries.** A's admins are taken in bytewise order of their public keys, the same order +confederation-profile.md D6 uses for who starts a signing. Admin `k` carries a message out if A's +own copy has not come back through A's inbox `k × 20` seconds after the message reached their +device. Admin `k` carries a bundle in if it has not appeared in A's room `k × 20` seconds after it +reached A's inbox. The admins are A's **current** admins, which A's own devices know. They are not +the founders, so an admin who joined A after formation carries too, though they hold no seat. + +Twenty seconds rather than D6's ten minutes. A nonce lives only in memory, so a round must cross +while the signers' devices are still awake. A bridge that takes minutes per round turns a signing +into an hour. + +**Batching.** One bundle carries whatever is waiting when its carrier's turn comes. Within one +round, A's selected role holders send at about the same moment, so their messages usually cross +together. That is one wrap per member group per group per round, at most 12 × 12, where sending +each person's message to every inbox would cost one wrap per group for every person. + +### D5. A seat signs while its holder is in its group's room + +A founder who has been demoted, but is still a member of group A, keeps their share. The +experimental refresh does not take it (confederation.md Phase 0), and they are in A's room. With +D2 and D4 they hear every round through A's room, so they keep signing for their seat, as they do +today. confederation-profile.md's test "a role holder who is no longer an admin of B still signs +for B's seat on B's voucher" stays true. + +A founder **removed** from A is no longer in A's room and hears nothing more about the +confederation, so their seat goes quiet. This is the one change from today, where they would +still be in the confederation's room. A group that removes someone has said that person no +longer speaks for it, so this is the intended outcome, not a loss. + +Admins who joined A after formation still hold no seat. Re-seating people is governance of the +roster, which is out of scope here as it was before (confederation.md Phase 15). + +### D6. Who sees the rounds + +Every member of A's room sees the confederation rounds of A's role holders. Where A has a seated +member who is not an admin, A's members also see the other groups' bundles carried in. This is +how A's members already see A's own FROST sessions. Nothing in a round is secret: public nonces, +host-key confirmations, partials that every device adds up. The event being signed is a post, a +profile or a charter, all of which are published once signed. + +The profile-change statements (9435–9437) are unaffected. They stay sealed between inboxes, and +only admins read them (confederation-profile.md D2 and D3). The proposal that starts a profile's +signing (30390) carries the kind:0 and its vouchers. Members who are not admins learn the new +profile a little earlier than they would from the relay, which they were about to see anyway. + +### D7. Vouchers travel as themselves + +A voucher (9438) is already a signed event, signed in the group's own FROST session in the +group's room, so every device of the group holds it (`FrostSigningManager.complete`). It goes into +the group's next bundle as itself, and the 30396 wrapper and `postVoucher` retire. On arrival a +voucher is verified against its group's npub and filed by `ConfederationProfileManager.recordVoucher`, +as today. A 30396 that arrives, from a device on an older build, is ignored. + +### D8. The confederation's signed events live with its other events + +`ConfederationEvent` already holds the charter (9434) and every kind:0, under the confederation's id +(`ConfederationEvent.confederationId`, schema 51). It takes kind:1 as well. `ConfederationSigningManager.complete` +writes every event the confederation signs there, and nothing reads the confederation's events from +`GroupSignedEvent` any more. `GroupSignedEvent` keeps its job for groups, and its foreign key onto +`ChatRoom` stays right for them. + +`ConfederationSigningAttempt`'s foreign key moves from `ChatRoom(id)` to `Confederation(id)`. Only +a device that holds the record signs, so every attempt has a `Confederation` row to hang from. + +### D9. A role holder acts on the confederation's screen; requests are lines in their group's room + +`ConfederationScreen` gains three sections, each with the four states the conventions ask for: + +1. **Posts**: the confederation's signed kind:1s, newest first, and **Add post** for a member who + holds a seat. Adding goes through the direct path, with every role holder asked as a person, as + today (confederation-profile.md, *What this does not do*). +2. **Charter**: whether one is signed and published. If not, **Propose the charter** for a member + who holds a seat, with the sentence the room's card has today. +3. **Signing**: attempts that are running, with the ones waiting for this person first, and the + last few that ended. Each one opens `ConfederationSigningScreen`, which is already room-free. + +**Open the confederation's room** goes. + +The lines `announce` writes today into the confederation's room (proposed, failed, profile +signed, post signed, charter signed) go into the room of each group the person holds a seat in. +Each device writes them for itself and sends nothing, the pattern confederation-profile.md D8 set. +A line about an attempt opens the signing screen, and a line about a signed event opens the +confederation's screen. `NotificationClassifier` treats an attempt that is waiting for this +person's answer as needing attention, the way a FROST session waiting for you is. Today the +confederation's lines are silent, because the room's transcript was where a person looked. + +### D10. A signed post is published, by every device that signed it + +Without the room, `BroadcastGroupSignedEventScreen` has nothing to open, and a confederation's post +would be signed and then go nowhere. A post is therefore marked owed on every device that signed +it, the same way confederation-profile.md's Phase 6 owes the kind:0, and `ConfederationPublisher` +sends it to the publish set and to every member group's 10050 relays. + +### D11. The rooms that exist are dropped on each device, and a Welcome to one is refused + +The feature has never been on in a release, so the only rooms are on development builds and +emulators. A migration deletes, on each device: + +- the `ChatRoom` row under a confederation's id, with its MLS state; +- the queued `MarmotInnerEvent`s and the room's lines. + +Before that, it copies any `GroupSignedEvent` under the id into `ConfederationEvent`, so posts +survive. Running attempts are dropped too: their nonces would not have survived a restart anyway. + +Nothing is sent to the MLS group. Every member drops it, so nobody is left to read a leave commit. + +A Welcome whose group id is a confederation this device knows, by record or by charter, is +refused and never joined. Without this, a device on an older build that still runs +`ConfederationFollowThrough` would make the room again, and `NostrDao` would accept it as an +ordinary invite. `MarmotGroupCreation.create` refuses that group id for the same reason. + +### D12. Behind both flags + +Signing now needs the group inbox, so everything here is behind both +`ExperimentalFeatures.confederation` and `ExperimentalFeatures.groupInbox`. The profile work +already needed both. The Welcome refusal (D11) runs with the flags off, as every refusal does. +The welcome replacement it takes over from was not behind a flag either (`NostrDao.kt:864`). + +--- + +## Who is asked what + +| step | who is asked | what they decide | automatic after that | +|---|---|---|---| +| propose a post | a member with a seat, on the confederation's screen | the post | writing the 30390 into each of their seat groups' rooms; the bridge | +| propose the charter | a member with a seat, on the confederation's screen | that the charter be signed | as above | +| a post or charter attempt arrives | every role holder, as a person, from the line in their group's room | yes or no, for each seat | nonces, confirmations, partials, carried by the bridge | +| a profile change reaches `T` vouchers | nobody | — | as confederation-profile.md D5 and D6, with the rounds on the new channels | +| signed | nobody | — | filed in `ConfederationEvent`; owed to relays by every device that signed it | +| carrying a bundle | nobody | — | the admins' devices, in order | + +The questions a person is asked do not change. What changes is where the question appears, and +that a member who holds no seat is never asked anything. + +--- + +## Phases + +One commit per phase, in the repository's style (`feat: … (confederation-room-removal, Phase n)`). +Every phase leaves these green: `./gradlew :composeApp:jvmTest`, `:composeApp:m3Audit`, +`compileDebugKotlinAndroid`, and the brand and wallet audits in `check`. Until Phase 4, signing +still runs in the confederation's room. Each phase before it makes one dependency on the room +unnecessary, without removing the room. + +### Phase 0: this document, and seven checks + +As scratch tests where a check is code, kept as pins where they stay true: + +1. **A person's seal to a group's inbox.** A wrap sealed by a person's key to a group's announced + inbox key opens in `GroupInboxManager.open`, and its rumor's author is the person. This is what + D4's carrier relies on. +2. **A signed event inside a rumor survives intact.** It must come out of both a seal and wrap and + an MLS application message byte for byte, with its signature verifying. Record the largest + bundle: a 30390 over a 1.1 KB kind:0 with twelve vouchers, and a nonce round of twelve groups + at ten selected roles each. Compare both with `MAX_STATEMENT_BYTES`. +3. **30398 is free.** It must appear nowhere in `RetiredKinds`, Bennu's kinds, the NIP kind table or + quartz. 30397 was reserved for a failure in confederation.md Phase 14 and never used, so leave + it alone. +4. **Every row a Marmot room leaves behind.** List every table keyed by a room's group id or + routing id: `ChatRoom.mlsGroupState`, epoch secrets, key schedules, the MLS stores marmot-kmp + persists ([marmot-kmp.md](./marmot-kmp.md) Phase 9). Phase 7's migration must delete all of + them. +5. **The inbox hears a back-dated wrap live.** NIP-59 dates a wrap up to two days in the past. + Check that the live inbox filter's `since` does not drop a wrap made a second ago and dated + yesterday. D4's twenty seconds assume a carried bundle is heard within seconds. +6. **What the development devices hold.** On the emulators that ran `139f5192`, count the + confederation rooms, their posts and any running attempts, so Phase 7 is tested against the + state that exists. +7. **The hops.** Count the legs an attempt takes now. Signing is five rounds: availability, + selection, nonces, confirmations, partials. Each crosses as room → carrier → inbox → (carrier → + room). Write down the worst-case extra delay at `k = 0`, so the device run has a number to beat. + +### Phase 1: the confederation's storage stands without the room (D8) + +Schema 52, by auto-migration with a spec: + +- `ConfederationSigningAttempt`'s foreign key moves to `Confederation(id)`. Room rebuilds the table. +- `ConfederationSigningHeard`: every signing message this device has heard for a confederation, + by any path. Its columns are the event id (primary key), `confederationId`, `sessionId` + (nullable, for a voucher), `kind`, `pubKey`, the signed event's JSON and `heardAt`. This + replaces `marmotInnerEventDao().getByChatRoomAndKinds(confederationId, …)` as the place + `replayStoredMessages` reads from, since messages will arrive through several rooms and inboxes. +- `ConfederationEvent` takes kind:1. `complete` writes every signed event there, beside + `GroupSignedEvent` (kept until Phase 7). +- The migration copies every `GroupSignedEvent` whose `chatRoomId` is a confederation's id into + `ConfederationEvent`. + +`ProtocolRetention` gets a rule for `ConfederationSigningHeard`: a message is released once its +attempt is complete or failed. A message with no attempt here is released after the signing +floor, which is what the rule already does for `FrostSigningEvents`. + +Readers move to `ConfederationEvent`: `ConfederationProfileManager.profiles`, +`DatabaseConfederationRepository.observeProfile` and `observeProfileChanges`, and a new +`ConfederationRepository.observePosts(confederationId)`. + +Tests: `ConfederationStorageJvmTest` gains: + +- an attempt filed with no `ChatRoom` row; +- posts read back from `ConfederationEvent`; +- the copy from `GroupSignedEvent`, opened from a v51 database the way `ShippedProfileUpgradeJvmTest` + opens one. + +### Phase 2: every signing message is signed by its author (D3) + +- `ConfederationSigningManager.publishOwn` and `broadcast` sign the event with the author's + `nostrPrivateKey`. It is still sent into the confederation's room. +- `process` and `record` verify the signature and read the sender from `event.pubKey`. An unsigned + or wrongly signed message is dropped with a warning. A message whose author holds no seat is + dropped, as before. +- Every message heard is written to `ConfederationSigningHeard`. + +Tests: `ConfederationSigningJvmTest` stays green unchanged, which shows the signatures cost the +protocol nothing. Two cases are added: + +- a message whose content was changed after signing is dropped on every device; +- a message signed by someone outside the roster is dropped. + +### Phase 3: the group's room carries its role holders' messages (D2) + +- Each signing message is also written into the room of every group where the author holds a + seat. It carries a `["confederation", ]` tag, because the room no longer says which + confederation it is about. +- `NostrDao`'s MLS branch for `ConfederationSigningEvents.ALL` routes by that tag rather than by + the room's id. The branch for the confederation's room stays until Phase 4. +- `DisappearingMessages`: the signing kinds keep their class. The stamp now uses the group room's + policy, and the signing floor still applies. + +The writes go to both places in this phase. The confederation's room remains the channel that +works, and the group rooms are filled beside it, so Phase 4 can switch over without a gap. + +Tests: on `ConfederationTestGroups` (three groups of three, real FROST, real inboxes; from +confederation-profile.md Phase 8): + +- every role holder's message is in its group's room on every device of that group, and in both + rooms for a person seated in two groups; +- a member of the group who holds no seat files the message and does not answer it. + +### Phase 4: the bridge, and the switch (D4, D5) + +- `ConfederationSigningEvents.CARRIED = 30398`, a bundle. `ConfederationBridge` decides when to + carry and keeps two marks per event and group room: `crossedAt` (A's own copy came back through + A's inbox) and `carriedInAt` (the bundle appeared in A's room). The order and the `k × 20` + seconds are D4's. It runs on the sweep `SynchronizationViewModel` already runs, and whenever a + message arrives. +- Out: an admin's device bundles, seals as the admin, and wraps to each member group's announced + inbox key. It owes the wraps through `GroupInboxPublication` under the group's room, with + relays from `InboxAnnouncements` and the groups' 10050s, as `ConfederationManager.proposeSealed` + finds them. +- In: `GroupInboxManager.open` takes a 30398 before the inbox's own filing, as it does for + statements. It verifies each event in the bundle and hands it to the signing manager. When the + group has a seated member who is not an admin, it also queues the bundle for carrying in. +- `DisappearingMessages.classOf(30398)` is the signing class. `DisappearingMessagesTest` fails until + it is. +- **The switch.** `broadcast` stops writing to the confederation's room. `propose`, `approve`, + `decline`, `resumeRunning` and `ConfederationProfileFollowThrough.takeNextStep` stop looking up a + `ChatRoom`: they take the confederation's id and find this person's seat groups' rooms. A seat + group with no room on this device is an error said out loud, not a silent return. + +Tests: the confederation's `ChatRoom` row goes from `ConfederationSigningJvmTest`'s fixture, +`ConfederationSharedSeatsSigningJvmTest` and `ConfederationProfileNetworkJvmTest`. The fixture now +ferries group rooms and inboxes. Every existing case must pass on the new channels, plus: + +- **a demoted founder signs**: Agora demotes one of its founders, and the profile is still signed + with that founder's seat selected, through Agora's room alone; +- **a removed founder is not heard**: Agora removes them, and the attempt selects someone else; +- **one carrier at a time**: with every admin online, each bundle crosses once; with the first + admin away, the second carries after twenty seconds on the test clock; +- **an admin who changes a bundle**: the changed event is dropped at the far end, and the attempt + goes on once the next carrier's copy arrives; +- **a group with no admin online**: its round does not cross, and the attempt's existing retry + carries the change once one comes back (confederation-profile.md D6). + +### Phase 5: vouchers travel as themselves (D7) + +- The group's bridge carries a signed 9438 like any other event, once the group's FROST session + completes. `ConfederationProfileManager.onSigned` stops calling `postVoucher`, which goes. +- `ConfederationSigningEvents.VOUCHER` (30396) leaves `ALL`. One that arrives is ignored, and a + KDoc line says why the number stays reserved. + +Tests: confederation-profile.md's voucher cases in `ConfederationSigningJvmTest` and the network +test pass with the vouchers in bundles. Add that a 30396 is ignored. + +### Phase 6: the confederation's screen takes over (D9, D10) + +- `ConfederationScreen`: the Posts, Charter and Signing sections. Each has its loading, empty and + error states and a required `EmptyState` message. Remove the room button. +- Posts: `AddConfederationPostRoute` reuses `AddGroupPostScreen`'s form, moved into a shared + composable the way `NostrProfileForm` was, and proposes through `ConfederationSigningManager`. + Posts are owed to relays on every device that signed them (D10). +- Charter: the room card's proposal moves here, with its two strings. +- Signing: `ConfederationRepository.observeAttempts(confederationId)`. +- `announce` writes into each seat group's room. Add the click handling for the new lines in + `ChatTranscript`, and the classifier rule. +- Remove from the room screens: `canSignAsConfederation`, `proposeAsConfederation`, + `confederationRoomInfo`, `confederationOfRoom`, and `ConfederationRoomInfo` with its card on + `ChatRoomDetailScreen` and its member labels. Remove the confederation branches of + `AddGroupPostViewModel`, `GroupPostsViewModel`, `GroupNostrProfileViewModel` and + `EditGroupNostrProfileViewModel`, whose `isConfederation` is already always false. +- Strings: add the sections' strings in sentence case. None of them says "room", "inbox", "bundle" + or "voucher" to a person. Remove `this_is_the_confederations_room`, `open_the_confederations_room`, + `group_and_its_role_holders` and `admins_who_joined_later_are_not_here`. Move + `propose_the_charter` and `the_charter_names_the_groups`. + +Tests: + +- `ConfederationProfileScreensJvmTest` gains: the three sections in each state; a member who holds + no seat sees posts and no **Add post**; an attempt waiting for you is listed first. +- `ConfederationScreensJvmTest` loses its room cases. +- The signing test checks that the lines are in each seat group's room, and that a post signed on + nine devices is owed on each of them. + +### Phase 7: no room is made, and the ones that exist go (D1, D11) + +- Delete `ConfederationFollowThrough` and its launch in `DatabaseChatRepository`. Delete + `welcomeReplaces` and `heldUnder` and their calls in `NostrDao`. +- `NostrDao`'s Welcome path refuses a group id that is a known confederation's. So does + `MarmotGroupCreation.create`. +- Remove `NostrDao`'s MLS branch for the confederation's own room. `complete` stops writing + `GroupSignedEvent`. +- The migration: drop `Confederation.roomCreator`, then delete every confederation room with + every row Phase 0's check 4 listed. Fold this into schema 52 if Phases 1 and 7 land before a + build that anyone keeps, as the earlier confederation plans folded theirs. Otherwise use 53. +- Make D1's renames. The ceremony room's banner string `the_key_ceremony_for_is_complete` stops + saying "The confederation works in its own room now." + +Tests: + +- `ConfederationCeremonyJvmTest`'s four room cases (`:367-454`) are replaced. A formed + confederation leaves no `ChatRoom` under its id on any of the nine devices, even after the old + hour and two hours have passed on the test clock. +- A Welcome for a confederation's id is refused. +- A v51 database holding a room, two posts and a running attempt opens at the new version with + the posts in `ConfederationEvent` and nothing left of the room. + +### Phase 8: the network run, the record, and devices + +- `ConfederationProfileNetworkJvmTest` and a new `ConfederationPostNetworkJvmTest`, end to end + with no confederation room anywhere: + - a profile changed, endorsed, signed with nobody asked and published; + - a post proposed from the confederation's screen, approved from the line in each role holder's + group room, signed and published; + - one founder demoted in Agora, still signing. +- The record: this document's header and a progress table, and a "where the build chose + differently" table. Add a line at the top of confederation.md Phase 13, confederation-without-coordinator.md + D11, and confederation-profile.md D5, D9 and Phase 7, pointing here. Add confederation-profile.md's + appendix row "run the confederation's nested signing through the groups' inboxes", with what this + plan found. Add the README row. +- Device run, on the emulators that hold rooms today: + - upgrade them and check the rooms are gone and the posts are on the confederation's screen; + - sign one profile change and one post across three groups, with one demoted founder seated; + - measure the time each round takes to cross, against Phase 0's check 7. + +--- + +## What this does not do + +- **Governance of the roster.** Admins who joined after formation hold no seat. A founder removed + from their group stops signing but still holds a share. Re-seating people needs a new key-state + transition signed by the confederation. That is confederation.md Phase 15's unbuilt half, and + it is no closer or further than before. +- **Posts and the charter through the groups.** They keep the direct path, with every role holder + asked as a person. confederation-profile.md names moving them onto group statements as its own + next plan, and nothing here stands in its way. +- **Retiring the voucher.** Under D5, a role holder may not be an admin and so may never see their + group's sealed endorsement. The transferable voucher stays necessary. +- **Making signing tolerate a restart.** Nonces still live in memory only. The bridge adds latency + to each round, which makes a restart mid-attempt somewhat more likely, but not a different + problem. + +## Risks + +| risk | what to do | +|---|---| +| the extra hop per round makes signing too slow for devices that are online together only briefly | Phase 0 check 7 sets a number; the device run measures it. D4's twenty seconds is the lever, and a carrier sends the moment its turn comes rather than waiting to batch | +| a group's inbox relays rate-limit a burst of wraps | at most one wrap per member group per group per round (D4); the existing backoff of `GroupInboxPublication` | +| a group rotates its inbox key during an attempt | the carrier reads each group's current announcement for every bundle; a bundle sealed to the old key is lost, and the attempt's retry covers it | +| no admin of a group is online, so its seated members cannot be heard | the round waits, and the attempt fails and retries as today; the signing screen names the group being waited on | +| a malicious admin withholds or changes bundles | changes are dropped (D3); withholding is covered by the next admin in order; an admin of every group's choosing is trusted this far already, by the group | +| a group's members who are not admins now see confederation rounds in their room | D6: nothing in them is secret, and the event is about to be public | +| a device on an older build makes the room again | the Welcome refusal (D11); the feature has never been in a release | +| the migration misses a table of MLS state, and a dropped room comes back half-open | Phase 0 check 4, and Phase 7's upgrade test opening a v51 database with a room in it | + +## Out of scope + +- Anything about the key ceremony and its NIP-17 room, which stays as confederation-profile.md D10 + left it. +- Re-seating admins, and removing a seat. +- Threshold-ECDH member groups, as in the earlier plans. + +--- + +## Appendix: considered and not chosen + +| idea | why not | +|---|---| +| keep the room, and only hide it from the chat list | it stays the wrong set of people (founders, as people), and its signing still runs where none of a group's other members can see it | +| every message straight to every group's inbox, as a person | one wrap per group per message per person, and every demoted founder cut off by `forgetIfNotAdmin` (D2) | +| run signing in the key ceremony's NIP-17 room | one wrap per founder per message, in a room over people that confederation-profile.md D10 closed (D2) | +| let each group combine its own nonces and send one | the transcript is over every role's nonce and every role confirms all of it; the protocol has no per-group nonce | +| a fixed carrier per group, its first admin | one person away stops their group's rounds; the order with a fallback costs twenty seconds instead | +| carry a bundle in for every group, always | only a group with a seated member who is not an admin needs it; elsewhere it doubles each round's traffic in the room for nothing | +| delete the rooms on devices with a leave commit | every member drops the room, so nobody is left to process the commit | + +--- + +## Order and size + +| phase | rough size | depends on | +|---|---|---| +| 0 | this document, scratch tests | — | +| 1 | ~250 main, ~250 test, an auto-migration with a spec | 0 | +| 2 | ~150 main, ~150 test | 1 | +| 3 | ~200 main, ~250 test | 2 | +| 4 | ~600 main, ~700 test | 3 | +| 5 | ~100 main, ~100 test | 4 | +| 6 | ~700 main, ~350 test | 1 (the screen), 4 (its lines) | +| 7 | ~150 main, removing ~400, ~250 test | 4, 6 | +| 8 | ~400 test, docs, a device session | all | + +Phase 6's screen sections need only Phase 1 and can be built beside Phases 2 to 5, with the lines +following Phase 4. Phase 4 is the one to review closely: it is where the room stops being the +channel, and every existing signing test moves onto the new one. + +## Checking the work + +```bash +./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest +``` + +```bash +./gradlew :composeApp:m3Audit +``` + +```bash +./gradlew check +``` + +The new tag (`confederation`) and kind (30398) are wire values, not hash inputs, so no `mantra/…` +tag is added. Bennu is named nowhere but in comments, and no kind in `RetiredKinds` is touched.