NAME
Net::Nostr::Wiki - NIP-54 Wiki
SYNOPSIS
use Net::Nostr::Wiki;
# Wiki article (kind 30818)
my $event = Net::Nostr::Wiki->article(
pubkey => $hex_pubkey,
identifier => 'Wiki Article',
title => 'Wiki Article',
content => 'A wiki is a hypertext publication.',
);
# Merge request (kind 818)
my $event = Net::Nostr::Wiki->merge_request(
pubkey => $hex_pubkey,
target => "30818:$dest_pk:bitcoin",
target_relay => 'wss://relay.com',
source => $source_event_id,
source_relay => 'wss://relay.com',
destination => $dest_pk,
content => 'Added block size info',
);
# Wiki redirect (kind 30819)
my $event = Net::Nostr::Wiki->redirect(
pubkey => $hex_pubkey,
identifier => 'btc',
target => "30818:$pk:bitcoin",
target_relay => 'wss://relay.com',
);
# Normalize a d tag
my $dtag = Net::Nostr::Wiki->normalize_dtag('Wiki Article');
# "wiki-article"
# Parse any wiki event
my $parsed = Net::Nostr::Wiki->from_event($event);
# Validate
Net::Nostr::Wiki->validate($event);
# Resolve wikilinks in Djot content
my $resolved = Net::Nostr::Wiki->resolve_wikilinks('[cryptocurrency][]');
DESCRIPTION
Implements NIP-54 (Wiki). Three event kinds are used:
Wiki Article (kind 30818) - An addressable event for encyclopedia entries. Articles are identified by lowercase, normalized
dtags. Content should be Djot with NIP-21 links and wikilinks. Multiple people may write articles about the same subject.Merge Request (kind 818) - A regular event requesting a merge from a forked article into the source. Directed to a pubkey, references the original article and the modified version. The destination pubkey can accept or reject via NIP-25 reactions.
Wiki Redirect (kind 30819) - An addressable event that redirects one article name to another. Useful for disambiguation and alternative names.
Articles support fork and defer markers on a and e tags. Fork markers indicate the article was derived from another version. Defer markers indicate the author considers another entry as a better version of their own.
CONSTANTS
WIKI_RELAY_LIST_KIND
use Net::Nostr::Wiki;
my $kind = Net::Nostr::Wiki::WIKI_RELAY_LIST_KIND; # 10102
NIP-51 list kind for wiki-specific relay lists. Clients can create kind 10102 lists to indicate preferred relays for wiki content.
CONSTRUCTOR
new
my $w = Net::Nostr::Wiki->new(
identifier => 'bitcoin',
title => 'Bitcoin',
);
Creates a new Net::Nostr::Wiki object. Croaks on unknown arguments.
CLASS METHODS
article
my $event = Net::Nostr::Wiki->article(
pubkey => $hex_pubkey, # required
identifier => $name, # required (d tag, auto-normalized)
content => $djot_content, # required
title => $display_title, # optional
summary => $description, # optional
fork_a => [$coord, $relay], # optional (a tag with fork marker)
fork_e => [$id, $relay], # optional (e tag with fork marker)
defer_a => [$coord, $relay], # optional (a tag with defer marker)
defer_e => [$id, $relay], # optional (e tag with defer marker)
);
Creates a kind 30818 wiki article Net::Nostr::Event. The identifier is automatically normalized per the NIP-54 d tag normalization rules.
merge_request
my $event = Net::Nostr::Wiki->merge_request(
pubkey => $hex_pubkey, # required
target => $article_coord, # required (a tag)
target_relay => $relay_url, # optional
source => $event_id, # required (e tag with source marker)
source_relay => $relay_url, # optional
destination => $dest_pubkey, # required (p tag)
base_version => $event_id, # optional (e tag, version base)
base_relay => $relay_url, # optional
content => $explanation, # optional, defaults to ''
);
Creates a kind 818 merge request Net::Nostr::Event. The source event ID MUST be of a kind 30818 event.
redirect
my $event = Net::Nostr::Wiki->redirect(
pubkey => $hex_pubkey, # required
identifier => $source_name, # required (d tag, auto-normalized)
target => $article_coord, # required (a tag)
target_relay => $relay_url, # optional
);
Creates a kind 30819 wiki redirect Net::Nostr::Event. The identifier is automatically normalized. Content is always empty.
normalize_dtag
my $normalized = Net::Nostr::Wiki->normalize_dtag('Wiki Article');
# "wiki-article"
Normalizes a string per NIP-54 rules:
Lowercase all letters
Whitespace converted to
-Punctuation and symbols removed
Consecutive
-collapsedLeading/trailing
-removedNon-ASCII letters preserved as UTF-8
Numbers preserved
from_event
my $w = Net::Nostr::Wiki->from_event($event);
Parses a kind 30818, 818, or 30819 event into a Net::Nostr::Wiki object. Returns undef for unrecognized kinds.
validate
Net::Nostr::Wiki->validate($event);
Validates a NIP-54 event. Croaks if:
Kind is not 30818, 818, or 30819
Kind 30818 missing
dtagKind 818 missing
a,p, oretag withsourcemarkerKind 30819 missing
doratag
Returns 1 on success.
resolve_wikilinks
my $resolved = Net::Nostr::Wiki->resolve_wikilinks($djot_content);
Resolves reference-style links in Djot content to wiki article links. Links with defined references ([label]: target at end of content) are preserved. Undefined reference-style links become wikilinks using nostr:30818:normalized-name URIs.
Handles both implicit ([text][]) and explicit ([text][Label]) reference-style links.
ACCESSORS
identifier
The normalized d tag value (kinds 30818, 30819).
title
Display title from title tag (kind 30818).
summary
Description from summary tag (kind 30818).
fork_a
Arrayref [$coord, $relay] from a tag with fork marker.
fork_e
Arrayref [$id, $relay] from e tag with fork marker.
defer_a
Arrayref [$coord, $relay] from a tag with defer marker.
defer_e
Arrayref [$id, $relay] from e tag with defer marker.
target
The article coordinate from a tag (kinds 818, 30819).
target_relay
Relay hint from a tag (kinds 818, 30819).
destination
Destination pubkey from p tag (kind 818).
source
Source event ID from e tag with source marker (kind 818).
source_relay
Relay from e tag with source marker (kind 818).
base_version
Base version event ID from e tag without marker (kind 818).
base_relay
Relay from base version e tag (kind 818).