⏺ fix: derive nostrGroupId from MLS GroupContext in Welcome processing

The "h" tag is optional in MIP-02 Welcome events — senders like
  whitenoise-rs omit it. Instead of failing when the h-tag is absent,
  derive nostrGroupId from the NostrGroupData extension embedded in the
  Welcome's GroupContext (the authoritative MLS source). An h-tag hint,
  if present, is still validated against the MLS-derived value.
This commit is contained in:
Vitor Pamplona
2026-04-20 12:32:42 -04:00
parent 9766cc5901
commit e0094f163b
4 changed files with 42 additions and 37 deletions
@@ -128,20 +128,14 @@ class MarmotManager(
*/
suspend fun processWelcome(
welcomeEvent: WelcomeEvent,
nostrGroupId: HexKey,
hintNostrGroupId: HexKey? = welcomeEvent.nostrGroupId(),
): WelcomeResult {
// Validate that the provided nostrGroupId matches the WelcomeEvent's h-tag if present
val eventGroupId = welcomeEvent.nostrGroupId()
if (eventGroupId != null && eventGroupId != nostrGroupId) {
return WelcomeResult.Error(
"nostrGroupId mismatch: expected $nostrGroupId but WelcomeEvent has $eventGroupId",
)
}
val result = inboundProcessor.processWelcome(welcomeEvent, nostrGroupId)
// nostrGroupId is derived from the MLS GroupContext's NostrGroupData extension.
// The h-tag value (hintNostrGroupId) is validated against the MLS content inside
// inboundProcessor, so senders that omit the h-tag are handled transparently.
val result = inboundProcessor.processWelcome(welcomeEvent, hintNostrGroupId)
if (result is WelcomeResult.Joined) {
// Update subscription state for the new group
subscriptionManager.subscribeGroup(result.nostrGroupId)
Log.d("MarmotManager", "Joined group ${result.nostrGroupId}")
}