d95412ffda84c8e9e2cce9099bb3bb21396969f3
111
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1c3e0e934e |
feat: re-enrollment, a stale member repaired into the generation the group signs with (frost-share-refresh, Phase 10)
ShareRepairManager brings back a participant id a refresh left stale, with FrostReducedEnrollment in repair mode, on kinds 30346-30349. t live helpers approve and run it; their round-1.1 shares and round-1.2 sums are raw additive shares, so each goes NIP-44-encrypted between the two parties' ChillDKG host keys. The target checks the result against the public share the group signed -- never one the helpers supply -- stores it, and proves it with a Schnorr signature by the share, which every device checks before marking the id live. The share is a point of the new polynomial that the old device never had. 10b: a new identity at an id -- a lost device, a compromised account -- is bound by a group-signed key state first (frost_member, GroupKeyState .memberBindings, schema 40), applied only to an id that is not live. Until then its request waits, with nothing sent. A key state amending one at the same generation is stamped a second later, so a binding can never tie with the state it adds to. jvmTest 1198/1198, compileDebugKotlinAndroid, audits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
f8974aec81 |
feat: a group rotates its shares, end to end between devices (frost-share-refresh, Phase 7)
ShareRefreshManager runs a FROST share refresh in the Marmot room the key derives, on kinds 30340-30345, in the image of ChillDkgRitualManager: every inbound message stored, every step recomputed from stored inputs, nothing of a member's own published before they approve, at two gates (DEAL, CONFIRM). Recipients are at least t and a majority of the ids not retired, and a device confirms one refresh per base generation -- ShareRefreshConfirmation, written in the same transaction as the pending generation it confirms -- so two refreshes from one generation cannot both complete. The certificate activates the new generation; a withheld device learns its table from the recovery data and files it with no share. Schema 39 (AutoMigration): ShareRefreshSession, ShareRefreshMessage, ShareRefreshConfirmation. Transcript lines as system lines; dispatch in the Marmot inbound path. ShareRefreshRitualJvmTest: three devices with real host keys refresh through bitcoin-kmp's FrostRefresh and then sign at generation 1 as the same room. jvmTest 1190/1190, compileDebugKotlinAndroid, audits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
fce51e20f6 |
feat: a key's shares have generations, and signing reads the one it names (frost-share-refresh, Phase 6)
Schema 38 (AutoMigration): KeyShareGeneration and KeyShareMember for every generation a refresh makes, FrostSigningSession.generation, and GroupKeyState.generation and publicSharesHash. Generation 0 has no row: it stays where ChillDKG wrote it, with ids derived from the host keys as before. ShareGenerations is the one door signing reads a share through. FrostSigningManager fixes a session to the generation the group signs with when it is proposed, carries it as frost_generation from generation 1 (a generation-0 proposal is byte for byte what it was), and a device holding no share of the named generation declines out loud with GENERATION_REFUSAL instead of waiting or signing with the wrong share. ShareGenerationsJvmTest refreshes a 2-of-3 group's shares by hand with a zero-constant polynomial; the new shares sign and the signature verifies as the unchanged room. jvmTest 1183/1183, compileDebugKotlinAndroid, and the M3, brand and wallet audits pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
e07bb68014 |
feat: the sender ratchet as its own row, and the receive side beside it (marmot-kmp, Phase 8)
The piece Phase 7 deferred, in both directions, because they are one question: a group's state is a few kilobytes of ratchet tree, group context and epoch secrets, and the app was rewriting all of it to record things that moved a counter. Sending an application message advances exactly one thing -- this leaf's entry in the secret tree (RFC 9420 §9) -- so the library carries the position as its own record, `MlsGroupStateStore.saveSenderRatchet`, in the spirit of OpenMLS keeping `message_secrets` apart from `group_state`. Giza defaulted that to false, which sent the manager back to a full save per message. It is now a `MarmotSenderRatchet` row, one per room, schema 36 -> 37 with an AutoMigration. The bytes are stored as the library wrote them -- the `MarmotPublishObligation` precedent, not the retained-epoch one -- because a record whose whole job is to never go backwards is safest when nothing here re-encodes it; the epoch, leaf and generation sit beside it, read off those same bytes, so they cannot drift. The hazard this introduces is an ordering, and it is in the app's code, not the library's. `MlsGroupManager.restoreAll` applies the record itself. A room joined after the engine restored is loaded from its row by `MarmotEngine.groupFor` instead, and that has to apply the record BEFORE `adoptGroup`, because adopting persists and persisting rewrites the row from the group being adopted. The other way round, the next restart re-emits generations already published, under AEAD keys and nonces already used. Finding the test that could tell the two orders apart took two goes. The first asserted the row after a lazy load and passed with the order inverted: a state saved before this leaf ever sent has no ratchet entry, `exportOwnSenderRatchet` returns null, and the adopt writes nothing. The order cannot matter until the stored state holds a position of its own behind the record's, and a received message is what puts one there. With one receive in the middle the inverted order fails with expected:<2> but was:<1>. The receive side is a full save, from `MarmotEngine.processGroupEvent`, which `NostrDao` now reads inbound events through so a second caller cannot forget it. And a correction to Phase 5, which said an unwritten row still lost the late message. It does not: mls-kmp writes the skipped keys beside the positions they belong to, so an unwritten row is an older COHERENT state, and a position that has not passed the late generation derives it forward. quartz's engine saved the positions and dropped the keys -- that pair is what lost messages. The cost of an unwritten row is the re-deriving, against SecretTree's thousand-step cap. The reason the write lands now is the send side: until this change every send wrote the whole state, so the row could not fall far behind inside an epoch. 1167 tests across 156 classes, 0 failures; Android and JVM compile clean; the four audits unchanged. docs/mls-skipped-keys.md loses its mitigation claim and gains the correction; docs/marmot-kmp.md gains Phase 8. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
9c2cbf0295 |
feat: schema 35 -> 36, the wallets' tables and rows dropped (wallet removal, Phase 5)
MIGRATION_35_36, by hand: the wallets' chat lines; GroupTransaction; every signing session over a transaction or a sweep, with its items and its members' messages; the other fifteen wallet tables, children first; and FrostSigningItem.inputIndex, DkgSession.guardianDelay and ChatMessage.lightningFactKey. DkgSession.walletPolicy stays: the join screen reads a Bennu ceremony's tag from it. The 36 schema is committed. The wallet line-type constants and the transcript's arms for them go with the rows they named. jvmTest: 1,150 run, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
30d5feaf87 |
refactor: move the sources to mobi/giza, paths only (fork, Phase 3a)
docs/scripts/giza-rename.sh --moves-only: com/machankura/bennu becomes mobi/giza in all six source sets, the nine files named Bennu* are named Giza*, and the Room schema directory moves to mobi.giza.compose.database.GizaDatabase. Every source file is a 100% rename, so log --follow and blame go straight through. This commit does not compile on purpose: the next one rewrites the contents. The script, which does both, comes with it so a merge from Bennu can re-run it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
db7d12b606 |
feat(lightning): a member asks the group to add inbound liquidity (liquidity, Phase 7)
GroupLightningLiquidityScreen asks as Phoenix asks its owner: Phoenix's amounts on a discrete slider, less those the LSP does not sell and those past the channel cap; the miner fee, service fee, its year and the total, priced on this device from the operator's report with lightning-kmp's own arithmetic (LiquidityPrice, which matches what eclair charged on regtest to the sat); Phoenix's warning at a quarter of the amount and its stop at the balance; a fee cap with room above the estimate; and a review sheet with Phoenix's acknowledgement. Then a proposal, and the signing session it opens. The wallet screen gains Add liquidity on its balance card, or the reason it is not there, a purchase's state on its channel row, and Inbound liquidity added in its payment list (a nullable liquiditySat on the payment row, in schema 35). The room gets a line when a purchase locks or fails. All of it is behind GroupLightningRollout.LIQUIDITY_ENABLED, off until the regtest run passes; the operator's node buys nothing while it is off. m3Audit meets every budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
b481c14cf9 |
feat(lightning): every co-signer checks a liquidity purchase before the group signs it (liquidity, Phase 5)
A co-signer keeps a ledger per funding output now (schema 35: IcebergChannelLedger keyed by output, with its index, the parent it spent and the purchase that let it). A commitment on an output it has no ledger for is the first commitment on a splice's new one: it must follow the newest output by one index, rebuild from its context, and open from the parent's ledger at the same number with the same HTLCs, the group's balance lower by no more than an open buy-liquidity authorisation's fee cap (CoSignerPolicy.openSplice). The shared input is then held to that authorisation: it spends the pinned output, makes one new output of the group's key with the LSP's under the cap, buys the amount the group named, is paid from the channel balance alone, costs what the first commitment took to the msat and no more than the cap, and the LSP puts in what it is paid for. An authorisation is bound to the parent of the first splice it let, so however many attempts there are, one confirms. While two outputs are live a payment settles on both at one commitment number; each ledger records what its last commitment consumed, and a sibling spends only the difference. Before this the second commitment was refused as under its floor. GroupLightningSpliceCoSigningJvmTest, seven four-device tests on regtest and mainnet: a purchase the group signs and the script interpreter accepts, payments over both live outputs, and each refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3ec79b95ad |
feat(lightning): what the operator's snapshots say happened, as lines (Phase 5)
A channel opening or closing, and a payment received, sent or failed, each get one line however many snapshots repeat them. The snapshot restates the whole wallet, so the line is keyed on the fact, not the message: ChatMessage.lightningFactKey (v34, an AutoMigration) holds the channel's or the payment's id. A payment's line sits where the payment happened, and a channel a newer snapshot no longer holds is said to have closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
638c5aab64 |
fix(lightning): the wallet's own messages leave no raw JSON in the chat (Phase 1)
Every kind the group Lightning wallet's devices send each other -- the Iceberg ceremony, the co-signing, the operator's snapshots and invoices -- reached applyInnerEvent's last arm and was written as an unsupported line holding the event's JSON, beside the lines the managers already write. GroupLightningEvents.PROTOCOL now joins the ChillDKG and FROST families as protocol, and MIGRATION_32_33 deletes the bubbles already in rooms, found by the kind of the inner event behind them, as MIGRATION_26_27 did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
cb277d3269 |
Merge branch 'bennu' into claude/lightning-wallet-iceberg-f20da1
Brings in the guarded member wallets, guarded subgroup wallets, ceremony creation, and the removal of the group's nostr profile, relays and posts. Two clashes needed more than a textual resolution: - Event kinds. The guarded-wallet family took 30333-30337, the numbers the Lightning family used for its ceremony. Nothing conflicted textually and nothing would have failed, since each side reads the other's events by kind. The Lightning family moves to a fresh run, 30350-30366, which costs nothing: rumor kinds that never shipped. GroupLightningEventsTest now knows the guarded-wallet kinds and asserts the family starts past every kind the app uses. - Schema versions. bennu used 27-31. This branch's four versions were never on an installed database, so they become one migration, 31 to 32, adding the 13 Lightning tables. Also: - bennu's new member-wallet calls (broadcast, confirmationsOf, guardianSpends, the fee suggestion) now take the network, because this branch made Electrum clients per network. - bennu's watcher conflict check uses the transaction's own network. - NEVER_BROADCAST is gone with the broadcast screen, and so is the test that checked the Lightning statements against it. The full JVM suite (1,554 tests) and the regtest run pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3b2d9bd82f |
Merge branch 'bennu' into claude/ecstatic-feynman-2c5628
Brings in member guarded wallets and funding a descendant's guarded wallet. - Schema: bennu's v30 (MemberWallet, MemberWalletSpend) is kept as it is; DkgSession.guardianDelay moves to v31, with a 30 -> 31 auto-migration. - Conflicts: strings and README take both sides; the send form's guardian delay line moves into the shared SpendForm; the guarded wallet card keeps its Fund and Spend buttons and gains this group's own leaf's delay. - bennu's uses of ANCESTOR_DELAY become each leaf's own delay: GuardedWalletRow.arriving, the funding form's "spend these coins again" line, the member wallet screens' reach text (MemberWalletManager.delaysOf) and the member certificate's proposal summary. - Four of bennu's fixtures built a "guarded" wallet with no guardian leaf; they now carry the ancestor's, as a verified statement would. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
5ff4af2d2f |
feat(dkg): a guarded subgroup's ceremony carries the delay its coordinator chose (Phase 4)
proposeRitual takes a guardianDelay and puts it on the proposal as ["guardian_delay", "<blocks>"], beside ["wallet", "guarded"] and only there; acceptProposal files it on DkgSession.guardianDelay. A delay that does not read, falls outside 6..65,535, or comes with an unguarded policy drops the proposal, and proposeRitual refuses the same before anything goes out. A guarded proposal with no delay files none, and is certified at the default later. Schema 29 -> 30: the nullable DkgSession.guardianDelay, an auto-migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
d6c2b1b20e |
feat(db): schema 30 keeps a member wallet's key and its spends (Phase 5)
MemberWallet holds the random key of a guarded wallet one member holds and a group guards, with the request that asked for it; MemberWalletSpend the transactions the member signed alone. Whether a wallet is certified is read off the group's signed events each time, so there is no column for it. Neither table has a foreign key: deleting a group's room on this device must never delete a key that coins may sit behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
58751692c6 |
feat(dkg): a subgroup's ceremony carries the wallet policy its coordinator chose (Phase 2)
proposeRitual takes a walletPolicy and puts it on the proposal as a ["wallet", ...] tag, beside the parent and subject; acceptProposal files it on DkgSession.walletPolicy. A proposal whose policy does not read, or that carries one with no parent, is dropped, and proposeRitual refuses a policy on a ceremony with no parent before anything else. Schema 28 -> 29: the nullable DkgSession.walletPolicy, an auto-migration like the other nullable additions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
33a1ef0ed2 |
feat(lightning): the operator reports the group's wallet to the room (Phase 10)
The running node sends a snapshot (kind 30345) as it starts, whenever its channels or payments change, and every five minutes otherwise: the channels, the payments it has seen, and the round-one label assignments, so whoever operates next signs under the verification nonces this operator published. A member believes a snapshot only from the operator the group elected for the term it names, about the node the statement names. It files the newest (schema 30) and keeps every payment, and the wallet screen shows balance, channels and payments, each channel checked against what this device last co-signed for it. The invoice wire and its table land here too, because they share the schema bump; Phase 11 puts them to use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
930ae341e8 |
feat(lightning): every member co-signs for the group's node (Phase 9)
GroupLightningCoSigner runs on every Iceberg participant. It publishes round one ahead of time for a pool of labels, and checks each of the operator's signing requests: the current operator in the current term, a pool label it never answered, contributions from the members they name, the funding output, and the transaction rebuilt with lightning- kmp's own builder from the context the request carries. CoSignerPolicy holds the group's claim on the channel against a floor that only authorised payments lower. A member echoes the hash it would sign and signs once n - t + 1 members echoed the same one. GroupIcebergTransport is the operator's side: it assigns pool labels, sends requests and collects shares. Schema 29 holds the pool, the ledgers and the echoes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
61c6f0b68e |
Merge remote-tracking branch 'origin/bennu' into claude/taproot-group-hierarchy-spending-7a37ac
# Conflicts: # composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/27.json # composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/BennuDatabase.kt # composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/ChatMessage.kt |
||
|
|
900fe6be28 |
feat(lightning): open a group Lightning wallet and elect its operator (Phases 6-7)
The wallet statement (30338) binds the onchain wallet it closes to, the Iceberg key and its holders, the node its seed produces, the LSP and a policy, and every member checks it against what they can recompute. The proposer sends the node seed to each participant encrypted to them, and a device files it only after deriving the node id itself (schema 28). The operator statement (30339) carries a term that only goes up; the newest term wins, a tie goes to the lower event id, and only the operator can step down. Both stay inside the group. A Lightning wallet screen walks a room from no onchain wallet to an elected operator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
99a2185463 |
feat(lightning): the group makes its Lightning wallet key (Phase 5)
IcebergRitualManager runs the Iceberg DKG in the group's Marmot room over the people who hold the onchain wallet's key, behind the same three approval gates the ChillDKG ceremony has. Contributions travel NIP-44 encrypted to the members who will hold them. Schema 27 adds the session and message tables; a screen and transcript lines show who has done what. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
2d57f9b4c9 |
refactor(db): drop the nip30303 document tables (Phase 8)
Schema 26 -> 27. MIGRATION_26_27 deletes the chat lines the removed document arms wrote and the unsupported bubbles a subgroup's ceremony left in its parent's chat -- found by the kind of the inner event behind them, so an unknown payload's bubble stays -- then drops the twelve document tables, children before parents, and MarmotInnerEvent.payloadEventId. Manual, because it deletes rows. GroupSignedEvent keeps whatever the group signed, and the chronicle keeps its column and its lines. The nip30303 events and tags, the Mantra entities and DAOs, the repository interface and the Markdown helper go with the tables, and so do the tests that only exercised them. The key-state test signs posts where it signed dialects. The migration test builds v26 from the exported schema and checks the result against v27's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
00df58c1f3 |
feat(wallet): an ancestor's quorum spends a descendant's coins through its leaf (Phase 7)
GroupSpend checks a spend as a guardian would sign it: every input under the descendant's account, locked by the leaf's 12 blocks, signed over the script-path sighash as the key the ancestor's walk reaches, and witnessed with the leaf and its control block. The builder waits out the lock and weighs the leaf; the signing manager proposes, accepts, signs and completes it, and every signer reads the descendant's wallet from its own copy of the statement. A guarded wallet row on the ancestor's wallet screen opens the send form for it. Schema v27 adds GroupTransaction.guardedChatRoomId. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
f7a9e05bbc |
feat(wallet): schema v26 for spends from a group's wallet (Phase 6)
FrostSigningSession.subject, NOT NULL with a default of EVENTS, says what a session's items are messages of; FrostSigningItem.inputIndex names the input a transaction item signs, with message and payload as getters over the existing columns. GroupTransaction holds a spend from proposal on: the PSBT, written once with IGNORE, the txid fixed before signing, and the signed transaction, broadcast, seen and confirmed. AutoMigration(25, 26) is three ADD COLUMNs and a CREATE TABLE -- no rebuild of either signing table, so no cascade fires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
b75d4b427f |
Rebrand Curare to Bennu under com.machankura.bennu
Move the packages to com.machankura.bennu.{compose,android,desktop}, the
Android applicationId to com.machankura.bennu.android and the iOS bundle
id to com.machankura.bennu.ios. The root project, launcher label, iOS
product, desktop window, user-facing strings, client tags and the
Curare* classes all say Bennu now.
Left alone on purpose: the mantra/ derivation tags, the `curated` desktop
data directory, the mantra.press relay and the curare.to references.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
01e022fdcc |
feat(frost): a proposer can resend a signing session
A session can sit in COLLECTING_NONCES forever waiting on a member who would have agreed, because the message asking them never arrived. MLS moved its ratchet past the generation it came in at, which is terminal at the receiver and invisible to the sender (docs/mls-skipped-keys.md); or a disappearing-message group expired it off the relay; or the member joined the room after the proposal was made, holding a share from an earlier ceremony. None of them heals on its own, and nothing asked the sender to resend. `FrostSigningManager.resend` repeats what the coordinator wrote -- the proposal, and whichever of the signer set or the signature the stage has reached. A resent message is a *new* message: new created_at, new id, encrypted at a generation the receiver has not passed, carrying a fresh expiry. That is why it works where the first copy did not. Two and never three. Publishing in bursts is what the skipped-keys bug feeds on, and a recovery for it that re-creates it is no recovery, so the stage table is a minimum rather than "send everything". The resent proposal names the members the coordinator has heard nothing from, and a named device republishes what *it* already sent -- the stored bytes, under its own key. That is the only half that can repair a nonce lost on the way *to* the coordinator: `advance` republishes a message it has no local copy of, so a device that published and recorded its nonce would never send it again. It publishes nothing new, so a nudge cannot talk a device into putting its share behind events its owner has not approved. Coordinator-only, both halves, and that is correctness rather than etiquette: `acceptProposal` takes coordinatorPublicKey from the proposal's author, so a non-coordinator resending to a member with no session row would have that member drop the real coordinator's signer set. Also fixes a bug `broadcast` had all along. An outbound row's primary key is a hash over its created_at, stored to the second, so a message re-published inside that second hashes to the id of the copy it repeats -- and the upsert put an already-sent row back on the queue with marmotGroupEventId cleared, double-sending it and losing its mapping to the group event it became. It now steps past a taken id rather than writing over it, and refuses after four tries. Schema 24 -> 25 for FrostSigningSession.resentAt, which is the cooldown and the second line of defence on that collision. Phase 4's column, pulled forward because Phase 2 needs it. Plan: docs/frost-session-resend.md, Phases 2-4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
984db0a180 |
Merge branch 'curated' into claude/quartz-1-15-2-compat-c8267f
Both sides had taken schema version 21: curated for the nullable FrostSigningSession.signDeclinedAt (one refusal takes a member out of the n), this branch for the Marmot current profile's three columns, with 22 and 23 behind it for the routing table and the publish obligations. Curated keeps 21. This branch's three migrations move up one -- 21->22, 22->23, 23->24 -- and the database is at 24; the comment on 22 says they moved and why. The exported schemas for 22 and 23 could not be hand-edited, since each is a snapshot of the whole entity set with an identity hash over it, and could not be produced from the merged tree, which only exports its own version. So each was regenerated the way the originals were: the tree of the commit that introduced it (Phase 3 for 22, Phase 4 for 23), with curated's entity change and its 21.json dropped in, the version bumped, and KSP run. The result is what a device on curated's 21 migrates through: 22 adds the three columns and nothing else, 23 adds MarmotRouting, 24 adds MarmotPublishObligation and MarmotOutboundGate together with MarmotCommitResult.obligationId, and every one of them carries signDeclinedAt. 24.json is the merged tree's own export. Everything else merged itself: ChatMessage's kinds and line types, the transcript's icons, the strings, the nav host. Full jvmTest 1220 green, Android debug compile, M3 audit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
a7f3917e65 |
fix(frost): one refusal takes a member out of the n; it takes n - t + 1 to abandon
"Don't sign" ended the session for everybody: decline() failed it locally and broadcast a FAILURE, which every other device failed on arrival. In a group whose whole reason for running a ceremony was that no one member is needed, one member's no was everybody's. A refusal is now its own kind, DECLINE (30330), and one FrostSignerMessage per member, like a nonce. Every device counts the refusals it has received from ceremony participants against the same arithmetic -- FrostSigningSession. declinesThatAbandon(), which is n - t + 1 -- and fails the session only on the refusal that leaves fewer than t who could still sign. Nobody broadcasts the abandonment, because nobody has to: each device reaches it the way each writes its own transcript, and a FAILURE sent to say so would blame one member for the group's arithmetic. In a 2-of-3 group the first refusal changes nothing the other two can do; the second ends it. FAILURE keeps meaning abandon-and-blame, for the faults no quorum can work around, and a build predating the new kind still sends its refusals that way and is honoured as it always was. decline() takes approve()'s shape: the decision goes on the row, as the new nullable signDeclinedAt (Room v21, an AutoMigration), and advance() publishes it whenever the row says so and no copy is on file -- so a device killed between deciding and sending says it on the next message rather than never. A member who refused is not asked again, but the session stays open around them and closes when the group's signature arrives. Refusals from a member holding no share of the key are turned away at the door. fail() now leaves a COMPLETE session alone. A member who refused before their device had seen the signature has refused something that no longer needed them, and a late FAILURE used to flip a signed session to failed. The transcript gets a TYPE_FROST_DECLINED line for a refusal the session survives, with the count -- "declined to sign. It takes 2 of 3 members, and 2 could still sign." -- and the tipping refusal is written as the FAILED line in that member's name, saying both that they declined and that it was the one that ended it. A reader's own refusal settles their request line, and only theirs; nothing earns a tick. The signing screen marks who declined and says how many could still sign, and the proposal list says "You declined." where it said "You agreed." Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
f617560cf9 |
feat(marmot): publish before apply (v2 Phase 6)
A commit this device makes into an established current-profile room is no longer applied and then broadcast. It is prepared on a clone by the manager, recorded as a durable obligation before anything is broadcast, sent, and installed only when a relay in its scope accepts it. docs/marmot-v2.md, Phase 6. The library's gate explains why apply-and-roll-back is not the same thing: between applying a local commit and undoing it on failure there is a window in which this client's canonical state is an epoch no peer has, and a crash inside it makes the fork permanent. Recording the obligation before the broadcast closes the mirror-image window -- a commit peers accepted that this device has no memory of preparing, and would mint a replacement for at the next start. Two new tables (schema 22 -> 23), MarmotPublishObligation and MarmotOutboundGate, back RoomPublishObligationStore; MarmotEngine holds a MarmotPublishGate over it and restores it after the groups. MarmotCommitResult -- the row that already held a commit's Welcome until the relay's OK -- carries the obligation id, and DatabaseNostrRepository.broadcastProcessed resolves it on "published" through MarmotEngine.confirmPublished, which installs the pending state, tells convergence of the commit we authored (without which a peer's competing commit would look like an orphan rather than a fork we are half of), and only then lets the Welcome go out: the MIP-02 ordering enforced by sequence rather than by hope. A second OK for the same event from another relay finds no obligation and changes nothing. The founding Add keeps its exception. A group that is only its creator has no peer a failure to publish could fork, so it installs at once -- the library's satisfyEmptyObligation draws the same line, "creation and its immediately following founding Add, never a later commit". While an obligation is pending the room cannot prepare another commit: a second invite is refused with MarmotCommitPendingException, shown as itself on the confirmation screen, rather than forked; the membership note's batching closed the race inside one invite, and this closes it between invites. The broadcast queue's requeue re-sends the same signed event, which is the byte-identical retry the rule demands, and a "failed" from the pump -- a timeout or a relay's refusal, which the pump does not tell apart -- leaves the obligation pending rather than discarding a state some relay may have taken. Legacy rooms are unchanged. Tests: PublishBeforeApplyJvmTest pins the founding Add installing at once, a later commit prepared and queued but not applied, the second Welcome held back, a concurrent invite refused, the OK installing the state and queueing the Welcome, a second OK changing nothing, and an obligation restored by an engine rebuilt over the same database and installed by a late OK. Full JVM suite: 1,177 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
9b5e4c95fc |
feat(marmot): current-profile rooms, and a routing address apart from the room id (v2 Phase 4)
After this the app can create rooms on the current profile -- behind MarmotProfile.DEFAULT_FOR_NEW_ROOMS, which stays legacy until the rollout flips it -- and every path keyed on the `h` tag reads the room through its address. docs/marmot-v2.md, Phase 4. The room's id is a key. A room built around a threshold key is keyed on the id derived from that key -- the one it signs as and every chronicle is verified against -- and every member can compute it unaided. v2's routing component says of `nostr_group_id` the opposite: random, never derived from any public key, because a derivable address lets a relay link a group's traffic to the identity behind it, which here is the key that authors the group's published entries. Both are right about their own value, so they are two values now. A new MarmotRouting table (schema 21 -> 22) maps an address to its room; a current-profile room this app creates mints a random one, and every other room -- legacy, or made by another client -- has a row whose address is its own id, or no row at all and is addressed by its own id, which every reader falls back to. The inbound ingest, the reindex, the negentropy answer for a `#h` filter, the chat list's sync request and the live subscriptions all resolve or emit addresses; LocalChatRoom carries its routings as a relation so the subscription planner needs no query; the outbound commit, application and Welcome templates are stamped with the room's address rather than its id. A joiner keys a room on the group's `nostr_group_id`, which for a current-profile room would be the address, and the creator, the joiner's own DKG session and every chronicle know the room by its derived id. The components carry no field for it, so it rides in the group profile's description as one line -- `Room id: <hex>` -- the way the derivation path already does, and MlsGroup.roomId() reads it back first. It is a claim by the creator, exactly as the legacy `nostr_group_id` was, and is trusted no further. MarmotGroupFactory is now the one place a group is minted. The three sites -- a direct message, the convenient room, and the derived room MarmotGroupCreation builds -- say what the room is, and the factory decides the profile: a legacy group is the 0xF2EE extension as before; a current-profile group is quartz's own CurrentProfileGroupFactory with the admin policy, routing, profile and the creator's proof-bearing leaf, and no 0xF2EE at all, because RFC 9420 requires every member to support every GroupContext extension and an MDK leaf does not advertise it. Creating a direct-message room reads the identity from the chat repository, which now takes it, so the creator's leaf can carry its proof. A peer's KeyPackage is picked by the room's profile rather than by age: a current-profile room takes the newest current-profile package or none, since the legacy package is deliberately the newest a peer publishes. A leaf on the wrong profile is refused a step before the library refuses it, with a reason the member can act on -- their package is from an older profile -- shown on the confirmation screen and in the room's line rather than as "try again". Tests: MarmotGroupFactoryJvmTest pins both profiles' shapes, the address minted apart from the room id, the room id riding in the description, the read-only creator refused on the current profile, and which leaves fit which groups; MarmotGroupCreationJvmTest adds a current-profile room keeping its derived id with a routing row, a legacy room unchanged, and a kind:445 under the address filed in the room; MarmotRoomIdentityTest the description line; LiveSubscriptionPlanTest the addresses watched. Full JVM suite: 1,166 pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
99dba546d8 |
feat(marmot): identity proofs and the current-profile KeyPackage (v2 Phase 3)
After this a peer on Amethyst 1.15.2 or White Noise can add this app's users to their current-profile groups, and the app joins. docs/marmot-v2.md, Phase 3. A current-profile leaf carries an app data dictionary with three components: the component ids it supports, an explicitly empty safe_aad list, and the 104-byte account identity proof -- the account's Nostr key signing a kind-450 template that is never published and names this leaf's own Ed25519 signature key. MLS never checked that the account in a credential agreed to the signature key beside it; the proof is what makes a leaf unforgeable, and a current-profile group refuses a leaf without one at add time. Only the account signer can make it, and it has to exist before the leaf is built, so publishMarmotKeyPackageBundle now takes the KeyPair rather than the public key it used to. The current-profile package comes from quartz's own CurrentProfileGroupFactory -- the same leaf shape Amethyst publishes, including the agent-text-stream component the reference client requires of every leaf it invites -- and its kind:30443 from KeyPackageEvent.buildCurrentProfileFrom: framed content, the 0x0006 extension, the 0x0008 and 0x000a proposals, an app_components tag, no encoding and no relays tag. KeyPackageUtils.isValid checks all of it, and the tests run that validator because it is the one a peer runs on ours. The legacy package is still published, in a second slot, for as long as builds that decode kind:30443 content as a bare KeyPackage are inviting people (Phase 9 retires it). It is stamped one second after the current-profile package, every time both are published: an inviter picks a peer's newest package by created_at, and an old build then fails on a framed one, so the legacy package has to stay the newest. Each profile now has a slot whose d-tag is minted once and reused on every rotation, so a replacement supersedes the previous event on relays instead of accumulating beside it -- the "TODO: Persist this" on the random d-tag. Schema 20 -> 21, an AutoMigration: MarmotKeyPackageBundle.profile and .dTag, and MarmotKeyPackage.profile filled at ingest from KeyPackageEvent.isCurrentProfile(). Rows from before read back null, which every reader takes as legacy. The notary keeps one publishable bundle per profile rather than any bundle at all, because a current-profile peer consumes only the current-profile package and the legacy one still being active would otherwise mean nothing was republished for them. The key-package screen takes the identity, not just its public key, and refuses to publish for one that cannot sign rather than reporting "published". KeyPackages now also go to the account's NIP-65 write set, unioned with the default DM relays -- transports/nostr.md has a conformant peer look there and nowhere else, "there is no dedicated KeyPackage relay list" -- and the member and peer sync requests ask for kind 10002 alongside the legacy 10051 hint. Tests: CurrentProfileKeyPackageJvmTest pins one package per profile with the legacy one a second later, both passing the peer's validator, the proof binding the leaf to the account, a rotation reusing its slot, and the join: a group made by quartz's own factory standing in for Amethyst adds the app's package, the Welcome arrives as a NIP-59 gift wrap through the sync funnel, and the app lands in a room keyed by the routing id from the 0x8004 component with the inviter as admin. The npub round-trip test now waits for both bundles. Full JVM suite: 1,153 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
759199f2af |
feat(sync): a fetch queue per identity, and the inbox reopened on activation
Phase 6 of docs/multiple-profiles.md. The one data problem, closed from both ends. The two queues that fetch -- SynchronizeNostrEventRequest and NegentropySynchronizeRequest -- gain a nullable ownerPublicKey, the identity that asked, because what a fetch brings back is opened with the fetcher's key. The pumps ask for their own: the head of the queue among this identity's requests and the ones nobody owns, so that a request another identity queued waits for that identity. Rows from before the column read back null, meaning "the device's", which is what they were, and any identity may drain them. The broadcast queue deliberately gets no owner: a signed event is anyone's to carry, and holding A's outgoing message until A is opened again would be a delivery failure the user would never be told about. Room version 20, an AutoMigration for two nullable columns, with the schema export committed beside its predecessors. The stamp is the repository's, not the call site's. Eighteen view models and two DAO paths queue requests, and every one of them does so as the active identity -- a screen cannot queue anything as anyone else. DatabaseNostrRepository takes the identity flow at construction, which meant moving the view model above the repositories in the nav host, and stamps every request it queues where the caller stamped nothing; a negentropy request carries its owner into the REQ it becomes. The DAO's own requests -- the placeholder-profile syncs it plants while indexing, and the participant syncs of a Marmot join -- stay unowned, on purpose and against the plan's sketch: they fetch public kinds that need no key to open, and any profile that is open may as well fetch them. The other end: wraps that were fetched under the wrong key -- before this, or by a read-only identity whose nsec was pasted later, the case the npub plan's DAO guard left with the words "the key that opens this one may be signed in later" and no code behind them. storeNostrEvent never indexes an event it already holds, so a wrap that arrived under the wrong key stayed closed for good: the live subscription re-received it, the DAO saw a known id, and returned. NostrDao.reopenInbox finds every wrap addressed to the active key that no seal names and runs each through indexNostrEvent again under the right key, one transaction per wrap so that one that cannot be opened rolls back its own changes and the next is still tried; one pass, since wraps do not depend on one another. It runs from the sync pumps' collector once per activation, for an identity that can sign, before the live inbox and the broadcast pump are launched -- so the sweep and the live subscription are not opening the same wrap at once; both are idempotent by event id. Found on the way: GiftWrapSeal.giftWrapMessageId, a foreign key to the wrap a seal came out of, existed and was never written, so nothing in the database could say which wraps had been opened. decryptGiftWrapSeal now sets it. A seal from before reads back null, is swept once, and comes back with the link -- the reindex is idempotent, and persistInboundChatMessage already files a message it has once. Tests: ReadOnlyGiftWrapDaoJvmTest -- a wrap for us stored under another profile's key is stored and not opened, a re-delivery under our key changes nothing, the sweep opens it once and finds nothing the second time; the other profile's sweep and a read-only pair open nothing; a wrap stored read-only is opened once the key is here. OwnedRequestQueueJvmTest -- A's request is offered to A and not to B, nobody's to both, oldest first; the repository stamps what it queues with the identity that is open, nothing when none is, and keeps an owner a caller named. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
e6aee79282 |
refactor: rebrand curated to curare, and the one name that stays on disk
`com.it.curated.{compose,android,desktop}` becomes `to.curare.{compose,android,desktop}`
across 700 file moves, and the app is Curare everywhere a user can read it. This is the
third rename this tree has been through, so the question was never how to spell the new
name but which of the 5074 occurrences of the old one were the brand. `3bc8be53` and
`d26cf6c7` had already sorted most of that, which is why this rename is mechanical where
those two were not -- and why the interesting part is the one place it is still not.
**`APP_DIR_NAME` keeps the old brand, and is the only thing that does.** It names the
desktop app's data directory -- `~/.local/share/curated`, `Application Support/curated`,
`%LOCALAPPDATA%\curated` -- and that single directory holds the Room database, the marmot
group state and the phoenix wallet. Renaming it does not move an install: it silently
starts an empty one beside it and leaves the old chat history and the old seed sitting
where nothing reads them any more. That is the same class of silent failure as the
`mantra/` hash prefixes, so it gets the same treatment -- it stays, with a comment saying
what renaming it would cost and that doing it properly is a first-run migration rather
than a rebrand. The desktop app is `curated` on disk and `Curare` everywhere a user can
read.
**The applicationId and the namespace are one value again, at `to.curare.android`.**
`3bc8be53` split them precisely so `com.it.curated` could land verbatim as the store
identity while the namespace kept `.android`; the decision here was to collapse them, so
both read `to.curare.android` and the manifest's relative `android:name=".CurareApplication"`
and `BuildConfig` resolve against the same package they always did. Debug is
`to.curare.android.debug` through the existing suffix. Worth stating plainly because
nothing in the build will: an applicationId *is* the app's identity to Play, so this is a
new listing rather than an update, and no installed Curated can update into it.
**`CuratedDatabase` -> `CurareDatabase` moves a directory, never a table.** The `@Database`
class name picks the schema *directory*, so
`composeApp/schemas/com.it.curated.compose.database.CuratedDatabase/` becomes
`to.curare.compose.database.CurareDatabase/` and its 19 files move unmodified. What makes
that safe has not changed since last time: the 12 entity classes are still `Mantra*` and
still declare no `tableName`, so Room still takes their class names as the SQLite table
names -- and this rename does not touch one of them. The check is that Room found all 19
schemas at the new directory and generated no twentieth.
**The generated resources package moved because `rootProject.name` did, again.** Compose
Resources derives it from the root project, so `Curated` -> `Curare` silently turns
`curated.composeapp.generated.resources` into `curare.composeapp.generated.resources` and
breaks 72 files' imports at once. Rewritten with them: the two string keys that carried
the brand -- `curated` and `sign_in_is_not_yet_available_while_curated_is` -- their three
call sites, and the eight `docs/scripts/` tools that hardcode the UI source path. The
audit reporting 582 `stringResource` sites and 178 `Icon(` call sites is the evidence
those tools still see the whole tree rather than an empty directory.
**A global rename edits the sentences that describe the previous rename, and two of them
came out false.** `material-design-conformance.md` recorded that `TorchTheme` became
`CuratedTheme` and that `UserAgent` was moved off Torch "when the app was rebranded to
Curated" -- which a blanket sweep turns into a claim about a change that had not happened
when it was written. Same in `HomeScreen`, where "the brand before that one" meant Torch
while Curated was current, and quietly came to mean Curated while still naming
`TorchTheme`. Both now say what happened, in order. The three deliberate Torch records --
the finding at :278, that note, and `NavigationRoutingTest`'s fixture -- are intact.
**What was protected stays protected, and now says "two rebrands".** `TWEAK_TAG`,
`HOST_KEY_DERIVATION_TAG` and `wss://ephemeral.mantra.press` are byte-identical; only the
prose around them moved, because "survived the rebrand to Curated" had stopped being the
whole story. The tree's 1668 `Mantra` and 17 `Torch` tokens differ from the 1666 and 16
before this change only by the words those comments added.
**iOS is `Curare` / `to.curare.ios`**, with the three pbxproj product references renamed
to match, and is unverified here for the same reason as last time -- the build gates the
ios targets behind `isMacOsX` and this was built on linux. The bundle id takes a platform
segment rather than the bare base it translates from, so that it reads alongside an
android applicationId that now carries one: `to.curare.android` and `to.curare.ios`, and
`to.curare` left as the base neither store claims.
1226 tests pass -- 787 in `:composeApp:jvmTest`, 439 in `:composeApp:testDebugUnitTest` --
`:composeApp:compileDebugKotlinAndroid` is clean, and `m3Audit` meets every budget.
Three stale things are left alone, because none of them is branding.
`.gitea/workflows/material-design-conformance.yml` still triggers on `branches: [mantra]`,
which stopped naming a branch that exists somewhere before this change and is now two
brands out; the three `torch_*` string keys still carry a brand two renames old, though
every value they hold reads Curare; and `androidMain/res/values/strings.xml` has opened
`<resources>a` since well before this. Each wants its own change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
||
|
|
3bc8be535a |
refactor: rebrand mantra to curated, and the five names that stay
`press.mantra.{compose,android,desktop}` becomes `com.it.curated.{compose,android,desktop}`
across 680 file moves, and the app is Curated everywhere a user can see it. The work
that mattered was not the rename; it was deciding which of the 6355 occurrences of
"mantra" were the brand and which were something else wearing it.
**"Mantra" was two words in one tree, and only one of them is a brand.** 1369 of the
tokens belong to a domain model -- `MantraArtifact`, `MantraChapter`, `MantraChunk`,
`MantraDialect`, the seven `MantraTranslation*` types, their 15 DAOs and
`MantraRepository` -- and those 12 entity classes declare no `tableName`, so Room takes
the class name as the SQLite table name. A blanket `s/Mantra/Curated/` renames 12 live
tables, which is not a rename but a v20 with 12 `@RenameTable` specs and a regenerated
schema. Asked, the decision was brand surface only, so the domain keeps its name and the
database keeps every one of its tables. The count is the check: the same 1369 tokens are
present before and after, and Room found all 19 existing schemas at the moved directory
and generated no stray -- which is what proves no table moved.
**Renamed instead is the set of names that only ever meant "this app".** `CuratedApp`,
`CuratedApplication`, `CuratedGlobal`, `CuratedNavHost`, `CuratedNavigationSuite`,
`CuratedShapes`, `CuratedConverters`, `defaultCuratedDir`, and `CuratedDatabase` with its
constructor and test. `CuratedDatabase` is safe to rename precisely because the entity
classes were not: the `@Database` class name picks the schema *directory*
(`composeApp/schemas/com.it.curated.compose.database.CuratedDatabase/`), never a table,
so the 19 schema files move unmodified and the AutoMigration chain from 1 is untouched.
**`com.it.curated` is the applicationId; the namespace is `com.it.curated.android`.**
These were one value before, and splitting them is what lets the identifier land verbatim
as the app's store identity while `BuildConfig` and the manifest's relative
`android:name=".CuratedApplication"` keep resolving against the android source package.
The debug build is `com.it.curated.debug` via the existing suffix.
**The generated resources package moved because `rootProject.name` did.** Compose
Resources derives it from the root project, so `Mantra` -> `Curated` silently turns
`mantra.composeapp.generated.resources` into `curated.composeapp.generated.resources` and
breaks all 501 imports at once. They are rewritten, along with the two string keys that
carried the brand -- `mantra` -> `curated` and `sign_in_is_not_yet_available_while_mantra_is`
-- and their three call sites. The seven `docs/scripts/` tools and `m3-audit.sh` hardcode
the UI source path, so they moved too; the audit passing is the evidence they still see
the whole tree rather than an empty one.
**Two hash inputs and a hostname keep the old name, and now say why.**
`SharedKeyDerivation.TWEAK_TAG` and `ChillDkgRitualManager.HOST_KEY_DERIVATION_TAG` are
`"mantra/..."` strings that are fed to SHA256. Renaming them derives different keys from
the same seed: every room already created is orphaned, every completed ChillDKG becomes
unrecoverable, and a Curated client and a Mantra client sharing a group derive different
keys from one threshold key, so their partial signatures aggregate to something that
verifies against nothing. That is a protocol fork and belongs in a `v2` tag, not in a
rebrand. `Relays.ephemeral` stays on `wss://ephemeral.mantra.press` for the duller reason
that it is a relay that is running and is in the bootstrap, publish, finder and DM sets;
pointing it at a name nobody has stood up takes the app off the network. All three sites,
and `docs/shared-key-derivation.md`, now carry the reasoning, because the failure mode of
each is silent and the next reader will otherwise finish the job.
**iOS had never been moved off the brand before this one.** `Config.xcconfig` still read
`PRODUCT_NAME=Torch` with a bundle id of `ac.aux.compose.Aux` -- two brands ago -- so a
Curated repo built a Torch.app. It is now `Curated` / `com.it.curated`, with the pbxproj's
three product references renamed to match. This is wider than Mantra -> Curated and is
called out for that reason; it is also unverified here, because the build gates the ios
targets behind `isMacOsX` and this was built on linux. In the same spirit the last stale
`press.auxiliary.compose` file -- a KMP template test asserting `1 + 2 == 3` -- was
relocated rather than deleted, so the source tree has one root package instead of an
orphan under the vacated one.
**Three things still say the old names on purpose and are not oversights.**
`UserAgent.APP_NAME` and `CLIENT_NAME` still read `"Torch"`, which a previous rename left
deliberately: it goes on the wire to relay operators and is a network identity rather
than a content one. `.gitea/workflows/material-design-conformance.yml` triggers on
`branches: [mantra]` because that is still the branch's real name. And
`docs/material-design-conformance.md:278` records that the top bar once read `"Torch"`
while the window title read `"Mantra"` -- a finding about a past defect, which rewriting
would falsify.
1136 tests pass -- 733 in `:composeApp:jvmTest`, 403 in `:composeApp:testDebugUnitTest` --
`:composeApp:compileDebugKotlinAndroid` is clean, and `m3Audit` meets every budget.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
||
|
|
1e7ddd844a |
feat(subgroups): schema 19 -- the two things a ceremony's own room used to answer
A subgroup's ChillDKG is about to move out of the sibling NIP-17 room derived from its admins and into the parent's Marmot room. That room answers two questions the sibling room answered for free, and it answers both of them wrong. **Who the ceremony is with.** The sibling room's membership *was* the participant set -- it was derived from it -- so `memberPublicKeys(localChatRoom)` was the admin list, and three callers read it that way: `broadcast`'s p-tags, the birth certificate's `adminPublicKeys`, and the members `MarmotGroupCreation` welcomes into the child. The parent's room is a superset, so each of those would silently name every person the subgroup is *not*. `participantPublicKeys` is the set the ceremony was opened on, sorted and comma-joined the way `publicShares` already stores a list. **What the room it makes is called.** The sibling room carried the subgroup's name as its subject, put there by the coordinator and delivered to everyone else by `getOrCreateNip17ChatRoom` reading the proposal's `subject` tag. A ceremony in the parent's room has no room of its own to be named, and the parent's name is the one name a child must not take -- `proposeBirthCertificate` normalises this string into the certificate the parent's quorum signs, and `MarmotGroupCreation` normalises it again onto the room. `subject` is where it lands instead. Both are read off the proposal, which has carried both since `7bccf243` -- the p-tags and the `subject` tag. Nothing new goes on the wire; what changes is where it is kept. Both are nullable and both fall back to the room, which is correct for every row written before this: a ceremony in its own NIP-17 room ran over exactly that room's members and was named after it. **Sorted, because two devices assemble the set differently.** The coordinator builds it from a picker; every other device builds it from the proposal's p-tags plus the sender. `DkgSession.formatParticipants` sorts so those are the same string, which is what makes it something a query can match on. Two queries, both of which exist because `DkgSession.chatRoomId` is about to stop identifying a ceremony: `getLatestSubgroupSessionFor(room, parent, admins)` is what "may I open another" means for a subgroup once the parent's room hosts every one the group ever runs. `getLatestSessionFor(room, parent)` cannot answer it -- two subgroups of one parent share both columns -- and scoping on the room alone would refuse a group's second subgroup on the strength of its first. `getLatestOwnSessionForChatRoom(room)` is `getLatestSessionForChatRoom` with `parentChatRoomId IS NULL`. It exists for `FrostSigningManager.completedKey`'s last fallback, which is the one every parent member welcomed after the group's own ceremony lands on: the parent's room will hold a *completed* ceremony whose key is the child's, and a ceremony run to make a subgroup is never the room's own key. The claim is unverified, but the only direction it can be abused in is a member excluding a ceremony they themselves proposed, whose key they would simply not have proposed. `AutoMigration(18, 19)`: two nullable columns, a shape Room migrates itself. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
0b65d7025b |
fix(subgroups): open the ceremony a transcript line is about, not the room's newest
Diagnosed off the four connected devices. Three subgroup ceremonies of "one (#admins)", all opened correctly by the coordinator, all sitting at COLLECTING_HOST_KEYS with 1 of 3 host keys in. Nothing was dropped: every participant device held the session, the ceremony room, its members and the "your approval is needed" line. What none of them could do was reach it. **A room does not have *a* ceremony, and every version of this screen has assumed it does.** A subgroup whose admins are the whole group runs in the room the group's own ceremony ran in -- that is the point of `1930d6aa`, and it is what the devices did. Ask that room for its ceremony and you get whichever was opened last. On the devices that was the group's own, already COMPLETE, in five of the six room/device pairs; the subgroup's request for a host key sat underneath it, unanswered, with the screen showing a finished ceremony and nothing to do. Both previous attempts were the same mistake: - unscoped "newest in room" -- picks the wrong ceremony whenever the other one is newer, which is what shipped and what the devices show; - scoped by purpose (`1930d6aa`) -- invisible to every member who did not open the subgroup, since only the coordinator's route carries a parent (`98626a9e`). Neither ordering can be right, because the question is wrong. **A line knows which ceremony it is about; the room does not.** So `ChatMessage` gains `dkgSessionId`, the pair to `frostSigningSessionId` and added for the same reason one-at-a-time stopped being true -- `docs/frost-batch-signing.md` reached this conclusion for signing sessions already, and the ceremony half was left on the clock because "a room runs one at a time". It doesn't any more. Every DKG line is stamped in `announce`, which all of them already funnel through. `DkgRitualRoute`, the three approval routes and their screens carry the id, the transcript's ritual notice passes the tapped line's, and `DkgRitualViewModel` observes that session when given one and the room's newest otherwise -- which is still the best a caller holding only a room can do, and is what the group's details entry passes. `ChatMessage.isAbout` uses it too, so `answeredRequests` stops crediting an answer given to one ceremony as an answer to the other. Rows written before the column read back null and fall back to the clock, which is correct for them: nothing that predates subgroups ran two ceremonies in one room. Schema 18, one nullable column, `AutoMigration(17, 18)`. One test in `RobustRoomKeyCeremonyTest`: with two ceremonies in one room, every line names one of them and a subgroup line resolves to the subgroup's ceremony. It deliberately does not assert which the room's "newest" is -- two ceremonies opened in the same second tie on `createdAt`, and the point is that nothing relies on that ordering any more. 397 common tests, 716 jvm tests, `m3Audit` meets every budget. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
f6217ce6ea |
feat(subgroups): schema 17 -- four nullable columns, and not one of them a foreign key
Phase 2 of docs/subgroups.md. Somewhere to put a parent, now that Phase 1 can prove one. | table | column | filled from | trusted? | |---|---|---|---| | GroupKeyState | parentChatRoomId | the state's parent tag | yes -- the certificate was checked | | GroupKeyState | birthCertificateJson | the state's certificate tag | yes -- same | | ChatRoom | parentChatRoomId | the verified key state | yes | | DkgSession | parentChatRoomId | a tag on a ceremony proposal | **no** -- a screen's title | The trust column is the point of the table and is written into the KDoc of each one. Three of these are written only after a signature has been checked; the fourth is an unverified claim off a wire message, and a column that mixed the two would be a column no reader could act on. Nothing may be granted on the strength of `DkgSession.parentChatRoomId` that would not be granted without it. **None of the four is a foreign key, and that is the change most likely to be "fixed" by somebody later.** `GroupKeyState`, `DkgSession` and `GroupSignedEvent` all declare `ForeignKey(onDelete = CASCADE)` onto ChatRoom, so pointing a parent column at ChatRoom the same way is the obvious next move. It would mean deleting a parent room deletes every subgroup row beneath it -- and then, by their own cascades, each subgroup's messages, participants, key state, signing sessions and signed events. A user tidying away a group they had left would silently destroy a group they are still in. RESTRICT is no better: it would make a parent undeletable while any child row exists, which is a foreign key deciding a product question. And neither would work anyway, because a parent pointer routinely names a room this device does not have at all -- a member of a subgroup who was never in its parent holds the id off a certificate and nothing else. A dangling reference is the normal, expected state here, and readers resolve it with a lookup allowed to return null. **The certificate is stored whole, as JSON, rather than as its signature.** A signature plus a rule for rebuilding the event it covers is a rule that breaks silently the first time the certificate's shape changes: a rebuild differing by one byte hashes to an id whose signature fails, and is indistinguishable from a forgery. A few hundred bytes inside an encryption removes the class. The parent column beside it is an index into that event, never a second source of truth -- the two are written together or not at all. Four DAO reads, each with the limits of what it answers written down. `GroupKeyStateDao.getByParentChatRoomId`/`observe` list the children whose state this device holds, which is *verified* but not complete -- a certified child whose room was never created here leaves no state at all. `ChatRoomDao.observeByParentChatRoomId` lists the ones there is something to open, excluding soft-deleted rooms so a room the user cleared away does not reappear because its parent lists it. `DkgSessionDao.getByParentChatRoomId` is how a member gets back into a subgroup flow they closed the app during, since before the certificate is signed the ceremony is the only thing on the device that knows the flow was started. `AutoMigration(16, 17)`: nullable additions are a shape Room migrates itself, and 17.json exports with no new foreign key on any of the three tables. Nine tests in `SubgroupDaoJvmTest`, all on properties the compiler cannot see: a state and a room may each name a parent this device holds no room for; deleting a parent leaves its child, its child's key state and its child's lineage standing; the parent lists its children newest-first and filters on *which* parent rather than on having one; a soft-deleted subgroup drops out; and a ceremony round-trips the parent it was opened for. 386 common tests and 673 jvm tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
30c732af67 |
Merge branch 'mantra' into claude/home-chat-previews-e1913f
Two conflicts, and both are the same collision: mantra took schema v15 while this branch was also calling its migration v15. **The version number.** mantra's v15 adds `ChatRoom.joinedGroupAt` with a manual MIGRATION_14_15, because half of what it does -- deleting the placeholder chat lines already written for messages sent before this device joined -- is not a shape Room generates. That is the older claim on the number and it keeps it. The index migration here becomes `AutoMigration(from = 15, to = 16)` and the database goes to v16, so a device that has already run v15 gets the index on top of it rather than the two fighting over one version. `15.json` is resolved to mantra's wholesale -- an add/add conflict between two unrelated schemas is not something to merge line by line -- and 16.json is regenerated from the build. Checked rather than assumed: 16.json differs from 15.json in exactly one place, `index_ChatMessage_chatRoomId`, and no table's fields, createSql or other indices move. **mantra's new membership lines needed handling here**, and nothing would have told me: `98f766f` added `TYPE_MEMBER_INVITED`, `TYPE_MEMBER_INVITE_SENT` and `TYPE_MEMBER_INVITE_FAILED`, which the transcript renders as system notices. The chat list preview dispatches on the same question the transcript does -- is this somebody's words -- and a type missing from that check falls through to the chat bubble branch. A room whose newest line was an invite would have previewed as "Alice: Invited Bob to the group", which reads as Alice having said it. Exactly the failure `ChatMessage.MEMBERSHIP_TYPES`' own comment warns about, one screen over from where it was written. So `MEMBERSHIP_TYPES` joins the ritual and chronicle sets in `lastChatMessagePreviewText`. They are not in the AUTHORED sets -- their content is a whole sentence with the invitee's name already in it -- so they stand alone, which is what the transcript does with them too. One new test, over all three types rather than a representative one, since the set is the thing being relied on. Nothing else needed reconciling. mantra's pre-join fix filters at indexing time and deletes the rows outright, so the last-message subquery sees fewer rows and needs no `memberSince` clause of its own to stay in step with the transcript. 550 jvm tests and 319 android unit tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
81965ba2d3 |
perf: index chat messages by their room
The query in the previous commit reads the newest line of every room the user is in, once per room, and Room re-runs the whole thing every time a message lands anywhere. Without an index on `ChatMessage.chatRoomId` each of those lookups is a scan of every message on the device: work that grows with the entire history rather than with the room, on the hot path of every arriving message. A device with ten rooms and a few thousand messages does tens of thousands of row reads to redraw a list whose visible change is one line of text. Room has wanted this index since the foreign key was declared and has said so on every build -- `chatRoomId column references a foreign key but it is not part of an index. This may trigger full table scans whenever parent table is modified` -- which is the same warning it still emits for a dozen other `chatRoomId` columns. Those stay as they are; this one now has a reader that makes it matter. **Schema v15, and Room writes the migration itself.** Adding an index changes no columns and moves no rows, which is one of the shapes `AutoMigration` handles without a spec, so this is an entry in the list rather than another manual migration alongside MIGRATION_13_14. The generated 15.json differs from 14.json in exactly one place, checked rather than assumed: `index_ChatMessage_chatRoomId` appears on ChatMessage, and no table's fields, createSql or other indices move at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
49c012bf8b |
fix: a member is not shown the messages sent before they were in the room
A joiner gets the MLS key schedule from their own epoch forward and nothing before it. The relay does not know that and hands them the whole room: negentropy syncs down every kind:445 the group ever published, `indexMarmotGroupEvent` read each one against the group, the outer layer refused, and every refusal wrote an `undecryptableOuterLayer` line. So the room a member had just been invited to opened on a screenful of "Undecryptable Message" above the conversation -- one per message the group had sent before they arrived, none of them ever readable, and the count only grows with how long the group had been talking. **The epoch of a kind:445 is inside the layer that will not decrypt**, so an event this device cannot read cannot be asked what epoch it is from. "From before we joined", "from an epoch we have not caught up to" and "from an epoch that fell out of the retention window" are indistinguishable from the outside, and only the first is permanent. What separates it is not the ciphertext but the clock: it was published before the group made the epoch we joined at. **`ChatRoom.joinedGroupAt` is that moment, written down.** The Welcome's `created_at`, which the inviter stamps as it mints the Welcome out of the Add commit that made us a member -- so it is the group's own account of when our epoch began, not this device's account of when it heard about it. A group this device created sets it to the room's creation; it was a member from epoch 0 and there is nothing behind it to hold back. Stored rather than read off `createdAt`, which today holds the same value in both paths. `createdAt` is row bookkeeping and this decides which of a group's messages a member is allowed to see at all; the two being equal is a coincidence of the current code, and hanging the second off the first makes a future change to when a room row is written into a change in what gets discarded. `memberSince` is `joinedGroupAt ?: createdAt`, so a room joined before the column existed gets the fix too -- and gets it from the value every path that sets the column would have written anyway. **`predatesMembership` draws the line strictly before**, and that is a judgement rather than a fact. Nostr stamps `created_at` in whole seconds, so the second the Welcome was minted holds both the commit that added us -- the last act of the epoch before ours, unreadable by construction -- and any message another member sent the instant they applied it. Only one of the two can be had. An unreadable event kept costs one refused decrypt; a readable event discarded is a message the member never sees. So the second is kept, and a room may still show a single placeholder for the commit that added its newest member. **Two places gate on it.** `indexMarmotGroupEvent` returns before touching the MLS group, so nothing is decrypted, no `MarmotGroupEvent` row is filed for ciphertext whose key this device never had, and no line is written. `reindexMarmotGroupEvents` partitions them out of the sweep entirely: a replay can say in advance that no pass will ever read them, so replaying them only spends a refused decrypt per sweep and reports every one as a failure on a room where nothing is wrong. `MarmotReindexSweep` is untouched apart from carrying the new count -- it decides how many times to go round, not what is worth going round for. **Schema v15, and the migration is the half that fixes devices already showing the bug.** Nothing rewrites a chat line that is already in the transcript, so fixing the write path alone would leave every member who joined a busy room opening it on the same run of placeholders forever. `MIGRATION_14_15` adds the column and deletes the lines: only the two types in `UNRESOLVED_MARMOT_TYPES`, and only where the group event behind them predates the room. Those lines say nothing by design -- they stand in for an event that was never read -- so removing one loses nothing, while every other line is the final word on its group event. The group events themselves stay; this is about what the room shows. The column is left null rather than backfilled from `createdAt`. Null already means "ask `createdAt`", and copying the value would turn a fallback into a claim this migration is in no position to make. It is manual rather than an `AutoMigration` only because of the delete: `ALTER TABLE ... ADD COLUMN` appends, which is where Room's own generated migration for a nullable addition puts one, and Room compares a table's columns by name rather than by position. **The reindex report stopped being true**, so it carries the number now. With the backlog held back, `unresolved` falls to zero and the screen said "Nothing to reindex - 30 event(s) all read" about a room where 27 of them were never this device's to read. `MarmotReindexReport.predatingMembership` is reported alongside `stored`, and the detail screen names it: "3 event(s) all read - 27 from before you joined". A member invited into an old room is the ordinary case, not an anomaly to bury in a total. Seventeen tests. `ChatRoomMembershipWindowTest` holds the boundary, including the same-second case and both directions of the `createdAt` fallback. `JoinedGroupAtMigrationJvmTest` runs the migration's own SQL against v14's three tables and covers what it must not take as carefully as what it must: a placeholder for an event from *after* the join is left to be recovered, a message that was read is left alone however old it is, a line with no group event behind it is out of reach of the rule, and two rooms joined at different times are each measured against their own join. `MarmotPreJoinIndexingJvmTest` drives the DAO against a room with no MLS state, which is what separates "left alone because it predates the join" from "tried and failed". 520 jvm tests and 302 android unit tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
ea11e8b233 |
refactor: call it a chronicle, and keep "archive" for what a user does to a chat
Archiving a chat is an ordinary thing a user will want to do to a conversation, and it is not this. This is the group's signed record, handed to a member who joined after the work was done so their room stops being empty. Two unrelated meanings of one word in one app is a bug waiting to be written, and `ChatRoom.archiveRequestedAt` is exactly where they would have met: a column on the chat row, named for the thing that is not the chat. So the whole feature is Chronicle now -- `press.mantra.compose.nostr.chronicle`, `ChronicleEvent` (30327), `ChronicleRequestEvent` (30328), the three tags, `ChronicleManager`, `docs/member-chronicle.md`. The kind numbers do not move; only the words do. **The wire tags move too**, `archiveId` -> `chronicleId` and `archivePage` -> `chroniclePage`, which is free exactly once. Both kinds are new and there is no old build to stay compatible with -- the design note says so in as many words -- so the alternative was carrying the old spelling on the wire forever to save a rename that costs nothing today. The recipient tag stays `p`; it was never ours. **Schema v14, because two things had the old word written into stored data.** `ChatRoom.archiveRequestedAt` becomes `chronicleRequestedAt`, renamed rather than dropped and re-added: while it is set it is the only record that a device with an empty room has already asked the group for its history, and a device that lost it mid-flight would ask again on its next launch, and the one after that. The three `ChatMessage.messageType` strings become their `chronicle*` spellings, rewritten rather than left to a legacy constant the way `dkgApprovalNeeded` was. These lines cannot be regenerated -- a chronicle is announced once, when it is requested, sent and applied -- and an unrecognised type is not skipped by the transcript. It renders as an ordinary chat bubble, so "Caught up on 12 items" would come back attributed to a member as something they said. `MIGRATION_13_14` does both, because Room can rename a column and cannot rewrite rows in the same breath. `ALTER TABLE ... RENAME COLUMN` needs SQLite 3.25, which `getRoomDatabase` guarantees by pinning `BundledSQLiteDriver`, and the column is in no index, no foreign key, and there is not a view or trigger in the database -- so nothing has to move with it. Five tests hold the two halves apart: the value survives, the column keeps its position, a room that never asked still reads as never having asked, the three types are rewritten, and every other type is left alone. **`isArchivable` is `isChroniclable`**, on the "recyclable" pattern, and it keeps its job unchanged: the allowlist that stands between a replayed `GroupKeyStateEvent` and the apply path. No behaviour change beyond the rename. 797 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
8f9e4de82e |
feat: keep what the group signed, and the path it signed as
A quorum signing something is the most expensive thing this app does and, until now, the least recorded. `FrostSigningManager.complete` verified the signature, handed the event to `ChatMessage.applyInnerEvent`, and let it go. What survived was whatever the row it became happened to keep -- an artifact keeps its `signature` and `publicKey`, a translation contributor list keeps nothing at all because that arm is still a TODO, and a kind this build has no arm for keeps nothing anywhere. The signature is the group's statement; the rows are one reading of it. `GroupSignedEvent` is where the statement itself now lives, at schema v13 behind an `AutoMigration(12, 13)`. **The columns are `NostrEvent`'s, not a summary of one.** `id`, `publicKey`, `kind`, `tags`, `content`, `signature` and the event's own `created_at` as `createdAt`, so what is stored is an event rather than a description of one. That is what makes `verifies()` answerable from the row alone: it delegates to `GroupKeyStateEvent.isSignedByRoom`, which asks whether the author is the room, whether the id is the hash of the fields sitting next to it, and whether the signature checks out. No ceremony, no key state and no path have to be on hand first -- which is exactly the position a member added after the ceremony is in. **The derivation path is the point of the exercise.** `publicKey` is the group's threshold key walked to `derivationPath`, and for a room that walk is also the room id -- see docs/shared-key-derivation.md, where those are one value. Without the path there is no way back from a signature to the ceremony behind it: a threshold key alone does not say which of a group's rooms signed, and a room id alone cannot be walked backwards. `GroupKeyState` records the path for the room; this records it for the event, so an event stays checkable after the room's state is gone or was never known. Null means the untweaked threshold key, the same meaning it carries on `FrostSigningSession.derivationPath`, which is where the signing path is copied from -- resolved from the room by `signingPath`, never from a proposer. **Two writers, and both file only what they have already checked.** `FrostSigningManager.recordSignedEvents` files a whole batch in one write, after every item's signature has verified and before any of them is applied -- a session's events are one decision by one quorum, so half a batch on file is a state no reader should have to reason about. `ArchiveManager.applyPage` files each payload it accepts, after the allowlist and `GroupKeyStateEvent.isSignedByRoom`, reading the room's path once per page from `GroupKeyState` rather than once per payload. Neither failure is the caller's: recording throws are logged and swallowed, because a ceremony that succeeded must not be reported as failed over a row this device could not write down. **The archive half is what makes a recipient more than a dead end.** A member handed their history used to end up holding the rows and none of the events -- able to read the group's work, unable to prove any of it, and unable to build a page for the next member to arrive. Now the events land too. **`record` merges rather than overwrites, and that direction is deliberate.** The same event reaches a device twice by design: once when the session that made it completes, once from any archive page carrying it. The second arrival is the poorer one -- an archive knows no session, and on a member who joined after the ceremony no derivation path either -- so the incoming row fills gaps and never empties them. The event's own fields are not merged because they cannot disagree: the id is the hash of them, so two rows under one id either hold the same event or one of them is not the event it claims to be. **Every `Mantra*` row points back at it.** `groupSignedEventId` on all twelve entities that carry `marmotGroupEventId`, stamped by `ChatMessage.applyInnerEvent` through a new defaulted parameter. On a group-signed row it is the only provenance there is: both Marmot ids are null, because there is no group event and no inner event behind one -- a signed event authored by the threshold key cannot travel as an inner event at all, since the outbound pipeline re-authors rumors as their sender and would strip the signature off. The column is only set when the record actually landed, so a row never points at an event that is not there. **`ArchiveManager`'s own doc said something that is no longer true.** It opened with "signed events are not stored as events", stated as present-tense fact and load-bearing for the paragraph under it. Corrected there and noted at the head of the same section in docs/member-archive.md, which is a phase history and so gets a note rather than a rewrite. Assembly still rebuilds payloads from rows via `toXEvent()` and the round-trip gate still holds it up: a room whose work predates v13 has no events on file, and rebuilding is the only way to reach it. Reading assembled events from the table is worth doing once that fallback can be dropped. **Two things this deliberately does not touch.** `ChatMessage` gets no such column -- it is not a `Mantra*` row and already carries `frostSigningSessionId` for the lines that need to name a session. `MantraTranslationChunkProposal` has a `marmotGroupEventId` but is not a `@Database` entity and nothing in `composeApp/src` references it, so it was left as the dead code it is rather than grown a column. Rows are not backfilled by the migration. The events they came from are gone, and minting an id for one would point a row at a signature nobody can produce; null reads as "this device does not hold the event behind this row", which is true of every row written before today. 490 jvm tests and 297 android unit tests pass. `GroupSignedEventDaoJvmTest` is eight cases against a real 2-of-3 quorum rather than a stub signature, because a fake one would satisfy every column assertion and prove nothing -- it covers the round trip, the path walking back to the row's own author, the merge in both directions, batch ordering, and a row edited after the fact no longer verifying. `SignedGroupKeyStateTest` adds the end-to-end claim over two devices: a batch of three signed in one session lands as three events on both, each at `m/9420/0/0` that neither device was told and both derived from the room they stand in. `ArchiveApplyJvmTest` asserts the receiver ends up holding the events and not only the rows, and that the four forgeries in its adversarial page become no signed-event rows either -- a forgery filed there is one the recipient goes on to hand to everybody else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
873203e4b4 |
feat: let a member with none of the group's work ask for it
Phase 5 of docs/member-archive.md, and the half that makes the whole thing reliable. A device opening a room it holds no signed work for asks the group; any member holding the work answers, addressed to whoever asked. **A request cannot lose the race a push loses.** Pushing an archive at an invitee is an application message in the epoch the add created, and one that overtakes the Welcome is dropped rather than deferred -- silently, while the inviter sees a success. That is marmot-membership.md's failure mode arriving in a new costume. Sending a request cannot lose it, because being able to send one is the proof it was won: a device that can put an application message into the room has processed its Welcome and is at the group's epoch. It also covers three things no invite-time push reaches, and they are answered by one rule because they are indistinguishable from inside the database: a member added after the work, a reinstall whose invite is long past, and a second device that was never invited at all. Hence the crude condition -- no dialects and no artifacts -- rather than anything that tries to tell them apart. **Anyone may answer and nobody is elected to.** A duplicate answer costs bandwidth and nothing else: pages are idempotent and every member who is not the named recipient ignores them. So the stand-down that would avoid the waste is an optimisation to add later rather than a correctness gap to close now. A member with nothing signed answers nothing at all, which is the honest reply from one still catching up themselves, and beats an empty archive that looks like an answer. **Queued with no chat line**, the way a signing message travels. Broadcast does not depend on one -- `encryptAndSendMarmotInnerEvent` inserts its `BroadcastNostrEventRequest` unconditionally, which is what let the FROST rounds travel with no transcript -- and an archive that filed a line per page would put a row of envelopes in the room's history. One line per archive is the right number and it is not writable from here, since the pages are indistinguishable from each other at this point. **Schema 11 -> 12**: `ChatRoom.archiveRequestedAt`, nullable, so Room generates the migration. It stops a device asking again on every launch while an answer is in flight. Rooms written before it read back null, meaning "never asked", which is true of all of them and harmless. Cleared as soon as an archive applies anything -- not when a sender's page count claims the archive was complete. A page count is the sender's word about the transfer rather than about the group's record, so a member who left work out must not get the last word on whether to ask again. A partial answer is followed by another request rather than by silence. The trigger is opening the room, through `ChatRepository` rather than from the view model into the database. Cheap to call every time: it stops at a room that already holds work and at one still waiting. A failure is not reported, because nothing acknowledges a request and the next open asks again. Eight tests: a device with nothing asks and does not ask twice, a device with work does not ask, answering queues pages addressed to the asker with every archivable kind in them and no chat line, a member with nothing signed answers nothing, a member does not answer themselves, an applied archive clears the stamp so a partial answer can be followed up, and the whole round trip -- ask, answer, apply -- leaves the joiner holding the sender's rows. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
4de87edf12 |
fix: tell one proposal's transcript lines from another's
A room with two proposals open showed "Review" on both, and then dropped it from both the moment either one was decided. The second proposal was still waiting on the reader, still had a decision in it, and had nowhere left to be reached from. Two proposals at once is not a corner case any more: a chapter and the translation scaffolding beside it are proposed as separate sessions, on purpose, and they run at the same time. Both write the same line types into the same stretch of transcript. `answeredRequests` matched a request against any later line of the fulfilling type, and `settledRequests` against any later ending. That reads a room signing one thing at a time exactly right -- the nonce after the request is the answer to it, because there is nothing else it could be an answer to -- and a room signing two things at once exactly wrong. Nothing else on the row could separate them: same type, same room, same minute, and `ChatMessage` carried no session. So the session goes on the row. `ChatMessage.frostSigningSessionId` is nullable, added as schema v11 through `AutoMigration(10, 11)`, and stamped by `FrostSigningManager.announce` -- the one place every FROST line is written, so there is no line that can be forgotten. Both rules read it when both rows have one and fall back to the clock when either does not. The fallback is not a compromise, it is the right reading of the rows it applies to. A line written before this column has no session and never will, and the rooms that wrote those lines could not run two sessions at once, so the clock is the whole truth there. A ceremony line falls back too and always will: a room runs one ritual at a time, and a DKG step is either taken or still waited on. **This reverses a call `FrostSigningRoute` argued for.** Its note said a chat row carrying a session id was "a poor trade for a lookup the screen can do". That was right when the lookup could only be wrong about which of one session it meant. The batch work made two sessions ordinary, and the lookup and the rules both became guesses at the same moment. A column on the table every message uses is the cost; two proposals, one of them unreachable, was the alternative. **Tests.** Three in TranscriptRequestStateTest for what the column buys: a nonce answers its own session's request and not the other's, one session completing settles nothing in the other, and a line naming no session is still read by the clock. TranslationBatchProposalJvmTest proves the other half against a real two-session proposal -- every FROST line the manager writes names its own session, and neither session's lines are attributed to the other. The rule is tested on rows and the stamping is tested on a database, because a rule that is right about rows nothing writes correctly is worth nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
dff41d417d |
feat(frost): move a signing session's per-event columns onto FrostSigningItem
Phase 1 of docs/frost-batch-signing.md, which is added here as the plan the next phases follow. Schema only: a session still signs exactly one event, the wire is byte-identical, and every existing test passes on the moved columns. ## What moved, and why it had to A batch of k events is k independent FROST instances sharing a signer set, not one signature over k messages. That is forced rather than chosen: a Schnorr partial signature is `s = k + e·x` with `e = H(R‖P‖m)`, so two messages under one nonce R give two equations in one unknown and the secret share falls out. So the five columns that enter that equation -- unsignedEventJson, eventId, nonceRandom, aggregatedNonce, signature -- move to a child table keyed (sessionId, itemIndex). What stays on FrostSigningSession is everything outside it: the ceremony, the threshold, the derivation path, the signer set, and the one approval. itemIndex is protocol rather than presentation -- nonces and partial signatures are joined positionally against it -- so getItems() orders by it and nothing re-sorts. Spelled itemIndex rather than index to keep hand-written queries free of backticks. No itemCount column. The count is a COUNT(*), for the same reason signerIds is derived from the ceremony's participant order rather than stored: a denormalised count is one more thing that can disagree with the rows. ## Migration 9 -> 10 Manual, not auto: Room can create the table and drop the columns but cannot copy between them, and the copy is the whole point. A session in flight at upgrade holds its nonce seed and the aggregate it is already signing against, and neither can be regenerated -- losing either makes the next pass derive a different nonce for the same message and publish a second partial signature over it, which is the extraction case. Both are copied verbatim into item 0, so an in-flight session resumes as though nothing happened. Removing the columns uses ALTER TABLE DROP COLUMN rather than the usual create-copy-drop-rename rebuild. FrostSignerMessage and FrostSigningItem both reference FrostSigningSession(id) ON DELETE CASCADE, and DROP TABLE fires cascades -- with foreign keys enforced the rebuild would delete every signer message and every item just written. Whether it does depends on Room disabling foreign keys around migrations, which is not worth depending on when DROP COLUMN cannot go wrong. It needs SQLite 3.35 and unindexed, unconstrained columns; these five qualify, and getRoomDatabase pins BundledSQLiteDriver on every platform. ## Invariants established here for the phases that follow - signerIds and every item's aggregatedNonce are one write-once unit, applied by applyAggregate() -- items first in one transaction, then the session, so "some items aggregated" is unreachable and signerIds != null stays the gate. - Signatures likewise, via applySignatures(); isSigned() counts rows instead of reading a flag. - complete() verifies every signature before applying any event, so a batch is all-or-nothing rather than half-filed. - itemsOver() gives each item its own 32 bytes of seed. Independent seeds mean an off-by-one in index handling produces a session that fails to aggregate rather than one that signs two messages under a single nonce. signedEvent() and isAwaitingApproval() now take the item(s) rather than the session, which propagates to the repository, the view model and the screen. advance() reads items.first() and Phase 2 turns that into a loop. ## Tests - FrostSigningSessionDaoJvmTest: index ordering, single-item read, upsert replacing rather than accumulating, signed-item counting, cascade delete. - FrostSigningItemMigrationJvmTest (new): the backfill against a real v9 database, asserting the seed and aggregate values survive -- not merely that a row appeared -- plus the exact column lists Room will check at open time. - 338 jvmTest and 217 testDebugUnitTest pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
a8f6638325 |
feat: sign a room's key state into being, at the room's own key
Two changes that turned out to be one. A room's key state stops being something its creator announces and becomes something the group signs, and every FROST signature moves from the group's root threshold key to the key derived at the room's own path -- which is the room's id. The second is what makes the first worth having: a key state is now signed by the very key it names. Supersedes the announcement introduced in |
||
|
|
bcdfd2ec94 |
Merge branch 'mantra' into claude/marmot-direct-message-type-7a0473
Twenty-two commits had landed on mantra since this branch left it, several of them in the same files. Merged this way round so mantra stayed untouched until the result compiled and its tests passed. The migration had to be renumbered, and this is the conflict that mattered. mantra is at database version 7 and already has its own 5.json -- for MarmotInnerEvent.payloadEventId, nothing to do with direct messages. This branch had also written a 5.json, for a different schema. Resolved by restoring mantra's 5.json untouched and moving the direct message columns to an AutoMigration(7, 8) with a regenerated 8.json. Taking either 5.json over the other would have left every device validating a migration chain against a schema it was never built from; keeping version = 5 would have made a v7 install refuse to open at all. The regenerated 8.json is two ADD COLUMNs and nothing else, same as before. fromGroupEventResult was restructured on mantra: the kind switch moved into applyInnerEvent, and a SubmissionEvent envelope now wraps nip30303 payloads. Took that structure and re-applied the direct message branch ahead of it rather than inside it -- a gift wrap is not a nip30303 payload to apply, and what happens to it depends only on whether this device's key opens it, so it does not belong in a function about applying submissions. The isUserMessage fix was re-applied to the eight call sites mantra's version has, up from the six it had here. ChatMessageListViewModel and ChatRoomMessagingScreen took mantra's versions with the composer state, the two renderings and the reply action layered back on. docs/README.md keeps both new rows and mantra's closing note about the skipped-keys document. 108 tests pass, up from 50 here and 83 on mantra. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
a909108300 |
feat: announce which key a room signs with, instead of rederiving it
A signer holds a different secret share under every ceremony it took part in, and signing with the wrong one produces a partial signature that cannot aggregate. Nothing said which was which: FrostSigningManager found a room's key by walking every ceremony this device holds a share for and rederiving each one's room id until one matched. That search can only find rooms derived at the one path the constant names. SharedKeyDerivation.parsePath was written to lift that limit and was never called, so a room derived anywhere else was invisible to signing. So the coordinator now says it. GroupKeyStateEvent (kind 30326) carries the threshold public key, the ceremony that made it and the path the room's id came from, posted into the room as its first application message and filed as a GroupKeyState row. completedKey reads that row first and follows it to the share. Nothing secret travels. Every member of the room can read the event, so a share on it would be each member holding everyone else's -- a 1-of-n key wearing a t-of-n's clothes. The event names the ceremony; the share stays in DkgSession.secretShare on the device that generated it. The coordinator is untrusted, as everywhere else in the ceremony, so a state is verified rather than believed: the room's id *is* the threshold key derived at the path, and one that does not rederive its own room is dropped. That is the same guarantee the rederivation gave, kept rather than traded for a lookup. The old scan stays behind it for rooms that predate the table. Announced after the members are added, which is the only order that works -- adding them commits a new epoch and MLS will not let a member read what was encrypted before the one they joined at. A member invited later still misses it and falls back to the scan, which is where every member was before this existed. Replacement is this app's job. These are rumors inside a Marmot group event, so no relay applies the 3xxxx rule, and the DAO keeps the newest announcement per room so a backfill cannot walk a room backwards. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
b4ac65f5c9 |
feat: sign a nostr event with the group's shared key
A ceremony leaves every member holding a share of a t-of-n key and no way
to use it. This is the other half: a session that turns an unsigned nostr
event into one signed by the group.
The shape is ChillDkgRitualManager's, deliberately. The member who
proposes coordinates, protocol messages travel as gift-wrapped rumors on
the same NIP-17 pipeline chat messages use, each inbound message is
persisted and then the session is asked whether it can move, and every
step is recomputed from stored inputs so a device killed mid-round
resumes on the next message. Anyone who has read that manager can read
this one.
proposer --[ 30320 proposal ]-> everyone the unsigned event
signer --[ 30321 nonce ]-> everyone this device's public nonce
proposer --[ 30322 signer set ]-> everyone who signs, and their aggregated nonce
signer --[ 30323 partial ]-> everyone this device's partial signature
proposer --[ 30324 signature ]-> everyone the finished 64-byte signature
anyone --[ 30325 failure ]-> everyone abandon + blame
Three things are genuinely different, and each is why this is a separate
manager rather than another branch of that one.
**It does not need everybody.** A DKG cannot finish until every member
takes part; that is what makes the key. Signing needs t, and waiting for
n would throw away the property the group ran a ceremony to get. So the
coordinator waits for the threshold to be reachable, picks a set and says
who is in it. Members left out do nothing and stall nothing.
**Restart-safety is forced rather than chosen.** SecretNonce cannot be
serialised and refuses to be used twice, so storing the randomness it
derives from and regenerating on demand is the only way a session
survives the app closing. That is safe for exactly one reason: a session
signs one message and cannot be made to sign another. Two rules hold it
in place and both are load-bearing rather than tidy:
- the event id is written at creation, and a proposal that disagrees
with it is refused rather than applied;
- the aggregated nonce and signer set are write-once. A coordinator
that sends a second, different set is ignored. Obeying it would mean
two partial signatures over one secret nonce against two challenges,
which is precisely how a secret share is extracted. The session
stalls; the share does not.
**One approval, not three.** A DKG asks three times because each step
publishes something different and commits the member to something
different. Here every step serves one decision -- sign this event or do
not -- and the event is fixed before the member is asked, so a second
prompt would be the same question twice. Declining is broadcast rather
than silent: a t-of-n group can sign without you, but only if it knows.
Two things are checked rather than trusted, both because the coordinator
is untrusted by construction: the event id is recomputed from the
proposal's own fields, so a proposer cannot have the group sign one thing
while showing them another; and the finished signature is verified before
the session is called complete, so a bad aggregate is a failure here
rather than a rejection at every relay it reaches.
Signer ids are derived, not stored: a member's FROST id is their index in
the bytewise sort of the ceremony's host keys, the same ordering ChillDKG
hashed into the session identity and the same one the public shares are
in. Deriving means signing cannot disagree with the ceremony that made
the key.
DkgSession gains publicShares, kept because FROST validates each signer's
secret share against its public one. A ceremony finished before this
column reads back null and signing runs without that check rather than
refusing.
The tests run the same calls in the same order against real FROST and
assert the aggregate verifies as a nostr signature. That path was written
from reading the library rather than from a working example, so it is the
part most likely to be subtly wrong -- and wired up wrong it fails
silently, on every device.
Kinds start at 30320 with a gap. The DKG runs 30310-30316 and the
nip30303 document kinds run 30300 up; those two already collide at 30310
and 30311, and SubmissionEvent sits on 30312, which is also the DKG's
round-1 kind. They are kept apart today only by riding different
transports, which is luck. Signing shares a transport and rooms with the
DKG, so it starts clear of both.
No UI yet: this is the session logic, reachable through proposeSigning,
approve and decline.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
||
|
|
fcc28de931 |
Revert "fix: hold a payload whose parent has not arrived instead of losing the event"
This reverts commit
|
||
|
|
d7aac49cf1 |
fix: hold a payload whose parent has not arrived instead of losing the event
A receiver hit `FOREIGN KEY constraint failed` on an artifact submission and lost the whole group event. The artifact referenced a dialect the receiver did not have, MantraArtifact.dialectId is a foreign key, and SQLite answers a violated constraint by aborting -- which rolled back the entire transaction the inbound pipeline runs in. Gone with it: the NostrEvent, the MarmotGroupEvent, the submission's MarmotInnerEvent holding the payload verbatim, and the transcript line. Nothing retries, so the artifact stayed lost even once the dialect turned up. Every nip30303 entity is a child of another and the schema enforces all of it -- artifact→dialect, version→artifact, chapter→version, chunk→chapter, translations→both of theirs -- so this was every branch, not one. And submissions make arriving before your parent ordinary rather than exotic. That is the point of them: an admin submits a backlog in whatever order they hold it, and a member who joined last week can be sent what the group was told last month. Both produce payloads whose parents are not here yet, and both were losing data. So check the parents before inserting. A payload that arrives early is held on the submission row -- awaitingEventId names what it waits for -- and applied when that arrives. Releasing one can release another, a version freeing its chapters and those freeing their chunks, so it walks outward until nothing more comes unstuck. A payload with a second parent still missing is re-pointed at that one rather than retried on every arrival. Nothing is written to the transcript while a payload is held. Nobody has said anything yet; the line appears when it is applied, in the position its own timestamp gives it. Two things fall out of the shape: parentRefsOf is pure and separate from the lookups, because the mapping is the part that can silently drift from the schema and there is no database harness in commonTest to catch it. ParentRefsTest pins one case per kind. Which table an id lives in is carried as the kind of event that would have created it, so there is no second enum to keep in step. applyInnerEvent takes ids rather than a GroupEvent, since replay happens long after that object is gone. A released payload is recorded as not ours: we hold the parents of anything we wrote, having written those too. Also reconstructs a held bare nip30303 event from its own columns rather than parsing its content as an event -- only submissions carry an event there, and reading both that way would have stranded every bare one permanently. Verified: the v5→v6 migration runs clean on the receiver's real populated database. The hold path itself still needs a fresh submission from a sender to exercise end to end. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |