@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,87 @@
1
+ // What a person is told when a public-code door refuses — one table, read by `nmts public-code …`
2
+ // and by `nmts share`.
3
+ //
4
+ // ⛔ IT TRANSLATES ONLY WHAT IT KNOWS. A refusal whose code is not in this table is handed on as
5
+ // the server sent it (`ServerError`, with the server's own advice), not reworded into a guess.
6
+ //
7
+ // ⚠ THE NUMBERS COME FROM THE REFUSAL WHEN IT CARRIES THEM (`details.cap`) and from the account's
8
+ // list otherwise — the server's ceiling, not a copy of it kept here.
9
+ import { ServerError } from "./api.js";
10
+ import { NmtsError } from "./errors.js";
11
+ import { BINARY_NAME } from "./product.js";
12
+ function capOf(error, fallback) {
13
+ const cap = error.details["cap"];
14
+ return typeof cap === "number" ? cap : fallback;
15
+ }
16
+ /** The refusal a person reads for `error`, or `error` itself when it is not one of the table's. */
17
+ export function publicCodeRefusal(error, facts = {}) {
18
+ if (!(error instanceof ServerError))
19
+ return error;
20
+ switch (error.code) {
21
+ case "TOO_MANY_LIVE_CODES": {
22
+ const cap = capOf(error, facts.liveMax);
23
+ const said = cap === undefined ? "as many live public codes as you may" : `${cap} live public codes`;
24
+ return new NmtsError(`You already hold ${said}.`, {
25
+ exitCode: 4,
26
+ nextStep: "Revoke one first, or make the new one with --replace <number>.",
27
+ });
28
+ }
29
+ case "PUBLIC_CODE_DAY_CAP": {
30
+ const cap = capOf(error, facts.dayCap);
31
+ const said = cap === undefined ? "as many public codes today as you may" : `${cap} public codes today`;
32
+ return new NmtsError(`You have made ${said}.`, { exitCode: 4, nextStep: "Try again after 00:00 UTC." });
33
+ }
34
+ case "LAST_LIVE_CODE":
35
+ return lastLiveCode(facts.replace);
36
+ case "PLATFORM_REPLACE_ONLY":
37
+ return new NmtsError("This account holds one public code, so a new one replaces it.", {
38
+ exitCode: 4,
39
+ nextStep: `Use --replace ${facts.replace ?? "<number>"}.`,
40
+ });
41
+ case "PUBLIC_CODE_REVOKED":
42
+ return new NmtsError("Its owner has revoked that public code.", {
43
+ exitCode: 4,
44
+ nextStep: "Ask them for the code they use now.",
45
+ });
46
+ default:
47
+ return error;
48
+ }
49
+ }
50
+ /** Revoking `index` would leave the account with no live code. */
51
+ export function lastLiveCode(index) {
52
+ return new NmtsError("That is your last live public code.", {
53
+ exitCode: 4,
54
+ nextStep: `Make a new one first: ${BINARY_NAME} public-code new --replace ${index ?? "<number>"}`,
55
+ });
56
+ }
57
+ /** A number that is not one of this account's live codes. */
58
+ export function notLiveCode(index) {
59
+ return new NmtsError(`Public code #${index} is not a live code of this account.`, {
60
+ exitCode: 4,
61
+ nextStep: `\`${BINARY_NAME} public-code list\` shows which are.`,
62
+ });
63
+ }
64
+ /**
65
+ * The server holds a code this key does not derive at that number.
66
+ *
67
+ * ⛔ THE BIGGER FACT, NOT "THE WRITE FAILED". Codes come from the NMTS key, so a different one means
68
+ * this machine holds a different account's key than the credential beside it.
69
+ */
70
+ export function differentCode() {
71
+ return new NmtsError("This account already publishes a different public code.", {
72
+ exitCode: 4,
73
+ nextStep: "The public code is derived from the NMTS key, so a different one means this machine " +
74
+ "is holding a different account's code than the key beside it. Check which account you meant.",
75
+ });
76
+ }
77
+ /** A public code's number as a person typed it after `flag`. */
78
+ export function codeNumber(text, flag) {
79
+ const trimmed = (text ?? "").trim();
80
+ const n = /^[0-9]{1,10}$/.test(trimmed) ? Number(trimmed) : Number.NaN;
81
+ if (!Number.isSafeInteger(n) || n > 2 ** 31 - 2) {
82
+ throw new NmtsError(`${flag} takes a public code's number, as \`${BINARY_NAME} public-code list\` prints it.`, {
83
+ exitCode: 2,
84
+ });
85
+ }
86
+ return n;
87
+ }
@@ -0,0 +1,76 @@
1
+ import type { CryptoGlue } from "./crypto.ts";
2
+ /** One code as `GET /v1/account/public-codes` lists it. */
3
+ export interface PublicCodeRow {
4
+ index: number;
5
+ /** The 16-byte address, base64url, as the wire carries it. */
6
+ address: string;
7
+ createdAt: string;
8
+ /** When it was revoked, or null while it is live. */
9
+ revokedAt: string | null;
10
+ /** Shares sent from it, shares received with it, support threads that carry it. */
11
+ sent: number;
12
+ received: number;
13
+ support: number;
14
+ }
15
+ /** The whole answer: every code this account ever published, and the two ceilings on making more. */
16
+ export interface PublicCodeList {
17
+ codes: PublicCodeRow[];
18
+ /** How many may be live at once — 3, or 1 for a Platform user. */
19
+ liveMax: number;
20
+ /** How many new ones this account may make per UTC day, and how many it has made today. */
21
+ dayCap: number;
22
+ madeToday: number;
23
+ }
24
+ /** How many numbers in a row publishing walks past before it stops. */
25
+ export declare const PUBLISH_TRIES = 64;
26
+ /** `GET /v1/account/public-codes`, read field by field. Codes come back in number order. */
27
+ export declare function readPublicCodes(server: string, token: string): Promise<PublicCodeList>;
28
+ /** The live codes, lowest number first. */
29
+ export declare function liveCodes(list: PublicCodeList): PublicCodeRow[];
30
+ /** The code this account shows and sends from unless told otherwise: its lowest-numbered live one. */
31
+ export declare function defaultCode(list: PublicCodeList): PublicCodeRow | null;
32
+ /** The number a new code gets: one past the highest ever published, or 0 for an account with none. */
33
+ export declare function nextCodeIndex(list: PublicCodeList): number;
34
+ /** Where a request goes and what it carries. */
35
+ export interface CodeDoor {
36
+ server: string;
37
+ token: string;
38
+ }
39
+ /** What publishing answers: the number it landed on and the code a person reads. */
40
+ export interface PublishedCode {
41
+ index: number;
42
+ /** The grouped form a person reads and types. */
43
+ code: string;
44
+ /** The 16 bytes, base64url. */
45
+ address: string;
46
+ }
47
+ /**
48
+ * Publish this key's code at `from` (default: the next number), revoking `replace` in the same
49
+ * request when it is given. Walks past numbers the server says were revoked, up to `PUBLISH_TRIES`.
50
+ *
51
+ * ⛔ THE IDENTITY IS DERIVED HERE AND NOWHERE ELSE. There is no form of this that takes an identity
52
+ * from a caller: what goes to the server is what this key makes at that number.
53
+ */
54
+ export declare function publishCode(crypt: CryptoGlue, code: string, door: CodeDoor, from: number, replace?: number): Promise<PublishedCode>;
55
+ /**
56
+ * Make sure the account has a live code, publishing the next number when it has none — what a
57
+ * first share does before anything else. Answers the list as it now stands, and whether it wrote.
58
+ */
59
+ export declare function ensureLiveCode(crypt: CryptoGlue, code: string, door: CodeDoor, onPublish?: () => void): Promise<{
60
+ list: PublicCodeList;
61
+ published: PublishedCode | null;
62
+ }>;
63
+ /** One bucket of the server's revoked list, fetched once per lookup that shares it. */
64
+ export type RevokedBuckets = Map<string, Promise<Uint8Array[]>>;
65
+ /**
66
+ * Whether the code at `address` is on the server's revoked list — or null when the list could not
67
+ * be read (offline, rate-limited, an older server), which is "unknown", not "live".
68
+ *
69
+ * ⛔ ASKED BY BUCKET, NEVER BY CODE. The server keeps SHA-256 of each revoked address; this fetches
70
+ * every mark whose hex starts with the same digit as this address's mark (one of sixteen) and
71
+ * compares here. A question about one code would tell the server who is dealing with whom — the
72
+ * thing a handover exists not to tell it. Needs no credential.
73
+ */
74
+ export declare function revokedOnServer(server: string, address: Uint8Array, buckets?: RevokedBuckets): Promise<boolean | null>;
75
+ /** `POST /v1/account/public-codes/{index}/revoke`. One way: nothing brings a code back. */
76
+ export declare function revokeCode(door: CodeDoor, index: number): Promise<void>;
@@ -0,0 +1,182 @@
1
+ // An account's public codes on the server: reading them, publishing the next one, revoking one.
2
+ //
3
+ // ⛔ NO TERMINAL HERE. `nmts public-code …`, `nmts share` and the library's `publicCodes` all come
4
+ // through these functions, so the three answer the same account the same way; what a person is
5
+ // told about a refusal is the command's business (`commands/public-code-manage.ts`), and a
6
+ // program gets the server's own `ServerError` with its code to branch on.
7
+ //
8
+ // ⛔ THE NEXT NUMBER IS THE HIGHEST EVER PLUS ONE, revoked ones included, and nothing is guessed
9
+ // beyond that: the server answers which number it wanted when it refuses one (`INDEX_NOT_NEXT`),
10
+ // and a number whose code was revoked once — by this account before it was erased and made again
11
+ // from the same key — is refused for ever, so publishing walks past it.
12
+ //
13
+ // ⚠ THE DEFAULT CODE IS NOT STORED ANYWHERE. It is the lowest-numbered live one, read
14
+ // off the list every time.
15
+ import { request, ServerError } from "./api.js";
16
+ import { fromBase64Url, toBase64Url } from "./bytes.js";
17
+ import { NmtsError } from "./errors.js";
18
+ import { isRecord } from "./guards.js";
19
+ import { requireCodeIndex, shareKeyRing } from "./share-codes.js";
20
+ /** How many numbers in a row publishing walks past before it stops. */
21
+ export const PUBLISH_TRIES = 64;
22
+ const unreadable = () => new NmtsError("The server listed this account's public codes in a shape this version cannot read.", {
23
+ nextStep: "Nothing was changed. A newer version of this tool may understand it.",
24
+ });
25
+ function whole(value) {
26
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)
27
+ throw unreadable();
28
+ return value;
29
+ }
30
+ function readRow(value) {
31
+ if (!isRecord(value) || typeof value["address"] !== "string" || typeof value["created_at"] !== "string") {
32
+ throw unreadable();
33
+ }
34
+ const revoked = value["revoked_at"];
35
+ return {
36
+ index: whole(value["index"]),
37
+ address: value["address"],
38
+ createdAt: value["created_at"],
39
+ revokedAt: typeof revoked === "string" ? revoked : null,
40
+ sent: whole(value["sent"] ?? 0),
41
+ received: whole(value["received"] ?? 0),
42
+ support: whole(value["support"] ?? 0),
43
+ };
44
+ }
45
+ /** `GET /v1/account/public-codes`, read field by field. Codes come back in number order. */
46
+ export async function readPublicCodes(server, token) {
47
+ const answer = await request(server, "/v1/account/public-codes", { token });
48
+ if (!isRecord(answer) || !Array.isArray(answer["codes"]))
49
+ throw unreadable();
50
+ const codes = answer["codes"].map(readRow).sort((a, b) => a.index - b.index);
51
+ return {
52
+ codes,
53
+ liveMax: whole(answer["live_max"]),
54
+ dayCap: whole(answer["day_cap"]),
55
+ madeToday: whole(answer["made_today"] ?? 0),
56
+ };
57
+ }
58
+ /** The server wants `index` next and refuses it as revoked, so no number can be published. */
59
+ function noNextNumber(index) {
60
+ return new NmtsError(`The server wants public code #${index} next, and refuses it as revoked.`, {
61
+ exitCode: 4,
62
+ nextStep: "Nothing was published. The server has to let this account skip that number; report it.",
63
+ });
64
+ }
65
+ /** The live codes, lowest number first. */
66
+ export function liveCodes(list) {
67
+ return list.codes.filter((c) => c.revokedAt === null);
68
+ }
69
+ /** The code this account shows and sends from unless told otherwise: its lowest-numbered live one. */
70
+ export function defaultCode(list) {
71
+ return liveCodes(list)[0] ?? null;
72
+ }
73
+ /** The number a new code gets: one past the highest ever published, or 0 for an account with none. */
74
+ export function nextCodeIndex(list) {
75
+ return list.codes.reduce((top, c) => Math.max(top, c.index + 1), 0);
76
+ }
77
+ /**
78
+ * Publish this key's code at `from` (default: the next number), revoking `replace` in the same
79
+ * request when it is given. Walks past numbers the server says were revoked, up to `PUBLISH_TRIES`.
80
+ *
81
+ * ⛔ THE IDENTITY IS DERIVED HERE AND NOWHERE ELSE. There is no form of this that takes an identity
82
+ * from a caller: what goes to the server is what this key makes at that number.
83
+ */
84
+ export async function publishCode(crypt, code, door, from, replace) {
85
+ let index = requireCodeIndex(from);
86
+ // ⛔ ONE RING for the walk: the key's derivation runs once, not once per number tried.
87
+ const ring = shareKeyRing(crypt, code);
88
+ const refusedAsRevoked = new Set();
89
+ try {
90
+ for (let tries = 0; tries < PUBLISH_TRIES; tries += 1) {
91
+ const keys = ring.at(index);
92
+ try {
93
+ const address = toBase64Url(keys.address);
94
+ await request(door.server, "/v1/account/public-codes", {
95
+ token: door.token,
96
+ method: "POST",
97
+ body: {
98
+ index,
99
+ identity: toBase64Url(keys.identity),
100
+ address,
101
+ ...(replace === undefined ? {} : { revoke: [requireCodeIndex(replace)] }),
102
+ },
103
+ });
104
+ return { index, code: keys.display, address };
105
+ }
106
+ catch (error) {
107
+ if (!(error instanceof ServerError))
108
+ throw error;
109
+ if (error.code === "PUBLIC_CODE_REVOKED") {
110
+ refusedAsRevoked.add(index);
111
+ index = requireCodeIndex(index + 1);
112
+ continue;
113
+ }
114
+ // Another device made one in between: the server says which number it wants now.
115
+ const wanted = error.details["next"];
116
+ if (error.code === "INDEX_NOT_NEXT" && typeof wanted === "number" && wanted !== index) {
117
+ // ⚠ A server that wants a number it also refuses as revoked would send this back and forth.
118
+ if (refusedAsRevoked.has(wanted))
119
+ throw noNextNumber(wanted);
120
+ index = requireCodeIndex(wanted);
121
+ continue;
122
+ }
123
+ throw error;
124
+ }
125
+ }
126
+ }
127
+ finally {
128
+ ring.wipe();
129
+ }
130
+ throw new NmtsError(`${PUBLISH_TRIES} public code numbers in a row were refused as revoked.`, {
131
+ nextStep: "Nothing was published. Try again later; if it repeats, report it.",
132
+ });
133
+ }
134
+ /**
135
+ * Make sure the account has a live code, publishing the next number when it has none — what a
136
+ * first share does before anything else. Answers the list as it now stands, and whether it wrote.
137
+ */
138
+ export async function ensureLiveCode(crypt, code, door, onPublish) {
139
+ const list = await readPublicCodes(door.server, door.token);
140
+ if (defaultCode(list) !== null)
141
+ return { list, published: null };
142
+ onPublish?.();
143
+ const published = await publishCode(crypt, code, door, nextCodeIndex(list));
144
+ return { list: await readPublicCodes(door.server, door.token), published };
145
+ }
146
+ /**
147
+ * Whether the code at `address` is on the server's revoked list — or null when the list could not
148
+ * be read (offline, rate-limited, an older server), which is "unknown", not "live".
149
+ *
150
+ * ⛔ ASKED BY BUCKET, NEVER BY CODE. The server keeps SHA-256 of each revoked address; this fetches
151
+ * every mark whose hex starts with the same digit as this address's mark (one of sixteen) and
152
+ * compares here. A question about one code would tell the server who is dealing with whom — the
153
+ * thing a handover exists not to tell it. Needs no credential.
154
+ */
155
+ export async function revokedOnServer(server, address, buckets = new Map()) {
156
+ try {
157
+ const mark = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new Uint8Array(address)));
158
+ const prefix = (mark[0] ?? 0).toString(16).padStart(2, "0").charAt(0);
159
+ let bucket = buckets.get(prefix);
160
+ if (bucket === undefined) {
161
+ bucket = request(server, `/v1/public-codes/revoked?prefix=${prefix}`, {}).then((answer) => {
162
+ const marks = isRecord(answer) ? answer["fingerprints"] : null;
163
+ if (!Array.isArray(marks))
164
+ throw unreadable();
165
+ return marks.filter((m) => typeof m === "string").map(fromBase64Url);
166
+ });
167
+ buckets.set(prefix, bucket);
168
+ }
169
+ const held = await bucket;
170
+ return held.some((m) => m.length === mark.length && m.every((byte, at) => byte === mark[at]));
171
+ }
172
+ catch {
173
+ return null;
174
+ }
175
+ }
176
+ /** `POST /v1/account/public-codes/{index}/revoke`. One way: nothing brings a code back. */
177
+ export async function revokeCode(door, index) {
178
+ await request(door.server, `/v1/account/public-codes/${requireCodeIndex(index)}/revoke`, {
179
+ token: door.token,
180
+ method: "POST",
181
+ });
182
+ }
package/dist/risk.d.ts CHANGED
@@ -56,9 +56,15 @@ export declare const ACTS: {
56
56
  readonly "public-code": {
57
57
  readonly tier: "none";
58
58
  };
59
+ readonly "public-code.list": {
60
+ readonly tier: "none";
61
+ };
59
62
  readonly handover: {
60
63
  readonly tier: "none";
61
64
  };
65
+ readonly link: {
66
+ readonly tier: "none";
67
+ };
62
68
  readonly wallet: {
63
69
  readonly tier: "none";
64
70
  };
@@ -179,6 +185,10 @@ export declare const ACTS: {
179
185
  readonly tier: "low";
180
186
  readonly what: "Withdraw this share. Whoever had it cannot download it again.";
181
187
  };
188
+ readonly "link.revoke": {
189
+ readonly tier: "low";
190
+ readonly what: "Cut a public link.";
191
+ };
182
192
  readonly tip: {
183
193
  readonly tier: "none";
184
194
  };
@@ -252,7 +262,11 @@ export declare const ACTS: {
252
262
  };
253
263
  readonly "public-code.publish": {
254
264
  readonly tier: "medium";
255
- readonly what: "Publish this account's public code. Publishing cannot be undone.";
265
+ readonly what: "Publish this account's public code so other accounts can send files to it.";
266
+ };
267
+ readonly "public-code.new": {
268
+ readonly tier: "medium";
269
+ readonly what: "Make a new public code for this account.";
256
270
  };
257
271
  readonly "losses.dismiss": {
258
272
  readonly tier: "medium";
@@ -278,6 +292,11 @@ export declare const ACTS: {
278
292
  readonly what: "Give another account this file in a handover file. It cannot be taken back.";
279
293
  readonly asksItself: true;
280
294
  };
295
+ readonly "link.make": {
296
+ readonly tier: "high";
297
+ readonly lock: "share";
298
+ readonly what: "Anyone with the link can open this file. Cutting the link stops new downloads, but copies already downloaded stay with whoever has them.";
299
+ };
281
300
  readonly "login.plain": {
282
301
  readonly tier: "high";
283
302
  readonly lock: "unsafe-code-storage";
@@ -377,6 +396,11 @@ export declare const ACTS: {
377
396
  readonly what: "Accept a new version of the Terms for this account.";
378
397
  readonly asksItself: true;
379
398
  };
399
+ readonly "public-code.revoke": {
400
+ readonly tier: "high";
401
+ readonly what: "Revoke a public code of this account. Nobody can send to it again, and nobody can bring it back.";
402
+ readonly asksItself: true;
403
+ };
380
404
  readonly "delete-account": {
381
405
  readonly tier: "ultra-high";
382
406
  readonly what: "Erase this account's server record, permanently.";
package/dist/risk.js CHANGED
@@ -39,9 +39,13 @@ export const ACTS = {
39
39
  // below, under the tiers they belong to.
40
40
  "ai-account": { tier: "none" },
41
41
  "public-code": { tier: "none" },
42
+ "public-code.list": { tier: "none" },
42
43
  // Opening a handover file someone passed on: it reads the file, fetches from Walrus and writes
43
44
  // one file here. `handover.make`, which gives a file away, is under `high` beside `share`.
44
45
  handover: { tier: "none" },
46
+ // Listing this file's public links, and opening somebody's link (no account). `link.make` is under
47
+ // `high` beside `share`; `link.revoke` is under `low` beside `unshare`.
48
+ link: { tier: "none" },
45
49
  wallet: { tier: "none" },
46
50
  get: { tier: "none" },
47
51
  pull: { tier: "none" },
@@ -86,6 +90,7 @@ export const ACTS = {
86
90
  rm: { tier: "low", what: "Move these to the trash, restorable for 30 days." },
87
91
  restore: { tier: "low", what: "Bring these back out of the trash." },
88
92
  unshare: { tier: "low", what: "Withdraw this share. Whoever had it cannot download it again." },
93
+ "link.revoke": { tier: "low", what: "Cut a public link." },
89
94
  tip: { tier: "none" },
90
95
  "tip.set": { tier: "none" },
91
96
  "on-collision.set": { tier: "low", what: "Change what an upload does when its name is already taken." },
@@ -117,7 +122,8 @@ export const ACTS = {
117
122
  // once has held the NMTS key — removal cannot unknow that.
118
123
  "openers.add": { tier: "medium", what: "Let this wallet open this account and every file in it." },
119
124
  "openers.remove": { tier: "medium", what: "Stop this wallet opening this account from now on." },
120
- "public-code.publish": { tier: "medium", what: "Publish this account's public code. Publishing cannot be undone." },
125
+ "public-code.publish": { tier: "medium", what: "Publish this account's public code so other accounts can send files to it." },
126
+ "public-code.new": { tier: "medium", what: "Make a new public code for this account." },
121
127
  "losses.dismiss": { tier: "medium", what: "Put this loss notice down. It will not be shown again." },
122
128
  // ⛔ MEDIUM AND NOT HIGH. It moves value, so it is not `low`; but it moves it INSIDE one person's
123
129
  // own family of accounts — nothing reaches a third party, nothing is spent, and the same
@@ -134,6 +140,12 @@ export const ACTS = {
134
140
  what: "Give another account this file in a handover file. It cannot be taken back.",
135
141
  asksItself: true,
136
142
  },
143
+ // ⛔ THE SAME UNLOCK AS `share`: it gives the file to whoever holds the link, account or not.
144
+ "link.make": {
145
+ tier: "high",
146
+ lock: "share",
147
+ what: "Anyone with the link can open this file. Cutting the link stops new downloads, but copies already downloaded stay with whoever has them.",
148
+ },
137
149
  "login.plain": { tier: "high", lock: "unsafe-code-storage", what: "Store the NMTS key in the clear.", standing: true },
138
150
  "login.env": { tier: "high", lock: "plain-env", what: "Print the NMTS key for an environment variable.", standing: true },
139
151
  extend: { tier: "high", lock: "wallet", what: "Sign a transaction that spends WAL from the wallet.", standing: true },
@@ -157,6 +169,14 @@ export const ACTS = {
157
169
  // itself — there is no version for anybody to type, so the gate takes the yes.
158
170
  "ai-account.create": { tier: "high", what: "Make a new account for an AI to work in, under the Terms in force." },
159
171
  "accept-terms.accept": { tier: "high", what: "Accept a new version of the Terms for this account.", asksItself: true },
172
+ // ⛔ HIGH, AND EVERY ROAD TO IT IS THIS ACT — `public-code new --replace` too. Nothing brings a
173
+ // revoked code back, and whoever holds it can no longer send to this account through it. It
174
+ // asks itself because the question names the code — and never without a yes.
175
+ "public-code.revoke": {
176
+ tier: "high",
177
+ what: "Revoke a public code of this account. Nobody can send to it again, and nobody can bring it back.",
178
+ asksItself: true,
179
+ },
160
180
  // ── ultra-high: permanent destruction ──
161
181
  "delete-account": { tier: "ultra-high", what: "Erase this account's server record, permanently.", asksItself: true },
162
182
  // ⛔ THE SAME ERASURE, AIMED AT AN ACCOUNT THIS ONE MADE — the row, the files, the keys and the
@@ -234,9 +254,20 @@ export function actOf(args) {
234
254
  case "losses":
235
255
  return args.dismiss !== undefined ? "losses.dismiss" : "losses";
236
256
  case "public-code":
257
+ // ⚠ `--save [file]` first: its operand is a file name, not one of the verbs below.
258
+ if (args.save)
259
+ return "public-code";
260
+ if (sub === "list")
261
+ return "public-code.list";
262
+ if (sub === "revoke" || (sub === "new" && args.replace !== undefined))
263
+ return "public-code.revoke";
264
+ if (sub === "new")
265
+ return "public-code.new";
237
266
  return args.publish ? "public-code.publish" : "public-code";
238
267
  case "handover":
239
268
  return sub === "make" ? "handover.make" : "handover";
269
+ case "link":
270
+ return sub === "make" ? "link.make" : sub === "revoke" ? "link.revoke" : "link";
240
271
  case "support":
241
272
  return sub === "send" || sub === "reply" ? "support.send" : "support";
242
273
  case "platform":
@@ -0,0 +1,40 @@
1
+ import { type CryptoGlue } from "./crypto.ts";
2
+ import { type ShareKeys, type ShareSealed } from "./share.ts";
3
+ /** The largest number a code may carry — the server keeps it in a signed 32-bit column. */
4
+ export declare const CODE_INDEX_MAX: number;
5
+ /** A code number as a caller wrote it. Refused, never rounded: a neighbouring code is a different one. */
6
+ export declare function requireCodeIndex(value: number): number;
7
+ /**
8
+ * Everything sharing needs for public code number `index` — the same shape `shareKeysOf` answers,
9
+ * which is exactly what it answers for 0. ⛔ The caller wipes it.
10
+ */
11
+ export declare function shareKeysAt(crypt: CryptoGlue, code: string, index: number): ShareKeys;
12
+ /** The keys of several codes of one NMTS key. */
13
+ export interface ShareKeyRing {
14
+ /** The keys at `index`, made on first use and kept. Not to be wiped by the caller. */
15
+ at(index: number): ShareKeys;
16
+ /** Wipes every key made and the root they grew from. */
17
+ wipe(): void;
18
+ }
19
+ /**
20
+ * The keys of several codes, from ONE run of the key's derivation, on first use. What stays between
21
+ * uses is code 0's keys and the 32-byte root the other numbers grow from — never the rest of the
22
+ * derivation. ⛔ `wipe()` wipes all of it.
23
+ */
24
+ export declare function shareKeyRing(crypt: CryptoGlue, code: string): ShareKeyRing;
25
+ /**
26
+ * Open one envelope with whichever of `indices` it was sealed to, trying them in the order given.
27
+ *
28
+ * ⛔ ONE REFUSAL FOR EVERY FAILURE. Which number was tried and how it failed is not something to
29
+ * report: a wrong code, a tampered envelope and a sender who is not who it claims all fail the
30
+ * same way, and saying which would be telling somebody holding the file more than the file says.
31
+ */
32
+ export declare function openShareAnyCode(crypt: CryptoGlue, code: string, indices: readonly number[], sealed: ShareSealed): {
33
+ dek: Uint8Array;
34
+ index: number;
35
+ };
36
+ /** `openShareAnyCode` with a ring the caller holds, and wipes. */
37
+ export declare function openShareWithRing(crypt: CryptoGlue, ring: ShareKeyRing, indices: readonly number[], sealed: ShareSealed): {
38
+ dek: Uint8Array;
39
+ index: number;
40
+ };