@ghostlytools/cli 1.10.1 → 1.10.3

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.
Files changed (97) hide show
  1. package/README.md +14 -10
  2. package/SKILL.md +3 -2
  3. package/dist/assets/{api-BOWLZYXM.js → api-BdaxsDvA.js} +2 -2
  4. package/dist/assets/{api-Bi6hCcwG.js → api-C4MLg5Rs.js} +126 -49
  5. package/dist/assets/api-C4MLg5Rs.js.map +1 -0
  6. package/dist/assets/{apiKit-DzXHZojD.js → apiKit-BbNaxZGZ.js} +87 -25
  7. package/dist/assets/apiKit-BbNaxZGZ.js.map +1 -0
  8. package/dist/assets/{apps-DIQbzG08.js → apps-BluQgEhv.js} +5 -5
  9. package/dist/assets/{apps-DIQbzG08.js.map → apps-BluQgEhv.js.map} +1 -1
  10. package/dist/assets/{apps-0Ks6KjqS.js → apps-BtGFth7o.js} +1 -1
  11. package/dist/assets/{arkade-zozCldAE.js → arkade-DdZx4b_I.js} +2 -2
  12. package/dist/assets/{arkade-zozCldAE.js.map → arkade-DdZx4b_I.js.map} +1 -1
  13. package/dist/assets/{backup-BL49Kt-T.js → backup-DyDsW7sC.js} +7 -7
  14. package/dist/assets/{backup-BL49Kt-T.js.map → backup-DyDsW7sC.js.map} +1 -1
  15. package/dist/assets/{backup-BvIFcZM7.js → backup-I1n7ccz7.js} +1 -1
  16. package/dist/assets/{buttons-CAW5v5EE.js → buttons-Do7dCku6.js} +6 -6
  17. package/dist/assets/{buttons-CAW5v5EE.js.map → buttons-Do7dCku6.js.map} +1 -1
  18. package/dist/assets/buttons-DpjwXePb.js +2 -0
  19. package/dist/assets/{client-CyApKBEw.js → client-CWsjRiH8.js} +3 -3
  20. package/dist/assets/{client-CyApKBEw.js.map → client-CWsjRiH8.js.map} +1 -1
  21. package/dist/assets/{codec-DqFxxB_q.js → codec-DPaXhuYc.js} +2 -2
  22. package/dist/assets/{codec-DqFxxB_q.js.map → codec-DPaXhuYc.js.map} +1 -1
  23. package/dist/assets/{envelope-CMUgz31I.js → envelope-5Gu9yGk_.js} +2 -2
  24. package/dist/assets/{envelope-CMUgz31I.js.map → envelope-5Gu9yGk_.js.map} +1 -1
  25. package/dist/assets/{errors-R4S2SAEM.js → errors-Dt-ZnyOX.js} +3 -1
  26. package/dist/assets/errors-Dt-ZnyOX.js.map +1 -0
  27. package/dist/assets/{fixedHosts-C2hdCfzK.js → fixedHosts-PR1BcfKX.js} +7 -8
  28. package/dist/assets/fixedHosts-PR1BcfKX.js.map +1 -0
  29. package/dist/assets/{groupFiles-BAQIt_bJ.js → groupFiles-BuToTMUk.js} +307 -69
  30. package/dist/assets/groupFiles-BuToTMUk.js.map +1 -0
  31. package/dist/assets/{host-CaRlDMTd.js → host-fkQYBvKH.js} +322 -72
  32. package/dist/assets/host-fkQYBvKH.js.map +1 -0
  33. package/dist/assets/{hyperdhtRelay-BxADl3SG.js → hyperdhtRelay-DDCak5PY.js} +28 -20
  34. package/dist/assets/hyperdhtRelay-DDCak5PY.js.map +1 -0
  35. package/dist/assets/{irohWeb-D2sh6EWp.js → irohWeb-B4_swKx0.js} +112 -34
  36. package/dist/assets/{irohWeb-D2sh6EWp.js.map → irohWeb-B4_swKx0.js.map} +1 -1
  37. package/dist/assets/{main-Bc4Ow56Z.js → main-ClYsttvY.js} +98 -51
  38. package/dist/assets/main-ClYsttvY.js.map +1 -0
  39. package/dist/assets/{mainline-DWh4Ccri.js → mainline-Hsk2SZ1B.js} +66 -6
  40. package/dist/assets/mainline-Hsk2SZ1B.js.map +1 -0
  41. package/dist/assets/{networkReason-DT_D_Wpc.js → networkReason-C9Hr-hO7.js} +4 -4
  42. package/dist/assets/{networkReason-DT_D_Wpc.js.map → networkReason-C9Hr-hO7.js.map} +1 -1
  43. package/dist/assets/{nwc-DoSEhUKb.js → nwc-BbK6qNxS.js} +3 -3
  44. package/dist/assets/{nwc-DoSEhUKb.js.map → nwc-BbK6qNxS.js.map} +1 -1
  45. package/dist/assets/{nwcProvider-CGWqUjpB.js → nwcProvider-D_tt2X3Z.js} +2 -2
  46. package/dist/assets/{nwcProvider-CGWqUjpB.js.map → nwcProvider-D_tt2X3Z.js.map} +1 -1
  47. package/dist/assets/{ownDid-CbGjRLBn.js → ownDid-DkK_jem4.js} +2 -2
  48. package/dist/assets/{ownDid-CbGjRLBn.js.map → ownDid-DkK_jem4.js.map} +1 -1
  49. package/dist/assets/{profiles-DgIfvBeN.js → profiles-aV9vaK0B.js} +17 -8
  50. package/dist/assets/profiles-aV9vaK0B.js.map +1 -0
  51. package/dist/assets/{registry-C5cn80Rw.js → registry-C9T6tYCO.js} +1 -1
  52. package/dist/assets/{registry-BSyxGjN6.js → registry-CEjnubep.js} +57 -17
  53. package/dist/assets/registry-CEjnubep.js.map +1 -0
  54. package/dist/assets/{resolve-D-9YRFhl.js → resolve-BBOrN13E.js} +27 -6
  55. package/dist/assets/resolve-BBOrN13E.js.map +1 -0
  56. package/dist/assets/{restoredRows-CRYwIx3g.js → restoredRows-YhlbokEE.js} +4 -2
  57. package/dist/assets/restoredRows-YhlbokEE.js.map +1 -0
  58. package/dist/assets/{secretGuard-CSVNxXVW.js → secretGuard-B7Hj0Kvz.js} +2 -2
  59. package/dist/assets/{secretGuard-CSVNxXVW.js.map → secretGuard-B7Hj0Kvz.js.map} +1 -1
  60. package/dist/assets/secretGuard-DUr6bgKc.js +2 -0
  61. package/dist/assets/{server-BufntkX8.js → server-BJ3T-kx3.js} +1051 -389
  62. package/dist/assets/server-BJ3T-kx3.js.map +1 -0
  63. package/dist/assets/{src-CCt5s4DK.js → src-BIdfHB7t.js} +667 -134
  64. package/dist/assets/src-BIdfHB7t.js.map +1 -0
  65. package/dist/assets/{sshForges-D8CPaIbR.js → sshForges-CRg-NGld.js} +2 -2
  66. package/dist/assets/{sshForges-D8CPaIbR.js.map → sshForges-CRg-NGld.js.map} +1 -1
  67. package/dist/assets/{translate-Cb-6hMhD.js → translate-b0X61WMI.js} +3 -3
  68. package/dist/assets/{translate-Cb-6hMhD.js.map → translate-b0X61WMI.js.map} +1 -1
  69. package/dist/assets/{usdt-ds461mzA.js → usdt-6CQdfye1.js} +7 -4
  70. package/dist/assets/usdt-6CQdfye1.js.map +1 -0
  71. package/dist/assets/waitNotice-Ce3YCinu.js +101 -0
  72. package/dist/assets/waitNotice-Ce3YCinu.js.map +1 -0
  73. package/dist/assets/{words-B1ylON2h.js → words-Dk6o6wz4.js} +4 -4
  74. package/dist/assets/words-Dk6o6wz4.js.map +1 -0
  75. package/dist/ghostly.mjs +1 -1
  76. package/package.json +1 -1
  77. package/dist/assets/api-Bi6hCcwG.js.map +0 -1
  78. package/dist/assets/apiKit-DzXHZojD.js.map +0 -1
  79. package/dist/assets/buttons-oJI5mHSL.js +0 -2
  80. package/dist/assets/errors-R4S2SAEM.js.map +0 -1
  81. package/dist/assets/fixedHosts-C2hdCfzK.js.map +0 -1
  82. package/dist/assets/groupFiles-BAQIt_bJ.js.map +0 -1
  83. package/dist/assets/host-CaRlDMTd.js.map +0 -1
  84. package/dist/assets/hyperdhtRelay-BxADl3SG.js.map +0 -1
  85. package/dist/assets/main-Bc4Ow56Z.js.map +0 -1
  86. package/dist/assets/mainline-DWh4Ccri.js.map +0 -1
  87. package/dist/assets/profiles-DgIfvBeN.js.map +0 -1
  88. package/dist/assets/registry-BSyxGjN6.js.map +0 -1
  89. package/dist/assets/resolve-D-9YRFhl.js.map +0 -1
  90. package/dist/assets/restoredRows-CRYwIx3g.js.map +0 -1
  91. package/dist/assets/secretGuard-Q2BKq0q0.js +0 -2
  92. package/dist/assets/server-BufntkX8.js.map +0 -1
  93. package/dist/assets/src-CCt5s4DK.js.map +0 -1
  94. package/dist/assets/usdt-ds461mzA.js.map +0 -1
  95. package/dist/assets/waitNotice-B8D8WhbE.js +0 -45
  96. package/dist/assets/waitNotice-B8D8WhbE.js.map +0 -1
  97. package/dist/assets/words-B1ylON2h.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { Br as FileUplink, Di as IDENTITY_REVOCATION_LABEL, Dn as resolveLightningDestination, En as requestLnurlInvoice, Fi as newIdentityBinding, Hr as transferEnded, Ii as receivedIdentityStatus, J as meshMessageRef, Ju as randomBytes, Ku as fromBase64Url, La as RateWindow, Li as revokesIdentity, Mi as identityRevocationValue, Ni as identityStatement, Oa as fileMessageText, Oi as IdentityCheckUnavailable, On as decodeBolt11, Ou as budgetRetryMs, Pi as isIdentityBinding, Qn as engineText, Rr as ChatFiles, Yu as toBase64Url, Zn as engineError, ar as groupFileFallback, cr as readGroupHave, er as GROUP_FILE_LIMITS, in as WALLET_NETWORKS, ir as fetchesByItself, ji as emptyIdentityLedger, ki as IdentityExchange, ku as isDiscoveryBudgetError, lr as readGroupWant, or as isGroupMessageId, ro as replySnippet, rr as GROUP_WANT_NO_FRAME, tr as GROUP_HAVE_FRAME, un as walletNetworkOf, ur as readGroupWantNo } from "./src-CCt5s4DK.js";
