@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.
- package/CHANGELOG.md +16 -0
- package/README.ko.md +27 -1
- package/README.md +29 -1
- package/dist/api-advice.js +6 -0
- package/dist/api.d.ts +10 -1
- package/dist/api.js +12 -2
- package/dist/arg-options.d.ts +21 -0
- package/dist/args.js +12 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/create-link.d.ts +9 -0
- package/dist/commands/create-link.js +31 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +17 -0
- package/dist/commands/login-passphrase.d.ts +13 -0
- package/dist/commands/login-passphrase.js +64 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +15 -55
- package/dist/commands/openers-attach.d.ts +38 -0
- package/dist/commands/openers-attach.js +97 -0
- package/dist/commands/openers.d.ts +23 -0
- package/dist/commands/openers.js +195 -0
- package/dist/crypto-surface.d.ts +28 -0
- package/dist/crypto-surface.js +7 -0
- package/dist/help.js +15 -0
- package/dist/main.js +11 -12
- package/dist/openers/doors.d.ts +65 -0
- package/dist/openers/doors.js +97 -0
- package/dist/openers/hints.d.ts +22 -0
- package/dist/openers/hints.js +11 -0
- package/dist/openers/sign.d.ts +56 -0
- package/dist/openers/sign.js +202 -0
- package/dist/openers/wallet.d.ts +71 -0
- package/dist/openers/wallet.js +210 -0
- package/dist/openers-key-file.d.ts +14 -0
- package/dist/openers-key-file.js +99 -0
- package/dist/openers.d.ts +7 -0
- package/dist/openers.js +21 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/risk.d.ts +11 -0
- package/dist/risk.js +15 -0
- package/docs/commands/openers.md +31 -0
- package/package.json +5 -1
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +54 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +108 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +4 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type AttachedWallet, type WalletOpener } from "../openers.ts";
|
|
2
|
+
/** What attaching to a fresh account takes. */
|
|
3
|
+
export interface AttachInput {
|
|
4
|
+
server: string;
|
|
5
|
+
/** The account's NMTS key — made in this run and held by nobody else. */
|
|
6
|
+
code: string;
|
|
7
|
+
wallet: WalletOpener;
|
|
8
|
+
}
|
|
9
|
+
/** What it did, and the one thing that can be left behind by a failure. */
|
|
10
|
+
export interface AttachOutcome extends AttachedWallet {
|
|
11
|
+
/**
|
|
12
|
+
* The id of the borrowed key this run could NOT revoke, or null when nothing was left.
|
|
13
|
+
*
|
|
14
|
+
* ⚠ NOT A FAILURE OF THE ATTACH. The wallet does open the account; what did not happen is the
|
|
15
|
+
* tidying, and a person can cut the key from a browser or with `nmts key revoke`.
|
|
16
|
+
*/
|
|
17
|
+
keyLeft: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** Attach `wallet` to the account `code` opens, borrowing a credential for the length of one PUT. */
|
|
20
|
+
export declare function attachWalletToNewAccount(input: AttachInput): Promise<AttachOutcome>;
|
|
21
|
+
/**
|
|
22
|
+
* Ask, before an account is made, whether this wallet already opens one.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ THE ONE STEP THAT HAS TO HAPPEN EARLY. Everywhere else a taken locator is a refusal and
|
|
25
|
+
* nothing else; on `nmts create --wallet` it would be an account that exists, holds a key the
|
|
26
|
+
* person has been handed, and cannot have the wallet they asked for. One signature spent here
|
|
27
|
+
* is cheaper than an account nobody wanted.
|
|
28
|
+
*/
|
|
29
|
+
export declare function refuseIfWalletIsTaken(server: string, wallet: WalletOpener): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* What a wallet attached to a new account means, said after the code has been handed over.
|
|
32
|
+
*
|
|
33
|
+
* ⚠ Copy facts — both sentences. Facts for the first: this wallet now opens this account from any
|
|
34
|
+
* machine, so whoever holds it can read every file in it, and `nmts openers remove <locator>`
|
|
35
|
+
* takes it off. For the second: a write-scoped key borrowed for this one step is still live on
|
|
36
|
+
* the brand-new account, and its id is how to cut it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function sayWalletAttached(say: (line: string) => void, attached: AttachOutcome): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Attaching a wallet to an account THIS RUN JUST CREATED — the one case where the account has no
|
|
2
|
+
// credential on this machine yet.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ WHY THIS FILE EXISTS AT ALL. The three opener doors take a credential AND the NMTS key's own
|
|
5
|
+
// proof: the proof says whoever is asking holds the key, and the credential says which account
|
|
6
|
+
// the server is talking to. A brand-new account has the first and not the second — `nmts create`
|
|
7
|
+
// deliberately stores nothing and switches nothing over (`create.ts`) — so there is nothing to
|
|
8
|
+
// speak with. `POST /v1/account/api-keys/by-code` is the door built for exactly that shape: a
|
|
9
|
+
// program set up from one secret rather than from a browser session plus that secret.
|
|
10
|
+
//
|
|
11
|
+
// ⛔ SO THE KEY IS MINTED, USED ONCE, AND CUT. It lasts a day, carries `write` and nothing else,
|
|
12
|
+
// and is revoked as soon as the slot is stored — through `revoke-by-code`, which needs the same
|
|
13
|
+
// one secret. What is left behind is an account with the wallet attached and no credential,
|
|
14
|
+
// which is what `nmts create` leaves behind today.
|
|
15
|
+
//
|
|
16
|
+
// ⛔ AND A REVOKE THAT FAILED IS REPORTED, NEVER SWALLOWED. A live key on somebody's new account
|
|
17
|
+
// that they were not told about is worse than one they were: the caller is handed the key's id
|
|
18
|
+
// so it can say so, and the attach itself still counts as done, because it is.
|
|
19
|
+
//
|
|
20
|
+
// The sentences the caller prints around this: The facts are in `create.ts` and in
|
|
21
|
+
// the comment above each return.
|
|
22
|
+
import { request } from "../api.js";
|
|
23
|
+
import { addWallet, refuseIfWalletOpensAnAccount, } from "../openers.js";
|
|
24
|
+
import { BINARY_NAME } from "../product.js";
|
|
25
|
+
import { registrationProofOf } from "../registration.js";
|
|
26
|
+
import { OPENER_HINTS } from "./openers.js";
|
|
27
|
+
/** Permission to write this account's own openers, and nothing else. `api/src/domain/api_key.rs`. */
|
|
28
|
+
const WRITE_ONLY = 2;
|
|
29
|
+
/** How long the borrowed key may live. It is cut seconds later; this is what covers a failure. */
|
|
30
|
+
const ONE_DAY = 1;
|
|
31
|
+
/** Attach `wallet` to the account `code` opens, borrowing a credential for the length of one PUT. */
|
|
32
|
+
export async function attachWalletToNewAccount(input) {
|
|
33
|
+
const { accountId, authSecret } = await registrationProofOf(input.code);
|
|
34
|
+
const proven = { account_id: accountId, auth_secret: authSecret };
|
|
35
|
+
const issued = await request(input.server, "/v1/account/api-keys/by-code", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body: { ...proven, scopes: WRITE_ONLY, lifetime_days: ONE_DAY },
|
|
38
|
+
// ⛔ NOT REPEATED ON A TIMEOUT. A request that reached the server and died on the way back has
|
|
39
|
+
// already spent one of the two live keys this account may hold, and a retry would spend the
|
|
40
|
+
// other — leaving a new account at its cap over a key nobody received.
|
|
41
|
+
retryBudgetMs: 0,
|
|
42
|
+
});
|
|
43
|
+
const apiKey = field(issued, "key");
|
|
44
|
+
const keyId = field(issued, "key_id");
|
|
45
|
+
if (apiKey === null || keyId === null) {
|
|
46
|
+
throw new Error("OPENER_ATTACH_NO_KEY: the server's answer held no usable key.");
|
|
47
|
+
}
|
|
48
|
+
const attached = await addWallet({ server: input.server, apiKey, accountProof: authSecret }, input.code, input.wallet, OPENER_HINTS);
|
|
49
|
+
return { ...attached, keyLeft: (await revoked(input.server, proven, keyId)) ? null : keyId };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Ask, before an account is made, whether this wallet already opens one.
|
|
53
|
+
*
|
|
54
|
+
* ⛔ THE ONE STEP THAT HAS TO HAPPEN EARLY. Everywhere else a taken locator is a refusal and
|
|
55
|
+
* nothing else; on `nmts create --wallet` it would be an account that exists, holds a key the
|
|
56
|
+
* person has been handed, and cannot have the wallet they asked for. One signature spent here
|
|
57
|
+
* is cheaper than an account nobody wanted.
|
|
58
|
+
*/
|
|
59
|
+
export async function refuseIfWalletIsTaken(server, wallet) {
|
|
60
|
+
await refuseIfWalletOpensAnAccount(server, wallet, OPENER_HINTS);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What a wallet attached to a new account means, said after the code has been handed over.
|
|
64
|
+
*
|
|
65
|
+
* ⚠ Copy facts — both sentences. Facts for the first: this wallet now opens this account from any
|
|
66
|
+
* machine, so whoever holds it can read every file in it, and `nmts openers remove <locator>`
|
|
67
|
+
* takes it off. For the second: a write-scoped key borrowed for this one step is still live on
|
|
68
|
+
* the brand-new account, and its id is how to cut it.
|
|
69
|
+
*/
|
|
70
|
+
export function sayWalletAttached(say, attached) {
|
|
71
|
+
say(``);
|
|
72
|
+
say(`This wallet also opens the new account: ${attached.locator}`);
|
|
73
|
+
if (attached.keyLeft !== null) {
|
|
74
|
+
say(`⚠ The key borrowed to store it — ${attached.keyLeft} — is still live. Cut it with \`${BINARY_NAME} key revoke ${attached.keyLeft}\`.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Cut the borrowed key. Its failure is an answer, not a throw: the wallet is attached either way. */
|
|
78
|
+
async function revoked(server, proven, keyId) {
|
|
79
|
+
try {
|
|
80
|
+
await request(server, "/v1/account/api-keys/revoke-by-code", {
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: { ...proven, key_id: keyId },
|
|
83
|
+
retryBudgetMs: 0,
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// ⚠ The cause is not carried up. What the caller can act on is that a key is still live and
|
|
89
|
+
// which one; why the revoke failed is already in the run log.
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** One string field of the server's answer, or null. ⛔ Nothing here prints what it read. */
|
|
94
|
+
function field(answer, name) {
|
|
95
|
+
const value = typeof answer === "object" && answer !== null ? Reflect.get(answer, name) : undefined;
|
|
96
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
97
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParsedArgs } from "../args.ts";
|
|
2
|
+
import { type OpenerHints, type WalletOpener } from "../openers.ts";
|
|
3
|
+
import { type KeyFileWallet } from "../openers-key-file.ts";
|
|
4
|
+
export interface OpenersCommandOptions {
|
|
5
|
+
write?: ((line: string) => void) | undefined;
|
|
6
|
+
/** Injected in tests: a wallet that is not read from a file on a disk. */
|
|
7
|
+
wallet?: KeyFileWallet | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The sentences a TERMINAL puts in the library's refusals. A library names no commands, so these
|
|
11
|
+
* are the caller's half of each judgement (`openers/hints.ts`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const OPENER_HINTS: OpenerHints;
|
|
14
|
+
/** `nmts openers [add|remove <locator>]`. */
|
|
15
|
+
export declare function openers(verb: string | undefined, args: ParsedArgs, options?: OpenersCommandOptions): Promise<number>;
|
|
16
|
+
/**
|
|
17
|
+
* The wallet this command line names, and which account of it to open.
|
|
18
|
+
*
|
|
19
|
+
* ⚠ THE ADDRESS IS THE KEY FILE'S OWN. It is not an option: an address typed beside a key file is
|
|
20
|
+
* two answers to one question, and the message a person signs carries whichever of them is
|
|
21
|
+
* right only by luck.
|
|
22
|
+
*/
|
|
23
|
+
export declare function walletOpenerFrom(args: ParsedArgs, options?: OpenersCommandOptions): WalletOpener;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// `nmts openers` — the wallets that open this account: what they are, adding one, taking one off.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ THE LIST IS AN INVENTORY OF WAYS INTO THE ACCOUNT, which is why all three verbs present the
|
|
4
|
+
// NMTS key's own proof beside the API key. Adding one makes a standing road in that outlives
|
|
5
|
+
// whatever made it; removing one takes a road away; and seeing the list is seeing every road
|
|
6
|
+
// somebody's files can be reached by. All three are acts of whoever holds the key.
|
|
7
|
+
//
|
|
8
|
+
// ⛔ WHAT IS DECIDED HERE IS ONLY WHAT A TERMINAL DECIDES: which file the wallet is read from, what
|
|
9
|
+
// is printed, and the exit code. The acts themselves are `openers.ts`, which the SDK calls with
|
|
10
|
+
// none of those — so "which bytes are signed and when the key bytes are wiped" is written once.
|
|
11
|
+
//
|
|
12
|
+
// ⛔ THE WALLET'S SECRET IS NEVER AN ARGUMENT. `--sui-key-file` names a FILE; the key is read from
|
|
13
|
+
// it, used to sign one message, and never printed — see `openers-key-file.ts`.
|
|
14
|
+
//
|
|
15
|
+
// ⚠ Copy facts — every sentence below that a person reads. The facts each one has to carry are in
|
|
16
|
+
// the comment above it, and the machine codes in the refusals are not copy — they are the
|
|
17
|
+
// contract a program branches on.
|
|
18
|
+
import { accountProofFor } from "../account-proof.js";
|
|
19
|
+
import { requireAccountCode } from "../code-access.js";
|
|
20
|
+
import { readCredentialsFile } from "../credentials.js";
|
|
21
|
+
import { NmtsError } from "../errors.js";
|
|
22
|
+
import { addWallet, listOpeners, removeWallet } from "../openers.js";
|
|
23
|
+
import { walletFromKeyFile } from "../openers-key-file.js";
|
|
24
|
+
import { BINARY_NAME } from "../product.js";
|
|
25
|
+
import { resolveServer } from "../server.js";
|
|
26
|
+
import { requireApiKey } from "../session.js";
|
|
27
|
+
/**
|
|
28
|
+
* The sentences a TERMINAL puts in the library's refusals. A library names no commands, so these
|
|
29
|
+
* are the caller's half of each judgement (`openers/hints.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export const OPENER_HINTS = {
|
|
32
|
+
// Copy facts — Facts: the wallet signed, and this server has no slot under the name that
|
|
33
|
+
// signature makes; the account number is inside the signed bytes, so another number means
|
|
34
|
+
// another signature; `--account n` is how to ask for one.
|
|
35
|
+
noOpener: `Nothing was opened. \`${BINARY_NAME} login --wallet --sui-key-file <file> --account 2\` asks a different number.`,
|
|
36
|
+
// Copy facts — Facts: the wallet was asked for the same signature twice and answered differently,
|
|
37
|
+
// so it could not open what it was about to seal; nothing was stored.
|
|
38
|
+
notRepeatable: `Nothing was stored. This wallet cannot be used for wallet login; \`${BINARY_NAME} login\` takes the NMTS key itself.`,
|
|
39
|
+
// Copy facts — Facts: multisig, zkLogin and passkey wallets sign differently every time; an
|
|
40
|
+
// opener needs a wallet whose signature over one message never changes.
|
|
41
|
+
wrongKind: `Nothing was stored. \`${BINARY_NAME} openers\` lists the wallets this account already has.`,
|
|
42
|
+
// ⛔ FINAL COPY, both of these. They are the two answers to a locator that is already taken, and
|
|
43
|
+
// the second one has to say the rule as well as the way out: the number used to attach is the
|
|
44
|
+
// number that must be given at every later sign-in.
|
|
45
|
+
alreadyAttached: `Nothing was stored. \`${BINARY_NAME} openers\` lists it.`,
|
|
46
|
+
opensAnother: `Nothing was stored. One wallet and one number open one account: pass another number with --account, and use the same number with \`${BINARY_NAME} login --wallet\`.`,
|
|
47
|
+
};
|
|
48
|
+
/** `nmts openers [add|remove <locator>]`. */
|
|
49
|
+
export async function openers(verb, args, options = {}) {
|
|
50
|
+
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
51
|
+
const asked = (verb ?? "").trim();
|
|
52
|
+
if (asked === "" || asked === "list")
|
|
53
|
+
return await list(args, say);
|
|
54
|
+
if (asked === "add")
|
|
55
|
+
return await add(args, say, options);
|
|
56
|
+
if (asked === "remove")
|
|
57
|
+
return await remove(args, say);
|
|
58
|
+
throw new NmtsError(`\`${BINARY_NAME} openers\` has no verb "${asked}".`, {
|
|
59
|
+
exitCode: 2,
|
|
60
|
+
nextStep: `The verbs are: (none) to list, \`add\`, and \`remove <locator>\`.`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** What this account holds, and how many it may. */
|
|
64
|
+
async function list(args, say) {
|
|
65
|
+
const { access } = await reach(args);
|
|
66
|
+
const listing = await listOpeners(access);
|
|
67
|
+
if (args.json) {
|
|
68
|
+
say(JSON.stringify({ openers: listing.openers, cap: listing.cap }));
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
// Copy facts — Facts: each row is a way into this account; `kind` says what holds it; the date is
|
|
72
|
+
// when it was added; the count against the cap is what the account may hold.
|
|
73
|
+
say(`${listing.openers.length} of ${listing.cap} openers on this account. An opener is a wallet that opens it without the NMTS key typed.`);
|
|
74
|
+
for (const one of listing.openers)
|
|
75
|
+
say(` ${one.locator} ${one.kind} ${one.createdAt}`);
|
|
76
|
+
if (listing.openers.length === 0) {
|
|
77
|
+
// Copy facts — Facts: nothing but the NMTS key opens this account today; adding a wallet is one
|
|
78
|
+
// command; whoever holds an added wallet can open every file in the account.
|
|
79
|
+
say(``);
|
|
80
|
+
say(` Only the NMTS key opens this account. \`${BINARY_NAME} openers add --sui-key-file <file>\` adds a wallet.`);
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A locator as it must be TYPED, which is not always as it reads.
|
|
86
|
+
*
|
|
87
|
+
* ⛔ ABOUT ONE LOCATOR IN 64 BEGINS WITH `-`: it is 16 bytes written in base64url and that alphabet
|
|
88
|
+
* has a dash in it. Pasted onto a command line as it stands, such a name is an option to the
|
|
89
|
+
* shell and to this tool, so a line printed here for a person to copy carries the `--` that ends
|
|
90
|
+
* the options — the same way this tool already takes a file named `-h`.
|
|
91
|
+
*/
|
|
92
|
+
function asTyped(locator) {
|
|
93
|
+
return locator.startsWith("-") ? `-- ${locator}` : locator;
|
|
94
|
+
}
|
|
95
|
+
/** Attach one wallet to this account. */
|
|
96
|
+
async function add(args, say, options) {
|
|
97
|
+
const { access, code } = await reach(args);
|
|
98
|
+
const attached = await addWallet(access, code, walletOpenerFrom(args, options), OPENER_HINTS);
|
|
99
|
+
if (args.json) {
|
|
100
|
+
say(JSON.stringify({ locator: attached.locator, kind: attached.kind }));
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
// Copy facts — Facts: this wallet now opens this account from any machine; the server holds a
|
|
104
|
+
// locked slot it cannot open and a name it cannot trace to a wallet; removing it later stops it
|
|
105
|
+
// opening the account from then on and cannot unknow what it has already opened.
|
|
106
|
+
say(`This wallet now opens this account.`);
|
|
107
|
+
say(``);
|
|
108
|
+
say(` ${attached.locator}`);
|
|
109
|
+
say(``);
|
|
110
|
+
say(` Whoever holds this wallet can open every file in the account until it is removed.`);
|
|
111
|
+
say(` \`${BINARY_NAME} openers remove ${asTyped(attached.locator)}\` takes it off.`);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
/** Take one wallet off this account. */
|
|
115
|
+
async function remove(args, say) {
|
|
116
|
+
const locator = (args.operands[1] ?? "").trim();
|
|
117
|
+
if (locator === "") {
|
|
118
|
+
throw new NmtsError(`\`${BINARY_NAME} openers remove\` needs the locator of the opener to take off.`, {
|
|
119
|
+
exitCode: 2,
|
|
120
|
+
nextStep: `\`${BINARY_NAME} openers\` prints the locators this account holds.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const { access } = await reach(args);
|
|
124
|
+
await removeWallet(access, locator);
|
|
125
|
+
if (args.json) {
|
|
126
|
+
say(JSON.stringify({ removed: locator }));
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
// Copy facts — Facts: from now on that wallet cannot open this account; it is not "as if it never
|
|
130
|
+
// knew" — a wallet that opened the account once has held the NMTS key, and the only answer to
|
|
131
|
+
// that is a new account.
|
|
132
|
+
say(`Removed ${locator}. That wallet cannot open this account from now on.`);
|
|
133
|
+
say(` Removing does not undo the past: a wallet that opened this account once has held the NMTS key.`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The account this run acts on, and the proof the three doors ask for.
|
|
138
|
+
*
|
|
139
|
+
* ⚠ NO NETWORK IS RESOLVED, and that is deliberate — the same reason `key new` does not resolve
|
|
140
|
+
* one. Nothing here touches a chain or the storage network, so demanding to be told which
|
|
141
|
+
* network a development server uses would refuse a run that was never going to use the answer.
|
|
142
|
+
*/
|
|
143
|
+
async function reach(args) {
|
|
144
|
+
const held = await requireAccountCode();
|
|
145
|
+
const apiKey = requireApiKey();
|
|
146
|
+
const stored = readCredentialsFile();
|
|
147
|
+
// ⛔ THE PROOF IS BUILT FOR THIS ONE RUN AND NOTHING KEEPS IT — `account-proof.ts`.
|
|
148
|
+
const accountProof = await accountProofFor(held);
|
|
149
|
+
return {
|
|
150
|
+
access: { server: resolveServer(args.server ?? stored?.server), apiKey, accountProof },
|
|
151
|
+
code: held.code,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The wallet this command line names, and which account of it to open.
|
|
156
|
+
*
|
|
157
|
+
* ⚠ THE ADDRESS IS THE KEY FILE'S OWN. It is not an option: an address typed beside a key file is
|
|
158
|
+
* two answers to one question, and the message a person signs carries whichever of them is
|
|
159
|
+
* right only by luck.
|
|
160
|
+
*/
|
|
161
|
+
export function walletOpenerFrom(args, options = {}) {
|
|
162
|
+
const path = (args.suiKeyFile ?? "").trim();
|
|
163
|
+
if (options.wallet === undefined && path === "") {
|
|
164
|
+
throw new NmtsError(`--sui-key-file names the file holding the wallet's \`suiprivkey1…\` line.`, {
|
|
165
|
+
exitCode: 2,
|
|
166
|
+
// Copy facts — Facts: the secret is never an option value because a command line is readable
|
|
167
|
+
// by other processes and recorded by the shell; the file is read and never copied.
|
|
168
|
+
nextStep: `Nothing was signed. Write the wallet's key to a file and name it with --sui-key-file.`,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const wallet = options.wallet ?? walletFromKeyFile(path);
|
|
172
|
+
const app = (args.app ?? "").trim();
|
|
173
|
+
return {
|
|
174
|
+
address: wallet.address,
|
|
175
|
+
sign: wallet.sign,
|
|
176
|
+
account: accountNumber(args.account),
|
|
177
|
+
...(app === "" ? {} : { app }),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Which of this wallet's accounts. ⛔ Whole and from 1: the engine refuses 0, and the number is
|
|
182
|
+
* inside what the person signs, so it is never tidied up here.
|
|
183
|
+
*/
|
|
184
|
+
function accountNumber(given) {
|
|
185
|
+
const text = (given ?? "").trim();
|
|
186
|
+
if (text === "")
|
|
187
|
+
return 1;
|
|
188
|
+
if (!/^[1-9][0-9]{0,9}$/u.test(text)) {
|
|
189
|
+
throw new NmtsError(`--account takes a whole number from 1, not "${text}".`, {
|
|
190
|
+
exitCode: 2,
|
|
191
|
+
nextStep: `Nothing was signed. One wallet opens a different account per number, and 1 is the default.`,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return Number(text);
|
|
195
|
+
}
|
package/dist/crypto-surface.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/crypto-surface.js
CHANGED
|
@@ -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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
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
|
+
}
|