fix(sdk): keep self-targeted p tags on add/remove member builders - #6246
fix(sdk): keep self-targeted p tags on add/remove member builders#6246santhiprakash wants to merge 1 commit into
Conversation
A self-targeted add-member (an owner explicitly granting themselves a role
on a channel they did not get auto-added to) carries a p tag that matches
the signer's own pubkey. nostr 0.44's EventBuilder strips such p tags by
default during signing, so the resulting event reaches the relay without
its p tag and is rejected with the misleading 'invalid: missing p tag'
error.
Apply the same .allow_self_tagging() opt-in that build_message,
build_forum_post, build_forum_comment, and the NIP-IA archive/unarchive
builders already use, to:
- crates/buzz-sdk/src/builders.rs build_add_member / build_remove_member
- desktop/src-tauri/src/events.rs build_add_member / build_remove_member
(the agent auto-add path in huddle/agents.rs grants the bot role to
the agent's own pubkey, so the same scrub bites there).
Regression tests assert that the self-targeted p tag survives signing for
all four builders.
Fixes block#6241
Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>
|
Closing this PR as a duplicate. The same fix (
Issue block/buzz#6241 is a fresh (2026-08-18) report of the same defect already tracked in block/buzz#4326 (LarsKlawitter, 2026-08-02) which is the canonical issue #4338 references. My pre-PR duplicate script only checks against If maintainers want a focused follow-up patch on the desktop mirror alone (without the SDK re-touch), I'm happy to send a PR against #3384. |
Summary
buzz_sdk::build_add_member(used bybuzz-cli channels add-member) builds its kind:9000 event via a plainEventBuilder::new(...).tags([h, p, role])without calling.allow_self_tagging(). Thenostrcrate'sEventBuilderstrips anyptag matching the signer's own pubkey by default (documented behavior —allow_self_tagging()exists precisely to opt out), so a self-targetedadd-membercall (e.g. an owner explicitly granting themselves membership on a channel they didn't get auto-added to — see #6240) silently loses itsptag before signing.The relay then rejects the resulting event with a confusing
invalid: missing p tag— which reads as if the CLI passed a bad--pubkey, when actually the tag was present in the builder and was stripped later, invisibly, during signing.Apply the same
.allow_self_tagging()opt-in thatbuild_message,build_forum_post,build_forum_comment, and the NIP-IA archive/unarchive builders already use, to both add- and remove-member builders in the SDK and the desktop Tauri event mirror:crates/buzz-sdk/src/builders.rsbuild_add_member/build_remove_memberdesktop/src-tauri/src/events.rsbuild_add_member/build_remove_memberThe desktop mirror is included because the agent auto-add path in
huddle/agents.rsgrants the bot role to the agent's own pubkey, so the same scrub bites there.build_leaveis left alone — it carries noptag.Related issue
Fixes #6241 (the SDK-side root cause; same code path, no new findings).
Adjacent: #6240 (the discoverer of the issue, in turn driven by the same scrub on the relay-side regeneration of kind:39002 — separate fix, separate PR).
Testing
cargo test -p buzz-sdk --lib→ 264 passed, 0 failed (4 new + 260 pre-existing). New tests cover the self-targeted path for bothbuild_add_memberandbuild_remove_member, asserting theptag survives signing.cargo clippy -p buzz-sdk --lib --tests -- -D warnings→ clean.cargo fmt -p buzz-sdk -- --check→ clean.cargo fmt -p buzz-desktop -- --check→ clean (verified at the desktop crate's manifest since it is not a member of the root workspace).cargo test -p buzz-sdk --lib add_member_preserves_self_targeted, gotFAILED. 0 passed; 1 failed("self-targeted p tag must survive signing"); restored the fix and re-ran → 1 passed.The desktop Tauri crate could not be compiled end-to-end in this environment (cmake / opus sys crate missing — pre-existing build-env gap, unrelated to the diff), but the builder change is the same one-line
.allow_self_tagging()addition tested in the SDK, and the test follows the same pattern.Diff
crates/buzz-sdk/src/builders.rs:+57 / -2desktop/src-tauri/src/events.rs:+68 / -2Signed-off-by: Santhi Prakash b.santhiprakash@gmail.com