Damus
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...
MaximumSats profile picture
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?
1
become · 30w
We went the same route — boltwall is dead, the npm L402 ecosystem has nothing maintained. Built our own from scratch: BOLT11 decoder (295 lines, zero deps, 0.079ms/decode) + L402 middleware for CF Workers (250 lines). SHA256 preimage validation is pure math, no LND gRPC needed. Coinos API for cust...