aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-04 18:19:25 -0700
committerAdam Soltys <[email protected]>2026-06-04 18:19:25 -0700
commit0154bb060fad7650cd8b825a30a5d88e7018bf8d (patch)
tree4a9153ec5adfbf26a95f3bb5d19d8cf133a8639e /lib
parentbd1ece38e42751575ac2e03a5c795b5b109653ac (diff)
downloadcoinos-server-0154bb060fad7650cd8b825a30a5d88e7018bf8d.tar.gz
coinos-server-0154bb060fad7650cd8b825a30a5d88e7018bf8d.zip
nwc: fix make_invoice timestamps (ms -> seconds) breaking NWC clients
generate() stores `created` in milliseconds (Date.now()), but the NWC make_invoice response returned it directly as created_at and computed expires_at = created_at + expiry. NWC timestamps are Unix SECONDS (NIP-47), so clients parsed a ~1.78e12 expires_at that overflowed their date types — e.g. ptcpay's .NET DateTimeOffset, whose max is 253402300799 (issue #84: "creating lightning invoices via NWC fails ... Valid values are between -62135596800 and 253402300799"). Convert created to seconds before use. The other NWC handlers were already correct (lookup_invoice reads seconds straight from cln; list_transactions divides p.created by 1000). Only make_invoice leaked milliseconds. Fixes #84 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/nwc.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 5677fea3..2213d68a 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -403,11 +403,14 @@ const handle = (method, params, ev, app, user) =>
expiry,
};
- const {
- hash,
- created: created_at,
- paymentHash,
- } = await generate({ invoice, user });
+ const { hash, created, paymentHash } = await generate({ invoice, user });
+
+ // generate() stores `created` in milliseconds (Date.now()), but NWC
+ // timestamps are Unix SECONDS (NIP-47). Returning ms here produced an
+ // expires_at ~1.78e12 that overflowed clients' date parsers — e.g.
+ // ptcpay's .NET DateTimeOffset (issue #84: "Valid values are between
+ // -62135596800 and 253402300799"). Convert to seconds.
+ const created_at = Math.floor(created / 1000);
return result({
type: "incoming",