NAME
Net::Nostr::AppData - NIP-78 Arbitrary Custom App Data
SYNOPSIS
use Net::Nostr::AppData;
# Store app-specific data
my $event = Net::Nostr::AppData->to_event(
pubkey => $pubkey,
d_tag => 'com.example.myapp/settings',
content => '{"theme":"dark","fontSize":14}',
);
# Store multiple normal app data events
my $entry = Net::Nostr::AppData->to_event(
pubkey => $pubkey,
kind => 78,
content => '{"entry":1}',
);
# Parse app data from an event
my $ad = Net::Nostr::AppData->from_event($event);
say $ad->d_tag; # com.example.myapp/settings
say $ad->content; # {"theme":"dark","fontSize":14}
# Validate
Net::Nostr::AppData->validate($event);
DESCRIPTION
Implements NIP-78 (Arbitrary Custom App Data). Provides remoteStorage-like capabilities for custom applications that do not care about interoperability.
Kind 30078 is the default addressable event form. The d tag contains a reference to the app name and context (or any other arbitrary string). Kind 78 is a normal event form for app data that should not replace prior events. The content and other tags can be anything or in any format.
Use cases include:
User personal settings on Nostr clients
Dynamic parameters propagated from client developers to users
Private data for apps that use Nostr relays as a personal database
CONSTRUCTOR
new
Accepts named arguments as either a flat list or a single hash reference.
my $ad = Net::Nostr::AppData->new(
kind => 30078,
d_tag => 'myapp-settings',
content => '{"theme":"dark"}',
);
Creates a new Net::Nostr::AppData object. All fields are optional. extra_tags defaults to []. Croaks on unknown arguments. Typically returned by "from_event".
CLASS METHODS
to_event
my $event = Net::Nostr::AppData->to_event(
pubkey => $hex_pubkey,
kind => 30078,
d_tag => 'com.example.myapp/settings',
content => '{"theme":"dark","fontSize":14}',
extra_tags => [['version', '2']],
created_at => time(),
);
Creates a NIP-78 Net::Nostr::Event. kind defaults to 30078; 78 may be supplied for normal app data events. d_tag is required for kind 30078 and optional for kind 78. content defaults to empty string. extra_tags, if provided, are appended after any d tag. Any remaining arguments are passed through to "new" in Net::Nostr::Event.
from_event
my $ad = Net::Nostr::AppData->from_event($event);
Parses a kind 78 or 30078 event into a Net::Nostr::AppData object. Returns undef if the event kind is not 78 or 30078.
my $ad = Net::Nostr::AppData->from_event($event);
say $ad->d_tag;
say $ad->content;
validate
Net::Nostr::AppData->validate($event);
Validates a NIP-78 event. Kind must be 78 or 30078. Kind 30078 requires a d tag; kind 78 does not. Croaks if invalid. Returns 1 on success.
eval { Net::Nostr::AppData->validate($event) };
warn "Invalid: $@" if $@;
ACCESSORS
kind
The app data event kind, 78 or 30078, when parsed from an event.
d_tag
The application identifier string from the d tag. Can be any arbitrary string referencing the app name and context.
content
The event content. Can be any format (JSON, plain text, etc.).
extra_tags
Arrayref of additional tags beyond the d tag. Can be anything in any format.