@needmoretruth/nmts-cli 0.57.0 → 0.59.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 +26 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/arg-options.d.ts +2 -0
- package/dist/args.js +2 -0
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/expiring.js +2 -2
- package/dist/commands/sweep.js +6 -64
- package/dist/commands/wallet-storage-buy.d.ts +22 -0
- package/dist/commands/wallet-storage-buy.js +111 -0
- package/dist/commands/wallet-storage-extend.d.ts +23 -0
- package/dist/commands/wallet-storage-extend.js +137 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.js +5 -1
- package/dist/extend-chain.js +19 -3
- package/dist/extend-plan.d.ts +38 -0
- package/dist/extend-plan.js +61 -0
- package/dist/help-options.js +8 -3
- package/dist/help.js +5 -0
- package/dist/main.js +1 -1
- package/dist/platform-sign.d.ts +12 -0
- package/dist/platform-sign.js +29 -1
- package/dist/portable.d.ts +7 -2
- package/dist/portable.js +7 -2
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-codes.d.ts +14 -3
- package/dist/public-codes.js +14 -5
- package/dist/rebuild.js +9 -24
- package/dist/risk.d.ts +12 -0
- package/dist/risk.js +8 -0
- package/dist/server-objects.d.ts +21 -0
- package/dist/server-objects.js +68 -0
- package/dist/sharing.d.ts +1 -1
- package/dist/sharing.js +12 -40
- package/dist/sponsor-check.d.ts +56 -0
- package/dist/sponsor-check.js +270 -0
- package/dist/sponsor-facts.d.ts +10 -0
- package/dist/sponsor-facts.js +75 -0
- package/dist/storage-control/buy.d.ts +65 -0
- package/dist/storage-control/buy.js +145 -0
- package/dist/storage-control/extend-for.d.ts +84 -0
- package/dist/storage-control/extend-for.js +204 -0
- package/dist/storage-control/extend.d.ts +57 -12
- package/dist/storage-control/extend.js +51 -45
- package/dist/storage-control-chain.d.ts +7 -0
- package/dist/storage-control-chain.js +19 -1
- package/dist/storage-control.d.ts +6 -2
- package/dist/storage-control.js +5 -2
- package/dist/upload-quote.d.ts +93 -0
- package/dist/upload-quote.js +135 -0
- package/dist/wallet-sign.d.ts +24 -0
- package/dist/wallet-sign.js +31 -1
- package/docs/commands/wallet.md +13 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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.0 — 2026-11-11
|
|
7
|
+
|
|
8
|
+
- `nmts wallet storage extend [<item-id>...] --delegation-file <file>` lets a business that paid
|
|
9
|
+
for its users' uploads extend those files from its own wallet. It needs a delegation token for the
|
|
10
|
+
user with `files_read` and `storage_spend`, and not the user's key. The library exports the same
|
|
11
|
+
call as `extendFor`.
|
|
12
|
+
- `extend`, here and in the library, now refuses a file whose storage another wallet holds, and
|
|
13
|
+
names that wallet, before anything is signed.
|
|
14
|
+
- A delegation token with the `share` scope can list, publish and revoke its own account's public
|
|
15
|
+
codes, with the NMTS key's proof on the same request. A device that holds its own key publishes
|
|
16
|
+
its first code itself when it first shares; the business no longer has to.
|
|
17
|
+
- `wallet storage buy` and `wallet storage extend` are rated as signing commands that spend WAL.
|
|
18
|
+
Until now `buy` was rated as a read.
|
|
19
|
+
- `expiring` says "1 day" and "1 file runs out" where it said "1 days" and "1 file run out".
|
|
20
|
+
|
|
21
|
+
## 0.58.0 — 2026-11-11
|
|
22
|
+
|
|
23
|
+
- `nmts wallet storage buy --size <n> [--epochs <n>]` buys a storage resource with nothing in it,
|
|
24
|
+
paid in WAL from the wallet, for 2 epochs unless `--epochs` says otherwise. It shows the price and
|
|
25
|
+
the chain fee first, signs only with `--yes`, and needs `nmts unlock wallet`. `put --pay wallet
|
|
26
|
+
--storage <id>` then writes a file into it.
|
|
27
|
+
- A program can price an upload with no account (`@needmoretruth/nmts-cli/portable` exports
|
|
28
|
+
`quoteUpload`), and a business's server can check a transaction a customer's device built before
|
|
29
|
+
its own wallet signs it (`judgeSponsored`, `signSponsored`): only Walrus storage work within the limits
|
|
30
|
+
it sets passes.
|
|
31
|
+
|
|
6
32
|
## 0.57.0 — 2026-11-10
|
|
7
33
|
|
|
8
34
|
- A program can share a file the way `nmts share` does: `@needmoretruth/nmts-cli/share` exports
|
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.59.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.
|
|
54
|
+
npm install -g github:needmoretruth/nmts-cli#v0.59.0 # a pinned version
|
|
55
55
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
56
56
|
```
|
|
57
57
|
|
package/dist/arg-options.d.ts
CHANGED
|
@@ -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",
|
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.59.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
|
/**
|
|
@@ -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"}
|
|
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(``);
|
package/dist/commands/sweep.js
CHANGED
|
@@ -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
|
-
* ⛔
|
|
186
|
-
*
|
|
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
|
|
195
|
-
|
|
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,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>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// `nmts wallet storage buy --size <n> [--epochs <n>]` — buying a storage resource with no file.
|
|
2
|
+
// ⛔ IT SIGNS AND SPENDS WAL. The order, the price, the dry run and the signature are
|
|
3
|
+
// `storage-control/buy.ts`, which the SDK calls as well; this file is the terminal over it: the
|
|
4
|
+
// words typed, the review read, `--yes`, and the wallet unlock held against what the review measured.
|
|
5
|
+
//
|
|
6
|
+
// ⛔ WHY (spec 2026-09-20 Deponejo · gap B2). A resource bought here is cut and handed on with the
|
|
7
|
+
// three commands beside it (`split`, `merge`, `transfer`), in the same place and under the same
|
|
8
|
+
// unlock scope — buying is a change to the wallet's storage like those, only one that costs WAL.
|
|
9
|
+
import { requireAccountCode } from "../code-access.js";
|
|
10
|
+
import { readCredentialsFile } from "../credentials.js";
|
|
11
|
+
import { NmtsError } from "../errors.js";
|
|
12
|
+
import { resolveNetwork } from "../network.js";
|
|
13
|
+
import { BINARY_NAME } from "../product.js";
|
|
14
|
+
import { resolveServer } from "../server.js";
|
|
15
|
+
import { buyStorage } from "../storage-control.js";
|
|
16
|
+
import { explorerTxUrl } from "../shared/lib/wallet/activity.js";
|
|
17
|
+
import { coinAmount, walletAddress } from "../wallet.js";
|
|
18
|
+
import { payingWalletIndex } from "../wallet-pay-index.js";
|
|
19
|
+
import { recordWalletSpend, requireWalletGrant } from "../wallet-grant.js";
|
|
20
|
+
import { parseBytes } from "./wallet-storage-ops.js";
|
|
21
|
+
import { formatBytes } from "./wallet-storage.js";
|
|
22
|
+
export async function walletStorageBuy(options = {}) {
|
|
23
|
+
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
24
|
+
if (options.size === undefined) {
|
|
25
|
+
throw new NmtsError(`\`${BINARY_NAME} wallet storage buy --size <bytes> [--epochs <n>]\``, { exitCode: 2 });
|
|
26
|
+
}
|
|
27
|
+
const sizeBytes = parseBytes(options.size);
|
|
28
|
+
const epochs = options.epochs === undefined ? undefined : Number(options.epochs);
|
|
29
|
+
const resolved = await requireAccountCode();
|
|
30
|
+
const wallet = await payingWalletIndex(options);
|
|
31
|
+
const address = await walletAddress(resolved.code, wallet);
|
|
32
|
+
const stored = resolved.source === "file" || resolved.source === "file-locked" ? readCredentialsFile() : null;
|
|
33
|
+
const server = resolveServer(options.server ?? stored?.server);
|
|
34
|
+
const network = resolveNetwork(server, options.network ?? stored?.network);
|
|
35
|
+
const command = `${BINARY_NAME} wallet storage buy --size ${options.size}${options.epochs === undefined ? "" : ` --epochs ${options.epochs}`}`;
|
|
36
|
+
// ⛔ WITHOUT `--yes` THE RUN STOPS AT THE REVIEW, exactly as `--dry-run` does.
|
|
37
|
+
const stopAtReview = options.dryRun === true || options.yes !== true;
|
|
38
|
+
const outcome = await buyStorage({ network, code: resolved.code, wallet, address }, { sizeBytes, epochs }, {
|
|
39
|
+
reads: options.buyReads,
|
|
40
|
+
sign: options.signStorage,
|
|
41
|
+
dryRun: stopAtReview,
|
|
42
|
+
onReview: (review) => {
|
|
43
|
+
if (!options.json)
|
|
44
|
+
describe(say, review, wallet);
|
|
45
|
+
},
|
|
46
|
+
// The unlock, held against the price and the fee. ⛔ Throwing here signs nothing.
|
|
47
|
+
agree: (review) => {
|
|
48
|
+
requireWalletGrant("reshape", spendOf(review), new Date(options.now ?? Date.now()));
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const { review } = outcome;
|
|
52
|
+
const facts = {
|
|
53
|
+
op: "buy",
|
|
54
|
+
network,
|
|
55
|
+
address,
|
|
56
|
+
sizeBytes: review.sizeBytes,
|
|
57
|
+
epochs: review.epochs,
|
|
58
|
+
endEpoch: review.endEpoch,
|
|
59
|
+
wal: coinAmount(review.priceFrost),
|
|
60
|
+
feeSui: review.feeMist === null ? null : coinAmount(review.feeMist),
|
|
61
|
+
shortfall: review.shortfall,
|
|
62
|
+
};
|
|
63
|
+
if (outcome.kind === "review") {
|
|
64
|
+
if (options.json) {
|
|
65
|
+
say(JSON.stringify({ ...facts, signed: false, dryRun: options.dryRun === true }));
|
|
66
|
+
return options.dryRun === true ? 0 : 4;
|
|
67
|
+
}
|
|
68
|
+
say(``);
|
|
69
|
+
if (options.dryRun === true) {
|
|
70
|
+
say(` Nothing was signed. Run the same command with --yes to buy it.`);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
throw new NmtsError(`Nothing was signed: this needs --yes.`, {
|
|
74
|
+
exitCode: 4,
|
|
75
|
+
nextStep: `Read the review above, then: \`${command} --yes\``,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
recordWalletSpend(spendOf(review));
|
|
79
|
+
const explorerUrl = explorerTxUrl(outcome.digest, network);
|
|
80
|
+
if (options.json) {
|
|
81
|
+
say(JSON.stringify({ ...facts, signed: true, digest: outcome.digest, id: outcome.objectId, explorerUrl }));
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
say(``);
|
|
85
|
+
say(` Bought. Transaction ${outcome.digest}`);
|
|
86
|
+
if (outcome.objectId !== null)
|
|
87
|
+
say(` Resource ${outcome.objectId}`);
|
|
88
|
+
say(` ${explorerUrl}`);
|
|
89
|
+
say(` \`${BINARY_NAME} wallet storage\` lists it; \`put --pay wallet --storage <id>\` uploads into it.`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
/** What a purchase costs this wallet: the price in WAL and the fee the dry run measured. */
|
|
93
|
+
function spendOf(review) {
|
|
94
|
+
return { walFrost: review.priceFrost, suiMist: review.feeMist ?? 0n };
|
|
95
|
+
}
|
|
96
|
+
/** The review a person reads, in the order somebody deciding needs it. */
|
|
97
|
+
function describe(say, review, wallet) {
|
|
98
|
+
say(`Would buy a storage resource of ${formatBytes(review.sizeBytes)} for ${review.epochs} epoch${review.epochs === 1 ? "" : "s"}, epoch ${review.startEpoch} to ${review.endEpoch}.`);
|
|
99
|
+
say(` paid by ${review.address} (wallet ${wallet}), which also receives it`);
|
|
100
|
+
say(` Storage ${coinAmount(review.priceFrost)} WAL. Writing a file into it later costs its own small WAL.`);
|
|
101
|
+
say(review.feeMist === null
|
|
102
|
+
? ` Chain fee (SUI): could not be measured just now; it is charged with the signature.`
|
|
103
|
+
: ` Chain fee about ${coinAmount(review.feeMist)} SUI, measured by a dry run just now.`);
|
|
104
|
+
const wal = review.walFrost === null ? "WAL not read" : `${coinAmount(review.walFrost)} WAL`;
|
|
105
|
+
const sui = review.suiMist === null ? "SUI not read" : `${coinAmount(review.suiMist)} SUI`;
|
|
106
|
+
say(` The wallet holds ${wal} and ${sui}.`);
|
|
107
|
+
if (review.shortfall !== null)
|
|
108
|
+
say(` ⛔ ${review.shortfall}`);
|
|
109
|
+
say(` The size is what the network holds once a file is encoded, the unit the listing shows.`);
|
|
110
|
+
say(` Nobody, NMTS included, can reverse it.`);
|
|
111
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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;
|
package/dist/commands/wallet.js
CHANGED
|
@@ -61,10 +61,14 @@ export async function wallet(what, options = {}) {
|
|
|
61
61
|
if (sub === "split" || sub === "merge" || sub === "transfer") {
|
|
62
62
|
return (await import("./wallet-storage-ops.js")).walletStorageOps(sub, more, options);
|
|
63
63
|
}
|
|
64
|
+
if (sub === "buy")
|
|
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);
|
|
64
68
|
if (sub !== undefined) {
|
|
65
69
|
throw new NmtsError(`\`${BINARY_NAME} wallet storage ${sub}\` is not something this command does.`, {
|
|
66
70
|
exitCode: 2,
|
|
67
|
-
nextStep: `\`${BINARY_NAME} wallet storage\` lists; \`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\`.`,
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
return (await import("./wallet-storage.js")).walletStorage(options);
|
package/dist/extend-chain.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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.
|
package/dist/extend-plan.d.ts
CHANGED
|
@@ -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;
|