NAME

Net::Nostr::MintDiscovery - NIP-87 Ecash Mint Discoverability

SYNOPSIS

use Net::Nostr::MintDiscovery;

# Recommend a mint (kind 38000)
my $event = Net::Nostr::MintDiscovery->recommendation(
    pubkey     => $hex_pubkey,
    identifier => 'my-rec',
    mint_kind  => '38173',
    urls       => [['fed11abc..', 'fedimint']],
    mint_refs  => [["38173:$mint_pk:fed-id", 'wss://relay1']],
    content    => 'I trust this mint with my life',
);

# Cashu mint information (kind 38172)
my $event = Net::Nostr::MintDiscovery->cashu_mint(
    pubkey     => $hex_pubkey,
    identifier => $mint_pubkey,
    urls       => ['https://cashu.example.com'],
    nuts       => '1,2,3,4,5,6,7',
    network    => 'mainnet',
);

# Fedimint information (kind 38173)
my $event = Net::Nostr::MintDiscovery->fedimint(
    pubkey     => $hex_pubkey,
    identifier => $federation_id,
    urls       => ['fed11abc..', 'fed11xyz..'],
    modules    => 'lightning,wallet,mint',
    network    => 'signet',
);

# Parse any mint discovery event
my $parsed = Net::Nostr::MintDiscovery->from_event($event);

# Validate
Net::Nostr::MintDiscovery->validate($event);

DESCRIPTION

Implements NIP-87 (Ecash Mint Discoverability). Three event kinds are used:

  • Recommendation (kind 38000) - A parameterized-replaceable event recommending an ecash mint. Contains a k tag indicating the recommended mint kind (38172 or 38173), optional u tags with URLs or invite codes, and a tags pointing to mint info events.

  • Cashu Mint (kind 38172) - Announces a Cashu mint's capabilities. The d tag SHOULD be the mint's pubkey. Lists supported NUTs via a nuts tag.

  • Fedimint (kind 38173) - Announces a Fedimint's capabilities. The d tag SHOULD be the federation ID. Lists invite codes via u tags and supported modules via a modules tag.

All three kinds are addressable.

CONSTRUCTOR

new

my $mint = Net::Nostr::MintDiscovery->new(
    identifier => 'mint-id',
);

Creates a new Net::Nostr::MintDiscovery object. Croaks on unknown arguments. Array fields default to []. description defaults to ''.

CLASS METHODS

recommendation

my $event = Net::Nostr::MintDiscovery->recommendation(
    pubkey     => $hex_pubkey,          # required
    identifier => $id,                  # required (d tag)
    mint_kind  => '38173',              # required (k tag)
    urls       => [[$url, $type]],      # optional (u tags; $type optional)
    mint_refs  => [[$coord, $relay, $type]], # optional (a tags; $type optional)
    content    => $review,              # optional, defaults to ''
);

Creates a kind 38000 recommendation Net::Nostr::Event. The k tag indicates which mint kind is being recommended (38172 for Cashu, 38173 for Fedimint). urls entries are arrayrefs of [$url_or_invite] or [$url_or_invite, $type]. mint_refs entries are arrayrefs of [$coord, $relay_hint] or [$coord, $relay_hint, $type].

cashu_mint

my $event = Net::Nostr::MintDiscovery->cashu_mint(
    pubkey     => $hex_pubkey,          # required
    identifier => $mint_pubkey,         # required (d tag)
    urls       => [$url],               # optional (u tags)
    nuts       => '1,2,3,4,5,6,7',     # optional (nuts tag)
    network    => 'mainnet',            # optional (n tag)
    content    => $metadata_json,       # optional, defaults to ''
);

Creates a kind 38172 Cashu mint info Net::Nostr::Event. The d tag SHOULD be the mint's pubkey (from /v1/info). The u tag SHOULD be the URL to the Cashu mint. nuts is a comma-separated list of supported NUT numbers. network is one of mainnet, testnet, signet, or regtest. content may contain stringified JSON metadata (kind 0 style).

fedimint

my $event = Net::Nostr::MintDiscovery->fedimint(
    pubkey     => $hex_pubkey,          # required
    identifier => $federation_id,       # required (d tag)
    urls       => [$invite_code],       # optional (u tags)
    modules    => 'lightning,wallet',   # optional (modules tag)
    network    => 'signet',             # optional (n tag)
    content    => $metadata_json,       # optional, defaults to ''
);

Creates a kind 38173 Fedimint info Net::Nostr::Event. The d tag SHOULD be the federation ID. urls lists known Fedimint invite codes. modules is a comma-separated list of supported modules. network is one of mainnet, testnet, signet, or regtest. content may contain stringified JSON metadata (kind 0 style).

from_event

my $mint = Net::Nostr::MintDiscovery->from_event($event);

Parses a kind 38000, 38172, or 38173 event into a Net::Nostr::MintDiscovery object. Returns undef for unrecognized kinds.

validate

Net::Nostr::MintDiscovery->validate($event);

Validates a NIP-87 event. Croaks if:

  • Kind is not 38000, 38172, or 38173

  • Kind 38000 missing d or k tag

  • Kind 38172/38173 missing d tag

Returns 1 on success.

ACCESSORS

identifier

The d tag value. For recommendations, this is the mint event identifier. For Cashu mints, this SHOULD be the mint's pubkey. For Fedimints, this SHOULD be the federation ID.

mint_kind

The k tag value (recommendation only). Either 38172 or 38173.

urls

For recommendations: arrayref of arrayrefs [$url_or_invite] or [$url_or_invite, $type] from u tags. For mint info events: arrayref of URL/invite code strings. Defaults to [].

mint_refs

Arrayref of arrayrefs from a tags (recommendation only). Each contains [$coord, $relay_hint] or [$coord, $relay_hint, $type]. Defaults to [].

nuts

Comma-separated list of supported NUT numbers (Cashu mint only).

modules

Comma-separated list of supported modules (Fedimint only).

network

Network identifier: mainnet, testnet, signet, or regtest.

description

The event content. For recommendations, this is a review. For mint info events, this may be stringified JSON metadata. Defaults to ''.

SEE ALSO

NIP-87, Net::Nostr, Net::Nostr::Event