@ghostlytools/cli 1.8.1 → 1.10.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.
- package/README.md +34 -23
- package/SKILL.md +9 -4
- package/dist/assets/{api-BpQC8dAw.js → api-BF_KwecF.js} +115 -45
- package/dist/assets/api-BF_KwecF.js.map +1 -0
- package/dist/assets/{api-CttDF-S5.js → api-DdrA86Ur.js} +2 -2
- package/dist/assets/{apiKit-CSMeHKgo.js → apiKit-Du1u2l4x.js} +8 -8
- package/dist/assets/apiKit-Du1u2l4x.js.map +1 -0
- package/dist/assets/{apps-DzFMdVt6.js → apps-Bti9fDoW.js} +1 -1
- package/dist/assets/{apps-DqTyZ40T.js → apps-DwPfp54I.js} +5 -3
- package/dist/assets/apps-DwPfp54I.js.map +1 -0
- package/dist/assets/{arkade-Cu3TbPxC.js → arkade-DOWpA2Kr.js} +2 -2
- package/dist/assets/{arkade-Cu3TbPxC.js.map → arkade-DOWpA2Kr.js.map} +1 -1
- package/dist/assets/{backup-CLZOORFC.js → backup-CeRckyl2.js} +1 -1
- package/dist/assets/{backup-CyTZhu28.js → backup-DZ_Q1eSu.js} +6 -6
- package/dist/assets/{backup-CyTZhu28.js.map → backup-DZ_Q1eSu.js.map} +1 -1
- package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
- package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
- package/dist/assets/buttons-BxIThdg9.js +332 -0
- package/dist/assets/buttons-BxIThdg9.js.map +1 -0
- package/dist/assets/buttons-D9QBHS9Y.js +2 -0
- package/dist/assets/client-D5E1RQYB.js +473 -0
- package/dist/assets/client-D5E1RQYB.js.map +1 -0
- package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
- package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
- package/dist/assets/{envelope-CGfUsR1m.js → envelope-CugS9qwQ.js} +2 -2
- package/dist/assets/{envelope-CGfUsR1m.js.map → envelope-CugS9qwQ.js.map} +1 -1
- package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
- package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
- package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
- package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
- package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
- package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
- package/dist/assets/{fixedHosts-BiukTsd9.js → fixedHosts-B4E4VrYE.js} +4 -4
- package/dist/assets/{fixedHosts-BiukTsd9.js.map → fixedHosts-B4E4VrYE.js.map} +1 -1
- package/dist/assets/{groupFiles-CeF9nPv9.js → groupFiles-NonOYBKN.js} +380 -650
- package/dist/assets/groupFiles-NonOYBKN.js.map +1 -0
- package/dist/assets/{host-CKAehWP6.js → host-DvcVt5YI.js} +144 -33
- package/dist/assets/host-DvcVt5YI.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-B8Pdykhg.js → hyperdhtRelay-Ce42sR8x.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B8Pdykhg.js.map → hyperdhtRelay-Ce42sR8x.js.map} +1 -1
- package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
- package/dist/assets/idb-BHsAqENE.js.map +1 -0
- package/dist/assets/{irohWeb-D6tAPHZa.js → irohWeb-C9ChbD-c.js} +71 -4
- package/dist/assets/{irohWeb-D6tAPHZa.js.map → irohWeb-C9ChbD-c.js.map} +1 -1
- package/dist/assets/{main-BDY-pfpz.js → main-4qE381KM.js} +226 -280
- package/dist/assets/main-4qE381KM.js.map +1 -0
- package/dist/assets/{mainline-3ueXpFQL.js → mainline-DOwZDHVy.js} +2 -2
- package/dist/assets/{mainline-3ueXpFQL.js.map → mainline-DOwZDHVy.js.map} +1 -1
- package/dist/assets/{networkReason-DhJYOomu.js → networkReason-MInk1Y63.js} +3 -3
- package/dist/assets/{networkReason-DhJYOomu.js.map → networkReason-MInk1Y63.js.map} +1 -1
- package/dist/assets/{nwc-B1Quqda-.js → nwc-CHLWFV1R.js} +3 -3
- package/dist/assets/{nwc-B1Quqda-.js.map → nwc-CHLWFV1R.js.map} +1 -1
- package/dist/assets/{nwcProvider-DUB6xO-b.js → nwcProvider-BlkPOJen.js} +2 -2
- package/dist/assets/{nwcProvider-DUB6xO-b.js.map → nwcProvider-BlkPOJen.js.map} +1 -1
- package/dist/assets/{ownDid-BfqHJdA6.js → ownDid-yXtY_1B5.js} +3 -3
- package/dist/assets/ownDid-yXtY_1B5.js.map +1 -0
- package/dist/assets/{profiles-MFtCmJwK.js → profiles-vbXHs0Mq.js} +40 -3
- package/dist/assets/profiles-vbXHs0Mq.js.map +1 -0
- package/dist/assets/{registry-CZTmtSws.js → registry-BN9r2pR4.js} +1 -1
- package/dist/assets/{registry-DwlTNQjr.js → registry-chCD0KWS.js} +5 -5
- package/dist/assets/registry-chCD0KWS.js.map +1 -0
- package/dist/assets/{resolve-BVwhiYjj.js → resolve-Dtzogt2W.js} +2 -2
- package/dist/assets/{resolve-BVwhiYjj.js.map → resolve-Dtzogt2W.js.map} +1 -1
- package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
- package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
- package/dist/assets/secretGuard-CSVNxXVW.js +1081 -0
- package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
- package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
- package/dist/assets/{server-Br3XPwFG.js → server-BZnsm5X5.js} +2510 -569
- package/dist/assets/server-BZnsm5X5.js.map +1 -0
- package/dist/assets/{src-C4sOH4zH.js → src-DZagapGt.js} +2015 -161
- package/dist/assets/src-DZagapGt.js.map +1 -0
- package/dist/assets/{sshForges-CQQomStK.js → sshForges-BkTgy5rx.js} +16 -9
- package/dist/assets/{sshForges-CQQomStK.js.map → sshForges-BkTgy5rx.js.map} +1 -1
- package/dist/assets/{translate-C2aNyUkR.js → translate-B9SMd6uf.js} +15 -8
- package/dist/assets/translate-B9SMd6uf.js.map +1 -0
- package/dist/assets/{usdt-CMwatDnQ.js → usdt-BU4ezonh.js} +3 -3
- package/dist/assets/{usdt-CMwatDnQ.js.map → usdt-BU4ezonh.js.map} +1 -1
- package/dist/assets/{waitNotice-Ck3el3_Z.js → waitNotice-B8D8WhbE.js} +2 -2
- package/dist/assets/waitNotice-B8D8WhbE.js.map +1 -0
- package/dist/assets/{words-CqN2KG1r.js → words-jYy7lTcb.js} +5 -2
- package/dist/assets/words-jYy7lTcb.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/call-echo.mjs +7 -5
- package/package.json +1 -1
- package/dist/assets/api-BpQC8dAw.js.map +0 -1
- package/dist/assets/apiKit-CSMeHKgo.js.map +0 -1
- package/dist/assets/apps-DqTyZ40T.js.map +0 -1
- package/dist/assets/buttons-Bd9fR31r.js +0 -698
- package/dist/assets/buttons-Bd9fR31r.js.map +0 -1
- package/dist/assets/buttons-c4CJnL6i.js +0 -2
- package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
- package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
- package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
- package/dist/assets/groupFiles-CeF9nPv9.js.map +0 -1
- package/dist/assets/host-CKAehWP6.js.map +0 -1
- package/dist/assets/idb-BkOJES5_.js.map +0 -1
- package/dist/assets/main-BDY-pfpz.js.map +0 -1
- package/dist/assets/ownDid-BfqHJdA6.js.map +0 -1
- package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
- package/dist/assets/registry-DwlTNQjr.js.map +0 -1
- package/dist/assets/server-Br3XPwFG.js.map +0 -1
- package/dist/assets/src-C4sOH4zH.js.map +0 -1
- package/dist/assets/translate-C2aNyUkR.js.map +0 -1
- package/dist/assets/waitNotice-Ck3el3_Z.js.map +0 -1
- package/dist/assets/words-CqN2KG1r.js.map +0 -1
|
@@ -1,605 +1,14 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $i as emptyIdentityLedger, Br as FileUplink, Da as fileMessageText, Dn as resolveLightningDestination, En as requestLnurlInvoice, Gu as toBase64Url, Hr as transferEnded, Hu as fromBase64Url, Ia as RateWindow, J as meshMessageRef, On as decodeBolt11, Qn as engineText, Rr as ChatFiles, Tu as isDiscoveryBudgetError, Wu as randomBytes, Xi as IdentityCheckUnavailable, Yi as IDENTITY_REVOCATION_LABEL, Zi as IdentityExchange, Zn as engineError, aa as revokesIdentity, ar as groupFileFallback, cr as readGroupHave, ea as identityRevocationValue, er as GROUP_FILE_LIMITS, ia as receivedIdentityStatus, in as WALLET_NETWORKS, ir as fetchesByItself, lr as readGroupWant, na as isIdentityBinding, no as replySnippet, or as isGroupMessageId, ra as newIdentityBinding, rr as GROUP_WANT_NO_FRAME, ta as identityStatement, tr as GROUP_HAVE_FRAME, un as walletNetworkOf, ur as readGroupWantNo, wu as budgetRetryMs } from "./src-DZagapGt.js";
|
|
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
|
-
import { g as wrap, h as transact, i as STORES, m as store, s as databaseName, u as fileStore } from "./idb-
|
|
4
|
-
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-
|
|
3
|
+
import { g as wrap, h as transact, i as STORES, m as store, s as databaseName, u as fileStore } from "./idb-BHsAqENE.js";
|
|
4
|
+
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-MInk1Y63.js";
|
|
5
5
|
import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
|
|
6
|
-
import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-
|
|
7
|
-
import { i as fromBase64Url$1 } from "./envelope-
|
|
8
|
-
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-
|
|
6
|
+
import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-yXtY_1B5.js";
|
|
7
|
+
import { i as fromBase64Url$1 } from "./envelope-CugS9qwQ.js";
|
|
8
|
+
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DjBYYyXT.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
|
|
603
12
|
//#region ../browser/src/engine/paymentAdapters/away.ts
|
|
604
13
|
var away = /* @__PURE__ */ new Map();
|
|
605
14
|
/** The wallets away from this device, by wallet id, with the name of their home device ("" when it has none here). */
|
|
@@ -732,6 +141,7 @@ var ModeGate = class {
|
|
|
732
141
|
*/
|
|
733
142
|
function iceServerProblem(server) {
|
|
734
143
|
if (typeof server?.urls !== "string") return "Each ICE server needs urls: one address, or several comma-separated (turn:host:port)";
|
|
144
|
+
if ([server.username, server.credential].some((value) => value !== void 0 && typeof value !== "string")) return "A TURN server's username and credential are texts";
|
|
735
145
|
const urls = server.urls.split(/[\s,]+/).filter(Boolean);
|
|
736
146
|
if (!urls.length) return "Enter the TURN server address";
|
|
737
147
|
for (const url of urls) {
|
|
@@ -1658,6 +1068,16 @@ async function readLightningJournal() {
|
|
|
1658
1068
|
}
|
|
1659
1069
|
return (await read.ops).map((op) => ({ ...op }));
|
|
1660
1070
|
}
|
|
1071
|
+
/**
|
|
1072
|
+
* What the journal says of the payments of one chat request (`DeskLightning.interrupted`): "pending" while one has not
|
|
1073
|
+
* ended (sending, pending, unknown: its card settles it and says so), "paid" once one went through, undefined when
|
|
1074
|
+
* none left the wallet (none journaled, or only failed ones).
|
|
1075
|
+
*/
|
|
1076
|
+
async function journaledPayment(paymentId) {
|
|
1077
|
+
const ops = (await readLightningJournal()).filter((op) => op.direction === "out" && op.paymentId === paymentId);
|
|
1078
|
+
if (ops.some((op) => op.state === "sending" || op.state === "pending" || op.state === "unknown")) return "pending";
|
|
1079
|
+
return ops.some((op) => op.state === "paid") ? "paid" : void 0;
|
|
1080
|
+
}
|
|
1661
1081
|
var OUT_POLL_MS = 15e3;
|
|
1662
1082
|
var RECENT = 20;
|
|
1663
1083
|
/** Resolved Lightning addresses are kept this long for the amount to be chosen; this many at most. */
|
|
@@ -1783,6 +1203,18 @@ var LightningService = class {
|
|
|
1783
1203
|
this.schedule(0);
|
|
1784
1204
|
return true;
|
|
1785
1205
|
}
|
|
1206
|
+
/**
|
|
1207
|
+
* A payer says it paid this invoice of ours: the source is asked about it now, and at the fast pace for
|
|
1208
|
+
* `INVOICE_PACE.watchMs`. The other open invoices keep their pace. Returns whether it is an open invoice of this card's.
|
|
1209
|
+
*/
|
|
1210
|
+
async check(invoice) {
|
|
1211
|
+
const hash = decodeBolt11(invoice)?.paymentHash;
|
|
1212
|
+
const op = hash ? await this.get("in", hash) : void 0;
|
|
1213
|
+
if (!op || !this.owns(op) || op.state !== "open") return false;
|
|
1214
|
+
this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
|
|
1215
|
+
await this.reconcile(false, op.paymentHash);
|
|
1216
|
+
return true;
|
|
1217
|
+
}
|
|
1786
1218
|
/** The Cashu wallet minted the ecash of one of its invoices (it polls its own quotes). */
|
|
1787
1219
|
async reportInvoicePaid(invoice, context = {}) {
|
|
1788
1220
|
const hash = decodeBolt11(invoice)?.paymentHash;
|
|
@@ -1969,14 +1401,15 @@ var LightningService = class {
|
|
|
1969
1401
|
}
|
|
1970
1402
|
/**
|
|
1971
1403
|
* 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
|
|
1404
|
+
* open invoice only when its pace says so (`nextInvoiceAsk`); otherwise every one now. `only`: the open invoice with
|
|
1405
|
+
* this payment hash alone (a payer says it paid it, `check`).
|
|
1973
1406
|
*/
|
|
1974
|
-
reconcile(paced = false) {
|
|
1975
|
-
const pass = this.passes.then(() => this.reconcileOnce(paced));
|
|
1407
|
+
reconcile(paced = false, only) {
|
|
1408
|
+
const pass = this.passes.then(() => this.reconcileOnce(paced, only));
|
|
1976
1409
|
this.passes = pass.catch(() => {});
|
|
1977
1410
|
return pass;
|
|
1978
1411
|
}
|
|
1979
|
-
async reconcileOnce(paced) {
|
|
1412
|
+
async reconcileOnce(paced, only) {
|
|
1980
1413
|
if (this.stopped) return;
|
|
1981
1414
|
let again = 0;
|
|
1982
1415
|
/** When the next open invoice is due. */
|
|
@@ -1988,7 +1421,7 @@ var LightningService = class {
|
|
|
1988
1421
|
const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
|
|
1989
1422
|
for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
|
|
1990
1423
|
for (const op of ops) {
|
|
1991
|
-
if (!this.owns(op)) continue;
|
|
1424
|
+
if (!this.owns(op) || only !== void 0 && (op.direction !== "in" || op.paymentHash !== only)) continue;
|
|
1992
1425
|
if (op.selfSettled) {
|
|
1993
1426
|
if (op.direction !== "out" || op.state !== "unknown") continue;
|
|
1994
1427
|
if (!provider) {
|
|
@@ -2523,6 +1956,10 @@ var LightningCards = class {
|
|
|
2523
1956
|
async watch(invoice) {
|
|
2524
1957
|
return (await Promise.all(this.here().map((s) => s.watch(invoice)))).some(Boolean);
|
|
2525
1958
|
}
|
|
1959
|
+
/** A payer says it paid this invoice of ours: the card that made it asks its source about it now, and about nothing else. */
|
|
1960
|
+
async check(invoice) {
|
|
1961
|
+
return (await Promise.all(this.here().map((s) => s.check(invoice)))).some(Boolean);
|
|
1962
|
+
}
|
|
2526
1963
|
async recover() {
|
|
2527
1964
|
for (const s of this.here()) await s.recover();
|
|
2528
1965
|
}
|
|
@@ -2611,7 +2048,20 @@ var PEER_DB = "ghostly";
|
|
|
2611
2048
|
* non-extractable key; nothing writes it anywhere. Empty, every secret is sealed as today (version 1).
|
|
2612
2049
|
*/
|
|
2613
2050
|
var slot = null;
|
|
2051
|
+
/**
|
|
2052
|
+
* The profile's migration is over (no `migrating` mark): a sealed place then takes version 2 only. A version 1 or plain
|
|
2053
|
+
* value there was put by someone who could write the profile's database but not read it, and is refused.
|
|
2054
|
+
*/
|
|
2055
|
+
var sealedOnly = false;
|
|
2614
2056
|
var onDrop = /* @__PURE__ */ new Set();
|
|
2057
|
+
var LOCKED = "This profile is locked. Enter its passphrase first.";
|
|
2058
|
+
function hasDataKey() {
|
|
2059
|
+
return slot !== null;
|
|
2060
|
+
}
|
|
2061
|
+
/** Whether a sealed place may still hold a version 1 or plain value. */
|
|
2062
|
+
function takesUnsealed() {
|
|
2063
|
+
return !(slot && sealedOnly);
|
|
2064
|
+
}
|
|
2615
2065
|
/** A cache of opened secrets empties itself when the key goes. Returns the way to stop listening. */
|
|
2616
2066
|
function whenDataKeyDropped(drop) {
|
|
2617
2067
|
onDrop.add(drop);
|
|
@@ -2630,10 +2080,21 @@ async function sealSecret(value, at) {
|
|
|
2630
2080
|
deviceKey
|
|
2631
2081
|
};
|
|
2632
2082
|
}
|
|
2083
|
+
/** Version 2 only, for a field the database layer seals: refused while the profile is locked, never version 1. */
|
|
2084
|
+
async function sealPlace(value, at) {
|
|
2085
|
+
if (!slot) throw new Error(LOCKED);
|
|
2086
|
+
return sealField(slot, {
|
|
2087
|
+
db: PEER_DB,
|
|
2088
|
+
...at
|
|
2089
|
+
}, value);
|
|
2090
|
+
}
|
|
2633
2091
|
/** Reads both versions: a profile being encrypted holds some of each until its migration ends. */
|
|
2634
2092
|
async function openSecret(secret, at) {
|
|
2635
|
-
if (!isSealedField(secret))
|
|
2636
|
-
|
|
2093
|
+
if (!isSealedField(secret)) {
|
|
2094
|
+
if (!takesUnsealed()) throw new Error("A secret of this profile was not sealed with its key");
|
|
2095
|
+
return unsealSeed(secret.sealed, secret.deviceKey);
|
|
2096
|
+
}
|
|
2097
|
+
if (!slot) throw new Error(LOCKED);
|
|
2637
2098
|
return openField(slot, {
|
|
2638
2099
|
db: PEER_DB,
|
|
2639
2100
|
...at
|
|
@@ -2650,7 +2111,7 @@ var registry;
|
|
|
2650
2111
|
var loading;
|
|
2651
2112
|
var listeners = /* @__PURE__ */ new Set();
|
|
2652
2113
|
function loadIdentityProviders() {
|
|
2653
|
-
return loading ??= import("./registry-
|
|
2114
|
+
return loading ??= import("./registry-BN9r2pR4.js").then((m) => {
|
|
2654
2115
|
registry = m;
|
|
2655
2116
|
for (const listener of listeners) listener();
|
|
2656
2117
|
return m;
|
|
@@ -2673,10 +2134,21 @@ var KEY = "identityProofs";
|
|
|
2673
2134
|
var REVOCATIONS = "identityRevocations";
|
|
2674
2135
|
/** When the contacts' proofs were last looked up for a revocation (ms), so a reload does not look them all up again. */
|
|
2675
2136
|
var REVOCATIONS_CHECKED_AT = "identityRevocationsCheckedAt";
|
|
2137
|
+
/** The lookup under way: when it began (ms) and the proofs it already looked up (`linkId|id`), so one cut short goes on from the rest. */
|
|
2138
|
+
var REVOCATIONS_ROUND = "identityRevocationsRound";
|
|
2676
2139
|
/** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
|
|
2677
2140
|
var REPUBLISH_MS = 36e5;
|
|
2678
2141
|
/** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
|
|
2679
2142
|
var REVOCATION_CHECK_MS = 432e5;
|
|
2143
|
+
/** A lookup that could not run (offline, no relay answered) is tried again after this, doubled each time, up to the 12 h. */
|
|
2144
|
+
var REVOCATION_RETRY_MS = 3e5;
|
|
2145
|
+
/** A proof's lookup the relays' budget held back is read again when it frees, at most this many times; then the lookup stops there and goes on from it at its next try. */
|
|
2146
|
+
var BUDGET_TRIES = 5;
|
|
2147
|
+
/**
|
|
2148
|
+
* The 12 h lookup reads one proof key this often: 20 a minute, under half the relays' background share (44 a minute over
|
|
2149
|
+
* the three default relays), which the profile's DID, contact link and public profiles read through too.
|
|
2150
|
+
*/
|
|
2151
|
+
var REVOCATION_READ_GAP_MS = 3e3;
|
|
2680
2152
|
/**
|
|
2681
2153
|
* After a contact withdraws a proof, how long to wait before each lookup for its revocation (WISP 300: removing a proof withdraws it from
|
|
2682
2154
|
* every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
|
|
@@ -2687,6 +2159,18 @@ var WITHDRAWN_REVOCATION_TRIES_MS = [
|
|
|
2687
2159
|
6e4,
|
|
2688
2160
|
18e4
|
|
2689
2161
|
];
|
|
2162
|
+
/**
|
|
2163
|
+
* A contact's proof whose provider asks for re-checks is checked again on its own (the provider's check, as "Check
|
|
2164
|
+
* again" runs it) this long after its last check, or the provider's own interval when longer: a domain record or a
|
|
2165
|
+
* listed key that is gone then stops reading verified.
|
|
2166
|
+
*/
|
|
2167
|
+
var AUTO_RECHECK_AFTER_S = 86400;
|
|
2168
|
+
/** Due proofs are looked for this often (the first time a few minutes after the start), and only a few checked each time. */
|
|
2169
|
+
var AUTO_RECHECK_TICK_MS = 9e5;
|
|
2170
|
+
var AUTO_RECHECK_FIRST_MS = 18e4;
|
|
2171
|
+
var AUTO_RECHECK_BATCH = 3;
|
|
2172
|
+
/** A check that could not reach the server leaves the proof as it was and is tried again after this, doubling, at most a day. */
|
|
2173
|
+
var AUTO_RECHECK_BACKOFF_MS = 72e5;
|
|
2690
2174
|
/** A proof begun and not completed is dropped this long after, or when a fifth one begins (the CLI says the same). */
|
|
2691
2175
|
var IDENTITY_DRAFT_TTL_MS = 18e5;
|
|
2692
2176
|
var MAX_PROOFS = 32;
|
|
@@ -2702,7 +2186,27 @@ var IdentityProofs = class {
|
|
|
2702
2186
|
proofs = [];
|
|
2703
2187
|
revocations = [];
|
|
2704
2188
|
revocationsCheckedAt = 0;
|
|
2705
|
-
/**
|
|
2189
|
+
/** Revocation lookups in a row that could not run: the next waits `REVOCATION_RETRY_MS` doubled this many times less one. */
|
|
2190
|
+
lookupsMissed = 0;
|
|
2191
|
+
/** The lookup under way, if one was cut short (`REVOCATIONS_ROUND`). */
|
|
2192
|
+
round;
|
|
2193
|
+
/**
|
|
2194
|
+
* How the last Pkarr read of each contact's proof went (`revoked`), by proof id: answered, could not run (offline, no
|
|
2195
|
+
* relay answered), or held back by the relays' budget, which takes reads again in this many ms.
|
|
2196
|
+
*/
|
|
2197
|
+
reads = /* @__PURE__ */ new Map();
|
|
2198
|
+
/** When each contact's proof was last read for a revocation this run (ms), by proof id: the 12 h lookup reads the longest unread first. */
|
|
2199
|
+
lastRead = /* @__PURE__ */ new Map();
|
|
2200
|
+
lookupTimer;
|
|
2201
|
+
looking = false;
|
|
2202
|
+
/** Counted at each `stop`: a 12 h lookup under way ends there. */
|
|
2203
|
+
stops = 0;
|
|
2204
|
+
/** Ends the 12 h lookup's wait (between two reads, or for the budget) at once: `stop`. */
|
|
2205
|
+
wakeLookup;
|
|
2206
|
+
/** Revocations not published because the app was offline: published when the network comes back (`networkBack`). */
|
|
2207
|
+
unpublished = /* @__PURE__ */ new Set();
|
|
2208
|
+
running = false;
|
|
2209
|
+
/** "Clear all data" (`revokeAll`): a revocation lookup or a proof's save still on its way writes nothing. */
|
|
2706
2210
|
ended = false;
|
|
2707
2211
|
/** Unsealed proof-key seeds, by proof id, for this run only. */
|
|
2708
2212
|
seeds = /* @__PURE__ */ new Map();
|
|
@@ -2714,6 +2218,8 @@ var IdentityProofs = class {
|
|
|
2714
2218
|
errors = /* @__PURE__ */ new Map();
|
|
2715
2219
|
/** Chats whose current connection already got the hello: "ready" is reported more than once per connection. */
|
|
2716
2220
|
greeted = /* @__PURE__ */ new Set();
|
|
2221
|
+
/** Automatic re-checks that could not reach the server, by chat and proof: how many in a row, and when to try again (ms). */
|
|
2222
|
+
recheckBackoff = /* @__PURE__ */ new Map();
|
|
2717
2223
|
fetch;
|
|
2718
2224
|
constructor(host, providers = loadedIdentityProviders) {
|
|
2719
2225
|
this.host = host;
|
|
@@ -2724,15 +2230,17 @@ var IdentityProofs = class {
|
|
|
2724
2230
|
async load() {
|
|
2725
2231
|
const providers = loadIdentityProviders();
|
|
2726
2232
|
const settings = await store(STORES.settings, "readonly");
|
|
2727
|
-
[this.proofs, this.revocations, this.revocationsCheckedAt] = await Promise.all([
|
|
2233
|
+
[this.proofs, this.revocations, this.revocationsCheckedAt, this.round] = await Promise.all([
|
|
2728
2234
|
wrap(settings.get(KEY)).then((v) => v ?? []),
|
|
2729
2235
|
wrap(settings.get(REVOCATIONS)).then((v) => v ?? []),
|
|
2730
|
-
wrap(settings.get(REVOCATIONS_CHECKED_AT)).then((v) => typeof v === "number" ? v : 0)
|
|
2236
|
+
wrap(settings.get(REVOCATIONS_CHECKED_AT)).then((v) => typeof v === "number" ? v : 0),
|
|
2237
|
+
wrap(settings.get(REVOCATIONS_ROUND)).then((v) => typeof v?.startedAt === "number" && Array.isArray(v.done) ? v : void 0)
|
|
2731
2238
|
]);
|
|
2732
2239
|
await providers;
|
|
2733
2240
|
}
|
|
2734
2241
|
/** Background work: republish revocations, look up the contacts' proofs for revocations. */
|
|
2735
2242
|
start() {
|
|
2243
|
+
this.running = true;
|
|
2736
2244
|
const every = (ms, first, work) => {
|
|
2737
2245
|
const tick = () => {
|
|
2738
2246
|
work().catch(() => {}).finally(() => {
|
|
@@ -2743,12 +2251,42 @@ var IdentityProofs = class {
|
|
|
2743
2251
|
};
|
|
2744
2252
|
every(REPUBLISH_MS, 5e3, () => this.republish());
|
|
2745
2253
|
const due = Math.min(REVOCATION_CHECK_MS, this.revocationsCheckedAt + REVOCATION_CHECK_MS - Date.now());
|
|
2746
|
-
|
|
2254
|
+
this.lookUpIn(Math.max(6e4, due));
|
|
2255
|
+
every(AUTO_RECHECK_TICK_MS, AUTO_RECHECK_FIRST_MS, () => this.recheckDue());
|
|
2747
2256
|
this.unlisten ??= whenDataKeyDropped(() => this.forgetSeeds());
|
|
2748
2257
|
}
|
|
2258
|
+
/** The network is back: a revocation lookup that could not run, and a revocation not published offline, go now. */
|
|
2259
|
+
networkBack() {
|
|
2260
|
+
if (!this.running || this.ended) return;
|
|
2261
|
+
if (this.lookupsMissed > 0) this.lookUpIn(0);
|
|
2262
|
+
for (const r of this.revocations) if (this.unpublished.has(r.id) && r.expiresAt > now()) this.publishRevocation(r).catch(() => {});
|
|
2263
|
+
}
|
|
2264
|
+
lookUpIn(ms) {
|
|
2265
|
+
if (this.lookupTimer) clearTimeout(this.lookupTimer);
|
|
2266
|
+
const timer = this.lookupTimer = setTimeout(() => {
|
|
2267
|
+
this.timers = this.timers.filter((t) => t !== timer);
|
|
2268
|
+
this.lookupTimer = void 0;
|
|
2269
|
+
this.lookUp();
|
|
2270
|
+
}, ms);
|
|
2271
|
+
this.timers.push(timer);
|
|
2272
|
+
}
|
|
2273
|
+
/** A lookup done waits 12 h for the next; one that could not run is tried again sooner, backing off. */
|
|
2274
|
+
async lookUp() {
|
|
2275
|
+
if (this.looking) return;
|
|
2276
|
+
this.looking = true;
|
|
2277
|
+
const done = await this.checkRevocations().catch(() => false);
|
|
2278
|
+
this.looking = false;
|
|
2279
|
+
if (!this.running) return;
|
|
2280
|
+
this.lookupsMissed = done ? 0 : this.lookupsMissed + 1;
|
|
2281
|
+
this.lookUpIn(done ? REVOCATION_CHECK_MS : Math.min(REVOCATION_CHECK_MS, REVOCATION_RETRY_MS * 2 ** (this.lookupsMissed - 1)));
|
|
2282
|
+
}
|
|
2749
2283
|
stop() {
|
|
2284
|
+
this.running = false;
|
|
2285
|
+
this.stops++;
|
|
2750
2286
|
for (const t of this.timers) clearTimeout(t);
|
|
2751
2287
|
this.timers = [];
|
|
2288
|
+
this.lookupTimer = void 0;
|
|
2289
|
+
this.wakeLookup?.();
|
|
2752
2290
|
this.unlisten?.();
|
|
2753
2291
|
this.unlisten = void 0;
|
|
2754
2292
|
this.forgetSeeds();
|
|
@@ -2763,6 +2301,7 @@ var IdentityProofs = class {
|
|
|
2763
2301
|
*/
|
|
2764
2302
|
save(change) {
|
|
2765
2303
|
const run = this.saving.then(async () => {
|
|
2304
|
+
if (this.ended) throw new Error("This profile's data was cleared");
|
|
2766
2305
|
const [proofs, revocations] = change(this.proofs, this.revocations);
|
|
2767
2306
|
await transact([STORES.settings], (stores) => {
|
|
2768
2307
|
stores[STORES.settings].put(proofs, KEY);
|
|
@@ -2799,7 +2338,7 @@ var IdentityProofs = class {
|
|
|
2799
2338
|
*/
|
|
2800
2339
|
verifyContact = async (statement, evidence) => {
|
|
2801
2340
|
if (!this.host.relayOnly?.()) return this.verify(statement, evidence);
|
|
2802
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
2341
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-B4E4VrYE.js");
|
|
2803
2342
|
const fixed = fixedIdentityHosts();
|
|
2804
2343
|
let refused;
|
|
2805
2344
|
const fetch = async (url, options) => {
|
|
@@ -2817,9 +2356,21 @@ var IdentityProofs = class {
|
|
|
2817
2356
|
throw e;
|
|
2818
2357
|
}
|
|
2819
2358
|
};
|
|
2359
|
+
/**
|
|
2360
|
+
* The exchange reads a lookup that failed as "not revoked": noted here (`reads`), so the 12 h lookup looks that proof
|
|
2361
|
+
* up again. One the relays' budget held back is kept apart: the lookup waits for the budget and reads it again.
|
|
2362
|
+
*/
|
|
2820
2363
|
revoked = async (statement) => {
|
|
2821
|
-
if (!this.host.online())
|
|
2822
|
-
|
|
2364
|
+
if (!this.host.online()) {
|
|
2365
|
+
this.reads.set(statement.id, "failed");
|
|
2366
|
+
return false;
|
|
2367
|
+
}
|
|
2368
|
+
const records = await this.host.resolve(statement.binding.key).catch((e) => {
|
|
2369
|
+
this.reads.set(statement.id, isDiscoveryBudgetError(e) ? budgetRetryMs(e, 1e3, 6e4) : "failed");
|
|
2370
|
+
throw e;
|
|
2371
|
+
});
|
|
2372
|
+
this.reads.set(statement.id, "answered");
|
|
2373
|
+
this.lastRead.set(statement.id, Date.now());
|
|
2823
2374
|
return !!records && revokesIdentity(records, statement.id);
|
|
2824
2375
|
};
|
|
2825
2376
|
async local(id) {
|
|
@@ -2868,6 +2419,7 @@ var IdentityProofs = class {
|
|
|
2868
2419
|
if (!draft) throw new Error("This proof was started too long ago. Start again.");
|
|
2869
2420
|
const statement = identityStatement(draft.binding);
|
|
2870
2421
|
const verified = await this.verify(statement, JSON.parse(JSON.stringify(evidence ?? null)));
|
|
2422
|
+
if (this.drafts.get(draftId) !== draft) throw new Error("This proof was started too long ago. Start again.");
|
|
2871
2423
|
if (this.proofs.length >= MAX_PROOFS) throw new Error("Remove an identity first");
|
|
2872
2424
|
this.drafts.delete(draftId);
|
|
2873
2425
|
const stored = {
|
|
@@ -2941,7 +2493,11 @@ var IdentityProofs = class {
|
|
|
2941
2493
|
return !!p.shared || this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
|
|
2942
2494
|
}
|
|
2943
2495
|
async publishRevocation(r) {
|
|
2944
|
-
if (!this.host.online())
|
|
2496
|
+
if (!this.host.online()) {
|
|
2497
|
+
this.unpublished.add(r.id);
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
this.unpublished.delete(r.id);
|
|
2945
2501
|
await this.host.publish(await this.seedOf(r.id, r.seed), [{
|
|
2946
2502
|
label: IDENTITY_REVOCATION_LABEL,
|
|
2947
2503
|
value: identityRevocationValue(r.id, r.revokedAt)
|
|
@@ -2961,18 +2517,118 @@ var IdentityProofs = class {
|
|
|
2961
2517
|
/**
|
|
2962
2518
|
* Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
|
|
2963
2519
|
* ones withdrawn, which a removal also revokes. Not a proof already revoked, nor one past its expiry: its owner
|
|
2964
|
-
* publishes the revocation only until then.
|
|
2520
|
+
* publishes the revocation only until then. True when every lookup was answered: only then is its time noted.
|
|
2521
|
+
*
|
|
2522
|
+
* Each proof answered is noted in the lookup under way (`round`, kept across a restart): one cut short (a read that
|
|
2523
|
+
* failed, the relays' budget still held after its tries, the network gone, the app stopped) goes on later from the
|
|
2524
|
+
* proofs still to look up. Started again from the first, a few keys no relay answered cost every proof's read again.
|
|
2525
|
+
*
|
|
2526
|
+
* One read every `REVOCATION_READ_GAP_MS`, the longest unread first: read back to back, the lookup took the relays'
|
|
2527
|
+
* whole background share for a minute, and every read past it was held back.
|
|
2965
2528
|
*/
|
|
2966
2529
|
async checkRevocations() {
|
|
2967
|
-
if (!this.host.online()) return;
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2530
|
+
if (!this.host.online()) return false;
|
|
2531
|
+
const at = Date.now();
|
|
2532
|
+
if (!this.round || at - this.round.startedAt >= REVOCATION_CHECK_MS || this.round.startedAt > at) this.round = {
|
|
2533
|
+
startedAt: at,
|
|
2534
|
+
done: []
|
|
2535
|
+
};
|
|
2536
|
+
const round = this.round, done = new Set(round.done);
|
|
2537
|
+
const todo = this.host.linkIds().flatMap((linkId) => (this.host.ledger(linkId)?.received ?? []).filter((r) => this.revocable(r) && !done.has(`${linkId}|${r.id}`)).map((r) => ({
|
|
2538
|
+
linkId,
|
|
2539
|
+
id: r.id
|
|
2540
|
+
}))).sort((a, b) => (this.lastRead.get(a.id) ?? 0) - (this.lastRead.get(b.id) ?? 0));
|
|
2541
|
+
let missed = false, wait = 0;
|
|
2542
|
+
const stops = this.stops;
|
|
2543
|
+
try {
|
|
2544
|
+
for (const { linkId, id } of todo) for (let tries = 0;; tries++) {
|
|
2545
|
+
if (wait > 0 && !await this.lookupPause(wait)) return false;
|
|
2546
|
+
if (this.ended || this.stops !== stops) return false;
|
|
2547
|
+
if (!this.host.online()) return false;
|
|
2548
|
+
this.reads.delete(id);
|
|
2549
|
+
await this.exchange(linkId)?.recheck(id, { revocationOnly: true }).catch(() => {});
|
|
2550
|
+
const read = this.reads.get(id);
|
|
2551
|
+
wait = typeof read === "number" ? read : REVOCATION_READ_GAP_MS;
|
|
2552
|
+
if (read === "failed") {
|
|
2553
|
+
missed = true;
|
|
2554
|
+
break;
|
|
2555
|
+
}
|
|
2556
|
+
if (typeof read !== "number") {
|
|
2557
|
+
round.done.push(`${linkId}|${id}`);
|
|
2558
|
+
this.saveRound(round);
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
if (tries >= BUDGET_TRIES) return false;
|
|
2562
|
+
}
|
|
2563
|
+
} finally {
|
|
2564
|
+
this.reads.clear();
|
|
2971
2565
|
}
|
|
2972
|
-
if (this.ended) return;
|
|
2566
|
+
if (this.ended || missed) return false;
|
|
2973
2567
|
this.revocationsCheckedAt = Date.now();
|
|
2568
|
+
if (this.round === round) this.round = void 0;
|
|
2974
2569
|
await transact([STORES.settings], (stores) => {
|
|
2975
2570
|
stores[STORES.settings].put(this.revocationsCheckedAt, REVOCATIONS_CHECKED_AT);
|
|
2571
|
+
stores[STORES.settings].delete(REVOCATIONS_ROUND);
|
|
2572
|
+
});
|
|
2573
|
+
return true;
|
|
2574
|
+
}
|
|
2575
|
+
/** Not waited on: the writes keep their order, so the lookup's end (which deletes it) lands after. */
|
|
2576
|
+
saveRound(round) {
|
|
2577
|
+
if (this.ended || this.round !== round) return;
|
|
2578
|
+
transact([STORES.settings], (stores) => {
|
|
2579
|
+
stores[STORES.settings].put({
|
|
2580
|
+
...round,
|
|
2581
|
+
done: [...round.done]
|
|
2582
|
+
}, REVOCATIONS_ROUND);
|
|
2583
|
+
}).catch(() => {});
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* The contacts' proofs due for an automatic re-check (`AUTO_RECHECK_AFTER_S`), the longest unchecked first, a few at a
|
|
2587
|
+
* time, one after the other. A proof whose record or key is gone shows unconfirmed with the reason, as after "Check
|
|
2588
|
+
* again"; one whose server could not be reached (or a network that went away meanwhile) is left as it was and backs off.
|
|
2589
|
+
*/
|
|
2590
|
+
async recheckDue() {
|
|
2591
|
+
if (!this.host.online()) return;
|
|
2592
|
+
const t = now(), at = Date.now();
|
|
2593
|
+
const due = [];
|
|
2594
|
+
for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) {
|
|
2595
|
+
const after = this.providers().find((p) => p.id === r.binding.provider)?.recheck?.afterSeconds;
|
|
2596
|
+
if (after === void 0 || r.status !== "verified" && r.status !== "unconfirmed" || !this.revocable(r)) continue;
|
|
2597
|
+
if (t - r.checkedAt < Math.max(after, 86400) || (this.recheckBackoff.get(`${linkId}|${r.id}`)?.until ?? 0) > at) continue;
|
|
2598
|
+
due.push({
|
|
2599
|
+
linkId,
|
|
2600
|
+
r
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
for (const { linkId, r } of due.sort((a, b) => a.r.checkedAt - b.r.checkedAt).slice(0, AUTO_RECHECK_BATCH)) {
|
|
2604
|
+
if (this.ended || !this.host.online()) return;
|
|
2605
|
+
const key = `${linkId}|${r.id}`;
|
|
2606
|
+
try {
|
|
2607
|
+
await this.exchange(linkId)?.recheck(r.id, { keepUnavailable: true });
|
|
2608
|
+
this.recheckBackoff.delete(key);
|
|
2609
|
+
} catch {
|
|
2610
|
+
const failures = (this.recheckBackoff.get(key)?.failures ?? 0) + 1;
|
|
2611
|
+
this.recheckBackoff.set(key, {
|
|
2612
|
+
failures,
|
|
2613
|
+
until: Date.now() + Math.min(AUTO_RECHECK_BACKOFF_MS * 2 ** (failures - 1), AUTO_RECHECK_AFTER_S * 1e3)
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
/** The 12 h lookup's wait between two reads, or for the budget: false when `stop` ended it. */
|
|
2619
|
+
lookupPause(ms) {
|
|
2620
|
+
return new Promise((resolve) => {
|
|
2621
|
+
const timer = setTimeout(() => {
|
|
2622
|
+
this.timers = this.timers.filter((t) => t !== timer);
|
|
2623
|
+
this.wakeLookup = void 0;
|
|
2624
|
+
resolve(true);
|
|
2625
|
+
}, ms);
|
|
2626
|
+
this.timers.push(timer);
|
|
2627
|
+
this.wakeLookup = () => {
|
|
2628
|
+
clearTimeout(timer);
|
|
2629
|
+
this.wakeLookup = void 0;
|
|
2630
|
+
resolve(false);
|
|
2631
|
+
};
|
|
2976
2632
|
});
|
|
2977
2633
|
}
|
|
2978
2634
|
revocable(r) {
|
|
@@ -3101,9 +2757,11 @@ var IdentityProofs = class {
|
|
|
3101
2757
|
async frame(linkId, frame) {
|
|
3102
2758
|
const x = this.exchange(linkId);
|
|
3103
2759
|
if (!x) return;
|
|
3104
|
-
const
|
|
2760
|
+
const id = frame.t === "idp-withdraw" && typeof frame.id === "string" ? frame.id : frame.t === "idp-present" && isIdentityBinding(frame.binding) ? identityStatement(frame.binding).id : void 0;
|
|
2761
|
+
const withdrawn = () => !!id && !!this.host.ledger(linkId)?.received.some((r) => r.id === id && r.status === "withdrawn");
|
|
2762
|
+
const before = withdrawn();
|
|
3105
2763
|
await x.receive(frame);
|
|
3106
|
-
if (
|
|
2764
|
+
if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
|
|
3107
2765
|
}
|
|
3108
2766
|
ready(linkId) {
|
|
3109
2767
|
if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
|
|
@@ -3583,7 +3241,7 @@ var GroupFileDesk = class {
|
|
|
3583
3241
|
groupId,
|
|
3584
3242
|
message: file.group.message,
|
|
3585
3243
|
author: file.group.author,
|
|
3586
|
-
...file.group.
|
|
3244
|
+
...file.group.arrived !== void 0 && { arrived: file.group.arrived },
|
|
3587
3245
|
meta: {
|
|
3588
3246
|
name,
|
|
3589
3247
|
size,
|
|
@@ -3736,8 +3394,10 @@ var GroupFileDesk = class {
|
|
|
3736
3394
|
*/
|
|
3737
3395
|
async announced(groupId, m, me) {
|
|
3738
3396
|
const known = this.byMessage.get(`${groupId}\n${m.id}`);
|
|
3739
|
-
if (known)
|
|
3740
|
-
|
|
3397
|
+
if (known) {
|
|
3398
|
+
this.arrivedAgain(groupId, m.id, m.epoch);
|
|
3399
|
+
return messageFile(this.kept.get(known));
|
|
3400
|
+
}
|
|
3741
3401
|
const ownId = m.sender === me ? this.own.get(`${groupId}\n${m.file.d}`) : void 0;
|
|
3742
3402
|
if (ownId) {
|
|
3743
3403
|
this.own.delete(`${groupId}\n${m.file.d}`);
|
|
@@ -3747,7 +3407,6 @@ var GroupFileDesk = class {
|
|
|
3747
3407
|
groupId,
|
|
3748
3408
|
message: m.id,
|
|
3749
3409
|
author: me,
|
|
3750
|
-
ts,
|
|
3751
3410
|
meta: m.file,
|
|
3752
3411
|
mine: true,
|
|
3753
3412
|
auto: false,
|
|
@@ -3765,8 +3424,7 @@ var GroupFileDesk = class {
|
|
|
3765
3424
|
await this.deps.store.patch(ownId, {
|
|
3766
3425
|
group: {
|
|
3767
3426
|
message: m.id,
|
|
3768
|
-
author: me
|
|
3769
|
-
ts
|
|
3427
|
+
author: me
|
|
3770
3428
|
},
|
|
3771
3429
|
transfer
|
|
3772
3430
|
}).catch(() => {});
|
|
@@ -3779,12 +3437,13 @@ var GroupFileDesk = class {
|
|
|
3779
3437
|
const auto = paced && this.deps.settings().autoDownloads && fetchesByItself(m.file, this.keptAutomatically(groupId)) && await this.hasRoom(m.file.size);
|
|
3780
3438
|
const holders = this.ahead.get(`${groupId}\n${m.id}`) ?? [];
|
|
3781
3439
|
this.ahead.delete(`${groupId}\n${m.id}`);
|
|
3440
|
+
const arrived = laterEpoch(m.id, m.epoch);
|
|
3782
3441
|
const kept = {
|
|
3783
3442
|
id,
|
|
3784
3443
|
groupId,
|
|
3785
3444
|
message: m.id,
|
|
3786
3445
|
author: m.sender,
|
|
3787
|
-
|
|
3446
|
+
...arrived !== void 0 && { arrived },
|
|
3788
3447
|
meta: m.file,
|
|
3789
3448
|
mine: false,
|
|
3790
3449
|
auto,
|
|
@@ -3818,7 +3477,7 @@ var GroupFileDesk = class {
|
|
|
3818
3477
|
group: {
|
|
3819
3478
|
message: m.id,
|
|
3820
3479
|
author: m.sender,
|
|
3821
|
-
|
|
3480
|
+
...arrived !== void 0 && { arrived },
|
|
3822
3481
|
...auto && { auto: true }
|
|
3823
3482
|
}
|
|
3824
3483
|
});
|
|
@@ -3828,6 +3487,17 @@ var GroupFileDesk = class {
|
|
|
3828
3487
|
} else this.waiting(kept);
|
|
3829
3488
|
return messageFile(kept);
|
|
3830
3489
|
}
|
|
3490
|
+
/**
|
|
3491
|
+
* A message whose file is known here reached this device again, said again by its author under a later epoch (it was
|
|
3492
|
+
* behind): that epoch's members could read it too, and are served it.
|
|
3493
|
+
*/
|
|
3494
|
+
arrivedAgain(groupId, messageId, epoch) {
|
|
3495
|
+
const kept = this.kept.get(this.byMessage.get(`${groupId}\n${messageId}`) ?? "");
|
|
3496
|
+
const arrived = laterEpoch(messageId, epoch);
|
|
3497
|
+
if (!kept || arrived === void 0 || arrived <= (kept.arrived ?? -1)) return;
|
|
3498
|
+
kept.arrived = arrived;
|
|
3499
|
+
this.deps.store.patch(kept.id, { group: this.groupField(kept) }).catch(() => {});
|
|
3500
|
+
}
|
|
3831
3501
|
/** The person asks for a file this device did not fetch by itself (Download), or for one that stopped coming. */
|
|
3832
3502
|
async download(fileId) {
|
|
3833
3503
|
const kept = this.kept.get(fileId);
|
|
@@ -3895,7 +3565,8 @@ var GroupFileDesk = class {
|
|
|
3895
3565
|
async frame(groupId, peer, linkId, frame) {
|
|
3896
3566
|
if (frame.t === "group-want") {
|
|
3897
3567
|
const want = readGroupWant(frame, groupId);
|
|
3898
|
-
|
|
3568
|
+
const edge = want && this.edge(groupId, peer, linkId);
|
|
3569
|
+
if (edge && edge.wantTaken.take()) await this.serve(edge, want.id);
|
|
3899
3570
|
} else if (frame.t === "group-want-no") {
|
|
3900
3571
|
const no = readGroupWantNo(frame, groupId);
|
|
3901
3572
|
if (no) this.refused(groupId, peer, linkId, no.id, no.why);
|
|
@@ -3967,6 +3638,13 @@ var GroupFileDesk = class {
|
|
|
3967
3638
|
this.ask(kept);
|
|
3968
3639
|
}
|
|
3969
3640
|
this.letGo();
|
|
3641
|
+
this.makeRoomForWaiting();
|
|
3642
|
+
const freed = /* @__PURE__ */ new Set();
|
|
3643
|
+
for (const edge of this.edgesById.values()) if (edge.wantPaced && !this.paced(edge.linkId)) {
|
|
3644
|
+
edge.wantPaced = false;
|
|
3645
|
+
freed.add(edge.groupId);
|
|
3646
|
+
}
|
|
3647
|
+
for (const groupId of freed) this.retry(groupId);
|
|
3970
3648
|
for (const edge of this.edgesById.values()) if (edge.have.size && this.deps.ready(edge.linkId)) this.sendHave(edge, [...edge.have]);
|
|
3971
3649
|
for (const [groupId, have] of this.communityHave) {
|
|
3972
3650
|
if (!have.ids.size || now - have.at < GROUP_FILE_LIMITS.communityHaveEveryMs) continue;
|
|
@@ -4008,7 +3686,11 @@ var GroupFileDesk = class {
|
|
|
4008
3686
|
}
|
|
4009
3687
|
/** The group's edges that are up, with files/3 live and no file asked of their member: a want could be asked on them. */
|
|
4010
3688
|
freeEdges(groupId) {
|
|
4011
|
-
return [...this.deps.edges(groupId)].filter(([, linkId]) => this.deps.ready(linkId) && this.edgesById.get(linkId)?.files.live && !this.askedOf(linkId));
|
|
3689
|
+
return [...this.deps.edges(groupId)].filter(([, linkId]) => this.deps.ready(linkId) && this.edgesById.get(linkId)?.files.live && !this.askedOf(linkId) && !this.paced(linkId));
|
|
3690
|
+
}
|
|
3691
|
+
/** This device sent as many wants on the edge as its window takes (`wantFrames`). */
|
|
3692
|
+
paced(linkId) {
|
|
3693
|
+
return !!this.edgesById.get(linkId)?.wantSent.wait();
|
|
4012
3694
|
}
|
|
4013
3695
|
/** One of these free edges (member key, link id) is one `ask` would ask this want on: asked now, it would not only queue again. */
|
|
4014
3696
|
freeFor(kept, want, free) {
|
|
@@ -4016,7 +3698,7 @@ var GroupFileDesk = class {
|
|
|
4016
3698
|
if (!membership) return false;
|
|
4017
3699
|
const known = this.knownHolders(kept, membership);
|
|
4018
3700
|
const others = !this.waitForKnown(kept, want, known, this.deps.edges(kept.groupId));
|
|
4019
|
-
return free.some(([key, linkId]) => this.mayAsk(kept, want, key, linkId) && (known.includes(key) || others && key !== membership.me && membership.couldRead(key, kept.message, kept.
|
|
3701
|
+
return free.some(([key, linkId]) => this.mayAsk(kept, want, key, linkId) && (known.includes(key) || others && key !== membership.me && membership.couldRead(key, kept.message, kept.arrived)));
|
|
4020
3702
|
}
|
|
4021
3703
|
/** The members known to hold the file (its author first), in the group's roster, but this device. */
|
|
4022
3704
|
knownHolders(kept, membership) {
|
|
@@ -4032,7 +3714,7 @@ var GroupFileDesk = class {
|
|
|
4032
3714
|
waitForKnown(kept, want, known, edges) {
|
|
4033
3715
|
if (!known.includes(kept.author)) return false;
|
|
4034
3716
|
const linkId = edges.get(kept.author) ?? "";
|
|
4035
|
-
return this.deps.ready(linkId) && (!!want.busy?.has(kept.author) || this.askedOf(linkId, want));
|
|
3717
|
+
return this.deps.ready(linkId) && (!!want.busy?.has(kept.author) || this.askedOf(linkId, want) || this.paced(linkId));
|
|
4036
3718
|
}
|
|
4037
3719
|
/** The want may ask this member in this round: not asked yet, it did not serve it damaged, and did not say it is gone. */
|
|
4038
3720
|
mayAsk(kept, want, key, linkId) {
|
|
@@ -4057,7 +3739,7 @@ var GroupFileDesk = class {
|
|
|
4057
3739
|
this.stopFailed(kept);
|
|
4058
3740
|
return;
|
|
4059
3741
|
}
|
|
4060
|
-
const others = this.waitForKnown(kept, want, known, edges) ? [] : [...edges.keys()].filter((key) => !known.includes(key) && membership && key !== membership.me && membership.couldRead(key, kept.message, kept.
|
|
3742
|
+
const others = this.waitForKnown(kept, want, known, edges) ? [] : [...edges.keys()].filter((key) => !known.includes(key) && membership && key !== membership.me && membership.couldRead(key, kept.message, kept.arrived));
|
|
4061
3743
|
const order = [...known, ...others].filter((key) => this.mayAsk(kept, want, key, edges.get(key)));
|
|
4062
3744
|
if (kept.left && order.includes(kept.left)) order.push(...order.splice(order.indexOf(kept.left), 1));
|
|
4063
3745
|
for (const key of order.filter((key) => kept.suspect?.has(key))) order.push(...order.splice(order.indexOf(key), 1));
|
|
@@ -4069,6 +3751,11 @@ var GroupFileDesk = class {
|
|
|
4069
3751
|
behind = true;
|
|
4070
3752
|
continue;
|
|
4071
3753
|
}
|
|
3754
|
+
if (this.paced(linkId)) {
|
|
3755
|
+
this.edgesById.get(linkId).wantPaced = true;
|
|
3756
|
+
behind = true;
|
|
3757
|
+
continue;
|
|
3758
|
+
}
|
|
4072
3759
|
Object.assign(want, {
|
|
4073
3760
|
holder: key,
|
|
4074
3761
|
linkId,
|
|
@@ -4078,6 +3765,7 @@ var GroupFileDesk = class {
|
|
|
4078
3765
|
id: kept.id,
|
|
4079
3766
|
want
|
|
4080
3767
|
});
|
|
3768
|
+
this.edgesById.get(linkId).wantSent.take();
|
|
4081
3769
|
if (!this.deps.send(linkId, {
|
|
4082
3770
|
t: "group-want",
|
|
4083
3771
|
g: kept.groupId,
|
|
@@ -4245,7 +3933,7 @@ var GroupFileDesk = class {
|
|
|
4245
3933
|
async serve(edge, messageId) {
|
|
4246
3934
|
const kept = this.kept.get(this.byMessage.get(`${edge.groupId}\n${messageId}`) ?? "");
|
|
4247
3935
|
const here = !!kept?.held && !!await this.deps.store.get(kept.id).catch(() => void 0);
|
|
4248
|
-
const why = this.mayServe(edge, messageId, here ? kept : void 0, kept?.
|
|
3936
|
+
const why = this.mayServe(edge, messageId, here ? kept : void 0, kept?.arrived);
|
|
4249
3937
|
if (why || !kept) {
|
|
4250
3938
|
this.deps.send(edge.linkId, {
|
|
4251
3939
|
t: GROUP_WANT_NO_FRAME,
|
|
@@ -4280,9 +3968,9 @@ var GroupFileDesk = class {
|
|
|
4280
3968
|
* someone who could not read the announcement, `gone` when it is not here (`kept` undefined), `busy` when serving is
|
|
4281
3969
|
* off or full, `day` when this device served its bytes for the day (`serveBytesPerDay`).
|
|
4282
3970
|
*/
|
|
4283
|
-
mayServe(edge, messageId, kept,
|
|
3971
|
+
mayServe(edge, messageId, kept, arrived) {
|
|
4284
3972
|
const membership = this.deps.membership(edge.groupId);
|
|
4285
|
-
if (!membership || !membership.couldRead(edge.peer, messageId,
|
|
3973
|
+
if (!membership || !membership.couldRead(edge.peer, messageId, arrived)) return "refused";
|
|
4286
3974
|
if (!kept) return "gone";
|
|
4287
3975
|
if (!this.deps.settings().serveFiles || !edge.files.live) return "busy";
|
|
4288
3976
|
this.letGo();
|
|
@@ -4290,7 +3978,7 @@ var GroupFileDesk = class {
|
|
|
4290
3978
|
const theirs = active.filter((a) => a.peer === edge.peer);
|
|
4291
3979
|
const placed = theirs.length > 1 || theirs.some((a) => a.sending || this.deps.now() - a.since >= GROUP_FILE_LIMITS.doneWaitMs);
|
|
4292
3980
|
if (active.length >= GROUP_FILE_LIMITS.serveAtOnce && (placed || !this.makeRoom())) {
|
|
4293
|
-
edge.busy.
|
|
3981
|
+
edge.busy.set(messageId, this.deps.now());
|
|
4294
3982
|
return "busy";
|
|
4295
3983
|
}
|
|
4296
3984
|
if (placed) return "busy";
|
|
@@ -4302,23 +3990,51 @@ var GroupFileDesk = class {
|
|
|
4302
3990
|
const reserved = this.servingNow().reduce((sum, a) => sum + a.size, 0);
|
|
4303
3991
|
return this.served.bytes + reserved + kept.meta.size > GROUP_FILE_LIMITS.serveBytesPerDay ? "day" : null;
|
|
4304
3992
|
}
|
|
4305
|
-
/**
|
|
3993
|
+
/**
|
|
3994
|
+
* Ends a served transfer for a member that holds no place: the one that has held its place longest, once past
|
|
3995
|
+
* `servePaceMs`; else the slowest of those under way for `servePaceMs` with more left to go at their pace than they
|
|
3996
|
+
* have been served (and than `servePaceMs`), each member's file once (its asker goes on from what it stored, from the
|
|
3997
|
+
* next holder or this one, and the members on fast links do not wait for the slow ones that asked first). False when
|
|
3998
|
+
* none is.
|
|
3999
|
+
*/
|
|
4306
4000
|
makeRoom() {
|
|
4307
4001
|
const now = this.deps.now();
|
|
4308
4002
|
let oldest;
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4003
|
+
let slowest;
|
|
4004
|
+
for (const edge of this.edgesById.values()) for (const [wire, id] of edge.serving) {
|
|
4005
|
+
const record = edge.files.get("out", wire), moved = edge.servedMoved.get(wire), from = moved?.from ?? now;
|
|
4006
|
+
if (!record || transferEnded(record)) continue;
|
|
4007
|
+
if (now - from >= GROUP_FILE_LIMITS.servePlaceMs && (!oldest || from < oldest.from)) oldest = {
|
|
4312
4008
|
edge,
|
|
4313
4009
|
wire,
|
|
4314
4010
|
from
|
|
4315
4011
|
};
|
|
4012
|
+
if (!moved?.mark || now - moved.mark[1] < GROUP_FILE_LIMITS.servePaceMs || edge.paced.has(id) || record.confirmed >= record.file.size) continue;
|
|
4013
|
+
const pace = (record.confirmed - moved.mark[0]) / (now - moved.mark[1]);
|
|
4014
|
+
if (pace > 0 && (record.file.size - record.confirmed) / pace <= Math.max(GROUP_FILE_LIMITS.servePaceMs, now - from)) continue;
|
|
4015
|
+
if (!slowest || pace < slowest.pace) slowest = {
|
|
4016
|
+
edge,
|
|
4017
|
+
wire,
|
|
4018
|
+
pace
|
|
4019
|
+
};
|
|
4316
4020
|
}
|
|
4317
|
-
|
|
4318
|
-
|
|
4021
|
+
const cut = oldest ?? slowest;
|
|
4022
|
+
if (!cut) return false;
|
|
4023
|
+
if (!oldest) cut.edge.paced.add(cut.edge.serving.get(cut.wire));
|
|
4024
|
+
cut.edge.files.cancel("out", cut.wire);
|
|
4319
4025
|
return true;
|
|
4320
4026
|
}
|
|
4321
4027
|
/**
|
|
4028
|
+
* A member turned away as busy within `wantWaitMs`, holding no place, waits for the holder's word that a place freed:
|
|
4029
|
+
* it is made one as when it asks (`makeRoom`), and hears so.
|
|
4030
|
+
*/
|
|
4031
|
+
makeRoomForWaiting() {
|
|
4032
|
+
if (!this.deps.settings().serveFiles) return;
|
|
4033
|
+
const active = this.servingNow(), now = this.deps.now();
|
|
4034
|
+
if (active.length < GROUP_FILE_LIMITS.serveAtOnce) return;
|
|
4035
|
+
if ([...this.edgesById.values()].some((edge) => edge.files.live && !active.some((a) => a.peer === edge.peer) && [...edge.busy.values()].some((at) => now - at < GROUP_FILE_LIMITS.wantWaitMs))) this.makeRoom();
|
|
4036
|
+
}
|
|
4037
|
+
/**
|
|
4322
4038
|
* Transfers served now, all groups together: to whom, what each takes of the day (its size, or what it sent when that
|
|
4323
4039
|
* is more), whether bytes are still to go, and since when it has not gone further.
|
|
4324
4040
|
*/
|
|
@@ -4371,6 +4087,11 @@ var GroupFileDesk = class {
|
|
|
4371
4087
|
if (gone || overtaken || now - moved.at >= GROUP_FILE_LIMITS.wantWaitMs) {
|
|
4372
4088
|
edge.files.cancel("out", wire);
|
|
4373
4089
|
theirs.set(edge.peer, theirs.get(edge.peer) - 1);
|
|
4090
|
+
continue;
|
|
4091
|
+
}
|
|
4092
|
+
if (moved.next && now - moved.next[1] >= GROUP_FILE_LIMITS.servePaceMs) {
|
|
4093
|
+
moved.mark = moved.next;
|
|
4094
|
+
moved.next = [record.confirmed, now];
|
|
4374
4095
|
}
|
|
4375
4096
|
}
|
|
4376
4097
|
}
|
|
@@ -4423,8 +4144,11 @@ var GroupFileDesk = class {
|
|
|
4423
4144
|
have: /* @__PURE__ */ new Set(),
|
|
4424
4145
|
haveSent: new RateWindow(GROUP_FILE_LIMITS.haveFrames, GROUP_FILE_LIMITS.haveWindowMs, () => this.deps.now()),
|
|
4425
4146
|
haveTaken: new RateWindow(GROUP_FILE_LIMITS.haveFramesTaken, GROUP_FILE_LIMITS.haveWindowMs, () => this.deps.now()),
|
|
4426
|
-
|
|
4427
|
-
|
|
4147
|
+
wantSent: new RateWindow(GROUP_FILE_LIMITS.wantFrames, GROUP_FILE_LIMITS.wantWindowMs, () => this.deps.now()),
|
|
4148
|
+
wantTaken: new RateWindow(GROUP_FILE_LIMITS.wantFramesTaken, GROUP_FILE_LIMITS.wantWindowMs, () => this.deps.now()),
|
|
4149
|
+
busy: /* @__PURE__ */ new Map(),
|
|
4150
|
+
gone: /* @__PURE__ */ new Set(),
|
|
4151
|
+
paced: /* @__PURE__ */ new Set()
|
|
4428
4152
|
};
|
|
4429
4153
|
edge.files = new ChatFiles({
|
|
4430
4154
|
uplink: this.uplink,
|
|
@@ -4531,6 +4255,7 @@ var GroupFileDesk = class {
|
|
|
4531
4255
|
if (transferEnded(record)) this.transferOver(edge, record);
|
|
4532
4256
|
if (record.direction === "out") {
|
|
4533
4257
|
const moved = edge.servedMoved.get(record.id);
|
|
4258
|
+
if (moved && !moved.mark && record.state === "active") moved.mark = moved.next = [record.confirmed, moved.from];
|
|
4534
4259
|
if (moved && record.confirmed > moved.confirmed && (record.confirmed - moved.confirmed >= GROUP_FILE_LIMITS.serveMoveBytes || record.confirmed === record.file.size)) edge.servedMoved.set(record.id, {
|
|
4535
4260
|
...moved,
|
|
4536
4261
|
confirmed: record.confirmed,
|
|
@@ -4547,7 +4272,7 @@ var GroupFileDesk = class {
|
|
|
4547
4272
|
edge.servedMoved.delete(record.id);
|
|
4548
4273
|
const serving = this.deps.settings().serveFiles;
|
|
4549
4274
|
for (const other of this.edgesById.values()) {
|
|
4550
|
-
if (serving) for (const id of other.busy) other.have.add(id);
|
|
4275
|
+
if (serving) for (const id of other.busy.keys()) other.have.add(id);
|
|
4551
4276
|
other.busy.clear();
|
|
4552
4277
|
}
|
|
4553
4278
|
}
|
|
@@ -4622,7 +4347,7 @@ var GroupFileDesk = class {
|
|
|
4622
4347
|
return {
|
|
4623
4348
|
message: kept.message,
|
|
4624
4349
|
author: kept.author,
|
|
4625
|
-
...kept.
|
|
4350
|
+
...kept.arrived !== void 0 && { arrived: kept.arrived },
|
|
4626
4351
|
...kept.auto && { auto: true },
|
|
4627
4352
|
...kept.asked && { asked: true },
|
|
4628
4353
|
...kept.paused && { paused: true }
|
|
@@ -4688,6 +4413,11 @@ function sameView(a, b) {
|
|
|
4688
4413
|
}
|
|
4689
4414
|
/** A file's holders with `key` the newest of them, the `holders` newest kept. */
|
|
4690
4415
|
var newestHolder = (key, holders) => [key, ...holders.filter((other) => other !== key)].slice(0, GROUP_FILE_LIMITS.holders);
|
|
4416
|
+
/** The epoch a private group's message reached this device under, when later than its own (said again); else none. */
|
|
4417
|
+
function laterEpoch(messageId, epoch) {
|
|
4418
|
+
const ref = meshMessageRef(messageId);
|
|
4419
|
+
return ref && epoch !== void 0 && epoch > ref.e ? epoch : void 0;
|
|
4420
|
+
}
|
|
4691
4421
|
function messageFile(kept) {
|
|
4692
4422
|
const { name, size, mime, voice, video, image } = kept.meta;
|
|
4693
4423
|
return {
|
|
@@ -4701,6 +4431,6 @@ function messageFile(kept) {
|
|
|
4701
4431
|
};
|
|
4702
4432
|
}
|
|
4703
4433
|
//#endregion
|
|
4704
|
-
export {
|
|
4434
|
+
export { breezDatabasesFor as $, IdentityProofs as A, cardsKey as B, FileAppender as C, streamStored as D, storedSize as E, takesUnsealed as F, INVOICE_PACE as G, normalizePhrase as H, whenDataKeyDropped as I, sourceKey as J, nextInvoiceAsk as K, isSealedField as L, openSecret as M, sealPlace as N, waitingGroupFile as O, sealSecret as P, breezDatabaseInUse as Q, CASHU_CARD as R, WALLET_TYPES as S, removeStored as T, journaledPayment as U, isRecoveryPhrase as V, lightningPaying as W, cashuMint as X, CASHU_MINT_SOURCE as Y, breezDatabase as Z, crossNetwork as _, storedGroupFiles as a, ModeGate as at, walletInstances as b, receivedPairedReply as c, awayFrom as ct, paymentAlias as d, setAwayWallets as dt, dropBreezDatabase as et, paymentWireId as f, setSingleWriterGate as ft, createTiming as g, createFailure as h, groupOfFile as i, ModeChanged as it, hasDataKey as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, refuseAway as lt, assertConfirmedReal as m, groupFileId as n, iceServerSetting as nt, groupReply as o, WrongNetworkError as ot, WALLET_NAMES as p, ProviderSources as q, groupFileText as r, relayOnlyProblem as rt, pairedWireReply as s, networkLabel as st, GroupFileDesk as t, iceServerProblem as tt, replyTo as u, requireTurn as ut, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, LightningCards as z };
|
|
4705
4435
|
|
|
4706
|
-
//# sourceMappingURL=groupFiles-
|
|
4436
|
+
//# sourceMappingURL=groupFiles-NonOYBKN.js.map
|