@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
package/dist/commands/s3.js
CHANGED
|
@@ -18,6 +18,8 @@ import { tmpdir } from "node:os";
|
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
20
20
|
import { createDriveSource, fetchObject, LIST_CACHE_MS } from "../s3/drive.js";
|
|
21
|
+
import { freeTrashedName } from "../s3/drive-trashed-name.js";
|
|
22
|
+
import { createStagingStore, SWEEP_EVERY_MS } from "../s3/staging.js";
|
|
21
23
|
import { NmtsError } from "../errors.js";
|
|
22
24
|
import { ensureFolderPath } from "../drive-edit.js";
|
|
23
25
|
import { put } from "./put.js";
|
|
@@ -30,6 +32,17 @@ import { BUCKET } from "../s3/listing.js";
|
|
|
30
32
|
import { BIND_ADDRESS, createGateway, newCredential } from "../s3/server.js";
|
|
31
33
|
/** MinIO's port, which is what most S3 tools already have in their examples. */
|
|
32
34
|
export const DEFAULT_PORT = 9000;
|
|
35
|
+
/** The `id` in the one line `put --json` prints, or undefined when there is none to read. */
|
|
36
|
+
function idIn(line) {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(line);
|
|
39
|
+
const id = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "id") : undefined;
|
|
40
|
+
return typeof id === "string" ? id : undefined;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
function portOf(raw) {
|
|
34
47
|
if (raw === undefined)
|
|
35
48
|
return DEFAULT_PORT;
|
|
@@ -54,6 +67,8 @@ export async function s3(options = {}) {
|
|
|
54
67
|
* takes and afterwards.
|
|
55
68
|
*/
|
|
56
69
|
const stagingRoot = join(tmpdir(), `nmts-s3-${randomUUID()}`);
|
|
70
|
+
// The uploads in pieces, swept on a timer that does not keep the process alive.
|
|
71
|
+
const staging = createStagingStore(stagingRoot, { sweepEveryMs: SWEEP_EVERY_MS });
|
|
57
72
|
// ⛔ THE QUESTION WAS ANSWERED BEFORE THIS STARTED. A gateway cannot ask: its caller is a program
|
|
58
73
|
// and its stdin is not a terminal. `s3` is a medium act (`risk.ts`) — uploads through it spend
|
|
59
74
|
// credits — so the tier gate asked at the start, or the mode waved it through, and every write
|
|
@@ -62,14 +77,19 @@ export async function s3(options = {}) {
|
|
|
62
77
|
/**
|
|
63
78
|
* This account, as the shared drive module takes it.
|
|
64
79
|
*
|
|
65
|
-
* ⛔
|
|
80
|
+
* ⛔ THESE FUNCTIONS ARE THE ONLY THING THIS COMMAND CONTRIBUTES. What an upload DOES — the
|
|
66
81
|
* same-file verdict, the folders above the key, forgetting the cached list — lives in
|
|
67
82
|
* `s3/drive.ts`, so that the gateway a business runs from the SDK and the one a person runs
|
|
68
83
|
* here cannot come to disagree about it.
|
|
69
84
|
*/
|
|
70
85
|
const source = createDriveSource({
|
|
71
86
|
stagingRoot,
|
|
87
|
+
staging,
|
|
88
|
+
bucket: BUCKET,
|
|
72
89
|
writable,
|
|
90
|
+
// ⛔ A FILE ALREADY IN THE DRIVE IS NOT REPLACED FROM HERE. Different bytes at a taken key are
|
|
91
|
+
// refused, and the person deletes the old file first; what is said at start-up below.
|
|
92
|
+
overwrite: "refuse",
|
|
73
93
|
onAlreadyStored: (key) => say(`same ${key} — already stored, nothing sent`),
|
|
74
94
|
account: {
|
|
75
95
|
readList: async () => {
|
|
@@ -81,22 +101,32 @@ export async function s3(options = {}) {
|
|
|
81
101
|
makeFolder: async (folder) => {
|
|
82
102
|
await ensureFolderPath(session, folder);
|
|
83
103
|
},
|
|
84
|
-
|
|
104
|
+
// ⚠ The collision rule is named rather than left to this machine's setting: the drive module
|
|
105
|
+
// decides replace-or-not, and a person's `on-collision` must not quietly change that answer.
|
|
106
|
+
// ⚠ Asked for `--json` so the id of the stored file comes back, and the tag answered is its.
|
|
107
|
+
store: async (path, name, folder, how) => {
|
|
108
|
+
let said = "";
|
|
85
109
|
await put(path, {
|
|
86
110
|
server: options.server,
|
|
87
111
|
network: options.network,
|
|
88
112
|
...(folder === undefined ? {} : { to: folder }),
|
|
89
113
|
name,
|
|
90
|
-
|
|
114
|
+
onCollision: how.replace ? "overwrite" : "rename",
|
|
115
|
+
json: true,
|
|
116
|
+
write: (line) => {
|
|
117
|
+
said = line;
|
|
118
|
+
},
|
|
91
119
|
});
|
|
120
|
+
return { id: idIn(said) };
|
|
92
121
|
},
|
|
93
122
|
trash: async (path) => {
|
|
94
|
-
await rm([path], {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
123
|
+
await rm([path], { server: options.server, network: options.network, write: () => undefined });
|
|
124
|
+
},
|
|
125
|
+
// One run of `rm` is one write to the file list, however many paths it names.
|
|
126
|
+
trashMany: async (paths) => {
|
|
127
|
+
await rm(paths, { server: options.server, network: options.network, write: () => undefined });
|
|
99
128
|
},
|
|
129
|
+
freeTrashedName: (folder, name) => freeTrashedName(session, folder, name),
|
|
100
130
|
fetch: (object, sink) => fetchObject({ server: session.server, bearer: session.apiKey, code: session.code, chain }, object, sink),
|
|
101
131
|
},
|
|
102
132
|
});
|
|
@@ -152,11 +182,15 @@ export async function s3(options = {}) {
|
|
|
152
182
|
}
|
|
153
183
|
await new Promise((resolve) => {
|
|
154
184
|
const stop = () => {
|
|
155
|
-
// Nothing half-uploaded outlives the command that was staging it.
|
|
156
|
-
void removeFile(stagingRoot, { recursive: true, force: true });
|
|
157
185
|
server.close(() => resolve());
|
|
158
186
|
// A client holding a connection open must not keep the process alive after Ctrl-C.
|
|
159
187
|
server.closeAllConnections();
|
|
188
|
+
// Nothing half-uploaded outlives the command that was staging it — but a finish still
|
|
189
|
+
// storing is waited for, rather than having its file removed underneath it.
|
|
190
|
+
void staging
|
|
191
|
+
.close()
|
|
192
|
+
.then(() => removeFile(stagingRoot, { recursive: true, force: true }))
|
|
193
|
+
.catch(() => undefined);
|
|
160
194
|
};
|
|
161
195
|
process.once("SIGINT", stop);
|
|
162
196
|
process.once("SIGTERM", stop);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The share verbs (share · shares · unshare · receive), dispatched here rather than in `main.ts`.
|
|
1
|
+
// The share verbs (share · shares · unshare · receive · link), dispatched here rather than in `main.ts`.
|
|
2
2
|
//
|
|
3
3
|
// ⛔ WHY A SECOND SWITCH. `main.ts` is measured (`check:size`) and had no room for `nmts support`;
|
|
4
4
|
// this block shares a file and an option shape, so it moved as one piece with its comments.
|
|
@@ -11,6 +11,7 @@ export async function runShare(command, args) {
|
|
|
11
11
|
network: args.network,
|
|
12
12
|
json: args.json,
|
|
13
13
|
yes: args.yes,
|
|
14
|
+
as: args.as,
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
case "shares": {
|
|
@@ -40,6 +41,18 @@ export async function runShare(command, args) {
|
|
|
40
41
|
json: args.json,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
44
|
+
case "link": {
|
|
45
|
+
const { link } = await import("./link.js");
|
|
46
|
+
return await link(args.operands[0], args.operands[1], {
|
|
47
|
+
server: args.server,
|
|
48
|
+
network: args.network,
|
|
49
|
+
hideName: args.hideName,
|
|
50
|
+
expires: args.expires,
|
|
51
|
+
out: args.out,
|
|
52
|
+
force: args.force,
|
|
53
|
+
json: args.json,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
43
56
|
default:
|
|
44
57
|
throw new Error(`not a share verb: ${command}`);
|
|
45
58
|
}
|
package/dist/commands/share.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface ShareOptions {
|
|
|
4
4
|
json?: boolean;
|
|
5
5
|
/** `--yes`: the per-attempt answer `share` needs in normal mode (see `share`). */
|
|
6
6
|
yes?: boolean;
|
|
7
|
+
/** `--as <n>`: which live public code sends. Absent = the lowest-numbered live one. */
|
|
8
|
+
as?: string | undefined;
|
|
7
9
|
write?: (line: string) => void;
|
|
8
10
|
}
|
|
9
11
|
export declare function out(options: ShareOptions): (line: string) => void;
|
package/dist/commands/share.js
CHANGED
|
@@ -19,36 +19,17 @@ import { readFileList } from "../manifest.js";
|
|
|
19
19
|
import { BINARY_NAME } from "../product.js";
|
|
20
20
|
import { request, ServerError } from "../api.js";
|
|
21
21
|
import { openSession } from "../session.js";
|
|
22
|
-
import { addressFromTyped, identityMatches, openReceived,
|
|
22
|
+
import { addressFromTyped, identityMatches, openReceived, receivedIndex, sealShare, } from "../share.js";
|
|
23
23
|
import { AAD, DERIVED } from "../crypto.js";
|
|
24
|
+
import { codeNumber, differentCode, notLiveCode, publicCodeRefusal } from "../public-code-refusals.js";
|
|
25
|
+
import { ensureLiveCode, liveCodes } from "../public-codes.js";
|
|
26
|
+
import { shareKeyRing, shareKeysAt } from "../share-codes.js";
|
|
24
27
|
export function out(options) {
|
|
25
28
|
return options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
26
29
|
}
|
|
27
30
|
function b64(bytes) {
|
|
28
31
|
return Buffer.from(bytes).toString("base64url");
|
|
29
32
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Make sure this account has published the identity other people encrypt to.
|
|
32
|
-
*
|
|
33
|
-
* ⛔ IT IS THE SAME BYTES EVERY TIME. The identity is derived from the NMTS key, so a browser
|
|
34
|
-
* and this tool publish something identical for one account — which is why publishing from here
|
|
35
|
-
* cannot claim a different account's place or overwrite anything meaningful.
|
|
36
|
-
*/
|
|
37
|
-
async function ensurePublished(session, identity, address, say, quiet) {
|
|
38
|
-
const seen = await request(session.server, "/v1/account/share-identity", {
|
|
39
|
-
token: session.apiKey,
|
|
40
|
-
});
|
|
41
|
-
const published = typeof seen === "object" && seen !== null && Reflect.get(seen, "published") === true;
|
|
42
|
-
if (published)
|
|
43
|
-
return;
|
|
44
|
-
if (!quiet)
|
|
45
|
-
say(` publishing this account's public code for the first time`);
|
|
46
|
-
await request(session.server, "/v1/account/share-identity", {
|
|
47
|
-
token: session.apiKey,
|
|
48
|
-
method: "PUT",
|
|
49
|
-
body: { share_public_key: b64(identity), share_address: b64(address) },
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
33
|
/** `nmts share <path> <address>` — hand one file to one account. */
|
|
53
34
|
export async function share(target, typedAddress, options = {}) {
|
|
54
35
|
const say = out(options);
|
|
@@ -59,6 +40,7 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
59
40
|
+ `and the code as their \`${BINARY_NAME} public-code\` or account screen prints it.`,
|
|
60
41
|
});
|
|
61
42
|
}
|
|
43
|
+
const sendAs = options.as === undefined ? undefined : codeNumber(options.as, "--as");
|
|
62
44
|
const crypt = await loadCrypto();
|
|
63
45
|
// ⛔ BEFORE ANYTHING ELSE, AND BEFORE THE NETWORK. A typo caught here costs nothing; a typo sent
|
|
64
46
|
// to the recipient lookup asks the server a question about an account that is not ours to ask.
|
|
@@ -91,14 +73,16 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
91
73
|
// allowed at all; `--yes` says THIS file to THIS address. A high act, so the tier gate
|
|
92
74
|
// takes the yes in every mode but skip-permissions, where it hands `--yes` in.
|
|
93
75
|
if (options.yes !== true) {
|
|
94
|
-
|
|
76
|
+
const from = sendAs === undefined ? "" : `, from public code #${sendAs}`;
|
|
77
|
+
say(`Would share "${fullPathOf(index, entry)}" with ${typedAddress}${from}.`);
|
|
95
78
|
say(``);
|
|
96
79
|
say(`⛔ Withdrawing later does not recall it — once the recipient has opened it, they have it.`);
|
|
97
|
-
|
|
80
|
+
const as = sendAs === undefined ? "" : ` --as ${sendAs}`;
|
|
81
|
+
say(`Nothing was shared. To go ahead: ${BINARY_NAME} share ${JSON.stringify(target)} ${typedAddress}${as} --yes`);
|
|
98
82
|
say(`⛔ If a program is reading this on somebody's behalf: show it to them and let them decide.`);
|
|
99
83
|
return 5;
|
|
100
84
|
}
|
|
101
|
-
|
|
85
|
+
let keys = null;
|
|
102
86
|
const derived = crypt.kdf_derive(crypt.account_code_parse(session.code));
|
|
103
87
|
const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
|
|
104
88
|
derived.fill(0);
|
|
@@ -108,7 +92,23 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
108
92
|
dek = crypt.envelope_open(dataKey, new TextEncoder().encode(AAD.dekWrap), new Uint8Array(Buffer.from(entry.dekWrapped, "base64url")));
|
|
109
93
|
digest = crypt.envelope_open(dataKey, new TextEncoder().encode(AAD.contentHash), new Uint8Array(Buffer.from(entry.contentHashCt, "base64url")));
|
|
110
94
|
dataKey.fill(0);
|
|
111
|
-
|
|
95
|
+
// ⛔ A SHARE NEEDS A LIVE CODE TO COME FROM. The first one publishes the next number; a
|
|
96
|
+
// later one sends from the lowest-numbered live code unless `--as` names another.
|
|
97
|
+
const door = { server: session.server, token: session.apiKey };
|
|
98
|
+
const quiet = options.json === true;
|
|
99
|
+
const { list: codes } = await ensureLiveCode(crypt, session.code, door, () => {
|
|
100
|
+
if (!quiet)
|
|
101
|
+
say(` publishing this account's public code for the first time`);
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
throw publicCodeRefusal(error);
|
|
104
|
+
});
|
|
105
|
+
const live = liveCodes(codes);
|
|
106
|
+
const sender = sendAs === undefined ? live[0] : live.find((c) => c.index === sendAs);
|
|
107
|
+
if (sender === undefined)
|
|
108
|
+
throw notLiveCode(sendAs ?? 0);
|
|
109
|
+
keys = shareKeysAt(crypt, session.code, sender.index);
|
|
110
|
+
if (b64(keys.address) !== sender.address)
|
|
111
|
+
throw differentCode();
|
|
112
112
|
const answer = await request(session.server, `/v1/share-recipients/${encodeURIComponent(b64(recipientAddress))}`, { token: session.apiKey });
|
|
113
113
|
const identityB64 = typeof answer === "object" && answer !== null ? Reflect.get(answer, "share_public_key") : null;
|
|
114
114
|
if (typeof identityB64 !== "string") {
|
|
@@ -156,7 +156,7 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
156
156
|
}
|
|
157
157
|
const id = typeof created === "object" && created !== null ? Reflect.get(created, "id") : null;
|
|
158
158
|
if (options.json) {
|
|
159
|
-
say(JSON.stringify({ id, name: entry.name, recipient: crypt.share_address_display(recipientAddress) }));
|
|
159
|
+
say(JSON.stringify({ id, name: entry.name, recipient: crypt.share_address_display(recipientAddress), fromIndex: keys.index }));
|
|
160
160
|
return 0;
|
|
161
161
|
}
|
|
162
162
|
say(`${entry.name} → ${crypt.share_address_display(recipientAddress)}`);
|
|
@@ -166,6 +166,8 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
166
166
|
return 0;
|
|
167
167
|
}
|
|
168
168
|
catch (error) {
|
|
169
|
+
if (error instanceof ServerError && error.code === "PUBLIC_CODE_REVOKED")
|
|
170
|
+
throw publicCodeRefusal(error);
|
|
169
171
|
if (error instanceof ServerError && error.status === 403) {
|
|
170
172
|
throw new NmtsError(error.message, {
|
|
171
173
|
exitCode: 3,
|
|
@@ -179,7 +181,7 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
179
181
|
dataKey.fill(0);
|
|
180
182
|
dek?.fill(0);
|
|
181
183
|
digest?.fill(0);
|
|
182
|
-
keys
|
|
184
|
+
keys?.wipe();
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
/** `nmts shares` — what was shared with this account, and what it shared. */
|
|
@@ -187,12 +189,16 @@ export async function shares(options = {}) {
|
|
|
187
189
|
const say = out(options);
|
|
188
190
|
const session = await openSession({ server: options.server, network: options.network });
|
|
189
191
|
const crypt = await loadCrypto();
|
|
190
|
-
|
|
192
|
+
// Each row opens with the code it came to; each code's keys are derived once.
|
|
193
|
+
const ring = shareKeyRing(crypt, session.code);
|
|
191
194
|
try {
|
|
192
195
|
const received = asReceived(await request(session.server, "/v1/shares/received", { token: session.apiKey }));
|
|
193
|
-
const opened = received.rows.map((row) => openReceived(crypt,
|
|
196
|
+
const opened = received.rows.map((row) => openReceived(crypt, ring.at(receivedIndex(row)), row));
|
|
194
197
|
for (const one of opened)
|
|
195
198
|
one.dek?.fill(0);
|
|
199
|
+
// ⚠ WHICH CODE IT CAME TO is said once any row came to a code other than 0: for an account
|
|
200
|
+
// that has only ever received with one, the line would say nothing.
|
|
201
|
+
const toCode = opened.some((o) => o.toIndex !== 0) ? (o) => `#${o.toIndex} ${ring.at(o.toIndex).display}` : null;
|
|
196
202
|
if (options.json) {
|
|
197
203
|
say(JSON.stringify({
|
|
198
204
|
received: opened.map((o) => ({
|
|
@@ -200,6 +206,8 @@ export async function shares(options = {}) {
|
|
|
200
206
|
name: o.name,
|
|
201
207
|
size: o.size,
|
|
202
208
|
sender: o.sender,
|
|
209
|
+
senderRevoked: o.senderRevoked,
|
|
210
|
+
toIndex: o.toIndex,
|
|
203
211
|
createdAt: o.createdAt,
|
|
204
212
|
problem: o.problem,
|
|
205
213
|
})),
|
|
@@ -213,7 +221,7 @@ export async function shares(options = {}) {
|
|
|
213
221
|
else {
|
|
214
222
|
say(`Shared with this account:`);
|
|
215
223
|
for (const one of opened)
|
|
216
|
-
printRow(say, one);
|
|
224
|
+
printRow(say, one, toCode);
|
|
217
225
|
// ⛔ SAID OUT LOUD. The listing is bounded, and a person who is not told cannot know that
|
|
218
226
|
// what they are looking at is not everything.
|
|
219
227
|
if (received.total > opened.length) {
|
|
@@ -227,17 +235,19 @@ export async function shares(options = {}) {
|
|
|
227
235
|
return 0;
|
|
228
236
|
}
|
|
229
237
|
finally {
|
|
230
|
-
|
|
238
|
+
ring.wipe();
|
|
231
239
|
}
|
|
232
240
|
}
|
|
233
|
-
function printRow(say, one) {
|
|
241
|
+
function printRow(say, one, toCode) {
|
|
234
242
|
if (one.problem !== null) {
|
|
235
243
|
say(` ${one.id} (will not open: ${one.problem})`);
|
|
236
244
|
return;
|
|
237
245
|
}
|
|
238
246
|
const size = one.size === null ? "" : ` ${one.size} bytes`;
|
|
239
247
|
say(` ${one.id} ${one.name ?? ""}${size}`);
|
|
240
|
-
say(` from ${one.sender ?? ""}`);
|
|
248
|
+
say(` from ${one.sender ?? ""}${one.senderRevoked ? " · the sender has revoked this code" : ""}`);
|
|
249
|
+
if (toCode !== null)
|
|
250
|
+
say(` to ${toCode(one)}`);
|
|
241
251
|
}
|
|
242
252
|
export async function unshare(id, options = {}) {
|
|
243
253
|
const say = out(options);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { request } from "../api.js";
|
|
3
3
|
import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
|
|
4
4
|
import { NmtsError } from "../errors.js";
|
|
5
|
+
import { isRecord } from "../guards.js";
|
|
5
6
|
import { readFileList } from "../manifest.js";
|
|
6
7
|
import { BINARY_NAME } from "../product.js";
|
|
7
8
|
import { openSession } from "../session.js";
|
|
@@ -65,12 +66,14 @@ export async function sharesSent(target, options = {}) {
|
|
|
65
66
|
return 0;
|
|
66
67
|
}
|
|
67
68
|
say(`${path} is shared with:`);
|
|
69
|
+
// ⚠ WHICH OF THIS ACCOUNT'S CODES SENT IT is said once any row went from a code other than 0.
|
|
70
|
+
const fromShown = rows.some((row) => isRecord(row) && typeof row["from_index"] === "number" && row["from_index"] !== 0);
|
|
68
71
|
for (const row of rows)
|
|
69
|
-
say(sentLine(row));
|
|
72
|
+
say(sentLine(row, fromShown));
|
|
70
73
|
return 0;
|
|
71
74
|
}
|
|
72
75
|
/** One row of `GET /v1/shares/sent`, as a person reads it. */
|
|
73
|
-
function sentLine(row) {
|
|
76
|
+
function sentLine(row, fromShown) {
|
|
74
77
|
const at = (name) => {
|
|
75
78
|
const value = typeof row === "object" && row !== null ? Reflect.get(row, name) : undefined;
|
|
76
79
|
if (typeof value !== "string") {
|
|
@@ -80,7 +83,9 @@ function sentLine(row) {
|
|
|
80
83
|
}
|
|
81
84
|
return value;
|
|
82
85
|
};
|
|
83
|
-
|
|
86
|
+
const from = fromShown && isRecord(row) && typeof row["from_index"] === "number" ? ` from #${row["from_index"]}` : "";
|
|
87
|
+
const gone = isRecord(row) && row["recipient_code_revoked"] === true ? " · the recipient has revoked this code" : "";
|
|
88
|
+
return `${at("recipient_address")} since ${utcDay(at("created_at"))}${from} share ${at("id")}${gone}`;
|
|
84
89
|
}
|
|
85
90
|
/** The UTC day of an RFC 3339 instant, `YYYY-MM-DD`. */
|
|
86
91
|
function utcDay(instant) {
|
package/dist/crypto-surface.d.ts
CHANGED
|
@@ -109,6 +109,23 @@ export interface CryptoGlue {
|
|
|
109
109
|
* that opens this. That is why the claimed sender may only be printed AFTER this succeeds.
|
|
110
110
|
*/
|
|
111
111
|
share_unwrap_dek(shareKemSeed: Uint8Array, shareAuthSecret: Uint8Array, shareSigSeed: Uint8Array, senderPublic: Uint8Array, envelope: Uint8Array, itemId: string, nameShareCt: Uint8Array, contentHashShareCt: Uint8Array): Uint8Array;
|
|
112
|
+
/**
|
|
113
|
+
* The three secrets of sharing identity `index` (1 and up), from the 32-byte `shareIdRoot` slice
|
|
114
|
+
* of the derivation (NCF-3 §5.9): `kem(32) || auth(32) || sig(32)`. Throws for 0 — identity 0's
|
|
115
|
+
* secrets are the three share slices of the derivation itself.
|
|
116
|
+
*/
|
|
117
|
+
share_id_seeds(shareIdRoot: Uint8Array, index: number): Uint8Array;
|
|
118
|
+
/** Identity `index`'s published bundle. At 0 it is `share_public_key`, byte for byte. */
|
|
119
|
+
share_public_key_at(shareKemSeed: Uint8Array, shareAuthSecret: Uint8Array, shareSigSeed: Uint8Array, index: number): Uint8Array;
|
|
120
|
+
/** Identity `index`'s 16-byte public code, from its signing seed alone. */
|
|
121
|
+
share_address_at(shareSigSeed: Uint8Array, index: number): Uint8Array;
|
|
122
|
+
/** `share_wrap_dek` sending as identity `senderIndex`: the envelope carries that identity's code. */
|
|
123
|
+
share_wrap_dek_as(senderAuthSecret: Uint8Array, senderSigSeed: Uint8Array, senderIndex: number, recipientPublic: Uint8Array, recipientAddress: Uint8Array, dek: Uint8Array, itemId: string, nameShareCt: Uint8Array, contentHashShareCt: Uint8Array): Uint8Array;
|
|
124
|
+
/**
|
|
125
|
+
* `share_unwrap_dek` as identity `index`. An envelope does not say which of the account's
|
|
126
|
+
* identities it was sealed to; opened as the wrong one it throws exactly like anybody else's.
|
|
127
|
+
*/
|
|
128
|
+
share_unwrap_dek_as(shareKemSeed: Uint8Array, shareAuthSecret: Uint8Array, shareSigSeed: Uint8Array, index: number, senderPublic: Uint8Array, envelope: Uint8Array, itemId: string, nameShareCt: Uint8Array, contentHashShareCt: Uint8Array): Uint8Array;
|
|
112
129
|
/**
|
|
113
130
|
* Open one NCF-3 envelope: key, the associated data it was sealed with, the envelope bytes.
|
|
114
131
|
*
|
|
@@ -223,6 +240,24 @@ export interface CryptoGlue {
|
|
|
223
240
|
* would look like the account's money had vanished.
|
|
224
241
|
*/
|
|
225
242
|
wallet_seed_for(walletRoot: Uint8Array, index: number): Uint8Array;
|
|
243
|
+
/**
|
|
244
|
+
* The secp256k1 private key (32 bytes) of EVM wallet `index`, from the same wallet root
|
|
245
|
+
* (NCF-3 §1.9) — the key that pays Filecoin itself for NMTS Heavy on the self-paid path.
|
|
246
|
+
*
|
|
247
|
+
* ⛔ KEY MATERIAL, LIKE `wallet_seed_for`. The address is computed from it on this side
|
|
248
|
+
* (`heavy-evm.ts`); the key is wiped by whoever asked for it.
|
|
249
|
+
*/
|
|
250
|
+
evm_key_for(walletRoot: Uint8Array, index: number): Uint8Array;
|
|
251
|
+
/** A fresh 32-byte public-link secret `S` (NCF-3 §5.8), drawn inside the engine. */
|
|
252
|
+
link_generate_secret(): Uint8Array;
|
|
253
|
+
/** `E(S, "nmts/v3/link-wrap", DEK)`, 104 bytes. */
|
|
254
|
+
link_wrap_dek(linkSecret: Uint8Array, dek: Uint8Array): Uint8Array;
|
|
255
|
+
/** The file key back from a link's wrapped key; throws when `S` or the envelope was changed. */
|
|
256
|
+
link_unwrap_dek(linkSecret: Uint8Array, wrapped: Uint8Array): Uint8Array;
|
|
257
|
+
/** `E(dataKey, "nmts/v3/link-secret", S)` — the owner's copy, so the link can be printed again. */
|
|
258
|
+
link_seal_secret(dataKey: Uint8Array, linkSecret: Uint8Array): Uint8Array;
|
|
259
|
+
/** `S` back from the owner's copy. */
|
|
260
|
+
link_open_secret(dataKey: Uint8Array, sealed: Uint8Array): Uint8Array;
|
|
226
261
|
}
|
|
227
262
|
export declare function isCryptoGlue(value: unknown): value is CryptoGlue;
|
|
228
263
|
/** Which of the required functions this object does not have. Empty means it is the engine. */
|
package/dist/crypto-surface.js
CHANGED
|
@@ -43,6 +43,19 @@ const REQUIRED = [
|
|
|
43
43
|
// "this function is missing" said at load time is a different day's problem from
|
|
44
44
|
// `undefined is not a function` in the middle of deriving somebody's second account.
|
|
45
45
|
"derive_ai_account_code",
|
|
46
|
+
// Numbered sharing identities (NCF-3 §5.9). Required for the same reason: an engine without them
|
|
47
|
+
// cannot make, show or open with any public code but the first.
|
|
48
|
+
"share_id_seeds",
|
|
49
|
+
"share_public_key_at",
|
|
50
|
+
"share_address_at",
|
|
51
|
+
"share_wrap_dek_as",
|
|
52
|
+
"share_unwrap_dek_as",
|
|
53
|
+
// The EVM wallets (NCF-3 §1.9), required for the same reason: `put --tier heavy --pay evm` and
|
|
54
|
+
// `heavy wallet` cannot run on a build without it.
|
|
55
|
+
"evm_key_for",
|
|
56
|
+
// Public links (NCF-3 §5.8): `link make`, `link list` and `link open` cannot run without them.
|
|
57
|
+
"link_generate_secret", "link_wrap_dek", "link_unwrap_dek",
|
|
58
|
+
"link_seal_secret", "link_open_secret",
|
|
46
59
|
];
|
|
47
60
|
export function isCryptoGlue(value) {
|
|
48
61
|
return missingExports(value).length === 0;
|
package/dist/crypto.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export declare const AAD: {
|
|
|
29
29
|
readonly shareName: "nmts/v3/share-name";
|
|
30
30
|
/** Seals the shared file's plaintext digest for the recipient, under the same file key. */
|
|
31
31
|
readonly shareContentHash: "nmts/v3/share-content-hash";
|
|
32
|
+
/** Seals a handover file's list of stored pieces under the file's own key (NCF-3 §5.6), so a file
|
|
33
|
+
* that is intercepted does not even say where the ciphertext is. */
|
|
34
|
+
readonly handoverParts: "nmts/v3/handover-parts";
|
|
32
35
|
/** Seals the RECOVERY LIST — where every file's bytes are (NRM §1). ⛔ The old spelling of the
|
|
33
36
|
* artefact's name is frozen INTO the separator: every list ever sealed is bound to these bytes. */
|
|
34
37
|
readonly recoveryMap: "nmts/v3/recovery-map";
|
|
@@ -73,6 +76,11 @@ export declare const DERIVED: {
|
|
|
73
76
|
* directly — and what it expands to is 20 bytes that ARE an NMTS key, not a seed.
|
|
74
77
|
*/
|
|
75
78
|
readonly aiAccountRoot: readonly [256, 288];
|
|
79
|
+
/**
|
|
80
|
+
* The parent of this account's numbered sharing identities, 1 and up (NCF-3 §5.9). Identity 0
|
|
81
|
+
* is the three share slices above. Appended at the TAIL on 2026-09-23, for the same reason.
|
|
82
|
+
*/
|
|
83
|
+
readonly shareIdRoot: readonly [288, 320];
|
|
76
84
|
};
|
|
77
85
|
/**
|
|
78
86
|
* The engine, loaded once by whichever host this program registered.
|
package/dist/crypto.js
CHANGED
|
@@ -47,6 +47,9 @@ export const AAD = {
|
|
|
47
47
|
shareName: "nmts/v3/share-name",
|
|
48
48
|
/** Seals the shared file's plaintext digest for the recipient, under the same file key. */
|
|
49
49
|
shareContentHash: "nmts/v3/share-content-hash",
|
|
50
|
+
/** Seals a handover file's list of stored pieces under the file's own key (NCF-3 §5.6), so a file
|
|
51
|
+
* that is intercepted does not even say where the ciphertext is. */
|
|
52
|
+
handoverParts: "nmts/v3/handover-parts",
|
|
50
53
|
/** Seals the RECOVERY LIST — where every file's bytes are (NRM §1). ⛔ The old spelling of the
|
|
51
54
|
* artefact's name is frozen INTO the separator: every list ever sealed is bound to these bytes. */
|
|
52
55
|
recoveryMap: "nmts/v3/recovery-map",
|
|
@@ -91,6 +94,11 @@ export const DERIVED = {
|
|
|
91
94
|
* directly — and what it expands to is 20 bytes that ARE an NMTS key, not a seed.
|
|
92
95
|
*/
|
|
93
96
|
aiAccountRoot: [256, 288],
|
|
97
|
+
/**
|
|
98
|
+
* The parent of this account's numbered sharing identities, 1 and up (NCF-3 §5.9). Identity 0
|
|
99
|
+
* is the three share slices above. Appended at the TAIL on 2026-09-23, for the same reason.
|
|
100
|
+
*/
|
|
101
|
+
shareIdRoot: [288, 320],
|
|
94
102
|
};
|
|
95
103
|
/**
|
|
96
104
|
* The engine, loaded once by whichever host this program registered.
|
package/dist/download-part.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { CryptoGlue } from "./crypto.ts";
|
|
2
2
|
import { type ReadOptions } from "./walrus.ts";
|
|
3
|
+
import type { HeavyCopy } from "./shared/lib/api/types-heavy.ts";
|
|
3
4
|
export interface PartView {
|
|
4
5
|
part_index: number;
|
|
5
6
|
storage_kind: number;
|
|
6
7
|
network?: number;
|
|
7
8
|
blob_id: string;
|
|
8
9
|
patch_id?: string;
|
|
10
|
+
/** Network 1 (NMTS Heavy): the storage companies keeping a whole copy each, in the order to ask. */
|
|
11
|
+
copies?: HeavyCopy[];
|
|
9
12
|
}
|
|
10
13
|
export interface PartsResponse {
|
|
11
14
|
size: number;
|
|
@@ -33,8 +36,36 @@ export declare function fetchPart(part: PartView, chain: string, read: ReadOptio
|
|
|
33
36
|
*
|
|
34
37
|
* ⛔ `finish()` IS WHAT CATCHES A PART CUT SHORT. Every chunk that arrived authenticates; only the
|
|
35
38
|
* end-of-stream check knows the rest is missing. Skipping it would accept a truncated part.
|
|
39
|
+
* ⚠ The one caller that skips it is a RANGE that asked for the part's first chunks only
|
|
40
|
+
* (`prefix`): it wants no byte past them, and every byte it keeps is authenticated.
|
|
36
41
|
*
|
|
37
42
|
* ⛔ THE ENGINE-SIDE SESSION IS FREED ON EVERY PATH OUT, including a failure: it holds the file
|
|
38
43
|
* key until it is, and a download that failed is exactly when nobody comes back to tidy up.
|
|
39
44
|
*/
|
|
40
|
-
export declare function openPart(crypt: CryptoGlue, dek: Uint8Array, part: PartView, sealed: Uint8Array,
|
|
45
|
+
export declare function openPart(crypt: CryptoGlue, dek: Uint8Array, part: PartView, sealed: Uint8Array, position: {
|
|
46
|
+
index: number;
|
|
47
|
+
total: number;
|
|
48
|
+
}, remaining: number, emit: (body: Uint8Array) => Promise<void>, prefix?: boolean): Promise<number>;
|
|
49
|
+
/** What a part's sealed header says about it, once it is known to be this file's. */
|
|
50
|
+
export interface PartHeader {
|
|
51
|
+
/** Plaintext bytes the stream declares — the whole part, padding included. */
|
|
52
|
+
declared: number;
|
|
53
|
+
/** Plaintext bytes per chunk. */
|
|
54
|
+
chunkSize: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Read a part's 72-byte header, and refuse it unless it is THIS file's part at THIS position.
|
|
58
|
+
*
|
|
59
|
+
* ⛔ THE ENGINE CHECKS THE KEY COMMITMENT FIRST. It covers every field read below, so a length or a
|
|
60
|
+
* position that passes here was sealed under this file's key — a range that leaves the parts
|
|
61
|
+
* before it out works out where it starts from these numbers, and a lie in them would put
|
|
62
|
+
* authentic bytes at the wrong place in the answer.
|
|
63
|
+
*
|
|
64
|
+
* ⛔ THE POSITION IS THE ONE THE CALLER IS READING INTO, never the part's own claim: every part of a
|
|
65
|
+
* file is sealed under one key, so a part served in another's place passes the commitment and is
|
|
66
|
+
* caught only by comparing where it says it is with where it is being used.
|
|
67
|
+
*/
|
|
68
|
+
export declare function checkedHeader(crypt: CryptoGlue, dek: Uint8Array, part: PartView, header: Uint8Array, position: {
|
|
69
|
+
index: number;
|
|
70
|
+
total: number;
|
|
71
|
+
}): PartHeader;
|