@needmoretruth/nmts-cli 0.42.0 → 0.44.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 (72) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +41 -0
  3. package/README.ko.md +8 -2
  4. package/README.md +8 -2
  5. package/dist/account.d.ts +7 -3
  6. package/dist/account.js +46 -19
  7. package/dist/arg-options.d.ts +16 -0
  8. package/dist/args.js +5 -2
  9. package/dist/artifact-about.d.ts +1 -1
  10. package/dist/commands/ai-account.d.ts +34 -0
  11. package/dist/commands/ai-account.js +260 -0
  12. package/dist/commands/balance.d.ts +68 -0
  13. package/dist/commands/balance.js +11 -1
  14. package/dist/commands/extend.d.ts +3 -0
  15. package/dist/commands/extend.js +1 -0
  16. package/dist/commands/login.js +2 -2
  17. package/dist/commands/push-wallet.js +4 -1
  18. package/dist/commands/push.d.ts +3 -0
  19. package/dist/commands/put-payer.d.ts +3 -1
  20. package/dist/commands/put-payer.js +13 -1
  21. package/dist/commands/put-wallet.d.ts +31 -0
  22. package/dist/commands/put-wallet.js +84 -10
  23. package/dist/commands/put.d.ts +5 -0
  24. package/dist/commands/whoami.d.ts +4 -0
  25. package/dist/commands/whoami.js +14 -1
  26. package/dist/crypto-surface.d.ts +11 -0
  27. package/dist/crypto-surface.js +6 -0
  28. package/dist/drive-edit/tree.d.ts +12 -0
  29. package/dist/drive-edit/tree.js +25 -4
  30. package/dist/drive-erase.d.ts +5 -3
  31. package/dist/drive-erase.js +7 -2
  32. package/dist/help-options.d.ts +2 -0
  33. package/dist/help-options.js +142 -0
  34. package/dist/help.js +10 -123
  35. package/dist/main.js +14 -19
  36. package/dist/mcp-tools/reads.js +4 -3
  37. package/dist/portable.d.ts +1 -1
  38. package/dist/portable.js +1 -1
  39. package/dist/product.d.ts +1 -1
  40. package/dist/product.js +1 -1
  41. package/dist/refill-source.d.ts +69 -0
  42. package/dist/refill-source.js +143 -0
  43. package/dist/risk.d.ts +12 -0
  44. package/dist/risk.js +16 -0
  45. package/dist/shared/lib/wallet/activity.js +23 -1
  46. package/dist/standing-tip.d.ts +26 -0
  47. package/dist/standing-tip.js +31 -0
  48. package/dist/storage-control/extend.d.ts +10 -0
  49. package/dist/storage-control/extend.js +1 -1
  50. package/dist/upload-store.d.ts +10 -0
  51. package/dist/upload-wallet-plan.d.ts +8 -0
  52. package/dist/upload-wallet-plan.js +12 -3
  53. package/dist/upload-wallet-put.d.ts +16 -0
  54. package/dist/upload-wallet-put.js +4 -2
  55. package/dist/upload-wallet.d.ts +11 -0
  56. package/dist/upload-wallet.js +14 -0
  57. package/dist/wallet-sign-external.d.ts +120 -0
  58. package/dist/wallet-sign-external.js +221 -0
  59. package/dist/wallet-sign.js +3 -1
  60. package/dist/walrus.d.ts +9 -1
  61. package/dist/walrus.js +17 -3
  62. package/docs/commands/ai-account.md +25 -0
  63. package/docs/commands/login.md +4 -3
  64. package/docs/commands/verify.md +1 -1
  65. package/docs/commands/whoami.md +4 -0
  66. package/examples/podman.sh +48 -0
  67. package/package.json +6 -1
  68. package/server.json +2 -2
  69. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +42 -6
  70. package/vendor/nmts-crypto/nmts_crypto_wasm.js +105 -2
  71. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  72. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +9 -4
