Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions crates/buzz-sdk/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Ok(EventBuilder::new(Kind::Custom(9), content)
.tags(tags)
.allow_self_tagging())
}

/// Build an encrypted agent observer frame (kind 24200).
Expand Down Expand Up @@ -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))
Ok(EventBuilder::new(Kind::Custom(45001), content)
.tags(tags)
.allow_self_tagging())
}

/// Build a forum comment reply (kind 45003).
Expand All @@ -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))
Ok(EventBuilder::new(Kind::Custom(45003), content)
.tags(tags)
.allow_self_tagging())
}

/// Build a diff/patch message (kind 40008).
Expand Down Expand Up @@ -2253,6 +2259,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();
Expand Down