@needmoretruth/nmts-cli 0.55.0 → 0.56.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.
@@ -13,6 +13,7 @@
13
13
  // costs the most: a zero would refuse an upload the wallet can afford.
14
14
  import { NmtsError } from "./errors.js";
15
15
  import { BINARY_NAME } from "./product.js";
16
+ import { RIDE_CEILING_BYTES } from "./upload-wire.js";
16
17
  import { fits, leftoverBytes, statusOf, usableFirst } from "./shared/lib/storage-control/plan.js";
17
18
  import { coinAmount } from "./wallet.js";
18
19
  /** The browser's default rung, and the term one credit buys. A number of EPOCHS, not days. */
@@ -179,15 +180,24 @@ export function describeUploadReview(say, facts, budget) {
179
180
  say(` This is paid in WAL and SUI from the wallet this NMTS key derives — not from credits, which`);
180
181
  say(` is what \`${BINARY_NAME} put\` spends without --pay wallet. Nobody, NMTS included, can reverse it.`);
181
182
  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
183
+ // ⛔ SAID WHERE IT CHANGES WHAT SOMEBODY GETS, AND NOWHERE ELSE. An account that never asked for
184
+ // the recovery list's copy has nothing to be told (`GET /v1/account/summary` `network_copy`).
185
+ // Since spec 2026-09-20 unit B a one-part upload onto new storage carries it, as the browser's
186
+ // small uploads do (`upload-recovery-patch.ts`); anything else still does not, and says so.
187
+ // Whether it rides was decided before the price, so the sentence says what happens, not "if".
188
+ const on = facts.carriesRecoveryList || facts.networkCopy === true;
189
+ if (on || facts.networkCopy === null) {
190
+ say(on
188
191
  ? ` This account asks for the recovery list to be copied to the storage network with its uploads.`
189
192
  : ` 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.`);
193
+ const fits = facts.parts === 1 && facts.storage.kind === "buy" && facts.sealedBytes <= RIDE_CEILING_BYTES;
194
+ if (facts.carriesRecoveryList)
195
+ say(` The newest recovery list goes up with this file, and the WAL above includes it.`);
196
+ else if (fits)
197
+ say(` This upload does not include it. \`${BINARY_NAME} recovery-list\` saves the list as a file.`);
198
+ else {
199
+ say(` Only a one-part upload under 64 MiB onto new storage includes it, so this one does not.`);
200
+ say(` \`${BINARY_NAME} recovery-list\` saves the list as a file.`);
201
+ }
192
202
  }
193
203
  }
@@ -92,14 +92,16 @@ export interface WalletPutSeams {
92
92
  agree?: ((review: WalletPutReview) => void) | undefined;
93
93
  /** Told what left the wallet, after each signature. */
94
94
  onSpend?: ((spend: Spend) => void) | undefined;
95
+ /** Told why the recovery list did not ride along, when it was switched on and did not. */
96
+ onRecoveryProblem?: ((message: string) => void) | undefined;
95
97
  }
96
98
  /** What this upload would buy, in the order somebody deciding needs it. Base units throughout. */
