@ghostlytools/cli 1.13.0 → 1.13.2
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 +13 -10
- package/dist/assets/api-DV52o7A8.js +3 -0
- package/dist/assets/{api-CjOaoG-v.js → api-O57SNJcb.js} +495 -99
- package/dist/assets/api-O57SNJcb.js.map +1 -0
- package/dist/assets/{apiKit-BAGvlQtm.js → apiKit-CPTFJHA7.js} +40 -8
- package/dist/assets/{apiKit-BAGvlQtm.js.map → apiKit-CPTFJHA7.js.map} +1 -1
- package/dist/assets/{appFetch-BwJd-kNq.js → appFetch-Ca9DNQQ2.js} +2 -2
- package/dist/assets/{appFetch-BwJd-kNq.js.map → appFetch-Ca9DNQQ2.js.map} +1 -1
- package/dist/assets/{apps-Cuk45sz5.js → apps-gXpGFPiv.js} +16 -14
- package/dist/assets/apps-gXpGFPiv.js.map +1 -0
- package/dist/assets/{apps-DjY095Af.js → apps-uZTu5FlR.js} +1 -1
- package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
- package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
- package/dist/assets/{backup-DekVCDWv.js → backup-CxH3auHB.js} +9 -7
- package/dist/assets/backup-CxH3auHB.js.map +1 -0
- package/dist/assets/{backup-B56sQqoQ.js → backup-Di2U6QVH.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +1 -1
- package/dist/assets/{bitcoind-B2bbVSzh.js → bitcoind-BpZn3bRN.js} +2 -2
- package/dist/assets/{bitcoind-B2bbVSzh.js.map → bitcoind-BpZn3bRN.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +1 -1
- package/dist/assets/{buttons-BGxzOtrq.js → buttons-D4udKEvT.js} +8 -8
- package/dist/assets/buttons-D4udKEvT.js.map +1 -0
- package/dist/assets/buttons-YTYEqvGC.js +1 -0
- package/dist/assets/{client-DcQAfc3h.js → client-DGx7E8b3.js} +3 -3
- package/dist/assets/{client-DcQAfc3h.js.map → client-DGx7E8b3.js.map} +1 -1
- package/dist/assets/{domainProofs-BDNP1dIy.js → domainProofs-b3Y1Gj9g.js} +6 -2
- package/dist/assets/{domainProofs-BDNP1dIy.js.map → domainProofs-b3Y1Gj9g.js.map} +1 -1
- package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
- package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
- package/dist/assets/{errors-DDLFO4Gf.js → errors-JVJsO8Iu.js} +18 -2
- package/dist/assets/errors-JVJsO8Iu.js.map +1 -0
- package/dist/assets/{fixedHosts-C3hBliM9.js → fixedHosts-CODN2pTL.js} +3 -3
- package/dist/assets/{fixedHosts-C3hBliM9.js.map → fixedHosts-CODN2pTL.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-DIj5xGmR.js → ghostly_iroh_web-9VOwZcJQ.js} +30 -35
- package/dist/assets/ghostly_iroh_web-9VOwZcJQ.js.map +1 -0
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupMeta-goASqzOt.js → groupMeta-CeZpqVVC.js} +174 -37
- package/dist/assets/groupMeta-CeZpqVVC.js.map +1 -0
- package/dist/assets/{host-C2WRKj3g.js → host-CRA7h5A2.js} +270 -64
- package/dist/assets/host-CRA7h5A2.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-DLUiwfnt.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-DLUiwfnt.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
- package/dist/assets/{hyperdhtRelay-bjNGacf5.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-bjNGacf5.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
- package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-B8zCp5_0.js} +140 -27
- package/dist/assets/identityProofs-B8zCp5_0.js.map +1 -0
- package/dist/assets/{irohWeb-NfthOL98.js → irohWeb-mnOi2Jp7.js} +10838 -4837
- package/dist/assets/irohWeb-mnOi2Jp7.js.map +1 -0
- package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
- package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
- package/dist/assets/{main-Dh7fePd8.js → main-Chc871HV.js} +119 -81
- package/dist/assets/main-Chc871HV.js.map +1 -0
- package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
- package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
- package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
- package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
- package/dist/assets/{ownDid-BErplN7N.js → ownDid-BOuSlDv-.js} +10 -6
- package/dist/assets/ownDid-BOuSlDv-.js.map +1 -0
- package/dist/assets/{ownStatus-ClrFjd7h.js → ownStatus-CLA1VPkL.js} +6 -6
- package/dist/assets/{ownStatus-ClrFjd7h.js.map → ownStatus-CLA1VPkL.js.map} +1 -1
- package/dist/assets/{pairedTransports-BKmvlKz1.js → pairedTransports-DAzupLYo.js} +23 -17
- package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
- package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
- package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
- package/dist/assets/{profiles-B8xO8-oj.js → profiles-BH1bH9aE.js} +3 -3
- package/dist/assets/{profiles-B8xO8-oj.js.map → profiles-BH1bH9aE.js.map} +1 -1
- package/dist/assets/{registry--Rg2YvOH.js → registry-DAq16T-V.js} +1 -1
- package/dist/assets/{registry-CU8PevhI.js → registry-DP_-RA-v.js} +11 -7
- package/dist/assets/registry-DP_-RA-v.js.map +1 -0
- package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
- package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
- package/dist/assets/{resolve-B1upovPM.js → resolve-B1eQ4dVQ.js} +10 -5
- package/dist/assets/resolve-B1eQ4dVQ.js.map +1 -0
- package/dist/assets/secretGuard-Bh11MPdI.js +1 -0
- package/dist/assets/{secretGuard-BrATm_gl.js → secretGuard-oz_3hBfW.js} +19 -2
- package/dist/assets/{secretGuard-BrATm_gl.js.map → secretGuard-oz_3hBfW.js.map} +1 -1
- package/dist/assets/{server-Dgxx_DaN.js → server-Bd2ofxc1.js} +1283 -6628
- package/dist/assets/server-Bd2ofxc1.js.map +1 -0
- package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-As7dbGXM.js} +2 -2
- package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-As7dbGXM.js.map} +1 -1
- package/dist/assets/{translate-BcbSWkuq.js → translate-DnuQMfj0.js} +22 -11
- package/dist/assets/translate-DnuQMfj0.js.map +1 -0
- package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
- package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
- package/dist/assets/{waitNotice-ylU3XwjO.js → waitNotice-BHuMofaH.js} +57 -3
- package/dist/assets/waitNotice-BHuMofaH.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/assets/api-CVtg7MpI.js +0 -3
- package/dist/assets/api-CjOaoG-v.js.map +0 -1
- package/dist/assets/apps-Cuk45sz5.js.map +0 -1
- package/dist/assets/backup-DekVCDWv.js.map +0 -1
- package/dist/assets/buttons-BGxzOtrq.js.map +0 -1
- package/dist/assets/buttons-CsN2WJOf.js +0 -1
- package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
- package/dist/assets/errors-DDLFO4Gf.js.map +0 -1
- package/dist/assets/ghostly_iroh_web-DIj5xGmR.js.map +0 -1
- package/dist/assets/groupMeta-goASqzOt.js.map +0 -1
- package/dist/assets/host-C2WRKj3g.js.map +0 -1
- package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
- package/dist/assets/irohWeb-NfthOL98.js.map +0 -1
- package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
- package/dist/assets/main-Dh7fePd8.js.map +0 -1
- package/dist/assets/ownDid-BErplN7N.js.map +0 -1
- package/dist/assets/pairedTransports-BKmvlKz1.js.map +0 -1
- package/dist/assets/registry-CU8PevhI.js.map +0 -1
- package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
- package/dist/assets/resolve-B1upovPM.js.map +0 -1
- package/dist/assets/secretGuard-Bm6nci0I.js +0 -1
- package/dist/assets/server-Dgxx_DaN.js.map +0 -1
- package/dist/assets/translate-BcbSWkuq.js.map +0 -1
- package/dist/assets/waitNotice-ylU3XwjO.js.map +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-
|
|
4
|
-
import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-
|
|
5
|
-
import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-
|
|
6
|
-
import { i as localFileError, r as asCliError, t as CliError } from "./errors-
|
|
7
|
-
import { A as
|
|
1
|
+
import { $a as readImageMeta, Ai as GhostlyHttpError, An as baseMime, Dn as PLAYABLE_AUDIO, Dt as TYPING_KINDS, Ea as isAppUrl, En as sanitizeMime, Er as checkStatusCard, Fi as LIMITS, Fn as voiceLevel, Mr as MESSAGE_CLOCK_SKEW_MS, Ni as parseLocalTarget, Nn as parseVoiceMeta, O as GROUP_FILE_LIMITS, On as VOICE_LIMITS, Ot as TYPING_REFRESH_MS, Pa as appRef, Pn as voiceDownloadName, Pr as claimedTime, Si as AWAITING_PEER_MS, Tn as sanitizeFileName, Va as isAppRef, br as appCardId, cr as replySnippet, do as ownInviteRefusal, ji as VIEWER_PERMISSIONS_POLICY, jn as downsamplePeaks, jt as sanitizeTypingStatus, kn as VOICE_METER, kr as statusCardBytes, lo as inviteLink, n as groupCallSfu, nn as APP_DATA_MAX_BYTES, vr as STATUS_CARD_LIMITS, wr as cardLine, xr as appCardUrl } from "./groupMeta-CeZpqVVC.js";
|
|
2
|
+
import { G as removeStored, J as waitingGroupFile, P as paymentNetwork, Pt as decodeCommunityLink, T as replyRef, Y as IDENTITY_DRAFT_TTL_MS, an as withoutAudioMetadata, b as groupOfFile, cn as NO_PICTURE_METADATA, d as groupPayLineId, f as groupPayNoteId, l as normalizeMintUrl, ln as stripPictureMetadata, p as groupPayTwin, sn as withoutVideoMetadata, t as DEFAULT_IROH_RELAYS, u as groupMemberOfLink, un as withoutPictureMetadata, v as groupFileId, vt as iceServerProblem, yt as iceServerSetting, zt as decodeGroupEntryLink } from "./irohWeb-mnOi2Jp7.js";
|
|
3
|
+
import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-gJTOYQJZ.js";
|
|
4
|
+
import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-oz_3hBfW.js";
|
|
5
|
+
import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-CLA1VPkL.js";
|
|
6
|
+
import { i as localFileError, o as shownValue, r as asCliError, t as CliError } from "./errors-JVJsO8Iu.js";
|
|
7
|
+
import { A as oneOf, B as str, C as noMessage, D as notInYet, E as node, F as shownName, H as waitForState, I as sinceSeq, L as somebodyJoined, M as ownChatOf, N as sentAt, O as notInYetError, P as settingsOf, S as noFile, U as shellWord, V as transportOffered, _ as keptForJoin, a as contactKeyOf, b as nameKey, c as findChatOrGroup, d as groupById, f as groupCalled, g as inviteTaken, h as groupPrefixed, j as oneShotWaits, k as num, l as findGroup, m as groupOf, n as chatOf, o as dhtOnly, p as groupNameOf, r as chatOrGroup, s as findChat, t as bool, v as list, w as nobodyJoined, y as messageOf, z as state } from "./apiKit-CPTFJHA7.js";
|
|
8
8
|
import { l as toBase64Url, s as randomBytes$1 } from "./bytes-C1DNGY18.js";
|
|
9
9
|
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-CfvUXdSy.js";
|
|
10
10
|
import { p as fileStore } from "./idb-ewvbqyDI.js";
|
|
11
11
|
import { t as childEnv } from "./childEnv-C-99hdbL.js";
|
|
12
|
-
import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-
|
|
13
|
-
import { a as checkShownName } from "./profiles-
|
|
14
|
-
import {
|
|
15
|
-
import { m as identityStatement } from "./identityProofs-
|
|
16
|
-
import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-
|
|
17
|
-
import { t as BACKUP_METHODS } from "./backup-
|
|
18
|
-
import { s as isAppFetchUrl } from "./appFetch-
|
|
19
|
-
import { o as checkedBundle } from "./apps-
|
|
20
|
-
import { m as parsePaymentAmount } from "./paymentIntent-
|
|
21
|
-
import { t as chatState } from "./waitNotice-
|
|
12
|
+
import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-D4udKEvT.js";
|
|
13
|
+
import { a as checkShownName } from "./profiles-BH1bH9aE.js";
|
|
14
|
+
import { o as MAX_AVATAR_LENGTH, s as sanitizeAvatar } from "./linkPreview-5kHmKUTN.js";
|
|
15
|
+
import { m as identityStatement } from "./identityProofs-B8zCp5_0.js";
|
|
16
|
+
import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-DP_-RA-v.js";
|
|
17
|
+
import { t as BACKUP_METHODS } from "./backup-CxH3auHB.js";
|
|
18
|
+
import { s as isAppFetchUrl } from "./appFetch-Ca9DNQQ2.js";
|
|
19
|
+
import { o as checkedBundle } from "./apps-gXpGFPiv.js";
|
|
20
|
+
import { m as parsePaymentAmount } from "./paymentIntent-Cr3uZa_0.js";
|
|
21
|
+
import { a as heldWords, n as dhtOnlyNote, t as chatState } from "./waitNotice-BHuMofaH.js";
|
|
22
22
|
import { generateMnemonic } from "@scure/bip39";
|
|
23
23
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
24
24
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -1122,6 +1122,15 @@ async function waitForFile(ctx, params, stopping) {
|
|
|
1122
1122
|
size: transfer.size
|
|
1123
1123
|
};
|
|
1124
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* `file accept` of a file that does not fit the room left beside the files still coming (`FileDesk.accept`), in this
|
|
1127
|
+
* CLI's MB: the engine's line gave the room in binary MB beside a size in decimal ones, and neither the files still
|
|
1128
|
+
* coming that take the rest nor the way out.
|
|
1129
|
+
*/
|
|
1130
|
+
function noRoomWords(fileId, name, size, room, coming) {
|
|
1131
|
+
const rest = coming > 0 ? `, and ${megabytes(coming)} of files still coming need it first` : "";
|
|
1132
|
+
return `${name ?? "The file"} (${megabytes(size)}) does not fit: ${megabytes(room)} free${rest}. Free some space, then ghostly file accept ${fileId} again (or file decline)`;
|
|
1133
|
+
}
|
|
1125
1134
|
/** A received file that waits for this person's `file accept` (`file wait`, `file save`): said naming the command. */
|
|
1126
1135
|
function waitsForYou(name, fileId, where, size) {
|
|
1127
1136
|
return new CliError("confirm", `${name ?? "The file"} (${megabytes(size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
@@ -1320,11 +1329,20 @@ var FILE_METHODS = {
|
|
|
1320
1329
|
const view = state(ctx).transfers[fileId];
|
|
1321
1330
|
if ((action === "resume" || action === "request" || action === "resend") && view?.stage === "paused" && view.pausedBy === "peer") throw new CliError("refused", "Paused by the contact: it goes on when they resume it");
|
|
1322
1331
|
if ((action === "pause" || action === "resume" || action === "request") && view?.stage === "asking" && view.direction === "in") throw new CliError("refused", "Not taken yet: it waits for you to take it (file accept, or file decline)");
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1332
|
+
try {
|
|
1333
|
+
await node(ctx).fileAction({
|
|
1334
|
+
linkId,
|
|
1335
|
+
fileId,
|
|
1336
|
+
action
|
|
1337
|
+
});
|
|
1338
|
+
} catch (error) {
|
|
1339
|
+
const { room, size, coming } = error ?? {};
|
|
1340
|
+
if (action === "accept" && error instanceof Error && typeof room === "number" && error.message.startsWith("No room on this device")) throw new CliError("refused", noRoomWords(fileId, (await fileStore.get(fileId).catch(() => void 0))?.metadata?.name, typeof size === "number" ? size : view?.size ?? 0, room, typeof coming === "number" ? coming : 0), {
|
|
1341
|
+
reason: "no_room",
|
|
1342
|
+
room
|
|
1343
|
+
});
|
|
1344
|
+
throw error;
|
|
1345
|
+
}
|
|
1328
1346
|
return {
|
|
1329
1347
|
...where,
|
|
1330
1348
|
file: fileId,
|
|
@@ -2029,6 +2047,15 @@ function holdOf(ctx, linkId) {
|
|
|
2029
2047
|
const until = readHolds(ctx)[linkId]?.until;
|
|
2030
2048
|
return until !== void 0 && until > Date.now() ? until : null;
|
|
2031
2049
|
}
|
|
2050
|
+
/**
|
|
2051
|
+
* When the chat's hold ends, or null for none, as what waits in a held chat reads it: also a hold whose time is up and
|
|
2052
|
+
* that has not ended yet (its release is under way, or waits for the chat to open: `expire`), which `holdOf` no longer
|
|
2053
|
+
* reports while the chat is still on DHT only. Read as no hold, a text or edit waiting through it was said to wait
|
|
2054
|
+
* for a transport to be chosen, and it goes by itself.
|
|
2055
|
+
*/
|
|
2056
|
+
function holdEnds(ctx, linkId) {
|
|
2057
|
+
return readHolds(ctx)[linkId]?.until ?? null;
|
|
2058
|
+
}
|
|
2032
2059
|
/** Keeps the chat off its direct link for `minutes` (again: from now). */
|
|
2033
2060
|
function holdChat(ctx, link, minutes) {
|
|
2034
2061
|
return inTurn(ctx, link.id, async () => {
|
|
@@ -2486,9 +2513,9 @@ function callNode(raw, ref, groupId) {
|
|
|
2486
2513
|
*/
|
|
2487
2514
|
function joined(ctx, params, twin) {
|
|
2488
2515
|
const group = groupOf(ctx, params, twin);
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2516
|
+
const yet = notInYet(group, str(params, "group", true));
|
|
2517
|
+
if (yet) throw new CliError("refused", yet);
|
|
2518
|
+
return group;
|
|
2492
2519
|
}
|
|
2493
2520
|
/** The member `params.member` names in `group`, this profile's own name said to be it; by its key only for a grant. */
|
|
2494
2521
|
var member = (ctx, group, params, grant = false) => findMember(group, str(params, "member", true), settingsOf(ctx).nick, grant);
|
|
@@ -2628,7 +2655,8 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2628
2655
|
*/
|
|
2629
2656
|
var drafts = /* @__PURE__ */ new Map();
|
|
2630
2657
|
var NO_DRAFT = `No such draft here: it is kept by the daemon that made it, for ${IDENTITY_DRAFT_TTL_MS / 6e4} minutes and while fewer than 4 newer ones wait`;
|
|
2631
|
-
|
|
2658
|
+
/** The provider `id` names; a one-shot `identity add` asks before the profile opens (main.ts `identityAddCommand`). */
|
|
2659
|
+
function identityProvider(id) {
|
|
2632
2660
|
const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
|
|
2633
2661
|
if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
|
|
2634
2662
|
return found;
|
|
@@ -2753,7 +2781,7 @@ var IDENTITY_METHODS = {
|
|
|
2753
2781
|
/** Starts a proof. In-app signers finish it here; the others return the statement and what to do with it. */
|
|
2754
2782
|
async "identity.add"(ctx, params) {
|
|
2755
2783
|
pruneDrafts();
|
|
2756
|
-
const p =
|
|
2784
|
+
const p = identityProvider(str(params, "provider", true));
|
|
2757
2785
|
const signer = signerOf(p, str(params, "signer"));
|
|
2758
2786
|
if (signer.kind === "in-app") {
|
|
2759
2787
|
const values = params.fields ?? {};
|
|
@@ -2772,6 +2800,12 @@ var IDENTITY_METHODS = {
|
|
|
2772
2800
|
max: most
|
|
2773
2801
|
});
|
|
2774
2802
|
const signal = AbortSignal.timeout(seconds * 1e3);
|
|
2803
|
+
let signed = false;
|
|
2804
|
+
const request = str(params, "request");
|
|
2805
|
+
const tag = {
|
|
2806
|
+
provider: p.id,
|
|
2807
|
+
...request ? { request } : {}
|
|
2808
|
+
};
|
|
2775
2809
|
return {
|
|
2776
2810
|
done: true,
|
|
2777
2811
|
proof: proofJson(await signer.run({
|
|
@@ -2780,19 +2814,19 @@ var IDENTITY_METHODS = {
|
|
|
2780
2814
|
waitMs: seconds * 1e3,
|
|
2781
2815
|
onAuthUrl: (url) => {
|
|
2782
2816
|
ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
|
|
2783
|
-
|
|
2817
|
+
...tag,
|
|
2784
2818
|
url
|
|
2785
2819
|
});
|
|
2786
2820
|
},
|
|
2787
2821
|
onProgress: (message) => {
|
|
2788
2822
|
ctx.hub.emit("identity.progress", `identity.progress:${Date.now()}`, {
|
|
2789
|
-
|
|
2823
|
+
...tag,
|
|
2790
2824
|
message
|
|
2791
2825
|
});
|
|
2792
2826
|
},
|
|
2793
2827
|
onApproval: (request) => {
|
|
2794
2828
|
if (request) ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
|
|
2795
|
-
|
|
2829
|
+
...tag,
|
|
2796
2830
|
...request.qr ? {
|
|
2797
2831
|
qr: request.qr.value,
|
|
2798
2832
|
label: request.qr.label
|
|
@@ -2803,9 +2837,11 @@ var IDENTITY_METHODS = {
|
|
|
2803
2837
|
}, async (session) => {
|
|
2804
2838
|
const { draftId, binding } = await begin(ctx, p, await session.subject(), params);
|
|
2805
2839
|
try {
|
|
2840
|
+
const evidence = await session.sign(identityStatement(binding));
|
|
2841
|
+
signed = true;
|
|
2806
2842
|
return await node(ctx).completeIdentityProof({
|
|
2807
2843
|
draftId,
|
|
2808
|
-
evidence
|
|
2844
|
+
evidence
|
|
2809
2845
|
});
|
|
2810
2846
|
} catch (error) {
|
|
2811
2847
|
try {
|
|
@@ -2814,7 +2850,7 @@ var IDENTITY_METHODS = {
|
|
|
2814
2850
|
throw error;
|
|
2815
2851
|
}
|
|
2816
2852
|
}).catch((error) => {
|
|
2817
|
-
if (!(signal.aborted || error instanceof SignerTimeout) || error instanceof CliError) throw error;
|
|
2853
|
+
if (signed || !(signal.aborted || error instanceof SignerTimeout) || error instanceof CliError) throw error;
|
|
2818
2854
|
throw new CliError("timeout", `Timed out after ${seconds} s waiting for ${signer.label} to approve the ${p.label} proof: --timeout <seconds> waits longer`);
|
|
2819
2855
|
}))
|
|
2820
2856
|
};
|
|
@@ -2850,7 +2886,7 @@ var IDENTITY_METHODS = {
|
|
|
2850
2886
|
pruneDrafts();
|
|
2851
2887
|
const draft = drafts.get(str(params, "draft", true));
|
|
2852
2888
|
if (!draft) throw new CliError("not_found", NO_DRAFT);
|
|
2853
|
-
const signer = signerOf(
|
|
2889
|
+
const signer = signerOf(identityProvider(draft.provider), draft.signer);
|
|
2854
2890
|
const statement = identityStatement(draft.binding);
|
|
2855
2891
|
let evidence;
|
|
2856
2892
|
try {
|
|
@@ -3250,9 +3286,25 @@ async function proxy(request, response, chunks, send, cookies, policy) {
|
|
|
3250
3286
|
*/
|
|
3251
3287
|
function serviceOf(ctx, params) {
|
|
3252
3288
|
const serviceId = str(params, "service", true);
|
|
3253
|
-
|
|
3289
|
+
const { services } = state(ctx);
|
|
3290
|
+
if (!services.some((s) => s.id === serviceId)) throw noService(serviceId, servicesNamed(services, serviceId));
|
|
3254
3291
|
return serviceId;
|
|
3255
3292
|
}
|
|
3293
|
+
/** The ids of the services `given` names by their name, compared as a chat's label is (`nameKey`: one case, one form). */
|
|
3294
|
+
function servicesNamed(services, given) {
|
|
3295
|
+
const key = nameKey(given);
|
|
3296
|
+
return key ? services.filter((s) => nameKey(s.name) === key).map((s) => s.id) : [];
|
|
3297
|
+
}
|
|
3298
|
+
/**
|
|
3299
|
+
* No service of that id. A service's name given instead (`service add "My App"` makes `my-app`) is told which id to
|
|
3300
|
+
* use: before, it read "No service" of a service `service list` shows by that very name. Same code and exit either way.
|
|
3301
|
+
*/
|
|
3302
|
+
function noService(given, named) {
|
|
3303
|
+
const quoted = JSON.stringify(given);
|
|
3304
|
+
if (!named.length) return new CliError("not_found", `No service ${quoted} (ghostly service list)`);
|
|
3305
|
+
const which = named.length === 1 ? `${named[0]}: use its id` : `${named.length} services, ${named.slice(0, -1).join(", ")} and ${named.at(-1)}: use one of their ids`;
|
|
3306
|
+
return new CliError("not_found", `No service with id ${quoted}. ${quoted} is the name of ${which} (ghostly service list)`);
|
|
3307
|
+
}
|
|
3256
3308
|
/**
|
|
3257
3309
|
* On, unless `off`; or as the answer's own key (`shared`, `enabled`) says, when a socket client sends it back. Before,
|
|
3258
3310
|
* only `off` was read, so `{"shared": false}` shared the service with the contact and `{"enabled": false}` turned it on.
|
|
@@ -3283,6 +3335,27 @@ function serviceNameOf(params) {
|
|
|
3283
3335
|
});
|
|
3284
3336
|
return name;
|
|
3285
3337
|
}
|
|
3338
|
+
/** `service add`'s name and target, checked with no profile open (api.ts `refuseBeforeStart`). */
|
|
3339
|
+
function serviceShape(params) {
|
|
3340
|
+
const name = serviceNameOf(params);
|
|
3341
|
+
const target = str(params, "target", true);
|
|
3342
|
+
try {
|
|
3343
|
+
parseLocalTarget(target);
|
|
3344
|
+
} catch (error) {
|
|
3345
|
+
const said = error instanceof Error ? error.message : String(error);
|
|
3346
|
+
const text = target.trim();
|
|
3347
|
+
let shown = "";
|
|
3348
|
+
try {
|
|
3349
|
+
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
|
|
3350
|
+
shown = `: ${url.protocol}//${url.host}${url.pathname}`;
|
|
3351
|
+
} catch {}
|
|
3352
|
+
throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}${shown}`);
|
|
3353
|
+
}
|
|
3354
|
+
return {
|
|
3355
|
+
name,
|
|
3356
|
+
target
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3286
3359
|
function portError(error, port) {
|
|
3287
3360
|
const { code } = error ?? {};
|
|
3288
3361
|
if (port && code === "EADDRINUSE") return new CliError("busy", `Port ${port} is in use on this machine: choose another, or leave out --port`);
|
|
@@ -3301,20 +3374,7 @@ var SERVICE_METHODS = {
|
|
|
3301
3374
|
})) };
|
|
3302
3375
|
},
|
|
3303
3376
|
async "service.add"(ctx, params) {
|
|
3304
|
-
const name =
|
|
3305
|
-
const target = str(params, "target", true);
|
|
3306
|
-
try {
|
|
3307
|
-
parseLocalTarget(target);
|
|
3308
|
-
} catch (error) {
|
|
3309
|
-
const said = error instanceof Error ? error.message : String(error);
|
|
3310
|
-
const text = target.trim();
|
|
3311
|
-
let shown = text;
|
|
3312
|
-
try {
|
|
3313
|
-
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
|
|
3314
|
-
shown = `${url.protocol}//${url.host}${url.pathname}`;
|
|
3315
|
-
} catch {}
|
|
3316
|
-
throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}: ${shown}`);
|
|
3317
|
-
}
|
|
3377
|
+
const { name, target } = serviceShape(params);
|
|
3318
3378
|
const { serviceId } = node(ctx).addService({
|
|
3319
3379
|
name,
|
|
3320
3380
|
target
|
|
@@ -3526,7 +3586,7 @@ var APP_SERVE_METHODS = {
|
|
|
3526
3586
|
if (grant.includes("internet")) throw new CliError("refused", "internet cannot be granted here: no app's page runs on the CLI, and a bot reaches the network as its own program");
|
|
3527
3587
|
if (grant.includes("files")) throw new CliError("refused", "files cannot be granted here: no app's page runs on the CLI to ask a person for a file, and a bot reads files as its own program");
|
|
3528
3588
|
const ungrantable = grant.filter((p) => !GRANTABLE.includes(p));
|
|
3529
|
-
if (ungrantable.length) throw new CliError("bad_request", `grant takes ${GRANTABLE.join(" or ")}, not ${ungrantable.map((p) =>
|
|
3589
|
+
if (ungrantable.length) throw new CliError("bad_request", `grant takes ${GRANTABLE.join(" or ")}, not ${ungrantable.map((p) => shownValue(p)).join(", ")}`);
|
|
3530
3590
|
const given = str(params, "url");
|
|
3531
3591
|
if (given !== void 0 && !isAppUrl(given)) throw new CliError("bad_request", "url is where a contact's app reads the bundle: https only, no user or password, jsDelivr only at a full commit");
|
|
3532
3592
|
if (given !== void 0 && /[?#]/.test(given)) throw new CliError("bad_request", "url goes to contacts on the app's card: no query or fragment (a private repository's token rides there); publish the app in a public repository");
|
|
@@ -3774,6 +3834,42 @@ var NOT_SENT = {
|
|
|
3774
3834
|
message: `More than 48 frames in a second, or the connection is still sending earlier ones: slow down and send it again`
|
|
3775
3835
|
}
|
|
3776
3836
|
};
|
|
3837
|
+
// ../../apps/ui/src/lib/localHost.ts
|
|
3838
|
+
/**
|
|
3839
|
+
* Names only a local network answers (RFC 6762, RFC 8375, ICANN's .internal, and the usual router and company ones).
|
|
3840
|
+
* A copy of packages/core/src/localNames.ts, as this module imports nothing; the same as Desktop's
|
|
3841
|
+
* apps/desktop/src/local_names.rs (src/test/chat/linkPreviewParse.test.ts pins all three).
|
|
3842
|
+
*/
|
|
3843
|
+
var LOCAL_SUFFIXES = [
|
|
3844
|
+
"localhost",
|
|
3845
|
+
"local",
|
|
3846
|
+
"internal",
|
|
3847
|
+
"lan",
|
|
3848
|
+
"home",
|
|
3849
|
+
"home.arpa",
|
|
3850
|
+
"localdomain",
|
|
3851
|
+
"intranet",
|
|
3852
|
+
"corp"
|
|
3853
|
+
];
|
|
3854
|
+
/**
|
|
3855
|
+
* A host that names this machine or the local network, as far as its spelling tells: a name under a local suffix
|
|
3856
|
+
* (`localhost`, `.local`, `.lan`, `.home`, `.corp`, …), a single label, private and reserved IP addresses. Previews
|
|
3857
|
+
* are never made for these, a page on the internet may not point its picture at one, and a contact's app may not open
|
|
3858
|
+
* one. (Desktop also checks the addresses a name resolves to.)
|
|
3859
|
+
* In a module of its own, importing nothing: the extension's background worker reads it too.
|
|
3860
|
+
*/
|
|
3861
|
+
function isLocalHost(hostname) {
|
|
3862
|
+
const host = hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
|
|
3863
|
+
if (!host.includes(".") && !host.includes(":")) return true;
|
|
3864
|
+
if (LOCAL_SUFFIXES.some((s) => host === s || host.endsWith(`.${s}`))) return true;
|
|
3865
|
+
const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
3866
|
+
if (v4) {
|
|
3867
|
+
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
3868
|
+
return a === 0 || a === 10 || a === 127 || a >= 224 || a === 169 && b === 254 || a === 172 && b >= 16 && b < 32 || a === 192 && b === 168 || a === 100 && b >= 64 && b < 128 || a === 198 && (b === 18 || b === 19) || a === 192 && b === 0;
|
|
3869
|
+
}
|
|
3870
|
+
if (host.includes(":")) return !/^[23][0-9a-f]{3}:/.test(host) || host.includes(".") || host.startsWith("2002:") || /^2001:(0{0,4}|0{0,3}db8):/.test(host);
|
|
3871
|
+
return false;
|
|
3872
|
+
}
|
|
3777
3873
|
// src/wallets.ts
|
|
3778
3874
|
/**
|
|
3779
3875
|
* Wallets and payments (WISP 1100, phase 2): the app's wallet deck and a chat's payment sheet, as methods. Test
|
|
@@ -3992,6 +4088,54 @@ function memoOf(params, verb, field = "memo") {
|
|
|
3992
4088
|
}
|
|
3993
4089
|
return memo || void 0;
|
|
3994
4090
|
}
|
|
4091
|
+
/**
|
|
4092
|
+
* What `pay` reads of its own words, the target's shape among them: checked again before a one-shot opens the profile
|
|
4093
|
+
* (`refuseBeforeStart`), where a target that is no invoice, address or LNURL started every saved chat to be refused.
|
|
4094
|
+
*/
|
|
4095
|
+
function payShape(params) {
|
|
4096
|
+
const comment = memoOf(params, "pay", "comment");
|
|
4097
|
+
const text = str(params, "target", true).trim();
|
|
4098
|
+
const card = cardParam(params);
|
|
4099
|
+
if (params.chat !== void 0 && !isInvoice(text)) throw new CliError("usage", "--chat names the chat an invoice came from: an address's or LNURL's invoice is its server's");
|
|
4100
|
+
if (!isInvoice(text) && !isLnurl(text)) throw new CliError("bad_request", "Not a Lightning invoice, Lightning address or LNURL");
|
|
4101
|
+
return {
|
|
4102
|
+
comment,
|
|
4103
|
+
text,
|
|
4104
|
+
card
|
|
4105
|
+
};
|
|
4106
|
+
}
|
|
4107
|
+
/** The token `wallet redeem` takes, refused as the engine refuses one Cashu's library cannot read (`refuseBeforeStart`). */
|
|
4108
|
+
async function tokenShape(params) {
|
|
4109
|
+
const token = str(params, "token", true).trim();
|
|
4110
|
+
const { getTokenMetadata } = await import("@cashu/cashu-ts");
|
|
4111
|
+
try {
|
|
4112
|
+
getTokenMetadata(token);
|
|
4113
|
+
} catch {
|
|
4114
|
+
throw new CliError("bad_request", "That is not a valid ecash token");
|
|
4115
|
+
}
|
|
4116
|
+
return token;
|
|
4117
|
+
}
|
|
4118
|
+
/** The mint URL `wallet add-mint` takes, refused in the engine's words when it is no URL or not https (`refuseBeforeStart`). */
|
|
4119
|
+
function mintUrlShape(params) {
|
|
4120
|
+
const url = str(params, "url", true);
|
|
4121
|
+
try {
|
|
4122
|
+
normalizeMintUrl(url);
|
|
4123
|
+
} catch (error) {
|
|
4124
|
+
throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
|
|
4125
|
+
}
|
|
4126
|
+
return url;
|
|
4127
|
+
}
|
|
4128
|
+
/**
|
|
4129
|
+
* What `pay` says with `paid: false`: the payment is not known paid yet. The mint (or the card's source) holds it
|
|
4130
|
+
* pending, or its answer was lost; the engine keeps asking and never pays it twice. Before, the answer said `paid:
|
|
4131
|
+
* false` and nothing else, and no read showed the sats the Cashu wallet set aside for it. Said in the
|
|
4132
|
+
* words of the app's Cashu card ("set aside", `wallet.cashu.setAsideInfo`).
|
|
4133
|
+
*/
|
|
4134
|
+
function notPaidYet(ctx, n, source, amount, feeReserve) {
|
|
4135
|
+
const running = ctx.mode === "one-shot" ? " while this profile runs (`ghostly daemon --detach`)" : "";
|
|
4136
|
+
if (source !== "cashu-mint") return `Not paid yet: your Lightning source has not confirmed this payment (it is pending, or its answer was lost). It is asked again${running} and never paid twice: \`ghostly wallet list\` shows the card's balance once it settles.`;
|
|
4137
|
+
return `Not paid yet: the mint has not settled this payment (it is pending, or its answer was lost). ${`${amount + feeReserve} ${n === "testnet" ? "test sats" : "sats"}`} are set aside for it, out of the balance: they leave with the payment, or come back to the balance if the mint says it failed. It settles by itself: the wallet keeps asking the mint${running} and never pays it twice. \`ghostly wallet history\` lists it once paid, and \`ghostly wallet list\` shows the balance.`;
|
|
4138
|
+
}
|
|
3995
4139
|
function badMintUrl(error) {
|
|
3996
4140
|
const code = error instanceof Error ? error.engineCode : void 0;
|
|
3997
4141
|
return code === "invalidMintUrl" || code === "mintNotHttps";
|
|
@@ -4046,6 +4190,34 @@ function walletRefusal(error) {
|
|
|
4046
4190
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
4047
4191
|
return code ? new CliError(code, error.message) : error;
|
|
4048
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* `wallet redeem` of ecash from a mint that is not one of the wallet's: the engine names the mint's host only and no
|
|
4195
|
+
* way on. Its words, then the command that adds the whole mint URL (the token's), for one who trusts that mint: a mint
|
|
4196
|
+
* holds the sats, so it is offered, never done. Shell-quoted as any hint's word; a URL no quoting survives is not printed.
|
|
4197
|
+
*/
|
|
4198
|
+
function mintNotAdded(error) {
|
|
4199
|
+
if (!(error instanceof Error) || !/^Ecash from \S+ is not accepted$/.test(error.message)) return void 0;
|
|
4200
|
+
const mint = error.mint;
|
|
4201
|
+
if (typeof mint !== "string") return void 0;
|
|
4202
|
+
return new CliError("engine", `${error.message}: its mint is not one of yours (if you trust it to hold your sats: ghostly wallet add-mint ${shellWord(mint, "<the token's mint URL>")})`);
|
|
4203
|
+
}
|
|
4204
|
+
/**
|
|
4205
|
+
* The mints `mintNotAdded` offers no `add-mint` for. A token is what a contact sends, and the way out reads as the
|
|
4206
|
+
* app's advice: never a command `wallet add-mint` refuses (plain http off this machine), nor one that makes a server
|
|
4207
|
+
* on this machine or the local network a mint the wallet then talks to. One who runs such a mint types its URL.
|
|
4208
|
+
*/
|
|
4209
|
+
function mintNotOffered(error) {
|
|
4210
|
+
const mint = error instanceof Error && /^Ecash from \S+ is not accepted$/.test(error.message) ? error.mint : void 0;
|
|
4211
|
+
if (typeof mint !== "string") return void 0;
|
|
4212
|
+
const words = error.message;
|
|
4213
|
+
try {
|
|
4214
|
+
normalizeMintUrl(mint);
|
|
4215
|
+
} catch (refusal) {
|
|
4216
|
+
return new CliError("engine", `${words}: its mint is not one of yours, and not one a wallet can add (${refusal.message})`);
|
|
4217
|
+
}
|
|
4218
|
+
if (!isLocalHost(new URL(mint).hostname)) return void 0;
|
|
4219
|
+
return new CliError("engine", `${words}: its mint is not one of yours, and it is on this machine or a local network (add a mint there only if you run it yourself)`);
|
|
4220
|
+
}
|
|
4049
4221
|
var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
4050
4222
|
async "wallet.list"(ctx, params) {
|
|
4051
4223
|
await federationsOpen(ctx);
|
|
@@ -4191,11 +4363,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4191
4363
|
};
|
|
4192
4364
|
},
|
|
4193
4365
|
async "wallet.redeem"(ctx, params) {
|
|
4194
|
-
return node(ctx).walletReceiveToken({ token:
|
|
4366
|
+
return node(ctx).walletReceiveToken({ token: await tokenShape(params) }).catch((error) => {
|
|
4367
|
+
throw mintNotOffered(error) ?? mintNotAdded(error) ?? error;
|
|
4368
|
+
});
|
|
4195
4369
|
},
|
|
4196
4370
|
async "wallet.mint.add"(ctx, params) {
|
|
4197
4371
|
return node(ctx).walletAddMint({
|
|
4198
|
-
url:
|
|
4372
|
+
url: mintUrlShape(params),
|
|
4199
4373
|
...bool(params, "primary") ? { primary: true } : {}
|
|
4200
4374
|
}).catch((error) => {
|
|
4201
4375
|
throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
|
|
@@ -4227,18 +4401,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4227
4401
|
},
|
|
4228
4402
|
/** An invoice, a Lightning address or an LNURL, from the network's Lightning (a card of it, or its default). */
|
|
4229
4403
|
async "pay"(ctx, params) {
|
|
4230
|
-
const comment =
|
|
4231
|
-
const text = str(params, "target", true).trim();
|
|
4232
|
-
const card = cardParam(params);
|
|
4404
|
+
const { comment, text, card } = payShape(params);
|
|
4233
4405
|
let invoice = text.replace(/^lightning:/i, "");
|
|
4234
|
-
let n;
|
|
4235
4406
|
let note;
|
|
4236
|
-
if (params.chat !== void 0 && !isInvoice(text)) throw new CliError("usage", "--chat names the chat an invoice came from: an address's or LNURL's invoice is its server's");
|
|
4237
4407
|
const chat = params.chat === void 0 ? void 0 : ownChatOf(ctx, params);
|
|
4238
4408
|
if (chat) inviteTaken(chat);
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
n = network(params);
|
|
4409
|
+
const n = network(params);
|
|
4410
|
+
if (!isInvoice(text)) {
|
|
4242
4411
|
const amount = num(params, "amount", 0, { min: 1 });
|
|
4243
4412
|
if (!amount) throw new CliError("bad_request", "amount is required to pay a Lightning address or LNURL");
|
|
4244
4413
|
if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
|
|
@@ -4255,7 +4424,7 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4255
4424
|
});
|
|
4256
4425
|
invoice = got.invoice;
|
|
4257
4426
|
note = got.note;
|
|
4258
|
-
}
|
|
4427
|
+
}
|
|
4259
4428
|
if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
|
|
4260
4429
|
await federationsOpen(ctx);
|
|
4261
4430
|
const quote = await node(ctx).walletQuoteInvoice({
|
|
@@ -4277,12 +4446,14 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4277
4446
|
invoice
|
|
4278
4447
|
} : {}
|
|
4279
4448
|
});
|
|
4449
|
+
const source = quote.source ?? quote.mint;
|
|
4280
4450
|
return {
|
|
4281
4451
|
network: n,
|
|
4282
4452
|
amount: quote.amount,
|
|
4283
4453
|
feeReserve: quote.feeReserve,
|
|
4284
|
-
source
|
|
4285
|
-
paid: paid.paid
|
|
4454
|
+
source,
|
|
4455
|
+
paid: paid.paid,
|
|
4456
|
+
...!paid.paid && { note: notPaidYet(ctx, n, source, quote.amount, quote.feeReserve) }
|
|
4286
4457
|
};
|
|
4287
4458
|
},
|
|
4288
4459
|
/** Ecash to a contact in a chat (the payment sheet's Pay). */
|
|
@@ -4784,6 +4955,62 @@ async function letIn(ctx, groupId, link, held) {
|
|
|
4784
4955
|
warning: `Not in yet: no member's app has let you in. A member's app lets you in only while this profile is running: ${show}`
|
|
4785
4956
|
};
|
|
4786
4957
|
}
|
|
4958
|
+
/**
|
|
4959
|
+
* Why a text that waits will not go by itself, or undefined (waitNotice.ts `dhtOnlyNote`). This side's DHT only that is
|
|
4960
|
+
* a hold (`chat disconnect --hold`) is read from `ctx`'s profile; without it, as a DHT only chosen.
|
|
4961
|
+
*/
|
|
4962
|
+
function dhtOnlyWait(link, text, ref, ctx) {
|
|
4963
|
+
const mine = link.deliveryMode === "dht";
|
|
4964
|
+
return dhtOnlyNote({
|
|
4965
|
+
mine,
|
|
4966
|
+
theirs: link.dhtDelivery?.peerMode === "dht",
|
|
4967
|
+
heldUntil: mine && ctx ? holdEnds(ctx, link.id) : null,
|
|
4968
|
+
oneShot: ctx?.mode === "one-shot"
|
|
4969
|
+
}, text, ref);
|
|
4970
|
+
}
|
|
4971
|
+
/**
|
|
4972
|
+
* A `--wait sent|delivered` on a text `dhtOnlyWait` holds back, ended short (its timeout, the daemon's stop): it said the
|
|
4973
|
+
* text still goes by itself, or with this profile's next command, which it does not while the chat stays on the DHT
|
|
4974
|
+
* only. It says why instead, with the note in `details.note` too; same code and exit. Read again at the end: a chat
|
|
4975
|
+
* taken off DHT only meanwhile keeps the usual words.
|
|
4976
|
+
*/
|
|
4977
|
+
function dhtOnlyTimeout(ctx, chat, text, ref, ms, error) {
|
|
4978
|
+
if (!(error instanceof CliError) || error.code !== "timeout" || error.details?.delivery !== "waiting") return error;
|
|
4979
|
+
const link = state(ctx).links.find((l) => l.id === chat);
|
|
4980
|
+
const note = link && dhtOnlyWait(link, text, ref, ctx);
|
|
4981
|
+
return note ? new CliError("timeout", `${ended(ctx, ms)}: the message is waiting. ${note}`, {
|
|
4982
|
+
...error.details,
|
|
4983
|
+
note
|
|
4984
|
+
}) : error;
|
|
4985
|
+
}
|
|
4986
|
+
/**
|
|
4987
|
+
* What keeps `link` off a live session, or undefined: a chat on DHT only opens none (WISP 100: no app dials it). A hold
|
|
4988
|
+
* of this side's (`chat disconnect --hold`) ends by itself (`held`: when), unless the contact's choice keeps it there
|
|
4989
|
+
* too; this side's choice or the contact's is `chat connect`'s refusal (apiKit `dhtOnly`), in its words.
|
|
4990
|
+
*/
|
|
4991
|
+
function offLive(ctx, link) {
|
|
4992
|
+
const held = link.deliveryMode === "dht" && link.dhtDelivery?.peerMode !== "dht" ? holdEnds(ctx, link.id) : null;
|
|
4993
|
+
if (held !== null) return { held };
|
|
4994
|
+
try {
|
|
4995
|
+
dhtOnly(link);
|
|
4996
|
+
} catch (error) {
|
|
4997
|
+
if (error instanceof CliError) return { refusal: error };
|
|
4998
|
+
throw error;
|
|
4999
|
+
}
|
|
5000
|
+
}
|
|
5001
|
+
/**
|
|
5002
|
+
* A `chat wait --until live` that timed out on a chat on DHT only: it could never go live, and its timeout read as a
|
|
5003
|
+
* slow network, so a script waited again. Said with why and what ends it, in `chat connect`'s words; same code, exit
|
|
5004
|
+
* and fields. Read as the chat is at the end: one taken off DHT only meanwhile keeps the usual words.
|
|
5005
|
+
*/
|
|
5006
|
+
function liveNeverCame(ctx, linkId, ref, error) {
|
|
5007
|
+
if (!(error instanceof CliError) || error.code !== "timeout" || error.details) return error;
|
|
5008
|
+
const link = state(ctx).links.find((l) => l.id === linkId);
|
|
5009
|
+
const off = link && offLive(ctx, link);
|
|
5010
|
+
if (!off) return error;
|
|
5011
|
+
const why = "held" in off ? heldWords(off.held, ref, "it goes live", ctx.mode === "one-shot") : off.refusal.message;
|
|
5012
|
+
return new CliError("timeout", `${error.message}. ${why.charAt(0).toUpperCase()}${why.slice(1)}`);
|
|
5013
|
+
}
|
|
4787
5014
|
var METHODS = {
|
|
4788
5015
|
...WALLET_METHODS,
|
|
4789
5016
|
...FILE_METHODS,
|
|
@@ -5006,10 +5233,14 @@ var METHODS = {
|
|
|
5006
5233
|
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
5007
5234
|
group: false,
|
|
5008
5235
|
ref: str(params, "chat", true)
|
|
5009
|
-
}) || (/not in this chat|cannot be replied to/.test(result.error) ? new CliError("not_found", result.error) : new CliError(result.refused ? "refused" : "unavailable", result.error));
|
|
5236
|
+
}) || (/not in this chat|cannot be replied to/.test(result.error) ? new CliError("not_found", result.error) : new CliError(result.refused ? "refused" : "unavailable", dhtTooLong(ctx, link, result.error, "text", str(params, "chat", true))));
|
|
5010
5237
|
if (!result.messageId) throw new CliError("bad_request", "Nothing to send");
|
|
5011
5238
|
let message = await node(ctx).getMessage(link.id, result.messageId);
|
|
5012
|
-
|
|
5239
|
+
const ref = str(params, "chat", true);
|
|
5240
|
+
const dhtOnly = message?.delivery === "waiting" ? dhtOnlyWait(link, text, ref, ctx) : void 0;
|
|
5241
|
+
if (wait !== "none" && !(dhtOnly && params.wait === void 0)) message = await waitForMessage(ctx, link.id, result.messageId, wait, ms).catch((error) => {
|
|
5242
|
+
throw dhtOnlyTimeout(ctx, link.id, text, ref, ms, error);
|
|
5243
|
+
});
|
|
5013
5244
|
return {
|
|
5014
5245
|
chat: link.id,
|
|
5015
5246
|
messageId: result.messageId,
|
|
@@ -5019,7 +5250,8 @@ var METHODS = {
|
|
|
5019
5250
|
card,
|
|
5020
5251
|
pressable: pressable(link)
|
|
5021
5252
|
} : {},
|
|
5022
|
-
...unjoined && message?.delivery === "waiting" && { note: `Nobody joined this chat yet: the message goes once they join${ctx.mode === "one-shot" ? " while this profile is online (`ghostly daemon --detach`)" : ""}` }
|
|
5253
|
+
...unjoined && message?.delivery === "waiting" && { note: `Nobody joined this chat yet: the message goes once they join${ctx.mode === "one-shot" ? " while this profile is online (`ghostly daemon --detach`)" : ""}` },
|
|
5254
|
+
...dhtOnly && message?.delivery === "waiting" && { note: dhtOnly }
|
|
5023
5255
|
};
|
|
5024
5256
|
},
|
|
5025
5257
|
/**
|
|
@@ -5036,17 +5268,21 @@ var METHODS = {
|
|
|
5036
5268
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; edit with --force if you mean to`, { kind: secret.kind });
|
|
5037
5269
|
}
|
|
5038
5270
|
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
5271
|
+
const prior = await node(ctx).getMessage(link.id, messageId);
|
|
5272
|
+
const before = prior ? prior.edit?.seq ?? 0 : void 0;
|
|
5039
5273
|
const result = await node(ctx).editMessage({
|
|
5040
5274
|
linkId: link.id,
|
|
5041
5275
|
messageId,
|
|
5042
5276
|
text
|
|
5043
5277
|
});
|
|
5044
|
-
if (result.error) throw
|
|
5278
|
+
if (result.error) throw await editRefused(ctx, link.id, messageId, {
|
|
5045
5279
|
group: false,
|
|
5046
5280
|
ref: str(params, "chat", true)
|
|
5047
|
-
}, result.error, result
|
|
5281
|
+
}, dhtTooLong(ctx, link, result.error, "edit", str(params, "chat", true)), result);
|
|
5048
5282
|
const id = result.messageId ?? messageId;
|
|
5049
5283
|
let message = await node(ctx).getMessage(link.id, id);
|
|
5284
|
+
const edits = message?.edit?.seq ?? 0;
|
|
5285
|
+
const unchanged = !!message && edits === (before ?? 0);
|
|
5050
5286
|
if (wait === "confirmed" && message?.edit?.pending) message = await waitForEdit(ctx, link.id, id, ms);
|
|
5051
5287
|
const confirmed = !!message && !message.edit?.pending;
|
|
5052
5288
|
return {
|
|
@@ -5054,6 +5290,8 @@ var METHODS = {
|
|
|
5054
5290
|
messageId: id,
|
|
5055
5291
|
edits: message?.edit?.seq ?? 0,
|
|
5056
5292
|
confirmed,
|
|
5293
|
+
...unchanged && { unchanged: true },
|
|
5294
|
+
...!confirmed && result.note && { note: result.note },
|
|
5057
5295
|
...!confirmed && keptForJoin(ctx, link.id, "the edit")
|
|
5058
5296
|
};
|
|
5059
5297
|
},
|
|
@@ -5150,7 +5388,11 @@ var METHODS = {
|
|
|
5150
5388
|
ref: str(params, "chat", true)
|
|
5151
5389
|
}) : void 0;
|
|
5152
5390
|
if (gone) throw gone;
|
|
5153
|
-
if (result.error)
|
|
5391
|
+
if (result.error) {
|
|
5392
|
+
const error = new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this (?:chat|group)|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
|
|
5393
|
+
const group = target.group ? groupById(ctx, target.id) : void 0;
|
|
5394
|
+
throw group ? notInYetError(group, str(params, "chat", true), error) : error;
|
|
5395
|
+
}
|
|
5154
5396
|
if (target.group) {
|
|
5155
5397
|
const n = result.n, pinned = remove ? null : messageId;
|
|
5156
5398
|
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, target.id, messageId ?? "", { pin: n }, ms) : node(ctx).groupTaken({
|
|
@@ -5223,7 +5465,10 @@ var METHODS = {
|
|
|
5223
5465
|
const target = chatOrGroup(ctx, ref, s);
|
|
5224
5466
|
if (to.some((t) => t.linkId === target.linkId)) continue;
|
|
5225
5467
|
if (to.length === 5) throw new CliError("bad_request", `Forward to at most 5 chats and groups at once`);
|
|
5226
|
-
to.push(
|
|
5468
|
+
to.push({
|
|
5469
|
+
...target,
|
|
5470
|
+
ref
|
|
5471
|
+
});
|
|
5227
5472
|
}
|
|
5228
5473
|
if (!to.length) throw new CliError("bad_request", "Forward to which chat? Name one or more with --to");
|
|
5229
5474
|
const chosen = [];
|
|
@@ -5265,6 +5510,14 @@ var METHODS = {
|
|
|
5265
5510
|
sent: result.sent,
|
|
5266
5511
|
error: result.error
|
|
5267
5512
|
}));
|
|
5513
|
+
for (const [i, result] of out.entries()) {
|
|
5514
|
+
const link = to[i].group ? void 0 : state(ctx).links.find((l) => l.id === to[i].id);
|
|
5515
|
+
if (!link || link.deliveryMode !== "dht" && link.dhtDelivery?.peerMode !== "dht") continue;
|
|
5516
|
+
for (const messageId of result.messageIds) {
|
|
5517
|
+
const copy = await node(ctx).getMessage(link.id, messageId);
|
|
5518
|
+
if (copy && !copy.file && copy.delivery === "waiting") result.note ??= dhtOnlyWait(link, copy.text, to[i].ref);
|
|
5519
|
+
}
|
|
5520
|
+
}
|
|
5268
5521
|
let short;
|
|
5269
5522
|
const waited = async (wait, now) => {
|
|
5270
5523
|
if (short) return now();
|
|
@@ -5296,7 +5549,9 @@ var METHODS = {
|
|
|
5296
5549
|
file: sent.file.id,
|
|
5297
5550
|
timeout: ms / 1e3
|
|
5298
5551
|
});
|
|
5299
|
-
else await waitForMessage(ctx, to[i].id, messageId, "sent", ms)
|
|
5552
|
+
else await waitForMessage(ctx, to[i].id, messageId, "sent", ms).catch((error) => {
|
|
5553
|
+
throw dhtOnlyTimeout(ctx, to[i].id, sent?.text ?? "", to[i].ref, ms, error);
|
|
5554
|
+
});
|
|
5300
5555
|
}, () => void 0);
|
|
5301
5556
|
}
|
|
5302
5557
|
const failed = out.filter((r) => r.error);
|
|
@@ -5353,14 +5608,15 @@ var METHODS = {
|
|
|
5353
5608
|
max: 3600
|
|
5354
5609
|
}) * 1e3;
|
|
5355
5610
|
const ref = str(params, "message", true);
|
|
5356
|
-
|
|
5357
|
-
|
|
5611
|
+
let theirs;
|
|
5612
|
+
const message = await messageOf(ctx, target.linkId, ref, (m) => {
|
|
5613
|
+
if (m.sender !== "me" && (m.id === ref || m.wireId === ref)) theirs ??= m;
|
|
5614
|
+
return m.sender === "me";
|
|
5615
|
+
});
|
|
5616
|
+
if (!message) throw deleteNotMine(ctx, target, ref, theirs, {
|
|
5358
5617
|
group: target.group,
|
|
5359
5618
|
ref: str(params, "chat", true)
|
|
5360
|
-
},
|
|
5361
|
-
whose: "of yours",
|
|
5362
|
-
tail: ": only your own messages are deleted for everyone"
|
|
5363
|
-
});
|
|
5619
|
+
}, purge);
|
|
5364
5620
|
const result = await node(ctx).removeMessage({
|
|
5365
5621
|
linkId: target.linkId,
|
|
5366
5622
|
messageId: message.id
|
|
@@ -5480,7 +5736,7 @@ var METHODS = {
|
|
|
5480
5736
|
return { removed: link.id };
|
|
5481
5737
|
},
|
|
5482
5738
|
async "chat.transport"(ctx, params) {
|
|
5483
|
-
const link =
|
|
5739
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5484
5740
|
const name = str(params, "transport", true);
|
|
5485
5741
|
const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
|
|
5486
5742
|
if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
|
|
@@ -5495,7 +5751,7 @@ var METHODS = {
|
|
|
5495
5751
|
},
|
|
5496
5752
|
/** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
|
|
5497
5753
|
async "chat.connect"(ctx, params) {
|
|
5498
|
-
const link =
|
|
5754
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5499
5755
|
await releaseHold(ctx, link.id, "connect");
|
|
5500
5756
|
inviteTaken(link);
|
|
5501
5757
|
dhtOnly(findChat(state(ctx).links, link.id));
|
|
@@ -5510,7 +5766,7 @@ var METHODS = {
|
|
|
5510
5766
|
* direct link that long, on the DHT (its "DHT only" choice, taken back after); 0 ends a hold now.
|
|
5511
5767
|
*/
|
|
5512
5768
|
async "chat.disconnect"(ctx, params) {
|
|
5513
|
-
const link =
|
|
5769
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5514
5770
|
const minutes = params.hold === void 0 ? void 0 : num(params, "hold", 0, {
|
|
5515
5771
|
min: 0,
|
|
5516
5772
|
max: HOLD_MAX_MINUTES
|
|
@@ -5541,7 +5797,7 @@ var METHODS = {
|
|
|
5541
5797
|
return chatJson(findChat(state(ctx).links, link.id));
|
|
5542
5798
|
},
|
|
5543
5799
|
async "chat.wait"(ctx, params) {
|
|
5544
|
-
const link =
|
|
5800
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5545
5801
|
const until = oneOf(params, "until", [
|
|
5546
5802
|
"live",
|
|
5547
5803
|
"text",
|
|
@@ -5551,11 +5807,14 @@ var METHODS = {
|
|
|
5551
5807
|
min: 1,
|
|
5552
5808
|
max: 86400
|
|
5553
5809
|
}) * 1e3;
|
|
5810
|
+
const ref = str(params, "chat", true);
|
|
5554
5811
|
return chatJson(await waitForState(ctx, (s) => {
|
|
5555
5812
|
const now = s.links.find((l) => l.id === link.id);
|
|
5556
5813
|
if (!now) throw new CliError("not_found", `Chat ${link.id} was removed`);
|
|
5557
5814
|
return (until === "live" ? isLive(now) : until === "text" ? now.textDelivery === "stream" || now.textDelivery === "dht" || now.textDelivery === "hold" : !!now.peerParticipationKey || !!now.pairingProgress?.peerSeen || now.pairing?.status === "ready" || isLive(now)) ? now : void 0;
|
|
5558
|
-
}, ms, `chat ${
|
|
5815
|
+
}, ms, `chat ${ref} ${chatState(until).to}`).catch((error) => {
|
|
5816
|
+
throw until === "live" ? liveNeverCame(ctx, link.id, ref, error) : error;
|
|
5817
|
+
}));
|
|
5559
5818
|
},
|
|
5560
5819
|
async "group.create"(ctx, params) {
|
|
5561
5820
|
const name = groupNameOf(params);
|
|
@@ -5577,7 +5836,7 @@ var METHODS = {
|
|
|
5577
5836
|
({groupId} = await node(ctx).joinGroupByLink({ link }));
|
|
5578
5837
|
} catch (error) {
|
|
5579
5838
|
if (error instanceof Error && error.message === "This is not a link to a group") throw new CliError("bad_request", error.message);
|
|
5580
|
-
throw error;
|
|
5839
|
+
throw joinRefused(link, error);
|
|
5581
5840
|
}
|
|
5582
5841
|
return letIn(ctx, groupId, link, before.find((g) => g.id === groupId));
|
|
5583
5842
|
},
|
|
@@ -5633,7 +5892,7 @@ var METHODS = {
|
|
|
5633
5892
|
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
5634
5893
|
group: true,
|
|
5635
5894
|
ref: str(params, "group", true)
|
|
5636
|
-
}) || (result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
5895
|
+
}) || notInYetError(group, str(params, "group", true), result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
5637
5896
|
const messageId = result.messageId ?? null;
|
|
5638
5897
|
const edges = messageId ? wait === "sent" ? await waitForGroupFrame(ctx, group.id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
5639
5898
|
groupId: group.id,
|
|
@@ -5679,10 +5938,10 @@ var METHODS = {
|
|
|
5679
5938
|
text,
|
|
5680
5939
|
...mentions.length ? { mentions } : {}
|
|
5681
5940
|
});
|
|
5682
|
-
if (result.error) throw
|
|
5941
|
+
if (result.error) throw await editRefused(ctx, linkId, messageId, {
|
|
5683
5942
|
group: true,
|
|
5684
5943
|
ref: str(params, "group", true)
|
|
5685
|
-
}, result.error, result
|
|
5944
|
+
}, result.error, result);
|
|
5686
5945
|
const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
|
|
5687
5946
|
if (edits === before) return {
|
|
5688
5947
|
group: group.id,
|
|
@@ -5716,9 +5975,12 @@ var METHODS = {
|
|
|
5716
5975
|
min: 1,
|
|
5717
5976
|
max: 3600
|
|
5718
5977
|
}) * 1e3;
|
|
5978
|
+
const ref = str(params, "group", true);
|
|
5719
5979
|
const { n, ...said } = await react(ctx, `group:${group.id}`, params, {
|
|
5720
5980
|
group: true,
|
|
5721
|
-
ref
|
|
5981
|
+
ref
|
|
5982
|
+
}).catch((error) => {
|
|
5983
|
+
throw error instanceof CliError ? notInYetError(group, ref, error) : error;
|
|
5722
5984
|
});
|
|
5723
5985
|
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, group.id, said.messageId, { reaction: n }, ms) : node(ctx).groupTaken({
|
|
5724
5986
|
groupId: group.id,
|
|
@@ -5750,7 +6012,7 @@ var METHODS = {
|
|
|
5750
6012
|
max: 600
|
|
5751
6013
|
});
|
|
5752
6014
|
if (!typing && seconds) throw new CliError("bad_request", "for keeps typing on: not with stop");
|
|
5753
|
-
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? "You are not in this group");
|
|
6015
|
+
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? notInYet(group, str(params, "group", true)) ?? "You are not in this group");
|
|
5754
6016
|
const target = { groupId: group.id };
|
|
5755
6017
|
endTyping(ctx, target, false);
|
|
5756
6018
|
sayTyping(ctx, target, typing, word);
|
|
@@ -5772,7 +6034,10 @@ var METHODS = {
|
|
|
5772
6034
|
async "group.leave"(ctx, params) {
|
|
5773
6035
|
const group = groupOf(ctx, params);
|
|
5774
6036
|
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass --yes (yes: true over the socket) to go on");
|
|
5775
|
-
const
|
|
6037
|
+
const ref = str(params, "group", true);
|
|
6038
|
+
const { admin } = await node(ctx).leaveGroup({ groupId: group.id }).catch((error) => {
|
|
6039
|
+
throw leaveRefused(group, ref, error);
|
|
6040
|
+
});
|
|
5776
6041
|
const next = admin ? group.members.find((m) => m.key === admin) : void 0;
|
|
5777
6042
|
return {
|
|
5778
6043
|
left: group.id,
|
|
@@ -5905,7 +6170,8 @@ var ENGINE_SENDS = /* @__PURE__ */ new Set([
|
|
|
5905
6170
|
"renameGroup",
|
|
5906
6171
|
"updateSettings",
|
|
5907
6172
|
"sendFile",
|
|
5908
|
-
"setOwnStatus"
|
|
6173
|
+
"setOwnStatus",
|
|
6174
|
+
"nostrDraft"
|
|
5909
6175
|
]);
|
|
5910
6176
|
async function guardEngineSend(ctx, method, args) {
|
|
5911
6177
|
const of = (value, key) => value && typeof value === "object" ? value[key] : void 0;
|
|
@@ -5918,12 +6184,14 @@ async function guardEngineSend(ctx, method, args) {
|
|
|
5918
6184
|
args.name,
|
|
5919
6185
|
of(args.settings, "nick"),
|
|
5920
6186
|
of(args.file, "name"),
|
|
5921
|
-
of(args.status, "text")
|
|
6187
|
+
of(args.status, "text"),
|
|
6188
|
+
args.content,
|
|
6189
|
+
...args.fields && typeof args.fields === "object" ? Object.values(args.fields) : []
|
|
5922
6190
|
];
|
|
5923
6191
|
if (method === "forwardMessages") {
|
|
5924
|
-
const ids = Array.isArray(args.messageIds) ? args.messageIds.filter((id) => typeof id === "string") : [];
|
|
6192
|
+
const ids = Array.isArray(args.messageIds) ? [...new Set(args.messageIds.filter((id) => typeof id === "string"))] : [];
|
|
5925
6193
|
const linkId = args.linkId;
|
|
5926
|
-
texts = typeof linkId === "string" && linkId ? await Promise.all(ids.map(async (id) => {
|
|
6194
|
+
texts = typeof linkId === "string" && linkId && ids.length <= 30 ? await Promise.all(ids.map(async (id) => {
|
|
5927
6195
|
const message = await node(ctx).getMessage(linkId, id);
|
|
5928
6196
|
return message && !message.file ? message.text : null;
|
|
5929
6197
|
})) : [];
|
|
@@ -5998,6 +6266,49 @@ function groupSendRefused(error) {
|
|
|
5998
6266
|
if (/^You (were removed from|left|are no longer in) this group$|Membership changes are halted/.test(error)) return new CliError("refused", error);
|
|
5999
6267
|
return new CliError("unavailable", error);
|
|
6000
6268
|
}
|
|
6269
|
+
/** The engine's admin who may not leave: the app's words say "make someone the admin", which names no command here. */
|
|
6270
|
+
var ADMIN_ALONE = "You are the admin and nobody else in the group is online to take over. Try again when a member is, or make someone the admin first.";
|
|
6271
|
+
/**
|
|
6272
|
+
* `group leave` the engine refused, said with the CLI's next step: an invitation not joined yet answered "Group not
|
|
6273
|
+
* found" of a group `group show` lists (its way out is `group decline`), and an admin alone online "make someone the
|
|
6274
|
+
* admin", the app's words. The code stays the engine's.
|
|
6275
|
+
*/
|
|
6276
|
+
function leaveRefused(group, ref, error) {
|
|
6277
|
+
if (!(error instanceof Error)) return error;
|
|
6278
|
+
const shown = shellWord(ref, group.id);
|
|
6279
|
+
if (error.message === ADMIN_ALONE) return new CliError("engine", `You are the admin and nobody else in ${groupCalled(group)} is online to take over: try again when a member is, or make one the admin first (ghostly group admin ${shown} <member key>)`);
|
|
6280
|
+
const yet = error.message === "Group not found" ? notInYet(group, ref, true) : void 0;
|
|
6281
|
+
return yet ? new CliError("engine", yet) : error;
|
|
6282
|
+
}
|
|
6283
|
+
/**
|
|
6284
|
+
* `group join` the engine refused for a group held here under the link's id, in the app's words ("Delete it from this
|
|
6285
|
+
* device", its menu item), said with the CLI's command. The code stays the engine's. "Answer it first" comes only for
|
|
6286
|
+
* an invitation taken back (a live one is kept and the link goes on beside it), which `group accept` refuses: its way
|
|
6287
|
+
* out is `group decline`.
|
|
6288
|
+
*/
|
|
6289
|
+
/**
|
|
6290
|
+
* The link `group join` takes, read before a one-shot opens the profile (`refuseBeforeStart`): one that names no group,
|
|
6291
|
+
* a private one's or a community's, is refused as the engine's `joinByLink` refuses it with the same two decoders.
|
|
6292
|
+
*/
|
|
6293
|
+
function groupLinkShape(params) {
|
|
6294
|
+
const link = str(params, "link", true);
|
|
6295
|
+
if (!decodeCommunityLink(link) && !decodeGroupEntryLink(link)) throw new CliError("bad_request", "This is not a link to a group");
|
|
6296
|
+
}
|
|
6297
|
+
function joinRefused(link, error) {
|
|
6298
|
+
if (!(error instanceof Error)) return error;
|
|
6299
|
+
const id = (decodeCommunityLink(link) ?? decodeGroupEntryLink(link))?.g ?? "<group>";
|
|
6300
|
+
if (error.message === "You are out of this group and its history is still here. Delete it from this device to join with a link.") return new CliError("engine", `You are out of this group and its history is still here: ghostly group forget ${id} --yes deletes it from this device, then join with the link`);
|
|
6301
|
+
if (error.message === "You have an invitation to this group. Answer it first.") return new CliError("engine", `Its invitation to this group was taken back: ghostly group decline ${id} drops it, then join with the link`);
|
|
6302
|
+
return error;
|
|
6303
|
+
}
|
|
6304
|
+
/**
|
|
6305
|
+
* The chat a command about a chat's own connection names (`chat connect`, `disconnect`, `transport`, `wait`): a group's
|
|
6306
|
+
* name says a group has none of its own, as `chat show` names `group show`. It read "(ghostly chat list)", a list that
|
|
6307
|
+
* never has the group.
|
|
6308
|
+
*/
|
|
6309
|
+
function chatNotGroupLink(ctx, params) {
|
|
6310
|
+
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `it connects through its members' chats, with no transport of its own (ghostly group show ${shown})`);
|
|
6311
|
+
}
|
|
6001
6312
|
/**
|
|
6002
6313
|
* A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
|
|
6003
6314
|
* command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
|
|
@@ -6028,11 +6339,63 @@ function chatNotGroup(ctx, params, command, rest = "") {
|
|
|
6028
6339
|
/**
|
|
6029
6340
|
* An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), said as every
|
|
6030
6341
|
* message id is (`noMessage`); before, a mistyped or lost id read "Only your own text messages can be edited"
|
|
6031
|
-
* (`refused`, exit 1), as if the message were someone else's.
|
|
6342
|
+
* (`refused`, exit 1), as if the message were someone else's. Whether it is there is the engine's answer (`missing`)
|
|
6343
|
+
* once it looked for it: read again here, an id no message goes by read the chat's whole history a second time (0.7 s
|
|
6344
|
+
* at 100,000 messages). Only a refusal before it looked (a chat that cannot edit, a group I am not in) looks here.
|
|
6032
6345
|
*/
|
|
6033
|
-
function editRefused(
|
|
6034
|
-
if (refused
|
|
6035
|
-
|
|
6346
|
+
async function editRefused(ctx, linkId, ref, place, error, result) {
|
|
6347
|
+
if (!result.refused) return new CliError("unavailable", error);
|
|
6348
|
+
if (result.missing ?? !await messageOf(ctx, linkId, ref)) return noMessage(ref, place);
|
|
6349
|
+
return new CliError("refused", editRefusalWords(error, ref, place));
|
|
6350
|
+
}
|
|
6351
|
+
/**
|
|
6352
|
+
* The engine's refusal of an edit with what to run instead: it named none, so a bot that hit the edit cap had a sentence
|
|
6353
|
+
* and exit 1 to go on. Matched by the engine's exact words (`editMessage`, `GroupEdits.edit`); any other sentence, or
|
|
6354
|
+
* one these no longer match, stays the engine's.
|
|
6355
|
+
*/
|
|
6356
|
+
function editRefusalWords(error, ref, place) {
|
|
6357
|
+
const chat = shellWord(place.ref, place.group ? "<group>" : "<chat>"), id = shellWord(ref, "<message>");
|
|
6358
|
+
const send = `ghostly ${place.group ? "group send" : "send"} ${chat}`;
|
|
6359
|
+
if (error === "Only your own text messages can be edited") return `${error}: to answer this one, reply to it (${send} --reply ${id} <text>)`;
|
|
6360
|
+
const most = /^(This message was edited \d+ times, the most one takes)\.$/.exec(error);
|
|
6361
|
+
if (most) return `${most[1]}: send the new text as a new message (${send} <text>); ghostly message delete ${chat} ${id} --everyone takes the old one away`;
|
|
6362
|
+
if (error === "An edit cannot read as a join notice.") return "An edit cannot read as a join notice (\"👋 … joined\"): change its first words";
|
|
6363
|
+
return error;
|
|
6364
|
+
}
|
|
6365
|
+
/**
|
|
6366
|
+
* `message delete --everyone` given no message of mine. It said "No message … of yours" for all of them, as if one of
|
|
6367
|
+
* mine deleted already were the contact's: another's message says whose it is (in a chat, with the delete that takes
|
|
6368
|
+
* it off this device), one of mine deleted already says so (the chat's deleted ids), and any other is not here.
|
|
6369
|
+
*/
|
|
6370
|
+
function deleteNotMine(ctx, target, ref, theirs, place, purge) {
|
|
6371
|
+
if (theirs && target.group) return new CliError("not_found", `${JSON.stringify(ref)} is another member's message: only its author deletes a group's message, for everyone`);
|
|
6372
|
+
if (theirs) return new CliError("not_found", `${JSON.stringify(ref)} is the contact's message: only your own messages are deleted for everyone (ghostly message delete ${shellWord(place.ref, "<chat>")} ${shellWord(theirs.id, "<message>")}${purge ? " --purge" : ""} deletes it on this device)`);
|
|
6373
|
+
const deleted = !target.group && node(ctx).deletedIdsOf(target.linkId).includes(ref);
|
|
6374
|
+
return noMessage(ref, place, deleted ? { tail: ": it was deleted already" } : {});
|
|
6375
|
+
}
|
|
6376
|
+
/**
|
|
6377
|
+
* About the longest ASCII text, and edit, the DHT packet carries once sealed and signed: within the 256 bytes, the
|
|
6378
|
+
* envelope's authentication (and an edit's element) takes the rest. The edge moves by a byte or two with the chat (the
|
|
6379
|
+
* envelope's sequence, the edit's number), so the words say "about"; `dhtBudgetWords.test.ts` sends both sizes on two
|
|
6380
|
+
* paired daemons.
|
|
6381
|
+
*/
|
|
6382
|
+
var DHT_TEXT_FITS = 248;
|
|
6383
|
+
var DHT_EDIT_FITS = 214;
|
|
6384
|
+
/**
|
|
6385
|
+
* The engine's refusal of a text or an edit within 256 bytes that the DHT packet cannot carry (`DHT_PACKET_BUDGET`,
|
|
6386
|
+
* "Text and authentication exceed the DHT packet budget"), said as the apps and `dhtOnlyWait` say it: too long for the
|
|
6387
|
+
* DHT, about how much fits, and what ends it, by whose choice keeps the chat on the DHT only (this side's hold: when
|
|
6388
|
+
* it ends, and the command that ends it now). Any other error as is.
|
|
6389
|
+
*/
|
|
6390
|
+
function dhtTooLong(ctx, asked, error, kind, ref) {
|
|
6391
|
+
if (error !== "Text and authentication exceed the DHT packet budget. Shorten the message.") return error;
|
|
6392
|
+
const link = state(ctx).links.find((l) => l.id === asked.id) ?? asked;
|
|
6393
|
+
const mine = link.deliveryMode === "dht", theirs = link.dhtDelivery?.peerMode === "dht";
|
|
6394
|
+
const held = mine ? holdEnds(ctx, link.id) : null, chosen = mine && held === null;
|
|
6395
|
+
const fits = kind === "text" ? `a text fits about ${DHT_TEXT_FITS} bytes there` : `an edit fits about ${DHT_EDIT_FITS} bytes there`;
|
|
6396
|
+
const act = kind === "text" ? "send it" : "make the edit";
|
|
6397
|
+
const switchBack = `ghostly chat transport ${shellWord(ref, "<chat>")} auto`;
|
|
6398
|
+
return `Too long for the DHT (${fits} once sealed): ${chosen && theirs ? `you and the contact keep this chat on the DHT only: ${act} once both choose a live transport (${switchBack}), or shorten it` : chosen ? `this chat is on the DHT only: ${act} once you choose a live transport (${switchBack}), or shorten it` : theirs ? `the contact keeps this chat on the DHT only: ${act} once they choose a live transport, or shorten it` : held !== null ? `${heldWords(held, ref, act)}, or shorten it` : `shorten it, or ${act} once the chat is live`}`;
|
|
6036
6399
|
}
|
|
6037
6400
|
/**
|
|
6038
6401
|
* The engine's "That message is not in this chat" (", or takes no reaction", ", or cannot be pinned", ", or cannot be
|
|
@@ -6071,7 +6434,24 @@ async function connectWithin(ctx, link, ms) {
|
|
|
6071
6434
|
} finally {
|
|
6072
6435
|
clearTimeout(timer);
|
|
6073
6436
|
}
|
|
6074
|
-
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s:
|
|
6437
|
+
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: ${notLiveYet(ctx, link)}. ${connectNext(ctx, link)}`, { chat: link.id });
|
|
6438
|
+
}
|
|
6439
|
+
/**
|
|
6440
|
+
* How long after a daemon's start a chat with no attempt ended yet reads as still resuming: with many chats, the start
|
|
6441
|
+
* brings them back a few at a time, over minutes.
|
|
6442
|
+
*/
|
|
6443
|
+
var RESUMING_MS = 3e5;
|
|
6444
|
+
/**
|
|
6445
|
+
* Why a daemon's `chat connect` timed out, as the chat reads at the end. No attempt of this run ended yet
|
|
6446
|
+
* (`lastAttempt` null) while the daemon just started, or while the contact reads online: the chat is still coming
|
|
6447
|
+
* back, nobody failed to answer. It said "the contact did not answer" right after a `daemon restart`, with the
|
|
6448
|
+
* contact online. A one-shot always just started: it keeps the words it had.
|
|
6449
|
+
*/
|
|
6450
|
+
function notLiveYet(ctx, link) {
|
|
6451
|
+
const now = state(ctx).links.find((l) => l.id === link.id) ?? link;
|
|
6452
|
+
if (ctx.mode !== "daemon" || now.liveAttempt) return "the contact did not answer";
|
|
6453
|
+
if (process.uptime() * 1e3 < RESUMING_MS) return "the chat is still resuming after the daemon's start, and no attempt to reach the contact has ended yet";
|
|
6454
|
+
return now.peerOnline ? "your contact's app reads online, and no attempt to reach it has ended yet" : "the contact did not answer";
|
|
6075
6455
|
}
|
|
6076
6456
|
/** What happens after a `chat connect` the contact did not answer: the daemon dials again by itself, a one-shot does not. */
|
|
6077
6457
|
function connectNext(ctx, link) {
|
|
@@ -6203,6 +6583,22 @@ function quoteChecked(json, message, originals) {
|
|
|
6203
6583
|
}
|
|
6204
6584
|
};
|
|
6205
6585
|
}
|
|
6586
|
+
/**
|
|
6587
|
+
* Each method's check of its own words, the one its handler makes first: none needs the profile. A one-shot makes it
|
|
6588
|
+
* before the profile opens (main.ts `session`): a target that is no invoice, a token or mint URL that is none, or a word
|
|
6589
|
+
* that is no group link started every saved chat to be refused (with 10 chats, 20 relay requests and 0.4 s more).
|
|
6590
|
+
*/
|
|
6591
|
+
var SHAPES = {
|
|
6592
|
+
"pay": payShape,
|
|
6593
|
+
"wallet.redeem": tokenShape,
|
|
6594
|
+
"wallet.mint.add": mintUrlShape,
|
|
6595
|
+
"group.join": groupLinkShape,
|
|
6596
|
+
"service.add": serviceShape
|
|
6597
|
+
};
|
|
6598
|
+
/** Throws what `method` answers `params` whose shape it refuses, with no profile open; nothing for any other. */
|
|
6599
|
+
async function refuseBeforeStart(method, params) {
|
|
6600
|
+
if (Object.hasOwn(SHAPES, method)) await SHAPES[method](params);
|
|
6601
|
+
}
|
|
6206
6602
|
var API_METHODS = Object.keys(METHODS);
|
|
6207
6603
|
/**
|
|
6208
6604
|
* Runs one method of the API: one the table lists itself (`constructor`, which every object has, is none). `call`: who
|
|
@@ -6214,6 +6610,6 @@ async function callApi(ctx, method, params = {}, call) {
|
|
|
6214
6610
|
if (params === null || typeof params !== "object" || Array.isArray(params)) throw new CliError("bad_request", "params must be an object");
|
|
6215
6611
|
return run(ctx, await withStoredIds(ctx, params), call);
|
|
6216
6612
|
}
|
|
6217
|
-
export {
|
|
6613
|
+
export { groupJson as _, hideStateSecrets as a, resumeHolds as b, refuseBeforeStart as c, reportAppFrames as d, servedApps as f, chatMessageJson as g, chatJson as h, groupSendRefused as i, settingsInEffect as l, identityProvider as m, SETTABLE as n, mentionsFor as o, nodeLocalFetch as p, callApi as r, redactSettings as s, API_METHODS as t, paymentJson as u, groupMessageJson as v, flushCardUpdates as x, groupPayTwins as y };
|
|
6218
6614
|
|
|
6219
|
-
//# sourceMappingURL=api-
|
|
6615
|
+
//# sourceMappingURL=api-O57SNJcb.js.map
|