@ghostlytools/cli 1.10.0 → 1.10.2

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 (104) hide show
  1. package/README.md +19 -17
  2. package/SKILL.md +5 -4
  3. package/dist/assets/api-DcE4KylM.js +3 -0
  4. package/dist/assets/{api-BF_KwecF.js → api-EUGHGnRz.js} +108 -49
  5. package/dist/assets/api-EUGHGnRz.js.map +1 -0
  6. package/dist/assets/{apiKit-Du1u2l4x.js → apiKit-CJVp_crp.js} +85 -22
  7. package/dist/assets/apiKit-CJVp_crp.js.map +1 -0
  8. package/dist/assets/{apps-Bti9fDoW.js → apps-C-KbyLCa.js} +1 -1
  9. package/dist/assets/{apps-DwPfp54I.js → apps-C54T_MOT.js} +33 -12
  10. package/dist/assets/apps-C54T_MOT.js.map +1 -0
  11. package/dist/assets/{arkade-DOWpA2Kr.js → arkade-BmxJTa65.js} +2 -2
  12. package/dist/assets/{arkade-DOWpA2Kr.js.map → arkade-BmxJTa65.js.map} +1 -1
  13. package/dist/assets/{backup-DZ_Q1eSu.js → backup-BxSH5BZG.js} +7 -6
  14. package/dist/assets/{backup-DZ_Q1eSu.js.map → backup-BxSH5BZG.js.map} +1 -1
  15. package/dist/assets/{backup-CeRckyl2.js → backup-C0Plp-DF.js} +1 -1
  16. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  17. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  18. package/dist/assets/{buttons-BxIThdg9.js → buttons-B-ZJYdo0.js} +6 -6
  19. package/dist/assets/{buttons-BxIThdg9.js.map → buttons-B-ZJYdo0.js.map} +1 -1
  20. package/dist/assets/buttons-DA3wZfG0.js +2 -0
  21. package/dist/assets/childEnv-BVOQK9EA.js +21 -0
  22. package/dist/assets/childEnv-BVOQK9EA.js.map +1 -0
  23. package/dist/assets/{client-D5E1RQYB.js → client-CDa87uYD.js} +3 -3
  24. package/dist/assets/{client-D5E1RQYB.js.map → client-CDa87uYD.js.map} +1 -1
  25. package/dist/assets/codec-D45W1L8n.js +13 -0
  26. package/dist/assets/codec-D45W1L8n.js.map +1 -0
  27. package/dist/assets/{envelope-CugS9qwQ.js → envelope-C3yFCQa-.js} +3 -12
  28. package/dist/assets/envelope-C3yFCQa-.js.map +1 -0
  29. package/dist/assets/{errors-R4S2SAEM.js → errors-Dt-ZnyOX.js} +3 -1
  30. package/dist/assets/errors-Dt-ZnyOX.js.map +1 -0
  31. package/dist/assets/{fixedHosts-B4E4VrYE.js → fixedHosts-C6nCHjOa.js} +4 -4
  32. package/dist/assets/{fixedHosts-B4E4VrYE.js.map → fixedHosts-C6nCHjOa.js.map} +1 -1
  33. package/dist/assets/{groupFiles-NonOYBKN.js → groupFiles-DYopNE57.js} +217 -178
  34. package/dist/assets/groupFiles-DYopNE57.js.map +1 -0
  35. package/dist/assets/{host-DvcVt5YI.js → host-G5seUwaI.js} +241 -87
  36. package/dist/assets/host-G5seUwaI.js.map +1 -0
  37. package/dist/assets/{hyperdhtRelay-Ce42sR8x.js → hyperdhtRelay-B_uHjg_r.js} +28 -20
  38. package/dist/assets/hyperdhtRelay-B_uHjg_r.js.map +1 -0
  39. package/dist/assets/{irohWeb-C9ChbD-c.js → irohWeb-C-2oslSU.js} +120 -38
  40. package/dist/assets/irohWeb-C-2oslSU.js.map +1 -0
  41. package/dist/assets/{main-4qE381KM.js → main-Dk--nD7X.js} +92 -48
  42. package/dist/assets/main-Dk--nD7X.js.map +1 -0
  43. package/dist/assets/{mainline-DOwZDHVy.js → mainline-HPlVrl8R.js} +5 -5
  44. package/dist/assets/mainline-HPlVrl8R.js.map +1 -0
  45. package/dist/assets/networkReason-CfpO9ayz.js +474 -0
  46. package/dist/assets/networkReason-CfpO9ayz.js.map +1 -0
  47. package/dist/assets/{nwc-CHLWFV1R.js → nwc-BY7BPttn.js} +3 -3
  48. package/dist/assets/{nwc-CHLWFV1R.js.map → nwc-BY7BPttn.js.map} +1 -1
  49. package/dist/assets/{nwcProvider-BlkPOJen.js → nwcProvider-CfpbNUf7.js} +2 -2
  50. package/dist/assets/{nwcProvider-BlkPOJen.js.map → nwcProvider-CfpbNUf7.js.map} +1 -1
  51. package/dist/assets/{ownDid-yXtY_1B5.js → ownDid-DJFZM2cV.js} +2 -2
  52. package/dist/assets/{ownDid-yXtY_1B5.js.map → ownDid-DJFZM2cV.js.map} +1 -1
  53. package/dist/assets/{profiles-vbXHs0Mq.js → profiles-DKmZGXp6.js} +22 -9
  54. package/dist/assets/profiles-DKmZGXp6.js.map +1 -0
  55. package/dist/assets/{registry-chCD0KWS.js → registry-BUm4cAzV.js} +60 -19
  56. package/dist/assets/registry-BUm4cAzV.js.map +1 -0
  57. package/dist/assets/{registry-BN9r2pR4.js → registry-CAzrtV0_.js} +1 -1
  58. package/dist/assets/{resolve-Dtzogt2W.js → resolve-CDD4X68j.js} +5 -3
  59. package/dist/assets/resolve-CDD4X68j.js.map +1 -0
  60. package/dist/assets/{restoredRows-CRYwIx3g.js → restoredRows-YhlbokEE.js} +4 -2
  61. package/dist/assets/restoredRows-YhlbokEE.js.map +1 -0
  62. package/dist/assets/{secretGuard-CSVNxXVW.js → secretGuard-B7Hj0Kvz.js} +2 -2
  63. package/dist/assets/{secretGuard-CSVNxXVW.js.map → secretGuard-B7Hj0Kvz.js.map} +1 -1
  64. package/dist/assets/secretGuard-DUr6bgKc.js +2 -0
  65. package/dist/assets/{server-BZnsm5X5.js → server-DcOsgYDU.js} +1046 -573
  66. package/dist/assets/server-DcOsgYDU.js.map +1 -0
  67. package/dist/assets/{src-DZagapGt.js → src-D31D1_oY.js} +2360 -1673
  68. package/dist/assets/src-D31D1_oY.js.map +1 -0
  69. package/dist/assets/{sshForges-BkTgy5rx.js → sshForges-DerRwMf3.js} +2 -2
  70. package/dist/assets/{sshForges-BkTgy5rx.js.map → sshForges-DerRwMf3.js.map} +1 -1
  71. package/dist/assets/{translate-B9SMd6uf.js → translate-C-sj0VJe.js} +12 -8
  72. package/dist/assets/{translate-B9SMd6uf.js.map → translate-C-sj0VJe.js.map} +1 -1
  73. package/dist/assets/{usdt-BU4ezonh.js → usdt-DwHqp625.js} +3 -3
  74. package/dist/assets/{usdt-BU4ezonh.js.map → usdt-DwHqp625.js.map} +1 -1
  75. package/dist/assets/{waitNotice-B8D8WhbE.js → waitNotice-D52RWbV4.js} +38 -4
  76. package/dist/assets/waitNotice-D52RWbV4.js.map +1 -0
  77. package/dist/assets/{words-jYy7lTcb.js → words-Db9WgatT.js} +3 -3
  78. package/dist/assets/words-Db9WgatT.js.map +1 -0
  79. package/dist/ghostly.mjs +1 -1
  80. package/package.json +1 -1
  81. package/dist/assets/api-BF_KwecF.js.map +0 -1
  82. package/dist/assets/api-DdrA86Ur.js +0 -3
  83. package/dist/assets/apiKit-Du1u2l4x.js.map +0 -1
  84. package/dist/assets/apps-DwPfp54I.js.map +0 -1
  85. package/dist/assets/buttons-D9QBHS9Y.js +0 -2
  86. package/dist/assets/envelope-CugS9qwQ.js.map +0 -1
  87. package/dist/assets/errors-R4S2SAEM.js.map +0 -1
  88. package/dist/assets/groupFiles-NonOYBKN.js.map +0 -1
  89. package/dist/assets/host-DvcVt5YI.js.map +0 -1
  90. package/dist/assets/hyperdhtRelay-Ce42sR8x.js.map +0 -1
  91. package/dist/assets/irohWeb-C9ChbD-c.js.map +0 -1
  92. package/dist/assets/main-4qE381KM.js.map +0 -1
  93. package/dist/assets/mainline-DOwZDHVy.js.map +0 -1
  94. package/dist/assets/networkReason-MInk1Y63.js +0 -154
  95. package/dist/assets/networkReason-MInk1Y63.js.map +0 -1
  96. package/dist/assets/profiles-vbXHs0Mq.js.map +0 -1
  97. package/dist/assets/registry-chCD0KWS.js.map +0 -1
  98. package/dist/assets/resolve-Dtzogt2W.js.map +0 -1
  99. package/dist/assets/restoredRows-CRYwIx3g.js.map +0 -1
  100. package/dist/assets/secretGuard-Q2BKq0q0.js +0 -2
  101. package/dist/assets/server-BZnsm5X5.js.map +0 -1
  102. package/dist/assets/src-DZagapGt.js.map +0 -1
  103. package/dist/assets/waitNotice-B8D8WhbE.js.map +0 -1
  104. package/dist/assets/words-jYy7lTcb.js.map +0 -1
