@ghostlytools/cli 1.10.2 → 1.10.4
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 +4 -2
- package/dist/assets/{api-DcE4KylM.js → api-DgS7f5TT.js} +2 -2
- package/dist/assets/{api-EUGHGnRz.js → api-DkcMOWLX.js} +44 -19
- package/dist/assets/api-DkcMOWLX.js.map +1 -0
- package/dist/assets/{apiKit-CJVp_crp.js → apiKit-D6Oj-vFx.js} +27 -11
- package/dist/assets/apiKit-D6Oj-vFx.js.map +1 -0
- package/dist/assets/{apps-C54T_MOT.js → apps-B22SeD6T.js} +3 -3
- package/dist/assets/{apps-C54T_MOT.js.map → apps-B22SeD6T.js.map} +1 -1
- package/dist/assets/{apps-C-KbyLCa.js → apps-DgALLHzS.js} +1 -1
- package/dist/assets/{arkade-BmxJTa65.js → arkade-D5cPr_dV.js} +2 -2
- package/dist/assets/{arkade-BmxJTa65.js.map → arkade-D5cPr_dV.js.map} +1 -1
- package/dist/assets/{backup-C0Plp-DF.js → backup-DndsW2uX.js} +1 -1
- package/dist/assets/{backup-BxSH5BZG.js → backup-dzJLzg-k.js} +6 -6
- package/dist/assets/{backup-BxSH5BZG.js.map → backup-dzJLzg-k.js.map} +1 -1
- package/dist/assets/{blobFiles-BnjN_Vrz.js → blobFiles-XZ9PEXYy.js} +2 -2
- package/dist/assets/{blobFiles-BnjN_Vrz.js.map → blobFiles-XZ9PEXYy.js.map} +1 -1
- package/dist/assets/{buttons-B-ZJYdo0.js → buttons-ByKT_vP8.js} +4 -4
- package/dist/assets/{buttons-B-ZJYdo0.js.map → buttons-ByKT_vP8.js.map} +1 -1
- package/dist/assets/buttons-TVCNj280.js +2 -0
- package/dist/assets/{client-CDa87uYD.js → client-q7dVOtYb.js} +10 -4
- package/dist/assets/client-q7dVOtYb.js.map +1 -0
- package/dist/assets/{codec-D45W1L8n.js → codec-HD6iOn_D.js} +2 -2
- package/dist/assets/{codec-D45W1L8n.js.map → codec-HD6iOn_D.js.map} +1 -1
- package/dist/assets/{envelope-C3yFCQa-.js → envelope-C-0tfbOG.js} +2 -2
- package/dist/assets/{envelope-C3yFCQa-.js.map → envelope-C-0tfbOG.js.map} +1 -1
- package/dist/assets/{fileBytes-DjBYYyXT.js → fileBytes-BABGEF13.js} +2 -2
- package/dist/assets/{fileBytes-DjBYYyXT.js.map → fileBytes-BABGEF13.js.map} +1 -1
- package/dist/assets/{fileBytes-DMzrIdCu.js → fileBytes-CQQK2uOh.js} +1 -1
- package/dist/assets/{fileBytes-Douk1yOp.js → fileBytes-DqnfKIkj.js} +2 -2
- package/dist/assets/{fileBytes-Douk1yOp.js.map → fileBytes-DqnfKIkj.js.map} +1 -1
- package/dist/assets/fileBytesIdb-BtXATa7j.js +2 -0
- package/dist/assets/{fileBytesIdb-CkClu9YI.js → fileBytesIdb-DrXmDUSy.js} +2 -2
- package/dist/assets/{fileBytesIdb-CkClu9YI.js.map → fileBytesIdb-DrXmDUSy.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-WryQuOgK.js → fileBytesOpfs-udKCzcLe.js} +6 -9
- package/dist/assets/{fileBytesOpfs-WryQuOgK.js.map → fileBytesOpfs-udKCzcLe.js.map} +1 -1
- package/dist/assets/{fixedHosts-C6nCHjOa.js → fixedHosts-CN3CsslV.js} +7 -8
- package/dist/assets/fixedHosts-CN3CsslV.js.map +1 -0
- package/dist/assets/{groupFiles-DYopNE57.js → groupFiles-BFv9K_za.js} +256 -110
- package/dist/assets/groupFiles-BFv9K_za.js.map +1 -0
- package/dist/assets/{host-G5seUwaI.js → host-C-wwtVt2.js} +378 -60
- package/dist/assets/host-C-wwtVt2.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-B_uHjg_r.js → hyperdhtRelay-B9EQTm_M.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B_uHjg_r.js.map → hyperdhtRelay-B9EQTm_M.js.map} +1 -1
- package/dist/assets/{irohWeb-C-2oslSU.js → irohWeb-o0H_NlCF.js} +2 -2
- package/dist/assets/{irohWeb-C-2oslSU.js.map → irohWeb-o0H_NlCF.js.map} +1 -1
- package/dist/assets/{main-Dk--nD7X.js → main-CLUIPy4d.js} +49 -30
- package/dist/assets/main-CLUIPy4d.js.map +1 -0
- package/dist/assets/{mainline-HPlVrl8R.js → mainline-B2qmNsib.js} +155 -3
- package/dist/assets/mainline-B2qmNsib.js.map +1 -0
- package/dist/assets/{networkReason-CfpO9ayz.js → networkReason-BEl-DDWd.js} +4 -4
- package/dist/assets/{networkReason-CfpO9ayz.js.map → networkReason-BEl-DDWd.js.map} +1 -1
- package/dist/assets/{nwc-BY7BPttn.js → nwc-BNkhjJHN.js} +3 -3
- package/dist/assets/{nwc-BY7BPttn.js.map → nwc-BNkhjJHN.js.map} +1 -1
- package/dist/assets/{nwcProvider-CfpbNUf7.js → nwcProvider-CvaRJdHT.js} +2 -2
- package/dist/assets/{nwcProvider-CfpbNUf7.js.map → nwcProvider-CvaRJdHT.js.map} +1 -1
- package/dist/assets/{ownDid-DJFZM2cV.js → ownDid-D67KNdJq.js} +3 -2
- package/dist/assets/ownDid-D67KNdJq.js.map +1 -0
- package/dist/assets/{profiles-DKmZGXp6.js → profiles-QDB7V_Qt.js} +7 -5
- package/dist/assets/profiles-QDB7V_Qt.js.map +1 -0
- package/dist/assets/{registry-BUm4cAzV.js → registry-BKkSnpjL.js} +126 -19
- package/dist/assets/registry-BKkSnpjL.js.map +1 -0
- package/dist/assets/{registry-CAzrtV0_.js → registry-DN5a8Ul6.js} +1 -1
- package/dist/assets/{resolve-CDD4X68j.js → resolve-DhpAggDP.js} +24 -5
- package/dist/assets/resolve-DhpAggDP.js.map +1 -0
- package/dist/assets/{server-DcOsgYDU.js → server-7w2O5wsv.js} +956 -277
- package/dist/assets/server-7w2O5wsv.js.map +1 -0
- package/dist/assets/{src-D31D1_oY.js → src-BZkY6N3J.js} +909 -198
- package/dist/assets/src-BZkY6N3J.js.map +1 -0
- package/dist/assets/{sshForges-DerRwMf3.js → sshForges-Cxjt3c51.js} +2 -2
- package/dist/assets/{sshForges-DerRwMf3.js.map → sshForges-Cxjt3c51.js.map} +1 -1
- package/dist/assets/{translate-C-sj0VJe.js → translate-v8wF1GcF.js} +2 -2
- package/dist/assets/{translate-C-sj0VJe.js.map → translate-v8wF1GcF.js.map} +1 -1
- package/dist/assets/{usdt-DwHqp625.js → usdt-63gYjM5E.js} +7 -4
- package/dist/assets/usdt-63gYjM5E.js.map +1 -0
- package/dist/assets/{waitNotice-D52RWbV4.js → waitNotice-Ce3YCinu.js} +27 -5
- package/dist/assets/waitNotice-Ce3YCinu.js.map +1 -0
- package/dist/assets/{words-Db9WgatT.js → words-PUnyO4ph.js} +4 -4
- package/dist/assets/words-PUnyO4ph.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-EUGHGnRz.js.map +0 -1
- package/dist/assets/apiKit-CJVp_crp.js.map +0 -1
- package/dist/assets/buttons-DA3wZfG0.js +0 -2
- package/dist/assets/client-CDa87uYD.js.map +0 -1
- package/dist/assets/fileBytesIdb-CD5Uv490.js +0 -2
- package/dist/assets/fixedHosts-C6nCHjOa.js.map +0 -1
- package/dist/assets/groupFiles-DYopNE57.js.map +0 -1
- package/dist/assets/host-G5seUwaI.js.map +0 -1
- package/dist/assets/main-Dk--nD7X.js.map +0 -1
- package/dist/assets/mainline-HPlVrl8R.js.map +0 -1
- package/dist/assets/ownDid-DJFZM2cV.js.map +0 -1
- package/dist/assets/profiles-DKmZGXp6.js.map +0 -1
- package/dist/assets/registry-BUm4cAzV.js.map +0 -1
- package/dist/assets/resolve-CDD4X68j.js.map +0 -1
- package/dist/assets/server-DcOsgYDU.js.map +0 -1
- package/dist/assets/src-D31D1_oY.js.map +0 -1
- package/dist/assets/usdt-DwHqp625.js.map +0 -1
- package/dist/assets/waitNotice-D52RWbV4.js.map +0 -1
- package/dist/assets/words-Db9WgatT.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $n as engineError, Ai as IDENTITY_REVOCATION_LABEL,
|
|
1
|
+
import { $n as engineError, Ai as IDENTITY_REVOCATION_LABEL, Bi as newIdentityBinding, Dn as requestLnurlInvoice, Fi as emptyIdentityLedger, Gr as transferEnded, Hi as revokesIdentity, Ii as identityRefusal, Iu as budgetRetryMs, J as meshMessageRef, Li as identityRevocationValue, Lu as isDiscoveryBudgetError, Mi as IdentityExchange, Ni as boundIdentityDisplay, On as resolveLightningDestination, Pa as fileMessageText, Ri as identityStatement, Ua as RateWindow, Ur as FileUplink, Vi as receivedIdentityStatus, Vr as ChatFiles, ad as toBase64Url, an as WALLET_NETWORKS, ar as GROUP_WANT_NO_FRAME, cr as isGroupMessageId, dn as walletNetworkOf, dr as readGroupWant, er as engineText, fr as readGroupWantNo, id as randomBytes, ji as IdentityCheckUnavailable, ki as IDENTITY_MAX_VALIDITY, kn as decodeBolt11, lo as replySnippet, nd as fromBase64Url, nr as GROUP_FILE_LIMITS, or as fetchesByItself, rr as GROUP_HAVE_FRAME, sr as groupFileFallback, ur as readGroupHave, zi as isIdentityBinding } from "./src-BZkY6N3J.js";
|
|
2
2
|
import { a as describeProvider, c as offeredIn, d as sourceProblem, n as PROVIDER_PLATFORMS, o as isNothingSpentError, s as networkMode, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
3
3
|
import { g as wrap, h as transact, i as STORES, m as store, s as databaseName, u as fileStore } from "./idb-BHsAqENE.js";
|
|
4
|
-
import { a as sealSeed,
|
|
4
|
+
import { a as sealSeed, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, m as openSecret, o as unsealSeed, t as networkReason } from "./networkReason-BEl-DDWd.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 { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-
|
|
6
|
+
import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-D67KNdJq.js";
|
|
7
|
+
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BABGEF13.js";
|
|
8
8
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
9
9
|
import { validateMnemonic } from "@scure/bip39";
|
|
10
10
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
@@ -315,6 +315,57 @@ async function dropBreezDatabase(name, options = {}) {
|
|
|
315
315
|
}).catch(() => {});
|
|
316
316
|
}
|
|
317
317
|
//#endregion
|
|
318
|
+
//#region ../browser/src/engine/askBackoff.ts
|
|
319
|
+
/**
|
|
320
|
+
* A growing wait with a cap, for whatever a wallet asks about again until it gets an answer: a Cashu melt or swap whose
|
|
321
|
+
* mint does not answer or keeps it pending, restored ecash at a mint that cannot say what is spent, a Lightning card's
|
|
322
|
+
* payment its source keeps pending or cannot be reached about. Asked at a fixed pace, each of these knocked on a dead
|
|
323
|
+
* mint or source every 15 to 60 s for as long as the app ran.
|
|
324
|
+
*
|
|
325
|
+
* Each key is asked at `firstMs` while it is `fast` (a request may still land, the payment is new), then twice as late
|
|
326
|
+
* after every ask with no answer, up to `capMs`. The pace lives in memory: an app start asks at once, and so does a
|
|
327
|
+
* caller that knows something changed (it `forget`s the key, or asks whatever the pace says).
|
|
328
|
+
*/
|
|
329
|
+
var AskBackoff = class {
|
|
330
|
+
firstMs;
|
|
331
|
+
capMs;
|
|
332
|
+
paces = /* @__PURE__ */ new Map();
|
|
333
|
+
constructor(firstMs, capMs) {
|
|
334
|
+
this.firstMs = firstMs;
|
|
335
|
+
this.capMs = capMs;
|
|
336
|
+
}
|
|
337
|
+
/** Whether `key` may be asked now: never asked in this run, or its time came. */
|
|
338
|
+
due(key, now) {
|
|
339
|
+
const pace = this.paces.get(key);
|
|
340
|
+
return !pace || now >= pace.at;
|
|
341
|
+
}
|
|
342
|
+
/** When `key` is asked next; `now` if it never was in this run. */
|
|
343
|
+
at(key, now) {
|
|
344
|
+
return this.paces.get(key)?.at ?? now;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* `key` was asked and gave no answer (unreachable, an error, still pending). The next ask waits `firstMs` while
|
|
348
|
+
* `fast`, else twice the last wait, up to `capMs`. Returns that wait.
|
|
349
|
+
*/
|
|
350
|
+
missed(key, now, fast = false) {
|
|
351
|
+
const last = this.paces.get(key)?.wait;
|
|
352
|
+
const wait = fast || last === void 0 ? this.firstMs : Math.min(last * 2, this.capMs);
|
|
353
|
+
this.paces.set(key, {
|
|
354
|
+
at: now + wait,
|
|
355
|
+
wait
|
|
356
|
+
});
|
|
357
|
+
return wait;
|
|
358
|
+
}
|
|
359
|
+
/** `key` answered, or is gone: its next ask is due at once. */
|
|
360
|
+
forget(key) {
|
|
361
|
+
this.paces.delete(key);
|
|
362
|
+
}
|
|
363
|
+
/** Forgets every key but these (the ones still open). */
|
|
364
|
+
keepOnly(keys) {
|
|
365
|
+
for (const key of this.paces.keys()) if (!keys.has(key)) this.paces.delete(key);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
//#endregion
|
|
318
369
|
//#region ../browser/src/engine/paymentAdapters/providers/cashuMint.ts
|
|
319
370
|
var CASHU_MINT_SOURCE = "cashu-mint";
|
|
320
371
|
var parseRef = (ref) => {
|
|
@@ -474,6 +525,14 @@ function retryDelay(failures, random = Math.random) {
|
|
|
474
525
|
return Math.round(base * (.8 + .4 * random()));
|
|
475
526
|
}
|
|
476
527
|
/**
|
|
528
|
+
* A connected source whose balance read gets no answer (its node went off, the relay is down) is read again twice as
|
|
529
|
+
* late after each failed read, from `refreshMs` up to this (`AskBackoff`, as a Lightning card's pending payment): at
|
|
530
|
+
* the fixed 15 s it was 240 failed requests an hour, for good. A read that answers, waking up and Retry read at once
|
|
531
|
+
* and go back to `refreshMs`.
|
|
532
|
+
*/
|
|
533
|
+
var REFRESH_SLOW_MS = 18e5;
|
|
534
|
+
var REFRESH_MS = 15e3;
|
|
535
|
+
/**
|
|
477
536
|
* Gives up on a connection when its signal aborts (a change of settings interrupts an attempt), even if the
|
|
478
537
|
* provider does not listen to it; what still arrives afterwards is closed.
|
|
479
538
|
*/
|
|
@@ -517,6 +576,8 @@ var ProviderSources = class {
|
|
|
517
576
|
failingSince;
|
|
518
577
|
seen;
|
|
519
578
|
stopped = false;
|
|
579
|
+
/** When the balance is read next, while reads get no answer (one key: this source). */
|
|
580
|
+
reads;
|
|
520
581
|
view = {
|
|
521
582
|
mode: "mainnet",
|
|
522
583
|
status: "none",
|
|
@@ -530,6 +591,8 @@ var ProviderSources = class {
|
|
|
530
591
|
status: "none",
|
|
531
592
|
offered: []
|
|
532
593
|
};
|
|
594
|
+
const every = options.refreshMs ?? REFRESH_MS;
|
|
595
|
+
this.reads = new AskBackoff(every, Math.max(every, REFRESH_SLOW_MS));
|
|
533
596
|
}
|
|
534
597
|
serial(run) {
|
|
535
598
|
const next = this.queue.then(run, run);
|
|
@@ -602,9 +665,16 @@ var ProviderSources = class {
|
|
|
602
665
|
this.connecting = void 0;
|
|
603
666
|
});
|
|
604
667
|
}
|
|
605
|
-
/**
|
|
668
|
+
/**
|
|
669
|
+
* Retry, now: the wait before the next attempt is skipped (a connected source reads its balance now, whatever
|
|
670
|
+
* the wait its failed reads earned). Resolves when the attempt ends.
|
|
671
|
+
*/
|
|
606
672
|
retryNow() {
|
|
607
|
-
if (this.
|
|
673
|
+
if (this.stopped) return Promise.resolve();
|
|
674
|
+
if (this.provider) {
|
|
675
|
+
this.reads.forget("balance");
|
|
676
|
+
return this.refresh();
|
|
677
|
+
}
|
|
608
678
|
clearTimeout(this.retry);
|
|
609
679
|
return this.ensureReady(true);
|
|
610
680
|
}
|
|
@@ -615,6 +685,7 @@ var ProviderSources = class {
|
|
|
615
685
|
wake() {
|
|
616
686
|
if (this.stopped) return;
|
|
617
687
|
if (this.provider) {
|
|
688
|
+
this.reads.forget("balance");
|
|
618
689
|
this.refresh();
|
|
619
690
|
return;
|
|
620
691
|
}
|
|
@@ -928,6 +999,7 @@ var ProviderSources = class {
|
|
|
928
999
|
return;
|
|
929
1000
|
}
|
|
930
1001
|
const before = this.view;
|
|
1002
|
+
let wait = this.options.refreshMs ?? REFRESH_MS;
|
|
931
1003
|
try {
|
|
932
1004
|
const details = await this.options.refresh(provider);
|
|
933
1005
|
if (provider !== this.provider) return;
|
|
@@ -939,19 +1011,24 @@ var ProviderSources = class {
|
|
|
939
1011
|
error: void 0
|
|
940
1012
|
};
|
|
941
1013
|
this.remember(details);
|
|
1014
|
+
this.reads.forget("balance");
|
|
942
1015
|
} catch (error) {
|
|
943
1016
|
if (provider !== this.provider) return;
|
|
944
1017
|
this.view = {
|
|
945
1018
|
...this.view,
|
|
946
1019
|
error: `Could not read the balance: ${redact(error, this.secrets)}`
|
|
947
1020
|
};
|
|
1021
|
+
wait = this.reads.missed("balance", Date.now());
|
|
948
1022
|
}
|
|
949
1023
|
const after = this.view, was = before;
|
|
950
1024
|
if (Object.keys({
|
|
951
1025
|
...was,
|
|
952
1026
|
...after
|
|
953
1027
|
}).some((key) => was[key] !== after[key])) this.options.changed();
|
|
954
|
-
if (this.provider)
|
|
1028
|
+
if (this.provider) {
|
|
1029
|
+
clearTimeout(this.timer);
|
|
1030
|
+
this.timer = setTimeout(() => void this.refresh(), wait);
|
|
1031
|
+
}
|
|
955
1032
|
}
|
|
956
1033
|
/** Keeps the balance read, for the next start: written only when it changed. */
|
|
957
1034
|
remember({ balance, unconfirmed }) {
|
|
@@ -974,6 +1051,7 @@ var ProviderSources = class {
|
|
|
974
1051
|
async disconnect(forget = false) {
|
|
975
1052
|
clearTimeout(this.timer);
|
|
976
1053
|
clearTimeout(this.retry);
|
|
1054
|
+
this.reads.forget("balance");
|
|
977
1055
|
this.controller.abort();
|
|
978
1056
|
this.controller = new AbortController();
|
|
979
1057
|
const provider = this.provider;
|
|
@@ -990,57 +1068,6 @@ var ProviderSources = class {
|
|
|
990
1068
|
}
|
|
991
1069
|
};
|
|
992
1070
|
//#endregion
|
|
993
|
-
//#region ../browser/src/engine/askBackoff.ts
|
|
994
|
-
/**
|
|
995
|
-
* A growing wait with a cap, for whatever a wallet asks about again until it gets an answer: a Cashu melt or swap whose
|
|
996
|
-
* mint does not answer or keeps it pending, restored ecash at a mint that cannot say what is spent, a Lightning card's
|
|
997
|
-
* payment its source keeps pending or cannot be reached about. Asked at a fixed pace, each of these knocked on a dead
|
|
998
|
-
* mint or source every 15 to 60 s for as long as the app ran.
|
|
999
|
-
*
|
|
1000
|
-
* Each key is asked at `firstMs` while it is `fast` (a request may still land, the payment is new), then twice as late
|
|
1001
|
-
* after every ask with no answer, up to `capMs`. The pace lives in memory: an app start asks at once, and so does a
|
|
1002
|
-
* caller that knows something changed (it `forget`s the key, or asks whatever the pace says).
|
|
1003
|
-
*/
|
|
1004
|
-
var AskBackoff = class {
|
|
1005
|
-
firstMs;
|
|
1006
|
-
capMs;
|
|
1007
|
-
paces = /* @__PURE__ */ new Map();
|
|
1008
|
-
constructor(firstMs, capMs) {
|
|
1009
|
-
this.firstMs = firstMs;
|
|
1010
|
-
this.capMs = capMs;
|
|
1011
|
-
}
|
|
1012
|
-
/** Whether `key` may be asked now: never asked in this run, or its time came. */
|
|
1013
|
-
due(key, now) {
|
|
1014
|
-
const pace = this.paces.get(key);
|
|
1015
|
-
return !pace || now >= pace.at;
|
|
1016
|
-
}
|
|
1017
|
-
/** When `key` is asked next; `now` if it never was in this run. */
|
|
1018
|
-
at(key, now) {
|
|
1019
|
-
return this.paces.get(key)?.at ?? now;
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* `key` was asked and gave no answer (unreachable, an error, still pending). The next ask waits `firstMs` while
|
|
1023
|
-
* `fast`, else twice the last wait, up to `capMs`. Returns that wait.
|
|
1024
|
-
*/
|
|
1025
|
-
missed(key, now, fast = false) {
|
|
1026
|
-
const last = this.paces.get(key)?.wait;
|
|
1027
|
-
const wait = fast || last === void 0 ? this.firstMs : Math.min(last * 2, this.capMs);
|
|
1028
|
-
this.paces.set(key, {
|
|
1029
|
-
at: now + wait,
|
|
1030
|
-
wait
|
|
1031
|
-
});
|
|
1032
|
-
return wait;
|
|
1033
|
-
}
|
|
1034
|
-
/** `key` answered, or is gone: its next ask is due at once. */
|
|
1035
|
-
forget(key) {
|
|
1036
|
-
this.paces.delete(key);
|
|
1037
|
-
}
|
|
1038
|
-
/** Forgets every key but these (the ones still open). */
|
|
1039
|
-
keepOnly(keys) {
|
|
1040
|
-
for (const key of this.paces.keys()) if (!keys.has(key)) this.paces.delete(key);
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
//#endregion
|
|
1044
1071
|
//#region ../browser/src/engine/invoicePace.ts
|
|
1045
1072
|
/**
|
|
1046
1073
|
* How often an open invoice of ours is asked about, at its Cashu mint or at a Lightning card's source (agents#2447).
|
|
@@ -1064,6 +1091,13 @@ var INVOICE_PACE = {
|
|
|
1064
1091
|
watchMs: 9e4,
|
|
1065
1092
|
/** A quote or an invoice goes only this long after its expiry, once its mint or source says it is unpaid. */
|
|
1066
1093
|
expiryGraceMs: 6e4,
|
|
1094
|
+
/**
|
|
1095
|
+
* A mint or a Lightning card's source that does not answer about an invoice, or answers with an error, is asked again
|
|
1096
|
+
* after this, then twice as late each time up to `missedCapMs` (`AskBackoff`): the pace above never looked at whether
|
|
1097
|
+
* it answered, and a dead mint or node was asked every minute (every 4 s about a paid invoice) for good.
|
|
1098
|
+
*/
|
|
1099
|
+
missedMs: 3e4,
|
|
1100
|
+
missedCapMs: 18e5,
|
|
1067
1101
|
/** Due this close to now counts as due: a timer may fire a moment before the clock reads its time. */
|
|
1068
1102
|
dueSlackMs: 250
|
|
1069
1103
|
};
|
|
@@ -1157,6 +1191,13 @@ var LightningService = class {
|
|
|
1157
1191
|
asked = /* @__PURE__ */ new Map();
|
|
1158
1192
|
/** Per invoice the screen shows (payment hash): until when (`watch`). */
|
|
1159
1193
|
watched = /* @__PURE__ */ new Map();
|
|
1194
|
+
/**
|
|
1195
|
+
* Per open invoice whose source did not answer about it, or answered with an error (payment hash): as Cashu quotes',
|
|
1196
|
+
* on top of its own pace. Asked every minute for good, one invoice cost 60 lookups an hour at a dead node, 20 cost 1,200.
|
|
1197
|
+
*/
|
|
1198
|
+
invoiceAsk = new AskBackoff(INVOICE_PACE.missedMs, INVOICE_PACE.missedCapMs);
|
|
1199
|
+
/** When an open invoice in `recent` next reads as expired (`shownExpiredAt`): the view is read again then. */
|
|
1200
|
+
recentTurns = Infinity;
|
|
1160
1201
|
/** Per outgoing payment left pending or unknown (payment hash): when its source is asked next, in this run. */
|
|
1161
1202
|
outAsk = new AskBackoff(OUT_POLL_MS, OUT_SLOW_POLL_MS);
|
|
1162
1203
|
passes = Promise.resolve();
|
|
@@ -1221,6 +1262,7 @@ var LightningService = class {
|
|
|
1221
1262
|
async createInvoice(amount, context = {}) {
|
|
1222
1263
|
const { provider, descriptor } = await this.sources.use();
|
|
1223
1264
|
if (!provider.capabilities.receive) throw new Error(`${descriptor.label} cannot create invoices`);
|
|
1265
|
+
if (!provider.capabilities.lookup && !provider.settlesItself) throw new Error(`${descriptor.label} cannot look up its invoices, so a payment to it would never be seen: receive with another Lightning card, or connect it with invoice lookup allowed`);
|
|
1224
1266
|
const created = await provider.createInvoice(amount, context.memo ?? "Ghostly");
|
|
1225
1267
|
const decoded = decodeBolt11(created.invoice);
|
|
1226
1268
|
if (!decoded || decoded.amountSat !== amount || decoded.paymentHash && decoded.paymentHash !== created.paymentHash || created.amount !== amount) throw new Error(`${descriptor.label} returned an invoice that does not match the request`);
|
|
@@ -1256,6 +1298,7 @@ var LightningService = class {
|
|
|
1256
1298
|
const op = hash ? await this.get("in", hash) : void 0;
|
|
1257
1299
|
if (!op || !this.owns(op) || op.state !== "open") return false;
|
|
1258
1300
|
this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
|
|
1301
|
+
this.invoiceAsk.forget(op.paymentHash);
|
|
1259
1302
|
this.schedule(0);
|
|
1260
1303
|
return true;
|
|
1261
1304
|
}
|
|
@@ -1268,6 +1311,7 @@ var LightningService = class {
|
|
|
1268
1311
|
const op = hash ? await this.get("in", hash) : void 0;
|
|
1269
1312
|
if (!op || !this.owns(op) || op.state !== "open") return false;
|
|
1270
1313
|
this.watched.set(op.paymentHash, Date.now() + INVOICE_PACE.watchMs);
|
|
1314
|
+
this.invoiceAsk.forget(op.paymentHash);
|
|
1271
1315
|
await this.reconcile(false, op.paymentHash);
|
|
1272
1316
|
return true;
|
|
1273
1317
|
}
|
|
@@ -1457,9 +1501,10 @@ var LightningService = class {
|
|
|
1457
1501
|
}
|
|
1458
1502
|
/**
|
|
1459
1503
|
* Asks the active source about everything of its that is open, pending or unknown. One pass at a time. `paced`: an
|
|
1460
|
-
* open invoice only when its pace says so (`nextInvoiceAsk
|
|
1461
|
-
* own does (`outAsk`); otherwise every one now.
|
|
1462
|
-
*
|
|
1504
|
+
* open invoice only when its pace says so (`nextInvoiceAsk`, and not before the wait its source's silence earned,
|
|
1505
|
+
* `invoiceAsk`), and a payment left pending or unknown only when its own does (`outAsk`); otherwise every one now.
|
|
1506
|
+
* Once one open invoice got no answer in a pass, the others due in it wait as that one does, unasked. `only`: the
|
|
1507
|
+
* open invoice with this payment hash alone (a payer says it paid it, `check`).
|
|
1463
1508
|
*/
|
|
1464
1509
|
reconcile(paced = false, only) {
|
|
1465
1510
|
const pass = this.passes.then(() => this.reconcileOnce(paced, only));
|
|
@@ -1482,12 +1527,20 @@ var LightningService = class {
|
|
|
1482
1527
|
};
|
|
1483
1528
|
/** When the next open invoice is due. */
|
|
1484
1529
|
let invoiceDue = Infinity;
|
|
1530
|
+
/** An open invoice got no answer in this pass: the source is taken as down until the next one. */
|
|
1531
|
+
let down = false;
|
|
1532
|
+
/** An open invoice of ours got no answer: asked again later, and later each time (on top of its own pace). */
|
|
1533
|
+
const unanswered = (op) => {
|
|
1534
|
+
this.invoiceAsk.missed(op.paymentHash, Date.now());
|
|
1535
|
+
invoiceDue = Math.min(invoiceDue, this.nextAsk(op, Date.now()));
|
|
1536
|
+
};
|
|
1485
1537
|
const writes = this.writes;
|
|
1486
1538
|
try {
|
|
1487
1539
|
const provider = this.sources.active, providerId = this.sources.activeId;
|
|
1488
1540
|
const ops = await this.list();
|
|
1489
1541
|
const open = new Set(ops.filter((op) => op.direction === "in" && op.state === "open").map((op) => op.paymentHash));
|
|
1490
1542
|
for (const pace of [this.asked, this.watched]) for (const hash of pace.keys()) if (!open.has(hash)) pace.delete(hash);
|
|
1543
|
+
this.invoiceAsk.keepOnly(open);
|
|
1491
1544
|
this.outAsk.keepOnly(new Set(ops.filter((op) => op.direction === "out" && ["pending", "unknown"].includes(op.state)).map((op) => op.paymentHash)));
|
|
1492
1545
|
for (const op of ops) {
|
|
1493
1546
|
if (!this.owns(op) || only !== void 0 && (op.direction !== "in" || op.paymentHash !== only)) continue;
|
|
@@ -1529,6 +1582,10 @@ var LightningService = class {
|
|
|
1529
1582
|
continue;
|
|
1530
1583
|
}
|
|
1531
1584
|
this.asked.set(op.paymentHash, Date.now());
|
|
1585
|
+
if (down) {
|
|
1586
|
+
unanswered(op);
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1532
1589
|
} else if (notYet(op)) continue;
|
|
1533
1590
|
try {
|
|
1534
1591
|
const unchanged = async () => (await this.get(op.direction, op.paymentHash))?.state === op.state;
|
|
@@ -1540,6 +1597,7 @@ var LightningService = class {
|
|
|
1540
1597
|
expiresAt: op.expiresAt,
|
|
1541
1598
|
ref: op.ref
|
|
1542
1599
|
});
|
|
1600
|
+
this.invoiceAsk.forget(op.paymentHash);
|
|
1543
1601
|
if (!await unchanged()) continue;
|
|
1544
1602
|
if (status.state === "paid") {
|
|
1545
1603
|
await this.put({
|
|
@@ -1575,24 +1633,26 @@ var LightningService = class {
|
|
|
1575
1633
|
this.events.resolved(op, status.state === "paid");
|
|
1576
1634
|
}
|
|
1577
1635
|
} catch {
|
|
1578
|
-
if (op.direction === "in")
|
|
1579
|
-
|
|
1636
|
+
if (op.direction === "in") {
|
|
1637
|
+
down = true;
|
|
1638
|
+
unanswered(op);
|
|
1639
|
+
} else missed(op);
|
|
1580
1640
|
}
|
|
1581
1641
|
}
|
|
1582
1642
|
} finally {
|
|
1583
1643
|
if (await this.loadRecent() || this.writes !== writes) this.events.changed();
|
|
1584
|
-
const wait = Math.min(again || Infinity, invoiceDue - Date.now());
|
|
1644
|
+
const wait = Math.min(again || Infinity, invoiceDue - Date.now(), this.recentTurns - Date.now());
|
|
1585
1645
|
if (wait < Infinity) this.schedule(Math.max(0, wait));
|
|
1586
1646
|
}
|
|
1587
1647
|
}
|
|
1588
|
-
/** When the source is next asked about this open invoice of ours. */
|
|
1648
|
+
/** When the source is next asked about this open invoice of ours: at its pace, and not before the wait its silence earned. */
|
|
1589
1649
|
nextAsk(op, now) {
|
|
1590
|
-
return nextInvoiceAsk({
|
|
1650
|
+
return Math.max(this.invoiceAsk.at(op.paymentHash, 0), nextInvoiceAsk({
|
|
1591
1651
|
createdAt: op.createdAt,
|
|
1592
1652
|
expiresAt: op.expiresAt,
|
|
1593
1653
|
watchedUntil: this.watched.get(op.paymentHash),
|
|
1594
1654
|
closed: !!op.paymentId && !!this.events.requestClosed?.(op.paymentId)
|
|
1595
|
-
}, this.asked.get(op.paymentHash), now);
|
|
1655
|
+
}, this.asked.get(op.paymentHash), now));
|
|
1596
1656
|
}
|
|
1597
1657
|
/** The next pass in `ms`, unless one is due sooner. It asks only what is due (`reconcile(true)`). */
|
|
1598
1658
|
schedule(ms) {
|
|
@@ -1650,11 +1710,28 @@ var LightningService = class {
|
|
|
1650
1710
|
}
|
|
1651
1711
|
/** True when the recent list reads otherwise than before. */
|
|
1652
1712
|
async loadRecent() {
|
|
1653
|
-
const was = this.recent;
|
|
1654
|
-
|
|
1713
|
+
const was = this.recent, now = Date.now();
|
|
1714
|
+
const ops = (await this.list()).filter((op) => this.owns(op)).sort((a, b) => b.createdAt - a.createdAt).slice(0, RECENT);
|
|
1715
|
+
this.recentTurns = Math.min(Infinity, ...ops.map((op) => shownExpiredAt(op)).filter((at) => at > now));
|
|
1716
|
+
this.recent = ops.map((op) => {
|
|
1717
|
+
const { ref: _ref, note: _note, selfSettled: _self, ...view } = op;
|
|
1718
|
+
return shownExpiredAt(op) <= now ? {
|
|
1719
|
+
...view,
|
|
1720
|
+
state: "expired"
|
|
1721
|
+
} : view;
|
|
1722
|
+
});
|
|
1655
1723
|
return JSON.stringify(was) !== JSON.stringify(this.recent);
|
|
1656
1724
|
}
|
|
1657
1725
|
};
|
|
1726
|
+
/**
|
|
1727
|
+
* When an open invoice of ours that this engine asks about reads as expired, though no answer said so: past its expiry
|
|
1728
|
+
* and the grace a source's own "expired" gets. Its source may not answer for hours (a node that is off, an NWC relay
|
|
1729
|
+
* gone), and "waiting for payment" on an invoice nobody can pay any more is wrong. The journal keeps it open, and it is
|
|
1730
|
+
* still asked about (`invoiceAsk`), so a late "paid" counts. Infinity: shown as it is stored.
|
|
1731
|
+
*/
|
|
1732
|
+
function shownExpiredAt(op) {
|
|
1733
|
+
return op.direction === "in" && op.state === "open" && !op.selfSettled && op.expiresAt > 0 ? op.expiresAt + INVOICE_PACE.expiryGraceMs + 1 : Infinity;
|
|
1734
|
+
}
|
|
1658
1735
|
//#endregion
|
|
1659
1736
|
//#region ../browser/src/engine/paymentAdapters/providers/recoveryPhrase.ts
|
|
1660
1737
|
/** A phrase as BIP 39 wants it, however it was typed or pasted. */
|
|
@@ -2068,7 +2145,7 @@ var registry;
|
|
|
2068
2145
|
var loading;
|
|
2069
2146
|
var listeners = /* @__PURE__ */ new Set();
|
|
2070
2147
|
function loadIdentityProviders() {
|
|
2071
|
-
return loading ??= import("./registry-
|
|
2148
|
+
return loading ??= import("./registry-DN5a8Ul6.js").then((m) => {
|
|
2072
2149
|
registry = m;
|
|
2073
2150
|
for (const listener of listeners) listener();
|
|
2074
2151
|
return m;
|
|
@@ -2095,6 +2172,12 @@ var REVOCATIONS_CHECKED_AT = "identityRevocationsCheckedAt";
|
|
|
2095
2172
|
var REVOCATIONS_ROUND = "identityRevocationsRound";
|
|
2096
2173
|
/** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
|
|
2097
2174
|
var REPUBLISH_MS = 36e5;
|
|
2175
|
+
/**
|
|
2176
|
+
* A revocation is kept (with its sealed seed) this long past its expiry by this device's clock, which may be the one that
|
|
2177
|
+
* is wrong: the contacts decide expiry by theirs. Only a clock ahead by more than the longest a proof may last (400 days)
|
|
2178
|
+
* drops one still standing for them. Republished only until its expiry, as before; a few hundred bytes each.
|
|
2179
|
+
*/
|
|
2180
|
+
var REVOCATION_KEPT_PAST_EXPIRY = IDENTITY_MAX_VALIDITY;
|
|
2098
2181
|
/** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
|
|
2099
2182
|
var REVOCATION_CHECK_MS = 432e5;
|
|
2100
2183
|
/** A lookup that could not run (offline, no relay answered) is tried again after this, doubled each time, up to the 12 h. */
|
|
@@ -2129,10 +2212,18 @@ var WITHDRAWN_REVOCATION_TRIES_MS = [
|
|
|
2129
2212
|
* listed key that is gone then stops reading verified.
|
|
2130
2213
|
*/
|
|
2131
2214
|
var AUTO_RECHECK_AFTER_S = 86400;
|
|
2132
|
-
/**
|
|
2215
|
+
/**
|
|
2216
|
+
* Due proofs are looked for this often (the first time a few minutes after the start). Each time checks enough of them
|
|
2217
|
+
* to clear the ones due within `AUTO_RECHECK_SPREAD_TICKS` times (at least `AUTO_RECHECK_BATCH`), one every
|
|
2218
|
+
* `AUTO_RECHECK_GAP_MS` at most, so every proof is checked about a day after its last check however many contacts.
|
|
2219
|
+
*/
|
|
2133
2220
|
var AUTO_RECHECK_TICK_MS = 9e5;
|
|
2134
2221
|
var AUTO_RECHECK_FIRST_MS = 18e4;
|
|
2135
2222
|
var AUTO_RECHECK_BATCH = 3;
|
|
2223
|
+
var AUTO_RECHECK_SPREAD_TICKS = 4;
|
|
2224
|
+
var AUTO_RECHECK_GAP_MS = 4e3;
|
|
2225
|
+
/** The checks of one time fit before the next: 150 every 15 minutes, 14,400 a day. */
|
|
2226
|
+
var AUTO_RECHECK_MAX_BATCH = Math.floor(AUTO_RECHECK_TICK_MS * 2 / 3 / AUTO_RECHECK_GAP_MS);
|
|
2136
2227
|
/** 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. */
|
|
2137
2228
|
var AUTO_RECHECK_BACKOFF_MS = 72e5;
|
|
2138
2229
|
/** A proof begun and not completed is dropped this long after, or when a fifth one begins (the CLI says the same). */
|
|
@@ -2140,6 +2231,15 @@ var IDENTITY_DRAFT_TTL_MS = 18e5;
|
|
|
2140
2231
|
var MAX_PROOFS = 32;
|
|
2141
2232
|
var now = () => Math.floor(Date.now() / 1e3);
|
|
2142
2233
|
/**
|
|
2234
|
+
* A share of mine as every reader gets it (the app, the CLI, `getState`): its reason only in words this app writes
|
|
2235
|
+
* (identityRefusal), else none. A ledger kept from before that check holds the contact's own words there.
|
|
2236
|
+
*/
|
|
2237
|
+
var ownRefusal = (s) => {
|
|
2238
|
+
if (s.error === void 0 || identityRefusal(s.error) !== void 0) return s;
|
|
2239
|
+
const { error: _contactWords, ...rest } = s;
|
|
2240
|
+
return rest;
|
|
2241
|
+
};
|
|
2242
|
+
/**
|
|
2143
2243
|
* Identity proofs, engine side: the profile's own proofs (made once, on the Identities page) and, per
|
|
2144
2244
|
* chat, the `IdentityExchange` that shares them with that contact and checks what the contact shares.
|
|
2145
2245
|
* Providers come from the registry; their `verify` runs here, through the shared checks.
|
|
@@ -2170,6 +2270,8 @@ var IdentityProofs = class {
|
|
|
2170
2270
|
stops = 0;
|
|
2171
2271
|
/** Ends the 12 h lookup's wait (between two reads, or for the budget) at once: `stop`. */
|
|
2172
2272
|
wakeLookup;
|
|
2273
|
+
/** Ends the automatic re-check's wait between two checks at once: `stop`. */
|
|
2274
|
+
wakeRecheck;
|
|
2173
2275
|
/** Revocations not published because the app was offline: published when the network comes back (`networkBack`). */
|
|
2174
2276
|
unpublished = /* @__PURE__ */ new Set();
|
|
2175
2277
|
running = false;
|
|
@@ -2187,6 +2289,8 @@ var IdentityProofs = class {
|
|
|
2187
2289
|
greeted = /* @__PURE__ */ new Set();
|
|
2188
2290
|
/** Automatic re-checks that could not reach the server, by chat and proof: how many in a row, and when to try again (ms). */
|
|
2189
2291
|
recheckBackoff = /* @__PURE__ */ new Map();
|
|
2292
|
+
/** When the automatic re-check asked each provider with a `recheck.perHour` (ms), this last hour, by provider id. */
|
|
2293
|
+
recheckedAt = /* @__PURE__ */ new Map();
|
|
2190
2294
|
fetch;
|
|
2191
2295
|
constructor(host, providers = loadedIdentityProviders) {
|
|
2192
2296
|
this.host = host;
|
|
@@ -2256,6 +2360,7 @@ var IdentityProofs = class {
|
|
|
2256
2360
|
this.lookupTimer = void 0;
|
|
2257
2361
|
this.saveRound();
|
|
2258
2362
|
this.wakeLookup?.();
|
|
2363
|
+
this.wakeRecheck?.();
|
|
2259
2364
|
this.unlisten?.();
|
|
2260
2365
|
this.unlisten = void 0;
|
|
2261
2366
|
this.forgetSeeds();
|
|
@@ -2309,7 +2414,7 @@ var IdentityProofs = class {
|
|
|
2309
2414
|
let refused;
|
|
2310
2415
|
let fetch = this.fetch;
|
|
2311
2416
|
if (this.host.relayOnly?.()) {
|
|
2312
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
2417
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-CN3CsslV.js");
|
|
2313
2418
|
const fixed = fixedIdentityHosts();
|
|
2314
2419
|
fetch = async (url, options) => {
|
|
2315
2420
|
const host = new URL(url).host;
|
|
@@ -2433,8 +2538,7 @@ var IdentityProofs = class {
|
|
|
2433
2538
|
expiresAt: Math.min(proof.binding.expiresAt, proof.verified.expiresAt ?? Infinity)
|
|
2434
2539
|
};
|
|
2435
2540
|
const wasShared = this.everShared(proof);
|
|
2436
|
-
|
|
2437
|
-
await this.save((proofs, revocations) => proofs.some((p) => identityStatement(p.binding).id === id) ? [proofs.filter((p) => identityStatement(p.binding).id !== id), revoke ? [...revocations, revocation] : revocations] : [proofs, revocations]);
|
|
2541
|
+
await this.save((proofs, revocations) => proofs.some((p) => identityStatement(p.binding).id === id) ? [proofs.filter((p) => identityStatement(p.binding).id !== id), wasShared ? [...revocations, revocation] : revocations] : [proofs, revocations]);
|
|
2438
2542
|
if (wasShared) this.publishRevocation(revocation).catch(() => {});
|
|
2439
2543
|
else {
|
|
2440
2544
|
this.seeds.get(id)?.fill(0);
|
|
@@ -2450,7 +2554,7 @@ var IdentityProofs = class {
|
|
|
2450
2554
|
this.ended = true;
|
|
2451
2555
|
this.stop();
|
|
2452
2556
|
const at = now();
|
|
2453
|
-
const last = [...this.revocations
|
|
2557
|
+
const last = [...this.revocations, ...this.proofs.filter((p) => this.everShared(p)).map((p) => ({
|
|
2454
2558
|
id: identityStatement(p.binding).id,
|
|
2455
2559
|
key: p.binding.key,
|
|
2456
2560
|
seed: p.seed,
|
|
@@ -2477,15 +2581,15 @@ var IdentityProofs = class {
|
|
|
2477
2581
|
}]);
|
|
2478
2582
|
}
|
|
2479
2583
|
async republish() {
|
|
2480
|
-
const
|
|
2481
|
-
if (
|
|
2482
|
-
for (const r of this.revocations) if (!
|
|
2584
|
+
const kept = (r) => r.expiresAt + REVOCATION_KEPT_PAST_EXPIRY > now();
|
|
2585
|
+
if (!this.revocations.every(kept)) {
|
|
2586
|
+
for (const r of this.revocations) if (!kept(r)) {
|
|
2483
2587
|
this.seeds.get(r.id)?.fill(0);
|
|
2484
2588
|
this.seeds.delete(r.id);
|
|
2485
2589
|
}
|
|
2486
|
-
await this.save((proofs, revocations) => [proofs, revocations.filter(
|
|
2590
|
+
await this.save((proofs, revocations) => [proofs, revocations.filter(kept)]);
|
|
2487
2591
|
}
|
|
2488
|
-
for (const r of
|
|
2592
|
+
for (const r of this.revocations.filter((r) => r.expiresAt > now())) {
|
|
2489
2593
|
if (!this.running) return;
|
|
2490
2594
|
await this.publishRevocation(r).catch(() => {});
|
|
2491
2595
|
}
|
|
@@ -2572,9 +2676,10 @@ var IdentityProofs = class {
|
|
|
2572
2676
|
}).catch(() => {});
|
|
2573
2677
|
}
|
|
2574
2678
|
/**
|
|
2575
|
-
* The contacts' proofs due for an automatic re-check (`AUTO_RECHECK_AFTER_S`), the longest unchecked first,
|
|
2576
|
-
*
|
|
2577
|
-
*
|
|
2679
|
+
* The contacts' proofs due for an automatic re-check (`AUTO_RECHECK_AFTER_S`), the longest unchecked first, as many
|
|
2680
|
+
* at a time as keep up with them (`AUTO_RECHECK_SPREAD_TICKS`), one after the other a few seconds apart, and no more
|
|
2681
|
+
* an hour of a provider's than its `recheck.perHour`. A proof whose
|
|
2682
|
+
* record or key is gone shows unconfirmed with the reason, as after "Check again"; one whose server could not be reached (or a network that went away meanwhile) is left as it was and backs off.
|
|
2578
2683
|
*/
|
|
2579
2684
|
async recheckDue() {
|
|
2580
2685
|
if (!this.host.online()) return;
|
|
@@ -2583,14 +2688,24 @@ var IdentityProofs = class {
|
|
|
2583
2688
|
for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) {
|
|
2584
2689
|
const after = this.providers().find((p) => p.id === r.binding.provider)?.recheck?.afterSeconds;
|
|
2585
2690
|
if (after === void 0 || r.status !== "verified" && r.status !== "unconfirmed" || !this.revocable(r)) continue;
|
|
2586
|
-
if (t - r.checkedAt < Math.max(after, 86400) || (this.recheckBackoff.get(`${linkId}|${r.id}`)?.until ?? 0) > at) continue;
|
|
2691
|
+
if (r.checkedAt <= t && t - r.checkedAt < Math.max(after, 86400) || (this.recheckBackoff.get(`${linkId}|${r.id}`)?.until ?? 0) > at) continue;
|
|
2587
2692
|
due.push({
|
|
2588
2693
|
linkId,
|
|
2589
2694
|
r
|
|
2590
2695
|
});
|
|
2591
2696
|
}
|
|
2592
|
-
|
|
2697
|
+
let batch = Math.min(AUTO_RECHECK_MAX_BATCH, Math.max(AUTO_RECHECK_BATCH, Math.ceil(due.length / AUTO_RECHECK_SPREAD_TICKS)));
|
|
2698
|
+
let first = true;
|
|
2699
|
+
for (const { linkId, r } of due.sort((a, b) => a.r.checkedAt - b.r.checkedAt)) {
|
|
2700
|
+
if (batch === 0) return;
|
|
2701
|
+
const perHour = this.providers().find((p) => p.id === r.binding.provider)?.recheck?.perHour;
|
|
2702
|
+
const recent = perHour === void 0 ? void 0 : (this.recheckedAt.get(r.binding.provider) ?? []).filter((t) => t > Date.now() - 36e5 && t <= Date.now());
|
|
2703
|
+
if (recent && recent.length >= perHour) continue;
|
|
2704
|
+
batch--;
|
|
2705
|
+
if (!first && !await this.recheckPause(AUTO_RECHECK_GAP_MS)) return;
|
|
2706
|
+
first = false;
|
|
2593
2707
|
if (this.ended || !this.running || !this.host.online()) return;
|
|
2708
|
+
if (recent) this.recheckedAt.set(r.binding.provider, [...recent, Date.now()]);
|
|
2594
2709
|
const key = `${linkId}|${r.id}`;
|
|
2595
2710
|
try {
|
|
2596
2711
|
await this.exchange(linkId)?.recheck(r.id, { keepUnavailable: true });
|
|
@@ -2604,6 +2719,22 @@ var IdentityProofs = class {
|
|
|
2604
2719
|
}
|
|
2605
2720
|
}
|
|
2606
2721
|
}
|
|
2722
|
+
/** The automatic re-check's wait between two checks: false when `stop` ended it. */
|
|
2723
|
+
recheckPause(ms) {
|
|
2724
|
+
return new Promise((resolve) => {
|
|
2725
|
+
const timer = setTimeout(() => {
|
|
2726
|
+
this.timers = this.timers.filter((t) => t !== timer);
|
|
2727
|
+
this.wakeRecheck = void 0;
|
|
2728
|
+
resolve(true);
|
|
2729
|
+
}, ms);
|
|
2730
|
+
this.timers.push(timer);
|
|
2731
|
+
this.wakeRecheck = () => {
|
|
2732
|
+
clearTimeout(timer);
|
|
2733
|
+
this.wakeRecheck = void 0;
|
|
2734
|
+
resolve(false);
|
|
2735
|
+
};
|
|
2736
|
+
});
|
|
2737
|
+
}
|
|
2607
2738
|
/** The 12 h lookup's wait between two reads, or for the budget: false when `stop` ended it. */
|
|
2608
2739
|
lookupPause(ms) {
|
|
2609
2740
|
return new Promise((resolve) => {
|
|
@@ -2748,8 +2879,9 @@ var IdentityProofs = class {
|
|
|
2748
2879
|
const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
|
|
2749
2880
|
const provider = r && this.providers().find((p) => p.id === r.binding.provider);
|
|
2750
2881
|
if (!r || !provider?.lookupDisplay) throw new Error("No public profile for this identity");
|
|
2751
|
-
const
|
|
2752
|
-
if (!
|
|
2882
|
+
const found = await provider.lookupDisplay(r.verified.subject, { signal: AbortSignal.timeout(15e3) });
|
|
2883
|
+
if (!found) throw new Error("No public profile found");
|
|
2884
|
+
const display = boundIdentityDisplay(found);
|
|
2753
2885
|
await this.host.updateLedger(linkId, (l) => ({
|
|
2754
2886
|
...l,
|
|
2755
2887
|
received: l.received.map((x) => x.id === id && x.verified.subject === r.verified.subject ? {
|
|
@@ -2797,7 +2929,7 @@ var IdentityProofs = class {
|
|
|
2797
2929
|
return {
|
|
2798
2930
|
support: supported,
|
|
2799
2931
|
contactProviders: supported ? this.exchanges.get(linkId)?.contactProviders?.slice() : void 0,
|
|
2800
|
-
shared: ledger.shared,
|
|
2932
|
+
shared: ledger.shared.map(ownRefusal),
|
|
2801
2933
|
received: ledger.received.map((r) => {
|
|
2802
2934
|
const provider = this.providers().find((p) => p.id === r.binding.provider);
|
|
2803
2935
|
const status = receivedIdentityStatus(r, theirs, mine, t);
|
|
@@ -2813,7 +2945,7 @@ var IdentityProofs = class {
|
|
|
2813
2945
|
checkedAt: r.checkedAt,
|
|
2814
2946
|
expiresAt: Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity),
|
|
2815
2947
|
error: r.error,
|
|
2816
|
-
recheckDue: !!provider?.recheck && t - r.checkedAt >= provider.recheck.afterSeconds,
|
|
2948
|
+
recheckDue: !!provider?.recheck && (r.checkedAt > t || t - r.checkedAt >= provider.recheck.afterSeconds),
|
|
2817
2949
|
...publicProfile ? { publicProfile } : {}
|
|
2818
2950
|
};
|
|
2819
2951
|
}),
|
|
@@ -3184,6 +3316,11 @@ var storedGroupFiles = {
|
|
|
3184
3316
|
room: async () => (await fileBytes()).room()
|
|
3185
3317
|
};
|
|
3186
3318
|
/**
|
|
3319
|
+
* Time gone by, on the monotonic clock: a transfer's pace and how long it held its place, which a device clock set
|
|
3320
|
+
* ahead or back (`deps.now()`, the wall clock) would cut short or stretch. Stored times and the day stay on the wall clock.
|
|
3321
|
+
*/
|
|
3322
|
+
var elapsed = () => performance.now();
|
|
3323
|
+
/**
|
|
3187
3324
|
* Ended transfers an edge keeps the record of. A late frame for one of them is still answered as files/3 says (an abort
|
|
3188
3325
|
* to an asker going on with a transfer cancelled here); older ones are forgotten, so an edge's records stay few
|
|
3189
3326
|
* however many transfers it has seen.
|
|
@@ -3614,7 +3751,7 @@ var GroupFileDesk = class {
|
|
|
3614
3751
|
want.wire = frame.id;
|
|
3615
3752
|
want.why = void 0;
|
|
3616
3753
|
want.moved = -1;
|
|
3617
|
-
want.movedAt = want.offeredAt =
|
|
3754
|
+
want.movedAt = want.offeredAt = elapsed();
|
|
3618
3755
|
want.offeredBytes = kept.stored ?? 0;
|
|
3619
3756
|
want.free = void 0;
|
|
3620
3757
|
want.knownAtOffer = new Set(kept.holders);
|
|
@@ -3631,7 +3768,7 @@ var GroupFileDesk = class {
|
|
|
3631
3768
|
continue;
|
|
3632
3769
|
}
|
|
3633
3770
|
if (this.leaveSlow(kept, want) || this.leaveGone(kept, want)) continue;
|
|
3634
|
-
if (
|
|
3771
|
+
if ((want.wire ? elapsed() - want.movedAt : now - (want.holder ? want.at : want.round)) < GROUP_FILE_LIMITS.wantWaitMs) continue;
|
|
3635
3772
|
if (want.wire) {
|
|
3636
3773
|
kept.left = want.holder;
|
|
3637
3774
|
const edge = want.linkId ? this.edgesById.get(want.linkId) : void 0;
|
|
@@ -3685,13 +3822,20 @@ var GroupFileDesk = class {
|
|
|
3685
3822
|
* only queue again. So a file that ends asks the few wants it frees an edge for, not every want waiting (a member back
|
|
3686
3823
|
* from away with hundreds of files to fetch asked each of them once per file, more so with a member in the group that
|
|
3687
3824
|
* holds none of them, or serves none).
|
|
3825
|
+
* `freed`, the edge a file ended or was refused on: a want waiting with nobody to ask is asked again only when that is
|
|
3826
|
+
* its author's edge, whose turn it may wait for (`waitForKnown`). A free edge does nothing else for it: one up and
|
|
3827
|
+
* live to a member it could ask would have queued it, not left it waiting. What may (an edge up, a session open, a
|
|
3828
|
+
* member saying it holds the file, a new round) asks it then.
|
|
3688
3829
|
*/
|
|
3689
|
-
retry(groupId) {
|
|
3830
|
+
retry(groupId, freed) {
|
|
3690
3831
|
let free;
|
|
3832
|
+
const peer = freed === void 0 ? void 0 : this.edgesById.get(freed)?.peer;
|
|
3691
3833
|
for (const [id, want] of this.wants) {
|
|
3692
3834
|
const kept = this.kept.get(id);
|
|
3693
3835
|
if (kept?.groupId !== groupId || want.holder) continue;
|
|
3694
|
-
|
|
3836
|
+
const stage = this.deps.transfers.get(id)?.stage;
|
|
3837
|
+
if (freed !== void 0 && stage === "waiting" && kept.author !== peer) continue;
|
|
3838
|
+
if (stage === "queued" && !this.freeFor(kept, want, free ??= this.freeEdges(groupId))) continue;
|
|
3695
3839
|
this.ask(kept);
|
|
3696
3840
|
free = void 0;
|
|
3697
3841
|
}
|
|
@@ -3706,6 +3850,7 @@ var GroupFileDesk = class {
|
|
|
3706
3850
|
}
|
|
3707
3851
|
/** 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. */
|
|
3708
3852
|
freeFor(kept, want, free) {
|
|
3853
|
+
if (!free.length) return false;
|
|
3709
3854
|
const membership = this.deps.membership(kept.groupId);
|
|
3710
3855
|
if (!membership) return false;
|
|
3711
3856
|
const known = this.knownHolders(kept, membership);
|
|
@@ -3852,9 +3997,9 @@ var GroupFileDesk = class {
|
|
|
3852
3997
|
const edge = want.linkId ? this.edgesById.get(want.linkId) : void 0;
|
|
3853
3998
|
const record = edge?.files.get("in", want.wire);
|
|
3854
3999
|
if (!edge || !record || transferEnded(record) || record.state === "verifying") return false;
|
|
3855
|
-
const
|
|
3856
|
-
if (
|
|
3857
|
-
const stored = Math.max(want.moved, kept.stored ?? 0, want.offeredBytes ?? 0), pace = (stored - (want.offeredBytes ?? 0)) /
|
|
4000
|
+
const served = elapsed() - want.offeredAt;
|
|
4001
|
+
if (served < GROUP_FILE_LIMITS.slowAfterMs) return false;
|
|
4002
|
+
const stored = Math.max(want.moved, kept.stored ?? 0, want.offeredBytes ?? 0), pace = (stored - (want.offeredBytes ?? 0)) / served;
|
|
3858
4003
|
if (pace > 0 && (kept.meta.size - stored) / pace <= GROUP_FILE_LIMITS.wantWaitMs) return false;
|
|
3859
4004
|
const edges = this.deps.edges(kept.groupId);
|
|
3860
4005
|
const known = this.knownHolders(kept, this.deps.membership(kept.groupId)).filter((key) => want.knownAtOffer?.has(key));
|
|
@@ -3918,7 +4063,7 @@ var GroupFileDesk = class {
|
|
|
3918
4063
|
want.tried.add(peer);
|
|
3919
4064
|
want.holder = want.linkId = void 0;
|
|
3920
4065
|
this.ask(kept);
|
|
3921
|
-
this.retry(groupId);
|
|
4066
|
+
this.retry(groupId, linkId);
|
|
3922
4067
|
}
|
|
3923
4068
|
/** A member says it holds these files: remembered as a holder of each (newest first), and asked when a want waits. */
|
|
3924
4069
|
heard(groupId, from, ids) {
|
|
@@ -3964,10 +4109,11 @@ var GroupFileDesk = class {
|
|
|
3964
4109
|
}
|
|
3965
4110
|
const wire = toBase64Url(randomBytes(12));
|
|
3966
4111
|
edge.serving.set(wire, kept.id);
|
|
4112
|
+
const at = elapsed();
|
|
3967
4113
|
edge.servedMoved.set(wire, {
|
|
3968
4114
|
confirmed: 0,
|
|
3969
|
-
at
|
|
3970
|
-
from:
|
|
4115
|
+
at,
|
|
4116
|
+
from: at
|
|
3971
4117
|
});
|
|
3972
4118
|
const { name, mime, size, voice, video, image } = kept.meta;
|
|
3973
4119
|
const file = {
|
|
@@ -3995,7 +4141,7 @@ var GroupFileDesk = class {
|
|
|
3995
4141
|
this.letGo();
|
|
3996
4142
|
const active = this.servingNow();
|
|
3997
4143
|
const theirs = active.filter((a) => a.peer === edge.peer);
|
|
3998
|
-
const placed = theirs.length > 1 || theirs.some((a) => a.sending ||
|
|
4144
|
+
const placed = theirs.length > 1 || theirs.some((a) => a.sending || elapsed() - a.since >= GROUP_FILE_LIMITS.doneWaitMs);
|
|
3999
4145
|
const full = active.length >= GROUP_FILE_LIMITS.serveAtOnce;
|
|
4000
4146
|
const room = full && !placed ? this.roomFor() : void 0;
|
|
4001
4147
|
if (full && !room) {
|
|
@@ -4021,7 +4167,7 @@ var GroupFileDesk = class {
|
|
|
4021
4167
|
* first). With its share of the day (as in `servingNow`) and what it sent.
|
|
4022
4168
|
*/
|
|
4023
4169
|
roomFor() {
|
|
4024
|
-
const now =
|
|
4170
|
+
const now = elapsed();
|
|
4025
4171
|
let oldest;
|
|
4026
4172
|
let slowest;
|
|
4027
4173
|
for (const edge of this.edgesById.values()) for (const [wire, id] of edge.serving) {
|
|
@@ -4085,7 +4231,7 @@ var GroupFileDesk = class {
|
|
|
4085
4231
|
peer: edge.peer,
|
|
4086
4232
|
size: Math.max(record.file.size, edge.files.sent(wire)),
|
|
4087
4233
|
sending: record.confirmed < record.file.size,
|
|
4088
|
-
since: edge.servedMoved.get(wire)?.at ??
|
|
4234
|
+
since: edge.servedMoved.get(wire)?.at ?? elapsed()
|
|
4089
4235
|
});
|
|
4090
4236
|
}
|
|
4091
4237
|
return active;
|
|
@@ -4109,7 +4255,7 @@ var GroupFileDesk = class {
|
|
|
4109
4255
|
* overtaken its word for `doneWaitMs`.
|
|
4110
4256
|
*/
|
|
4111
4257
|
letGo() {
|
|
4112
|
-
const now =
|
|
4258
|
+
const now = elapsed();
|
|
4113
4259
|
const theirs = /* @__PURE__ */ new Map();
|
|
4114
4260
|
for (const a of this.servingNow()) theirs.set(a.peer, (theirs.get(a.peer) ?? 0) + 1);
|
|
4115
4261
|
for (const edge of this.edgesById.values()) for (const wire of [...edge.serving.keys()]) {
|
|
@@ -4222,7 +4368,7 @@ var GroupFileDesk = class {
|
|
|
4222
4368
|
edge.taking.delete(file.id);
|
|
4223
4369
|
if (this.wants.get(kept.id) === want && want.wire === file.id) {
|
|
4224
4370
|
this.stopFailed(kept, NO_ROOM);
|
|
4225
|
-
this.retry(kept.groupId);
|
|
4371
|
+
this.retry(kept.groupId, edge.linkId);
|
|
4226
4372
|
}
|
|
4227
4373
|
return {
|
|
4228
4374
|
refuse: "no-room",
|
|
@@ -4298,7 +4444,7 @@ var GroupFileDesk = class {
|
|
|
4298
4444
|
if (moved && record.confirmed > moved.confirmed && (record.confirmed - moved.confirmed >= GROUP_FILE_LIMITS.serveMoveBytes || record.confirmed === record.file.size)) edge.servedMoved.set(record.id, {
|
|
4299
4445
|
...moved,
|
|
4300
4446
|
confirmed: record.confirmed,
|
|
4301
|
-
at:
|
|
4447
|
+
at: elapsed()
|
|
4302
4448
|
});
|
|
4303
4449
|
if (transferEnded(record) && edge.serving.has(record.id)) {
|
|
4304
4450
|
const today = Math.floor(this.deps.now() / 864e5);
|
|
@@ -4322,7 +4468,7 @@ var GroupFileDesk = class {
|
|
|
4322
4468
|
if (want.moved < 0) want.moved = transferred;
|
|
4323
4469
|
else if (transferred - want.moved >= Math.min(GROUP_FILE_LIMITS.wantMoveBytes, kept.meta.size - want.moved)) {
|
|
4324
4470
|
want.moved = transferred;
|
|
4325
|
-
want.movedAt =
|
|
4471
|
+
want.movedAt = elapsed();
|
|
4326
4472
|
}
|
|
4327
4473
|
if (record.state !== "failed" && record.state !== "declined" && record.state !== "cancelled") kept.stored = transferred;
|
|
4328
4474
|
const { size } = kept.meta;
|
|
@@ -4338,7 +4484,7 @@ var GroupFileDesk = class {
|
|
|
4338
4484
|
} }).catch(() => {});
|
|
4339
4485
|
this.finished(kept, "in");
|
|
4340
4486
|
this.queueHave(kept);
|
|
4341
|
-
this.retry(kept.groupId);
|
|
4487
|
+
this.retry(kept.groupId, edge.linkId);
|
|
4342
4488
|
return;
|
|
4343
4489
|
case "failed":
|
|
4344
4490
|
case "declined":
|
|
@@ -4353,7 +4499,7 @@ var GroupFileDesk = class {
|
|
|
4353
4499
|
moved: 0
|
|
4354
4500
|
});
|
|
4355
4501
|
this.ask(kept);
|
|
4356
|
-
this.retry(kept.groupId);
|
|
4502
|
+
this.retry(kept.groupId, edge.linkId);
|
|
4357
4503
|
return;
|
|
4358
4504
|
case "verifying":
|
|
4359
4505
|
this.show(kept, {
|
|
@@ -4470,6 +4616,6 @@ function messageFile(kept) {
|
|
|
4470
4616
|
};
|
|
4471
4617
|
}
|
|
4472
4618
|
//#endregion
|
|
4473
|
-
export { ModeGate as $, IdentityProofs as A,
|
|
4619
|
+
export { ModeGate as $, IdentityProofs as A, ProviderSources as B, FileAppender as C, streamStored as D, storedSize as E, normalizePhrase as F, breezDatabase as G, CASHU_MINT_SOURCE as H, journaledPayment as I, dropBreezDatabase as J, breezDatabaseInUse as K, lightningPaying as L, LightningCards as M, cardsKey as N, waitingGroupFile as O, isRecoveryPhrase as P, ModeChanged as Q, INVOICE_PACE as R, WALLET_TYPES as S, removeStored as T, cashuMint as U, sourceKey as V, AskBackoff as W, iceServerSetting as X, iceServerProblem as Y, relayOnlyProblem as Z, crossNetwork as _, storedGroupFiles as a, setAwayWallets as at, walletInstances as b, receivedPairedReply as c, paymentAlias as d, WrongNetworkError as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, requireTurn as it, CASHU_CARD as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, awayFrom as nt, groupReply as o, setSingleWriterGate as ot, WALLET_NAMES as p, breezDatabasesFor as q, groupFileText as r, refuseAway as rt, pairedWireReply as s, GroupFileDesk as t, networkLabel as tt, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, nextInvoiceAsk as z };
|
|
4474
4620
|
|
|
4475
|
-
//# sourceMappingURL=groupFiles-
|
|
4621
|
+
//# sourceMappingURL=groupFiles-BFv9K_za.js.map
|