feat: decline a profile or a post nothing could show, out loud (group-nostr-profile, Phase 4)

A kind:0 whose content is not a profile, or a kind:1 with nothing in it,
would be signed and filed and shown nowhere: every reader refuses them.
Giza signs only what it can check, so GroupStatementRefusal declines them
on arrival beside WalletRefusal, in the approve backstop, and with a
reason of its own on the wire, so the group counts the refusal. An empty
profile is still a profile, and is put to the member. (D5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-21 20:30:55 +02:00
1 parent 5b75c2c24d
commit 09649d9a91
3 files changed
+334

No files matched your search

@@ -658,6 +658,21 @@ object FrostSigningManager {
return declined
}
// A profile or a post that nothing would show once signed: a kind:0 that is
// not a profile, a kind:1 with nothing in it. Declined on arrival for the
// wallet's reason -- Giza signs only what it can check -- and filed the same
// way, so the decline goes out through [advance].
// docs/group-nostr-profile-and-posts.md, D5.
GroupStatementRefusal.of(unsignedEvents)?.let { why ->
logger.w("Signing proposal $sessionId $why; declining")
val declined = newSession(sessionId, localChatRoom, innerEvent, userPublicKey, key, signerId, path, generation ?: 0, participantCount = n)
.copy(signDeclinedAt = Clock.System.now())
database.frostSigningSessionDao().upsert(declined)
database.frostSigningSessionDao().upsertItems(itemsOver(sessionId, unsignedEvents))
announceStarted(database, declined)
return declined
}
// A change to a governed room whose commit does not say what its statement
// says -- or that the group's door would refuse anyway -- is declined before
// anybody is asked, for the wallet's reason: a device that signs what it
@@ -1008,6 +1023,15 @@ object FrostSigningManager {
session.subject != FrostSigningSubject.EVENTS ||
items.any { item -> Event.fromJsonOrNull(item.unsignedEventJson)?.let(WalletRefusal::of) != null }
/**
* Events [GroupStatementRefusal] says nothing would show once signed: a profile
* no reader could parse, a post with nothing in it.
* docs/group-nostr-profile-and-posts.md, D5.
*/
private fun isUnshowableSession(session: FrostSigningSession, items: List<FrostSigningItem>): Boolean =
session.subject == FrostSigningSubject.EVENTS &&
items.any { item -> Event.fromJsonOrNull(item.unsignedEventJson)?.let(GroupStatementRefusal::of) != null }
private fun isFromCoordinator(
session: FrostSigningSession,
innerEvent: Event
@@ -2126,6 +2150,15 @@ object FrostSigningManager {
return
}
// The same backstop for a profile or a post nothing would show, for a
// session an older build filed before it declined those on arrival.
if (isUnshowableSession(session, items)) {
logger.w("Session $sessionId signs a profile or a post nothing could show; declining")
update(database, session) { it.copy(signDeclinedAt = Clock.System.now()) }
advance(database, localChatRoom, sessionId)
return
}
update(database, session) { it.copy(signApprovedAt = Clock.System.now()) }
logger.i("Session $sessionId: signing approved")
@@ -2606,6 +2639,7 @@ object FrostSigningManager {
val items = database.frostSigningSessionDao().getItems(session.id)
val reason = when {
isWalletSession(session, items) -> WalletRefusal.REASON
isUnshowableSession(session, items) -> GroupStatementRefusal.REASON
!holdsShareFor(database, session) -> GENERATION_REFUSAL
else -> "Declined to sign"
}
@@ -0,0 +1,59 @@
package mobi.giza.compose.managers
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
/**
* A profile or a post the group is asked to sign that nothing would show once it had
* (docs/group-nostr-profile-and-posts.md, D5).
*
* The group's profile is read through `GroupNostrProfile.of` and its posts through
* `GroupPost.newestFirstAmong`, and both refuse rather than repair: a kind:0 whose
* content is not a profile, and a kind:1 with nothing in it, would each be signed,
* filed and shown nowhere, with nothing to tell the group its quorum was spent on
* nothing. Curare's editors never produce one -- they check before they propose -- but
* a proposal can come from any build, and Giza signs only what it can check. So it
* declines these the way it declines a wallet's: out loud, so the group counts it.
*
* The predicates are the ones the paste screen refuses on too
* (`GroupEventProposal.read`), so the member proposing and the member signing draw the
* same line.
*/
object GroupStatementRefusal {
/** What a decline says, on the wire and in this device's transcript. */
const val REASON = "Giza doesn't sign a profile or a post that nothing could show"
/**
* Whether [content] under [tags] is not a profile at all.
*
* An empty kind:0 is a profile -- the group wiping its own, which it is entitled to
* do -- and quartz reads it as the blank one it is. Only content that will not
* parse is refused, which is the same line `GroupNostrProfile.of` draws.
*/
fun isUnreadableProfile(tags: Array<Array<String>>, content: String): Boolean = MetadataEvent(
id = "",
pubKey = "",
createdAt = 0,
tags = tags,
content = content,
sig = "",
).contactMetaData() == null
/**
* Whether a kind:1 has nothing to say. A blank post cannot be told from a broken
* one, and a kind:1 is not replaceable, so it could not be taken back either.
*/
fun isBlankPost(content: String): Boolean = content.isBlank()
/** Why [event] would be shown nowhere once signed, or null when it would be. */
fun of(event: Event): String? = when (event.kind) {
MetadataEvent.KIND -> "is a profile no reader could parse".takeIf {
isUnreadableProfile(event.tags, event.content)
}
TextNoteEvent.KIND -> "is a post with nothing in it".takeIf { isBlankPost(event.content) }
else -> null
}
fun of(events: List<Event>): String? = events.firstNotNullOfOrNull(::of)
}