From 10452c27eaeacfd123ac4b45d891737797df3559 Mon Sep 17 00:00:00 2001 From: npub17q2gdupkvswvk5kprwc7plergm4gn295uw6fe4mjyjv53ahuhtnq02jd3f Date: Wed, 5 Aug 2026 17:47:03 -0500 Subject: [PATCH 1/2] fix(sdk): preserve self-mention p tags in message and forum event builders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nostr 0.44's EventBuilder strips p tags matching the signer's pubkey by default. build_message, build_forum_post, and build_forum_comment did not opt in via allow_self_tagging(), so an explicit --mention was silently removed from the signed event. The CLI returned accepted:true with empty mention_pubkeys — a silent-success failure. Add .allow_self_tagging() to all three builders, matching the pattern already used by build_archive_identity_request and build_unarchive_identity_request. Add regression tests that sign with the same key whose pubkey is in the mentions list and assert the p tag survives. Refs #4906 Co-authored-by: Brad Groux Signed-off-by: Brad Groux Signed-off-by: npub17q2gdupkvswvk5kprwc7plergm4gn295uw6fe4mjyjv53ahuhtnq02jd3f --- crates/buzz-sdk/src/builders.rs | 53 +++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/crates/buzz-sdk/src/builders.rs b/crates/buzz-sdk/src/builders.rs index c3b4432101..ef603ec2b1 100644 --- a/crates/buzz-sdk/src/builders.rs +++ b/crates/buzz-sdk/src/builders.rs @@ -239,7 +239,7 @@ pub fn build_message( tags.push(tag(&["broadcast", "1"])?); } imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(9), content).tags(tags)) + Ok(EventBuilder::new(Kind::Custom(9), content).tags(tags).allow_self_tagging()) } /// Build an encrypted agent observer frame (kind 24200). @@ -290,7 +290,7 @@ pub fn build_forum_post( let mut tags = vec![tag(&["h", &channel_id.to_string()])?]; mention_tags(mentions, &mut tags)?; imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(45001), content).tags(tags)) + Ok(EventBuilder::new(Kind::Custom(45001), content).tags(tags).allow_self_tagging()) } /// Build a forum comment reply (kind 45003). @@ -306,7 +306,7 @@ pub fn build_forum_comment( thread_tags(thread_ref, &mut tags)?; mention_tags(mentions, &mut tags)?; imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(45003), content).tags(tags)) + Ok(EventBuilder::new(Kind::Custom(45003), content).tags(tags).allow_self_tagging()) } /// Build a diff/patch message (kind 40008). @@ -2253,6 +2253,53 @@ mod tests { assert!(has_tag(&ev, "h", &cid.to_string())); } + #[test] + fn message_preserves_self_mention_p_tag() { + // nostr 0.44 strips p tags matching the signer by default. + // build_message must opt in via allow_self_tagging() so that + // explicit self-mentions survive signing. See #4906. + let cid = uuid(); + let sender = keys(); + let self_pk = sender.public_key().to_hex(); + let builder = build_message(cid, "self-canary", None, &[&self_pk], false, &[]).unwrap(); + let ev = builder.sign_with_keys(&sender).expect("sign"); + assert!( + has_tag(&ev, "p", &self_pk), + "self-mention p tag must survive signing" + ); + } + + #[test] + fn forum_post_preserves_self_mention_p_tag() { + let cid = uuid(); + let sender = keys(); + let self_pk = sender.public_key().to_hex(); + let builder = build_forum_post(cid, "self-canary", &[&self_pk], &[]).unwrap(); + let ev = builder.sign_with_keys(&sender).expect("sign"); + assert!( + has_tag(&ev, "p", &self_pk), + "self-mention p tag must survive signing" + ); + } + + #[test] + fn forum_comment_preserves_self_mention_p_tag() { + let cid = uuid(); + let sender = keys(); + let self_pk = sender.public_key().to_hex(); + let root = event_id(); + let tr = ThreadRef { + root_event_id: root, + parent_event_id: root, + }; + let builder = build_forum_comment(cid, "self-canary", &tr, &[&self_pk], &[]).unwrap(); + let ev = builder.sign_with_keys(&sender).expect("sign"); + assert!( + has_tag(&ev, "p", &self_pk), + "self-mention p tag must survive signing" + ); + } + #[test] fn agent_observer_frame_happy_path() { let sender = keys(); From cd0f30bca1bebd64dbc72357e2606fac101863c9 Mon Sep 17 00:00:00 2001 From: Brad Groux <3053586+BradGroux@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:26:39 -0500 Subject: [PATCH 2/2] chore(sdk): format self-mention builders Co-authored-by: Brad Groux Signed-off-by: Brad Groux Signed-off-by: Brad Groux <3053586+BradGroux@users.noreply.github.com> --- crates/buzz-sdk/src/builders.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/buzz-sdk/src/builders.rs b/crates/buzz-sdk/src/builders.rs index ef603ec2b1..948fa775f5 100644 --- a/crates/buzz-sdk/src/builders.rs +++ b/crates/buzz-sdk/src/builders.rs @@ -239,7 +239,9 @@ pub fn build_message( tags.push(tag(&["broadcast", "1"])?); } imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(9), content).tags(tags).allow_self_tagging()) + Ok(EventBuilder::new(Kind::Custom(9), content) + .tags(tags) + .allow_self_tagging()) } /// Build an encrypted agent observer frame (kind 24200). @@ -290,7 +292,9 @@ pub fn build_forum_post( let mut tags = vec![tag(&["h", &channel_id.to_string()])?]; mention_tags(mentions, &mut tags)?; imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(45001), content).tags(tags).allow_self_tagging()) + Ok(EventBuilder::new(Kind::Custom(45001), content) + .tags(tags) + .allow_self_tagging()) } /// Build a forum comment reply (kind 45003). @@ -306,7 +310,9 @@ pub fn build_forum_comment( thread_tags(thread_ref, &mut tags)?; mention_tags(mentions, &mut tags)?; imeta_tags(media_tags, &mut tags)?; - Ok(EventBuilder::new(Kind::Custom(45003), content).tags(tags).allow_self_tagging()) + Ok(EventBuilder::new(Kind::Custom(45003), content) + .tags(tags) + .allow_self_tagging()) } /// Build a diff/patch message (kind 40008).