@needmoretruth/nmts-cli 0.58.0 → 0.59.1

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 (45) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/arg-options.d.ts +2 -0
  5. package/dist/args.js +2 -0
  6. package/dist/artifact-about.d.ts +1 -1
  7. package/dist/commands/expiring.js +7 -5
  8. package/dist/commands/extend.js +6 -4
  9. package/dist/commands/login.js +3 -3
  10. package/dist/commands/sweep.js +6 -64
  11. package/dist/commands/wallet-storage-extend.d.ts +23 -0
  12. package/dist/commands/wallet-storage-extend.js +137 -0
  13. package/dist/commands/wallet-use.js +1 -1
  14. package/dist/commands/wallet.d.ts +3 -0
  15. package/dist/commands/wallet.js +5 -3
  16. package/dist/extend-chain.js +19 -3
  17. package/dist/extend-plan.d.ts +38 -0
  18. package/dist/extend-plan.js +61 -0
  19. package/dist/help-options.js +4 -1
  20. package/dist/help.js +3 -0
  21. package/dist/main.js +1 -1
  22. package/dist/platform-sign.d.ts +12 -0
  23. package/dist/platform-sign.js +29 -1
  24. package/dist/portable.d.ts +1 -1
  25. package/dist/portable.js +1 -1
  26. package/dist/product.d.ts +1 -1
  27. package/dist/product.js +1 -1
  28. package/dist/public-codes.d.ts +14 -3
  29. package/dist/public-codes.js +14 -5
  30. package/dist/rebuild.js +9 -24
  31. package/dist/risk.d.ts +12 -0
  32. package/dist/risk.js +8 -0
  33. package/dist/server-objects.d.ts +21 -0
  34. package/dist/server-objects.js +68 -0
  35. package/dist/sharing.d.ts +1 -1
  36. package/dist/sharing.js +12 -40
  37. package/dist/storage-control/extend-for.d.ts +84 -0
  38. package/dist/storage-control/extend-for.js +204 -0
  39. package/dist/storage-control/extend.d.ts +57 -12
  40. package/dist/storage-control/extend.js +51 -45
  41. package/dist/storage-control.d.ts +4 -2
  42. package/dist/storage-control.js +4 -2
  43. package/docs/commands/wallet.md +13 -1
  44. package/package.json +1 -1
  45. package/server.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
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.59.1 — 2026-11-11
7
+
8
+ - `expiring` says that storage another wallet bought, such as a service that paid for your
9
+ uploads, only that wallet can extend. It used to tell everyone to extend from their own wallet.
10
+ - `wallet` no longer says `extend` is the one command that signs: every command that signs from
11
+ the wallet stays locked until a person unlocks it on this machine. `extend` no longer says every
12
+ other command spends credits.
13
+
14
+ ## 0.59.0 — 2026-11-11
15
+
16
+ - `nmts wallet storage extend [<item-id>...] --delegation-file <file>` lets a business that paid
17
+ for its users' uploads extend those files from its own wallet. It needs a delegation token for the
18
+ user with `files_read` and `storage_spend`, and not the user's key. The library exports the same
19
+ call as `extendFor`.
20
+ - `extend`, here and in the library, now refuses a file whose storage another wallet holds, and
21
+ names that wallet, before anything is signed.
22
+ - A delegation token with the `share` scope can list, publish and revoke its own account's public
23
+ codes, with the NMTS key's proof on the same request. A device that holds its own key publishes
24
+ its first code itself when it first shares; the business no longer has to.
25
+ - `wallet storage buy` and `wallet storage extend` are rated as signing commands that spend WAL.
26
+ Until now `buy` was rated as a read.
27
+ - `expiring` says "1 day" and "1 file runs out" where it said "1 days" and "1 file run out".
28
+
6
29
  ## 0.58.0 — 2026-11-11
7
30
 
