@ghostlytools/cli 1.7.4 → 1.8.1

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 (99) hide show
  1. package/README.md +16 -10
  2. package/SKILL.md +1 -1
  3. package/dist/assets/{api-D3i2hwy0.js → api-BpQC8dAw.js} +121 -40
  4. package/dist/assets/api-BpQC8dAw.js.map +1 -0
  5. package/dist/assets/{api-Chhvpwok.js → api-CttDF-S5.js} +2 -2
  6. package/dist/assets/{apiKit-BtsHrnoo.js → apiKit-CSMeHKgo.js} +17 -5
  7. package/dist/assets/{apiKit-BtsHrnoo.js.map → apiKit-CSMeHKgo.js.map} +1 -1
  8. package/dist/assets/{apps-BHl97rHs.js → apps-DqTyZ40T.js} +8 -7
  9. package/dist/assets/apps-DqTyZ40T.js.map +1 -0
  10. package/dist/assets/{apps-BFJTqvAt.js → apps-DzFMdVt6.js} +1 -1
  11. package/dist/assets/{arkade-BFE8KkEE.js → arkade-Cu3TbPxC.js} +2 -2
  12. package/dist/assets/{arkade-BFE8KkEE.js.map → arkade-Cu3TbPxC.js.map} +1 -1
  13. package/dist/assets/{backup-Bbsr6nDi.js → backup-CLZOORFC.js} +1 -1
  14. package/dist/assets/{backup-CxACdtQX.js → backup-CyTZhu28.js} +6 -6
  15. package/dist/assets/{backup-CxACdtQX.js.map → backup-CyTZhu28.js.map} +1 -1
  16. package/dist/assets/{buttons-CieBtXEO.js → buttons-Bd9fR31r.js} +177 -23
  17. package/dist/assets/buttons-Bd9fR31r.js.map +1 -0
  18. package/dist/assets/buttons-c4CJnL6i.js +2 -0
  19. package/dist/assets/{daemonProof-QmtwDj-N.js → daemonProof-DtrL5lE5.js} +2 -2
  20. package/dist/assets/{daemonProof-QmtwDj-N.js.map → daemonProof-DtrL5lE5.js.map} +1 -1
  21. package/dist/assets/{envelope-DYiGwzq_.js → envelope-CGfUsR1m.js} +2 -2
  22. package/dist/assets/{envelope-DYiGwzq_.js.map → envelope-CGfUsR1m.js.map} +1 -1
  23. package/dist/assets/{errors-QUGP-jIF.js → errors-R4S2SAEM.js} +7 -2
  24. package/dist/assets/errors-R4S2SAEM.js.map +1 -0
  25. package/dist/assets/fixedHosts-BiukTsd9.js +24 -0
  26. package/dist/assets/fixedHosts-BiukTsd9.js.map +1 -0
  27. package/dist/assets/{ghostly_iroh_web-CO0onry8.js → ghostly_iroh_web-BzAXJUYH.js} +10 -10
  28. package/dist/assets/{ghostly_iroh_web-CO0onry8.js.map → ghostly_iroh_web-BzAXJUYH.js.map} +1 -1
  29. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  30. package/dist/assets/{groupFiles-CBJIEvCE.js → groupFiles-CeF9nPv9.js} +759 -29
  31. package/dist/assets/groupFiles-CeF9nPv9.js.map +1 -0
  32. package/dist/assets/{host-Va-r_KJz.js → host-CKAehWP6.js} +65 -29
  33. package/dist/assets/host-CKAehWP6.js.map +1 -0
  34. package/dist/assets/hyperdhtRelay-1wzya_0L.js +25 -0
  35. package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +1 -0
  36. package/dist/assets/{hyperdhtRelay-B2uK9tJv.js → hyperdhtRelay-B8Pdykhg.js} +15 -3
  37. package/dist/assets/hyperdhtRelay-B8Pdykhg.js.map +1 -0
  38. package/dist/assets/{irohWeb-DxeEgQ-W.js → irohWeb-D6tAPHZa.js} +11 -7
  39. package/dist/assets/{irohWeb-DxeEgQ-W.js.map → irohWeb-D6tAPHZa.js.map} +1 -1
  40. package/dist/assets/{main-BX4oPWCJ.js → main-BDY-pfpz.js} +121 -37
  41. package/dist/assets/main-BDY-pfpz.js.map +1 -0
  42. package/dist/assets/{mainline-IfWQOB-J.js → mainline-3ueXpFQL.js} +2 -2
  43. package/dist/assets/{mainline-IfWQOB-J.js.map → mainline-3ueXpFQL.js.map} +1 -1
  44. package/dist/assets/mints-BaOmx517.js +2 -0
  45. package/dist/assets/{mints-BrlY773j.js → mints-j5XAOk4f.js} +15 -3
  46. package/dist/assets/mints-j5XAOk4f.js.map +1 -0
  47. package/dist/assets/{networkReason-N2vAaoth.js → networkReason-DhJYOomu.js} +2 -2
  48. package/dist/assets/{networkReason-N2vAaoth.js.map → networkReason-DhJYOomu.js.map} +1 -1
  49. package/dist/assets/{nwc-CzyCtNK2.js → nwc-B1Quqda-.js} +3 -3
  50. package/dist/assets/{nwc-CzyCtNK2.js.map → nwc-B1Quqda-.js.map} +1 -1
  51. package/dist/assets/{nwcProvider-DjWmEn3j.js → nwcProvider-DUB6xO-b.js} +2 -2
  52. package/dist/assets/{nwcProvider-DjWmEn3j.js.map → nwcProvider-DUB6xO-b.js.map} +1 -1
  53. package/dist/assets/ownDid-BfqHJdA6.js +281 -0
  54. package/dist/assets/ownDid-BfqHJdA6.js.map +1 -0
  55. package/dist/assets/{profiles-DcCeOi7J.js → profiles-MFtCmJwK.js} +3 -3
  56. package/dist/assets/{profiles-DcCeOi7J.js.map → profiles-MFtCmJwK.js.map} +1 -1
  57. package/dist/assets/{registry-BmS02J5h.js → registry-CZTmtSws.js} +1 -1
  58. package/dist/assets/{registry-CeW8XEQc.js → registry-DwlTNQjr.js} +5 -246
  59. package/dist/assets/registry-DwlTNQjr.js.map +1 -0
  60. package/dist/assets/{resolve-BvHkAhDH.js → resolve-BVwhiYjj.js} +3 -268
  61. package/dist/assets/resolve-BVwhiYjj.js.map +1 -0
  62. package/dist/assets/{restoredRows-mTTp3XNs.js → restoredRows-BCRCjhdF.js} +26 -2
  63. package/dist/assets/{restoredRows-mTTp3XNs.js.map → restoredRows-BCRCjhdF.js.map} +1 -1
  64. package/dist/assets/{server-BUcJo4vz.js → server-Br3XPwFG.js} +1001 -243
  65. package/dist/assets/server-Br3XPwFG.js.map +1 -0
  66. package/dist/assets/{src-BB5-5P3s.js → src-C4sOH4zH.js} +1109 -181
  67. package/dist/assets/src-C4sOH4zH.js.map +1 -0
  68. package/dist/assets/sshForges-CQQomStK.js +253 -0
  69. package/dist/assets/sshForges-CQQomStK.js.map +1 -0
  70. package/dist/assets/{translate-2WyaRVCr.js → translate-C2aNyUkR.js} +20 -10
  71. package/dist/assets/translate-C2aNyUkR.js.map +1 -0
  72. package/dist/assets/{usdt-BLazHiaP.js → usdt-CMwatDnQ.js} +3 -3
  73. package/dist/assets/{usdt-BLazHiaP.js.map → usdt-CMwatDnQ.js.map} +1 -1
  74. package/dist/assets/waitNotice-Ck3el3_Z.js +45 -0
  75. package/dist/assets/waitNotice-Ck3el3_Z.js.map +1 -0
  76. package/dist/assets/{words-BaumxjXe.js → words-CqN2KG1r.js} +6 -3
  77. package/dist/assets/words-CqN2KG1r.js.map +1 -0
  78. package/dist/ghostly.mjs +1 -1
  79. package/examples/claude-code-agent.sh +1 -1
  80. package/package.json +1 -1
  81. package/dist/assets/api-D3i2hwy0.js.map +0 -1
  82. package/dist/assets/apps-BHl97rHs.js.map +0 -1
  83. package/dist/assets/buttons-CieBtXEO.js.map +0 -1
  84. package/dist/assets/buttons-YtAj3R_E.js +0 -2
  85. package/dist/assets/errors-QUGP-jIF.js.map +0 -1
  86. package/dist/assets/groupFiles-CBJIEvCE.js.map +0 -1
  87. package/dist/assets/host-Va-r_KJz.js.map +0 -1
  88. package/dist/assets/hyperdhtRelay-B2uK9tJv.js.map +0 -1
  89. package/dist/assets/hyperdhtRelay-BT_wRxab.js +0 -21
  90. package/dist/assets/hyperdhtRelay-BT_wRxab.js.map +0 -1
  91. package/dist/assets/main-BX4oPWCJ.js.map +0 -1
  92. package/dist/assets/mints-BrlY773j.js.map +0 -1
  93. package/dist/assets/mints-CqTdA4Gk.js +0 -2
  94. package/dist/assets/registry-CeW8XEQc.js.map +0 -1
  95. package/dist/assets/resolve-BvHkAhDH.js.map +0 -1
  96. package/dist/assets/server-BUcJo4vz.js.map +0 -1
  97. package/dist/assets/src-BB5-5P3s.js.map +0 -1
  98. package/dist/assets/translate-2WyaRVCr.js.map +0 -1
  99. package/dist/assets/words-BaumxjXe.js.map +0 -1
