@ghostlytools/cli 1.4.4 → 1.5.0

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 (88) hide show
  1. package/README.md +14 -7
  2. package/dist/assets/{api-Cr5NjA-g.js → api-C_IHKsrl.js} +2 -2
  3. package/dist/assets/{api-N5IiCxB7.js → api-ClHM_G5A.js} +87 -60
  4. package/dist/assets/api-ClHM_G5A.js.map +1 -0
  5. package/dist/assets/{apiKit-BDB40JPK.js → apiKit-gS-yfb25.js} +2 -2
  6. package/dist/assets/{apiKit-BDB40JPK.js.map → apiKit-gS-yfb25.js.map} +1 -1
  7. package/dist/assets/{apps-Cf_TQYPs.js → apps-DP8pElH-.js} +2 -2
  8. package/dist/assets/{apps-Cf_TQYPs.js.map → apps-DP8pElH-.js.map} +1 -1
  9. package/dist/assets/{apps-C3H4yttJ.js → apps-DyihkNO-.js} +1 -1
  10. package/dist/assets/{arkade-DCovElLt.js → arkade-GzJoov-w.js} +2 -2
  11. package/dist/assets/{arkade-DCovElLt.js.map → arkade-GzJoov-w.js.map} +1 -1
  12. package/dist/assets/{backup-lrj6hQ3t.js → backup-A_C4hYNO.js} +1 -1
  13. package/dist/assets/{backup-Dnh7GFXh.js → backup-DKDXkaS1.js} +6 -6
  14. package/dist/assets/{backup-Dnh7GFXh.js.map → backup-DKDXkaS1.js.map} +1 -1
  15. package/dist/assets/{blobFiles-B0rNnHlO.js → blobFiles-1wUBd8ZD.js} +3 -3
  16. package/dist/assets/{blobFiles-B0rNnHlO.js.map → blobFiles-1wUBd8ZD.js.map} +1 -1
  17. package/dist/assets/{buttons-BCzrFo-d.js → buttons-BDw8cqDq.js} +3 -3
  18. package/dist/assets/{buttons-BCzrFo-d.js.map → buttons-BDw8cqDq.js.map} +1 -1
  19. package/dist/assets/buttons-CNkxiN2c.js +2 -0
  20. package/dist/assets/daemonProof-CWTVNUmr.js +254 -0
  21. package/dist/assets/daemonProof-CWTVNUmr.js.map +1 -0
  22. package/dist/assets/{envelope-BKSHUJnt.js → envelope-DEvU5FA9.js} +2 -2
  23. package/dist/assets/{envelope-BKSHUJnt.js.map → envelope-DEvU5FA9.js.map} +1 -1
  24. package/dist/assets/{fileBytes-B-fqGdEd.js → fileBytes-B8eTZfAT.js} +3 -3
  25. package/dist/assets/{fileBytes-B-fqGdEd.js.map → fileBytes-B8eTZfAT.js.map} +1 -1
  26. package/dist/assets/{fileBytes-C2jycN_7.js → fileBytes-gTd_8l-P.js} +1 -1
  27. package/dist/assets/{fileBytes-D6fqFQEX.js → fileBytes-uRqLyxa0.js} +2 -2
  28. package/dist/assets/{fileBytes-D6fqFQEX.js.map → fileBytes-uRqLyxa0.js.map} +1 -1
  29. package/dist/assets/{fileBytesIdb-_HnxdacI.js → fileBytesIdb-BIFKtgln.js} +3 -3
  30. package/dist/assets/{fileBytesIdb-_HnxdacI.js.map → fileBytesIdb-BIFKtgln.js.map} +1 -1
  31. package/dist/assets/fileBytesIdb-BVVr_rWX.js +2 -0
  32. package/dist/assets/{fileBytesOpfs-p_CANncD.js → fileBytesOpfs-ChrHcCVV.js} +3 -3
  33. package/dist/assets/{fileBytesOpfs-p_CANncD.js.map → fileBytesOpfs-ChrHcCVV.js.map} +1 -1
  34. package/dist/assets/{groupFiles-Dw0BA5-Z.js → groupFiles-Cr4Gj9-R.js} +49 -16
  35. package/dist/assets/groupFiles-Cr4Gj9-R.js.map +1 -0
  36. package/dist/assets/{host-BjTfNkxj.js → host-D0MIWyOe.js} +47 -129
  37. package/dist/assets/host-D0MIWyOe.js.map +1 -0
  38. package/dist/assets/{hyperdhtRelay-CmqjYDch.js → hyperdhtRelay-SBo4aoMk.js} +2 -2
  39. package/dist/assets/{hyperdhtRelay-CmqjYDch.js.map → hyperdhtRelay-SBo4aoMk.js.map} +1 -1
  40. package/dist/assets/{idb-CMVgtn2k.js → idb-BJARz3Qi.js} +5 -3
  41. package/dist/assets/idb-BJARz3Qi.js.map +1 -0
  42. package/dist/assets/{irohWeb-4Q4EdaCa.js → irohWeb-D2WaYPdN.js} +2 -2
  43. package/dist/assets/{irohWeb-4Q4EdaCa.js.map → irohWeb-D2WaYPdN.js.map} +1 -1
  44. package/dist/assets/{main-Dd5INTcu.js → main-DUG0nGLw.js} +279 -67
  45. package/dist/assets/main-DUG0nGLw.js.map +1 -0
  46. package/dist/assets/{mainline-o7bmeZsk.js → mainline-B8NGRodL.js} +79 -15
  47. package/dist/assets/mainline-B8NGRodL.js.map +1 -0
  48. package/dist/assets/{networkReason-ve6jyxIs.js → networkReason-BAnNO1Ji.js} +3 -3
  49. package/dist/assets/{networkReason-ve6jyxIs.js.map → networkReason-BAnNO1Ji.js.map} +1 -1
  50. package/dist/assets/{nwc-CL27LJx-.js → nwc-DQT3rx-s.js} +3 -3
  51. package/dist/assets/{nwc-CL27LJx-.js.map → nwc-DQT3rx-s.js.map} +1 -1
  52. package/dist/assets/{nwcProvider-CIlvpLT5.js → nwcProvider-Dq647EAl.js} +2 -2
  53. package/dist/assets/{nwcProvider-CIlvpLT5.js.map → nwcProvider-Dq647EAl.js.map} +1 -1
  54. package/dist/assets/{profiles-DSxPYdlU.js → profiles-BehWURA9.js} +18 -4
  55. package/dist/assets/profiles-BehWURA9.js.map +1 -0
  56. package/dist/assets/{registry-dG_Wm7fC.js → registry-DFiOxH5q.js} +1 -1
  57. package/dist/assets/{registry-CWJRfG2e.js → registry-ieI8INKT.js} +3 -3
  58. package/dist/assets/registry-ieI8INKT.js.map +1 -0
  59. package/dist/assets/{resolve-BDoQLkJR.js → resolve-C39pc4Kf.js} +2 -2
  60. package/dist/assets/{resolve-BDoQLkJR.js.map → resolve-C39pc4Kf.js.map} +1 -1
  61. package/dist/assets/{restoredRows-DeBImGRd.js → restoredRows-DGuKtIBz.js} +2 -2
  62. package/dist/assets/{restoredRows-DeBImGRd.js.map → restoredRows-DGuKtIBz.js.map} +1 -1
  63. package/dist/assets/{server-CYCzKx-R.js → server-DIICuvgy.js} +1150 -192
  64. package/dist/assets/server-DIICuvgy.js.map +1 -0
  65. package/dist/assets/{src-D1X4uVPW.js → src-CwMTZ5Hj.js} +864 -82
  66. package/dist/assets/src-CwMTZ5Hj.js.map +1 -0
  67. package/dist/assets/{usdt-Byi5OFic.js → usdt-CxSyuXq4.js} +3 -3
  68. package/dist/assets/{usdt-Byi5OFic.js.map → usdt-CxSyuXq4.js.map} +1 -1
  69. package/dist/assets/{turnRefs-BJeWWYlJ.js → words-31VaDW5h.js} +61 -3
  70. package/dist/assets/words-31VaDW5h.js.map +1 -0
  71. package/dist/ghostly.mjs +1 -1
  72. package/package.json +1 -1
  73. package/skills/ghostly/scripts/status +3 -2
  74. package/dist/assets/api-N5IiCxB7.js.map +0 -1
  75. package/dist/assets/buttons-B5dhQKnU.js +0 -2
  76. package/dist/assets/daemonProof-B53VnZ1Z.js +0 -100
  77. package/dist/assets/daemonProof-B53VnZ1Z.js.map +0 -1
  78. package/dist/assets/fileBytesIdb-DOxm_BKt.js +0 -2
  79. package/dist/assets/groupFiles-Dw0BA5-Z.js.map +0 -1
  80. package/dist/assets/host-BjTfNkxj.js.map +0 -1
  81. package/dist/assets/idb-CMVgtn2k.js.map +0 -1
  82. package/dist/assets/main-Dd5INTcu.js.map +0 -1
  83. package/dist/assets/mainline-o7bmeZsk.js.map +0 -1
  84. package/dist/assets/profiles-DSxPYdlU.js.map +0 -1
  85. package/dist/assets/registry-CWJRfG2e.js.map +0 -1
  86. package/dist/assets/server-CYCzKx-R.js.map +0 -1
  87. package/dist/assets/src-D1X4uVPW.js.map +0 -1
  88. package/dist/assets/turnRefs-BJeWWYlJ.js.map +0 -1
@@ -738,13 +738,24 @@ var RelayBreaker = class {
738
738
  const circuit = this.circuits.get(relay);
739
739
  if (circuit) circuit.probing = false;
740
740
  }
