Payment Layer
l402-kit is a soberano middleware that adds a Bitcoin Lightning paywall to any HTTP endpoint in 3 lines of code. You bring your own Lightning provider — funds go directly to your wallet, no intermediary required.Protocol: L402
L402 is an open standard that extends HTTP/1.1 with a native payment handshake:paymentHash. The preimage is the cryptographic secret released by the Lightning node when payment settles. The server verifies:
Invoice Creation Flow
Payment Verification Flow
payment_hash logging) runs asynchronously and does not block the request.
Macaroon format
l402-kit uses a lightweight custom macaroon — not libmacaroon. The token is abase64url-encoded JSON object:
Authorization header format is:
Fee Model
| Mode | Fee | Setup |
|---|---|---|
| Soberano (any provider) | 0% — you keep 100% | Bring your own provider credentials |
Managed (ManagedProvider) | 0.3% to l402kit.com | No Lightning node — works immediately |
Data Storage (optional — Supabase)
SetSUPABASE_URL + SUPABASE_ANON_KEY to log payments automatically:
payment_hash instead of preimage? The payment_hash is already embedded in every BOLT11 invoice — it’s public by design. Only the preimage is secret. Storing the hash gives replay protection with zero additional exposure.
Lightning Providers
l402-kit is provider-agnostic. Any backend that implementsLightningProvider works:
| Provider | Notes |
|---|---|
| Alby Hub | Self-custodial, 0% fee |
| Blink | Free custodial, no KYC for small amounts |
| BTCPay Server | Self-hosted, full soberanoty |
| OpenNode | Custodial, no setup |
| LNbits | Self-hosted or cloud |
Security Guarantees
| Threat | Mitigation |
|---|---|
| Replay attack | Preimage marked used after first verification — in-memory or Redis adapter |
| Fake preimage | SHA256(preimage) === paymentHash is cryptographically unforgeable |
| Token expiry | Macaroon embeds exp timestamp — verified on every request |
| Webhook spoofing | HMAC-SHA256(secret, body) verified before processing |