@@ -1,14 +1,605 @@
1
- import { $n as readGroupHave, Cu as randomBytes, Dn as decodeBolt11, En as resolveLightningDestination, Ga as replySnippet, Gi as identityStatement, Gn as GROUP_FILE_LIMITS, Hn as engineError, Ji as revokesIdentity, Jn as GROUP_WANT_NO_FRAME, Ki as newIdentityBinding, Kn as GROUP_HAVE_FRAME, Mr as transferEnded, Ta as RateWindow, Tn as requestLnurlInvoice, Ui as emptyIdentityLedger, Un as engineText, Vi as IdentityExchange, Wi as identityRevocationValue, Xn as groupFileFallback, Yn as fetchesByItself, Zn as isGroupMessageId, er as readGroupWant, ga as fileMessageText, jr as FileUplink, kr as ChatFiles, ln as walletNetworkOf, qi as receivedIdentityStatus, rn as WALLET_NETWORKS, tr as readGroupWantNo, wu as toBase64Url, xu as fromBase64Url, zi as IDENTITY_REVOCATION_LABEL } from "./src-BB5-5P3s.js";
1
+ import { $n as readGroupHave, Bi as IDENTITY_REVOCATION_LABEL, Dn as decodeBolt11, Ea as RateWindow, En as resolveLightningDestination, Gi as identityRevocationValue, Gn as GROUP_FILE_LIMITS, Hi as IdentityExchange, Hn as engineError, Ji as receivedIdentityStatus, Jn as GROUP_WANT_NO_FRAME, Ka as replySnippet, Ki as identityStatement, Kn as GROUP_HAVE_FRAME, Mu as toBase64Url, Nr as transferEnded, Tn as requestLnurlInvoice, Un as engineText, Vi as IdentityCheckUnavailable, Wi as emptyIdentityLedger, Xn as groupFileFallback, Yi as revokesIdentity, Yn as fetchesByItself, Zn as isGroupMessageId, _a as fileMessageText, cl as exifOrientation, er as readGroupWant, jr as FileUplink, ju as randomBytes, kr as ChatFiles, ku as fromBase64Url, ln as walletNetworkOf, qi as newIdentityBinding, rn as WALLET_NETWORKS, tr as readGroupWantNo } from "./src-C4sOH4zH.js";
2
2
  import { a as describeProvider, c as offeredIn, d as sourceProblem, n as PROVIDER_PLATFORMS, o as isNothingSpentError, s as networkMode, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
3
3
  import { g as wrap, h as transact, i as STORES, m as store, s as databaseName, u as fileStore } from "./idb-BkOJES5_.js";
4
- import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-N2vAaoth.js";
5
- import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-BrlY773j.js";
6
- import { v as boundedIdentityFetch, y as verifyIdentity } from "./resolve-BvHkAhDH.js";
7
- import { i as fromBase64Url$1 } from "./envelope-DYiGwzq_.js";
4
+ import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-DhJYOomu.js";
5
+ import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
6
+ import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-BfqHJdA6.js";
7
+ import { i as fromBase64Url$1 } from "./envelope-CGfUsR1m.js";
8
8
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DNgrRL0R.js";
9
9
  import { sha256 } from "@noble/hashes/sha2.js";
10
10
  import { validateMnemonic } from "@scure/bip39";
11
11
  import { wordlist } from "@scure/bip39/wordlists/english.js";
12
+ //#region ../core/src/pictureMetadata.ts
13
+ /**
14
+ * What a picture leaves with. A photo's file says more than its pixels: its Exif and XMP hold where it was taken, the
15
+ * device, the time, often a thumbnail of the uncropped original. The sender removes them before the file is stored and
16
+ * its digest computed, so what the contact (or anyone in a community) receives is the picture alone: JPEG, PNG, WebP
17
+ * and HEIF (HEIC, AVIF), without decoding or re-encoding a pixel.
18
+ *
19
+ * Fail-closed: a file that is one of these pictures, by its bytes or by its type, and whose metadata cannot be removed
20
+ * (truncated, malformed, a part this does not know) is refused with `NO_PICTURE_METADATA`, never sent as it was. Any
21
+ * other file goes as it is.
22
+ */
23
+ var PICTURE_METADATA_LIMITS = {
24
+ /** The largest picture read whole to remove its metadata: past this it is refused. */
25
+ maxBytes: 268435456,
26
+ /** Bytes read first to tell a picture from another file. */
27
+ headBytes: 64
28
+ };
29
+ /** Why a picture is refused: its metadata could not be removed, so it does not go at all. */
30
+ var NO_PICTURE_METADATA = "This picture cannot be sent: Ghostly could not remove the details saved in it, like where it was taken";
31
+ /** The types of the pictures stripped here: a file of one of them whose bytes are not that picture is refused. */
32
+ var STRIPPED_TYPES = /* @__PURE__ */ new Set([
33
+ "image/jpeg",
34
+ "image/jpg",
35
+ "image/pjpeg",
36
+ "image/png",
37
+ "image/apng",
38
+ "image/webp",
39
+ "image/heic",
40
+ "image/heif",
41
+ "image/heic-sequence",
42
+ "image/heif-sequence",
43
+ "image/avif",
44
+ "image/gif",
45
+ "image/tiff",
46
+ "image/tiff-fx"
47
+ ]);
48
+ /** HEIF brands (HEIC, AVIF, the generic `mif1`): an MP4 video's `ftyp` names none of them. */
49
+ var HEIF_BRANDS = /* @__PURE__ */ new Set([
50
+ "heic",
51
+ "heix",
52
+ "heim",
53
+ "heis",
54
+ "hevc",
55
+ "hevx",
56
+ "mif1",
57
+ "mif2",
58
+ "msf1",
59
+ "avif",
60
+ "avis"
61
+ ]);
62
+ var u16be = (b, at) => b[at] << 8 | b[at + 1];
63
+ var u32be = (b, at) => (b[at] << 24 >>> 0) + (b[at + 1] << 16) + (b[at + 2] << 8) + b[at + 3];
64
+ var u32le = (b, at) => (b[at] | b[at + 1] << 8 | b[at + 2] << 16 | b[at + 3] << 24) >>> 0;
65
+ var text = (b, at, length) => String.fromCharCode(...b.subarray(at, at + length));
66
+ var starts = (b, at, prefix) => at + prefix.length <= b.length && text(b, at, prefix.length) === prefix;
67
+ /** A picture this strips, by its first bytes. */
68
+ function kindOf(b) {
69
+ if (b.length >= 3 && b[0] === 255 && b[1] === 216 && b[2] === 255) return "jpeg";
70
+ if (b.length >= 8 && b[0] === 137 && starts(b, 1, "PNG\r\n\n")) return "png";
71
+ if (b.length >= 12 && starts(b, 0, "RIFF") && starts(b, 8, "WEBP")) return "webp";
72
+ if (starts(b, 0, "GIF87a") || starts(b, 0, "GIF89a")) return "gif";
73
+ if (starts(b, 0, "II*\0") || starts(b, 0, "MM\0*") || starts(b, 0, "II+\0") || starts(b, 0, "MM\0+")) return "tiff";
74
+ if (b.length >= 16 && starts(b, 4, "ftyp")) {
75
+ const end = Math.min(b.length, u32be(b, 0));
76
+ for (let at = 8; at + 4 <= end; at += 4) if (at !== 12 && HEIF_BRANDS.has(text(b, at, 4))) return "heif";
77
+ }
78
+ }
79
+ /** Refuses the picture where its bytes are not what this expects. */
80
+ function check(ok) {
81
+ if (!ok) throw new Error(NO_PICTURE_METADATA);
82
+ }
83
+ /** SOFn markers: every frame type but DHT (C4), JPG (C8) and DAC (CC). */
84
+ var JPEG_FRAME = /* @__PURE__ */ new Set([
85
+ 192,
86
+ 193,
87
+ 194,
88
+ 195,
89
+ 197,
90
+ 198,
91
+ 199,
92
+ 201,
93
+ 202,
94
+ 203,
95
+ 205,
96
+ 206,
97
+ 207
98
+ ]);
99
+ function jpegKeeps(marker, b, payload) {
100
+ if (marker >= 192 && marker <= 207 || marker >= 218 && marker <= 223) return true;
101
+ if (marker === 224) return starts(b, payload, "JFIF\0");
102
+ if (marker === 226) return starts(b, payload, "ICC_PROFILE\0");
103
+ if (marker === 238) return starts(b, payload, "Adobe");
104
+ return false;
105
+ }
106
+ /** An APP1 Exif, big-endian, whose IFD0 holds `orientation` alone. */
107
+ var orientationOnly = (orientation) => Uint8Array.of(255, 225, 0, 34, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 1, 1, 18, 0, 3, 0, 0, 0, 1, 0, orientation, 0, 0, 0, 0, 0, 0);
108
+ function stripJpeg(b) {
109
+ const parts = [b.subarray(0, 2)];
110
+ let at = 2, framed = false, scanned = false, exif = false;
111
+ for (;;) {
112
+ check(at < b.length && b[at] === 255);
113
+ while (at < b.length && b[at] === 255) at++;
114
+ check(at < b.length);
115
+ const marker = b[at++];
116
+ if (marker === 217) {
117
+ check(framed && scanned);
118
+ parts.push(Uint8Array.of(255, 217));
119
+ return parts;
120
+ }
121
+ if (marker === 1 || marker >= 208 && marker <= 215) {
122
+ parts.push(Uint8Array.of(255, marker));
123
+ continue;
124
+ }
125
+ check(marker !== 0 && marker !== 216 && at + 2 <= b.length);
126
+ const length = u16be(b, at);
127
+ check(length >= 2 && at + length <= b.length);
128
+ if (jpegKeeps(marker, b, at + 2)) {
129
+ parts.push(Uint8Array.of(255, marker), b.subarray(at, at + length));
130
+ if (JPEG_FRAME.has(marker)) framed = true;
131
+ } else if (marker === 225 && !scanned && !exif && starts(b, at + 2, "Exif\0\0")) {
132
+ exif = true;
133
+ const orientation = exifOrientation(b, at + 8, at + length);
134
+ if (orientation >= 2) parts.push(orientationOnly(orientation));
135
+ }
136
+ at += length;
137
+ if (marker !== 218) continue;
138
+ check(framed);
139
+ scanned = true;
140
+ let end = at;
141
+ for (;;) {
142
+ end = b.indexOf(255, end);
143
+ check(end >= 0);
144
+ let next = end + 1;
145
+ while (next < b.length && b[next] === 255) next++;
146
+ check(next < b.length);
147
+ if (b[next] !== 0 && !(b[next] >= 208 && b[next] <= 215)) break;
148
+ end = next + 1;
149
+ }
150
+ parts.push(b.subarray(at, end));
151
+ at = end;
152
+ }
153
+ }
154
+ var PNG_CRITICAL = /* @__PURE__ */ new Set([
155
+ "IHDR",
156
+ "PLTE",
157
+ "IDAT",
158
+ "IEND"
159
+ ]);
160
+ var PNG_DRAWS = /* @__PURE__ */ new Set([
161
+ "tRNS",
162
+ "gAMA",
163
+ "cHRM",
164
+ "sRGB",
165
+ "iCCP",
166
+ "sBIT",
167
+ "bKGD",
168
+ "pHYs",
169
+ "cICP",
170
+ "mDCV",
171
+ "cLLI",
172
+ "acTL",
173
+ "fcTL",
174
+ "fdAT"
175
+ ]);
176
+ function stripPng(b) {
177
+ const parts = [b.subarray(0, 8)];
178
+ let at = 8;
179
+ for (;;) {
180
+ check(at + 12 <= b.length);
181
+ const length = u32be(b, at), type = text(b, at + 4, 4);
182
+ check(at + 12 + length <= b.length && (at > 8 || type === "IHDR"));
183
+ const critical = (b[at + 4] & 32) === 0;
184
+ check(!critical || PNG_CRITICAL.has(type));
185
+ if (critical || PNG_DRAWS.has(type)) parts.push(b.subarray(at, at + 12 + length));
186
+ at += 12 + length;
187
+ if (type === "IEND") return parts;
188
+ }
189
+ }
190
+ var WEBP_KEEPS = /* @__PURE__ */ new Set([
191
+ "VP8 ",
192
+ "VP8L",
193
+ "VP8X",
194
+ "ALPH",
195
+ "ANIM",
196
+ "ANMF",
197
+ "ICCP"
198
+ ]);
199
+ function stripWebp(b) {
200
+ check(b.length >= 20);
201
+ const riffEnd = 8 + u32le(b, 4);
202
+ check(riffEnd <= b.length && riffEnd % 2 === 0);
203
+ const parts = [];
204
+ let at = 12, size = 4, drawn = false;
205
+ while (at < riffEnd) {
206
+ check(at + 8 <= riffEnd);
207
+ const type = text(b, at, 4), length = u32le(b, at + 4), end = at + 8 + length + (length & 1);
208
+ check(end <= riffEnd && (at > 12 || type === "VP8 " || type === "VP8L" || type === "VP8X"));
209
+ if (WEBP_KEEPS.has(type)) {
210
+ let chunk = b.subarray(at, end);
211
+ if (type === "VP8X") {
212
+ check(length >= 10);
213
+ chunk = chunk.slice();
214
+ chunk[8] = chunk[8] & -13;
215
+ }
216
+ if (type === "VP8 " || type === "VP8L" || type === "ANMF") drawn = true;
217
+ parts.push(chunk);
218
+ size += chunk.length;
219
+ }
220
+ at = end;
221
+ }
222
+ check(drawn);
223
+ const header = /* @__PURE__ */ new Uint8Array(12);
224
+ header.set(b.subarray(0, 12));
225
+ new DataView(header.buffer).setUint32(4, size, true);
226
+ return [header, ...parts];
227
+ }
228
+ var HEIF_TOP = /* @__PURE__ */ new Set([
229
+ "ftyp",
230
+ "meta",
231
+ "mdat",
232
+ "free",
233
+ "skip"
234
+ ]);
235
+ var HEIF_META = /* @__PURE__ */ new Set([
236
+ "hdlr",
237
+ "dinf",
238
+ "pitm",
239
+ "iloc",
240
+ "iinf",
241
+ "iref",
242
+ "iprp",
243
+ "idat",
244
+ "grpl",
245
+ "free",
246
+ "skip"
247
+ ]);
248
+ /** Items that hold metadata: Exif, and XMP (or any other document) as a MIME item. */
249
+ var HEIF_METADATA_ITEMS = /* @__PURE__ */ new Set([
250
+ "Exif",
251
+ "mime",
252
+ "uri "
253
+ ]);
254
+ function boxes(b, start, end) {
255
+ const found = [];
256
+ for (let at = start; at < end;) {
257
+ check(at + 8 <= end);
258
+ let size = u32be(b, at), body = at + 8;
259
+ const type = text(b, at + 4, 4);
260
+ if (size === 1) {
261
+ check(at + 16 <= end);
262
+ size = u32be(b, at + 8) * 2 ** 32 + u32be(b, at + 12);
263
+ body = at + 16;
264
+ } else if (size === 0) size = end - at;
265
+ if (type === "uuid") body += 16;
266
+ check(size >= body - at && at + size <= end);
267
+ found.push({
268
+ type,
269
+ start: at,
270
+ body,
271
+ end: at + size
272
+ });
273
+ at += size;
274
+ }
275
+ return found;
276
+ }
277
+ function stripHeif(b) {
278
+ const top = boxes(b, 0, b.length);
279
+ check(top[0]?.type === "ftyp" && top.every((box) => HEIF_TOP.has(box.type)));
280
+ const metas = top.filter((box) => box.type === "meta");
281
+ check(metas.length === 1);
282
+ const meta = metas[0];
283
+ const children = boxes(b, meta.body + 4, meta.end);
284
+ check(children.every((box) => HEIF_META.has(box.type)));
285
+ const one = (type) => {
286
+ const of = children.filter((box) => box.type === type);
287
+ check(of.length <= 1);
288
+ return of[0];
289
+ };
290
+ const iinf = one("iinf"), iloc = one("iloc"), idat = one("idat");
291
+ check(!!iinf && !!iloc);
292
+ const metadata = /* @__PURE__ */ new Set();
293
+ const infeVersion = b[iinf.body];
294
+ const entries = boxes(b, iinf.body + 4 + (infeVersion === 0 ? 2 : 4), iinf.end);
295
+ for (const infe of entries) {
296
+ check(infe.type === "infe" && infe.body + 4 <= infe.end);
297
+ const version = b[infe.body];
298
+ check(version === 2 || version === 3);
299
+ let at = infe.body + 4;
300
+ const id = version === 2 ? u16be(b, at) : u32be(b, at);
301
+ at += version === 2 ? 2 : 4;
302
+ check(at + 6 <= infe.end);
303
+ if (HEIF_METADATA_ITEMS.has(text(b, at + 2, 4))) metadata.add(id);
304
+ }
305
+ const out = b.slice();
306
+ const version = b[iloc.body];
307
+ check(version <= 2);
308
+ let at = iloc.body + 4;
309
+ /** The next field of `size` bytes (0, 2, 4 or 8), big-endian. */
310
+ const read = (size) => {
311
+ check(at + size <= iloc.end);
312
+ const value = size === 0 ? 0 : size === 2 ? u16be(b, at) : size === 4 ? u32be(b, at) : size === 8 ? u32be(b, at) * 2 ** 32 + u32be(b, at + 4) : NaN;
313
+ check(Number.isSafeInteger(value));
314
+ at += size;
315
+ return value;
316
+ };
317
+ const read2 = () => read(2);
318
+ check(at + 2 <= iloc.end);
319
+ const offsetSize = b[at] >> 4, lengthSize = b[at] & 15, baseSize = b[at + 1] >> 4, indexSize = version > 0 ? b[at + 1] & 15 : 0;
320
+ check([
321
+ offsetSize,
322
+ lengthSize,
323
+ baseSize,
324
+ indexSize
325
+ ].every((size) => size === 0 || size === 4 || size === 8));
326
+ at += 2;
327
+ const count = read(version < 2 ? 2 : 4);
328
+ for (let i = 0; i < count; i++) {
329
+ const id = version < 2 ? read2() : read(4);
330
+ const method = version > 0 ? read2() & 15 : 0;
331
+ const reference = read2();
332
+ const base = read(baseSize);
333
+ const extents = read2();
334
+ for (let e = 0; e < extents; e++) {
335
+ if (indexSize) read(indexSize);
336
+ const offset = read(offsetSize), length = read(lengthSize);
337
+ if (!metadata.has(id)) continue;
338
+ check(reference === 0 && length > 0 && (method === 0 || method === 1 && !!idat));
339
+ const start = (method === 1 ? idat.body : 0) + base + offset, limit = method === 1 ? idat.end : b.length;
340
+ check(start + length <= limit);
341
+ out.fill(0, start, start + length);
342
+ }
343
+ }
344
+ return [out];
345
+ }
346
+ var GIF_APPS_KEPT = /* @__PURE__ */ new Set([
347
+ "NETSCAPE2.0",
348
+ "ANIMEXTS1.0",
349
+ "ICCRGBG1012"
350
+ ]);
351
+ function stripGif(b) {
352
+ check(b.length >= 13);
353
+ /** A colour table's bytes, from the flags that say it is there and its size. */
354
+ const table = (flags) => flags & 128 ? 3 << (flags & 7) + 1 : 0;
355
+ /** The end of the data sub-blocks at `at`, past their empty block. */
356
+ const blocks = (at) => {
357
+ for (;;) {
358
+ check(at < b.length);
359
+ const length = b[at];
360
+ at += 1 + length;
361
+ if (!length) return at;
362
+ }
363
+ };
364
+ let at = 13 + table(b[10]), framed = false;
365
+ check(at <= b.length);
366
+ const parts = [b.subarray(0, at)];
367
+ for (;;) {
368
+ check(at < b.length);
369
+ const introducer = b[at];
370
+ if (introducer === 59) {
371
+ check(framed);
372
+ parts.push(Uint8Array.of(59));
373
+ return parts;
374
+ }
375
+ if (introducer === 44) {
376
+ check(at + 10 <= b.length);
377
+ const data = at + 10 + table(b[at + 9]);
378
+ check(data < b.length);
379
+ const end = blocks(data + 1);
380
+ parts.push(b.subarray(at, end));
381
+ framed = true;
382
+ at = end;
383
+ continue;
384
+ }
385
+ check(introducer === 33 && at + 2 < b.length);
386
+ const label = b[at + 1], end = blocks(at + 2);
387
+ const app = label === 255 && b[at + 2] === 11 && GIF_APPS_KEPT.has(text(b, at + 3, 11));
388
+ if (label === 249 || label === 1 || app) parts.push(b.subarray(at, end));
389
+ else check(label === 254 || label === 255);
390
+ at = end;
391
+ }
392
+ }
393
+ var TIFF_DRAWS = /* @__PURE__ */ new Set([
394
+ 254,
395
+ 255,
396
+ 256,
397
+ 257,
398
+ 258,
399
+ 259,
400
+ 262,
401
+ 263,
402
+ 264,
403
+ 265,
404
+ 266,
405
+ 273,
406
+ 274,
407
+ 277,
408
+ 278,
409
+ 279,
410
+ 280,
411
+ 281,
412
+ 282,
413
+ 283,
414
+ 284,
415
+ 286,
416
+ 287,
417
+ 290,
418
+ 291,
419
+ 292,
420
+ 293,
421
+ 296,
422
+ 297,
423
+ 301,
424
+ 317,
425
+ 318,
426
+ 319,
427
+ 320,
428
+ 321,
429
+ 322,
430
+ 323,
431
+ 324,
432
+ 325,
433
+ 332,
434
+ 334,
435
+ 336,
436
+ 338,
437
+ 339,
438
+ 340,
439
+ 341,
440
+ 529,
441
+ 530,
442
+ 531,
443
+ 532,
444
+ 34675
445
+ ]);
446
+ /** Text and documents about the picture: DocumentName to HostComputer, InkNames, XMP, Copyright, IPTC, Photoshop, Windows' XP tags, PrintIM. */
447
+ var TIFF_METADATA = /* @__PURE__ */ new Set([
448
+ 269,
449
+ 270,
450
+ 271,
451
+ 272,
452
+ 285,
453
+ 305,
454
+ 306,
455
+ 315,
456
+ 316,
457
+ 333,
458
+ 700,
459
+ 33432,
460
+ 33723,
461
+ 34377,
462
+ 18246,
463
+ 18249,
464
+ 40091,
465
+ 40092,
466
+ 40093,
467
+ 40094,
468
+ 40095,
469
+ 50341
470
+ ]);
471
+ /** The IFDs of Exif, GPS and interoperability, emptied whole. */
472
+ var TIFF_METADATA_IFDS = /* @__PURE__ */ new Set([
473
+ 34665,
474
+ 34853,
475
+ 40965
476
+ ]);
477
+ /** Compression without JPEG: none, CCITT, LZW, Deflate, PackBits. */
478
+ var TIFF_COMPRESSION = /* @__PURE__ */ new Set([
479
+ 1,
480
+ 2,
481
+ 3,
482
+ 4,
483
+ 5,
484
+ 8,
485
+ 32773,
486
+ 32946
487
+ ]);
488
+ /** Bytes per value of each field type. */
489
+ var TIFF_TYPE_BYTES = [
490
+ 0,
491
+ 1,
492
+ 1,
493
+ 2,
494
+ 4,
495
+ 8,
496
+ 1,
497
+ 1,
498
+ 2,
499
+ 4,
500
+ 8,
501
+ 4,
502
+ 8,
503
+ 4
504
+ ];
505
+ function stripTiff(b) {
506
+ const little = b[0] === 73;
507
+ const u16 = (at) => {
508
+ check(at + 2 <= b.length);
509
+ return little ? b[at] | b[at + 1] << 8 : u16be(b, at);
510
+ };
511
+ const u32 = (at) => {
512
+ check(at + 4 <= b.length);
513
+ return little ? u32le(b, at) : u32be(b, at);
514
+ };
515
+ check(b.length >= 8 && u16(2) === 42);
516
+ const out = b.slice(), seen = /* @__PURE__ */ new Set();
517
+ /** An IFD's entries: tag, type, the value's first byte (in the entry or where it points) and its bytes. */
518
+ const entries = (ifd) => {
519
+ check(ifd >= 8 && !seen.has(ifd) && seen.size < 1024);
520
+ seen.add(ifd);
521
+ const count = u16(ifd), next = ifd + 2 + count * 12;
522
+ u32(next);
523
+ return {
524
+ next,
525
+ list: Array.from({ length: count }, (_, i) => {
526
+ const at = ifd + 2 + i * 12, tag = u16(at), type = u16(at + 2);
527
+ check(type >= 1 && type < TIFF_TYPE_BYTES.length);
528
+ const bytes = TIFF_TYPE_BYTES[type] * u32(at + 4);
529
+ const value = bytes <= 4 ? at + 8 : u32(at + 8);
530
+ check(Number.isSafeInteger(bytes) && value + bytes <= b.length);
531
+ return {
532
+ at,
533
+ tag,
534
+ type,
535
+ value,
536
+ bytes
537
+ };
538
+ })
539
+ };
540
+ };
541
+ /** An Exif, GPS or interoperability IFD: every value zeroed, then the IFD itself, so it holds no entry. */
542
+ const empty = (ifd) => {
543
+ const { next, list } = entries(ifd);
544
+ for (const entry of list) {
545
+ check(entry.tag !== 37500);
546
+ if (TIFF_METADATA_IFDS.has(entry.tag)) empty(u32(entry.value));
547
+ out.fill(0, entry.value, entry.value + entry.bytes);
548
+ }
549
+ out.fill(0, ifd, next + 4);
550
+ };
551
+ for (let ifd = u32(4); ifd;) {
552
+ const { next, list } = entries(ifd);
553
+ for (const { tag, value, bytes } of list) {
554
+ if (tag === 259) check(TIFF_COMPRESSION.has(u16(value)));
555
+ if (TIFF_METADATA_IFDS.has(tag)) empty(u32(value));
556
+ else if (TIFF_METADATA.has(tag)) out.fill(0, value, value + bytes);
557
+ else check(TIFF_DRAWS.has(tag));
558
+ }
559
+ ifd = u32(next);
560
+ }
561
+ return [out];
562
+ }
563
+ var STRIP = {
564
+ jpeg: stripJpeg,
565
+ png: stripPng,
566
+ webp: stripWebp,
567
+ heif: stripHeif,
568
+ gif: stripGif,
569
+ tiff: stripTiff
570
+ };
571
+ /**
572
+ * A picture's bytes without its metadata, as parts to put in a Blob; undefined when the file is not a picture this
573
+ * strips (by its bytes and its type), so it goes as it is. Throws `NO_PICTURE_METADATA` when it is one but its
574
+ * metadata cannot be removed.
575
+ */
576
+ function stripPictureMetadata(bytes, mime) {
577
+ const kind = kindOf(bytes);
578
+ if (!kind) {
579
+ if (STRIPPED_TYPES.has(mime.split(";")[0].trim().toLowerCase())) throw new Error(NO_PICTURE_METADATA);
580
+ return;
581
+ }
582
+ return STRIP[kind](bytes);
583
+ }
584
+ /**
585
+ * Whether a file is a picture whose metadata goes before it is sent, by its first `PICTURE_METADATA_LIMITS.headBytes`
586
+ * bytes or by its type: then it is read whole and stripped (`stripPictureMetadata`), else it goes as it is.
587
+ */
588
+ function isStrippedPicture(head, mime) {
589
+ return !!kindOf(head) || STRIPPED_TYPES.has(mime.split(";")[0].trim().toLowerCase());
590
+ }
591
+ /**
592
+ * `source` as it is sent: without its metadata when it is a picture (`stripPictureMetadata`), or undefined when it is
593
+ * not one and goes as it is. Only its first bytes are read for any other file. Throws `NO_PICTURE_METADATA` for a
594
+ * picture that cannot be stripped or is past `PICTURE_METADATA_LIMITS.maxBytes`; an error reading `source` as it is.
595
+ */
596
+ async function withoutPictureMetadata(source, mime) {
597
+ if (!isStrippedPicture(new Uint8Array(await source.slice(0, PICTURE_METADATA_LIMITS.headBytes).arrayBuffer()), mime)) return void 0;
598
+ if (source.size > PICTURE_METADATA_LIMITS.maxBytes) throw new Error(NO_PICTURE_METADATA);
599
+ const parts = stripPictureMetadata(new Uint8Array(await source.arrayBuffer()), mime);
600
+ return parts && new Blob(parts, { type: mime });
601
+ }
602
+ //#endregion
12
603
  //#region ../browser/src/engine/paymentAdapters/away.ts
13
604
  var away = /* @__PURE__ */ new Map();
14
605
  /** The wallets away from this device, by wallet id, with the name of their home device ("" when it has none here). */
@@ -990,6 +1581,45 @@ var ProviderSources = class {
990
1581
  }
991
1582
  };