1
+ import { $n as engineError, Ai as IDENTITY_REVOCATION_LABEL, Bi as newIdentityBinding, Dn as requestLnurlInvoice, Fi as emptyIdentityLedger, Gr as transferEnded, Hi as revokesIdentity, Ii as identityRefusal, Iu as budgetRetryMs, J as meshMessageRef, Li as identityRevocationValue, Lu as isDiscoveryBudgetError, Mi as IdentityExchange, Ni as boundIdentityDisplay, On as resolveLightningDestination, Pa as fileMessageText, Ri as identityStatement, Ua as RateWindow, Ur as FileUplink, Vi as receivedIdentityStatus, Vr as ChatFiles, ad as toBase64Url, an as WALLET_NETWORKS, ar as GROUP_WANT_NO_FRAME, cr as isGroupMessageId, dn as walletNetworkOf, dr as readGroupWant, er as engineText, fr as readGroupWantNo, id as randomBytes, ji as IdentityCheckUnavailable, ki as IDENTITY_MAX_VALIDITY, kn as decodeBolt11, lo as replySnippet, nd as fromBase64Url, nr as GROUP_FILE_LIMITS, or as fetchesByItself, rr as GROUP_HAVE_FRAME, sr as groupFileFallback, ur as readGroupHave, zi as isIdentityBinding } from "./src-BIdfHB7t.js";
2
2
  import { a as describeProvider, c as offeredIn, d as sourceProblem, n as PROVIDER_PLATFORMS, o as isNothingSpentError, s as networkMode, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
3
3
  import { g as wrap, h as transact, i as STORES, m as store, s as databaseName, u as fileStore } from "./idb-BHsAqENE.js";
4
- import { a as sealSeed, f as openSecret, i as newDeviceKey, m as whenDataKeyDropped, o as unsealSeed, p as sealSecret, t as networkReason } from "./networkReason-DT_D_Wpc.js";
4
+ import { a as sealSeed, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, m as openSecret, o as unsealSeed, t as networkReason } from "./networkReason-C9Hr-hO7.js";
5
5
  import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
6
- import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-CbGjRLBn.js";
6
+ import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-DkK_jem4.js";
7
7
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DjBYYyXT.js";
8
8
  import { sha256 } from "@noble/hashes/sha2.js";
9
9
  import { validateMnemonic } from "@scure/bip39";
@@ -460,6 +460,57 @@ var cashuMint = {
460
460
  }
461
461
  };
462
462
  //#endregion
463
+ //#region ../browser/src/engine/askBackoff.ts
464
+ /**
465
+ * A growing wait with a cap, for whatever a wallet asks about again until it gets an answer: a Cashu melt or swap whose
466
+ * mint does not answer or keeps it pending, restored ecash at a mint that cannot say what is spent, a Lightning card's
467
+ * payment its source keeps pending or cannot be reached about. Asked at a fixed pace, each of these knocked on a dead
468
+ * mint or source every 15 to 60 s for as long as the app ran.
469
+ *
470
+ * Each key is asked at `firstMs` while it is `fast` (a request may still land, the payment is new), then twice as late
471
+ * after every ask with no answer, up to `capMs`. The pace lives in memory: an app start asks at once, and so does a
472
+ * caller that knows something changed (it `forget`s the key, or asks whatever the pace says).
473
+ */
474
+ var AskBackoff = class {
475
+ firstMs;
476
+ capMs;
477
+ paces = /* @__PURE__ */ new Map();
478
+ constructor(firstMs, capMs) {
479
+ this.firstMs = firstMs;
480
+ this.capMs = capMs;
481
+ }
482
+ /** Whether `key` may be asked now: never asked in this run, or its time came. */
483
+ due(key, now) {
484
+ const pace = this.paces.get(key);
485
+ return !pace || now >= pace.at;
486
+ }
487
+ /** When `key` is asked next; `now` if it never was in this run. */
488
+ at(key, now) {
489
+ return this.paces.get(key)?.at ?? now;
490
+ }
491
+ /**
492
+ * `key` was asked and gave no answer (unreachable, an error, still pending). The next ask waits `firstMs` while
493
+ * `fast`, else twice the last wait, up to `capMs`. Returns that wait.
494
+ */
495
+ missed(key, now, fast = false) {
496
+ const last = this.paces.get(key)?.wait;
497
+ const wait = fast || last === void 0 ? this.firstMs : Math.min(last * 2, this.capMs);
498
+ this.paces.set(key, {
499
+ at: now + wait,
500
+ wait
501
+ });
502
+ return wait;
503
+ }
504
+ /** `key` answered, or is gone: its next ask is due at once. */
505
+ forget(key) {
506
+ this.paces.delete(key);
507
+ }
508
+ /** Forgets every key but these (the ones still open). */
509
+ keepOnly(keys) {
510
+ for (const key of this.paces.keys()) if (!keys.has(key)) this.paces.delete(key);
511
+ }
512
+ };
513
+ //#endregion
463
514
  //#region ../browser/src/engine/paymentAdapters/providers/sources.ts
464
515
  /** Where a source is stored: the mode's one, or one of several (`key`). */
