create-fedi-app
Modules

lnurl

Optional module — LNURL-pay, LNURL-auth, and LNURL-withdraw callback routes with demo UI at /demo/lnurl.

Implements the three common LNURL subprotocols as API routes plus React demo components. Useful for Lightning addresses, login-with-Lightning, and faucet-style withdraw flows.

Files added

FilePurpose
lib/lnurl-utils.tsEncode/decode LNURL, callback URL helpers
lib/lnurl-store.tsIn-memory store for auth challenges, withdraw links
lib/lnurl-auth-verify.tsLNURL-auth signature verification
components/lnurl/LnurlQR.tsxQR code for LNURL strings
components/lnurl/LnurlPay.tsxLNURL-pay flow demo
components/lnurl/LnurlAuth.tsxLNURL-auth login demo
components/lnurl/LnurlWithdraw.tsxLNURL-withdraw demo
app/api/lnurlp/[username]/route.tsLNURL-pay endpoint
app/api/lnurlauth/route.tsLNURL-auth endpoint
app/api/lnurlw/route.tsLNURL-withdraw endpoint
app/demo/lnurl/page.tsxCombined demo

Dependencies

  • qrcode.react

Environment variables

KeyRequiredDescription
LNURL_SERVER_URLnoPublic base URL for callbacks (required behind reverse proxies)

Set to your production URL when deployed — LNURL callbacks must be reachable from the Lightning network.

LNURL-pay

GET /api/lnurlp/[username]

Returns LNURL-pay metadata JSON per LUD-06:

{
  "callback": "https://your-app.com/api/lnurlp/alice?amount=...",
  "maxSendable": 1000000000,
  "minSendable": 1000,
  "metadata": "[[\"text/plain\",\"Pay alice\"]]",
  "tag": "payRequest"
}

Client decodes lnurl1... bech32, fetches metadata, then pays via WebLN.

LNURL-auth

GET /api/lnurlauth

Issues a k1 challenge. Wallet signs k1 with node key via WebLN signMessage.

POST verification

Server verifies signature against k1, issues session token.

LNURL-withdraw

GET /api/lnurlw

Returns withdraw parameters. Client creates invoice via WebLN makeInvoice, submits to callback URL.

LnurlWithdraw component

Demonstrates the withdraw loop:

  1. Display withdraw LNURL QR
  2. User scans with wallet (or mock via WebLN in Fedi)
  3. Wallet creates invoice, server pays out

Shows error when WebLN unavailable: "Open inside Fedi to create a withdraw invoice."

Demo route

/demo/lnurl — tabbed UI for pay, auth, and withdraw flows.

See also

On this page