@needmoretruth/nmts-cli 0.39.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 (65) hide show
  1. package/CHANGELOG.md +23 -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/extend.d.ts +3 -3
  15. package/dist/commands/extend.js +52 -161
  16. package/dist/commands/login-passphrase.d.ts +13 -0
  17. package/dist/commands/login-passphrase.js +64 -0
  18. package/dist/commands/login.d.ts +3 -0
  19. package/dist/commands/login.js +15 -55
  20. package/dist/commands/openers-attach.d.ts +38 -0
  21. package/dist/commands/openers-attach.js +97 -0
  22. package/dist/commands/openers.d.ts +23 -0
  23. package/dist/commands/openers.js +195 -0
  24. package/dist/commands/wallet-storage-ops.d.ts +2 -2
  25. package/dist/commands/wallet-storage-ops.js +108 -134
  26. package/dist/commands/wallet-storage.d.ts +3 -8
  27. package/dist/commands/wallet-storage.js +16 -37
  28. package/dist/crypto-surface.d.ts +28 -0
  29. package/dist/crypto-surface.js +7 -0
  30. package/dist/help.js +15 -0
  31. package/dist/main.js +11 -12
  32. package/dist/openers/doors.d.ts +65 -0
  33. package/dist/openers/doors.js +97 -0
  34. package/dist/openers/hints.d.ts +22 -0
  35. package/dist/openers/hints.js +11 -0
  36. package/dist/openers/sign.d.ts +56 -0
  37. package/dist/openers/sign.js +202 -0
  38. package/dist/openers/wallet.d.ts +71 -0
  39. package/dist/openers/wallet.js +210 -0
  40. package/dist/openers-key-file.d.ts +14 -0
  41. package/dist/openers-key-file.js +99 -0
  42. package/dist/openers.d.ts +7 -0
  43. package/dist/openers.js +21 -0
  44. package/dist/product.d.ts +1 -1
  45. package/dist/product.js +1 -1
  46. package/dist/risk.d.ts +11 -0
  47. package/dist/risk.js +15 -0
  48. package/dist/storage-control/extend.d.ts +124 -0
  49. package/dist/storage-control/extend.js +189 -0
  50. package/dist/storage-control/hints.d.ts +20 -0
  51. package/dist/storage-control/hints.js +11 -0
  52. package/dist/storage-control/list.d.ts +55 -0
  53. package/dist/storage-control/list.js +71 -0
  54. package/dist/storage-control/reshape.d.ts +120 -0
  55. package/dist/storage-control/reshape.js +188 -0
  56. package/dist/storage-control-chain.d.ts +1 -1
  57. package/dist/storage-control.d.ts +13 -0
  58. package/dist/storage-control.js +24 -0
  59. package/dist/wallet-storage-chain.d.ts +1 -1
  60. package/docs/commands/openers.md +31 -0
  61. package/package.json +9 -1
  62. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +54 -0
  63. package/vendor/nmts-crypto/nmts_crypto_wasm.js +108 -0
  64. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  65. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +4 -0
@@ -6,16 +6,16 @@
6
6
  // fusing and spending a resource need a signature and are not here.
7
7
  //
8
8
  // ⛔ "NONE" AND "COULD NOT READ" ARE DIFFERENT SENTENCES — holding no resource is normal; failing to
9
- // read is a reason to look again. The reader (`shared/lib/storage-control/chain.ts`, the
10
- // browser's own, copied byte-for-byte) throws rather than answering an empty list.
9
+ // read is a reason to look again. The reading, the ordering and that refusal are
10
+ // `storage-control.ts`, which the SDK calls as well; this file is the terminal over it.
11
11
  import { requireAccountCode } from "../code-access.js";
12
12
  import { readCredentialsFile } from "../credentials.js";
13
- import { NmtsError } from "../errors.js";
14
13
  import { resolveNetwork } from "../network.js";
15
14
  import { BINARY_NAME } from "../product.js";
15
+ import { formatBytes, listStorage, } from "../storage-control.js";
16
16
  import { resolveServer } from "../server.js";
17
- import { statusOf, totalUsableBytes, usableFirst } from "../shared/lib/storage-control/plan.js";
18
17
  import { walletAddress } from "../wallet.js";
