@ipab/cli 0.1.0-rc.4 → 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 +12 -7
- package/dist/cli.d.ts +3 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +114 -25
- 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 +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -1
- 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/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 +11 -4
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +150 -197
- 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 +2 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +59 -29
- package/dist/state.js.map +1 -1
- package/dist/swarm-files.d.ts +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +4 -1
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm.d.ts +6 -3
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +184 -70
- package/dist/swarm.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +146 -39
- package/src/config-secret.ts +2 -84
- package/src/config.ts +14 -1
- package/src/context-types.ts +11 -0
- package/src/context.ts +40 -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 +207 -269
- 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 +68 -35
- package/src/swarm-files.ts +4 -0
- package/src/swarm.ts +256 -90
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";
|
|
@@ -47,7 +48,9 @@ import {
|
|
|
47
48
|
addSwarm,
|
|
48
49
|
updateSwarm,
|
|
49
50
|
searchNames,
|
|
51
|
+
formatNameReference,
|
|
50
52
|
resolveReference,
|
|
53
|
+
parseNameReference,
|
|
51
54
|
publish,
|
|
52
55
|
type SwarmContext,
|
|
53
56
|
} from "./swarm.js";
|
|
@@ -59,18 +62,27 @@ import { readSecretStream } from "./config-secret.js";
|
|
|
59
62
|
|
|
60
63
|
export interface IO {
|
|
61
64
|
out(text: string): void;
|
|
62
|
-
err(text: string): void;
|
|
65
|
+
err(text: string, progress?: boolean): void;
|
|
63
66
|
tty: boolean;
|
|
64
67
|
columns?(): number | undefined;
|
|
65
68
|
confirm(text: string): Promise<boolean>;
|
|
66
69
|
readSecret?(): Promise<string>;
|
|
67
70
|
}
|
|
71
|
+
let progressLine = false;
|
|
68
72
|
export const processIO: IO = {
|
|
69
73
|
out(text) {
|
|
70
74
|
process.stdout.write(`${text}\n`);
|
|
71
75
|
},
|
|
72
|
-
err(text) {
|
|
73
|
-
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
|
+
}
|
|
74
86
|
},
|
|
75
87
|
tty: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
76
88
|
columns() {
|
|
@@ -99,7 +111,7 @@ export const processIO: IO = {
|
|
|
99
111
|
},
|
|
100
112
|
};
|
|
101
113
|
const commands: Record<string, string> = {
|
|
102
|
-
setup: "setup [--yes]",
|
|
114
|
+
setup: "setup [--yes] [--kubo-archive FILE]",
|
|
103
115
|
"swarm create": "swarm create [--service URL] [--resume OPERATION]",
|
|
104
116
|
"swarm request":
|
|
105
117
|
"swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
|
|
@@ -172,6 +184,7 @@ const commandHelp: Record<
|
|
|
172
184
|
examples: ["ipab setup --yes", "ipab setup"],
|
|
173
185
|
options: [
|
|
174
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.",
|
|
175
188
|
],
|
|
176
189
|
notes: [
|
|
177
190
|
"Idempotent: reuse the same verified program and existing identity.",
|
|
@@ -211,6 +224,7 @@ const commandHelp: Record<
|
|
|
211
224
|
],
|
|
212
225
|
notes: [
|
|
213
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.",
|
|
214
228
|
],
|
|
215
229
|
},
|
|
216
230
|
"swarm approve": {
|
|
@@ -320,6 +334,7 @@ const commandHelp: Record<
|
|
|
320
334
|
"Searches all registered swarms unless --current or --swarm selects one.",
|
|
321
335
|
"Valid caches use local Names only; absent/expired caches refresh. No payload downloads.",
|
|
322
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.",
|
|
323
338
|
],
|
|
324
339
|
},
|
|
325
340
|
publish: {
|
|
@@ -358,6 +373,7 @@ const commandHelp: Record<
|
|
|
358
373
|
"Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
|
|
359
374
|
"Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
|
|
360
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.",
|
|
361
377
|
"Does not install, build, edit, or automatically retrieve associated source.",
|
|
362
378
|
],
|
|
363
379
|
},
|
|
@@ -583,7 +599,7 @@ const commandHelp: Record<
|
|
|
583
599
|
"store.gateway is a read-only HTTP gateway; blocks, pins and GC remain local.",
|
|
584
600
|
"pointers.service is a canonical HTTPS origin (HTTP loopback allowed).",
|
|
585
601
|
"pointers.apiKey is accepted only through stdin using VALUE '-'; queries and confirmations redact it.",
|
|
586
|
-
"
|
|
602
|
+
"SQLite state is account-only even without a key. Reading or saving a nonempty key rechecks Unix modes or Windows ACLs.",
|
|
587
603
|
],
|
|
588
604
|
},
|
|
589
605
|
"config reset": {
|
|
@@ -637,7 +653,7 @@ const commandHelp: Record<
|
|
|
637
653
|
export function help(path = ""): string {
|
|
638
654
|
const globalOptions = `Global options (before COMMAND):
|
|
639
655
|
--swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
|
|
640
|
-
--state-dir PATH Set
|
|
656
|
+
--state-dir PATH Set a dedicated, account-private local state directory
|
|
641
657
|
--store-gateway URL Use a read-only upstream HTTP gateway
|
|
642
658
|
--json Output management/development metadata, not App stdio`;
|
|
643
659
|
const footer =
|
|
@@ -714,6 +730,19 @@ function printable(text: string): string {
|
|
|
714
730
|
.join("");
|
|
715
731
|
}
|
|
716
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
|
+
|
|
717
746
|
function runTime(value: string, field: "start" | "end"): string {
|
|
718
747
|
const date = new Date(value);
|
|
719
748
|
if (!Number.isFinite(date.getTime()))
|
|
@@ -1012,6 +1041,7 @@ export function parse(argv: readonly string[]): Parsed {
|
|
|
1012
1041
|
: result.path === "pin list"
|
|
1013
1042
|
? ["type"]
|
|
1014
1043
|
: [];
|
|
1044
|
+
if (result.path === "setup") values.push("kubo-archive");
|
|
1015
1045
|
while (tokens.length) {
|
|
1016
1046
|
const value = tokens.shift()!;
|
|
1017
1047
|
if (
|
|
@@ -1153,6 +1183,7 @@ async function performCli(
|
|
|
1153
1183
|
let state: State | undefined;
|
|
1154
1184
|
let store: IpfsStore | undefined;
|
|
1155
1185
|
let appExitCode: number | undefined;
|
|
1186
|
+
let readContext: SwarmContext | undefined;
|
|
1156
1187
|
try {
|
|
1157
1188
|
const parsed = parse(argv);
|
|
1158
1189
|
if (parsed.help) {
|
|
@@ -1184,19 +1215,46 @@ async function performCli(
|
|
|
1184
1215
|
throw new HostError(
|
|
1185
1216
|
"Setup requires explicit --yes or interactive confirmation.",
|
|
1186
1217
|
);
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
);
|
|
1196
|
-
|
|
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
|
+
}
|
|
1197
1251
|
}
|
|
1198
1252
|
const builtins = await builtinContent();
|
|
1199
|
-
state = new State(
|
|
1253
|
+
state = new State(
|
|
1254
|
+
stateLocation(parsed.flags, env).path,
|
|
1255
|
+
builtins.pins,
|
|
1256
|
+
env,
|
|
1257
|
+
);
|
|
1200
1258
|
if (
|
|
1201
1259
|
parsed.path === "config reset" &&
|
|
1202
1260
|
parsed.positional[0] === "store.rpc"
|
|
@@ -1259,14 +1317,12 @@ async function performCli(
|
|
|
1259
1317
|
? filters(state, parsed.options)
|
|
1260
1318
|
: {};
|
|
1261
1319
|
const selection = () => {
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
env,
|
|
1266
|
-
(reference) => state!.resolveSwarm(reference),
|
|
1320
|
+
const saved = state!.config({ includeSecrets: false });
|
|
1321
|
+
const current = effectiveConfig(saved, parsed.flags, env, (reference) =>
|
|
1322
|
+
state!.resolveSwarm(reference),
|
|
1267
1323
|
).find((item) => item.key === "swarm.default")!;
|
|
1268
1324
|
return {
|
|
1269
|
-
savedCurrent:
|
|
1325
|
+
savedCurrent: saved["swarm.default"] ?? null,
|
|
1270
1326
|
effectiveCurrent: current.value,
|
|
1271
1327
|
source: current.source,
|
|
1272
1328
|
};
|
|
@@ -1313,7 +1369,11 @@ async function performCli(
|
|
|
1313
1369
|
case "swarm remove": {
|
|
1314
1370
|
const removed = state.removeSwarm(first!);
|
|
1315
1371
|
emit(
|
|
1316
|
-
{
|
|
1372
|
+
{
|
|
1373
|
+
removed,
|
|
1374
|
+
savedCurrent:
|
|
1375
|
+
state.config({ includeSecrets: false })["swarm.default"] ?? null,
|
|
1376
|
+
},
|
|
1317
1377
|
`Removed registration ${removed}. Credentials, content and remote membership are unchanged.`,
|
|
1318
1378
|
);
|
|
1319
1379
|
break;
|
|
@@ -1414,7 +1474,9 @@ async function performCli(
|
|
|
1414
1474
|
{
|
|
1415
1475
|
configUrl: entry.cid,
|
|
1416
1476
|
alias: entry.alias,
|
|
1417
|
-
savedCurrent:
|
|
1477
|
+
savedCurrent:
|
|
1478
|
+
state.config({ includeSecrets: false })["swarm.default"] ??
|
|
1479
|
+
null,
|
|
1418
1480
|
},
|
|
1419
1481
|
`Registered swarm ${entry.alias ?? cid} (${cid}).`,
|
|
1420
1482
|
);
|
|
@@ -1441,17 +1503,7 @@ async function performCli(
|
|
|
1441
1503
|
]
|
|
1442
1504
|
: registrations;
|
|
1443
1505
|
const result = await searchNames(context, first!, scope);
|
|
1444
|
-
emit(
|
|
1445
|
-
result,
|
|
1446
|
-
result.matches.length
|
|
1447
|
-
? result.matches
|
|
1448
|
-
.map(
|
|
1449
|
-
(match) =>
|
|
1450
|
-
`${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${printable(match.reference)}`,
|
|
1451
|
-
)
|
|
1452
|
-
.join("\n")
|
|
1453
|
-
: "No matching Names.",
|
|
1454
|
-
);
|
|
1506
|
+
emit(result, formatSearchResults(result.matches));
|
|
1455
1507
|
break;
|
|
1456
1508
|
}
|
|
1457
1509
|
if (parsed.path === "swarm status") {
|
|
@@ -1517,7 +1569,8 @@ async function performCli(
|
|
|
1517
1569
|
break;
|
|
1518
1570
|
}
|
|
1519
1571
|
if (parsed.path === "get") {
|
|
1520
|
-
|
|
1572
|
+
readContext = context;
|
|
1573
|
+
const localCid = /^(ipab|name):/i.test(first!)
|
|
1521
1574
|
? undefined
|
|
1522
1575
|
: state.resolve(first!);
|
|
1523
1576
|
const builtin = builtins.pins.find((pin) => pin.cid === localCid);
|
|
@@ -1529,6 +1582,7 @@ async function performCli(
|
|
|
1529
1582
|
selectedSwarm,
|
|
1530
1583
|
(reference) => state!.resolve(reference),
|
|
1531
1584
|
Boolean(parsed.options.raw),
|
|
1585
|
+
"local-first",
|
|
1532
1586
|
);
|
|
1533
1587
|
const contentStore = context.store;
|
|
1534
1588
|
const source = IpfsStore.fromClient(
|
|
@@ -1634,7 +1688,7 @@ async function performCli(
|
|
|
1634
1688
|
store = context.store;
|
|
1635
1689
|
if (parsed.path === "swarm create")
|
|
1636
1690
|
io.err(
|
|
1637
|
-
`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)"}.`,
|
|
1638
1692
|
);
|
|
1639
1693
|
emit(
|
|
1640
1694
|
parsed.path === "swarm request"
|
|
@@ -2090,6 +2144,56 @@ async function performCli(
|
|
|
2090
2144
|
)
|
|
2091
2145
|
).cid;
|
|
2092
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
|
+
};
|
|
2093
2197
|
let appCid: string;
|
|
2094
2198
|
let appArgv: string[];
|
|
2095
2199
|
if (parsed.path === "open") {
|
|
@@ -2119,6 +2223,7 @@ async function performCli(
|
|
|
2119
2223
|
{ origin: "open", appCid, argv: appArgv },
|
|
2120
2224
|
{
|
|
2121
2225
|
inputSchema: schema,
|
|
2226
|
+
resolveBundleReference,
|
|
2122
2227
|
history: Boolean(value("history.enabled")),
|
|
2123
2228
|
retain: value("output.retention") === "history",
|
|
2124
2229
|
log: Boolean(parsed.options.log),
|
|
@@ -2142,6 +2247,7 @@ async function performCli(
|
|
|
2142
2247
|
store,
|
|
2143
2248
|
{ origin: "exec", appCid, argv: appArgv },
|
|
2144
2249
|
{
|
|
2250
|
+
resolveBundleReference,
|
|
2145
2251
|
history: Boolean(value("history.enabled")),
|
|
2146
2252
|
retain: value("output.retention") === "history",
|
|
2147
2253
|
log: Boolean(parsed.options.log),
|
|
@@ -2162,6 +2268,7 @@ async function performCli(
|
|
|
2162
2268
|
return error instanceof HostError ? error.exitCode : 1;
|
|
2163
2269
|
} finally {
|
|
2164
2270
|
try {
|
|
2271
|
+
await readContext?.finishRead?.();
|
|
2165
2272
|
await closeStore(store, appExitCode);
|
|
2166
2273
|
} finally {
|
|
2167
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
|
-
}
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
+
import { CID } from "multiformats/cid";
|
|
3
4
|
import { readContentConfiguration } from "@ipab/ipfs-store/node";
|
|
4
5
|
import type { StoreConfiguration } from "@ipab/ipfs-store";
|
|
5
6
|
import { HostError, object, syntax } from "./errors.js";
|
|
@@ -223,6 +224,17 @@ export function parseValue(
|
|
|
223
224
|
);
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
export function rejectLegacySwarmCid(value: string): void {
|
|
228
|
+
try {
|
|
229
|
+
CID.parse(value);
|
|
230
|
+
} catch {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
throw new HostError(
|
|
234
|
+
"The old Swarm CID protocol is unsupported. Ask the Owner for the Swarm configuration URL.",
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
226
238
|
export function swarmUrl(value: string): string {
|
|
227
239
|
try {
|
|
228
240
|
const url = new URL(value);
|
|
@@ -238,8 +250,9 @@ export function swarmUrl(value: string): string {
|
|
|
238
250
|
throw new Error();
|
|
239
251
|
return value;
|
|
240
252
|
} catch {
|
|
253
|
+
rejectLegacySwarmCid(value);
|
|
241
254
|
return syntax(
|
|
242
|
-
"Swarm requires an exact /v1/{scope}/{variable} configuration URL
|
|
255
|
+
"Swarm requires an exact /v1/{scope}/{variable} configuration URL (HTTPS or HTTP loopback), with two 16-character lowercase hex IDs and no credentials, query or fragment.",
|
|
243
256
|
);
|
|
244
257
|
}
|
|
245
258
|
}
|
package/src/context.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { HostError } from "./errors.js";
|
|
2
2
|
import { CHUNK_BYTES, relativePath } from "./space.js";
|
|
3
3
|
|
|
4
|
+
import type { BundleInspection } from "./context-types.js";
|
|
5
|
+
export type { BundleInspection } from "./context-types.js";
|
|
6
|
+
|
|
4
7
|
export interface AppContext {
|
|
5
8
|
readonly appCid: string;
|
|
6
9
|
resolvePin(name: string): Promise<string | undefined>;
|
|
10
|
+
inspectBundle(
|
|
11
|
+
reference: string,
|
|
12
|
+
options?: { signal?: AbortSignal; swarm?: string },
|
|
13
|
+
): Promise<BundleInspection>;
|
|
7
14
|
readFile(
|
|
8
15
|
rootCid: string,
|
|
9
16
|
path: string,
|
|
@@ -127,6 +134,39 @@ export function createContext(port: Port): {
|
|
|
127
134
|
}
|
|
128
135
|
};
|
|
129
136
|
const context: AppContext = {
|
|
137
|
+
async inspectBundle(reference, options = {}) {
|
|
138
|
+
if (!reference || reference.length > 2048)
|
|
139
|
+
throw new HostError(
|
|
140
|
+
"Bundle reference must contain 1..2048 characters.",
|
|
141
|
+
);
|
|
142
|
+
const result = await rpc(
|
|
143
|
+
"inspectBundle",
|
|
144
|
+
{
|
|
145
|
+
reference,
|
|
146
|
+
...(options.swarm ? { swarm: options.swarm } : {}),
|
|
147
|
+
},
|
|
148
|
+
options.signal,
|
|
149
|
+
);
|
|
150
|
+
if (!result || typeof result !== "object")
|
|
151
|
+
throw new HostError("Invalid Bundle inspection response.");
|
|
152
|
+
const data = result as Partial<BundleInspection>;
|
|
153
|
+
if (
|
|
154
|
+
![
|
|
155
|
+
"targetCid",
|
|
156
|
+
"cid",
|
|
157
|
+
"title",
|
|
158
|
+
"description",
|
|
159
|
+
"entry",
|
|
160
|
+
"contentType",
|
|
161
|
+
"schemaCid",
|
|
162
|
+
].every((key) => typeof Reflect.get(data, key) === "string") ||
|
|
163
|
+
!Array.isArray(data.files) ||
|
|
164
|
+
!data.files.every((path) => typeof path === "string") ||
|
|
165
|
+
(data.swarm !== undefined && typeof data.swarm !== "string")
|
|
166
|
+
)
|
|
167
|
+
throw new HostError("Invalid Bundle inspection response.");
|
|
168
|
+
return data as BundleInspection;
|
|
169
|
+
},
|
|
130
170
|
async resolvePin(name) {
|
|
131
171
|
if (!name || name.length > 256)
|
|
132
172
|
throw new HostError("Pin name must contain 1..256 characters.");
|
package/src/ipc.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ChildProcess } from "node:child_process";
|
|
2
2
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
3
|
+
import { openBundle } from "@ipab/bundle";
|
|
3
4
|
import { CID } from "multiformats/cid";
|
|
4
5
|
import { HostError, message, object } from "./errors.js";
|
|
5
|
-
import { requestFrame, type Reply } from "./context.js";
|
|
6
|
+
import { requestFrame, type BundleInspection, type Reply } from "./context.js";
|
|
6
7
|
import { CHUNK_BYTES, type OutputSpace, relativePath } from "./space.js";
|
|
7
8
|
import type { Ownership } from "./history.js";
|
|
8
9
|
|
|
@@ -78,6 +79,11 @@ export class ContextServer {
|
|
|
78
79
|
readonly resolvePin: (name: string) => string | undefined = () => {
|
|
79
80
|
throw new HostError("Pin lookup is unavailable in this context.");
|
|
80
81
|
},
|
|
82
|
+
readonly resolveBundleReference?: (
|
|
83
|
+
reference: string,
|
|
84
|
+
signal: AbortSignal,
|
|
85
|
+
swarm?: string,
|
|
86
|
+
) => Promise<Pick<BundleInspection, "cid" | "targetCid" | "swarm">>,
|
|
81
87
|
) {
|
|
82
88
|
child.on("message", this.receive);
|
|
83
89
|
}
|
|
@@ -156,6 +162,49 @@ export class ContextServer {
|
|
|
156
162
|
): Promise<unknown> {
|
|
157
163
|
signal.throwIfAborted();
|
|
158
164
|
if (operation === "identity") return this.appCid;
|
|
165
|
+
if (operation === "inspectBundle") {
|
|
166
|
+
const request = object(args, "Bundle inspection request");
|
|
167
|
+
if (
|
|
168
|
+
typeof request.reference !== "string" ||
|
|
169
|
+
!request.reference ||
|
|
170
|
+
request.reference.length > 2048
|
|
171
|
+
)
|
|
172
|
+
throw new HostError(
|
|
173
|
+
"Bundle reference must contain 1..2048 characters.",
|
|
174
|
+
);
|
|
175
|
+
if (
|
|
176
|
+
request.swarm !== undefined &&
|
|
177
|
+
(typeof request.swarm !== "string" || request.swarm.length > 2048)
|
|
178
|
+
)
|
|
179
|
+
throw new HostError("Invalid Bundle inspection Swarm.");
|
|
180
|
+
if (!this.resolveBundleReference)
|
|
181
|
+
throw new HostError(
|
|
182
|
+
"Bundle inspection is unavailable in this context.",
|
|
183
|
+
);
|
|
184
|
+
const resolved = await this.resolveBundleReference(
|
|
185
|
+
request.reference,
|
|
186
|
+
signal,
|
|
187
|
+
request.swarm,
|
|
188
|
+
);
|
|
189
|
+
await this.owner.retain([resolved.targetCid, resolved.cid], signal);
|
|
190
|
+
const bundle = await openBundle(CID.parse(resolved.cid), {
|
|
191
|
+
signal,
|
|
192
|
+
resolveCid: (cid, options) =>
|
|
193
|
+
this.store.block.get(cid.toString(), options),
|
|
194
|
+
});
|
|
195
|
+
const result: BundleInspection = {
|
|
196
|
+
...resolved,
|
|
197
|
+
title: bundle.manifest.title,
|
|
198
|
+
description: bundle.manifest.description,
|
|
199
|
+
entry: bundle.manifest.entry,
|
|
200
|
+
contentType: bundle.schema.type.contentType,
|
|
201
|
+
schemaCid: bundle.schemaKey,
|
|
202
|
+
files: [...bundle.files],
|
|
203
|
+
};
|
|
204
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 1024 * 1024)
|
|
205
|
+
throw new HostError("Bundle inspection exceeds 1 MiB.");
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
159
208
|
if (operation === "resolvePin") {
|
|
160
209
|
if (typeof args !== "string" || !args || args.length > 256)
|
|
161
210
|
throw new HostError("Pin name must contain 1..256 characters.");
|