Merge branch 'claude/dm-envelope-30330' into bennu
A direct message's envelope is opened, not taken for a signing decline: both are kind 30330, and recognising protocol kinds first had dropped every direct message in a current-profile room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b400280486
3 files changed
+66
-14
No files matched your search
+10
-2
@@ -888,8 +888,16 @@ data class ChatMessage(
|
||||
// before its proposal; acted on by the managers
|
||||
// `NostrDao.fileGroupEventResult` dispatches to, which write
|
||||
// their own transcript lines.
|
||||
val isProtocolMessage = event.kind in DkgRitualEvents.ALL ||
|
||||
event.kind in FrostSigningEvents.ALL
|
||||
//
|
||||
// Except a direct message's envelope. It shares 30330 with a
|
||||
// signing session's decline, and is told apart by what it
|
||||
// carries: an envelope holds a gift wrap, a decline does not.
|
||||
// Treating every 30330 as a decline dropped every direct
|
||||
// message in a current-profile room.
|
||||
val isDirectMessageEnvelope = MarmotDirectMessage.wrapInside(event) != null
|
||||
val isProtocolMessage = !isDirectMessageEnvelope && (
|
||||
event.kind in DkgRitualEvents.ALL || event.kind in FrostSigningEvents.ALL
|
||||
)
|
||||
|
||||
database.marmotInnerEventDao().upsert(
|
||||
MarmotInnerEvent(
|
||||
|
||||
+48
-12
@@ -8,6 +8,11 @@ import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlin.test.assertNotNull
|
||||
import com.machankura.bennu.compose.nostr.MarmotDirectMessage
|
||||
import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
|
||||
import kotlin.test.AfterTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -36,13 +41,27 @@ class ProtocolKindDispatchJvmTest {
|
||||
fun closeDb() = database.close()
|
||||
|
||||
private val self = KeyPair()
|
||||
private val sender = KeyPair().pubKey.toHexKey()
|
||||
private val senderSigner = NostrSignerSync(KeyPair())
|
||||
private val sender = senderSigner.pubKey
|
||||
private val chatRoomId = "639f".repeat(16)
|
||||
|
||||
private var next = 0
|
||||
|
||||
/** A kind:445 this device has stored, carrying one inner event of [kind]. */
|
||||
private suspend fun arrive(kind: Kind, content: String): Pair<GroupEvent, ChatMessage?> {
|
||||
private suspend fun arrive(kind: Kind, content: String): Pair<GroupEvent, ChatMessage?> = arrive(
|
||||
Event(
|
||||
id = "%064x".format(2000 + next),
|
||||
pubKey = sender,
|
||||
createdAt = 1,
|
||||
kind = kind,
|
||||
tags = DkgRitualEvents.assembleTags(sessionId = "5e55".repeat(16)),
|
||||
content = content,
|
||||
sig = "",
|
||||
)
|
||||
)
|
||||
|
||||
/** A kind:445 this device has stored, carrying [inner]. */
|
||||
private suspend fun arrive(inner: Event): Pair<GroupEvent, ChatMessage?> {
|
||||
val n = next++
|
||||
val groupEventId = "%064x".format(1000 + n)
|
||||
|
||||
@@ -77,16 +96,6 @@ class ProtocolKindDispatchJvmTest {
|
||||
content = "ciphertext",
|
||||
sig = "0".repeat(128),
|
||||
)
|
||||
val inner = Event(
|
||||
id = "%064x".format(2000 + n),
|
||||
pubKey = sender,
|
||||
createdAt = 1,
|
||||
kind = kind,
|
||||
tags = DkgRitualEvents.assembleTags(sessionId = "5e55".repeat(16)),
|
||||
content = content,
|
||||
sig = "",
|
||||
)
|
||||
|
||||
val line = ChatMessage.fromGroupEventResult(
|
||||
database = database,
|
||||
activeKeyPair = self,
|
||||
@@ -129,6 +138,33 @@ class ProtocolKindDispatchJvmTest {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A direct message's envelope shares 30330 with a signing session's decline.
|
||||
*
|
||||
* Treating every 30330 as a decline -- which is what recognising protocol
|
||||
* kinds first did at first -- dropped every direct message in a
|
||||
* current-profile room before it was opened. What tells the two apart is
|
||||
* what the event carries.
|
||||
*/
|
||||
@Test
|
||||
fun `a direct message envelope is opened, not taken for a decline`(): Unit = runBlocking {
|
||||
val wrap = MarmotDirectMessage.wrap(
|
||||
signer = senderSigner,
|
||||
recipientPublicKey = self.pubKey.toHexKey(),
|
||||
kind = ChatMessageEvent.KIND,
|
||||
createdAt = 1,
|
||||
tags = arrayOf(PTag.assemble(self.pubKey.toHexKey(), null)),
|
||||
content = "the vote is at six",
|
||||
)
|
||||
val envelope = MarmotDirectMessage.envelope(sender, self.pubKey.toHexKey(), wrap, createdAt = 1)
|
||||
assertEquals(FrostSigningEvents.DECLINE, envelope.kind, "the collision this test exists for")
|
||||
|
||||
val (_, line) = arrive(Event.fromJson(envelope.toJson()))
|
||||
|
||||
val opened = assertNotNull(line, "the envelope must reach the direct-message path")
|
||||
assertTrue(opened.content.contains("the vote is at six"), "and be opened: ${opened.content}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a signing message writes no chat line`(): Unit = runBlocking {
|
||||
FrostSigningEvents.ALL.forEach { kind ->
|
||||
|
||||
@@ -45,6 +45,14 @@ key** handed over to its finished ceremony, and back returned to its details.
|
||||
Not exercised on a device: the certificate and key state after Tapscript, and
|
||||
starting a ceremony from `CreateSharedKeyScreen` in a group without a key.
|
||||
|
||||
**A regression Phase 6 shipped, and its fix.** `FrostSigningEvents.DECLINE` and
|
||||
`MarmotDirectMessage.ENVELOPE_KIND` are both 30330. Phase 6 returned early for
|
||||
every protocol kind before the direct-message branch, so every direct message in
|
||||
a current-profile room was dropped unopened. Found while mapping this fix onto
|
||||
Curare. An event of kind 30330 that holds a gift wrap is now an envelope, never a
|
||||
decline -- the test `MarmotDirectMessage.wrapInside` already made -- and
|
||||
`ProtocolKindDispatchJvmTest` opens one. Any port of Phase 6 has to carry this.
|
||||
|
||||
The headline: **a ceremony is started only from a screen that knows what it is
|
||||
for, and the screen that shows a ceremony can never start one.** Today
|
||||
`DkgRitualScreen` does three jobs (showing progress, asking for approvals, and
|
||||
|
||||
Reference in new issue
Block a user