97
99
  export interface WalletPutReview {
98
100
  name: string;
99
- /** Plaintext bytes. */
100
101
  bytes: number;
101
- /** Bytes the storage network holds, padding and sealing included. */
102
+ /** Bytes the storage network holds, sealing and padding included — the quilt, when the list rides. */
102
103
  sealedBytes: number;
104
+ carriesRecoveryList: boolean;
103
105
  parts: number;
104
106
  epochs: number;
105
107
  /** The term in days, read from the network's own clock. */
@@ -131,6 +133,8 @@ export type WalletPutOutcome = {
131
133
  fileListVersion: number;
132
134
  /** True when every part was already signed for by an earlier run: this call spent nothing. */
133
135
  resumed: boolean;
136
+ /** The number of the recovery list that rode in this upload's quilt; null when none did. */
137
+ recoveryList: number | null;
134
138
  };
135
139
  /**
136
140
  * Price, agree, sign, upload and record ONE file, paid from the wallet the NMTS key derives.
@@ -41,6 +41,7 @@ import { createUploadApi } from "./upload-api.js";
41
41
  import { uploadFile } from "./upload-file.js";
42
42
  import { CREDIT_BYTES, planAndPrice } from "./upload-price.js";
43
43
  import { forgetUpload } from "./upload-run.js";
44
+ import { planWalletRide } from "./upload-recovery-patch.js";
44
45
  import { walletRail } from "./upload-wallet.js";
45
46
  import { chooseUploadEpochs, daysOf, parseStorageAsk, pickResource, uploadBudget, uploadShortfallNextStep, } from "./upload-wallet-plan.js";
46
47
  import { UploadError } from "./upload-wire.js";
@@ -75,7 +76,15 @@ export async function walletPut(ctx, file, seams = {}) {
75
76
  }
76
77
  const epochs = chooseUploadEpochs(seams.epochs, window);
77
78
  const endEpoch = window.clock.current + epochs;
78
- const quotes = await reads.quoteParts(sealedLens, epochs);
79
+ // ⛔ THE RIDE IS PLANNED BEFORE THE PRICE: a riding list makes the quilt what is registered, so
80
+ // the quilt is quoted, reviewed, checked and told to the ledger (`upload-recovery-patch.ts`).
81
+ // The file is quoted too: a list that cannot ride after all sends it, for less than agreed.
82
+ const range = plan[0];
83
+ const riding = storageAsk === null && range !== undefined && plan.length === 1
84
+ ? await planWalletRide(ctx, protocol, seams.onRecoveryProblem, { ...file, streamPlaintextLen: sealFor(range), sealedLen: sealedBytes }) : null;
85
+ const quiltLen = riding?.quiltLen ?? null, lens = quiltLen === null ? sealedLens : [quiltLen];
86
+ const quoted = await reads.quoteParts(quiltLen === null ? sealedLens : [quiltLen, ...sealedLens], epochs);
87
+ const quotes = quoted.slice(0, lens.length);
79
88
  // ⛔ THE ADDRESS THAT IS PRICED IS THE ADDRESS THAT SIGNS — the same wallet the rail carries,
80
89
  // whether that is a number this key derives or a wallet the caller holds the key to.
81
90
  const address = ctx.payer?.address ?? (await walletAddress(ctx.code, ctx.wallet));
@@ -108,7 +117,7 @@ export async function walletPut(ctx, file, seams = {}) {
108
117
  reads.readWallet(address),
109
118
  reads.estimateRegisterGas({
110
119
  sender: address,
111
- sealedLen: Math.max(...sealedLens),
120
+ sealedLen: Math.max(...lens),
112
121
  epochs,
113
122
  storage: storage.kind === "buy"
114
123
  ? storage
@@ -119,7 +128,8 @@ export async function walletPut(ctx, file, seams = {}) {
119
128
  const review = {
120
129
  name: file.name,
121
130
  bytes: file.source.size,
122
- sealedBytes,
131
+ sealedBytes: lens.reduce((sum, len) => sum + len, 0),
132
+ carriesRecoveryList: quiltLen !== null,
123
133
  parts: plan.length,
124
134
  epochs,
125
135
  days: daysOf(window, epochs),
@@ -148,6 +158,20 @@ export async function walletPut(ctx, file, seams = {}) {
148
158
  seams.agree?.(review);
149
159
  const sign = seams.sign ?? (await signers());
150
160
  const onSpend = seams.onSpend ?? (() => undefined);
161
+ const rail = walletRail({
162
+ network: ctx.network,
163
+ code: ctx.code,
164
+ wallet: ctx.wallet,
165
+ ...(ctx.payer === undefined ? {} : { payer: ctx.payer }),
166
+ relayUrl: protocol.relayUrl,
167
+ epochs,
168
+ storage,
169
+ quotes: quoted,
170
+ feeMist,
171
+ signRegister: sign.register,
172
+ signCertify: sign.certify,
173
+ onSpend,
174
+ });
151
175
  const derived = ctx.crypt.kdf_derive(ctx.crypt.account_code_parse(ctx.code));
152
176
  const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
153
177
  derived.fill(0);
@@ -168,20 +192,7 @@ export async function walletPut(ctx, file, seams = {}) {
168
192
  partSize: ctx.partSize,
169
193
  padding: { rule: ctx.rule, unitBytes: CREDIT_BYTES },
170
194
  ...(seams.onStep === undefined ? {} : { onStep: seams.onStep }),
171
- buy: walletRail({
172
- network: ctx.network,
173
- code: ctx.code,
174
- wallet: ctx.wallet,
175
- ...(ctx.payer === undefined ? {} : { payer: ctx.payer }),
176
- relayUrl: protocol.relayUrl,
177
- epochs,
178
- storage,
179
- quotes,
180
- feeMist,
181
- signRegister: sign.register,
182
- signCertify: sign.certify,
183
- onSpend,
184
- }),
195
+ buy: riding === null ? rail : riding.ride.wrap(rail),
185
196
  });
186
197
  }
187
198
  finally {
@@ -223,6 +234,8 @@ export async function walletPut(ctx, file, seams = {}) {
223
234
  replaced: added.replaced?.id ?? null,
224
235
  fileListVersion: added.seq,
225
236
  resumed: result.resumed,
237
+ // After the list names the file, so the account screen and the next list agree.
238
+ recoveryList: riding === null ? null : await riding.ride.record(),
226
239
  };
227
240
  }
228
241
  async function defaultReads(network, relayUrl) {
@@ -25,7 +25,10 @@ export interface WalletRailContext {
25
25
  epochs: number;
26
26
  /** Where the storage comes from. A held resource serves one blob, so it applies to a one-part file. */
27
27
  storage: StorageChoice;
28
- /** What each part was quoted, in part order — what the grant ledger is told after each signature. */
28
+ /**
29
+ * What was quoted, by sealed length — what the grant ledger is told after each signature. Bytes of
30
+ * a length not here are refused before anything is signed.
31
+ */
29
32
  quotes: readonly PartQuote[];
30
33
  /** The measured register fee, added to the ledger with the tip; null adds the tip alone. */
31
34
  feeMist: bigint | null;
@@ -80,6 +80,17 @@ async function buyAndPushPartWithWallet(ctx, input) {
80
80
  return paidPart((await readReservationRecord(key)) ?? existing, true);
81
81
  }
82
82
  // ── fresh, or interrupted before the signature ──
83
+ // ⛔ ONLY BYTES WHOSE PRICE WAS AGREED ARE REGISTERED. Storage is bought for the length the
84
+ // signature names, and a length nobody quoted would spend what nobody reviewed.
85
+ const quote = ctx.quotes.find((q) => q.sealedLen === sealed.length);
86
+ if (quote === undefined) {
87
+ throw new UploadError({
88
+ phase: "reserve",
89
+ message: `These ${sealed.length} bytes are not the ones this upload was priced for.`,
90
+ paid: false,
91
+ nextStep: "Nothing was signed. Running the same command again prices them first.",
92
+ });
93
+ }
83
94
  onStep?.({ step: "encoding", bytes: sealed.length });
84
95
  let meta;
85
96
  try {
@@ -119,9 +130,6 @@ async function buyAndPushPartWithWallet(ctx, input) {
119
130
  // ⛔ BEFORE THE SIGNATURE. See the module header.
120
131
  await writeReservation(key, record, sealed);
121
132
  onStep?.({ step: "reserving" });
122
- const quote = ctx.quotes[input.part.index];
123
- if (quote === undefined)
124
- throw new NmtsError("unreachable: a part with no quote");
125
133
  let registered;
126
134
  try {
127
135
  registered = await ctx.signRegister({
@@ -16,6 +16,8 @@ export interface Certificate {
16
16
  serialized_message_b64: string;
17
17
  signature_b64: string;
18
18
  }
19
+ /** The largest sealed file a recovery list rides with — the browser's quilt line (`upload-recovery-patch.ts`). */
20
+ export declare const RIDE_CEILING_BYTES: number;
19
21
  /** The Walrus protocol seam. The real one is in `walrus-write.ts`; the tests supply a fake. */
20
22
  export interface BlobProtocol {
21
23
  computeMetadata(input: {
@@ -34,6 +36,21 @@ export interface BlobProtocol {
34
36
  */
35
37
  relayUrl?: string;
36
38
  }): Promise<Certificate>;
39
+ /**
40
+ * Lay several byte runs out as one quilt, with each patch's place in it. Optional: a protocol
41
+ * without it uploads files as their own blobs, and no recovery list rides along.
42
+ */
43
+ encodeQuilt?(blobs: readonly {
44
+ contents: Uint8Array;
45
+ identifier: string;
46
+ }[]): Promise<{
47
+ quilt: Uint8Array;
48
+ patches: readonly {
49
+ identifier: string;
50
+ startIndex: number;
51
+ endIndex: number;
52
+ }[];
53
+ }>;
37
54
  }
38
55
  /** The reservation as the server describes it. */
39
56
  export interface ReserveReply {
@@ -238,6 +255,11 @@ export interface PaidPart {
238
255
  suiObjectId?: string;
239
256
  /** Wallet rail only: the epoch the bought storage ends at, read from the blob object. */
240
257
  endEpoch?: number;
258
+ /**
259
+ * Set when the part is one patch of a quilt — `blobId` is then the quilt and `sealedLen` this
260
+ * part's own stream, not the quilt's length.
261
+ */
262
+ patchId?: string;
241
263
  }
242
264
  /** What finished. The caller writes the file list, THEN clears the records. */
243
265
  export interface UploadResult {
@@ -6,6 +6,8 @@
6
6
  // and means the file that DOES spend stays short enough to read in one sitting.
7
7
  import { HttpError, ServerError } from "./api.js";
8
8
  import { NmtsError } from "./errors.js";
9
+ /** The largest sealed file a recovery list rides with — the browser's quilt line (`upload-recovery-patch.ts`). */
10
+ export const RIDE_CEILING_BYTES = 64 * 1024 * 1024;
9
11
  /**
10
12
  * A failure that names its phase — and, crucially, whether the account has already paid.
11
13
  *
@@ -157,6 +157,18 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
157
157
  signature_b64: toBase64Url(certificate.signature),
158
158
  };
159
159
  },
160
+ async encodeQuilt(blobs) {
161
+ // ⛔ THE SDK'S OWN LAYOUT, the one the browser's `writeFilesFlow` uses — patches sorted by
162
+ // identifier, the shard count read from the chain — so an aggregator reads a patch of this
163
+ // quilt by name exactly as it reads one the browser wrote (spec 2026-09-20 unit B).
164
+ const { quilt, index } = await client.walrus
165
+ .encodeQuilt({ blobs: blobs.map((b) => ({ contents: b.contents, identifier: b.identifier })) })
166
+ .catch((error) => fail("The storage network's encoder could not build the quilt", error));
167
+ return {
168
+ quilt,
169
+ patches: index.patches.map((p) => ({ identifier: p.identifier, startIndex: p.startIndex, endIndex: p.endIndex })),
170
+ };
171
+ },
160
172
  };
161
173
  }
162
174
  /**
@@ -33,7 +33,11 @@ run (`null` in `--json` when it could not be measured, never 0), both balances,
33
33
  fit|whole|<object id>` uses a free storage resource the wallet holds for a one-part file: `fit`
34
34
  cuts it to size and leaves the rest free, `whole` binds all of it with the file. Do not choose
35
35
  `--storage` for the person: the leftover is their decision. `--epochs` and `--storage` without
36
- `--pay wallet` exit 2.
36
+ `--pay wallet` exit 2. With the account's storage copy of the recovery list on, a one-part file
37
+ under 64 MiB onto new storage goes up with the newest recovery list in the same quilt, as in the web
38
+ app, and `nmts-recovery --find` finds that list with the NMTS key alone. The review's WAL includes
39
+ it. If the list is left out, a warning says why and the file goes up on its own; `--json` reports
40
+ `recoveryList` (its number, or `null`).
37
41
 
38
42
  **`--tier heavy`** stores the file on NMTS Heavy instead of NMTS Standard: each part is kept whole in
39
43
  two separate places on Filecoin rather than spread across Walrus storage nodes. It is paid the same
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needmoretruth/nmts-cli",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "description": "Command-line and MCP access to NMTS (NeedMoreTruthStorage, https://nmts.me): open-source, end-to-end encrypted storage on the Walrus network. No fee to NMTS; you pay the network from your own wallet. For people and for their agents.",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -45,6 +45,10 @@
45
45
  "types": "./dist/portable.d.ts",
46
46
  "default": "./dist/portable.js"
47
47
  },
48
+ "./recovery": {
49
+ "types": "./dist/recovery.d.ts",
50
+ "default": "./dist/recovery.js"
51
+ },
48
52
  "./host": {
49
53
  "types": "./dist/host.d.ts",
50
54
  "default": "./dist/host.js"
package/server.json CHANGED
@@ -6,13 +6,13 @@
6
6
  "url": "https://github.com/needmoretruth/nmts-cli",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.55.0",
9
+ "version": "0.56.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "registryBaseUrl": "https://registry.npmjs.org",
14
14
  "identifier": "@needmoretruth/nmts-cli",
15
- "version": "0.55.0",
15
+ "version": "0.56.0",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },