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
Soberano mode is the default. Managed mode is an explicit opt-in:
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:
See the TypeScript SDK or Python SDK for provider setup.