@ipab/cli 0.1.0-rc.3 → 0.1.0-rc.5
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 +21 -10
- package/dist/cli.d.ts +3 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +188 -46
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.d.ts +1 -1
- package/dist/config-secret.d.ts.map +1 -1
- package/dist/config-secret.js +2 -73
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -3
- package/dist/config.js.map +1 -1
- package/dist/context-types.d.ts +12 -0
- package/dist/context-types.d.ts.map +1 -0
- package/dist/context-types.js +2 -0
- package/dist/context-types.js.map +1 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +25 -0
- package/dist/context.js.map +1 -1
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +5 -0
- package/dist/identity.js.map +1 -1
- package/dist/ipc.d.ts +3 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +34 -1
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +9 -0
- package/dist/kubo-install.d.ts.map +1 -0
- package/dist/kubo-install.js +361 -0
- package/dist/kubo-install.js.map +1 -0
- package/dist/kubo-peering.d.ts +11 -0
- package/dist/kubo-peering.d.ts.map +1 -0
- package/dist/kubo-peering.js +93 -0
- package/dist/kubo-peering.js.map +1 -0
- package/dist/kubo-peers.d.ts +12 -0
- package/dist/kubo-peers.d.ts.map +1 -0
- package/dist/kubo-peers.js +118 -0
- package/dist/kubo-peers.js.map +1 -0
- package/dist/kubo-release.d.ts +3 -0
- package/dist/kubo-release.d.ts.map +1 -0
- package/dist/kubo-release.js +12 -0
- package/dist/kubo-release.js.map +1 -0
- package/dist/kubo.d.ts +14 -5
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +186 -206
- package/dist/kubo.js.map +1 -1
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -2
- package/dist/runtime.js.map +1 -1
- package/dist/setup.d.ts +2 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +23 -18
- package/dist/setup.js.map +1 -1
- package/dist/state-storage-windows.d.ts +2 -0
- package/dist/state-storage-windows.d.ts.map +1 -0
- package/dist/state-storage-windows.js +114 -0
- package/dist/state-storage-windows.js.map +1 -0
- package/dist/state-storage.d.ts +3 -0
- package/dist/state-storage.d.ts.map +1 -0
- package/dist/state-storage.js +299 -0
- package/dist/state-storage.js.map +1 -0
- package/dist/state.d.ts +5 -3
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +64 -30
- package/dist/state.js.map +1 -1
- package/dist/swarm-files.d.ts +3 -2
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +25 -9
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm.d.ts +10 -5
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +225 -79
- package/dist/swarm.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +224 -60
- package/src/config-secret.ts +2 -84
- package/src/config.ts +25 -3
- package/src/context-types.ts +11 -0
- package/src/context.ts +40 -0
- package/src/identity.ts +13 -0
- package/src/ipc.ts +50 -1
- package/src/kubo-install.ts +452 -0
- package/src/kubo-peering.ts +126 -0
- package/src/kubo-peers.ts +145 -0
- package/src/kubo-release.ts +17 -0
- package/src/kubo.ts +254 -275
- package/src/runtime.ts +12 -1
- package/src/setup.ts +30 -17
- package/src/state-storage-windows.ts +134 -0
- package/src/state-storage.ts +329 -0
- package/src/state.ts +76 -35
- package/src/swarm-files.ts +26 -6
- package/src/swarm.ts +316 -97
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { IpfsStore } from "@ipab/ipfs-store";
|
|
3
|
+
import { ContentError, IpfsStore } from "@ipab/ipfs-store";
|
|
4
|
+
import { ContentBundleError } from "@ipab/bundle";
|
|
4
5
|
import { randomUUID } from "node:crypto";
|
|
5
6
|
import { CID } from "multiformats/cid";
|
|
6
7
|
import stringWidth from "string-width";
|
|
@@ -43,10 +44,13 @@ import {
|
|
|
43
44
|
verifiedRequest,
|
|
44
45
|
membershipRequestSummary,
|
|
45
46
|
swarmHeader,
|
|
47
|
+
sharedSwarmStatus,
|
|
46
48
|
addSwarm,
|
|
47
49
|
updateSwarm,
|
|
48
50
|
searchNames,
|
|
51
|
+
formatNameReference,
|
|
49
52
|
resolveReference,
|
|
53
|
+
parseNameReference,
|
|
50
54
|
publish,
|
|
51
55
|
type SwarmContext,
|
|
52
56
|
} from "./swarm.js";
|
|
@@ -58,18 +62,27 @@ import { readSecretStream } from "./config-secret.js";
|
|
|
58
62
|
|
|
59
63
|
export interface IO {
|
|
60
64
|
out(text: string): void;
|
|
61
|
-
err(text: string): void;
|
|
65
|
+
err(text: string, progress?: boolean): void;
|
|
62
66
|
tty: boolean;
|
|
63
67
|
columns?(): number | undefined;
|
|
64
68
|
confirm(text: string): Promise<boolean>;
|
|
65
69
|
readSecret?(): Promise<string>;
|
|
66
70
|
}
|
|
71
|
+
let progressLine = false;
|
|
67
72
|
export const processIO: IO = {
|
|
68
73
|
out(text) {
|
|
69
74
|
process.stdout.write(`${text}\n`);
|
|
70
75
|
},
|
|
71
|
-
err(text) {
|
|
72
|
-
process.stderr.
|
|
76
|
+
err(text, progress = false) {
|
|
77
|
+
if (progress && process.stderr.isTTY) {
|
|
78
|
+
const width =
|
|
79
|
+
(process.stderr.columns > 1 ? process.stderr.columns : 80) - 1;
|
|
80
|
+
process.stderr.write(`\r\x1b[2K${text.slice(0, width)}`);
|
|
81
|
+
progressLine = true;
|
|
82
|
+
} else {
|
|
83
|
+
process.stderr.write(`${progressLine ? "\n" : ""}${text}\n`);
|
|
84
|
+
progressLine = false;
|
|
85
|
+
}
|
|
73
86
|
},
|
|
74
87
|
tty: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
75
88
|
columns() {
|
|
@@ -98,7 +111,7 @@ export const processIO: IO = {
|
|
|
98
111
|
},
|
|
99
112
|
};
|
|
100
113
|
const commands: Record<string, string> = {
|
|
101
|
-
setup: "setup [--yes]",
|
|
114
|
+
setup: "setup [--yes] [--kubo-archive FILE]",
|
|
102
115
|
"swarm create": "swarm create [--service URL] [--resume OPERATION]",
|
|
103
116
|
"swarm request":
|
|
104
117
|
"swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
|
|
@@ -171,6 +184,7 @@ const commandHelp: Record<
|
|
|
171
184
|
examples: ["ipab setup --yes", "ipab setup"],
|
|
172
185
|
options: [
|
|
173
186
|
"--yes Confirm installation and identity initialization outside a TTY.",
|
|
187
|
+
"--kubo-archive FILE Use a local official archive matching this CLI's pinned platform digest, without network access.",
|
|
174
188
|
],
|
|
175
189
|
notes: [
|
|
176
190
|
"Idempotent: reuse the same verified program and existing identity.",
|
|
@@ -210,6 +224,7 @@ const commandHelp: Record<
|
|
|
210
224
|
],
|
|
211
225
|
notes: [
|
|
212
226
|
"No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
|
|
227
|
+
"If the alias is taken, choose another to keep both Swarms. If you mean to replace only the local registration, run ipab swarm remove ALIAS and retry.",
|
|
213
228
|
],
|
|
214
229
|
},
|
|
215
230
|
"swarm approve": {
|
|
@@ -246,10 +261,18 @@ const commandHelp: Record<
|
|
|
246
261
|
],
|
|
247
262
|
},
|
|
248
263
|
"swarm status": {
|
|
249
|
-
summary: "
|
|
250
|
-
|
|
264
|
+
summary: "Read the current shared Swarm state",
|
|
265
|
+
options: [
|
|
266
|
+
"--local Also authenticate local membership, connect the node and diagnose interrupted Owner operations.",
|
|
267
|
+
],
|
|
268
|
+
examples: [
|
|
269
|
+
"ipab swarm status",
|
|
270
|
+
"ipab swarm status work",
|
|
271
|
+
"ipab swarm status work --local",
|
|
272
|
+
],
|
|
251
273
|
notes: [
|
|
252
|
-
"Always
|
|
274
|
+
"Always read public configuration, Scope and HEAD, and verify the State. Local content needs no HOME identity or node activation.",
|
|
275
|
+
"Missing local content may require the registered Swarm's private source. --local preserves the full local diagnostic and header-cache update.",
|
|
253
276
|
],
|
|
254
277
|
},
|
|
255
278
|
"swarm list": {
|
|
@@ -311,6 +334,7 @@ const commandHelp: Record<
|
|
|
311
334
|
"Searches all registered swarms unless --current or --swarm selects one.",
|
|
312
335
|
"Valid caches use local Names only; absent/expired caches refresh. No payload downloads.",
|
|
313
336
|
"No matches is success, not a reason to refresh valid caches. Any failed swarm fails the whole search.",
|
|
337
|
+
"Text uses local alias URIs when available; JSON references use full configuration URLs for cross-device sharing.",
|
|
314
338
|
],
|
|
315
339
|
},
|
|
316
340
|
publish: {
|
|
@@ -349,6 +373,7 @@ const commandHelp: Record<
|
|
|
349
373
|
"Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
|
|
350
374
|
"Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
|
|
351
375
|
"ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
|
|
376
|
+
"Copy the reference from ipab search, or percent-encode the entire configuration URL and each Name path segment separately.",
|
|
352
377
|
"Does not install, build, edit, or automatically retrieve associated source.",
|
|
353
378
|
],
|
|
354
379
|
},
|
|
@@ -574,7 +599,7 @@ const commandHelp: Record<
|
|
|
574
599
|
"store.gateway is a read-only HTTP gateway; blocks, pins and GC remain local.",
|
|
575
600
|
"pointers.service is a canonical HTTPS origin (HTTP loopback allowed).",
|
|
576
601
|
"pointers.apiKey is accepted only through stdin using VALUE '-'; queries and confirmations redact it.",
|
|
577
|
-
"
|
|
602
|
+
"SQLite state is account-only even without a key. Reading or saving a nonempty key rechecks Unix modes or Windows ACLs.",
|
|
578
603
|
],
|
|
579
604
|
},
|
|
580
605
|
"config reset": {
|
|
@@ -628,7 +653,7 @@ const commandHelp: Record<
|
|
|
628
653
|
export function help(path = ""): string {
|
|
629
654
|
const globalOptions = `Global options (before COMMAND):
|
|
630
655
|
--swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
|
|
631
|
-
--state-dir PATH Set
|
|
656
|
+
--state-dir PATH Set a dedicated, account-private local state directory
|
|
632
657
|
--store-gateway URL Use a read-only upstream HTTP gateway
|
|
633
658
|
--json Output management/development metadata, not App stdio`;
|
|
634
659
|
const footer =
|
|
@@ -705,6 +730,19 @@ function printable(text: string): string {
|
|
|
705
730
|
.join("");
|
|
706
731
|
}
|
|
707
732
|
|
|
733
|
+
export function formatSearchResults(
|
|
734
|
+
matches: Awaited<ReturnType<typeof searchNames>>["matches"],
|
|
735
|
+
): string {
|
|
736
|
+
return matches.length
|
|
737
|
+
? matches
|
|
738
|
+
.map(
|
|
739
|
+
(match) =>
|
|
740
|
+
`${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${formatNameReference(match.alias ?? match.swarm, match.name)}`,
|
|
741
|
+
)
|
|
742
|
+
.join("\n")
|
|
743
|
+
: "No matching Names.";
|
|
744
|
+
}
|
|
745
|
+
|
|
708
746
|
function runTime(value: string, field: "start" | "end"): string {
|
|
709
747
|
const date = new Date(value);
|
|
710
748
|
if (!Number.isFinite(date.getTime()))
|
|
@@ -954,15 +992,17 @@ export function parse(argv: readonly string[]): Parsed {
|
|
|
954
992
|
? ["current", "force", "no-force"]
|
|
955
993
|
: result.path === "swarm approve"
|
|
956
994
|
? ["yes", "again"]
|
|
957
|
-
: result.path === "swarm
|
|
958
|
-
? ["
|
|
959
|
-
: result.path === "
|
|
960
|
-
? ["
|
|
961
|
-
: result.path === "
|
|
962
|
-
? ["
|
|
963
|
-
: result.path === "
|
|
964
|
-
? ["
|
|
965
|
-
:
|
|
995
|
+
: result.path === "swarm status"
|
|
996
|
+
? ["local"]
|
|
997
|
+
: result.path === "swarm exclude"
|
|
998
|
+
? ["yes"]
|
|
999
|
+
: result.path === "register set"
|
|
1000
|
+
? ["replace"]
|
|
1001
|
+
: result.path === "history remove"
|
|
1002
|
+
? ["yes"]
|
|
1003
|
+
: result.path === "open"
|
|
1004
|
+
? ["log", "raw", "force", "no-force"]
|
|
1005
|
+
: [];
|
|
966
1006
|
const values =
|
|
967
1007
|
result.path === "swarm create"
|
|
968
1008
|
? ["service", "resume", "name", "description", "alias"]
|
|
@@ -1001,6 +1041,7 @@ export function parse(argv: readonly string[]): Parsed {
|
|
|
1001
1041
|
: result.path === "pin list"
|
|
1002
1042
|
? ["type"]
|
|
1003
1043
|
: [];
|
|
1044
|
+
if (result.path === "setup") values.push("kubo-archive");
|
|
1004
1045
|
while (tokens.length) {
|
|
1005
1046
|
const value = tokens.shift()!;
|
|
1006
1047
|
if (
|
|
@@ -1142,6 +1183,7 @@ async function performCli(
|
|
|
1142
1183
|
let state: State | undefined;
|
|
1143
1184
|
let store: IpfsStore | undefined;
|
|
1144
1185
|
let appExitCode: number | undefined;
|
|
1186
|
+
let readContext: SwarmContext | undefined;
|
|
1145
1187
|
try {
|
|
1146
1188
|
const parsed = parse(argv);
|
|
1147
1189
|
if (parsed.help) {
|
|
@@ -1173,19 +1215,46 @@ async function performCli(
|
|
|
1173
1215
|
throw new HostError(
|
|
1174
1216
|
"Setup requires explicit --yes or interactive confirmation.",
|
|
1175
1217
|
);
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
);
|
|
1185
|
-
|
|
1218
|
+
const controller = new AbortController();
|
|
1219
|
+
const interrupt = () => {
|
|
1220
|
+
controller.abort(new HostError("Setup interrupted.", 130, "ABORTED"));
|
|
1221
|
+
};
|
|
1222
|
+
const terminate = () => {
|
|
1223
|
+
controller.abort(new HostError("Setup terminated.", 143, "ABORTED"));
|
|
1224
|
+
};
|
|
1225
|
+
process.once("SIGINT", interrupt);
|
|
1226
|
+
process.once("SIGTERM", terminate);
|
|
1227
|
+
try {
|
|
1228
|
+
const result = await setupDevice(
|
|
1229
|
+
stateLocation(parsed.flags, env).path,
|
|
1230
|
+
env,
|
|
1231
|
+
{
|
|
1232
|
+
diagnostic: (text, progress) => {
|
|
1233
|
+
io.err(text, progress);
|
|
1234
|
+
},
|
|
1235
|
+
signal: controller.signal,
|
|
1236
|
+
...(typeof parsed.options["kubo-archive"] === "string"
|
|
1237
|
+
? { archive: parsed.options["kubo-archive"] }
|
|
1238
|
+
: {}),
|
|
1239
|
+
},
|
|
1240
|
+
);
|
|
1241
|
+
io.out(
|
|
1242
|
+
parsed.flags.json
|
|
1243
|
+
? JSON.stringify(result)
|
|
1244
|
+
: `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`,
|
|
1245
|
+
);
|
|
1246
|
+
return 0;
|
|
1247
|
+
} finally {
|
|
1248
|
+
process.removeListener("SIGINT", interrupt);
|
|
1249
|
+
process.removeListener("SIGTERM", terminate);
|
|
1250
|
+
}
|
|
1186
1251
|
}
|
|
1187
1252
|
const builtins = await builtinContent();
|
|
1188
|
-
state = new State(
|
|
1253
|
+
state = new State(
|
|
1254
|
+
stateLocation(parsed.flags, env).path,
|
|
1255
|
+
builtins.pins,
|
|
1256
|
+
env,
|
|
1257
|
+
);
|
|
1189
1258
|
if (
|
|
1190
1259
|
parsed.path === "config reset" &&
|
|
1191
1260
|
parsed.positional[0] === "store.rpc"
|
|
@@ -1199,7 +1268,10 @@ async function performCli(
|
|
|
1199
1268
|
return 0;
|
|
1200
1269
|
}
|
|
1201
1270
|
const items = effectiveConfig(
|
|
1202
|
-
state.config(
|
|
1271
|
+
state.config({
|
|
1272
|
+
includeSecrets:
|
|
1273
|
+
parsed.path !== "swarm status" || Boolean(parsed.options.local),
|
|
1274
|
+
}),
|
|
1203
1275
|
parsed.flags,
|
|
1204
1276
|
env,
|
|
1205
1277
|
(reference) => state!.resolveSwarm(reference),
|
|
@@ -1225,6 +1297,7 @@ async function performCli(
|
|
|
1225
1297
|
env,
|
|
1226
1298
|
stateDir: stateLocation(parsed.flags, env).path,
|
|
1227
1299
|
cacheTtl: Number(value("swarm.cacheTtl")),
|
|
1300
|
+
listen: value("swarm.listen") === "loopback" ? "loopback" : "lan",
|
|
1228
1301
|
forceRefresh: parsed.options.force
|
|
1229
1302
|
? true
|
|
1230
1303
|
: parsed.options["no-force"]
|
|
@@ -1244,14 +1317,12 @@ async function performCli(
|
|
|
1244
1317
|
? filters(state, parsed.options)
|
|
1245
1318
|
: {};
|
|
1246
1319
|
const selection = () => {
|
|
1247
|
-
const
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
env,
|
|
1251
|
-
(reference) => state!.resolveSwarm(reference),
|
|
1320
|
+
const saved = state!.config({ includeSecrets: false });
|
|
1321
|
+
const current = effectiveConfig(saved, parsed.flags, env, (reference) =>
|
|
1322
|
+
state!.resolveSwarm(reference),
|
|
1252
1323
|
).find((item) => item.key === "swarm.default")!;
|
|
1253
1324
|
return {
|
|
1254
|
-
savedCurrent:
|
|
1325
|
+
savedCurrent: saved["swarm.default"] ?? null,
|
|
1255
1326
|
effectiveCurrent: current.value,
|
|
1256
1327
|
source: current.source,
|
|
1257
1328
|
};
|
|
@@ -1270,10 +1341,17 @@ async function performCli(
|
|
|
1270
1341
|
[
|
|
1271
1342
|
...result.swarms.map(
|
|
1272
1343
|
(entry) =>
|
|
1273
|
-
`${entry.cid === result.
|
|
1344
|
+
`${entry.cid === result.effectiveCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`,
|
|
1274
1345
|
),
|
|
1275
|
-
|
|
1276
|
-
|
|
1346
|
+
...(result.swarms.length ? [] : ["No registered Swarms."]),
|
|
1347
|
+
...(result.effectiveCurrent === null
|
|
1348
|
+
? ["Use ipab swarm use <alias> to select a default Swarm."]
|
|
1349
|
+
: []),
|
|
1350
|
+
...(result.effectiveCurrent !== result.savedCurrent
|
|
1351
|
+
? [
|
|
1352
|
+
`Selected via --swarm: ${printable(String(result.swarms.find((entry) => entry.cid === result.effectiveCurrent)?.alias ?? result.effectiveCurrent ?? "(none)"))}; saved default: ${printable(String(result.swarms.find((entry) => entry.cid === result.savedCurrent)?.alias ?? result.savedCurrent ?? "(none)"))}.`,
|
|
1353
|
+
]
|
|
1354
|
+
: []),
|
|
1277
1355
|
].join("\n"),
|
|
1278
1356
|
);
|
|
1279
1357
|
break;
|
|
@@ -1291,7 +1369,11 @@ async function performCli(
|
|
|
1291
1369
|
case "swarm remove": {
|
|
1292
1370
|
const removed = state.removeSwarm(first!);
|
|
1293
1371
|
emit(
|
|
1294
|
-
{
|
|
1372
|
+
{
|
|
1373
|
+
removed,
|
|
1374
|
+
savedCurrent:
|
|
1375
|
+
state.config({ includeSecrets: false })["swarm.default"] ?? null,
|
|
1376
|
+
},
|
|
1295
1377
|
`Removed registration ${removed}. Credentials, content and remote membership are unchanged.`,
|
|
1296
1378
|
);
|
|
1297
1379
|
break;
|
|
@@ -1392,7 +1474,9 @@ async function performCli(
|
|
|
1392
1474
|
{
|
|
1393
1475
|
configUrl: entry.cid,
|
|
1394
1476
|
alias: entry.alias,
|
|
1395
|
-
savedCurrent:
|
|
1477
|
+
savedCurrent:
|
|
1478
|
+
state.config({ includeSecrets: false })["swarm.default"] ??
|
|
1479
|
+
null,
|
|
1396
1480
|
},
|
|
1397
1481
|
`Registered swarm ${entry.alias ?? cid} (${cid}).`,
|
|
1398
1482
|
);
|
|
@@ -1419,17 +1503,7 @@ async function performCli(
|
|
|
1419
1503
|
]
|
|
1420
1504
|
: registrations;
|
|
1421
1505
|
const result = await searchNames(context, first!, scope);
|
|
1422
|
-
emit(
|
|
1423
|
-
result,
|
|
1424
|
-
result.matches.length
|
|
1425
|
-
? result.matches
|
|
1426
|
-
.map(
|
|
1427
|
-
(match) =>
|
|
1428
|
-
`${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${printable(match.reference)}`,
|
|
1429
|
-
)
|
|
1430
|
-
.join("\n")
|
|
1431
|
-
: "No matching Names.",
|
|
1432
|
-
);
|
|
1506
|
+
emit(result, formatSearchResults(result.matches));
|
|
1433
1507
|
break;
|
|
1434
1508
|
}
|
|
1435
1509
|
if (parsed.path === "swarm status") {
|
|
@@ -1438,16 +1512,24 @@ async function performCli(
|
|
|
1438
1512
|
syntax(
|
|
1439
1513
|
"swarm status requires a configuration URL or swarm.default.",
|
|
1440
1514
|
);
|
|
1441
|
-
const
|
|
1515
|
+
const local = Boolean(parsed.options.local);
|
|
1516
|
+
const { head, config } = local
|
|
1517
|
+
? await swarmHeader(context, cid, true)
|
|
1518
|
+
: await sharedSwarmStatus(context, cid);
|
|
1519
|
+
const fingerprint = await keyId(config.owner);
|
|
1442
1520
|
store = context.store;
|
|
1443
1521
|
emit(
|
|
1444
1522
|
{
|
|
1445
1523
|
configUrl: cid,
|
|
1446
1524
|
owner: config.owner,
|
|
1447
|
-
ownerFingerprint:
|
|
1525
|
+
ownerFingerprint: fingerprint,
|
|
1448
1526
|
epoch: config.epoch,
|
|
1449
|
-
|
|
1450
|
-
|
|
1527
|
+
...(local
|
|
1528
|
+
? {
|
|
1529
|
+
peerId: context.node!.peerId,
|
|
1530
|
+
addresses: context.node!.addresses,
|
|
1531
|
+
}
|
|
1532
|
+
: {}),
|
|
1451
1533
|
root: head.root,
|
|
1452
1534
|
valueCid: head.cid,
|
|
1453
1535
|
properties: {
|
|
@@ -1455,12 +1537,40 @@ async function performCli(
|
|
|
1455
1537
|
description: config.description,
|
|
1456
1538
|
},
|
|
1457
1539
|
},
|
|
1458
|
-
|
|
1540
|
+
[
|
|
1541
|
+
"Swarm",
|
|
1542
|
+
` Name: ${printable(config.name)}`,
|
|
1543
|
+
` Description: ${config.description ? printable(config.description) : "(none)"}`,
|
|
1544
|
+
" Config URL:",
|
|
1545
|
+
` ${cid}`,
|
|
1546
|
+
"",
|
|
1547
|
+
"Identity",
|
|
1548
|
+
" Owner fingerprint:",
|
|
1549
|
+
` ${fingerprint}`,
|
|
1550
|
+
...(local
|
|
1551
|
+
? [
|
|
1552
|
+
" PeerID:",
|
|
1553
|
+
` ${context.node!.peerId}`,
|
|
1554
|
+
"",
|
|
1555
|
+
"Local addresses",
|
|
1556
|
+
...context.node!.addresses.map(
|
|
1557
|
+
(address) => ` ${printable(address)}`,
|
|
1558
|
+
),
|
|
1559
|
+
]
|
|
1560
|
+
: []),
|
|
1561
|
+
"",
|
|
1562
|
+
"Content",
|
|
1563
|
+
" HEAD (publication root):",
|
|
1564
|
+
` ${head.root}`,
|
|
1565
|
+
" Content CID (HEAD value):",
|
|
1566
|
+
` ${head.cid}`,
|
|
1567
|
+
].join("\n"),
|
|
1459
1568
|
);
|
|
1460
1569
|
break;
|
|
1461
1570
|
}
|
|
1462
1571
|
if (parsed.path === "get") {
|
|
1463
|
-
|
|
1572
|
+
readContext = context;
|
|
1573
|
+
const localCid = /^(ipab|name):/i.test(first!)
|
|
1464
1574
|
? undefined
|
|
1465
1575
|
: state.resolve(first!);
|
|
1466
1576
|
const builtin = builtins.pins.find((pin) => pin.cid === localCid);
|
|
@@ -1472,6 +1582,7 @@ async function performCli(
|
|
|
1472
1582
|
selectedSwarm,
|
|
1473
1583
|
(reference) => state!.resolve(reference),
|
|
1474
1584
|
Boolean(parsed.options.raw),
|
|
1585
|
+
"local-first",
|
|
1475
1586
|
);
|
|
1476
1587
|
const contentStore = context.store;
|
|
1477
1588
|
const source = IpfsStore.fromClient(
|
|
@@ -1577,7 +1688,7 @@ async function performCli(
|
|
|
1577
1688
|
store = context.store;
|
|
1578
1689
|
if (parsed.path === "swarm create")
|
|
1579
1690
|
io.err(
|
|
1580
|
-
`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`,
|
|
1691
|
+
`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config({ includeSecrets: false })["swarm.default"] ?? "(none)"}.`,
|
|
1581
1692
|
);
|
|
1582
1693
|
emit(
|
|
1583
1694
|
parsed.path === "swarm request"
|
|
@@ -2033,6 +2144,56 @@ async function performCli(
|
|
|
2033
2144
|
)
|
|
2034
2145
|
).cid;
|
|
2035
2146
|
store = context.store;
|
|
2147
|
+
const resolveBundleReference = async (
|
|
2148
|
+
reference: string,
|
|
2149
|
+
signal: AbortSignal,
|
|
2150
|
+
preferredSwarm?: string,
|
|
2151
|
+
) => {
|
|
2152
|
+
signal.throwIfAborted();
|
|
2153
|
+
const lookup: SwarmContext = {
|
|
2154
|
+
...swarmContext(),
|
|
2155
|
+
store: new IpfsStore(
|
|
2156
|
+
await storeConfiguration(value("store.gateway")),
|
|
2157
|
+
),
|
|
2158
|
+
};
|
|
2159
|
+
try {
|
|
2160
|
+
const named = parseNameReference(reference);
|
|
2161
|
+
const swarm = named?.swarm
|
|
2162
|
+
? state!.resolveSwarm(named.swarm)
|
|
2163
|
+
: preferredSwarm
|
|
2164
|
+
? state!.resolveSwarm(preferredSwarm)
|
|
2165
|
+
: selectedSwarm;
|
|
2166
|
+
const resolve = (source: string | undefined) =>
|
|
2167
|
+
resolveReference(lookup, reference, source, (input) =>
|
|
2168
|
+
state!.resolve(input),
|
|
2169
|
+
);
|
|
2170
|
+
let resolved;
|
|
2171
|
+
try {
|
|
2172
|
+
resolved = await resolve(named ? swarm : undefined);
|
|
2173
|
+
} catch (cause) {
|
|
2174
|
+
let failure: unknown = cause;
|
|
2175
|
+
for (
|
|
2176
|
+
let depth = 0;
|
|
2177
|
+
depth < 8 && failure instanceof ContentBundleError;
|
|
2178
|
+
depth++
|
|
2179
|
+
)
|
|
2180
|
+
failure = failure.cause;
|
|
2181
|
+
if (
|
|
2182
|
+
named ||
|
|
2183
|
+
!swarm ||
|
|
2184
|
+
!(failure instanceof ContentError) ||
|
|
2185
|
+
failure.code !== "missing_block"
|
|
2186
|
+
)
|
|
2187
|
+
throw cause;
|
|
2188
|
+
signal.throwIfAborted();
|
|
2189
|
+
resolved = await resolve(swarm);
|
|
2190
|
+
}
|
|
2191
|
+
signal.throwIfAborted();
|
|
2192
|
+
return { ...resolved, ...(swarm ? { swarm } : {}) };
|
|
2193
|
+
} finally {
|
|
2194
|
+
await lookup.store.close();
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2036
2197
|
let appCid: string;
|
|
2037
2198
|
let appArgv: string[];
|
|
2038
2199
|
if (parsed.path === "open") {
|
|
@@ -2062,6 +2223,7 @@ async function performCli(
|
|
|
2062
2223
|
{ origin: "open", appCid, argv: appArgv },
|
|
2063
2224
|
{
|
|
2064
2225
|
inputSchema: schema,
|
|
2226
|
+
resolveBundleReference,
|
|
2065
2227
|
history: Boolean(value("history.enabled")),
|
|
2066
2228
|
retain: value("output.retention") === "history",
|
|
2067
2229
|
log: Boolean(parsed.options.log),
|
|
@@ -2085,6 +2247,7 @@ async function performCli(
|
|
|
2085
2247
|
store,
|
|
2086
2248
|
{ origin: "exec", appCid, argv: appArgv },
|
|
2087
2249
|
{
|
|
2250
|
+
resolveBundleReference,
|
|
2088
2251
|
history: Boolean(value("history.enabled")),
|
|
2089
2252
|
retain: value("output.retention") === "history",
|
|
2090
2253
|
log: Boolean(parsed.options.log),
|
|
@@ -2105,6 +2268,7 @@ async function performCli(
|
|
|
2105
2268
|
return error instanceof HostError ? error.exitCode : 1;
|
|
2106
2269
|
} finally {
|
|
2107
2270
|
try {
|
|
2271
|
+
await readContext?.finishRead?.();
|
|
2108
2272
|
await closeStore(store, appExitCode);
|
|
2109
2273
|
} finally {
|
|
2110
2274
|
state?.close();
|
package/src/config-secret.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { HostError, syntax } from "./errors.js";
|
|
1
|
+
import { syntax } from "./errors.js";
|
|
2
|
+
export { verifyStateStorage as secureConfigurationStorage } from "./state-storage.js";
|
|
5
3
|
|
|
6
4
|
export async function readSecretStream(
|
|
7
5
|
input: AsyncIterable<string>,
|
|
@@ -14,83 +12,3 @@ export async function readSecretStream(
|
|
|
14
12
|
}
|
|
15
13
|
return text.trim();
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
function windowsAcl(paths: string[], protect: boolean): void {
|
|
19
|
-
const script = `
|
|
20
|
-
$ErrorActionPreference = 'Stop'
|
|
21
|
-
$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
22
|
-
foreach ($path in (ConvertFrom-Json $env:IPAB_CONFIG_PATHS)) {
|
|
23
|
-
$acl = Get-Acl -LiteralPath $path
|
|
24
|
-
if ($env:IPAB_CONFIG_PROTECT -eq 'true') {
|
|
25
|
-
if ((Get-Item -LiteralPath $path).PSIsContainer) {
|
|
26
|
-
$acl = New-Object System.Security.AccessControl.DirectorySecurity
|
|
27
|
-
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
|
|
28
|
-
} else {
|
|
29
|
-
$acl = New-Object System.Security.AccessControl.FileSecurity
|
|
30
|
-
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'Allow')
|
|
31
|
-
}
|
|
32
|
-
$acl.SetAccessRuleProtection($true, $false)
|
|
33
|
-
$acl.AddAccessRule($rule)
|
|
34
|
-
if ((Get-Item -LiteralPath $path).PSIsContainer) {
|
|
35
|
-
[System.IO.Directory]::SetAccessControl($path, $acl)
|
|
36
|
-
} else {
|
|
37
|
-
[System.IO.File]::SetAccessControl($path, $acl)
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
|
|
41
|
-
if ($rule.AccessControlType -eq 'Allow' -and $rule.IdentityReference.Value -ne $sid.Value) {
|
|
42
|
-
throw 'Configuration storage must be account-only'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
execFileSync(
|
|
48
|
-
"powershell.exe",
|
|
49
|
-
[
|
|
50
|
-
"-NoProfile",
|
|
51
|
-
"-NonInteractive",
|
|
52
|
-
"-EncodedCommand",
|
|
53
|
-
Buffer.from(script, "utf16le").toString("base64"),
|
|
54
|
-
],
|
|
55
|
-
{
|
|
56
|
-
env: {
|
|
57
|
-
...Object.fromEntries(
|
|
58
|
-
Object.entries(process.env).filter(
|
|
59
|
-
([key]) => key.toLowerCase() !== "psmodulepath",
|
|
60
|
-
),
|
|
61
|
-
),
|
|
62
|
-
IPAB_CONFIG_PATHS: JSON.stringify(paths),
|
|
63
|
-
IPAB_CONFIG_PROTECT: String(protect),
|
|
64
|
-
},
|
|
65
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
export function secureConfigurationStorage(
|
|
70
|
-
directory: string,
|
|
71
|
-
protect: boolean,
|
|
72
|
-
): void {
|
|
73
|
-
try {
|
|
74
|
-
const paths = [
|
|
75
|
-
directory,
|
|
76
|
-
...["state.sqlite", "state.sqlite-wal", "state.sqlite-shm"].map((file) =>
|
|
77
|
-
join(directory, file),
|
|
78
|
-
),
|
|
79
|
-
].filter((path) => existsSync(path));
|
|
80
|
-
for (const path of paths) {
|
|
81
|
-
const stat = lstatSync(path);
|
|
82
|
-
if (stat.isSymbolicLink() || (!stat.isFile() && !stat.isDirectory()))
|
|
83
|
-
throw new Error();
|
|
84
|
-
if (process.platform !== "win32") {
|
|
85
|
-
if (stat.uid !== process.getuid?.()) throw new Error();
|
|
86
|
-
if (protect) chmodSync(path, stat.isDirectory() ? 0o700 : 0o600);
|
|
87
|
-
else if ((stat.mode & 0o077) !== 0) throw new Error();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (process.platform === "win32") windowsAcl(paths, protect);
|
|
91
|
-
} catch {
|
|
92
|
-
throw new HostError(
|
|
93
|
-
"Pointer API key configuration requires account-only state storage permissions.",
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|