From 65ac6ef83205c41653e6ffe2acd664f968926fb2 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 23 Feb 2026 13:29:47 +0000 Subject: feat: remove purgatory announcements on NIP-09 deletion events Kind 5 deletion events signed by the announcement author now evict the corresponding purgatory entry and delete the bare repository from disk. Both NIP-09 reference styles are supported: - e tag (event ID): matches the purgatory entry whose event ID equals the tag value - a tag (coordinate 30617::): matches by coordinate, only removes entries with created_at <= deletion event created_at per NIP-09 spec Author-only enforcement: coordinate pubkey and e-tag owner must match the deletion event pubkey; third-party deletion attempts are silently ignored. Includes 6 unit tests and 2 integration tests (event ID and coordinate paths). --- src/nostr/builder.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nostr/builder.rs') diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index c2d4939..d056e46 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs @@ -14,8 +14,8 @@ use nostr_relay_builder::prelude::*; use crate::config::{Config, DatabaseBackend}; use crate::nostr::events::RepositoryAnnouncement; use crate::nostr::policy::{ - AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, - RelatedEventPolicy, StatePolicy, StateResult, + AnnouncementPolicy, AnnouncementResult, DeletionPolicy, PolicyContext, PrEventPolicy, + ReferenceResult, RelatedEventPolicy, StatePolicy, StateResult, }; @@ -29,6 +29,7 @@ pub type SharedDatabase = Arc; /// - `StatePolicy` - State event validation + ref alignment /// - `PrEventPolicy` - PR/PR Update validation /// - `RelatedEventPolicy` - Forward/backward reference checking +/// - `DeletionPolicy` - NIP-09 event deletion request handling /// /// Uses stateful database queries to check event relationships. #[derive(Clone)] @@ -38,6 +39,7 @@ pub struct Nip34WritePolicy { state_policy: StatePolicy, pr_event_policy: PrEventPolicy, related_event_policy: RelatedEventPolicy, + deletion_policy: DeletionPolicy, } impl std::fmt::Debug for Nip34WritePolicy { @@ -69,6 +71,7 @@ impl Nip34WritePolicy { state_policy: StatePolicy::new(ctx.clone()), pr_event_policy: PrEventPolicy::new(ctx.clone()), related_event_policy: RelatedEventPolicy::new(ctx.clone()), + deletion_policy: DeletionPolicy::new(ctx.clone()), ctx, } } @@ -521,6 +524,7 @@ impl WritePolicy for Nip34WritePolicy { ); WritePolicyResult::Accept } + Kind::EventDeletion => self.deletion_policy.handle(event).await, _ => self.handle_related_event(event, "Event").await, } }) -- cgit v1.2.3