@needmoretruth/nmts-cli 0.46.0 → 0.47.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 (66) hide show
  1. package/AGENTS.md +8 -8
  2. package/CHANGELOG.md +18 -1
  3. package/README.ko.md +1 -1
  4. package/README.md +19 -11
  5. package/dist/arg-options.d.ts +11 -1
  6. package/dist/args.js +7 -1
  7. package/dist/artifact-about.d.ts +1 -1
  8. package/dist/autonomy.js +3 -3
  9. package/dist/commands/handover.d.ts +2 -0
  10. package/dist/commands/handover.js +65 -17
  11. package/dist/commands/link.d.ts +12 -0
  12. package/dist/commands/link.js +121 -0
  13. package/dist/commands/public-code-manage.d.ts +24 -0
  14. package/dist/commands/public-code-manage.js +217 -0
  15. package/dist/commands/public-code.d.ts +7 -2
  16. package/dist/commands/public-code.js +104 -55
  17. package/dist/commands/receive.js +11 -5
  18. package/dist/commands/share-dispatch.js +14 -1
  19. package/dist/commands/share.d.ts +2 -0
  20. package/dist/commands/share.js +45 -35
  21. package/dist/commands/shares-sent.js +8 -3
  22. package/dist/crypto-surface.d.ts +27 -0
  23. package/dist/crypto-surface.js +10 -0
  24. package/dist/crypto.d.ts +5 -0
  25. package/dist/crypto.js +5 -0
  26. package/dist/handover-codes.d.ts +25 -0
  27. package/dist/handover-codes.js +106 -0
  28. package/dist/handover.d.ts +21 -3
  29. package/dist/handover.js +47 -29
  30. package/dist/help-options.js +9 -2
  31. package/dist/help.js +9 -1
  32. package/dist/links.d.ts +58 -0
  33. package/dist/links.js +206 -0
  34. package/dist/main.js +3 -2
  35. package/dist/mcp-tools/reads.js +20 -6
  36. package/dist/mcp-tools/share.js +47 -1
  37. package/dist/mcp-tools/tiers.js +16 -1
  38. package/dist/portable.d.ts +8 -0
  39. package/dist/portable.js +8 -0
  40. package/dist/product.d.ts +1 -1
  41. package/dist/product.js +1 -1
  42. package/dist/public-code-activity.d.ts +35 -0
  43. package/dist/public-code-activity.js +88 -0
  44. package/dist/public-code-refusals.d.ts +25 -0
  45. package/dist/public-code-refusals.js +87 -0
  46. package/dist/public-codes.d.ts +76 -0
  47. package/dist/public-codes.js +182 -0
  48. package/dist/risk.d.ts +25 -1
  49. package/dist/risk.js +32 -1
  50. package/dist/share-codes.d.ts +40 -0
  51. package/dist/share-codes.js +151 -0
  52. package/dist/share.d.ts +34 -0
  53. package/dist/share.js +53 -12
  54. package/dist/shared/lib/share/public-link.d.ts +41 -0
  55. package/dist/shared/lib/share/public-link.js +107 -0
  56. package/docs/commands/handover.md +17 -1
  57. package/docs/commands/link.md +27 -0
  58. package/docs/commands/mcp.md +2 -1
  59. package/docs/commands/public-code.md +21 -9
  60. package/docs/commands/share.md +6 -3
  61. package/package.json +1 -1
  62. package/server.json +2 -2
  63. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +91 -5
  64. package/vendor/nmts-crypto/nmts_crypto_wasm.js +259 -4
  65. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  66. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +11 -1
