@ghostlytools/cli 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +22 -14
  2. package/SKILL.md +5 -1
  3. package/dist/assets/{api-CcuCtc1H.js → api-B42F9ytB.js} +2 -2
  4. package/dist/assets/{api-tSZELCPQ.js → api-tf-wAAnB.js} +214 -87
  5. package/dist/assets/api-tf-wAAnB.js.map +1 -0
  6. package/dist/assets/{apiKit-BFk7GAk9.js → apiKit-DJb9hulp.js} +33 -4
  7. package/dist/assets/{apiKit-BFk7GAk9.js.map → apiKit-DJb9hulp.js.map} +1 -1
  8. package/dist/assets/{apps-D6THreq_.js → apps-BfoDISRg.js} +1 -1
  9. package/dist/assets/{apps-C5Mi6x9Q.js → apps-DIrWmLgL.js} +3 -3
  10. package/dist/assets/{apps-C5Mi6x9Q.js.map → apps-DIrWmLgL.js.map} +1 -1
  11. package/dist/assets/{arkade-Cz0B9bJ0.js → arkade-CJAhhgPQ.js} +2 -2
  12. package/dist/assets/{arkade-Cz0B9bJ0.js.map → arkade-CJAhhgPQ.js.map} +1 -1
  13. package/dist/assets/{backup-A0hIa9GE.js → backup-BkUeeduy.js} +1 -1
  14. package/dist/assets/{backup-Wb2sm2dd.js → backup-Bko-AAm0.js} +4 -4
  15. package/dist/assets/{backup-Wb2sm2dd.js.map → backup-Bko-AAm0.js.map} +1 -1
  16. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  17. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  18. package/dist/assets/buttons-Be7u0V5g.js +2 -0
  19. package/dist/assets/{buttons-Cf70NVYq.js → buttons-DeA6Yddq.js} +34 -8
  20. package/dist/assets/buttons-DeA6Yddq.js.map +1 -0
  21. package/dist/assets/{envelope-kQ5kYjVE.js → envelope-Cz5fc7BM.js} +2 -2
  22. package/dist/assets/{envelope-kQ5kYjVE.js.map → envelope-Cz5fc7BM.js.map} +1 -1
  23. package/dist/assets/{groupFiles-D9Ttlm3M.js → groupFiles-BlZRBWpt.js} +558 -4
  24. package/dist/assets/groupFiles-BlZRBWpt.js.map +1 -0
  25. package/dist/assets/{host-DpypH-fR.js → host-BX0DmKW6.js} +38 -15
  26. package/dist/assets/host-BX0DmKW6.js.map +1 -0
  27. package/dist/assets/{hyperdhtRelay-D1rj84v2.js → hyperdhtRelay-DitYDnXx.js} +2 -2
  28. package/dist/assets/{hyperdhtRelay-D1rj84v2.js.map → hyperdhtRelay-DitYDnXx.js.map} +1 -1
  29. package/dist/assets/{irohWeb-BTSlWgEX.js → irohWeb-R3bcd34h.js} +2 -2
  30. package/dist/assets/{irohWeb-BTSlWgEX.js.map → irohWeb-R3bcd34h.js.map} +1 -1
  31. package/dist/assets/{main-BwgoQZVu.js → main-6QOSvQ8b.js} +247 -102
  32. package/dist/assets/main-6QOSvQ8b.js.map +1 -0
  33. package/dist/assets/{mainline-B1urhbEZ.js → mainline-BfwezHWi.js} +2 -2
  34. package/dist/assets/{mainline-B1urhbEZ.js.map → mainline-BfwezHWi.js.map} +1 -1
  35. package/dist/assets/{networkReason-D2Z0BdIj.js → networkReason-Ba9415nn.js} +2 -2
  36. package/dist/assets/{networkReason-D2Z0BdIj.js.map → networkReason-Ba9415nn.js.map} +1 -1
  37. package/dist/assets/{nwc-T2aUK6bi.js → nwc-ovXSN2M2.js} +3 -3
  38. package/dist/assets/{nwc-T2aUK6bi.js.map → nwc-ovXSN2M2.js.map} +1 -1
  39. package/dist/assets/{nwcProvider-Dz-ty_DE.js → nwcProvider-BzZbfFP3.js} +2 -2
  40. package/dist/assets/{nwcProvider-Dz-ty_DE.js.map → nwcProvider-BzZbfFP3.js.map} +1 -1
  41. package/dist/assets/{registry-Bazitl0a.js → registry-B0Uv9yL6.js} +3 -3
  42. package/dist/assets/{registry-Bazitl0a.js.map → registry-B0Uv9yL6.js.map} +1 -1
  43. package/dist/assets/{registry-BlSTJlbv.js → registry-CFtlhWCI.js} +1 -1
  44. package/dist/assets/{resolve-Bx1Eeg-w.js → resolve-BzFG4WDU.js} +2 -2
  45. package/dist/assets/{resolve-Bx1Eeg-w.js.map → resolve-BzFG4WDU.js.map} +1 -1
  46. package/dist/assets/{server-CnPj9wWh.js → server-BGCuHbmQ.js} +266 -594
  47. package/dist/assets/server-BGCuHbmQ.js.map +1 -0
  48. package/dist/assets/{src-BsznF3XG.js → src-DWw2hUE5.js} +106 -38
  49. package/dist/assets/src-DWw2hUE5.js.map +1 -0
  50. package/dist/assets/{translate-cDBotA-b.js → translate-DObb-1tq.js} +2 -2
  51. package/dist/assets/{translate-cDBotA-b.js.map → translate-DObb-1tq.js.map} +1 -1
  52. package/dist/assets/{usdt-DxxLdG60.js → usdt-Bkva90Vo.js} +3 -3
  53. package/dist/assets/{usdt-DxxLdG60.js.map → usdt-Bkva90Vo.js.map} +1 -1
  54. package/dist/assets/{words-qH8gGtmc.js → words-odSAoasK.js} +4 -2
  55. package/dist/assets/words-odSAoasK.js.map +1 -0
  56. package/dist/ghostly.mjs +1 -1
  57. package/package.json +1 -1
  58. package/dist/assets/api-tSZELCPQ.js.map +0 -1
  59. package/dist/assets/buttons-Bxxu3lSk.js +0 -2
  60. package/dist/assets/buttons-Cf70NVYq.js.map +0 -1
  61. package/dist/assets/groupFiles-D9Ttlm3M.js.map +0 -1
  62. package/dist/assets/host-DpypH-fR.js.map +0 -1
  63. package/dist/assets/main-BwgoQZVu.js.map +0 -1
  64. package/dist/assets/server-CnPj9wWh.js.map +0 -1
  65. package/dist/assets/src-BsznF3XG.js.map +0 -1
  66. package/dist/assets/words-qH8gGtmc.js.map +0 -1