992
1583
  //#endregion
1584
+ //#region ../browser/src/engine/invoicePace.ts
1585
+ /**
1586
+ * How often an open invoice of ours is asked about, at its Cashu mint or at a Lightning card's source (agents#2447).
1587
+ * Someone pays an invoice soon after it is shown, or not at all: it is asked about every few seconds at first, then
1588
+ * less and less. Asked every 4 s for the hour a mint or a node keeps it open, an invoice nobody paid cost about 900
1589
+ * requests (on NWC each one signed, encrypted and carried by the wallet's relay); on this pace it costs about 100.
1590
+ *
1591
+ * Whoever knows a payment may have happened asks at once, whatever the pace: a payer's "I paid" (`vouch`), the
1592
+ * request's check, a wallet about to be removed. The screen showing an invoice keeps it `watched`, at the fast pace.
1593
+ */
1594
+ var INVOICE_PACE = {
1595
+ /** While the invoice is new, or watched: a payment shows within seconds. */
1596
+ fastMs: 4e3,
1597
+ fastForMs: 12e4,
1598
+ /** Then, until it is this old. */
1599
+ midMs: 15e3,
1600
+ midForMs: 3e5,
1601
+ /** From then on, until it expires. */
1602
+ slowMs: 6e4,
1603
+ /** How long one word from the screen keeps an invoice watched: the screen says it again while it shows it. */
1604
+ watchMs: 9e4,
1605
+ /** A quote or an invoice goes only this long after its expiry, once its mint or source says it is unpaid. */
1606
+ expiryGraceMs: 6e4,
1607
+ /** Due this close to now counts as due: a timer may fire a moment before the clock reads its time. */
1608
+ dueSlackMs: 250
1609
+ };
1610
+ /** When the invoice is next asked about. `asked`: when it was last, in this run; never, it is due now. */
1611
+ function nextInvoiceAsk(invoice, asked, now) {
1612
+ const { fastMs, fastForMs, midMs, midForMs, slowMs, expiryGraceMs } = INVOICE_PACE;
1613
+ const fast = invoice.paid || (invoice.watchedUntil ?? 0) > now;
1614
+ if (invoice.closed && !fast) {
1615
+ if (invoice.expiresAt !== null) return Math.max(asked === void 0 ? now : asked + slowMs, invoice.expiresAt + expiryGraceMs + 1);
1616
+ return asked === void 0 ? now : asked + slowMs;
1617
+ }
1618
+ if (asked === void 0) return now;
1619
+ const age = now - invoice.createdAt;
1620
+ return asked + (fast || age < fastForMs ? fastMs : age < midForMs ? midMs : slowMs);
1621
+ }
1622
+ //#endregion
993
1623
  //#region ../browser/src/engine/paymentAdapters/providers/lightningService.ts
