@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.
- package/CHANGELOG.md +10 -0
- package/README.ko.md +9 -1
- package/README.md +9 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/put-wallet.js +11 -11
- package/dist/commands/recovery-list.js +3 -2
- package/dist/crypto-surface.d.ts +2 -0
- package/dist/crypto-surface.js +4 -7
- package/dist/portable.d.ts +2 -0
- package/dist/portable.js +3 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/recovery-assemble.d.ts +4 -11
- package/dist/recovery-assemble.js +25 -106
- package/dist/recovery-build.d.ts +7 -1
- package/dist/recovery-build.js +15 -11
- package/dist/recovery-seq.d.ts +2 -2
- package/dist/recovery-seq.js +30 -23
- package/dist/recovery.d.ts +92 -0
- package/dist/recovery.js +202 -0
- package/dist/upload-file.d.ts +2 -0
- package/dist/upload-file.js +6 -0
- package/dist/upload-recovery-patch.d.ts +65 -0
- package/dist/upload-recovery-patch.js +250 -0
- package/dist/upload-steps.js +4 -1
- package/dist/upload-wallet-plan.d.ts +4 -0
- package/dist/upload-wallet-plan.js +18 -8
- package/dist/upload-wallet-put.d.ts +6 -2
- package/dist/upload-wallet-put.js +30 -17
- package/dist/upload-wallet.d.ts +4 -1
- package/dist/upload-wallet.js +11 -3
- package/dist/upload-wire.d.ts +22 -0
- package/dist/upload-wire.js +2 -0
- package/dist/walrus-write.js +12 -0
- package/docs/commands/put.md +5 -1
- package/package.json +5 -1
- package/server.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.56.0 — 2026-11-10
|
|
7
|
+
|
|
8
|
+
- With the account's storage copy of the recovery list switched on, `put --pay wallet` of a one-part
|
|
9
|
+
file under 64 MiB onto new storage uploads the newest recovery list in the same quilt, as the web
|
|
10
|
+
app does. The standalone recovery program then finds that list with the NMTS key alone. The WAL in
|
|
11
|
+
the review includes the list, and a list that cannot go along never stops the upload.
|
|
12
|
+
- A program can build the recovery list without the command: `@needmoretruth/nmts-cli/recovery`
|
|
13
|
+
exports `makeRecoveryList`, `readRecoveryCopy` and `setRecoveryCopy`, and runs in a browser as well
|
|
14
|
+
as in Node. `nmts recovery-list` writes the same file as before.
|
|
15
|
+
|
|
6
16
|
## 0.55.0 — 2026-11-10
|
|
7
17
|
|
|
8
18
|
- Uploads (`put`, `push`) keep working when every company's upload relay is down. The order is now
|
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.56.0 # 버전을 고정할 때
|
|
54
54
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -362,6 +362,14 @@ NMTS 키는 들어 있지 않습니다. `kit`은 그 목록과 NMTS 키를 한
|
|
|
362
362
|
목록을 잃은 계정의 파일 목록을 서버의 줄로 다시 짓습니다. 키·해시·날짜·크기는 돌아오고 이름과
|
|
363
363
|
폴더는 돌아오지 않습니다.
|
|
364
364
|
|
|
365
|
+
계정에서 복구 목록의 Walrus 사본을 켜 두었으면(웹 앱에서, 또는 SDK의 `setRecoveryCopy(true)`로)
|
|
366
|
+
64 MiB 미만의 한 조각 파일을 새 저장 자원에 `put --pay wallet`으로 올릴 때 최신 목록이 같은 묶음에
|
|
367
|
+
함께 올라갑니다. 그러면 복구 프로그램이 `--find`로 NMTS 키만 가지고 그 목록을 찾습니다. 검토에
|
|
368
|
+
나오는 값에는 목록이 들어 있습니다. NMTS 키에서 나오지 않는 지갑으로 낸 사본은 이 방법으로
|
|
369
|
+
찾지 못합니다. 명령 없이 프로그램에서 같은 파일을 만들 수도 있습니다.
|
|
370
|
+
`@needmoretruth/nmts-cli/recovery`가 `makeRecoveryList` · `readRecoveryCopy` · `setRecoveryCopy`를
|
|
371
|
+
내보내고, Node와 브라우저에서 모두 돕니다.
|
|
372
|
+
|
|
365
373
|
`nmts rollback`은 파일 목록의 이전 버전을 현재 버전으로 되돌립니다 — 현재 목록이 열리지 않을
|
|
366
374
|
때를 위한 것입니다. 새 버전이 더한 파일은 그 뒤 목록에서 빠지지만 바이트는 그대로 저장돼 있고,
|
|
367
375
|
`nmts rebuild`가 목록에 없는 파일을 찾습니다. `nmts unlock rollback`으로 열기 전에는 잠겨 있고 매번 `--yes`가 필요합니다.
|
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.56.0 # a pinned version
|
|
55
55
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
56
56
|
```
|
|
57
57
|
|
|
@@ -396,6 +396,14 @@ machine, checks it against the release's checksum file before making it runnable
|
|
|
396
396
|
anything on your PATH. `rebuild` reconstructs a file list from the server's rows for an account
|
|
397
397
|
that has lost its own: keys, hashes, dates and sizes come back; names and folders do not.
|
|
398
398
|
|
|
399
|
+
With the account's storage copy of the recovery list switched on (in the web app, or with the
|
|
400
|
+
SDK's `setRecoveryCopy(true)`), `put --pay wallet` of a one-part file under 64 MiB onto new storage
|
|
401
|
+
uploads the newest list in the same quilt. The recovery program then finds it with `--find` and the
|
|
402
|
+
NMTS key alone. The WAL in the review includes the list. A copy paid from a wallet the NMTS key does
|
|
403
|
+
not derive cannot be found that way. A program can build the same file without the command:
|
|
404
|
+
`@needmoretruth/nmts-cli/recovery` exports `makeRecoveryList`, `readRecoveryCopy` and
|
|
405
|
+
`setRecoveryCopy`, and runs in a browser as well as in Node.
|
|
406
|
+
|
|
399
407
|
`nmts rollback` puts the previous version of the file list back as the current one, for the case
|
|
400
408
|
where the current one will not open. Files the newer version added are out of the list afterwards —
|
|
401
409
|
their bytes are still stored, and `nmts rebuild` finds files the list does not name. It is locked
|
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.56.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
|
/**
|
|
@@ -202,29 +202,29 @@ export async function uploadOneWithWallet(ctx, file, options) {
|
|
|
202
202
|
if (ctx.json)
|
|
203
203
|
return;
|
|
204
204
|
describeUploadReview(say, {
|
|
205
|
-
name: review.name,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
days: review.days,
|
|
210
|
-
endEpoch: review.endEpoch,
|
|
211
|
-
walNeeded: review.budget.walNeededFrost,
|
|
212
|
-
tipMist: review.tipMist,
|
|
213
|
-
storage: review.storage,
|
|
214
|
-
heldResources: review.heldResources,
|
|
215
|
-
networkCopy: ctx.networkCopy,
|
|
205
|
+
name: review.name, bytes: review.bytes, sealedBytes: review.sealedBytes, parts: review.parts,
|
|
206
|
+
epochs: review.epochs, days: review.days, endEpoch: review.endEpoch,
|
|
207
|
+
walNeeded: review.budget.walNeededFrost, tipMist: review.tipMist, storage: review.storage,
|
|
208
|
+
heldResources: review.heldResources, networkCopy: ctx.networkCopy, carriesRecoveryList: review.carriesRecoveryList,
|
|
216
209
|
}, review.budget);
|
|
217
210
|
},
|
|
218
211
|
agree: (review) => {
|
|
219
212
|
requireWalletGrant("seal", { walFrost: review.budget.walNeededFrost, suiMist: review.budget.suiNeededMist }, new Date(options.now ?? Date.now()));
|
|
220
213
|
},
|
|
221
214
|
onSpend: recordWalletSpend,
|
|
215
|
+
// The copy is a passenger: why it stayed behind is said, and the upload goes on.
|
|
216
|
+
onRecoveryProblem: (message) => (ctx.json ? process.stderr.write(`${message}\n`) : say(` ⚠ ${message}`)),
|
|
222
217
|
});
|
|
223
218
|
}
|
|
224
219
|
finally {
|
|
225
220
|
ctx.progress.done();
|
|
226
221
|
}
|
|
227
222
|
const facts = factsOf(outcome.review);
|
|
223
|
+
if (outcome.kind === "uploaded") {
|
|
224
|
+
facts["recoveryList"] = outcome.recoveryList;
|
|
225
|
+
if (outcome.recoveryList !== null && !ctx.json)
|
|
226
|
+
say(` Recovery list ${outcome.recoveryList} went up with this file.`);
|
|
227
|
+
}
|
|
228
228
|
if (outcome.kind === "review") {
|
|
229
229
|
if (ctx.json)
|
|
230
230
|
say(JSON.stringify({ dryRun: true, name: outcome.review.name, ...facts, signed: false }));
|
|
@@ -36,8 +36,9 @@ export async function recoveryList(options = {}) {
|
|
|
36
36
|
throw alreadyThere(destination);
|
|
37
37
|
try {
|
|
38
38
|
// ⛔ 0600. These bytes are one account's whole storage index, sealed — and a mode is cheaper to
|
|
39
|
-
// get right than an explanation of why it did not matter.
|
|
40
|
-
|
|
39
|
+
// get right than an explanation of why it did not matter. The library's own bytes, so an
|
|
40
|
+
// app on the SDK and this command hand out the same file (spec 2026-09-20 unit B).
|
|
41
|
+
writeFileSync(destination, file.bytes, {
|
|
41
42
|
flag: options.force === true ? "w" : "wx",
|
|
42
43
|
mode: 0o600,
|
|
43
44
|
});
|
package/dist/crypto-surface.d.ts
CHANGED
|
@@ -258,6 +258,8 @@ export interface CryptoGlue {
|
|
|
258
258
|
link_seal_secret(dataKey: Uint8Array, linkSecret: Uint8Array): Uint8Array;
|
|
259
259
|
/** `S` back from the owner's copy. */
|
|
260
260
|
link_open_secret(dataKey: Uint8Array, sealed: Uint8Array): Uint8Array;
|
|
261
|
+
/** The name the recovery list's patch takes inside a quilt (NCF-3 §2.5), from the data key. */
|
|
262
|
+
recovery_patch_name(dataKey: Uint8Array): string;
|
|
261
263
|
}
|
|
262
264
|
export declare function isCryptoGlue(value: unknown): value is CryptoGlue;
|
|
263
265
|
/** Which of the required functions this object does not have. Empty means it is the engine. */
|
package/dist/crypto-surface.js
CHANGED
|
@@ -45,17 +45,14 @@ const REQUIRED = [
|
|
|
45
45
|
"derive_ai_account_code",
|
|
46
46
|
// Numbered sharing identities (NCF-3 §5.9). Required for the same reason: an engine without them
|
|
47
47
|
// cannot make, show or open with any public code but the first.
|
|
48
|
-
"share_id_seeds",
|
|
49
|
-
"share_public_key_at",
|
|
50
|
-
"share_address_at",
|
|
51
|
-
"share_wrap_dek_as",
|
|
52
|
-
"share_unwrap_dek_as",
|
|
48
|
+
"share_id_seeds", "share_public_key_at", "share_address_at", "share_wrap_dek_as", "share_unwrap_dek_as",
|
|
53
49
|
// The EVM wallets (NCF-3 §1.9), required for the same reason: `put --tier heavy --pay evm` and
|
|
54
50
|
// `heavy wallet` cannot run on a build without it.
|
|
55
51
|
"evm_key_for",
|
|
56
52
|
// Public links (NCF-3 §5.8): `link make`, `link list` and `link open` cannot run without them.
|
|
57
|
-
"link_generate_secret", "link_wrap_dek", "link_unwrap_dek",
|
|
58
|
-
|
|
53
|
+
"link_generate_secret", "link_wrap_dek", "link_unwrap_dek", "link_seal_secret", "link_open_secret",
|
|
54
|
+
// The recovery patch's name: a wallet upload cannot carry the recovery list without it.
|
|
55
|
+
"recovery_patch_name",
|
|
59
56
|
];
|
|
60
57
|
export function isCryptoGlue(value) {
|
|
61
58
|
return missingExports(value).length === 0;
|
package/dist/portable.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export { codeActivity } from "./public-code-activity.ts";
|
|
|
27
27
|
export type { ActivityDoor, CodeActivity, ReceivedThrough, SentThrough } from "./public-code-activity.ts";
|
|
28
28
|
export { readFileList } from "./manifest.ts";
|
|
29
29
|
export type { FileList } from "./manifest.ts";
|
|
30
|
+
export { makeRecoveryList, nextRecoverySeq, readRecoveryCopy, recordRecoveryList, setRecoveryCopy } from "./recovery.ts";
|
|
31
|
+
export type { MadeRecoveryList, RecoveryAccount, RecoveryCopyState } from "./recovery.ts";
|
|
30
32
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
|
|
31
33
|
export type { AddEntryInput, AddEntryResult, ListEditInput, ListEditResult } from "./manifest-write.ts";
|
|
32
34
|
export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
package/dist/portable.js
CHANGED
|
@@ -50,6 +50,9 @@ export { CODE_INDEX_MAX, openShareAnyCode, openShareWithRing, requireCodeIndex,
|
|
|
50
50
|
export { defaultCode, ensureLiveCode, liveCodes, nextCodeIndex, publishCode, PUBLISH_TRIES, readPublicCodes, revokeCode, } from "./public-codes.js";
|
|
51
51
|
export { codeActivity } from "./public-code-activity.js";
|
|
52
52
|
export { readFileList } from "./manifest.js";
|
|
53
|
+
// The recovery list (spec 2026-09-20 unit B): the file `nmts recovery-list` writes, and its
|
|
54
|
+
// storage-network copy's switch. Also its own entry, `./recovery`.
|
|
55
|
+
export { makeRecoveryList, nextRecoverySeq, readRecoveryCopy, recordRecoveryList, setRecoveryCopy } from "./recovery.js";
|
|
53
56
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
|
|
54
57
|
export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
|
|
55
58
|
export { setTrashed } from "./item-trash.js";
|
package/dist/product.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const BINARY_NAME = "nmts";
|
|
|
9
9
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
10
10
|
* command importing the entry point is a cycle waiting to bite.
|
|
11
11
|
*/
|
|
12
|
-
export declare const VERSION = "0.
|
|
12
|
+
export declare const VERSION = "0.56.0";
|
|
13
13
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
14
14
|
export declare const HOME_URL = "https://nmts.me";
|
|
15
15
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/product.js
CHANGED
|
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
|
|
|
18
18
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
19
19
|
* command importing the entry point is a cycle waiting to bite.
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.
|
|
21
|
+
export const VERSION = "0.56.0";
|
|
22
22
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
23
23
|
export const HOME_URL = "https://nmts.me";
|
|
24
24
|
/** The source, so a person holding only the built program can find what it was built from. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RecoveryAccount } from "./recovery.ts";
|
|
2
|
+
import type { BuiltRecoveryList } from "./recovery-build.ts";
|
|
2
3
|
import { type Session } from "./session.ts";
|
|
3
4
|
export interface AssembleOptions {
|
|
4
5
|
server?: string | undefined;
|
|
@@ -8,8 +9,7 @@ export interface AssembleOptions {
|
|
|
8
9
|
}
|
|
9
10
|
export interface AssembledRecoveryList {
|
|
10
11
|
session: Session;
|
|
11
|
-
|
|
12
|
-
proof: string;
|
|
12
|
+
account: RecoveryAccount;
|
|
13
13
|
built: BuiltRecoveryList;
|
|
14
14
|
/** This list's own version number. */
|
|
15
15
|
seq: number;
|
|
@@ -19,6 +19,7 @@ export interface AssembledRecoveryList {
|
|
|
19
19
|
file: {
|
|
20
20
|
filename: string;
|
|
21
21
|
content: string;
|
|
22
|
+
bytes: Uint8Array;
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
export declare function assembleRecoveryList(options?: AssembleOptions): Promise<AssembledRecoveryList>;
|
|
@@ -28,13 +29,5 @@ export declare function assembleRecoveryList(options?: AssembleOptions): Promise
|
|
|
28
29
|
* ⛔ THE FILE FIRST, THE RECORD SECOND — so this takes the path that already exists. The record is
|
|
29
30
|
* what makes an account screen say "your list is up to date"; saying that before the file
|
|
30
31
|
* exists would be a claim about something that may never have been written.
|
|
31
|
-
*
|
|
32
|
-
* ⛔ `kind: "local"` AND NO BLOB ID. This tool keeps the list on the person's own disk and writes
|
|
33
|
-
* no copy to the storage network, and the server refuses a blob id alongside `local` for
|
|
34
|
-
* exactly that reason: a recorded address nothing was written to would let a screen advertise
|
|
35
|
-
* a copy that does not exist.
|
|
36
|
-
*
|
|
37
|
-
* ⛔ THE ATTEMPT IS REMEMBERED WHETHER OR NOT IT LANDS. See `recovery-seq.ts`: a number the server
|
|
38
|
-
* refused must not be the number the next run offers again, or the refusal repeats for ever.
|
|
39
32
|
*/
|
|
40
33
|
export declare function recordRecoveryList(assembled: AssembledRecoveryList, destination: string): Promise<void>;
|
|
@@ -5,104 +5,37 @@
|
|
|
5
5
|
// NMTS key. If those were assembled twice, one of them would eventually be built from a
|
|
6
6
|
// check the other had dropped — and the difference would only show up in a recovery.
|
|
7
7
|
//
|
|
8
|
-
// ⛔ THE
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// ⛔ THE DATA KEY IS DERIVED HERE AND WIPED HERE. It opens every file in the account; the
|
|
14
|
-
// derivation output it is cut from holds the wallet root and the sign-in secret as well, so it
|
|
15
|
-
// is zeroed on every path out, including the failing one.
|
|
8
|
+
// ⛔ AND THE ASSEMBLY ITSELF IS THE LIBRARY'S (`recovery.ts`, spec 2026-09-20 unit B), so an app
|
|
9
|
+
// on the SDK hands its user the same bytes these commands write. What stays here is what only a
|
|
10
|
+
// terminal has: this machine's session, the agreement that lets it read the code, and the
|
|
11
|
+
// sentence that names the file on disk when the server's record fails.
|
|
16
12
|
import { accountProofFor } from "./account-proof.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
13
|
+
import { ServerError } from "./api.js";
|
|
14
|
+
import { fromUtf8 } from "./bytes.js";
|
|
19
15
|
import { NmtsError } from "./errors.js";
|
|
20
|
-
import {
|
|
21
|
-
import { BINARY_NAME } from "./product.js";
|
|
22
|
-
import { artifactAbout } from "./artifact-about.js";
|
|
23
|
-
import { buildRecoveryList } from "./recovery-build.js";
|
|
24
|
-
import { buildRecoveryMapFile } from "./recovery-map-file.js";
|
|
25
|
-
import { recoveryDocMeta } from "./recovery-map.js";
|
|
26
|
-
import { lastOfferedSeq, rememberOfferedSeq } from "./recovery-seq.js";
|
|
27
|
-
import { readAllRecoverySource } from "./recovery-source.js";
|
|
16
|
+
import { makeRecoveryList, recordRecoveryList as recordWithServer } from "./recovery.js";
|
|
28
17
|
import { openSession } from "./session.js";
|
|
29
|
-
import { AGGREGATOR_HOSTS, suiRpcHost } from "./walrus.js";
|
|
30
|
-
/**
|
|
31
|
-
* Where the bytes this list points at live, for the sealed self-description.
|
|
32
|
-
*
|
|
33
|
-
* ⚠ `aggregators` AND `chain_rpc` ARE HINTS. They are the endpoints this build reads from today —
|
|
34
|
-
* the first thing in the file to go stale — so a reader treats them as candidates AFTER its own
|
|
35
|
-
* built-in defaults, never as instructions. `chain` is the one that changes behaviour: a blob id
|
|
36
|
-
* from testnet and one from mainnet are the same kind of string, and without this a recovery has
|
|
37
|
-
* to try both and let a wrong guess look like missing bytes.
|
|
38
|
-
*/
|
|
39
|
-
function storageFor(network) {
|
|
40
|
-
return {
|
|
41
|
-
network: "walrus",
|
|
42
|
-
chain: network,
|
|
43
|
-
aggregators: [...(AGGREGATOR_HOSTS[network] ?? [])],
|
|
44
|
-
chain_rpc: suiRpcHost(network),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
18
|
export async function assembleRecoveryList(options = {}) {
|
|
48
|
-
// ⛔ BEFORE THE FIRST READ. Everything created from here on is outside this list.
|
|
49
|
-
const capturedAt = new Date().toISOString();
|
|
50
19
|
const session = await openSession({ server: options.server, network: options.network });
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
exitCode: 4,
|
|
56
|
-
nextStep: `Nothing was written. A recovery list says what each stored file is CALLED and which key ` +
|
|
57
|
-
`opens it, and both come from the account's own file list — the storage network holds ` +
|
|
58
|
-
`neither. Run \`${BINARY_NAME} rebuild\` if this account has stored files but no list.`,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const source = await readAllRecoverySource({
|
|
20
|
+
// ⛔ THE AGREEMENT IS ASKED HERE, not in the library: a code read from a plain environment
|
|
21
|
+
// variable needs this machine's consent before its proof is built (`account-proof.ts`).
|
|
22
|
+
const accountProof = await accountProofFor({ code: session.code, source: session.source });
|
|
23
|
+
const account = {
|
|
62
24
|
server: session.server,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const derived = crypt.kdf_derive(crypt.account_code_parse(session.code));
|
|
71
|
-
const [from, to] = DERIVED.dataKey;
|
|
72
|
-
const dataKey = derived.slice(from, to);
|
|
73
|
-
derived.fill(0);
|
|
74
|
-
let built;
|
|
75
|
-
try {
|
|
76
|
-
built = buildRecoveryList({
|
|
77
|
-
crypt,
|
|
78
|
-
dataKey,
|
|
79
|
-
accountId: session.accountId,
|
|
80
|
-
entries: list.manifest.entries,
|
|
81
|
-
source,
|
|
82
|
-
seq,
|
|
83
|
-
generatedAt,
|
|
84
|
-
meta: recoveryDocMeta(artifactAbout("recovery-list"), storageFor(session.network)),
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
dataKey.fill(0);
|
|
89
|
-
}
|
|
25
|
+
bearer: session.apiKey,
|
|
26
|
+
code: session.code,
|
|
27
|
+
accountId: session.accountId,
|
|
28
|
+
network: session.network,
|
|
29
|
+
accountProof,
|
|
30
|
+
};
|
|
31
|
+
const made = await makeRecoveryList(account, { onProgress: options.onProgress });
|
|
90
32
|
return {
|
|
91
33
|
session,
|
|
92
|
-
|
|
93
|
-
built,
|
|
94
|
-
seq,
|
|
95
|
-
capturedAt,
|
|
96
|
-
file:
|
|
97
|
-
accountId: session.accountId,
|
|
98
|
-
seq,
|
|
99
|
-
generatedAt,
|
|
100
|
-
// ⛔ READ BACK OUT OF THE DOCUMENT, not assumed. From NRM-3 on the number a document declares
|
|
101
|
-
// depends on what is in it, and a wrapper that stated the newest version this build knows
|
|
102
|
-
// would mislabel every ordinary file.
|
|
103
|
-
nrm: built.doc.v,
|
|
104
|
-
sealed: built.sealed,
|
|
105
|
-
}),
|
|
34
|
+
account,
|
|
35
|
+
built: made.built,
|
|
36
|
+
seq: made.seq,
|
|
37
|
+
capturedAt: made.capturedAt,
|
|
38
|
+
file: { filename: made.file.filename, content: fromUtf8(made.file.content), bytes: made.file.content },
|
|
106
39
|
};
|
|
107
40
|
}
|
|
108
41
|
/**
|
|
@@ -111,25 +44,11 @@ export async function assembleRecoveryList(options = {}) {
|
|
|
111
44
|
* ⛔ THE FILE FIRST, THE RECORD SECOND — so this takes the path that already exists. The record is
|
|
112
45
|
* what makes an account screen say "your list is up to date"; saying that before the file
|
|
113
46
|
* exists would be a claim about something that may never have been written.
|
|
114
|
-
*
|
|
115
|
-
* ⛔ `kind: "local"` AND NO BLOB ID. This tool keeps the list on the person's own disk and writes
|
|
116
|
-
* no copy to the storage network, and the server refuses a blob id alongside `local` for
|
|
117
|
-
* exactly that reason: a recorded address nothing was written to would let a screen advertise
|
|
118
|
-
* a copy that does not exist.
|
|
119
|
-
*
|
|
120
|
-
* ⛔ THE ATTEMPT IS REMEMBERED WHETHER OR NOT IT LANDS. See `recovery-seq.ts`: a number the server
|
|
121
|
-
* refused must not be the number the next run offers again, or the refusal repeats for ever.
|
|
122
47
|
*/
|
|
123
48
|
export async function recordRecoveryList(assembled, destination) {
|
|
124
|
-
const {
|
|
125
|
-
rememberOfferedSeq(session.accountId, seq);
|
|
49
|
+
const { seq } = assembled;
|
|
126
50
|
try {
|
|
127
|
-
await
|
|
128
|
-
method: "PUT",
|
|
129
|
-
token: session.apiKey,
|
|
130
|
-
accountProof: assembled.proof,
|
|
131
|
-
body: { kind: "local", seq, captured_at: assembled.capturedAt },
|
|
132
|
-
});
|
|
51
|
+
await recordWithServer(assembled.account, { seq, capturedAt: assembled.capturedAt });
|
|
133
52
|
}
|
|
134
53
|
catch (error) {
|
|
135
54
|
// ⛔ THE FILE IS GOOD AND THE RECORD IS NOT. Those are two different facts and the person needs
|
package/dist/recovery-build.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type CryptoGlue } from "./crypto.ts";
|
|
2
|
-
import { type RecoveryDocMetaDraft, type RecoveryListDoc } from "./recovery-map.ts";
|
|
2
|
+
import { type ManifestItemInput, type RecoveryDocMetaDraft, type RecoveryListDoc } from "./recovery-map.ts";
|
|
3
3
|
import { type SourceItem } from "./recovery-source.ts";
|
|
4
4
|
import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
|
5
5
|
/** Path of the account root. Every file sits at this or below it. */
|
|
6
6
|
export declare const ROOT_PATH = "/";
|
|
7
7
|
/** Folder names, root-down, as the `/a/b` string the format stores. Empty means the root. */
|
|
8
8
|
export declare function pathString(names: readonly string[]): string;
|
|
9
|
+
/** base64url of the RAW bytes inside one envelope sealed under the account's data key. */
|
|
10
|
+
export declare function openRaw(crypt: CryptoGlue, dataKey: Uint8Array, envelope: string, aad: string, what: string): string;
|
|
9
11
|
export interface BuildRecoveryListInput {
|
|
10
12
|
crypt: CryptoGlue;
|
|
11
13
|
/** ⛔ BORROWED, NOT KEPT. The caller derived it and the caller wipes it. */
|
|
@@ -19,6 +21,10 @@ export interface BuildRecoveryListInput {
|
|
|
19
21
|
seq: number;
|
|
20
22
|
/** RFC3339, stamped by the caller before the walk began. */
|
|
21
23
|
generatedAt: string;
|
|
24
|
+
/** Files riding in the quilt this list goes into (NRM-3 own-quilt form), appended after the rest. */
|
|
25
|
+
pending?: readonly ManifestItemInput[] | undefined;
|
|
26
|
+
/** The storage-network copy this one follows, when it is itself such a copy. */
|
|
27
|
+
prevBlobId?: string | null | undefined;
|
|
22
28
|
meta: RecoveryDocMetaDraft;
|
|
23
29
|
}
|
|
24
30
|
export interface BuiltRecoveryList {
|
package/dist/recovery-build.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
// ⛔ TWO SOURCES, JOINED ON ID. The server is asked only for what it still owns — a file's storage
|
|
22
22
|
// parts. Its NAME, its folder, its size and its key envelope come from the account's sealed file
|
|
23
23
|
// list, because that is the only place the tree exists.
|
|
24
|
+
import { fromBase64Url, fromUtf8, toBase64Url } from "./bytes.js";
|
|
24
25
|
import { AAD, DERIVED } from "./crypto.js";
|
|
25
26
|
import { NmtsError } from "./errors.js";
|
|
26
27
|
import { buildRecoveryListDoc, RecoveryListProblem, withTotals, } from "./recovery-map.js";
|
|
@@ -96,10 +97,10 @@ function describeAll(entries) {
|
|
|
96
97
|
return out;
|
|
97
98
|
}
|
|
98
99
|
/** base64url of the RAW bytes inside one envelope sealed under the account's data key. */
|
|
99
|
-
function openRaw(crypt, dataKey, envelope, aad, what) {
|
|
100
|
+
export function openRaw(crypt, dataKey, envelope, aad, what) {
|
|
100
101
|
let opened;
|
|
101
102
|
try {
|
|
102
|
-
opened = crypt.envelope_open(dataKey, utf8.encode(aad),
|
|
103
|
+
opened = crypt.envelope_open(dataKey, utf8.encode(aad), fromBase64Url(envelope));
|
|
103
104
|
}
|
|
104
105
|
catch {
|
|
105
106
|
// ⛔ The engine's own message is not repeated: it can quote what it was given.
|
|
@@ -107,7 +108,7 @@ function openRaw(crypt, dataKey, envelope, aad, what) {
|
|
|
107
108
|
`The recovery list was not written.`);
|
|
108
109
|
}
|
|
109
110
|
try {
|
|
110
|
-
return
|
|
111
|
+
return toBase64Url(opened);
|
|
111
112
|
}
|
|
112
113
|
finally {
|
|
113
114
|
opened.fill(0);
|
|
@@ -213,13 +214,16 @@ export function buildRecoveryList(input) {
|
|
|
213
214
|
items.push(item);
|
|
214
215
|
totalBytes += about.size;
|
|
215
216
|
}
|
|
217
|
+
for (const riding of input.pending ?? []) {
|
|
218
|
+
items.push(riding);
|
|
219
|
+
totalBytes += riding.size;
|
|
220
|
+
}
|
|
216
221
|
const doc = buildRecoveryListDoc({
|
|
217
222
|
seq: input.seq,
|
|
218
|
-
// ⛔
|
|
219
|
-
// address, and a list
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
prevBlobId: null,
|
|
223
|
+
// ⛔ NULL FOR A LIST ON SOMEBODY'S DISK. `prev_manifest_blob_id` chains MIRRORS: it is a
|
|
224
|
+
// storage-network address, and a local list has none for a successor to point at. `seq`
|
|
225
|
+
// still increases across every list of either kind, so "which is newest" stays answerable.
|
|
226
|
+
prevBlobId: input.prevBlobId ?? null,
|
|
223
227
|
generatedAt: input.generatedAt,
|
|
224
228
|
accountId: input.accountId,
|
|
225
229
|
// Finished here because here is where they are first true: everything before this point could
|
|
@@ -229,13 +233,13 @@ export function buildRecoveryList(input) {
|
|
|
229
233
|
items,
|
|
230
234
|
});
|
|
231
235
|
const json = JSON.stringify(doc);
|
|
232
|
-
const sealed =
|
|
236
|
+
const sealed = toBase64Url(input.crypt.envelope_seal(input.dataKey, utf8.encode(AAD.recoveryMap), utf8.encode(json)));
|
|
233
237
|
// ⛔ READ IT BACK BEFORE ANYBODY IS TOLD IT EXISTS. Catches a truncated seal, a wrong key, and
|
|
234
238
|
// any future change that returns something other than what it just sealed. Without it, "your
|
|
235
239
|
// list covers 412 files" is an assumption rather than a measurement.
|
|
236
240
|
let reopened;
|
|
237
241
|
try {
|
|
238
|
-
reopened = input.crypt.envelope_open(input.dataKey, utf8.encode(AAD.recoveryMap),
|
|
242
|
+
reopened = input.crypt.envelope_open(input.dataKey, utf8.encode(AAD.recoveryMap), fromBase64Url(sealed));
|
|
239
243
|
}
|
|
240
244
|
catch {
|
|
241
245
|
throw new NmtsError("The sealed recovery list did not open again on this machine.", {
|
|
@@ -243,7 +247,7 @@ export function buildRecoveryList(input) {
|
|
|
243
247
|
nextStep: "Nothing was written. This is a fault in the tool rather than in the account.",
|
|
244
248
|
});
|
|
245
249
|
}
|
|
246
|
-
if (
|
|
250
|
+
if (fromUtf8(reopened) !== json) {
|
|
247
251
|
throw new NmtsError("The sealed recovery list did not come back as what was sealed.", {
|
|
248
252
|
exitCode: 1,
|
|
249
253
|
nextStep: "Nothing was written. This is a fault in the tool rather than in the account.",
|
package/dist/recovery-seq.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The highest sequence this machine has offered for an account, or 0 when it has offered none. */
|
|
2
|
-
export declare function lastOfferedSeq(accountId: string): number
|
|
2
|
+
export declare function lastOfferedSeq(accountId: string): Promise<number>;
|
|
3
3
|
/**
|
|
4
4
|
* Write down a sequence this machine OFFERED — whether or not the server took it.
|
|
5
5
|
*
|
|
@@ -7,4 +7,4 @@ export declare function lastOfferedSeq(accountId: string): number;
|
|
|
7
7
|
* refused number the number the next run offers again, and every run after it: the same
|
|
8
8
|
* refusal for ever. Recording the attempt is what makes a second run get past it.
|
|
9
9
|
*/
|
|
10
|
-
export declare function rememberOfferedSeq(accountId: string, seq: number): void
|
|
10
|
+
export declare function rememberOfferedSeq(accountId: string, seq: number): Promise<void>;
|
package/dist/recovery-seq.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
// Which recovery list this machine wrote last, so the next one gets a higher number.
|
|
2
2
|
//
|
|
3
|
-
// ⛔ WHY IT IS REMEMBERED HERE
|
|
4
|
-
// `GET /v1/account
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// ⛔ WHY IT IS STILL REMEMBERED HERE. The account's recorded number is said by
|
|
4
|
+
// `GET /v1/account/recovery-network-copy` (spec 2026-09-20 unit B), and `recovery.ts` asks it
|
|
5
|
+
// first. A server older than that door answers 404 or 405, and a record the server refused or
|
|
6
|
+
// never received still has to push the next number past it. So the two are put together: the
|
|
7
|
+
// next list carries the higher of the two, plus one.
|
|
7
8
|
//
|
|
8
|
-
// ⛔ WHAT
|
|
9
|
-
//
|
|
10
|
-
// server has already passed, the server refuses it — that is what its `seq`
|
|
11
|
-
// the refusal is reported rather than worked around. The attempt is recorded
|
|
12
|
-
// second run offers a higher number and the two converge instead of looping.
|
|
9
|
+
// ⛔ WHAT A MISSING SERVER NUMBER COSTS, SAID PLAINLY. A list written from a browser moves the
|
|
10
|
+
// server's number without moving this one. Against an older server the next run here then
|
|
11
|
+
// offers a number the server has already passed, the server refuses it — that is what its `seq`
|
|
12
|
+
// guard is for — and the refusal is reported rather than worked around. The attempt is recorded
|
|
13
|
+
// either way, so a second run offers a higher number and the two converge instead of looping.
|
|
14
|
+
//
|
|
15
|
+
// ⛔ IT GOES THROUGH THE HOST'S STATE, so the same counter runs in a page. On Node a key without a
|
|
16
|
+
// slash is one file directly under the config directory — the same `recovery-seq-<id>.json`,
|
|
17
|
+
// with the same text, that this module wrote with `node:fs` before (`host-node.ts::placeOf`).
|
|
13
18
|
//
|
|
14
19
|
// ⛔ IT IS NOT A SECRET AND IT IS STILL WRITTEN 0600. It holds an account id and a counter. The
|
|
15
20
|
// mode matches every other file this tool keeps beside it: one mode is easier to keep right
|
|
16
21
|
// than two.
|
|
17
|
-
import {
|
|
18
|
-
import { join } from "node:path";
|
|
19
|
-
import { configDir } from "./credentials.js";
|
|
22
|
+
import { fromUtf8, utf8 } from "./bytes.js";
|
|
20
23
|
import { NmtsError } from "./errors.js";
|
|
21
24
|
import { isRecord } from "./guards.js";
|
|
25
|
+
import { host } from "./host.js";
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* The state key one account's counter lives under.
|
|
24
28
|
*
|
|
25
|
-
* ⛔ AN ACCOUNT ID BECOMES PART OF A
|
|
26
|
-
* tool has comes from its own derivation and is base64url, but a value that reaches a path
|
|
29
|
+
* ⛔ AN ACCOUNT ID BECOMES PART OF A FILE NAME HERE, so it is CHECKED rather than trusted. Every id
|
|
30
|
+
* this tool has comes from its own derivation and is base64url, but a value that reaches a path
|
|
27
31
|
* unchecked is how `..` becomes a write somewhere else, and the check costs one line.
|
|
28
32
|
*/
|
|
29
|
-
function
|
|
33
|
+
function seqKey(accountId) {
|
|
30
34
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(accountId)) {
|
|
31
35
|
throw new NmtsError("That is not an account id this tool derived.", {
|
|
32
36
|
nextStep: "Nothing was written. This is a fault in the tool rather than in the account.",
|
|
33
37
|
});
|
|
34
38
|
}
|
|
35
|
-
return
|
|
39
|
+
return `recovery-seq-${accountId}.json`;
|
|
36
40
|
}
|
|
37
41
|
/** The highest sequence this machine has offered for an account, or 0 when it has offered none. */
|
|
38
|
-
export function lastOfferedSeq(accountId) {
|
|
42
|
+
export async function lastOfferedSeq(accountId) {
|
|
43
|
+
const key = seqKey(accountId);
|
|
39
44
|
try {
|
|
40
|
-
const
|
|
45
|
+
const bytes = await host().state.read(key);
|
|
46
|
+
if (bytes === undefined)
|
|
47
|
+
return 0;
|
|
48
|
+
const parsed = JSON.parse(fromUtf8(bytes));
|
|
41
49
|
if (!isRecord(parsed))
|
|
42
50
|
return 0;
|
|
43
51
|
const seq = parsed["seq"];
|
|
@@ -55,9 +63,8 @@ export function lastOfferedSeq(accountId) {
|
|
|
55
63
|
* refused number the number the next run offers again, and every run after it: the same
|
|
56
64
|
* refusal for ever. Recording the attempt is what makes a second run get past it.
|
|
57
65
|
*/
|
|
58
|
-
export function rememberOfferedSeq(accountId, seq) {
|
|
59
|
-
if (seq <= lastOfferedSeq(accountId))
|
|
66
|
+
export async function rememberOfferedSeq(accountId, seq) {
|
|
67
|
+
if (seq <= (await lastOfferedSeq(accountId)))
|
|
60
68
|
return;
|
|
61
|
-
|
|
62
|
-
writeFileSync(seqPath(accountId), `${JSON.stringify({ seq }, null, 2)}\n`, { mode: 0o600 });
|
|
69
|
+
await host().state.write(seqKey(accountId), utf8(`${JSON.stringify({ seq }, null, 2)}\n`));
|
|
63
70
|
}
|