@needmoretruth/nmts-cli 0.45.0 → 0.47.0
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/AGENTS.md +8 -8
- package/CHANGELOG.md +78 -0
- package/README.ko.md +6 -3
- package/README.md +31 -11
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +19 -1
- package/dist/args.js +14 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/autonomy.js +3 -3
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/handover.d.ts +15 -0
- package/dist/commands/handover.js +376 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/link.d.ts +12 -0
- package/dist/commands/link.js +121 -0
- package/dist/commands/ls.d.ts +5 -0
- package/dist/commands/ls.js +9 -1
- package/dist/commands/public-code-manage.d.ts +24 -0
- package/dist/commands/public-code-manage.js +217 -0
- package/dist/commands/public-code.d.ts +12 -1
- package/dist/commands/public-code.js +140 -45
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put.d.ts +2 -2
- package/dist/commands/put.js +8 -7
- package/dist/commands/receive.js +14 -8
- package/dist/commands/s3.js +44 -10
- package/dist/commands/share-dispatch.js +14 -1
- package/dist/commands/share.d.ts +2 -0
- package/dist/commands/share.js +45 -35
- package/dist/commands/shares-sent.js +8 -3
- package/dist/crypto-surface.d.ts +35 -0
- package/dist/crypto-surface.js +13 -0
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +8 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/handover-codes.d.ts +25 -0
- package/dist/handover-codes.js +106 -0
- package/dist/handover.d.ts +62 -0
- package/dist/handover.js +217 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +13 -4
- package/dist/help.js +24 -3
- package/dist/links.d.ts +58 -0
- package/dist/links.js +206 -0
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +13 -10
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/reads.js +20 -6
- package/dist/mcp-tools/share.js +47 -1
- package/dist/mcp-tools/tiers.js +16 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +23 -0
- package/dist/portable.js +19 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-code-activity.d.ts +35 -0
- package/dist/public-code-activity.js +88 -0
- package/dist/public-code-refusals.d.ts +25 -0
- package/dist/public-code-refusals.js +87 -0
- package/dist/public-codes.d.ts +76 -0
- package/dist/public-codes.js +182 -0
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +55 -1
- package/dist/risk.js +55 -3
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share-codes.d.ts +40 -0
- package/dist/share-codes.js +151 -0
- package/dist/share.d.ts +39 -0
- package/dist/share.js +54 -13
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/public-link.d.ts +41 -0
- package/dist/shared/lib/share/public-link.js +107 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +9 -4
- package/dist/upload-wallet-put.js +16 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/handover.md +54 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/link.md +27 -0
- package/docs/commands/mcp.md +2 -1
- package/docs/commands/public-code.md +25 -6
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +15 -1
- package/docs/commands/share.md +8 -3
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +106 -4
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +286 -3
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +12 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The directory side of `nmts push`: what is on this machine, and what the drive already holds.
|
|
2
|
+
//
|
|
3
|
+
// ⚠ MOVED OUT OF `push.ts` UNCHANGED (2026-09-24) so both tiers read one tree the same way — that
|
|
4
|
+
// file had reached the length gate the day NMTS Heavy needed the same walk and the same
|
|
5
|
+
// "already there" rule. The rules are the ones `push.ts` states in its header: dot-files stay
|
|
6
|
+
// unless asked for, symbolic links are not followed, and a name already in its folder is skipped.
|
|
7
|
+
import { readdirSync, statSync } from "node:fs";
|
|
8
|
+
import { basename, join, resolve } from "node:path";
|
|
9
|
+
import { normaliseName, normalisePath } from "../drive-paths.js";
|
|
10
|
+
import { NmtsError } from "../errors.js";
|
|
11
|
+
import { BINARY_NAME } from "../product.js";
|
|
12
|
+
/** The directory as typed: refused when it is missing or a file, then walked. */
|
|
13
|
+
export function localTree(target, to, hidden) {
|
|
14
|
+
const root = resolve(target);
|
|
15
|
+
let rootStat;
|
|
16
|
+
try {
|
|
17
|
+
rootStat = statSync(root);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new NmtsError(`There is nothing at ${root}.`, { exitCode: 4 });
|
|
21
|
+
}
|
|
22
|
+
if (!rootStat.isDirectory()) {
|
|
23
|
+
throw new NmtsError(`${root} is a file.`, {
|
|
24
|
+
exitCode: 4,
|
|
25
|
+
nextStep: `Nothing was sent. \`${BINARY_NAME} put\` uploads one file.`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const under = normalisePath(to ?? "");
|
|
29
|
+
const base = under === "" ? basename(root) : `${under}/${basename(root)}`;
|
|
30
|
+
return { root, found: walk(root, base, hidden) };
|
|
31
|
+
}
|
|
32
|
+
/** Which found files the drive already holds, which to send, and the folders already known. */
|
|
33
|
+
export function splitAlready(entries, found) {
|
|
34
|
+
const taken = new Set(entries
|
|
35
|
+
.filter((e) => e.deletedAt === undefined)
|
|
36
|
+
.map((e) => `${e.parentId ?? ""} ${normaliseName(e.name)}`));
|
|
37
|
+
const folderIds = new Map();
|
|
38
|
+
const already = [];
|
|
39
|
+
const todo = [];
|
|
40
|
+
for (const one of found) {
|
|
41
|
+
const parentId = knownFolderId(entries, one.folder);
|
|
42
|
+
if (parentId !== undefined)
|
|
43
|
+
folderIds.set(one.folder, parentId);
|
|
44
|
+
const there = parentId !== undefined && taken.has(`${parentId ?? ""} ${normaliseName(one.name)}`);
|
|
45
|
+
(there ? already : todo).push(one);
|
|
46
|
+
}
|
|
47
|
+
return { folderIds, already, todo };
|
|
48
|
+
}
|
|
49
|
+
export { walk as filesUnderDirectory };
|
|
50
|
+
/** Every file under a local directory, with the drive folder each one belongs in. */
|
|
51
|
+
function walk(dir, driveFolder, hidden) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const items = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
if (!hidden && item.name.startsWith("."))
|
|
56
|
+
continue;
|
|
57
|
+
const local = join(dir, item.name);
|
|
58
|
+
// ⛔ SYMBOLIC LINKS ARE NOT FOLLOWED. One pointing at a parent directory would walk forever,
|
|
59
|
+
// and one pointing outside would upload a file nobody meant to send.
|
|
60
|
+
if (item.isSymbolicLink())
|
|
61
|
+
continue;
|
|
62
|
+
if (item.isDirectory()) {
|
|
63
|
+
out.push(...walk(local, `${driveFolder}/${item.name}`, hidden));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!item.isFile())
|
|
67
|
+
continue;
|
|
68
|
+
const size = statSync(local).size;
|
|
69
|
+
// An empty file has nothing to store, and the storage network would refuse the reservation.
|
|
70
|
+
if (size === 0)
|
|
71
|
+
continue;
|
|
72
|
+
out.push({ local, folder: driveFolder, name: item.name, size });
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** The id of a drive folder path that ALREADY exists, or undefined when it does not. */
|
|
77
|
+
function knownFolderId(entries, folder) {
|
|
78
|
+
if (folder === "")
|
|
79
|
+
return null;
|
|
80
|
+
let parentId = null;
|
|
81
|
+
for (const name of folder.split("/")) {
|
|
82
|
+
const there = entries.find((e) => e.parentId === parentId &&
|
|
83
|
+
e.kind === 0 &&
|
|
84
|
+
e.deletedAt === undefined &&
|
|
85
|
+
normaliseName(e.name) === normaliseName(name));
|
|
86
|
+
if (there === undefined)
|
|
87
|
+
return undefined;
|
|
88
|
+
parentId = there.id;
|
|
89
|
+
}
|
|
90
|
+
return parentId;
|
|
91
|
+
}
|
package/dist/commands/push.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { openSession } from "../session.ts";
|
|
2
|
-
|
|
2
|
+
import { type HeavyFlags } from "./put-payer.ts";
|
|
3
|
+
import { filesUnderDirectory, localTree, splitAlready, type PlannedFile } from "./push-tree.ts";
|
|
4
|
+
export interface PushOptions extends HeavyFlags {
|
|
3
5
|
server?: string | undefined;
|
|
4
6
|
network?: string | undefined;
|
|
5
7
|
/** Where the tree goes in the drive. The top of the drive when absent. */
|
|
@@ -35,18 +37,7 @@ export interface PushOptions {
|
|
|
35
37
|
*/
|
|
36
38
|
send?: (one: PlannedFile, parentId: string | null) => Promise<string>;
|
|
37
39
|
}
|
|
38
|
-
/** One local file, and where it goes in the drive. */
|
|
39
|
-
export interface PlannedFile {
|
|
40
|
-
/** Absolute path on this machine. */
|
|
41
|
-
local: string;
|
|
42
|
-
/** Folder path inside the drive. */
|
|
43
|
-
folder: string;
|
|
44
|
-
name: string;
|
|
45
|
-
size: number;
|
|
46
|
-
}
|
|
47
40
|
export declare function push(target: string | undefined, options?: PushOptions): Promise<number>;
|
|
48
41
|
/** The folder id for a drive path, made if it is not there yet. Remembered for the next file. */
|
|
49
42
|
export declare function folderFor(session: Awaited<ReturnType<typeof openSession>>, known: Map<string, string | null>, folder: string): Promise<string | null>;
|
|
50
|
-
export {
|
|
51
|
-
/** Every file under a local directory, with the drive folder each one belongs in. */
|
|
52
|
-
declare function walk(dir: string, driveFolder: string, hidden: boolean): PlannedFile[];
|
|
43
|
+
export { filesUnderDirectory, localTree, splitAlready, type PlannedFile };
|
package/dist/commands/push.js
CHANGED
|
@@ -16,10 +16,7 @@
|
|
|
16
16
|
// ⛔ NOTHING HIDDEN IS SENT. Entries whose name begins with a dot are left alone unless they are
|
|
17
17
|
// asked for: a directory of source code carries credentials in exactly those files, and an
|
|
18
18
|
// upload goes to a public storage network. `--hidden` includes them.
|
|
19
|
-
import { readdirSync, statSync } from "node:fs";
|
|
20
|
-
import { basename, join, resolve } from "node:path";
|
|
21
19
|
import { DERIVED, loadCrypto } from "../crypto.js";
|
|
22
|
-
import { normaliseName, normalisePath } from "../drive-paths.js";
|
|
23
20
|
import { NmtsError } from "../errors.js";
|
|
24
21
|
import { addEntry } from "../manifest-write.js";
|
|
25
22
|
import { parseAsked } from "../collision.js";
|
|
@@ -38,6 +35,8 @@ import { CREDIT_BYTES, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "../uploa
|
|
|
38
35
|
import { createBlobProtocol, readCurrentEpoch } from "../walrus-write.js";
|
|
39
36
|
import { ensureFolderPath } from "../drive-edit.js";
|
|
40
37
|
import { payerOf, refuseWalletOnlyOptions } from "./put.js";
|
|
38
|
+
import { tierOf } from "./put-payer.js";
|
|
39
|
+
import { filesUnderDirectory, localTree, splitAlready } from "./push-tree.js";
|
|
41
40
|
export async function push(target, options = {}) {
|
|
42
41
|
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
43
42
|
if (target === undefined || target === "") {
|
|
@@ -46,6 +45,8 @@ export async function push(target, options = {}) {
|
|
|
46
45
|
nextStep: `\`${BINARY_NAME} push <directory>\` — a directory on this machine.`,
|
|
47
46
|
});
|
|
48
47
|
}
|
|
48
|
+
if (tierOf(options) === "heavy")
|
|
49
|
+
return (await import("./push-heavy.js")).pushHeavy(target, options);
|
|
49
50
|
const payer = payerOf(options.pay);
|
|
50
51
|
if (payer === "wallet")
|
|
51
52
|
refuseDepositWithWallet(options.deposit);
|
|
@@ -59,23 +60,7 @@ export async function push(target, options = {}) {
|
|
|
59
60
|
nextStep: `Nothing was sent. Leave --storage off to buy new storage for each file.`,
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
|
-
const root =
|
|
63
|
-
let rootStat;
|
|
64
|
-
try {
|
|
65
|
-
rootStat = statSync(root);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
throw new NmtsError(`There is nothing at ${root}.`, { exitCode: 4 });
|
|
69
|
-
}
|
|
70
|
-
if (!rootStat.isDirectory()) {
|
|
71
|
-
throw new NmtsError(`${root} is a file.`, {
|
|
72
|
-
exitCode: 4,
|
|
73
|
-
nextStep: `Nothing was sent. \`${BINARY_NAME} put\` uploads one file.`,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const under = normalisePath(options.to ?? "");
|
|
77
|
-
const base = under === "" ? basename(root) : `${under}/${basename(root)}`;
|
|
78
|
-
const found = walk(root, base, options.hidden === true);
|
|
63
|
+
const { root, found } = localTree(target, options.to, options.hidden === true);
|
|
79
64
|
if (found.length === 0) {
|
|
80
65
|
if (options.json) {
|
|
81
66
|
say(JSON.stringify({ files: 0, uploaded: 0, skipped: 0, credits: 0 }));
|
|
@@ -92,20 +77,7 @@ export async function push(target, options = {}) {
|
|
|
92
77
|
const rule = paddingRuleOf(list.manifest?.settings);
|
|
93
78
|
// ⛔ WHAT IS ALREADY THERE IS DECIDED BEFORE ANYTHING IS PRICED, so the number printed is what
|
|
94
79
|
// this run will actually spend rather than what a first run would have.
|
|
95
|
-
const
|
|
96
|
-
const taken = new Set(entries
|
|
97
|
-
.filter((e) => e.deletedAt === undefined)
|
|
98
|
-
.map((e) => `${e.parentId ?? ""} ${normaliseName(e.name)}`));
|
|
99
|
-
const folderIds = new Map();
|
|
100
|
-
const already = [];
|
|
101
|
-
const todo = [];
|
|
102
|
-
for (const one of found) {
|
|
103
|
-
const parentId = knownFolderId(entries, one.folder);
|
|
104
|
-
if (parentId !== undefined)
|
|
105
|
-
folderIds.set(one.folder, parentId);
|
|
106
|
-
const there = parentId !== undefined && taken.has(`${parentId ?? ""} ${normaliseName(one.name)}`);
|
|
107
|
-
(there ? already : todo).push(one);
|
|
108
|
-
}
|
|
80
|
+
const { folderIds, already, todo } = splitAlready(list.manifest?.entries ?? [], found);
|
|
109
81
|
const credits = todo.reduce((sum, one) => sum + planAndPrice(one.size, partSize, rule).credits, 0);
|
|
110
82
|
const bytes = todo.reduce((sum, one) => sum + one.size, 0);
|
|
111
83
|
// Per FILE, not per run: every file in the tree sets the same amount aside.
|
|
@@ -265,46 +237,4 @@ export async function folderFor(session, known, folder) {
|
|
|
265
237
|
known.set(folder, parentId);
|
|
266
238
|
return parentId;
|
|
267
239
|
}
|
|
268
|
-
|
|
269
|
-
function knownFolderId(entries, folder) {
|
|
270
|
-
if (folder === "")
|
|
271
|
-
return null;
|
|
272
|
-
let parentId = null;
|
|
273
|
-
for (const name of folder.split("/")) {
|
|
274
|
-
const there = entries.find((e) => e.parentId === parentId &&
|
|
275
|
-
e.kind === 0 &&
|
|
276
|
-
e.deletedAt === undefined &&
|
|
277
|
-
normaliseName(e.name) === normaliseName(name));
|
|
278
|
-
if (there === undefined)
|
|
279
|
-
return undefined;
|
|
280
|
-
parentId = there.id;
|
|
281
|
-
}
|
|
282
|
-
return parentId;
|
|
283
|
-
}
|
|
284
|
-
export { walk as filesUnderDirectory };
|
|
285
|
-
/** Every file under a local directory, with the drive folder each one belongs in. */
|
|
286
|
-
function walk(dir, driveFolder, hidden) {
|
|
287
|
-
const out = [];
|
|
288
|
-
const items = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
289
|
-
for (const item of items) {
|
|
290
|
-
if (!hidden && item.name.startsWith("."))
|
|
291
|
-
continue;
|
|
292
|
-
const local = join(dir, item.name);
|
|
293
|
-
// ⛔ SYMBOLIC LINKS ARE NOT FOLLOWED. One pointing at a parent directory would walk forever,
|
|
294
|
-
// and one pointing outside would upload a file nobody meant to send.
|
|
295
|
-
if (item.isSymbolicLink())
|
|
296
|
-
continue;
|
|
297
|
-
if (item.isDirectory()) {
|
|
298
|
-
out.push(...walk(local, `${driveFolder}/${item.name}`, hidden));
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
if (!item.isFile())
|
|
302
|
-
continue;
|
|
303
|
-
const size = statSync(local).size;
|
|
304
|
-
// An empty file has nothing to store, and the storage network would refuse the reservation.
|
|
305
|
-
if (size === 0)
|
|
306
|
-
continue;
|
|
307
|
-
out.push({ local, folder: driveFolder, name: item.name, size });
|
|
308
|
-
}
|
|
309
|
-
return out;
|
|
310
|
-
}
|
|
240
|
+
export { filesUnderDirectory, localTree, splitAlready };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Session } from "../session.ts";
|
|
2
|
+
import { type AccountSettings } from "../shared/lib/drive/manifest-settings.ts";
|
|
3
|
+
import { type HeavyPayer } from "./heavy-run.ts";
|
|
4
|
+
import { type PutOptions } from "./put.ts";
|
|
5
|
+
/** Who would pay, by address, for a dry run — derived offline, nothing signed. */
|
|
6
|
+
export declare function payerAddressOf(session: Session, payer: HeavyPayer, options: PutOptions, settings: AccountSettings | undefined): Promise<Record<string, unknown>>;
|
|
7
|
+
/** The dry run's words for a person: one plan line per payer, and the closing line. */
|
|
8
|
+
export declare function sayDryRun(say: (line: string) => void, name: string, facts: Record<string, unknown>): void;
|
|
9
|
+
export declare function putHeavy(target: string | undefined, options: PutOptions): Promise<number>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// `nmts put <file> --tier heavy` — one file into NMTS Heavy: whole copies kept by two separate
|
|
2
|
+
// storage companies on Filecoin. Paid with credits (the default), with WAL from the wallet
|
|
3
|
+
// (`--pay wallet`), or — developer mode — by this key's own EVM wallet (`--pay evm`).
|
|
4
|
+
//
|
|
5
|
+
// ⛔ EVERYTHING BUT THE ONE FILE IS `heavy-run.ts`: the payer, the review, the agreement, the progress
|
|
6
|
+
// and the failure words are the same for `push --tier heavy`, so they live once.
|
|
7
|
+
import { basename, resolve } from "node:path";
|
|
8
|
+
import { parseAsked } from "../collision.js";
|
|
9
|
+
import { loadCrypto } from "../crypto.js";
|
|
10
|
+
import { NmtsError } from "../errors.js";
|
|
11
|
+
import { HEAVY_COPY } from "../heavy-copy.js";
|
|
12
|
+
import { evmAddressFor, evmIndexOf } from "../heavy-evm.js";
|
|
13
|
+
import { copiesOf } from "../heavy-self-pay.js";
|
|
14
|
+
import { paddingRuleOf, readFileList } from "../manifest.js";
|
|
15
|
+
import { resolveNetwork } from "../network.js";
|
|
16
|
+
import { BINARY_NAME } from "../product.js";
|
|
17
|
+
import { Progress, silentSink } from "../progress.js";
|
|
18
|
+
import { stderrSink } from "../progress-node.js";
|
|
19
|
+
import { openSession } from "../session.js";
|
|
20
|
+
import { activeWalletOf } from "../shared/lib/drive/manifest-settings.js";
|
|
21
|
+
import { fileSource } from "../upload-file-node.js";
|
|
22
|
+
import { measureLocal } from "../upload-price-node.js";
|
|
23
|
+
import { walletAddress } from "../wallet.js";
|
|
24
|
+
import { payingWalletIndex } from "../wallet-pay-index.js";
|
|
25
|
+
import { heavyDryRun, heavyPayerOf, recordHeavy, refuseHeavyClashes, runHeavy, termDaysOf } from "./heavy-run.js";
|
|
26
|
+
import { folderIdFor } from "./put.js";
|
|
27
|
+
/** Who would pay, by address, for a dry run — derived offline, nothing signed. */
|
|
28
|
+
export async function payerAddressOf(session, payer, options, settings) {
|
|
29
|
+
if (payer === "evm") {
|
|
30
|
+
return { payer: await evmAddressFor(session.code, evmIndexOf(options.evmWallet)), copies: copiesOf(options.copies) };
|
|
31
|
+
}
|
|
32
|
+
if (payer === "credits")
|
|
33
|
+
return {};
|
|
34
|
+
const wallet = await payingWalletIndex({ wallet: options.wallet, readActiveWallet: async () => activeWalletOf(settings) });
|
|
35
|
+
return { wallet: await walletAddress(session.code, wallet), termDays: termDaysOf(options.days) };
|
|
36
|
+
}
|
|
37
|
+
/** The dry run's words for a person: one plan line per payer, and the closing line. */
|
|
38
|
+
export function sayDryRun(say, name, facts) {
|
|
39
|
+
const bytes = typeof facts["bytes"] === "number" ? facts["bytes"] : 0;
|
|
40
|
+
if (typeof facts["credits"] === "number")
|
|
41
|
+
say(HEAVY_COPY.creditsPlan(name, bytes, facts["credits"]));
|
|
42
|
+
if (typeof facts["payer"] === "string")
|
|
43
|
+
say(HEAVY_COPY.evmPlan(name, bytes, Number(facts["copies"]), facts["payer"]));
|
|
44
|
+
if (typeof facts["wallet"] === "string")
|
|
45
|
+
say(HEAVY_COPY.walletDryPlan(name, bytes, Number(facts["termDays"]), facts["wallet"]));
|
|
46
|
+
say(HEAVY_COPY.dryRunEnd);
|
|
47
|
+
}
|
|
48
|
+
export async function putHeavy(target, options) {
|
|
49
|
+
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
50
|
+
const payer = heavyPayerOf(options.pay);
|
|
51
|
+
refuseHeavyClashes(options, payer);
|
|
52
|
+
if (target === undefined || target === "") {
|
|
53
|
+
throw new NmtsError("Say which file to put.", {
|
|
54
|
+
exitCode: 2,
|
|
55
|
+
nextStep: `\`${BINARY_NAME} put <file>\` — a path on this machine.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const localPath = resolve(target);
|
|
59
|
+
const size = measureLocal(localPath);
|
|
60
|
+
const session = await openSession({ server: options.server, network: options.network });
|
|
61
|
+
const network = resolveNetwork(session.server, session.network);
|
|
62
|
+
const asked = parseAsked(options.onCollision);
|
|
63
|
+
const list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
|
|
64
|
+
const rule = paddingRuleOf(list.manifest?.settings);
|
|
65
|
+
const name = options.name ?? basename(localPath);
|
|
66
|
+
const destination = (options.to ?? "").replace(/^\.?\//, "").replace(/\/$/, "");
|
|
67
|
+
const parentId = folderIdFor(options.to, list.manifest?.entries ?? []);
|
|
68
|
+
const file = { source: fileSource(localPath, size), name, parentId, destination };
|
|
69
|
+
if (options.dryRun === true) {
|
|
70
|
+
const facts = { ...heavyDryRun([file], rule, payer), ...(await payerAddressOf(session, payer, options, list.manifest?.settings)) };
|
|
71
|
+
if (options.json)
|
|
72
|
+
say(JSON.stringify({ name, ...facts }));
|
|
73
|
+
else
|
|
74
|
+
sayDryRun(say, name, facts);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
const json = options.json === true;
|
|
78
|
+
const report = await runHeavy({
|
|
79
|
+
session,
|
|
80
|
+
network,
|
|
81
|
+
crypt: await loadCrypto(),
|
|
82
|
+
rule,
|
|
83
|
+
settings: list.manifest?.settings,
|
|
84
|
+
say,
|
|
85
|
+
json,
|
|
86
|
+
progress: new Progress(json ? silentSink() : stderrSink(), "uploading"),
|
|
87
|
+
}, [file], payer, options);
|
|
88
|
+
const done = report.files[0];
|
|
89
|
+
if (done === undefined)
|
|
90
|
+
throw new NmtsError(HEAVY_COPY.commitNoId, { nextStep: HEAVY_COPY.commitNoIdNext });
|
|
91
|
+
const added = await recordHeavy(session, done, asked);
|
|
92
|
+
if (json) {
|
|
93
|
+
say(JSON.stringify({
|
|
94
|
+
id: done.itemId,
|
|
95
|
+
name: added.name,
|
|
96
|
+
bytes: size,
|
|
97
|
+
sealedBytes: done.sealedBytes,
|
|
98
|
+
parts: done.parts,
|
|
99
|
+
...report.facts,
|
|
100
|
+
renamed: added.name !== name,
|
|
101
|
+
...(added.replaced === null ? {} : { replacedIntoTrash: added.replaced }),
|
|
102
|
+
fileListVersion: added.seq,
|
|
103
|
+
}));
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
say(` saved as ${added.name}`);
|
|
107
|
+
if (typeof report.facts["expiryEpoch"] === "number")
|
|
108
|
+
say(HEAVY_COPY.stored(report.facts["expiryEpoch"]));
|
|
109
|
+
if (added.replaced !== null) {
|
|
110
|
+
say(``);
|
|
111
|
+
say(` A file called ${name} was already there. It is in the trash now — ${BINARY_NAME} restore`);
|
|
112
|
+
say(` brings it back for 30 days. This machine is set to overwrite: ${BINARY_NAME} on-collision`);
|
|
113
|
+
}
|
|
114
|
+
else if (added.name !== name) {
|
|
115
|
+
say(``);
|
|
116
|
+
say(` A file called ${name} was already there, so this one was numbered rather than`);
|
|
117
|
+
say(` replacing it. This machine is set to rename: ${BINARY_NAME} on-collision`);
|
|
118
|
+
}
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StorageTier } from "../shared/lib/storage-tier.ts";
|
|
1
2
|
/** Who pays, or a refusal for a payer this tool does not know. */
|
|
2
3
|
export declare function payerOf(pay: string | undefined): "credits" | "wallet";
|
|
3
4
|
/** The options that only mean something when the wallet pays, refused when it does not. */
|
|
@@ -8,3 +9,23 @@ export declare function refuseWalletOnlyOptions(options: {
|
|
|
8
9
|
trustServerTipAddress?: boolean;
|
|
9
10
|
from?: string | undefined;
|
|
10
11
|
}): void;
|
|
12
|
+
/** What NMTS Heavy adds to an upload command line: the tier, and the self-paid knobs. */
|
|
13
|
+
export interface HeavyFlags {
|
|
14
|
+
/** `--tier standard|heavy`. Absent = standard. */
|
|
15
|
+
tier?: string | undefined;
|
|
16
|
+
/** `--tier heavy --pay evm`: how many copies, 1..12 (default 2). */
|
|
17
|
+
copies?: string | undefined;
|
|
18
|
+
/** `--tier heavy --pay evm`: which storage companies, by id, comma-separated. */
|
|
19
|
+
providers?: string | undefined;
|
|
20
|
+
/** `--tier heavy --pay evm`: which of this key's EVM wallets pays. Absent = 0. */
|
|
21
|
+
evmWallet?: string | undefined;
|
|
22
|
+
/** `--tier heavy --pay wallet`: how many days to keep it, 1..365 (default 28). */
|
|
23
|
+
days?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Which tier this upload goes to — the same reader the browser and the SDK use — and a refusal for
|
|
27
|
+
* every option that means nothing on that tier. Decided before a file is measured.
|
|
28
|
+
*/
|
|
29
|
+
export declare function tierOf(options: HeavyFlags & {
|
|
30
|
+
pay?: string | undefined;
|
|
31
|
+
}): StorageTier;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// ⚠ They moved out of `put.ts` on 2026-09-16 (`--wallet` joined them and that file has a ceiling).
|
|
8
8
|
// `put.ts` re-exports them, so `push.ts` and the tests spell the same path they always did.
|
|
9
9
|
import { NmtsError } from "../errors.js";
|
|
10
|
+
import { HEAVY_COPY } from "../heavy-copy.js";
|
|
11
|
+
import { DEFAULT_STORAGE_TIER, parseStorageTier } from "../shared/lib/storage-tier.js";
|
|
10
12
|
/** Who pays, or a refusal for a payer this tool does not know. */
|
|
11
13
|
export function payerOf(pay) {
|
|
12
14
|
if (pay === undefined || pay === "credits")
|
|
@@ -51,3 +53,25 @@ export function refuseWalletOnlyOptions(options) {
|
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Which tier this upload goes to — the same reader the browser and the SDK use — and a refusal for
|
|
58
|
+
* every option that means nothing on that tier. Decided before a file is measured.
|
|
59
|
+
*/
|
|
60
|
+
export function tierOf(options) {
|
|
61
|
+
let tier;
|
|
62
|
+
try {
|
|
63
|
+
tier = options.tier === undefined ? DEFAULT_STORAGE_TIER : parseStorageTier(options.tier);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new NmtsError(error instanceof Error ? error.message : String(error), { exitCode: 2 });
|
|
67
|
+
}
|
|
68
|
+
if (tier === "standard") {
|
|
69
|
+
if (options.pay === "evm")
|
|
70
|
+
throw new NmtsError(HEAVY_COPY.evmNeedsHeavy, { exitCode: 2 });
|
|
71
|
+
for (const [flag, value] of [["--copies", options.copies], ["--providers", options.providers], ["--evm-wallet", options.evmWallet], ["--days", options.days]]) {
|
|
72
|
+
if (value !== undefined)
|
|
73
|
+
throw new NmtsError(HEAVY_COPY.heavyOnlyFlag(flag), { exitCode: 2 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return tier;
|
|
77
|
+
}
|
package/dist/commands/put.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ManifestEntry } from "../shared/lib/drive/manifest-codec.ts";
|
|
2
|
-
export interface PutOptions {
|
|
2
|
+
export interface PutOptions extends HeavyFlags {
|
|
3
3
|
server?: string | undefined;
|
|
4
4
|
network?: string | undefined;
|
|
5
5
|
/** The name it gets in the drive. Defaults to the local file's own name. */
|
|
@@ -54,7 +54,7 @@ export interface PutOptions {
|
|
|
54
54
|
onStored?: (itemId: string, savedAs: string) => void;
|
|
55
55
|
}
|
|
56
56
|
/** Who pays, and the options that lose their meaning under that answer — the rule is in `put-payer.ts`; this is its one road. */
|
|
57
|
-
import { payerOf, refuseWalletOnlyOptions } from "./put-payer.ts";
|
|
57
|
+
import { payerOf, refuseWalletOnlyOptions, type HeavyFlags } from "./put-payer.ts";
|
|
58
58
|
export { payerOf, refuseWalletOnlyOptions };
|
|
59
59
|
/**
|
|
60
60
|
* The folder id `--to` names, or null for the root. Refuses rather than guessing.
|
package/dist/commands/put.js
CHANGED
|
@@ -27,15 +27,15 @@ import { paddingRuleOf, readFileList } from "../manifest.js";
|
|
|
27
27
|
import { resolveNetwork } from "../network.js";
|
|
28
28
|
import { BINARY_NAME } from "../product.js";
|
|
29
29
|
import { resolveServer } from "../server.js";
|
|
30
|
-
import {
|
|
30
|
+
import { forgetUpload } from "../upload-run.js";
|
|
31
31
|
import { createUploadApi } from "../upload-api.js";
|
|
32
|
-
import {
|
|
32
|
+
import { uploadFile } from "../upload-file.js";
|
|
33
33
|
import { fileSource } from "../upload-file-node.js";
|
|
34
34
|
import { CREDIT_BYTES, creditsFor, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "../upload-price.js";
|
|
35
35
|
import { measureLocal } from "../upload-price-node.js";
|
|
36
36
|
import { createBlobProtocol, readCurrentEpoch } from "../walrus-write.js";
|
|
37
37
|
/** Who pays, and the options that lose their meaning under that answer — the rule is in `put-payer.ts`; this is its one road. */
|
|
38
|
-
import { payerOf, refuseWalletOnlyOptions } from "./put-payer.js";
|
|
38
|
+
import { payerOf, refuseWalletOnlyOptions, tierOf } from "./put-payer.js";
|
|
39
39
|
export { payerOf, refuseWalletOnlyOptions };
|
|
40
40
|
/**
|
|
41
41
|
* The folder id `--to` names, or null for the root. Refuses rather than guessing.
|
|
@@ -69,6 +69,9 @@ export function folderIdFor(wanted, entries) {
|
|
|
69
69
|
return folder.id;
|
|
70
70
|
}
|
|
71
71
|
export async function put(target, options = {}) {
|
|
72
|
+
// NMTS Heavy is its own road (`put-heavy.ts`), taken before the preview picture: Heavy refuses one.
|
|
73
|
+
if (tierOf(options) === "heavy")
|
|
74
|
+
return (await import("./put-heavy.js")).putHeavy(target, options);
|
|
72
75
|
if (options.thumbnail === true || options.thumbnailFile !== undefined) {
|
|
73
76
|
return (await import("./put-thumbnail.js")).putWithThumbnail(target, options, put);
|
|
74
77
|
}
|
|
@@ -267,10 +270,8 @@ export async function put(target, options = {}) {
|
|
|
267
270
|
options.onStored?.(result.itemId, added.name);
|
|
268
271
|
// ⛔ ONLY NOW, AND EVERY PART. Until the entry is in the list the file is paid for and invisible,
|
|
269
272
|
// and the records are the only thing that lets a second run finish the job without spending
|
|
270
|
-
// again.
|
|
271
|
-
await
|
|
272
|
-
for (const record of partKeysOf(result.fileKey, result.parts))
|
|
273
|
-
await clearReservation(record);
|
|
273
|
+
// again. The order they are forgotten in is `forgetUpload`'s.
|
|
274
|
+
await forgetUpload(result.fileKey, result.parts);
|
|
274
275
|
// ⛔ THE DISPLACED FILE IS TOLD TO THE SERVER ONLY NOW, and only after the new one is in the
|
|
275
276
|
// list. Until this line the person still had the file they started with.
|
|
276
277
|
// ⚠ A failure here leaves it hidden in this account's trash while the server still counts it as
|
package/dist/commands/receive.js
CHANGED
|
@@ -20,7 +20,8 @@ import { destinationFor } from "../safe-path.js";
|
|
|
20
20
|
import { resolveNetwork } from "../network.js";
|
|
21
21
|
import { BINARY_NAME } from "../product.js";
|
|
22
22
|
import { openSession } from "../session.js";
|
|
23
|
-
import { openReceived, openSharedDigest,
|
|
23
|
+
import { openReceived, openSharedDigest, receivedIndex } from "../share.js";
|
|
24
|
+
import { shareKeyRing } from "../share-codes.js";
|
|
24
25
|
import { processStdout, STDOUT_TARGET } from "../stdout.js";
|
|
25
26
|
export async function receive(id, options = {}) {
|
|
26
27
|
const toStdout = options.out === "-";
|
|
@@ -34,7 +35,8 @@ export async function receive(id, options = {}) {
|
|
|
34
35
|
const session = await openSession({ server: options.server, network: options.network });
|
|
35
36
|
const chain = resolveNetwork(session.server, session.network);
|
|
36
37
|
const crypt = await loadCrypto();
|
|
37
|
-
|
|
38
|
+
// The row names which of this account's codes it came to; that code's keys open it.
|
|
39
|
+
const ring = shareKeyRing(crypt, session.code);
|
|
38
40
|
try {
|
|
39
41
|
// ⛔ THE ROW IS FOUND IN THE LISTING, not asked for by id. The listing is what carries the
|
|
40
42
|
// sender's published identity, and without that identity the envelope cannot be
|
|
@@ -52,7 +54,7 @@ export async function receive(id, options = {}) {
|
|
|
52
54
|
nextStep: `Nothing was written. \`${BINARY_NAME} shares\` lists what is there.`,
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
|
-
const opened = openReceived(crypt,
|
|
57
|
+
const opened = openReceived(crypt, ring.at(receivedIndex(row)), row);
|
|
56
58
|
if (opened.dek === null || opened.name === null) {
|
|
57
59
|
throw new NmtsError(`That share ${opened.problem ?? "did not open"}.`, {
|
|
58
60
|
exitCode: 1,
|
|
@@ -81,9 +83,9 @@ export async function receive(id, options = {}) {
|
|
|
81
83
|
? null
|
|
82
84
|
: options.out !== undefined
|
|
83
85
|
? resolve(options.out)
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
: // ⛔ The name is the SENDER'S choice, so it lands in a directory by its last segment only:
|
|
87
|
+
// `../x` or an absolute path must not put a file outside where this tool was run.
|
|
88
|
+
destinationFor(options.intoDir ?? ".", opened.name);
|
|
87
89
|
// ⛔ `--force` has nothing to overwrite on the stdout branch and is ignored there on purpose.
|
|
88
90
|
// On the disk branch the file streams into a temporary name beside the destination and is
|
|
89
91
|
// renamed into place only once the sender's digest matches, so a share that turns out to be
|
|
@@ -109,17 +111,21 @@ export async function receive(id, options = {}) {
|
|
|
109
111
|
name: opened.name,
|
|
110
112
|
bytes: fetched.byteCount,
|
|
111
113
|
from: opened.sender,
|
|
114
|
+
senderRevoked: opened.senderRevoked,
|
|
115
|
+
toIndex: opened.toIndex,
|
|
112
116
|
parts: fetched.partCount,
|
|
113
117
|
out: destination ?? STDOUT_TARGET,
|
|
114
118
|
}));
|
|
115
119
|
return 0;
|
|
116
120
|
}
|
|
117
121
|
say(`${opened.name} ${fetched.byteCount} bytes`);
|
|
118
|
-
say(` from ${opened.sender ?? ""}`);
|
|
122
|
+
say(` from ${opened.sender ?? ""}${opened.senderRevoked ? " · the sender has revoked this code" : ""}`);
|
|
123
|
+
if (opened.toIndex !== 0)
|
|
124
|
+
say(` to #${opened.toIndex} ${ring.at(opened.toIndex).display}`);
|
|
119
125
|
say(` checked against the hash the sender sealed with it`);
|
|
120
126
|
return 0;
|
|
121
127
|
}
|
|
122
128
|
finally {
|
|
123
|
-
|
|
129
|
+
ring.wipe();
|
|
124
130
|
}
|
|
125
131
|
}
|