8
31
  - `nmts wallet storage buy --size <n> [--epochs <n>]` buys a storage resource with nothing in it,
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.58.0 # 버전을 고정할 때
53
+ npm install -g github:needmoretruth/nmts-cli#v0.59.1 # 버전을 고정할 때
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.58.0 # a pinned version
54
+ npm install -g github:needmoretruth/nmts-cli#v0.59.1 # a pinned version
55
55
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
56
56
  ```
57
57
 
@@ -107,6 +107,8 @@ export interface ParsedArgs {
107
107
  * used to sign one message, and never copied or printed.
108
108
  */
109
109
  suiKeyFile?: string;
110
+ /** `wallet storage extend`: the file holding the user's delegation token. ⛔ A path, never the token. */
111
+ delegationFile?: string;
110
112
  /** `login`/`create`/`openers add`: which of that wallet's NMTS accounts. Whole, from 1. */
111
113
  account?: string;
112
114
  /**
package/dist/args.js CHANGED
@@ -57,6 +57,8 @@ const VALUE_OPTIONS = {
57
57
  // credential and lists this one as the exception it is: what it names is a FILE, the shape
58
58
  // this tool already recommends for every other secret (`NMTS_ACCOUNT_CODE_FILE`).
59
59
  "--sui-key-file": "suiKeyFile",
60
+ // A PATH, like the one above: a business's server names the file holding a user's delegation token.
61
+ "--delegation-file": "delegationFile",
60
62
  "--from": "from",
61
63
  // NMTS Heavy: which tier, and the self-paid path's knobs (developer mode).
62
64
  "--tier": "tier",
@@ -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.58.0";
14
+ export declare const WRITTEN_BY = "nmts-cli 0.59.1";
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
  /**
@@ -15,8 +15,8 @@
15
15
  // address to send one to.
16
16
  //
17
17
  // ⛔ AND IT BUYS NOTHING. What this does is make the deadline visible in time for somebody to act
18
- // on it. Acting on it is `nmts extend`, which spends from the person's own wallet and asks for
19
- // its own agreement first — this command reads, and no amount of it costs anything.
18
+ // on it. Acting on it is `nmts extend`, which spends from the wallet that holds the storage and
19
+ // asks for its own agreement first — this command reads, and no amount of it costs anything.
20
20
  import { request } from "../api.js";
21
21
  import { buildIndex, fullPathOf } from "../drive-paths.js";
22
22
  import { NmtsError } from "../errors.js";
@@ -79,7 +79,7 @@ export async function expiring(options = {}) {
79
79
  }
80
80
  const epochDays = clock.durationMs / 86_400_000;
81
81
  say(`The ${session.network} storage network is at epoch ${clock.current}, and one epoch is ` +
82
- `${epochDays === Math.round(epochDays) ? epochDays : epochDays.toFixed(1)} days.`);
82
+ `${epochDays === 1 ? "1 day" : `${epochDays === Math.round(epochDays) ? epochDays : epochDays.toFixed(1)} days`}.`);
83
83
  if (dated.length === 0 && unrecorded.length === 0) {
84
84
  say(`Nothing in this account runs out before epoch ${cutoff}.`);
85
85
  return 0;
@@ -94,7 +94,7 @@ export async function expiring(options = {}) {
94
94
  MARK[row.stage]);
95
95
  }
96
96
  say(``);
97
- say(`${dated.length} file${dated.length === 1 ? "" : "s"} run out before epoch ${cutoff}.`);
97
+ say(`${dated.length} file${dated.length === 1 ? " runs" : "s run"} out before epoch ${cutoff}.`);
98
98
  }
99
99
  if (unrecorded.length > 0) {
100
100
  say(``);
@@ -118,9 +118,11 @@ export async function expiring(options = {}) {
118
118
  say(` and running this again shows the next ones.`);
119
119
  }
120
120
  say(``);
121
- say(`Extending storage is paid for from your own wallet and signed on this machine: ` +
121
+ say(`Storage your own wallet bought is extended from that wallet and signed on this machine: ` +
122
122
  `\`${BINARY_NAME} extend <path>\`, or the browser at ${HOME_URL}. It spends WAL rather than ` +
123
123
  `credits, and it asks once before it signs.`);
124
+ say(`Storage another wallet bought, such as a service that paid for your uploads, only that wallet ` +
125
+ `can extend; \`${BINARY_NAME} extend\` names it and stops before signing.`);
124
126
  return 0;
125
127
  }
126
128
  /** What a row is called, with the reason spelled out when it has no name. */
@@ -167,8 +167,10 @@ function describe(say, facts) {
167
167
  say(` ${unreachable} part${unreachable === 1 ? "" : "s"} of this file cannot be extended from here.`);
168
168
  }
169
169
  say(``);
170
- // ⛔ REQUIRED, AND IT COMES BEFORE THE AGREEMENT. Every other purchase in this tool spends
171
- // credits; this one spends assets out of a wallet, and nobody can put them back.
172
- say(` This is paid in WAL from the wallet this NMTS key derives — not from credits, which`);
173
- say(` is what every other command in this tool spends. \`${BINARY_NAME} wallet\` shows what is in it.`);
170
+ // ⛔ REQUIRED, AND IT COMES BEFORE THE AGREEMENT. A person who has only ever stored with credits
171
+ // must read that this spends assets out of a wallet, and nobody can put them back. (It once said
172
+ // "every other command spends credits", which stopped being true when wallet uploads, sends,
173
+ // swaps and storage purchases arrived.)
174
+ say(` This is paid in WAL from the wallet this NMTS key derives, not from credits, and nobody`);
175
+ say(` can put it back. \`${BINARY_NAME} wallet\` shows what is in it.`);
174
176
  }
@@ -282,9 +282,9 @@ function sayAboutTheKey(outcome, server, say) {
282
282
  say(``);
283
283
  say(`⚠ A different API key is in ${keySourceName(outcome.from)}. It was NOT stored.`);
284
284
  say(``);
285
- say(` The key already on this machine is left as it is. Replacing one is something to say`);
286
- say(` out loud, not something a run about the NMTS key does on the way past — every`);
287
- say(` agent using the old one would stop working at a moment nobody would connect to this.`);
285
+ say(` The key already on this machine is left as it is. Storing the NMTS key does not replace`);
286
+ say(` it on the side: every agent using the old one would stop at a moment nobody would`);
287
+ say(` connect to this.`);
288
288
  say(``);
289
289
  say(` While that variable is set, every command uses what it holds anyway: the environment`);
290
290
  say(` wins over what is stored. To store it instead — at a terminal, run this again and`);
@@ -23,24 +23,15 @@
23
23
  //
24
24
  // ⛔ AND IT DROPS WHOLE BRANCHES. See `trash-sweep.ts`: a folder dropped while a file under it is
25
25
  // kept leaves that file with no trashed ancestor, which reads as LIVE for ever after.
26
- import { request } from "../api.js";
27
26
  import { buildIndex, fullPathOf, trashedAt } from "../drive-paths.js";
28
27
  import { NmtsError } from "../errors.js";
29
28
  import { readFileList } from "../manifest.js";
30
29
  import { applyToList } from "../manifest-write.js";
31
30
  import { BINARY_NAME } from "../product.js";
31
+ import { serverObjects } from "../server-objects.js";
32
32
  import { openSession } from "../session.js";
33
33
  import { expiredTrashEntries, filesAmong, planPurge, TRASH_RETENTION_DAYS, } from "../trash-sweep.js";
34
34
  const DAY_MS = 86_400_000;
35
- /**
36
- * How many pages of the server's item listing one sweep will read.
37
- *
38
- * ⛔ THERE IS A CEILING BECAUSE "ABSENT FROM A PARTIAL LISTING" IS NOT "ERASED". The whole
39
- * safeguard below rests on having seen every row the server still holds, so a listing that ran
40
- * out of patience must stop the sweep rather than shorten it. A hundred rows a page puts the
41
- * limit well past any drive a command-line tool is the right way to manage.
42
- */
43
- const MAX_PAGES = 200;
44
35
  export async function sweep(options = {}) {
45
36
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
46
37
  const now = options.now ?? Date.now();
@@ -180,61 +171,12 @@ function describe(plan, shown, ageDays) {
180
171
  return rows;
181
172
  }
182
173
  /**
183
- * Every item id the server still holds a row for, live or trashed.
174
+ * Every item id the server still holds a row for, live or trashed (`server-objects.ts`).
184
175
  *
185
- * ⛔ `/v1/objects` AND NOT `/v1/items?deleted=true`. The trash listing stops at the retention
186
- * window, so a row that is past thirty days and not yet erased is missing from it — and
187
- * "missing" is exactly the answer this function must not get wrong. `/v1/objects` is the
188
- * reconciliation view: every row of the account, with no window on it.
189
- *
190
- * ⚠ The two calls are written out rather than built from a variable so that the gate comparing
191
- * this tool's addresses against the server's routes can see them both. It reads literal strings.
176
+ * ⛔ A WALK THAT STOPPED AT THE CEILING IS REPORTED AS ONE: "absent from a partial listing" is not
177
+ * "erased", and the safeguard above rests on having seen every row.
192
178
  */
193
179
  async function serverItemIds(base, apiKey) {
194
- const ids = new Set();
195
- let cursor = null;
196
- for (let page = 0; page < MAX_PAGES; page += 1) {
197
- const answer = cursor === null
198
- ? await request(base, "/v1/objects", { token: apiKey })
199
- : await request(base, `/v1/objects?after=${encodeURIComponent(cursor)}`, { token: apiKey });
200
- const read = asObjectsAnswer(answer);
201
- for (const id of read.ids)
202
- ids.add(id);
203
- if (read.next === null)
204
- return { ids, complete: true };
205
- cursor = read.next;
206
- }
207
- return { ids, complete: false };
208
- }
209
- /**
210
- * What `GET /v1/objects` answers, narrowed rather than trusted.
211
- *
212
- * ⛔ A ROW THIS CANNOT READ IS A REFUSAL. Skipping one would shrink the set of things the server is
213
- * known to hold, and every id missing from that set is an entry this command then drops.
214
- */
215
- function asObjectsAnswer(value) {
216
- const unreadable = () => {
217
- throw new NmtsError("The server answered with an item listing this version cannot read.", {
218
- nextStep: "Nothing was changed. Update this tool before sweeping.",
219
- });
220
- };
221
- if (typeof value !== "object" || value === null)
222
- return unreadable();
223
- const raw = Reflect.get(value, "objects");
224
- if (!Array.isArray(raw))
225
- return unreadable();
226
- const objects = raw;
227
- const ids = [];
228
- for (const object of objects) {
229
- if (typeof object !== "object" || object === null)
230
- return unreadable();
231
- const id = Reflect.get(object, "id");
232
- if (typeof id !== "string")
233
- return unreadable();
234
- ids.push(id);
235
- }
236
- const next = Reflect.get(value, "next_cursor");
237
- if (next !== null && next !== undefined && typeof next !== "string")
238
- return unreadable();
239
- return { ids, next: typeof next === "string" && next !== "" ? next : null };
180
+ const { rows, complete } = await serverObjects(base, apiKey);
181
+ return { ids: new Set(rows.map((row) => row.id)), complete };
240
182
  }
@@ -0,0 +1,23 @@
1
+ import type { ExtendReads, SignExtension } from "../extend-plan.ts";
2
+ export interface StorageExtendOptions {
3
+ server?: string | undefined;
4
+ network?: string | undefined;
5
+ json?: boolean;
6
+ write?: (line: string) => void;
7
+ yes?: boolean;
8
+ dryRun?: boolean;
9
+ /** `--force`: extend files that are not near their end yet too. */
10
+ force?: boolean;
11
+ /** `--delegation-file <file>`: the user's delegation token, read from that file. */
12
+ delegationFile?: string | undefined;
13
+ /** `--epochs <n>`: added to each file. Default 2. */
14
+ epochs?: string | undefined;
15
+ /** `--wallet N`: which of this key's wallets pays, this run only. */
16
+ wallet?: string | undefined;
17
+ now?: number;
18
+ /** ⚠ SEAMS, NOT OPTIONS — no flag reaches them. */
19
+ readActiveWallet?: () => Promise<number>;
20
+ readChain?: ((network: string) => Promise<ExtendReads> | ExtendReads) | undefined;
21
+ sign?: SignExtension | undefined;
22
+ }
23
+ export declare function walletStorageExtend(items: readonly string[], options?: StorageExtendOptions): Promise<number>;
@@ -0,0 +1,137 @@
1
+ // `nmts wallet storage extend [<item-id>...] --delegation-file <file>` — a business extending a
2
+ // user's files from ITS OWN wallet, with the user's delegation token and no key of the user's.
3
+ //
4
+ // ⛔ IT SIGNS AND SPENDS WAL. The order, the skips and the per-file transactions are
5
+ // `storage-control/extend-for.ts`, which the SDK's `extendFor` calls as well; this file is the
6
+ // terminal over it: the review a person reads, `--yes`, and the wallet unlock held against the
7
+ // total the review measured.
8
+ //
9
+ // ⛔ WHOSE MONEY. The key this tool is signed in with is the BUSINESS's; its wallet holds the storage
10
+ // a sponsored upload left there and pays. The user is a token in a file, which lists the user's
11
+ // files and records each new date. A blob the business's wallet does not hold is skipped, named.
12
+ //
13
+ // ⚠ A TOKEN IS A FILE, NEVER AN OPTION'S VALUE: a command line is readable by every process on the
14
+ // machine and recorded by the shell (`args.ts`).
15
+ import { readFileSync } from "node:fs";
16
+ import { requireAccountCode } from "../code-access.js";
17
+ import { readCredentialsFile } from "../credentials.js";
18
+ import { NmtsError } from "../errors.js";
19
+ import { resolveNetwork } from "../network.js";
20
+ import { BINARY_NAME } from "../product.js";
21
+ import { resolveServer } from "../server.js";
22
+ import { extendFor } from "../storage-control.js";
23
+ import { explorerTxUrl } from "../shared/lib/wallet/activity.js";
24
+ import { coinAmount, walletAddress } from "../wallet.js";
25
+ import { payingWalletIndex } from "../wallet-pay-index.js";
26
+ import { recordWalletSpend, requireWalletGrant } from "../wallet-grant.js";
27
+ const USAGE = `\`${BINARY_NAME} wallet storage extend [<item-id>...] --delegation-file <file> [--epochs <n>] [--force] [--dry-run] [--yes]\``;
28
+ export async function walletStorageExtend(items, options = {}) {
29
+ const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
30
+ const token = readToken(options.delegationFile);
31
+ const resolved = await requireAccountCode();
32
+ const wallet = await payingWalletIndex(options);
33
+ const address = await walletAddress(resolved.code, wallet);
34
+ const stored = resolved.source === "file" || resolved.source === "file-locked" ? readCredentialsFile() : null;
35
+ const server = resolveServer(options.server ?? stored?.server);
36
+ const network = resolveNetwork(server, options.network ?? stored?.network);
37
+ const now = options.now ?? Date.now();
38
+ const sign = options.sign ?? (await import("../wallet-sign.js")).signExtension;
39
+ const run = (dryRun) => extendFor({ server, network, token, payer: address }, { items: items.length === 0 ? undefined : items, epochs: options.epochs, force: options.force === true, dryRun }, {
40
+ readChain: options.readChain,
41
+ now,
42
+ sign: ({ objectIds, epochs }) => sign({ network, code: resolved.code, wallet, objectIds, epochs }),
43
+ });
44
+ // ⛔ THE REVIEW FIRST, ALWAYS: what would be bought, what is left and why, before any signature.
45
+ const review = await run(true);
46
+ const due = review.files.filter((f) => f.outcome === "priced").length;
47
+ if (!options.json)
48
+ describe(say, review, wallet);
49
+ if (due === 0 || options.dryRun === true || options.yes !== true) {
50
+ if (options.json) {
51
+ say(JSON.stringify({ network, signed: false, ...review }));
52
+ return due === 0 || options.dryRun === true ? 0 : 4;
53
+ }
54
+ say(``);
55
+ if (due === 0) {
56
+ say(` Nothing to extend. Nothing was signed.`);
57
+ return 0;
58
+ }
59
+ if (options.dryRun === true) {
60
+ say(` Nothing was signed. Run the same command with --yes to extend them.`);
61
+ return 0;
62
+ }
63
+ throw new NmtsError(`Nothing was signed: this needs --yes.`, {
64
+ exitCode: 4,
65
+ nextStep: `Read the review above, then run the same command with --yes.`,
66
+ });
67
+ }
68
+ // The unlock, held against the total the review measured. ⛔ Throwing here signs nothing.
69
+ requireWalletGrant("extend", spendOf(review), new Date(now));
70
+ const done = await run(false);
71
+ recordWalletSpend(spendOf(done));
72
+ if (options.json) {
73
+ say(JSON.stringify({ network, signed: true, ...done }));
74
+ }
75
+ else {
76
+ say(``);
77
+ for (const file of done.files) {
78
+ if (file.outcome !== "extended" || file.digest === null)
79
+ continue;
80
+ say(` Extended ${file.itemId} to epoch ${String(file.newEndEpoch)}. ${explorerTxUrl(file.digest, network)}`);
81
+ }
82
+ }
83
+ if (done.stopped === null)
84
+ return 0;
85
+ throw new NmtsError(`${done.stopped.code}: ${done.stopped.reason}`, {
86
+ exitCode: done.stopped.code === "EXTEND_RECORDED_LATE" ? 1 : 4,
87
+ nextStep: done.stopped.code === "EXTEND_RECORDED_LATE"
88
+ ? "Do not run this again for that file: it would pay for the same time twice."
89
+ : "The files above it were extended; the rest were not. Run it again once that is fixed.",
90
+ });
91
+ }
92
+ /** The user's token out of its file, refusing a missing or empty one before anything is read. */
93
+ function readToken(file) {
94
+ if (file === undefined || file === "") {
95
+ throw new NmtsError(`Name the file that holds the user's delegation token.`, { exitCode: 2, nextStep: USAGE });
96
+ }
97
+ let text;
98
+ try {
99
+ text = readFileSync(file, "utf8");
100
+ }
101
+ catch (error) {
102
+ // ⚠ The reason is the system's, about a path; never the file's content.
103
+ throw new NmtsError(`The delegation token file could not be read: ${file}.`, {
104
+ exitCode: 2,
105
+ nextStep: `${error instanceof Error && "code" in error ? String(error.code) : "unreadable"}. Nothing was signed.`,
106
+ });
107
+ }
108
+ const token = text.trim();
109
+ if (token === "")
110
+ throw new NmtsError(`The delegation token file is empty: ${file}.`, { exitCode: 2, nextStep: USAGE });
111
+ return token;
112
+ }
113
+ /** What a run costs this wallet: the WAL of every file bought and the fees measured for them. */
114
+ function spendOf(result) {
115
+ return { walFrost: BigInt(result.wal), suiMist: BigInt(result.sui) };
116
+ }
117
+ /** The review a person reads: each file and what happens to it, then the total and the wallet. */
118
+ function describe(say, review, wallet) {
119
+ const priced = review.files.filter((f) => f.outcome === "priced");
120
+ say(`Would extend ${priced.length} of ${review.files.length} file${review.files.length === 1 ? "" : "s"} from ${review.wallet.address} (wallet ${wallet}).`);
121
+ for (const file of review.files) {
122
+ if (file.outcome === "priced") {
123
+ say(` ${file.itemId} epoch ${String(file.endEpoch)} to ${String(file.newEndEpoch)} ${coinAmount(BigInt(file.wal ?? "0"))} WAL`);
124
+ }
125
+ else {
126
+ say(` ${file.itemId} left as it is: ${file.reason ?? file.code ?? "skipped"}`);
127
+ }
128
+ }
129
+ if (priced.length === 0)
130
+ return;
131
+ say(` Storage ${coinAmount(BigInt(review.wal))} WAL in all, one transaction per file.`);
132
+ say(` Chain fees about ${coinAmount(BigInt(review.sui))} SUI, measured by dry runs just now.`);
133
+ const wal = review.wallet.wal === null ? "WAL not read" : `${coinAmount(BigInt(review.wallet.wal))} WAL`;
134
+ const sui = review.wallet.sui === null ? "SUI not read" : `${coinAmount(BigInt(review.wallet.sui))} SUI`;
135
+ say(` The wallet holds ${wal} and ${sui}.`);
136
+ say(` Nobody, NMTS included, can reverse it.`);
137
+ }
@@ -49,7 +49,7 @@ export async function walletUse(said, options = {}) {
49
49
  say(`Address ${address}`);
50
50
  say(``);
51
51
  say(` Storage paid from this account's wallet now leaves this address, on every device — the`);
52
- say(` number rides in the sealed file list, not on this machine. What is already stored is`);
52
+ say(` number is kept in the sealed file list, not on this machine. What is already stored is`);
53
53
  say(` unaffected, and the wallets you were using keep whatever is in them.`);
54
54
  return 0;
55
55
  }
@@ -24,6 +24,9 @@ export interface WalletOptions {
24
24
  /** `wallet storage split`: what the resource keeps, by size or by epochs (`wallet-storage-ops.ts`). */
25
25
  size?: string | undefined;
26
26
  epochs?: string | undefined;
27
+ /** `wallet storage extend`: the user's delegation token file, and whether files not due go too. */
28
+ delegationFile?: string | undefined;
29
+ force?: boolean;
27
30
  /** `wallet hall`: the name to be listed under, or `remove` to go back to a shortened address. */
28
31
  name?: string | undefined;
29
32
  remove?: boolean;
@@ -63,10 +63,12 @@ export async function wallet(what, options = {}) {
63
63
  }
64
64
  if (sub === "buy")
65
65
  return (await import("./wallet-storage-buy.js")).walletStorageBuy(options);
66
+ if (sub === "extend")
67
+ return (await import("./wallet-storage-extend.js")).walletStorageExtend(more, options);
66
68
  if (sub !== undefined) {
67
69
  throw new NmtsError(`\`${BINARY_NAME} wallet storage ${sub}\` is not something this command does.`, {
68
70
  exitCode: 2,
69
- nextStep: `\`${BINARY_NAME} wallet storage\` lists; \`buy\`, \`split\`, \`merge\` and \`transfer\` sign — \`${BINARY_NAME} help wallet\`.`,
71
+ nextStep: `\`${BINARY_NAME} wallet storage\` lists; \`buy\`, \`extend\`, \`split\`, \`merge\` and \`transfer\` sign — \`${BINARY_NAME} help wallet\`.`,
70
72
  });
71
73
  }
72
74
  return (await import("./wallet-storage.js")).walletStorage(options);
@@ -141,8 +143,8 @@ export async function wallet(what, options = {}) {
141
143
  say(` exits non-zero when it happens — so nothing driving it reads a missing number as an`);
142
144
  say(` empty wallet.`);
143
145
  }
144
- say(` Nothing here signs or spends. \`${BINARY_NAME} extend\` is the one command that signs, and it`);
145
- say(` asks for a separate agreement before it does.`);
146
+ say(` Nothing here signs or spends. Every command that signs from this wallet stays locked until a`);
147
+ say(` person unlocks it on this machine — \`${BINARY_NAME} unlock\` lists what is open.`);
146
148
  say(` Storing needs no coin here: credits pay the network. \`${BINARY_NAME} help wallet\` says where`);
147
149
  say(` SUI comes from when you want to pay the network yourself.`);
148
150
  return exitCodeFor(balances);
@@ -19,7 +19,7 @@ import { ObjectError } from "@mysten/sui/client";
19
19
  import { walrus } from "@mysten/walrus";
20
20
  import { NmtsError } from "./errors.js";
21
21
  import { epochClock } from "./expiry.js";
22
- import { dryRun, objectFields } from "./shared/lib/wallet/chain-calls.js";
22
+ import { dryRun } from "./shared/lib/wallet/chain-calls.js";
23
23
  import { epochStartedMs } from "./walrus-write.js";
24
24
  import { storageNodesThrough } from "./walrus.js";
25
25
  import { freshWalrus } from "./walrus-fresh.js";
@@ -60,8 +60,12 @@ function numberOf(value) {
60
60
  */
61
61
  export async function readBlobLease(client, objectId) {
62
62
  let fields;
63
+ let holder;
63
64
  try {
64
- fields = await objectFields(client, objectId);
65
+ // ⛔ ONE READ FOR THE LEASE AND ITS HOLDER, so the two describe the same version of the object.
66
+ const { object } = await client.core.getObject({ objectId, include: { json: true } });
67
+ fields = object.json ?? null;
68
+ holder = holderOf(object.owner);
65
69
  }
66
70
  catch (error) {
67
71
  // Only the node's own "no such object" is said as one; a node that did not answer is thrown
@@ -87,7 +91,19 @@ export async function readBlobLease(client, objectId) {
87
91
  nextStep: "Nothing was signed and nothing was charged. Update this tool.",
88
92
  });
89
93
  }
90
- return { objectId, size, endEpoch };
94
+ return { objectId, size, endEpoch, holder };
95
+ }
96
+ /** Who holds an object, in the three kinds an extension cares about. */
97
+ function holderOf(owner) {
98
+ if (owner.AddressOwner !== undefined)
99
+ return { kind: "address", address: owner.AddressOwner };
100
+ if (owner.ConsensusAddressOwner !== undefined)
101
+ return { kind: "address", address: owner.ConsensusAddressOwner.owner };
102
+ if (owner.$kind === "Shared")
103
+ return { kind: "shared" };
104
+ if (owner.ObjectOwner !== undefined)
105
+ return { kind: "other", what: `the object ${owner.ObjectOwner}` };
106
+ return { kind: "other", what: owner.$kind === "Immutable" ? "nobody (it is frozen)" : `an owner of kind ${owner.$kind}` };
91
107
  }
92
108
  /**
93
109
  * The reads one `nmts extend` run needs, bound to one network.
@@ -59,7 +59,37 @@ export interface BlobLease {
59
59
  size: number;
60
60
  /** The epoch the lease runs out at. THE authoritative expiry. */
61
61
  endEpoch: number;
62
+ /**
63
+ * Who may extend it, as the chain says.
64
+ *
65
+ * ⚠ OPTIONAL ONLY FOR A TEST'S FAKE CHAIN. The real reader (`extend-chain.ts`) always reads it, and
66
+ * a lease without it skips only the early refusal below — the chain itself still refuses a
67
+ * transaction that names a blob its sender does not hold.
68
+ */
69
+ holder?: BlobHolder | undefined;
62
70
  }
71
+ /**
72
+ * Who holds a blob object. An address holds it alone; a shared blob anyone may extend; anything else
73
+ * (held inside another object, frozen) nobody can extend with a plain transaction.
74
+ */
75
+ export type BlobHolder = {
76
+ kind: "address";
77
+ address: string;
78
+ } | {
79
+ kind: "shared";
80
+ } | {
81
+ kind: "other";
82
+ what: string;
83
+ };
84
+ /**
85
+ * Refuse, before anything is signed, a blob the paying wallet does not hold.
86
+ *
87
+ * ⛔ WHAT A WALLET PAID FOR, ONLY THAT WALLET EXTENDS (`pay.ts` in the SDK says the same). The chain
88
+ * enforces it — but only after a signature was asked for, and for a remote signer (an operator's
89
+ * server signing for a customer) that is a request to sign a transaction that cannot run. Named
90
+ * here, each blob and who holds it, so the caller knows which wallet to pay from instead.
91
+ */
92
+ export declare function refuseUnheld(leases: readonly BlobLease[], payer: string, file: string): void;
63
93
  /**
64
94
  * When the file actually runs out: the SOONEST end epoch across the blobs it rides on.
65
95
  *
@@ -148,3 +178,11 @@ export type SignExtension = (input: {
148
178
  objectIds: readonly string[];
149
179
  epochs: number;
150
180
  }) => Promise<string>;
181
+ /**
182
+ * The network's clock and how far ahead it sells, or the refusal for a network that would not say.
183
+ *
184
+ * ⛔ Not "nothing needs extending". The two look identical from outside and mean opposite things.
185
+ */
186
+ export declare function readWindowOrRefuse(reads: ExtendReads, network: string): Promise<ExtendWindow>;
187
+ /** Why a file has nothing to extend, said as the two different things it can be. */
188
+ export declare function nothingToExtend(preview: ExtendPreview): string;
@@ -75,6 +75,37 @@ export function asExtendPreview(value) {
75
75
  return unreadable();
76
76
  return { targets, treasuryParts: treasury, untrackedParts: untracked };
77
77
  }
78
+ /**
79
+ * Refuse, before anything is signed, a blob the paying wallet does not hold.
80
+ *
81
+ * ⛔ WHAT A WALLET PAID FOR, ONLY THAT WALLET EXTENDS (`pay.ts` in the SDK says the same). The chain
82
+ * enforces it — but only after a signature was asked for, and for a remote signer (an operator's
83
+ * server signing for a customer) that is a request to sign a transaction that cannot run. Named
84
+ * here, each blob and who holds it, so the caller knows which wallet to pay from instead.
85
+ */
86
+ export function refuseUnheld(leases, payer, file) {
87
+ const mine = normaliseAddress(payer);
88
+ const unheld = leases.flatMap((lease) => {
89
+ const holder = lease.holder;
90
+ if (holder === undefined || holder.kind === "shared")
91
+ return [];
92
+ if (holder.kind === "address" && normaliseAddress(holder.address) === mine)
93
+ return [];
94
+ return [`${lease.objectId} is held by ${holder.kind === "address" ? holder.address : holder.what}`];
95
+ });
96
+ if (unheld.length === 0)
97
+ return;
98
+ throw new NmtsError(`EXTEND_NOT_OWNED: the wallet ${payer} does not hold the storage of "${file}": ${unheld.join("; ")}.`, {
99
+ exitCode: 4,
100
+ nextStep: "Nothing was signed and nothing was charged. Only the wallet that holds a blob can extend it — " +
101
+ "pay from that wallet, or leave this file to whoever holds it.",
102
+ });
103
+ }
104
+ /** `0x` and 64 lower-case hex digits, whatever the spelling it arrived in. */
105
+ function normaliseAddress(address) {
106
+ const hex = address.toLowerCase().replace(/^0x/, "");
107
+ return `0x${hex.padStart(64, "0")}`;
108
+ }
78
109
  /**
79
110
  * When the file actually runs out: the SOONEST end epoch across the blobs it rides on.
80
111
  *
@@ -147,3 +178,33 @@ function parseEpochs(asked) {
147
178
  }
148
179
  return epochs;
149
180
  }
181
+ /**
182
+ * The network's clock and how far ahead it sells, or the refusal for a network that would not say.
183
+ *
184
+ * ⛔ Not "nothing needs extending". The two look identical from outside and mean opposite things.
185
+ */
186
+ export async function readWindowOrRefuse(reads, network) {
187
+ const window = await reads.readWindow();
188
+ if (window !== null)
189
+ return window;
190
+ throw new NmtsError(`The ${network} storage network could not be read.`, {
191
+ exitCode: 1,
192
+ nextStep: `Nothing was signed and nothing was charged. Which epoch the network is in, and how far ` +
193
+ `ahead it will sell, are facts only the chain has — this will not spend against a ` +
194
+ `guess. Try again, or name a different Sui node in NMTS_SUI_RPC.`,
195
+ });
196
+ }
197
+ /** Why a file has nothing to extend, said as the two different things it can be. */
198
+ export function nothingToExtend(preview) {
199
+ const parts = [];
200
+ if (preview.treasuryParts > 0) {
201
+ parts.push(`${preview.treasuryParts} part${preview.treasuryParts === 1 ? " is" : "s are"} on storage NMTS ` +
202
+ `paid for, which this account cannot extend`);
203
+ }
204
+ if (preview.untrackedParts > 0) {
205
+ parts.push(`${preview.untrackedParts} part${preview.untrackedParts === 1 ? " has" : "s have"} no ` +
206
+ `recorded storage object, so there is nothing to name on the chain`);
207
+ }
208
+ const why = parts.length === 0 ? "The server lists no storage object for it." : `${parts.join(", and ")}.`;
209
+ return `Nothing was signed and nothing was charged. ${why} Opening the account in a browser shows what it is stored on.`;
210
+ }
@@ -75,7 +75,8 @@ export function optionLines() {
75
75
  ` public code file`,
76
76
  ` --force Replace a file that is already there (get, pull, listfile,`,
77
77
  ` recovery, recovery-list, kit), or rebuild an account this machine`,
78
- ` has seen a list for (rebuild). \`create\` never replaces a file`,
78
+ ` has seen a list for (rebuild), or extend files not due yet (wallet`,
79
+ ` storage extend). \`create\` never replaces a file`,
79
80
  ` --name <name> The name the uploaded file gets in the drive (put), or the name to`,
80
81
  ` be listed under in the gift hall of fame (wallet hall)`,
81
82
  ` --to <folder> Destination folder, as \`${BINARY_NAME} ls\` prints it (put, push).`,
@@ -151,6 +152,8 @@ export function optionLines() {
151
152
  ` --wallet The NMTS key comes from a wallet's signature (login, create)`,
152
153
  ` --sui-key-file <p> File holding the wallet's \`suiprivkey1…\` line. Never the key itself.`,
153
154
  ` With put --pay wallet, that wallet pays for the upload`,
155
+ ` --delegation-file <p> File holding a user's delegation token (wallet storage extend).`,
156
+ ` Never the token itself`,
154
157
  ` --account <n> Which of that wallet's accounts. Default 1; it is inside what is signed`,
155
158
  ` --app <name> Scope the signature to one product. Without it, one account everywhere`,
156
159
  ` --version Print the version and exit`,