Skip to content

Commit c814c9e

Browse files
BradGrouxnpub17q2gdupkvswvk5kprwc7plergm4gn295uw6fe4mjyjv53ahuhtnq02jd3fwesbillmanCarl
authored
fix(sdk): preserve self-mention p tags in message and forum event builders (#4975)
## What users saw `buzz messages send` silently removed an explicitly supplied self-mention. The caller passed `--mention <sender-pubkey>` and received `accepted:true`, but the signed event had no matching `p` tag and `mention_pubkeys` was empty. ## Why it happened `nostr` 0.44 strips `p` tags matching the signer's pubkey by default. The codebase already opts out with `.allow_self_tagging()` for identity archive and unarchive requests, but the message and forum builders that accept mentions did not. The library therefore removed the tag during signing after the CLI had validated the explicit mention. ## What changed Added `.allow_self_tagging()` to all three event builders that accept mention tags: - `build_message` (kind 9) - `build_forum_post` (kind 45001) - `build_forum_comment` (kind 45003) An explicit mention now survives signing even when it matches the sender. ## How this was tested Added one regression test per builder. Each test signs with the same key included in the mention list and asserts that the resulting event preserves the self-referential `p` tag. Validation at `1ea172355`: ```text ./bin/cargo fmt --all -- --check cargo test -p buzz-sdk --lib cargo test -p buzz-cli --lib cargo clippy -p buzz-sdk -p buzz-cli --all-targets -- -D warnings ``` All 257 `buzz-sdk` tests and all 321 `buzz-cli` tests passed, and formatting and strict Clippy checks completed successfully. ## Scope and non-goals - Does not change mention validation, deduplication, or channel-member checks. - Does not change `normalize_mention_pubkeys`, which is not used by the messages-send path. - Does not add a dropped-mentions output field because the explicit tags are now preserved. Closes #4906. --------- Signed-off-by: Brad Groux <[email protected]> Signed-off-by: npub17q2gdupkvswvk5kprwc7plergm4gn295uw6fe4mjyjv53ahuhtnq02jd3f <f01486f036641ccb52c11bb1e0ff2346ea89a8b4e3b49cd772249948f6fcbae6@digitalmeld.communities.buzz.xyz> Signed-off-by: Brad Groux <[email protected]> Signed-off-by: Wes <[email protected]> Co-authored-by: npub17q2gdupkvswvk5kprwc7plergm4gn295uw6fe4mjyjv53ahuhtnq02jd3f <f01486f036641ccb52c11bb1e0ff2346ea89a8b4e3b49cd772249948f6fcbae6@digitalmeld.communities.buzz.xyz> Co-authored-by: Wes <[email protected]> Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
1 parent cb88d0f commit c814c9e

1 file changed

Lines changed: 56 additions & 3 deletions

File tree

‎crates/buzz-sdk/src/builders.rs‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ pub fn build_message(
239239
tags.push(tag(&["broadcast", "1"])?);
240240
}
241241
imeta_tags(media_tags, &mut tags)?;
242-
Ok(EventBuilder::new(Kind::Custom(9), content).tags(tags))
242+
Ok(EventBuilder::new(Kind::Custom(9), content)
243+
.tags(tags)
244+
.allow_self_tagging())
243245
}
244246

245247
/// Build an encrypted agent observer frame (kind 24200).
@@ -290,7 +292,9 @@ pub fn build_forum_post(
290292
let mut tags = vec![tag(&["h", &channel_id.to_string()])?];
291293
mention_tags(mentions, &mut tags)?;
292294
imeta_tags(media_tags, &mut tags)?;
293-
Ok(EventBuilder::new(Kind::Custom(45001), content).tags(tags))
295+
Ok(EventBuilder::new(Kind::Custom(45001), content)
296+
.tags(tags)
297+
.allow_self_tagging())
294298
}
295299

296300
/// Build a forum comment reply (kind 45003).
@@ -306,7 +310,9 @@ pub fn build_forum_comment(
306310
thread_tags(thread_ref, &mut tags)?;
307311
mention_tags(mentions, &mut tags)?;
308312
imeta_tags(media_tags, &mut tags)?;
309-
Ok(EventBuilder::new(Kind::Custom(45003), content).tags(tags))
313+
Ok(EventBuilder::new(Kind::Custom(45003), content)
314+
.tags(tags)
315+
.allow_self_tagging())
310316
}
311317

312318
/// Build a diff/patch message (kind 40008).
@@ -2253,6 +2259,53 @@ mod tests {
22532259
assert!(has_tag(&ev, "h", &cid.to_string()));
22542260
}
22552261

2262+
#[test]
2263+
fn message_preserves_self_mention_p_tag() {
2264+
// nostr 0.44 strips p tags matching the signer by default.
2265+
// build_message must opt in via allow_self_tagging() so that
2266+
// explicit self-mentions survive signing. See #4906.
2267+
let cid = uuid();
2268+
let sender = keys();
2269+
let self_pk = sender.public_key().to_hex();
2270+
let builder = build_message(cid, "self-canary", None, &[&self_pk], false, &[]).unwrap();
2271+
let ev = builder.sign_with_keys(&sender).expect("sign");
2272+
assert!(
2273+
has_tag(&ev, "p", &self_pk),
2274+
"self-mention p tag must survive signing"
2275+
);
2276+
}
2277+
2278+
#[test]
2279+
fn forum_post_preserves_self_mention_p_tag() {
2280+
let cid = uuid();
2281+
let sender = keys();
2282+
let self_pk = sender.public_key().to_hex();
2283+
let builder = build_forum_post(cid, "self-canary", &[&self_pk], &[]).unwrap();
2284+
let ev = builder.sign_with_keys(&sender).expect("sign");
2285+
assert!(
2286+
has_tag(&ev, "p", &self_pk),
2287+
"self-mention p tag must survive signing"
2288+
);
2289+
}
2290+
2291+
#[test]
2292+
fn forum_comment_preserves_self_mention_p_tag() {
2293+
let cid = uuid();
2294+
let sender = keys();
2295+
let self_pk = sender.public_key().to_hex();
2296+
let root = event_id();
2297+
let tr = ThreadRef {
2298+
root_event_id: root,
2299+
parent_event_id: root,
2300+
};
2301+
let builder = build_forum_comment(cid, "self-canary", &tr, &[&self_pk], &[]).unwrap();
2302+
let ev = builder.sign_with_keys(&sender).expect("sign");
2303+
assert!(
2304+
has_tag(&ev, "p", &self_pk),
2305+
"self-mention p tag must survive signing"
2306+
);
2307+
}
2308+
22562309
#[test]
22572310
fn agent_observer_frame_happy_path() {
22582311
let sender = keys();

0 commit comments

Comments
 (0)