@openreceive/http 0.4.11 → 0.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import {
7
7
  isServiceErrorShape,
8
8
  mapHostRouteError,
9
9
  startNotificationWorker
10
- } from "./chunk-PGZAFYN6.js";
10
+ } from "./chunk-YIN33FVH.js";
11
11
  export {
12
12
  HostError,
13
13
  HttpError,
@@ -1307,10 +1307,11 @@ function abortableDelay(milliseconds, signal) {
1307
1307
  }
1308
1308
 
1309
1309
  // src/reconcile-gate.ts
1310
- var OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS = 2;
1310
+ var OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS = 3;
1311
1311
  var OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS = 9e3;
1312
+ var SCAN_BACKSTOP_GRACE_MS = 500;
1312
1313
  var OPENRECEIVE_RECONCILE_SCAN_MAX_PAGES = 50;
1313
- var EARLY_INVOICE_INTERVAL_SECONDS = 2;
1314
+ var EARLY_INVOICE_INTERVAL_SECONDS = 3;
1314
1315
  var MID_INVOICE_INTERVAL_SECONDS = 6;
1315
1316
  var LATE_INVOICE_INTERVAL_SECONDS = 12;
1316
1317
  var EARLY_INVOICE_WINDOW_SECONDS = 2 * 60;
@@ -1345,7 +1346,10 @@ async function maybeReconcilePayments(input) {
1345
1346
  try {
1346
1347
  const clock = input.clock ?? unixSeconds5;
1347
1348
  const now = clock();
1348
- const minInterval = Math.max(2, input.minIntervalSeconds ?? 2);
1349
+ const minInterval = Math.max(
1350
+ OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS,
1351
+ input.minIntervalSeconds ?? OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS
1352
+ );
1349
1353
  const timeout = Math.min(
1350
1354
  OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS,
1351
1355
  input.scanTimeoutMs ?? OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS
@@ -1370,20 +1374,19 @@ async function maybeReconcilePayments(input) {
1370
1374
  candidates = await input.host.payments.listReconcilableAttempts(null);
1371
1375
  const last = candidates.at(-1);
1372
1376
  scheduler.cursor = last === void 0 || candidates.length < OPENRECEIVE_RECONCILE_BATCH_SIZE ? null : { created_at: last.createdAt, payment_hash: last.paymentHash };
1373
- const fresh = candidates.filter((attempt) => !queued.has(attempt.paymentHash));
1374
- if (fresh.length > 0)
1375
- scheduler.windows.push(
1376
- createPaymentScanWindow(
1377
- fresh.map((attempt) => ({
1378
- payment_hash: attempt.paymentHash,
1379
- created_at: attempt.createdAt,
1380
- expires_at: attempt.expiresAt,
1381
- created_at_source: attempt.createdAtSource ?? "host"
1382
- })),
1383
- now,
1384
- input.overlapSeconds
1385
- )
1377
+ const fresh = candidates.filter((attempt) => !queued.has(attempt.paymentHash)).map((attempt) => ({
1378
+ payment_hash: attempt.paymentHash,
1379
+ created_at: attempt.createdAt,
1380
+ expires_at: attempt.expiresAt,
1381
+ created_at_source: attempt.createdAtSource ?? "host"
1382
+ }));
1383
+ for (const wallet of [true, false]) {
1384
+ const cohort = fresh.filter(
1385
+ (attempt) => attempt.created_at_source === "wallet" === wallet
1386
1386
  );
1387
+ if (cohort.length > 0 && scheduler.windows.length < 2)
1388
+ scheduler.windows.push(createPaymentScanWindow(cohort, now, input.overlapSeconds));
1389
+ }
1387
1390
  }
1388
1391
  const window = scheduler.windows.shift();
1389
1392
  if (window === void 0) {
@@ -1445,7 +1448,7 @@ async function maybeReconcilePayments(input) {
1445
1448
  }
1446
1449
  }
1447
1450
  }),
1448
- timeout,
1451
+ timeout + SCAN_BACKSTOP_GRACE_MS,
1449
1452
  controller
1450
1453
  );
1451
1454
  if (slice.outcome === "continued") {
package/dist/index.d.ts CHANGED
@@ -282,15 +282,16 @@ declare function startReconciler(input: {
282
282
 
283
283
  /**
284
284
  * Floor for the durable reconcile-gate interval: at most one real wallet scan
285
- * per two seconds across EVERY worker sharing the host database. This gate is
285
+ * per three seconds across EVERY worker sharing the host database. This gate is
286
286
  * the NWC rate limit for settlement scans — open tabs polling `payments/check`
287
287
  * (~3s) all share the one global pass instead of fanning out wallet walks.
288
288
  */
289
- declare const OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS: 2;
289
+ declare const OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS: 3;
290
290
  /**
291
291
  * Wall-clock bound on an awaited request-path pass: a slow wallet must not
292
- * hang user-facing requests. A timed-out pass counts as a failed scan; the
293
- * gate stays claimed so the next interval retries without a stampede.
292
+ * hang user-facing requests. A page still in flight at the deadline is cut;
293
+ * the pass keeps the progress of its completed pages, and the next interval
294
+ * resumes there.
294
295
  */
295
296
  declare const OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS: 9000;
296
297
  /** Page cap per wallet-history walk on the awaited request path. */
@@ -304,7 +305,7 @@ type OpportunisticReconcileResult = {
304
305
  interface MaybeReconcilePaymentsOptions {
305
306
  readonly service: OpenReceive;
306
307
  readonly host: Host;
307
- /** Gate interval floor. Default (and minimum) 2 seconds. */
308
+ /** Gate interval floor. Default (and minimum) 3 seconds. */
308
309
  readonly minIntervalSeconds?: number;
309
310
  readonly overlapSeconds?: number;
310
311
  readonly scanTimeoutMs?: number;
@@ -315,7 +316,7 @@ interface MaybeReconcilePaymentsOptions {
315
316
  }
316
317
  /**
317
318
  * The gate interval for the current pending set: the configured floor,
318
- * stretched by invoice age (2s while any pending invoice is under 2 minutes
319
+ * stretched by invoice age (3s while any pending invoice is under 2 minutes
319
320
  * old, 6s under 5 minutes, else 12s).
320
321
  */
321
322
  declare function reconcileIntervalSeconds(attempts: readonly ReconcilableAttempt[], now: number, minIntervalSeconds?: number): number;
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  startReconciler,
35
35
  typeOrmDb,
36
36
  webRequest
37
- } from "./chunk-PGZAFYN6.js";
37
+ } from "./chunk-YIN33FVH.js";
38
38
  export {
39
39
  HostError,
40
40
  HttpError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openreceive/http",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "description": "Node.js HTTP routes and payment storage for Bitcoin Lightning checkout, with optional USDT, USDC, SOL and ETH swaps.",
5
5
  "keywords": [
6
6
  "bitcoin",
@@ -17,8 +17,8 @@
17
17
  "main": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts",
19
19
  "dependencies": {
20
- "@openreceive/core": "0.4.11",
21
- "@openreceive/node": "0.4.11"
20
+ "@openreceive/core": "0.4.13",
21
+ "@openreceive/node": "0.4.13"
22
22
  },
23
23
  "exports": {
24
24
  ".": {
@@ -49,7 +49,7 @@ same diagnostics redacted, always exit 0 — safe to share.
49
49
  ## 4. Paid but never settles
50
50
 
51
51
  - Settlement is opportunistic: any OpenReceive request runs one reconcile pass
52
- through a durable gate (min 2s between wallet scans, stretched by invoice
52
+ through a durable gate (min 3s between wallet scans, stretched by invoice
53
53
  age). A quiet server settles on the next request — or run the optional
54
54
  notification worker. No timer is missing; that is the design.
55
55
  - An unpaid attempt closes only after a successful wallet scan at/after expiry
@@ -34,9 +34,10 @@ code** (`NWC_URI`).
34
34
  - BTCPay Server: [references/btcpay.md](references/btcpay.md) — a plugin,
35
35
  configured in BTCPay's store UI or Greenfield API; no application code,
36
36
  no npm packages, no gem. The rest of this file is about the library.
37
- 3. Follow its **Step 0** first: confirm `NWC_URI` is set in the server
38
- environment before writing code. Never print the value; never invent a
39
- placeholder.
37
+ 3. Follow its **Step 0** first: before writing code or searching the machine,
38
+ ask the user for the receive-only NWC code (then the swap URI), one question
39
+ per message, and store each pasted code in the project's env file yourself.
40
+ Never print the value; never invent a placeholder.
40
41
 
41
42
  Install, per adapter — Express: `npm install @openreceive/express @openreceive/react`;
42
43
  Fastify: `npm install @openreceive/fastify @openreceive/react`; Next.js:
@@ -1,6 +1,6 @@
1
1
  # OpenReceive agent directions (BTCPay Server)
2
2
 
3
- These directions describe OpenReceive 0.4.11.
3
+ These directions describe OpenReceive 0.4.13.
4
4
 
5
5
  Connect a BTCPay Server store to a receive-only NWC wallet with the OpenReceive
6
6
  plugin, and optionally let payers pay BTCPay invoices with USDT, USDC, ETH or
@@ -35,10 +35,12 @@ refund path on the same checkout screen.
35
35
  1. Confirm the BTCPay Server version is 2.4.4 or later (Server Settings →
36
36
  About, or `GET /api/v1/server/info`). The plugin declares that minimum and
37
37
  BTCPay refuses to load it below.
38
- 2. Check whether the plugin is installed (Server Settings → Plugins, or the
39
- store navigation shows an "OpenReceive" entry). If not, install it from the
40
- BTCPay plugin directory (Server Settings → Plugins, search "OpenReceive"),
41
- as the quickstart says; do not invent an installer command.
38
+ 2. Check whether the plugin is installed (the Plugins menu — the plug icon in
39
+ the top-right corner — under Installed Plugins, or the store navigation
40
+ shows an "OpenReceive" entry). If not, install it from the BTCPay plugin
41
+ directory (the same Plugins menu → Plugin Directory, search "openreceive",
42
+ then Install and Restart now), as the quickstart says; do not invent an
43
+ installer command.
42
44
  3. Check whether the store already has an OpenReceive connection:
43
45
  `GET /api/v1/stores/{storeId}/openreceive/settings` returns
44
46
  `lightningNodeIsOpenReceive`. If true, the wallet step is done — go to
@@ -133,15 +135,15 @@ passes. The page it comes from is https://openreceive.org/guides/quickstart-btcp
133
135
  Requires BTCPay Server ≥ 2.4.4.
134
136
 
135
137
  The OpenReceive plugin makes a receive-only NWC wallet the Lightning node of a
136
- BTCPay store. BTCPay mints every Lightning invoice in that wallet and records
137
- payments through its own settlement machinery. Optionally, payers can pay a
138
- BTCPay invoice with USDT, USDC, ETH or SOL through a Lightning Swap Connect
139
- provider; the swap settles into the same wallet. The store's internal node is
138
+ BTCPay store. BTCPay creates every Lightning invoice in that wallet. It records
139
+ payments the same way it records any other payment. You can also let payers pay
140
+ a BTCPay invoice with USDT, USDC, ETH or SOL through a Lightning Swap Connect
141
+ provider. The swap pays into the same wallet. The store's internal node is
140
142
  never used.
141
143
 
142
144
  This is not the Node or Rails library. There are no hooks, no
143
- `openreceive_payments` table and no OpenReceive HTTP routes: BTCPay's
144
- invoices, checkout, webhooks and Greenfield API are the host.
145
+ `openreceive_payments` table and no OpenReceive HTTP routes. BTCPay's own
146
+ invoices, checkout, webhooks and Greenfield API do that work.
145
147
 
146
148
  ### 1. Prerequisites
147
149
 
@@ -157,39 +159,66 @@ invoices, checkout, webhooks and Greenfield API are the host.
157
159
 
158
160
  ### 2. Install the plugin
159
161
 
160
- In BTCPay, open **Server Settings → Plugins**, search the plugin directory
161
- for **OpenReceive**, click **Install**, and restart BTCPay when prompted.
162
- BTCPay creates the plugin's two tables (`openreceive_invoices` and
163
- `openreceive_swaps`, schema `BTCPayServer.Plugins.OpenReceive`) in its own
164
- Postgres at startup; nothing else is created.
162
+ Sign in as a **server administrator**. If someone else hosts your server, ask
163
+ them to install the plugin for you.
164
+
165
+ **1. Open the Plugins menu.** It is the plug icon in the top-right corner.
166
+
167
+ **2. Click Plugin Directory.**
168
+
169
+ **3. Search for `openreceive`** and click the **OpenReceive** result.
170
+
171
+ **4. Click Install in BTCPay Server.** Confirm when prompted, then click
172
+ **Restart now** and wait for BTCPay to come back.
173
+
174
+ At startup, BTCPay creates the plugin's two tables in its own Postgres
175
+ database: `openreceive_invoices` and `openreceive_swaps`, in the schema
176
+ `BTCPayServer.Plugins.OpenReceive`. Nothing else is created.
165
177
 
166
178
  To build the plugin from source instead, follow
167
179
  [the .NET workspace README](https://github.com/OpenReceive/openreceive/blob/master/packages/dotnet/README.md).
168
180
 
169
181
  ### 3. Connect the wallet
170
182
 
171
- Follow the plugin README's illustrated walkthrough:
172
- [OpenReceive for BTCPay Server](https://github.com/OpenReceive/openreceive/blob/master/packages/dotnet/BTCPayServer.Plugins.OpenReceive/README.md).
173
- It opens the **OpenReceive** page in the store's sidebar, saves the
174
- receive-only NWC code, optionally saves the LSC code to turn swaps on, and
175
- creates a first test invoice. There is nothing else to configure: you never
176
- open BTCPay's Lightning node screen, and the plugin never reads the internal
177
- node.
183
+ 1. Select your store and open **OpenReceive** in its sidebar, under Wallets.
184
+ 2. Paste your receive-only NWC code. To see what the wallet supports first,
185
+ click **Test connection**.
186
+ 3. Click **Save NWC Code**.
187
+ 4. To turn swaps on, paste a Lightning Swap Connect code and click **Save swap
188
+ settings**.
178
189
 
179
- Saving fails closed if the wallet advertises a spend method such as
180
- `pay_invoice`. Mint a receive-only code instead; the override for a wallet
181
- that cannot is a deliberate, logged choice. Swaps raise the store's invoice
182
- expiration to 60 minutes when it is shorter, because a swap needs at least 45
183
- minutes of invoice life.
190
+ The page then shows **Wallet connected**. If you set up a provider, it also
191
+ shows **Swaps on**. There is nothing else to configure. You never open BTCPay's
192
+ Lightning node screen, and the plugin never reads the internal node.
193
+
194
+ Screenshots for each of those steps, and for creating a first test invoice,
195
+ are in the plugin's
196
+ [README](https://github.com/OpenReceive/openreceive/blob/master/packages/dotnet/BTCPayServer.Plugins.OpenReceive/README.md).
197
+
198
+ The plugin refuses to save a code whose wallet advertises a spend method such
199
+ as `pay_invoice`. Create a receive-only code instead. If your wallet cannot
200
+ make one, there is an override, but using it is a deliberate choice and the
201
+ plugin logs it.
202
+
203
+ Turning swaps on raises the store's invoice expiration to 60 minutes if it is
204
+ shorter. A swap needs the invoice to stay open for at least 45 minutes.
184
205
 
185
206
  ### 4. Check it
186
207
 
187
- **Run a health check** on the OpenReceive page runs every probe in place:
188
- the connection, the wallet preflight, payment notifications, the last wallet
189
- scan, the swap provider and its assets, the invoice expiration, and swaps
190
- that need a human. Each failing probe carries a fix link.
208
+ Click **Run a health check** on the OpenReceive page. It runs every check
209
+ right there:
210
+
211
+ - the connection
212
+ - the wallet preflight
213
+ - payment notifications
214
+ - the last wallet scan
215
+ - the swap provider and its assets
216
+ - the invoice expiration
217
+ - swaps that need a human
218
+
219
+ Each failing check comes with a link to the fix.
191
220
 
192
- Every setting, Greenfield route, swap state, log event and probe is in the
193
- [BTCPay plugin reference](https://openreceive.org/guides/btcpay-reference.md), including what is
194
- unsupported by design: every send-side feature, top-up invoices, and a bare
195
- `nostr+walletconnect://` string in BTCPay's Lightning node screen.
221
+ The [BTCPay plugin reference](https://openreceive.org/guides/btcpay-reference.md) lists every setting,
222
+ Greenfield route, swap state, log event and check. It also lists what the
223
+ plugin does not support by design: every send-side feature, top-up invoices,
224
+ and a bare `nostr+walletconnect://` string in BTCPay's Lightning node screen.