@@ -0,0 +1,143 @@
1
+ // Taking a file that credits paid for and handing it back as something a wallet can pay for:
2
+ // finding it in the sealed list, and getting its plaintext onto this machine once.
3
+ //
4
+ // ⛔ WHY IT IS A DOWNLOAD AND A RE-SEAL RATHER THAN A MOVE. Storage on the network is bought for
5
+ // particular bytes under a particular blob id, and the treasury owns the storage under a
6
+ // credit-paid part. Nothing on the chain can transfer that object to somebody's own wallet, and
7
+ // nothing in NMTS can re-point an existing part at storage bought elsewhere. So the only honest
8
+ // shape is: read the file out, seal it again, buy storage for the new sealing, and let the old
9
+ // file go to the trash — which is what `put --pay wallet --from <path>` does.
10
+ //
11
+ // ⛔ THE PLAINTEXT LANDS IN THIS TOOL'S OWN DIRECTORY, NOT IN THE SYSTEM TEMPORARY ONE. It is
12
+ // somebody's decrypted file; `/tmp` is world-listable on every machine this runs on, and a name
13
+ // other accounts can see is a name they can watch for. The config directory is 0700 where the
14
+ // platform honours it, the file itself is 0600 (`fileSink`), and it is removed on every path out
15
+ // including the failing ones.
16
+ //
17
+ // ⚠ IT IS A COPY ON DISK FOR AS LONG AS THE UPLOAD TAKES, and that is the price of not holding a
18
+ // whole file in memory. A caller who cannot pay it should download and upload by hand, which is
19
+ // the same two acts with the copy in a place they chose.
20
+ import { mkdirSync, rmSync } from "node:fs";
21
+ import { randomBytes } from "node:crypto";
22
+ import { join } from "node:path";
23
+ import { configDir } from "./credentials.js";
24
+ import { setTrashed } from "./item-trash.js";
25
+ import { applyManyToList } from "./manifest-write.js";
26
+ import { fetchFile } from "./download.js";
27
+ import { fileSink } from "./download-sink-node.js";
28
+ import { buildIndex, entryAt, fullPathOf, isLive, KIND_FILE, normalisePath } from "./drive-paths.js";
29
+ import { NmtsError } from "./errors.js";
30
+ import { BINARY_NAME } from "./product.js";
31
+ /**
32
+ * The live file a drive path names, with the place the replacement goes.
33
+ *
34
+ * ⛔ A FOLDER, A TRASHED FILE AND A FILE WITH NO KEY ARE ALL REFUSED HERE, before anything is
35
+ * priced. Each one would fail later, after a price had been quoted and possibly after money had
36
+ * moved, and the third would fail in the worst place of all: the download.
37
+ */
38
+ export function findOriginal(entries, path) {
39
+ const wanted = normalisePath(path);
40
+ const index = buildIndex(entries);
41
+ const entry = entryAt(entries, wanted, { nothingHappened: "Nothing was signed and nothing was sent." });
42
+ if (entry.kind !== KIND_FILE) {
43
+ throw new NmtsError(`"${wanted}" is a folder.`, {
44
+ exitCode: 4,
45
+ nextStep: `Nothing was signed. --from takes one file at a time.`,
46
+ });
47
+ }
48
+ if (!isLive(index, entry)) {
49
+ throw new NmtsError(`"${wanted}" is in the trash.`, {
50
+ exitCode: 4,
51
+ nextStep: `Nothing was signed. \`${BINARY_NAME} restore\` brings it back, and then this can re-upload it.`,
52
+ });
53
+ }
54
+ if (entry.dekWrapped === undefined) {
55
+ throw new NmtsError(`The file list holds no key for "${wanted}".`, {
56
+ exitCode: 4,
57
+ nextStep: `Nothing was signed. Without it nothing can open the stored bytes, so there is nothing to re-seal.`,
58
+ });
59
+ }
60
+ const full = fullPathOf(index, entry);
61
+ return {
62
+ entry,
63
+ name: entry.name,
64
+ parentId: entry.parentId,
65
+ destination: full.slice(0, Math.max(0, full.length - entry.name.length)).replace(/\/$/, ""),
66
+ };
67
+ }
68
+ /**
69
+ * Read one file out of the account and leave it on this machine, checked.
70
+ *
71
+ * ⛔ THE SAME READ `nmts get` MAKES, including the whole-file hash. A re-upload that sealed bytes
72
+ * the download had not proved would replace a good file with a corrupt one and put the good one
73
+ * in the trash — the one outcome this command must never produce.
74
+ */
75
+ export async function downloadForRefill(input) {
76
+ const { entry } = input.original;
77
+ const dekWrapped = entry.dekWrapped;
78
+ if (dekWrapped === undefined)
79
+ throw new NmtsError("unreachable: an original with no key");
80
+ const area = join(configDir(), "refill");
81
+ mkdirSync(area, { recursive: true, mode: 0o700 });
82
+ const localPath = join(area, `${randomBytes(9).toString("hex")}.part`);
83
+ const remove = () => rmSync(localPath, { force: true });
84
+ try {
85
+ await fetchFile({
86
+ base: input.server,
87
+ apiKey: input.apiKey,
88
+ accountCode: input.code,
89
+ itemId: entry.id,
90
+ size: entry.size,
91
+ dekWrapped,
92
+ ...(entry.contentHashCt === undefined ? {} : { contentHashCt: entry.contentHashCt }),
93
+ chain: input.network,
94
+ sink: fileSink(localPath, { force: true }),
95
+ });
96
+ }
97
+ catch (error) {
98
+ remove();
99
+ throw error;
100
+ }
101
+ return { localPath, remove };
102
+ }
103
+ /**
104
+ * Give the new file the old one's name and put the old one in the trash — after the upload, in one
105
+ * write.
106
+ *
107
+ * ⛔ WHY IT IS A SECOND WRITE AND NOT AN OVERWRITE ON THE COMMIT. `collision.ts` refuses to let a
108
+ * per-run answer of "overwrite" take effect while this machine is in the default mode, on
109
+ * purpose: a program passing a flag must not be able to destroy a file. That rule is not worked
110
+ * around here. The upload lands as an ordinary addition — numbered beside the original if the
111
+ * machine renames — and only then, with the paid-for bytes safely in the list, is the name moved
112
+ * across and the original trashed. A person named the file they were replacing; nothing here
113
+ * decides that for anybody.
114
+ *
115
+ * ⛔ AND THE ORDER IS THE ONE THE WHOLE TOOL KEEPS: the new file is committed first, so a failure
116
+ * anywhere in this step leaves both files in the drive rather than neither. Running the same
117
+ * command again is not the repair for that — the file is already there under a numbered name —
118
+ * so what a failure here costs is a rename somebody does by hand, never bytes.
119
+ *
120
+ * ⚠ IT IS DECIDED AGAIN ON EVERY ATTEMPT of the compare-and-swap, which is what makes it safe to
121
+ * replay: a list where another device already trashed the original, or where this run's own
122
+ * earlier attempt already renamed the new file, produces no intent for that half.
123
+ */
124
+ export async function settleRefill(input, original, newItemId) {
125
+ const at = Date.now();
126
+ const result = await applyManyToList(input, (entries) => {
127
+ const intents = [];
128
+ const old = entries.find((e) => e.id === original.entry.id);
129
+ if (old !== undefined && old.deletedAt === undefined) {
130
+ intents.push({ op: "trash", ids: [original.entry.id], at });
131
+ }
132
+ const fresh = entries.find((e) => e.id === newItemId);
133
+ if (fresh !== undefined && fresh.name !== original.name) {
134
+ intents.push({ op: "rename", id: newItemId, name: original.name, at });
135
+ }
136
+ return intents;
137
+ });
138
+ // ⛔ THE SERVER IS TOLD LAST, and a 404 there is "already in that state" (`item-trash.ts`). Until
139
+ // this line the original is a live row the account still holds — which is the harmless
140
+ // direction: it is restorable, it still expires on its own, and `nmts rm` finishes the job.
141
+ await setTrashed(input.server, input.apiKey, original.entry.id, true);
142
+ return result.seq;
143
+ }
package/dist/risk.d.ts CHANGED
@@ -50,6 +50,9 @@ export declare const ACTS: {
50
50
  readonly losses: {
51
51
  readonly tier: "none";
52
52
  };
53
+ readonly "ai-account": {
54
+ readonly tier: "none";
55
+ };
53
56
  readonly "public-code": {
54
57
  readonly tier: "none";
55
58
  };
@@ -335,6 +338,10 @@ export declare const ACTS: {
335
338
  readonly what: "Create a new account under the Terms in force.";
336
339
  readonly asksItself: true;
337
340
  };
341
+ readonly "ai-account.create": {
342
+ readonly tier: "high";
343
+ readonly what: "Make a new account for an AI to work in, under the Terms in force.";
344
+ };
338
345
  readonly "accept-terms.accept": {
339
346
  readonly tier: "high";
340
347
  readonly what: "Accept a new version of the Terms for this account.";
@@ -345,6 +352,11 @@ export declare const ACTS: {
345
352
  readonly what: "Erase this account's server record, permanently.";
346
353
  readonly asksItself: true;
347
354
  };
355
+ readonly "ai-account.delete": {
356
+ readonly tier: "ultra-high";
357
+ readonly what: "Erase an AI account this one made, and everything in it, permanently.";
358
+ readonly asksItself: true;
359
+ };
348
360
  readonly erase: {
349
361
  readonly tier: "ultra-high";
350
362
  readonly what: "Erase files for good: the server's record and this account's key to them.";
package/dist/risk.js CHANGED
@@ -35,6 +35,9 @@ export const ACTS = {
35
35
  trial: { tier: "none" },
36
36
  expiring: { tier: "none" },
37
37
  losses: { tier: "none" },
38
+ // Reading which accounts this one has made for an AI. The two acts that change something are
39
+ // below, under the tiers they belong to.
40
+ "ai-account": { tier: "none" },
38
41
  "public-code": { tier: "none" },
39
42
  wallet: { tier: "none" },
40
43
  get: { tier: "none" },
@@ -132,9 +135,20 @@ export const ACTS = {
132
135
  "whoami.reveal": { tier: "high", lock: "reveal", what: "Print the NMTS key on this screen." },
133
136
  kit: { tier: "high", lock: "kit", what: "Write the NMTS key into a recovery kit file on this disk." },
134
137
  create: { tier: "high", what: "Create a new account under the Terms in force.", asksItself: true },
138
+ // ⛔ BESIDE `create`, BECAUSE IT IS THE SAME ACT aimed at a new account: it makes an account under
139
+ // the Terms in force, and the acceptance recorded for it is this caller's own. It does not ask
140
+ // itself — there is no version for anybody to type, so the gate takes the yes.
141
+ "ai-account.create": { tier: "high", what: "Make a new account for an AI to work in, under the Terms in force." },
135
142
  "accept-terms.accept": { tier: "high", what: "Accept a new version of the Terms for this account.", asksItself: true },
136
143
  // ── ultra-high: permanent destruction ──
137
144
  "delete-account": { tier: "ultra-high", what: "Erase this account's server record, permanently.", asksItself: true },
145
+ // ⛔ THE SAME ERASURE, AIMED AT AN ACCOUNT THIS ONE MADE — the row, the files, the keys and the
146
+ // shares in both directions. It types the same sentence `delete-account` does.
147
+ "ai-account.delete": {
148
+ tier: "ultra-high",
149
+ what: "Erase an AI account this one made, and everything in it, permanently.",
150
+ asksItself: true,
151
+ },
138
152
  erase: { tier: "ultra-high", what: "Erase files for good: the server's record and this account's key to them.", asksItself: true },
139
153
  "erase.release": {
140
154
  tier: "ultra-high",
@@ -190,6 +204,8 @@ export function actOf(args) {
190
204
  return args.pay === "wallet" ? "push.wallet" : "push";
191
205
  case "key":
192
206
  return sub === "new" ? "key.new" : sub === "revoke" ? "key.revoke" : "key";
207
+ case "ai-account":
208
+ return sub === "create" ? "ai-account.create" : sub === "delete" ? "ai-account.delete" : "ai-account";
193
209
  case "openers":
194
210
  return sub === "add" ? "openers.add" : sub === "remove" ? "openers.remove" : "openers";
195
211
  case "trial":
@@ -83,6 +83,25 @@ function inputObjectIds(tx) {
83
83
  }
84
84
  return ids;
85
85
  }
86
+ /**
87
+ * One balance change's amount, or null when the RPC's figure is not a whole decimal number.
88
+ *
89
+ * ⛔ WHY NULL RATHER THAN ZERO, AND WHY IT IS CHECKED AT ALL. `BigInt("1.5")` and `BigInt("")`
90
+ * THROW, and this parse sits inside `toActivityRow`, which the list runs once per transaction —
91
+ * so ONE malformed figure from ONE entry threw all the way out and the whole activity list came
92
+ * up EMPTY, with nothing on screen to say why. The declared type says `string`, but the value
93
+ * arrives as JSON from a public mirror we do not control, so the shape is a claim, not a fact.
94
+ * ▶ A figure that cannot be read is ONE entry that cannot be priced: that entry is dropped and
95
+ * every other row still stands. Zero would be worse than dropping it — it would print a real
96
+ * movement as "0", which is the "not knowing drawn as nothing happened" this file forbids.
97
+ */
98
+ function amountOf(raw) {
99
+ if (typeof raw !== "string")
100
+ return null;
101
+ const text = raw.trim();
102
+ // The regex is what makes BigInt total here: only an optionally-signed run of digits reaches it.
103
+ return /^-?\d+$/.test(text) ? BigInt(text) : null;
104
+ }
86
105
  /** The functions of the Walrus `system` module whose names we know → our kind. */
87
106
  const WALRUS_FUNCTION_KIND = {
88
107
  register_blob: "seal",
@@ -114,7 +133,10 @@ export function toActivityRow(tx, ctx) {
114
133
  if (owner === null)
115
134
  continue;
116
135
  const normalized = normalizeAddress(owner);
117
- const amount = BigInt(change.amount ?? "0");
136
+ const amount = change.amount === undefined ? 0n : amountOf(change.amount);
137
+ // An entry whose figure we cannot read is skipped; the rest of the transaction is still a row.
138
+ if (amount === null)
139
+ continue;
118
140
  if (normalized === me) {
119
141
  const coinType = change.coinType ?? "";
120
142
  changes.push({
@@ -1,6 +1,24 @@
1
1
  import { type DonationConfig } from "./commands/wallet-donate.ts";
2
2
  import type { Network } from "./network.ts";
3
3
  import type { SignTransfer } from "./wallet-sign.ts";
4
+ /**
5
+ * Where a standing gift goes, per network — written into the build, not asked for.
6
+ *
7
+ * ⛔ THE RECEIVING ADDRESS IS NOT THE SERVER'S TO CHOOSE. Until now it was whatever `--server`
8
+ * answered and only its SHAPE was checked, so one wrong or hostile server collected every
9
+ * standing gift from every machine pointed at it — silently, because a well-formed address is
10
+ * indistinguishable from the right one. The browser never had that hole: its address comes from
11
+ * the build the owner ships. This is that same value, and the server's answer is held against
12
+ * it below.
13
+ *
14
+ * ⚠ ONE STRING UNDER TWO NETWORKS, and that is a fact rather than a placeholder: a Sui address
15
+ * belongs to a keypair, not to a network, so the owner's wallet is the same address on both. The
16
+ * table is per network so that the day one of them moves there is a line to change.
17
+ *
18
+ * ⛔ IT IS A PUBLIC VALUE, NOT A SECRET. An address is what you hand out to be paid — the site
19
+ * prints this one on the donation card — and the key behind it is nowhere near this package.
20
+ */
21
+ export declare const TIP_ADDRESS: Readonly<Record<Network, string>>;
4
22
  /** The owner's thank-you, in both languages, printed after every gift whatever its size. */
5
23
  export declare const THANKS_EN = "Thank you for your gift. Honestly, I did not know anyone would. Thank you.";
6
24
  export declare const THANKS_KO = "\uD6C4\uC6D0\uD574 \uC8FC\uC154\uC11C \uC815\uB9D0 \uAC10\uC0AC\uD569\uB2C8\uB2E4. \uC0AC\uC2E4 \uC800\uB294 \uD6C4\uC6D0\uD574 \uC904 \uC0AC\uB78C\uC774 \uC788\uC744 \uAC70\uB77C\uACE0\uB3C4 \uBAB0\uB790\uC2B5\uB2C8\uB2E4. \uC815\uB9D0 \uAC10\uC0AC\uD569\uB2C8\uB2E4.";
@@ -19,6 +37,14 @@ export interface StandingTipInput {
19
37
  * a balance nobody was looking at, and the payment above named this one. */
20
38
  wallet: number;
21
39
  say: (line: string) => void;
40
+ /**
41
+ * Send to the address THIS SERVER names, even when it is not the one pinned above.
42
+ *
43
+ * ⛔ OFF BY DEFAULT AND IT HAS TO STAY THAT WAY. It exists for somebody running their own NMTS
44
+ * server, whose developer address is their own and is not ours; switching it on for a server
45
+ * you do not run hands that server every standing gift this machine sends.
46
+ */
47
+ trustServerAddress?: boolean;
22
48
  /** Seams for tests. */
23
49
  readDonation?: (server: string) => Promise<DonationConfig>;
24
50
  sign?: SignTransfer;
@@ -16,6 +16,27 @@ import { asDonationConfig } from "./commands/wallet-donate.js";
16
16
  import { isValidSuiAddress } from "./shared/lib/wallet/send-rules.js";
17
17
  import { percentText, tipFromTenths } from "./shared/lib/wallet/tip.js";
18
18
  import { coinAmount, walCoinType } from "./wallet.js";
19
+ /**
20
+ * Where a standing gift goes, per network — written into the build, not asked for.
21
+ *
22
+ * ⛔ THE RECEIVING ADDRESS IS NOT THE SERVER'S TO CHOOSE. Until now it was whatever `--server`
23
+ * answered and only its SHAPE was checked, so one wrong or hostile server collected every
24
+ * standing gift from every machine pointed at it — silently, because a well-formed address is
25
+ * indistinguishable from the right one. The browser never had that hole: its address comes from
26
+ * the build the owner ships. This is that same value, and the server's answer is held against
27
+ * it below.
28
+ *
29
+ * ⚠ ONE STRING UNDER TWO NETWORKS, and that is a fact rather than a placeholder: a Sui address
30
+ * belongs to a keypair, not to a network, so the owner's wallet is the same address on both. The
31
+ * table is per network so that the day one of them moves there is a line to change.
32
+ *
33
+ * ⛔ IT IS A PUBLIC VALUE, NOT A SECRET. An address is what you hand out to be paid — the site
34
+ * prints this one on the donation card — and the key behind it is nowhere near this package.
35
+ */
36
+ export const TIP_ADDRESS = {
37
+ mainnet: "0x5414efbeeab97a210e3ad48e458056fd62bcfc0d99ea78b632b813a6540c09c1",
38
+ testnet: "0x5414efbeeab97a210e3ad48e458056fd62bcfc0d99ea78b632b813a6540c09c1",
39
+ };
19
40
  /** The owner's thank-you, in both languages, printed after every gift whatever its size. */
20
41
  export const THANKS_EN = "Thank you for your gift. Honestly, I did not know anyone would. Thank you.";
21
42
  export const THANKS_KO = "후원해 주셔서 정말 감사합니다. 사실 저는 후원해 줄 사람이 있을 거라고도 몰랐습니다. 정말 감사합니다."; // shown in Korean
@@ -33,6 +54,16 @@ export async function standingTipAfter(input) {
33
54
  input.say(` Your standing ${percentText(tenths)} % gift was not sent: gifts in WAL are not open right now.`);
34
55
  return "failed";
35
56
  }
57
+ // ⛔ THE ONE CHECK THAT COSTS NOTHING AND CLOSES THE HOLE. Everything above asks whether a gift
58
+ // may be sent; this asks whether it is going where the person meant. A mismatch is refused
59
+ // rather than reported afterwards — money does not come back from a wrong address.
60
+ if (config.devAddress !== TIP_ADDRESS[input.network] && input.trustServerAddress !== true) {
61
+ input.say(` Your standing ${percentText(tenths)} % gift was not sent: this server named a different ` +
62
+ `receiving address than the one built into this tool for ${input.network}.`);
63
+ input.say(` Nothing was signed. On a server you run yourself, --trust-server-tip-address sends to ` +
64
+ `the address that server names.`);
65
+ return "failed";
66
+ }
36
67
  const sign = input.sign ?? (await import("./wallet-sign.js")).signTransfer;
37
68
  const digest = await sign({
38
69
  network: input.network,
@@ -79,6 +79,16 @@ export interface ExtendPlanSeams {
79
79
  epochs?: string | number | undefined;
80
80
  /** Which of this key's wallets pays. Absent = the account's own number, out of the list read here. */
81
81
  wallet?: number | undefined;
82
+ /**
83
+ * A wallet OUTSIDE this tool that pays instead — its address, because this is where the price is
84
+ * measured against a balance.
85
+ *
86
+ * ⛔ THE SIGNATURE HAS TO COME FROM THE SAME ADDRESS (`wallet-sign-external.ts`), and the blobs
87
+ * have to be ones that wallet paid for: extending storage is a payment by whoever holds it.
88
+ */
89
+ payer?: {
90
+ address: string;
91
+ } | undefined;
82
92
  /** The instant to measure against. Passed in so one run reports one moment. */
83
93
  now: number;
84
94
  /** What this caller wants said in a refusal instead of the neutral sentence. */
@@ -107,7 +107,7 @@ export async function planExtension(input, target, seams) {
107
107
  // ⛔ WHICH WALLET PAYS comes out of the list this run already read, before the price is measured
108
108
  // against a balance: the address below is the one that will sign.
109
109
  const wallet = seams.wallet ?? activeWalletOf(settings);
110
- const address = await walletAddress(input.code, wallet);
110
+ const address = seams.payer?.address ?? (await walletAddress(input.code, wallet));
111
111
  const budget = await readBudget(reads, { address, objectIds, epochs, priceFrost: frost });
112
112
  return {
113
113
  facts: {
@@ -119,6 +119,16 @@ export interface Reservation {
119
119
  * a part under the wrong payer.
120
120
  */
121
121
  paidFrom?: "wallet";
122
+ /**
123
+ * Wallet rail: the address that signed, when the wallet paying was one OUTSIDE this tool. Absent
124
+ * when the wallet this NMTS key derives paid, which is what it has always been.
125
+ *
126
+ * ⛔ WRITTEN SO A RESUME CANNOT CHANGE PAYER. What a registration creates belongs to the address
127
+ * that signed for it: only that wallet can certify the part or ever reclaim its storage. A
128
+ * later run paying from somewhere else would spend a fee to be refused on-chain, so
129
+ * `upload-wallet.ts` compares this and says so instead.
130
+ */
131
+ payerAddress?: string;
122
132
  /** Wallet rail: present once the certify transaction executed — the part is finished on-chain. */
123
133
  certifyTxDigest?: string;
124
134
  /** Wallet rail: the epoch the bought storage ends at, read from the blob object after registering. */
@@ -125,4 +125,12 @@ export declare function describeUploadReview(say: (line: string) => void, facts:
125
125
  tipMist: bigint;
126
126
  storage: StorageChoice;
127
127
  heldResources: number | null;
128
+ /**
129
+ * Does this account ask its uploads to carry the recovery list's storage-network copy?
130
+ *
131
+ * ⚠ `null` = it could not be read. The sentence below is said for `true` AND for `null`,
132
+ * because silence would let somebody assume a copy rode along; only a switch known to be
133
+ * off buys silence.
134
+ */
135
+ networkCopy: boolean | null;
128
136
  }, budget: UploadBudget): void;
@@ -178,7 +178,16 @@ export function describeUploadReview(say, facts, budget) {
178
178
  say(``);
179
179
  say(` This is paid in WAL and SUI from the wallet this NMTS key derives — not from credits, which`);
180
180
  say(` is what \`${BINARY_NAME} put\` spends without --pay wallet. Nobody, NMTS included, can reverse it.`);
181
- say(` The storage is the wallet's own: NMTS records the file and does not hold it. This upload does`);
182
- say(` not carry the recovery list's storage-network copy, whatever the account's switch says —`);
183
- say(` only the browser's small-file uploads do.`);
181
+ say(` The storage is the wallet's own: NMTS records the file and does not hold it.`);
182
+ // ⛔ SAID WHERE IT CHANGES WHAT SOMEBODY GETS, AND NOWHERE ELSE. The wallet rail never carries
183
+ // the recovery list's copy; an account that never asked for one has nothing to be told, and
184
+ // the sentence was printed to everybody until this account's own switch became readable
185
+ // (`GET /v1/account/summary` `network_copy`, 2026-09-20).
186
+ if (facts.networkCopy !== false) {
187
+ say(facts.networkCopy === true
188
+ ? ` This account asks for the recovery list to be copied to the storage network with its uploads.`
189
+ : ` Whether this account asks for the recovery list's storage-network copy could not be read.`);
190
+ say(` This upload does not carry that copy — only the browser's small-file uploads write one, and`);
191
+ say(` \`${BINARY_NAME} recovery-list\` writes the list out as a file from here.`);
192
+ }
184
193
  }
@@ -28,8 +28,24 @@ export interface WalletPutContext {
28
28
  * ⛔ THE CALLER RESOLVES IT, BEFORE ANYTHING IS PRICED. It is the account's own number, kept in
29
29
  * the sealed file list (`wallet-pay-index.ts`), and a library that guessed at it here would
30
30
  * price one address and sign with another.
31
+ *
32
+ * ⚠ Ignored when `payer` names a wallet this key does not derive — see below.
31
33
  */
32
34
  wallet: number;
35
+ /**
36
+ * A wallet OUTSIDE this tool that pays instead: somebody's browser extension, a hardware wallet,
37
+ * a remote signer.
38
+ *
39
+ * ⛔ IT IS THE ADDRESS, HERE, BECAUSE THIS IS WHERE THE PRICE IS MEASURED. Everything below reads
40
+ * one address — the quote's sender, both balances, the measured register fee, the review, and
41
+ * the sentence that says where to send coins — and that address has to be the one that will
42
+ * sign. Absent, it is the wallet `wallet` names, exactly as before; present, the `sign` seam
43
+ * must be the signer of that same address (`wallet-sign-external.ts`), and nothing here derives
44
+ * a key at all.
45
+ */
46
+ payer?: {
47
+ address: string;
48
+ } | undefined;
33
49
  }
34
50
  /** One file and where it goes — already resolved, because a library resolves nothing by asking. */
35
51
  export interface WalletPutFile {
@@ -73,8 +73,9 @@ export async function walletPut(ctx, file, seams = {}) {
73
73
  const epochs = chooseUploadEpochs(seams.epochs, window);
74
74
  const endEpoch = window.clock.current + epochs;
75
75
  const quotes = await reads.quoteParts(sealedLens, epochs);
76
- // ⛔ THE ADDRESS THAT IS PRICED IS THE ADDRESS THAT SIGNS — the same number the rail carries.
77
- const address = await walletAddress(ctx.code, ctx.wallet);
76
+ // ⛔ THE ADDRESS THAT IS PRICED IS THE ADDRESS THAT SIGNS — the same wallet the rail carries,
77
+ // whether that is a number this key derives or a wallet the caller holds the key to.
78
+ const address = ctx.payer?.address ?? (await walletAddress(ctx.code, ctx.wallet));
78
79
  let storage = { kind: "buy" };
79
80
  let heldResources = null;
80
81
  if (storageAsk !== null) {
@@ -159,6 +160,7 @@ export async function walletPut(ctx, file, seams = {}) {
159
160
  network: ctx.network,
160
161
  code: ctx.code,
161
162
  wallet: ctx.wallet,
163
+ ...(ctx.payer === undefined ? {} : { payer: ctx.payer }),
162
164
  relayUrl: protocol.relayUrl,
163
165
  epochs,
164
166
  storage,
@@ -10,6 +10,17 @@ export interface WalletRailContext {
10
10
  /** Which of this key's wallets pays — the account's own number, resolved before anything was
11
11
  * priced (`wallet-pay-index.ts`), so the address in the review is the address that signs. */
12
12
  wallet: number;
13
+ /**
14
+ * Set when a wallet OUTSIDE this tool is paying, and then it is that wallet's address.
15
+ *
16
+ * ⛔ IT GOES INTO THE RECORD SO A RESUME CANNOT CHANGE PAYER. The blob object a registration
17
+ * creates belongs to the address that signed for it, and only that address can certify it or
18
+ * reclaim its storage. A second run that finished this part from another wallet would spend a
19
+ * fee to be refused by the chain, so the mismatch is said here instead.
20
+ */
21
+ payer?: {
22
+ address: string;
23
+ } | undefined;
13
24
  relayUrl: string;
14
25
  epochs: number;
15
26
  /** Where the storage comes from. A held resource serves one blob, so it applies to a one-part file. */
@@ -41,6 +41,19 @@ async function buyAndPushPartWithWallet(ctx, input) {
41
41
  "to start over. Nothing was sent.",
42
42
  });
43
43
  }
44
+ // ⛔ THE SAME WALLET FINISHES WHAT IT STARTED. The record names the payer when one was outside
45
+ // this tool; whoever is paying now has to be the same address, because the blob object and its
46
+ // storage belong to the wallet that registered them.
47
+ if (existing !== null && (existing.payerAddress ?? null) !== (ctx.payer?.address ?? null)) {
48
+ const started = existing.payerAddress ?? "the wallet this NMTS key derives";
49
+ throw new UploadError({
50
+ phase: "reserve",
51
+ message: `This upload was started with ${started} paying, and this run would pay from ${ctx.payer?.address ?? "the wallet this NMTS key derives"}.`,
52
+ paid: existing.registerTxDigest !== undefined,
53
+ nextStep: "Nothing was sent. Run it again with the wallet that started it, or clear the unfinished " +
54
+ "upload records to start over — the storage the first wallet bought stays that wallet's.",
55
+ });
56
+ }
44
57
  if (existing !== null && (existing.partIndex !== input.part.index || existing.partTotal !== input.part.total)) {
45
58
  throw new UploadError({
46
59
  phase: "reserve",
@@ -97,6 +110,7 @@ async function buyAndPushPartWithWallet(ctx, input) {
97
110
  contentHashCt: input.entry.contentHashCt,
98
111
  name: input.entry.name,
99
112
  parentId: input.entry.parentId,
113
+ ...(ctx.payer === undefined ? {} : { payerAddress: ctx.payer.address }),
100
114
  };
101
115
  // ⛔ BEFORE THE SIGNATURE. See the module header.
102
116
  await writeReservation(key, record, sealed);
@@ -0,0 +1,120 @@
1
+ import type { SignExtension } from "./extend-plan.ts";
2
+ import { type KeepTryingOptions } from "./net-retry.ts";
3
+ import type { SignBlobCertify, SignBlobRegister, SignStorageOp } from "./wallet-sign-seams.ts";
4
+ /** What a wallet answers once it has signed: the bytes it signed, and the signature over them. */
5
+ export interface SignedTransaction {
6
+ /** Base64 — what a browser wallet answers — or the raw bytes. */
7
+ bytes: Uint8Array | string;
8
+ signature: string;
9
+ }
10
+ /**
11
+ * The wallet that pays, from outside this tool.
12
+ *
13
+ * ⚠ THE SHAPE IS THE WALLET STANDARD'S, so a page hands over what `useSignTransaction()` gives it
14
+ * and a server hands over whatever signs for the person whose storage this is.
15
+ */
16
+ export interface ExternalPayer {
17
+ /**
18
+ * The address that pays: the sender of every transaction below, and the address whose balances
19
+ * the price was measured against.
20
+ */
21
+ address: string;
22
+ /** Asked once per transaction. `chain` is `sui:mainnet` or `sui:testnet`. */
23
+ signTransaction(input: {
24
+ bytes: Uint8Array;
25
+ chain: string;
26
+ }): Promise<SignedTransaction>;
27
+ }
28
+ /** What the chain says about one submitted transaction. */
29
+ export interface SubmittedTransaction {
30
+ digest: string;
31
+ effects?: unknown;
32
+ objectChanges?: unknown;
33
+ }
34
+ /**
35
+ * Just the three calls a submitted transaction needs.
36
+ *
37
+ * ⚠ NARROW ON PURPOSE: a test hands in a client that answers from a table, and every real client
38
+ * fits it. Asking the node the plain question is also why the wallet is only ever asked to SIGN —
39
+ * a wallet's own "sign and execute" would answer a digest and leave the judging to nobody.
40
+ */
41
+ export interface SubmitClient {
42
+ executeTransactionBlock(input: {
43
+ transactionBlock: Uint8Array;
44
+ signature: string | string[];
45
+ options: {
46
+ showEffects: true;
47
+ showObjectChanges: true;
48
+ };
49
+ }): Promise<SubmittedTransaction>;
50
+ getTransactionBlock(input: {
51
+ digest: string;
52
+ options: {
53
+ showEffects: true;
54
+ showObjectChanges: true;
55
+ };
56
+ }): Promise<SubmittedTransaction>;
57
+ waitForTransaction(input: {
58
+ digest: string;
59
+ }): Promise<unknown>;
60
+ }
61
+ /** What a caller is told when one of these transactions does not go through. */
62
+ export interface ExternalRefusals {
63
+ /** What is true when the WALLET said no. Nothing was signed, by definition. */
64
+ unsigned: string;
65
+ /** What the chain refused, named as a sentence, and what is true once it has. */
66
+ refused: {
67
+ what: string;
68
+ nextStep: string;
69
+ };
70
+ }
71
+ /**
72
+ * One transaction, from bytes to a judged result: ask the wallet, submit it once, read the effects.
73
+ *
74
+ * ⛔ THE ONLY THING THAT CAN THROW BEFORE A SIGNATURE EXISTS IS THE WALLET SAYING NO, and it is
75
+ * named `WALLET_REFUSED` rather than passed on as whatever the wallet threw: a person who
76
+ * declined is not a broken wallet, and a caller that cannot tell them apart shows the wrong
77
+ * sentence to somebody who did exactly what they meant to.
78
+ */
79
+ export declare function signAndSubmit(client: SubmitClient, payer: ExternalPayer, input: {
80
+ network: string;
81
+ bytes: Uint8Array;
82
+ refusals: ExternalRefusals;
83
+ /**
84
+ * How long a dropped line is waited out, and how the waiting is done.
85
+ *
86
+ * ⚠ A SEAM, NOT AN OPTION, and `retryable` is not part of it: what may be repeated is decided
87
+ * here. `sleep`, `now` and `random` are injected so a test runs a flapping link in
88
+ * milliseconds rather than in minutes, and `onWait` is how a caller says it is waiting.
89
+ */
90
+ retry?: Omit<KeepTryingOptions, "retryable"> | undefined;
91
+ }): Promise<SubmittedTransaction>;
92
+ /**
93
+ * The two halves of a wallet-paid upload, signed by a wallet outside this tool: registering one
94
+ * part's blob (which buys the storage or binds a held resource, and pays the relay's tip) and
95
+ * certifying it (gas only).
96
+ *
97
+ * ⛔ THE BUILDERS ARE `upload-wallet-chain.ts`'s OWN — the same ones the measured fee came from and
98
+ * the same ones the keypair signers use. What is registered, bought and tipped is therefore the
99
+ * same transaction whichever wallet signs it.
100
+ */
101
+ export declare function externalBlobSigners(payer: ExternalPayer): {
102
+ register: SignBlobRegister;
103
+ certify: SignBlobCertify;
104
+ };
105
+ /**
106
+ * Extending every blob under one file by `epochs`, in ONE transaction signed by a wallet outside
107
+ * this tool. The ids are de-duplicated: naming a blob twice pays for the same epochs twice.
108
+ *
109
+ * ⚠ The transaction is the shape `extend-chain.ts` measured the fee of — sender, de-duplicated ids,
110
+ * one fragment per blob — so what is approved is what was priced.
111
+ */
112
+ export declare function externalExtendSigner(payer: ExternalPayer): SignExtension;
113
+ /**
114
+ * Cutting, joining or handing over a storage resource, signed by a wallet outside this tool.
115
+ *
116
+ * ⛔ THE RESOURCE MUST BE THAT WALLET'S. The review reads the resources at the address it was given
117
+ * and this signs as the same address, so a resource held somewhere else is refused by the chain
118
+ * rather than half-done here.
119
+ */
120
+ export declare function externalStorageOpSigner(payer: ExternalPayer): SignStorageOp;