@needmoretruth/nmts-cli 0.55.0 → 0.57.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 +20 -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/receive.js +30 -87
- package/dist/commands/recovery-list.js +3 -2
- package/dist/commands/share.d.ts +7 -0
- package/dist/commands/share.js +58 -180
- package/dist/commands/shares-sent.js +4 -29
- package/dist/crypto-surface.d.ts +2 -0
- package/dist/crypto-surface.js +4 -7
- package/dist/links.d.ts +5 -0
- package/dist/links.js +6 -1
- package/dist/platform-sign.d.ts +7 -1
- package/dist/platform-sign.js +12 -1
- package/dist/portable.d.ts +4 -0
- package/dist/portable.js +5 -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/sharing-inbox.d.ts +52 -0
- package/dist/sharing-inbox.js +146 -0
- package/dist/sharing.d.ts +52 -0
- package/dist/sharing.js +218 -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 +9 -1
- package/server.json +2 -2
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// `nmts shares --sent` — moved out of `share.ts` whole (that file is measured by `check:size`).
|
|
2
|
-
import { request } from "../api.js";
|
|
3
|
-
import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
|
|
4
2
|
import { NmtsError } from "../errors.js";
|
|
5
3
|
import { isRecord } from "../guards.js";
|
|
6
|
-
import { readFileList } from "../manifest.js";
|
|
7
4
|
import { BINARY_NAME } from "../product.js";
|
|
8
5
|
import { openSession } from "../session.js";
|
|
9
|
-
import {
|
|
6
|
+
import { sentShares } from "../sharing.js";
|
|
7
|
+
import { out, shareAccountOf } from "./share.js";
|
|
10
8
|
/**
|
|
11
9
|
* `nmts shares --sent <path>` — who ONE file was shared with.
|
|
12
10
|
*
|
|
@@ -31,34 +29,11 @@ export async function sharesSent(target, options = {}) {
|
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
const session = await openSession({ server: options.server, network: options.network });
|
|
34
|
-
const
|
|
35
|
-
if (list.manifest === null) {
|
|
36
|
-
throw new NmtsError("This account has no file list, so there is nothing to look up.", {
|
|
37
|
-
exitCode: 4,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const index = buildIndex(list.manifest.entries);
|
|
41
|
-
const entry = entryAt(list.manifest.entries, normalisePath(target), {
|
|
42
|
-
nothingHappened: "Nothing was changed.",
|
|
43
|
-
});
|
|
44
|
-
if (entry.kind !== KIND_FILE) {
|
|
45
|
-
throw new NmtsError(`No file at "${fullPathOf(index, entry)}".`, {
|
|
46
|
-
exitCode: 4,
|
|
47
|
-
nextStep: "That is a folder, and a share is of one file.",
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const path = fullPathOf(index, entry);
|
|
51
|
-
const answer = await request(session.server, `/v1/shares/sent?item_id=${encodeURIComponent(entry.id)}`, { token: session.apiKey });
|
|
52
|
-
const rows = typeof answer === "object" && answer !== null ? Reflect.get(answer, "shares") : null;
|
|
53
|
-
if (!Array.isArray(rows)) {
|
|
54
|
-
throw new NmtsError("The server's answer did not carry a list of shares.", {
|
|
55
|
-
nextStep: "Nothing was changed. Report it rather than retrying — the shape, not the network, is wrong.",
|
|
56
|
-
});
|
|
57
|
-
}
|
|
32
|
+
const { path, itemId, rows } = await sentShares(shareAccountOf(session), target);
|
|
58
33
|
if (options.json) {
|
|
59
34
|
// ⛔ THE SERVER'S ROWS, UNCHANGED. A reader of this arm is reading the route, and a shape
|
|
60
35
|
// rewritten here would be a second wire to keep in step with the first.
|
|
61
|
-
say(JSON.stringify({ path, item_id:
|
|
36
|
+
say(JSON.stringify({ path, item_id: itemId, shares: rows }));
|
|
62
37
|
return 0;
|
|
63
38
|
}
|
|
64
39
|
if (rows.length === 0) {
|
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/links.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface LinkAccount {
|
|
|
8
8
|
readonly bearer: string;
|
|
9
9
|
/** The NMTS key, display form. Its dataKey opens the file key and seals the owner's copy of `S`. */
|
|
10
10
|
readonly code: string;
|
|
11
|
+
/**
|
|
12
|
+
* ⛔ base64url of the code's proof, sent on making a link and nowhere else. A delegation token
|
|
13
|
+
* reaches that door only with its `share` bit and this proof; an API key does not need it.
|
|
14
|
+
*/
|
|
15
|
+
readonly accountProof?: string | undefined;
|
|
11
16
|
}
|
|
12
17
|
export interface MadeLink {
|
|
13
18
|
/** The whole link, secret included. */
|
package/dist/links.js
CHANGED
|
@@ -67,7 +67,12 @@ export async function makeLink(account, entry, options) {
|
|
|
67
67
|
digest.fill(0);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
-
const answer = await request(account.server, "/v1/share-links", {
|
|
70
|
+
const answer = await request(account.server, "/v1/share-links", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
body,
|
|
73
|
+
token: account.bearer,
|
|
74
|
+
...(account.accountProof === undefined ? {} : { accountProof: account.accountProof }),
|
|
75
|
+
});
|
|
71
76
|
const id = isRecord(answer) ? text(answer["link_id"]) : null;
|
|
72
77
|
const createdAt = isRecord(answer) ? text(answer["created_at"]) : null;
|
|
73
78
|
if (id === null || createdAt === null) {
|
package/dist/platform-sign.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export declare const DELEGATION_MAX_TTL_SECS = 2592000;
|
|
|
32
32
|
* an app can upload cannot destroy — and it does not stand alone: both doors also ask for the
|
|
33
33
|
* account code's own proof on the same request, which is an act only whoever holds the code can
|
|
34
34
|
* perform. The token is the business's permission; the proof is the key holder's.
|
|
35
|
+
*
|
|
36
|
+
* ⛔ `share` IS THE SIXTH, AND IT IS BUILT THE SAME WAY (spec 2026-09-20 unit C). It opens what sends
|
|
37
|
+
* a file's key out of the account: sharing it with another account and making a public link,
|
|
38
|
+
* and the lookup of the identity a share is sealed to. Those two sending doors also ask for the
|
|
39
|
+
* code's proof. Listing, receiving and cutting stay on `files_read` and `files_write`.
|
|
35
40
|
*/
|
|
36
41
|
export declare const SCOPE_BITS: {
|
|
37
42
|
readonly files_read: 1;
|
|
@@ -39,8 +44,9 @@ export declare const SCOPE_BITS: {
|
|
|
39
44
|
readonly storage_spend: 4;
|
|
40
45
|
readonly register: 8;
|
|
41
46
|
readonly files_erase: 16;
|
|
47
|
+
readonly share: 32;
|
|
42
48
|
};
|
|
43
|
-
/** One of the
|
|
49
|
+
/** One of the six names above. */
|
|
44
50
|
export type ScopeName = keyof typeof SCOPE_BITS;
|
|
45
51
|
/** Every bit a token may carry. */
|
|
46
52
|
export declare const SCOPE_ALL: number;
|
package/dist/platform-sign.js
CHANGED
|
@@ -60,6 +60,11 @@ export const DELEGATION_MAX_TTL_SECS = 2_592_000;
|
|
|
60
60
|
* an app can upload cannot destroy — and it does not stand alone: both doors also ask for the
|
|
61
61
|
* account code's own proof on the same request, which is an act only whoever holds the code can
|
|
62
62
|
* perform. The token is the business's permission; the proof is the key holder's.
|
|
63
|
+
*
|
|
64
|
+
* ⛔ `share` IS THE SIXTH, AND IT IS BUILT THE SAME WAY (spec 2026-09-20 unit C). It opens what sends
|
|
65
|
+
* a file's key out of the account: sharing it with another account and making a public link,
|
|
66
|
+
* and the lookup of the identity a share is sealed to. Those two sending doors also ask for the
|
|
67
|
+
* code's proof. Listing, receiving and cutting stay on `files_read` and `files_write`.
|
|
63
68
|
*/
|
|
64
69
|
export const SCOPE_BITS = {
|
|
65
70
|
files_read: 1,
|
|
@@ -67,9 +72,15 @@ export const SCOPE_BITS = {
|
|
|
67
72
|
storage_spend: 4,
|
|
68
73
|
register: 8,
|
|
69
74
|
files_erase: 16,
|
|
75
|
+
share: 32,
|
|
70
76
|
};
|
|
71
77
|
/** Every bit a token may carry. */
|
|
72
|
-
export const SCOPE_ALL = SCOPE_BITS.files_read |
|
|
78
|
+
export const SCOPE_ALL = SCOPE_BITS.files_read |
|
|
79
|
+
SCOPE_BITS.files_write |
|
|
80
|
+
SCOPE_BITS.storage_spend |
|
|
81
|
+
SCOPE_BITS.register |
|
|
82
|
+
SCOPE_BITS.files_erase |
|
|
83
|
+
SCOPE_BITS.share;
|
|
73
84
|
/**
|
|
74
85
|
* A new key pair, from the runtime's own random source.
|
|
75
86
|
*
|
package/dist/portable.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ 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";
|
|
32
|
+
export { addressFromTyped, receivedShares, receiveShare, removeShare, sendShare, sentShares, shareableFileAt } from "./sharing.ts";
|
|
33
|
+
export type { ReceivedFile, ReceivedShare, SentShare, ShareAccount, ShareableFile } from "./sharing.ts";
|
|
30
34
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
|
|
31
35
|
export type { AddEntryInput, AddEntryResult, ListEditInput, ListEditResult } from "./manifest-write.ts";
|
|
32
36
|
export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
package/dist/portable.js
CHANGED
|
@@ -50,6 +50,11 @@ 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";
|
|
56
|
+
// Sharing one file with another account (spec 2026-09-20 unit C). Also its own entry, `./share`.
|
|
57
|
+
export { addressFromTyped, receivedShares, receiveShare, removeShare, sendShare, sentShares, shareableFileAt } from "./sharing.js";
|
|
53
58
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
|
|
54
59
|
export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
|
|
55
60
|
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.57.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.57.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
|
}
|