465
516
  var sourceKey = (kind, mode, key) => `${kind}Source-${mode}${key ? `-${key}` : ""}`;
@@ -474,6 +525,14 @@ function retryDelay(failures, random = Math.random) {
474
525
  return Math.round(base * (.8 + .4 * random()));
475
526
  }
476
527
  /**
528
+ * A connected source whose balance read gets no answer (its node went off, the relay is down) is read again twice as
529
+ * late after each failed read, from `refreshMs` up to this (`AskBackoff`, as a Lightning card's pending payment): at
530
+ * the fixed 15 s it was 240 failed requests an hour, for good. A read that answers, waking up and Retry read at once
531
+ * and go back to `refreshMs`.
532
+ */
533
+ var REFRESH_SLOW_MS = 18e5;
534
+ var REFRESH_MS = 15e3;
535
+ /**
477
536
  * Gives up on a connection when its signal aborts (a change of settings interrupts an attempt), even if the
478
537
  * provider does not listen to it; what still arrives afterwards is closed.
479
538
  */
@@ -517,6 +576,8 @@ var ProviderSources = class {
517
576
  failingSince;
518
577
  seen;
519
578
  stopped = false;
579
+ /** When the balance is read next, while reads get no answer (one key: this source). */
580
+ reads;
520
581
  view = {
521
582
  mode: "mainnet",
522
583
  status: "none",
@@ -530,6 +591,8 @@ var ProviderSources = class {
530
591
  status: "none",
531
592
  offered: []
532
593
  };
594
+ const every = options.refreshMs ?? REFRESH_MS;
595
+ this.reads = new AskBackoff(every, Math.max(every, REFRESH_SLOW_MS));
533
596
  }
534
597
  serial(run) {
535
598
  const next = this.queue.then(run, run);
@@ -602,9 +665,16 @@ var ProviderSources = class {
602
665
  this.connecting = void 0;
603
666
  });
604
667
  }
605
- /** Retry, now: the wait before the next attempt is skipped. Resolves when the attempt ends. */
668
+ /**
669
+ * Retry, now: the wait before the next attempt is skipped (a connected source reads its balance now, whatever
670
+ * the wait its failed reads earned). Resolves when the attempt ends.
671
+ */
606
672
  retryNow() {
607
- if (this.provider || this.stopped) return Promise.resolve();
673
+ if (this.stopped) return Promise.resolve();
674
+ if (this.provider) {
675
+ this.reads.forget("balance");
676
+ return this.refresh();
677
+ }
608
678
  clearTimeout(this.retry);
609
679
  return this.ensureReady(true);
610
680
  }