994
1624
  var PREFIX = "lightningOp-";
995
1625
  var opKey = (direction, hash) => `${PREFIX}${direction}-${hash}`;
@@ -1028,7 +1658,6 @@ async function readLightningJournal() {
1028
1658
  }
1029
1659
  return (await read.ops).map((op) => ({ ...op }));
1030
1660
  }
1031
- var IN_POLL_MS = 4e3;
1032
1661
  var OUT_POLL_MS = 15e3;
1033
1662
  var RECENT = 20;
1034
1663
  /** Resolved Lightning addresses are kept this long for the amount to be chosen; this many at most. */
@@ -1048,6 +1677,12 @@ var LightningService = class {
1048
1677
  quotes = /* @__PURE__ */ new Map();
1049
1678
  mode;
1050
1679
  timer;
1680
+ /** When `timer` fires: a pass that would fire later leaves it as it is. */
1681
+ timerAt = 0;
1682
+ /** Per open invoice of ours (payment hash): when the source was last asked about it, in this run. */
1683
+ asked = /* @__PURE__ */ new Map();
1684
+ /** Per invoice the screen shows (payment hash): until when (`watch`). */
1685
+ watched = /* @__PURE__ */ new Map();
1051
1686
  passes = Promise.resolve();
1052
1687
  stopped = false;
1053
1688
  recent = [];
@@ -1101,6 +1736,7 @@ var LightningService = class {
1101
1736
  async stop() {
1102
1737
  this.stopped = true;
1103
1738
  clearTimeout(this.timer);
1739
+ this.timer = void 0;
1104
1740
  await this.sources.stop();
1105
1741
  }
1106
1742
  refreshOffered() {
@@ -1128,12 +1764,25 @@ var LightningService = class {
1128
1764
  selfSettled: !!provider.settlesItself,
1129
1765
  state: "open"
1130
1766
  });
1131
- this.schedule(IN_POLL_MS);
1767
+ this.asked.set(created.paymentHash, Date.now());
1768
+ this.schedule(INVOICE_PACE.fastMs);
1132
1769
  return {
1133
1770
  ...created,
1134
1771
  source: descriptor.id
1135
1772
  };
1136
1773
  }
1774
+ /**
1775
+ * The screen shows this invoice of ours (Receive): the source is asked about it at the fast pace for
1776
+ * `INVOICE_PACE.watchMs`, and now if it was not just asked. Returns whether it is an open invoice of this card's.
1777
+ */
1778
+ async watch(invoice) {
1779
+ const hash = decodeBolt11(invoice)?.paymentHash;
1780
+ const op = hash ? await this.get("in", hash) : void 0;
1781
+ if (!op || !this.owns(op) || op.state !== "open") return false;
1782
+ this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
1783
+ this.schedule(0);
1784
+ return true;
1785
+ }
1137
1786
  /** The Cashu wallet minted the ecash of one of its invoices (it polls its own quotes). */
1138
1787
  async reportInvoicePaid(invoice, context = {}) {
1139
1788
  const hash = decodeBolt11(invoice)?.paymentHash;
@@ -1318,19 +1967,27 @@ var LightningService = class {
1318
1967
  await this.loadRecent();
1319
1968
  this.events.changed();
1320
1969
  }
1321
- /** Asks the active source about everything of its that is open, pending or unknown. One pass at a time. */
1322
- reconcile() {
1323
- const pass = this.passes.then(() => this.reconcileOnce());
1970
+ /**
1971
+ * Asks the active source about everything of its that is open, pending or unknown. One pass at a time. `paced`: an
1972
+ * open invoice only when its pace says so (`nextInvoiceAsk`); otherwise every one now (someone says it was paid).
1973
+ */
1974
+ reconcile(paced = false) {
1975
+ const pass = this.passes.then(() => this.reconcileOnce(paced));
1324
1976
  this.passes = pass.catch(() => {});
1325
1977
  return pass;
1326
1978
  }
1327
- async reconcileOnce() {
1979
+ async reconcileOnce(paced) {
1328
1980
  if (this.stopped) return;
1329
1981
  let again = 0;
1982
+ /** When the next open invoice is due. */
1983
+ let invoiceDue = Infinity;
1330
1984
  const writes = this.writes;
1331
1985
  try {
1332
1986
  const provider = this.sources.active, providerId = this.sources.activeId;
1333
- for (const op of await this.list()) {
1987
+ const ops = await this.list();
1988
+ const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
1989
+ for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
1990
+ for (const op of ops) {
1334
1991
  if (!this.owns(op)) continue;
1335
1992
  if (op.selfSettled) {
1336
1993
  if (op.direction !== "out" || op.state !== "unknown") continue;
@@ -1362,6 +2019,14 @@ var LightningService = class {
1362
2019
  }
1363
2020
  if (!(op.direction === "in" ? op.state === "open" : ["pending", "unknown"].includes(op.state))) continue;
1364
2021
  if (!provider || op.providerId !== providerId || !provider.capabilities.lookup) continue;
2022
+ if (op.direction === "in") {
2023
+ const due = this.nextAsk(op, Date.now());
2024
+ if (paced && due > Date.now() + INVOICE_PACE.dueSlackMs) {
2025
+ invoiceDue = Math.min(invoiceDue, due);
2026
+ continue;
2027
+ }
2028
+ this.asked.set(op.paymentHash, Date.now());
2029
+ }
1365
2030
  try {
1366
2031
  const unchanged = async () => (await this.get(op.direction, op.paymentHash))?.state === op.state;
1367
2032
  if (op.direction === "in") {
@@ -1380,11 +2045,11 @@ var LightningService = class {
1380
2045
  settledAt: Date.now()
1381
2046
  });
1382
2047
  this.events.received(op);
1383
- } else if (status.state === "expired" || op.expiresAt + 6e4 < Date.now()) await this.put({
2048
+ } else if (status.state === "expired" || op.expiresAt + INVOICE_PACE.expiryGraceMs < Date.now()) await this.put({
1384
2049
  ...op,
1385
2050
  state: "expired"
1386
2051
  });
1387
- else again = again ? Math.min(again, IN_POLL_MS) : IN_POLL_MS;
2052
+ else invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
1388
2053
  } else {
1389
2054
  const status = await provider.paymentStatus({
1390
2055
  invoice: op.invoice,
@@ -1406,18 +2071,36 @@ var LightningService = class {
1406
2071
  this.events.resolved(op, status.state === "paid");
1407
2072
  }
1408
2073
  } catch {
1409
- again = again ? Math.min(again, op.direction === "in" ? IN_POLL_MS : OUT_POLL_MS) : op.direction === "in" ? IN_POLL_MS : OUT_POLL_MS;
2074
+ if (op.direction === "in") invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
2075
+ else again = again ? Math.min(again, OUT_POLL_MS) : OUT_POLL_MS;
1410
2076
  }
1411
2077
  }
1412
2078
  } finally {
1413
2079
  if (await this.loadRecent() || this.writes !== writes) this.events.changed();
1414
- if (again) this.schedule(again);
2080
+ const wait = Math.min(again || Infinity, invoiceDue - Date.now());
2081
+ if (wait < Infinity) this.schedule(Math.max(0, wait));
1415
2082
  }
1416
2083
  }
2084
+ /** When the source is next asked about this open invoice of ours. */
2085
+ nextAsk(op, now) {
2086
+ return nextInvoiceAsk({
2087
+ createdAt: op.createdAt,
2088
+ expiresAt: op.expiresAt,
2089
+ watchedUntil: this.watched.get(op.paymentHash),
2090
+ closed: !!op.paymentId && !!this.events.requestClosed?.(op.paymentId)
2091
+ }, this.asked.get(op.paymentHash), now);
2092
+ }
2093
+ /** The next pass in `ms`, unless one is due sooner. It asks only what is due (`reconcile(true)`). */
1417
2094
  schedule(ms) {
1418
2095
  if (this.stopped) return;
2096
+ const at = Date.now() + ms;
2097
+ if (this.timer && this.timerAt <= at) return;
1419
2098
  clearTimeout(this.timer);
1420
- this.timer = setTimeout(() => void this.reconcile(), ms);
2099
+ this.timerAt = at;
2100
+ this.timer = setTimeout(() => {
2101
+ this.timer = void 0;
2102
+ this.reconcile(true);
2103
+ }, ms);
1421
2104
  }
1422
2105
  /** Changing the source is refused while a payment through it has not ended: only it can say how. */
1423
2106
  async refusal(providerId, mode) {
@@ -1836,6 +2519,10 @@ var LightningCards = class {
1836
2519
  async reconcile() {
1837
2520
  await Promise.all(this.here().map((s) => s.reconcile()));
1838
2521
  }
2522
+ /** The screen shows this invoice of ours: the card that made it asks about it at the fast pace a while longer. */
2523
+ async watch(invoice) {
2524
+ return (await Promise.all(this.here().map((s) => s.watch(invoice)))).some(Boolean);
2525
+ }
1839
2526
  async recover() {
1840
2527
  for (const s of this.here()) await s.recover();
1841
2528
  }
@@ -1963,7 +2650,7 @@ var registry;
1963
2650
  var loading;
1964
2651
  var listeners = /* @__PURE__ */ new Set();
1965
2652
  function loadIdentityProviders() {
1966
- return loading ??= import("./registry-BmS02J5h.js").then((m) => {
2653
+ return loading ??= import("./registry-CZTmtSws.js").then((m) => {
1967
2654
  registry = m;
1968
2655
  for (const listener of listeners) listener();
1969
2656
  return m;
@@ -2015,6 +2702,8 @@ var IdentityProofs = class {
2015
2702
  proofs = [];
2016
2703
  revocations = [];
2017
2704
  revocationsCheckedAt = 0;
2705
+ /** "Clear all data" (`revokeAll`): a revocation lookup still on its way notes nothing. */
2706
+ ended = false;
2018
2707
  /** Unsealed proof-key seeds, by proof id, for this run only. */
2019
2708
  seeds = /* @__PURE__ */ new Map();
2020
2709
  timers = [];
@@ -2094,14 +2783,40 @@ var IdentityProofs = class {
2094
2783
  }
2095
2784
  return seed;
2096
2785
  }
2097
- ctx() {
2786
+ ctx(fetch = this.fetch) {
2098
2787
  return {
2099
2788
  now: now(),
2100
2789
  signal: AbortSignal.timeout(3e4),
2101
- fetch: this.fetch
2790
+ fetch
2102
2791
  };
2103
2792
  }
2793
+ /** The person's own proof, before it is saved: on whatever servers it names, their own. */
2104
2794
  verify = (statement, evidence) => verifyIdentity(this.providers(), statement, evidence, this.ctx());
2795
+ /**
2796
+ * A contact's proof. With Hide my IP on, a host its evidence names (a did:web or domain's web server, an AT Protocol
2797
+ * server, a Pubky homeserver) is not contacted, since it would learn this device's IP address: the check fails as one
2798
+ * that could not run, and the contact is told only that.
2799
+ */
2800
+ verifyContact = async (statement, evidence) => {
2801
+ if (!this.host.relayOnly?.()) return this.verify(statement, evidence);
2802
+ const { fixedIdentityHosts } = await import("./fixedHosts-BiukTsd9.js");
2803
+ const fixed = fixedIdentityHosts();
2804
+ let refused;
2805
+ const fetch = async (url, options) => {
2806
+ const host = new URL(url).host;
2807
+ if (!fixed.has(host)) {
2808
+ refused ??= host;
2809
+ throw new IdentityCheckUnavailable(`${host} was not contacted`);
2810
+ }
2811
+ return this.fetch(url, options);
2812
+ };
2813
+ try {
2814
+ return await verifyIdentity(this.providers(), statement, evidence, this.ctx(fetch));
2815
+ } catch (e) {
2816
+ if (refused) throw new IdentityCheckUnavailable(`Hide my IP from contacts is on: ${refused}, a server your contact chose, was not contacted`);
2817
+ throw e;
2818
+ }
2819
+ };
2105
2820
  revoked = async (statement) => {
2106
2821
  if (!this.host.online()) return false;
2107
2822
  const records = await this.host.resolve(statement.binding.key);
@@ -2192,7 +2907,7 @@ var IdentityProofs = class {
2192
2907
  revokedAt: now(),
2193
2908
  expiresAt: Math.min(proof.binding.expiresAt, proof.verified.expiresAt ?? Infinity)
2194
2909
  };
2195
- const wasShared = this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
2910
+ const wasShared = this.everShared(proof);
2196
2911
  const revoke = wasShared && revocation.expiresAt > now();
2197
2912
  await this.save((proofs, revocations) => proofs.some((p) => identityStatement(p.binding).id === id) ? [proofs.filter((p) => identityStatement(p.binding).id !== id), revoke ? [...revocations, revocation] : revocations] : [proofs, revocations]);
2198
2913
  if (wasShared) this.publishRevocation(revocation).catch(() => {});
@@ -2207,10 +2922,10 @@ var IdentityProofs = class {
2207
2922
  * contacts who check; proofs posted elsewhere (a Bluesky record, a Pubky file, a DNS record) are the person's to delete.
2208
2923
  */
2209
2924
  async revokeAll() {
2925
+ this.ended = true;
2210
2926
  this.stop();
2211
- const shared = new Set(this.host.linkIds().flatMap((l) => this.host.ledger(l)?.shared.map((s) => s.id) ?? []));
2212
2927
  const at = now();
2213
- const last = [...this.revocations.filter((r) => r.expiresAt > at), ...this.proofs.filter((p) => shared.has(identityStatement(p.binding).id)).map((p) => ({
2928
+ const last = [...this.revocations.filter((r) => r.expiresAt > at), ...this.proofs.filter((p) => this.everShared(p)).map((p) => ({
2214
2929
  id: identityStatement(p.binding).id,
2215
2930
  key: p.binding.key,
2216
2931
  seed: p.seed,
@@ -2220,6 +2935,11 @@ var IdentityProofs = class {
2220
2935
  await Promise.allSettled(last.map((r) => this.publishRevocation(r)));
2221
2936
  this.stop();
2222
2937
  }
2938
+ /** Marked when shared; the chats' ledgers still count for a proof shared before the mark was kept. */
2939
+ everShared(p) {
2940
+ const id = identityStatement(p.binding).id;
2941
+ return !!p.shared || this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
2942
+ }
2223
2943
  async publishRevocation(r) {
2224
2944
  if (!this.host.online()) return;
2225
2945
  await this.host.publish(await this.seedOf(r.id, r.seed), [{
@@ -2245,7 +2965,11 @@ var IdentityProofs = class {
2245
2965
  */
2246
2966
  async checkRevocations() {
2247
2967
  if (!this.host.online()) return;
2248
- for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) if (this.revocable(r)) await this.exchange(linkId)?.recheck(r.id, { revocationOnly: true }).catch(() => {});
2968
+ for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) {
2969
+ if (this.ended) return;
2970
+ if (this.revocable(r)) await this.exchange(linkId)?.recheck(r.id, { revocationOnly: true }).catch(() => {});
2971
+ }
2972
+ if (this.ended) return;
2249
2973
  this.revocationsCheckedAt = Date.now();
2250
2974
  await transact([STORES.settings], (stores) => {
2251
2975
  stores[STORES.settings].put(this.revocationsCheckedAt, REVOCATIONS_CHECKED_AT);
@@ -2325,7 +3049,7 @@ var IdentityProofs = class {
2325
3049
  },
2326
3050
  providers: () => this.providers().map((p) => p.id),
2327
3051
  localProof: (id) => this.local(id),
2328
- verify: this.verify,
3052
+ verify: this.verifyContact,
2329
3053
  revoked: this.revoked,
2330
3054
  onError: (error) => {
2331
3055
  this.errors.set(linkId, error);
@@ -2343,6 +3067,10 @@ var IdentityProofs = class {
2343
3067
  if (!p) throw new Error("That identity is no longer in your profile");
2344
3068
  if (Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity) <= now()) throw new Error("This identity has expired. Make a new proof in your profile.");
2345
3069
  this.errors.delete(linkId);
3070
+ if (!p.shared) await this.save((proofs, revocations) => [proofs.map((q) => identityStatement(q.binding).id === id ? {
3071
+ ...q,
3072
+ shared: true
3073
+ } : q), revocations]);
2346
3074
  await x.share(id, !!this.host.channel(linkId));
2347
3075
  }
2348
3076
  async withdraw({ linkId, id }) {
@@ -2797,6 +3525,7 @@ var ENDED_KEPT = 8;
2797
3525
  /** Why a want waits, as the person reads it (the app shows its own words for each `wait`). */
2798
3526
  var WAITING_NOTES = {
2799
3527
  nobody: "Nobody you are connected to has this file yet",
3528
+ author: "Nobody you are connected to has this file yet, and its sender is not one of them",
2800
3529
  busy: "Its holders are busy; asking again soon",
2801
3530
  day: "Its holders have shared all they can today; it comes when another member has it, or tomorrow",
2802
3531
  damaged: "It arrived damaged; ask again"
@@ -3316,7 +4045,7 @@ var GroupFileDesk = class {
3316
4045
  * asked whether or not it said so (one that does not hold it answers `gone`, and is not asked again). Only over an
3317
4046
  * edge this device has. (A private group past 16 members, or a community, reaches a holder it has no edge with
3318
4047
  * over a file session of the two members, WISP 503 § The file session; that session is not built yet, so such a
3319
- * holder is not asked, and the file waits for one that is reachable.)
4048
+ * holder is not asked, and the file waits for one that is reachable: `author` when that is its author alone.)
3320
4049
  */
3321
4050
  ask(kept) {
3322
4051
  const want = this.wants.get(kept.id);
@@ -3381,7 +4110,8 @@ var GroupFileDesk = class {
3381
4110
  });
3382
4111
  return;
3383
4112
  }
3384
- const wait = want.why ?? "nobody";
4113
+ const outOfReach = !!membership?.onHubs && known.includes(kept.author) && known.every((key) => !edges.has(key));
4114
+ const wait = want.why ?? (outOfReach ? "author" : "nobody");
3385
4115
  this.show(kept, {
3386
4116
  state: "transferring",
3387
4117
  stage: "waiting",
@@ -3971,6 +4701,6 @@ function messageFile(kept) {
3971
4701
  };
3972
4702
  }
3973
4703
  //#endregion
3974
- export { WrongNetworkError as $, IdentityProofs as A, ProviderSources as B, FileAppender as C, streamStored as D, storedSize as E, LightningCards as F, breezDatabaseInUse as G, CASHU_MINT_SOURCE as H, cardsKey as I, iceServerProblem as J, breezDatabasesFor as K, isRecoveryPhrase as L, sealSecret as M, whenDataKeyDropped as N, waitingGroupFile as O, CASHU_CARD as P, ModeGate as Q, normalizePhrase as R, WALLET_TYPES as S, removeStored as T, cashuMint as U, sourceKey as V, breezDatabase as W, relayOnlyProblem as X, iceServerSetting as Y, ModeChanged as Z, crossNetwork as _, storedGroupFiles as a, setSingleWriterGate as at, walletInstances as b, receivedPairedReply as c, paymentAlias as d, networkLabel as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, setAwayWallets as it, openSecret as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, refuseAway as nt, groupReply as o, WALLET_NAMES as p, dropBreezDatabase as q, groupFileText as r, requireTurn as rt, pairedWireReply as s, GroupFileDesk as t, awayFrom as tt, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, lightningPaying as z };
4704
+ export { ModeChanged as $, IdentityProofs as A, INVOICE_PACE as B, FileAppender as C, streamStored as D, storedSize as E, LightningCards as F, cashuMint as G, ProviderSources as H, cardsKey as I, breezDatabasesFor as J, breezDatabase as K, isRecoveryPhrase as L, sealSecret as M, whenDataKeyDropped as N, waitingGroupFile as O, CASHU_CARD as P, relayOnlyProblem as Q, normalizePhrase as R, WALLET_TYPES as S, removeStored as T, sourceKey as U, nextInvoiceAsk as V, CASHU_MINT_SOURCE as W, iceServerProblem as X, dropBreezDatabase as Y, iceServerSetting as Z, crossNetwork as _, storedGroupFiles as a, requireTurn as at, walletInstances as b, receivedPairedReply as c, NO_PICTURE_METADATA as ct, paymentAlias as d, stripPictureMetadata as dt, ModeGate as et, paymentWireId as f, withoutPictureMetadata as ft, createTiming as g, createFailure as h, groupOfFile as i, refuseAway as it, openSecret as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, PICTURE_METADATA_LIMITS as lt, assertConfirmedReal as m, groupFileId as n, networkLabel as nt, groupReply as o, setAwayWallets as ot, WALLET_NAMES as p, breezDatabaseInUse as q, groupFileText as r, awayFrom as rt, pairedWireReply as s, setSingleWriterGate as st, GroupFileDesk as t, WrongNetworkError as tt, replyTo as u, isStrippedPicture as ut, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, lightningPaying as z };
3975
4705
 
3976
- //# sourceMappingURL=groupFiles-CBJIEvCE.js.map
4706
+ //# sourceMappingURL=groupFiles-CeF9nPv9.js.map