L402 — Lightning Network
Pay for oracle attestations with Lightning sats. Native Bitcoin integration for wallets, nodes, and Lightning-enabled applications.
L402 (formerly LSAT) is an HTTP payment protocol: the server answers 402 with a Lightning invoice and a macaroon, the client pays the invoice, and retries with the macaroon and the payment preimage as proof. The response is the same Ed25519-signed attestation the x402 rail returns.
L402 is served under https://api.myceliasignal.com/l402/<path>. The same paths without /l402/ are x402 (USDC on Base) only and answer with an x402 challenge, not an L402 one. Every L402 endpoint and its price is listed in /.well-known/l402.
How It Works
Request an oracle endpoint under /l402/
Send a GET request to any L402 endpoint. No credentials, no account.
curl -i https://api.myceliasignal.com/l402/oracle/price/btc/usd
Receive 402 with invoice and macaroon
The server responds with HTTP 402. The WWW-Authenticate header carries the challenge: a standard-base64 v2 macaroon and a BOLT 11 invoice.
HTTP/2 402 WWW-Authenticate: L402 macaroon="AgERbXljZWxp...", invoice="lnbc100n1p..."
The macaroon's identifier carries the invoice's payment hash; its caveats bind it to this path and to an expiry. The invoice amount is the endpoint's price in sats. The invoice and the macaroon both expire after 300 seconds — pay and retry within that window.
Pay the Lightning invoice
Pay the BOLT 11 invoice from any Lightning wallet or node. Keep the preimage from the payment result — it is your proof of payment.
You need the preimage (also called the payment proof). Without it you cannot authenticate. Most Lightning libraries and wallets return it with the payment, or show it in the payment's details.
# Pay the invoice and extract the preimage
lncli payinvoice --json lnbc100n1p... | jq -r '.payment_preimage'
Retry with L402 credentials
Resend the request to the same /l402/ path with an Authorization header: the macaroon and the preimage, separated by a colon.
curl https://api.myceliasignal.com/l402/oracle/price/btc/usd \ -H "Authorization: L402 <macaroon_base64>:<preimage_hex>"
The proxy checks the macaroon's signature and caveats (path and expiry), takes the payment hash from its identifier, and asks the Lightning node (phoenixd) whether that invoice has been paid.
Receive the signed attestation
On success the response is HTTP 200 with the signed payload. The signature is Ed25519 over the bytes of the canonical string (not over a hash of it), hex-encoded, under the 32-byte public key in pubkey.
{
"canonical": "v1|PRICE|BTCUSD|83185.35|USD|2|binance,binance_us,bitfinex,...|median|1792507281|223948",
"domain": "BTCUSD",
"price": "83185.35",
"pubkey": "f4f0e52b5f7b54831f965632bf1ebf72769beda4c4e3d36a593f7729ec812615",
"signature": "<128 hex characters, Ed25519>"
}
Both rails return the same canonical format signed with Ed25519, and the verification code is the same for both. Each signing node has its own key; accept only the keys published at /docs/keys/, never a key merely because the response supplies it. The DLC oracle is the exception: its attestations are BIP-340 Schnorr over secp256k1, with a separate key (see Endpoints).
Programmatic Integration (Python)
import httpx, re from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey L402 = "https://api.myceliasignal.com/l402" # Published Ed25519 keys, one per signing node (see /docs/keys/) KEYS = {"f4f0e52b5f7b54831f965632bf1ebf72769beda4c4e3d36a593f7729ec812615", # US node "7ab07fbe7d08cd16823e5eb0db0e21f3f38e9366d5fd00d14e95df0fb9b51a1a"} # Asia node def parse_l402_challenge(www_auth: str) -> tuple[str, str]: """Macaroon and invoice from the WWW-Authenticate header.""" mac = re.search(r'macaroon="([^"]+)"', www_auth).group(1) inv = re.search(r'invoice="([^"]+)"', www_auth).group(1) return mac, inv def query_oracle_l402(path: str, pay_invoice_fn) -> dict: """path like "/oracle/price/btc/usd". pay_invoice_fn takes a BOLT11 invoice and returns the payment preimage as hex.""" url = L402 + path with httpx.Client(timeout=15) as client: # Step 1: get the 402 challenge resp = client.get(url) if resp.status_code != 402: raise Exception(f"Expected 402, got {resp.status_code}") macaroon, invoice = parse_l402_challenge(resp.headers["WWW-Authenticate"]) # Step 2: pay the invoice (your Lightning wallet or node) -- within 300 s preimage = pay_invoice_fn(invoice) # Step 3: retry with L402 credentials resp = client.get(url, headers={"Authorization": f"L402 {macaroon}:{preimage}"}) if resp.status_code != 200: raise Exception(f"Auth failed: {resp.status_code} {resp.text}") data = resp.json() # Step 4: verify the Ed25519 signature over the canonical string's bytes if data["pubkey"] not in KEYS: raise Exception("signed by an unpublished key") Ed25519PublicKey.from_public_bytes(bytes.fromhex(data["pubkey"])).verify( bytes.fromhex(data["signature"]), data["canonical"].encode()) # v1|PRICE|PAIR|PRICE|CURRENCY|DECIMALS|SOURCES|METHOD|TIMESTAMP|NONCE f = data["canonical"].split("|") return {"price": f[3], "sources": f[6].split(","), "timestamp": int(f[8]), "verified": True}
Other attestation types use their own canonical layouts; see Canonical Format. The signature check is the same for all of them.
Pricing
The authoritative list of L402 endpoints and prices is /.well-known/l402. By type:
| Endpoint Type | Lightning Amount |
|---|---|
| Spot pairs (BTC/USD, ETH/USD, etc.) | 10 sats |
| VWAP (BTC/USD VWAP) | 20 sats |
| Stablecoins (USDC/USD, USDT/USD, etc.) | 10 sats |
| FX pairs (EUR/USD, GBP/USD, etc.) | 10 sats |
| Gold (XAU/USD, XAU/EUR, XAU/JPY) | 10 sats |
| Gas — single chain | 10 sats |
| Gas — cross-chain index | 50 sats |
| Marine — sea state | 100 sats |
| Marine — route summary | 200 sats |
| Marine — vessel tracking | 500 sats |
| Marine — voyage forecast | 500 sats |
| Weather (WRSI, rainfall, temperature, wind) | 100 sats |
| MSVI (volatility), MSXI (sentiment), MSSI (stress) | 500 sats |
| Synopsis — BTC, ETH or SOL | 500 sats |
| Synopsis — market | 1,000 sats |
| Equity regime composite, sector rotation | 1,000 sats |
| COT (CFTC positioning) | 1,000 sats |
| Economic indicators (US, EU) | 1,000 sats |
| Commodities | 1,000 sats |
| DLC threshold contract (POST) | 10,000 sats |
Authentication Details
What the proxy checks
1. The macaroon's signature, and its caveats: the request path must match, and the expiry must not have passed.
2. The payment hash in the macaroon's identifier, against the Lightning node: the invoice must be paid.
3. If both hold, the request goes to the oracle backend and its signed response is returned.
A macaroon and preimage are valid for one path for 300 seconds after the challenge was issued. Within that window the same credentials can be presented again for that path; after it, request a new challenge. The invoice expires at the same time, so a payment can never settle for a token that has already expired.
Rejected credentials
An invalid, expired or unpaid token gets HTTP 402 with a fresh challenge in WWW-Authenticate and the body {"error":"invalid token or unpaid invoice", ...}. Pay the new invoice and retry, or check that the preimage belongs to the invoice you paid.
Authorization Header Format
Authorization: L402 <macaroon_base64>:<preimage_hex>
The macaroon exactly as received in WWW-Authenticate (standard base64); the preimage hex-encoded, as most Lightning implementations return it. The legacy LSAT prefix is also accepted.
The DLC oracle (/l402/dlc/...) issues its own L402 challenges: a v1 macaroon in base64url with a 30-minute expiry, and a JSON 402 body that offers both rails. Its paid operations are POST. Treat the macaroon as an opaque string and send it back exactly as received.
Lightning Node Requirements
To use L402, you need the ability to pay Lightning invoices programmatically. Common options:
| Implementation | Language | Notes |
|---|---|---|
LND (lncli / gRPC / REST) | Go / any | Most common. Use sendpayment and extract payment_preimage |
CLN (lightning-cli) | C / any | Use pay command, preimage in response |
| phoenixd | REST API | payinvoice returns the preimage |
| LDK | Rust | Embedded Lightning node library |
| Breez SDK | Dart / Kotlin / Swift | Mobile-friendly, non-custodial |
| LNbits / Alby | REST API | Custodial — simpler but trust tradeoff |
L402 Protocol Details
| Parameter | Value |
|---|---|
| Protocol | L402 (formerly LSAT) |
| Base URL | https://api.myceliasignal.com/l402/ |
| Invoice format | BOLT 11, Bitcoin mainnet |
| Challenge lifetime | 300 s (invoice and macaroon) |
| Macaroon | v2 binary, standard base64 (gopkg.in/macaroon.v2); caveats path= and expires= |
| Lightning node | phoenixd |
| Signing scheme | Ed25519 over the canonical string's bytes |
| Public key format | 32-byte hex |
Choosing Between L402 and x402
| L402 (Lightning) | x402 (USDC on Base) | |
|---|---|---|
| Path | /l402/oracle/... | /oracle/... |
| Best for | Bitcoin-native apps, Lightning wallets | AI agents, EVM apps, stablecoin workflows |
| Payment speed | Seconds (Lightning) | ~2 seconds (Base L2 confirmation) |
| Currency risk | BTC-denominated (sat price stable in sats) | USD-denominated (depeg risk mitigated by circuit breaker) |
| Signature | Ed25519 (published node keys) | Ed25519 (published node keys) |
| Infrastructure | Requires Lightning node or wallet | Requires Base wallet with USDC |
| Depeg immunity | Yes — sats are sats | No — circuit breaker suspends if USDC depegs |
Both protocols return the same oracle data, the same canonical format and the same signature. You can implement both and fall back from one to the other if either payment rail is disrupted.