From 0d55c0ccceb378a9c1992f6e7d82a6786cdd19b8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 13 Jul 2026 20:21:49 -0700 Subject: preimages: enforce a merchant-set price per preimage batch Invoice creation is unauthenticated, so buyers could name their own price for a queued preimage (create the usePreimage invoice with amount: 1). POST /preimages now takes an optional price (sats) that is stored per entry and overrides the requested amount when the preimage is consumed; omitting it keeps the old any-amount behavior. Also gate the stored-preimage reveal in credit() on the invoice being fully paid, since internal sends can settle partial amounts. Bare-hex entries queued before this change still parse (treated as priceless). Co-Authored-By: Claude Fable 5 --- lib/payments.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/payments.ts') diff --git a/lib/payments.ts b/lib/payments.ts index 01de2eff..df2c8857 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -293,10 +293,13 @@ export const credit = async ({ // preimage:${paymentHash} (see generate()). Prefer it as the settlement // ref: external settlements already carry the same value, but internal // ones pass ref=sender.id, which would otherwise be surfaced as the - // payment preimage and lose the secret the buyer paid for. + // payment preimage and lose the secret the buyer paid for. Only once the + // invoice is fully paid, though — internal sends can settle partial + // amounts, and an underpayment must not reveal the secret. if ( inv.paymentHash && - ![PaymentType.bitcoin, PaymentType.liquid].includes(type) + ![PaymentType.bitcoin, PaymentType.liquid].includes(type) && + inv.received + amount >= inv.amount ) { const stored = await db.get(`preimage:${inv.paymentHash}`); if (stored) ref = stored; -- cgit v1.2.3