@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
package/AGENTS.md CHANGED
@@ -61,11 +61,11 @@ Four things need a person, all at the beginning. If you are being set up, hand t
61
61
  | 4. Get credits into the account | you, for the free trial (`nmts trial apply`, while step 3 is live) — a person, for a funded wallet | a terminal, or nmts.me | once, then as they run out |
62
62
 
63
63
  **Step 3 does not gate the work.** Reading, writing, listing, folders, the trash, the recovery files and the
64
- wallet's balances never ask about it. Exactly five things do — making another account, the free trial,
65
- creating a share, making a public link, and moving credits between your own accounts. A lapsed check does not stop you storing and
66
- fetching files; it stops you growing the account, and the account runs in a tighter rate tier until a person
67
- checks in again. `nmts verify --status` says whether it is live and until when; you cannot pass it
68
- (`nmts help verify`).
64
+ wallet's balances never ask about it. Exactly six things do — making another account, the free trial,
65
+ creating a share, making a public link, making a new public code, and
66
+ moving credits between your own accounts. A lapsed check does not stop you storing and fetching files; it
67
+ stops you growing the account, and the account runs in a tighter rate tier until a person checks in again.
68
+ `nmts verify --status` says whether it is live and until when; you cannot pass it (`nmts help verify`).
69
69
 
70
70
  **An account and the accounts made under it count as one.** The check is shared — one passed anywhere in that
71
71
  group is live for all of it — and so is the free trial: the whole group gets one application a week, not one
@@ -102,8 +102,8 @@ week's free places are gone, so it needs a funded wallet" is something a person
102
102
 
103
103
  Every act this tool performs has a tier: **none** (free and reversible: listing, fetching,
104
104
  folders, marks), **low** (reversible but worth a word: the trash, a setting, a report), **medium**
105
- (spends credits or is permanent: uploading, publishing the public code, a new key), **high**
106
- (signs with the wallet, hands a file to somebody, reveals or stores the NMTS key unsealed), and
105
+ (spends credits or is hard to undo: uploading, publishing or making a public code, a new key), **high**
106
+ (signs with the wallet, hands a file to somebody, revokes a public code, reveals or stores the NMTS key unsealed), and
107
107
  **ultra-high** (erasing the account). The person's **mode** says what each tier meets:
108
108
 
109
109
  | | default | auto-low | auto-high | skip-permissions |
