NAME
Net::Nostr::Repost - NIP-18 reposts and generic reposts
SYNOPSIS
use Net::Nostr::Repost;
# Repost a kind 1 text note (creates kind 6)
my $repost = Net::Nostr::Repost->repost(
event => $note,
pubkey => $my_pubkey,
relay_url => 'wss://relay.example.com',
);
# Repost any other event (creates kind 16)
my $repost = Net::Nostr::Repost->repost(
event => $article,
pubkey => $my_pubkey,
relay_url => 'wss://relay.example.com',
);
# Quote repost (adds q tag)
my $repost = Net::Nostr::Repost->repost(
event => $note,
pubkey => $my_pubkey,
relay_url => 'wss://relay.example.com',
quote => 1,
);
# Parse repost structure from an event
my $info = Net::Nostr::Repost->from_event($event);
if ($info) {
say "Reposted event: " . $info->event_id;
say "From relay: " . $info->relay_url;
if ($info->embedded_event) {
say "Content: " . $info->embedded_event->content;
}
}
# Validate a repost event
Net::Nostr::Repost->validate($event);
DESCRIPTION
Implements NIP-18 reposts. A repost is a kind 6 event for sharing kind 1 text notes, or a kind 16 "generic repost" for sharing any other event kind.
The repost content is the stringified JSON of the reposted event (MAY be empty). Reposts of NIP-70-protected events SHOULD always have an empty content. Tags include an e tag with the event ID and relay URL (MUST), a p tag with the original author (SHOULD), and for generic reposts a k tag with the stringified kind (SHOULD) and an a tag with the event coordinate for addressable events (SHOULD).
Quote reposts use a q tag instead of being pulled into reply threads. The q tag format is ["q", "<event-id>", "<relay-url>", "<pubkey>"].
CONSTRUCTOR
new
my $info = Net::Nostr::Repost->new(%fields);
Creates a new Net::Nostr::Repost object. Typically returned by "from_event"; calling new directly is useful for testing or manual construction.
my $info = Net::Nostr::Repost->new(
event_id => 'aa' x 32,
relay_url => 'wss://relay.example.com',
);
Accepted fields: event_id, relay_url, author_pubkey, reposted_kind, event_coordinate, embedded_event, quote_event_id. Croaks on unknown arguments.
CLASS METHODS
repost
my $event = Net::Nostr::Repost->repost(
event => $original_event, # Net::Nostr::Event to repost
pubkey => $hex_pubkey, # reposter's hex pubkey
relay_url => 'wss://relay.example.com',
content => '', # optional, override content
quote => 1, # optional, add q tag
created_at => time(), # optional, passed to Event
);
Creates a repost Net::Nostr::Event. If the original event is kind 1, creates a kind 6 repost. Otherwise creates a kind 16 generic repost with a k tag and (for addressable events) an a tag.
The event parameter is the Net::Nostr::Event being reposted. The pubkey is the reposter's hex public key (the original author's pubkey is taken from the event's pubkey field for the p tag).
The content defaults to the stringified JSON of the original event. Pass content => '' to create a repost with empty content (e.g. for NIP-70-protected events).
Pass quote => 1 to add a q tag for quote reposts.
Returns a Net::Nostr::Event with the appropriate kind, tags, and content.
Croaks if event, pubkey, or relay_url is missing.
from_event
my $info = Net::Nostr::Repost->from_event($event);
Parses repost structure from a kind 6 or kind 16 Net::Nostr::Event. Returns a Net::Nostr::Repost object with accessors, or undef if the event is not a repost kind.
my $info = Net::Nostr::Repost->from_event($event);
say $info->event_id; # reposted event id
say $info->embedded_event->content if $info->embedded_event;
validate
Net::Nostr::Repost->validate($event);
Validates that a Net::Nostr::Event is a well-formed NIP-18 repost. Croaks if:
Kind is not 6 or 16
Missing
etagetag missing relay URL
eval { Net::Nostr::Repost->validate($event) };
warn "Invalid repost: $@" if $@;
ACCESSORS
These are available on objects returned by "from_event".
event_id
my $id = $info->event_id;
The ID of the reposted event (from the e tag).
relay_url
my $url = $info->relay_url;
The relay URL where the reposted event can be fetched (from the e tag).
author_pubkey
my $pk = $info->author_pubkey;
The pubkey of the original event author (from the p tag), or undef.
reposted_kind
my $kind = $info->reposted_kind; # '30023'
The stringified kind of the reposted event (from the k tag), or undef. Only present on kind 16 generic reposts.
event_coordinate
my $coord = $info->event_coordinate; # '30023:pubkey:d-tag'
The event coordinate (from the a tag), or undef. Only present when reposting addressable events.
embedded_event
my $event = $info->embedded_event; # Net::Nostr::Event or undef
The reposted event parsed from the repost's content field. Returns undef if the content is empty or cannot be parsed as a valid event.
quote_event_id
my $qid = $info->quote_event_id; # event id or undef
The quoted event ID (from the q tag), or undef. Present only when the repost is a quote repost.