UNDER DEVELOPMENT - DRAFT
Skip to main content
nostr101
Foundations track page 6 of 6 NIP-57 @ 656cecc

Zaps, and the Lightning underneath them

A zap is a Lightning payment that comes with a public receipt, written as a Nostr event, so a tip can show up under a post. The receipt is signed by the recipient's payment server, so it tells you what that server claims and gives you no proof by itself that the payment happened. This lesson follows the steps from a profile to a receipt, then sets out which parts of a receipt you can check and which you can only trust.

1 100 words5 min0 explainersSpec: NIP-57
Anchor text · read alongside terms stated per work · free online
NIP-57 · anchor
Nostr Implementation Possibilities (NIPs)
the contributors to nostr-protocol/nips
"Lightning Zaps" — the zap request (kind 9734), the zap receipt (kind 9735), the protocol flow, and the rules for validating a receipt. This lesson is a reading of it in teaching order.
Read the chapter →

From a profile to a receipt

A zap needs a request and a receipt. Lightning moves the money, and only the receipt is published to relays, so a receipt is a claim for you to weigh and not a proof of payment. The request goes to the recipient’s payment server, and NIP-57 says the receipt carries the request inside it. NIP-57 gives each a kind number. Kind 9734 is a zap request, “a payer’s request to a recipient’s lightning wallet for an invoice.” Kind 9735 is a zap receipt, “the confirmation by the recipient’s lightning wallet that the invoice issued in response to a zap request has been paid.” The address format and the pay request come from the LNURL specifications, which live outside the NIPs repository.1

Stepper · a zap, step by step 6 steps
  1. 01 The client finds the recipient's payment endpoint The profile has a lud16 field, a Lightning address of the form name@domain. LUD-16 says a wallet then makes a GET request to https://domain/.well-known/lnurlp/name. The reply follows LUD-06: a callback address, a minimum and maximum amount in millisatoshis, and metadata. A server that supports zaps adds allowsNostr set to true and a nostrPubkey, the key it will use to sign receipts. GET https://domain/.well-known/lnurlp/name → { "callback": "…", "minSendable": …, "maxSendable": …, "allowsNostr": true, "nostrPubkey": "…" }
  2. 02 The sender's client signs a zap request The request is a kind 9734 event with a p tag for the recipient, an optional e tag for the note being zapped, a relays tag that lists where the receipt should be published, and an optional amount in millisatoshis. NIP-57 says it is "not published to relays." { "kind": 9734, "tags": [["relays","wss://…"],["amount","…"],["p","<recipient>"],["e","<note id>"]], … }
  3. 03 The client sends the request to the callback address It is an HTTP GET with the amount, the lnurl and the request itself, JSON encoded and then URI encoded, in a query parameter named nostr. The server must check that the signature is valid, that there is exactly one p tag, and that any amount tag equals the amount parameter. GET <callback>?amount=…&nostr=<encoded 9734 event>&lnurl=…
  4. 04 The server returns a Lightning invoice The server should fetch a description-hash invoice whose description is the zap request and nothing else. The JSON reply carries it under the key pr. { "pr": "lnbc…" }
  5. 05 The sender's wallet pays the invoice The payment itself travels over Lightning, not over relays. pay(pr)
  6. 06 The server publishes the receipt Once it sees the invoice paid, the recipient's server "MUST generate a zap receipt" and publish it to the relays listed in the request. It signs the receipt with the key it advertised as nostrPubkey. { "kind": 9735, "pubkey": "<nostrPubkey>", "tags": [["p","…"],["bolt11","lnbc…"],["description","<the 9734 JSON>"],["preimage","…"]], … }

Without JavaScript every step is expanded: the block reads as six numbered paragraphs with their messages, which is also what prints.

The Lightning underneath

The invoice in step 4 follows BOLT 11. Two of its fields matter here. The p field holds the payment hash, and BOLT 11 says “preimage of this provides proof of payment.” The h field holds a SHA-256 hash of the description, which commits the invoice to one exact piece of text. In a zap, that text is the signed zap request, so changing one character of the request gives a hash that no longer matches the description.

