@ghostlytools/cli 1.11.1 → 1.11.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.
- package/README.md +32 -23
- package/dist/assets/{api-DL0Uazf6.js → api-DBlaoz8i.js} +478 -141
- package/dist/assets/api-DBlaoz8i.js.map +1 -0
- package/dist/assets/{api-D89ubgas.js → api-DgU4MZPD.js} +2 -2
- package/dist/assets/{apiKit-D78MXTrk.js → apiKit-DesObIDf.js} +19 -9
- package/dist/assets/apiKit-DesObIDf.js.map +1 -0
- package/dist/assets/appFetch-C8yZIq1e.js +194 -0
- package/dist/assets/appFetch-C8yZIq1e.js.map +1 -0
- package/dist/assets/{apps--pAqmfgQ.js → apps-DkMjDHML.js} +142 -67
- package/dist/assets/apps-DkMjDHML.js.map +1 -0
- package/dist/assets/{apps-BlSl1nGn.js → apps-rzxsjfBV.js} +1 -1
- package/dist/assets/{arkade-DxB-MR43.js → arkade-CarKONmH.js} +2 -2
- package/dist/assets/{arkade-DxB-MR43.js.map → arkade-CarKONmH.js.map} +1 -1
- package/dist/assets/{backup-B3JJd75o.js → backup-C0OJCJlM.js} +90 -47
- package/dist/assets/backup-C0OJCJlM.js.map +1 -0
- package/dist/assets/{backup-T7gFpU80.js → backup-CgWU7x0T.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/{bitcoind-CZchoh43.js → bitcoind-CdSmvy2y.js} +3 -3
- package/dist/assets/{bitcoind-CZchoh43.js.map → bitcoind-CdSmvy2y.js.map} +1 -1
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js → bitcoindProvider-BvoRh0D5.js} +2 -2
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js.map → bitcoindProvider-BvoRh0D5.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/buttons-Cco0Agfa.js +2 -0
- package/dist/assets/{buttons-C1VbDihe.js → buttons-fZTEa_2i.js} +47 -7
- package/dist/assets/buttons-fZTEa_2i.js.map +1 -0
- package/dist/assets/{childEnv-BVOQK9EA.js → childEnv-K_IzUqQx.js} +4 -3
- package/dist/assets/childEnv-K_IzUqQx.js.map +1 -0
- package/dist/assets/{client-CGLuWFRV.js → client-Ibk3-e60.js} +31 -3
- package/dist/assets/client-Ibk3-e60.js.map +1 -0
- package/dist/assets/{codec-YGJDr7uH.js → codec-DMpQqVSt.js} +2 -2
- package/dist/assets/{codec-YGJDr7uH.js.map → codec-DMpQqVSt.js.map} +1 -1
- package/dist/assets/endpoint-DarqblYE.js +5052 -0
- package/dist/assets/endpoint-DarqblYE.js.map +1 -0
- package/dist/assets/{envelope-Dwq8EN8x.js → envelope-CvQVCGdf.js} +2 -2
- package/dist/assets/{envelope-Dwq8EN8x.js.map → envelope-CvQVCGdf.js.map} +1 -1
- package/dist/assets/{fedimintSdk-CqTeMdF0.js → fedimintSdk-zV_5Qdqz.js} +6 -3
- package/dist/assets/fedimintSdk-zV_5Qdqz.js.map +1 -0
- package/dist/assets/{fixedHosts-CINXidpd.js → fixedHosts-6gKn8dp2.js} +3 -3
- package/dist/assets/{fixedHosts-CINXidpd.js.map → fixedHosts-6gKn8dp2.js.map} +1 -1
- package/dist/assets/{host-CGlHkiQv.js → host-CYlIiY3r.js} +455 -104
- package/dist/assets/host-CYlIiY3r.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js → hyperdhtRelay-CdsLcAhY.js} +2 -2
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js.map → hyperdhtRelay-CdsLcAhY.js.map} +1 -1
- package/dist/assets/{irohWeb-CYn0uB_A.js → irohWeb-D2IuloLL.js} +705 -43
- package/dist/assets/irohWeb-D2IuloLL.js.map +1 -0
- package/dist/assets/jsonOut-POtMBS_V.js +16 -0
- package/dist/assets/jsonOut-POtMBS_V.js.map +1 -0
- package/dist/assets/{main-CgLW_Gyx.js → main-C0PfjKTe.js} +263 -128
- package/dist/assets/main-C0PfjKTe.js.map +1 -0
- package/dist/assets/{mainline-B0h8RchD.js → mainline-Cu61qcPS.js} +60 -24
- package/dist/assets/mainline-Cu61qcPS.js.map +1 -0
- package/dist/assets/{networkReason-BBosp2KG.js → networkReason-Dt7Yx_n4.js} +3 -3
- package/dist/assets/{networkReason-BBosp2KG.js.map → networkReason-Dt7Yx_n4.js.map} +1 -1
- package/dist/assets/{nwc-SSNS1aJ-.js → nwc-CtZypDcv.js} +6 -5
- package/dist/assets/nwc-CtZypDcv.js.map +1 -0
- package/dist/assets/{nwcProvider-BXqJmM98.js → nwcProvider-DYHkd0iu.js} +6 -3
- package/dist/assets/{nwcProvider-BXqJmM98.js.map → nwcProvider-DYHkd0iu.js.map} +1 -1
- package/dist/assets/{ownDid--DtH_Jdi.js → ownDid-CJ0ta8CL.js} +3 -3
- package/dist/assets/{ownDid--DtH_Jdi.js.map → ownDid-CJ0ta8CL.js.map} +1 -1
- package/dist/assets/{ownStatus-CQPGjCUR.js → ownStatus-D4HC6tNR.js} +12 -6
- package/dist/assets/{ownStatus-CQPGjCUR.js.map → ownStatus-D4HC6tNR.js.map} +1 -1
- package/dist/assets/{profiles-4UQ1Hsds.js → profiles-Ccdq6Xf6.js} +82 -6
- package/dist/assets/profiles-Ccdq6Xf6.js.map +1 -0
- package/dist/assets/{registry-B6BXKv6Q.js → registry-CE0PpQAE.js} +1 -1
- package/dist/assets/{registry-BKCFTEYp.js → registry-LvxsLJ5S.js} +88 -25
- package/dist/assets/registry-LvxsLJ5S.js.map +1 -0
- package/dist/assets/{resolve-MFeFljsN.js → resolve-6kVu2DE5.js} +4 -3
- package/dist/assets/resolve-6kVu2DE5.js.map +1 -0
- package/dist/assets/{server-rHKhnog1.js → server-Q3VcNqGt.js} +630 -933
- package/dist/assets/server-Q3VcNqGt.js.map +1 -0
- package/dist/assets/{src-BzsyAvPf.js → src-DjVj2ynY.js} +580 -168
- package/dist/assets/src-DjVj2ynY.js.map +1 -0
- package/dist/assets/{sshForges-qITn-RoV.js → sshForges-DeZ9cN9Q.js} +4 -3
- package/dist/assets/sshForges-DeZ9cN9Q.js.map +1 -0
- package/dist/assets/{translate-Bkr_iDgp.js → translate-iQZq4TnY.js} +36 -15
- package/dist/assets/translate-iQZq4TnY.js.map +1 -0
- package/dist/assets/{types-C4_KafL_.js → types-Clyb52K2.js} +2 -1
- package/dist/assets/types-Clyb52K2.js.map +1 -0
- package/dist/assets/{usdt-Bp7T2iqt.js → usdt-DnyTGdTX.js} +3 -3
- package/dist/assets/{usdt-Bp7T2iqt.js.map → usdt-DnyTGdTX.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +3592 -0
- package/package.json +5 -3
- package/dist/assets/api-DL0Uazf6.js.map +0 -1
- package/dist/assets/apiKit-D78MXTrk.js.map +0 -1
- package/dist/assets/apps--pAqmfgQ.js.map +0 -1
- package/dist/assets/backup-B3JJd75o.js.map +0 -1
- package/dist/assets/buttons-C1VbDihe.js.map +0 -1
- package/dist/assets/buttons-DwWuK_uN.js +0 -2
- package/dist/assets/childEnv-BVOQK9EA.js.map +0 -1
- package/dist/assets/client-CGLuWFRV.js.map +0 -1
- package/dist/assets/endpoint-DWHkXWVM.js +0 -419
- package/dist/assets/endpoint-DWHkXWVM.js.map +0 -1
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +0 -1
- package/dist/assets/host-CGlHkiQv.js.map +0 -1
- package/dist/assets/irohWeb-CYn0uB_A.js.map +0 -1
- package/dist/assets/main-CgLW_Gyx.js.map +0 -1
- package/dist/assets/mainline-B0h8RchD.js.map +0 -1
- package/dist/assets/nwc-SSNS1aJ-.js.map +0 -1
- package/dist/assets/profiles-4UQ1Hsds.js.map +0 -1
- package/dist/assets/registry-BKCFTEYp.js.map +0 -1
- package/dist/assets/resolve-MFeFljsN.js.map +0 -1
- package/dist/assets/server-rHKhnog1.js.map +0 -1
- package/dist/assets/src-BzsyAvPf.js.map +0 -1
- package/dist/assets/sshForges-qITn-RoV.js.map +0 -1
- package/dist/assets/translate-Bkr_iDgp.js.map +0 -1
- package/dist/assets/types-C4_KafL_.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./src-
|
|
1
|
+
import "./src-DjVj2ynY.js";
|
|
2
2
|
import { t as CliError } from "./errors-Dt-ZnyOX.js";
|
|
3
|
-
import {
|
|
4
|
-
import { t as childEnv } from "./childEnv-
|
|
3
|
+
import { i as cleanName, k as shownName } from "./apiKit-DesObIDf.js";
|
|
4
|
+
import { t as childEnv } from "./childEnv-K_IzUqQx.js";
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
|
-
import { chmodSync, closeSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
6
|
+
import { chmodSync, closeSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
7
7
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -212,6 +212,77 @@ function startingDaemon(paths) {
|
|
|
212
212
|
return Number.isInteger(pid) && pid > 0 && pid === lockOwner(paths) ? pid : null;
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
|
+
* The file in which `daemon restart` or `daemon --detach` keeps the profile for the daemon it starts (`claimForDaemon`):
|
|
216
|
+
* its pid, the file touched every CLAIM_TOUCH_MS while it waits.
|
|
217
|
+
*/
|
|
218
|
+
function claimPath(dir) {
|
|
219
|
+
return join(dir, "daemon.claim");
|
|
220
|
+
}
|
|
221
|
+
var CLAIM_TOUCH_MS = 1e3;
|
|
222
|
+
/** A claim not touched for that long is a start that ended without removing it (killed): none. */
|
|
223
|
+
var CLAIM_FRESH_MS = 1e4;
|
|
224
|
+
/**
|
|
225
|
+
* The pid of the `daemon restart` or `daemon --detach` that keeps the profile for the daemon it starts, from the stop
|
|
226
|
+
* of the old one until the new one holds the profile: the lock is free in between, and one-shot commands that kept
|
|
227
|
+
* taking it in turn (a bot's typing indicator every few seconds) left the new daemon, seconds to boot, never finding
|
|
228
|
+
* it free. Null when no live start claims it.
|
|
229
|
+
*/
|
|
230
|
+
function daemonClaim(paths) {
|
|
231
|
+
const file = claimPath(paths.dir);
|
|
232
|
+
let pid;
|
|
233
|
+
try {
|
|
234
|
+
if (Date.now() - statSync(file).mtimeMs > CLAIM_FRESH_MS) return null;
|
|
235
|
+
pid = Number(readFileSync(file, "utf8").trim());
|
|
236
|
+
} catch {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
240
|
+
try {
|
|
241
|
+
process.kill(pid, 0);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error.code !== "EPERM") return null;
|
|
244
|
+
}
|
|
245
|
+
return pid;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Keeps the profile for the daemon this process starts (`daemonClaim`): until the function it returns is called, only
|
|
249
|
+
* this process and its children take the profile's lock; any other command waits for the daemon's socket instead.
|
|
250
|
+
* Another live start's claim stands (its daemon is the one that comes up); a claim that cannot be written is none.
|
|
251
|
+
*/
|
|
252
|
+
function claimForDaemon(paths) {
|
|
253
|
+
if (daemonClaim(paths) !== null) return () => {};
|
|
254
|
+
const mine = String(process.pid), file = claimPath(paths.dir), draft = `${file}.${mine}`;
|
|
255
|
+
try {
|
|
256
|
+
writeFileSync(draft, mine, { mode: 384 });
|
|
257
|
+
renameSync(draft, file);
|
|
258
|
+
} catch {
|
|
259
|
+
rmSync(draft, { force: true });
|
|
260
|
+
return () => {};
|
|
261
|
+
}
|
|
262
|
+
const ours = () => {
|
|
263
|
+
try {
|
|
264
|
+
return readFileSync(file, "utf8").trim() === mine;
|
|
265
|
+
} catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const touch = setInterval(() => {
|
|
270
|
+
if (!ours()) return;
|
|
271
|
+
const now = /* @__PURE__ */ new Date();
|
|
272
|
+
try {
|
|
273
|
+
utimesSync(file, now, now);
|
|
274
|
+
} catch {}
|
|
275
|
+
}, CLAIM_TOUCH_MS);
|
|
276
|
+
touch.unref();
|
|
277
|
+
let released = false;
|
|
278
|
+
return () => {
|
|
279
|
+
if (released) return;
|
|
280
|
+
released = true;
|
|
281
|
+
clearInterval(touch);
|
|
282
|
+
if (ours()) rmSync(file, { force: true });
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
215
286
|
* The daemon's socket: in the profile's folder, unless that path is longer than a Unix socket may be (104 bytes on
|
|
216
287
|
* macOS); then in a folder of the user's runtime folder named after the profile's (`runtimePath`), which the daemon
|
|
217
288
|
* makes owner-only and checks before use (`privateFolder`), and whose socket a client connects to only when it is this
|
|
@@ -272,8 +343,13 @@ function selectProfile(home, name) {
|
|
|
272
343
|
* reboot) whose pid now belongs to another process is then stale too: it held the profile for good, every command busy
|
|
273
344
|
* until someone found the file. It is written before the lock is placed, so a lock of this release never lacks it for
|
|
274
345
|
* a moment; one without it (an older release's) is held while its pid is alive, as before.
|
|
346
|
+
*
|
|
347
|
+
* While a `daemon restart` or `daemon --detach` keeps the profile for the daemon it starts (`daemonClaim`), it is busy
|
|
348
|
+
* for every other process: a one-shot then waits for that daemon's socket (`openOneShot`).
|
|
275
349
|
*/
|
|
276
350
|
function acquireLock(paths) {
|
|
351
|
+
const claim = daemonClaim(paths);
|
|
352
|
+
if (claim !== null && claim !== process.pid && claim !== process.ppid) throw new CliError("busy", `Profile ${paths.name} is kept for the daemon that process ${claim} starts`, { pid: claim });
|
|
277
353
|
const mine = String(process.pid);
|
|
278
354
|
const draft = `${paths.lock}.${mine}`;
|
|
279
355
|
const start = startPath(paths.lock, process.pid);
|
|
@@ -447,6 +523,6 @@ function holder(file, lock) {
|
|
|
447
523
|
return recorded && now !== null && now !== recorded ? null : pid;
|
|
448
524
|
}
|
|
449
525
|
//#endregion
|
|
450
|
-
export {
|
|
526
|
+
export { ownProfile as C, runtimePath as E, ownFolder as S, privateFolder as T, profilePaths as _, checkShownName as a, startingPath as b, createProfile as c, ghostlyHome as d, listProfiles as f, profileExists as g, noProfile as h, checkProfileName as i, currentProfile as l, lockPath as m, RESTORED_MARK as n, checkShownNameOption as o, lockOwner as p, acquireLock as r, claimForDaemon as s, DEFAULT_PROFILE as t, daemonClaim as u, selectProfile as v, ownSocket as w, userPath as x, startingDaemon as y };
|
|
451
527
|
|
|
452
|
-
//# sourceMappingURL=profiles-
|
|
528
|
+
//# sourceMappingURL=profiles-Ccdq6Xf6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles-Ccdq6Xf6.js","names":[],"sources":["../../src/privateFolder.ts","../../src/profiles.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { chmodSync, lstatSync, mkdirSync, readdirSync, statSync, type Stats } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, isAbsolute, join } from \"node:path\";\nimport { CliError } from \"./errors\";\n\n/**\n * Where a socket goes when its path in the profile is longer than a Unix socket may be: `<base>/<prefix>-<hash of the\n * profile>/<leaf>`, in `$XDG_RUNTIME_DIR` or else the temp folder (macOS gives each user one) when that folder is the\n * user's alone, so no other user can make the folder first. When neither is, or the path would still be too long:\n * `/tmp/<prefix>-<uid>-<hash>/<leaf>`. Either way `privateFolder` checks the folder before use.\n */\nexport function runtimePath(prefix: string, profileDir: string, leaf: string): string {\n const hash = createHash(\"sha256\").update(profileDir).digest(\"hex\").slice(0, 24);\n for (const base of [process.env.XDG_RUNTIME_DIR, tmpdir()]) {\n if (!base || !isAbsolute(base) || !usersAlone(base)) continue;\n const path = join(base, `${prefix}-${hash}`, leaf);\n if (Buffer.byteLength(path) <= 100) return path;\n }\n return join(\"/tmp\", `${prefix}-${process.getuid?.() ?? 0}-${hash}`, leaf);\n}\n\nfunction usersAlone(path: string): boolean {\n try {\n const info = statSync(path);\n return info.isDirectory() && (!process.getuid || info.uid === process.getuid()) && (info.mode & 0o077) === 0;\n } catch {\n return false;\n }\n}\n\n/**\n * A folder for a socket outside the profile (when the profile's path is too long for one): made owner-only, and\n * refused when it is a link, someone else made it, or anyone else may enter it.\n */\nexport function privateFolder(path: string, what: string): void {\n mkdirSync(path, { recursive: true, mode: 0o700 });\n const info = lstatSync(path);\n if (!info.isDirectory() || (process.getuid && info.uid !== process.getuid()) || (info.mode & 0o077) !== 0) {\n throw new Error(`${path} is not a folder of this user's alone: ${what}`);\n }\n}\n\n/**\n * The profile's own folder, made owner-only again before the daemon's socket goes in it: a folder made by an older\n * release, or opened up by hand, is closed rather than trusted. Refused when it is a link or someone else's.\n */\nexport function ownFolder(path: string, what: string): void {\n const info = lstatSync(path);\n if (!info.isDirectory() || (process.getuid && info.uid !== process.getuid())) throw new Error(`${path} is not a folder of this user's: ${what}`);\n if ((info.mode & 0o077) !== 0) chmodSync(path, 0o700);\n}\n\n/**\n * A profile's folders and files, checked before a command (a one-shot as much as the daemon) takes its lock or opens\n * its store, which append to the files in place and follow a link: the home and its `profiles/` must be this user's\n * (a link to a folder of this user's is one); the home is closed to others' writes, `profiles/` to 0700. The profile's\n * folder and its `db/` must be this user's and not links, and are closed to 0700; what is in them must be this user's\n * and not a link, and a file is closed to 0600. A home, profile or journal opened up by hand, or made by another\n * account in a folder it could write, was used as it was: the events journal (message texts) stayed readable by others.\n */\nexport function ownProfile(dir: string): void {\n if (process.platform === \"win32\") return;\n const what = \"ghostly will not open the profile there\";\n const profiles = dirname(dir), home = dirname(profiles);\n const mine = (info: Stats) => !process.getuid || info.uid === process.getuid();\n for (const folder of [home, profiles]) {\n const info = statSync(folder);\n if (!info.isDirectory() || !mine(info)) throw new CliError(\"refused\", `${folder} is not a folder of this user's: ${what}`);\n const open = folder === home ? 0o022 : 0o077;\n if ((info.mode & open) !== 0) chmodSync(folder, info.mode & 0o777 & ~open);\n }\n const db = join(dir, \"db\");\n for (const folder of [dir, db]) {\n let info;\n try { info = lstatSync(folder); } catch (error) { if (folder === db && (error as NodeJS.ErrnoException).code === \"ENOENT\") continue; throw error; }\n if (!info.isDirectory() || !mine(info)) throw new CliError(\"refused\", `${folder} is not a folder of this user's: ${what}`);\n if ((info.mode & 0o077) !== 0) chmodSync(folder, 0o700);\n for (const name of readdirSync(folder)) {\n // Another command at once on the profile removes its lock's draft, start and stale files as it goes: one gone\n // since the listing is passed over, not the command's error.\n const path = join(folder, name), entry = lstatSync(path, { throwIfNoEntry: false });\n if (!entry) continue;\n if (entry.isSymbolicLink() || !mine(entry)) throw new CliError(\"refused\", `${path} is a link or another user's: ${what}`);\n if (entry.isFile() && (entry.mode & 0o077) !== 0) {\n try { chmodSync(path, 0o600); } catch (error) { if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error; }\n }\n }\n }\n}\n\n/** False when `path` is there but is not a socket of this user's: nothing to connect to. */\nexport function ownSocket(path: string): boolean {\n if (process.platform === \"win32\") return true;\n let info;\n try { info = lstatSync(path); } catch { return true; }\n return info.isSocket() && (!process.getuid || info.uid === process.getuid());\n}\n","import { execFileSync } from \"node:child_process\";\nimport { closeSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, writeFileSync, writeSync, type Stats } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\nimport { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { MAX_NICK_LENGTH } from \"@ghostly/core\";\nimport { cleanName, shownName } from \"./apiKit\";\nimport { childEnv } from \"./childEnv\";\nimport { CliError } from \"./errors\";\nimport { runtimePath } from \"./privateFolder\";\n\n/**\n * Profiles on disk (WISP 1100 § Profiles and files): `<home>/profiles/<name>/`, 0700, one engine store each.\n * `<home>/current` names the profile commands use when none is given.\n */\nexport const DEFAULT_PROFILE = \"default\";\nconst NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/i;\n\n/**\n * An empty `--home` or `--profile` (an unset variable in a script) is a usage error: taken as not given, it ran the\n * command in the current folder, or as the current profile. An empty variable of the environment counts as unset.\n */\nexport function ghostlyHome(option?: string): string {\n if (option === \"\") throw new CliError(\"usage\", \"--home needs a folder\");\n return userPath(option ?? (process.env.GHOSTLY_HOME || join(homedir(), \".ghostly\")), true);\n}\n\n/**\n * A path the CLI was given, made absolute. A `~` the shell left alone (`--home=~/bots`, a quoted variable, a unit\n * file's `Environment=` line) is the user's home, as the shell reads it: it was a folder named `~` in the current one.\n * `~user/…` is a usage error, not a guess at another user's home, unless it is there under this folder. Any other name\n * that starts with `~` is a file here, as the shell and every other tool read it (`~notes.txt`, Office's\n * `~$report.docx`, a new `~cursor`): all of them were refused (agents#1604). `home`: the profiles' folder, where a bare\n * `~bob` that is not there is refused too, as a new profile would be made in a folder of that name.\n */\nexport function userPath(path: string, home = false): string {\n if (path === \"~\" || path.startsWith(\"~/\")) return join(homedir(), path.slice(1));\n if (path.startsWith(\"~\") && (home || path.includes(\"/\")) && !existsSync(resolve(path))) {\n throw new CliError(\"usage\", `${path}: ~user is not read here: write the ${home || path.endsWith(\"/\") ? \"folder\" : \"path\"} in full`);\n }\n return resolve(path);\n}\n\nexport function checkProfileName(name: string): string {\n if (!NAME.test(name) || name.includes(\"..\")) throw new CliError(\"usage\", `Not a profile name: ${JSON.stringify(name)} (letters, digits, \".\", \"_\" and \"-\", up to 64)`);\n return name;\n}\n\n/**\n * The name a profile shows its contacts, whichever command sets it (`--name`, `profile.set`, `settings set nick`):\n * cleaned as a group's name is (`shownName`: a tab or a line break is a space, invisible characters go), then up to 64\n * characters as stored; empty (or spaces) is no name. `settings set nick` took any length and every one took a line\n * break, printed whole by `status`; a name with nothing that shows was kept as given, and contacts saw no name. `field`\n * names it in the refusal.\n */\nexport function checkShownName(name: unknown, field = \"name\"): string {\n if (typeof name !== \"string\") throw new CliError(\"bad_request\", `${field} must be up to ${MAX_NICK_LENGTH} characters on one line`);\n if (!name.trim()) return \"\";\n return shownName(name, MAX_NICK_LENGTH, field, \" (an empty one is no name)\");\n}\n\n/**\n * `--name` of `profile create` and `profile set`, checked before the profile opens: `checkShownName`'s rule, counted as\n * it counts (code points once cleaned, so a line break is a space and e + a combining accent is one), refused as a\n * usage error (exit 2) that names the option, as `app init --title` is. It was the engine's `bad_request` (exit 1),\n * \"name must be up to 64 characters on one line\", which named neither the option nor the length given.\n */\nexport function checkShownNameOption(name: string): string {\n const shown = cleanName(name, Infinity) ?? \"\";\n const length = [...shown].length;\n if (length > MAX_NICK_LENGTH) throw new CliError(\"usage\", `--name is up to ${MAX_NICK_LENGTH} characters, not ${length} characters`);\n if (name.trim() && !shown) throw new CliError(\"usage\", \"--name needs a character that shows (an empty one is no name)\");\n return checkShownName(name);\n}\n\nexport function currentProfile(home: string, option?: string): string {\n if (option === \"\") throw new CliError(\"usage\", \"--profile needs a profile name\");\n if (option !== undefined) return checkProfileName(option);\n if (process.env.GHOSTLY_PROFILE) return checkProfileName(process.env.GHOSTLY_PROFILE);\n const file = join(home, \"current\");\n if (existsSync(file)) {\n const name = readFileSync(file, \"utf8\").trim();\n if (name) return checkProfileName(name);\n }\n return DEFAULT_PROFILE;\n}\n\nexport function profileDir(home: string, name: string): string {\n return join(home, \"profiles\", checkProfileName(name));\n}\n\nexport interface ProfilePaths { name: string; dir: string; db: string; socket: string; lock: string; events: string; files: string; log: string }\nexport function profilePaths(home: string, name: string): ProfilePaths {\n const dir = profileDir(home, name);\n return {\n name, dir, db: join(dir, \"db\"), socket: socketPath(dir), lock: lockPath(dir),\n events: join(dir, \"events.jsonl\"), files: join(dir, \"files\"), log: join(dir, \"daemon.log\"),\n };\n}\n\n/** The file that says which process holds the profile (`acquireLock`). */\nexport function lockPath(dir: string): string {\n return join(dir, \"daemon.lock\");\n}\n\n/** The file in which a daemon says it is starting: its pid, from the lock it took until its socket listens. */\nexport function startingPath(dir: string): string {\n return join(dir, \"daemon.starting\");\n}\n\n/**\n * The pid of the profile's daemon while it starts (its engine, before its socket listens): the lock's holder, when it\n * marked its start. Null otherwise: nobody holds the profile, a one-shot command does, or the mark is a dead daemon's.\n */\nexport function startingDaemon(paths: ProfilePaths): number | null {\n let pid: number;\n try { pid = Number(readFileSync(startingPath(paths.dir), \"utf8\").trim()); } catch { return null; }\n // Alive, and this profile's: the lock's holder is.\n return Number.isInteger(pid) && pid > 0 && pid === lockOwner(paths) ? pid : null;\n}\n\n/**\n * The file in which `daemon restart` or `daemon --detach` keeps the profile for the daemon it starts (`claimForDaemon`):\n * its pid, the file touched every CLAIM_TOUCH_MS while it waits.\n */\nexport function claimPath(dir: string): string {\n return join(dir, \"daemon.claim\");\n}\n\nconst CLAIM_TOUCH_MS = 1_000;\n/** A claim not touched for that long is a start that ended without removing it (killed): none. */\nconst CLAIM_FRESH_MS = 10_000;\n\n/**\n * The pid of the `daemon restart` or `daemon --detach` that keeps the profile for the daemon it starts, from the stop\n * of the old one until the new one holds the profile: the lock is free in between, and one-shot commands that kept\n * taking it in turn (a bot's typing indicator every few seconds) left the new daemon, seconds to boot, never finding\n * it free. Null when no live start claims it.\n */\nexport function daemonClaim(paths: ProfilePaths): number | null {\n const file = claimPath(paths.dir);\n let pid: number;\n try {\n if (Date.now() - statSync(file).mtimeMs > CLAIM_FRESH_MS) return null;\n pid = Number(readFileSync(file, \"utf8\").trim());\n } catch { return null; }\n if (!Number.isInteger(pid) || pid <= 0) return null;\n try { process.kill(pid, 0); } catch (error) { if ((error as NodeJS.ErrnoException).code !== \"EPERM\") return null; }\n return pid;\n}\n\n/**\n * Keeps the profile for the daemon this process starts (`daemonClaim`): until the function it returns is called, only\n * this process and its children take the profile's lock; any other command waits for the daemon's socket instead.\n * Another live start's claim stands (its daemon is the one that comes up); a claim that cannot be written is none.\n */\nexport function claimForDaemon(paths: ProfilePaths): () => void {\n if (daemonClaim(paths) !== null) return () => {};\n const mine = String(process.pid), file = claimPath(paths.dir), draft = `${file}.${mine}`;\n try {\n writeFileSync(draft, mine, { mode: 0o600 });\n renameSync(draft, file);\n } catch {\n rmSync(draft, { force: true });\n return () => {};\n }\n const ours = () => { try { return readFileSync(file, \"utf8\").trim() === mine; } catch { return false; } };\n const touch = setInterval(() => {\n if (!ours()) return;\n const now = new Date();\n try { utimesSync(file, now, now); } catch { /* removed meanwhile */ }\n }, CLAIM_TOUCH_MS);\n touch.unref();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n clearInterval(touch);\n if (ours()) rmSync(file, { force: true });\n };\n}\n\n/**\n * The daemon's socket: in the profile's folder, unless that path is longer than a Unix socket may be (104 bytes on\n * macOS); then in a folder of the user's runtime folder named after the profile's (`runtimePath`), which the daemon\n * makes owner-only and checks before use (`privateFolder`), and whose socket a client connects to only when it is this\n * user's (`ownSocket`).\n */\nfunction socketPath(dir: string): string {\n const inside = join(dir, \"daemon.sock\");\n if (process.platform === \"win32\") return `\\\\\\\\.\\\\pipe\\\\ghostly-${createHash(\"sha256\").update(dir).digest(\"hex\").slice(0, 24)}`;\n if (Buffer.byteLength(inside) <= 100) return inside;\n return runtimePath(\"ghostly\", dir, \"daemon.sock\");\n}\n\nfunction ensureFolder(path: string): void {\n mkdirSync(path, { recursive: true, mode: 0o700 });\n}\n\n/** Makes the profile's folder; refused when it exists and `existing` is not allowed. */\nexport function createProfile(home: string, name: string, { existing = false } = {}): ProfilePaths {\n const paths = profilePaths(home, name);\n if (existsSync(paths.dir) && !existing) throw new CliError(\"refused\", `Profile ${name} exists`);\n ensureFolder(join(home, \"profiles\"));\n ensureFolder(paths.dir);\n return paths;\n}\n\n/**\n * A file in the folder of a profile a restore made, until its engine starts for the first time: the store came back\n * whole, as the backup held it, and the money in it is then treated as every restore treats it (WISP 05 § Restoring).\n */\nexport const RESTORED_MARK = \"restored\";\n\nexport function profileExists(home: string, name: string): boolean {\n return existsSync(profileDir(home, name));\n}\n\nexport function listProfiles(home: string): string[] {\n const root = join(home, \"profiles\");\n if (!existsSync(root)) return [];\n return readdirSync(root).filter((name) => NAME.test(name) && statSync(join(root, name)).isDirectory()).sort();\n}\n\n/** A profile this home lacks, as `profile use` and `--profile` both say it: quoted, with how to list or make one. */\nexport const noProfile = (name: string): CliError =>\n new CliError(\"not_found\", `No profile ${JSON.stringify(name)} (ghostly profile list, or ghostly profile create ${name})`);\n\nexport function selectProfile(home: string, name: string): void {\n if (!profileExists(home, name)) throw noProfile(name);\n ensureFolder(home);\n writeFileSync(join(home, \"current\"), name + \"\\n\", { mode: 0o600 });\n}\n\n/**\n * One process per profile: the daemon or a one-shot command. The lock holds the owner's pid; a lock whose\n * process is gone is taken over.\n *\n * The lock is a link to a file that already holds the pid, so it never exists empty (agents#1642): one made by\n * `openSync` + `writeSync` was empty for a moment, and another process read that as nobody's and removed it under its\n * owner. An empty lock younger than `EMPTY_LOCK_GRACE_MS` is still an older release's being written: busy. A stale\n * lock is moved aside before it is removed, and only when what was moved is the file judged stale: one that vanished,\n * or that another process made since, is no longer removed.\n *\n * The lock stays the bare pid, as older releases read it; beside it, `<lock>.<pid>.start` holds when that process\n * started (`processStart`). A lock left by a process that died without releasing it (kill -9, Ctrl-C of a one-shot, a\n * reboot) whose pid now belongs to another process is then stale too: it held the profile for good, every command busy\n * until someone found the file. It is written before the lock is placed, so a lock of this release never lacks it for\n * a moment; one without it (an older release's) is held while its pid is alive, as before.\n *\n * While a `daemon restart` or `daemon --detach` keeps the profile for the daemon it starts (`daemonClaim`), it is busy\n * for every other process: a one-shot then waits for that daemon's socket (`openOneShot`).\n */\nexport function acquireLock(paths: ProfilePaths): () => void {\n // Kept for the daemon a start brings up (`daemonClaim`): its own process and the daemon it spawns take it, no other.\n const claim = daemonClaim(paths);\n if (claim !== null && claim !== process.pid && claim !== process.ppid) throw new CliError(\"busy\", `Profile ${paths.name} is kept for the daemon that process ${claim} starts`, { pid: claim });\n const mine = String(process.pid);\n const draft = `${paths.lock}.${mine}`;\n const start = startPath(paths.lock, process.pid);\n const started = processStart(process.pid);\n let placed = false;\n writeFileSync(draft, mine, { mode: 0o600 });\n if (started !== null) writeFileSync(start, started, { mode: 0o600 });\n try {\n for (let attempt = 0; attempt < 3; attempt++) {\n if (placeLock(draft, paths.lock, mine)) {\n placed = true;\n heldHere.add(paths.lock);\n let released = false;\n return () => {\n if (released) return;\n released = true;\n heldHere.delete(paths.lock);\n try { if (readFileSync(paths.lock, \"utf8\").trim() === mine) rmSync(paths.lock, { force: true }); } catch { /* gone already */ }\n rmSync(start, { force: true });\n };\n }\n let seen: Stats;\n try { seen = lstatSync(paths.lock); } catch { continue; }\n const owner = lockOwner(paths);\n if (owner !== null) throw new CliError(\"busy\", `Profile ${paths.name} is in use by process ${owner}`, { pid: owner });\n if (seen.size === 0 && Date.now() - seen.mtimeMs < EMPTY_LOCK_GRACE_MS) break;\n removeStaleLock(paths.lock, seen);\n }\n } finally {\n rmSync(draft, { force: true });\n if (!placed) rmSync(start, { force: true });\n }\n throw new CliError(\"busy\", `Profile ${paths.name} is in use`);\n}\n\n/** The locks this process holds: a lock naming this pid that is not one of them is a dead holder's whose pid it has now. */\nconst heldHere = new Set<string>();\n\nfunction startPath(lock: string, pid: number): string {\n return `${lock}.${pid}.start`;\n}\n\n/**\n * When the process `pid` started, as a text that is the same for as long as it runs and another for the next process\n * given that pid; null where it cannot be read (Windows, a `/proc` that hides others' processes, no `ps`). On Linux the\n * boot's id and `/proc/<pid>/stat`'s start time (clock ticks since boot); elsewhere `ps -o lstart=`.\n */\nexport function processStart(pid: number): string | null {\n try {\n if (process.platform === \"linux\") {\n const stat = readFileSync(`/proc/${pid}/stat`, \"utf8\");\n // Fields after the command, which may hold spaces and parentheses: the start time is field 22.\n const ticks = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \")[19];\n if (!ticks || !/^\\d+$/.test(ticks)) return null;\n return `${readFileSync(\"/proc/sys/kernel/random/boot_id\", \"utf8\").trim()} ${ticks}`;\n }\n if (process.platform === \"win32\") return null;\n const lstart = execFileSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(pid)], {\n encoding: \"utf8\", stdio: [\"ignore\", \"pipe\", \"ignore\"], timeout: 2_000, env: { ...childEnv(), LC_ALL: \"C\" },\n }).trim();\n return lstart || null;\n } catch {\n return null;\n }\n}\n\n/** How long an empty lock is taken for one an older release is still writing its pid into. */\nconst EMPTY_LOCK_GRACE_MS = 1_000;\n\n/**\n * Links `draft` (which holds `mine`) as the lock; false when there is a lock already. Where the file system has no\n * hard links, the lock is made in place, as before.\n */\nfunction placeLock(draft: string, lock: string, mine: string): boolean {\n try {\n linkSync(draft, lock);\n return true;\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"EEXIST\") return false;\n if (![\"EPERM\", \"ENOTSUP\", \"EOPNOTSUPP\", \"ENOSYS\"].includes(code ?? \"\")) throw error;\n }\n let fd: number;\n try { fd = openSync(lock, \"wx\", 0o600); } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n throw error;\n }\n writeSync(fd, mine);\n closeSync(fd);\n return true;\n}\n\n/**\n * Removes the lock judged stale (`seen`): it is moved aside first, and removed only when what was moved is that same\n * file and holds no live pid (a freed inode is soon reused). A lock another process made in the meantime is put back.\n */\nfunction removeStaleLock(lock: string, seen: Stats): void {\n const aside = `${lock}.stale.${process.pid}`;\n try { renameSync(lock, aside); } catch { return; }\n try {\n const moved = lstatSync(aside);\n if (moved.ino === seen.ino && moved.dev === seen.dev && holder(aside, lock) === null && moved.size === seen.size) {\n const pid = lockPid(aside);\n if (pid !== null && pid !== process.pid) rmSync(startPath(lock, pid), { force: true });\n return;\n }\n try { linkSync(aside, lock); } catch { /* another lock is there already */ }\n } finally {\n rmSync(aside, { force: true });\n }\n}\n\n/**\n * The pid holding the profile, or null when nobody does: the lock's process is gone, or its pid is another process's\n * now (it started at another time than the lock's holder, or it is this process, which does not hold the lock).\n */\nexport function lockOwner(paths: ProfilePaths): number | null {\n return holder(paths.lock, paths.lock);\n}\n\nfunction lockPid(file: string): number | null {\n let pid: number;\n try { pid = Number(readFileSync(file, \"utf8\").trim()); } catch { return null; }\n return Number.isInteger(pid) && pid > 0 ? pid : null;\n}\n\n/** `file`: the lock, or the stale one moved aside; `lock`: the lock's own path, beside which its start is. */\nfunction holder(file: string, lock: string): number | null {\n const pid = lockPid(file);\n if (pid === null) return null;\n if (pid === process.pid) return heldHere.has(lock) ? pid : null;\n try { process.kill(pid, 0); } catch (error) { if ((error as NodeJS.ErrnoException).code !== \"EPERM\") return null; }\n let recorded: string;\n try { recorded = readFileSync(startPath(lock, pid), \"utf8\").trim(); } catch { return pid; }\n const now = processStart(pid);\n return recorded && now !== null && now !== recorded ? null : pid;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,SAAgB,YAAY,QAAgB,YAAoB,MAAsB;CACpF,MAAM,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE;CAC9E,KAAK,MAAM,QAAQ,CAAC,QAAQ,IAAI,iBAAiB,OAAO,CAAC,GAAG;EAC1D,IAAI,CAAC,QAAQ,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG;EACrD,MAAM,OAAO,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ,IAAI;EACjD,IAAI,OAAO,WAAW,IAAI,KAAK,KAAK,OAAO;CAC7C;CACA,OAAO,KAAK,QAAQ,GAAG,OAAO,GAAG,QAAQ,SAAS,KAAK,EAAE,GAAG,QAAQ,IAAI;AAC1E;AAEA,SAAS,WAAW,MAAuB;CACzC,IAAI;EACF,MAAM,OAAO,SAAS,IAAI;EAC1B,OAAO,KAAK,YAAY,MAAM,CAAC,QAAQ,UAAU,KAAK,QAAQ,QAAQ,OAAO,OAAO,KAAK,OAAO,QAAW;CAC7G,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,SAAgB,cAAc,MAAc,MAAoB;CAC9D,UAAU,MAAM;EAAE,WAAW;EAAM,MAAM;CAAM,CAA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CAC1F,MAAM,MAAM,aAAa,GAAG;CAC5B,OAAO,YAAY,QAAQ,QAAQ,QAAQ,WAAW,OAAO;AAC/D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as identityProvider, r as identityProviders, t as IDENTITY_PROVIDERS } from "./registry-
|
|
1
|
+
import { n as identityProvider, r as identityProviders, t as IDENTITY_PROVIDERS } from "./registry-LvxsLJ5S.js";
|
|
2
2
|
export { IDENTITY_PROVIDERS, identityProvider, identityProviders };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as boundedIdentityFetch, i as registeredIdentityProviders, s as reserveAdapterIds, t as ownDid, u as testBuild } from "./ownDid
|
|
3
|
-
import { a as verifiedAtprotoHandle, c as assertDomainRecord, d as chosenResolver, f as resolverById, i as resolveAtprotoHandle, l as assertNip05, p as pkarrRelays, r as resolveAtprotoDid, s as DomainCheckError, t as assertPublicServer, u as assertPublicHost } from "./resolve-
|
|
4
|
-
import { a as PUBKY_RELAYS, c as isConfigured, d as providerForIssuer, i as validForgeLogin, l as issuerFor, n as SSH_FORGE_LABEL, o as audiences, r as checkSshForge, s as clientIdFor, t as SSH_FORGE_HOST, u as oidcProviders } from "./sshForges-
|
|
1
|
+
import { At as checkDidSignature, Bt as parseDid, Ca as domainWellKnownFile, Cd as toBase64Url, Cn as normalizePubkyKey, Ct as AtprotoProofError, Da as normalizeDomain, Dn as homeserverWebEndpoint, Ed as utf8Encode, En as pubkyProofPath, Et as DID_FILE_MAX_BYTES, Ft as didWebFile, Gt as strictBase64Url, Ht as parseDidSignaturePaste, It as didWebFileNames, Kt as DidDhtError, Lt as didWebFileUrl, Ma as wellKnownUrl, Mt as didJwsAlg, Nt as didSignedMessages, On as pubkyHomeserverOf, Ot as DidError, Pt as didWebDocumentUrl, Rt as didWebHost, Sa as domainTxtRecord, Sd as randomBytes, Sn as newPubkyProofFolder, St as shortAtprotoDid, Td as utf8Decode, Tn as pubkyProofFile, Tt as DID_DOCUMENT_MAX_BYTES, Ut as signingKeys, Vt as parseDidDocument, Wi as IdentityCheckUnavailable, Wt as staticDidDocument, Zt as resolveDidDht, _t as atprotoProofRkey, ad as openRelayPayload, bd as fromBase64Url, bn as isPubkyKey, bt as normalizeAtprotoHandle, ct as verifyBitcoinMessage, dt as ATPROTO_DECLARED_SCOPE, ft as ATPROTO_FULL_SCOPE, gt as atprotoProofRecord, it as parseSshSignature, jt as didGhostlyServiceEntry, kt as checkDidJws, lt as BitcoinAddressError, mt as ATPROTO_PROOF_SCOPE, nd as RELAY_PAYLOAD_MAX_BYTES, nt as SshSigError, ot as sshSignCommand, pt as ATPROTO_PROOF_COLLECTION, rt as parseSshPublicKey, st as verifySshSignature, tt as SSHSIG_NAMESPACE, ut as decodeAnyBitcoinAddress, vt as checkAtprotoProofRecord, wn as pubkyProofCapability, wt as verifyAtprotoRecordProof, xa as dnsProofName, xn as isPubkyProofFolder, yn as PUBKY_PROOF_MAX_BYTES, yt as isAtprotoDid, zt as normalizeDid } from "./src-DjVj2ynY.js";
|
|
2
|
+
import { c as boundedIdentityFetch, i as registeredIdentityProviders, s as reserveAdapterIds, t as ownDid, u as testBuild } from "./ownDid-CJ0ta8CL.js";
|
|
3
|
+
import { a as verifiedAtprotoHandle, c as assertDomainRecord, d as chosenResolver, f as resolverById, i as resolveAtprotoHandle, l as assertNip05, p as pkarrRelays, r as resolveAtprotoDid, s as DomainCheckError, t as assertPublicServer, u as assertPublicHost } from "./resolve-6kVu2DE5.js";
|
|
4
|
+
import { a as PUBKY_RELAYS, c as isConfigured, d as providerForIssuer, i as validForgeLogin, l as issuerFor, n as SSH_FORGE_LABEL, o as audiences, r as checkSshForge, s as clientIdFor, t as SSH_FORGE_HOST, u as oidcProviders } from "./sshForges-DeZ9cN9Q.js";
|
|
5
5
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
6
6
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
7
7
|
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
@@ -290,9 +290,13 @@ var OPENPGP_USER_ID_SOURCE = "User ID on the key, written by its holder: not pro
|
|
|
290
290
|
var OPENPGP_KEYSERVER_SOURCE = "Email confirmed to keys.openpgp.org by its owner: the keyserver's check, not Ghostly's";
|
|
291
291
|
/** How a Nostr proof was checked (`verified.source`): the event's own signature. */
|
|
292
292
|
var NOSTR_SIGNATURE_SOURCE = "Nostr signature (NIP-01, BIP-340)";
|
|
293
|
-
/**
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
/**
|
|
294
|
+
* A sign-in provider's ID token: who signed it, whether it says the email is checked, and whether the name is one the
|
|
295
|
+
* account set for itself (`nameUnchecked`): a display name its holder (or any directory's admin) types, which the
|
|
296
|
+
* provider signs but never checks, so it carries that caveat as an OpenPGP user ID does.
|
|
297
|
+
*/
|
|
298
|
+
function oidcDisplaySource(provider, email, nameUnchecked = false) {
|
|
299
|
+
return `Signed by ${provider}${email === "verified" ? `; email verified by ${provider}` : email === "unverified" ? `; email not verified by ${provider}` : ""}${nameUnchecked ? `; name set on the account, not checked by ${provider}` : ""}`;
|
|
296
300
|
}
|
|
297
301
|
//#endregion
|
|
298
302
|
//#region ../browser/src/proofs/nostr.ts
|
|
@@ -836,6 +840,8 @@ var ALLOWED_HASHES = /* @__PURE__ */ new Set([
|
|
|
836
840
|
var PgpProofError = class extends Error {
|
|
837
841
|
name = "PgpProofError";
|
|
838
842
|
};
|
|
843
|
+
/** A copy of a v4 key without user IDs: what keys.openpgp.org serves until its owner confirms an email there. */
|
|
844
|
+
var PGP_NO_USER_IDS = "This copy of the key has no user IDs (keys.openpgp.org leaves them out until you confirm an email there), so it cannot be checked. Paste your public key instead.";
|
|
839
845
|
/** Armored blocks in pasted text; more BEGIN lines than any real paste has are refused before the regex scans. */
|
|
840
846
|
function armorBlocks(text) {
|
|
841
847
|
if ((text.match(/-----BEGIN PGP /g) ?? []).length > 4) throw new PgpProofError("Paste only what gpg printed: one signature and your public key.");
|
|
@@ -891,6 +897,7 @@ function assertSignableStatement(statement) {
|
|
|
891
897
|
async function explainInvalidKey(key, keyId, at, cfg, when) {
|
|
892
898
|
const past = when === "signing" ? " when it signed" : "";
|
|
893
899
|
if (await key.isRevoked(void 0, void 0, at, cfg).catch(() => false)) throw new PgpProofError(`This key has been revoked${past}. A revoked key proves nothing.`);
|
|
900
|
+
if (key.keyPacket.version === 4 && !key.users.length) throw new PgpProofError(PGP_NO_USER_IDS);
|
|
894
901
|
try {
|
|
895
902
|
await key.verifyPrimaryKey(at, void 0, cfg);
|
|
896
903
|
} catch (e) {
|
|
@@ -908,6 +915,20 @@ async function explainInvalidKey(key, keyId, at, cfg, when) {
|
|
|
908
915
|
throw new PgpProofError(`The key that signed is not a valid signing key${past}.`);
|
|
909
916
|
}
|
|
910
917
|
var message = (e) => e instanceof Error ? e.message : String(e);
|
|
918
|
+
var keyVersionRefused = (version) => `This is an OpenPGP v${version} key, which Ghostly does not accept. Use a v4 key (gpg makes Ed25519 ones) or a v6 key.`;
|
|
919
|
+
/** The version byte of the public or secret key packet `bytes` start with, read from its header alone. */
|
|
920
|
+
function firstKeyVersion(bytes) {
|
|
921
|
+
const [h, l] = bytes;
|
|
922
|
+
if (!(h & 128)) return void 0;
|
|
923
|
+
const newFormat = !!(h & 64), tag = newFormat ? h & 63 : h >> 2 & 15;
|
|
924
|
+
if (tag !== 5 && tag !== 6) return void 0;
|
|
925
|
+
const at = newFormat ? l < 192 ? 2 : l < 224 ? 3 : l === 255 ? 6 : void 0 : [
|
|
926
|
+
2,
|
|
927
|
+
3,
|
|
928
|
+
5
|
|
929
|
+
][h & 3];
|
|
930
|
+
return at === void 0 ? void 0 : bytes[at];
|
|
931
|
+
}
|
|
911
932
|
/** Parses exactly one public key; refuses private keys, v3/v5 keys and key rings. */
|
|
912
933
|
async function readOneKey(pgp, input) {
|
|
913
934
|
const cfg = config(pgp);
|
|
@@ -921,13 +942,15 @@ async function readOneKey(pgp, input) {
|
|
|
921
942
|
config: cfg
|
|
922
943
|
});
|
|
923
944
|
} catch (e) {
|
|
945
|
+
const bytes = "armored" in input ? await pgp.unarmor(input.armored).then((a) => a.data, () => void 0) : input.binary;
|
|
946
|
+
if (bytes && firstKeyVersion(bytes) === 5) throw new PgpProofError(keyVersionRefused(5));
|
|
924
947
|
throw new PgpProofError(`Could not read this public key: ${message(e)}`);
|
|
925
948
|
}
|
|
926
949
|
if (keys.length !== 1) throw new PgpProofError("Paste one public key, not a key ring.");
|
|
927
950
|
const [key] = keys;
|
|
928
951
|
if (key.isPrivate()) throw new PgpProofError("This is a PRIVATE key. Ghostly only needs your public key (gpg --armor --export).");
|
|
929
952
|
const version = key.keyPacket.version;
|
|
930
|
-
if (version !== 4 && version !== 6) throw new PgpProofError(
|
|
953
|
+
if (version !== 4 && version !== 6) throw new PgpProofError(keyVersionRefused(version));
|
|
931
954
|
assertRsaSizes(key);
|
|
932
955
|
return key;
|
|
933
956
|
}
|
|
@@ -1284,7 +1307,13 @@ async function fetchKeyFromKeyserver(query, options = {}) {
|
|
|
1284
1307
|
* keyserver checked. That is the keyserver's check, and says nothing about a name.
|
|
1285
1308
|
*/
|
|
1286
1309
|
async function keyserverVerifiedEmails(keyserverArmored, fingerprint, options = {}) {
|
|
1287
|
-
|
|
1310
|
+
let info;
|
|
1311
|
+
try {
|
|
1312
|
+
info = await readPgpPublicKey(keyserverArmored, options);
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
if (e instanceof PgpProofError && e.message === "This copy of the key has no user IDs (keys.openpgp.org leaves them out until you confirm an email there), so it cannot be checked. Paste your public key instead.") return [];
|
|
1315
|
+
throw e;
|
|
1316
|
+
}
|
|
1288
1317
|
if (info.fingerprint !== fingerprint.toUpperCase()) throw new PgpProofError("keys.openpgp.org returned a different key.");
|
|
1289
1318
|
const emails = info.userIds.map((u) => /<([^<>\s]+@[^<>\s]+)>\s*$/.exec(u)?.[1] ?? (/^[^<>\s]+@[^<>\s]+$/.test(u) ? u : void 0));
|
|
1290
1319
|
return [...new Set(emails.filter((e) => !!e).map((e) => e.toLowerCase()))];
|
|
@@ -1430,9 +1459,13 @@ var openpgp = {
|
|
|
1430
1459
|
//#endregion
|
|
1431
1460
|
//#region ../browser/src/proofs/providers/ssh.ts
|
|
1432
1461
|
var FINGERPRINT = /^SHA256:[A-Za-z0-9+/]{43}$/;
|
|
1462
|
+
/** The line `ssh-keygen -l -f key.pub` prints: bits, fingerprint, comment, type ("256 SHA256:… me@laptop (ED25519)"). */
|
|
1463
|
+
var KEYGEN_LIST_LINE = /^\d+ (SHA256:[A-Za-z0-9+/]{43}) .* \([A-Z0-9-]+\)$/;
|
|
1433
1464
|
function normalizeKeySubject(input) {
|
|
1434
1465
|
const value = input.trim();
|
|
1435
1466
|
if (FINGERPRINT.test(value)) return value;
|
|
1467
|
+
const listed = KEYGEN_LIST_LINE.exec(value);
|
|
1468
|
+
if (listed) return listed[1];
|
|
1436
1469
|
try {
|
|
1437
1470
|
return parseSshPublicKey(value).fingerprint;
|
|
1438
1471
|
} catch (e) {
|
|
@@ -1451,19 +1484,21 @@ function canonicalArmor(pasted) {
|
|
|
1451
1484
|
if (parsed.namespace !== "ghostly") throw new Error(`That signature is for "${parsed.namespace}", not "${SSHSIG_NAMESPACE}": run the command with -n ${SSHSIG_NAMESPACE}`);
|
|
1452
1485
|
return `-----BEGIN SSH SIGNATURE-----\n${pasted.replace(/\r\n/g, "\n").trim().split("\n").map((l) => l.trim()).slice(1, -1).join("").match(/.{1,70}/g).join("\n")}\n-----END SSH SIGNATURE-----\n`;
|
|
1453
1486
|
}
|
|
1454
|
-
/** Exactly the statement; or with one trailing newline, which an editor adds when the
|
|
1455
|
-
* saved to a file and signed there (the Windows route). Nothing else is accepted. */
|
|
1487
|
+
/** Exactly the statement; or with one trailing newline ("\r\n" on Windows), which an editor adds when the
|
|
1488
|
+
* statement is saved to a file and signed there (the Windows route). Nothing else is accepted. */
|
|
1456
1489
|
async function verifyStatementSignature(statement, evidence) {
|
|
1457
|
-
|
|
1458
|
-
|
|
1490
|
+
let last;
|
|
1491
|
+
for (const bytes of [
|
|
1492
|
+
statement.bytes,
|
|
1493
|
+
utf8Encode(`${statement.text}\n`),
|
|
1494
|
+
utf8Encode(`${statement.text}\r\n`)
|
|
1495
|
+
]) try {
|
|
1496
|
+
return await verifySshSignature(evidence.signature, bytes);
|
|
1459
1497
|
} catch (e) {
|
|
1460
1498
|
if (!(e instanceof SshSigError) || !/does not match this statement/.test(e.message)) throw e;
|
|
1461
|
-
|
|
1462
|
-
return await verifySshSignature(evidence.signature, utf8Encode(`${statement.text}\n`));
|
|
1463
|
-
} catch (again) {
|
|
1464
|
-
throw Object.assign(/* @__PURE__ */ new Error("The signature is not over this statement: copy the command again and sign exactly what it shows"), { cause: again });
|
|
1465
|
-
}
|
|
1499
|
+
last = e;
|
|
1466
1500
|
}
|
|
1501
|
+
throw Object.assign(/* @__PURE__ */ new Error("The signature is not over this statement: copy the command again and sign exactly what it shows"), { cause: last });
|
|
1467
1502
|
}
|
|
1468
1503
|
var keyKind = (c) => c.securityKey ? `security key, touch${c.securityKey.userVerified ? " and PIN" : ""} confirmed` : c.key.type === "ssh-rsa" ? `RSA ${c.key.bits}` : c.key.type.replace(/^ssh-|^ecdsa-sha2-/, "");
|
|
1469
1504
|
function sshKeygenSigner(forAccount) {
|
|
@@ -1605,6 +1640,12 @@ function getBrowserHost() {
|
|
|
1605
1640
|
}
|
|
1606
1641
|
//#endregion
|
|
1607
1642
|
//#region ../browser/src/proofs/oidc/jwks.ts
|
|
1643
|
+
/**
|
|
1644
|
+
* A provider's signing keys, fetched from its pinned JWKS URL with limits and
|
|
1645
|
+
* cached. A key ID that is not in the cached set triggers one early refetch
|
|
1646
|
+
* (providers rotate keys), rate-limited so that a stream of made-up key IDs
|
|
1647
|
+
* cannot turn a contact's app into a request generator.
|
|
1648
|
+
*/
|
|
1608
1649
|
var JWKS_MAX_BYTES = 65536;
|
|
1609
1650
|
var MIN_TTL_MS = 3e5;
|
|
1610
1651
|
var MAX_TTL_MS = 864e5;
|
|
@@ -1648,9 +1689,19 @@ var JwksCache = class {
|
|
|
1648
1689
|
if (running) return running;
|
|
1649
1690
|
const task = (async () => {
|
|
1650
1691
|
if (!allowedUrl(url)) throw new Error("Provider key URL refused");
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1692
|
+
let response;
|
|
1693
|
+
try {
|
|
1694
|
+
response = await fetcher(url, { maxBytes: JWKS_MAX_BYTES });
|
|
1695
|
+
} catch (e) {
|
|
1696
|
+
throw e instanceof IdentityCheckUnavailable ? e : new IdentityCheckUnavailable(`Provider keys could not be fetched: ${e instanceof Error ? e.message : String(e)}`);
|
|
1697
|
+
}
|
|
1698
|
+
if (response.status !== 200) throw new IdentityCheckUnavailable(`Provider keys unavailable (${response.status})`);
|
|
1699
|
+
let keys;
|
|
1700
|
+
try {
|
|
1701
|
+
keys = parseKeys(response.text);
|
|
1702
|
+
} catch (e) {
|
|
1703
|
+
throw new IdentityCheckUnavailable(e.message);
|
|
1704
|
+
}
|
|
1654
1705
|
const fetched = this.now();
|
|
1655
1706
|
const entry = {
|
|
1656
1707
|
keys,
|
|
@@ -1969,11 +2020,21 @@ async function signInForProof(options) {
|
|
|
1969
2020
|
});
|
|
1970
2021
|
const redirected = await w.authorize(request.url, options.signal);
|
|
1971
2022
|
options.signal.throwIfAborted();
|
|
1972
|
-
|
|
2023
|
+
const idToken = await completeSignIn(options.provider, request, redirected, options);
|
|
2024
|
+
refuseUnchosenClaims(options.provider, idToken, options.reveal);
|
|
2025
|
+
return idToken;
|
|
1973
2026
|
} finally {
|
|
1974
2027
|
w.close();
|
|
1975
2028
|
}
|
|
1976
2029
|
}
|
|
2030
|
+
/** A token the provider filled with more than the person chose to share never becomes evidence: it would go to every contact. */
|
|
2031
|
+
function refuseUnchosenClaims(provider, idToken, reveal) {
|
|
2032
|
+
const { claims } = decodeIdToken(idToken);
|
|
2033
|
+
for (const [claim, coveredBy] of Object.entries(provider.disclosing ?? {})) {
|
|
2034
|
+
if (claims[claim] === void 0 || reveal.includes(coveredBy)) continue;
|
|
2035
|
+
throw new Error(claim === "hd" ? `This is a work or school ${provider.name} account: ${provider.name} adds its organisation’s domain to the sign-in, and your contacts would see it. Choose to share your email too, or sign in with a personal account.` : `${provider.name} added more to the sign-in than you chose to share. Choose to share your ${coveredBy} too, or sign in with another account.`);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
1977
2038
|
//#endregion
|
|
1978
2039
|
//#region ../browser/src/proofs/providers/oidc.ts
|
|
1979
2040
|
/** How long after the statement the sign-in may have happened: time to pick an account and approve. */
|
|
@@ -2096,6 +2157,7 @@ function createOidcIdentityProvider(options = {}) {
|
|
|
2096
2157
|
if (!SUB.test(id.subject)) throw new Error("The provider’s account identifier cannot be shown");
|
|
2097
2158
|
const attester = hostOf$1(provider.issuer);
|
|
2098
2159
|
const person = id.name ?? id.username;
|
|
2160
|
+
const handle = !id.name && (provider.id === "gitlab" || provider.id === "twitch");
|
|
2099
2161
|
const email = id.emailVerified ? id.email : void 0;
|
|
2100
2162
|
const name = email ? person && `${person} · ${email}`.length <= 64 ? `${person} · ${email}` : email : person;
|
|
2101
2163
|
const url = id.username && /^[A-Za-z0-9_.-]{1,64}$/.test(id.username) ? provider.id === "gitlab" ? `https://gitlab.com/${id.username}` : provider.id === "twitch" ? `https://www.twitch.tv/${id.username}` : void 0 : void 0;
|
|
@@ -2107,7 +2169,7 @@ function createOidcIdentityProvider(options = {}) {
|
|
|
2107
2169
|
...name ? { name } : {},
|
|
2108
2170
|
...url ? { url } : {},
|
|
2109
2171
|
fetchedAt: id.issuedAt,
|
|
2110
|
-
source: oidcDisplaySource(provider.name, id.email ? id.emailVerified ? "verified" : "unverified" : void 0)
|
|
2172
|
+
source: oidcDisplaySource(provider.name, id.email ? id.emailVerified ? "verified" : "unverified" : void 0, !!person && !handle)
|
|
2111
2173
|
} } : {}
|
|
2112
2174
|
};
|
|
2113
2175
|
}
|
|
@@ -2296,9 +2358,10 @@ function nobleScript(statement, curve) {
|
|
|
2296
2358
|
`console.log(Buffer.from(${lib.name}.sign(statement, secret)).toString("hex"));`
|
|
2297
2359
|
].join("\n");
|
|
2298
2360
|
}
|
|
2361
|
+
/** OpenSSL alone: the signature comes out as one line of base64 (xxd, for hex, is missing on many Linux systems). */
|
|
2299
2362
|
function opensslCommand(statement, curve) {
|
|
2300
2363
|
const save = `printf '%s' '${statement}' > statement.txt`;
|
|
2301
|
-
return curve === "Ed25519" ? `${save} && openssl pkeyutl -sign -rawin -inkey key.pem -in statement.txt |
|
|
2364
|
+
return curve === "Ed25519" ? `${save} && openssl pkeyutl -sign -rawin -inkey key.pem -in statement.txt | openssl base64 -A` : `${save} && openssl dgst -sha256 -sign key.pem statement.txt | openssl base64 -A`;
|
|
2302
2365
|
}
|
|
2303
2366
|
var signer = {
|
|
2304
2367
|
id: "sign",
|
|
@@ -3737,4 +3800,4 @@ function identityProvider(id, providers = identityProviders()) {
|
|
|
3737
3800
|
//#endregion
|
|
3738
3801
|
export { identityProvider as n, identityProviders as r, IDENTITY_PROVIDERS as t };
|
|
3739
3802
|
|
|
3740
|
-
//# sourceMappingURL=registry-
|
|
3803
|
+
//# sourceMappingURL=registry-LvxsLJ5S.js.map
|