NAME
Net::Nostr::Deletion - NIP-09 event deletion requests
SYNOPSIS
use Net::Nostr::Deletion;
# Create a deletion request
my $del = Net::Nostr::Deletion->new(reason => 'posted by accident');
$del->add_event($event_id, kind => 1);
$del->add_event($other_id, kind => 1);
$del->add_address("30023:$pubkey:my-article", kind => 30023);
my $event = $del->to_event(pubkey => $my_pubkey);
$key->sign_event($event);
$client->publish($event);
# Parse a received deletion request
my $del = Net::Nostr::Deletion->from_event($event);
say $del->reason;
say join ', ', @{$del->event_ids};
# Check if a deletion applies to a specific event
if ($del->applies_to($target_event, $deletion_event->pubkey)) {
# hide or delete the target event
}
DESCRIPTION
Implements NIP-09 event deletion requests. A deletion request is a kind 5 event containing e and/or a tags referencing events to be deleted, and k tags indicating the kinds of those events.
Deletion requests are just requests - relays and clients SHOULD honor them but there is no guarantee that events will be deleted from all relays.
CONSTRUCTOR
new
my $del = Net::Nostr::Deletion->new;
my $del = Net::Nostr::Deletion->new(reason => 'posted by accident');
Creates an empty deletion request. reason is optional and becomes the event's content field.
from_event
my $del = Net::Nostr::Deletion->from_event($event);
Parses a kind 5 event into a Deletion object. Croaks if the event is not kind 5.
my $del = Net::Nostr::Deletion->from_event($event);
for my $id (@{$del->event_ids}) {
say "delete: $id";
}
METHODS
add_event
$del->add_event($event_id, kind => 1);
Adds an event ID to the deletion request. kind is required and will be included as a k tag. Returns $self for chaining.
$del->add_event($id1, kind => 1)
->add_event($id2, kind => 1);
add_address
$del->add_address("30023:$pubkey:my-article", kind => 30023);
Adds an addressable event coordinate (a tag) to the deletion request. kind is required. Returns $self for chaining.
event_ids
my $ids = $del->event_ids; # arrayref
Returns the list of event IDs referenced by e tags.
addresses
my $addrs = $del->addresses; # arrayref
Returns the list of addressable event coordinates referenced by a tags.
reason
my $reason = $del->reason;
Returns the deletion reason (the event's content), or empty string.
to_event
my $event = $del->to_event(pubkey => $pubkey_hex);
my $event = $del->to_event(pubkey => $pubkey_hex, created_at => time());
Creates a kind 5 Net::Nostr::Event from the deletion request. Extra arguments are passed through to the Event constructor.
my $event = $del->to_event(pubkey => $key->pubkey_hex);
$key->sign_event($event);
applies_to
my $bool = $del->applies_to($target_event, $deletion_pubkey);
Returns true if this deletion request applies to the given event. Checks that:
The target event's pubkey matches the deletion request's pubkey
The target event's ID is referenced by an
etag, or its addressable coordinate is referenced by anatag
if ($del->applies_to($event, $del_event->pubkey)) {
# event should be hidden/deleted
}