docs(tools): the shipped engine against the old one, both ways, three epochs (quartz-mls-marmot-update, Phase 3)
docs/tools/engine-interop runs marmot-kmp 2.3.0 over mls-kmp 1.3.1 against quartz 1.15.2's engine -- the one a Bennu peer on that version runs -- in two JVMs over a pipe, since one build cannot hold two versions of the quartz group. Each side creates a room in turn; the other joins by Welcome, applies two more commits and reads a message each way at every epoch. 20 checks, all green, so mls 1.3.1's new epoch-0 shape costs nothing against the old engine. The note records Phase 3, including the first draft of the epoch-0 test, which asserted a restore-time repair mls-kmp drafted and then removed before 1.3.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c81e4a2dbb
commit
a08a878935
9 files changed
+383
No files matched your search
@@ -398,6 +398,74 @@ Then quartz's behavioural deltas that reach the app, both small:
|
||||
recorded here. A test that needed its assertions edited to pass is a finding, as in
|
||||
marmot-kmp.md's Phase 2.
|
||||
|
||||
**Built.** The existing suite needed nothing: it was already green on 1.3.1 in Phase 2, with
|
||||
no assertion moved.
|
||||
|
||||
**`OldEpochZeroGroupJvmTest`**, two tests, both green. The first draft of the first one
|
||||
was wrong, and the way it was wrong is worth keeping.
|
||||
|
||||
mls-kmp's commit `6a1ba88` says a creator's epoch-0 state saved by 1.3.0 or older "is
|
||||
repaired on restore", and the test asserted that. It failed. The *released* 1.3.1 has no
|
||||
repair: its audit commit, `125614a`, took it out ("repairing only the creator forked the two
|
||||
apart" from a PublicGroup saved beside it). The library's upgrading guide says what ships:
|
||||
"an older release['s epoch-0 group] keeps the old hash, so external joins into it fail until
|
||||
its first commit". So the test now pins both sides of that:
|
||||
|
||||
- an old epoch-0 room keeps its empty interim hash across a restore;
|
||||
- a room created now gets the §11 hash;
|
||||
- the old room still adds its first member, and the joiner and the creator agree on the
|
||||
epoch authenticator and the kind:445 key and read each other.
|
||||
|
||||
A future mls-kmp that brings the repair back fails the first assertion, and its KDoc says
|
||||
to re-read the upgrading guide before inverting it. The app has no `externalJoin`, so the
|
||||
one thing an old epoch-0 room cannot do is something this app never asks of it.
|
||||
|
||||
**`docs/tools/engine-interop/`** is the probe, built as two programs rather than an
|
||||
extension of `old-state-blob`, for two reasons:
|
||||
|
||||
- That tool's whole job is provenance for one blob, and should stay that small.
|
||||
- The probe cannot be one build. Both halves depend on the `com.vitorpamplona.quartz`
|
||||
group, at 1.15.2 and 2.20.0, and Magpie serves that group exclusively from a relay with
|
||||
nothing older than 2.19.0. So `old/` is quartz 1.15.2 from Central and nothing else,
|
||||
answering one command per line on stdin, and `new/` is the app's versions through
|
||||
Magpie, driving it as a child process.
|
||||
|
||||
Each scenario goes three epochs:
|
||||
|
||||
1. the Welcome;
|
||||
2. two further adds by the room's creator, which the other engine applies, checking each
|
||||
confirmation tag against a transcript it computed itself;
|
||||
3. a message each way at every epoch.
|
||||
|
||||
The first draft had the joiner commit an add too, and both engines refused it on MIP-03's
|
||||
rule that only an admin may. That was correct of them, and the scenario was wrong. Across
|
||||
the two scenarios each engine authors commits and each applies the other's. The run:
|
||||
|
||||
```
|
||||
== the new engine creates the room, the old one joins
|
||||
ok after the Welcome: both at epoch 1 with the same kind:445 key
|
||||
ok epoch 1: the old engine reads the new one / the new engine reads the old one
|
||||
ok after the new engine's first commit past the Welcome: both at epoch 2 …
|
||||
ok after its second: both at epoch 3 … (and both ways at 2 and 3)
|
||||
== the old engine creates the room, the new one joins
|
||||
…the same ten checks, with the old engine committing…
|
||||
ALL PASSED
|
||||
```
|
||||
|
||||
That is 20 checks, 20 green. So a room either engine creates, at either epoch-0 shape, works
|
||||
with the other through three epochs. **What it does not say** is which engine Bennu ships
|
||||
today. Its repository is not readable without signing in, so quartz 1.15.2 is
|
||||
marmot-kmp.md's last record of it, not a fresh one. If Bennu has moved, the probe's `old/`
|
||||
pins that version instead, and Phase 8's real-peer check covers whatever it is.
|
||||
|
||||
**quartz's two behavioural deltas**, both checked:
|
||||
|
||||
- **`GiftWrapEvent.create`** is called at 16 sites with the same signature. The NIP-17,
|
||||
Welcome-wrapping and `MarmotClientInteropJvmTest` suites pass unchanged, and the last
|
||||
of those has the library's `MarmotWelcomeSender` wrap a Welcome the app opens.
|
||||
- **`EventFactory`'s new subclasses** are for kinds 30078, 30100 and 30102.
|
||||
`grep -rnE '\b(30078|30100|30102)\b' composeApp/src` finds nothing.
|
||||
|
||||
## Phase 4 — C1, and the fork, measured again
|
||||
|
||||
No new code expected. This phase runs the tests marmot-kmp.md left as tripwires and records
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# engine-interop
|
||||
|
||||
The MLS engine the app ships against the one it shipped before, in two JVMs.
|
||||
[docs/quartz-mls-marmot-update.md](../../quartz-mls-marmot-update.md), Phase 3.
|
||||
|
||||
- `old/` is one Marmot member played by quartz 1.15.2's engine, the one a Bennu peer
|
||||
on that version still runs. It reads one command per line on stdin and answers on
|
||||
stdout (see `OldPeer.kt`).
|
||||
- `new/` is the app's engine at the versions in `gradle/libs.versions.toml`:
|
||||
marmot-kmp over mls-kmp, through Magpie. Its driver starts the old peer as a child
|
||||
process and runs two scenarios: the new engine creates the room and the old one joins,
|
||||
then the reverse. In each, the creator commits two more adds after the Welcome, and
|
||||
both sides must land on the same epoch and kind:445 key and read each other's
|
||||
messages at every epoch.
|
||||
|
||||
They are two builds because they cannot be one: both depend on the `com.vitorpamplona.quartz`
|
||||
group, at 1.15.2 and 2.20.0. Magpie serves that group exclusively, and its relay has nothing
|
||||
older than 2.19.0, so `old/` resolves from Maven Central with no Magpie at all.
|
||||
|
||||
Not part of `./gradlew check`. It is a probe to run by hand when the engine moves.
|
||||
|
||||
```bash
|
||||
../../../gradlew -p old installDist
|
||||
```
|
||||
|
||||
```bash
|
||||
../../../gradlew -p new run --args="$PWD/old/build/install/engine-interop-old/lib"
|
||||
```
|
||||
|
||||
It prints `ok` per check and `ALL PASSED`, or `FAIL` with the step and exits 1. Move
|
||||
`new/build.gradle.kts`'s versions with the catalogue's, and let the first run add them to
|
||||
`new/gradle/magpie.lock`.
|
||||
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.10"
|
||||
application
|
||||
}
|
||||
dependencies {
|
||||
// What the app resolves. Keep these at gradle/libs.versions.toml's versions: the point of
|
||||
// this probe is the engine the app ships against the one it shipped before.
|
||||
implementation("com.vitorpamplona.marmot:marmot:2.3.0")
|
||||
implementation("com.vitorpamplona.mls:mls:1.3.1")
|
||||
implementation("com.vitorpamplona.quartz:quartz:2.20.0")
|
||||
implementation("com.vitorpamplona.crypto:crypto:2.1.1")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0")
|
||||
runtimeOnly("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:0.24.0")
|
||||
}
|
||||
kotlin { jvmToolchain(21) }
|
||||
application { mainClass.set("DriverKt") }
|
||||
@@ -0,0 +1,21 @@
|
||||
# Magpie lock file. Commit it: it pins the key each group's domain vouched for and the
|
||||
# manifest each resolved version came from. A change to either fails the build.
|
||||
version 1
|
||||
publisher com.vitorpamplona.crypto e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
publisher com.vitorpamplona.marmot e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
publisher com.vitorpamplona.mls e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
publisher com.vitorpamplona.negentropy e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
publisher com.vitorpamplona.quartz e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
publisher com.vitorpamplona.schnorr256k1 e9867c970848e300d6fca32bbd600c2fd4bd92c760ae5707355058720991955c nip05:releases@vitorpamplona.com
|
||||
release com.vitorpamplona.crypto:crypto-jvm:2.1.1 1012859c6c4548599c203c41f2126fcc0ca2138feae1f2acf84f42222f96825e 1c993cfd7b8b034a12ce66b20b1910a88f2c1816a39f3c284155fd8831acf80d
|
||||
release com.vitorpamplona.crypto:crypto:2.1.1 1012859c6c4548599c203c41f2126fcc0ca2138feae1f2acf84f42222f96825e 1c993cfd7b8b034a12ce66b20b1910a88f2c1816a39f3c284155fd8831acf80d
|
||||
release com.vitorpamplona.marmot:marmot-jvm:2.3.0 a24c22b76974376bb4c271e3dc973b12478d88af76b326ce55ca23ca66ce0aa0 b9498111dfc41c27fdb152869aa6d3f04052e2588ca9aac7a301a7dc7eb40341
|
||||
release com.vitorpamplona.marmot:marmot:2.3.0 a24c22b76974376bb4c271e3dc973b12478d88af76b326ce55ca23ca66ce0aa0 b9498111dfc41c27fdb152869aa6d3f04052e2588ca9aac7a301a7dc7eb40341
|
||||
release com.vitorpamplona.mls:mls-jvm:1.3.1 afaee9458cfea00107297adeb93ef7315543288cdd008b4ed2dcf08d67f2c162 1b6b39440116e65adce199f237c878fbc3821d2e09946550af6b3852218fe086
|
||||
release com.vitorpamplona.mls:mls:1.3.1 afaee9458cfea00107297adeb93ef7315543288cdd008b4ed2dcf08d67f2c162 1b6b39440116e65adce199f237c878fbc3821d2e09946550af6b3852218fe086
|
||||
release com.vitorpamplona.negentropy:kmp-negentropy-jvm:v1.2.3 d005ae7d13d4fc0b5b498d554a880366554edef8c39ba123248676f360df3635 c4dfe76b4bdaa3442c5b8223778b0347e9bd9ab63f71a4b183ea42087353fdf5
|
||||
release com.vitorpamplona.negentropy:kmp-negentropy:v1.2.3 d005ae7d13d4fc0b5b498d554a880366554edef8c39ba123248676f360df3635 c4dfe76b4bdaa3442c5b8223778b0347e9bd9ab63f71a4b183ea42087353fdf5
|
||||
release com.vitorpamplona.quartz:quartz-jvm:2.20.0 893d9b079b98f3aead17fbbceaa46902beb6707bdac2fea136cbe08a66c686b6 5b125908669198513ef9eae94c337280dd81b75cd55789bcd7ccbe1f7e3a8d66
|
||||
release com.vitorpamplona.quartz:quartz:2.20.0 893d9b079b98f3aead17fbbceaa46902beb6707bdac2fea136cbe08a66c686b6 5b125908669198513ef9eae94c337280dd81b75cd55789bcd7ccbe1f7e3a8d66
|
||||
release com.vitorpamplona.schnorr256k1:schnorr256k1-kotlin-jvm:1.0.3 c8b474acf88c25958132495167bc27613f0db8492871fdced6bd4ac51a2a660e 004147e4e84462d3f867001b45e41b16eec93f0e00ca3668741c085be7af5c21
|
||||
release com.vitorpamplona.schnorr256k1:schnorr256k1-kotlin:1.0.3 c8b474acf88c25958132495167bc27613f0db8492871fdced6bd4ac51a2a660e 004147e4e84462d3f867001b45e41b16eec93f0e00ca3668741c085be7af5c21
|
||||
@@ -0,0 +1,25 @@
|
||||
rootProject.name = "engine-interop-new"
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
// The same groups, plugin and versions as the app's own settings and catalog.
|
||||
plugins {
|
||||
id("com.vitorpamplona.magpie") version "0.2.3"
|
||||
}
|
||||
magpie {
|
||||
group("com.vitorpamplona.quartz")
|
||||
group("com.vitorpamplona.marmot")
|
||||
group("com.vitorpamplona.mls")
|
||||
group("com.vitorpamplona.crypto")
|
||||
group("com.vitorpamplona.negentropy")
|
||||
group("com.vitorpamplona.schnorr256k1")
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import com.vitorpamplona.marmot.appComponents.CurrentProfileGroupFactory
|
||||
import com.vitorpamplona.marmot.groups.MarmotGroupPolicy
|
||||
import com.vitorpamplona.mls.group.MlsGroup
|
||||
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
|
||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import kotlin.system.exitProcess
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
* The engine the app ships (marmot-kmp 2.3.0 over mls-kmp 1.3.1) against the one it shipped
|
||||
* before (quartz 1.15.2), both ways round, one commit past the Welcome each way.
|
||||
*
|
||||
* mls-kmp 1.3.1 changed what a new group's epoch 0 is -- a random epoch secret and the
|
||||
* RFC 9420 §11 interim transcript hash where quartz 1.15.2 left it empty -- so a room one of
|
||||
* them creates starts from an epoch 0 the other would not have built. The Welcome carries the
|
||||
* confirmed transcript, which argues that nobody notices; the commits after it are where a
|
||||
* disagreement would surface, because the joiner checks each one's confirmation tag against a
|
||||
* transcript it computed itself. So in each scenario the room's creator -- its only admin, and
|
||||
* under MIP-03 the only member who may commit an Add -- commits two more adds, and the other
|
||||
* engine applies them. Between the two scenarios each engine authors commits and each applies
|
||||
* the other's.
|
||||
*
|
||||
* Usage: `run --args=<dir holding the old peer's jars>`. docs/tools/engine-interop/README.md.
|
||||
* docs/quartz-mls-marmot-update.md, Phase 3.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
val libDir = File(args.firstOrNull() ?: error("pass the old peer's lib directory"))
|
||||
val failures = mutableListOf<String>()
|
||||
for ((name, scenario) in listOf(
|
||||
"the new engine creates the room, the old one joins" to ::newCreatesOldJoins,
|
||||
"the old engine creates the room, the new one joins" to ::oldCreatesNewJoins,
|
||||
)) {
|
||||
println("== $name")
|
||||
OldPeer(libDir).use { old ->
|
||||
runCatching { runBlocking { scenario(old) } }.onFailure {
|
||||
println(" FAIL ${it.message}")
|
||||
failures += name
|
||||
}
|
||||
}
|
||||
}
|
||||
println(if (failures.isEmpty()) "ALL PASSED" else "FAILED: ${failures.joinToString("; ")}")
|
||||
exitProcess(if (failures.isEmpty()) 0 else 1)
|
||||
}
|
||||
|
||||
private suspend fun freshKeyPackage() = CurrentProfileGroupFactory.createKeyPackage(NostrSignerInternal(KeyPair())).keyPackage.toTlsBytes().toHexKey()
|
||||
|
||||
private fun MlsGroup.state() = "$epoch ${exporterSecret("marmot", "group-event".encodeToByteArray(), 32).toHexKey()}"
|
||||
|
||||
private fun check(what: String, ok: Boolean, detail: () -> String = { "" }) {
|
||||
if (!ok) error("$what ${detail()}")
|
||||
println(" ok $what")
|
||||
}
|
||||
|
||||
private fun agree(step: String, new: MlsGroup, old: OldPeer) {
|
||||
val ours = new.state()
|
||||
val theirs = old.call("state")
|
||||
check("$step: both at epoch ${new.epoch} with the same kind:445 key", ours == theirs) { "-- new '$ours', old '$theirs'" }
|
||||
}
|
||||
|
||||
private fun talk(step: String, new: MlsGroup, old: OldPeer) {
|
||||
val toOld = "new to old, $step"
|
||||
check("$step: the old engine reads the new one", old.call("dec ${new.encrypt(toOld.encodeToByteArray()).toHexKey()}").hexToByteArray().decodeToString() == toOld)
|
||||
val toNew = "old to new, $step"
|
||||
val sealed = old.call("enc ${toNew.encodeToByteArray().toHexKey()}").hexToByteArray()
|
||||
check("$step: the new engine reads the old one", new.decrypt(sealed).content.decodeToString() == toNew)
|
||||
}
|
||||
|
||||
private suspend fun newCreatesOldJoins(old: OldPeer) {
|
||||
val room = CurrentProfileGroupFactory.createGroup(NostrSignerInternal(KeyPair()), ByteArray(32) { 1 }, listOf("wss://relay.example.com"))
|
||||
check("the new room starts at epoch 0", room.epoch == 0L)
|
||||
|
||||
val (welcome, _) = room.addMember(old.call("kp").hexToByteArray()).let { it.welcomeBytes!! to it.framedCommitBytes }
|
||||
old.call("join ${welcome.toHexKey()}")
|
||||
agree("after the Welcome", room, old)
|
||||
talk("epoch 1", room, old)
|
||||
|
||||
old.call("commit ${room.addMember(freshKeyPackage().hexToByteArray()).framedCommitBytes.toHexKey()}")
|
||||
agree("after the new engine's first commit past the Welcome", room, old)
|
||||
talk("epoch 2", room, old)
|
||||
|
||||
old.call("commit ${room.addMember(freshKeyPackage().hexToByteArray()).framedCommitBytes.toHexKey()}")
|
||||
agree("after its second", room, old)
|
||||
talk("epoch 3", room, old)
|
||||
}
|
||||
|
||||
private suspend fun oldCreatesNewJoins(old: OldPeer) {
|
||||
old.call("create ${ByteArray(32) { 2 }.toHexKey()}")
|
||||
check("the old room starts at epoch 0", old.call("state").startsWith("0 "))
|
||||
|
||||
val bundle = CurrentProfileGroupFactory.createKeyPackage(NostrSignerInternal(KeyPair()))
|
||||
val (welcome, _) = old.call("add ${bundle.keyPackage.toTlsBytes().toHexKey()}").split(" ")
|
||||
val joined = MlsGroup.processWelcome(welcome.hexToByteArray(), bundle, MarmotGroupPolicy)
|
||||
agree("after the Welcome", joined, old)
|
||||
talk("epoch 1", joined, old)
|
||||
|
||||
joined.processFramedCommit(old.call("add ${freshKeyPackage()}").split(" ")[1].hexToByteArray())
|
||||
agree("after the old engine's first commit past the Welcome", joined, old)
|
||||
talk("epoch 2", joined, old)
|
||||
|
||||
joined.processFramedCommit(old.call("add ${freshKeyPackage()}").split(" ")[1].hexToByteArray())
|
||||
agree("after its second", joined, old)
|
||||
talk("epoch 3", joined, old)
|
||||
}
|
||||
|
||||
/** The quartz 1.15.2 member, in its own JVM. See OldPeer.kt in ../old for its commands. */
|
||||
private class OldPeer(libDir: File) : AutoCloseable {
|
||||
private val java = ProcessHandle.current().info().command().orElse("java")
|
||||
private val process = ProcessBuilder(java, "-cp", "${libDir.absolutePath}/*", "OldPeerKt").redirectErrorStream(false).start()
|
||||
private val input = process.outputStream.bufferedWriter()
|
||||
private val output: BufferedReader = process.inputStream.bufferedReader()
|
||||
|
||||
fun call(command: String): String {
|
||||
input.write(command)
|
||||
input.newLine()
|
||||
input.flush()
|
||||
val reply = output.readLine() ?: error("the old peer exited: ${process.errorStream.bufferedReader().readText().take(500)}")
|
||||
if (reply.startsWith("error ")) error("old peer, '${command.take(12)}…': ${reply.removePrefix("error ")}")
|
||||
return reply
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
input.close()
|
||||
process.waitFor()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.10"
|
||||
application
|
||||
}
|
||||
dependencies {
|
||||
// The engine the app shipped before marmot-kmp, and the one a Bennu peer on that version
|
||||
// runs. From Maven Central: this build is separate from ../new because Magpie serves the
|
||||
// quartz group exclusively, and its relay has nothing older than 2.19.0.
|
||||
implementation("com.vitorpamplona.quartz:quartz:1.15.2")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0")
|
||||
runtimeOnly("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:0.24.0")
|
||||
}
|
||||
kotlin { jvmToolchain(21) }
|
||||
application { mainClass.set("OldPeerKt") }
|
||||
@@ -0,0 +1,7 @@
|
||||
rootProject.name = "engine-interop-old"
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import com.vitorpamplona.quartz.marmot.appComponents.CurrentProfileGroupFactory
|
||||
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroup
|
||||
import com.vitorpamplona.quartz.marmot.mls.messages.KeyPackageBundle
|
||||
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
|
||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
* One Marmot member played by the engine the app shipped before marmot-kmp: quartz 1.15.2,
|
||||
* whose MLS engine is the one a Bennu peer still on that version runs. It reads one command
|
||||
* per line on stdin and answers one line on stdout, so the new engine can drive it from
|
||||
* another JVM -- the two cannot share a classpath, being two versions of one Maven group.
|
||||
*
|
||||
* pubkey -> <hex> this member's nostr pubkey
|
||||
* kp -> <hex> a current-profile KeyPackage; its bundle is kept
|
||||
* create <roomIdHex> -> ok a current-profile group, this member its admin
|
||||
* join <welcomeHex> -> ok joins with the bundle `kp` kept
|
||||
* add <kpHex> -> <welcomeHex> <commitHex> commits the add, applied here
|
||||
* commit <commitHex> -> ok applies a framed commit someone else sent
|
||||
* state -> <epoch> <exporterHex> the epoch and the kind:445 exporter secret
|
||||
* enc <plaintextHex> -> <ciphertextHex>
|
||||
* dec <ciphertextHex> -> <plaintextHex>
|
||||
*
|
||||
* Any failure answers `error <message>` and the driver fails the scenario.
|
||||
* docs/quartz-mls-marmot-update.md, Phase 3.
|
||||
*/
|
||||
fun main() {
|
||||
val signer = NostrSignerInternal(KeyPair())
|
||||
var bundle: KeyPackageBundle? = null
|
||||
var group: MlsGroup? = null
|
||||
|
||||
fun g() = checkNotNull(group) { "no group yet" }
|
||||
|
||||
while (true) {
|
||||
val line = readLine() ?: return
|
||||
val parts = line.trim().split(" ")
|
||||
val reply =
|
||||
runCatching {
|
||||
runBlocking {
|
||||
when (parts[0]) {
|
||||
"pubkey" -> signer.pubKey
|
||||
"kp" -> CurrentProfileGroupFactory.createKeyPackage(signer).also { bundle = it }.keyPackage.toTlsBytes().toHexKey()
|
||||
"create" -> {
|
||||
group = CurrentProfileGroupFactory.createGroup(signer, parts[1].hexToByteArray(), listOf("wss://relay.example.com"))
|
||||
"ok"
|
||||
}
|
||||
"join" -> {
|
||||
group = MlsGroup.processWelcome(parts[1].hexToByteArray(), checkNotNull(bundle) { "no bundle" })
|
||||
"ok"
|
||||
}
|
||||
"add" -> {
|
||||
val result = g().addMember(parts[1].hexToByteArray())
|
||||
"${checkNotNull(result.welcomeBytes).toHexKey()} ${result.framedCommitBytes.toHexKey()}"
|
||||
}
|
||||
"commit" -> {
|
||||
g().processFramedCommit(parts[1].hexToByteArray())
|
||||
"ok"
|
||||
}
|
||||
"state" -> "${g().epoch} ${g().exporterSecret("marmot", "group-event".encodeToByteArray(), 32).toHexKey()}"
|
||||
"enc" -> g().encrypt(parts[1].hexToByteArray()).toHexKey()
|
||||
"dec" -> g().decrypt(parts[1].hexToByteArray()).content.toHexKey()
|
||||
else -> error("unknown command ${parts[0]}")
|
||||
}
|
||||
}
|
||||
}.getOrElse { "error ${it::class.simpleName}: ${it.message?.lines()?.first()}" }
|
||||
println(reply)
|
||||
System.out.flush()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user