@@ -1,8 +1,10 @@
1
- import { $n as readGroupWant, Ar as FileUplink, En as decodeBolt11, Gn as GROUP_HAVE_FRAME, Ha as replySnippet, Hn as engineText, Jn as fetchesByItself, Or as ChatFiles, Qn as readGroupHave, Tn as resolveLightningDestination, Vn as engineError, Wn as GROUP_FILE_LIMITS, Xn as isGroupMessageId, Yn as groupFileFallback, bu as randomBytes, cn as walletNetworkOf, er as readGroupWantNo, ha as fileMessageText, jr as transferEnded, nn as WALLET_NETWORKS, qn as GROUP_WANT_NO_FRAME, wa as RateWindow, wn as requestLnurlInvoice, xu as toBase64Url } from "./src-BsznF3XG.js";
1
+ import { $n as readGroupWant, Ar as FileUplink, Bi as IdentityExchange, En as decodeBolt11, Gi as newIdentityBinding, Gn as GROUP_HAVE_FRAME, Ha as replySnippet, Hi as emptyIdentityLedger, Hn as engineText, Jn as fetchesByItself, Ki as receivedIdentityStatus, Or as ChatFiles, Qn as readGroupHave, Ri as IDENTITY_REVOCATION_LABEL, Tn as resolveLightningDestination, Ui as identityRevocationValue, Vn as engineError, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Xn as isGroupMessageId, Yn as groupFileFallback, bu as randomBytes, cn as walletNetworkOf, er as readGroupWantNo, ha as fileMessageText, jr as transferEnded, nn as WALLET_NETWORKS, qi as revokesIdentity, qn as GROUP_WANT_NO_FRAME, vu as fromBase64Url, wa as RateWindow, wn as requestLnurlInvoice, xu as toBase64Url } from "./src-DWw2hUE5.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-BlH8-O3R.js";
4
- import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-D2Z0BdIj.js";
4
+ import { a as sealSeed, i as newDeviceKey, o as unsealSeed, t as networkReason } from "./networkReason-Ba9415nn.js";
5
5
  import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-BrlY773j.js";
6
+ import { v as boundedIdentityFetch, y as verifyIdentity } from "./resolve-BzFG4WDU.js";
7
+ import { i as fromBase64Url$1 } from "./envelope-Cz5fc7BM.js";
6
8
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BD0v3rRG.js";
7
9
  import { sha256 } from "@noble/hashes/sha2.js";
8
10
  import { validateMnemonic } from "@scure/bip39";
@@ -1861,6 +1863,558 @@ var LightningCards = class {
1861
1863
  }
1862
1864
  };
1863
1865
  //#endregion
