Nostr. Event. ZapReceipt
(Nostr Lib v0.2.1)
(event)
(nip57)
View Source
Zap Receipt events (Kind 9735).
Implements NIP-57: https://github.com/nostr-protocol/nips/blob/master/57.md
A zap receipt is published by the recipient's lightning wallet after a zap request invoice has been paid. It serves as proof that a Lightning payment was made.
Required Tags
p- zap recipient pubkeybolt11- the paid Lightning invoicedescription- JSON-encoded zap request event
Optional Tags
P- zap sender pubkey (uppercase P)e- event that was zappeda- addressable event coordinatek- kind of the zapped eventpreimage- payment preimage
Validation
Per NIP-57 Appendix F, clients should validate:
- Receipt's pubkey matches the recipient's LNURL
nostrPubkey - Invoice amount matches the zap request's amount tag
- Receipt's lnurl tag (if present) matches recipient's lnurl
Examples
# Parse a zap receipt
{:ok, receipt} = ZapReceipt.parse(event)
# Get the zap amount
sats = ZapReceipt.get_amount_sats(receipt)
# Get the embedded zap request
{:ok, request} = ZapReceipt.get_zap_request(receipt)
Summary
Functions
Creates a zap receipt event.
Returns the zap amount in millisatoshis from the parsed invoice.
Returns the zap amount in satoshis from the parsed invoice.
Returns the parsed zap request from the description tag.
Parses a kind 9735 event into a ZapReceipt struct.
Serializes an event to JSON object format for use in the description tag.
Validates the zap receipt according to NIP-57 Appendix F.
Types
@type t() :: %Nostr.Event.ZapReceipt{ address: binary() | nil, bolt11: binary(), description: binary(), event: Nostr.Event.t(), event_id: binary() | nil, invoice: Nostr.Bolt11.t() | nil, kind: non_neg_integer() | nil, preimage: binary() | nil, recipient: binary(), sender: binary() | nil, zap_request: Nostr.Event.ZapRequest.t() | nil }
Functions
Creates a zap receipt event.
Required Options
:recipient- recipient pubkey (p tag):bolt11- the paid Lightning invoice:description- JSON-encoded zap request event
Optional Options
:sender- sender pubkey (P tag):event_id- event that was zapped (e tag):address- addressable event coordinate (a tag):kind- kind of the zapped event (k tag):preimage- payment preimage
Examples
ZapReceipt.create(
recipient: "recipient_pubkey",
bolt11: "lnbc...",
description: ~s({"kind":9734,...}),
sender: "sender_pubkey",
event_id: "zapped_event_id"
)
@spec get_amount_msats(t()) :: non_neg_integer() | nil
Returns the zap amount in millisatoshis from the parsed invoice.
@spec get_amount_sats(t()) :: non_neg_integer() | nil
Returns the zap amount in satoshis from the parsed invoice.
Returns nil if the invoice couldn't be parsed or has no amount.
@spec get_zap_request(t()) :: {:ok, Nostr.Event.ZapRequest.t()} | {:error, String.t()}
Returns the parsed zap request from the description tag.
Returns {:ok, zap_request} if successfully parsed, {:error, reason} otherwise.
@spec parse(Nostr.Event.t()) :: t() | {:error, String.t(), Nostr.Event.t()}
Parses a kind 9735 event into a ZapReceipt struct.
Automatically parses the embedded bolt11 invoice and zap request.
@spec serialize_event_to_json(Nostr.Event.t()) :: binary()
Serializes an event to JSON object format for use in the description tag.
This is different from Event.serialize/1 which returns array format for ID computation.
Validates the zap receipt according to NIP-57 Appendix F.
Validation Steps
- Receipt's pubkey must match the wallet's
nostrPubkey - Invoice amount must match the zap request's amount tag (if present)
- Zap request's lnurl tag (if present) should match recipient's lnurl
Returns :ok if valid, {:error, reason} otherwise.