Skip to main content

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:
The macaroon is a capability token bound to the invoice’s paymentHash. The preimage is the cryptographic secret released by the Lightning node when payment settles. The server verifies:
No account, no session, no JWT — the preimage is the proof of payment.

Invoice Creation Flow


Payment Verification Flow

Verification is O(1) — pure cryptography, no database lookup on the hot path. Replay protection (Supabase 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 a base64url-encoded JSON object:
This is simpler and auditable without any external library. The Authorization header format is:

Fee Model

Soberano mode is the default. Managed mode is an explicit opt-in:

Data Storage (optional — Supabase)

Set SUPABASE_URL + SUPABASE_ANON_KEY to log payments automatically:
Why 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 implements LightningProvider works: See the TypeScript SDK or Python SDK for provider setup.

Security Guarantees