@@ -1,10 +1,9 @@
1
- import { $i as emptyIdentityLedger, Br as FileUplink, Da as fileMessageText, Dn as resolveLightningDestination, En as requestLnurlInvoice, Gu as toBase64Url, Hr as transferEnded, Hu as fromBase64Url, Ia as RateWindow, J as meshMessageRef, On as decodeBolt11, Qn as engineText, Rr as ChatFiles, Tu as isDiscoveryBudgetError, Wu as randomBytes, Xi as IdentityCheckUnavailable, Yi as IDENTITY_REVOCATION_LABEL, Zi as IdentityExchange, Zn as engineError, aa as revokesIdentity, ar as groupFileFallback, cr as readGroupHave, ea as identityRevocationValue, er as GROUP_FILE_LIMITS, ia as receivedIdentityStatus, in as WALLET_NETWORKS, ir as fetchesByItself, lr as readGroupWant, na as isIdentityBinding, no as replySnippet, or as isGroupMessageId, ra as newIdentityBinding, rr as GROUP_WANT_NO_FRAME, ta as identityStatement, tr as GROUP_HAVE_FRAME, un as walletNetworkOf, ur as readGroupWantNo, wu as budgetRetryMs } from "./src-DZagapGt.js";
1
+ import { $n as engineError, Ai as IDENTITY_REVOCATION_LABEL, Ba as RateWindow, Bi as revokesIdentity, Dn as requestLnurlInvoice, Fi as identityRevocationValue, Gr as transferEnded, Ii as identityStatement, J as meshMessageRef, Li as isIdentityBinding, Mi as IdentityExchange, Mu as budgetRetryMs, Nu as isDiscoveryBudgetError, On as resolveLightningDestination, Pi as emptyIdentityLedger, Qu as fromBase64Url, Ri as newIdentityBinding, Ur as FileUplink, Vr as ChatFiles, an as WALLET_NETWORKS, ar as GROUP_WANT_NO_FRAME, cr as isGroupMessageId, dn as walletNetworkOf, dr as readGroupWant, ed as randomBytes, er as engineText, fr as readGroupWantNo, ja as fileMessageText, ji as IdentityCheckUnavailable, kn as decodeBolt11, nr as GROUP_FILE_LIMITS, oo as replySnippet, or as fetchesByItself, rr as GROUP_HAVE_FRAME, sr as groupFileFallback, td as toBase64Url, ur as readGroupHave, zi as receivedIdentityStatus } from "./src-D31D1_oY.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, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-MInk1Y63.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-CfpO9ayz.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-yXtY_1B5.js";
7
- import { i as fromBase64Url$1 } from "./envelope-CugS9qwQ.js";
6
+ import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-DJFZM2cV.js";
8
7
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DjBYYyXT.js";
9
8
  import { sha256 } from "@noble/hashes/sha2.js";
10
9
  import { validateMnemonic } from "@scure/bip39";
@@ -991,6 +990,57 @@ var ProviderSources = class {
991
990
  }
992
991
  };
993
992
  //#endregion