@@ -141,7 +141,7 @@ folders, marks), **low** (reversible but worth a word: the trash, a setting, a r
141
141
  | where am I | `env` · `whoami` · `mode` · `unlock` / `lock` |
142
142
  | credentials | `login` · `logout` · `key` (new · list · revoke) · `devices` · `verify` |
143
143
  | files | `ls` / `listfile` · `get` · `pull` · `put` · `push` · `rm` / `restore` / `sweep` · `mkdir` / `mv` / `rename` · `star` / `pin` / `label` |
144
- | the account | `usage` / `balance` / `expiring` · `losses` · `trial` · `credits` · `public-code` · `create` · `delete-account` · `accept-terms` |
144
+ | the account | `usage` / `balance` / `expiring` · `losses` · `trial` · `credits` · `public-code` (list · new · revoke) · `create` · `delete-account` · `accept-terms` |
145
145
  | paying and the wallet | `extend` · `wallet` (address · activity · storage · send · swap · donate · hall) |
146
146
  | other accounts | `share` / `shares` / `receive` / `unshare` |
147
147
  | settings | `on-collision` · `padding` · `deposit` · `tip` |
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  Each version's entry is what changed for the person or the program using `nmts`. The product's own
4
4
  update history, which covers the site and the server too, is at https://nmts.me/updates.
5
5
 
6
+ ## 0.47.0 — 2026-09-27
7
+
8
+ - **Public links.** `nmts link make <path>` makes a link to one file that anyone can open without
9
+ an account, and prints it. The file's key travels in the part after `#`, which no request
10
+ carries. `--hide-name` leaves the name out and `--expires <n>d` ends the link after 1 to 3650
11
+ days. `link list <path>` prints every link to that file with its download count, `link revoke
12
+ <id>` cuts one, and `link open <link>` downloads and checks a file from a link without logging
13
+ in. `make` sits behind the same unlock as `share`. See `nmts help link`.
14
+ - **Up to three public codes.** Every code comes from the one NMTS key at a number.
15
+ `nmts public-code list` shows them all, live and revoked, with what went through each;
16
+ `public-code new` publishes the next one (`--replace <n>` revokes one in the same request); and
17
+ `public-code revoke <n>` revokes one for good, asking every time. `share`, `handover make` and
18
+ `public-code --save` take `--as <n>` to use a code other than the lowest-numbered live one.
19
+ - **NMTS Heavy on nmts.me.** nmts.me switched Heavy on, paid with credits. Its `--pay wallet`
20
+ payment is still off and answers `heavy_wallet_pay_off`; `--pay evm` works as before.
21
+
6
22
  ## 0.46.0 — 2026-09-27
7
23
 
8
24
  - **NMTS Heavy.** `nmts put --tier heavy` and `nmts push --tier heavy` keep each part of a file whole
@@ -17,7 +33,8 @@ update history, which covers the site and the server too, is at https://nmts.me/
17
33
  into Filecoin Pay. `put --tier heavy --pay evm` then pays the storage providers from that deposit,
18
34
  with `--copies` (1 to 12, default 2) and `--providers` choosing where; it does not go through
19
35
  NMTS's treasury. See `nmts help heavy`.
20
- - **Empty files** are stored instead of refused, by `put`, `push` and `nmts s3`.
36
+ - **Empty files:** `put` and `nmts s3` store an empty file on NMTS Standard instead of refusing it.
37
+ `push` still skips empty files, and `--tier heavy` refuses one.
21
38
  - **`nmts s3`:**
22
39
  - A range is read from the stored part it starts in. Each range used to be decrypted from the
23
40
  file's first byte, so a client fetching a 1 GB file in 8 MiB ranges read about 64 GB and the
package/README.ko.md CHANGED
@@ -50,7 +50,7 @@ nmts --help
50
50
 
51
51
  ```sh
52
52
  npm install -g github:needmoretruth/nmts-cli # 기본 브랜치
53
- npm install -g github:needmoretruth/nmts-cli#v0.46.0 # 버전을 고정할 때
53
+ npm install -g github:needmoretruth/nmts-cli#v0.47.0 # 버전을 고정할 때
54
54
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
55
55
  ```
56
56
 
package/README.md CHANGED
@@ -51,7 +51,7 @@ default branch, from a pinned version, or from the tarball attached to the
51
51
 
52
52
  ```sh
53
53
  npm install -g github:needmoretruth/nmts-cli # the default branch
54
- npm install -g github:needmoretruth/nmts-cli#v0.46.0 # a pinned version
54
+ npm install -g github:needmoretruth/nmts-cli#v0.47.0 # a pinned version
55
55
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
56
56
  ```
57
57
 
@@ -187,12 +187,17 @@ your main one.
187
187
  | `nmts create` | Make a NEW account and print its NMTS key once. Nothing can print it again. With no verified API key on this machine it makes the NMTS key here, prints an address, and waits while a person opens it, types that NMTS key and passes the human check — the account exists the moment they finish. `--no-wait` prints the address and stops |
188
188
  | `nmts verify` | Ask a person to pass the check that opens this account's limits. Only the account holder can: signed in to this account in that browser, or typing its NMTS key there |
189
189
  | `nmts public-code` | The code other accounts send files to. `--publish` makes it reachable; `--save [file]` writes your public code file |
190
+ | `nmts public-code list · new · revoke <n>` | Every code your NMTS key has published; publish the next one (`--replace <n>` revokes one in the same step); revoke one — nobody can send to it again. Revoking asks every time |
190
191
  | `nmts share <path> <address>` | Give one file to another account — **withdrawing does not recall it**. Locked until `nmts unlock share`; every share stops and `--yes` answers for that one file |
191
192
  | `nmts shares` | What was shared with this account; `--sent <path>` shows who one file went to |
192
193
  | `nmts receive <id>` | Download one file somebody shared with this account |
193
194
  | `nmts unshare <id>` | Withdraw a share you sent, or remove one you were sent |
194
195
  | `nmts handover make <path> --to <public code \| public code file>` | Write a handover file for one account and pass it on yourself — **it cannot be taken back**, and NMTS keeps no record of it. Locked like `share` |
195
- | `nmts handover open <file>` | Download the file a handover file carries. Needs the NMTS key and no API key; asks the NMTS server nothing |
196
+ | `nmts handover open <file>` | Download the file a handover file carries. Needs the NMTS key and no API key; tells the NMTS server nothing about the file |
197
+ | `nmts link make <path> [--hide-name] [--expires <n>d]` | Make a public link to a file |
198
+ | `nmts link list <path>` | List a file's public links |
199
+ | `nmts link revoke <id>` | Cut a public link |
200
+ | `nmts link open <link> [--out <path>]` | Download and decrypt a file from a public link, without logging in |
196
201
  | `nmts rebuild` | Build a file list from the server's rows, for an account with none |
197
202
  | `nmts rollback` | Put the previous version of the file list back — locked until `nmts unlock rollback`, `--yes` every run |
198
203
  | `nmts listfile` | Write this machine's copy of the sealed file list out as a file |
@@ -358,9 +363,11 @@ share stops further downloads and cannot reach a copy already taken, which is wh
358
363
  for an agreement the first time.
359
364
 
360
365
  `public-code` prints the value other accounts send files to and says whether it is published.
361
- Until it is published nobody can send to you. `--publish` writes it, permanently: it derives from
362
- your NMTS key, so it cannot be chosen or changed. It is not your NMTS key, and it opens
363
- nothing on its own.
366
+ Until it is published nobody can send to you. `--publish` writes it. Every code derives from your
367
+ NMTS key at a number, so it cannot be chosen; you hold one to three live ones, make the next with
368
+ `public-code new`, and revoke one with `public-code revoke <n>` — nobody can send to a revoked code,
369
+ and files already received with it stay. `share --as <n>` picks which code sends. A public code is
370
+ not your NMTS key, and it opens nothing on its own.
364
371
 
365
372
  `nmts shares --sent <path>` lists who one file was shared with — the recipient address, since when,
366
373
  and the share id `unshare` takes.
@@ -368,7 +375,7 @@ and the share id `unshare` takes.
368
375
  A share tells NMTS who shared with whom. A handover does not: `nmts handover make <path> --to
369
376
  <recipient>` writes the file, sealed to one recipient, into a handover file you pass on yourself,
370
377
  and no share is registered. The recipient opens it with `nmts handover open <file>`, which needs no
371
- API key and asks the NMTS server nothing. Give `--to` their public code file (`nmts public-code
378
+ API key and tells the NMTS server nothing about the file. Give `--to` their public code file (`nmts public-code
372
379
  --save` on their side) and the server is not even asked whose code it is; give it the code and the
373
380
  server sees that lookup. Whoever holds a handover file sees your public code in it. It cannot be
374
381
  taken back: the recipient can download the file until its storage ends or its stored bytes are
@@ -437,10 +444,11 @@ nmts openers remove <locator> # take one off
437
444
  ## What it stops to ask about
438
445
 
439
446
  Every act has a tier. **None** (listing, fetching, folders, marks) never asks. **Low** (the trash,
440
- a setting, a report) and **medium** (uploading, publishing the public code, a new key) ask once
441
- per run — y/N at the terminal, or `--yes`. **High** (signing with the wallet, giving another
447
+ a setting, a report) and **medium** (uploading, publishing or making a public code, a new key) ask
448
+ once per run — y/N at the terminal, or `--yes`. **High** (signing with the wallet, giving another
442
449
  account a file, revealing or storing your NMTS key unsealed) is locked until you run `nmts unlock
443
- <key>` once on this machine, and then still asks on every run. **Ultra-high** (erasing the
450
+ <key>` once on this machine, and then still asks on every run; revoking a public code is high too,
451
+ with no unlock, and asks every time. **Ultra-high** (erasing the
444
452
  account) is a typed sentence. `nmts unlock` lists the keys; each unlock prints what it opens, what
445
453
  could go wrong and what it does not cover before it asks. `nmts help <command>` prints any
446
454
  command's document, with its tier at the top.
@@ -542,14 +550,14 @@ the arguments `mcp --out <directory>`, for example in opencode's own file:
542
550
  { "mcp": { "nmts": { "type": "local", "command": ["nmts", "mcp", "--out", "/where/files/should/land"] } } }
543
551
  ```
544
552
 
545
- It offers thirty-eight tools: reading the account (`nmts_whoami`, `nmts_list`, `nmts_usage`,
553
+ It offers forty tools: reading the account (`nmts_whoami`, `nmts_list`, `nmts_usage`,
546
554
  `nmts_expiring`, `nmts_balance`, `nmts_shares`, `nmts_shares_sent`), the wallet's own reads
547
555
  (`nmts_wallet_activity`, `nmts_wallet_storage`), the signed-in devices (`nmts_devices`), storage the daily check could
548
556
  not find (`nmts_losses`, `nmts_loss_recheck`), fetching (`nmts_get`, `nmts_pull`, `nmts_receive`),
549
557
  uploading (`nmts_put`, `nmts_push`, `nmts_padding`, `nmts_deposit`), rearranging (`nmts_mkdir`, `nmts_move`,
550
558
  `nmts_rename`, `nmts_mark`, `nmts_label_rename`, `nmts_unlabel_all`, `nmts_trash`, `nmts_restore`),
551
559
  moving credits between accounts of your own (`nmts_credits_transfer`),
552
- sharing (`nmts_public_code`, `nmts_share`, `nmts_unshare`), writing to the developer
560
+ sharing (`nmts_public_code`, `nmts_public_code_new`, `nmts_public_code_revoke`, `nmts_share`, `nmts_unshare`), writing to the developer
553
561
  (`nmts_support_send`, `nmts_support_list`, `nmts_support_show`, `nmts_support_reply`) and the
554
562
  documents this service publishes (`nmts_notices`, `nmts_notice`, `nmts_terms`, `nmts_privacy`).
555
563
 
@@ -34,8 +34,14 @@ export interface ParsedArgs {
34
34
  deposit?: string;
35
35
  /** Answer yes to a warning this run would otherwise stop on. */
36
36
  yes: boolean;
37
- /** `public-code`: publish this account's public code on the server. Permanent. */
37
+ /** `public-code`: publish this account's public code on the server. */
38
38
  publish: boolean;
39
+ /** `public-code list`: each code's shares as well as its counts. */
40
+ activity: boolean;
41
+ /** `public-code new`: the number of the live code the new one replaces, revoked in the same step. */
42
+ replace?: string;
43
+ /** `share`: which of this account's live public codes sends. Absent = the lowest-numbered live one. */
44
+ as?: string;
39
45
  /** `login`: store the NMTS key unsealed rather than under a passphrase. */
40
46
  plain: boolean;
41
47
  /** `login`: store nothing; print the environment variable to set. */
@@ -143,6 +149,10 @@ export interface ParsedArgs {
143
149
  dismiss?: string;
144
150
  /** `shares`: who ONE file was shared with, instead of what was shared with this account. */
145
151
  sent?: string;
152
+ /** `link make`: how long the link lasts, `<n>d` (1 to 3650 days). Absent = until it is cut. */
153
+ expires?: string;
154
+ /** `link make`: seal the size without the file's name, and the page shows 「Shared file」. */
155
+ hideName: boolean;
146
156
  /** ultra-high acts under skip-permissions: why this is right to do now. Kept in the run log. */
147
157
  reason?: string;
148
158
  releaseStorage: boolean;
package/dist/args.js CHANGED
@@ -41,6 +41,9 @@ const VALUE_OPTIONS = {
41
41
  "--recheck": "recheck",
42
42
  "--dismiss": "dismiss",
43
43
  "--sent": "sent",
44
+ "--expires": "expires",
45
+ "--replace": "replace",
46
+ "--as": "as",
44
47
  "--reason": "reason",
45
48
  "--size": "size",
46
49
  "--sign-out": "signOut",
@@ -103,6 +106,7 @@ const FLAG_OPTIONS = {
103
106
  "--yes": "yes",
104
107
  "-y": "yes",
105
108
  "--publish": "publish",
109
+ "--activity": "activity",
106
110
  "--plain": "plain",
107
111
  "--env": "env",
108
112
  "--status": "status",
@@ -120,6 +124,7 @@ const FLAG_OPTIONS = {
120
124
  "--accept-extremes": "acceptExtremes",
121
125
  "--trust-server-tip-address": "trustServerTipAddress",
122
126
  "--long": "long",
127
+ "--hide-name": "hideName",
123
128
  };
124
129
  // ⛔ Derived from the tables, not written again. A hand-kept list is how an option ends up tested
125
130
  // for one property and accepted with another. ⚠ Every option that carries a value is in here,
@@ -156,9 +161,10 @@ function append(parsed, field, value) {
156
161
  */
157
162
  const FLAG_DEFAULTS = {
158
163
  help: false, version: false, json: false, all: false, force: false, dryRun: false, thumbnail: false, releaseStorage: false,
159
- yes: false, publish: false, plain: false, env: false, status: false,
164
+ yes: false, publish: false, activity: false, plain: false, env: false, status: false,
160
165
  desc: false, hidden: false, reveal: false, phrase: false, print: false, qr: false, board: false,
161
166
  save: false, acceptExtremes: false, remove: false, noWait: false, trustServerTipAddress: false, long: false,
167
+ hideName: false,
162
168
  };
163
169
  export function parseArgs(argv) {
164
170
  const parsed = { command: null, operands: [], ...FLAG_DEFAULTS };
@@ -11,7 +11,7 @@ export declare const CRYPTO_SPEC_URL = "https://github.com/needmoretruth/nmts-re
11
11
  * is the field's own contract — what the writer says about itself — and a person holding two
12
12
  * copies of one account's artefacts can then tell which program made each.
13
13
  */
14
- export declare const WRITTEN_BY = "nmts-cli 0.46.0";
14
+ export declare const WRITTEN_BY = "nmts-cli 0.47.0";
15
15
  /** Which of the three artefacts a wrapper is. A reader holding several can sort them. */
16
16
  export type ArtifactKind = "recovery-list" | "file-list" | "recovery-kit";
17
17
  /**
package/dist/autonomy.js CHANGED
@@ -66,9 +66,9 @@ export function explain(mode) {
66
66
  `auto-low — ${MODE_MEANS["auto-low"]}`,
67
67
  `What happens: the agent runs reads, tidying and reversible changes without asking, and may run`,
68
68
  `medium acts — uploads that spend credits within the server's daily ceiling, making an API key,`,
69
- `publishing your public code — when it judges you asked for them or would want them. High acts`,
70
- `(sharing, wallet signing, signing devices out) are still asked about and stay locked until you`,
71
- `unlock them. Erasing the account or files is refused however it is asked.`,
69
+ `publishing or making a public code — when it judges you asked for them or would want them.`,
70
+ `High acts (sharing, wallet signing, signing devices out) are still asked about and stay locked`,
71
+ `until you unlock them. Erasing the account or files is refused however it is asked.`,
72
72
  `Risk: credits can be spent and metadata changed without a question each time. What you gain:`,
73
73
  `an agent that finishes a task instead of stopping at every step.`,
74
74
  off,
@@ -5,6 +5,8 @@ export interface HandoverOptions {
5
5
  to?: string | undefined;
6
6
  /** `make`: the handover file to write. `open`: the file to save the received file as. */
7
7
  out?: string | undefined;
8
+ /** `make`: the number of the live public code to send from. Default: the lowest-numbered live one. */
9
+ as?: string | undefined;
8
10
  force?: boolean;
9
11
  yes?: boolean;
10
12
  json?: boolean;
@@ -5,8 +5,15 @@
5
5
  // public code file — asks the server for the recipient's published identity, exactly as `share`
6
6
  // does. No share row is written: the handover is a file on this disk, passed on by the person.
7
7
  //
8
- // ⛔ OPEN asks the NMTS server nothing, and needs no API key: the file carries everything, the
9
- // NMTS key opens it, and the pieces come from Walrus aggregators.
8
+ // ⛔ OPEN needs no API key and tells the NMTS server nothing about the file or who sent it: the file
9
+ // carries everything, the NMTS key opens it, and the pieces come from Walrus aggregators. It asks
10
+ // the server two things at most, neither about this file: this account's own list of codes, only
11
+ // when code 0 did not open it and a key on this machine can read the list (which code to try
12
+ // next); and the public revoked list, one sixteenth at a time, never a single code
13
+ // (`revokedOnServer`). Offline, both are skipped and it still opens.
14
+ //
15
+ // ⛔ MAKE SENDS FROM A LIVE CODE of this account — the default, or `--as <n>` as `share` takes it —
16
+ // and refuses a recipient that is any code of this account, live or revoked.
10
17
  //
11
18
  // ⛔ A HANDOVER CANNOT BE TAKEN BACK. There is no row to delete. The recipient can download the file
12
19
  // until its storage ends or its stored bytes are destroyed; removing it from the drive (`rm`,
@@ -27,7 +34,8 @@ import { fileSink } from "../download-sink-node.js";
27
34
  import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
28
35
  import { NmtsError } from "../errors.js";
29
36
  import { isRecord } from "../guards.js";
30
- import { checkHandoverName, isHandoverNetwork, makeHandoverText, openHandoverText, readPublicCodeFileText } from "../handover.js";
37
+ import { checkHandoverName, finishHandover, isHandoverNetwork, makeHandoverText, readHandoverText, readPublicCodeFileText } from "../handover.js";
38
+ import { checkedKeys, isMine, openWithMyCodes, senderIndexOf } from "../handover-codes.js";
31
39
  import { readFileList } from "../manifest.js";
32
40
  import { resolveNetwork } from "../network.js";
33
41
  import { BINARY_NAME } from "../product.js";
@@ -35,7 +43,9 @@ import { destinationFor } from "../safe-path.js";
35
43
  import { resolveServer } from "../server.js";
36
44
  import { readCredentialsFile } from "../credentials.js";
37
45
  import { openSession } from "../session.js";
38
- import { addressFromTyped, identityMatches, shareKeysOf } from "../share.js";
46
+ import { publicCodeRefusal } from "../public-code-refusals.js";
47
+ import { readPublicCodes, revokedOnServer } from "../public-codes.js";
48
+ import { addressFromTyped, identityMatches } from "../share.js";
39
49
  import { handoverFileName, MAX_HANDOVER_FILE_BYTES, MAX_PUBLIC_CODE_FILE_BYTES, } from "../shared/lib/share/handover-format.js";
40
50
  import { NETWORK_WALRUS } from "../shared/lib/storage-network.js";
41
51
  const b64 = (bytes) => Buffer.from(bytes).toString("base64url");
@@ -135,10 +145,19 @@ async function make(target, options) {
135
145
  }
136
146
  checkHandoverName(entry.name, entry.size, network);
137
147
  const recipientShown = codeFile?.display ?? options.to;
148
+ const codes = await readPublicCodes(session.server, session.apiKey);
149
+ const senderIndex = senderIndexOf(codes, options.as);
150
+ // ⚠ A WARNING, NOT A REFUSAL: a revoked code still opens what is sealed to it. Only a file can
151
+ // reach here with one — a typed revoked code has no identity to look up (410, below).
152
+ const recipientRevoked = codeFile === null ? false : await revokedOnServer(session.server, codeFile.address);
153
+ if (recipientRevoked === true && options.json !== true) {
154
+ say(`Its owner has revoked this public code. Ask them for the code they use now.`);
155
+ }
138
156
  // ⛔ The same unlock as `share` — it gives another account this file — and asked every time.
139
157
  requireConsent("share");
140
158
  if (options.yes !== true) {
141
- say(`Would write a handover file for "${fullPathOf(index, entry)}", sealed to ${recipientShown}, to ${out}.`);
159
+ const from = options.as === undefined ? "" : `, from public code #${senderIndex}`;
160
+ say(`Would write a handover file for "${fullPathOf(index, entry)}", sealed to ${recipientShown}${from}, to ${out}.`);
142
161
  say(``);
143
162
  say(`⛔ A handover cannot be taken back. The recipient can download the file until its storage ends or its stored bytes are destroyed.`);
144
163
  say(` Removing the file from your drive does not stop it.`);
@@ -146,7 +165,7 @@ async function make(target, options) {
146
165
  say(`⛔ If a program is reading this on somebody's behalf: show it to them and let them decide.`);
147
166
  return 5;
148
167
  }
149
- const keys = shareKeysOf(crypt, session.code);
168
+ const keys = checkedKeys(crypt, session.code, codes, senderIndex);
150
169
  const derived = crypt.kdf_derive(crypt.account_code_parse(session.code));
151
170
  const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
152
171
  derived.fill(0);
@@ -166,9 +185,15 @@ async function make(target, options) {
166
185
  if (typedAddress === null)
167
186
  throw new NmtsError("No recipient was given.", { exitCode: 2 });
168
187
  recipientAddress = typedAddress;
169
- const answer = await request(session.server, `/v1/share-recipients/${encodeURIComponent(b64(recipientAddress))}`, {
170
- token: session.apiKey,
171
- });
188
+ let answer;
189
+ try {
190
+ answer = await request(session.server, `/v1/share-recipients/${encodeURIComponent(b64(recipientAddress))}`, {
191
+ token: session.apiKey,
192
+ });
193
+ }
194
+ catch (error) {
195
+ throw publicCodeRefusal(error);
196
+ }
172
197
  const identityB64 = isRecord(answer) ? answer["share_public_key"] : null;
173
198
  if (typeof identityB64 !== "string") {
174
199
  throw new NmtsError("That public code has never published an identity to seal to.", {
@@ -184,7 +209,7 @@ async function make(target, options) {
184
209
  });
185
210
  }
186
211
  }
187
- if (Buffer.from(recipientAddress).equals(Buffer.from(keys.address))) {
212
+ if (isMine(codes, keys, recipientAddress)) {
188
213
  throw new NmtsError("That is your own public code.", { exitCode: 2, nextStep: "Nothing was written." });
189
214
  }
190
215
  const parts = partsOf(await request(session.server, `/v1/items/${encodeURIComponent(entry.id)}/parts`, { token: session.apiKey }));
@@ -213,7 +238,7 @@ async function make(target, options) {
213
238
  }
214
239
  const shown = codeFile?.display ?? crypt.share_address_display(recipientAddress);
215
240
  if (options.json === true) {
216
- say(JSON.stringify({ out, name: entry.name, recipient: shown }));
241
+ say(JSON.stringify({ out, name: entry.name, recipient: shown, fromIndex: keys.index, recipientRevoked }));
217
242
  return 0;
218
243
  }
219
244
  say(`${entry.name} → ${shown}`);
@@ -238,6 +263,9 @@ function goAhead(target, options) {
238
263
  words.push("--out", JSON.stringify(options.out));
239
264
  if (options.force === true)
240
265
  words.push("--force");
266
+ // ⚠ Already read as a number before the review is printed, so it is digits.
267
+ if (options.as !== undefined)
268
+ words.push("--as", options.as.trim());
241
269
  if (options.server !== undefined)
242
270
  words.push("--server", JSON.stringify(options.server));
243
271
  if (options.network !== undefined)
@@ -288,12 +316,14 @@ async function open(file, options) {
288
316
  // NMTS key (to open the file) and the network (which aggregators to ask) are needed.
289
317
  const code = await requireAccountCode();
290
318
  const stored = readCredentialsFile();
291
- const chain = resolveNetwork(resolveServer(options.server ?? stored?.server), options.network ?? stored?.network);
319
+ const server = resolveServer(options.server ?? stored?.server);
320
+ const chain = resolveNetwork(server, options.network ?? stored?.network);
292
321
  const crypt = await loadCrypto();
293
- const keys = shareKeysOf(crypt, code.code);
322
+ const sealed = readHandoverText(crypt, text, networkOf(chain));
323
+ const found = await openWithMyCodes(crypt, code.code, sealed.sealed, server);
294
324
  let opened = null;
295
325
  try {
296
- opened = openHandoverText(crypt, keys, text, networkOf(chain));
326
+ opened = finishHandover(crypt, sealed, found.dek);
297
327
  // ⛔ The name is the SENDER'S choice: only its last segment, in the current directory.
298
328
  const destination = options.out !== undefined ? resolve(options.out) : destinationFor(".", opened.name);
299
329
  const parts = opened.parts.map((p, i) => ({
@@ -311,18 +341,36 @@ async function open(file, options) {
311
341
  chain,
312
342
  sink: fileSink(destination, { force: options.force === true }),
313
343
  });
344
+ // ⛔ Both by bucket, never by code; null (offline, refused) says nothing.
345
+ const buckets = new Map();
346
+ const toRevoked = found.revoked ?? (await revokedOnServer(server, found.address, buckets));
347
+ const senderRevoked = await revokedOnServer(server, opened.senderAddress, buckets);
314
348
  if (options.json === true) {
315
- say(JSON.stringify({ name: opened.name, bytes: fetched.byteCount, from: opened.sender, out: destination, expiryEpoch: opened.expiryEpoch }));
349
+ say(JSON.stringify({
350
+ name: opened.name,
351
+ bytes: fetched.byteCount,
352
+ from: opened.sender,
353
+ out: destination,
354
+ expiryEpoch: opened.expiryEpoch,
355
+ toIndex: found.index,
356
+ toRevoked,
357
+ senderRevoked,
358
+ }));
316
359
  return 0;
317
360
  }
318
361
  say(`${opened.name} ${fetched.byteCount} bytes`);
319
362
  say(` from ${opened.sender}`);
363
+ if (senderRevoked === true)
364
+ say(` The sender has since revoked this code.`);
365
+ if (toRevoked === true)
366
+ say(` received with your revoked public code #${found.index} ${found.display}`);
367
+ else if (found.index !== 0)
368
+ say(` to #${found.index} ${found.display}`);
320
369
  say(` saved to ${destination}, checked against the hash the sender sealed with it`);
321
370
  return 0;
322
371
  }
323
372
  finally {
324
- opened?.dek.fill(0);
373
+ found.dek.fill(0);
325
374
  opened?.digest.fill(0);
326
- keys.wipe();
327
375
  }
328
376
  }
@@ -0,0 +1,12 @@
1
+ export interface LinkOptions {
2
+ server?: string | undefined;
3
+ network?: string | undefined;
4
+ hideName?: boolean;
5
+ /** `<n>d`. */
6
+ expires?: string | undefined;
7
+ out?: string | undefined;
8
+ force?: boolean;
9
+ json?: boolean;
10
+ write?: (line: string) => void;
11
+ }
12
+ export declare function link(sub: string | undefined, operand: string | undefined, options?: LinkOptions): Promise<number>;
@@ -0,0 +1,121 @@
1
+ // `nmts link make|list|revoke|open` — public links (NCF-3 §5.8). The work is in
2
+ // `../links.ts`, which the SDK calls too; this file is the terminal around it.
3
+ //
4
+ // ⛔ `open` NEEDS NO LOGIN. It reads the link, asks the server for the token only, and writes one file
5
+ // here — the name the owner showed (its last segment), or `nmts-link-<token>` when it was hidden.
6
+ //
7
+ // ⛔ `make` sits behind the `share` unlock (`risk.ts`), because it gives the file to whoever holds the
8
+ // link. The gate asks for the yes; the trade-off line is what it shows.
9
+ //
10
+ import { resolve } from "node:path";
11
+ import { fileSink } from "../download-sink-node.js";
12
+ import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
13
+ import { NmtsError } from "../errors.js";
14
+ import { listLinks, makeLink, openLink, revokeLink } from "../links.js";
15
+ import { readFileList } from "../manifest.js";
16
+ import { resolveNetwork } from "../network.js";
17
+ import { BINARY_NAME } from "../product.js";
18
+ import { readCredentialsFile } from "../credentials.js";
19
+ import { destinationFor } from "../safe-path.js";
20
+ import { resolveServer } from "../server.js";
21
+ import { openSession } from "../session.js";
22
+ import { linkExpiryDays } from "../shared/lib/share/public-link.js";
23
+ const USAGE = `\`${BINARY_NAME} link make <path> [--hide-name] [--expires <n>d]\` · \`${BINARY_NAME} link list <path>\` · ` +
24
+ `\`${BINARY_NAME} link revoke <id>\` · \`${BINARY_NAME} link open <link> [--out <path>]\``;
25
+ export async function link(sub, operand, options = {}) {
26
+ const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
27
+ if (sub !== "make" && sub !== "list" && sub !== "revoke" && sub !== "open") {
28
+ throw new NmtsError("Say `make`, `list`, `revoke` or `open`.", { exitCode: 2, nextStep: USAGE });
29
+ }
30
+ if (operand === undefined || operand === "") {
31
+ throw new NmtsError(`Say which ${sub === "revoke" ? "link id" : sub === "open" ? "link" : "file"}.`, {
32
+ exitCode: 2,
33
+ nextStep: USAGE,
34
+ });
35
+ }
36
+ if (sub === "open")
37
+ return await open(operand, options, say);
38
+ if (sub === "revoke") {
39
+ const session = await openSession({ server: options.server, network: options.network });
40
+ await revokeLink(accountOf(session), operand);
41
+ say(options.json === true ? JSON.stringify({ id: operand, cut: true }) : `${operand} cut`);
42
+ return 0;
43
+ }
44
+ const session = await openSession({ server: options.server, network: options.network });
45
+ const entry = await fileAt(session, operand);
46
+ if (sub === "list") {
47
+ const links = await listLinks(accountOf(session), entry.id);
48
+ if (options.json === true) {
49
+ say(JSON.stringify({ path: operand, links }));
50
+ return 0;
51
+ }
52
+ for (const row of links) {
53
+ const state = row.cutAt === null ? `downloads ${row.downloads}` : `cut ${row.cutAt} by ${row.cutBy ?? "?"}`;
54
+ say(`${row.id} made ${row.createdAt} ${state}`);
55
+ if (row.link !== null)
56
+ say(` ${row.link}`);
57
+ }
58
+ return 0;
59
+ }
60
+ const days = expiryOf(options.expires);
61
+ const made = await makeLink(accountOf(session), entry, { showName: options.hideName !== true, expiresDays: days });
62
+ if (options.json === true) {
63
+ say(JSON.stringify(made));
64
+ return 0;
65
+ }
66
+ say(made.link);
67
+ say(` id ${made.id}${made.expiresAt === null ? "" : ` expires ${made.expiresAt}`}`);
68
+ return 0;
69
+ }
70
+ /** `30d` → 30. Absent → never. */
71
+ function expiryOf(value) {
72
+ if (value === undefined)
73
+ return null;
74
+ const match = /^([0-9]+)d$/u.exec(value.trim());
75
+ const days = match?.[1] === undefined ? null : linkExpiryDays(Number(match[1]));
76
+ if (days === null) {
77
+ throw new NmtsError(`--expires takes a number of days, like 30d, from 1d to 3650d.`, { exitCode: 2, nextStep: USAGE });
78
+ }
79
+ return days;
80
+ }
81
+ function accountOf(session) {
82
+ return { server: session.server, bearer: session.apiKey, code: session.code };
83
+ }
84
+ async function fileAt(session, target) {
85
+ const list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
86
+ if (list.manifest === null) {
87
+ throw new NmtsError("This account has no file list, so there is nothing to link.", { exitCode: 4 });
88
+ }
89
+ const entry = entryAt(list.manifest.entries, normalisePath(target), { nothingHappened: "Nothing was changed." });
90
+ if (entry.kind !== KIND_FILE) {
91
+ throw new NmtsError(`No file at "${fullPathOf(buildIndex(list.manifest.entries), entry)}".`, {
92
+ exitCode: 4,
93
+ nextStep: "That is a folder, and a link is to one file.",
94
+ });
95
+ }
96
+ return entry;
97
+ }
98
+ async function open(text, options, say) {
99
+ // ⛔ No session: a link is opened by whoever holds it. Only where to ask and which network to read.
100
+ const stored = readCredentialsFile();
101
+ const server = resolveServer(options.server ?? stored?.server);
102
+ const chain = resolveNetwork(server, options.network ?? stored?.network);
103
+ let destination = "";
104
+ const opened = await openLink({
105
+ link: text,
106
+ server,
107
+ chain,
108
+ sink: (name) => {
109
+ const token = /\/l\/([A-Za-z0-9_-]{22})/u.exec(text)?.[1] ?? "file";
110
+ destination = options.out !== undefined ? resolve(options.out) : destinationFor(".", name ?? `nmts-link-${token}`);
111
+ return fileSink(destination, { force: options.force === true });
112
+ },
113
+ });
114
+ if (options.json === true) {
115
+ say(JSON.stringify({ name: opened.name, bytes: opened.bytes, out: destination }));
116
+ return 0;
117
+ }
118
+ say(`${opened.name ?? "(name hidden)"} ${opened.bytes} bytes`);
119
+ say(` saved to ${destination}, checked against the hash the owner sealed with it`);
120
+ return 0;
121
+ }
@@ -0,0 +1,24 @@
1
+ import { type CryptoGlue } from "../crypto.ts";
2
+ import { type PublicCodeRow } from "../public-codes.ts";
3
+ export interface PublicCodeManageOptions {
4
+ server?: string | undefined;
5
+ network?: string | undefined;
6
+ json?: boolean;
7
+ /** The person's yes to a revoke, or the one the tier gate already took. */
8
+ yes?: boolean;
9
+ /** `list`: each code's shares as well as its counts. */
10
+ activity?: boolean;
11
+ /** `new`: the number of the live code the new one replaces. */
12
+ replace?: string | undefined;
13
+ write?: (line: string) => void;
14
+ /** Injected in tests: answers the revoke question. */
15
+ readLine?: ((question: string) => Promise<string>) | undefined;
16
+ }
17
+ /** The code this key derives at `row`'s number, as a person reads it — or `differentCode` when the server's differs. */
18
+ export declare function checkedDisplay(crypt: CryptoGlue, code: string, row: PublicCodeRow): string;
19
+ /** `nmts public-code list [--activity]` — every code, live ones first, and the two ceilings. */
20
+ export declare function listCodes(options?: PublicCodeManageOptions): Promise<number>;
21
+ /** `nmts public-code new [--replace <n>]` — the next number, published; with --replace, that code revoked in the same request. */
22
+ export declare function newCode(options?: PublicCodeManageOptions): Promise<number>;
23
+ /** `nmts public-code revoke <n>` — one way, and never the last live code. */
24
+ export declare function revokeCodeCommand(operand: string | undefined, options?: PublicCodeManageOptions): Promise<number>;