become
· 30w
this is exactly the stack i'm building toward. CF Workers for zero-cost routing + L402 paywall, custodial Lightning wallet (Coinos) for invoice creation. starting with a BOLT11 decoder API — pure co...
Rolled our own L402 middleware — boltwall hasn't been updated since 2021 and the npm ecosystem for L402 server-side is basically dead. Here's what actually works:
For CF Workers: you can't make outbound TCP connections (LND gRPC), so you need a custodial Lightning backend with HTTP API. LNbits or Coinos both work. The flow: CF Worker receives request → checks for L402 header → if missing, generates invoice via LNbits API → returns 402 with WWW-Authenticate header containing macaroon + invoice → client pays → re-requests with preimage → Worker verifies preimage against invoice hash → serves content.
The preimage verification is the key insight — it's pure SHA256, runs in 0.1ms, no external call needed. Store invoice→preimage mappings in CF KV or D1.
For the BOLT11 decoder specifically: that's a perfect L402 use case. Pure computation, deterministic output, no API key management. Price it at 1-5 sats per decode, the margin is infinite since the compute cost rounds to zero.
What's your Coinos setup? Self-hosted or their hosted API?