When the sender’s wallet pays, the payment moves as hashed time-locked contracts (HTLCs). The BOLT specifications define an HTLC as “a conditional payment between two peers: the recipient can spend the payment by presenting its signature and a payment preimage, otherwise the payer can cancel the contract by spending it after a given time.” BOLT 2 says a node offers HTLCs “to initiate a payment of its own, or to forward another node’s payment.” When the final recipient claims the payment, the preimage is passed back with update_fulfill_htlc, and a forwarding node that receives it “MUST fulfill the incoming HTLC.”2

The preimage matters here because it never reaches the relays on its own. The payment, the hash and the preimage all live on Lightning. The receipt is a separate Nostr event that points back at them.

What a receipt shows

Appendix F of NIP-57 lists three checks for a client, and Appendix E adds a fourth rule about the description:

CheckRule in NIP-57What a pass shows
The receipt’s pubkey equals the nostrPubkey from the recipient’s LNURL endpoint“MUST”The key that the recipient’s server advertised signed this receipt
The amount in the bolt11 tag equals the amount tag of the request, if present“MUST”The invoice is for the amount the sender asked for
The request’s lnurl tag equals the recipient’s LNURL, if present“SHOULD”The request was for this recipient’s endpoint
The SHA-256 of the description tag matches the invoice’s description hash“SHOULD”The invoice was built for this exact request

Each check compares the receipt with the request or with the recipient’s endpoint, and none looks at the Lightning network. A pass shows that the receipt is consistent and that the key the endpoint advertised signed it.

What a receipt cannot show

The NIP says it plainly: “The zap receipt is not a proof of payment, all it proves is that some nostr user fetched an invoice. The existence of the zap receipt implies the invoice as paid, but it could be a lie given a rogue implementation.”

So a reader cannot confirm from a receipt that the invoice was paid. The preimage tag does not change that. NIP-57 makes the tag optional (“MAY”). It says “This isn’t really a payment proof, there is no real way to prove that the invoice is real or has been paid,” and adds “You are trusting the author of the zap receipt for the legitimacy of the payment.” A reader can hash the preimage and compare the result with the payment hash inside the bolt11 invoice, but the invoice writer chooses the preimage before any payment, so a matching value does not show that a payment came first.3

The same gap covers the sender. The receipt includes the signed zap request, and if the client checks the signature on that embedded request, a valid one shows that the sender’s key asked for the invoice. NIP-57 Appendix F does not require that check. NIP-57 does not tie the Lightning payer to that key, so a reader cannot tell that the person behind the key paid.

A third gap concerns what you can see at all. The server publishes the receipt to the relays listed in the request, and it is an ordinary event, so it follows the rules from the relays lesson. A paid zap can be missing from your client’s view.

What this means in use

Treat a zap total as a count of claims by payment servers. A receipt shows what the signing server claims about who asked for an invoice and for how much. To settle whether a particular payment happened, ask the sender, who can check the paying wallet, or ask the recipient, whose wallet shows what arrived. Both checks happen outside Nostr.

An event can also carry zap tags that name several recipients, each with an optional weight, and a client should split the zap by those weights (NIP-57, Appendix G). The trust question applies to each recipient’s server.

This is the last page of the foundations track. The NIP index lists every NIP this track mentioned.

Notes

  1. LUD-06 and LUD-16 belong to the LNURL specifications, which live outside the NIPs repository. NIP-57 points to them for the address format and the pay request, and this page quotes only what those two documents say.LNURL specifications
  2. This is our reading of two texts, not a sentence from either. BOLT 11 says the invoice writer sets the payment hash to the hash of "the payment_preimage that will be given in return for payment," so the invoice writer chooses the preimage before any payment. NIP-57 says the receipt publisher can be a "rogue implementation."BOLT 11
  3. The ln.university Fundamentals track lists a lesson called "An HTLC, in full." It is named here in plain text because the two sites do not link to each other.

Source & license

This page adapts no licensed material. It is original work by Delta Gamma LLC and is published under CC BY-SA 4.0; the figures it reports are separately dedicated to the public domain, below.

nostr101 adds no normative claims. Where this page and a NIP disagree, the NIP is correct and this page is a bug. Every page states the revision it was written against: NIP-57 @ 656cecc.

Numbers, titles and kind assignments come from the NIPs repository and belong to its contributors, who state that all NIPs are public domain. This page asserts no license over that text. Its own prose is CC BY-SA 4.0; attribute to nostr101.com and to the NIPs contributors.