@needmoretruth/nmts-cli 0.55.0 → 0.57.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/CHANGELOG.md +20 -0
- package/README.ko.md +9 -1
- package/README.md +9 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/put-wallet.js +11 -11
- package/dist/commands/receive.js +30 -87
- package/dist/commands/recovery-list.js +3 -2
- package/dist/commands/share.d.ts +7 -0
- package/dist/commands/share.js +58 -180
- package/dist/commands/shares-sent.js +4 -29
- package/dist/crypto-surface.d.ts +2 -0
- package/dist/crypto-surface.js +4 -7
- package/dist/links.d.ts +5 -0
- package/dist/links.js +6 -1
- package/dist/platform-sign.d.ts +7 -1
- package/dist/platform-sign.js +12 -1
- package/dist/portable.d.ts +4 -0
- package/dist/portable.js +5 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/recovery-assemble.d.ts +4 -11
- package/dist/recovery-assemble.js +25 -106
- package/dist/recovery-build.d.ts +7 -1
- package/dist/recovery-build.js +15 -11
- package/dist/recovery-seq.d.ts +2 -2
- package/dist/recovery-seq.js +30 -23
- package/dist/recovery.d.ts +92 -0
- package/dist/recovery.js +202 -0
- package/dist/sharing-inbox.d.ts +52 -0
- package/dist/sharing-inbox.js +146 -0
- package/dist/sharing.d.ts +52 -0
- package/dist/sharing.js +218 -0
- package/dist/upload-file.d.ts +2 -0
- package/dist/upload-file.js +6 -0
- package/dist/upload-recovery-patch.d.ts +65 -0
- package/dist/upload-recovery-patch.js +250 -0
- package/dist/upload-steps.js +4 -1
- package/dist/upload-wallet-plan.d.ts +4 -0
- package/dist/upload-wallet-plan.js +18 -8
- package/dist/upload-wallet-put.d.ts +6 -2
- package/dist/upload-wallet-put.js +30 -17
- package/dist/upload-wallet.d.ts +4 -1
- package/dist/upload-wallet.js +11 -3
- package/dist/upload-wire.d.ts +22 -0
- package/dist/upload-wire.js +2 -0
- package/dist/walrus-write.js +12 -0
- package/docs/commands/put.md +5 -1
- package/package.json +9 -1
- package/server.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
Each version's entry is what changed for the person or the program using `nmts`. The product's own
|
|
4
4
|
update history, which covers the site and the server too, is at https://nmts.me/updates.
|
|
5
5
|
|
|
6
|
+
## 0.57.0 — 2026-11-10
|
|
7
|
+
|
|
8
|
+
- A program can share a file the way `nmts share` does: `@needmoretruth/nmts-cli/share` exports
|
|
9
|
+
sending a share, listing what came in and what went out, receiving one and withdrawing one, and
|
|
10
|
+
runs in a browser as well as in Node. `nmts share`, `shares`, `receive` and `unshare` print what
|
|
11
|
+
they printed before.
|
|
12
|
+
- Delegation tokens have a sixth scope, `share`. With it, and the NMTS key's proof on the same
|
|
13
|
+
request, a token can share a file and make a public link. Listing shares and links needs
|
|
14
|
+
`files_read`; withdrawing a share or cutting a link needs `files_write`.
|
|
15
|
+
|
|
16
|
+
## 0.56.0 — 2026-11-10
|
|
17
|
+
|
|
18
|
+
- With the account's storage copy of the recovery list switched on, `put --pay wallet` of a one-part
|
|
19
|
+
file under 64 MiB onto new storage uploads the newest recovery list in the same quilt, as the web
|
|
20
|
+
app does. The standalone recovery program then finds that list with the NMTS key alone. The WAL in
|
|
21
|
+
the review includes the list, and a list that cannot go along never stops the upload.
|
|
22
|
+
- A program can build the recovery list without the command: `@needmoretruth/nmts-cli/recovery`
|
|
23
|
+
exports `makeRecoveryList`, `readRecoveryCopy` and `setRecoveryCopy`, and runs in a browser as well
|
|
24
|
+
as in Node. `nmts recovery-list` writes the same file as before.
|
|
25
|
+
|
|
6
26
|
## 0.55.0 — 2026-11-10
|
|
7
27
|
|
|
8
28
|
- Uploads (`put`, `push`) keep working when every company's upload relay is down. The order is now
|
package/README.ko.md
CHANGED
|
@@ -50,7 +50,7 @@ nmts --help
|
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
52
|
npm install -g github:needmoretruth/nmts-cli # 기본 브랜치
|
|
53
|
-
npm install -g github:needmoretruth/nmts-cli#v0.
|
|
53
|
+
npm install -g github:needmoretruth/nmts-cli#v0.57.0 # 버전을 고정할 때
|
|
54
54
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -362,6 +362,14 @@ NMTS 키는 들어 있지 않습니다. `kit`은 그 목록과 NMTS 키를 한
|
|
|
362
362
|
목록을 잃은 계정의 파일 목록을 서버의 줄로 다시 짓습니다. 키·해시·날짜·크기는 돌아오고 이름과
|
|
363
363
|
폴더는 돌아오지 않습니다.
|
|
364
364
|
|
|
365
|
+
계정에서 복구 목록의 Walrus 사본을 켜 두었으면(웹 앱에서, 또는 SDK의 `setRecoveryCopy(true)`로)
|
|
366
|
+
64 MiB 미만의 한 조각 파일을 새 저장 자원에 `put --pay wallet`으로 올릴 때 최신 목록이 같은 묶음에
|
|
367
|
+
함께 올라갑니다. 그러면 복구 프로그램이 `--find`로 NMTS 키만 가지고 그 목록을 찾습니다. 검토에
|
|
368
|
+
나오는 값에는 목록이 들어 있습니다. NMTS 키에서 나오지 않는 지갑으로 낸 사본은 이 방법으로
|
|
369
|
+
찾지 못합니다. 명령 없이 프로그램에서 같은 파일을 만들 수도 있습니다.
|
|
370
|
+
`@needmoretruth/nmts-cli/recovery`가 `makeRecoveryList` · `readRecoveryCopy` · `setRecoveryCopy`를
|
|
371
|
+
내보내고, Node와 브라우저에서 모두 돕니다.
|
|
372
|
+
|
|
365
373
|
`nmts rollback`은 파일 목록의 이전 버전을 현재 버전으로 되돌립니다 — 현재 목록이 열리지 않을
|
|
366
374
|
때를 위한 것입니다. 새 버전이 더한 파일은 그 뒤 목록에서 빠지지만 바이트는 그대로 저장돼 있고,
|
|
367
375
|
`nmts rebuild`가 목록에 없는 파일을 찾습니다. `nmts unlock rollback`으로 열기 전에는 잠겨 있고 매번 `--yes`가 필요합니다.
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ default branch, from a pinned version, or from the tarball attached to the
|
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
53
|
npm install -g github:needmoretruth/nmts-cli # the default branch
|
|
54
|
-
npm install -g github:needmoretruth/nmts-cli#v0.
|
|
54
|
+
npm install -g github:needmoretruth/nmts-cli#v0.57.0 # a pinned version
|
|
55
55
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
56
56
|
```
|
|
57
57
|
|
|
@@ -396,6 +396,14 @@ machine, checks it against the release's checksum file before making it runnable
|
|
|
396
396
|
anything on your PATH. `rebuild` reconstructs a file list from the server's rows for an account
|
|
397
397
|
that has lost its own: keys, hashes, dates and sizes come back; names and folders do not.
|
|
398
398
|
|
|
399
|
+
With the account's storage copy of the recovery list switched on (in the web app, or with the
|
|
400
|
+
SDK's `setRecoveryCopy(true)`), `put --pay wallet` of a one-part file under 64 MiB onto new storage
|
|
401
|
+
uploads the newest list in the same quilt. The recovery program then finds it with `--find` and the
|
|
402
|
+
NMTS key alone. The WAL in the review includes the list. A copy paid from a wallet the NMTS key does
|
|
403
|
+
not derive cannot be found that way. A program can build the same file without the command:
|
|
404
|
+
`@needmoretruth/nmts-cli/recovery` exports `makeRecoveryList`, `readRecoveryCopy` and
|
|
405
|
+
`setRecoveryCopy`, and runs in a browser as well as in Node.
|
|
406
|
+
|
|
399
407
|
`nmts rollback` puts the previous version of the file list back as the current one, for the case
|
|
400
408
|
where the current one will not open. Files the newer version added are out of the list afterwards —
|
|
401
409
|
their bytes are still stored, and `nmts rebuild` finds files the list does not name. It is locked
|
package/dist/artifact-about.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const CRYPTO_SPEC_URL = "https://github.com/needmoretruth/nmts-re
|
|
|
11
11
|
* is the field's own contract — what the writer says about itself — and a person holding two
|
|
12
12
|
* copies of one account's artefacts can then tell which program made each.
|
|
13
13
|
*/
|
|
14
|
-
export declare const WRITTEN_BY = "nmts-cli 0.
|
|
14
|
+
export declare const WRITTEN_BY = "nmts-cli 0.57.0";
|
|
15
15
|
/** Which of the three artefacts a wrapper is. A reader holding several can sort them. */
|
|
16
16
|
export type ArtifactKind = "recovery-list" | "file-list" | "recovery-kit";
|
|
17
17
|
/**
|
|
@@ -202,29 +202,29 @@ export async function uploadOneWithWallet(ctx, file, options) {
|
|
|
202
202
|
if (ctx.json)
|
|
203
203
|
return;
|
|
204
204
|
describeUploadReview(say, {
|
|
205
|
-
name: review.name,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
days: review.days,
|
|
210
|
-
endEpoch: review.endEpoch,
|
|
211
|
-
walNeeded: review.budget.walNeededFrost,
|
|
212
|
-
tipMist: review.tipMist,
|
|
213
|
-
storage: review.storage,
|
|
214
|
-
heldResources: review.heldResources,
|
|
215
|
-
networkCopy: ctx.networkCopy,
|
|
205
|
+
name: review.name, bytes: review.bytes, sealedBytes: review.sealedBytes, parts: review.parts,
|
|
206
|
+
epochs: review.epochs, days: review.days, endEpoch: review.endEpoch,
|
|
207
|
+
walNeeded: review.budget.walNeededFrost, tipMist: review.tipMist, storage: review.storage,
|
|
208
|
+
heldResources: review.heldResources, networkCopy: ctx.networkCopy, carriesRecoveryList: review.carriesRecoveryList,
|
|
216
209
|
}, review.budget);
|
|
217
210
|
},
|
|
218
211
|
agree: (review) => {
|
|
219
212
|
requireWalletGrant("seal", { walFrost: review.budget.walNeededFrost, suiMist: review.budget.suiNeededMist }, new Date(options.now ?? Date.now()));
|
|
220
213
|
},
|
|
221
214
|
onSpend: recordWalletSpend,
|
|
215
|
+
// The copy is a passenger: why it stayed behind is said, and the upload goes on.
|
|
216
|
+
onRecoveryProblem: (message) => (ctx.json ? process.stderr.write(`${message}\n`) : say(` ⚠ ${message}`)),
|
|
222
217
|
});
|
|
223
218
|
}
|
|
224
219
|
finally {
|
|
225
220
|
ctx.progress.done();
|
|
226
221
|
}
|
|
227
222
|
const facts = factsOf(outcome.review);
|
|
223
|
+
if (outcome.kind === "uploaded") {
|
|
224
|
+
facts["recoveryList"] = outcome.recoveryList;
|
|
225
|
+
if (outcome.recoveryList !== null && !ctx.json)
|
|
226
|
+
say(` Recovery list ${outcome.recoveryList} went up with this file.`);
|
|
227
|
+
}
|
|
228
228
|
if (outcome.kind === "review") {
|
|
229
229
|
if (ctx.json)
|
|
230
230
|
say(JSON.stringify({ dryRun: true, name: outcome.review.name, ...facts, signed: false }));
|
package/dist/commands/receive.js
CHANGED
|
@@ -11,18 +11,15 @@
|
|
|
11
11
|
// key and nothing else of the sender's, which is exactly why the check works at all: a storage
|
|
12
12
|
// network that returned different bytes cannot produce a matching hash without the key.
|
|
13
13
|
import { resolve } from "node:path";
|
|
14
|
-
import { request } from "../api.js";
|
|
15
|
-
import { loadCrypto } from "../crypto.js";
|
|
16
|
-
import { fetchWithKey } from "../download.js";
|
|
17
14
|
import { fileSink, stdoutSink } from "../download-sink-node.js";
|
|
18
15
|
import { NmtsError } from "../errors.js";
|
|
19
16
|
import { destinationFor } from "../safe-path.js";
|
|
20
17
|
import { resolveNetwork } from "../network.js";
|
|
21
18
|
import { BINARY_NAME } from "../product.js";
|
|
22
19
|
import { openSession } from "../session.js";
|
|
23
|
-
import {
|
|
24
|
-
import { shareKeyRing } from "../share-codes.js";
|
|
20
|
+
import { receiveShare } from "../sharing.js";
|
|
25
21
|
import { processStdout, STDOUT_TARGET } from "../stdout.js";
|
|
22
|
+
import { shareAccountOf } from "./share.js";
|
|
26
23
|
export async function receive(id, options = {}) {
|
|
27
24
|
const toStdout = options.out === "-";
|
|
28
25
|
const say = options.write ?? ((line) => (toStdout ? process.stderr : process.stdout).write(`${line}\n`));
|
|
@@ -33,99 +30,45 @@ export async function receive(id, options = {}) {
|
|
|
33
30
|
});
|
|
34
31
|
}
|
|
35
32
|
const session = await openSession({ server: options.server, network: options.network });
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// sender's published identity, and without that identity the envelope cannot be
|
|
43
|
-
// authenticated — an unauthenticated open is not one worth doing.
|
|
44
|
-
const answer = await request(session.server, "/v1/shares/received", {
|
|
45
|
-
token: session.apiKey,
|
|
46
|
-
});
|
|
47
|
-
const rows = typeof answer === "object" && answer !== null ? Reflect.get(answer, "shares") : null;
|
|
48
|
-
if (!Array.isArray(rows))
|
|
49
|
-
throw new NmtsError("The server did not list any shares.");
|
|
50
|
-
const row = rows.find((candidate) => typeof candidate === "object" && candidate !== null && Reflect.get(candidate, "id") === id);
|
|
51
|
-
if (row === undefined) {
|
|
52
|
-
throw new NmtsError(`Nothing shared with this account has the id "${id}".`, {
|
|
53
|
-
exitCode: 4,
|
|
54
|
-
nextStep: `Nothing was written. \`${BINARY_NAME} shares\` lists what is there.`,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const opened = openReceived(crypt, ring.at(receivedIndex(row)), row);
|
|
58
|
-
if (opened.dek === null || opened.name === null) {
|
|
59
|
-
throw new NmtsError(`That share ${opened.problem ?? "did not open"}.`, {
|
|
60
|
-
exitCode: 1,
|
|
61
|
-
nextStep: "Nothing was written. The sender can withdraw it and share the file again.",
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (opened.size === null) {
|
|
65
|
-
// ⛔ NOT A GUESS. Without the sender's number there is nothing to trim the stored bytes back
|
|
66
|
-
// to, and taking the stored length would write padding into the end of the file.
|
|
67
|
-
opened.dek.fill(0);
|
|
68
|
-
throw new NmtsError("The sender did not record this file's real length.", {
|
|
69
|
-
exitCode: 1,
|
|
70
|
-
nextStep: "Nothing was written. It was shared by an older client; ask them to share it again from " +
|
|
71
|
-
"a current one, which seals the length beside the name.",
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const expected = openSharedDigest(crypt, opened.dek, opened.digestCt);
|
|
75
|
-
if (expected === null) {
|
|
76
|
-
opened.dek.fill(0);
|
|
77
|
-
throw new NmtsError("This share's content hash did not open with the file's own key.", {
|
|
78
|
-
exitCode: 1,
|
|
79
|
-
nextStep: "Nothing was written. There would be nothing to check the bytes against.",
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const destination = toStdout
|
|
33
|
+
const account = shareAccountOf(session, resolveNetwork(session.server, session.network));
|
|
34
|
+
// ⛔ THE ROW IS FOUND IN THE LISTING, not asked for by id, and the length written is the one the
|
|
35
|
+
// sender sealed — both inside `receiveShare`, for the reasons at the top of this file.
|
|
36
|
+
let destination = null;
|
|
37
|
+
const got = await receiveShare(account, id, ({ name }) => {
|
|
38
|
+
destination = toStdout
|
|
83
39
|
? null
|
|
84
40
|
: options.out !== undefined
|
|
85
41
|
? resolve(options.out)
|
|
86
42
|
: // ⛔ The name is the SENDER'S choice, so it lands in a directory by its last segment only:
|
|
87
43
|
// `../x` or an absolute path must not put a file outside where this tool was run.
|
|
88
|
-
destinationFor(options.intoDir ?? ".",
|
|
44
|
+
destinationFor(options.intoDir ?? ".", name);
|
|
89
45
|
// ⛔ `--force` has nothing to overwrite on the stdout branch and is ignored there on purpose.
|
|
90
46
|
// On the disk branch the file streams into a temporary name beside the destination and is
|
|
91
47
|
// renamed into place only once the sender's digest matches, so a share that turns out to be
|
|
92
48
|
// wrong — or a transfer that stops half way — leaves nothing under the name it was given.
|
|
93
|
-
|
|
49
|
+
return destination === null
|
|
94
50
|
? stdoutSink(options.stdout ?? processStdout())
|
|
95
51
|
: fileSink(destination, { force: options.force === true });
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
id,
|
|
111
|
-
name: opened.name,
|
|
112
|
-
bytes: fetched.byteCount,
|
|
113
|
-
from: opened.sender,
|
|
114
|
-
senderRevoked: opened.senderRevoked,
|
|
115
|
-
toIndex: opened.toIndex,
|
|
116
|
-
parts: fetched.partCount,
|
|
117
|
-
out: destination ?? STDOUT_TARGET,
|
|
118
|
-
}));
|
|
119
|
-
return 0;
|
|
120
|
-
}
|
|
121
|
-
say(`${opened.name} ${fetched.byteCount} bytes`);
|
|
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}`);
|
|
125
|
-
say(` checked against the hash the sender sealed with it`);
|
|
52
|
+
});
|
|
53
|
+
if (!got.delivered)
|
|
54
|
+
return 0;
|
|
55
|
+
if (options.json) {
|
|
56
|
+
say(JSON.stringify({
|
|
57
|
+
id,
|
|
58
|
+
name: got.name,
|
|
59
|
+
bytes: got.bytes,
|
|
60
|
+
from: got.sender,
|
|
61
|
+
senderRevoked: got.senderRevoked,
|
|
62
|
+
toIndex: got.toIndex,
|
|
63
|
+
parts: got.parts,
|
|
64
|
+
out: destination ?? STDOUT_TARGET,
|
|
65
|
+
}));
|
|
126
66
|
return 0;
|
|
127
67
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
68
|
+
say(`${got.name} ${got.bytes} bytes`);
|
|
69
|
+
say(` from ${got.sender ?? ""}${got.senderRevoked ? " · the sender has revoked this code" : ""}`);
|
|
70
|
+
if (got.toIndex !== 0)
|
|
71
|
+
say(` to #${got.toIndex} ${got.toCode}`);
|
|
72
|
+
say(` checked against the hash the sender sealed with it`);
|
|
73
|
+
return 0;
|
|
131
74
|
}
|
|
@@ -36,8 +36,9 @@ export async function recoveryList(options = {}) {
|
|
|
36
36
|
throw alreadyThere(destination);
|
|
37
37
|
try {
|
|
38
38
|
// ⛔ 0600. These bytes are one account's whole storage index, sealed — and a mode is cheaper to
|
|
39
|
-
// get right than an explanation of why it did not matter.
|
|
40
|
-
|
|
39
|
+
// get right than an explanation of why it did not matter. The library's own bytes, so an
|
|
40
|
+
// app on the SDK and this command hand out the same file (spec 2026-09-20 unit B).
|
|
41
|
+
writeFileSync(destination, file.bytes, {
|
|
41
42
|
flag: options.force === true ? "w" : "wx",
|
|
42
43
|
mode: 0o600,
|
|
43
44
|
});
|
package/dist/commands/share.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Session } from "../session.ts";
|
|
2
|
+
import { type ShareAccount } from "../sharing.ts";
|
|
1
3
|
export interface ShareOptions {
|
|
2
4
|
server?: string | undefined;
|
|
3
5
|
network?: string | undefined;
|
|
@@ -9,6 +11,11 @@ export interface ShareOptions {
|
|
|
9
11
|
write?: (line: string) => void;
|
|
10
12
|
}
|
|
11
13
|
export declare function out(options: ShareOptions): (line: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* The session as the share doors take it. ⛔ No account proof: an API key is asked for a live
|
|
16
|
+
* human check on the sending doors, and the commands send exactly what they sent before.
|
|
17
|
+
*/
|
|
18
|
+
export declare function shareAccountOf(session: Session, network?: string): ShareAccount;
|
|
12
19
|
/** `nmts share <path> <address>` — hand one file to one account. */
|
|
13
20
|
export declare function share(target: string | undefined, typedAddress: string | undefined, options?: ShareOptions): Promise<number>;
|
|
14
21
|
/** `nmts shares` — what was shared with this account, and what it shared. */
|
package/dist/commands/share.js
CHANGED
|
@@ -11,24 +11,24 @@
|
|
|
11
11
|
// ⛔ THE CLAIMED SENDER IS PRINTED ONLY AFTER THE ENVELOPE OPENED. Opening it IS the proof of who
|
|
12
12
|
// sent it, so a row that did not open is listed with no sender at all rather than with the name
|
|
13
13
|
// it claims.
|
|
14
|
+
import { ServerError } from "../api.js";
|
|
14
15
|
import { requireConsent } from "../consent.js";
|
|
15
16
|
import { loadCrypto } from "../crypto.js";
|
|
16
|
-
import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
|
|
17
17
|
import { NmtsError } from "../errors.js";
|
|
18
|
-
import { readFileList } from "../manifest.js";
|
|
19
18
|
import { BINARY_NAME } from "../product.js";
|
|
20
|
-
import {
|
|
19
|
+
import { codeNumber, publicCodeRefusal } from "../public-code-refusals.js";
|
|
21
20
|
import { openSession } from "../session.js";
|
|
22
|
-
import { addressFromTyped
|
|
23
|
-
import {
|
|
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";
|
|
21
|
+
import { addressFromTyped } from "../share.js";
|
|
22
|
+
import { receivedShares, removeShare, sendShare, shareableFileAt } from "../sharing.js";
|
|
27
23
|
export function out(options) {
|
|
28
24
|
return options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The session as the share doors take it. ⛔ No account proof: an API key is asked for a live
|
|
28
|
+
* human check on the sending doors, and the commands send exactly what they sent before.
|
|
29
|
+
*/
|
|
30
|
+
export function shareAccountOf(session, network = session.network) {
|
|
31
|
+
return { server: session.server, bearer: session.apiKey, code: session.code, accountId: session.accountId, network };
|
|
32
32
|
}
|
|
33
33
|
/** `nmts share <path> <address>` — hand one file to one account. */
|
|
34
34
|
export async function share(target, typedAddress, options = {}) {
|
|
@@ -46,27 +46,8 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
46
46
|
// to the recipient lookup asks the server a question about an account that is not ours to ask.
|
|
47
47
|
const recipientAddress = addressFromTyped(crypt, typedAddress);
|
|
48
48
|
const session = await openSession({ server: options.server, network: options.network });
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
throw new NmtsError("This account has no file list, so there is nothing to share.", { exitCode: 4 });
|
|
52
|
-
}
|
|
53
|
-
const index = buildIndex(list.manifest.entries);
|
|
54
|
-
const entry = entryAt(list.manifest.entries, normalisePath(target), {
|
|
55
|
-
nothingHappened: "Nothing was shared.",
|
|
56
|
-
});
|
|
57
|
-
if (entry.kind !== KIND_FILE) {
|
|
58
|
-
throw new NmtsError(`No file at "${fullPathOf(index, entry)}".`, {
|
|
59
|
-
exitCode: 4,
|
|
60
|
-
nextStep: "That is a folder. Nothing was shared — this version shares one file at a time.",
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (entry.dekWrapped === undefined || entry.contentHashCt === undefined) {
|
|
64
|
-
throw new NmtsError(`The file list holds no ${entry.dekWrapped === undefined ? "key" : "hash"} for "${entry.name}".`, {
|
|
65
|
-
exitCode: 4,
|
|
66
|
-
nextStep: "A share carries both — the key that opens the file and the hash the recipient checks the " +
|
|
67
|
-
"bytes against. Nothing was shared.",
|
|
68
|
-
});
|
|
69
|
-
}
|
|
49
|
+
const account = shareAccountOf(session);
|
|
50
|
+
const file = await shareableFileAt(account, target);
|
|
70
51
|
// ⛔ ASKED AFTER THE FILE IS KNOWN AND BEFORE ANYTHING LEAVES, so the question names a real file.
|
|
71
52
|
requireConsent("share");
|
|
72
53
|
// ⭐ AND ASKED EVERY TIME (2026-09-05): the once-per-machine unlock above says sharing is
|
|
@@ -74,7 +55,7 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
74
55
|
// takes the yes in every mode but skip-permissions, where it hands `--yes` in.
|
|
75
56
|
if (options.yes !== true) {
|
|
76
57
|
const from = sendAs === undefined ? "" : `, from public code #${sendAs}`;
|
|
77
|
-
say(`Would share "${
|
|
58
|
+
say(`Would share "${file.path}" with ${typedAddress}${from}.`);
|
|
78
59
|
say(``);
|
|
79
60
|
say(`⛔ Withdrawing later does not recall it — once the recipient has opened it, they have it.`);
|
|
80
61
|
const as = sendAs === undefined ? "" : ` --as ${sendAs}`;
|
|
@@ -82,84 +63,22 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
82
63
|
say(`⛔ If a program is reading this on somebody's behalf: show it to them and let them decide.`);
|
|
83
64
|
return 5;
|
|
84
65
|
}
|
|
85
|
-
let keys = null;
|
|
86
|
-
const derived = crypt.kdf_derive(crypt.account_code_parse(session.code));
|
|
87
|
-
const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
|
|
88
|
-
derived.fill(0);
|
|
89
|
-
let dek = null;
|
|
90
|
-
let digest = null;
|
|
91
66
|
try {
|
|
92
|
-
dek = crypt.envelope_open(dataKey, new TextEncoder().encode(AAD.dekWrap), new Uint8Array(Buffer.from(entry.dekWrapped, "base64url")));
|
|
93
|
-
digest = crypt.envelope_open(dataKey, new TextEncoder().encode(AAD.contentHash), new Uint8Array(Buffer.from(entry.contentHashCt, "base64url")));
|
|
94
|
-
dataKey.fill(0);
|
|
95
67
|
// ⛔ A SHARE NEEDS A LIVE CODE TO COME FROM. The first one publishes the next number; a
|
|
96
68
|
// later one sends from the lowest-numbered live code unless `--as` names another.
|
|
97
|
-
const door = { server: session.server, token: session.apiKey };
|
|
98
69
|
const quiet = options.json === true;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
70
|
+
const sent = await sendShare(account, file, recipientAddress, {
|
|
71
|
+
as: sendAs,
|
|
72
|
+
onFirstCode: () => {
|
|
73
|
+
if (!quiet)
|
|
74
|
+
say(` publishing this account's public code for the first time`);
|
|
75
|
+
},
|
|
104
76
|
});
|
|
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
|
-
const answer = await request(session.server, `/v1/share-recipients/${encodeURIComponent(b64(recipientAddress))}`, { token: session.apiKey });
|
|
113
|
-
const identityB64 = typeof answer === "object" && answer !== null ? Reflect.get(answer, "share_public_key") : null;
|
|
114
|
-
if (typeof identityB64 !== "string") {
|
|
115
|
-
throw new NmtsError("That public code has never published an identity to share to.", {
|
|
116
|
-
exitCode: 4,
|
|
117
|
-
nextStep: "Nothing was shared. The code may be right and unused — somebody has to open " +
|
|
118
|
-
"their account once before anything can be encrypted to them.",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
const recipientIdentity = new Uint8Array(Buffer.from(identityB64, "base64url"));
|
|
122
|
-
// ⛔ CHECKED BEFORE ANYTHING IS ENCRYPTED TO IT. The engine checks it again inside the wrap;
|
|
123
|
-
// this exists so the refusal names WHICH thing was wrong.
|
|
124
|
-
if (!identityMatches(crypt, recipientIdentity, recipientAddress)) {
|
|
125
|
-
throw new NmtsError("The identity the server returned is not the one that public code names.", {
|
|
126
|
-
exitCode: 1,
|
|
127
|
-
nextStep: "Nothing was shared. Encrypting to it would hand the file to somebody else.",
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
const payload = sealShare(crypt, {
|
|
131
|
-
keys,
|
|
132
|
-
recipientIdentity,
|
|
133
|
-
recipientAddress,
|
|
134
|
-
dek,
|
|
135
|
-
itemId: entry.id,
|
|
136
|
-
name: entry.name,
|
|
137
|
-
size: entry.size,
|
|
138
|
-
digest,
|
|
139
|
-
});
|
|
140
|
-
const created = await request(session.server, "/v1/shares", {
|
|
141
|
-
token: session.apiKey,
|
|
142
|
-
method: "POST",
|
|
143
|
-
body: { item_id: entry.id, recipient_address: b64(recipientAddress), ...payload },
|
|
144
|
-
});
|
|
145
|
-
// ⛔ READ BACK, NOT ECHOED. The server returns the address it actually STORED the share under.
|
|
146
|
-
// Comparing it is the only way to notice a share that was filed against somebody else.
|
|
147
|
-
const stored = typeof created === "object" && created !== null
|
|
148
|
-
? Reflect.get(created, "recipient_address")
|
|
149
|
-
: null;
|
|
150
|
-
if (typeof stored !== "string" || stored !== b64(recipientAddress)) {
|
|
151
|
-
throw new NmtsError("The server filed this share against a different public code.", {
|
|
152
|
-
exitCode: 1,
|
|
153
|
-
nextStep: `Withdraw it now with \`${BINARY_NAME} unshare\` and share it again. The file's key was ` +
|
|
154
|
-
`wrapped for the address you typed, so it is not readable by whoever it was filed under.`,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const id = typeof created === "object" && created !== null ? Reflect.get(created, "id") : null;
|
|
158
77
|
if (options.json) {
|
|
159
|
-
say(JSON.stringify({ id, name:
|
|
78
|
+
say(JSON.stringify({ id: sent.id, name: sent.name, recipient: sent.recipient, fromIndex: sent.fromIndex }));
|
|
160
79
|
return 0;
|
|
161
80
|
}
|
|
162
|
-
say(`${
|
|
81
|
+
say(`${sent.name} → ${sent.recipient}`);
|
|
163
82
|
say(``);
|
|
164
83
|
say(` They can download it from now on. Withdrawing the share stops further downloads`);
|
|
165
84
|
say(` and cannot reach a copy they have already taken.`);
|
|
@@ -177,66 +96,50 @@ export async function share(target, typedAddress, options = {}) {
|
|
|
177
96
|
}
|
|
178
97
|
throw error;
|
|
179
98
|
}
|
|
180
|
-
finally {
|
|
181
|
-
dataKey.fill(0);
|
|
182
|
-
dek?.fill(0);
|
|
183
|
-
digest?.fill(0);
|
|
184
|
-
keys?.wipe();
|
|
185
|
-
}
|
|
186
99
|
}
|
|
187
100
|
/** `nmts shares` — what was shared with this account, and what it shared. */
|
|
188
101
|
export async function shares(options = {}) {
|
|
189
102
|
const say = out(options);
|
|
190
103
|
const session = await openSession({ server: options.server, network: options.network });
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
toIndex: o.toIndex,
|
|
211
|
-
createdAt: o.createdAt,
|
|
212
|
-
problem: o.problem,
|
|
213
|
-
})),
|
|
214
|
-
total: received.total,
|
|
215
|
-
}));
|
|
216
|
-
return 0;
|
|
217
|
-
}
|
|
218
|
-
if (opened.length === 0) {
|
|
219
|
-
say(`Nothing has been shared with this account.`);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
say(`Shared with this account:`);
|
|
223
|
-
for (const one of opened)
|
|
224
|
-
printRow(say, one, toCode);
|
|
225
|
-
// ⛔ SAID OUT LOUD. The listing is bounded, and a person who is not told cannot know that
|
|
226
|
-
// what they are looking at is not everything.
|
|
227
|
-
if (received.total > opened.length) {
|
|
228
|
-
say(``);
|
|
229
|
-
say(` ${received.total} in total; this shows ${opened.length}.`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
say(``);
|
|
233
|
-
say(` \`${BINARY_NAME} receive <id>\` downloads one. \`${BINARY_NAME} unshare <id>\` removes it`);
|
|
234
|
-
say(` from this list, which does not touch the sender's own file.`);
|
|
104
|
+
const received = await receivedShares(shareAccountOf(session));
|
|
105
|
+
const opened = received.shares;
|
|
106
|
+
// ⚠ WHICH CODE IT CAME TO is said once any row came to a code other than 0: for an account
|
|
107
|
+
// that has only ever received with one, the line would say nothing.
|
|
108
|
+
const toCode = opened.some((o) => o.toIndex !== 0) ? (o) => `#${o.toIndex} ${o.toCode}` : null;
|
|
109
|
+
if (options.json) {
|
|
110
|
+
say(JSON.stringify({
|
|
111
|
+
received: opened.map((o) => ({
|
|
112
|
+
id: o.id,
|
|
113
|
+
name: o.name,
|
|
114
|
+
size: o.size,
|
|
115
|
+
sender: o.sender,
|
|
116
|
+
senderRevoked: o.senderRevoked,
|
|
117
|
+
toIndex: o.toIndex,
|
|
118
|
+
createdAt: o.createdAt,
|
|
119
|
+
problem: o.problem,
|
|
120
|
+
})),
|
|
121
|
+
total: received.total,
|
|
122
|
+
}));
|
|
235
123
|
return 0;
|
|
236
124
|
}
|
|
237
|
-
|
|
238
|
-
|
|
125
|
+
if (opened.length === 0) {
|
|
126
|
+
say(`Nothing has been shared with this account.`);
|
|
239
127
|
}
|
|
128
|
+
else {
|
|
129
|
+
say(`Shared with this account:`);
|
|
130
|
+
for (const one of opened)
|
|
131
|
+
printRow(say, one, toCode);
|
|
132
|
+
// ⛔ SAID OUT LOUD. The listing is bounded, and a person who is not told cannot know that
|
|
133
|
+
// what they are looking at is not everything.
|
|
134
|
+
if (received.total > opened.length) {
|
|
135
|
+
say(``);
|
|
136
|
+
say(` ${received.total} in total; this shows ${opened.length}.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
say(``);
|
|
140
|
+
say(` \`${BINARY_NAME} receive <id>\` downloads one. \`${BINARY_NAME} unshare <id>\` removes it`);
|
|
141
|
+
say(` from this list, which does not touch the sender's own file.`);
|
|
142
|
+
return 0;
|
|
240
143
|
}
|
|
241
144
|
function printRow(say, one, toCode) {
|
|
242
145
|
if (one.problem !== null) {
|
|
@@ -258,10 +161,7 @@ export async function unshare(id, options = {}) {
|
|
|
258
161
|
});
|
|
259
162
|
}
|
|
260
163
|
const session = await openSession({ server: options.server, network: options.network });
|
|
261
|
-
await
|
|
262
|
-
token: session.apiKey,
|
|
263
|
-
method: "DELETE",
|
|
264
|
-
});
|
|
164
|
+
await removeShare(shareAccountOf(session), id);
|
|
265
165
|
if (options.json) {
|
|
266
166
|
say(JSON.stringify({ id, removed: true }));
|
|
267
167
|
return 0;
|
|
@@ -272,25 +172,3 @@ export async function unshare(id, options = {}) {
|
|
|
272
172
|
say(` took is still theirs. If you received it, the sender's own file is untouched.`);
|
|
273
173
|
return 0;
|
|
274
174
|
}
|
|
275
|
-
function asReceived(value) {
|
|
276
|
-
if (typeof value !== "object" || value === null) {
|
|
277
|
-
throw new NmtsError("The server's answer was not an object.");
|
|
278
|
-
}
|
|
279
|
-
const rows = Reflect.get(value, "shares");
|
|
280
|
-
if (!Array.isArray(rows))
|
|
281
|
-
throw new NmtsError("The server did not list any shares.");
|
|
282
|
-
const total = Reflect.get(value, "total");
|
|
283
|
-
return {
|
|
284
|
-
rows: rows.filter(isRow),
|
|
285
|
-
total: typeof total === "number" ? total : rows.length,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function isRow(value) {
|
|
289
|
-
if (typeof value !== "object" || value === null)
|
|
290
|
-
return false;
|
|
291
|
-
for (const name of ["id", "item_id", "dek_share_ct", "name_share_ct", "content_hash_share_ct"]) {
|
|
292
|
-
if (typeof Reflect.get(value, name) !== "string")
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
return true;
|
|
296
|
-
}
|