@@ -615,6 +685,7 @@ var ProviderSources = class {
615
685
  wake() {
616
686
  if (this.stopped) return;
617
687
  if (this.provider) {
688
+ this.reads.forget("balance");
618
689
  this.refresh();
619
690
  return;
620
691
  }
@@ -928,6 +999,7 @@ var ProviderSources = class {
928
999
  return;
929
1000
  }
930
1001
  const before = this.view;
1002
+ let wait = this.options.refreshMs ?? REFRESH_MS;
931
1003
  try {
932
1004
  const details = await this.options.refresh(provider);
933
1005
  if (provider !== this.provider) return;
@@ -939,19 +1011,24 @@ var ProviderSources = class {
939
1011
  error: void 0
940
1012
  };
941
1013
  this.remember(details);
1014
+ this.reads.forget("balance");
942
1015
  } catch (error) {
943
1016
  if (provider !== this.provider) return;
944
1017
  this.view = {
945
1018
  ...this.view,
946
1019
  error: `Could not read the balance: ${redact(error, this.secrets)}`
947
1020
  };
1021
+ wait = this.reads.missed("balance", Date.now());
948
1022
  }
949
1023
  const after = this.view, was = before;
950
1024
  if (Object.keys({
951
1025
  ...was,
952
1026
  ...after
953
1027
  }).some((key) => was[key] !== after[key])) this.options.changed();
954
- if (this.provider) this.timer = setTimeout(() => void this.refresh(), this.options.refreshMs ?? 15e3);
1028
+ if (this.provider) {
1029
+ clearTimeout(this.timer);
1030
+ this.timer = setTimeout(() => void this.refresh(), wait);
1031
+ }
955
1032
  }
956
1033
  /** Keeps the balance read, for the next start: written only when it changed. */
957
1034
  remember({ balance, unconfirmed }) {
@@ -974,6 +1051,7 @@ var ProviderSources = class {
974
1051
  async disconnect(forget = false) {
975
1052
  clearTimeout(this.timer);
976
1053
  clearTimeout(this.retry);
1054
+ this.reads.forget("balance");
977
1055
  this.controller.abort();
978
1056
  this.controller = new AbortController();
979
1057
  const provider = this.provider;
@@ -1013,6 +1091,13 @@ var INVOICE_PACE = {
1013
1091
  watchMs: 9e4,
1014
1092
  /** A quote or an invoice goes only this long after its expiry, once its mint or source says it is unpaid. */
1015
1093
  expiryGraceMs: 6e4,
1094
+ /**
1095
+ * A mint or a Lightning card's source that does not answer about an invoice, or answers with an error, is asked again
1096
+ * after this, then twice as late each time up to `missedCapMs` (`AskBackoff`): the pace above never looked at whether
1097
+ * it answered, and a dead mint or node was asked every minute (every 4 s about a paid invoice) for good.
1098
+ */
1099
+ missedMs: 3e4,
1100
+ missedCapMs: 18e5,
1016
1101
  /** Due this close to now counts as due: a timer may fire a moment before the clock reads its time. */
1017
1102
  dueSlackMs: 250
1018
1103
  };
@@ -1077,7 +1162,11 @@ async function journaledPayment(paymentId) {
1077
1162
  if (ops.some((op) => op.state === "sending" || op.state === "pending" || op.state === "unknown")) return "pending";
1078
1163
  return ops.some((op) => op.state === "paid") ? "paid" : void 0;
1079
1164
  }
1165
+ /** A payment whose answer was lost is asked about this often while it is new (OUT_FAST_FOR_MS)... */
1080
1166
  var OUT_POLL_MS = 15e3;
1167
+ var OUT_FAST_FOR_MS = 3e5;
1168
+ /** ...then, while its source keeps it pending or cannot be reached, twice as late each time up to this. */
1169
+ var OUT_SLOW_POLL_MS = 18e5;
1081
1170
  var RECENT = 20;
1082
1171
  /** Resolved Lightning addresses are kept this long for the amount to be chosen; this many at most. */
1083
1172
  var LNURL_TTL_MS = 6e5;
@@ -1102,6 +1191,15 @@ var LightningService = class {
1102
1191
  asked = /* @__PURE__ */ new Map();
1103
1192
  /** Per invoice the screen shows (payment hash): until when (`watch`). */
1104
1193
  watched = /* @__PURE__ */ new Map();
1194
+ /**
1195
+ * Per open invoice whose source did not answer about it, or answered with an error (payment hash): as Cashu quotes',
1196
+ * on top of its own pace. Asked every minute for good, one invoice cost 60 lookups an hour at a dead node, 20 cost 1,200.
1197
+ */
1198
+ invoiceAsk = new AskBackoff(INVOICE_PACE.missedMs, INVOICE_PACE.missedCapMs);
1199
+ /** When an open invoice in `recent` next reads as expired (`shownExpiredAt`): the view is read again then. */
1200
+ recentTurns = Infinity;
1201
+ /** Per outgoing payment left pending or unknown (payment hash): when its source is asked next, in this run. */
1202
+ outAsk = new AskBackoff(OUT_POLL_MS, OUT_SLOW_POLL_MS);
1105
1203
  passes = Promise.resolve();
1106
1204
  stopped = false;
1107
1205
  recent = [];
@@ -1164,6 +1262,7 @@ var LightningService = class {
1164
1262
  async createInvoice(amount, context = {}) {
1165
1263
  const { provider, descriptor } = await this.sources.use();
1166
1264
  if (!provider.capabilities.receive) throw new Error(`${descriptor.label} cannot create invoices`);
1265
+ if (!provider.capabilities.lookup && !provider.settlesItself) throw new Error(`${descriptor.label} cannot look up its invoices, so a payment to it would never be seen: receive with another Lightning card, or connect it with invoice lookup allowed`);
1167
1266
  const created = await provider.createInvoice(amount, context.memo ?? "Ghostly");
1168
1267
  const decoded = decodeBolt11(created.invoice);
1169
1268
  if (!decoded || decoded.amountSat !== amount || decoded.paymentHash && decoded.paymentHash !== created.paymentHash || created.amount !== amount) throw new Error(`${descriptor.label} returned an invoice that does not match the request`);
@@ -1199,6 +1298,7 @@ var LightningService = class {
1199
1298
  const op = hash ? await this.get("in", hash) : void 0;
1200
1299
  if (!op || !this.owns(op) || op.state !== "open") return false;
1201
1300
  this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
1301
+ this.invoiceAsk.forget(op.paymentHash);
1202
1302
  this.schedule(0);
1203
1303
  return true;
1204
1304
  }
@@ -1211,6 +1311,7 @@ var LightningService = class {
1211
1311
  const op = hash ? await this.get("in", hash) : void 0;
1212
1312
  if (!op || !this.owns(op) || op.state !== "open") return false;
1213
1313
  this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
1314
+ this.invoiceAsk.forget(op.paymentHash);
1214
1315
  await this.reconcile(false, op.paymentHash);
1215
1316
  return true;
1216
1317
  }
@@ -1400,8 +1501,10 @@ var LightningService = class {
1400
1501
  }
1401
1502
  /**
1402
1503
  * Asks the active source about everything of its that is open, pending or unknown. One pass at a time. `paced`: an
1403
- * open invoice only when its pace says so (`nextInvoiceAsk`); otherwise every one now. `only`: the open invoice with
1404
- * this payment hash alone (a payer says it paid it, `check`).
1504
+ * open invoice only when its pace says so (`nextInvoiceAsk`, and not before the wait its source's silence earned,
1505
+ * `invoiceAsk`), and a payment left pending or unknown only when its own does (`outAsk`); otherwise every one now.
1506
+ * Once one open invoice got no answer in a pass, the others due in it wait as that one does, unasked. `only`: the
1507
+ * open invoice with this payment hash alone (a payer says it paid it, `check`).
1405
1508
  */
1406
1509
  reconcile(paced = false, only) {
1407
1510
  const pass = this.passes.then(() => this.reconcileOnce(paced, only));
@@ -1411,31 +1514,52 @@ var LightningService = class {
1411
1514
  async reconcileOnce(paced, only) {
1412
1515
  if (this.stopped) return;
1413
1516
  let again = 0;
1517
+ const later = (ms) => {
1518
+ again = again ? Math.min(again, ms) : ms;
1519
+ };
1520
+ /** An outgoing payment asked with no answer (pending, or the source unreachable): asked less and less often. */
1521
+ const missed = (op) => later(this.outAsk.missed(op.paymentHash, Date.now(), Date.now() < op.createdAt + OUT_FAST_FOR_MS));
1522
+ /** Whether a paced pass leaves this outgoing payment for later. */
1523
+ const notYet = (op) => {
1524
+ if (!paced || this.outAsk.due(op.paymentHash, Date.now())) return false;
1525
+ later(Math.max(0, this.outAsk.at(op.paymentHash, Date.now()) - Date.now()));
1526
+ return true;
1527
+ };
1414
1528
  /** When the next open invoice is due. */
1415
1529
  let invoiceDue = Infinity;
1530
+ /** An open invoice got no answer in this pass: the source is taken as down until the next one. */
1531
+ let down = false;
1532
+ /** An open invoice of ours got no answer: asked again later, and later each time (on top of its own pace). */
1533
+ const unanswered = (op) => {
1534
+ this.invoiceAsk.missed(op.paymentHash, Date.now());
1535
+ invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
1536
+ };
1416
1537
  const writes = this.writes;
1417
1538
  try {
1418
1539
  const provider = this.sources.active, providerId = this.sources.activeId;
1419
1540
  const ops = await this.list();
1420
1541
  const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
1421
1542
  for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
1543
+ this.invoiceAsk.keepOnly(open);
1544
+ this.outAsk.keepOnly(new Set(ops.filter((op) => op.direction === "out" && ["pending", "unknown"].includes(op.state)).map((op) => op.paymentHash)));
1422
1545
  for (const op of ops) {
1423
1546
  if (!this.owns(op) || only !== void 0 && (op.direction !== "in" || op.paymentHash !== only)) continue;
1424
1547
  if (op.selfSettled) {
1425
1548
  if (op.direction !== "out" || op.state !== "unknown") continue;
1426
1549
  if (!provider) {
1427
- again = again || OUT_POLL_MS;
1550
+ later(OUT_POLL_MS);
1428
1551
  continue;
1429
1552
  }
1430
- if (op.providerId !== providerId || !provider.interruptedPayment) continue;
1553
+ if (op.providerId !== providerId || !provider.interruptedPayment || notYet(op)) continue;
1431
1554
  try {
1432
1555
  const outcome = await provider.interruptedPayment({
1433
1556
  invoice: op.invoice,
1434
1557
  paymentHash: op.paymentHash,
1435
1558
  ref: op.ref
1436
1559
  });
1437
- if (outcome === "pending") again = again || OUT_POLL_MS;
1560
+ if (outcome === "pending") missed(op);
1438
1561
  if (outcome !== "paid" && outcome !== "failed") continue;
1562
+ this.outAsk.forget(op.paymentHash);
1439
1563
  if ((await this.get("out", op.paymentHash))?.state !== "unknown") continue;
1440
1564
  await this.put({
1441
1565
  ...op,
@@ -1445,7 +1569,7 @@ var LightningService = class {
1445
1569
  });
1446
1570
  this.events.resolved(op, outcome === "paid");
1447
1571
  } catch {
1448
- again = again || OUT_POLL_MS;
1572
+ missed(op);
1449
1573
  }
1450
1574
  continue;
1451
1575
  }
@@ -1458,7 +1582,11 @@ var LightningService = class {
1458
1582
  continue;
1459
1583
  }
1460
1584
  this.asked.set(op.paymentHash, Date.now());
1461
- }
1585
+ if (down) {
1586
+ unanswered(op);
1587
+ continue;
1588
+ }
1589
+ } else if (notYet(op)) continue;
1462
1590
  try {
1463
1591
  const unchanged = async () => (await this.get(op.direction, op.paymentHash))?.state === op.state;
1464
1592
  if (op.direction === "in") {
@@ -1469,6 +1597,7 @@ var LightningService = class {
1469
1597
  expiresAt: op.expiresAt,
1470
1598
  ref: op.ref
1471
1599
  });
1600
+ this.invoiceAsk.forget(op.paymentHash);
1472
1601
  if (!await unchanged()) continue;
1473
1602
  if (status.state === "paid") {
1474
1603
  await this.put({
@@ -1489,9 +1618,10 @@ var LightningService = class {
1489
1618
  ref: op.ref
1490
1619
  });
1491
1620
  if (status.state === "pending") {
1492
- again = again || OUT_POLL_MS;
1621
+ missed(op);
1493
1622
  continue;
1494
1623
  }
1624
+ this.outAsk.forget(op.paymentHash);
1495
1625
  if (!await unchanged()) continue;
1496
1626
  await this.put({
1497
1627
  ...op,
@@ -1503,24 +1633,26 @@ var LightningService = class {
1503
1633
  this.events.resolved(op, status.state === "paid");
1504
1634
  }
1505
1635
  } catch {
1506
- if (op.direction === "in") invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
1507
- else again = again ? Math.min(again, OUT_POLL_MS) : OUT_POLL_MS;
1636
+ if (op.direction === "in") {
1637
+ down = true;
1638
+ unanswered(op);
1639
+ } else missed(op);
1508
1640
  }
1509
1641
  }
1510
1642
  } finally {
1511
1643
  if (await this.loadRecent() || this.writes !== writes) this.events.changed();
1512
- const wait = Math.min(again || Infinity, invoiceDue - Date.now());
1644
+ const wait = Math.min(again || Infinity, invoiceDue - Date.now(), this.recentTurns - Date.now());
1513
1645
  if (wait < Infinity) this.schedule(Math.max(0, wait));
1514
1646
  }
1515
1647
  }
1516
- /** When the source is next asked about this open invoice of ours. */
1648
+ /** When the source is next asked about this open invoice of ours: at its pace, and not before the wait its silence earned. */
1517
1649
  nextAsk(op, now) {
1518
- return nextInvoiceAsk({
1650
+ return Math.max(this.invoiceAsk.at(op.paymentHash, 0), nextInvoiceAsk({
1519
1651
  createdAt: op.createdAt,
1520
1652
  expiresAt: op.expiresAt,
1521
1653
  watchedUntil: this.watched.get(op.paymentHash),
1522
1654
  closed: !!op.paymentId && !!this.events.requestClosed?.(op.paymentId)
1523
- }, this.asked.get(op.paymentHash), now);
1655
+ }, this.asked.get(op.paymentHash), now));
1524
1656
  }
1525
1657
  /** The next pass in `ms`, unless one is due sooner. It asks only what is due (`reconcile(true)`). */
1526
1658
  schedule(ms) {
@@ -1578,11 +1710,28 @@ var LightningService = class {
1578
1710
  }
1579
1711
  /** True when the recent list reads otherwise than before. */
1580
1712
  async loadRecent() {
1581
- const was = this.recent;
1582
- this.recent = (await this.list()).filter((op) => this.owns(op)).sort((a, b) => b.createdAt - a.createdAt).slice(0, RECENT).map(({ ref: _ref, note: _note, selfSettled: _self, ...view }) => view);
1713
+ const was = this.recent, now = Date.now();
1714
+ const ops = (await this.list()).filter((op) => this.owns(op)).sort((a, b) => b.createdAt - a.createdAt).slice(0, RECENT);
1715
+ this.recentTurns = Math.min(Infinity, ...ops.map((op) => shownExpiredAt(op)).filter((at) => at > now));
1716
+ this.recent = ops.map((op) => {
1717
+ const { ref: _ref, note: _note, selfSettled: _self, ...view } = op;
1718
+ return shownExpiredAt(op) <= now ? {
1719
+ ...view,
1720
+ state: "expired"
1721
+ } : view;
1722
+ });
1583
1723
  return JSON.stringify(was) !== JSON.stringify(this.recent);
1584
1724
  }
1585
1725
  };
1726
+ /**
1727
+ * When an open invoice of ours that this engine asks about reads as expired, though no answer said so: past its expiry
1728
+ * and the grace a source's own "expired" gets. Its source may not answer for hours (a node that is off, an NWC relay
1729
+ * gone), and "waiting for payment" on an invoice nobody can pay any more is wrong. The journal keeps it open, and it is
1730
+ * still asked about (`invoiceAsk`), so a late "paid" counts. Infinity: shown as it is stored.
1731
+ */
1732
+ function shownExpiredAt(op) {
1733
+ return op.direction === "in" && op.state === "open" && !op.selfSettled && op.expiresAt > 0 ? op.expiresAt + INVOICE_PACE.expiryGraceMs + 1 : Infinity;
1734
+ }
1586
1735
  //#endregion
1587
1736
  //#region ../browser/src/engine/paymentAdapters/providers/recoveryPhrase.ts
1588
1737
  /** A phrase as BIP 39 wants it, however it was typed or pasted. */
@@ -1996,7 +2145,7 @@ var registry;
1996
2145
  var loading;
1997
2146
  var listeners = /* @__PURE__ */ new Set();
1998
2147
  function loadIdentityProviders() {
1999
- return loading ??= import("./registry-C5cn80Rw.js").then((m) => {
2148
+ return loading ??= import("./registry-C9T6tYCO.js").then((m) => {
2000
2149
  registry = m;
2001
2150
  for (const listener of listeners) listener();
2002
2151
  return m;
@@ -2023,6 +2172,12 @@ var REVOCATIONS_CHECKED_AT = "identityRevocationsCheckedAt";
2023
2172
  var REVOCATIONS_ROUND = "identityRevocationsRound";
2024
2173
  /** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
2025
2174
  var REPUBLISH_MS = 36e5;
2175
+ /**
2176
+ * A revocation is kept (with its sealed seed) this long past its expiry by this device's clock, which may be the one that
2177
+ * is wrong: the contacts decide expiry by theirs. Only a clock ahead by more than the longest a proof may last (400 days)
2178
+ * drops one still standing for them. Republished only until its expiry, as before; a few hundred bytes each.
2179
+ */
2180
+ var REVOCATION_KEPT_PAST_EXPIRY = IDENTITY_MAX_VALIDITY;
2026
2181
  /** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
2027
2182
  var REVOCATION_CHECK_MS = 432e5;
2028
2183
  /** A lookup that could not run (offline, no relay answered) is tried again after this, doubled each time, up to the 12 h. */
@@ -2035,6 +2190,13 @@ var BUDGET_TRIES = 5;
2035
2190
  */
2036
2191
  var REVOCATION_READ_GAP_MS = 3e3;
2037
2192
  /**
2193
+ * The lookup under way (`REVOCATIONS_ROUND`) is written at most this often, or once this many proofs were read since
2194
+ * (the reads of that time), and when it ends cut short or the engine stops: a restart after a crash reads again at most
2195
+ * those. Written after every read, it cost n writes of 1 to n entries: 45 MB a lookup for 900 proofs.
2196
+ */
2197
+ var ROUND_SAVE_MS = 6e4;
2198
+ var ROUND_SAVE_READS = ROUND_SAVE_MS / REVOCATION_READ_GAP_MS;
2199
+ /**
2038
2200
  * After a contact withdraws a proof, how long to wait before each lookup for its revocation (WISP 300: removing a proof withdraws it from
2039
2201
  * every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
2040
2202
  * off, and the first that finds it stops the rest. The 12 h check covers it after that.
@@ -2050,10 +2212,18 @@ var WITHDRAWN_REVOCATION_TRIES_MS = [
2050
2212
  * listed key that is gone then stops reading verified.
2051
2213
  */
2052
2214
  var AUTO_RECHECK_AFTER_S = 86400;
2053
- /** Due proofs are looked for this often (the first time a few minutes after the start), and only a few checked each time. */
2215
+ /**
2216
+ * Due proofs are looked for this often (the first time a few minutes after the start). Each time checks enough of them
2217
+ * to clear the ones due within `AUTO_RECHECK_SPREAD_TICKS` times (at least `AUTO_RECHECK_BATCH`), one every
2218
+ * `AUTO_RECHECK_GAP_MS` at most, so every proof is checked about a day after its last check however many contacts.
2219
+ */
2054
2220
  var AUTO_RECHECK_TICK_MS = 9e5;
2055
2221
  var AUTO_RECHECK_FIRST_MS = 18e4;
2056
2222
  var AUTO_RECHECK_BATCH = 3;
2223
+ var AUTO_RECHECK_SPREAD_TICKS = 4;
2224
+ var AUTO_RECHECK_GAP_MS = 4e3;
2225
+ /** The checks of one time fit before the next: 150 every 15 minutes, 14,400 a day. */
2226
+ var AUTO_RECHECK_MAX_BATCH = Math.floor(AUTO_RECHECK_TICK_MS * 2 / 3 / AUTO_RECHECK_GAP_MS);
2057
2227
  /** A check that could not reach the server leaves the proof as it was and is tried again after this, doubling, at most a day. */
2058
2228
  var AUTO_RECHECK_BACKOFF_MS = 72e5;
2059
2229
  /** A proof begun and not completed is dropped this long after, or when a fifth one begins (the CLI says the same). */
@@ -2061,6 +2231,15 @@ var IDENTITY_DRAFT_TTL_MS = 18e5;
2061
2231
  var MAX_PROOFS = 32;
2062
2232
  var now = () => Math.floor(Date.now() / 1e3);
2063
2233
  /**
2234
+ * A share of mine as every reader gets it (the app, the CLI, `getState`): its reason only in words this app writes
2235
+ * (identityRefusal), else none. A ledger kept from before that check holds the contact's own words there.
2236
+ */
2237
+ var ownRefusal = (s) => {
2238
+ if (s.error === void 0 || identityRefusal(s.error) !== void 0) return s;
2239
+ const { error: _contactWords, ...rest } = s;
2240
+ return rest;
2241
+ };
2242
+ /**
2064
2243
  * Identity proofs, engine side: the profile's own proofs (made once, on the Identities page) and, per
2065
2244
  * chat, the `IdentityExchange` that shares them with that contact and checks what the contact shares.
2066
2245
  * Providers come from the registry; their `verify` runs here, through the shared checks.
@@ -2075,6 +2254,9 @@ var IdentityProofs = class {
2075
2254
  lookupsMissed = 0;
2076
2255
  /** The lookup under way, if one was cut short (`REVOCATIONS_ROUND`). */
2077
2256
  round;
2257
+ /** When `round` was last written (ms), and how many proofs it gained since: `noteRound`. */
2258
+ roundSavedAt = 0;
2259
+ roundUnsaved = 0;
2078
2260
  /**
2079
2261
  * How the last Pkarr read of each contact's proof went (`revoked`), by proof id: answered, could not run (offline, no
2080
2262
  * relay answered), or held back by the relays' budget, which takes reads again in this many ms.
@@ -2088,6 +2270,8 @@ var IdentityProofs = class {
2088
2270
  stops = 0;
2089
2271
  /** Ends the 12 h lookup's wait (between two reads, or for the budget) at once: `stop`. */
2090
2272
  wakeLookup;
2273
+ /** Ends the automatic re-check's wait between two checks at once: `stop`. */
2274
+ wakeRecheck;
2091
2275
  /** Revocations not published because the app was offline: published when the network comes back (`networkBack`). */
2092
2276
  unpublished = /* @__PURE__ */ new Set();
2093
2277
  running = false;
@@ -2126,10 +2310,11 @@ var IdentityProofs = class {
2126
2310
  /** Background work: republish revocations, look up the contacts' proofs for revocations. */
2127
2311
  start() {
2128
2312
  this.running = true;
2313
+ const stops = this.stops;
2129
2314
  const every = (ms, first, work) => {
2130
2315
  const tick = () => {
2131
2316
  work().catch(() => {}).finally(() => {
2132
- this.timers.push(setTimeout(tick, ms));
2317
+ if (this.stops === stops) this.timers.push(setTimeout(tick, ms));
2133
2318
  });
2134
2319
  };
2135
2320
  this.timers.push(setTimeout(tick, first));
@@ -2171,7 +2356,9 @@ var IdentityProofs = class {
2171
2356
  for (const t of this.timers) clearTimeout(t);
2172
2357
  this.timers = [];
2173
2358
  this.lookupTimer = void 0;
2359
+ this.saveRound();
2174
2360
  this.wakeLookup?.();
2361
+ this.wakeRecheck?.();
2175
2362
  this.unlisten?.();
2176
2363
  this.unlisten = void 0;
2177
2364
  this.forgetSeeds();
@@ -2222,22 +2409,26 @@ var IdentityProofs = class {
2222
2409
  * that could not run, and the contact is told only that.
2223
2410
  */
2224
2411
  verifyContact = async (statement, evidence) => {
2225
- if (!this.host.relayOnly?.()) return this.verify(statement, evidence);
2226
- const { fixedIdentityHosts } = await import("./fixedHosts-C2hdCfzK.js");
2227
- const fixed = fixedIdentityHosts();
2228
2412
  let refused;
2229
- const fetch = async (url, options) => {
2230
- const host = new URL(url).host;
2231
- if (!fixed.has(host)) {
2232
- refused ??= host;
2233
- throw new IdentityCheckUnavailable(`${host} was not contacted`);
2234
- }
2235
- return this.fetch(url, options);
2236
- };
2413
+ let fetch = this.fetch;
2414
+ if (this.host.relayOnly?.()) {
2415
+ const { fixedIdentityHosts } = await import("./fixedHosts-PR1BcfKX.js");
2416
+ const fixed = fixedIdentityHosts();
2417
+ fetch = async (url, options) => {
2418
+ const host = new URL(url).host;
2419
+ if (!fixed.has(host)) {
2420
+ refused ??= host;
2421
+ throw new IdentityCheckUnavailable(`${host} was not contacted`);
2422
+ }
2423
+ return this.fetch(url, options);
2424
+ };
2425
+ }
2426
+ const ctx = this.ctx(fetch);
2237
2427
  try {
2238
- return await verifyIdentity(this.providers(), statement, evidence, this.ctx(fetch));
2428
+ return await verifyIdentity(this.providers(), statement, evidence, ctx);
2239
2429
  } catch (e) {
2240
2430
  if (refused) throw new IdentityCheckUnavailable(`Hide my IP from contacts is on: ${refused}, a server your contact chose, was not contacted`);
2431
+ if (ctx.signal.aborted && !(e instanceof IdentityCheckUnavailable)) throw new IdentityCheckUnavailable(e instanceof Error ? e.message : String(e));
2241
2432
  throw e;
2242
2433
  }
2243
2434
  };
@@ -2345,8 +2536,7 @@ var IdentityProofs = class {
2345
2536
  expiresAt: Math.min(proof.binding.expiresAt, proof.verified.expiresAt ?? Infinity)
2346
2537
  };
2347
2538
  const wasShared = this.everShared(proof);
2348
- const revoke = wasShared && revocation.expiresAt > now();
2349
- await this.save((proofs, revocations) => proofs.some((p) => identityStatement(p.binding).id === id) ? [proofs.filter((p) => identityStatement(p.binding).id !== id), revoke ? [...revocations, revocation] : revocations] : [proofs, revocations]);
2539
+ await this.save((proofs, revocations) => proofs.some((p) => identityStatement(p.binding).id === id) ? [proofs.filter((p) => identityStatement(p.binding).id !== id), wasShared ? [...revocations, revocation] : revocations] : [proofs, revocations]);
2350
2540
  if (wasShared) this.publishRevocation(revocation).catch(() => {});
2351
2541
  else {
2352
2542
  this.seeds.get(id)?.fill(0);
@@ -2362,7 +2552,7 @@ var IdentityProofs = class {
2362
2552
  this.ended = true;
2363
2553
  this.stop();
2364
2554
  const at = now();
2365
- const last = [...this.revocations.filter((r) => r.expiresAt > at), ...this.proofs.filter((p) => this.everShared(p)).map((p) => ({
2555
+ const last = [...this.revocations, ...this.proofs.filter((p) => this.everShared(p)).map((p) => ({
2366
2556
  id: identityStatement(p.binding).id,
2367
2557
  key: p.binding.key,
2368
2558
  seed: p.seed,
@@ -2389,15 +2579,18 @@ var IdentityProofs = class {
2389
2579
  }]);
2390
2580
  }
2391
2581
  async republish() {
2392
- const live = this.revocations.filter((r) => r.expiresAt > now());
2393
- if (live.length !== this.revocations.length) {
2394
- for (const r of this.revocations) if (!live.includes(r)) {
2582
+ const kept = (r) => r.expiresAt + REVOCATION_KEPT_PAST_EXPIRY > now();
2583
+ if (!this.revocations.every(kept)) {
2584
+ for (const r of this.revocations) if (!kept(r)) {
2395
2585
  this.seeds.get(r.id)?.fill(0);
2396
2586
  this.seeds.delete(r.id);
2397
2587
  }
2398
- await this.save((proofs, revocations) => [proofs, revocations.filter((r) => r.expiresAt > now())]);
2588
+ await this.save((proofs, revocations) => [proofs, revocations.filter(kept)]);
2589
+ }
2590
+ for (const r of this.revocations.filter((r) => r.expiresAt > now())) {
2591
+ if (!this.running) return;
2592
+ await this.publishRevocation(r).catch(() => {});
2399
2593
  }
2400
- for (const r of live) await this.publishRevocation(r).catch(() => {});
2401
2594
  }
2402
2595
  /**
2403
2596
  * Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
@@ -2407,6 +2600,7 @@ var IdentityProofs = class {
2407
2600
  * Each proof answered is noted in the lookup under way (`round`, kept across a restart): one cut short (a read that
2408
2601
  * failed, the relays' budget still held after its tries, the network gone, the app stopped) goes on later from the
2409
2602
  * proofs still to look up. Started again from the first, a few keys no relay answered cost every proof's read again.
2603
+ * It is written about once a minute (`ROUND_SAVE_MS`) and whenever the lookup ends without completing.
2410
2604
  *
2411
2605
  * One read every `REVOCATION_READ_GAP_MS`, the longest unread first: read back to back, the lookup took the relays'
2412
2606
  * whole background share for a minute, and every read past it was held back.
@@ -2419,11 +2613,13 @@ var IdentityProofs = class {
2419
2613
  done: []
2420
2614
  };
2421
2615
  const round = this.round, done = new Set(round.done);
2616
+ this.roundSavedAt = at;
2617
+ this.roundUnsaved = 0;
2422
2618
  const todo = this.host.linkIds().flatMap((linkId) => (this.host.ledger(linkId)?.received ?? []).filter((r) => this.revocable(r) && !done.has(`${linkId}|${r.id}`)).map((r) => ({
2423
2619
  linkId,
2424
2620
  id: r.id
2425
2621
  }))).sort((a, b) => (this.lastRead.get(a.id) ?? 0) - (this.lastRead.get(b.id) ?? 0));
2426
- let missed = false, wait = 0;
2622
+ let missed = false, wait = 0, complete = false;
2427
2623
  const stops = this.stops;
2428
2624
  try {
2429
2625
  for (const { linkId, id } of todo) for (let tries = 0;; tries++) {
@@ -2440,13 +2636,15 @@ var IdentityProofs = class {
2440
2636
  }
2441
2637
  if (typeof read !== "number") {
2442
2638
  round.done.push(`${linkId}|${id}`);
2443
- this.saveRound(round);
2639
+ this.noteRound(round);
2444
2640
  break;
2445
2641
  }
2446
2642
  if (tries >= BUDGET_TRIES) return false;
2447
2643
  }
2644
+ complete = !missed;
2448
2645
  } finally {
2449
2646
  this.reads.clear();
2647
+ if (!complete) this.saveRound(round);
2450
2648
  }
2451
2649
  if (this.ended || missed) return false;
2452
2650
  this.revocationsCheckedAt = Date.now();
@@ -2457,9 +2655,17 @@ var IdentityProofs = class {
2457
2655
  });
2458
2656
  return true;
2459
2657
  }
2460
- /** Not waited on: the writes keep their order, so the lookup's end (which deletes it) lands after. */
2461
- saveRound(round) {
2462
- if (this.ended || this.round !== round) return;
2658
+ /** A proof read in the lookup under way: written a minute after the last write, or once `ROUND_SAVE_READS` wait (a clock set back writes too). */
2659
+ noteRound(round) {
2660
+ this.roundUnsaved++;
2661
+ const since = Date.now() - this.roundSavedAt;
2662
+ if (this.roundUnsaved >= ROUND_SAVE_READS || since >= ROUND_SAVE_MS || since < 0) this.saveRound(round);
2663
+ }
2664
+ /** Not waited on: the writes keep their order, so the lookup's end (which deletes it) lands after. Nothing new since the last write: nothing written. */
2665
+ saveRound(round = this.round) {
2666
+ if (!round || this.roundUnsaved === 0 || this.ended || this.round !== round) return;
2667
+ this.roundUnsaved = 0;
2668
+ this.roundSavedAt = Date.now();
2463
2669
  transact([STORES.settings], (stores) => {
2464
2670
  stores[STORES.settings].put({
2465
2671
  ...round,
@@ -2468,9 +2674,9 @@ var IdentityProofs = class {
2468
2674
  }).catch(() => {});
2469
2675
  }
2470
2676
  /**
2471
- * The contacts' proofs due for an automatic re-check (`AUTO_RECHECK_AFTER_S`), the longest unchecked first, a few at a
2472
- * time, one after the other. A proof whose record or key is gone shows unconfirmed with the reason, as after "Check
2473
- * again"; one whose server could not be reached (or a network that went away meanwhile) is left as it was and backs off.
2677
+ * The contacts' proofs due for an automatic re-check (`AUTO_RECHECK_AFTER_S`), the longest unchecked first, as many
2678
+ * at a time as keep up with them (`AUTO_RECHECK_SPREAD_TICKS`), one after the other a few seconds apart. A proof whose
2679
+ * record or key is gone shows unconfirmed with the reason, as after "Check again"; one whose server could not be reached (or a network that went away meanwhile) is left as it was and backs off.
2474
2680
  */
2475
2681
  async recheckDue() {
2476
2682
  if (!this.host.online()) return;
@@ -2479,14 +2685,18 @@ var IdentityProofs = class {
2479
2685
  for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) {
2480
2686
  const after = this.providers().find((p) => p.id === r.binding.provider)?.recheck?.afterSeconds;
2481
2687
  if (after === void 0 || r.status !== "verified" && r.status !== "unconfirmed" || !this.revocable(r)) continue;
2482
- if (t - r.checkedAt < Math.max(after, 86400) || (this.recheckBackoff.get(`${linkId}|${r.id}`)?.until ?? 0) > at) continue;
2688
+ if (r.checkedAt <= t && t - r.checkedAt < Math.max(after, 86400) || (this.recheckBackoff.get(`${linkId}|${r.id}`)?.until ?? 0) > at) continue;
2483
2689
  due.push({
2484
2690
  linkId,
2485
2691
  r
2486
2692
  });
2487
2693
  }
2488
- for (const { linkId, r } of due.sort((a, b) => a.r.checkedAt - b.r.checkedAt).slice(0, AUTO_RECHECK_BATCH)) {
2489
- if (this.ended || !this.host.online()) return;
2694
+ const batch = Math.min(AUTO_RECHECK_MAX_BATCH, Math.max(AUTO_RECHECK_BATCH, Math.ceil(due.length / AUTO_RECHECK_SPREAD_TICKS)));
2695
+ let first = true;
2696
+ for (const { linkId, r } of due.sort((a, b) => a.r.checkedAt - b.r.checkedAt).slice(0, batch)) {
2697
+ if (!first && !await this.recheckPause(AUTO_RECHECK_GAP_MS)) return;
2698
+ first = false;
2699
+ if (this.ended || !this.running || !this.host.online()) return;
2490
2700
  const key = `${linkId}|${r.id}`;
2491
2701
  try {
2492
2702
  await this.exchange(linkId)?.recheck(r.id, { keepUnavailable: true });
@@ -2500,6 +2710,22 @@ var IdentityProofs = class {
2500
2710
  }
2501
2711
  }
2502
2712
  }
2713
+ /** The automatic re-check's wait between two checks: false when `stop` ended it. */
2714
+ recheckPause(ms) {
2715
+ return new Promise((resolve) => {
2716
+ const timer = setTimeout(() => {
2717
+ this.timers = this.timers.filter((t) => t !== timer);
2718
+ this.wakeRecheck = void 0;
2719
+ resolve(true);
2720
+ }, ms);
2721
+ this.timers.push(timer);
2722
+ this.wakeRecheck = () => {
2723
+ clearTimeout(timer);
2724
+ this.wakeRecheck = void 0;
2725
+ resolve(false);
2726
+ };
2727
+ });
2728
+ }
2503
2729
  /** The 12 h lookup's wait between two reads, or for the budget: false when `stop` ended it. */
2504
2730
  lookupPause(ms) {
2505
2731
  return new Promise((resolve) => {
@@ -2644,8 +2870,9 @@ var IdentityProofs = class {
2644
2870
  const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
2645
2871
  const provider = r && this.providers().find((p) => p.id === r.binding.provider);
2646
2872
  if (!r || !provider?.lookupDisplay) throw new Error("No public profile for this identity");
2647
- const display = await provider.lookupDisplay(r.verified.subject, { signal: AbortSignal.timeout(15e3) });
2648
- if (!display) throw new Error("No public profile found");
2873
+ const found = await provider.lookupDisplay(r.verified.subject, { signal: AbortSignal.timeout(15e3) });
2874
+ if (!found) throw new Error("No public profile found");
2875
+ const display = boundIdentityDisplay(found);
2649
2876
  await this.host.updateLedger(linkId, (l) => ({
2650
2877
  ...l,
2651
2878
  received: l.received.map((x) => x.id === id && x.verified.subject === r.verified.subject ? {
@@ -2660,9 +2887,13 @@ var IdentityProofs = class {
2660
2887
  if (!x) return;
2661
2888
  const id = frame.t === "idp-withdraw" && typeof frame.id === "string" ? frame.id : frame.t === "idp-present" && isIdentityBinding(frame.binding) ? identityStatement(frame.binding).id : void 0;
2662
2889
  const withdrawn = () => !!id && !!this.host.ledger(linkId)?.received.some((r) => r.id === id && r.status === "withdrawn");
2663
- const before = withdrawn();
2664
- await x.receive(frame);
2665
- if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
2890
+ const checking = () => frame.t === "idp-withdraw" && !!this.host.ledger(linkId)?.challenges.some((c) => c.id === id && !c.withdrawn);
2891
+ const before = withdrawn() && !checking();
2892
+ const handled = x.receive(frame).then(() => {
2893
+ if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
2894
+ });
2895
+ if (frame.t === "idp-present") handled.catch(() => {});
2896
+ else await handled;
2666
2897
  }
2667
2898
  ready(linkId) {
2668
2899
  if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
@@ -2689,7 +2920,7 @@ var IdentityProofs = class {
2689
2920
  return {
2690
2921
  support: supported,
2691
2922
  contactProviders: supported ? this.exchanges.get(linkId)?.contactProviders?.slice() : void 0,
2692
- shared: ledger.shared,
2923
+ shared: ledger.shared.map(ownRefusal),
2693
2924
  received: ledger.received.map((r) => {
2694
2925
  const provider = this.providers().find((p) => p.id === r.binding.provider);
2695
2926
  const status = receivedIdentityStatus(r, theirs, mine, t);
@@ -2705,7 +2936,7 @@ var IdentityProofs = class {
2705
2936
  checkedAt: r.checkedAt,
2706
2937
  expiresAt: Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity),
2707
2938
  error: r.error,
2708
- recheckDue: !!provider?.recheck && t - r.checkedAt >= provider.recheck.afterSeconds,
2939
+ recheckDue: !!provider?.recheck && (r.checkedAt > t || t - r.checkedAt >= provider.recheck.afterSeconds),
2709
2940
  ...publicProfile ? { publicProfile } : {}
2710
2941
  };
2711
2942
  }),
@@ -3166,7 +3397,7 @@ var GroupFileDesk = class {
3166
3397
  transferred: 0,
3167
3398
  size,
3168
3399
  direction: "in",
3169
- retry: true,
3400
+ retry: !this.deps.out?.(groupId),
3170
3401
  error: file.transfer.error ?? DAMAGED
3171
3402
  });
3172
3403
  else if (file.group.paused) {
@@ -3404,6 +3635,8 @@ var GroupFileDesk = class {
3404
3635
  const kept = this.kept.get(fileId);
3405
3636
  if (!kept) throw new Error("No such file");
3406
3637
  if (kept.held) return;
3638
+ const out = this.deps.out?.(kept.groupId);
3639
+ if (out) throw new Error(out);
3407
3640
  if (!await this.hasRoom(kept.meta.size)) throw new Error(NO_ROOM);
3408
3641
  if (!kept.asked || kept.paused) {
3409
3642
  kept.asked = true;
@@ -3634,6 +3867,11 @@ var GroupFileDesk = class {
3634
3867
  ask(kept) {
3635
3868
  const want = this.wants.get(kept.id);
3636
3869
  if (!want || kept.held || want.wire) return;
3870
+ const out = this.deps.out?.(kept.groupId);
3871
+ if (out) {
3872
+ this.stop(kept, false).then(() => this.stopFailed(kept, out, false));
3873
+ return;
3874
+ }
3637
3875
  const membership = this.deps.membership(kept.groupId);
3638
3876
  const edges = this.deps.edges(kept.groupId);
3639
3877
  const known = this.knownHolders(kept, membership);
@@ -3767,9 +4005,9 @@ var GroupFileDesk = class {
3767
4005
  }
3768
4006
  /**
3769
4007
  * No holder serves the author's bytes (`DAMAGED`), or this device has no room for them (`NO_ROOM`): the want stops,
3770
- * and stays stopped after a restart, until Download.
4008
+ * and stays stopped after a restart, until Download. Out of the group (`retry` false), Download says why instead.
3771
4009
  */
3772
- stopFailed(kept, error = DAMAGED) {
4010
+ stopFailed(kept, error = DAMAGED, retry = true) {
3773
4011
  this.wants.delete(kept.id);
3774
4012
  const { size } = kept.meta;
3775
4013
  this.deps.store.patch(kept.id, { transfer: {
@@ -3783,7 +4021,7 @@ var GroupFileDesk = class {
3783
4021
  transferred: 0,
3784
4022
  size,
3785
4023
  direction: "in",
3786
- retry: true,
4024
+ retry,
3787
4025
  error
3788
4026
  });
3789
4027
  }
@@ -4355,6 +4593,6 @@ function messageFile(kept) {
4355
4593
  };
4356
4594
  }
4357
4595
  //#endregion
4358
- export { WrongNetworkError as $, IdentityProofs as A, ProviderSources as B, FileAppender as C, streamStored as D, storedSize as E, normalizePhrase as F, breezDatabaseInUse as G, CASHU_MINT_SOURCE as H, journaledPayment as I, iceServerProblem as J, breezDatabasesFor as K, lightningPaying as L, LightningCards as M, cardsKey as N, waitingGroupFile as O, isRecoveryPhrase as P, ModeGate as Q, INVOICE_PACE as R, WALLET_TYPES as S, removeStored as T, cashuMint as U, sourceKey as V, breezDatabase as W, relayOnlyProblem as X, iceServerSetting as Y, ModeChanged as Z, crossNetwork as _, storedGroupFiles as a, setSingleWriterGate as at, walletInstances as b, receivedPairedReply as c, paymentAlias as d, networkLabel as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, setAwayWallets as it, CASHU_CARD as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, refuseAway as nt, groupReply as o, WALLET_NAMES as p, dropBreezDatabase as q, groupFileText as r, requireTurn as rt, pairedWireReply as s, GroupFileDesk as t, awayFrom as tt, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, nextInvoiceAsk as z };
4596
+ export { ModeGate as $, IdentityProofs as A, ProviderSources as B, FileAppender as C, streamStored as D, storedSize as E, normalizePhrase as F, breezDatabase as G, AskBackoff as H, journaledPayment as I, dropBreezDatabase as J, breezDatabaseInUse as K, lightningPaying as L, LightningCards as M, cardsKey as N, waitingGroupFile as O, isRecoveryPhrase as P, ModeChanged as Q, INVOICE_PACE as R, WALLET_TYPES as S, removeStored as T, CASHU_MINT_SOURCE as U, sourceKey as V, cashuMint as W, iceServerSetting as X, iceServerProblem as Y, relayOnlyProblem as Z, crossNetwork as _, storedGroupFiles as a, setAwayWallets as at, walletInstances as b, receivedPairedReply as c, paymentAlias as d, WrongNetworkError as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, requireTurn as it, CASHU_CARD as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, awayFrom as nt, groupReply as o, setSingleWriterGate as ot, WALLET_NAMES as p, breezDatabasesFor as q, groupFileText as r, refuseAway as rt, pairedWireReply as s, GroupFileDesk as t, networkLabel as tt, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, nextInvoiceAsk as z };
4359
4597
 
4360
- //# sourceMappingURL=groupFiles-BAQIt_bJ.js.map
4598
+ //# sourceMappingURL=groupFiles-BuToTMUk.js.map