Files
giza-kmp/composeApp/src/commonMain
Kgothatso NgakoandClaude Opus 5 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>
2026-09-13 22:46:22 +02:00
..