oneie 5.5.2 → 5.7.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/README.md +29 -0
- package/dist/package.json +2 -2
- package/dist/src/index.js +15 -15
- package/dist/src/init.d.ts +10 -1
- package/dist/src/init.js +26 -11
- package/dist/src/join.d.ts +1 -1
- package/dist/src/join.js +2 -1
- package/dist/src/key-publish.d.ts +40 -0
- package/dist/src/key-publish.js +232 -0
- package/dist/src/key-seal.d.ts +21 -0
- package/dist/src/key-seal.js +142 -0
- package/dist/src/key.js +22 -5
- package/dist/src/lib/age-plugin.d.ts +51 -0
- package/dist/src/lib/age-plugin.js +130 -0
- package/dist/src/lib/env-sealed.d.ts +53 -0
- package/dist/src/lib/env-sealed.js +184 -0
- package/dist/src/lib/journey.d.ts +137 -0
- package/dist/src/lib/journey.js +232 -0
- package/dist/src/lib/key-receipt.d.ts +48 -0
- package/dist/src/lib/key-receipt.js +116 -0
- package/dist/src/lib/lock-lookup.d.ts +40 -0
- package/dist/src/lib/lock-lookup.js +92 -0
- package/dist/src/lib/message-seal.d.ts +63 -0
- package/dist/src/lib/message-seal.js +150 -0
- package/dist/src/lib/shop-init.js +2 -2
- package/dist/src/lib/vault-read.d.ts +24 -0
- package/dist/src/lib/vault-read.js +77 -0
- package/dist/src/media.d.ts +27 -0
- package/dist/src/media.js +249 -18
- package/dist/src/secrets-device.d.ts +32 -0
- package/dist/src/secrets-device.js +127 -0
- package/dist/src/secrets-give.d.ts +125 -0
- package/dist/src/secrets-give.js +236 -0
- package/dist/src/secrets-run.d.ts +31 -0
- package/dist/src/secrets-run.js +182 -0
- package/dist/src/secrets.d.ts +32 -0
- package/dist/src/secrets.js +197 -0
- package/dist/src/social.js +27 -8
- package/dist/src/start.d.ts +15 -0
- package/dist/src/start.js +200 -0
- package/dist/src/write.d.ts +43 -0
- package/dist/src/write.js +174 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -149,6 +149,35 @@ one key verify # compare this key's public identity with the ser
|
|
|
149
149
|
|
|
150
150
|
The words are never accepted on the command line (shell history, `ps`) — pipe them on stdin, set `ONE_WALLET_MNEMONIC`, or type them at the hidden prompt. `--phrase` and `--mnemonic` are refused, and a stray argument is never echoed back, because it may be your phrase. The words print only to a terminal: a shell that looks like an agent or CI is refused, and a non-terminal stdout needs `--yes-print-to-pipe` (a printer, on purpose). Under `--json` the words never reach stdout; `--out <file>` writes them at mode `0600` and needs `--yes-i-accept-plaintext-file`. That is detection, not proof — a pty with no agent marker is not caught. A key minted under v1 and one minted under v2 have different addresses from the same words, which is why `recover` and `public` print both.
|
|
151
151
|
|
|
152
|
+
### Sealed notes — `one key lock | seal | open | identity` and `one write`
|
|
153
|
+
|
|
154
|
+
Your key has a lock (`age1…`) anyone can seal a note to; only your key opens it. These run offline, never prompt, and answer `--json` with an exit code (0 done, 1 refused, with a plain sentence). The key is a file — `--key key.json`, what `one key new --out key.json` writes — or `ONE_WALLET_MNEMONIC`; the note is a file argument or stdin. The format is standard [age](https://age-encryption.org), so the stock `age` tool reads and writes the same notes.
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
one key lock --key key.json # age1… — what you give to senders
|
|
158
|
+
echo "ship it" | one key seal --to age1… --to age1… --self # armored age block; --self so you can reopen it
|
|
159
|
+
one key open --key key.json note.age # the note; says plainly if it is not for you, was changed, or is unsupported
|
|
160
|
+
one key identity --key key.json 2> /dev/null > id.txt # AGE-SECRET-KEY-1… (a secret) so `age -d -i id.txt note.age` works with no ONE code
|
|
161
|
+
echo "ship it" | one write brian --to age1… --from "ops agent" # seal here, drop the ciphertext in brian's inbox on one.ie; plaintext never leaves
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`one write` posts only the sealed block to `https://one.ie/api/write` (a web route — `--api` to point elsewhere). The door takes 8000 sealed characters and ten notes a minute from one address.
|
|
165
|
+
|
|
166
|
+
#### Publish your lock under your name, and look one up
|
|
167
|
+
|
|
168
|
+
A lock handed to you in a message proves nothing about whose it is. Publishing signs "your name + your lock" with your key's Sui key and files it with ONE; anyone can then look it up and check the signature on their own machine.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
one login # a person's login key — publishing reads the account's own registered Sui wallet
|
|
172
|
+
one key publish-lock --key key.json --slug brian # published age1… as brian, signed by Sui address 0x…
|
|
173
|
+
one key lock-of brian # prints the lock after re-checking the signature here
|
|
174
|
+
echo "ship it" | one write brian # no --to: seals to brian's CHECKED published lock, else refuses
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`publish-lock` sends only the lock and the signature (never the words). It signs under the key file's `derivation` marker, else v1; if the server says the signer is not the account's Sui key, the error prints this key's Sui address under both v1 and v2 and you retry with `--derivation v2`. `--slug` is the name your login key belongs to (else `AGENCY_SLUG` / `WORKSPACE_SLUG`); a wrong name comes back as a signature refusal that names the name used. Today only a person account with a registered Sui address can publish — an agent's own key gets `no_sui_address`. `lock-of` and `write` without `--to` refuse (never guess) when the name has published nothing, the lookup is not live or unreachable, or the lock does not verify. What a terminal cannot check is that the signing address belongs to the name; ONE's server vouches for that.
|
|
178
|
+
|
|
179
|
+
Exit codes for `publish-lock`, `lock-of` and lookup refusals: 2 no key / no name / bad derivation · 3 not signed in · 4 no Sui address on file, or the wrong key · 5 bad signature, lock or name · 6 server or network (including a lookup that is not live) · 7 nothing published · 8 published but does not verify.
|
|
180
|
+
|
|
152
181
|
## Wallets
|
|
153
182
|
|
|
154
183
|
Every actor — human or agent — gets real, self-custodied multi-chain wallets. The CLI reads and writes the same `wallet:*` receivers `/w` uses:
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oneie",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"build": "tsc && cp package.json dist/ && chmod +x dist/src/index.js",
|
|
16
16
|
"dev": "tsx src/index.ts",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
|
-
"test": "bash ../../.claude/scripts/gate-run.sh test-cli -- vitest run",
|
|
18
|
+
"test": "bash ../../.claude/scripts/gate-run.sh test-cli -- ./node_modules/.bin/vitest run",
|
|
19
19
|
"prepublishOnly": "bun run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
package/dist/src/index.js
CHANGED
|
@@ -20,6 +20,9 @@ import { setupCmd } from './setup.js';
|
|
|
20
20
|
import { clientCmd } from './client.js';
|
|
21
21
|
import { walletCmd } from './wallet.js';
|
|
22
22
|
import { keyCmd } from './key.js';
|
|
23
|
+
import { secretsCmd } from './secrets.js';
|
|
24
|
+
import { runCmd } from './secrets-run.js';
|
|
25
|
+
import { writeCmd } from './write.js';
|
|
23
26
|
import { pushCmd } from './push.js';
|
|
24
27
|
import { deployCmd } from './deploy.js';
|
|
25
28
|
import { statusCmd } from './status.js';
|
|
@@ -40,6 +43,7 @@ import { drawCmd } from './draw.js';
|
|
|
40
43
|
import { endpointCmd } from './endpoint.js';
|
|
41
44
|
import { shopCmd } from './shop.js';
|
|
42
45
|
import { bareDoors, joinCommands } from './join.js';
|
|
46
|
+
import { startCmd, startArgv } from './start.js';
|
|
43
47
|
import { bareMessageArgv } from './message.js';
|
|
44
48
|
import { readFileSync } from 'node:fs';
|
|
45
49
|
import { fileURLToPath } from 'node:url';
|
|
@@ -72,6 +76,9 @@ program.addCommand(whoamiCmd());
|
|
|
72
76
|
program.addCommand(buildLoginCommand());
|
|
73
77
|
program.addCommand(walletCmd());
|
|
74
78
|
program.addCommand(keyCmd());
|
|
79
|
+
program.addCommand(secretsCmd());
|
|
80
|
+
program.addCommand(runCmd());
|
|
81
|
+
program.addCommand(writeCmd());
|
|
75
82
|
program.addCommand(pushCmd());
|
|
76
83
|
program.addCommand(deployCmd());
|
|
77
84
|
program.addCommand(statusCmd());
|
|
@@ -92,23 +99,16 @@ program.addCommand(mediaCmd());
|
|
|
92
99
|
program.addCommand(drawCmd());
|
|
93
100
|
program.addCommand(endpointCmd());
|
|
94
101
|
program.addCommand(shopCmd());
|
|
102
|
+
program.addCommand(startCmd());
|
|
95
103
|
joinCommands(program);
|
|
96
|
-
|
|
97
|
-
// journey
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
process.stdout.write('oneie — no workspace yet.\n' + bareDoors(true));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
displayBanner();
|
|
106
|
-
process.stdout.write(bareDoors(false));
|
|
107
|
-
}
|
|
108
|
-
process.exit(0);
|
|
109
|
-
}
|
|
104
|
+
program.addHelpText('after', '\n' + bareDoors(isAgentEnvironment()));
|
|
105
|
+
// Bare `oneie` (no args) runs the journey in this folder — key → products →
|
|
106
|
+
// test sale → handover link (`start.ts`). A re-run resumes from the first step
|
|
107
|
+
// whose proof is not on disk yet. `oneie --help` still lists every other door.
|
|
108
|
+
if (process.argv.length === 2 && !isAgentEnvironment())
|
|
109
|
+
displayBanner();
|
|
110
110
|
const known = new Set(['help', ...program.commands.flatMap((c) => [c.name(), ...c.aliases()])]);
|
|
111
|
-
program.parseAsync(bareMessageArgv(process.argv, known)).catch((err) => {
|
|
111
|
+
program.parseAsync(bareMessageArgv(startArgv(process.argv), known)).catch((err) => {
|
|
112
112
|
const isJson = process.argv.includes('--json');
|
|
113
113
|
if (isJson)
|
|
114
114
|
process.stdout.write(JSON.stringify({ ok: false, error: err.message }) + '\n');
|
package/dist/src/init.d.ts
CHANGED
|
@@ -8,11 +8,19 @@
|
|
|
8
8
|
* No prior account or API key required. The server mints everything.
|
|
9
9
|
*/
|
|
10
10
|
import { Command } from 'commander';
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Where the new wallet goes. A vault by default; plaintext only on the flag.
|
|
13
|
+
* `keychain` seals it under a random secret held in Apple Keychain — the store an
|
|
14
|
+
* agent shell can use, since it has no terminal to type a passphrase into and its
|
|
15
|
+
* stdout must never carry the words. Touch ID opens it later.
|
|
16
|
+
*/
|
|
12
17
|
export type WalletStore = {
|
|
13
18
|
kind: 'vault';
|
|
14
19
|
dir: string;
|
|
15
20
|
passphrase: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'keychain';
|
|
23
|
+
dir: string;
|
|
16
24
|
} | {
|
|
17
25
|
kind: 'plaintext';
|
|
18
26
|
file: string;
|
|
@@ -48,6 +56,7 @@ export declare function provisionLocalWallet(opts: {
|
|
|
48
56
|
ok: boolean;
|
|
49
57
|
file?: string;
|
|
50
58
|
sealed?: boolean;
|
|
59
|
+
keychain?: boolean;
|
|
51
60
|
addresses?: Record<string, string>;
|
|
52
61
|
error?: string;
|
|
53
62
|
}>;
|
package/dist/src/init.js
CHANGED
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
* No prior account or API key required. The server mints everything.
|
|
9
9
|
*/
|
|
10
10
|
import { Command } from 'commander';
|
|
11
|
-
import { mkdirSync, existsSync } from 'node:fs';
|
|
11
|
+
import { mkdirSync, existsSync, rmSync } from 'node:fs';
|
|
12
12
|
import { resolve, dirname } from 'node:path';
|
|
13
13
|
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
14
14
|
import { writeKeyFolder } from './lib/keyfile.js';
|
|
15
15
|
import { KEY_FILE, CONFIG_DIR, writeMachineKey } from './lib/paths.js';
|
|
16
16
|
import { walletFor, writeKeysFile, registerAgentWallet, sealWallet, promptSecret } from './wallet.js';
|
|
17
|
-
import { writeVaultFolder, vaultPath } from './lib/vaultfile.js';
|
|
17
|
+
import { writeVaultFolder, vaultPath, keychainStore } from './lib/vaultfile.js';
|
|
18
|
+
import { mintKeychainSecret } from '@oneie/sdk/vault-file';
|
|
18
19
|
import { cliPrefix } from './lib/invoked-as.js';
|
|
19
20
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
20
21
|
function out(cmd, data) {
|
|
@@ -74,7 +75,7 @@ export function initWalletRefusal(o) {
|
|
|
74
75
|
* four addresses and one signature per address over its own fresh challenge.
|
|
75
76
|
*/
|
|
76
77
|
export async function provisionLocalWallet(opts) {
|
|
77
|
-
const target = opts.store.kind === '
|
|
78
|
+
const target = opts.store.kind === 'plaintext' ? opts.store.file : vaultPath(opts.store.dir);
|
|
78
79
|
// Never replace a wallet: it may hold the only copy of the words behind
|
|
79
80
|
// addresses already registered and funded (`wallet new` refuses the same way).
|
|
80
81
|
if (existsSync(target)) {
|
|
@@ -82,24 +83,36 @@ export async function provisionLocalWallet(opts) {
|
|
|
82
83
|
}
|
|
83
84
|
try {
|
|
84
85
|
const { wallet, derivation } = await walletFor({}, () => '');
|
|
85
|
-
if (opts.store.kind
|
|
86
|
+
if (opts.store.kind !== 'plaintext') {
|
|
86
87
|
const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
|
|
87
|
-
const
|
|
88
|
+
const keychain = opts.store.kind === 'keychain';
|
|
89
|
+
const secret = keychain ? mintKeychainSecret() : opts.store.passphrase;
|
|
90
|
+
const blob = await sealWallet(wallet.mnemonic, secret, { wrap: keychain ? 'keychain' : 'passphrase', authPub, derivation });
|
|
88
91
|
const written = writeVaultFolder(opts.store.dir, { ...blob });
|
|
89
92
|
if (!written.ok)
|
|
90
93
|
return { ok: false, file: target, error: written.error ?? 'vault not written' };
|
|
94
|
+
if (keychain) {
|
|
95
|
+
const k = keychainStore(authPub, secret);
|
|
96
|
+
// A vault sealed under a secret nobody holds is a wallet nobody can open.
|
|
97
|
+
// Remove it before any address is registered, the way `wallet new --keychain` does.
|
|
98
|
+
if (!k.ok) {
|
|
99
|
+
rmSync(written.path, { force: true });
|
|
100
|
+
return { ok: false, file: target, error: `keychain_write_failed (${k.error}) — the wallet was removed, nothing was registered` };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
91
103
|
}
|
|
92
104
|
else {
|
|
93
105
|
mkdirSync(dirname(opts.store.file), { recursive: true, mode: 0o700 });
|
|
94
106
|
writeKeysFile(opts.store.file, JSON.stringify({ mnemonic: wallet.mnemonic, derivation, keys: wallet.keys, workspace: opts.workspace }, null, 2) + '\n', true);
|
|
95
107
|
}
|
|
96
|
-
const sealed = opts.store.kind
|
|
108
|
+
const sealed = opts.store.kind !== 'plaintext';
|
|
109
|
+
const keychain = opts.store.kind === 'keychain';
|
|
97
110
|
const res = await registerAgentWallet({
|
|
98
111
|
base: opts.api.replace(/\/$/, ''), key: opts.key, workspace: opts.workspace, actor: opts.workspace, keys: wallet.keys,
|
|
99
112
|
});
|
|
100
113
|
if (!res.ok)
|
|
101
|
-
return { ok: false, file: target, sealed, error: String(res.error ?? 'wallet:create refused') };
|
|
102
|
-
return { ok: true, file: target, sealed, addresses: (res.addresses ?? {}) };
|
|
114
|
+
return { ok: false, file: target, sealed, keychain, error: String(res.error ?? 'wallet:create refused') };
|
|
115
|
+
return { ok: true, file: target, sealed, keychain, addresses: (res.addresses ?? {}) };
|
|
103
116
|
}
|
|
104
117
|
catch (err) {
|
|
105
118
|
return { ok: false, file: target, error: err.message };
|
|
@@ -115,9 +128,11 @@ export async function provisionLocalWallet(opts) {
|
|
|
115
128
|
export function initWalletReceipt(wallet, o) {
|
|
116
129
|
const atVault = resolve(o.vaultDir) === resolve(o.dir) ? '' : ` --dir ${o.vaultDir}`;
|
|
117
130
|
return {
|
|
118
|
-
wallet: wallet.
|
|
119
|
-
? `${wallet.file} (sealed
|
|
120
|
-
:
|
|
131
|
+
wallet: wallet.keychain
|
|
132
|
+
? `${wallet.file} (sealed in Apple Keychain — Touch ID opens it; run \`${o.cli} wallet paper${atVault}\` in your own terminal to write the 24 words down)`
|
|
133
|
+
: wallet.sealed
|
|
134
|
+
? `${wallet.file} (sealed with your passphrase — \`${o.cli} wallet open${atVault}\` to read it, \`${o.cli} wallet paper${atVault}\` to back it up)`
|
|
135
|
+
: `${wallet.file} (0600 PLAINTEXT — the 24 words and keys; back it up, never commit it)`,
|
|
121
136
|
...(wallet.ok ? { addresses: Object.entries(wallet.addresses ?? {}).filter(([, a]) => a).map(([c, a]) => `${c} ${a}`).join(', ') } : {}),
|
|
122
137
|
...(!wallet.ok ? { wallet_error: wallet.sealed === false
|
|
123
138
|
? `${wallet.error} — retry: ${o.cli} wallet register --kind agent --workspace ${o.workspace} --from ${wallet.file}`
|
package/dist/src/join.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
export declare const JOIN_VERBS: readonly ["request", "requests", "approve"];
|
|
3
|
-
/** The door block
|
|
3
|
+
/** The door block `oneie --help` ends with. Bare `oneie` runs the journey instead (start.ts). */
|
|
4
4
|
export declare function bareDoors(agent: boolean): string;
|
|
5
5
|
export declare function joinCommands(program: Command): void;
|
|
6
6
|
/**
|
package/dist/src/join.js
CHANGED
|
@@ -14,13 +14,14 @@ const DEFAULT_API = 'https://one.ie';
|
|
|
14
14
|
const ROLES = ['viewer', 'member', 'admin'];
|
|
15
15
|
const STATUSES = ['pending', 'approved', 'rejected'];
|
|
16
16
|
export const JOIN_VERBS = ['request', 'requests', 'approve'];
|
|
17
|
-
/** The door block
|
|
17
|
+
/** The door block `oneie --help` ends with. Bare `oneie` runs the journey instead (start.ts). */
|
|
18
18
|
export function bareDoors(agent) {
|
|
19
19
|
const newGroup = agent
|
|
20
20
|
? ' oneie init --write-env # provision a group, no account required\n' +
|
|
21
21
|
' oneie onboard # provision + walk the lifecycle stages\n'
|
|
22
22
|
: ' npx oneie create <name> # scaffold a new group\n';
|
|
23
23
|
return ('new group:\n' +
|
|
24
|
+
' npx oneie [--email <owner>] # key → products → test sale → handover link\n' +
|
|
24
25
|
newGroup +
|
|
25
26
|
'existing group:\n' +
|
|
26
27
|
' oneie login # become someone — no new group\n' +
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-publish.ts — `one key publish-lock | lock-of`: put a lock under a name, and read one back
|
|
3
|
+
* with the check made HERE.
|
|
4
|
+
*
|
|
5
|
+
* publish-lock derive this key's lock (same as `one key lock`), sign the text
|
|
6
|
+
* "ONE message lock v1\n<name>\n<lock>" with this key's Sui account-0
|
|
7
|
+
* key, and send {lock, signature} to `wallet:lock-publish`.
|
|
8
|
+
* lock-of GET /api/lock/<name>, rebuild the text, check the signature, print the lock.
|
|
9
|
+
*
|
|
10
|
+
* WHAT GOES ON THE WIRE: the lock and the signature. Never the words, never a secret, and
|
|
11
|
+
* not the name — the server signs-over the name of the key's own session, so a name in
|
|
12
|
+
* the body would be ignored (the request schema has no field for it, and the edge strips
|
|
13
|
+
* unknown ones). That makes the NAME a thing this command must get right on its own: it
|
|
14
|
+
* signs for `--slug` (else AGENCY_SLUG / WORKSPACE_SLUG, the way `one whoami` reads them),
|
|
15
|
+
* and every success and every refusal says which name it signed for. A key that belongs to
|
|
16
|
+
* another name comes back `bad_signature`, and the sentence says so.
|
|
17
|
+
*
|
|
18
|
+
* THE SUI KEY IS THE SAME KEY THE WALLETS USE — `recoverWallet(words, derivation)` from
|
|
19
|
+
* @oneie/sdk/wallet, the account-0 Sui key /keys derives, no second derivation. Derivation
|
|
20
|
+
* is v2 only when the key file says so (or `--derivation v2`): an unmarked key is v1
|
|
21
|
+
* forever (wallet.ts readDerivation), and the two give different Sui addresses. A wrong
|
|
22
|
+
* guess is a `wrong_signer`, and that sentence prints both addresses so the fix is a flag.
|
|
23
|
+
*
|
|
24
|
+
* WHO CAN PUBLISH — a PERSON publishes under their name with their login key (`one login`).
|
|
25
|
+
* An AGENT publishes under `<workspace>/<agent-id>` with `--agent <its id>`, authenticated by
|
|
26
|
+
* ITS OWN API key: the door takes the agent from that key and refuses a person, an owner,
|
|
27
|
+
* the service key or another agent (`not_the_agent`) however the body is worded. The Sui key
|
|
28
|
+
* that signs must be the address on the agent's wallet row (`one wallet register --kind
|
|
29
|
+
* agent` proves it); a shell row answers `no_sui_address`. `--workspace` picks which of the
|
|
30
|
+
* agent's rows (default: the agent's own id, the self-registered shape) and grants nothing.
|
|
31
|
+
* The service key sends no name at all (`unauthorized`).
|
|
32
|
+
*
|
|
33
|
+
* No prompts, no stdin: an agent runs this. Exit codes are in lib/lock-lookup.ts EXIT.
|
|
34
|
+
*/
|
|
35
|
+
import { Command } from 'commander';
|
|
36
|
+
/** Swappable in tests: the API key the ask door will be sent. */
|
|
37
|
+
export declare const auth: {
|
|
38
|
+
key: () => string;
|
|
39
|
+
};
|
|
40
|
+
export declare function keyPublishCommands(): Command[];
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-publish.ts — `one key publish-lock | lock-of`: put a lock under a name, and read one back
|
|
3
|
+
* with the check made HERE.
|
|
4
|
+
*
|
|
5
|
+
* publish-lock derive this key's lock (same as `one key lock`), sign the text
|
|
6
|
+
* "ONE message lock v1\n<name>\n<lock>" with this key's Sui account-0
|
|
7
|
+
* key, and send {lock, signature} to `wallet:lock-publish`.
|
|
8
|
+
* lock-of GET /api/lock/<name>, rebuild the text, check the signature, print the lock.
|
|
9
|
+
*
|
|
10
|
+
* WHAT GOES ON THE WIRE: the lock and the signature. Never the words, never a secret, and
|
|
11
|
+
* not the name — the server signs-over the name of the key's own session, so a name in
|
|
12
|
+
* the body would be ignored (the request schema has no field for it, and the edge strips
|
|
13
|
+
* unknown ones). That makes the NAME a thing this command must get right on its own: it
|
|
14
|
+
* signs for `--slug` (else AGENCY_SLUG / WORKSPACE_SLUG, the way `one whoami` reads them),
|
|
15
|
+
* and every success and every refusal says which name it signed for. A key that belongs to
|
|
16
|
+
* another name comes back `bad_signature`, and the sentence says so.
|
|
17
|
+
*
|
|
18
|
+
* THE SUI KEY IS THE SAME KEY THE WALLETS USE — `recoverWallet(words, derivation)` from
|
|
19
|
+
* @oneie/sdk/wallet, the account-0 Sui key /keys derives, no second derivation. Derivation
|
|
20
|
+
* is v2 only when the key file says so (or `--derivation v2`): an unmarked key is v1
|
|
21
|
+
* forever (wallet.ts readDerivation), and the two give different Sui addresses. A wrong
|
|
22
|
+
* guess is a `wrong_signer`, and that sentence prints both addresses so the fix is a flag.
|
|
23
|
+
*
|
|
24
|
+
* WHO CAN PUBLISH — a PERSON publishes under their name with their login key (`one login`).
|
|
25
|
+
* An AGENT publishes under `<workspace>/<agent-id>` with `--agent <its id>`, authenticated by
|
|
26
|
+
* ITS OWN API key: the door takes the agent from that key and refuses a person, an owner,
|
|
27
|
+
* the service key or another agent (`not_the_agent`) however the body is worded. The Sui key
|
|
28
|
+
* that signs must be the address on the agent's wallet row (`one wallet register --kind
|
|
29
|
+
* agent` proves it); a shell row answers `no_sui_address`. `--workspace` picks which of the
|
|
30
|
+
* agent's rows (default: the agent's own id, the self-registered shape) and grants nothing.
|
|
31
|
+
* The service key sends no name at all (`unauthorized`).
|
|
32
|
+
*
|
|
33
|
+
* No prompts, no stdin: an agent runs this. Exit codes are in lib/lock-lookup.ts EXIT.
|
|
34
|
+
*/
|
|
35
|
+
import { Command } from 'commander';
|
|
36
|
+
import { readFileSync } from 'node:fs';
|
|
37
|
+
import { readDerivation, recoverWallet } from '@oneie/sdk/wallet';
|
|
38
|
+
import { mergeEnv } from './env.js';
|
|
39
|
+
import { askPath } from './lib/api-path.js';
|
|
40
|
+
import { authHeaders, jsonMode, resolveBase, resolveKey } from './lib/client.js';
|
|
41
|
+
import { exitFor, lookupLock, TRUST_LIMIT } from './lib/lock-lookup.js';
|
|
42
|
+
import { keyWords, loadMessageKey } from './lib/message-seal.js';
|
|
43
|
+
import { writeBase } from './write.js';
|
|
44
|
+
const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
45
|
+
const AGENT_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
46
|
+
const DEADLINE_MS = 15_000;
|
|
47
|
+
/** Swappable in tests: the API key the ask door will be sent. */
|
|
48
|
+
export const auth = { key: () => resolveKey({}) };
|
|
49
|
+
function refuse(cmd, f) {
|
|
50
|
+
if (jsonMode(cmd))
|
|
51
|
+
process.stdout.write(JSON.stringify(f) + '\n');
|
|
52
|
+
else
|
|
53
|
+
process.stderr.write(`error ${f.error}\n`);
|
|
54
|
+
process.exitCode = exitFor(f.code);
|
|
55
|
+
}
|
|
56
|
+
/** The derivation the Sui key is read under: --derivation, else the key file's marker, else v1. */
|
|
57
|
+
function derivationFor(flag, keyPath) {
|
|
58
|
+
let marker = flag;
|
|
59
|
+
if (flag === undefined && keyPath) {
|
|
60
|
+
try {
|
|
61
|
+
marker = JSON.parse(readFileSync(keyPath, 'utf8')).derivation;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
marker = undefined; // not JSON (a bare phrase file) or unreadable — keyWords reports that one
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return readDerivation(marker);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return { ok: false, error: `the derivation is "v1" or "v2", not ${JSON.stringify(String(marker))}`, code: 'bad_derivation' };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const hexBytes = (h) => Uint8Array.from(h.match(/../g) ?? [], (b) => parseInt(b, 16));
|
|
75
|
+
/** The sentence for each way `wallet:lock-publish` can refuse. */
|
|
76
|
+
function serverRefusal(error, ctx) {
|
|
77
|
+
const who = ctx.agent === undefined ? ctx.slug : `${ctx.slug}/${ctx.agent}`;
|
|
78
|
+
const other = ctx.derivation === 'v1' ? 'v2' : 'v1';
|
|
79
|
+
switch (error) {
|
|
80
|
+
case 'unauthorized':
|
|
81
|
+
return { ok: false, code: error, error: 'you are not signed in — the key sent was refused, or the door could not tell whose it is. Sign in with `one login` (a person\'s login key; a service key names no one)' };
|
|
82
|
+
case 'no_sui_address':
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
code: error,
|
|
86
|
+
error: ctx.agent === undefined
|
|
87
|
+
? 'your account has no Sui address on file — a person account needs a registered Sui wallet: open Wallets on one.ie once, then try again. An agent publishes with --agent <its id>'
|
|
88
|
+
: `the agent ${who} has no Sui address on file — register one with proof of control first (\`one wallet register --kind agent\`), then try again`,
|
|
89
|
+
};
|
|
90
|
+
case 'not_the_agent':
|
|
91
|
+
return { ok: false, code: error, error: `only the agent itself can publish ${who}: run this with the agent's own API key, and --agent set to that agent's id. A person, an owner or another agent is refused. Nothing was published` };
|
|
92
|
+
case 'bad_agent':
|
|
93
|
+
return { ok: false, code: error, error: `"${ctx.agent ?? ''}" is not an agent name — letters, digits, dots, dashes or underscores. Nothing was published` };
|
|
94
|
+
case 'wrong_signer':
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
code: error,
|
|
98
|
+
error: `the key used here is not the Sui key ${ctx.agent === undefined ? 'your account' : `${who}`} has on file, so nothing was published. This key's Sui address is ${ctx.suiV1} under v1 and ${ctx.suiV2} under v2; this run signed with ${ctx.derivation}. If your account registered the other one, add --derivation ${other}`,
|
|
99
|
+
};
|
|
100
|
+
case 'bad_signature':
|
|
101
|
+
return { ok: false, code: error, error: ctx.agent === undefined ? `the signature did not check out for the name "${ctx.slug}" — nothing was published. The server signs for the name your login key belongs to; if that is not "${ctx.slug}", pass --slug <your name>` : `the signature did not check out for "${who}" — nothing was published. Check --agent and --workspace` };
|
|
102
|
+
case 'bad_lock':
|
|
103
|
+
return { ok: false, code: error, error: 'that is not a lock — it should be age1 followed by 58 characters. Nothing was published' };
|
|
104
|
+
case 'bad_slug':
|
|
105
|
+
return { ok: false, code: error, error: 'the server says your account name is not a name it can file a lock under — nothing was published' };
|
|
106
|
+
case 'db_error':
|
|
107
|
+
case 'no_db':
|
|
108
|
+
return { ok: false, code: error, error: 'the server could not save the lock right now — nothing was published; try again in a moment' };
|
|
109
|
+
default:
|
|
110
|
+
return { ok: false, code: error, error: `the server refused it (${error}) — nothing was published` };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function keyPublishCommands() {
|
|
114
|
+
const publish = new Command('publish-lock')
|
|
115
|
+
.description('Publish this key\'s lock under your name, signed with its Sui key — so anyone can look it up and check it (a person account with a registered Sui address)')
|
|
116
|
+
.option('--key <file>', 'Key file made by `one key new --out` (else ONE_WALLET_MNEMONIC). Never read from stdin')
|
|
117
|
+
.option('--slug <name>', 'The name to publish under — the name your login key belongs to (else AGENCY_SLUG / WORKSPACE_SLUG)')
|
|
118
|
+
.option('--agent <id>', 'Publish an AGENT\'s own lock as <workspace>/<id>. Run it with that agent\'s own API key; a person or owner is refused')
|
|
119
|
+
.option('--workspace <name>', 'With --agent: the workspace of the agent\'s wallet row (default: the agent\'s own id, the self-registered shape)')
|
|
120
|
+
.option('--derivation <v1|v2>', 'Which Sui key: the key file\'s marker, else v1. Pass v2 for a key minted under standard paths')
|
|
121
|
+
.option('--api <url>', 'API base URL (default https://api.one.ie)')
|
|
122
|
+
.action(async (o, c) => {
|
|
123
|
+
const env = mergeEnv(process.cwd());
|
|
124
|
+
const agent = o.agent?.trim();
|
|
125
|
+
if (agent !== undefined && !AGENT_RE.test(agent))
|
|
126
|
+
return refuse(c, { ok: false, error: `"${agent}" is not an agent name — letters, digits, dots, dashes or underscores`, code: 'bad_agent' });
|
|
127
|
+
// An agent's name is its workspace (default: its own id) — the env slug is NOT read, since
|
|
128
|
+
// that is usually the person's, and a text signed for the wrong name is only refused later.
|
|
129
|
+
const slug = (agent !== undefined ? (o.workspace ?? agent) : (o.slug ?? env.AGENCY_SLUG ?? env.WORKSPACE_SLUG ?? '')).trim().toLowerCase();
|
|
130
|
+
if (!slug)
|
|
131
|
+
return refuse(c, { ok: false, error: 'which name? pass --slug <your name> — the name your login key belongs to', code: 'no_slug' });
|
|
132
|
+
if (!SLUG_RE.test(slug))
|
|
133
|
+
return refuse(c, { ok: false, error: `"${slug}" is not a name — lowercase letters, digits and dashes`, code: 'bad_slug' });
|
|
134
|
+
const derivation = derivationFor(o.derivation, o.key);
|
|
135
|
+
if (typeof derivation !== 'string')
|
|
136
|
+
return refuse(c, derivation);
|
|
137
|
+
const words = keyWords(o.key);
|
|
138
|
+
if (typeof words !== 'string')
|
|
139
|
+
return refuse(c, words);
|
|
140
|
+
if (!auth.key())
|
|
141
|
+
return refuse(c, { ok: false, error: 'no API key — run `one login`, or set ONE_API_KEY. Nothing was sent', code: 'no_api_key' });
|
|
142
|
+
// Everything secret stays in this block: the lock, then the signature, then zeroed.
|
|
143
|
+
const mk = await loadMessageKey(o.key);
|
|
144
|
+
if ('ok' in mk)
|
|
145
|
+
return refuse(c, mk);
|
|
146
|
+
const lock = mk.recipient;
|
|
147
|
+
mk.secret.fill(0);
|
|
148
|
+
let signature;
|
|
149
|
+
let signer;
|
|
150
|
+
let suiV1;
|
|
151
|
+
let suiV2;
|
|
152
|
+
try {
|
|
153
|
+
const { agentLockMessage, lockMessage, signSuiPersonalMessage } = await import('@oneie/sdk/message-lock');
|
|
154
|
+
const suiOf = async (d) => (await recoverWallet(words, d)).keys.find((k) => k.chain === 'sui');
|
|
155
|
+
const [k1, k2] = await Promise.all([suiOf('v1'), suiOf('v2')]);
|
|
156
|
+
suiV1 = k1.address;
|
|
157
|
+
suiV2 = k2.address;
|
|
158
|
+
const used = derivation === 'v2' ? k2 : k1;
|
|
159
|
+
const secret = hexBytes(used.privateKeyHex);
|
|
160
|
+
try {
|
|
161
|
+
const s = signSuiPersonalMessage(secret, agent === undefined ? lockMessage(slug, lock) : agentLockMessage(slug, agent, lock));
|
|
162
|
+
signature = s.signature;
|
|
163
|
+
signer = s.address;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
secret.fill(0);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
return refuse(c, { ok: false, error: e.message, code: 'bad_key' });
|
|
171
|
+
}
|
|
172
|
+
const base = resolveBase({ api: o.api }, 'https://api.one.ie');
|
|
173
|
+
const ctl = new AbortController();
|
|
174
|
+
const timer = setTimeout(() => ctl.abort(), DEADLINE_MS);
|
|
175
|
+
let res;
|
|
176
|
+
try {
|
|
177
|
+
res = await fetch(askPath(base, 'wallet:lock-publish'), {
|
|
178
|
+
method: 'POST',
|
|
179
|
+
headers: authHeaders(),
|
|
180
|
+
body: JSON.stringify({ data: agent === undefined ? { lock, signature } : { lock, signature, agent, ...(slug === agent ? {} : { workspace: slug }) } }),
|
|
181
|
+
signal: ctl.signal,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return refuse(c, { ok: false, error: `could not reach ${base} — nothing was published`, code: 'unreachable' });
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
}
|
|
190
|
+
let body = {};
|
|
191
|
+
try {
|
|
192
|
+
body = (await res.json());
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
/* judged by status below */
|
|
196
|
+
}
|
|
197
|
+
// The ask door answers 200 for refusals too: read the outcome, not just the status.
|
|
198
|
+
if (res.status === 401 || res.status === 403)
|
|
199
|
+
return refuse(c, serverRefusal('unauthorized', { slug, agent, suiV1, suiV2, derivation }));
|
|
200
|
+
if (body.outcome === 'result' && body.result) {
|
|
201
|
+
if (body.result.ok) {
|
|
202
|
+
const r = body.result;
|
|
203
|
+
const name = agent === undefined ? slug : `${slug}/${agent}`;
|
|
204
|
+
const done = { ok: true, slug, ...(agent === undefined ? {} : { agent }), name, lock, suiAddress: r.suiAddress ?? signer, publishedAt: r.publishedAt ?? null, derivation };
|
|
205
|
+
if (jsonMode(c))
|
|
206
|
+
process.stdout.write(JSON.stringify(done) + '\n');
|
|
207
|
+
else
|
|
208
|
+
process.stdout.write(`published ${lock}\n as ${name}, signed by Sui address ${done.suiAddress} (${derivation})\n anyone can check it: one key lock-of ${name}\n`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
return refuse(c, serverRefusal(String(body.result.error ?? 'failed'), { slug, agent, suiV1, suiV2, derivation }));
|
|
212
|
+
}
|
|
213
|
+
return refuse(c, { ok: false, error: `the server did not complete it (${body.outcome ?? `HTTP ${res.status}`}) — nothing was published`, code: 'failed' });
|
|
214
|
+
});
|
|
215
|
+
const lockOf = new Command('lock-of')
|
|
216
|
+
.description('Look up the lock a name has published and CHECK it here — prints the lock. Refuses if it is unpublished, unreachable, or does not verify')
|
|
217
|
+
.argument('<slug>', "The holder's name, or <workspace>/<agent-id> for an agent's own lock")
|
|
218
|
+
.option('--api <url>', 'Web base (default https://one.ie; the lookup is a web route, not on the gateway)')
|
|
219
|
+
.action(async (slugArg, o, c) => {
|
|
220
|
+
const r = await lookupLock(writeBase(o.api), slugArg.trim());
|
|
221
|
+
if (!r.ok)
|
|
222
|
+
return refuse(c, r);
|
|
223
|
+
if (jsonMode(c)) {
|
|
224
|
+
process.stdout.write(JSON.stringify({ ok: true, slug: r.slug, ...(r.agent === undefined ? {} : { agent: r.agent }), name: r.name, lock: r.lock, suiAddress: r.suiAddress, publishedAt: r.publishedAt, verified: true, trustLimit: TRUST_LIMIT }) + '\n');
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
process.stdout.write(r.lock + '\n');
|
|
228
|
+
process.stderr.write(`checked signed by Sui address ${r.suiAddress}; ${TRUST_LIMIT}\n`);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return [publish, lockOf];
|
|
232
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-seal.ts — `one key lock | seal | open | identity`: sealed notes without ONE's web page.
|
|
3
|
+
*
|
|
4
|
+
* Every command here is offline — no network — and none prompts, because an agent runs
|
|
5
|
+
* them. The key is a key file (`--key`, what `one key new --out` writes) or
|
|
6
|
+
* ONE_WALLET_MNEMONIC; the note is a file argument or stdin. Each answers `--json` and
|
|
7
|
+
* sets the exit code: 0 done, 1 refused (with a plain sentence, and a `code` under --json).
|
|
8
|
+
*
|
|
9
|
+
* lock the `age1…` lock for this key — what anyone seals a note to
|
|
10
|
+
* seal a note → an armored age block, for one or more `age1…` locks
|
|
11
|
+
* open an age block → the note, with this key
|
|
12
|
+
* identity the `AGE-SECRET-KEY-1…` line, so the stock `age -d -i` opens a note with
|
|
13
|
+
* no ONE code on the machine
|
|
14
|
+
*
|
|
15
|
+
* `identity` is the one verb that prints a secret to stdout, on purpose: the spec for
|
|
16
|
+
* this door is "age -d works with nothing else installed". A stderr warning always
|
|
17
|
+
* says so; under --json the warning is a field. Everything else in `one key` keeps its
|
|
18
|
+
* posture of never printing key material.
|
|
19
|
+
*/
|
|
20
|
+
import { Command } from 'commander';
|
|
21
|
+
export declare function keySealCommands(): Command[];
|