1866
+ //#region ../browser/src/shared/profileKey.ts
1867
+ /**
1868
+ * Only the record key can hold a newline: the other parts come from the code, so the joined binding still reads one
1869
+ * way (the first two lines, the last line, and the key between them).
1870
+ */
1871
+ function binding(b) {
1872
+ for (const part of [
1873
+ b.db,
1874
+ b.store,
1875
+ b.field
1876
+ ]) if (!part || part.includes("\n")) throw new Error("Invalid sealed field binding");
1877
+ return new TextEncoder().encode([
1878
+ "ghostly-field/2",
1879
+ b.db,
1880
+ b.store,
1881
+ b.key,
1882
+ b.field
1883
+ ].join("\n"));
1884
+ }
1885
+ function isSealedField(value) {
1886
+ const v = value;
1887
+ return !!v && typeof v === "object" && v.v === 2 && typeof v.iv === "string" && typeof v.ct === "string";
1888
+ }
1889
+ /** Seals one field under DK with a fresh random 96-bit nonce and no KDF per field. */
1890
+ async function sealField(key, where, value) {
1891
+ const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
1892
+ const ct = new Uint8Array(await crypto.subtle.encrypt({
1893
+ name: "AES-GCM",
1894
+ iv,
1895
+ additionalData: binding(where)
1896
+ }, key, new TextEncoder().encode(value)));
1897
+ return {
1898
+ v: 2,
1899
+ iv: toBase64Url(iv),
1900
+ ct: toBase64Url(ct)
1901
+ };
1902
+ }
1903
+ /** Opens a field sealed for exactly this place under this DK; anything else fails instead of opening wrong. */
1904
+ async function openField(key, where, sealed) {
1905
+ if (!isSealedField(sealed)) throw new Error("Unsupported sealed field version");
1906
+ const aad = binding(where);
1907
+ try {
1908
+ const iv = fromBase64Url$1(sealed.iv);
1909
+ if (iv.length !== 12) throw new Error("nonce");
1910
+ return new TextDecoder().decode(await crypto.subtle.decrypt({
1911
+ name: "AES-GCM",
1912
+ iv,
1913
+ additionalData: aad
1914
+ }, key, fromBase64Url$1(sealed.ct)));
1915
+ } catch {
1916
+ throw new Error("A sealed field could not be opened: it was changed, or it belongs to another record");
1917
+ }
1918
+ }
1919
+ //#endregion
1920
+ //#region ../browser/src/engine/dataKey.ts
1921
+ var PEER_DB = "ghostly";
1922
+ /**
1923
+ * The profile's data key (DK), when the profile is encrypted and unlocked: the one slot the engine owns. A
1924
+ * non-extractable key; nothing writes it anywhere. Empty, every secret is sealed as today (version 1).
1925
+ */
1926
+ var slot = null;
1927
+ var onDrop = /* @__PURE__ */ new Set();
1928
+ /** A cache of opened secrets empties itself when the key goes. Returns the way to stop listening. */
1929
+ function whenDataKeyDropped(drop) {
1930
+ onDrop.add(drop);
1931
+ return () => {
1932
+ onDrop.delete(drop);
1933
+ };
1934
+ }
1935
+ async function sealSecret(value, at) {
1936
+ if (slot) return sealField(slot, {
1937
+ db: PEER_DB,
1938
+ ...at
1939
+ }, value);
1940
+ const deviceKey = newDeviceKey();
1941
+ return {
1942
+ sealed: await sealSeed(value, deviceKey),
1943
+ deviceKey
1944
+ };
1945
+ }
1946
+ /** Reads both versions: a profile being encrypted holds some of each until its migration ends. */
1947
+ async function openSecret(secret, at) {
1948
+ if (!isSealedField(secret)) return unsealSeed(secret.sealed, secret.deviceKey);
1949
+ if (!slot) throw new Error("This profile is locked. Enter its passphrase first.");
1950
+ return openField(slot, {
1951
+ db: PEER_DB,
1952
+ ...at
1953
+ }, secret);
1954
+ }
1955
+ //#endregion
1956
+ //#region ../browser/src/proofs/load.ts
1957
+ /**
1958
+ * The identity proof providers, loaded on first need and not with the app: they and their libraries (OpenPGP, the
1959
+ * Bitcoin signer, the DID, AT Protocol and OpenID Connect checks) are a large part of the code, and the first screen
1960
+ * draws none of it. The engine loads them with the profile's proofs; the UI once it draws something about identities.
1961
+ */
1962
+ var registry;
1963
+ var loading;
1964
+ var listeners = /* @__PURE__ */ new Set();
1965
+ function loadIdentityProviders() {
1966
+ return loading ??= import("./registry-CFtlhWCI.js").then((m) => {
1967
+ registry = m;
1968
+ for (const listener of listeners) listener();
1969
+ return m;
1970
+ }, (error) => {
1971
+ loading = void 0;
1972
+ throw error;
1973
+ });
1974
+ }
1975
+ /** The providers (built in, from plugins, the test ones when asked for), once loaded; none before. */
1976
+ var loadedIdentityProviders = () => registry?.identityProviders() ?? [];
1977
+ //#endregion
1978
+ //#region ../browser/src/engine/identities.ts
1979
+ /** Where a proof key's seed belongs: by proof id, so it still opens once the proof moved to the revocations. */
1980
+ var proofKeyAt = (id) => ({
1981
+ store: STORES.settings,
1982
+ key: id,
1983
+ field: "identityProof.seed"
1984
+ });
1985
+ var KEY = "identityProofs";
1986
+ var REVOCATIONS = "identityRevocations";
1987
+ /** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
1988
+ var REPUBLISH_MS = 36e5;
1989
+ /** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
1990
+ var REVOCATION_CHECK_MS = 432e5;
1991
+ /**
1992
+ * After a contact withdraws a proof, how long to wait before each lookup for its revocation (WISP 300: removing a proof withdraws it from
1993
+ * every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
1994
+ * off, and the first that finds it stops the rest. The 12 h check covers it after that.
1995
+ */
1996
+ var WITHDRAWN_REVOCATION_TRIES_MS = [
1997
+ 2e4,
1998
+ 6e4,
1999
+ 18e4
2000
+ ];
2001
+ /** A proof begun and not completed is dropped this long after, or when a fifth one begins (the CLI says the same). */
2002
+ var IDENTITY_DRAFT_TTL_MS = 18e5;
2003
+ var MAX_PROOFS = 32;
2004
+ var now = () => Math.floor(Date.now() / 1e3);
2005
+ /**
2006
+ * Identity proofs, engine side: the profile's own proofs (made once, on the Identities page) and, per
2007
+ * chat, the `IdentityExchange` that shares them with that contact and checks what the contact shares.
2008
+ * Providers come from the registry; their `verify` runs here, through the shared checks.
2009
+ */
2010
+ var IdentityProofs = class {
2011
+ host;
2012
+ providers;
2013
+ proofs = [];
2014
+ revocations = [];
2015
+ /** Unsealed proof-key seeds, by proof id, for this run only. */
2016
+ seeds = /* @__PURE__ */ new Map();
2017
+ timers = [];
2018
+ unlisten;
2019
+ drafts = /* @__PURE__ */ new Map();
2020
+ exchanges = /* @__PURE__ */ new Map();
2021
+ saving = Promise.resolve();
2022
+ errors = /* @__PURE__ */ new Map();
2023
+ /** Chats whose current connection already got the hello: "ready" is reported more than once per connection. */
2024
+ greeted = /* @__PURE__ */ new Set();
2025
+ fetch;
2026
+ constructor(host, providers = loadedIdentityProviders) {
2027
+ this.host = host;
2028
+ this.providers = providers;
2029
+ this.fetch = boundedIdentityFetch({ online: host.online });
2030
+ }
2031
+ /** The profile's proofs, and the providers that check and show them: loaded here, not with the app. */
2032
+ async load() {
2033
+ const providers = loadIdentityProviders();
2034
+ const settings = await store(STORES.settings, "readonly");
2035
+ [this.proofs, this.revocations] = await Promise.all([wrap(settings.get(KEY)).then((v) => v ?? []), wrap(settings.get(REVOCATIONS)).then((v) => v ?? [])]);
2036
+ await providers;
2037
+ }
2038
+ /** Background work: republish revocations, look up the contacts' proofs for revocations. */
2039
+ start() {
2040
+ const every = (ms, first, work) => {
2041
+ const tick = () => {
2042
+ work().catch(() => {}).finally(() => {
2043
+ this.timers.push(setTimeout(tick, ms));
2044
+ });
2045
+ };
2046
+ this.timers.push(setTimeout(tick, first));
2047
+ };
2048
+ every(REPUBLISH_MS, 5e3, () => this.republish());
2049
+ every(REVOCATION_CHECK_MS, 6e4, () => this.checkRevocations());
2050
+ this.unlisten ??= whenDataKeyDropped(() => this.forgetSeeds());
2051
+ }
2052
+ stop() {
2053
+ for (const t of this.timers) clearTimeout(t);
2054
+ this.timers = [];
2055
+ this.unlisten?.();
2056
+ this.unlisten = void 0;
2057
+ this.forgetSeeds();
2058
+ }
2059
+ forgetSeeds() {
2060
+ for (const seed of this.seeds.values()) seed.fill(0);
2061
+ this.seeds.clear();
2062
+ }
2063
+ /**
2064
+ * Every change of the proofs and revocations, one after the other, each made on what the one before stored: two at
2065
+ * once (two proofs completed, a proof removed while another completes) both from the same list lost one of them.
2066
+ */
2067
+ save(change) {
2068
+ const run = this.saving.then(async () => {
2069
+ const [proofs, revocations] = change(this.proofs, this.revocations);
2070
+ await transact([STORES.settings], (stores) => {
2071
+ stores[STORES.settings].put(proofs, KEY);
2072
+ stores[STORES.settings].put(revocations, REVOCATIONS);
2073
+ });
2074
+ this.proofs = proofs;
2075
+ this.revocations = revocations;
2076
+ this.host.emit();
2077
+ });
2078
+ this.saving = run.catch(() => {});
2079
+ return run;
2080
+ }
2081
+ async seedOf(id, sealed) {
2082
+ let seed = this.seeds.get(id);
2083
+ if (!seed) {
2084
+ seed = fromBase64Url(await openSecret(sealed, proofKeyAt(id)));
2085
+ this.seeds.set(id, seed);
2086
+ }
2087
+ return seed;
2088
+ }
2089
+ ctx() {
2090
+ return {
2091
+ now: now(),
2092
+ signal: AbortSignal.timeout(3e4),
2093
+ fetch: this.fetch
2094
+ };
2095
+ }
2096
+ verify = (statement, evidence) => verifyIdentity(this.providers(), statement, evidence, this.ctx());
2097
+ revoked = async (statement) => {
2098
+ if (!this.host.online()) return false;
2099
+ const records = await this.host.resolve(statement.binding.key);
2100
+ return !!records && revokesIdentity(records, statement.id);
2101
+ };
2102
+ async local(id) {
2103
+ const p = this.proofs.find((x) => identityStatement(x.binding).id === id);
2104
+ return p && {
2105
+ statement: identityStatement(p.binding),
2106
+ evidence: p.evidence,
2107
+ seed: await this.seedOf(id, p.seed)
2108
+ };
2109
+ }
2110
+ /** Step 1 of adding a proof: a fresh proof key and the statement the external identity must sign. */
2111
+ begin({ provider, subject, validityDays }) {
2112
+ const p = this.providers().find((x) => x.id === provider);
2113
+ if (!p) throw new Error("Unknown kind of identity");
2114
+ const days = validityDays ?? p.validity.defaultDays;
2115
+ if (!Number.isInteger(days) || days < 1 || days > p.validity.maxDays) throw new Error(`Choose between 1 and ${p.validity.maxDays} days`);
2116
+ const canonical = p.subject.normalize(subject);
2117
+ for (const [id, d] of this.drafts) if (Date.now() - d.at > 18e5) {
2118
+ d.seed.fill(0);
2119
+ this.drafts.delete(id);
2120
+ }
2121
+ while (this.drafts.size >= 4) {
2122
+ const [id, d] = this.drafts.entries().next().value;
2123
+ d.seed.fill(0);
2124
+ this.drafts.delete(id);
2125
+ }
2126
+ const { binding, seed } = newIdentityBinding({
2127
+ provider,
2128
+ subject: canonical,
2129
+ validitySeconds: days * 86400
2130
+ });
2131
+ const draftId = toBase64Url(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)));
2132
+ this.drafts.set(draftId, {
2133
+ binding,
2134
+ seed,
2135
+ at: Date.now()
2136
+ });
2137
+ return {
2138
+ draftId,
2139
+ binding
2140
+ };
2141
+ }
2142
+ /** Step 2: the evidence. Verified here, exactly as a contact will, before anything is saved. */
2143
+ async complete({ draftId, evidence }) {
2144
+ const draft = this.drafts.get(draftId);
2145
+ if (!draft) throw new Error("This proof was started too long ago. Start again.");
2146
+ const statement = identityStatement(draft.binding);
2147
+ const verified = await this.verify(statement, JSON.parse(JSON.stringify(evidence ?? null)));
2148
+ if (this.proofs.length >= MAX_PROOFS) throw new Error("Remove an identity first");
2149
+ this.drafts.delete(draftId);
2150
+ const stored = {
2151
+ binding: draft.binding,
2152
+ evidence,
2153
+ seed: await sealSecret(toBase64Url(draft.seed), proofKeyAt(statement.id)),
2154
+ verified,
2155
+ createdAt: Date.now()
2156
+ };
2157
+ this.seeds.set(statement.id, draft.seed);
2158
+ await this.save((proofs, revocations) => {
2159
+ if (proofs.length >= MAX_PROOFS) throw new Error("Remove an identity first");
2160
+ return [[...proofs, stored], revocations];
2161
+ });
2162
+ return this.viewOf(stored);
2163
+ }
2164
+ cancel({ draftId }) {
2165
+ this.drafts.get(draftId)?.seed.fill(0);
2166
+ this.drafts.delete(draftId);
2167
+ }
2168
+ /**
2169
+ * Removes a proof from the profile: withdrawn from every chat it was shared in (each contact is told now
2170
+ * or when it next connects), and revoked for good, by a record its proof key publishes on Pkarr and this
2171
+ * app republishes until the proof would have expired, for contacts it never reconnects to.
2172
+ */
2173
+ async remove({ id }) {
2174
+ const proof = this.proofs.find((p) => identityStatement(p.binding).id === id);
2175
+ if (!proof) return;
2176
+ for (const linkId of this.host.linkIds()) {
2177
+ const shared = this.host.ledger(linkId)?.shared.find((s) => s.id === id);
2178
+ if (shared && shared.status !== "withdrawn") await this.exchange(linkId)?.withdraw(id, !!this.host.channel(linkId));
2179
+ }
2180
+ const revocation = {
2181
+ id,
2182
+ key: proof.binding.key,
2183
+ seed: proof.seed,
2184
+ revokedAt: now(),
2185
+ expiresAt: Math.min(proof.binding.expiresAt, proof.verified.expiresAt ?? Infinity)
2186
+ };
2187
+ const wasShared = this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
2188
+ const revoke = wasShared && revocation.expiresAt > now();
2189
+ 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]);
2190
+ if (wasShared) this.publishRevocation(revocation).catch(() => {});
2191
+ else {
2192
+ this.seeds.get(id)?.fill(0);
2193
+ this.seeds.delete(id);
2194
+ }
2195
+ }
2196
+ /**
2197
+ * "Clear all data": every proof that was ever shared, and every removed one still being revoked, gets its revocation
2198
+ * record published once more, all at once. Nothing will republish them after the clear, so this is a last word for
2199
+ * contacts who check; proofs posted elsewhere (a Bluesky record, a Pubky file, a DNS record) are the person's to delete.
2200
+ */
2201
+ async revokeAll() {
2202
+ this.stop();
2203
+ const shared = new Set(this.host.linkIds().flatMap((l) => this.host.ledger(l)?.shared.map((s) => s.id) ?? []));
2204
+ const at = now();
2205
+ const last = [...this.revocations.filter((r) => r.expiresAt > at), ...this.proofs.filter((p) => shared.has(identityStatement(p.binding).id)).map((p) => ({
2206
+ id: identityStatement(p.binding).id,
2207
+ key: p.binding.key,
2208
+ seed: p.seed,
2209
+ revokedAt: at,
2210
+ expiresAt: Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity)
2211
+ }))];
2212
+ await Promise.allSettled(last.map((r) => this.publishRevocation(r)));
2213
+ this.stop();
2214
+ }
2215
+ async publishRevocation(r) {
2216
+ if (!this.host.online()) return;
2217
+ await this.host.publish(await this.seedOf(r.id, r.seed), [{
2218
+ label: IDENTITY_REVOCATION_LABEL,
2219
+ value: identityRevocationValue(r.id, r.revokedAt)
2220
+ }]);
2221
+ }
2222
+ async republish() {
2223
+ const live = this.revocations.filter((r) => r.expiresAt > now());
2224
+ if (live.length !== this.revocations.length) {
2225
+ for (const r of this.revocations) if (!live.includes(r)) {
2226
+ this.seeds.get(r.id)?.fill(0);
2227
+ this.seeds.delete(r.id);
2228
+ }
2229
+ await this.save((proofs, revocations) => [proofs, revocations.filter((r) => r.expiresAt > now())]);
2230
+ }
2231
+ for (const r of live) await this.publishRevocation(r).catch(() => {});
2232
+ }
2233
+ /**
2234
+ * Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
2235
+ * ones withdrawn, which a removal also revokes. Not a proof already revoked, nor one past its expiry: its owner
2236
+ * publishes the revocation only until then.
2237
+ */
2238
+ async checkRevocations() {
2239
+ if (!this.host.online()) return;
2240
+ for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) if (this.revocable(r)) await this.exchange(linkId)?.recheck(r.id, { revocationOnly: true }).catch(() => {});
2241
+ }
2242
+ revocable(r) {
2243
+ return r.status !== "revoked" && Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity) > now();
2244
+ }
2245
+ /** A proof the contact just withdrew: looked up for its revocation a few times (`WITHDRAWN_REVOCATION_TRIES_MS`). */
2246
+ afterWithdrawal(linkId, id, tries = WITHDRAWN_REVOCATION_TRIES_MS) {
2247
+ const [wait, ...rest] = tries;
2248
+ if (wait === void 0) return;
2249
+ const timer = setTimeout(() => {
2250
+ this.timers = this.timers.filter((t) => t !== timer);
2251
+ const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
2252
+ if (!r || r.status !== "withdrawn" || !this.revocable(r)) return;
2253
+ (async () => {
2254
+ if ((this.host.online() ? await this.exchange(linkId)?.recheck(id, { revocationOnly: true }).catch(() => void 0) : void 0)?.status !== "revoked") this.afterWithdrawal(linkId, id, rest);
2255
+ })();
2256
+ }, wait);
2257
+ this.timers.push(timer);
2258
+ }
2259
+ views() {
2260
+ return this.proofs.map((p) => this.viewOf(p));
2261
+ }
2262
+ viewOf(p) {
2263
+ const id = identityStatement(p.binding).id;
2264
+ const sharedWith = this.host.linkIds().filter((l) => this.host.ledger(l)?.shared.some((s) => s.id === id && s.status !== "withdrawn" && s.status !== "withdrawal-pending" && s.status !== "rejected")).length;
2265
+ const publicUri = this.publicUri(p);
2266
+ const expiresAt = Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity);
2267
+ const publicProfile = expiresAt > now() ? this.host.publicProfile?.(p.binding.provider, p.verified.subject) : void 0;
2268
+ return {
2269
+ id,
2270
+ provider: p.binding.provider,
2271
+ subject: p.binding.subject,
2272
+ key: p.binding.key,
2273
+ verified: p.verified,
2274
+ issuedAt: p.binding.issuedAt,
2275
+ expiresAt,
2276
+ createdAt: p.createdAt,
2277
+ sharedWith,
2278
+ evidence: p.evidence,
2279
+ ...publicUri ? { publicUri } : {},
2280
+ ...publicProfile ? { publicProfile } : {}
2281
+ };
2282
+ }
2283
+ /** What the profile's public DID would list for this identity: the provider's URI for the verified subject, if well formed. */
2284
+ publicUri(p) {
2285
+ try {
2286
+ const uri = this.providers().find((x) => x.id === p.binding.provider)?.publicUri?.(p.verified.subject);
2287
+ return uri && /^[A-Za-z][A-Za-z0-9+.-]*:[^\s,;]+$/.test(uri) ? uri : void 0;
2288
+ } catch {
2289
+ return;
2290
+ }
2291
+ }
2292
+ exchange(linkId) {
2293
+ if (!this.host.ledger(linkId)) return void 0;
2294
+ let x = this.exchanges.get(linkId);
2295
+ if (!x) {
2296
+ x = new IdentityExchange({
2297
+ scope: () => {
2298
+ const c = this.host.channel(linkId);
2299
+ if (!c) throw new Error("Connect to this contact first");
2300
+ return c.scope();
2301
+ },
2302
+ send: (frame) => {
2303
+ const c = this.host.channel(linkId);
2304
+ if (!c) throw new Error("Connect to this contact first");
2305
+ c.send(frame);
2306
+ },
2307
+ storage: {
2308
+ read: () => this.host.ledger(linkId) ?? emptyIdentityLedger(),
2309
+ update: async (change) => {
2310
+ await this.host.updateLedger(linkId, change);
2311
+ this.host.emit();
2312
+ }
2313
+ },
2314
+ providers: () => this.providers().map((p) => p.id),
2315
+ localProof: (id) => this.local(id),
2316
+ verify: this.verify,
2317
+ revoked: this.revoked,
2318
+ onError: (error) => {
2319
+ this.errors.set(linkId, error);
2320
+ this.host.emit();
2321
+ }
2322
+ });
2323
+ this.exchanges.set(linkId, x);
2324
+ }
2325
+ return x;
2326
+ }
2327
+ async share({ linkId, id }) {
2328
+ const x = this.exchange(linkId);
2329
+ if (!x) throw new Error("Identities can be shared in paired chats only");
2330
+ const p = this.proofs.find((q) => identityStatement(q.binding).id === id);
2331
+ if (!p) throw new Error("That identity is no longer in your profile");
2332
+ if (Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity) <= now()) throw new Error("This identity has expired. Make a new proof in your profile.");
2333
+ this.errors.delete(linkId);
2334
+ await x.share(id, !!this.host.channel(linkId));
2335
+ }
2336
+ async withdraw({ linkId, id }) {
2337
+ await this.exchange(linkId)?.withdraw(id, !!this.host.channel(linkId));
2338
+ }
2339
+ /** The contact's proof, checked again: its revocation record, then the provider's own check. */
2340
+ async recheck({ linkId, id }) {
2341
+ if (!this.host.online()) throw new Error("Offline: turn the network on to check again");
2342
+ await this.exchange(linkId)?.recheck(id);
2343
+ }
2344
+ /** Only on the person's request: the provider's public name/picture for a verified identity. */
2345
+ async lookupDisplay({ linkId, id }) {
2346
+ if (!this.host.online()) throw new Error("Offline: turn the network on first");
2347
+ const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
2348
+ const provider = r && this.providers().find((p) => p.id === r.binding.provider);
2349
+ if (!r || !provider?.lookupDisplay) throw new Error("No public profile for this identity");
2350
+ const display = await provider.lookupDisplay(r.verified.subject, { signal: AbortSignal.timeout(15e3) });
2351
+ if (!display) throw new Error("No public profile found");
2352
+ await this.host.updateLedger(linkId, (l) => ({
2353
+ ...l,
2354
+ received: l.received.map((x) => x.id === id && x.verified.subject === r.verified.subject ? {
2355
+ ...x,
2356
+ display
2357
+ } : x)
2358
+ }));
2359
+ this.host.emit();
2360
+ }
2361
+ async frame(linkId, frame) {
2362
+ const x = this.exchange(linkId);
2363
+ if (!x) return;
2364
+ const withdrawn = frame.t === "idp-withdraw" && typeof frame.id === "string" && this.host.ledger(linkId)?.received.some((r) => r.id === frame.id && r.status !== "withdrawn" && r.status !== "revoked");
2365
+ await x.receive(frame);
2366
+ if (withdrawn && this.host.ledger(linkId)?.received.some((r) => r.id === frame.id && r.status === "withdrawn")) this.afterWithdrawal(linkId, frame.id);
2367
+ }
2368
+ ready(linkId) {
2369
+ if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
2370
+ try {
2371
+ this.exchange(linkId)?.ready();
2372
+ this.greeted.add(linkId);
2373
+ } catch {}
2374
+ }
2375
+ closed(linkId) {
2376
+ this.greeted.delete(linkId);
2377
+ this.exchanges.get(linkId)?.stop();
2378
+ }
2379
+ forget(linkId) {
2380
+ this.greeted.delete(linkId);
2381
+ this.exchanges.get(linkId)?.stop();
2382
+ this.exchanges.delete(linkId);
2383
+ this.errors.delete(linkId);
2384
+ }
2385
+ linkView(linkId, supported) {
2386
+ const ledger = this.host.ledger(linkId);
2387
+ if (!ledger) return void 0;
2388
+ const { mine, theirs } = this.host.keys(linkId);
2389
+ const t = now();
2390
+ return {
2391
+ support: supported,
2392
+ contactProviders: supported ? this.exchanges.get(linkId)?.contactProviders?.slice() : void 0,
2393
+ shared: ledger.shared,
2394
+ received: ledger.received.map((r) => {
2395
+ const provider = this.providers().find((p) => p.id === r.binding.provider);
2396
+ const status = receivedIdentityStatus(r, theirs, mine, t);
2397
+ const publicProfile = status === "verified" ? this.host.publicProfile?.(r.binding.provider, r.verified.subject) : void 0;
2398
+ return {
2399
+ id: r.id,
2400
+ provider: r.binding.provider,
2401
+ subject: r.verified.subject,
2402
+ verified: r.verified,
2403
+ display: r.display,
2404
+ status,
2405
+ verifiedAt: r.verifiedAt,
2406
+ checkedAt: r.checkedAt,
2407
+ expiresAt: Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity),
2408
+ error: r.error,
2409
+ recheckDue: !!provider?.recheck && t - r.checkedAt >= provider.recheck.afterSeconds,
2410
+ ...publicProfile ? { publicProfile } : {}
2411
+ };
2412
+ }),
2413
+ error: this.errors.get(linkId)
2414
+ };
2415
+ }
2416
+ };
2417
+ //#endregion
1864
2418
  //#region ../browser/src/shared/storedFiles.ts
