diff options
| author | Adam Soltys <[email protected]> | 2026-07-30 08:51:36 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-07-30 08:51:36 -0700 |
| commit | add3ad93ff37f1daaedab5788f00663be299555c (patch) | |
| tree | de0523f7f6d13e57e58c26d8b03dabbdcb5790cb /lib/invoices.ts | |
| parent | 81c3593f1eec7f94dc9cbc22edc3456fa57b95cb (diff) | |
| download | coinos-server-add3ad93ff37f1daaedab5788f00663be299555c.tar.gz coinos-server-add3ad93ff37f1daaedab5788f00663be299555c.zip | |
bolt12 zaps: pay offers, NWC pay/receive, per-user offers, NIP-44
- sendLightning fetches an invoice from lno1 offers (payer_note passthrough
for NIP-177 zap intents) and pays it through the existing bolt12 path
- NWC: new nwc#2 pay/receive methods (BIP-321 URIs, payer proofs stubbed
until CLN 26.06 createproof), nip44_v2 alongside nip04 with per-request
scheme detection, dual 23196/23197 notifications, 13194 refreshed when
its content or encryption tag goes stale
- standing per-user bolt12 offer via GET /offer; incoming bolt12 payments
record invreq_payer_note as memo
- parse/fetchinvoice routes handle offers; zap display parses kind 9736
receipts (amount tag + embedded intent) and drops a call to a sync()
helper that never existed
Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'lib/invoices.ts')
| -rw-r--r-- | lib/invoices.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts index 613287a3..d11073c2 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -188,7 +188,15 @@ export const generate = async ({ invoice, user }) => { description: memo || id, }); - if (await getInvoice(r.offer_id)) fail("Duplicate offer exists"); + // CLN returns the same offer_id for identical offer contents, so a + // re-create of an offer we already track must not register a second + // invoice for it (duplicate :invoices entries — see kaliyi's OCEAN + // offer). If it's the same user's offer, hand back the existing record. + const existing = await getInvoice(r.offer_id); + if (existing) { + if (existing.uid === user.id) return existing; + fail("Duplicate offer exists"); + } await s(`invoice:${r.offer_id}`, id); } @@ -266,3 +274,32 @@ export const generate = async ({ invoice, user }) => { return invoice; }; + +// Each user gets one standing amountless bolt12 offer (lno1...) they can hand +// out as a reusable payment code — e.g. published in a kind 10058 list for +// NIP-177 bolt12 zaps. Created lazily on first request, then reused; incoming +// payments credit through the regular bolt12 receive path via local_offer_id. +export const getUserOffer = async (user) => { + const key = `${user.id}:offer`; + const existingId = await g(key); + if (existingId) { + const existing = await g(`invoice:${existingId}`); + if (existing?.hash) return existing; + } + + let domain; + try { + domain = new globalThis.URL(process.env.URL).host; + } catch (e) {} + + const invoice = await generate({ + invoice: { + type: PaymentType.bolt12, + memo: domain ? `${user.username}@${domain}` : user.username, + }, + user, + }); + + await s(key, invoice.id); + return invoice; +}; |