18
+ export { formatBytes } from "../storage-control.js";
19
19
  export async function walletStorage(options = {}) {
20
20
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
21
21
  const resolved = await requireAccountCode();
@@ -23,33 +23,25 @@ export async function walletStorage(options = {}) {
23
23
  const stored = resolved.source === "file" || resolved.source === "file-locked" ? readCredentialsFile() : null;
24
24
  const server = resolveServer(options.server ?? stored?.server);
25
25
  const network = resolveNetwork(server, options.network ?? stored?.network);
26
- const read = options.readStorage ??
27
- (async (net, addr) => (await import("../wallet-storage-chain.js")).readWalletStorage(net, addr));
28
- let got;
29
- try {
30
- got = await read(network, address);
31
- }
32
- catch (error) {
33
- throw new NmtsError("The storage resources could not be read from the chain.", {
34
- exitCode: 1,
35
- nextStep: `That is not the same as holding none. \`${BINARY_NAME} env\` says which network was asked. ` +
36
- `Cause: ${error instanceof Error ? error.message : String(error)}`,
37
- });
38
- }
39
- const epoch = got.currentEpoch;
40
- const items = epoch === null ? [...got.items] : usableFirst(got.items, epoch);
26
+ // ⚠ THE SENTENCE A PERSON READS IS THIS FILE'S, not the library's: `nmts env` is a command at a
27
+ // prompt and means nothing inside somebody else's program.
28
+ const listed = await listStorage({ network, address }, options.readStorage, {
29
+ cannotRead: `That is not the same as holding none. \`${BINARY_NAME} env\` says which network was asked.`,
30
+ });
31
+ const epoch = listed.currentEpoch;
32
+ const items = listed.items;
41
33
  if (options.json) {
42
34
  say(JSON.stringify({
43
35
  address,
44
36
  network,
45
37
  currentEpoch: epoch,
46
- usableBytes: epoch === null ? null : totalUsableBytes(items, epoch),
38
+ usableBytes: listed.usableBytes,
47
39
  resources: items.map((r) => ({
48
40
  objectId: r.objectId,
49
41
  sizeBytes: r.sizeBytes,
50
42
  startEpoch: r.startEpoch,
51
43
  endEpoch: r.endEpoch,
52
- status: epoch === null ? null : statusOf(r, epoch),
44
+ status: r.status,
53
45
  })),
54
46
  }));
55
47
  return 0;
@@ -61,10 +53,10 @@ export async function walletStorage(options = {}) {
61
53
  say(` This wallet holds no free storage resource. Anything bound inside a file is not listed here.`);
62
54
  }
63
55
  else {
64
- if (epoch !== null)
65
- say(` ${formatBytes(totalUsableBytes(items, epoch))} usable now, in ${items.length} resource${items.length === 1 ? "" : "s"}.`);
56
+ if (listed.usableBytes !== null)
57
+ say(` ${formatBytes(listed.usableBytes)} usable now, in ${items.length} resource${items.length === 1 ? "" : "s"}.`);
66
58
  for (const r of items) {
67
- const status = epoch === null ? "" : ` ${statusWord(statusOf(r, epoch))}`;
59
+ const status = r.status === null ? "" : ` ${statusWord(r.status)}`;
68
60
  say(` ${formatBytes(r.sizeBytes).padStart(11)} · epoch ${r.startEpoch} to ${r.endEpoch}${status}`);
69
61
  say(` ${r.objectId}`);
70
62
  }
@@ -80,16 +72,3 @@ export async function walletStorage(options = {}) {
80
72
  function statusWord(status) {
81
73
  return status === "usable" ? "usable now" : status === "notYet" ? "not started" : "ended";
82
74
  }
83
- /** Bytes for a person: binary units, two decimals, whole bytes below a KiB. */
84
- export function formatBytes(bytes) {
85
- const units = ["KiB", "MiB", "GiB", "TiB"];
86
- let value = bytes;
87
- let unit = "B";
88
- for (const next of units) {
89
- if (value < 1024)
90
- break;
91
- value /= 1024;
92
- unit = next;
93
- }
94
- return unit === "B" ? `${bytes} B` : `${value.toFixed(2)} ${unit}`;
95
- }
@@ -175,6 +175,34 @@ export interface CryptoGlue {
175
175
  * ciphertext is fed in.
176
176
  */
177
177
  StreamDecryptor: new (dek: Uint8Array, header: Uint8Array) => StreamOpener;
178
+ /**
179
+ * The EXACT bytes a Sui wallet signs to open an account (NCF-3 §1.7).
180
+ *
181
+ * ⛔ BUILT IN THE ENGINE, NEVER IN TYPESCRIPT. The browser, this tool and the recovery tool must
182
+ * ask one wallet for one message: a character of drift between them is a different wrapping
183
+ * key, a different locator, and a slot that no longer opens. It throws for an address that is
184
+ * not `0x` and 64 LOWERCASE hex, for an account number below 1, and for an app label outside
185
+ * `a-z0-9.-` — and repairs none of them, because all three are inside what a person signs.
186
+ */
187
+ opener_message(address: string, account: number, app?: string): Uint8Array;
188
+ /**
189
+ * A serialized wallet signature to the 16-byte LOCATOR the server files that opener's slot under.
190
+ *
191
+ * ⛔ THESE THREE TAKE THE SIGNATURE AND NONE OF THEM RETURNS IT, or the wrapping key it expands
192
+ * to. Whoever holds either holds the account, so the boundary is shaped so that they cannot
193
+ * come back across it — a locator, a sealed slot and an opened NMTS key are what may travel.
194
+ */
195
+ opener_locator(serializedSignature: Uint8Array): Uint8Array;
196
+ /** A signature and the account's 20 key bytes to the 62-byte slot the server stores. Fresh nonce. */
197
+ opener_seal(serializedSignature: Uint8Array, nmtsKey: Uint8Array): Uint8Array;
198
+ /**
199
+ * A signature and a 62-byte slot to the 20 NMTS-key bytes inside it.
200
+ *
201
+ * ⚠ It throws by name for a wrong length or an unknown version, and with ONE indistinguishable
202
+ * message for a different wallet, a different message or altered bytes — telling those three
203
+ * apart would tell somebody holding a fetched slot whether their guess was getting warmer.
204
+ */
205
+ opener_open(serializedSignature: Uint8Array, slot: Uint8Array): Uint8Array;
178
206
  /**
179
207
  * The Ed25519 seed of wallet `index`, from the 32-byte wallet root (NCF-3 §1).
180
208
  *
@@ -29,6 +29,13 @@ const REQUIRED = [
29
29
  "stream_encrypt_all",
30
30
  "StreamEncryptor",
31
31
  "StreamDecryptor",
32
+ // The opener surface (NCF-3 §1.7). Required rather than optional: a build of the engine without
33
+ // it cannot sign anybody in with a wallet, and "this function is missing" said at load time is a
34
+ // different day's problem from `undefined is not a function` inside somebody's sign-in.
35
+ "opener_message",
36
+ "opener_locator",
37
+ "opener_seal",
38
+ "opener_open",
32
39
  "wallet_seed_for",
33
40
  ];
34
41
  export function isCryptoGlue(value) {
package/dist/help.js CHANGED
@@ -34,6 +34,13 @@ export function helpText(version) {
34
34
  ` key list Every API key of this account: what it may do, when it stops, when it`,
35
35
  ` was last used. Needs the NMTS key; an API key cannot list keys`,
36
36
  ` key revoke <id|all> Cut one key, or all of them — whatever uses it stops at once`,
37
+ // Copy facts — these three lines. Facts: the list says which wallets open this account and when
38
+ // each was added; adding one lets whoever holds that wallet open every file in the account
39
+ // from any machine; removing one stops it from then on and cannot unknow what it opened. All
40
+ // three need the NMTS key itself, not only an API key.
41
+ ` openers The wallets that open this account, and when each was added`,
42
+ ` openers add Attach a wallet — it opens every file here until it is removed`,
43
+ ` openers remove <loc> Stop one wallet opening this account from now on`,
37
44
  ` devices What is signed in to this account. \`--sign-out <id|all>\` ends one`,
38
45
  ` or all — a person's act: needs the NMTS key, refused in mode auto`,
39
46
  ` ls List files in the account`,
@@ -236,6 +243,14 @@ export function helpText(version) {
236
243
  ` --status Say whether the check is live, and stop (verify)`,
237
244
  ` --plain Store the NMTS key unsealed instead (login). Asks for an agreement`,
238
245
  ` --env Store nothing; print the variable to set (login). Same agreement`,
246
+ // Copy facts — these four lines. Facts: `--wallet` with no number means the NMTS key comes from
247
+ // a wallet's signature (login, create); the wallet's secret is never an option value, only a
248
+ // file path; the account number is inside what is signed, so another number is another
249
+ // signature; without `--app` one wallet opens the same account in every product that asks.
250
+ ` --wallet The NMTS key comes from a wallet's signature (login, create)`,
251
+ ` --sui-key-file <p> File holding the wallet's \`suiprivkey1…\` line. Never the key itself`,
252
+ ` --account <n> Which of that wallet's accounts. Default 1; it is inside what is signed`,
253
+ ` --app <name> Scope the signature to one product. Without it, one account everywhere`,
239
254
  ` --version Print the version and exit`,
240
255
  ` --help Print this and exit`,
241
256
  ``,
package/dist/main.js CHANGED
@@ -70,12 +70,10 @@ export async function run(argv) {
70
70
  switch (args.command) {
71
71
  case "login": {
72
72
  const { login } = await import("./commands/login.js");
73
- return await login({
74
- server: args.server,
75
- network: args.network,
76
- plain: args.plain,
77
- env: args.env,
78
- });
73
+ // ⚠ Loaded only when a wallet was named: it reaches the chain library's keypairs, and
74
+ // `check:cli-startup` measures what every other run pays for.
75
+ const wallet = args.wallet === undefined ? {} : { wallet: (await import("./commands/openers.js")).walletOpenerFrom(args) };
76
+ return await login({ server: args.server, network: args.network, plain: args.plain, env: args.env, ...wallet });
79
77
  }
80
78
  case "logout":
81
79
  return (await import("./commands/logout.js")).logout();
@@ -153,15 +151,16 @@ export async function run(argv) {
153
151
  }
154
152
  case "create": {
155
153
  const { create } = await import("./commands/create.js");
154
+ const wallet = args.wallet === undefined ? {} : { wallet: (await import("./commands/openers.js")).walletOpenerFrom(args) };
156
155
  return await create({
157
- server: args.server,
158
- network: args.network,
159
- out: args.out,
160
- acceptTerms: args.acceptTerms,
161
- acceptPrivacy: args.acceptPrivacy,
162
- json: args.json, noWait: args.noWait,
156
+ server: args.server, network: args.network, out: args.out, acceptTerms: args.acceptTerms,
157
+ acceptPrivacy: args.acceptPrivacy, json: args.json, noWait: args.noWait, ...wallet,
163
158
  });
164
159
  }
160
+ case "openers": {
161
+ const { openers } = await import("./commands/openers.js");
162
+ return await openers(args.operands[0], args);
163
+ }
165
164
  case "trial": {
166
165
  const { trial } = await import("./commands/trial.js");
167
166
  return await trial(args.operands[0], { server: args.server, network: args.network, json: args.json });
@@ -0,0 +1,65 @@
1
+ /** Where to talk, what the server answers to, and the proof the three account doors ask for. */
2
+ export interface OpenerAccess {
3
+ server: string;
4
+ /** The API key or delegation token this client speaks with. */
5
+ apiKey: string;
6
+ /** The account code's own proof for this one run, base64url (`x-nmts-account-proof`). */
7
+ accountProof: string;
8
+ }
9
+ /**
10
+ * One opener as its own account sees it.
11
+ *
12
+ * ⛔ NO SLOT BYTES. The list says what roads exist, not what is inside them; the one caller that
13
+ * needs the bytes asks for them by locator, without a credential.
14
+ */
15
+ export interface OpenerInfo {
16
+ /** The name the server files it under, unpadded base64url. */
17
+ locator: string;
18
+ /**
19
+ * What kind of thing opens it.
20
+ *
21
+ * ⚠ `other` IS NOT A THIRD FEATURE — it is what a kind this version has no name for is called.
22
+ * A list that quietly dropped such a row, or called it one of the two it knows, would be
23
+ * under-reporting the roads into an account, which is the one thing this list must not do.
24
+ */
25
+ kind: "wallet" | "passkey" | "other";
26
+ /** When it was added, as the server spells it (RFC 3339, UTC). */
27
+ createdAt: string;
28
+ }
29
+ /** What this account holds, and how many it may. */
30
+ export interface OpenerListing {
31
+ openers: OpenerInfo[];
32
+ /** The ceiling the server enforces, so a caller can say "3 of 8" without holding an 8 of its own. */
33
+ cap: number;
34
+ }
35
+ /** Slot kind: a Sui wallet's signature over the opener message. */
36
+ export declare const KIND_WALLET = 1;
37
+ /** Slot kind: a WebAuthn passkey's PRF output. Reserved; nothing in this package writes one. */
38
+ export declare const KIND_PASSKEY = 2;
39
+ /** Every opener on this account. */
40
+ export declare function listOpeners(access: OpenerAccess): Promise<OpenerListing>;
41
+ /**
42
+ * Store or replace the slot filed under this locator.
43
+ *
44
+ * ⚠ REPLACING IS NOT AN ACCIDENT. The same wallet re-wrapping its own slot — a new message version,
45
+ * a new derivation — writes the same locator and must overwrite rather than be refused as one
46
+ * opener too many.
47
+ */
48
+ export declare function putOpener(access: OpenerAccess, locator: string, kind: number, slot: Uint8Array): Promise<void>;
49
+ /**
50
+ * Take one road into the account away.
51
+ *
52
+ * ⛔ IT IS "FROM NOW ON", NOT "AS IF IT NEVER KNEW". A wallet that has opened this account once has
53
+ * held the NMTS key; removing its slot stops it opening the account again and cannot unknow
54
+ * what it learned. The sentence saying so belongs to whoever asked — it is not the server's and
55
+ * it is not this file's.
56
+ */
57
+ export declare function removeOpener(access: OpenerAccess, locator: string): Promise<void>;
58
+ /**
59
+ * The sealed bytes filed under this locator, or `null` when the server has none.
60
+ *
61
+ * ⛔ NO CREDENTIAL AND NO ACCOUNT ID GOES WITH IT, and none comes back: the answer is the slot and
62
+ * nothing else. `null` covers every reason the server has to refuse it — unknown, malformed, or
63
+ * an account since erased — because telling them apart is a way to learn which names exist.
64
+ */
65
+ export declare function fetchSlot(server: string, locator: string): Promise<Uint8Array | null>;
@@ -0,0 +1,97 @@
1
+ // The four doors an opener travels through, and nothing else.
2
+ //
3
+ // ⛔ THREE OF THEM ASK FOR THE ACCOUNT CODE'S OWN PROOF BESIDE THE CREDENTIAL, the grade erasing
4
+ // files carries. Adding an opener makes a standing way into the account that outlives whatever
5
+ // session made it; removing one takes a way in away; and the LIST is the inventory of every
6
+ // road into somebody's files. All three are acts of whoever holds the key, so all three ask for
7
+ // the key. ⚠ The proof is built by the caller and arrives as a value, exactly as `drive-erase.ts`
8
+ // takes it: whether this run may make one is a policy question with two different answers.
9
+ //
10
+ // ⛔ AND THE FOURTH TAKES NOTHING AT ALL, WHICH IS THE POINT. Somebody signing in with a wallet has
11
+ // no credential yet and does not know which account they are about to open — that is what the
12
+ // slot tells them. So the fetch carries no header, and a locator nobody has answers exactly as
13
+ // one belonging to somebody else does: `null` here, one 404 there.
14
+ //
15
+ // ⚠ NOTHING HERE REACHES FOR `node:`, and nothing here prints. The SDK's browser entry bundles what
16
+ // this exports, and every sentence a person reads belongs to whoever called.
17
+ import { request, ServerError } from "../api.js";
18
+ import { toBase64Url } from "../bytes.js";
19
+ /** Slot kind: a Sui wallet's signature over the opener message. */
20
+ export const KIND_WALLET = 1;
21
+ /** Slot kind: a WebAuthn passkey's PRF output. Reserved; nothing in this package writes one. */
22
+ export const KIND_PASSKEY = 2;
23
+ /** Every opener on this account. */
24
+ export async function listOpeners(access) {
25
+ const answer = await request(access.server, "/v1/openers", {
26
+ token: access.apiKey,
27
+ accountProof: access.accountProof,
28
+ });
29
+ const rows = at(answer, "openers");
30
+ const cap = at(answer, "cap");
31
+ return {
32
+ openers: (Array.isArray(rows) ? rows : []).flatMap((row) => (row === null ? [] : [oneOpener(row)])),
33
+ cap: typeof cap === "number" ? cap : 0,
34
+ };
35
+ }
36
+ /**
37
+ * Store or replace the slot filed under this locator.
38
+ *
39
+ * ⚠ REPLACING IS NOT AN ACCIDENT. The same wallet re-wrapping its own slot — a new message version,
40
+ * a new derivation — writes the same locator and must overwrite rather than be refused as one
41
+ * opener too many.
42
+ */
43
+ export async function putOpener(access, locator, kind, slot) {
44
+ await request(access.server, `/v1/openers/${encodeURIComponent(locator)}`, {
45
+ method: "PUT",
46
+ body: { kind, slot: toBase64Url(slot) },
47
+ token: access.apiKey,
48
+ accountProof: access.accountProof,
49
+ });
50
+ }
51
+ /**
52
+ * Take one road into the account away.
53
+ *
54
+ * ⛔ IT IS "FROM NOW ON", NOT "AS IF IT NEVER KNEW". A wallet that has opened this account once has
55
+ * held the NMTS key; removing its slot stops it opening the account again and cannot unknow
56
+ * what it learned. The sentence saying so belongs to whoever asked — it is not the server's and
57
+ * it is not this file's.
58
+ */
59
+ export async function removeOpener(access, locator) {
60
+ await request(access.server, `/v1/openers/${encodeURIComponent(locator)}`, {
61
+ method: "DELETE",
62
+ token: access.apiKey,
63
+ accountProof: access.accountProof,
64
+ });
65
+ }
66
+ /**
67
+ * The sealed bytes filed under this locator, or `null` when the server has none.
68
+ *
69
+ * ⛔ NO CREDENTIAL AND NO ACCOUNT ID GOES WITH IT, and none comes back: the answer is the slot and
70
+ * nothing else. `null` covers every reason the server has to refuse it — unknown, malformed, or
71
+ * an account since erased — because telling them apart is a way to learn which names exist.
72
+ */
73
+ export async function fetchSlot(server, locator) {
74
+ try {
75
+ return await request(server, `/v1/opener/${encodeURIComponent(locator)}`, { as: "bytes" });
76
+ }
77
+ catch (error) {
78
+ if (error instanceof ServerError && error.status === 404)
79
+ return null;
80
+ throw error;
81
+ }
82
+ }
83
+ /** One listed row, read defensively: it arrived over the network. */
84
+ function oneOpener(row) {
85
+ const kind = at(row, "kind");
86
+ const locator = at(row, "locator");
87
+ const created = at(row, "created_at");
88
+ return {
89
+ locator: typeof locator === "string" ? locator : "",
90
+ kind: kind === KIND_WALLET ? "wallet" : kind === KIND_PASSKEY ? "passkey" : "other",
91
+ createdAt: typeof created === "string" ? created : "",
92
+ };
93
+ }
94
+ /** One field of something the server sent, without asserting its shape. */
95
+ function at(value, name) {
96
+ return typeof value === "object" && value !== null ? Reflect.get(value, name) : undefined;
97
+ }
@@ -0,0 +1,22 @@
1
+ export interface OpenerHints {
2
+ /**
3
+ * The `nextStep` for a wallet that has no opener on this server — the sign-in that found
4
+ * nothing. ⚠ The account NUMBER is inside the signed bytes, so nothing can search for it.
5
+ */
6
+ noOpener?: string | undefined;
7
+ /** The `nextStep` for a wallet whose two signatures over one message differed. */
8
+ notRepeatable?: string | undefined;
9
+ /** The `nextStep` for a wallet whose signing scheme cannot be used as an opener. */
10
+ wrongKind?: string | undefined;
11
+ /** The `nextStep` for a wallet that already opens THIS account — there is nothing to do. */
12
+ alreadyAttached?: string | undefined;
13
+ /**
14
+ * The `nextStep` for a wallet that already opens ANOTHER account at this account number.
15
+ *
16
+ * ⚠ The way out is another number now and the SAME number at every later sign-in, which is a
17
+ * sentence about the caller's own options — so it is one of these rather than a fixed one.
18
+ */
19
+ opensAnother?: string | undefined;
20
+ /** The `nextStep` for an account that is already holding as many openers as it may. */
21
+ full?: string | undefined;
22
+ }
@@ -0,0 +1,11 @@
1
+ // The words a caller puts in a refusal, where the neutral sentence is not the one to say.
2
+ //
3
+ // ⛔ A TERMINAL NAMES ITS OWN COMMANDS AND A LIBRARY NAMES NONE. "`nmts openers add` attaches this
4
+ // wallet" is the right next step for somebody at a prompt and the wrong one inside somebody
5
+ // else's page, where that program does not exist. So the JUDGEMENT is written once, in this
6
+ // folder, and the sentence that follows it belongs to whoever asked — the same division
7
+ // `storage-control/hints.ts` keeps, for the same reason.
8
+ //
9
+ // ⚠ EVERY FIELD IS OPTIONAL, and what is left out is answered with a sentence that names nothing
10
+ // outside the caller's own program. The SDK passes none of them.
11
+ export {};
@@ -0,0 +1,56 @@
1
+ import type { OpenerHints } from "./hints.ts";
2
+ /** What a wallet hands back: the serialized signature, and what it says it signed. */
3
+ export interface WalletSignature {
4
+ /** The serialized signature, base64 — `flag ‖ signature ‖ public key`, as every wallet sends it. */
5
+ signature: string;
6
+ /** Base64 of the bytes the wallet signed, when it says. Compared, never trusted. */
7
+ bytes?: string | undefined;
8
+ }
9
+ /** A wallet's answer in either shape: the standard's object, or the signature on its own. */
10
+ export type SignedMessage = WalletSignature | string;
11
+ /** Whatever holds the wallet's key: a browser extension, a key file, a hardware device. */
12
+ export type SignWallet = (message: Uint8Array) => Promise<SignedMessage> | SignedMessage;
13
+ /** Which account this wallet opens, and how to ask it. */
14
+ export interface WalletOpener {
15
+ /** The wallet's Sui address, `0x` and 64 LOWERCASE hex. Refused, never repaired. */
16
+ address: string;
17
+ /**
18
+ * Which of this wallet's NMTS accounts. Default 1.
19
+ *
20
+ * ⛔ IT IS INSIDE THE SIGNED BYTES, so nothing can look for the others: a sign-in that finds no
21
+ * opener cannot try 2, 3, 4 without asking the person to sign again, once per number.
22
+ */
23
+ account?: number | undefined;
24
+ /**
25
+ * A product scope. Absent means one wallet opens the same account everywhere; present means this
26
+ * wallet opens a different account for this product alone.
27
+ *
28
+ * ⚠ THE PRICE OF LEAVING IT OUT: every product that gets this signature opens the same files.
29
+ */
30
+ app?: string | undefined;
31
+ sign: SignWallet;
32
+ }
33
+ /** The exact bytes this wallet is asked to sign. Built by the engine; refused, never repaired. */
34
+ export declare function openerMessage(input: WalletOpener): Promise<Uint8Array>;
35
+ /**
36
+ * Get one signature over this account's message, judge it, and lend it to `use`.
37
+ *
38
+ * ⛔ THE SIGNATURE IS NOT THE ANSWER. Whatever `use` returns is; the bytes are dropped when this
39
+ * call ends, and there is deliberately no form of this that hands them back.
40
+ */
41
+ export declare function withSignature<T>(input: WalletOpener, use: (serialized: Uint8Array) => Promise<T>, hints?: OpenerHints): Promise<T>;
42
+ /**
43
+ * Get the signature TWICE and refuse unless both are the same 64 bytes, then lend it to `use`.
44
+ *
45
+ * ⛔ THE ONE CHECK THAT MAKES AN OPENER WORTH STORING. A slot is opened by the same signature that
46
+ * sealed it, so a wallet that signs differently the second time seals something it can never
47
+ * open — and the person would learn that at their next sign-in, with the account behind it.
48
+ * Two signatures now is a question a wallet answers in seconds; the alternative is a slot that
49
+ * looks fine forever.
50
+ *
51
+ * ⚠ IT IS RUN FOR EVERY SCHEME, including the three that sign deterministically. An Ed25519 wallet
52
+ * held by a signing service, an MPC wallet or a hardware wallet with its own nonce rule all
53
+ * present as Ed25519 and all may hedge — the flag says how a signature is checked, not how it
54
+ * was made.
55
+ */
56
+ export declare function withRepeatedSignature<T>(input: WalletOpener, use: (serialized: Uint8Array) => Promise<T>, hints?: OpenerHints): Promise<T>;