feat: taking part is a rotation's only approval (rotate-shares-single-approval, Phase 2)

ShareRefreshManager.advance no longer stops before round 2 for its owner.
The gate's two reasons never needed a person: participantStep2 is the
check that stops a substituted table, and it fails the rotation out loud
before any prompt could appear; ShareRefreshConfirmation is the one
confirmation per generation, claimed with the pending share in one
transaction. pendingApproval now only answers DEAL.

No migration: confirmApprovedAt and ShareRefreshApprovalStep.CONFIRM stay
so rows written before still decode, documented as read by nothing.

Tests: the pinned gate flips (taking part alone completes the rotation,
asked once); the last to take part deals and confirms with nothing more
asked; a tampered sum fails the rotation on every device with nobody
asked; two rotations opened at once never split the group.
ShareRefreshRitualJvmTest 23/23.

Must ship with Phase 3: a rotation paused at the old second approval has
nothing left to arrive and needs the sweep to move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-20 00:53:49 +02:00
1 parent 18f426ca46
commit b4103bcb40
4 files changed
+133 -41

No files matched your search

@@ -74,7 +74,14 @@ data class ShareRefreshSession(
/** Secret-adjacent. Round 2's auxiliary randomness for the confirmation's signature. */
val auxRandom: HexKey,
/** When this device's owner agreed to take part: the refresh's one approval. */
val dealApprovedAt: Instant? = null,
/**
* Written by builds before docs/rotate-shares-single-approval.md, when storing
* the new share was its own approval. Read by nothing; kept rather than
* migrated away.
*/
val confirmApprovedAt: Instant? = null,
/** The furthest step this device has asked its owner about, so the request line is written once. */
@@ -1,21 +1,30 @@
package mobi.giza.compose.database.model.types
/**
* The two decisions a recipient makes in a share refresh. Each publishes
* something different and commits the member to something different.
* Everything a share refresh has ever asked a recipient. One step is still
* asked; the other is kept so rows that stored it by name still decode
* (`ShareRefreshSession.approvalRequestedThrough`).
*/
enum class ShareRefreshApprovalStep {
/**
* Deal round 1: join the refresh, and agree to the withheld list. Withholding
* Take part: deal round 1, and agree to the withheld list. Withholding
* someone takes their signing away, so every recipient decides it, not only
* the proposer.
* the proposer. **The only approval a refresh asks for**: the device does
* everything after it on its own (docs/rotate-shares-single-approval.md).
*/
DEAL,
/**
* Confirm round 2: store the new generation and say so. This is what stops a
* coordinator substituting a table the recipients never dealt, and the one
* confirmation per base generation this device will ever give.
* Was: confirm round 2, storing the new generation and saying so. **No
* longer asked**, and nothing produces it.
*
* Its two reasons never needed a person. Stopping a coordinator substituting
* a table nobody dealt is `FrostRefresh.participantStep2`'s check, which runs
* before any prompt could appear and fails the refresh out loud. The one
* confirmation per base generation is `ShareRefreshConfirmation`, claimed in
* the same transaction as the pending share. Neither depended on the tap.
* Don't put the gate back: a person shown "store your new share" has nothing
* to check that the device has not already checked.
*/
CONFIRM,
}
@@ -60,8 +60,12 @@ import mobi.giza.compose.nostr.frost.ShareRefreshEvents
* - **Every recipient takes part** (D2). A certificate needs them all; anyone
* who cannot is withheld, and repaired later.
*
* Nothing of this device's own goes out without its owner's approval, at two
* gates ([ShareRefreshApprovalStep]). [pendingApproval] mirrors them.
* Nothing of this device's own goes out until its owner agrees to take part,
* with the withheld list the proposal names ([ShareRefreshApprovalStep.DEAL]).
* That is the only gate, and [pendingApproval] mirrors it. Everything after it
* -- dealing, checking the combined result, storing the new share, confirming --
* the device does itself: the check is the device's, and a person tapping
* "store" added nothing to it (docs/rotate-shares-single-approval.md).
*/
object ShareRefreshManager {
private val logger = Logger.withTag("ShareRefreshManager")
@@ -388,6 +392,8 @@ object ShareRefreshManager {
val hostSecretKey = ChillDkgRitualManager.deriveHostSecretKey(nostrPrivateKey)
if (isRecipient) {
// The one gate: taking part, with these members withheld. Every
// step after it follows from that decision and asks nothing more.
if (session.dealApprovedAt == null) {
announceApprovalNeeded(database, session, ShareRefreshApprovalStep.DEAL)
return
@@ -412,10 +418,10 @@ object ShareRefreshManager {
session = moveTo(database, session, ShareRefreshStage.COLLECTING_ROUND_2)
if (isRecipient && ownMessage(database, session, ShareRefreshEvents.ROUND_2) == null) {
if (session.confirmApprovedAt == null) {
announceApprovalNeeded(database, session, ShareRefreshApprovalStep.CONFIRM)
return
}
// No gate here. participantStep2 is the check that stops a
// coordinator substituting a table nobody dealt, and it runs
// whoever is looking; confirmAndStore is the one-confirmation
// rule, and it holds whoever is looking.
val secretShare = base.secretShare ?: throw IllegalStateException("this device holds no share of generation ${base.generation}")
val step2 = FrostRefresh.participantStep2(hostSecretKey, secretShare, params, myId.toUInt(), ByteVector(cmsg1.hexToByteArray()), ByteVector32(session.auxRandom))
step2.fault.raiseIfFaulty("round 2", base)
@@ -583,8 +589,11 @@ object ShareRefreshManager {
/**
* What this device's owner is being asked for, or null. **Must mirror the
* gates in [advance] exactly**: drift makes the screen offer an approval that
* gate in [advance] exactly**: drift makes the screen offer an approval that
* does nothing, or none while the refresh sits still.
*
* Only ever [ShareRefreshApprovalStep.DEAL]. [ShareRefreshApprovalStep.CONFIRM]
* was a second gate until docs/rotate-shares-single-approval.md.
*/
suspend fun pendingApproval(database: GizaDatabase, session: ShareRefreshSession): ShareRefreshApprovalStep? {
if (session.stage == ShareRefreshStage.COMPLETE || session.stage == ShareRefreshStage.FAILED) return null
@@ -592,11 +601,7 @@ object ShareRefreshManager {
val base = ShareGenerations.at(database, key, session.baseGeneration) ?: return null
val myId = base.roster.firstOrNull { it.memberPublicKey == session.userPublicKey }?.participantId ?: return null
if (myId !in session.recipientIdList()) return null
if (session.dealApprovedAt == null) return ShareRefreshApprovalStep.DEAL
if (session.coordinatorRound1 != null && session.confirmApprovedAt == null &&
ownMessage(database, session, ShareRefreshEvents.ROUND_2) == null
) return ShareRefreshApprovalStep.CONFIRM
return null
return if (session.dealApprovedAt == null) ShareRefreshApprovalStep.DEAL else null
}
/** Approves the step this device's owner is being asked for, and moves on. */
@@ -605,8 +610,8 @@ object ShareRefreshManager {
val now = Clock.System.now()
when (pendingApproval(database, session)) {
ShareRefreshApprovalStep.DEAL -> update(database, session) { it.copy(dealApprovedAt = now) }
ShareRefreshApprovalStep.CONFIRM -> update(database, session) { it.copy(confirmApprovedAt = now) }
null -> return
// Never pending any more; kept so the `when` stays over the whole enum.
ShareRefreshApprovalStep.CONFIRM, null -> return
}
advance(database, localChatRoom, sessionId, nostrPrivateKey)
}
@@ -707,6 +712,7 @@ object ShareRefreshManager {
update(database, session) { it.copy(approvalRequestedThrough = step) }
val line = when (step) {
ShareRefreshApprovalStep.DEAL -> "Your approval is needed to take part in rotating the group's shares."
// Unreachable: CONFIRM is no longer asked. Kept because the enum keeps the value.
ShareRefreshApprovalStep.CONFIRM -> "Your approval is needed to store your new share."
}
announce(database, session, ChatMessage.TYPE_SHARE_REFRESH_APPROVAL_NEEDED, line, session.userPublicKey)