1865
2419
  /** The bytes a file holds: its metadata says, and a file stored before that says it with its Blob. */
1866
2420
  function storedSize(file) {
@@ -3405,6 +3959,6 @@ function messageFile(kept) {
3405
3959
  };
3406
3960
  }
3407
3961
  //#endregion
3408
- export { setAwayWallets as $, LightningCards as A, breezDatabaseInUse as B, FileAppender as C, streamStored as D, storedSize as E, ProviderSources as F, relayOnlyProblem as G, dropBreezDatabase as H, sourceKey as I, WrongNetworkError as J, ModeChanged as K, CASHU_MINT_SOURCE as L, isRecoveryPhrase as M, normalizePhrase as N, waitingGroupFile as O, lightningPaying as P, requireTurn as Q, cashuMint as R, WALLET_TYPES as S, removeStored as T, iceServerProblem as U, breezDatabasesFor as V, iceServerSetting as W, awayFrom as X, networkLabel as Y, refuseAway as Z, crossNetwork as _, storedGroupFiles as a, walletInstances as b, receivedPairedReply as c, paymentAlias as d, setSingleWriterGate as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, cardsKey as j, CASHU_CARD as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, groupReply as o, WALLET_NAMES as p, ModeGate as q, groupFileText as r, pairedWireReply as s, GroupFileDesk as t, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, breezDatabase as z };
3962
+ export { WrongNetworkError as $, IdentityProofs as A, ProviderSources as B, FileAppender as C, streamStored as D, storedSize as E, LightningCards as F, breezDatabaseInUse as G, CASHU_MINT_SOURCE as H, cardsKey as I, iceServerProblem as J, breezDatabasesFor as K, isRecoveryPhrase as L, sealSecret as M, whenDataKeyDropped as N, waitingGroupFile as O, CASHU_CARD as P, ModeGate as Q, normalizePhrase as R, WALLET_TYPES as S, removeStored as T, cashuMint as U, sourceKey as V, breezDatabase as W, relayOnlyProblem as X, iceServerSetting as Y, ModeChanged as Z, crossNetwork as _, storedGroupFiles as a, setSingleWriterGate as at, walletInstances as b, receivedPairedReply as c, paymentAlias as d, networkLabel as et, paymentWireId as f, createTiming as g, createFailure as h, groupOfFile as i, setAwayWallets as it, openSecret as j, IDENTITY_DRAFT_TTL_MS as k, replyRef as l, assertConfirmedReal as m, groupFileId as n, refuseAway as nt, groupReply as o, WALLET_NAMES as p, dropBreezDatabase as q, groupFileText as r, requireTurn as rt, pairedWireReply as s, GroupFileDesk as t, awayFrom as tt, replyTo as u, paymentNetwork as v, readStored as w, MESSAGE_DETAILS_MAX_BYTES as x, paymentNetworksOf as y, lightningPaying as z };
3409
3963
 
3410
- //# sourceMappingURL=groupFiles-D9Ttlm3M.js.map
3964
+ //# sourceMappingURL=groupFiles-BlZRBWpt.js.map