993
+ //#region ../browser/src/engine/askBackoff.ts
994
+ /**
995
+ * A growing wait with a cap, for whatever a wallet asks about again until it gets an answer: a Cashu melt or swap whose
996
+ * mint does not answer or keeps it pending, restored ecash at a mint that cannot say what is spent, a Lightning card's
997
+ * payment its source keeps pending or cannot be reached about. Asked at a fixed pace, each of these knocked on a dead
998
+ * mint or source every 15 to 60 s for as long as the app ran.
999
+ *
1000
+ * Each key is asked at `firstMs` while it is `fast` (a request may still land, the payment is new), then twice as late
1001
+ * after every ask with no answer, up to `capMs`. The pace lives in memory: an app start asks at once, and so does a
1002
+ * caller that knows something changed (it `forget`s the key, or asks whatever the pace says).
1003
+ */
1004
+ var AskBackoff = class {
1005
+ firstMs;
1006
+ capMs;
1007
+ paces = /* @__PURE__ */ new Map();
1008
+ constructor(firstMs, capMs) {
1009
+ this.firstMs = firstMs;
1010
+ this.capMs = capMs;
1011
+ }
1012
+ /** Whether `key` may be asked now: never asked in this run, or its time came. */
1013
+ due(key, now) {
1014
+ const pace = this.paces.get(key);
1015
+ return !pace || now >= pace.at;
1016
+ }
1017
+ /** When `key` is asked next; `now` if it never was in this run. */
1018
+ at(key, now) {
1019
+ return this.paces.get(key)?.at ?? now;
1020
+ }
1021
+ /**
1022
+ * `key` was asked and gave no answer (unreachable, an error, still pending). The next ask waits `firstMs` while
1023
+ * `fast`, else twice the last wait, up to `capMs`. Returns that wait.
1024
+ */
1025
+ missed(key, now, fast = false) {
1026
+ const last = this.paces.get(key)?.wait;
1027
+ const wait = fast || last === void 0 ? this.firstMs : Math.min(last * 2, this.capMs);
1028
+ this.paces.set(key, {
1029
+ at: now + wait,
1030
+ wait
1031
+ });
1032
+ return wait;
1033
+ }
1034
+ /** `key` answered, or is gone: its next ask is due at once. */
1035
+ forget(key) {
1036
+ this.paces.delete(key);
1037
+ }
1038
+ /** Forgets every key but these (the ones still open). */
1039
+ keepOnly(keys) {
1040
+ for (const key of this.paces.keys()) if (!keys.has(key)) this.paces.delete(key);
1041
+ }
1042
+ };
1043
+ //#endregion
994
1044
  //#region ../browser/src/engine/invoicePace.ts
995
1045
  /**
996
1046
  * How often an open invoice of ours is asked about, at its Cashu mint or at a Lightning card's source (agents#2447).
@@ -1078,7 +1128,11 @@ async function journaledPayment(paymentId) {
1078
1128
  if (ops.some((op) => op.state === "sending" || op.state === "pending" || op.state === "unknown")) return "pending";
1079
1129
  return ops.some((op) => op.state === "paid") ? "paid" : void 0;
1080
1130
  }
1131
+ /** A payment whose answer was lost is asked about this often while it is new (OUT_FAST_FOR_MS)... */
1081
1132
  var OUT_POLL_MS = 15e3;
1133
+ var OUT_FAST_FOR_MS = 3e5;
1134
+ /** ...then, while its source keeps it pending or cannot be reached, twice as late each time up to this. */
1135
+ var OUT_SLOW_POLL_MS = 18e5;
1082
1136
  var RECENT = 20;
1083
1137
  /** Resolved Lightning addresses are kept this long for the amount to be chosen; this many at most. */
1084
1138
  var LNURL_TTL_MS = 6e5;