@@ -0,0 +1,58 @@
1
+ import type { PlaintextSink } from "./download-sink.ts";
2
+ import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
3
+ import type { ReadOptions } from "./walrus.ts";
4
+ /** The account a link is made or listed for — the same four things every account call takes. */
5
+ export interface LinkAccount {
6
+ readonly server: string;
7
+ /** API key or delegation token. */
8
+ readonly bearer: string;
9
+ /** The NMTS key, display form. Its dataKey opens the file key and seals the owner's copy of `S`. */
10
+ readonly code: string;
11
+ }
12
+ export interface MadeLink {
13
+ /** The whole link, secret included. */
14
+ link: string;
15
+ id: string;
16
+ createdAt: string;
17
+ expiresAt: string | null;
18
+ }
19
+ export interface ListedLink {
20
+ id: string;
21
+ /** The whole link again, or null when it is cut (or its sealed secret did not open). */
22
+ link: string | null;
23
+ showsName: boolean;
24
+ createdAt: string;
25
+ expiresAt: string | null;
26
+ /** When it was cut, and by whom: `owner` · `operator` · `report`. */
27
+ cutAt: string | null;
28
+ cutBy: string | null;
29
+ downloads: number;
30
+ }
31
+ /** Make a link to one file of the account's list. */
32
+ export declare function makeLink(account: LinkAccount, entry: ManifestEntry, options: {
33
+ showName: boolean;
34
+ expiresDays: number | null;
35
+ now?: Date;
36
+ }): Promise<MadeLink>;
37
+ /** Every link the account made to one file, newest first, cut ones included. */
38
+ export declare function listLinks(account: LinkAccount, itemId: string): Promise<ListedLink[]>;
39
+ /** Cut one of the account's links. Cutting one that is already cut is not an error. */
40
+ export declare function revokeLink(account: LinkAccount, id: string): Promise<void>;
41
+ export interface OpenedLinkFile {
42
+ /** The file's name, or null when the owner hid it. */
43
+ name: string | null;
44
+ bytes: number;
45
+ parts: number;
46
+ }
47
+ /**
48
+ * Open a link and deliver its file to `sink`, checked against the owner's digest. No account.
49
+ *
50
+ * `name` is told the file's name (or null) before a byte is fetched, so the caller can pick the sink.
51
+ */
52
+ export declare function openLink(input: {
53
+ link: string;
54
+ server: string;
55
+ chain: string;
56
+ sink: (name: string | null) => PlaintextSink;
57
+ read?: ReadOptions;
58
+ }): Promise<OpenedLinkFile>;
package/dist/links.js ADDED
@@ -0,0 +1,206 @@
1
+ // Public links (NCF-3 §5.8): make one, list them,
2
+ // cut one, and open one without an account — the code under `nmts link` and the SDK's four methods.
3
+ //
4
+ // A link is `<server>/l/<token>#<secret>`. The token names the server's row; the secret `S` opens the
5
+ // file key that row holds, and it is in the part after `#` that no server is sent. The shapes (link
6
+ // text, the sealed document) are the browser's own, copied byte for byte into `shared/`.
7
+ //
8
+ // ⛔ MAKING ONE SENDS NO SECRET. Every value in the request is an envelope made here: the file key
9
+ // under `S`, the document and the digest under the file key (§5.4's two re-seals), and `S` under
10
+ // this account's dataKey so the owner can print the same link again (`list`).
11
+ //
12
+ // ⛔ OPENING ONE ASKS FOR THE TOKEN AND NOTHING ELSE, with no session: whoever holds the link opens
13
+ // the file. The pieces are read from Walrus as for any download, and the whole file is checked
14
+ // against the digest the owner sealed before anything is delivered.
15
+ import { request, ServerError } from "./api.js";
16
+ import { fromBase64Url, fromUtf8, toBase64Url, utf8 } from "./bytes.js";
17
+ import { AAD, DERIVED, loadCrypto } from "./crypto.js";
18
+ import { fetchKnownParts } from "./download.js";
19
+ import { asParts } from "./download-part.js";
20
+ import { NmtsError } from "./errors.js";
21
+ import { isRecord } from "./guards.js";
22
+ import { buildPublicLink, decodeLinkDocument, encodeLinkDocument, linkExpiresAt, parsePublicLink, } from "./shared/lib/share/public-link.js";
23
+ /** Run `use` with this account's dataKey, and wipe it however `use` ends. */
24
+ async function withDataKey(crypt, code, use) {
25
+ const derived = crypt.kdf_derive(crypt.account_code_parse(code));
26
+ const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
27
+ derived.fill(0);
28
+ try {
29
+ return await use(dataKey);
30
+ }
31
+ finally {
32
+ dataKey.fill(0);
33
+ }
34
+ }
35
+ const text = (value) => (typeof value === "string" ? value : null);
36
+ /** Make a link to one file of the account's list. */
37
+ export async function makeLink(account, entry, options) {
38
+ if (entry.dekWrapped === undefined || entry.contentHashCt === undefined) {
39
+ const missing = entry.dekWrapped === undefined ? "key, so nobody could open the link" : "hash, so a download could not be checked";
40
+ throw new NmtsError(`No link can be made to "${entry.name}": the file list holds no ${missing}.`, {
41
+ exitCode: 4,
42
+ nextStep: "Nothing was made.",
43
+ });
44
+ }
45
+ const { dekWrapped, contentHashCt } = entry;
46
+ const crypt = await loadCrypto();
47
+ const secret = crypt.link_generate_secret();
48
+ try {
49
+ const body = await withDataKey(crypt, account.code, async (dataKey) => {
50
+ const dek = crypt.envelope_open(dataKey, utf8(AAD.dekWrap), fromBase64Url(dekWrapped));
51
+ const digest = crypt.envelope_open(dataKey, utf8(AAD.contentHash), fromBase64Url(contentHashCt));
52
+ try {
53
+ const doc = encodeLinkDocument({ name: options.showName ? entry.name : null, size: entry.size });
54
+ const expiresAt = linkExpiresAt(options.expiresDays, options.now ?? new Date());
55
+ return {
56
+ item_id: entry.id,
57
+ wrapped: toBase64Url(crypt.link_wrap_dek(secret, dek)),
58
+ name: toBase64Url(crypt.envelope_seal(dek, utf8(AAD.shareName), utf8(doc))),
59
+ disclosed_name: options.showName,
60
+ hash: toBase64Url(crypt.envelope_seal(dek, utf8(AAD.shareContentHash), digest)),
61
+ owner_secret: toBase64Url(crypt.link_seal_secret(dataKey, secret)),
62
+ ...(expiresAt === undefined ? {} : { expires_at: expiresAt }),
63
+ };
64
+ }
65
+ finally {
66
+ dek.fill(0);
67
+ digest.fill(0);
68
+ }
69
+ });
70
+ const answer = await request(account.server, "/v1/share-links", { method: "POST", body, token: account.bearer });
71
+ const id = isRecord(answer) ? text(answer["link_id"]) : null;
72
+ const createdAt = isRecord(answer) ? text(answer["created_at"]) : null;
73
+ if (id === null || createdAt === null) {
74
+ throw new NmtsError("The server's answer did not name the new link.");
75
+ }
76
+ return {
77
+ link: buildPublicLink(account.server, id, toBase64Url(secret)),
78
+ id,
79
+ createdAt,
80
+ expiresAt: isRecord(answer) ? text(answer["expires_at"]) : null,
81
+ };
82
+ }
83
+ finally {
84
+ secret.fill(0);
85
+ }
86
+ }
87
+ /** Every link the account made to one file, newest first, cut ones included. */
88
+ export async function listLinks(account, itemId) {
89
+ const answer = await request(account.server, `/v1/share-links?item_id=${encodeURIComponent(itemId)}`, {
90
+ token: account.bearer,
91
+ });
92
+ const rows = isRecord(answer) ? answer["links"] : null;
93
+ if (!Array.isArray(rows))
94
+ throw new NmtsError("The server listed the links in a shape this version cannot read.");
95
+ const crypt = await loadCrypto();
96
+ return withDataKey(crypt, account.code, async (dataKey) => rows.map((row) => {
97
+ if (!isRecord(row))
98
+ throw new NmtsError("The server listed the links in a shape this version cannot read.");
99
+ const id = text(row["link_id"]) ?? "";
100
+ const cutAt = text(row["revoked_at"]);
101
+ const sealed = text(row["owner_secret"]);
102
+ let link = null;
103
+ if (cutAt === null && sealed !== null) {
104
+ try {
105
+ const secret = crypt.link_open_secret(dataKey, fromBase64Url(sealed));
106
+ link = buildPublicLink(account.server, id, toBase64Url(secret));
107
+ secret.fill(0);
108
+ }
109
+ catch {
110
+ // A secret that does not open is a row without a link, not a list that fails.
111
+ link = null;
112
+ }
113
+ }
114
+ return {
115
+ id,
116
+ link,
117
+ showsName: row["disclosed_name"] === true,
118
+ createdAt: text(row["created_at"]) ?? "",
119
+ expiresAt: text(row["expires_at"]),
120
+ cutAt,
121
+ cutBy: text(row["revoked_by"]),
122
+ downloads: typeof row["downloads"] === "number" ? row["downloads"] : 0,
123
+ };
124
+ }));
125
+ }
126
+ /** Cut one of the account's links. Cutting one that is already cut is not an error. */
127
+ export async function revokeLink(account, id) {
128
+ await request(account.server, `/v1/share-links/${encodeURIComponent(id)}`, { method: "DELETE", token: account.bearer });
129
+ }
130
+ /**
131
+ * Open a link and deliver its file to `sink`, checked against the owner's digest. No account.
132
+ *
133
+ * `name` is told the file's name (or null) before a byte is fetched, so the caller can pick the sink.
134
+ */
135
+ export async function openLink(input) {
136
+ const parts = parsePublicLink(input.link);
137
+ if (parts === null) {
138
+ throw new NmtsError("That is not a whole public link.", {
139
+ exitCode: 2,
140
+ nextStep: "Copy all of it, including the part after #: a link ends in /l/<token>#<secret>.",
141
+ });
142
+ }
143
+ let answer;
144
+ try {
145
+ answer = await request(input.server, `/v1/share-links/${encodeURIComponent(parts.token)}`);
146
+ }
147
+ catch (error) {
148
+ if (error instanceof ServerError && error.status === 404)
149
+ throw new NmtsError("This link does not exist.", { exitCode: 4 });
150
+ if (error instanceof ServerError && error.status === 410)
151
+ throw new NmtsError("This link has been cut.", { exitCode: 4 });
152
+ throw error;
153
+ }
154
+ if (!isRecord(answer))
155
+ throw new NmtsError("The server's answer was not an object.");
156
+ const wrapped = text(answer["wrapped"]);
157
+ const sealedName = text(answer["name"]);
158
+ const sealedHash = text(answer["hash"]);
159
+ if (wrapped === null || sealedName === null || sealedHash === null) {
160
+ throw new NmtsError("The server described this link in a shape this version cannot read.");
161
+ }
162
+ const network = answer["network"] === "mainnet" || answer["network"] === "testnet" ? answer["network"] : input.chain;
163
+ const described = asParts(answer);
164
+ const crypt = await loadCrypto();
165
+ const secret = fromBase64Url(parts.secret);
166
+ let dek;
167
+ try {
168
+ dek = crypt.link_unwrap_dek(secret, fromBase64Url(wrapped));
169
+ }
170
+ catch {
171
+ throw new NmtsError("This link is incomplete or damaged: the part after # does not open the file.", {
172
+ exitCode: 4,
173
+ nextStep: "Nothing was fetched. Ask the person who sent it for the whole link.",
174
+ });
175
+ }
176
+ finally {
177
+ secret.fill(0);
178
+ }
179
+ let digest;
180
+ let doc;
181
+ try {
182
+ doc = decodeLinkDocument(fromUtf8(crypt.envelope_open(dek, utf8(AAD.shareName), fromBase64Url(sealedName))));
183
+ digest = crypt.envelope_open(dek, utf8(AAD.shareContentHash), fromBase64Url(sealedHash));
184
+ }
185
+ catch {
186
+ doc = null;
187
+ digest = new Uint8Array(0);
188
+ }
189
+ if (doc === null || digest.length === 0) {
190
+ dek.fill(0);
191
+ throw new NmtsError("This link is damaged: the file's name and size stored with it do not open.", {
192
+ exitCode: 4,
193
+ nextStep: "Nothing was fetched. Ask the person who sent it for a new link.",
194
+ });
195
+ }
196
+ const fetched = await fetchKnownParts({
197
+ parts: [...described.parts].sort((a, b) => a.part_index - b.part_index),
198
+ size: doc.size,
199
+ dek,
200
+ expected: digest,
201
+ chain: network,
202
+ sink: input.sink(doc.name),
203
+ ...(input.read === undefined ? {} : { read: input.read }),
204
+ });
205
+ return { name: doc.name, bytes: fetched.byteCount, parts: fetched.partCount };
206
+ }
package/dist/main.js CHANGED
@@ -114,10 +114,10 @@ export async function run(argv) {
114
114
  });
