@ghostlytools/cli 1.9.0 → 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 +28 -20
- package/SKILL.md +5 -1
- package/dist/assets/{api-DFCgr6RH.js → api-BF_KwecF.js} +84 -38
- package/dist/assets/api-BF_KwecF.js.map +1 -0
- package/dist/assets/{api-raWw9j_m.js → api-DdrA86Ur.js} +2 -2
- package/dist/assets/{apiKit-CCavJJcl.js → apiKit-Du1u2l4x.js} +8 -8
- package/dist/assets/apiKit-Du1u2l4x.js.map +1 -0
- package/dist/assets/{apps-B7o2BPj6.js → apps-Bti9fDoW.js} +1 -1
- package/dist/assets/{apps-DmxEG147.js → apps-DwPfp54I.js} +5 -3
- package/dist/assets/apps-DwPfp54I.js.map +1 -0
- package/dist/assets/{arkade-DtYR9H0c.js → arkade-DOWpA2Kr.js} +2 -2
- package/dist/assets/{arkade-DtYR9H0c.js.map → arkade-DOWpA2Kr.js.map} +1 -1
- package/dist/assets/{backup-BserdrNk.js → backup-CeRckyl2.js} +1 -1
- package/dist/assets/{backup-YIB2XIES.js → backup-DZ_Q1eSu.js} +6 -6
- package/dist/assets/{backup-YIB2XIES.js.map → backup-DZ_Q1eSu.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.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-Dt75vrmY.js → envelope-CugS9qwQ.js} +2 -2
- package/dist/assets/{envelope-Dt75vrmY.js.map → envelope-CugS9qwQ.js.map} +1 -1
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.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-B598JzbC.js → fixedHosts-B4E4VrYE.js} +4 -4
- package/dist/assets/{fixedHosts-B598JzbC.js.map → fixedHosts-B4E4VrYE.js.map} +1 -1
- package/dist/assets/{groupFiles-FXel6zIc.js → groupFiles-NonOYBKN.js} +378 -59
- package/dist/assets/groupFiles-NonOYBKN.js.map +1 -0
- package/dist/assets/{host-DIBeK_c_.js → host-DvcVt5YI.js} +79 -23
- package/dist/assets/{host-DIBeK_c_.js.map → host-DvcVt5YI.js.map} +1 -1
- package/dist/assets/{hyperdhtRelay-D185dETu.js → hyperdhtRelay-Ce42sR8x.js} +2 -2
- package/dist/assets/{hyperdhtRelay-D185dETu.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-BSv_BWyG.js → irohWeb-C9ChbD-c.js} +57 -3
- package/dist/assets/{irohWeb-BSv_BWyG.js.map → irohWeb-C9ChbD-c.js.map} +1 -1
- package/dist/assets/{main-BbhfMTt8.js → main-4qE381KM.js} +194 -276
- package/dist/assets/main-4qE381KM.js.map +1 -0
- package/dist/assets/{mainline-9Vc3c3SA.js → mainline-DOwZDHVy.js} +2 -2
- package/dist/assets/{mainline-9Vc3c3SA.js.map → mainline-DOwZDHVy.js.map} +1 -1
- package/dist/assets/{networkReason-BncJ9KSM.js → networkReason-MInk1Y63.js} +3 -3
- package/dist/assets/{networkReason-BncJ9KSM.js.map → networkReason-MInk1Y63.js.map} +1 -1
- package/dist/assets/{nwc-QX3Yt1Sb.js → nwc-CHLWFV1R.js} +3 -3
- package/dist/assets/{nwc-QX3Yt1Sb.js.map → nwc-CHLWFV1R.js.map} +1 -1
- package/dist/assets/{nwcProvider-CzX3xH47.js → nwcProvider-BlkPOJen.js} +2 -2
- package/dist/assets/{nwcProvider-CzX3xH47.js.map → nwcProvider-BlkPOJen.js.map} +1 -1
- package/dist/assets/{ownDid-D8z5gwGI.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-PTtBMaYZ.js → registry-BN9r2pR4.js} +1 -1
- package/dist/assets/{registry-B2Dtnibo.js → registry-chCD0KWS.js} +5 -5
- package/dist/assets/registry-chCD0KWS.js.map +1 -0
- package/dist/assets/{resolve-ZxVzwFNA.js → resolve-Dtzogt2W.js} +2 -2
- package/dist/assets/{resolve-ZxVzwFNA.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/{buttons-CuRfKnPI.js → secretGuard-CSVNxXVW.js} +80 -330
- package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
- package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
- package/dist/assets/{server-Dw1o8z1o.js → server-BZnsm5X5.js} +1749 -335
- package/dist/assets/server-BZnsm5X5.js.map +1 -0
- package/dist/assets/{src-BD8RBVEp.js → src-DZagapGt.js} +1043 -197
- package/dist/assets/src-DZagapGt.js.map +1 -0
- package/dist/assets/{sshForges-DWrESWkK.js → sshForges-BkTgy5rx.js} +16 -9
- package/dist/assets/{sshForges-DWrESWkK.js.map → sshForges-BkTgy5rx.js.map} +1 -1
- package/dist/assets/{translate-D1uP0q32.js → translate-B9SMd6uf.js} +8 -7
- package/dist/assets/translate-B9SMd6uf.js.map +1 -0
- package/dist/assets/{usdt-DhVN8geQ.js → usdt-BU4ezonh.js} +3 -3
- package/dist/assets/{usdt-DhVN8geQ.js.map → usdt-BU4ezonh.js.map} +1 -1
- package/dist/assets/{words-DdXPkB3n.js → words-jYy7lTcb.js} +4 -2
- package/dist/assets/words-jYy7lTcb.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-DFCgr6RH.js.map +0 -1
- package/dist/assets/apiKit-CCavJJcl.js.map +0 -1
- package/dist/assets/apps-DmxEG147.js.map +0 -1
- package/dist/assets/buttons-CuRfKnPI.js.map +0 -1
- package/dist/assets/buttons-De3LPdSG.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-FXel6zIc.js.map +0 -1
- package/dist/assets/idb-BkOJES5_.js.map +0 -1
- package/dist/assets/main-BbhfMTt8.js.map +0 -1
- package/dist/assets/ownDid-D8z5gwGI.js.map +0 -1
- package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
- package/dist/assets/registry-B2Dtnibo.js.map +0 -1
- package/dist/assets/server-Dw1o8z1o.js.map +0 -1
- package/dist/assets/src-BD8RBVEp.js.map +0 -1
- package/dist/assets/translate-D1uP0q32.js.map +0 -1
- package/dist/assets/words-DdXPkB3n.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
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";
|
|
@@ -1068,6 +1068,16 @@ async function readLightningJournal() {
|
|
|
1068
1068
|
}
|
|
1069
1069
|
return (await read.ops).map((op) => ({ ...op }));
|
|
1070
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
|
+
}
|
|
1071
1081
|
var OUT_POLL_MS = 15e3;
|
|
1072
1082
|
var RECENT = 20;
|
|
1073
1083
|
/** Resolved Lightning addresses are kept this long for the amount to be chosen; this many at most. */
|
|
@@ -1193,6 +1203,18 @@ var LightningService = class {
|
|
|
1193
1203
|
this.schedule(0);
|
|
1194
1204
|
return true;
|
|
1195
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
|
+
}
|
|
1196
1218
|
/** The Cashu wallet minted the ecash of one of its invoices (it polls its own quotes). */
|
|
1197
1219
|
async reportInvoicePaid(invoice, context = {}) {
|
|
1198
1220
|
const hash = decodeBolt11(invoice)?.paymentHash;
|
|
@@ -1379,14 +1401,15 @@ var LightningService = class {
|
|
|
1379
1401
|
}
|
|
1380
1402
|
/**
|
|
1381
1403
|
* Asks the active source about everything of its that is open, pending or unknown. One pass at a time. `paced`: an
|
|
1382
|
-
* 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`).
|
|
1383
1406
|
*/
|
|
1384
|
-
reconcile(paced = false) {
|
|
1385
|
-
const pass = this.passes.then(() => this.reconcileOnce(paced));
|
|
1407
|
+
reconcile(paced = false, only) {
|
|
1408
|
+
const pass = this.passes.then(() => this.reconcileOnce(paced, only));
|
|
1386
1409
|
this.passes = pass.catch(() => {});
|
|
1387
1410
|
return pass;
|
|
1388
1411
|
}
|
|
1389
|
-
async reconcileOnce(paced) {
|
|
1412
|
+
async reconcileOnce(paced, only) {
|
|
1390
1413
|
if (this.stopped) return;
|
|
1391
1414
|
let again = 0;
|
|
1392
1415
|
/** When the next open invoice is due. */
|
|
@@ -1398,7 +1421,7 @@ var LightningService = class {
|
|
|
1398
1421
|
const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
|
|
1399
1422
|
for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
|
|
1400
1423
|
for (const op of ops) {
|
|
1401
|
-
if (!this.owns(op)) continue;
|
|
1424
|
+
if (!this.owns(op) || only !== void 0 && (op.direction !== "in" || op.paymentHash !== only)) continue;
|
|
1402
1425
|
if (op.selfSettled) {
|
|
1403
1426
|
if (op.direction !== "out" || op.state !== "unknown") continue;
|
|
1404
1427
|
if (!provider) {
|
|
@@ -1933,6 +1956,10 @@ var LightningCards = class {
|
|
|
1933
1956
|
async watch(invoice) {
|
|
1934
1957
|
return (await Promise.all(this.here().map((s) => s.watch(invoice)))).some(Boolean);
|
|
1935
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
|
+
}
|
|
1936
1963
|
async recover() {
|
|
1937
1964
|
for (const s of this.here()) await s.recover();
|
|
1938
1965
|
}
|
|
@@ -2021,7 +2048,20 @@ var PEER_DB = "ghostly";
|
|
|
2021
2048
|
* non-extractable key; nothing writes it anywhere. Empty, every secret is sealed as today (version 1).
|
|
2022
2049
|
*/
|
|
2023
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;
|
|
2024
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
|
+
}
|
|
2025
2065
|
/** A cache of opened secrets empties itself when the key goes. Returns the way to stop listening. */
|
|
2026
2066
|
function whenDataKeyDropped(drop) {
|
|
2027
2067
|
onDrop.add(drop);
|
|
@@ -2040,10 +2080,21 @@ async function sealSecret(value, at) {
|
|
|
2040
2080
|
deviceKey
|
|
2041
2081
|
};
|
|
2042
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
|
+
}
|
|
2043
2091
|
/** Reads both versions: a profile being encrypted holds some of each until its migration ends. */
|
|
2044
2092
|
async function openSecret(secret, at) {
|
|
2045
|
-
if (!isSealedField(secret))
|
|
2046
|
-
|
|
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);
|
|
2047
2098
|
return openField(slot, {
|
|
2048
2099
|
db: PEER_DB,
|
|
2049
2100
|
...at
|
|
@@ -2060,7 +2111,7 @@ var registry;
|
|
|
2060
2111
|
var loading;
|
|
2061
2112
|
var listeners = /* @__PURE__ */ new Set();
|
|
2062
2113
|
function loadIdentityProviders() {
|
|
2063
|
-
return loading ??= import("./registry-
|
|
2114
|
+
return loading ??= import("./registry-BN9r2pR4.js").then((m) => {
|
|
2064
2115
|
registry = m;
|
|
2065
2116
|
for (const listener of listeners) listener();
|
|
2066
2117
|
return m;
|
|
@@ -2083,10 +2134,21 @@ var KEY = "identityProofs";
|
|
|
2083
2134
|
var REVOCATIONS = "identityRevocations";
|
|
2084
2135
|
/** When the contacts' proofs were last looked up for a revocation (ms), so a reload does not look them all up again. */
|
|
2085
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";
|
|
2086
2139
|
/** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
|
|
2087
2140
|
var REPUBLISH_MS = 36e5;
|
|
2088
2141
|
/** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
|
|
2089
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;
|
|
2090
2152
|
/**
|
|
2091
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
|
|
2092
2154
|
* every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
|
|
@@ -2097,6 +2159,18 @@ var WITHDRAWN_REVOCATION_TRIES_MS = [
|
|
|
2097
2159
|
6e4,
|
|
2098
2160
|
18e4
|
|
2099
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;
|
|
2100
2174
|
/** A proof begun and not completed is dropped this long after, or when a fifth one begins (the CLI says the same). */
|
|
2101
2175
|
var IDENTITY_DRAFT_TTL_MS = 18e5;
|
|
2102
2176
|
var MAX_PROOFS = 32;
|
|
@@ -2112,7 +2186,27 @@ var IdentityProofs = class {
|
|
|
2112
2186
|
proofs = [];
|
|
2113
2187
|
revocations = [];
|
|
2114
2188
|
revocationsCheckedAt = 0;
|
|
2115
|
-
/**
|
|
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. */
|
|
2116
2210
|
ended = false;
|
|
2117
2211
|
/** Unsealed proof-key seeds, by proof id, for this run only. */
|
|
2118
2212
|
seeds = /* @__PURE__ */ new Map();
|
|
@@ -2124,6 +2218,8 @@ var IdentityProofs = class {
|
|
|
2124
2218
|
errors = /* @__PURE__ */ new Map();
|
|
2125
2219
|
/** Chats whose current connection already got the hello: "ready" is reported more than once per connection. */
|
|
2126
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();
|
|
2127
2223
|
fetch;
|
|
2128
2224
|
constructor(host, providers = loadedIdentityProviders) {
|
|
2129
2225
|
this.host = host;
|
|
@@ -2134,15 +2230,17 @@ var IdentityProofs = class {
|
|
|
2134
2230
|
async load() {
|
|
2135
2231
|
const providers = loadIdentityProviders();
|
|
2136
2232
|
const settings = await store(STORES.settings, "readonly");
|
|
2137
|
-
[this.proofs, this.revocations, this.revocationsCheckedAt] = await Promise.all([
|
|
2233
|
+
[this.proofs, this.revocations, this.revocationsCheckedAt, this.round] = await Promise.all([
|
|
2138
2234
|
wrap(settings.get(KEY)).then((v) => v ?? []),
|
|
2139
2235
|
wrap(settings.get(REVOCATIONS)).then((v) => v ?? []),
|
|
2140
|
-
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)
|
|
2141
2238
|
]);
|
|
2142
2239
|
await providers;
|
|
2143
2240
|
}
|
|
2144
2241
|
/** Background work: republish revocations, look up the contacts' proofs for revocations. */
|
|
2145
2242
|
start() {
|
|
2243
|
+
this.running = true;
|
|
2146
2244
|
const every = (ms, first, work) => {
|
|
2147
2245
|
const tick = () => {
|
|
2148
2246
|
work().catch(() => {}).finally(() => {
|
|
@@ -2153,12 +2251,42 @@ var IdentityProofs = class {
|
|
|
2153
2251
|
};
|
|
2154
2252
|
every(REPUBLISH_MS, 5e3, () => this.republish());
|
|
2155
2253
|
const due = Math.min(REVOCATION_CHECK_MS, this.revocationsCheckedAt + REVOCATION_CHECK_MS - Date.now());
|
|
2156
|
-
|
|
2254
|
+
this.lookUpIn(Math.max(6e4, due));
|
|
2255
|
+
every(AUTO_RECHECK_TICK_MS, AUTO_RECHECK_FIRST_MS, () => this.recheckDue());
|
|
2157
2256
|
this.unlisten ??= whenDataKeyDropped(() => this.forgetSeeds());
|
|
2158
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
|
+
}
|
|
2159
2283
|
stop() {
|
|
2284
|
+
this.running = false;
|
|
2285
|
+
this.stops++;
|
|
2160
2286
|
for (const t of this.timers) clearTimeout(t);
|
|
2161
2287
|
this.timers = [];
|
|
2288
|
+
this.lookupTimer = void 0;
|
|
2289
|
+
this.wakeLookup?.();
|
|
2162
2290
|
this.unlisten?.();
|
|
2163
2291
|
this.unlisten = void 0;
|
|
2164
2292
|
this.forgetSeeds();
|
|
@@ -2173,6 +2301,7 @@ var IdentityProofs = class {
|
|
|
2173
2301
|
*/
|
|
2174
2302
|
save(change) {
|
|
2175
2303
|
const run = this.saving.then(async () => {
|
|
2304
|
+
if (this.ended) throw new Error("This profile's data was cleared");
|
|
2176
2305
|
const [proofs, revocations] = change(this.proofs, this.revocations);
|
|
2177
2306
|
await transact([STORES.settings], (stores) => {
|
|
2178
2307
|
stores[STORES.settings].put(proofs, KEY);
|
|
@@ -2209,7 +2338,7 @@ var IdentityProofs = class {
|
|
|
2209
2338
|
*/
|
|
2210
2339
|
verifyContact = async (statement, evidence) => {
|
|
2211
2340
|
if (!this.host.relayOnly?.()) return this.verify(statement, evidence);
|
|
2212
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
2341
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-B4E4VrYE.js");
|
|
2213
2342
|
const fixed = fixedIdentityHosts();
|
|
2214
2343
|
let refused;
|
|
2215
2344
|
const fetch = async (url, options) => {
|
|
@@ -2227,9 +2356,21 @@ var IdentityProofs = class {
|
|
|
2227
2356
|
throw e;
|
|
2228
2357
|
}
|
|
2229
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
|
+
*/
|
|
2230
2363
|
revoked = async (statement) => {
|
|
2231
|
-
if (!this.host.online())
|
|
2232
|
-
|
|
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());
|
|
2233
2374
|
return !!records && revokesIdentity(records, statement.id);
|
|
2234
2375
|
};
|
|
2235
2376
|
async local(id) {
|
|
@@ -2352,7 +2493,11 @@ var IdentityProofs = class {
|
|
|
2352
2493
|
return !!p.shared || this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
|
|
2353
2494
|
}
|
|
2354
2495
|
async publishRevocation(r) {
|
|
2355
|
-
if (!this.host.online())
|
|
2496
|
+
if (!this.host.online()) {
|
|
2497
|
+
this.unpublished.add(r.id);
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
this.unpublished.delete(r.id);
|
|
2356
2501
|
await this.host.publish(await this.seedOf(r.id, r.seed), [{
|
|
2357
2502
|
label: IDENTITY_REVOCATION_LABEL,
|
|
2358
2503
|
value: identityRevocationValue(r.id, r.revokedAt)
|
|
@@ -2372,18 +2517,118 @@ var IdentityProofs = class {
|
|
|
2372
2517
|
/**
|
|
2373
2518
|
* Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
|
|
2374
2519
|
* ones withdrawn, which a removal also revokes. Not a proof already revoked, nor one past its expiry: its owner
|
|
2375
|
-
* 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.
|
|
2376
2528
|
*/
|
|
2377
2529
|
async checkRevocations() {
|
|
2378
|
-
if (!this.host.online()) return;
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
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();
|
|
2382
2565
|
}
|
|
2383
|
-
if (this.ended) return;
|
|
2566
|
+
if (this.ended || missed) return false;
|
|
2384
2567
|
this.revocationsCheckedAt = Date.now();
|
|
2568
|
+
if (this.round === round) this.round = void 0;
|
|
2385
2569
|
await transact([STORES.settings], (stores) => {
|
|
2386
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
|
+
};
|
|
2387
2632
|
});
|
|
2388
2633
|
}
|
|
2389
2634
|
revocable(r) {
|
|
@@ -2512,9 +2757,11 @@ var IdentityProofs = class {
|
|
|
2512
2757
|
async frame(linkId, frame) {
|
|
2513
2758
|
const x = this.exchange(linkId);
|
|
2514
2759
|
if (!x) return;
|
|
2515
|
-
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();
|
|
2516
2763
|
await x.receive(frame);
|
|
2517
|
-
if (
|
|
2764
|
+
if (id && !before && withdrawn()) this.afterWithdrawal(linkId, id);
|
|
2518
2765
|
}
|
|
2519
2766
|
ready(linkId) {
|
|
2520
2767
|
if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
|
|
@@ -2994,7 +3241,7 @@ var GroupFileDesk = class {
|
|
|
2994
3241
|
groupId,
|
|
2995
3242
|
message: file.group.message,
|
|
2996
3243
|
author: file.group.author,
|
|
2997
|
-
...file.group.
|
|
3244
|
+
...file.group.arrived !== void 0 && { arrived: file.group.arrived },
|
|
2998
3245
|
meta: {
|
|
2999
3246
|
name,
|
|
3000
3247
|
size,
|
|
@@ -3147,8 +3394,10 @@ var GroupFileDesk = class {
|
|
|
3147
3394
|
*/
|
|
3148
3395
|
async announced(groupId, m, me) {
|
|
3149
3396
|
const known = this.byMessage.get(`${groupId}\n${m.id}`);
|
|
3150
|
-
if (known)
|
|
3151
|
-
|
|
3397
|
+
if (known) {
|
|
3398
|
+
this.arrivedAgain(groupId, m.id, m.epoch);
|
|
3399
|
+
return messageFile(this.kept.get(known));
|
|
3400
|
+
}
|
|
3152
3401
|
const ownId = m.sender === me ? this.own.get(`${groupId}\n${m.file.d}`) : void 0;
|
|
3153
3402
|
if (ownId) {
|
|
3154
3403
|
this.own.delete(`${groupId}\n${m.file.d}`);
|
|
@@ -3158,7 +3407,6 @@ var GroupFileDesk = class {
|
|
|
3158
3407
|
groupId,
|
|
3159
3408
|
message: m.id,
|
|
3160
3409
|
author: me,
|
|
3161
|
-
ts,
|
|
3162
3410
|
meta: m.file,
|
|
3163
3411
|
mine: true,
|
|
3164
3412
|
auto: false,
|
|
@@ -3176,8 +3424,7 @@ var GroupFileDesk = class {
|
|
|
3176
3424
|
await this.deps.store.patch(ownId, {
|
|
3177
3425
|
group: {
|
|
3178
3426
|
message: m.id,
|
|
3179
|
-
author: me
|
|
3180
|
-
ts
|
|
3427
|
+
author: me
|
|
3181
3428
|
},
|
|
3182
3429
|
transfer
|
|
3183
3430
|
}).catch(() => {});
|
|
@@ -3190,12 +3437,13 @@ var GroupFileDesk = class {
|
|
|
3190
3437
|
const auto = paced && this.deps.settings().autoDownloads && fetchesByItself(m.file, this.keptAutomatically(groupId)) && await this.hasRoom(m.file.size);
|
|
3191
3438
|
const holders = this.ahead.get(`${groupId}\n${m.id}`) ?? [];
|
|
3192
3439
|
this.ahead.delete(`${groupId}\n${m.id}`);
|
|
3440
|
+
const arrived = laterEpoch(m.id, m.epoch);
|
|
3193
3441
|
const kept = {
|
|
3194
3442
|
id,
|
|
3195
3443
|
groupId,
|
|
3196
3444
|
message: m.id,
|
|
3197
3445
|
author: m.sender,
|
|
3198
|
-
|
|
3446
|
+
...arrived !== void 0 && { arrived },
|
|
3199
3447
|
meta: m.file,
|
|
3200
3448
|
mine: false,
|
|
3201
3449
|
auto,
|
|
@@ -3229,7 +3477,7 @@ var GroupFileDesk = class {
|
|
|
3229
3477
|
group: {
|
|
3230
3478
|
message: m.id,
|
|
3231
3479
|
author: m.sender,
|
|
3232
|
-
|
|
3480
|
+
...arrived !== void 0 && { arrived },
|
|
3233
3481
|
...auto && { auto: true }
|
|
3234
3482
|
}
|
|
3235
3483
|
});
|
|
@@ -3239,6 +3487,17 @@ var GroupFileDesk = class {
|
|
|
3239
3487
|
} else this.waiting(kept);
|
|
3240
3488
|
return messageFile(kept);
|
|
3241
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
|
+
}
|
|
3242
3501
|
/** The person asks for a file this device did not fetch by itself (Download), or for one that stopped coming. */
|
|
3243
3502
|
async download(fileId) {
|
|
3244
3503
|
const kept = this.kept.get(fileId);
|
|
@@ -3306,7 +3565,8 @@ var GroupFileDesk = class {
|
|
|
3306
3565
|
async frame(groupId, peer, linkId, frame) {
|
|
3307
3566
|
if (frame.t === "group-want") {
|
|
3308
3567
|
const want = readGroupWant(frame, groupId);
|
|
3309
|
-
|
|
3568
|
+
const edge = want && this.edge(groupId, peer, linkId);
|
|
3569
|
+
if (edge && edge.wantTaken.take()) await this.serve(edge, want.id);
|
|
3310
3570
|
} else if (frame.t === "group-want-no") {
|
|
3311
3571
|
const no = readGroupWantNo(frame, groupId);
|
|
3312
3572
|
if (no) this.refused(groupId, peer, linkId, no.id, no.why);
|
|
@@ -3378,6 +3638,13 @@ var GroupFileDesk = class {
|
|
|
3378
3638
|
this.ask(kept);
|
|
3379
3639
|
}
|
|
3380
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);
|
|
3381
3648
|
for (const edge of this.edgesById.values()) if (edge.have.size && this.deps.ready(edge.linkId)) this.sendHave(edge, [...edge.have]);
|
|
3382
3649
|
for (const [groupId, have] of this.communityHave) {
|
|
3383
3650
|
if (!have.ids.size || now - have.at < GROUP_FILE_LIMITS.communityHaveEveryMs) continue;
|
|
@@ -3419,7 +3686,11 @@ var GroupFileDesk = class {
|
|
|
3419
3686
|
}
|
|
3420
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. */
|
|
3421
3688
|
freeEdges(groupId) {
|
|
3422
|
-
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();
|
|
3423
3694
|
}
|
|
3424
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. */
|
|
3425
3696
|
freeFor(kept, want, free) {
|
|
@@ -3427,7 +3698,7 @@ var GroupFileDesk = class {
|
|
|
3427
3698
|
if (!membership) return false;
|
|
3428
3699
|
const known = this.knownHolders(kept, membership);
|
|
3429
3700
|
const others = !this.waitForKnown(kept, want, known, this.deps.edges(kept.groupId));
|
|
3430
|
-
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)));
|
|
3431
3702
|
}
|
|
3432
3703
|
/** The members known to hold the file (its author first), in the group's roster, but this device. */
|
|
3433
3704
|
knownHolders(kept, membership) {
|
|
@@ -3443,7 +3714,7 @@ var GroupFileDesk = class {
|
|
|
3443
3714
|
waitForKnown(kept, want, known, edges) {
|
|
3444
3715
|
if (!known.includes(kept.author)) return false;
|
|
3445
3716
|
const linkId = edges.get(kept.author) ?? "";
|
|
3446
|
-
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));
|
|
3447
3718
|
}
|
|
3448
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. */
|
|
3449
3720
|
mayAsk(kept, want, key, linkId) {
|
|
@@ -3468,7 +3739,7 @@ var GroupFileDesk = class {
|
|
|
3468
3739
|
this.stopFailed(kept);
|
|
3469
3740
|
return;
|
|
3470
3741
|
}
|
|
3471
|
-
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));
|
|
3472
3743
|
const order = [...known, ...others].filter((key) => this.mayAsk(kept, want, key, edges.get(key)));
|
|
3473
3744
|
if (kept.left && order.includes(kept.left)) order.push(...order.splice(order.indexOf(kept.left), 1));
|
|
3474
3745
|
for (const key of order.filter((key) => kept.suspect?.has(key))) order.push(...order.splice(order.indexOf(key), 1));
|
|
@@ -3480,6 +3751,11 @@ var GroupFileDesk = class {
|
|
|
3480
3751
|
behind = true;
|
|
3481
3752
|
continue;
|
|
3482
3753
|
}
|
|
3754
|
+
if (this.paced(linkId)) {
|
|
3755
|
+
this.edgesById.get(linkId).wantPaced = true;
|
|
3756
|
+
behind = true;
|
|
3757
|
+
continue;
|
|
3758
|
+
}
|
|
3483
3759
|
Object.assign(want, {
|
|
3484
3760
|
holder: key,
|
|
3485
3761
|
linkId,
|
|
@@ -3489,6 +3765,7 @@ var GroupFileDesk = class {
|
|
|
3489
3765
|
id: kept.id,
|
|
3490
3766
|
want
|
|
3491
3767
|
});
|
|
3768
|
+
this.edgesById.get(linkId).wantSent.take();
|
|
3492
3769
|
if (!this.deps.send(linkId, {
|
|
3493
3770
|
t: "group-want",
|
|
3494
3771
|
g: kept.groupId,
|
|
@@ -3656,7 +3933,7 @@ var GroupFileDesk = class {
|
|
|
3656
3933
|
async serve(edge, messageId) {
|
|
3657
3934
|
const kept = this.kept.get(this.byMessage.get(`${edge.groupId}\n${messageId}`) ?? "");
|
|
3658
3935
|
const here = !!kept?.held && !!await this.deps.store.get(kept.id).catch(() => void 0);
|
|
3659
|
-
const why = this.mayServe(edge, messageId, here ? kept : void 0, kept?.
|
|
3936
|
+
const why = this.mayServe(edge, messageId, here ? kept : void 0, kept?.arrived);
|
|
3660
3937
|
if (why || !kept) {
|
|
3661
3938
|
this.deps.send(edge.linkId, {
|
|
3662
3939
|
t: GROUP_WANT_NO_FRAME,
|
|
@@ -3691,9 +3968,9 @@ var GroupFileDesk = class {
|
|
|
3691
3968
|
* someone who could not read the announcement, `gone` when it is not here (`kept` undefined), `busy` when serving is
|
|
3692
3969
|
* off or full, `day` when this device served its bytes for the day (`serveBytesPerDay`).
|
|
3693
3970
|
*/
|
|
3694
|
-
mayServe(edge, messageId, kept,
|
|
3971
|
+
mayServe(edge, messageId, kept, arrived) {
|
|
3695
3972
|
const membership = this.deps.membership(edge.groupId);
|
|
3696
|
-
if (!membership || !membership.couldRead(edge.peer, messageId,
|
|
3973
|
+
if (!membership || !membership.couldRead(edge.peer, messageId, arrived)) return "refused";
|
|
3697
3974
|
if (!kept) return "gone";
|
|
3698
3975
|
if (!this.deps.settings().serveFiles || !edge.files.live) return "busy";
|
|
3699
3976
|
this.letGo();
|
|
@@ -3701,7 +3978,7 @@ var GroupFileDesk = class {
|
|
|
3701
3978
|
const theirs = active.filter((a) => a.peer === edge.peer);
|
|
3702
3979
|
const placed = theirs.length > 1 || theirs.some((a) => a.sending || this.deps.now() - a.since >= GROUP_FILE_LIMITS.doneWaitMs);
|
|
3703
3980
|
if (active.length >= GROUP_FILE_LIMITS.serveAtOnce && (placed || !this.makeRoom())) {
|
|
3704
|
-
edge.busy.
|
|
3981
|
+
edge.busy.set(messageId, this.deps.now());
|
|
3705
3982
|
return "busy";
|
|
3706
3983
|
}
|
|
3707
3984
|
if (placed) return "busy";
|
|
@@ -3713,23 +3990,51 @@ var GroupFileDesk = class {
|
|
|
3713
3990
|
const reserved = this.servingNow().reduce((sum, a) => sum + a.size, 0);
|
|
3714
3991
|
return this.served.bytes + reserved + kept.meta.size > GROUP_FILE_LIMITS.serveBytesPerDay ? "day" : null;
|
|
3715
3992
|
}
|
|
3716
|
-
/**
|
|
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
|
+
*/
|
|
3717
4000
|
makeRoom() {
|
|
3718
4001
|
const now = this.deps.now();
|
|
3719
4002
|
let oldest;
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
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 = {
|
|
3723
4008
|
edge,
|
|
3724
4009
|
wire,
|
|
3725
4010
|
from
|
|
3726
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
|
+
};
|
|
3727
4020
|
}
|
|
3728
|
-
|
|
3729
|
-
|
|
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);
|
|
3730
4025
|
return true;
|
|
3731
4026
|
}
|
|
3732
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
|
+
/**
|
|
3733
4038
|
* Transfers served now, all groups together: to whom, what each takes of the day (its size, or what it sent when that
|
|
3734
4039
|
* is more), whether bytes are still to go, and since when it has not gone further.
|
|
3735
4040
|
*/
|
|
@@ -3782,6 +4087,11 @@ var GroupFileDesk = class {
|
|
|
3782
4087
|
if (gone || overtaken || now - moved.at >= GROUP_FILE_LIMITS.wantWaitMs) {
|
|
3783
4088
|
edge.files.cancel("out", wire);
|
|
3784
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];
|
|
3785
4095
|
}
|
|
3786
4096
|
}
|
|
3787
4097
|
}
|
|
@@ -3834,8 +4144,11 @@ var GroupFileDesk = class {
|
|
|
3834
4144
|
have: /* @__PURE__ */ new Set(),
|
|
3835
4145
|
haveSent: new RateWindow(GROUP_FILE_LIMITS.haveFrames, GROUP_FILE_LIMITS.haveWindowMs, () => this.deps.now()),
|
|
3836
4146
|
haveTaken: new RateWindow(GROUP_FILE_LIMITS.haveFramesTaken, GROUP_FILE_LIMITS.haveWindowMs, () => this.deps.now()),
|
|
3837
|
-
|
|
3838
|
-
|
|
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()
|
|
3839
4152
|
};
|
|
3840
4153
|
edge.files = new ChatFiles({
|
|
3841
4154
|
uplink: this.uplink,
|
|
@@ -3942,6 +4255,7 @@ var GroupFileDesk = class {
|
|
|
3942
4255
|
if (transferEnded(record)) this.transferOver(edge, record);
|
|
3943
4256
|
if (record.direction === "out") {
|
|
3944
4257
|
const moved = edge.servedMoved.get(record.id);
|
|
4258
|
+
if (moved && !moved.mark && record.state === "active") moved.mark = moved.next = [record.confirmed, moved.from];
|
|
3945
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, {
|
|
3946
4260
|
...moved,
|
|
3947
4261
|
confirmed: record.confirmed,
|
|
@@ -3958,7 +4272,7 @@ var GroupFileDesk = class {
|
|
|
3958
4272
|
edge.servedMoved.delete(record.id);
|
|
3959
4273
|
const serving = this.deps.settings().serveFiles;
|
|
3960
4274
|
for (const other of this.edgesById.values()) {
|
|
3961
|
-
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);
|
|
3962
4276
|
other.busy.clear();
|
|
3963
4277
|
}
|
|
3964
4278
|
}
|
|
@@ -4033,7 +4347,7 @@ var GroupFileDesk = class {
|
|
|
4033
4347
|
return {
|
|
4034
4348
|
message: kept.message,
|
|
4035
4349
|
author: kept.author,
|
|
4036
|
-
...kept.
|
|
4350
|
+
...kept.arrived !== void 0 && { arrived: kept.arrived },
|
|
4037
4351
|
...kept.auto && { auto: true },
|
|
4038
4352
|
...kept.asked && { asked: true },
|
|
4039
4353
|
...kept.paused && { paused: true }
|
|
@@ -4099,6 +4413,11 @@ function sameView(a, b) {
|
|
|
4099
4413
|
}
|
|
4100
4414
|
/** A file's holders with `key` the newest of them, the `holders` newest kept. */
|
|
4101
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
|
+
}
|
|
4102
4421
|
function messageFile(kept) {
|
|
4103
4422
|
const { name, size, mime, voice, video, image } = kept.meta;
|
|
4104
4423
|
return {
|
|
@@ -4112,6 +4431,6 @@ function messageFile(kept) {
|
|
|
4112
4431
|
};
|
|
4113
4432
|
}
|
|
4114
4433
|
//#endregion
|
|
4115
|
-
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 };
|
|
4116
4435
|
|
|
4117
|
-
//# sourceMappingURL=groupFiles-
|
|
4436
|
+
//# sourceMappingURL=groupFiles-NonOYBKN.js.map
|