@needmoretruth/nmts-cli 0.56.0 → 0.58.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/artifact-about.d.ts +1 -1
  5. package/dist/commands/receive.js +30 -87
  6. package/dist/commands/share.d.ts +7 -0
  7. package/dist/commands/share.js +58 -180
  8. package/dist/commands/shares-sent.js +4 -29
  9. package/dist/commands/wallet-storage-buy.d.ts +22 -0
  10. package/dist/commands/wallet-storage-buy.js +111 -0
  11. package/dist/commands/wallet.js +3 -1
  12. package/dist/help-options.js +4 -2
  13. package/dist/help.js +2 -0
  14. package/dist/links.d.ts +5 -0
  15. package/dist/links.js +6 -1
  16. package/dist/platform-sign.d.ts +7 -1
  17. package/dist/platform-sign.js +12 -1
  18. package/dist/portable.d.ts +8 -1
  19. package/dist/portable.js +8 -1
  20. package/dist/product.d.ts +1 -1
  21. package/dist/product.js +1 -1
  22. package/dist/sharing-inbox.d.ts +52 -0
  23. package/dist/sharing-inbox.js +146 -0
  24. package/dist/sharing.d.ts +52 -0
  25. package/dist/sharing.js +218 -0
  26. package/dist/sponsor-check.d.ts +56 -0
  27. package/dist/sponsor-check.js +270 -0
  28. package/dist/sponsor-facts.d.ts +10 -0
  29. package/dist/sponsor-facts.js +75 -0
  30. package/dist/storage-control/buy.d.ts +65 -0
  31. package/dist/storage-control/buy.js +145 -0
  32. package/dist/storage-control-chain.d.ts +7 -0
  33. package/dist/storage-control-chain.js +19 -1
  34. package/dist/storage-control.d.ts +2 -0
  35. package/dist/storage-control.js +1 -0
  36. package/dist/upload-quote.d.ts +93 -0
  37. package/dist/upload-quote.js +135 -0
  38. package/dist/wallet-sign.d.ts +24 -0
  39. package/dist/wallet-sign.js +31 -1
  40. package/package.json +5 -1
  41. package/server.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
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.58.0 — 2026-11-11
7
+
8
+ - `nmts wallet storage buy --size <n> [--epochs <n>]` buys a storage resource with nothing in it,
9
+ paid in WAL from the wallet, for 2 epochs unless `--epochs` says otherwise. It shows the price and
10
+ the chain fee first, signs only with `--yes`, and needs `nmts unlock wallet`. `put --pay wallet
11
+ --storage <id>` then writes a file into it.
12
+ - A program can price an upload with no account (`@needmoretruth/nmts-cli/portable` exports
13
+ `quoteUpload`), and a business's server can check a transaction a customer's device built before
14
+ its own wallet signs it (`judgeSponsored`, `signSponsored`): only Walrus storage work within the limits
15
+ it sets passes.
16
+
17
+ ## 0.57.0 — 2026-11-10
18
+
19
+ - A program can share a file the way `nmts share` does: `@needmoretruth/nmts-cli/share` exports
20
+ sending a share, listing what came in and what went out, receiving one and withdrawing one, and
21
+ runs in a browser as well as in Node. `nmts share`, `shares`, `receive` and `unshare` print what
22
+ they printed before.
23
+ - Delegation tokens have a sixth scope, `share`. With it, and the NMTS key's proof on the same
24
+ request, a token can share a file and make a public link. Listing shares and links needs
25
+ `files_read`; withdrawing a share or cutting a link needs `files_write`.
26
+
6
27
  ## 0.56.0 — 2026-11-10
7
28
 
8
29
  - With the account's storage copy of the recovery list switched on, `put --pay wallet` of a one-part
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.56.0 # 버전을 고정할 때
53
+ npm install -g github:needmoretruth/nmts-cli#v0.58.0 # 버전을 고정할 때
54
54
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
55
55
  ```
56
56
 
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.56.0 # a pinned version
54
+ npm install -g github:needmoretruth/nmts-cli#v0.58.0 # a pinned version
55
55
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
56
56
  ```
57
57
 
@@ -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.56.0";
14
+ export declare const WRITTEN_BY = "nmts-cli 0.58.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
  /**
@@ -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 { openReceived, openSharedDigest, receivedIndex } from "../share.js";
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 chain = resolveNetwork(session.server, session.network);
37
- const crypt = await loadCrypto();
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);
40
- try {
41
- // ⛔ THE ROW IS FOUND IN THE LISTING, not asked for by id. The listing is what carries the
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 ?? ".", opened.name);
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
- const sink = destination === null
49
+ return destination === null
94
50
  ? stdoutSink(options.stdout ?? processStdout())
95
51
  : fileSink(destination, { force: options.force === true });
96
- const fetched = await fetchWithKey({
97
- base: session.server,
98
- apiKey: session.apiKey,
99
- descriptorPath: `/v1/shares/${encodeURIComponent(id)}/parts?for=download`,
100
- size: opened.size,
101
- dek: opened.dek,
102
- expected,
103
- chain,
104
- sink,
105
- });
106
- if (!fetched.delivered)
107
- return 0;
108
- if (options.json) {
109
- say(JSON.stringify({
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
- finally {
129
- ring.wipe();
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
  }
@@ -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. */
@@ -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 { request, ServerError } from "../api.js";
19
+ import { codeNumber, publicCodeRefusal } from "../public-code-refusals.js";
21
20
  import { openSession } from "../session.js";