@@ -1103,6 +1157,8 @@ var LightningService = class {
1103
1157
  asked = /* @__PURE__ */ new Map();
1104
1158
  /** Per invoice the screen shows (payment hash): until when (`watch`). */
1105
1159
  watched = /* @__PURE__ */ new Map();
1160
+ /** Per outgoing payment left pending or unknown (payment hash): when its source is asked next, in this run. */
1161
+ outAsk = new AskBackoff(OUT_POLL_MS, OUT_SLOW_POLL_MS);
1106
1162
  passes = Promise.resolve();
1107
1163
  stopped = false;
1108
1164
  recent = [];
@@ -1401,7 +1457,8 @@ var LightningService = class {
1401
1457
  }
1402
1458
  /**
1403
1459
  * Asks the active source about everything of its that is open, pending or unknown. One pass at a time. `paced`: an
1404
- * open invoice only when its pace says so (`nextInvoiceAsk`); otherwise every one now. `only`: the open invoice with
1460
+ * open invoice only when its pace says so (`nextInvoiceAsk`), and a payment left pending or unknown only when its
1461
+ * own does (`outAsk`); otherwise every one now. `only`: the open invoice with
1405
1462
  * this payment hash alone (a payer says it paid it, `check`).
1406
1463
  */
1407
1464
  reconcile(paced = false, only) {
@@ -1412,6 +1469,17 @@ var LightningService = class {
1412
1469
  async reconcileOnce(paced, only) {
1413
1470
  if (this.stopped) return;
1414
1471
  let again = 0;
1472
+ const later = (ms) => {
1473
+ again = again ? Math.min(again, ms) : ms;
1474
+ };
1475
+ /** An outgoing payment asked with no answer (pending, or the source unreachable): asked less and less often. */
1476
+ const missed = (op) => later(this.outAsk.missed(op.paymentHash, Date.now(), Date.now() < op.createdAt + OUT_FAST_FOR_MS));
1477
+ /** Whether a paced pass leaves this outgoing payment for later. */
1478
+ const notYet = (op) => {
1479
+ if (!paced || this.outAsk.due(op.paymentHash, Date.now())) return false;
1480
+ later(Math.max(0, this.outAsk.at(op.paymentHash, Date.now()) - Date.now()));
1481
+ return true;
1482
+ };
1415
1483
  /** When the next open invoice is due. */
1416
1484
  let invoiceDue = Infinity;
1417
1485
  const writes = this.writes;
@@ -1420,23 +1488,25 @@ var LightningService = class {
1420
1488
  const ops = await this.list();
1421
1489
  const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
1422
1490
  for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
1491
+ this.outAsk.keepOnly(new Set(ops.filter((op) => op.direction === "out" && ["pending", "unknown"].includes(op.state)).map((op) => op.paymentHash)));
1423
1492
  for (const op of ops) {
1424
1493
  if (!this.owns(op) || only !== void 0 && (op.direction !== "in" || op.paymentHash !== only)) continue;
1425
1494
  if (op.selfSettled) {
1426
1495
  if (op.direction !== "out" || op.state !== "unknown") continue;
1427
1496
  if (!provider) {
1428
- again = again || OUT_POLL_MS;
1497
+ later(OUT_POLL_MS);
1429
1498
  continue;
1430
1499
  }
1431
- if (op.providerId !== providerId || !provider.interruptedPayment) continue;
1500
+ if (op.providerId !== providerId || !provider.interruptedPayment || notYet(op)) continue;
1432
1501
  try {
1433
1502
  const outcome = await provider.interruptedPayment({
1434
1503
  invoice: op.invoice,
1435
1504
  paymentHash: op.paymentHash,
1436
1505
  ref: op.ref
1437
1506
  });
1438
- if (outcome === "pending") again = again || OUT_POLL_MS;
1507
+ if (outcome === "pending") missed(op);
1439
1508
  if (outcome !== "paid" && outcome !== "failed") continue;
1509
+ this.outAsk.forget(op.paymentHash);
1440
1510
  if ((await this.get("out", op.paymentHash))?.state !== "unknown") continue;
1441
1511
  await this.put({
1442
1512
  ...op,
@@ -1446,7 +1516,7 @@ var LightningService = class {
1446
1516
  });
1447
1517
  this.events.resolved(op, outcome === "paid");
1448
1518
  } catch {
1449
- again = again || OUT_POLL_MS;
1519
+ missed(op);
1450
1520
  }
1451
1521
  continue;
1452
1522
  }
@@ -1459,7 +1529,7 @@ var LightningService = class {
1459
1529
  continue;
1460
1530
  }
1461
1531
  this.asked.set(op.paymentHash, Date.now());
1462
- }
1532
+ } else if (notYet(op)) continue;
1463
1533
  try {
1464
1534
  const unchanged = async () => (await this.get(op.direction, op.paymentHash))?.state === op.state;
1465
1535
  if (op.direction === "in") {
@@ -1490,9 +1560,10 @@ var LightningService = class {
1490
1560
  ref: op.ref
1491
1561
  });
1492
1562
  if (status.state === "pending") {
1493
- again = again || OUT_POLL_MS;
1563
+ missed(op);
1494
1564
  continue;
1495
1565
  }
1566
+ this.outAsk.forget(op.paymentHash);
1496
1567
  if (!await unchanged()) continue;
1497
1568
  await this.put({
1498
1569
  ...op,
@@ -1505,7 +1576,7 @@ var LightningService = class {
1505
1576
  }
1506
1577
  } catch {
1507
1578
  if (op.direction === "in") invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
1508
- else again = again ? Math.min(again, OUT_POLL_MS) : OUT_POLL_MS;
1579
+ else missed(op);
1509
1580
  }
1510
1581
  }
1511
1582
  } finally {
@@ -1987,120 +2058,6 @@ var LightningCards = class {
1987
2058
  }
1988
2059
  };
1989
2060
  //#endregion
1990
- //#region ../browser/src/shared/profileKey.ts
1991
- /**
1992
- * Only the record key can hold a newline: the other parts come from the code, so the joined binding still reads one
1993
- * way (the first two lines, the last line, and the key between them).
1994
- */
1995
- function binding(b) {
1996
- for (const part of [
1997
- b.db,
1998
- b.store,
1999
- b.field
2000
- ]) if (!part || part.includes("\n")) throw new Error("Invalid sealed field binding");
2001
- return new TextEncoder().encode([
2002
- "ghostly-field/2",
2003
- b.db,
2004
- b.store,
2005
- b.key,
2006
- b.field
2007
- ].join("\n"));
2008
- }
2009
- function isSealedField(value) {
2010
- const v = value;
2011
- return !!v && typeof v === "object" && v.v === 2 && typeof v.iv === "string" && typeof v.ct === "string";
2012
- }
2013
- /** Seals one field under DK with a fresh random 96-bit nonce and no KDF per field. */
2014
- async function sealField(key, where, value) {
2015
- const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
2016
- const ct = new Uint8Array(await crypto.subtle.encrypt({
2017
- name: "AES-GCM",
2018
- iv,
2019
- additionalData: binding(where)
2020
- }, key, new TextEncoder().encode(value)));
2021
- return {
2022
- v: 2,
2023
- iv: toBase64Url(iv),
2024
- ct: toBase64Url(ct)
2025
- };
2026
- }
2027
- /** Opens a field sealed for exactly this place under this DK; anything else fails instead of opening wrong. */
2028
- async function openField(key, where, sealed) {
2029
- if (!isSealedField(sealed)) throw new Error("Unsupported sealed field version");
2030
- const aad = binding(where);
2031
- try {
2032
- const iv = fromBase64Url$1(sealed.iv);
2033
- if (iv.length !== 12) throw new Error("nonce");
2034
- return new TextDecoder().decode(await crypto.subtle.decrypt({
2035
- name: "AES-GCM",
2036
- iv,
2037
- additionalData: aad
2038
- }, key, fromBase64Url$1(sealed.ct)));
2039
- } catch {
2040
- throw new Error("A sealed field could not be opened: it was changed, or it belongs to another record");
2041
- }
2042
- }
2043
- //#endregion
2044
- //#region ../browser/src/engine/dataKey.ts
2045
- var PEER_DB = "ghostly";
2046
- /**
2047
- * The profile's data key (DK), when the profile is encrypted and unlocked: the one slot the engine owns. A
2048
- * non-extractable key; nothing writes it anywhere. Empty, every secret is sealed as today (version 1).
2049
- */
2050
- var slot = null;
2051
- /**
2052
- * The profile's migration is over (no `migrating` mark): a sealed place then takes version 2 only. A version 1 or plain
2053
- * value there was put by someone who could write the profile's database but not read it, and is refused.
2054
- */
2055
- var sealedOnly = false;
2056
- var onDrop = /* @__PURE__ */ new Set();
2057
- var LOCKED = "This profile is locked. Enter its passphrase first.";
2058
- function hasDataKey() {
2059
- return slot !== null;
2060
- }
2061
- /** Whether a sealed place may still hold a version 1 or plain value. */
2062
- function takesUnsealed() {
2063
- return !(slot && sealedOnly);
2064
- }
2065
- /** A cache of opened secrets empties itself when the key goes. Returns the way to stop listening. */
2066
- function whenDataKeyDropped(drop) {
2067
- onDrop.add(drop);
2068
- return () => {
2069
- onDrop.delete(drop);
2070
- };
2071
- }
2072
- async function sealSecret(value, at) {
2073
- if (slot) return sealField(slot, {
2074
- db: PEER_DB,
2075
- ...at
2076
- }, value);
2077
- const deviceKey = newDeviceKey();
2078
- return {
2079
- sealed: await sealSeed(value, deviceKey),
2080
- deviceKey
2081
- };
2082
- }
2083
- /** Version 2 only, for a field the database layer seals: refused while the profile is locked, never version 1. */
2084
- async function sealPlace(value, at) {
2085
- if (!slot) throw new Error(LOCKED);
2086
- return sealField(slot, {
2087
- db: PEER_DB,
2088
- ...at
2089
- }, value);
2090
- }
2091
- /** Reads both versions: a profile being encrypted holds some of each until its migration ends. */
2092
- async function openSecret(secret, at) {
2093
- if (!isSealedField(secret)) {
2094
- if (!takesUnsealed()) throw new Error("A secret of this profile was not sealed with its key");
2095
- return unsealSeed(secret.sealed, secret.deviceKey);
2096
- }
2097
- if (!slot) throw new Error(LOCKED);
2098
- return openField(slot, {
2099
- db: PEER_DB,
2100
- ...at
2101
- }, secret);
2102
- }
2103
- //#endregion
2104
2061
  //#region ../browser/src/proofs/load.ts
2105
2062
  /**
2106
2063
  * The identity proof providers, loaded on first need and not with the app: they and their libraries (OpenPGP, the
@@ -2111,7 +2068,7 @@ var registry;
2111
2068
  var loading;
2112
2069
  var listeners = /* @__PURE__ */ new Set();
2113
2070
  function loadIdentityProviders() {
2114
- return loading ??= import("./registry-BN9r2pR4.js").then((m) => {
2071
+ return loading ??= import("./registry-CAzrtV0_.js").then((m) => {
2115
2072
  registry = m;
2116
2073
  for (const listener of listeners) listener();
2117
2074
  return m;
@@ -2150,6 +2107,13 @@ var BUDGET_TRIES = 5;
2150
2107
  */
2151
2108
  var REVOCATION_READ_GAP_MS = 3e3;
2152
2109
  /**
2110
+ * The lookup under way (`REVOCATIONS_ROUND`) is written at most this often, or once this many proofs were read since
2111
+ * (the reads of that time), and when it ends cut short or the engine stops: a restart after a crash reads again at most
2112
+ * those. Written after every read, it cost n writes of 1 to n entries: 45 MB a lookup for 900 proofs.
2113
+ */
2114
+ var ROUND_SAVE_MS = 6e4;
2115
+ var ROUND_SAVE_READS = ROUND_SAVE_MS / REVOCATION_READ_GAP_MS;
2116
+ /**
2153
2117
  * After a contact withdraws a proof, how long to wait before each lookup for its revocation (WISP 300: removing a proof withdraws it from
2154
2118
  * every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
2155
2119
  * off, and the first that finds it stops the rest. The 12 h check covers it after that.
@@ -2190,6 +2154,9 @@ var IdentityProofs = class {
2190
2154
  lookupsMissed = 0;
2191
2155
  /** The lookup under way, if one was cut short (`REVOCATIONS_ROUND`). */
2192
2156
  round;
2157
+ /** When `round` was last written (ms), and how many proofs it gained since: `noteRound`. */
2158
+ roundSavedAt = 0;
2159
+ roundUnsaved = 0;
2193
2160
  /**
2194
2161
  * How the last Pkarr read of each contact's proof went (`revoked`), by proof id: answered, could not run (offline, no
2195
2162
  * relay answered), or held back by the relays' budget, which takes reads again in this many ms.
@@ -2241,10 +2208,11 @@ var IdentityProofs = class {
2241
2208
  /** Background work: republish revocations, look up the contacts' proofs for revocations. */
2242
2209
  start() {
2243
2210
  this.running = true;
2211
+ const stops = this.stops;
2244
2212
  const every = (ms, first, work) => {
2245
2213
  const tick = () => {
2246
2214
  work().catch(() => {}).finally(() => {
2247
- this.timers.push(setTimeout(tick, ms));
2215
+ if (this.stops === stops) this.timers.push(setTimeout(tick, ms));
2248
2216
  });
2249
2217
  };
2250
2218
  this.timers.push(setTimeout(tick, first));
@@ -2286,6 +2254,7 @@ var IdentityProofs = class {
2286
2254
  for (const t of this.timers) clearTimeout(t);
2287
2255
  this.timers = [];
2288
2256
  this.lookupTimer = void 0;
2257
+ this.saveRound();
2289
2258
  this.wakeLookup?.();
2290
2259
  this.unlisten?.();
2291
2260
  this.unlisten = void 0;
@@ -2337,22 +2306,26 @@ var IdentityProofs = class {
2337
2306
  * that could not run, and the contact is told only that.
2338
2307
  */
2339
2308
  verifyContact = async (statement, evidence) => {
2340
- if (!this.host.relayOnly?.()) return this.verify(statement, evidence);
2341
- const { fixedIdentityHosts } = await import("./fixedHosts-B4E4VrYE.js");
2342
- const fixed = fixedIdentityHosts();
2343
2309
  let refused;
2344
- const fetch = async (url, options) => {
2345
- const host = new URL(url).host;
2346
- if (!fixed.has(host)) {
2347
- refused ??= host;
2348
- throw new IdentityCheckUnavailable(`${host} was not contacted`);
2349
- }
2350
- return this.fetch(url, options);
2351
- };
2310
+ let fetch = this.fetch;
2311
+ if (this.host.relayOnly?.()) {
2312
+ const { fixedIdentityHosts } = await import("./fixedHosts-C6nCHjOa.js");
2313
+ const fixed = fixedIdentityHosts();
2314
+ fetch = async (url, options) => {
2315
+ const host = new URL(url).host;
2316
+ if (!fixed.has(host)) {
2317
+ refused ??= host;
2318
+ throw new IdentityCheckUnavailable(`${host} was not contacted`);
2319
+ }
2320
+ return this.fetch(url, options);
2321
+ };
2322
+ }
2323
+ const ctx = this.ctx(fetch);
2352
2324
  try {
2353
- return await verifyIdentity(this.providers(), statement, evidence, this.ctx(fetch));
2325
+ return await verifyIdentity(this.providers(), statement, evidence, ctx);
2354
2326
  } catch (e) {
2355
2327
  if (refused) throw new IdentityCheckUnavailable(`Hide my IP from contacts is on: ${refused}, a server your contact chose, was not contacted`);
2328
+ if (ctx.signal.aborted && !(e instanceof IdentityCheckUnavailable)) throw new IdentityCheckUnavailable(e instanceof Error ? e.message : String(e));
2356
2329
  throw e;
2357
2330
  }
2358
2331
  };
@@ -2512,7 +2485,10 @@ var IdentityProofs = class {
2512
2485
  }
2513
2486
  await this.save((proofs, revocations) => [proofs, revocations.filter((r) => r.expiresAt > now())]);
2514
2487
  }
2515
- for (const r of live) await this.publishRevocation(r).catch(() => {});
2488
+ for (const r of live) {
2489
+ if (!this.running) return;
2490
+ await this.publishRevocation(r).catch(() => {});
2491
+ }
2516
2492
  }
2517
2493
  /**
2518
2494
  * Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
@@ -2522,6 +2498,7 @@ var IdentityProofs = class {
2522
2498
  * Each proof answered is noted in the lookup under way (`round`, kept across a restart): one cut short (a read that
2523
2499
  * failed, the relays' budget still held after its tries, the network gone, the app stopped) goes on later from the
2524
2500
  * proofs still to look up. Started again from the first, a few keys no relay answered cost every proof's read again.
2501
+ * It is written about once a minute (`ROUND_SAVE_MS`) and whenever the lookup ends without completing.
2525
2502
  *
2526
2503
  * One read every `REVOCATION_READ_GAP_MS`, the longest unread first: read back to back, the lookup took the relays'
2527
2504
  * whole background share for a minute, and every read past it was held back.
@@ -2534,11 +2511,13 @@ var IdentityProofs = class {
2534
2511
  done: []
2535
2512
  };
2536
2513
  const round = this.round, done = new Set(round.done);
2514
+ this.roundSavedAt = at;
2515
+ this.roundUnsaved = 0;
2537
2516
  const todo = this.host.linkIds().flatMap((linkId) => (this.host.ledger(linkId)?.received ?? []).filter((r) => this.revocable(r) && !done.has(`${linkId}|${r.id}`)).map((r) => ({
2538
2517
  linkId,
2539
2518
  id: r.id
2540
2519
  }))).sort((a, b) => (this.lastRead.get(a.id) ?? 0) - (this.lastRead.get(b.id) ?? 0));
2541
- let missed = false, wait = 0;
2520
+ let missed = false, wait = 0, complete = false;
2542
2521
  const stops = this.stops;
2543
2522
  try {
2544
2523
  for (const { linkId, id } of todo) for (let tries = 0;; tries++) {
@@ -2555,13 +2534,15 @@ var IdentityProofs = class {
2555
2534
  }
2556
2535
  if (typeof read !== "number") {
2557
2536
  round.done.push(`${linkId}|${id}`);
2558
- this.saveRound(round);
2537
+ this.noteRound(round);
2559
2538
  break;
2560
2539
  }
2561
2540
  if (tries >= BUDGET_TRIES) return false;
2562
2541
  }
2542
+ complete = !missed;
2563
2543
  } finally {
2564
2544
  this.reads.clear();
2545
+ if (!complete) this.saveRound(round);
2565
2546
  }
2566
2547
  if (this.ended || missed) return false;
2567
2548
  this.revocationsCheckedAt = Date.now();
@@ -2572,9 +2553,17 @@ var IdentityProofs = class {
2572
2553
  });
2573
2554
  return true;
2574
2555
  }
2575
- /** Not waited on: the writes keep their order, so the lookup's end (which deletes it) lands after. */
2576
- saveRound(round) {
2577
- if (this.ended || this.round !== round) return;
2556
+ /** 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). */
2557
+ noteRound(round) {
2558
+ this.roundUnsaved++;
2559
+ const since = Date.now() - this.roundSavedAt;
2560
+ if (this.roundUnsaved >= ROUND_SAVE_READS || since >= ROUND_SAVE_MS || since < 0) this.saveRound(round);
2561
+ }
2562
+ /** 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. */
2563
+ saveRound(round = this.round) {
2564
+ if (!round || this.roundUnsaved === 0 || this.ended || this.round !== round) return;
2565
+ this.roundUnsaved = 0;
2566
+ this.roundSavedAt = Date.now();
2578
2567
  transact([STORES.settings], (stores) => {
2579
2568
  stores[STORES.settings].put({
2580
2569
  ...round,
@@ -2601,7 +2590,7 @@ var IdentityProofs = class {
2601
2590
  });
2602
2591
  }
2603
2592
  for (const { linkId, r } of due.sort((a, b) => a.r.checkedAt - b.r.checkedAt).slice(0, AUTO_RECHECK_BATCH)) {
2604
- if (this.ended || !this.host.online()) return;
2593
+ if (this.ended || !this.running || !this.host.online()) return;
2605
2594
  const key = `${linkId}|${r.id}`;
2606
2595
  try {
2607
2596
  await this.exchange(linkId)?.recheck(r.id, { keepUnavailable: true });
@@ -2648,12 +2637,28 @@ var IdentityProofs = class {
2648
2637
  }, wait);
2649
2638
  this.timers.push(timer);
2650
2639
  }
2640
+ /** Every engine state builds these: each chat's ledger is read once for all the proofs, not once per proof. */
2651
2641
  views() {
2652
- return this.proofs.map((p) => this.viewOf(p));
2642
+ const sharedWith = this.sharedWith();
2643
+ return this.proofs.map((p) => this.viewOf(p, sharedWith));
2644
+ }
2645
+ /** The subjects of the profile's own proofs of one provider, without building their views (no chat's ledger is read). */
2646
+ subjects(provider) {
2647
+ return this.proofs.filter((p) => p.binding.provider === provider).map((p) => p.binding.subject);
2648
+ }
2649
+ /** By proof id, the chats it is shared in (not withdrawn, nor rejected by the contact). */
2650
+ sharedWith() {
2651
+ const counts = /* @__PURE__ */ new Map();
2652
+ for (const l of this.host.linkIds()) {
2653
+ const ids = /* @__PURE__ */ new Set();
2654
+ for (const s of this.host.ledger(l)?.shared ?? []) if (s.status !== "withdrawn" && s.status !== "withdrawal-pending" && s.status !== "rejected") ids.add(s.id);
2655
+ for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
2656
+ }
2657
+ return counts;
2653
2658
  }
2654
- viewOf(p) {
2659
+ viewOf(p, shared = this.sharedWith()) {
2655
2660
  const id = identityStatement(p.binding).id;
2656
- const sharedWith = this.host.linkIds().filter((l) => this.host.ledger(l)?.shared.some((s) => s.id === id && s.status !== "withdrawn" && s.status !== "withdrawal-pending" && s.status !== "rejected")).length;
2661
+ const sharedWith = shared.get(id) ?? 0;
2657
2662
  const publicUri = this.publicUri(p);
2658
2663
  const expiresAt = Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity);
2659
2664
  const publicProfile = expiresAt > now() ? this.host.publicProfile?.(p.binding.provider, p.verified.subject) : void 0;
@@ -2759,9 +2764,13 @@ var IdentityProofs = class {
2759
2764
  if (!x) return;
2760
2765
  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;
2761
2766
  const withdrawn = () => !!id && !!this.host.ledger(linkId)?.received.some((r) => r.id === id && r.status === "withdrawn");
2762
- const before = withdrawn();
2763
- await x.receive(frame);
2764
- if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
2767
+ const checking = () => frame.t === "idp-withdraw" && !!this.host.ledger(linkId)?.challenges.some((c) => c.id === id && !c.withdrawn);
2768
+ const before = withdrawn() && !checking();
2769
+ const handled = x.receive(frame).then(() => {
2770
+ if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
2771
+ });
2772
+ if (frame.t === "idp-present") handled.catch(() => {});
2773
+ else await handled;
2765
2774
  }
2766
2775
  ready(linkId) {
2767
2776
  if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
@@ -3265,7 +3274,7 @@ var GroupFileDesk = class {
3265
3274
  transferred: 0,
3266
3275
  size,
3267
3276
  direction: "in",
3268
- retry: true,
3277
+ retry: !this.deps.out?.(groupId),
3269
3278
  error: file.transfer.error ?? DAMAGED
3270
3279
  });
3271
3280
  else if (file.group.paused) {
@@ -3503,6 +3512,8 @@ var GroupFileDesk = class {
3503
3512
  const kept = this.kept.get(fileId);
3504
3513
  if (!kept) throw new Error("No such file");
3505
3514
  if (kept.held) return;
3515
+ const out = this.deps.out?.(kept.groupId);
3516
+ if (out) throw new Error(out);
3506
3517
  if (!await this.hasRoom(kept.meta.size)) throw new Error(NO_ROOM);
3507
3518
  if (!kept.asked || kept.paused) {
3508
3519
  kept.asked = true;
@@ -3606,6 +3617,7 @@ var GroupFileDesk = class {
3606
3617
  want.movedAt = want.offeredAt = this.deps.now();
3607
3618
  want.offeredBytes = kept.stored ?? 0;
3608
3619
  want.free = void 0;
3620
+ want.knownAtOffer = new Set(kept.holders);
3609
3621
  }
3610
3622
  return edge.files.handle(frame);
3611
3623
  }
@@ -3732,6 +3744,11 @@ var GroupFileDesk = class {
3732
3744
  ask(kept) {
3733
3745
  const want = this.wants.get(kept.id);
3734
3746
  if (!want || kept.held || want.wire) return;
3747
+ const out = this.deps.out?.(kept.groupId);
3748
+ if (out) {
3749
+ this.stop(kept, false).then(() => this.stopFailed(kept, out, false));
3750
+ return;
3751
+ }
3735
3752
  const membership = this.deps.membership(kept.groupId);
3736
3753
  const edges = this.deps.edges(kept.groupId);
3737
3754
  const known = this.knownHolders(kept, membership);
@@ -3824,13 +3841,14 @@ var GroupFileDesk = class {
3824
3841
  return false;
3825
3842
  }
3826
3843
  /**
3827
- * The holder serving this want is slow (served `slowAfterMs`, and at its pace more than `wantWaitMs` to go) and a holder
3828
- * that answered it busy said since that a place freed (`want.free`), and is free to ask: the transfer ends here, what
3829
- * came stays, and the next holder is asked (`transferChanged`), so a phone's slow upload does not keep a member the
3830
- * author or a fast holder could serve.
3844
+ * The holder serving this want is slow (served `slowAfterMs`, and at its pace more than `wantWaitMs` to go) and another
3845
+ * holder is free to ask, one known when it offered (`want.knownAtOffer`) or one that answered it busy and said since that
3846
+ * a place freed (`want.free`): the transfer ends here, what came stays, and the next holder is asked
3847
+ * (`transferChanged`), so a phone's slow upload does not keep a member the author or a fast holder could serve. (The
3848
+ * newest holder heard is asked first, whatever its pace: a phone that finished after a fast member is the one taken.)
3831
3849
  */
3832
3850
  leaveSlow(kept, want) {
3833
- if (!want.wire || !want.free?.size || want.offeredAt === void 0) return false;
3851
+ if (!want.wire || want.offeredAt === void 0) return false;
3834
3852
  const edge = want.linkId ? this.edgesById.get(want.linkId) : void 0;
3835
3853
  const record = edge?.files.get("in", want.wire);
3836
3854
  if (!edge || !record || transferEnded(record) || record.state === "verifying") return false;
@@ -3839,7 +3857,8 @@ var GroupFileDesk = class {
3839
3857
  const stored = Math.max(want.moved, kept.stored ?? 0, want.offeredBytes ?? 0), pace = (stored - (want.offeredBytes ?? 0)) / elapsed;
3840
3858
  if (pace > 0 && (kept.meta.size - stored) / pace <= GROUP_FILE_LIMITS.wantWaitMs) return false;
3841
3859
  const edges = this.deps.edges(kept.groupId);
3842
- if (![...want.free].some((key) => {
3860
+ const known = this.knownHolders(kept, this.deps.membership(kept.groupId)).filter((key) => want.knownAtOffer?.has(key));
3861
+ if (![.../* @__PURE__ */ new Set([...known, ...want.free ?? []])].some((key) => {
3843
3862
  const linkId = edges.get(key);
3844
3863
  return !!linkId && key !== want.holder && !kept.suspect?.has(key) && this.mayAsk(kept, want, key, linkId) && this.deps.ready(linkId) && !!this.edgesById.get(linkId)?.files.live && !this.askedOf(linkId, want);
3845
3864
  })) return false;
@@ -3863,9 +3882,9 @@ var GroupFileDesk = class {
3863
3882
  }
3864
3883
  /**
3865
3884
  * No holder serves the author's bytes (`DAMAGED`), or this device has no room for them (`NO_ROOM`): the want stops,
3866
- * and stays stopped after a restart, until Download.
3885
+ * and stays stopped after a restart, until Download. Out of the group (`retry` false), Download says why instead.
3867
3886
  */
3868
- stopFailed(kept, error = DAMAGED) {
3887
+ stopFailed(kept, error = DAMAGED, retry = true) {
3869
3888
  this.wants.delete(kept.id);
3870
3889
  const { size } = kept.meta;
3871
3890
  this.deps.store.patch(kept.id, { transfer: {
@@ -3879,7 +3898,7 @@ var GroupFileDesk = class {
3879
3898
  transferred: 0,
3880
3899
  size,
3881
3900
  direction: "in",
3882
- retry: true,
3901
+ retry,
3883
3902
  error
3884
3903
  });
3885
3904
  }
@@ -3977,7 +3996,9 @@ var GroupFileDesk = class {
3977
3996
  const active = this.servingNow();
3978
3997
  const theirs = active.filter((a) => a.peer === edge.peer);
3979
3998
  const placed = theirs.length > 1 || theirs.some((a) => a.sending || this.deps.now() - a.since >= GROUP_FILE_LIMITS.doneWaitMs);
3980
- if (active.length >= GROUP_FILE_LIMITS.serveAtOnce && (placed || !this.makeRoom())) {
3999
+ const full = active.length >= GROUP_FILE_LIMITS.serveAtOnce;
4000
+ const room = full && !placed ? this.roomFor() : void 0;
4001
+ if (full && !room) {
3981
4002
  edge.busy.set(messageId, this.deps.now());
3982
4003
  return "busy";
3983
4004
  }
@@ -3987,17 +4008,19 @@ var GroupFileDesk = class {
3987
4008
  day: today,
3988
4009
  bytes: 0
3989
4010
  };
3990
- const reserved = this.servingNow().reduce((sum, a) => sum + a.size, 0);
3991
- return this.served.bytes + reserved + kept.meta.size > GROUP_FILE_LIMITS.serveBytesPerDay ? "day" : null;
4011
+ const reserved = active.reduce((sum, a) => sum + a.size, 0) - (room ? room.size - room.sent : 0);
4012
+ if (this.served.bytes + reserved + kept.meta.size > GROUP_FILE_LIMITS.serveBytesPerDay) return "day";
4013
+ if (room) this.cut(room);
4014
+ return null;
3992
4015
  }
3993
4016
  /**
3994
- * Ends a served transfer for a member that holds no place: the one that has held its place longest, once past
3995
- * `servePaceMs`; else the slowest of those under way for `servePaceMs` with more left to go at their pace than they
3996
- * have been served (and than `servePaceMs`), each member's file once (its asker goes on from what it stored, from the
3997
- * next holder or this one, and the members on fast links do not wait for the slow ones that asked first). False when
3998
- * none is.
4017
+ * The served transfer to end for a member that holds no place (undefined when none is): the one that has held its place
4018
+ * longest, once past `servePaceMs`; else the slowest of those under way for `servePaceMs` with more left to go at their
4019
+ * pace than they have been served (and than `servePaceMs`), each member's file once (its asker goes on from what it
4020
+ * stored, from the next holder or this one, and the members on fast links do not wait for the slow ones that asked
4021
+ * first). With its share of the day (as in `servingNow`) and what it sent.
3999
4022
  */
4000
- makeRoom() {
4023
+ roomFor() {
4001
4024
  const now = this.deps.now();
4002
4025
  let oldest;
4003
4026
  let slowest;
@@ -4019,10 +4042,26 @@ var GroupFileDesk = class {
4019
4042
  };
4020
4043
  }
4021
4044
  const cut = oldest ?? slowest;
4022
- if (!cut) return false;
4023
- if (!oldest) cut.edge.paced.add(cut.edge.serving.get(cut.wire));
4024
- cut.edge.files.cancel("out", cut.wire);
4025
- return true;
4045
+ if (!cut) return void 0;
4046
+ const sent = cut.edge.files.sent(cut.wire);
4047
+ return {
4048
+ edge: cut.edge,
4049
+ wire: cut.wire,
4050
+ size: Math.max(cut.edge.files.get("out", cut.wire).file.size, sent),
4051
+ sent,
4052
+ paced: !oldest
4053
+ };
4054
+ }
4055
+ /** Ends the served transfer `roomFor` chose; one ended for its pace is not served its member again. */
4056
+ cut(room) {
4057
+ if (room.paced) room.edge.paced.add(room.edge.serving.get(room.wire));
4058
+ room.edge.files.cancel("out", room.wire);
4059
+ }
4060
+ /** Ends a served transfer for a member that holds no place (`roomFor`): false when none is. */
4061
+ makeRoom() {
4062
+ const room = this.roomFor();
4063
+ if (room) this.cut(room);
4064
+ return !!room;
4026
4065
  }
4027
4066
  /**
4028
4067
  * A member turned away as busy within `wantWaitMs`, holding no place, waits for the holder's word that a place freed:
@@ -4431,6 +4470,6 @@ function messageFile(kept) {
4431
4470
  };
4432
4471
  }
4433
4472
  //#endregion
4434
- export { breezDatabasesFor as $, IdentityProofs as A, cardsKey as B, FileAppender as C, streamStored as D, storedSize as E, takesUnsealed as F, INVOICE_PACE as G, normalizePhrase as H, whenDataKeyDropped as I, sourceKey as J, nextInvoiceAsk as K, isSealedField as L, openSecret as M, sealPlace as N, waitingGroupFile as O, sealSecret as P, breezDatabaseInUse as Q, CASHU_CARD as R, WALLET_TYPES as S, removeStored as T, journaledPayment as U, isRecoveryPhrase as V, lightningPaying as W, cashuMint as X, CASHU_MINT_SOURCE as Y, breezDatabase as Z, crossNetwork as _, storedGroupFiles as a, ModeGate as at, walletInstances as b, receivedPairedReply as c, awayFrom as ct, paymentAlias as d, setAwayWallets as dt, dropBreezDatabase as et, paymentWireId as f, setSingleWriterGate as ft, createTiming as g, createFailure as h, groupOfFile as i, ModeChanged as it, hasDataKey as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, refuseAway as lt, assertConfirmedReal as m, groupFileId as n, iceServerSetting as nt, groupReply as o, WrongNetworkError as ot, WALLET_NAMES as p, ProviderSources as q, groupFileText as r, relayOnlyProblem as rt, pairedWireReply as s, networkLabel as st, GroupFileDesk as t, iceServerProblem as tt, replyTo as u, requireTurn as ut, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, LightningCards as z };
4473
+ export { ModeGate as $, IdentityProofs as A, AskBackoff as B, FileAppender as C, streamStored as D, storedSize as E, normalizePhrase as F, breezDatabase as G, sourceKey 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, ProviderSources 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 };
4435
4474
 
4436
- //# sourceMappingURL=groupFiles-NonOYBKN.js.map
4475
+ //# sourceMappingURL=groupFiles-DYopNE57.js.map