aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-14 12:38:29 -0700
committerAdam Soltys <[email protected]>2026-06-17 07:47:48 -0700
commitaf8e395dd9ed010fce0e3b92593d5ea6d39dc65a (patch)
treeb7734423601fd0ce14ec7e09eea5299677c3b448
parent58ae0b1d73992bdce4f44c19fde1585ea4312e29 (diff)
downloadcoinos-server-af8e395dd9ed010fce0e3b92593d5ea6d39dc65a.tar.gz
coinos-server-af8e395dd9ed010fce0e3b92593d5ea6d39dc65a.zip
nwc: fix make_invoice timestamps (ms -> seconds) breaking NWC clients
Port of master 0154bb06. generate() stores `created` in milliseconds, but NWC make_invoice 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 (ptcpay's .NET DateTimeOffset, issue #84). Convert created to seconds. Fixes #84. Co-Authored-By: Claude Opus 4.8 <[email protected]>
-rw-r--r--lib/nwc.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 2053ccb5..662d2fa8 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -341,7 +341,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",