22
- import { addressFromTyped, identityMatches, openReceived, receivedIndex, sealShare, } from "../share.js";
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";
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
- function b64(bytes) {
31
- return Buffer.from(bytes).toString("base64url");
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 list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
50
- if (list.manifest === null) {
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 "${fullPathOf(index, entry)}" with ${typedAddress}${from}.`);
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 { 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);
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: entry.name, recipient: crypt.share_address_display(recipientAddress), fromIndex: keys.index }));
78
+ say(JSON.stringify({ id: sent.id, name: sent.name, recipient: sent.recipient, fromIndex: sent.fromIndex }));
160
79
  return 0;
161
80
  }
162
- say(`${entry.name} → ${crypt.share_address_display(recipientAddress)}`);
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 crypt = await loadCrypto();
192
- // Each row opens with the code it came to; each code's keys are derived once.
193
- const ring = shareKeyRing(crypt, session.code);
194
- try {
195
- const received = asReceived(await request(session.server, "/v1/shares/received", { token: session.apiKey }));
196
- const opened = received.rows.map((row) => openReceived(crypt, ring.at(receivedIndex(row)), row));
197
- for (const one of opened)
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;
202
- if (options.json) {
203
- say(JSON.stringify({
204
- received: opened.map((o) => ({
205
- id: o.id,
206
- name: o.name,
207
- size: o.size,
208
- sender: o.sender,
209
- senderRevoked: o.senderRevoked,
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
- finally {
238
- ring.wipe();
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 request(session.server, `/v1/shares/${encodeURIComponent(id)}`, {
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
- }
@@ -1,12 +1,10 @@
1
1
  // `nmts shares --sent` — moved out of `share.ts` whole (that file is measured by `check:size`).
2
- import { request } from "../api.js";
3
- import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
4
2
  import { NmtsError } from "../errors.js";
5
3
  import { isRecord } from "../guards.js";
6
- import { readFileList } from "../manifest.js";
7
4
  import { BINARY_NAME } from "../product.js";
8
5
  import { openSession } from "../session.js";
9
- import { out } from "./share.js";
6
+ import { sentShares } from "../sharing.js";
7
+ import { out, shareAccountOf } from "./share.js";
10
8
  /**
11
9
  * `nmts shares --sent <path>` — who ONE file was shared with.
12
10
  *
@@ -31,34 +29,11 @@ export async function sharesSent(target, options = {}) {
31
29
  });
32
30
  }
33
31
  const session = await openSession({ server: options.server, network: options.network });
34
- const list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
35
- if (list.manifest === null) {
36
- throw new NmtsError("This account has no file list, so there is nothing to look up.", {
37
- exitCode: 4,
38
- });
39
- }
40
- const index = buildIndex(list.manifest.entries);
41
- const entry = entryAt(list.manifest.entries, normalisePath(target), {
42
- nothingHappened: "Nothing was changed.",
43
- });
44
- if (entry.kind !== KIND_FILE) {
45
- throw new NmtsError(`No file at "${fullPathOf(index, entry)}".`, {
46
- exitCode: 4,
47
- nextStep: "That is a folder, and a share is of one file.",
48
- });
49
- }
50
- const path = fullPathOf(index, entry);
51
- const answer = await request(session.server, `/v1/shares/sent?item_id=${encodeURIComponent(entry.id)}`, { token: session.apiKey });
52
- const rows = typeof answer === "object" && answer !== null ? Reflect.get(answer, "shares") : null;
53
- if (!Array.isArray(rows)) {
54
- throw new NmtsError("The server's answer did not carry a list of shares.", {
55
- nextStep: "Nothing was changed. Report it rather than retrying — the shape, not the network, is wrong.",
56
- });
57
- }
32
+ const { path, itemId, rows } = await sentShares(shareAccountOf(session), target);
58
33
  if (options.json) {
59
34
  // ⛔ THE SERVER'S ROWS, UNCHANGED. A reader of this arm is reading the route, and a shape
60
35
  // rewritten here would be a second wire to keep in step with the first.
61
- say(JSON.stringify({ path, item_id: entry.id, shares: rows }));
36
+ say(JSON.stringify({ path, item_id: itemId, shares: rows }));
62
37
  return 0;
63
38
  }
64
39
  if (rows.length === 0) {
@@ -0,0 +1,22 @@
1
+ import { type BuySeams } from "../storage-control.ts";
2
+ import type { SignStorageOp } from "../wallet-sign.ts";
3
+ export interface StorageBuyOptions {
4
+ server?: string | undefined;
5
+ network?: string | undefined;
6
+ json?: boolean;
7
+ write?: (line: string) => void;
8
+ yes?: boolean;
9
+ dryRun?: boolean;
10
+ /** `--size <bytes|KiB|MiB|GiB>`: the resource's size, encoded bytes as the listing shows them. */
11
+ size?: string | undefined;
12
+ /** `--epochs <n>`: the term, from the current epoch. Default 2. */
13
+ epochs?: string | undefined;
14
+ /** `--wallet N`: which wallet pays and receives it, this run only. */
15
+ wallet?: string | undefined;
16
+ now?: number;
17
+ /** ⚠ SEAMS, NOT OPTIONS — no flag reaches them. */
18
+ readActiveWallet?: () => Promise<number>;
19
+ buyReads?: BuySeams["reads"];
20
+ signStorage?: SignStorageOp;
21
+ }
22
+ export declare function walletStorageBuy(options?: StorageBuyOptions): Promise<number>;