@needmoretruth/nmts-cli 0.40.0 → 0.41.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 (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.ko.md +27 -1
  3. package/README.md +29 -1
  4. package/dist/api-advice.js +6 -0
  5. package/dist/api.d.ts +10 -1
  6. package/dist/api.js +12 -2
  7. package/dist/arg-options.d.ts +21 -0
  8. package/dist/args.js +12 -1
  9. package/dist/artifact-about.d.ts +1 -1
  10. package/dist/commands/create-link.d.ts +9 -0
  11. package/dist/commands/create-link.js +31 -1
  12. package/dist/commands/create.d.ts +9 -0
  13. package/dist/commands/create.js +17 -0
  14. package/dist/commands/login-passphrase.d.ts +13 -0
  15. package/dist/commands/login-passphrase.js +64 -0
  16. package/dist/commands/login.d.ts +3 -0
  17. package/dist/commands/login.js +15 -55
  18. package/dist/commands/openers-attach.d.ts +38 -0
  19. package/dist/commands/openers-attach.js +97 -0
  20. package/dist/commands/openers.d.ts +23 -0
  21. package/dist/commands/openers.js +195 -0
  22. package/dist/crypto-surface.d.ts +28 -0
  23. package/dist/crypto-surface.js +7 -0
  24. package/dist/help.js +15 -0
  25. package/dist/main.js +11 -12
  26. package/dist/openers/doors.d.ts +65 -0
  27. package/dist/openers/doors.js +97 -0
  28. package/dist/openers/hints.d.ts +22 -0
  29. package/dist/openers/hints.js +11 -0
  30. package/dist/openers/sign.d.ts +56 -0
  31. package/dist/openers/sign.js +202 -0
  32. package/dist/openers/wallet.d.ts +71 -0
  33. package/dist/openers/wallet.js +210 -0
  34. package/dist/openers-key-file.d.ts +14 -0
  35. package/dist/openers-key-file.js +99 -0
  36. package/dist/openers.d.ts +7 -0
  37. package/dist/openers.js +21 -0
  38. package/dist/product.d.ts +1 -1
  39. package/dist/product.js +1 -1
  40. package/dist/risk.d.ts +11 -0
  41. package/dist/risk.js +15 -0
  42. package/docs/commands/openers.md +31 -0
  43. package/package.json +5 -1
  44. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +54 -0
  45. package/vendor/nmts-crypto/nmts_crypto_wasm.js +108 -0
  46. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  47. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +4 -0
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.41.0 — 2026-09-20
7
+
8
+ - **Wallet login.** `nmts login --wallet --sui-key-file <file>` signs in with a Sui wallet, and
9
+ `nmts create --wallet …` makes an account and attaches the wallet to it. The account keeps its NMTS
10
+ key; a copy of it sits on the NMTS server, locked so that only the wallet's signature of one fixed
11
+ message opens it. `nmts openers`, `nmts openers add` and `nmts openers remove <locator>` list,
12
+ attach and take off the wallets that open an account. `--account <n>` and `--app <name>` are inside
13
+ the signed message. The wallet's key is never an option value.
14
+ - Attaching asks the wallet to sign twice and refuses unless the signatures match; a zkLogin, a
15
+ multi-signature and a passkey account are refused by name. An attached wallet opens every file in
16
+ the account until it is removed, and removal counts from then on.
17
+ - One wallet and one account number open one account. A wallet that already opens an account under
18
+ that number is refused before anything is made or stored (`WALLET_OPENS_ANOTHER_ACCOUNT`), and
19
+ `--account <n>` picks another number.
20
+ - The library surface has a new entry, `@needmoretruth/nmts-cli/openers`.
21
+
6
22
  ## 0.40.0 — 2026-09-20
7
23
 
8
24
  - The library surface has a new entry, `@needmoretruth/nmts-cli/storage-control`: what `nmts extend`
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.40.0 # 버전을 고정할 때
53
+ npm install -g github:needmoretruth/nmts-cli#v0.41.0 # 버전을 고정할 때
54
54
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
55
55
  ```
56
56
 
@@ -374,6 +374,32 @@ nmts verify # 계정 주인이 nmts.me에 칠 짧은 코드를 찍고
374
374
  도구도 에이전트도 이 확인을 대신 지날 수 없습니다. 며칠이 아니라 확인이 **끝나는 시각**을 찍는
375
375
  이유는, 그 창이 서버 자신의 주 단위 경계에서 닫히기 때문입니다.
376
376
 
377
+ ## 지갑 로그인
378
+
379
+ 계정을 Sui 지갑으로도 엽니다. 계정에는 NMTS 키가 그대로 있고, 지갑 로그인은 그 키의 사본을 NMTS
380
+ 서버에 둡니다. 사본은 정해진 문장에 대한 그 지갑의 서명으로만 열리도록 잠겨 있습니다. NMTS는 사본을
381
+ 열지 못하고 어느 지갑의 것인지도 알지 못합니다.
382
+
383
+ ```sh
384
+ nmts create --wallet --sui-key-file ~/.sui/agent.key # 새 계정을 만들고 이 지갑을 붙입니다
385
+ nmts login --wallet --sui-key-file ~/.sui/agent.key # 로그인합니다. 아무것도 입력하지 않습니다
386
+ nmts openers # 이 계정을 여는 지갑 목록
387
+ nmts openers add --sui-key-file ~/.sui/other.key # 지갑을 하나 더 붙입니다
388
+ nmts openers remove <locator> # 지갑 하나를 뗍니다
389
+ ```
390
+
391
+ - 키 파일에는 `suiprivkey1…` 한 줄이 들어 있습니다. 지갑의 키는 옵션 값으로 받지 않고 화면에 찍지
392
+ 않습니다.
393
+ - `--account <n>`(기본 1)은 그 지갑의 몇 번째 계정인지를, `--app <이름>`은 한 제품에서만 쓰는 키를
394
+ 고릅니다. 둘 다 서명하는 문장 안에 있어서, 값이 다르면 서명도 계정도 다릅니다.
395
+ - 지갑을 붙일 때 서명을 두 번 받아 두 서명의 바이트가 같아야 붙입니다. 같은 문장에 매번 다르게
396
+ 서명하는 지갑(zkLogin 계정 · 다중 서명 계정 · 패스키 계정)은 각각의 코드로 거절합니다.
397
+ - 붙인 지갑을 가진 사람은 떼기 전까지 이 계정의 모든 파일을 엽니다. 떼면 그때부터 열지 못합니다.
398
+ 다만 전에 계정을 연 적이 있는 지갑은 NMTS 키를 알고 있을 수 있습니다.
399
+ - NMTS 키는 보관하십시오. 지갑을 잃거나 지갑의 서명 방식이 바뀌어도 그 키로 계정이 열립니다.
400
+
401
+ 긴 설명은 `nmts help openers`에 있습니다.
402
+
377
403
  ## 멈춰 서서 묻는 것
378
404
 
379
405
  행위마다 등급이 있습니다. **none**(목록·받기·폴더·표시)은 묻지 않습니다. **low**(휴지통·설정·문의)와
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.40.0 # a pinned version
54
+ npm install -g github:needmoretruth/nmts-cli#v0.41.0 # a pinned version
55
55
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
56
56
  ```
57
57
 
@@ -394,6 +394,34 @@ nmts verify # prints a short code for the account holder to type at n
394
394
  Neither the tool nor an agent can pass the check. It prints the moment the check ends rather than
395
395
  a number of days, because the window ends on a boundary of the server's own weeks.
396
396
 
397
+ ## Wallet login
398
+
399
+ An account can also be opened by a Sui wallet. The account keeps its NMTS key; wallet login puts a
400
+ copy of that key on the NMTS server, locked so that only the wallet's signature of one fixed message
401
+ opens it. NMTS cannot open the copy and does not learn which wallet it belongs to.
402
+
403
+ ```sh
404
+ nmts create --wallet --sui-key-file ~/.sui/agent.key # a new account, and this wallet opens it
405
+ nmts login --wallet --sui-key-file ~/.sui/agent.key # sign in: nothing is typed
406
+ nmts openers # the wallets that open this account
407
+ nmts openers add --sui-key-file ~/.sui/other.key # attach another
408
+ nmts openers remove <locator> # take one off
409
+ ```
410
+
411
+ - The key file holds one `suiprivkey1…` line. The wallet's key is never an option value and is never
412
+ printed.
413
+ - `--account <n>` (default 1) picks which of that wallet's accounts, and `--app <name>` makes a key
414
+ for one product only. Both are inside the signed message, so another value is another signature
415
+ and another account.
416
+ - Attaching asks the wallet to sign twice and refuses unless the two signatures are the same bytes.
417
+ A wallet that signs the same message differently each time — a zkLogin account, a multi-signature
418
+ account, a passkey account — is refused with a code of its own.
419
+ - Whoever holds an attached wallet can open every file in the account until it is removed. Removing
420
+ stops it from then on; a wallet that opened the account before has held the NMTS key.
421
+ - Keep the NMTS key. It opens the account if the wallet is lost or starts signing differently.
422
+
423
+ `nmts help openers` has the long form.
424
+
397
425
  ## What it stops to ask about
398
426
 
399
427
  Every act has a tier. **None** (listing, fetching, folders, marks) never asks. **Low** (the trash,
@@ -87,6 +87,12 @@ export function adviseFor(code) {
87
87
  case "API_KEY_CAP":
88
88
  return ("The account holds as many live keys as it is allowed. Nothing here can raise the limit: " +
89
89
  "the person has to revoke a key they no longer use, on the account screen at nmts.me.");
90
+ // Copy facts — the sentence. Facts it has to carry: an account holds a fixed number of openers
91
+ // at most; the refusal itself names the cap and how many are live; nothing on this side raises
92
+ // it; `nmts openers` lists them and `nmts openers remove <locator>` frees a place.
93
+ case "OPENER_CAP":
94
+ return ("This account already has as many wallets attached as it may. Nothing here can raise that: list " +
95
+ "them with `nmts openers` and remove one that is no longer used, then add this one.");
90
96
  case "API_KEY_CHANNEL":
91
97
  return ("This account is enrolled on a preview build, and keys are not issued while it is. Ask " +
92
98
  "the person to leave the preview on the account screen, then make the key.");
package/dist/api.d.ts CHANGED
@@ -98,8 +98,14 @@ export interface RequestOptions {
98
98
  * reading. Two of those going out of step is not hypothetical here: `check:cli-routes` exists
99
99
  * because a command once called an address the server did not have, and it can only see
100
100
  * calls that come through this function.
101
+ *
102
+ * ⛔ `bytes` IS THAT SAME OPTION FOR THE ONE ROUTE THAT ANSWERS OPAQUE BYTES — the sealed opener
103
+ * slot (`GET /v1/opener/{locator}`), which is ciphertext on its way into a crypto boundary.
104
+ * Read as text it would go through a UTF-8 decoder, which silently replaces whatever is not
105
+ * valid: the slot would arrive altered and present as "this signature does not open this
106
+ * slot", which is the one refusal that must mean what it says.
101
107
  */
102
- as?: "text";
108
+ as?: "text" | "bytes";
103
109
  }
104
110
  /**
105
111
  * One request to the NMTS server, returning parsed JSON or throwing a named refusal.
@@ -111,4 +117,7 @@ export interface RequestOptions {
111
117
  export declare function request(base: string, path: string, options: RequestOptions & {
112
118
  as: "text";
113
119
  }): Promise<TextAnswer>;
120
+ export declare function request(base: string, path: string, options: RequestOptions & {
121
+ as: "bytes";
122
+ }): Promise<Uint8Array>;
114
123
  export declare function request(base: string, path: string, options?: RequestOptions): Promise<unknown>;
package/dist/api.js CHANGED
@@ -84,7 +84,12 @@ async function once(base, path, options) {
84
84
  if (options.signal)
85
85
  options.signal.addEventListener("abort", () => controller.abort(), { once: true });
86
86
  const headers = {
87
- accept: options.as === "text" ? "text/plain, text/markdown, */*" : "application/json",
87
+ // ⚠ A refusal is JSON whatever was asked for, which is why it is named on every branch.
88
+ accept: options.as === "text"
89
+ ? "text/plain, text/markdown, */*"
90
+ : options.as === "bytes"
91
+ ? "application/octet-stream, application/json"
92
+ : "application/json",
88
93
  };
89
94
  if (body !== undefined)
90
95
  headers["content-type"] = "application/json";
@@ -120,7 +125,10 @@ async function once(base, path, options) {
120
125
  finally {
121
126
  clearTimeout(deadline);
122
127
  }
123
- const text = await response.text();
128
+ // ⛔ THE ANSWER IS TAKEN AS BYTES ONLY WHERE BYTES WERE ASKED FOR, and even there a REFUSAL is
129
+ // decoded and read as JSON below: the server answers one of those however the request asked.
130
+ const raw = options.as === "bytes" ? new Uint8Array(await response.arrayBuffer()) : null;
131
+ const text = raw === null ? await response.text() : response.ok ? "" : new TextDecoder().decode(raw);
124
132
  // ⛔ A TEXT ANSWER IS ONLY TEXT WHEN THE SERVER AGREED. A refusal is JSON however the request
125
133
  // asked, so a failing document fetch still goes through the reading below and still reaches
126
134
  // the caller as a named refusal rather than as a page of HTML pretending to be a notice.
@@ -148,6 +156,8 @@ async function once(base, path, options) {
148
156
  }
149
157
  throw new HttpError(response.status, `${base} answered ${response.status}.`);
150
158
  }
159
+ if (raw !== null)
160
+ return raw;
151
161
  if (asText)
152
162
  return { text, filename: filenameFrom(response.headers.get("content-disposition")) };
153
163
  return parsed;
@@ -73,6 +73,23 @@ export interface ParsedArgs {
73
73
  acceptExtremes: boolean;
74
74
  /** `wallet address`: which of this key's wallets to print. Absent = the first one, offline. */
75
75
  index?: string;
76
+ /**
77
+ * `login`/`create`/`openers add`: the file holding the wallet's `suiprivkey1…` line.
78
+ *
79
+ * ⛔ A PATH AND NEVER THE KEY. A secret on a command line is readable by any process on the
80
+ * machine and is recorded by the shell — the rule this file opens with. The file is read,
81
+ * used to sign one message, and never copied or printed.
82
+ */
83
+ suiKeyFile?: string;
84
+ /** `login`/`create`/`openers add`: which of that wallet's NMTS accounts. Whole, from 1. */
85
+ account?: string;
86
+ /**
87
+ * `login`/`create`/`openers add`: a product scope for the wallet's signature.
88
+ *
89
+ * ⚠ WITHOUT IT ONE WALLET OPENS THE SAME ACCOUNT EVERYWHERE, which is usually what somebody
90
+ * wants and is also the price: every product that gets this signature opens the same files.
91
+ */
92
+ app?: string;
76
93
  /**
77
94
  * `put`/`push`/`extend`/`wallet send`/`wallet donate`: which wallet pays, THIS RUN ONLY — and
78
95
  * `wallet swap`/`wallet storage split|merge|transfer`/`wallet hall --name`, which act on that
@@ -81,6 +98,10 @@ export interface ParsedArgs {
81
98
  * ⛔ IT DOES NOT SAVE. Which wallet pays is the account's own setting (`nmts wallet use N`), read
82
99
  * from the sealed file list so every device agrees; a flag that quietly rewrote it would make
83
100
  * one hurried command change where the money comes from for every later one, everywhere.
101
+ *
102
+ * ⚠ AND ON `login`/`create` IT CARRIES NO NUMBER: the bare `--wallet` says the NMTS key comes
103
+ * from a wallet's signature rather than from a person typing it. Absent is "no wallet was
104
+ * named"; `""` is the bare form.
84
105
  */
85
106
  wallet?: string;
86
107
  /** `s3`: which loopback port the gateway listens on. */
package/dist/args.js CHANGED
@@ -33,7 +33,6 @@ const VALUE_OPTIONS = {
33
33
  "--venue": "venue",
34
34
  "--slippage-bps": "slippageBps",
35
35
  "--index": "index",
36
- "--wallet": "wallet",
37
36
  "--port": "port",
38
37
  "--accept-terms": "acceptTerms",
39
38
  "--accept-privacy": "acceptPrivacy",
@@ -49,6 +48,12 @@ const VALUE_OPTIONS = {
49
48
  "--message": "message",
50
49
  "--message-file": "messageFile",
51
50
  "--lang": "lang",
51
+ // ⛔ A PATH, NEVER THE KEY ITSELF. `cli/test/args.test.ts` refuses option names that look like a
52
+ // credential and lists this one as the exception it is: what it names is a FILE, the shape
53
+ // this tool already recommends for every other secret (`NMTS_ACCOUNT_CODE_FILE`).
54
+ "--sui-key-file": "suiKeyFile",
55
+ "--account": "account",
56
+ "--app": "app",
52
57
  };
53
58
  /**
54
59
  * Which field an option that may be given more than once appends to.
@@ -69,6 +74,12 @@ const LIST_OPTIONS = {
69
74
  */
70
75
  const OPTIONAL_VALUE_OPTIONS = {
71
76
  "--attach-log": "attachLog",
77
+ // ⛔ IT MOVED HERE ON 2026-09-20, AND THE RULE ABOVE IS WHY IT COULD. Every value `--wallet` has
78
+ // ever taken is a wallet NUMBER, so "is it digits" answers the whole question — and
79
+ // `nmts login --wallet --sui-key-file …` needs the bare form, which a value option refuses as
80
+ // a missing value. The two readers of the field already treat `""` as "not given"
81
+ // (`wallet-pay-index.ts`, `commands/extend.ts`), which is what the bare form means to them.
82
+ "--wallet": "wallet",
72
83
  };
73
84
  /** Which field a flag sets to true. */
74
85
  const FLAG_OPTIONS = {
@@ -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.40.0";
14
+ export declare const WRITTEN_BY = "nmts-cli 0.41.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
  /**
@@ -1,3 +1,4 @@
1
+ import type { WalletOpener } from "../openers.ts";
1
2
  export interface CreateLinkOptions {
2
3
  server: string;
3
4
  network: string;
@@ -6,5 +7,13 @@ export interface CreateLinkOptions {
6
7
  /** Print the address and stop, instead of waiting for somebody to use it. */
7
8
  noWait?: boolean | undefined;
8
9
  write?: ((line: string) => void) | undefined;
10
+ /**
11
+ * `--wallet`: attach this wallet once a PERSON has finished the account in a browser.
12
+ *
13
+ * ⛔ THERE IS NOTHING TO ATTACH TO BEFORE THEN. The account does not exist while the address is
14
+ * unused, so this happens at the end of the wait — and a `--no-wait` run, which returns
15
+ * before a person has been, says so rather than attaching to nothing.
16
+ */
17
+ wallet?: WalletOpener | undefined;
9
18
  }
10
19
  export declare function createThroughLink(options: CreateLinkOptions): Promise<number>;
@@ -42,6 +42,13 @@ export async function createThroughLink(options) {
42
42
  const codeFile = codeFileTarget(options.out);
43
43
  if (options.json === true && codeFile === null)
44
44
  throw jsonNeedsAFile();
45
+ // ⛔ THE WALLET IS ASKED BEFORE ANY OF THIS IS SET IN MOTION — the same order `create.ts` keeps,
46
+ // and for the same reason: a wallet that already opens an account cannot be attached to the
47
+ // one this link would make, and nobody should be sent to a browser to find that out.
48
+ if (options.wallet !== undefined) {
49
+ const { refuseIfWalletIsTaken } = await import("./openers-attach.js");
50
+ await refuseIfWalletIsTaken(server, options.wallet);
51
+ }
45
52
  const puzzle = await askForWork(server);
46
53
  const code = await newAccountCode();
47
54
  const proof = await registrationProofOf(code);
@@ -63,7 +70,16 @@ export async function createThroughLink(options) {
63
70
  // machine-readable output is one object, and the address is worth nothing to the program
64
71
  // reading it until it has handed it to a person. `status_url` is how it finds out what
65
72
  // happened next.
66
- say(JSON.stringify({ url, expires_at: expiresAt, code_file: codeFile, status_url: statusUrl }));
73
+ // ⚠ `opener_attached` IS FALSE AND SAYS SO RATHER THAN BEING ABSENT. This path does not wait,
74
+ // so there is no account to attach a wallet to by the time it answers, and a program that
75
+ // asked for one has to be able to see that it did not happen.
76
+ say(JSON.stringify({
77
+ url,
78
+ expires_at: expiresAt,
79
+ code_file: codeFile,
80
+ status_url: statusUrl,
81
+ ...(options.wallet === undefined ? {} : { opener_attached: false }),
82
+ }));
67
83
  return 0;
68
84
  }
69
85
  sayTheAddress(say, url, expiresAt, server, network);
@@ -75,6 +91,13 @@ export async function createThroughLink(options) {
75
91
  say(` ${statusUrl}`);
76
92
  say(``);
77
93
  say(`It answers {"status":"pending"}, {"status":"done"} or {"status":"expired"}.`);
94
+ // Copy facts — Fact: a wallet cannot be attached to an account that does not exist yet, so this
95
+ // run did not attach one; `nmts openers add` does it once the account is there.
96
+ if (options.wallet !== undefined) {
97
+ say(``);
98
+ say(`The wallet was NOT attached: there is no account to attach it to until somebody uses that`);
99
+ say(`address. Run \`${BINARY_NAME} openers add --sui-key-file <file>\` once this account is signed in.`);
100
+ }
78
101
  sayWhereTheCodeIs(say, codeFile, code);
79
102
  return 0;
80
103
  }
@@ -86,6 +109,13 @@ export async function createThroughLink(options) {
86
109
  say(``);
87
110
  say(`Registered. The account exists now.`);
88
111
  sayWhereTheCodeIs(say, codeFile, code);
112
+ // ⛔ AFTER THE CODE IS OUT — `create.ts` says why that order is the whole of it: the account
113
+ // exists by now, and a failure attaching a wallet must not take the only copy of its NMTS key
114
+ // down with it.
115
+ if (options.wallet !== undefined) {
116
+ const { attachWalletToNewAccount, sayWalletAttached } = await import("./openers-attach.js");
117
+ sayWalletAttached(say, await attachWalletToNewAccount({ server, code, wallet: options.wallet }));
118
+ }
89
119
  sayWhatIsNext(say);
90
120
  return 0;
91
121
  }
@@ -1,3 +1,4 @@
1
+ import type { WalletOpener } from "../openers.ts";
1
2
  export interface CreateOptions {
2
3
  server?: string | undefined;
3
4
  network?: string | undefined;
@@ -15,6 +16,14 @@ export interface CreateOptions {
15
16
  * exists by the time that path prints anything.
16
17
  */
17
18
  noWait?: boolean | undefined;
19
+ /**
20
+ * `--wallet`: attach this wallet to the account once it exists, so it opens it from then on.
21
+ *
22
+ * ⛔ THE ROOT IS STILL A RANDOM NMTS KEY — the account is made exactly as it is without this,
23
+ * and the wallet becomes a second way in rather than the account's origin. That is what lets
24
+ * the wallet be swapped, added to or removed later.
25
+ */
26
+ wallet?: WalletOpener | undefined;
18
27
  write?: (line: string) => void;
19
28
  }
20
29
  export declare function create(options?: CreateOptions): Promise<number>;
@@ -49,6 +49,7 @@ import { BINARY_NAME, HOME_URL } from "../product.js";
49
49
  import { newAccountCode, registrationProofOf } from "../registration.js";
50
50
  import { resolveServer } from "../server.js";
51
51
  import { codeFileTarget, jsonNeedsAFile, writeCodeFile } from "./create-code-file.js";
52
+ import { attachWalletToNewAccount, refuseIfWalletIsTaken, sayWalletAttached } from "./openers-attach.js";
52
53
  export async function create(options = {}) {
53
54
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
54
55
  const held = resolveApiKey();
@@ -71,6 +72,7 @@ export async function create(options = {}) {
71
72
  json: options.json === true,
72
73
  noWait: options.noWait,
73
74
  write: options.write,
75
+ wallet: options.wallet,
74
76
  });
75
77
  }
76
78
  const apiKey = held.key;
@@ -81,6 +83,11 @@ export async function create(options = {}) {
81
83
  throw jsonNeedsAFile();
82
84
  const inForce = await termsInForce(server, apiKey);
83
85
  const accepted = inForce === null ? null : acceptanceOffered(inForce, options);
86
+ // ⛔ THE WALLET IS ASKED BEFORE ANYTHING EXISTS. A wallet that already opens an account at this
87
+ // number cannot be attached to a second one, and learning that after the account was made
88
+ // would leave behind an account nobody asked for, with a key somebody now has to keep.
89
+ if (options.wallet !== undefined)
90
+ await refuseIfWalletIsTaken(server, options.wallet);
84
91
  const code = await newAccountCode();
85
92
  const proof = await registrationProofOf(code);
86
93
  // The file, then the account — see the header. Nothing below this line may fail without either
@@ -115,6 +122,9 @@ export async function create(options = {}) {
115
122
  }
116
123
  const createdAt = accountField(answer, "created_at");
117
124
  if (options.json === true && codeFile !== null) {
125
+ // ⚠ BEFORE THE ANSWER AND AFTER THE FILE, which is the safe order on this path: the code is
126
+ // already on disk, so an attach that fails loses nothing but the attach.
127
+ const attached = options.wallet === undefined ? null : await attachWalletToNewAccount({ server, code, wallet: options.wallet });
118
128
  // ⛔ NO `account_code` FIELD, AND THERE NEVER WILL BE. See the header.
119
129
  say(JSON.stringify({
120
130
  account_id: proof.accountId,
@@ -122,6 +132,7 @@ export async function create(options = {}) {
122
132
  code_file: codeFile,
123
133
  server,
124
134
  network,
135
+ ...(attached === null ? {} : { opener_locator: attached.locator, api_key_left: attached.keyLeft }),
125
136
  }));
126
137
  return 0;
127
138
  }
@@ -130,6 +141,12 @@ export async function create(options = {}) {
130
141
  sayTheCode(say, code);
131
142
  else
132
143
  sayWhereTheCodeWent(say, codeFile);
144
+ // ⛔ AFTER THE CODE IS OUT, AND THAT ORDER IS THE WHOLE OF IT. The account exists by now; a
145
+ // failure attaching the wallet must not be able to take the only copy of its NMTS key down
146
+ // with it, which is exactly what throwing before this printed would do.
147
+ if (options.wallet !== undefined) {
148
+ sayWalletAttached(say, await attachWalletToNewAccount({ server, code, wallet: options.wallet }));
149
+ }
133
150
  return 0;
134
151
  }
135
152
  /** What documents this server is enforcing, read from the one route a key may ask. */
@@ -0,0 +1,13 @@
1
+ /** What this needs of `login`'s options: the injected prompt, when a test supplies one. */
2
+ export interface PassphraseSource {
3
+ /** Injected in tests. Called twice for a new passphrase — the second is the confirmation. */
4
+ readPassphrase?: ((prompt: string) => Promise<string>) | undefined;
5
+ }
6
+ /**
7
+ * A passphrase for a NEW seal: from the environment, or typed twice.
8
+ *
9
+ * ⚠ The environment form is not confirmed, because there is nothing to confirm it against and
10
+ * asking would hang. A typo there produces a file whose passphrase nobody knows — which is why
11
+ * the message below says to keep it, not merely to choose it.
12
+ */
13
+ export declare function newPassphrase(options: PassphraseSource): Promise<string>;
@@ -0,0 +1,64 @@
1
+ // The passphrase a NEW seal is made under: where it comes from, and the two rules about it.
2
+ //
3
+ // ⛔ MOVED OUT OF `login.ts` RATHER THAN REWRITTEN (2026-09-20). Every line below was in that file
4
+ // and is unchanged; it moved because that file reached the length gate when wallet sign-in
5
+ // arrived, and this is where the seam already was: `login.ts` decides which of the three shapes
6
+ // the NMTS key is stored in and what a person is told, and this answers one question inside one
7
+ // of them. Nothing here reads the code, writes a file or talks to a server.
8
+ import { samePassphrase } from "../code-vault.js";
9
+ import { PASSPHRASE_ENV_VAR } from "../credentials.js";
10
+ import { NmtsError } from "../errors.js";
11
+ import { BINARY_NAME } from "../product.js";
12
+ import { promptSecret, stdinIsATerminal } from "../prompt.js";
13
+ /**
14
+ * ⚠ EIGHT, AND NO COMPOSITION RULES. scrypt makes a short passphrase expensive to attack, not
15
+ * safe: four characters is guessed whatever the cost factor. Requiring a digit and a capital
16
+ * would not change that and would push people to reuse the one they always type.
17
+ */
18
+ const MIN_PASSPHRASE = 8;
19
+ /**
20
+ * A passphrase for a NEW seal: from the environment, or typed twice.
21
+ *
22
+ * ⚠ The environment form is not confirmed, because there is nothing to confirm it against and
23
+ * asking would hang. A typo there produces a file whose passphrase nobody knows — which is why
24
+ * the message below says to keep it, not merely to choose it.
25
+ */
26
+ export async function newPassphrase(options) {
27
+ const ask = options.readPassphrase;
28
+ const fromEnv = process.env[PASSPHRASE_ENV_VAR];
29
+ if (ask === undefined && fromEnv !== undefined && fromEnv.length > 0) {
30
+ if (fromEnv.length < MIN_PASSPHRASE)
31
+ throw tooShort();
32
+ return fromEnv;
33
+ }
34
+ if (ask === undefined && !stdinIsATerminal()) {
35
+ throw new NmtsError("Sealing the NMTS key needs a passphrase, and there is no terminal.", {
36
+ exitCode: 2,
37
+ nextStep: [
38
+ `One of these:`,
39
+ ` · set ${PASSPHRASE_ENV_VAR} and run this again`,
40
+ ` · ${BINARY_NAME} login --plain store it unsealed (asks for an agreement first)`,
41
+ ` · ${BINARY_NAME} login --env store nothing; print the variable to set`,
42
+ ].join("\n"),
43
+ });
44
+ }
45
+ const prompt = ask ?? ((q) => promptSecret(q, PASSPHRASE_ENV_VAR));
46
+ const first = await prompt(`New passphrase for the stored NMTS key (not shown as you type): `);
47
+ if (first.length < MIN_PASSPHRASE)
48
+ throw tooShort();
49
+ const again = await prompt(`Type it again: `);
50
+ if (!samePassphrase(first, again)) {
51
+ throw new NmtsError("Those two passphrases are not the same.", {
52
+ exitCode: 2,
53
+ nextStep: `Nothing was written. Run \`${BINARY_NAME} login\` again.`,
54
+ });
55
+ }
56
+ return first;
57
+ }
58
+ function tooShort() {
59
+ return new NmtsError(`That passphrase is shorter than ${MIN_PASSPHRASE} characters.`, {
60
+ exitCode: 2,
61
+ nextStep: `Nothing was written. A short passphrase is guessed whatever the tool does to slow guessing ` +
62
+ `down. ⛔ If it is lost, the sealed copy cannot be opened by anybody — keep it somewhere.`,
63
+ });
64
+ }
@@ -1,3 +1,4 @@
1
+ import { type WalletOpener } from "../openers.ts";
1
2
  export interface LoginOptions {
2
3
  server?: string | undefined;
3
4
  network?: string | undefined;
@@ -5,6 +6,8 @@ export interface LoginOptions {
5
6
  plain?: boolean | undefined;
6
7
  /** Store nothing; print the environment variable to set. Behind `plain-env`. */
7
8
  env?: boolean | undefined;
9
+ /** `--wallet`: the NMTS key is opened by a wallet's signature instead of being typed. */
10
+ wallet?: WalletOpener | undefined;
8
11
  /** Injected in tests so the terminal is not involved. */
9
12
  readCode?: (() => Promise<string>) | undefined;
10
13
  /** Injected in tests. Called twice for a new passphrase — the second is the confirmation. */
@@ -27,22 +27,18 @@
27
27
  // to stop. What it can do is make the shape it writes ITSELF a decision.
28
28
  import { assertUsableCode } from "../account.js";
29
29
  import { keySourceName, keyToStore, settleApiKey } from "../api-key.js";
30
- import { lockCode, samePassphrase } from "../code-vault.js";
30
+ import { signInWithWallet } from "../openers.js";
31
+ import { lockCode } from "../code-vault.js";
31
32
  import { API_KEY_ENV_VAR, API_KEY_FILE_ENV_VAR, CODE_ENV_VAR, CODE_FILE_ENV_VAR, PASSPHRASE_ENV_VAR, codeStorageIsPrivate, credentialsPath, modesAreEnforced, readCredentialsFile, readSecretFile, writeCredentials, } from "../credentials.js";
32
33
  import { requireConsent } from "../consent.js";
33
34
  import { NmtsError } from "../errors.js";
34
35
  import { firstRunNotice } from "../notice.js";
36
+ import { newPassphrase } from "./login-passphrase.js";
35
37
  import { holdTerminal, promptSecret, stdinIsATerminal } from "../prompt.js";
36
38
  import { askAboutCollisions } from "../setup-questions.js";
37
39
  import { BINARY_NAME, HOME_URL } from "../product.js";
38
40
  import { resolveNetwork } from "../network.js";
39
41
  import { resolveServer } from "../server.js";
40
- /**
41
- * ⚠ EIGHT, AND NO COMPOSITION RULES. scrypt makes a short passphrase expensive to attack, not
42
- * safe: four characters is guessed whatever the cost factor. Requiring a digit and a capital
43
- * would not change that and would push people to reuse the one they always type.
44
- */
45
- const MIN_PASSPHRASE = 8;
46
42
  export async function login(options = {}) {
47
43
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
48
44
  const server = resolveServer(options.server);
@@ -62,7 +58,7 @@ export async function login(options = {}) {
62
58
  // line mode, where it echoes what is typed and swallows lines the next prompt never sees —
63
59
  // and this command asks up to three things with a check in the middle.
64
60
  const exit = await holdTerminal(async () => {
65
- const code = await readTheCode(options);
61
+ const code = await readTheCode(options, server);
66
62
  // ⛔ CHECKED BEFORE IT IS WRITTEN. The engine verifies the code's own check symbol offline, so
67
63
  // a mistyped code fails here as "that is not a code" instead of being stored and coming
68
64
  // back later as a sign-in failure indistinguishable from a wrong password or a suspended
@@ -108,7 +104,14 @@ export async function login(options = {}) {
108
104
  * ⚠ ORDER: a file first, because that is the shape this tool recommends and it asks for nothing;
109
105
  * then the environment, which asks once; then the terminal.
110
106
  */
111
- async function readTheCode(options) {
107
+ async function readTheCode(options, server) {
108
+ // ⛔ A WALLET ANSWERS THE CODE INSTEAD OF A PERSON TYPING IT, and nothing else about this command
109
+ // changes: what comes back is the account's own NMTS key, stored in whichever of the three
110
+ // shapes this run asked for. The sentences a wallet's refusal carries are `openers.ts`'s.
111
+ if (options.wallet !== undefined) {
112
+ const { OPENER_HINTS } = await import("./openers.js");
113
+ return (await signInWithWallet(server, options.wallet, OPENER_HINTS)).accountCode;
114
+ }
112
115
  const fromFile = readSecretFile(CODE_FILE_ENV_VAR);
113
116
  const fromEnv = process.env[CODE_ENV_VAR];
114
117
  if (options.readCode === undefined && fromFile === null && fromEnv !== undefined && fromEnv.length > 0) {
@@ -217,6 +220,9 @@ function printEnvForm(code, say) {
217
220
  * be checked by anybody, because the code never goes to the server. Saying the old sentence
218
221
  * after a key had just been accepted would have been the tool describing the world before it.
219
222
  */
223
+ // Copy facts — the wallet case has a sharper sentence available and does not have one yet. What is
224
+ // true after `--wallet`: a slot for this NMTS key was found on this server and opened, so something
225
+ // registered it — which is more than the check symbol says and less than "the account is live".
220
226
  function sayCheckSymbol(say, keyWasAccepted) {
221
227
  say(``);
222
228
  say(` The NMTS key is well-formed — its own check symbol matches. That was verified here, offline.`);
@@ -287,49 +293,3 @@ function sayAboutTheKey(outcome, server, say) {
287
293
  return;
288
294
  }
289
295
  }
290
- /**
291
- * A passphrase for a NEW seal: from the environment, or typed twice.
292
- *
293
- * ⚠ The environment form is not confirmed, because there is nothing to confirm it against and
294
- * asking would hang. A typo there produces a file whose passphrase nobody knows — which is why
295
- * the message below says to keep it, not merely to choose it.
296
- */
297
- async function newPassphrase(options) {
298
- const ask = options.readPassphrase;
299
- const fromEnv = process.env[PASSPHRASE_ENV_VAR];
300
- if (ask === undefined && fromEnv !== undefined && fromEnv.length > 0) {
301
- if (fromEnv.length < MIN_PASSPHRASE)
302
- throw tooShort();
303
- return fromEnv;
304
- }
305
- if (ask === undefined && !stdinIsATerminal()) {
306
- throw new NmtsError("Sealing the NMTS key needs a passphrase, and there is no terminal.", {
307
- exitCode: 2,
308
- nextStep: [
309
- `One of these:`,
310
- ` · set ${PASSPHRASE_ENV_VAR} and run this again`,
311
- ` · ${BINARY_NAME} login --plain store it unsealed (asks for an agreement first)`,
312
- ` · ${BINARY_NAME} login --env store nothing; print the variable to set`,
313
- ].join("\n"),
314
- });
315
- }
316
- const prompt = ask ?? ((q) => promptSecret(q, PASSPHRASE_ENV_VAR));
317
- const first = await prompt(`New passphrase for the stored NMTS key (not shown as you type): `);
318
- if (first.length < MIN_PASSPHRASE)
319
- throw tooShort();
320
- const again = await prompt(`Type it again: `);
321
- if (!samePassphrase(first, again)) {
322
- throw new NmtsError("Those two passphrases are not the same.", {
323
- exitCode: 2,
324
- nextStep: `Nothing was written. Run \`${BINARY_NAME} login\` again.`,
325
- });
326
- }
327
- return first;
328
- }
329
- function tooShort() {
330
- return new NmtsError(`That passphrase is shorter than ${MIN_PASSPHRASE} characters.`, {
331
- exitCode: 2,
332
- nextStep: `Nothing was written. A short passphrase is guessed whatever the tool does to slow guessing ` +
333
- `down. ⛔ If it is lost, the sealed copy cannot be opened by anybody — keep it somewhere.`,
334
- });
335
- }