741
- /** The relay answered: whatever was wrong is over. */
742
- success(relay) {
741
+ /**
742
+ * The relay answered: whatever was wrong is over. When it was left alone and so was every other relay of `relays`
743
+ * (by default those that failed), for failing, the outage is over for them too: they are asked again now, not at the
744
+ * end of a wait of up to `BREAKER_MAX_MS` (two clients whose probes another relay answered each would share none
745
+ * for minutes). Their trips stay: one really down trips again at once, for longer.
746
+ */
747
+ success(relay, relays = [...this.circuits.keys()]) {
743
748
  const circuit = this.circuits.get(relay);
744
749
  if (!circuit) return;
745
750
  const recovered = circuit.openUntil !== 0;
746
751
  this.circuits.delete(relay);
747
- if (recovered) this.options.onRecover?.(relay);
752
+ if (!recovered) return;
753
+ const others = relays.filter((r) => r !== relay).map((r) => this.circuits.get(r));
754
+ if (others.length && others.every((other) => !!other && other.openUntil !== 0 && other.kind === "error")) {
755
+ const now = this.now();
756
+ for (const other of others) other.openUntil = Math.min(other.openUntil, now);
757
+ }
758
+ this.options.onRecover?.(relay);
748
759
  }
749
760
  /**
750
761
  * The relay failed a request; a probe that fails trips it again at once. While it is left alone and no probe is out,
@@ -1059,10 +1070,24 @@ var RELAY_REQUESTS_PER_MINUTE = {
1059
1070
  "https://pkarr.miguelmedeiros.dev": 5
1060
1071
  };
1061
1072
  /**
1073
+ * A read asks the next relay too when the one it asked has not answered within this long, and takes the first good
1074
+ * answer. Measured on 2026-10-03 from a home connection: a relay hands over a packet it holds in 0.25 s (0.7 s on a new
1075
+ * connection), and one that has to fetch the packet from the DHT first takes 2.7 s. Reads used to wait for a relay's
1076
+ * answer before asking the next one, up to the 10 s timeout: a relay that answered slowly or not at all (pkarr.pubky.org
1077
+ * on 2026-10-03) made every read of a pairing that slow, and the pairing never finished.
1078
+ */
1079
+ var HEDGE_MS = 1500;
1080
+ /**
1062
1081
  * The hedge delay for a key whose last read found nothing (404): a relay takes 3 to 5 s to say so (it asks the DHT
1063
1082
  * every time), and a hedge at `HEDGE_MS` would double every poll of a key nobody has published yet.
1064
1083
  */
1065
1084
  var HEDGE_MISSING_MS = 6e3;
1085
+ /**
1086
+ * A packet that took longer than this to arrive, or a hedge lost to a relay that answered with the packet, is slow: it
1087
+ * counts against the relay's breaker like a failure (three in a row trip it, logged as "slow"), while another relay is
1088
+ * there to ask. A 404 says nothing either way: every relay is slow to give one.
1089
+ */
1090
+ var SLOW_MS = 3e3;
1066
1091
  /** A relay found slow goes after the others in every read for this long, unless it answers fast meanwhile. */
1067
1092
  var SLOW_DEMOTE_MS = 6e4;
1068
1093
  /** How long each source has to answer a read or a put of the turn record (WISP 06 § Publishing and reading). */
@@ -1096,6 +1121,17 @@ function normalizeRelayUrl(input) {
1096
1121
  }
1097
1122
  /** A relay the breaker leaves alone for failing (`RelayBreaker`): nothing was asked of it now. */
1098
1123
  var RelayLeftAloneError = class extends Error {};
1124
+ /**
1125
+ * A read the relays failed (or left alone for failing before), when its caller has another path to ask
1126
+ * (`RelayTransport.resolve` with `keptOnFailure` false): `kept` is the newest packet the relays gave for the key before.
1127
+ */
1128
+ var RelaysFailedError = class extends Error {
1129
+ kept;
1130
+ constructor(kept) {
1131
+ super("No Pkarr relay reachable");
1132
+ this.kept = kept;
1133
+ }
1134
+ };
1099
1135
  var RelayTransport = class {
1100
1136
  relays;
1101
1137
  timeoutMs;
@@ -1258,7 +1294,7 @@ var RelayTransport = class {
1258
1294
  return;
1259
1295
  }
1260
1296
  if (method) this.networkCooldown.delete(`${method} ${relay}`);
1261
- this.breaker.success(relay);
1297
+ this.breaker.success(relay, this.relays);
1262
1298
  }
1263
1299
  setRelays(relays) {
1264
1300
  const normalized = relays.map(normalizeRelayUrl).filter((r) => r !== null);
@@ -1539,8 +1575,11 @@ var RelayTransport = class {
1539
1575
  *
1540
1576
  * A hedge spends a second request, so it goes only where the budget has requests to spare (`hedgeRoom`), never for a
1541
1577
  * background read (nobody waits on it), and later for a key whose last read found nothing (`HEDGE_MISSING_MS`).
1578
+ *
1579
+ * `keptOnFailure` false: a read the relays failed throws `RelaysFailedError` with the packet they gave last, in place
1580
+ * of handing that back as their answer (a CLI asks the DHT then, `RelaysAndDht`).
1542
1581
  */
1543
- async resolve(pubKeyZ32, options = {}) {
1582
+ async resolve(pubKeyZ32, options = {}, keptOnFailure = true) {
1544
1583
  if (this.relays.length === 0) throw new Error("No Pkarr relays configured");
1545
1584
  if (options.background && !options.urgent && !options.group) this.chatNeeds.delete(pubKeyZ32);
1546
1585
  const readAt = this.readAt.get(pubKeyZ32);
@@ -1674,6 +1713,7 @@ var RelayTransport = class {
1674
1713
  const resting = this.relays.every((r) => this.isCoolingDown(r, "GET") || this.breaker.blockedFor(r) > 0 || this.heldFor(r, who, Date.now(), pubKeyZ32) > 0);
1675
1714
  const known = down ? this.newest.get(pubKeyZ32) : newerPacket(this.newest.get(pubKeyZ32), this.written.get(pubKeyZ32));
1676
1715
  if (resting && known) {
1716
+ if (down && !keptOnFailure) throw new RelaysFailedError(known);
1677
1717
  if (!down && budgetWait < Infinity) this.heldBackUntil(pubKeyZ32, Date.now() + budgetWait);
1678
1718
  return known;
1679
1719
  }
@@ -1743,7 +1783,7 @@ var RelayTransport = class {
1743
1783
  slow(relay) {
1744
1784
  this.slowUntil.set(relay, Date.now() + SLOW_DEMOTE_MS);
1745
1785
  if (this.relays.some((r) => r !== relay && this.breaker.blockedFor(r) === 0 && !this.isCoolingDown(r, "GET"))) this.breaker.failure(relay, "error", "slow");
1746
- else this.breaker.success(relay);
1786
+ else this.breaker.success(relay, this.relays);
1747
1787
  }
1748
1788
  /**
1749
1789
  * A hedge may go to this relay: its minute has more requests left than what groups leave a chat (`reserveOf`), so
@@ -5999,11 +6039,15 @@ var RTC_CONFIG = {
5999
6039
  * A call's WebRTC configuration: the apps' STUN servers, then the profile's own (Settings → Network → ICE
6000
6040
  * servers: a TURN relay, typically). A relay is what connects a call when no direct path works: a VPN that takes
6001
6041
  * every packet through its tunnel, or a NAT that maps each destination apart.
6042
+ *
6043
+ * `relayOnly` ("Hide my IP from contacts", WISP 100 § Relay only): the profile's TURN servers alone, no STUN server
6044
+ * (the apps' or the profile's), and the relay policy, so the connection gathers and uses relay candidates only. With
6045
+ * no usable TURN server it has no server at all, and finds no candidate: it fails, it never goes direct.
6002
6046
  */
6003
- function callRtcConfig(extra = []) {
6047
+ function callRtcConfig(extra = [], { relayOnly = false } = {}) {
6004
6048
  const servers = [];
6005
6049
  for (const server of extra) {
6006
- const urls = (Array.isArray(server.urls) ? server.urls : server.urls.split(/[\s,]+/)).filter(Boolean);
6050
+ const urls = (Array.isArray(server.urls) ? server.urls : server.urls.split(/[\s,]+/)).filter(Boolean).filter((url) => !relayOnly || /^turns?:/i.test(url));
6007
6051
  if (!urls.length) continue;
6008
6052
  if (urls.some((url) => /^turns?:/i.test(url)) && (!server.username?.trim() || !server.credential?.trim())) continue;
6009
6053
  servers.push({
@@ -6012,12 +6056,30 @@ function callRtcConfig(extra = []) {
6012
6056
  ...server.credential ? { credential: server.credential } : {}
6013
6057
  });
6014
6058
  }
6059
+ if (relayOnly) return {
6060
+ ...RTC_CONFIG,
6061
+ iceServers: servers,
6062
+ iceTransportPolicy: "relay"
6063
+ };
6015
6064
  return {
6016
6065
  ...RTC_CONFIG,
6017
6066
  iceServers: [...RTC_CONFIG.iceServers ?? [], ...servers]
6018
6067
  };
6019
6068
  }
6020
6069
  /**
6070
+ * The WebRTC configuration of a chat's data link or a group's edge, from the profile's settings: its ICE servers,
6071
+ * and "Hide my IP from contacts" (`relayOnly`), as a call's (`callRtcConfig`). No candidate pool: an app holds one
6072
+ * such connection per chat and per group member, and a call only one.
6073
+ */
6074
+ function contactRtcConfig(settings) {
6075
+ const { iceCandidatePoolSize: _pool, ...config } = callRtcConfig(settings.iceServers ?? [], { relayOnly: settings.relayOnly === true });
6076
+ return config;
6077
+ }
6078
+ /** Whether a connection keeps to relays (`iceTransportPolicy: "relay"`): what it sends a contact is then relay candidates only. */
6079
+ function keepsToRelays(pc) {
6080
+ return pc?.getConfiguration?.().iceTransportPolicy === "relay";
6081
+ }
6082
+ /**
6021
6083
  * The candidates a signal carries, from the `a=candidate:` values of an SDP, when it may carry up to `max`.
6022
6084
  *
6023
6085
  * A computer often has several interfaces (Wi-Fi, Ethernet, VM bridges, Tailscale, a VPN) and the one listed first is
@@ -6032,11 +6094,14 @@ function callRtcConfig(extra = []) {
6032
6094
  *
6033
6095
  * UDP only, loopback, link-local and unspecified addresses left out (loopback kept with `loopback`), the related
6034
6096
  * address dropped (it is informational, and an IPv6 one broke apps before 0.5).
6097
+ *
6098
+ * `relayOnly` ("Hide my IP from contacts"): relay candidates alone, whatever else the connection gathered. A relay
6099
+ * candidate's address is the TURN server's; its related address, dropped as every one is, would be this device's.
6035
6100
  */
6036
- function pickCallCandidates(candidates, max = 8, { loopback = false } = {}) {
6037
- const udp = candidates.map((c) => c.trim()).filter((c) => / udp /i.test(c));
6038
- const address = (c) => c.split(" ")[4] ?? "";
6101
+ function pickCallCandidates(candidates, max = 8, { loopback = false, relayOnly = false } = {}) {
6039
6102
  const type = (c) => / typ (\S+)/.exec(c)?.[1];
6103
+ const udp = candidates.map((c) => c.trim()).filter((c) => / udp /i.test(c) && (!relayOnly || type(c) === "relay"));
6104
+ const address = (c) => c.split(" ")[4] ?? "";
6040
6105
  const cost = (c) => Number(/ network-cost (\d+)/.exec(c)?.[1] ?? 0);
6041
6106
  const ipv6 = (c) => address(c).includes(":");
6042
6107
  const usable = (c) => {
@@ -6061,9 +6126,10 @@ function pickCallCandidates(candidates, max = 8, { loopback = false } = {}) {
6061
6126
  /**
6062
6127
  * The parameters of a call signal, from an SDP. `maxCandidates` above two (a signal on the chat session) carries
6063
6128
  * the candidates `pickCallCandidates` chooses; the default keeps a compatibility chat's one host and one server
6064
- * reflexive candidate.
6129
+ * reflexive candidate. `relayOnly` ("Hide my IP from contacts"): relay candidates only, in either; a compatibility
6130
+ * chat's two then go to the first two relay ones.
6065
6131
  */
6066
- function extractParamsFromSdp(sdp, { maxCandidates = 2, loopback = false } = {}) {
6132
+ function extractParamsFromSdp(sdp, { maxCandidates = 2, loopback = false, relayOnly = false } = {}) {
6067
6133
  const lines = sdp.split("\r\n");
6068
6134
  let ufrag = "";
6069
6135
  let pwd = "";
@@ -6107,7 +6173,10 @@ function extractParamsFromSdp(sdp, { maxCandidates = 2, loopback = false } = {})
6107
6173
  }
6108
6174
  const srflxCandidates = candidates.filter((c) => / typ srflx( |$)/.test(c));
6109
6175
  const hostCandidates = candidates.filter((c) => / typ host( |$)/.test(c) && / udp /i.test(c));
6110
- const selectedCandidates = maxCandidates > 2 ? pickCallCandidates(candidates, maxCandidates, { loopback }) : [...hostCandidates.slice(0, 1), ...srflxCandidates.slice(0, 1)].map((c) => c.replace(/ raddr \S*:\S* rport \d+/, ""));
6176
+ const selectedCandidates = maxCandidates > 2 || relayOnly ? pickCallCandidates(candidates, maxCandidates, {
6177
+ loopback,
6178
+ relayOnly
6179
+ }) : [...hostCandidates.slice(0, 1), ...srflxCandidates.slice(0, 1)].map((c) => c.replace(/ raddr \S+ rport \d+/, ""));
6111
6180
  const ssrcs = [];
6112
6181
  if (audioSsrc !== null) ssrcs.push(audioSsrc);
6113
6182
  if (videoSsrc !== null) ssrcs.push(videoSsrc);
@@ -6542,7 +6611,8 @@ function hostRank(parts, reflexiveBases) {
6542
6611
  const wayOut = reflexiveBases.has(parts[4]) || isGlobalIpv4Host(parts.join(" "));
6543
6612
  return (costly ? 2 : 0) + (wayOut ? 0 : 1);
6544
6613
  }
6545
- function extractRtcParams(sdp) {
6614
+ /** `relayOnly` ("Hide my IP from contacts", the connection keeps to relays): relay candidates only, whatever else is in the SDP. */
6615
+ function extractRtcParams(sdp, { relayOnly = false } = {}) {
6546
6616
  let u = "";
6547
6617
  let p = "";
6548
6618
  let f = "";
@@ -6558,7 +6628,7 @@ function extractRtcParams(sdp) {
6558
6628
  const parts = line.slice(12).split(" ");
6559
6629
  if (parts.length < 8 || parts[1] !== "1" || parts[2].toLowerCase() !== "udp") continue;
6560
6630
  const type = CANDIDATE_TYPES[parts[7]];
6561
- if (!type) continue;
6631
+ if (!type || relayOnly && type !== "r") continue;
6562
6632
  const compact = `${type},${parts[4]},${parts[5]}`;
6563
6633
  if (found.some((c) => c.compact === compact)) continue;
6564
6634
  found.push({
@@ -8469,7 +8539,7 @@ var DataLink = class {
8469
8539
  const signal = {
8470
8540
  t: "o",
8471
8541
  ts: this.myOfferTs,
8472
- ...extractRtcParams(pc.localDescription.sdp)
8542
+ ...extractRtcParams(pc.localDescription.sdp, { relayOnly: keepsToRelays(pc) })
8473
8543
  };
8474
8544
  this.options.publishSignal(JSON.stringify(signal));
8475
8545
  } catch {
@@ -8656,7 +8726,7 @@ var DataLink = class {
8656
8726
  t: "a",
8657
8727
  ts: Date.now(),
8658
8728
  o: offer.ts,
8659
- ...extractRtcParams(pc.localDescription.sdp)
8729
+ ...extractRtcParams(pc.localDescription.sdp, { relayOnly: keepsToRelays(pc) })
8660
8730
  };
8661
8731
  this.options.publishSignal(JSON.stringify(signal));
8662
8732
  this.setState("connecting");
@@ -9230,10 +9300,13 @@ var PR_CHECKS = [
9230
9300
  "failing",
9231
9301
  "pending"
9232
9302
  ];
9303
+ /** The kinds a sender may take back (WISP 405 § Removing a card). */
9304
+ var REMOVABLE_KINDS = ["task", "routine"];
9233
9305
  var ID$4 = /^[A-Za-z0-9_.:][A-Za-z0-9_.:-]{0,63}$/;
9234
9306
  /** A button's id: 1 to 32 of `A-Z a-z 0-9 _ . : -`, not starting with `-`. */
9235
9307
  var BUTTON_ID = /^[A-Za-z0-9_.:][A-Za-z0-9_.:-]{0,31}$/;
9236
- var CRON = /^[0-9A-Za-z*,/?#\- ]{1,64}$/;
9308
+ /** A routine's cron line, trimmed: 1 to 64 of `0-9 A-Z a-z * , / ? # -` and spaces (shown, never run). */
9309
+ var CRON_LINE = /^[0-9A-Za-z*,/?#\- ]{1,64}$/;
9237
9310
  /**
9238
9311
  * Whether a typed answer is a button's label or id (WISP 406 · Message Buttons): ignoring case and spaces at the ends.
9239
9312
  * Not the device's locale's case: the presser's and the author's apps must agree ("I" is not "ı" anywhere).
@@ -9412,6 +9485,14 @@ function readStatusCard(raw, now = Date.now()) {
9412
9485
  ...raw.opened === true && { opened: true }
9413
9486
  };
9414
9487
  }
9488
+ if (raw.kind === "removed") {
9489
+ const of = oneOf(REMOVABLE_KINDS, raw.of);
9490
+ return of && {
9491
+ kind: "removed",
9492
+ id,
9493
+ of
9494
+ };
9495
+ }
9415
9496
  const latest = now + MESSAGE_CLOCK_SKEW_MS;
9416
9497
  if (raw.kind === "usage") return readUsage(raw, id, now);
9417
9498
  const links = readLinks(raw.links);
@@ -9475,7 +9556,7 @@ function readStatusCard(raw, now = Date.now()) {
9475
9556
  if (raw.kind === "routine") {
9476
9557
  const name = cardLine(raw.name, STATUS_CARD_LIMITS.title), schedule = cardLine(raw.schedule, STATUS_CARD_LIMITS.schedule), state = oneOf(ROUTINE_STATES, raw.state);
9477
9558
  if (!name || !schedule || !state) return void 0;
9478
- const cron = typeof raw.cron === "string" && CRON.test(raw.cron.trim()) ? raw.cron.trim() : void 0;
9559
+ const cron = typeof raw.cron === "string" && CRON_LINE.test(raw.cron.trim()) ? raw.cron.trim() : void 0;
9479
9560
  const lastRun = readRun(raw.lastRun, now);
9480
9561
  const nextRunAt = typeof raw.nextRunAt === "number" && Number.isSafeInteger(raw.nextRunAt) && raw.nextRunAt > 0 && raw.nextRunAt <= now + STATUS_CARD_LIMITS.nextRunMs ? raw.nextRunAt : void 0;
9481
9562
  const runs = [];
@@ -9532,7 +9613,7 @@ function checkStatusCard(raw, now = Date.now()) {
9532
9613
  if (!isObject$4(raw)) return { error: "A card is an object" };
9533
9614
  const bytes = statusCardBytes(raw);
9534
9615
  if (bytes > STATUS_CARD_LIMITS.bytes) return { error: `The card takes ${bytes} bytes; at most ${STATUS_CARD_LIMITS.bytes}` };
9535
- if (raw.kind !== "task" && raw.kind !== "routine" && raw.kind !== "buttons" && raw.kind !== "app" && raw.kind !== "usage") return { error: "kind is task, routine, buttons, app or usage" };
9616
+ if (raw.kind !== "task" && raw.kind !== "routine" && raw.kind !== "buttons" && raw.kind !== "app" && raw.kind !== "usage" && raw.kind !== "removed") return { error: "kind is task, routine, buttons, app, usage or removed" };
9536
9617
  if (typeof raw.id !== "string" || !ID$4.test(raw.id)) return { error: `id is 1 to ${STATUS_CARD_LIMITS.id} of A-Z a-z 0-9 _ . : - and does not start with -` };
9537
9618
  const line = (field, value, max, required = false) => {
9538
9619
  if (value === void 0 && !required) return null;
@@ -9555,7 +9636,11 @@ function checkStatusCard(raw, now = Date.now()) {
9555
9636
  }
9556
9637
  const share = (field, value) => value === void 0 || typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 100 ? null : `${field} is a number from 0 to 100`;
9557
9638
  const reset = (field, value) => value === void 0 || ahead(value, now) !== void 0 ? null : `${field} is a time in milliseconds, within a year`;
9558
- if (raw.kind === "usage") {
9639
+ if (raw.kind === "removed") {
9640
+ if (!oneOf(REMOVABLE_KINDS, raw.of)) errors.push(`of is one of ${REMOVABLE_KINDS.join(", ")}`);
9641
+ const extra = Object.keys(raw).find((key) => key !== "kind" && key !== "id" && key !== "of");
9642
+ if (extra) errors.push(`a removed card takes only kind, id and of, not ${extra}`);
9643
+ } else if (raw.kind === "usage") {
9559
9644
  if (raw.links !== void 0) errors.push("a usage card takes no links");
9560
9645
  if (raw.left === void 0 && raw.used === void 0) errors.push("left (a percent) or used and limit");
9561
9646
  errors.push(share("left", raw.left));
@@ -9662,7 +9747,7 @@ function checkStatusCard(raw, now = Date.now()) {
9662
9747
  } else {
9663
9748
  errors.push(line("name", raw.name, STATUS_CARD_LIMITS.title, true), line("schedule", raw.schedule, STATUS_CARD_LIMITS.schedule, true));
9664
9749
  if (!oneOf(ROUTINE_STATES, raw.state)) errors.push(`state is one of ${ROUTINE_STATES.join(", ")}`);
9665
- if (raw.cron !== void 0 && !(typeof raw.cron === "string" && CRON.test(raw.cron.trim()))) errors.push(`cron is a cron line of at most ${STATUS_CARD_LIMITS.cron} characters`);
9750
+ if (raw.cron !== void 0 && !(typeof raw.cron === "string" && CRON_LINE.test(raw.cron.trim()))) errors.push(`cron is a cron line of at most ${STATUS_CARD_LIMITS.cron} characters`);
9666
9751
  if (raw.nextRunAt !== void 0 && !(typeof raw.nextRunAt === "number" && Number.isSafeInteger(raw.nextRunAt) && raw.nextRunAt > 0 && raw.nextRunAt <= now + STATUS_CARD_LIMITS.nextRunMs)) errors.push("nextRunAt is a time in milliseconds, within a year");
9667
9752
  const run = (field, value) => {
9668
9753
  if (!isObject$4(value)) return errors.push(`${field} is an object`);
@@ -9712,10 +9797,18 @@ function cardTimeUtc(ms) {
9712
9797
  return `${new Date(ms).toISOString().slice(0, 16).replace("T", " ")} UTC`;
9713
9798
  }
9714
9799
  /**
9800
+ * The text a removed card's message carries (WISP 405 § Removing a card): "🗑 Task removed", with the card's title or
9801
+ * name when the sender knows it ("🗑 Task removed: Fix relay rotation"). An app without the `removed` kind shows it.
9802
+ */
9803
+ function removedCardText(of, title) {
9804
+ return `🗑 ${of === "task" ? "Task" : "Routine"} removed${title ? `: ${title}` : ""}`;
9805
+ }
9806
+ /**
9715
9807
  * The text a card's message carries: what an app without cards shows, the DHT floor carries, the chat list previews
9716
9808
  * and search finds. Plain lines, the first naming the card, no bars or layout that would read badly elsewhere.
9717
9809
  */
9718
9810
  function statusCardText(card) {
9811
+ if (card.kind === "removed") return removedCardText(card.of);
9719
9812
  if (card.kind === "app") {
9720
9813
  const named = `${card.title}${card.version ? ` ${card.version}` : ""}`;
9721
9814
  return [card.opened ? `🧩 Opened ${named} in this chat (Ghostly app)` : `🧩 ${named} (Ghostly app)`, ...card.url ? [card.url] : []].join("\n");
@@ -10213,13 +10306,24 @@ function parseLinkPreview(raw, text) {
10213
10306
  * message. A status card (`sc`, WISP 405 · Status Cards) may come with it too; a card message takes up to
10214
10307
  * `STATUS_CARD_LIMITS.edits` edits, a number past `MAX_EDITS_PER_MESSAGE` holding only with a card. Older apps drop
10215
10308
  * both frames: they have an id, but a `t` they do not know.
10309
+ *
10310
+ * A removal (WISP 400 § Delete for everyone) is the message's last edit, flagged `rm`, with a fallback text and
10311
+ * nothing else beside it; an app from before removals shows that text as the edit:
10312
+ *
10313
+ * {"t":"paired-edit","id":"<the message's wire id>","e":4,"ts":1790000000000,"m":"🗑 Message removed","rm":true}
10216
10314
  */
10217
10315
  var EDIT_FRAME = "paired-edit";
10218
10316
  var EDITED_FRAME = "paired-edited";
10317
+ /** A removal is numbered one past the message's last edit, so it may pass a card message's bound by one. */
10318
+ var MAX_REMOVAL_NUMBER = STATUS_CARD_LIMITS.edits + 1;
10319
+ /** The text a removal carries: only what an app from before removals shows in the message's place. */
10320
+ var REMOVED_TEXT = "🗑 Message removed";
10219
10321
  var EDIT_RATE_WINDOW_MS = 1e4;
10220
10322
  /** An edit of a message not here yet waits this long for it, at most `EDIT_BUFFER_MAX` of them per chat. */
10221
10323
  var EDIT_BUFFER_MS = 6e4;
10222
10324
  var ID$3 = /^[A-Za-z0-9_-]{22}$/;
10325
+ /** A removal may name a file too (WISP 401 § Edits): its offer's id, as a file's id holds (`files.ts`). */
10326
+ var REMOVAL_ID = /^[A-Za-z0-9_-]{8,64}$/;
10223
10327
  /** Largest edit frame sent with a preview: the preview is left out past it, as with a message. */
10224
10328
  var MAX_EDIT_FRAME = 57344;
10225
10329
  /**
@@ -10227,6 +10331,14 @@ var MAX_EDIT_FRAME = 57344;
10227
10331
  * goes: it is bounded well under what the frame has room for, and it is what a card message is.
10228
10332
  */
10229
10333
  function editFrame(edit) {
10334
+ if (edit.rm) return JSON.stringify({
10335
+ t: EDIT_FRAME,
10336
+ id: edit.id,
10337
+ e: edit.e,
10338
+ ts: edit.ts,
10339
+ m: edit.m,
10340
+ rm: true
10341
+ });
10230
10342
  const base = {
10231
10343
  t: EDIT_FRAME,
10232
10344
  id: edit.id,
@@ -10255,6 +10367,10 @@ function editedFrame(id, e) {
10255
10367
  function validEditNumber(e) {
10256
10368
  return Number.isSafeInteger(e) && e >= 1 && e <= 100;
10257
10369
  }
10370
+ /** A removal's number: any up to one past a card message's bound, card or not. */
10371
+ function validRemovalNumber(e) {
10372
+ return Number.isSafeInteger(e) && e >= 1 && e <= MAX_REMOVAL_NUMBER;
10373
+ }
10258
10374
  /** A message's new text: not empty, no space around it, within a chat message's bytes. The same on a session and on the DHT. */
10259
10375
  function validEditMessage(m) {
10260
10376
  return typeof m === "string" && !!m.trim() && m === m.trim() && utf8Encode(m).length <= LIMITS.maxChatMessageBytes;
@@ -10262,14 +10378,22 @@ function validEditMessage(m) {
10262
10378
  /**
10263
10379
  * The edit a `paired-edit` frame says, or null when it is malformed (then it says nothing and is not confirmed). A
10264
10380
  * preview or a card that does not hold is dropped, never the edit; an edit numbered past `MAX_EDITS_PER_MESSAGE`
10265
- * holds only with a card.
10381
+ * holds only with a card. A removal carries its fallback text alone, and a `rm` other than `true` is no edit.
10266
10382
  */
10267
10383
  function parseEditFrame(frame, now = Date.now()) {
10268
10384
  if (frame?.t !== "paired-edit") return null;
10269
- const { id, e, ts, m } = frame;
10270
- if (typeof id !== "string" || !ID$3.test(id) || !cardEditNumber(e)) return null;
10385
+ const { id, e, ts, m, rm } = frame;
10386
+ if (rm !== void 0 && rm !== true) return null;
10387
+ if (typeof id !== "string" || !(rm ? REMOVAL_ID : ID$3).test(id) || typeof e !== "number" || !(rm ? validRemovalNumber(e) : cardEditNumber(e))) return null;
10271
10388
  if (typeof ts !== "number" || !Number.isSafeInteger(ts) || ts <= 0) return null;
10272
10389
  if (!validEditMessage(m)) return null;
10390
+ if (rm) return {
10391
+ id,
10392
+ e,
10393
+ ts,
10394
+ m,
10395
+ rm
10396
+ };
10273
10397
  const sc = frame.sc === void 0 ? void 0 : readStatusCard(frame.sc, now);
10274
10398
  if (!validEditNumber(e) && !sc) return null;
10275
10399
  const pv = frame.pv === void 0 ? void 0 : parseLinkPreview(frame.pv, m);
@@ -10285,7 +10409,7 @@ function parseEditFrame(frame, now = Date.now()) {
10285
10409
  /** The confirmation a `paired-edited` frame says, or null when it is malformed. */
10286
10410
  function parseEditedFrame(frame) {
10287
10411
  if (frame?.t !== "paired-edited") return null;
10288
- return typeof frame.id === "string" && ID$3.test(frame.id) && cardEditNumber(frame.e) ? {
10412
+ return typeof frame.id === "string" && REMOVAL_ID.test(frame.id) && validRemovalNumber(frame.e) ? {
10289
10413
  id: frame.id,
10290
10414
  e: frame.e
10291
10415
  } : null;
@@ -10342,7 +10466,7 @@ var VIDEO_LIMITS = {
10342
10466
  function isVideoMime(mime) {
10343
10467
  return mime.split(";")[0].trim().toLowerCase().startsWith("video/");
10344
10468
  }
10345
- var BASE64URL = /^[A-Za-z0-9_-]+$/;
10469
+ var BASE64URL$1 = /^[A-Za-z0-9_-]+$/;
10346
10470
  var JPEG_START = [
10347
10471
  255,
10348
10472
  216,
@@ -10365,7 +10489,7 @@ function parseVideoMeta(value, mime) {
10365
10489
  width,
10366
10490
  height
10367
10491
  };
10368
- if (typeof poster === "string" && poster.length <= Math.ceil(VIDEO_LIMITS.maxPosterBytes * 4 / 3) && BASE64URL.test(poster)) try {
10492
+ if (typeof poster === "string" && poster.length <= Math.ceil(VIDEO_LIMITS.maxPosterBytes * 4 / 3) && BASE64URL$1.test(poster)) try {
10369
10493
  const bytes = fromBase64Url(poster);
10370
10494
  const size = bytes.length <= VIDEO_LIMITS.maxPosterBytes && JPEG_START.every((b, i) => bytes[i] === b) ? imageSize(bytes) : void 0;
10371
10495
  if (size && Math.max(size.width, size.height) <= VIDEO_LIMITS.posterEdge) meta.poster = poster;
@@ -11714,7 +11838,7 @@ var DhtDelivery = class DhtDelivery {
11714
11838
  let found = null;
11715
11839
  for (const [i, box] of boxes.entries()) {
11716
11840
  if (i > 0 && box === "pinned") {
11717
- if (!this.state.peerPinned && (!found || Date.now() - this.pinnedProbeAt < PINNED_PROBE_MS)) return;
11841
+ if (!this.state.peerPinned && (!found || this.state.inviteTaken || Date.now() - this.pinnedProbeAt < PINNED_PROBE_MS)) return;
11718
11842
  if (!this.state.peerPinned) this.pinnedProbeAt = Date.now();
11719
11843
  }
11720
11844
  const address = box === "pinned" ? pinned.peerAddress : this.peerAddress;
@@ -11841,14 +11965,14 @@ var DhtDelivery = class DhtDelivery {
11841
11965
  return age >= 6e5 ? age : void 0;
11842
11966
  }
11843
11967
  /**
11844
- * The wait between reads of the mailbox of a joined chat whose invite someone else used first (`inviteTaken`), before
11845
- * it pinned anyone: nothing is awaited from its inviter, so it is read as an unused invite of its age (counted from
11846
- * the join) from the notice on, however few other invites the app holds. One slow read stays, so a chat whose invite
11847
- * turns out not to be taken (`untaken`) still notices. Undefined for any other chat.
11968
+ * The wait between reads of the mailbox of a joined chat whose invite someone else used first (`inviteTaken`), whether
11969
+ * or not its look-up pinned the inviter first (`unanswered`): nothing is awaited from its inviter, so it is read as an
11970
+ * unused invite of its age (counted from the join) from the notice on, however few other invites the app holds. One
11971
+ * slow read stays, so a chat whose invite turns out not to be taken (`untaken`) still notices. Undefined for any other chat.
11848
11972
  */
11849
11973
  takenInviteWait() {
11850
11974
  const now = Date.now(), madeAt = this.options.inviteMadeAt;
11851
- if (!this.state.inviteTaken || this.options.credentials.peerKey || madeAt === void 0 || this.active || now < this.fastUntil) return void 0;
11975
+ if (!this.state.inviteTaken || madeAt === void 0 || this.active || now < this.fastUntil) return void 0;
11852
11976
  return unusedInviteWait(now - Math.min(madeAt, this.startedAt), this.mode === "dht" ? DHT_POLL_MS : STREAM_POLL_MS, Infinity);
11853
11977
  }
11854
11978
  schedule() {
@@ -15440,6 +15564,11 @@ var UPGRADE_CAPABILITY = "upgrade/1";
15440
15564
  * `pairedApps.ts`). Offered only while the apps feature is on.
15441
15565
  */
15442
15566
  var APPS_CAPABILITY = "apps/1";
15567
+ /**
15568
+ * The read lane of mini-apps (WISP 1200 § A read lane to the contact, `pairedAppRanges.ts`): the contact's app reads a
15569
+ * file this side's app serves, in ranges, outside `apps/1`. Offered beside `apps/1` only.
15570
+ */
15571
+ var APP_RANGES_CAPABILITY = "app-ranges/1";
15443
15572
  /** Every capability this app knows on a session: what `receive` reports changes of. */
15444
15573
  var KNOWN_SESSION_CAPABILITIES = [
15445
15574
  CALLS_CAPABILITY,
@@ -15454,7 +15583,8 @@ var KNOWN_SESSION_CAPABILITIES = [
15454
15583
  STATUS_CARD_CAPABILITY,
15455
15584
  BUTTONS_CAPABILITY,
15456
15585
  UPGRADE_CAPABILITY,
15457
- APPS_CAPABILITY
15586
+ APPS_CAPABILITY,
15587
+ APP_RANGES_CAPABILITY
15458
15588
  ];
15459
15589
  var SESSION_CAPABILITIES_FRAME = "paired-capabilities";
15460
15590
  var MAX_ENTRIES$1 = 32;
@@ -15786,6 +15916,411 @@ var AppSessions = class {
15786
15916
  }
15787
15917
  };
15788
15918
  //#endregion
15919
+ //#region ../core/src/pairedAppRanges.ts
15920
+ /**
15921
+ * The read lane of mini-apps in a 1:1 chat (WISP 1200 § A read lane to the contact: `app-ranges/1`): the contact's app
15922
+ * reads, in ranges, a file this side's app serves, over the chat's session but not through `apps/1`.
15923
+ *
15924
+ * {"t":"ar-get","a":"<chat app id>","s":"<serve id>","r":7,"o":0,"n":1048576}
15925
+ * {"t":"ar-data","a":"<chat app id>","r":7,"o":0,"d":"<base64url>"}
15926
+ * {"t":"ar-end","a":"<chat app id>","r":7,"z":734003200}
15927
+ * {"t":"ar-err","a":"<chat app id>","r":7,"e":"not-served"}
15928
+ * {"t":"ar-cancel","a":"<chat app id>","r":7}
15929
+ *
15930
+ * The asker sends `ar-get` (request `r`, a number of its own, for `n` bytes at offset `o` of serve `s`) and may send
15931
+ * `ar-cancel`; the server answers with the bytes in chunks of at most `APP_RANGE_LIMITS.chunkBytes`, then `ar-end`
15932
+ * once every byte asked was sent (fewer at the end of the file), with `z` the served file's size, or `ar-err` instead of
15933
+ * any. A read of one byte at 0 is how the asker learns the size. Where `files/4` is on,
15934
+ * a chunk is a binary message of kind `APP_RANGE_DATA_KIND` (`encodeAppRangeData`) in place of `ar-data`. It needs
15935
+ * `app-ranges/1` in `paired-capabilities` on both sides. A reader ignores keys it does not know, so a later version
15936
+ * can add some.
15937
+ */
15938
+ var APP_RANGE_FRAMES = /* @__PURE__ */ new Set([
15939
+ "ar-get",
15940
+ "ar-data",
15941
+ "ar-end",
15942
+ "ar-err",
15943
+ "ar-cancel"
15944
+ ]);
15945
+ var APP_RANGE_LIMITS = {
15946
+ /** One `ar-get`, at most: as one `remote.read` of the app. */
15947
+ requestBytes: 1048576,
15948
+ /** One chunk, `ar-data` or binary: as a chat file's. */
15949
+ chunkBytes: 16384,
15950
+ /** The largest request number: it is 4 bytes in a binary chunk. */
15951
+ maxRequest: 4294967295,
15952
+ /** Requests a server takes in flight per app; one more is answered `busy`. An asker keeps the rest waiting. */
15953
+ inFlight: 4
15954
+ };
15955
+ /**
15956
+ * What an `ar-err` says. `not-served`: no serve of that id on this session (never given, or ended); `changed` and
15957
+ * `gone`: the file under it, as `files.read` says them; `busy`: past the requests the server takes in flight. A
15958
+ * later version may add one: an asker reads a code it does not know as a failure.
15959
+ */
15960
+ var APP_RANGE_ERRORS = [
15961
+ "not-served",
15962
+ "changed",
15963
+ "gone",
15964
+ "busy"
15965
+ ];
15966
+ /** A serve id as it is on the wire: 22 base64url characters (16 random bytes, no padding), as a chat app id. */
15967
+ var isServeId = isChatAppId;
15968
+ var isRequest = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= APP_RANGE_LIMITS.maxRequest;
15969
+ var isOffset = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
15970
+ var ERROR_CODE = /^[a-z][a-z-]{0,31}$/;
15971
+ var BASE64URL = /^[A-Za-z0-9_-]*$/;
15972
+ /** The bytes of `d`, or null when it is not 1 to `chunkBytes` bytes of canonical base64url without padding. */
15973
+ function appRangeChunk(d) {
15974
+ if (typeof d !== "string" || !d.length || d.length % 4 === 1 || d.length > Math.ceil(APP_RANGE_LIMITS.chunkBytes * 4 / 3) || !BASE64URL.test(d)) return null;
15975
+ let bytes;
15976
+ try {
15977
+ bytes = fromBase64Url(d);
15978
+ } catch {
15979
+ return null;
15980
+ }
15981
+ return bytes.length && bytes.length <= APP_RANGE_LIMITS.chunkBytes && toBase64Url(bytes) === d ? bytes : null;
15982
+ }
15983
+ function appRangeGetFrame(app, serve, request, offset, length) {
15984
+ const frame = {
15985
+ t: "ar-get",
15986
+ a: app,
15987
+ s: serve,
15988
+ r: request,
15989
+ o: offset,
15990
+ n: length
15991
+ };
15992
+ if (!readAppRangeFrame(frame).ok) throw new Error("Not an app range request");
15993
+ return frame;
15994
+ }
15995
+ function appRangeDataFrame(app, request, offset, data) {
15996
+ const frame = {
15997
+ t: "ar-data",
15998
+ a: app,
15999
+ r: request,
16000
+ o: offset,
16001
+ d: toBase64Url(data)
16002
+ };
16003
+ if (!readAppRangeFrame(frame).ok) throw new Error("Not app range data");
16004
+ return frame;
16005
+ }
16006
+ function appRangeEndFrame(app, request, size) {
16007
+ if (!isChatAppId(app) || !isRequest(request) || !isOffset(size)) throw new Error("Not an app range end");
16008
+ return {
16009
+ t: "ar-end",
16010
+ a: app,
16011
+ r: request,
16012
+ z: size
16013
+ };
16014
+ }
16015
+ function appRangeErrorFrame(app, request, error) {
16016
+ if (!isChatAppId(app) || !isRequest(request) || !APP_RANGE_ERRORS.includes(error)) throw new Error("Not an app range error");
16017
+ return {
16018
+ t: "ar-err",
16019
+ a: app,
16020
+ r: request,
16021
+ e: error
16022
+ };
16023
+ }
16024
+ function appRangeCancelFrame(app, request) {
16025
+ if (!isChatAppId(app) || !isRequest(request)) throw new Error("Not an app range cancel");
16026
+ return {
16027
+ t: "ar-cancel",
16028
+ a: app,
16029
+ r: request
16030
+ };
16031
+ }
16032
+ /**
16033
+ * An `ar-*` frame as the peer sent it, or why a reader must refuse it: an unknown `t`, no valid `a`, an `ar-get`
16034
+ * without a valid `s`, a request number that is not 0 to 2^32 - 1, an offset that is not a safe whole number at or
16035
+ * above 0, an `n` that is not 1 to `requestBytes` (or runs past 2^53 - 1), a `d` that is not 1 to `chunkBytes` bytes of
16036
+ * canonical base64url, an `e` that is not a code (lower case letters and `-`, at most 32), an `ar-end` whose `z` is not
16037
+ * a size (a safe whole number at or above 0). Other keys are ignored.
16038
+ */
16039
+ function readAppRangeFrame(frame) {
16040
+ const refuse = (refusal) => ({
16041
+ ok: false,
16042
+ refusal
16043
+ });
16044
+ const t = frame?.t;
16045
+ if (typeof t !== "string" || !APP_RANGE_FRAMES.has(t)) return refuse("not-ranges");
16046
+ if (!isChatAppId(frame.a)) return refuse("bad-a");
16047
+ const a = frame.a;
16048
+ if (t === "ar-get" && !isServeId(frame.s)) return refuse("bad-s");
16049
+ if (!isRequest(frame.r)) return refuse("bad-r");
16050
+ const r = frame.r;
16051
+ switch (t) {
16052
+ case "ar-get": {
16053
+ if (!isOffset(frame.o)) return refuse("bad-o");
16054
+ const n = frame.n;
16055
+ if (typeof n !== "number" || !Number.isInteger(n) || n < 1 || n > APP_RANGE_LIMITS.requestBytes || !Number.isSafeInteger(frame.o + n)) return refuse("bad-n");
16056
+ return {
16057
+ ok: true,
16058
+ frame: {
16059
+ t,
16060
+ a,
16061
+ s: frame.s,
16062
+ r,
16063
+ o: frame.o,
16064
+ n
16065
+ }
16066
+ };
16067
+ }
16068
+ case "ar-data":
16069
+ if (!isOffset(frame.o)) return refuse("bad-o");
16070
+ if (!appRangeChunk(frame.d)) return refuse("bad-d");
16071
+ return {
16072
+ ok: true,
16073
+ frame: {
16074
+ t,
16075
+ a,
16076
+ r,
16077
+ o: frame.o,
16078
+ d: frame.d
16079
+ }
16080
+ };
16081
+ case "ar-err": return typeof frame.e === "string" && ERROR_CODE.test(frame.e) ? {
16082
+ ok: true,
16083
+ frame: {
16084
+ t,
16085
+ a,
16086
+ r,
16087
+ e: frame.e
16088
+ }
16089
+ } : refuse("bad-e");
16090
+ case "ar-end": return isOffset(frame.z) ? {
16091
+ ok: true,
16092
+ frame: {
16093
+ t,
16094
+ a,
16095
+ r,
16096
+ z: frame.z
16097
+ }
16098
+ } : refuse("bad-z");
16099
+ default: return {
16100
+ ok: true,
16101
+ frame: {
16102
+ t: "ar-cancel",
16103
+ a,
16104
+ r
16105
+ }
16106
+ };
16107
+ }
16108
+ }
16109
+ var HEAD = 29;
16110
+ /** The binary message for the bytes of request `request` of app `app` at `offset`. Throws on what no receiver would take. */
16111
+ function encodeAppRangeData(app, request, offset, data) {
16112
+ if (!isChatAppId(app) || !isRequest(request) || !isOffset(offset) || !data.length || data.length > APP_RANGE_LIMITS.chunkBytes) throw new Error("Invalid app range data");
16113
+ const id = fromBase64Url(app);
16114
+ if (id.length !== 16) throw new Error("Invalid app range data");
16115
+ const out = new Uint8Array(HEAD + data.length);
16116
+ out[0] = 5;
16117
+ out.set(id, 1);
16118
+ const view = new DataView(out.buffer);
16119
+ view.setUint32(17, request);
16120
+ view.setUint32(21, Math.floor(offset / 2 ** 32));
16121
+ view.setUint32(25, offset % 2 ** 32);
16122
+ out.set(data, HEAD);
16123
+ return out;
16124
+ }
16125
+ /** What a binary message from the contact says, or null when it is not well-formed app range data. `data` is a view of `message`. */
16126
+ function decodeAppRangeData(message) {
16127
+ if (message.length <= HEAD || message[0] !== 5 || message.length - HEAD > APP_RANGE_LIMITS.chunkBytes) return null;
16128
+ const view = new DataView(message.buffer, message.byteOffset, message.byteLength);
16129
+ const high = view.getUint32(21);
16130
+ if (high > 2097151) return null;
16131
+ return {
16132
+ a: toBase64Url(message.slice(1, 17)),
16133
+ r: view.getUint32(17),
16134
+ o: high * 2 ** 32 + view.getUint32(25),
16135
+ data: message.subarray(HEAD)
16136
+ };
16137
+ }
16138
+ var slot = (app, request) => `${app}:${request}`;
16139
+ /**
16140
+ * The read lane of one chat, both ways (WISP 1200 § A read lane to the contact). As the side that serves it keeps the
16141
+ * serve ids it gave out on this session and answers the contact's `ar-get` for those only, at most
16142
+ * `APP_RANGE_LIMITS.inFlight` per app (`busy` past it); the bytes themselves are read and sent by the session, which
16143
+ * calls `finish` or `fail` for each task. As the side that asks it sends at most `inFlight` requests per app, keeps
16144
+ * the rest waiting, and puts each answer back together, in order, from the offset asked. Serves and requests last one
16145
+ * session: `reset` ends them all, `closeApp` those of one app.
16146
+ */
16147
+ var AppRanges = class {
16148
+ send;
16149
+ newServeId;
16150
+ serves = /* @__PURE__ */ new Map();
16151
+ serving = /* @__PURE__ */ new Map();
16152
+ /** Tasks cancelled or unserved that the session is still reading or sending: each counts in its app's `inFlight` until settled. */
16153
+ draining = /* @__PURE__ */ new Set();
16154
+ asking = /* @__PURE__ */ new Map();
16155
+ waiting = /* @__PURE__ */ new Map();
16156
+ nextRequest = 0;
16157
+ constructor(send, newServeId = () => toBase64Url(randomBytes(16))) {
16158
+ this.send = send;
16159
+ this.newServeId = newServeId;
16160
+ }
16161
+ /** Lets the contact's `app` read `file` on this session: the serve id to tell it. */
16162
+ serve(app, file) {
16163
+ if (!isChatAppId(app)) throw new Error("Not a chat app id");
16164
+ let id = this.newServeId();
16165
+ while (this.serves.has(id)) id = this.newServeId();
16166
+ this.serves.set(id, {
16167
+ app,
16168
+ file
16169
+ });
16170
+ return id;
16171
+ }
16172
+ /** Ends one serve: requests under it still being sent stop. False when it was not served. */
16173
+ unserve(serveId) {
16174
+ if (!this.serves.get(serveId)) return false;
16175
+ this.serves.delete(serveId);
16176
+ for (const task of this.serving.values()) if (task.serve === serveId) this.drop(task, true);
16177
+ return true;
16178
+ }
16179
+ /** The serve ids `app` has given out on this session (what the panel's "Sharing with" line shows). */
16180
+ servesOf(app) {
16181
+ return [...this.serves].filter(([, serve]) => serve.app === app).map(([id]) => id);
16182
+ }
16183
+ /** An `ar-get` from the contact: the task to read and send, or null when it was refused (the refusal is sent) or dropped. */
16184
+ receiveGet(frame) {
16185
+ const { a: app, r: request } = frame;
16186
+ if (this.serving.has(slot(app, request))) return null;
16187
+ const serve = this.serves.get(frame.s);
16188
+ if (!serve || serve.app !== app) {
16189
+ this.send(appRangeErrorFrame(app, request, "not-served"));
16190
+ return null;
16191
+ }
16192
+ if ([...this.serving.values(), ...this.draining].filter((task) => task.app === app).length >= APP_RANGE_LIMITS.inFlight) {
16193
+ this.send(appRangeErrorFrame(app, request, "busy"));
16194
+ return null;
16195
+ }
16196
+ const task = {
16197
+ app,
16198
+ request,
16199
+ serve: frame.s,
16200
+ file: serve.file,
16201
+ offset: frame.o,
16202
+ length: frame.n,
16203
+ live: true
16204
+ };
16205
+ this.serving.set(slot(app, request), task);
16206
+ return task;
16207
+ }
16208
+ /** An `ar-cancel` from the contact: that request sends nothing more, and its number frees; its place frees once it is settled. */
16209
+ receiveCancel(frame) {
16210
+ const task = this.serving.get(slot(frame.a, frame.r));
16211
+ if (task) this.drop(task, true);
16212
+ }
16213
+ /** Every byte of `task` was sent: `ar-end` goes with the file's size, unless the task was dropped meanwhile. */
16214
+ finish(task, size) {
16215
+ if (this.take(task)) this.send(appRangeEndFrame(task.app, task.request, size));
16216
+ }
16217
+ /** The file under `task` could not be read: `ar-err` goes in place of the rest, unless the task was dropped meanwhile. */
16218
+ fail(task, error) {
16219
+ if (this.take(task)) this.send(appRangeErrorFrame(task.app, task.request, error));
16220
+ }
16221
+ /** The session stopped working on `task` without an answer (it is no longer live, or the channel went): its place frees, nothing is sent. */
16222
+ release(task) {
16223
+ this.take(task);
16224
+ }
16225
+ /** Reads `length` bytes at `offset` of what the contact's `app` serves as `serve`: the bytes (fewer at the end) and the file's size. */
16226
+ read(app, serve, offset, length) {
16227
+ appRangeGetFrame(app, serve, 0, offset, length);
16228
+ return new Promise((resolve, reject) => {
16229
+ const ask = {
16230
+ app,
16231
+ serve,
16232
+ offset,
16233
+ length,
16234
+ chunks: [],
16235
+ got: 0,
16236
+ resolve,
16237
+ reject
16238
+ };
16239
+ const queue = this.waiting.get(app) ?? [];
16240
+ queue.push(ask);
16241
+ this.waiting.set(app, queue);
16242
+ this.pump(app);
16243
+ });
16244
+ }
16245
+ /** Bytes of a request of ours, from `ar-data` or a binary chunk. Out of order or past what was asked fails the request. */
16246
+ receiveData(app, request, offset, data) {
16247
+ const ask = this.asking.get(slot(app, request));
16248
+ if (!ask) return;
16249
+ if (offset !== ask.offset + ask.got || ask.got + data.length > ask.length) {
16250
+ this.send(appRangeCancelFrame(app, request));
16251
+ return this.settle(ask, "failed");
16252
+ }
16253
+ ask.chunks.push(data.slice());
16254
+ ask.got += data.length;
16255
+ }
16256
+ /** The contact's `ar-end` or `ar-err` for a request of ours. */
16257
+ receiveAnswer(frame) {
16258
+ const ask = this.asking.get(slot(frame.a, frame.r));
16259
+ if (!ask) return;
16260
+ if (frame.t === "ar-err") return this.settle(ask, [
16261
+ "not-served",
16262
+ "changed",
16263
+ "gone"
16264
+ ].find((code) => code === frame.e) ?? "failed");
16265
+ if (ask.got !== Math.max(0, Math.min(ask.length, frame.z - ask.offset))) return this.settle(ask, "failed");
16266
+ this.settle(ask);
16267
+ ask.resolve({
16268
+ bytes: concatBytes$1(...ask.chunks),
16269
+ size: frame.z
16270
+ });
16271
+ }
16272
+ /** `app` closed on either side: its serves end, what it was sending stops and what it asked fails with `error`. */
16273
+ closeApp(app, error = "peer-closed") {
16274
+ for (const [id, serve] of this.serves) if (serve.app === app) this.serves.delete(id);
16275
+ for (const task of this.serving.values()) if (task.app === app) this.drop(task);
16276
+ for (const task of this.draining) if (task.app === app) this.draining.delete(task);
16277
+ for (const ask of this.waiting.get(app) ?? []) ask.reject(new Error(error));
16278
+ this.waiting.delete(app);
16279
+ for (const ask of this.asking.values()) if (ask.app === app) this.settle(ask, error);
16280
+ }
16281
+ /** The session ended: no serve id lasts into the next, and every request fails with `offline`. */
16282
+ reset() {
16283
+ const apps = new Set([...this.serves.values()].map((serve) => serve.app).concat([...this.serving.values(), ...this.draining].map((task) => task.app), [...this.waiting.keys()], [...this.asking.values()].map((ask) => ask.app)));
16284
+ for (const app of apps) this.closeApp(app, "offline");
16285
+ }
16286
+ /** Stops `task` and frees its request number; `draining` keeps it counted until it is settled. */
16287
+ drop(task, draining = false) {
16288
+ task.live = false;
16289
+ this.serving.delete(slot(task.app, task.request));
16290
+ if (draining) this.draining.add(task);
16291
+ }
16292
+ /** Frees `task`'s place; false when it was no longer live (nothing to send for it). */
16293
+ take(task) {
16294
+ if (this.draining.delete(task)) return false;
16295
+ const held = this.serving.get(slot(task.app, task.request));
16296
+ if (held !== task || !held.live) return false;
16297
+ this.drop(held);
16298
+ return true;
16299
+ }
16300
+ /** Ends `ask` (failing it with `error` when given) and sends the next one waiting for its app. */
16301
+ settle(ask, error) {
16302
+ if (ask.request === void 0 || this.asking.get(slot(ask.app, ask.request)) !== ask) return;
16303
+ this.asking.delete(slot(ask.app, ask.request));
16304
+ if (error) ask.reject(new Error(error));
16305
+ this.pump(ask.app);
16306
+ }
16307
+ pump(app) {
16308
+ const queue = this.waiting.get(app);
16309
+ let inFlight = [...this.asking.values()].filter((ask) => ask.app === app).length;
16310
+ while (queue?.length && inFlight < APP_RANGE_LIMITS.inFlight) {
16311
+ const ask = queue.shift();
16312
+ let request = this.nextRequest;
16313
+ while (this.asking.has(slot(app, request))) request = request === APP_RANGE_LIMITS.maxRequest ? 0 : request + 1;
16314
+ this.nextRequest = request === APP_RANGE_LIMITS.maxRequest ? 0 : request + 1;
16315
+ ask.request = request;
16316
+ this.asking.set(slot(app, request), ask);
16317
+ inFlight++;
16318
+ this.send(appRangeGetFrame(app, ask.serve, request, ask.offset, ask.length));
16319
+ }
16320
+ if (queue && !queue.length) this.waiting.delete(app);
16321
+ }
16322
+ };
16323
+ //#endregion
15789
16324
  //#region ../core/src/webPush.ts
15790
16325
  var WebPushError = class extends Error {};
15791
16326
  var RECORD_SIZE = 4096;
@@ -19241,6 +19776,12 @@ var GhostLink = class {
19241
19776
  typingReceiver = new TypingReceiver((typing, activity) => this.options.events?.onPeerTyping?.(typing, activity));
19242
19777
  /** Mini-apps on this session (`apps/1`): this side's open apps (kept across sessions), the peer's, the limits. */
19243
19778
  apps;
19779
+ /** The read lane on this session (`app-ranges/1`): what this side serves and what it asked; none of it outlives the session. */
19780
+ appRanges = new AppRanges((frame) => {
19781
+ if (this.supportsAppRanges && this.channel) try {
19782
+ this.channel.send(JSON.stringify(frame));
19783
+ } catch {}
19784
+ });
19244
19785
  /** Reaction frames the contact may send per window; the rest go unconfirmed and come again. */
19245
19786
  reactionsReceived = new ReactionWindow(REACTION_LIMITS.receive);
19246
19787
  /** Pin frames the contact may send per window; the rest go unconfirmed and come again. */
@@ -20001,9 +20542,12 @@ var GhostLink = class {
20001
20542
  get presence() {
20002
20543
  return this.mergePresence(this.session.peerPresence);
20003
20544
  }
20004
- /** Someone else used the invite first, and this side never pinned its inviter: there is nobody to pair with. */
20545
+ /**
20546
+ * Someone else used the invite first: there is nobody to pair with, whether or not this side's look-up pinned its
20547
+ * inviter from the envelope put out before anyone joined (said only while unproven: never live, nothing confirmed).
20548
+ */
20005
20549
  get takenFromUs() {
20006
- return !this.options.pairing?.credentials.peerKey && !!this.dht?.inviteTaken;
20550
+ return !!this.dht?.inviteTaken;
20007
20551
  }
20008
20552
  /**
20009
20553
  * The session runs on the joiner's link key, which every copy of the invite derives: while the invite is taken from
@@ -21968,6 +22512,7 @@ var GhostLink = class {
21968
22512
  if (this.options.buttonsSupport) offered.push(BUTTONS_CAPABILITY);
21969
22513
  if (this.options.upgradeSupport) offered.push(UPGRADE_CAPABILITY);
21970
22514
  if (this.options.appsSupport) offered.push(APPS_CAPABILITY);
22515
+ if (this.options.appsSupport && this.options.appRangesSupport) offered.push(APP_RANGES_CAPABILITY);
21971
22516
  if (this.options.deviceCapabilities) offered.push(...this.options.deviceCapabilities);
21972
22517
  return offered;
21973
22518
  }
@@ -22090,7 +22635,7 @@ var GhostLink = class {
22090
22635
  if (!this.options.params.profile) return "Edits need a current chat";
22091
22636
  if (this.channel && this.isDataLinkOpen) {
22092
22637
  if (!this.supportsEdits) return "Your contact's app does not show edits yet";
22093
- if (!validEditNumber(edit.e) && !(edit.sc && this.supportsStatusCards)) return "Your contact's app takes no more edits of this message";
22638
+ if (!edit.rm && !validEditNumber(edit.e) && !(edit.sc && this.supportsStatusCards)) return "Your contact's app takes no more edits of this message";
22094
22639
  try {
22095
22640
  this.channel.send(editFrame(edit));
22096
22641
  return null;
@@ -22099,6 +22644,7 @@ var GhostLink = class {
22099
22644
  }
22100
22645
  }
22101
22646
  if (edit.sc) return "A card's update goes when you are live";
22647
+ if (edit.rm) return "A removal goes when you are live";
22102
22648
  if (dht && this.dht && this.textDelivery === "dht") return this.dht.send(edit.m, edit.ts, dhtEditId(edit.id, edit.e), void 0, [edit.id, edit.e]);
22103
22649
  return "Edits go when you are live";
22104
22650
  }
@@ -22156,6 +22702,7 @@ var GhostLink = class {
22156
22702
  closeApp(app) {
22157
22703
  const frame = JSON.stringify(appCloseFrame(app));
22158
22704
  if (!this.apps.open.delete(app)) return;
22705
+ this.appRanges.closeApp(app, "offline");
22159
22706
  if (this.supportsApps && this.channel) try {
22160
22707
  this.channel.send(frame);
22161
22708
  } catch {}
@@ -22190,8 +22737,98 @@ var GhostLink = class {
22190
22737
  if (files) files.appAhead = Math.min(files.appAhead + frame.length, APP_AHEAD_OF_FILES + APP_DATA_MAX_BYTES);
22191
22738
  return null;
22192
22739
  }
22740
+ /** Both sides offer `app-ranges/1` (and `apps/1`) on the open session: an app's files can be read from the other side. */
22741
+ get supportsAppRanges() {
22742
+ return this.supportsApps && this.sessionCapabilities.agreed("app-ranges/1");
22743
+ }
22744
+ /** Why the read lane cannot be used for `app` now, or null when it can: open on both sides, on a live session that has it. */
22745
+ appRangesRefusal(app) {
22746
+ if (!this.apps.open.has(app)) return "not-open";
22747
+ if (!this.channel || !this.isDataLinkOpen) return "offline";
22748
+ return this.supportsAppRanges && this.apps.peerOpen.has(app) ? null : "peer-closed";
22749
+ }
22750
+ /**
22751
+ * Lets the contact's `app` read `file` (what this side's app calls it) for as long as both have the app open on this
22752
+ * session: the serve id to tell it, or why not.
22753
+ */
22754
+ serveAppFile(app, file) {
22755
+ const error = this.appRangesRefusal(app);
22756
+ return error ? { error } : { serve: this.appRanges.serve(app, file) };
22757
+ }
22758
+ /** Ends a serve; false when it was not served (any more). */
22759
+ unserveAppFile(serve) {
22760
+ return this.appRanges.unserve(serve);
22761
+ }
22762
+ /** The serve ids `app` has given out on this session. */
22763
+ appServes(app) {
22764
+ return this.appRanges.servesOf(app);
22765
+ }
22766
+ /**
22767
+ * Reads `length` bytes at `offset` of what the contact's `app` serves as `serve`: the bytes (fewer at the end of the
22768
+ * file) and the file's size. Rejects with an `Error` whose message is an `AppRangeReadError` or `not-open`.
22769
+ */
22770
+ readAppRange(app, serve, offset, length) {
22771
+ const error = this.appRangesRefusal(app);
22772
+ return error ? Promise.reject(new Error(error)) : this.appRanges.read(app, serve, offset, length);
22773
+ }
22774
+ /**
22775
+ * The bytes `task` asked for (fewer at the end of the file, none past it) and the file's size: sent in chunks as the
22776
+ * channel has room, sharing files' line (`filesWritable`), as binary messages where `files/4` is agreed, then
22777
+ * `ar-end`. Stops when the task is no longer live or the session changes.
22778
+ */
22779
+ async sendAppRange(task, bytes, size) {
22780
+ bytes = bytes.subarray(0, task.length);
22781
+ const channel = this.channel;
22782
+ try {
22783
+ if (!channel) return;
22784
+ for (let at = 0; at < bytes.length; at += APP_RANGE_LIMITS.chunkBytes) {
22785
+ for (let room = this.filesWritable(); room; room = this.channel === channel ? this.filesWritable() : void 0) await room;
22786
+ if (!task.live || this.channel !== channel || !this.supportsAppRanges) return;
22787
+ const chunk = bytes.subarray(at, at + APP_RANGE_LIMITS.chunkBytes);
22788
+ const message = this.supportsBinaryFiles ? encodeAppRangeData(task.app, task.request, task.offset + at, chunk) : JSON.stringify(appRangeDataFrame(task.app, task.request, task.offset + at, chunk));
22789
+ try {
22790
+ channel.send(message);
22791
+ } catch {
22792
+ await new Promise((resolve) => setTimeout(resolve, FILE_LIMITS.sendRetryMs));
22793
+ at -= APP_RANGE_LIMITS.chunkBytes;
22794
+ continue;
22795
+ }
22796
+ this.filesWrote(channel, typeof message === "string" ? message.length : message.byteLength);
22797
+ }
22798
+ this.appRanges.finish(task, size);
22799
+ } finally {
22800
+ this.appRanges.release(task);
22801
+ }
22802
+ }
22803
+ /** `task`'s file cannot be read: `changed` or `gone` goes in place of its bytes (nothing once it is no longer live, but its place frees). */
22804
+ failAppRange(task, error) {
22805
+ this.appRanges.fail(task, error);
22806
+ }
22807
+ /** An `ar-*` frame from the contact, on a session that agreed `app-ranges/1`. */
22808
+ receiveAppRange(frame) {
22809
+ const read = readAppRangeFrame(frame);
22810
+ if (!read.ok) return;
22811
+ const ranges = read.frame;
22812
+ switch (ranges.t) {
22813
+ case "ar-get": {
22814
+ if (this.appRangesRefusal(ranges.a)) {
22815
+ try {
22816
+ this.channel?.send(JSON.stringify(appRangeErrorFrame(ranges.a, ranges.r, "not-served")));
22817
+ } catch {}
22818
+ return;
22819
+ }
22820
+ const task = this.appRanges.receiveGet(ranges);
22821
+ if (task) this.options.events?.onAppRangeTask?.(task);
22822
+ return;
22823
+ }
22824
+ case "ar-cancel": return this.appRanges.receiveCancel(ranges);
22825
+ case "ar-data": return this.appRanges.receiveData(ranges.a, ranges.r, ranges.o, appRangeChunk(ranges.d));
22826
+ default: return this.appRanges.receiveAnswer(ranges);
22827
+ }
22828
+ }
22193
22829
  /** What the contact had open is gone (`apps/1` is no longer agreed, or this link stopped): each app hears it now. */
22194
22830
  appsEnded() {
22831
+ this.appRanges.reset();
22195
22832
  if (this.appsGrace) {
22196
22833
  clearTimeout(this.appsGrace);
22197
22834
  this.appsGrace = null;
@@ -22205,6 +22842,7 @@ var GhostLink = class {
22205
22842
  * hears only that open, not a close first; one not said again by then is closed with `offline`.
22206
22843
  */
22207
22844
  appsSuspended() {
22845
+ this.appRanges.reset();
22208
22846
  this.apps.sessionSuspended();
22209
22847
  if (!this.apps.holding || this.appsGrace) return;
22210
22848
  this.appsGrace = setTimeout(() => {
@@ -22370,6 +23008,7 @@ var GhostLink = class {
22370
23008
  if (!this.supportsApps) this.appsEnded();
22371
23009
  this.options.events?.onAppsSupport?.(this.supportsApps);
22372
23010
  }
23011
+ if (changed.includes("app-ranges/1") && !this.supportsAppRanges) this.appRanges.reset();
22373
23012
  const devices = this.options.deviceCapabilities;
22374
23013
  if (devices && changed.some((capability) => devices.includes(capability))) this.options.events?.onDeviceCapabilities?.(devices.filter((capability) => this.supportsDevice(capability)));
22375
23014
  this.emitPairingState();
@@ -22914,6 +23553,11 @@ var GhostLink = class {
22914
23553
  this.heardFromPeer();
22915
23554
  this.framesHeard++;
22916
23555
  if (typeof data !== "string") {
23556
+ if (data[0] === 5) {
23557
+ const range = this.supportsAppRanges && this.supportsBinaryFiles ? decodeAppRangeData(data) : null;
23558
+ if (range) this.appRanges.receiveData(range.a, range.r, range.o, range.data);
23559
+ return;
23560
+ }
22917
23561
  const chunk = this.supportsBinaryFiles ? decodeFileData(data) : null;
22918
23562
  if (!chunk) return;
22919
23563
  this.activityAt = Date.now();
@@ -23061,9 +23705,14 @@ var GhostLink = class {
23061
23705
  if (frame?.t === "paired-app") {
23062
23706
  if (!this.supportsApps) return;
23063
23707
  const event = this.apps.receive(frame);
23708
+ if (event && "o" in event && event.o === "close") this.appRanges.closeApp(event.app);
23064
23709
  if (event) this.options.events?.onAppFrame?.(event);
23065
23710
  return;
23066
23711
  }
23712
+ if (APP_RANGE_FRAMES.has(String(frame?.t))) {
23713
+ if (this.supportsAppRanges) this.receiveAppRange(frame);
23714
+ return;
23715
+ }
23067
23716
  if (frame?.t === "paired-reaction") {
23068
23717
  if (!this.supportsReactions || !this.reactionsReceived.take()) return;
23069
23718
  const reaction = parseReactionFrame(frame);
@@ -27368,6 +28017,10 @@ var wireMentions = (mentions) => mentions.map(({ k, o, l }) => ({
27368
28017
  * `sc` is the status card of this version (WISP 405 · Status Cards); an edit with one may be numbered up to
27369
28018
  * `STATUS_CARD_LIMITS.edits`, one without only up to `MAX_EDITS_PER_MESSAGE`.
27370
28019
  *
28020
+ * A removal (WISP 400 § Delete for everyone) is an edit with `rm: true` and a fallback text, nothing else beside it,
28021
+ * numbered up to `MAX_REMOVAL_NUMBER`: in a mesh group's box as `{ "text", "rm": true }`, in a community's frame beside
28022
+ * `text`. A `rm` other than `true` is no edit.
28023
+ *
27371
28024
  * Older apps drop both: a mesh session ignores a `t` it does not know, a community app the `x` frames it does not know.
27372
28025
  */
27373
28026
  var GROUP_EDIT_FRAME = "group-edit";
@@ -27397,6 +28050,14 @@ function validEditText(text) {
27397
28050
  }
27398
28051
  /** The `x` frame a community edit travels as. */
27399
28052
  function communityEditFrame(edit) {
28053
+ if (edit.rm) return {
28054
+ t: COMMUNITY_EDIT_FRAME,
28055
+ id: edit.id,
28056
+ v: edit.e,
28057
+ ts: edit.ts,
28058
+ text: edit.m,
28059
+ rm: true
28060
+ };
27400
28061
  return {
27401
28062
  t: COMMUNITY_EDIT_FRAME,
27402
28063
  id: edit.id,
@@ -27414,9 +28075,17 @@ function communityEditFrame(edit) {
27414
28075
  */
27415
28076
  function parseCommunityEdit(frame, sender) {
27416
28077
  if (frame?.t !== "edit") return null;
27417
- const { id, v, ts, text } = frame;
27418
- if (typeof id !== "string" || communityMessageAuthor(id) !== sender || !cardEditNumber(v)) return null;
28078
+ const { id, v, ts, text, rm } = frame;
28079
+ if (rm !== void 0 && rm !== true) return null;
28080
+ if (typeof id !== "string" || communityMessageAuthor(id) !== sender || typeof v !== "number" || !(rm ? validRemovalNumber(v) : cardEditNumber(v))) return null;
27419
28081
  if (typeof ts !== "number" || !Number.isSafeInteger(ts) || ts <= 0 || !validEditText(text)) return null;
28082
+ if (rm) return {
28083
+ id,
28084
+ e: v,
28085
+ ts,
28086
+ m: text,
28087
+ rm
28088
+ };
27420
28089
  const sc = frame.sc === void 0 ? void 0 : readStatusCard(frame.sc);
27421
28090
  if (!validEditNumber(v) && !sc) return null;
27422
28091
  const k = validMentions(frame.m, text, false);
@@ -27476,15 +28145,21 @@ var CatchUpAnswers = class {
27476
28145
  hooks;
27477
28146
  /** Answers still going out, per member: what is left of each. */
27478
28147
  going = /* @__PURE__ */ new Map();
28148
+ /**
28149
+ * Per member, the frames sent (`hooks.key`) whose `handled` has not resolved yet: still waiting in its app, which asks
28150
+ * again every 10 s while it handles 1 or 2 a second, and each answer sent the same ones again (200 missed went 1,009
28151
+ * times). Left out of a newer answer until handled; one handled and still missing (lost) goes in the next.
28152
+ */
28153
+ onTheirWay = /* @__PURE__ */ new Map();
27479
28154
  constructor(hooks) {
27480
28155
  this.hooks = hooks;
27481
28156
  }
27482
28157
  /**
27483
28158
  * The first two slices go now, the rest without holding the group's other frames back. A newer answer to the same
27484
- * member goes after what is left of the last, without the frames still queued there (the same objects: a store's);
27485
- * it took their place before, and left out what the member's `have` said it held: a live frame of an author raises
27486
- * it above that author's frames still queued, which were lost for good. A frame the edge did not take ends the answer
27487
- * (the member asks again when its edge opens).
28159
+ * member goes after what is left of the last, without the frames still queued there (the same objects: a store's)
28160
+ * nor those still on their way (`onTheirWay`); it took their place before, and left out what the member's `have`
28161
+ * said it held: a live frame of an author raises it above that author's frames still queued, which were lost for
28162
+ * good. A frame the edge did not take ends the answer (the member asks again when its edge opens).
27488
28163
  */
27489
28164
  handOut(to, frames) {
27490
28165
  const handled = this.hooks.handled;
@@ -27492,6 +28167,11 @@ var CatchUpAnswers = class {
27492
28167
  for (const frame of frames) this.hooks.send(to, frame);
27493
28168
  return;
27494
28169
  }
28170
+ const sent = this.onTheirWay.get(to), key = this.hooks.key;
28171
+ if (sent?.size && key) frames = frames.filter((frame) => {
28172
+ const k = key(frame);
28173
+ return k === void 0 || !sent.has(k);
28174
+ });
27495
28175
  const going = this.going.get(to);
27496
28176
  if (going) {
27497
28177
  const queued = new Set(going);
@@ -27500,9 +28180,19 @@ var CatchUpAnswers = class {
27500
28180
  }
27501
28181
  const rest = [...frames], told = [];
27502
28182
  const ask = () => handled(to).catch(() => false);
28183
+ const settled = async () => {
28184
+ let answer = await ask();
28185
+ while (answer === "late" && this.hooks.active()) answer = await ask();
28186
+ return answer;
28187
+ };
27503
28188
  const next = () => {
27504
- if (!this.sendSlice(to, rest)) return false;
27505
- if (rest.length) told.push(ask());
28189
+ const slice = this.sendSlice(to, rest);
28190
+ if (!slice) return false;
28191
+ const keys = key ? slice.map(key).filter((k) => k !== void 0) : [];
28192
+ if (!rest.length && !keys.length) return true;
28193
+ const done = settled();
28194
+ if (keys.length) this.track(to, keys, done);
28195
+ if (rest.length) told.push(done);
27506
28196
  return true;
27507
28197
  };
27508
28198
  if (!next() || !next() || !rest.length) return;
@@ -27510,9 +28200,7 @@ var CatchUpAnswers = class {
27510
28200
  (async () => {
27511
28201
  try {
27512
28202
  while (rest.length) {
27513
- let answer = await told.shift();
27514
- while (answer === "late" && this.hooks.active()) answer = await ask();
27515
- if (!answer) await new Promise((resolve) => setTimeout(resolve, 500));
28203
+ if (!await told.shift()) await new Promise((resolve) => setTimeout(resolve, 500));
27516
28204
  if (!this.hooks.active() || !next()) break;
27517
28205
  }
27518
28206
  } finally {
@@ -27520,13 +28208,24 @@ var CatchUpAnswers = class {
27520
28208
  }
27521
28209
  })();
27522
28210
  }
27523
- /** The next slice of `rest` to `to`: false, and nothing left, when the edge did not take one. */
28211
+ /** The next slice of `rest` to `to`, as sent: undefined, and nothing left, when the edge did not take one. */
27524
28212
  sendSlice(to, rest) {
27525
- for (const frame of rest.splice(0, 16)) if (this.hooks.send(to, frame) === false) {
28213
+ const slice = rest.splice(0, 16);
28214
+ for (const frame of slice) if (this.hooks.send(to, frame) === false) {
27526
28215
  rest.length = 0;
27527
- return false;
28216
+ return;
27528
28217
  }
27529
- return true;
28218
+ return slice;
28219
+ }
28220
+ /** A slice's frames (`keys`) are on their way to `to` until `done`: its app handled them, or cannot say (`false`). */
28221
+ track(to, keys, done) {
28222
+ let sent = this.onTheirWay.get(to);
28223
+ if (!sent) this.onTheirWay.set(to, sent = /* @__PURE__ */ new Set());
28224
+ for (const k of keys) sent.add(k);
28225
+ done.then(() => {
28226
+ for (const k of keys) sent.delete(k);
28227
+ if (!sent.size && this.onTheirWay.get(to) === sent) this.onTheirWay.delete(to);
28228
+ });
27530
28229
  }
27531
28230
  };
27532
28231
  //#endregion
@@ -27786,7 +28485,7 @@ var editSigned = (f) => utf8Encode(JSON.stringify([
27786
28485
  function isEditFrame(v) {
27787
28486
  if (!v || typeof v !== "object") return false;
27788
28487
  const f = v;
27789
- return f.t === "group-edit" && typeof f.g === "string" && GROUP_ID.test(f.g) && Number.isSafeInteger(f.e) && f.e >= 0 && typeof f.s === "string" && MEMBER_KEY.test(f.s) && Number.isSafeInteger(f.n) && f.n >= 0 && cardEditNumber(f.v) && Number.isSafeInteger(f.ts) && f.ts > 0 && typeof f.nn === "string" && f.nn.length === 32 && B64$1.test(f.nn) && typeof f.c === "string" && f.c.length <= MAX_EDIT_BOX && B64$1.test(f.c) && typeof f.sig === "string" && f.sig.length === 86 && B64$1.test(f.sig);
28488
+ return f.t === "group-edit" && typeof f.g === "string" && GROUP_ID.test(f.g) && Number.isSafeInteger(f.e) && f.e >= 0 && typeof f.s === "string" && MEMBER_KEY.test(f.s) && Number.isSafeInteger(f.n) && f.n >= 0 && validRemovalNumber(f.v) && Number.isSafeInteger(f.ts) && f.ts > 0 && typeof f.nn === "string" && f.nn.length === 32 && B64$1.test(f.nn) && typeof f.c === "string" && f.c.length <= MAX_EDIT_BOX && B64$1.test(f.c) && typeof f.sig === "string" && f.sig.length === 86 && B64$1.test(f.sig);
27790
28489
  }
27791
28490
  /**
27792
28491
  * Where a frame said again was first said (`o`): an earlier epoch than the frame's own and a sequence number there, or
@@ -27996,7 +28695,8 @@ var GroupSession = class {
27996
28695
  return hooks.send(to, frame);
27997
28696
  },
27998
28697
  ...hooks.handled && { handled: (to) => hooks.handled(to) },
27999
- active: () => this.state.status === "active"
28698
+ active: () => this.state.status === "active",
28699
+ key: (frame) => frame.t === "group-msg" ? frameKey$1(frame) : void 0
28000
28700
  });
28001
28701
  this.provisional = new Set((state.provisional ?? []).slice(-GROUP_LIMITS.provisional));
28002
28702
  this.chainMovedAt = this.clock();
@@ -28123,13 +28823,24 @@ var GroupSession = class {
28123
28823
  return this.roster.map(([k]) => k).filter((k) => k !== this.myKey);
28124
28824
  }
28125
28825
  /**
28126
- * Whether `key` could read message `messageId` (`<s>:<e>:<n>`) and still can: in the roster of its epoch, and in the
28127
- * roster now. A holder serves a group file only to such a member (WISP 503 § Asking).
28826
+ * Whether `key` could read message `messageId` (`<s>:<e>:<n>`) and still can: in the roster now, and in the roster of
28827
+ * its epoch or, given the message's time `ts`, in the roster of the epoch its author, behind on the chain, said it
28828
+ * again under (`saidAgainEpoch`): the newest after its own that comes before any `add` dated later than it. That
28829
+ * member read it under its first id. A holder serves a group file only to such a member (WISP 503 § Asking).
28128
28830
  */
28129
- couldRead(key, messageId) {
28831
+ couldRead(key, messageId, ts) {
28130
28832
  const e = Number(messageId.split(":")[1]);
28131
28833
  const then = this.state.chain.find((c) => c.e === e);
28132
- return !!then && rosterHas(then.m, key) && rosterHas(this.roster, key);
28834
+ if (!then || !rosterHas(this.roster, key)) return false;
28835
+ if (rosterHas(then.m, key)) return true;
28836
+ if (ts === void 0) return false;
28837
+ let again;
28838
+ for (let later = e + 1; later <= this.epoch; later++) {
28839
+ const c = this.state.chain[later];
28840
+ if (!c || c.k === "add" && c.ts > ts) break;
28841
+ again = c;
28842
+ }
28843
+ return !!again && rosterHas(again.m, key);
28133
28844
  }
28134
28845
  role(key) {
28135
28846
  return this.roster.find(([k]) => k === key)?.[1];
@@ -28754,12 +29465,15 @@ var GroupSession = class {
28754
29465
  const ref = meshMessageRef(messageId);
28755
29466
  const commit = ref && this.state.chain[ref.e];
28756
29467
  if (!ref || ref.s !== this.myKey || !commit || !rosterHas(commit.m, this.myKey)) return { error: "Only your own messages can be edited" };
28757
- if (!(edit.card ? cardEditNumber(edit.v) : validEditNumber(edit.v))) return { error: "This message was edited too many times" };
29468
+ if (!(edit.remove ? validRemovalNumber(edit.v) : edit.card ? cardEditNumber(edit.v) : validEditNumber(edit.v))) return { error: "This message was edited too many times" };
28758
29469
  const text = edit.text.trim();
28759
29470
  if (!validEditText(text)) return { error: text ? "Message exceeds 16 KiB" : "An edit cannot be empty" };
28760
29471
  if (!this.secret(ref.e)) return { error: "This message is too old to edit: its epoch's key is gone" };
28761
29472
  const named = validMentions(wireMentions(edit.mentions ?? []), text, rosterAdmin(commit.m) === this.myKey && this.isAdmin);
28762
- const plain = JSON.stringify({
29473
+ const plain = JSON.stringify(edit.remove ? {
29474
+ text,
29475
+ rm: true
29476
+ } : {
28763
29477
  text,
28764
29478
  ...named.length ? { m: named } : {},
28765
29479
  ...edit.card ? { sc: edit.card } : {}
@@ -29156,9 +29870,12 @@ var GroupSession = class {
29156
29870
  return;
29157
29871
  }
29158
29872
  if (!body || typeof body !== "object" || !validEditText(body.text)) return;
29159
- const k = validMentions(body.m, body.text, rosterAdmin(commit.m) === raw.s && this.admin === raw.s);
29160
- const sc = body.sc === void 0 ? void 0 : readStatusCard(body.sc);
29161
- if (!validEditNumber(raw.v) && !sc) return;
29873
+ if (body.rm !== void 0 && body.rm !== true) return;
29874
+ const rm = body.rm === true;
29875
+ if (!rm && !cardEditNumber(raw.v)) return;
29876
+ const k = rm ? [] : validMentions(body.m, body.text, rosterAdmin(commit.m) === raw.s && this.admin === raw.s);
29877
+ const sc = rm || body.sc === void 0 ? void 0 : readStatusCard(body.sc);
29878
+ if (!rm && !validEditNumber(raw.v) && !sc) return;
29162
29879
  const copy = this.kept().find((f) => f.s === raw.s && f.e === raw.e && f.n === raw.n);
29163
29880
  const first = copy && readFirstPlace(copy.o, copy.e);
29164
29881
  await this.hooks.edit?.({
@@ -29168,7 +29885,8 @@ var GroupSession = class {
29168
29885
  ts: raw.ts,
29169
29886
  m: body.text,
29170
29887
  ...k.length ? { k } : {},
29171
- ...sc ? { sc } : {}
29888
+ ...sc ? { sc } : {},
29889
+ ...rm ? { rm: true } : {}
29172
29890
  });
29173
29891
  if (this.keepEdit(raw)) {
29174
29892
  await this.persist();
@@ -29935,12 +30653,16 @@ var FRESH = /* @__PURE__ */ new Set([
29935
30653
  * history keeps room for everyone else to get out after it: two commits a member (a leave or a remove is one, and a
29936
30654
  * leaving admin hands the role over first). The history is never compacted, and one that filled with people in it
29937
30655
  * took no leave, remove or handover any more. Its own rule: a history up to `COMMUNITY_LIMITS.chain` verifies as before.
30656
+ * A member takes in such a commit from someone else only when it keeps that room too (`receiveCommit`): an app that
30657
+ * does not keep it could otherwise fill the history for everyone.
29938
30658
  */
29939
30659
  var GROWS = /* @__PURE__ */ new Set([
29940
30660
  "add",
29941
30661
  "rotate",
29942
30662
  "link"
29943
30663
  ]);
30664
+ /** Whether a history whose last commit is at `epoch`, with `roster` in it, still has room for everyone else to get out. */
30665
+ var keepsRoom = (epoch, roster) => epoch + 1 + 2 * (roster.length - 1) <= COMMUNITY_LIMITS.chain;
29944
30666
  /**
29945
30667
  * Kinds only the admin commits. They are final: a branch that drops one never replaces the branch
29946
30668
  * that has it, however long, so no member can undo a removal, a hand-over, a rotation or a link change
@@ -30002,6 +30724,30 @@ var leftStatement = (g, h, hi) => utf8Encode(JSON.stringify([
30002
30724
  Object.entries(hi).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
30003
30725
  ]));
30004
30726
  var LEFT_EPOCH = /^\d{1,15}:[a-f0-9]{16}$/;
30727
+ /** A leave of one admission: `h` is the hash of the commit that last put `s` in the roster (its `add`, or the `create` it signed). */
30728
+ var leaveStatement3 = (g, s, h) => utf8Encode(JSON.stringify([
30729
+ "ghostly-group/3 leave",
30730
+ g,
30731
+ s,
30732
+ h
30733
+ ]));
30734
+ /**
30735
+ * Whether a leave holds after `before` (the commits before it, newest first): its `ls3` names the commit that last
30736
+ * admitted the leaver, or, from an app that signs no such statement, no earlier leave carries its `ls`. `ls` says the
30737
+ * same for every admission of a member, so by itself it ends one admission only.
30738
+ */
30739
+ function leaveStands(leave, before) {
30740
+ if (!leave.s || !leave.ls) return false;
30741
+ let admitted = false;
30742
+ for (const c of before) {
30743
+ if (!admitted && (c.k === "add" && c.s === leave.s || c.k === "create" && c.by === leave.s)) {
30744
+ admitted = true;
30745
+ if (leave.ls3 && SIG.test(leave.ls3) && verify(fromBase64Url(leave.ls3), leaveStatement3(leave.g, leave.s, communityCommitHash(c)), publicKeyFromZ32(leave.s))) return true;
30746
+ }
30747
+ if (c.k === "leave" && c.ls === leave.ls) return false;
30748
+ }
30749
+ return true;
30750
+ }
30005
30751
  /** The secret of an epoch that adds, re-roles or re-links: from the previous one and the commit. */
30006
30752
  function derivedSecret(previous, untaggedHash) {
30007
30753
  return hkdf(sha256, previous, utf8Encode(untaggedHash), utf8Encode("ghostly-group/2 derived"), 32);
@@ -30027,6 +30773,7 @@ function parseCommit(raw) {
30027
30773
  if (c.x !== void 0) out.x = c.x;
30028
30774
  if (c.n !== void 0) out.n = c.n;
30029
30775
  if (c.ls !== void 0) out.ls = c.ls;
30776
+ if (out.k === "leave" && typeof c.ls3 === "string" && SIG.test(c.ls3)) out.ls3 = c.ls3;
30030
30777
  return out;
30031
30778
  }
30032
30779
  /**
@@ -30059,15 +30806,18 @@ function communityRoster(previous, c, trusted = false) {
30059
30806
  /**
30060
30807
  * One commit against its parent (null for a genesis) and the parent's roster: shape, id, link,
30061
30808
  * authority, roster arithmetic, roster hash and signature. The confirmation tag is checked once
30062
- * the secret is known.
30809
+ * the secret is known. `before`: the commits before it on its branch, newest first; given, a `leave` is held to the
30810
+ * admission it ends (`leaveStands`). A member gives it for every commit it takes in after its own admission; the chain
30811
+ * of a welcome is not held to it (`verifyCommunityChain`).
30063
30812
  */
30064
- function verifyCommunityCommit(raw, parent, parentRoster, groupId) {
30813
+ function verifyCommunityCommit(raw, parent, parentRoster, groupId, before) {
30065
30814
  const commit = parseCommit(raw);
30066
30815
  if (!commit) return { error: "Malformed membership commit" };
30067
30816
  if (groupId && commit.g !== groupId) return { error: "Commit for another group" };
30068
30817
  if (parent) {
30069
30818
  if (commit.g !== parent.g) return { error: "Commit for another group" };
30070
30819
  if (commit.e !== parent.e + 1) return { error: "Commit out of sequence" };
30820
+ if (commit.e >= COMMUNITY_LIMITS.chain) return { error: "Membership chain too long" };
30071
30821
  if (commit.p !== communityCommitHash(parent)) return { error: "Commit does not follow its parent" };
30072
30822
  } else {
30073
30823
  if (commit.e !== 0 || commit.p !== "" || commit.k !== "create") return { error: "The chain does not start with the creation of the group" };
@@ -30077,6 +30827,7 @@ function verifyCommunityCommit(raw, parent, parentRoster, groupId) {
30077
30827
  if (commit.k !== "leave" && commit.ls !== void 0) return { error: "Malformed membership commit" };
30078
30828
  const roster = communityRoster(parent ? parentRoster : null, commit);
30079
30829
  if (!roster) return { error: "Unauthorized or inconsistent membership change" };
30830
+ if (commit.k === "leave" && before && !leaveStands(commit, before)) return { error: "This leave is not for the member's current admission" };
30080
30831
  if (rosterHash(roster) !== commit.m) return { error: "The roster hash does not match the change" };
30081
30832
  if (!verify(fromBase64Url(commit.sig), utf8Encode(tuple(commit)), publicKeyFromZ32(commit.by))) return { error: "Membership commit signature is invalid" };
30082
30833
  return {
@@ -30084,7 +30835,11 @@ function verifyCommunityCommit(raw, parent, parentRoster, groupId) {
30084
30835
  roster
30085
30836
  };
30086
30837
  }
30087
- /** A whole chain from its genesis; the rosters after each commit and the entry key at the end. */
30838
+ /**
30839
+ * A whole chain from its genesis; the rosters after each commit and the entry key at the end. What a newcomer is
30840
+ * handed: a `leave` in it is not held to the admission it ends, since a chain from before 2026-10-10 may hold a
30841
+ * member's second leave under the one statement there was, and no newcomer could enter that group again.
30842
+ */
30088
30843
  function verifyCommunityChain(raw, groupId) {
30089
30844
  if (!Array.isArray(raw) || raw.length === 0 || raw.length > COMMUNITY_LIMITS.chain) return { error: "Malformed membership chain" };
30090
30845
  const chain = [], rosters = [];
@@ -30575,13 +31330,17 @@ var CommunitySession = class {
30575
31330
  placeSide(commit) {
30576
31331
  const parent = this.known.get(commit.p), parentRoster = parent ? this.rosterAt(commit.p) : void 0;
30577
31332
  if (!parentRoster || !parent) return false;
30578
- const result = verifyCommunityCommit(commit, parent, parentRoster, this.id);
31333
+ const result = verifyCommunityCommit(commit, parent, parentRoster, this.id, this.ancestry(commit.p));
30579
31334
  if ("error" in result) return false;
30580
31335
  const h = communityCommitHash(result.commit);
30581
31336
  this.known.set(h, result.commit);
30582
31337
  this.rosters.set(h, result.roster);
30583
31338
  return true;
30584
31339
  }
31340
+ /** The commit `h` and those before it on its branch, newest first. */
31341
+ *ancestry(h) {
31342
+ for (let c = this.known.get(h); c; c = this.known.get(c.p)) yield c;
31343
+ }
30585
31344
  rosterOf(h) {
30586
31345
  return this.rosterAt(h);
30587
31346
  }
@@ -30704,8 +31463,9 @@ var CommunitySession = class {
30704
31463
  }
30705
31464
  const parsed = parseCommit(raw);
30706
31465
  if (!parsed || this.known.has(communityCommitHash(parsed))) return false;
30707
- const result = verifyCommunityCommit(raw, parent, parentRoster, this.id);
31466
+ const result = verifyCommunityCommit(raw, parent, parentRoster, this.id, this.ancestry(p));
30708
31467
  if ("error" in result) return false;
31468
+ if (GROWS.has(result.commit.k) && !keepsRoom(result.commit.e, result.roster)) return false;
30709
31469
  const commit = result.commit, h = communityCommitHash(commit);
30710
31470
  const admin = rosterAdmin(parentRoster);
30711
31471
  if (commit.by === admin) {
@@ -30936,8 +31696,8 @@ var CommunitySession = class {
30936
31696
  ts: now
30937
31697
  };
30938
31698
  const roster = communityRoster(this.roster, draftBase);
30939
- if (!roster) throw new Error("This change is not allowed");
30940
- if (GROWS.has(kind) && this.state.chain.length + 1 + 2 * (roster.length - 1) > COMMUNITY_LIMITS.chain) throw new Error("This group has reached its membership history limit. Create a new group.");
31699
+ if (!roster || kind === "leave" && !leaveStands(draftBase, this.ancestry(parentHash))) throw new Error("This change is not allowed");
31700
+ if (GROWS.has(kind) && !keepsRoom(draftBase.e, roster)) throw new Error("This group has reached its membership history limit. Create a new group.");
30941
31701
  const draft = {
30942
31702
  ...draftBase,
30943
31703
  m: rosterHash(roster)
@@ -31107,6 +31867,10 @@ var CommunitySession = class {
31107
31867
  s: this.myKey,
31108
31868
  ls: toBase64Url(sign(leaveStatement(this.id, this.myKey), this.identity.seed))
31109
31869
  };
31870
+ for (const c of this.ancestry(this.topHash)) if (c.k === "add" && c.s === this.myKey || c.k === "create" && c.by === this.myKey) {
31871
+ frame.ls3 = toBase64Url(sign(leaveStatement3(this.id, this.myKey, communityCommitHash(c)), this.identity.seed));
31872
+ break;
31873
+ }
31110
31874
  this.hooks.broadcast(frame);
31111
31875
  this.out("left", "You left this group");
31112
31876
  await this.persist();
@@ -31128,7 +31892,8 @@ var CommunitySession = class {
31128
31892
  try {
31129
31893
  const { hash } = await this.commit("leave", {
31130
31894
  s: request.s,
31131
- ls: request.ls
31895
+ ls: request.ls,
31896
+ ...request.ls3 ? { ls3: request.ls3 } : {}
31132
31897
  }, now);
31133
31898
  this.markLeft(hash, request.s);
31134
31899
  done++;
@@ -31266,17 +32031,18 @@ var CommunitySession = class {
31266
32031
  return this.serialize(async () => {
31267
32032
  if (!this.isMember) return { error: this.state.statusReason ?? "You are not in this group" };
31268
32033
  if (communityMessageAuthor(edit.id) !== this.myKey) return { error: "Only your own messages can be edited" };
31269
- if (!(edit.card ? cardEditNumber(edit.v) : validEditNumber(edit.v))) return { error: "This message was edited too many times" };
32034
+ if (!(edit.remove ? validRemovalNumber(edit.v) : edit.card ? cardEditNumber(edit.v) : validEditNumber(edit.v))) return { error: "This message was edited too many times" };
31270
32035
  const text = edit.text.trim();
31271
32036
  if (!validEditText(text)) return { error: text ? "Message exceeds 16 KiB" : "An edit cannot be empty" };
31272
- const named = validMentions(wireMentions(edit.mentions ?? []), text, false);
32037
+ const named = edit.remove ? [] : validMentions(wireMentions(edit.mentions ?? []), text, false);
31273
32038
  const frame = communityEditFrame({
31274
32039
  id: edit.id,
31275
32040
  e: edit.v,
31276
32041
  ts: edit.ts,
31277
32042
  m: text,
31278
32043
  k: named,
31279
- ...edit.card && { sc: edit.card }
32044
+ ...edit.card && !edit.remove && { sc: edit.card },
32045
+ ...edit.remove && { rm: true }
31280
32046
  });
31281
32047
  const room = COMMUNITY_LIMITS.textBytes + 256, clean = sanitizeNick(nick);
31282
32048
  const size = (withNick) => utf8Encode(JSON.stringify(withNick && clean ? {
@@ -31526,11 +32292,27 @@ var CommunitySession = class {
31526
32292
  receiveLeave(frame) {
31527
32293
  const s = frame.s, ls = frame.ls;
31528
32294
  if (typeof s !== "string" || !MEMBER_KEY.test(s) || typeof ls !== "string" || !SIG.test(ls) || !rosterHas(this.roster, s)) return false;
31529
- if (this.state.pendingLeaves.some((r) => r.s === s)) return false;
32295
+ const ls3 = typeof frame.ls3 === "string" && SIG.test(frame.ls3) ? frame.ls3 : void 0;
32296
+ let held = this.state.pendingLeaves.find((r) => r.s === s);
32297
+ if (held && !leaveStands({
32298
+ g: this.id,
32299
+ ...held
32300
+ }, this.ancestry(this.topHash))) {
32301
+ this.state.pendingLeaves = this.state.pendingLeaves.filter((r) => r !== held);
32302
+ held = void 0;
32303
+ }
32304
+ if (held && (held.ls3 || !ls3)) return false;
31530
32305
  if (!verify(fromBase64Url(ls), leaveStatement(this.id, s), publicKeyFromZ32(s))) return false;
31531
- this.state.pendingLeaves = [...this.state.pendingLeaves, {
32306
+ if (!leaveStands({
32307
+ g: this.id,
32308
+ s,
32309
+ ls,
32310
+ ls3
32311
+ }, this.ancestry(this.topHash))) return false;
32312
+ this.state.pendingLeaves = [...this.state.pendingLeaves.filter((r) => r !== held), {
31532
32313
  s,
31533
- ls
32314
+ ls,
32315
+ ...ls3 ? { ls3 } : {}
31534
32316
  }].slice(-COMMUNITY_LIMITS.pendingLeaves);
31535
32317
  this.persistSoon();
31536
32318
  return true;
@@ -32691,6 +33473,6 @@ function readX401SdJwtVc(text) {
32691
33473
  };
32692
33474
  }
32693
33475
  //#endregion
32694
- export { parseSshPublicKey as $, GROUP_MEMBER_CAP as $a, DEVICES_CAPABILITY as $c, DHT_MESSAGE_TTL as $i, randomBytes as $l, readGroupWantNo as $n, handoffContextProof as $o, chatAppId as $r, knockSlotIdentity as $s, SEPOLIA_TEST_USDT_FAUCET as $t, knockRecords as A, wireReaction as Aa, isAppRef as Ac, capsDescriptors as Ai, normalizeRelayUrl as Al, findEndpoint as An, signalHasVideo as Ao, transferStalled as Ar, ENROLL_HELLO as As, didWebDocumentUrl as At, GROUP_READ_NOTE as B, appCardId as Ba, createContactLink as Bc, identityStatement as Bi, openRelayPayload as Bl, engineError as Bn, HANDOFF_OFFER as Bo, pinIsNewer as Br, readEnrollHello as Bs, staticDidDocument as Bt, decodeCommunityLink as C, ReactionWindow as Ca, APP_PREFIXES as Cc, recordsFromTxt as Ci, turnKeys as Cl, pubkyHomeserverOf as Cn, RTC_CONFIG as Co, readBeacon as Cr, readSetUpdate as Cs, DID_JWS_MAX_LENGTH as Ct, encodeGroupEntryLink as D, reactionIsNewer as Da, checkAppRevokeStatement as Dc, wellKnownUrl as Di, DEFAULT_RELAYS as Dl, ENDPOINT as Dn, callSignalHeardAt as Do, ChatFiles as Dr, verifySetUpdate as Ds, didGhostlyServiceEntry as Dt, decodeGroupEntryLink as E, reactionEmoji as Ea, appRef as Ec, txtValue as Ei, turnVerifierMark as El, decodeBolt11 as En, callRtcConfig as Eo, shouldBeHub as Er, signTombstone as Es, checkDidSignature as Et, groupWakeFrame as F, ITEM_STATES as Fa, parseImageMeta as Fc, IdentityCheckUnavailable as Fi, withRequestOptions as Fl, INVITE_TAKEN as Fn, HANDOFF_ACK as Fo, typingActivity as Fr, enrollDoneFrame as Fs, normalizeDid as Ft, GROUP_EDIT_TEXT_BYTES as G, sameButtonText as Ga, readDeviceInvite as Gc, PeerProofs as Gi, publicKeyFromZ32 as Gl, GROUP_WANT_FRAME as Gn, HANDOFF_VERIFIED as Go, deviceWakeRequest as Gr, newInbox as Gs, encodeDidDhtPacket as Gt, frameBytes as H, cardLine as Ha, readContactLink as Hc, receivedIdentityStatus as Hi, createIdentity as Hl, parseEngineError as Hn, HANDOFF_PIECE_BYTES as Ho, readPin as Hr, clearMissed as Hs, didDhtDocument as Ht, groupWakes as I, PR_CHECKS as Ia, readImageMeta as Ic, IdentityExchange as Ii, PacketTooLargeError as Il, LIVENESS_PING_MS as In, HANDOFF_CANCEL as Io, GROUP_PIN_FRAME as Ir, enrollGrantFrame as Is, parseDid as It, mentionsMember as J, claimedTime as Ja, decodeInviteCode as Jc, TRANSPORTS as Ji, sanitizeAvatar as Jl, groupFileFallback as Jn, handoffAttemptFailed as Jo, relayRequest as Jr, takeRequest as Js, ETHEREUM_USDT as Jt, carryMentions as K, statusCardText as Ka, OwnInviteError as Kc, emptyProofLedger as Ki, verify as Kl, GROUP_WANT_NO_FRAME as Kn, filePartName as Ko, newWakeToken as Kr, planKnocks as Ks, resolveDidDht as Kt, parseGroupWakeFrame as L, PR_STATES as La, canonicalJson as Lc, boundVerifiedIdentity as Li, RELAY_PAYLOAD_MAX_BYTES as Ll, PAIRED_FRAME_TOO_LARGE as Ln, HANDOFF_DONE as Lo, PIN_LIMITS as Lr, enrollHelloFrame as Ls, parseDidDocument as Lt, readKnocks as M, readReply as Ma, readAppRevocations as Mc, IDENTITY_MAX_EVIDENCE as Mi, traceLink as Ml, parseCashuRequestPayload as Mn, HTTP_SERVICE_PROTO as Mo, TYPING_REFRESH_MS as Mr, enrollCancelFrame as Ms, didWebFileNames as Mt, GROUP_WAKE_FRAME as N, replySnippet as Na, signAppObject as Nc, IDENTITY_MAX_VALIDITY as Ni, budgetRetryMs as Nl, parseFedimintRequestPayload as Nn, LEGACY_SERVICES as No, TypingSender as Nr, enrollCancelReason as Ns, didWebFileUrl as Nt, entryParams as O, readReaction as Oa, isAppHash as Oc, CapsExchange as Oi, RelayTransport as Ol, cashuRequestPayload as On, extractParamsFromSdp as Oo, FILE_LIMITS as Or, ENROLL_DONE as Os, didJwsAlg as Ot, GroupWakeLimiter as P, BUTTON_ID as Pa, signAppRevocation as Pc, IDENTITY_REVOCATION_LABEL as Pi, isDiscoveryBudgetError as Pl, GhostLink as Pn, serviceIdFromName as Po, sanitizeTypingStatus as Pr, enrollDigits as Ps, didWebHost as Pt, SshSigError as Q, GROUP_ADMIN_OFF_ERROR as Qa, ownInviteRefusal as Qc, DHT_FILE_TOO_LARGE as Qi, isZ32Key as Ql, readGroupWant as Qn, handoffContext as Qo, APP_DATA_MAX_BYTES as Qr, contactDay as Qs, SEPOLIA_TEST_USDT as Qt, GROUP_LIMITS as R, RUN_RESULTS as Ra, canonicalJsonBytes as Rc, emptyIdentityLedger as Ri, createRelayPayload as Rl, pairedMessageFits as Rn, HANDOFF_HAVE as Ro, mayPin as Rr, enrollProofFrame as Rs, parseDidSignaturePaste as Rt, communityHasFrame as S, REACTION_LIMITS as Sa, sha256Paced as Sc, normalizeDomain as Si, turnInstance as Sl, homeserverWebEndpoint as Sn, CALL_SIGNAL_MAX_AGE_MS as So, rankHubs as Sr, SET_UPDATE as Ss, DID_FILE_MAX_BYTES as St, KNOCK_TTL_MS as T, queueReaction as Ta, appFingerprint as Tc, recordsName as Ti, turnStatedVerifier as Tl, resolveLightningDestination as Tn, buildSdpFromSignal as To, readLobby as Tr, setUpdateFrame as Ts, checkDidJws as Tt, COMMUNITY_EDIT_FRAME as U, cardUrl as Ua, createDeviceInvite as Uc, revokesIdentity as Ui, identityFromSeed as Ul, GROUP_FILE_LIMITS as Un, HANDOFF_REQUEST as Uo, WAKE_CALL_INTERVAL_MS as Ur, endedRequests as Us, didDhtFromPublicKey as Ut, GroupSession as V, buttonLabelClash as Va, encodeContactLink as Vc, newIdentityBinding as Vi, parseRelayPayload as Vl, engineText as Vn, HANDOFF_PAKE as Vo, pinNumberHolds as Vr, verifyEnrollProof as Vs, strictBase64Url as Vt, GROUP_EDIT_FRAME as W, checkStatusCard as Wa, deviceInviteJoinerParams as Wc, lastSharedWithMe as Wi, identityFromSeedB64 as Wl, GROUP_HAVE_FRAME as Wn, HANDOFF_TIMINGS as Wo, WakeLimiter as Wr, inboxRecord as Ws, encodeDidDhtDeactivated as Wt, SSHSIG_MAX_ARMOR as X, receivedTimestamp as Xa, inviteLink as Xc, irohDescriptor as Xi, bytesEqual as Xl, readGroupFileMeta as Xn, handoffBusyFrame as Xo, checkPushEndpoint as Xr, ContactRequestError as Xs, ONCHAIN_PROVIDER as Xt, groupName as Y, heardTime as Ya, encodeInviteCode as Yc, automaticTransport as Yi, sanitizeDisplayText as Yl, isGroupMessageId as Yn, handoffAttemptSucceeded as Yo, wakeRequest as Yr, turnOff as Ys, EVM_TEST_CHAINS as Yt, SSHSIG_NAMESPACE as Z, shownTime as Za, inviteOwnership as Zc, irohRelayUrl as Zi, fromBase64Url as Zl, readGroupHave as Zn, handoffCancelFrame as Zo, vapidKeysMatch as Zr, REQUEST_LIFETIME_MS as Zs, PaymentPreflightError as Zt, openGroupTyping as _, parseLinkPreview as _a, checkAppManifest as _c, domainTxtRecord as _i, firstDeviceSetSecret as _l, newPubkyProofFolder as _n, parseLocalTarget as _o, lobbyRecords as _r, readHandoffPake as _s, parseAtprotoDidDocument as _t, appStoreDecision as a, sanitizeMime as aa, openRequest as ac, UPGRADE_CAPABILITY as ai, deviceLinkPairing as al, assertWholeSats as an, rosterHas as ao, groupSignalFrame as ar, handoffOfferFrame as as, BitcoinAddressError as at, CommunitySession as b, COMMUNITY_REACTION_FRAME as ba, readAppBundle as bc, isPublicAddress as bi, signTurnPacket as bl, pubkyProofFile as bn, decodeControl as bo, newerHead as br, sealHandoffPiece as bs, verifyAtprotoRecordProof as bt, planAppUpdate as c, baseMime as ca, requestRecords as cc, HOLD_LIMITS as ci, seedSigner as cl, walletNetworkOf as cn, DirectPathWatch as co, mayBeHub as cr, handoffRetryAfter as cs, ATPROTO_FULL_SCOPE as ct, readAppStore as d, voicePeaksOf as da, APP_BUNDLE_MAGIC as dc, isHoldUrl as di, TURN_RAISE_READ_TIMEOUT_MS as dl, sparkAddressKind as dn, EXPECT_PEER_MS as do, COMMUNITY_TOPOLOGY as dr, newHandoffId as ds, atprotoDidMethod as dt, peekDhtMailbox as ea, knockSlotOf as ec, isAppVersion as ei, ENROLL_CAPABILITY as el, TEST_USDT_FAUCET_AMOUNT as en, MAX_GROUP_CHAIN as eo, CarriedTransport as er, handoffDataFrame as es, parseSshSignature as et, toBase64Url as eu, readAppStoreSteps as f, parseVideoMeta as fa, APP_ICON_PATH as fc, newMailbox as fi, TURN_SETTLE_MS as fl, sparkInvoiceDetails as fn, RELAY_POLL_INTERVALS as fo, beaconKeys as fr, readHandoffAck as fs, atprotoProofRecord as ft, groupTypingEpoch as g, dhtEditId as ga, assembleAppBundle as gc, dnsProofName as gi, TURN_MAX as gl, isPubkyProofFolder as gn, formatLocalTarget as go, lobbyKeys as gr, readHandoffHello as gs, normalizeAtprotoHandle as gt, GroupTypingBoard as h, RateWindow as ha, appViewOf as hc, decodeDnsResponse as hi, TURN_LAST_SEQUENCE as hl, isPubkyKey as hn, GhostlyHttpError as ho, freshHubs as hr, readHandoffHave as hs, isAtprotoDid as ht, appRevocationFor as i, sanitizeFileName as ia, mergeContactKnocks as ic, STATUS_CARD_CAPABILITY as ii, deviceKeyZ32 as il, assertTokenUnits as in, rosterAdmin as io, SIGNAL_REPLY_MS as ir, handoffManifestFrames as is, verifyBitcoinMessage as it, mergeKnocks as j, pairedReplyAuthor as ja, readAppRevocation as jc, dialDescriptors as ji, setLinkTraceSink as jl, isFederationId as jn, emptyLinkRecords as jo, TYPING_KINDS as jr, ENROLL_PROOF as js, didWebFile as jt, knockIdentity as k, validReactionNumber as ka, isAppKey as kc, DHT_TEXT_CAPABILITY as ki, currentRelays as kl, fedimintRequestPayload as kn, parseCallSignal as ko, transferEnded as kr, ENROLL_GRANT as ks, didSignedMessages as kt, APP_STORE_LIMITS as l, fileMessageText as la, seenEntry as lc, HoldKeys as li, webCryptoSigner as ll, SPARK_NETWORKS as ln, AWAITING_PEER_MS as lo, meshHubs as lr, handoffStreamKey as ls, ATPROTO_PROOF_COLLECTION as lt, GROUP_TYPING_FRAME as m, EDIT_RATE_WINDOW_MS as ma, appDigest as mc, DOMAIN_FILE_MAX_BYTES as mi, turnPutSummary as ml, PUBKY_PROOF_MAX_BYTES as mn, presenceSeenAt as mo, doorHubs as mr, readHandoffDone as ms, checkAtprotoProofRecord as mt, readX401SdJwtVc as n, dhtFileId as na, linkRecords as nc, BUTTONS_CAPABILITY as ni, deviceEchoFrame as nl, WALLET_NETWORKS as nn, commitHash as no, SIGNAL_FRESH_MS as nr, handoffEphemeral as ns, sshSignCommand as nt, utf8Decode as nu, appUpdateDecision as o, PLAYABLE_AUDIO as oa, readKnockSlot as oc, HOLD_CAPABILITY as oi, devicePingFrame as ol, formatPaymentAmount as on, verifyCommitSignature as oo, readGroupSignal as or, handoffPakeFrame as os, decodeAnyBitcoinAddress as ot, signAppStore as p, EDIT_BUFFER_MS as pa, APP_PERMISSIONS as pc, readManifest as pi, classifyTurnRead as pl, isBitcoinAddress as pn, WATCH_PEER_MS as po, beaconRecords as pr, readHandoffCancel as ps, atprotoProofRkey as pt, parseCommunityEdit as q, arrivalKey as qa, createChatInvite as qc, validExternalKey as qi, MAX_AVATAR_LENGTH as ql, fetchesByItself as qn, handoffAttemptAllowed as qo, parseWakeFrame as qr, settleRequest as qs, signDidDhtPacket as qt, sameX401HolderJwk as r, formatFileSize as ra, makeStampPaced as rc, EDIT_CAPABILITY as ri, deviceEchoNonce as rl, arkAddressPrefix as rn, parseGroupCommit as ro, SIGNAL_HOLD_MS as rr, handoffHelloFrame as rs, verifySshSignature as rt, utf8Encode as ru, checkAppBeforeRun as s, VOICE_LIMITS as sa, readLinkRecord as sc, HOLD_DATED_BACK_MS as si, newDeviceSetSecret as sl, validatePaymentTarget as sn, edgeParams as so, MESH_HUBS as sr, handoffReleaseFrame as ss, ATPROTO_DECLARED_SCOPE as st, newX401HolderKey as t, DHT_FILE_CAPABILITY as ta, knockSlotRecords as tc, APPS_CAPABILITY as ti, HANDOFF_CAPABILITY as tl, USDT_PUBLIC_RPC as tn, MEMBER_KEY as to, GROUP_SIGNAL_FRAME as tr, handoffDigest as ts, sameSshKey as tt, toZ32 as tu, checkAppStoreIndex as u, parseVoiceMeta as ua, APP_BUNDLE_LIMITS as uc, HoldRefusedError as ui, TURN_PUT_WINDOW_MS as ul, SPARK_PROVIDER as un, DHT_POLL_INTERVALS as uo, pickMeshHubs as ur, handoffVersions as us, ATPROTO_PROOF_SCOPE as ut, sealGroupTyping as v, forwardedAgain as va, isAppUrl as vc, domainWellKnownFile as vi, nextTurnPosition as vl, normalizePubkyKey as vn, webLocalFetch as vo, mergeBeacon as vr, readHandoffTurnFrame as vs, shortAtprotoDid as vt, encodeCommunityLink as w, nextReactionNumber as wa, APP_STATEMENT_LIMITS as wc, recordsFromWellKnown as wi, turnName as wl, requestLnurlInvoice as wn, answersOffer as wo, readBeaconHead as wr, setAckFrame as ws, DidError as wt, GROUP_READ_NOTE_COMMUNITY as x, GROUP_REACTION_FRAME as xa, readAppBundleAsync as xc, nip05RootKey as xi, signTurnRelease as xl, pubkyProofPath as xn, encodeControl as xo, pickHubs as xr, SET_ACK as xs, DID_DOCUMENT_MAX_BYTES as xt, COMMUNITY_LIMITS as y, readForwarded as ya, pacer as yc, encodeDnsQuery as yi, readTurnPacket as yl, pubkyProofCapability as yn, LIMITS as yo, mergeLobby as yr, readHandoffVerified as ys, AtprotoProofError as yt, GROUP_REACTED_FRAME as z, STATUS_CARD_LIMITS as za, readCanonicalJson as zc, identityRevocationValue as zi, newerPacket as zl, pairedMessageFrame as zn, HANDOFF_HELLO as zo, nextPinNumber as zr, readEnrollGrant as zs, signingKeys as zt };
33476
+ export { parseSshPublicKey as $, statusCardText as $a, readDeviceInvite as $c, irohRelayUrl as $i, createIdentity as $l, readGroupWantNo as $n, HANDOFF_VERIFIED as $o, isServeId as $r, newInbox as $s, SEPOLIA_TEST_USDT_FAUCET as $t, knockRecords as A, reactionEmoji as Aa, sha256Paced as Ac, CapsExchange as Ai, turnInstance as Al, findEndpoint as An, RTC_CONFIG as Ao, transferStalled as Ar, SET_UPDATE as As, didWebDocumentUrl as At, GROUP_READ_NOTE as B, ITEM_STATES as Ba, readAppRevocations as Bc, emptyIdentityLedger as Bi, currentRelays as Bl, engineError as Bn, HTTP_SERVICE_PROTO as Bo, pinIsNewer as Br, enrollCancelFrame as Bs, staticDidDocument as Bt, decodeCommunityLink as C, readForwarded as Ca, appViewOf as Cc, nip05RootKey as Ci, TURN_LAST_SEQUENCE as Cl, pubkyHomeserverOf as Cn, formatLocalTarget as Co, readBeacon as Cr, readHandoffHave as Cs, DID_JWS_MAX_LENGTH as Ct, encodeGroupEntryLink as D, ReactionWindow as Da, pacer as Dc, recordsName as Di, readTurnPacket as Dl, ENDPOINT as Dn, decodeControl as Do, ChatFiles as Dr, readHandoffVerified as Ds, didGhostlyServiceEntry as Dt, decodeGroupEntryLink as E, REACTION_LIMITS as Ea, isAppUrl as Ec, recordsFromWellKnown as Ei, nextTurnPosition as El, decodeBolt11 as En, LIMITS as Eo, shouldBeHub as Er, readHandoffTurnFrame as Es, checkDidSignature as Et, groupWakeFrame as F, pairedReplyAuthor as Fa, checkAppRevokeStatement as Fc, IDENTITY_MAX_VALIDITY as Fi, DEFAULT_RELAYS as Fl, INVITE_TAKEN as Fn, contactRtcConfig as Fo, typingActivity as Fr, verifySetUpdate as Fs, normalizeDid as Ft, GROUP_EDIT_TEXT_BYTES as G, STATUS_CARD_LIMITS as Ga, canonicalJson as Gc, revokesIdentity as Gi, isDiscoveryBudgetError as Gl, GROUP_WANT_FRAME as Gn, HANDOFF_DONE as Go, deviceWakeRequest as Gr, enrollHelloFrame as Gs, encodeDidDhtPacket as Gt, frameBytes as H, PR_STATES as Ha, signAppRevocation as Hc, identityStatement as Hi, setLinkTraceSink as Hl, parseEngineError as Hn, serviceIdFromName as Ho, readPin as Hr, enrollDigits as Hs, didDhtDocument as Ht, groupWakes as I, readReply as Ia, isAppHash as Ic, IDENTITY_REVOCATION_LABEL as Ii, HEDGE_MS as Il, LIVENESS_PING_MS as In, extractParamsFromSdp as Io, GROUP_PIN_FRAME as Ir, ENROLL_DONE as Is, parseDid as It, mentionsMember as J, buttonLabelClash as Ja, createContactLink as Jc, emptyProofLedger as Ji, RELAY_PAYLOAD_MAX_BYTES as Jl, groupFileFallback as Jn, HANDOFF_OFFER as Jo, relayRequest as Jr, readEnrollHello as Js, ETHEREUM_USDT as Jt, carryMentions as K, TASK_STATUSES as Ka, canonicalJsonBytes as Kc, lastSharedWithMe as Ki, withRequestOptions as Kl, GROUP_WANT_NO_FRAME as Kn, HANDOFF_HAVE as Ko, newWakeToken as Kr, enrollProofFrame as Ks, resolveDidDht as Kt, parseGroupWakeFrame as L, replySnippet as La, isAppKey as Lc, IdentityCheckUnavailable as Li, RelayTransport as Ll, PAIRED_FRAME_TOO_LARGE as Ln, parseCallSignal as Lo, PIN_LIMITS as Lr, ENROLL_GRANT as Ls, parseDidDocument as Lt, readKnocks as M, readReaction as Ma, APP_STATEMENT_LIMITS as Mc, capsDescriptors as Mi, turnName as Ml, parseCashuRequestPayload as Mn, buildSdpFromSignal as Mo, TYPING_REFRESH_MS as Mr, setAckFrame as Ms, didWebFileNames as Mt, GROUP_WAKE_FRAME as N, validReactionNumber as Na, appFingerprint as Nc, dialDescriptors as Ni, turnStatedVerifier as Nl, parseFedimintRequestPayload as Nn, callRtcConfig as No, TypingSender as Nr, setUpdateFrame as Ns, didWebFileUrl as Nt, entryParams as O, nextReactionNumber as Oa, readAppBundle as Oc, txtValue as Oi, signTurnPacket as Ol, cashuRequestPayload as On, encodeControl as Oo, FILE_LIMITS as Or, sealHandoffPiece as Os, didJwsAlg as Ot, GroupWakeLimiter as P, wireReaction as Pa, appRef as Pc, IDENTITY_MAX_EVIDENCE as Pi, turnVerifierMark as Pl, GhostLink as Pn, callSignalHeardAt as Po, sanitizeTypingStatus as Pr, signTombstone as Ps, didWebHost as Pt, SshSigError as Q, sameButtonText as Qa, deviceInviteJoinerParams as Qc, irohDescriptor as Qi, parseRelayPayload as Ql, readGroupWant as Qn, HANDOFF_TIMINGS as Qo, APP_RANGE_LIMITS as Qr, inboxRecord as Qs, SEPOLIA_TEST_USDT as Qt, GROUP_LIMITS as R, BUTTON_ID as Ra, isAppRef as Rc, IdentityExchange as Ri, RelaysFailedError as Rl, pairedMessageFits as Rn, signalHasVideo as Ro, mayPin as Rr, ENROLL_HELLO as Rs, parseDidSignaturePaste as Rt, communityHasFrame as S, forwardedAgain as Sa, appDigest as Sc, isPublicAddress as Si, turnPutSummary as Sl, homeserverWebEndpoint as Sn, GhostlyHttpError as So, rankHubs as Sr, readHandoffDone as Ss, DID_FILE_MAX_BYTES as St, KNOCK_TTL_MS as T, GROUP_REACTION_FRAME as Ta, checkAppManifest as Tc, recordsFromTxt as Ti, firstDeviceSetSecret as Tl, resolveLightningDestination as Tn, webLocalFetch as To, readLobby as Tr, readHandoffPake as Ts, checkDidJws as Tt, COMMUNITY_EDIT_FRAME as U, ROUTINE_STATES as Ua, parseImageMeta as Uc, newIdentityBinding as Ui, traceLink as Ul, GROUP_FILE_LIMITS as Un, HANDOFF_ACK as Uo, WAKE_CALL_INTERVAL_MS as Ur, enrollDoneFrame as Us, didDhtFromPublicKey as Ut, GroupSession as V, PR_CHECKS as Va, signAppObject as Vc, identityRevocationValue as Vi, normalizeRelayUrl as Vl, engineText as Vn, LEGACY_SERVICES as Vo, pinNumberHolds as Vr, enrollCancelReason as Vs, strictBase64Url as Vt, GROUP_EDIT_FRAME as W, RUN_RESULTS as Wa, readImageMeta as Wc, receivedIdentityStatus as Wi, budgetRetryMs as Wl, GROUP_HAVE_FRAME as Wn, HANDOFF_CANCEL as Wo, WakeLimiter as Wr, enrollGrantFrame as Ws, encodeDidDhtDeactivated as Wt, SSHSIG_MAX_ARMOR as X, cardUrl as Xa, readContactLink as Xc, TRANSPORTS as Xi, newerPacket as Xl, readGroupFileMeta as Xn, HANDOFF_PIECE_BYTES as Xo, checkPushEndpoint as Xr, clearMissed as Xs, ONCHAIN_PROVIDER as Xt, groupName as Y, cardLine as Ya, encodeContactLink as Yc, validExternalKey as Yi, createRelayPayload as Yl, isGroupMessageId as Yn, HANDOFF_PAKE as Yo, wakeRequest as Yr, verifyEnrollProof as Ys, EVM_TEST_CHAINS as Yt, SSHSIG_NAMESPACE as Z, checkStatusCard as Za, createDeviceInvite as Zc, automaticTransport as Zi, openRelayPayload as Zl, readGroupHave as Zn, HANDOFF_REQUEST as Zo, vapidKeysMatch as Zr, endedRequests as Zs, PaymentPreflightError as Zt, openGroupTyping as _, MAX_REMOVAL_NUMBER as _a, seenEntry as _c, decodeDnsResponse as _i, webCryptoSigner as _l, newPubkyProofFolder as _n, DHT_POLL_INTERVALS as _o, lobbyRecords as _r, handoffStreamKey as _s, parseAtprotoDidDocument as _t, appStoreDecision as a, formatFileSize as aa, REQUEST_LIFETIME_MS as ac, EDIT_CAPABILITY as ai, inviteOwnership as al, assertWholeSats as an, GROUP_ADMIN_OFF_ERROR as ao, groupSignalFrame as ar, handoffCancelFrame as as, BitcoinAddressError as at, sanitizeAvatar as au, CommunitySession as b, dhtEditId as ba, APP_ICON_PATH as bc, domainWellKnownFile as bi, TURN_SETTLE_MS as bl, pubkyProofFile as bn, WATCH_PEER_MS as bo, newerHead as br, readHandoffAck as bs, verifyAtprotoRecordProof as bt, planAppUpdate as c, PLAYABLE_AUDIO as ca, knockSlotOf as cc, HOLD_CAPABILITY as ci, ENROLL_CAPABILITY as cl, walletNetworkOf as cn, MEMBER_KEY as co, mayBeHub as cr, handoffDataFrame as cs, ATPROTO_FULL_SCOPE as ct, fromBase64Url as cu, readAppStore as d, fileMessageText as da, makeStampPaced as dc, HoldKeys as di, deviceEchoNonce as dl, sparkAddressKind as dn, rosterAdmin as do, COMMUNITY_TOPOLOGY as dr, handoffHelloFrame as ds, atprotoDidMethod as dt, toBase64Url as du, DHT_FILE_TOO_LARGE as ea, planKnocks as ec, APP_DATA_MAX_BYTES as ei, OwnInviteError as el, TEST_USDT_FAUCET_AMOUNT as en, arrivalKey as eo, CarriedTransport as er, filePartName as es, parseSshSignature as et, identityFromSeed as eu, readAppStoreSteps as f, parseVoiceMeta as fa, mergeContactKnocks as fc, HoldRefusedError as fi, deviceKeyZ32 as fl, sparkInvoiceDetails as fn, rosterHas as fo, beaconKeys as fr, handoffManifestFrames as fs, atprotoProofRecord as ft, toZ32 as fu, groupTypingEpoch as g, EDIT_RATE_WINDOW_MS as ga, requestRecords as gc, DOMAIN_FILE_MAX_BYTES as gi, seedSigner as gl, isPubkyProofFolder as gn, AWAITING_PEER_MS as go, lobbyKeys as gr, handoffRetryAfter as gs, normalizeAtprotoHandle as gt, GroupTypingBoard as h, EDIT_BUFFER_MS as ha, readLinkRecord as hc, readManifest as hi, newDeviceSetSecret as hl, isPubkyKey as hn, DirectPathWatch as ho, freshHubs as hr, handoffReleaseFrame as hs, isAtprotoDid as ht, appRevocationFor as i, dhtFileId as ia, ContactRequestError as ic, BUTTONS_CAPABILITY as ii, inviteLink as il, assertTokenUnits as in, shownTime as io, SIGNAL_REPLY_MS as ir, handoffBusyFrame as is, verifyBitcoinMessage as it, MAX_AVATAR_LENGTH as iu, mergeKnocks as j, reactionIsNewer as ja, APP_PREFIXES as jc, DHT_TEXT_CAPABILITY as ji, turnKeys as jl, isFederationId as jn, answersOffer as jo, TYPING_KINDS as jr, readSetUpdate as js, didWebFile as jt, knockIdentity as k, queueReaction as ka, readAppBundleAsync as kc, wellKnownUrl as ki, signTurnRelease as kl, fedimintRequestPayload as kn, CALL_SIGNAL_MAX_AGE_MS as ko, transferEnded as kr, SET_ACK as ks, didSignedMessages as kt, APP_STORE_LIMITS as l, VOICE_LIMITS as la, knockSlotRecords as lc, HOLD_DATED_BACK_MS as li, HANDOFF_CAPABILITY as ll, SPARK_NETWORKS as ln, commitHash as lo, meshHubs as lr, handoffDigest as ls, ATPROTO_PROOF_COLLECTION as lt, isZ32Key as lu, GROUP_TYPING_FRAME as m, parseVideoMeta as ma, readKnockSlot as mc, newMailbox as mi, devicePingFrame as ml, PUBKY_PROOF_MAX_BYTES as mn, edgeParams as mo, doorHubs as mr, handoffPakeFrame as ms, checkAtprotoProofRecord as mt, utf8Encode as mu, readX401SdJwtVc as n, peekDhtMailbox as na, takeRequest as nc, isAppVersion as ni, decodeInviteCode as nl, WALLET_NETWORKS as nn, heardTime as no, SIGNAL_FRESH_MS as nr, handoffAttemptFailed as ns, sshSignCommand as nt, publicKeyFromZ32 as nu, appUpdateDecision as o, sanitizeFileName as oa, contactDay as oc, STATUS_CARD_CAPABILITY as oi, ownInviteRefusal as ol, formatPaymentAmount as on, GROUP_MEMBER_CAP as oo, readGroupSignal as or, handoffContext as os, decodeAnyBitcoinAddress as ot, sanitizeDisplayText as ou, signAppStore as p, voicePeaksOf as pa, openRequest as pc, isHoldUrl as pi, deviceLinkPairing as pl, isBitcoinAddress as pn, verifyCommitSignature as po, beaconRecords as pr, handoffOfferFrame as ps, atprotoProofRkey as pt, utf8Decode as pu, parseCommunityEdit as q, appCardId as qa, readCanonicalJson as qc, PeerProofs as qi, PacketTooLargeError as ql, fetchesByItself as qn, HANDOFF_HELLO as qo, parseWakeFrame as qr, readEnrollGrant as qs, signDidDhtPacket as qt, sameX401HolderJwk as r, DHT_FILE_CAPABILITY as ra, turnOff as rc, APPS_CAPABILITY as ri, encodeInviteCode as rl, arkAddressPrefix as rn, receivedTimestamp as ro, SIGNAL_HOLD_MS as rr, handoffAttemptSucceeded as rs, verifySshSignature as rt, verify as ru, checkAppBeforeRun as s, sanitizeMime as sa, knockSlotIdentity as sc, UPGRADE_CAPABILITY as si, DEVICES_CAPABILITY as sl, validatePaymentTarget as sn, MAX_GROUP_CHAIN as so, MESH_HUBS as sr, handoffContextProof as ss, ATPROTO_DECLARED_SCOPE as st, bytesEqual as su, newX401HolderKey as t, DHT_MESSAGE_TTL as ta, settleRequest as tc, chatAppId as ti, createChatInvite as tl, USDT_PUBLIC_RPC as tn, claimedTime as to, GROUP_SIGNAL_FRAME as tr, handoffAttemptAllowed as ts, sameSshKey as tt, identityFromSeedB64 as tu, checkAppStoreIndex as u, baseMime as ua, linkRecords as uc, HOLD_LIMITS as ui, deviceEchoFrame as ul, SPARK_PROVIDER as un, parseGroupCommit as uo, pickMeshHubs as ur, handoffEphemeral as us, ATPROTO_PROOF_SCOPE as ut, randomBytes as uu, sealGroupTyping as v, REMOVED_TEXT as va, APP_BUNDLE_LIMITS as vc, dnsProofName as vi, TURN_PUT_WINDOW_MS as vl, normalizePubkyKey as vn, EXPECT_PEER_MS as vo, mergeBeacon as vr, handoffVersions as vs, shortAtprotoDid as vt, encodeCommunityLink as w, COMMUNITY_REACTION_FRAME as wa, assembleAppBundle as wc, normalizeDomain as wi, TURN_MAX as wl, requestLnurlInvoice as wn, parseLocalTarget as wo, readBeaconHead as wr, readHandoffHello as ws, DidError as wt, GROUP_READ_NOTE_COMMUNITY as x, parseLinkPreview as xa, APP_PERMISSIONS as xc, encodeDnsQuery as xi, classifyTurnRead as xl, pubkyProofPath as xn, presenceSeenAt as xo, pickHubs as xr, readHandoffCancel as xs, DID_DOCUMENT_MAX_BYTES as xt, COMMUNITY_LIMITS as y, RateWindow as ya, APP_BUNDLE_MAGIC as yc, domainTxtRecord as yi, TURN_RAISE_READ_TIMEOUT_MS as yl, pubkyProofCapability as yn, RELAY_POLL_INTERVALS as yo, mergeLobby as yr, newHandoffId as ys, AtprotoProofError as yt, GROUP_REACTED_FRAME as z, CRON_LINE as za, readAppRevocation as zc, boundVerifiedIdentity as zi, SLOW_MS as zl, pairedMessageFrame as zn, emptyLinkRecords as zo, nextPinNumber as zr, ENROLL_PROOF as zs, signingKeys as zt };
32695
33477
 
32696
- //# sourceMappingURL=src-D1X4uVPW.js.map
33478
+ //# sourceMappingURL=src-CwMTZ5Hj.js.map