fix: preserve self-referential p tags in channel member builders - #4338
Open
iroiro147 wants to merge 1 commit into
Open
fix: preserve self-referential p tags in channel member builders#4338iroiro147 wants to merge 1 commit into
iroiro147 wants to merge 1 commit into
Conversation
nostr 0.44's EventBuilder::build strips p tags whose value equals the author's public key by default (see allow_self_tagging flag). The build_add_member (kind 9000) and build_remove_member (kind 9001) builders constructed the p tag correctly, but sign_with_keys would then strip it when target_pubkey == signer pubkey, causing the relay to reply 400 "missing p tag" for self-removal/self-add operations. Fix by chaining .allow_self_tagging() on both builders, matching the existing convention in NIP-IA builders (builders.rs:1816,1837). Add regression tests that sign with the same key as the target pubkey and assert the p tag survives — the existing happy-path tests only exercised the non-self case, which is why the bug shipped. Closes block#4326. Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4326:
buzz channels remove-member --pubkey <your-own-key>fails with400 missing p tag.Root cause
It's in nostr 0.44's
EventBuilder::build, not buzz code. Fromnostr/src/event/builder.rs:430:The SDK builders construct the
ptag correctly (builders.rs:582-592), butsign_with_keysstrips it when the target equals the signer. The existing tests only exercised non-self targets, which is why the bug shipped.Fix
Chain
.allow_self_tagging()on bothbuild_add_member(kind 9000) andbuild_remove_member(kind 9001), matching the existing convention in the NIP-IA builders elsewhere in this file (lines 1816, 1837).Tests added
Two regression tests that sign with the same key as the target pubkey:
remove_member_self_referential_preserves_p_tagadd_member_self_referential_preserves_p_tagBoth assert the
ptag survives signing. Verified withcargo test -p buzz-sdk --lib(243/243 passing).Closes #4326.