x402
x402 copied to clipboard
Feature/exact btc lightning
Description
This PR adds a BTC Lightning implementation of the exact scheme and exposes it through the demo site.
TypeScript SDK (typescript/packages/x402)
- Implement
exact/btc_lightningscheme with client + facilitator helpers - Export the BTC Lightning exact scheme from the main
schemes/exactentry point - Add tests covering BTC Lightning client/facilitator behavior
Demo site (site/)
- Add LND-backed Lightning integration via
app/facilitator/lightning-lnd.ts- Uses
LND_REST_URL,LND_MACAROON_HEX, andLIGHTNING_NETWORKenv vars - Supports
exactscheme on BTC Lightning networks (e.g.btc-lightning-signet)
- Uses
- Add
/examples/lightningAPI route:- On missing/invalid
X-PAYMENTheader: returns HTTP402with x402PaymentRequirementsfor BTC Lightning - On valid, settled payment: returns HTTP
200with demo payload (message, network, transaction, sats, random number)
- On missing/invalid
- Add
/examples/lightning-demopage:- Calls
/examples/lightningto fetch payment requirements - Lets the user paste a BOLT11 invoice from their Lightning wallet
- Sends the invoice in the
X-PAYMENTheader using the BTC Lightningexactscheme - Displays error states for unpaid/invalid invoices and a success UI once the invoice is settled
- Calls
Docs
- Update
site/README.mdto describe:- BTC Lightning
exactscheme demo - LND facilitator configuration and env vars
- End-to-end Lightning payment flow (verify + settle) behind
/examples/lightningand/examples/lightning-demo
- BTC Lightning
Tests
Automated
pnpm testfrom/typescriptpnpm format && pnpm lintfrom/typescriptcd site && pnpm lint
Manual sanity tests
Facilitator / Lightning
- Started LND on the target network (e.g. signet) with REST + macaroon configured
- Set
LND_REST_URL,LND_MACAROON_HEX, andLIGHTNING_NETWORKinsite/.env.local - Hit
/facilitatorendpoints and confirmed invalid inputs produce structured x402 errors (no500responses)
/examples/lightning API
GET /examples/lightningwithoutX-PAYMENT:- Returns
402withx402Versionand at least oneaccepts[]entry accepts[0].scheme === "exact"accepts[0].network === LIGHTNING_NETWORK(e.g.btc-lightning-signet)maxAmountRequiredmatches the expected sats amount
- Returns
GET /examples/lightningwith an invalid or unpaid BOLT11 invoice inX-PAYMENT:- Returns
402with anerror/invalidReason - No server crash or unhandled error
- Returns
/examples/lightning-demo UI
- Started dev server with
cd site && pnpm dev - Visited
/examples/lightning-demo:- Saw “Loading payment requirements…” followed by the “Payment requirements” card
- Network and amount matched
/examples/lightningresponse
- Pasted an unpaid but otherwise valid BOLT11 invoice:
- Clicked “Send payment & retry”
- Got a “Payment not accepted yet” error and stayed in the
needsPaymentstate
- Paid the same invoice from a Lightning wallet:
- Clicked “Send payment & retry” again
- Got
200from/examples/lightningand saw the “Access granted” card showing:- Message
- Network
- Transaction
- Amount in sats
- Random number from the demo payload
- Tried invalid input (wrong network / garbage string):
- UI showed an appropriate error
- No 500s or crashes in the terminal
Checklist
- [x] I have formatted and linted my code
- [x] All new and existing tests pass
- [x] My commits are signed (required for merge)
🟡 Heimdall Review Status
| Requirement | Status | More Info | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reviews |
🟡
0/1
|
Denominator calculation
|
@jllauwers is attempting to deploy a commit to the Coinbase Team on Vercel.
A member of the Team first needs to authorize it.