115
115
  }
116
116
  case "public-code":
117
- return await (await import("./commands/public-code.js")).publicCode({ server: args.server, network: args.network, publish: args.publish, json: args.json, save: args.save, file: args.operands[0], force: args.force });
117
+ return await (await import("./commands/public-code.js")).runPublicCode(args);
118
118
  case "handover":
119
119
  return await (await import("./commands/handover.js")).handover(args.operands[0], args.operands[1], {
120
- server: args.server, network: args.network, to: args.to, out: args.out, force: args.force, yes: args.yes, json: args.json,
120
+ server: args.server, network: args.network, to: args.to, out: args.out, as: args.as, force: args.force, yes: args.yes, json: args.json,
121
121
  });
122
122
  case "wallet": {
123
123
  const { wallet } = await import("./commands/wallet.js");
@@ -295,6 +295,7 @@ export async function run(argv) {
295
295
  case "share":
296
296
  case "shares":
297
297
  case "unshare":
298
+ case "link":
298
299
  case "receive": {
299
300
  const { runShare } = await import("./commands/share-dispatch.js");
300
301
  return await runShare(args.command, args);
@@ -5,6 +5,8 @@
5
5
  // do next will call them repeatedly, and a surface where "just checking" costs money teaches
6
6
  // the opposite of the habit this tool wants.
7
7
  import { publicCode } from "../commands/public-code.js";
8
+ import { listCodes } from "../commands/public-code-manage.js";
9
+ import { isRecord } from "../guards.js";
8
10
  import { balance } from "../commands/balance.js";
9
11
  import { devices } from "../commands/devices.js";
10
12
  import { legal, notices } from "../commands/documents.js";
@@ -122,13 +124,25 @@ export function readTools(ctx) {
122
124
  },
123
125
  {
124
126
  name: "nmts_public_code",
125
- description: "The account's PUBLIC CODE — the value other accounts send files to — and whether it has " +
126
- "been published yet. Until it is published nobody can send to this account. ⛔ It only " +
127
- "reads. Publishing is permanent and is a person's decision at the command line: if the " +
128
- "reply says it is not published, say so rather than working around it. ⚠ Not the NMTS " +
127
+ description: "The account's PUBLIC CODES — the values other accounts send files to. `code` is the " +
128
+ "default one (the lowest-numbered live code) and whether it is published; `codes` lists " +
129
+ "every code with its number, whether it is live or revoked, and how many shares and " +
130
+ "messages went through it; `live`, `liveMax`, `madeToday` and `dayCap` are the server's " +
131
+ "ceilings. With `activity`, each code also lists its shares. Until a code is published " +
132
+ "nobody can send to this account; nmts_public_code_new publishes one. ⚠ Not the NMTS " +
129
133
  "key, which opens every file and is never given away.",
130
- inputSchema: NO_ARGS,
131
- run: () => say((write) => publicCode({ ...common(ctx), json: true, write })),
134
+ inputSchema: {
135
+ type: "object",
136
+ properties: {
137
+ activity: { type: "boolean", description: "List each code's sent and received shares too." },
138
+ },
139
+ additionalProperties: false,
140
+ },
141
+ run: async (args) => {
142
+ const head = JSON.parse(await say((write) => publicCode({ ...common(ctx), json: true, write })));
143
+ const all = JSON.parse(await say((write) => listCodes({ ...common(ctx), json: true, activity: args["activity"] === true, write })));
144
+ return JSON.stringify({ ...(isRecord(head) ? head : {}), ...(isRecord(all) ? all : {}) });
145
+ },
132
146
  },
133
147
  {
134
148
  name: "nmts_shares",
@@ -31,10 +31,51 @@
31
31
  // ⛔ THE RECIPIENT'S PUBLIC CODE IS NOT CHECKED AGAINST A PERSON. A share sent to a well-formed
32
32
  // code that belongs to somebody else is sent, and is not recallable. Confirm it with whoever
33
33
  // gave it to you, out of band, before calling this.
34
+ import { newCode, revokeCodeCommand } from "../commands/public-code-manage.js";
34
35
  import { share, unshare } from "../commands/share.js";
35
36
  import { common, needString, say } from "./context.js";
37
+ /** A code's number from a tool call, as the command takes it. The schema already said it is an integer. */
38
+ function numberArg(args, name) {
39
+ const value = args[name];
40
+ return typeof value === "number" ? String(value) : undefined;
41
+ }
36
42
  export function shareTools(ctx) {
37
43
  return [
44
+ {
45
+ name: "nmts_public_code_new",
46
+ description: "Make a new public code for this account — the next number from the same NMTS key — and " +
47
+ "publish it, so other accounts can send files to it. `replace` names a live code to revoke " +
48
+ "in the same step: nobody can send to that one again and nobody can bring it back. The " +
49
+ "server caps how many codes are live at once and how many are made per UTC day; the reply " +
50
+ "of nmts_public_code says both.",
51
+ inputSchema: {
52
+ type: "object",
53
+ properties: {
54
+ replace: {
55
+ type: "integer",
56
+ description: "The number of a live code to revoke in the same step, from nmts_public_code.",
57
+ },
58
+ },
59
+ additionalProperties: false,
60
+ },
61
+ run: (args) => say((write) => newCode({ ...common(ctx), json: true, yes: true, replace: numberArg(args, "replace"), write })),
62
+ },
63
+ {
64
+ name: "nmts_public_code_revoke",
65
+ description: "Revoke one of this account's public codes, by its number from nmts_public_code. Nobody can " +
66
+ "send to it again and nobody can bring it back; files already received with it stay and " +
67
+ "still open. The account's last live code cannot be revoked — make a new one with " +
68
+ "nmts_public_code_new and `replace` instead.",
69
+ inputSchema: {
70
+ type: "object",
71
+ properties: {
72
+ index: { type: "integer", description: "The code's number, from nmts_public_code." },
73
+ },
74
+ required: ["index"],
75
+ additionalProperties: false,
76
+ },
77
+ run: (args) => say((write) => revokeCodeCommand(numberArg(args, "index"), { ...common(ctx), json: true, yes: true, write })),
78
+ },
38
79
  {
39
80
  name: "nmts_share",
40
81
  description: "Give another NMTS account the key to one file in this account. ⛔ IT CANNOT BE TAKEN " +
@@ -53,6 +94,11 @@ export function shareTools(ctx) {
53
94
  type: "string",
54
95
  description: "The recipient's PUBLIC CODE, given to you by them. Not their NMTS key.",
55
96
  },
97
+ as: {
98
+ type: "integer",
99
+ description: "Which of this account's live public codes sends it, by number from nmts_public_code. " +
100
+ "Absent: the lowest-numbered live one.",
101
+ },
56
102
  },
57
103
  required: ["path", "public_code"],
58
104
  additionalProperties: false,
@@ -60,7 +106,7 @@ export function shareTools(ctx) {
60
106
  run: async (args) => {
61
107
  const path = needString(args, "path");
62
108
  const code = needString(args, "public_code");
63
- return say((write) => share(path, code, { ...common(ctx), json: true, write }));
109
+ return say((write) => share(path, code, { ...common(ctx), json: true, as: numberArg(args, "as"), write }));
64
110
  },
65
111
  },
66
112
  {
@@ -12,6 +12,11 @@ import { unlocked } from "../gate.js";
12
12
  import { BINARY_NAME } from "../product.js";
13
13
  import { ACTS } from "../risk.js";
14
14
  const READ = { act: "ls", readOnly: true };
15
+ /** The revoke question, naming the code by its number — the same words `nmts public-code revoke` asks. */
16
+ function revokeQuestion(index) {
17
+ return (`Revoke public code #${String(index)}? Nobody can send to it again, and nobody can bring it back. ` +
18
+ "Files already received with it stay.");
19
+ }
15
20
  export const TOOL_TIERS = {
16
21
  nmts_whoami: { act: "whoami", readOnly: true },
17
22
  nmts_list: READ,
@@ -24,6 +29,15 @@ export const TOOL_TIERS = {
24
29
  nmts_wallet_storage: { act: "wallet", readOnly: true },
25
30
  nmts_devices: { act: "devices", readOnly: true },
26
31
  nmts_public_code: { act: "public-code", readOnly: true },
32
+ // ⛔ A REPLACEMENT IS A REVOKE, and is asked as one — the act follows the arguments.
33
+ nmts_public_code_new: {
34
+ act: (args) => (typeof args["replace"] === "number" ? "public-code.revoke" : "public-code.new"),
35
+ question: (args) => typeof args["replace"] === "number"
36
+ ? `Make a new public code for this account and revoke public code #${String(args["replace"])}? ` +
37
+ "Nobody can send to that one again, and nobody can bring it back. Files already received with it stay."
38
+ : "Make a new public code for this account. Go ahead?",
39
+ },
40
+ nmts_public_code_revoke: { act: "public-code.revoke", question: (args) => revokeQuestion(args["index"]) },
27
41
  nmts_shares: { act: "shares", readOnly: true },
28
42
  nmts_shares_sent: { act: "shares", readOnly: true },
29
43
  nmts_notices: { act: "notices", readOnly: true },
@@ -54,7 +68,8 @@ export const TOOL_TIERS = {
54
68
  nmts_restore: { act: "restore" },
55
69
  nmts_share: {
56
70
  act: "share",
57
- question: (args) => `Share "${String(args["path"])}" with the NMTS account whose public code is ${String(args["public_code"])}?\n\n` +
71
+ question: (args) => `Share "${String(args["path"])}" with the NMTS account whose public code is ${String(args["public_code"])}` +
72
+ `${typeof args["as"] === "number" ? `, from this account's public code #${String(args["as"])}` : ""}?\n\n` +
58
73
  "Whoever holds that code can then download the file. Withdrawing the share afterwards stops " +
59
74
  "further downloads and cannot reach a copy already fetched. The code is not checked against " +
60
75
  "a person — if it is the wrong one, the file goes to whoever holds it.",
@@ -17,6 +17,12 @@ export type { AccountIdentity } from "./account.ts";
17
17
  export { AAD, DERIVED, loadCrypto } from "./crypto.ts";
18
18
  export type { CryptoGlue } from "./crypto.ts";
19
19
  export { isCryptoGlue, missingExports } from "./crypto-surface.ts";
20
+ export { CODE_INDEX_MAX, openShareAnyCode, openShareWithRing, requireCodeIndex, shareKeyRing, shareKeysAt, type ShareKeyRing, } from "./share-codes.ts";
21
+ export type { ShareKeys, ShareSealed } from "./share.ts";
22
+ export { defaultCode, ensureLiveCode, liveCodes, nextCodeIndex, publishCode, PUBLISH_TRIES, readPublicCodes, revokeCode, } from "./public-codes.ts";
23
+ export type { CodeDoor, PublicCodeList, PublicCodeRow, PublishedCode } from "./public-codes.ts";
24
+ export { codeActivity } from "./public-code-activity.ts";
25
+ export type { ActivityDoor, CodeActivity, ReceivedThrough, SentThrough } from "./public-code-activity.ts";
20
26
  export { readFileList } from "./manifest.ts";
21
27
  export type { FileList } from "./manifest.ts";
22
28
  export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
@@ -51,6 +57,8 @@ export type { PlaintextSink } from "./download-sink.ts";
51
57
  export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./walrus.ts";
52
58
  export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.ts";
53
59
  export type { ReadOptions } from "./walrus.ts";
60
+ export { listLinks, makeLink, openLink, revokeLink } from "./links.ts";
61
+ export type { LinkAccount, ListedLink, MadeLink, OpenedLinkFile } from "./links.ts";
54
62
  export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.ts";
55
63
  export type { ChainReader, CoinBalance, WalletBalances } from "./wallet.ts";
56
64
  export { chainReader } from "./wallet-chain.ts";
package/dist/portable.js CHANGED
@@ -41,6 +41,12 @@ export { AAD, DERIVED, loadCrypto } from "./crypto.js";
41
41
  // runs its answer through this rather than trusting it.
42
42
  export { isCryptoGlue, missingExports } from "./crypto-surface.js";
43
43
  // The sealed file list: reading it, editing it, and walking it by path.
44
+ // Public codes (spec 2026-09-23): the numbered codes one key derives, the account's list of them on
45
+ // the server, and what each one was used for. `openShareAnyCode` is what opens a share whose code is
46
+ // not named — it tries the numbers it is given.
47
+ export { CODE_INDEX_MAX, openShareAnyCode, openShareWithRing, requireCodeIndex, shareKeyRing, shareKeysAt, } from "./share-codes.js";
48
+ export { defaultCode, ensureLiveCode, liveCodes, nextCodeIndex, publishCode, PUBLISH_TRIES, readPublicCodes, revokeCode, } from "./public-codes.js";
49
+ export { codeActivity } from "./public-code-activity.js";
44
50
  export { readFileList } from "./manifest.js";
45
51
  export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
46
52
  export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
@@ -75,6 +81,8 @@ export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./
75
81
  // to rather than finding out from a request that went somewhere else. Each reads what the
76
82
  // caller said first, then the environment, then the network's own.
77
83
  export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.js";
84
+ // Public links (NCF-3 §5.8): make, list, cut, and open without an account — `nmts link`'s four.
85
+ export { listLinks, makeLink, openLink, revokeLink } from "./links.js";
78
86
  // The wallet the NMTS key derives: reading it, and signing with it.
79
87
  export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.js";
80
88
  export { chainReader } from "./wallet-chain.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.46.0";
12
+ export declare const VERSION = "0.47.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.46.0";
21
+ export const VERSION = "0.47.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. */
@@ -0,0 +1,35 @@
1
+ import type { CryptoGlue } from "./crypto.ts";
2
+ import type { PublicCodeList } from "./public-codes.ts";
3
+ /** One share sent from a code. */
4
+ export interface SentThrough {
5
+ id: string;
6
+ itemId: string;
7
+ /** Where the file sits in this account, or null when the list no longer holds it. */
8
+ path: string | null;
9
+ /** The recipient's code in the form a person reads, or as the server sent it if it will not parse. */
10
+ recipient: string;
11
+ recipientRevoked: boolean;
12
+ createdAt: string;
13
+ }
14
+ /** One share received with a code. */
15
+ export interface ReceivedThrough {
16
+ id: string;
17
+ /** The name its sender sealed, or null when it would not open — `problem` says why. */
18
+ name: string | null;
19
+ sender: string | null;
20
+ senderRevoked: boolean;
21
+ createdAt: string;
22
+ problem: string | null;
23
+ }
24
+ export interface CodeActivity {
25
+ sent: SentThrough[];
26
+ received: ReceivedThrough[];
27
+ }
28
+ /** Where to ask and as whom — the account the code opens, on its server. */
29
+ export interface ActivityDoor {
30
+ server: string;
31
+ token: string;
32
+ accountId: string;
33
+ }
34
+ /** Every code's shares, by number. A code with none has two empty lists. */
35
+ export declare function codeActivity(crypt: CryptoGlue, code: string, door: ActivityDoor, list: PublicCodeList): Promise<Map<number, CodeActivity>>;
@@ -0,0 +1,88 @@
1
+ // What each of an account's public codes has been used for: the shares sent from it and the shares
2
+ // received with it — `nmts public-code list --activity` and the library's `publicCodes.list`.
3
+ //
4
+ // ⛔ THE NAMES ARE OPENED HERE, NOT READ FROM THE SERVER. The server knows which code a share went
5
+ // through and nothing about what it holds: a received file's name is sealed by its sender and
6
+ // opens with the code it came to, and a sent file's name is this account's own, in its sealed list.
7
+ //
8
+ // ⚠ A ROW THAT WILL NOT OPEN IS STILL LISTED, with the reason and no name — the rule `openReceived`
9
+ // keeps for the inbox, for the same reason: leaving it out would say less was received than was.
10
+ import { request } from "./api.js";
11
+ import { fromBase64Url } from "./bytes.js";
12
+ import { buildIndex, fullPathOf } from "./drive-paths.js";
13
+ import { isRecord } from "./guards.js";
14
+ import { readFileList } from "./manifest.js";
15
+ import { openReceived, receivedIndex } from "./share.js";
16
+ import { shareKeyRing } from "./share-codes.js";
17
+ function readable(crypt, wire) {
18
+ try {
19
+ return crypt.share_address_display(fromBase64Url(wire));
20
+ }
21
+ catch {
22
+ return wire;
23
+ }
24
+ }
25
+ function rowsOf(answer) {
26
+ return isRecord(answer) && Array.isArray(answer["shares"]) ? answer["shares"] : [];
27
+ }
28
+ function isReceived(value) {
29
+ if (!isRecord(value))
30
+ return false;
31
+ return ["id", "item_id", "dek_share_ct", "name_share_ct", "content_hash_share_ct"].every((name) => typeof value[name] === "string");
32
+ }
33
+ /** Every code's shares, by number. A code with none has two empty lists. */
34
+ export async function codeActivity(crypt, code, door, list) {
35
+ const out = new Map();
36
+ for (const c of list.codes)
37
+ out.set(c.index, { sent: [], received: [] });
38
+ const slot = (index) => {
39
+ const had = out.get(index);
40
+ if (had !== undefined)
41
+ return had;
42
+ const made = { sent: [], received: [] };
43
+ out.set(index, made);
44
+ return made;
45
+ };
46
+ const files = await readFileList(door.server, door.token, code, door.accountId);
47
+ const entries = files.manifest?.entries ?? [];
48
+ const index = buildIndex(entries);
49
+ const pathOf = new Map(entries.map((e) => [e.id, fullPathOf(index, e)]));
50
+ for (const c of list.codes) {
51
+ const answer = await request(door.server, `/v1/shares/sent?from_index=${c.index}`, { token: door.token });
52
+ for (const row of rowsOf(answer)) {
53
+ if (!isRecord(row))
54
+ continue;
55
+ const { id, item_id: itemId, recipient_address: to, created_at: at } = row;
56
+ if (typeof id !== "string" || typeof itemId !== "string" || typeof to !== "string" || typeof at !== "string")
57
+ continue;
58
+ slot(c.index).sent.push({
59
+ id,
60
+ itemId,
61
+ path: pathOf.get(itemId) ?? null,
62
+ recipient: readable(crypt, to),
63
+ recipientRevoked: row["recipient_code_revoked"] === true,
64
+ createdAt: at,
65
+ });
66
+ }
67
+ }
68
+ const ring = shareKeyRing(crypt, code);
69
+ try {
70
+ const answer = await request(door.server, "/v1/shares/received", { token: door.token });
71
+ for (const row of rowsOf(answer).filter(isReceived)) {
72
+ const opened = openReceived(crypt, ring.at(receivedIndex(row)), row);
73
+ opened.dek?.fill(0);
74
+ slot(opened.toIndex).received.push({
75
+ id: opened.id,
76
+ name: opened.name,
77
+ sender: opened.sender,
78
+ senderRevoked: opened.senderRevoked,
79
+ createdAt: opened.createdAt,
80
+ problem: opened.problem,
81
+ });
82
+ }
83
+ }
84
+ finally {
85
+ ring.wipe();
86
+ }
87
+ return out;
88
+ }
@@ -0,0 +1,25 @@
1
+ import { NmtsError } from "./errors.ts";
2
+ /** What the texts below fill in. Each is optional; a missing one falls back to a sentence without it. */
3
+ export interface RefusalFacts {
4
+ /** How many live codes the account may hold. */
5
+ liveMax?: number | undefined;
6
+ /** How many new codes it may make per UTC day. */
7
+ dayCap?: number | undefined;
8
+ /** The number of the code a replacement would revoke — the account's default. */
9
+ replace?: number | undefined;
10
+ }
11
+ /** The refusal a person reads for `error`, or `error` itself when it is not one of the table's. */
12
+ export declare function publicCodeRefusal(error: unknown, facts?: RefusalFacts): unknown;
13
+ /** Revoking `index` would leave the account with no live code. */
14
+ export declare function lastLiveCode(index: number | undefined): NmtsError;
15
+ /** A number that is not one of this account's live codes. */
16
+ export declare function notLiveCode(index: number): NmtsError;
17
+ /**
18
+ * The server holds a code this key does not derive at that number.
19
+ *
20
+ * ⛔ THE BIGGER FACT, NOT "THE WRITE FAILED". Codes come from the NMTS key, so a different one means
21
+ * this machine holds a different account's key than the credential beside it.
22
+ */
23
+ export declare function differentCode(): NmtsError;
24
+ /** A public code's number as a person typed it after `flag`. */
25
+ export declare function codeNumber(text: string | undefined, flag: string): number;