oneie 5.3.1 → 5.3.3

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 CHANGED
@@ -37,6 +37,20 @@ one ship "<message>" # git add + commit + push in one step
37
37
  deploys `ai/workflows/*.md` as runnable workflows — the step graph rides in a fenced
38
38
  ` ```graph ` block (`{ "steps": [...], "edges": [...] }`), prose above it is human docs.
39
39
 
40
+ ## Say it — `oneie message`
41
+
42
+ One command, no receiver names. The router picks who answers, the answer prints here, and a receipt says what it cost:
43
+
44
+ ```bash
45
+ npx oneie message "add a dark-mode toggle"
46
+ npx oneie "add a dark-mode toggle" # bare text works too: anything that is not a command or a flag
47
+ oneie message "…" --json # the whole reply as JSON (answer, model, shape, usage)
48
+ ```
49
+
50
+ The text goes to the router (`world:route`), which derives its tags on the server, picks a model, and returns the reply. The CLI waits up to 30 s. The receipt under the answer shows the model and shape (`warmed` from measured runs, `cold` if unmeasured), tokens in and out, and a cost **estimated** from those tokens at the registry price. The billed figure arrives later with the hourly gateway mirror, so it prints as `pending` with a link to the stream (the link shows `<your-group>` as a placeholder — use your own slug). Any figure the CLI could not read prints as `unmeasured`, never as `0`, and it never prints a "Nx cheaper" multiple.
51
+
52
+ Exit `0` with an answer; `1` when there is no key (it prints `not signed in — run: npx oneie login`), the call is refused, times out or comes back empty; `2` for empty text. Under `--json` it exits `0` only when the reply carries text.
53
+
40
54
  ## Reach the whole surface
41
55
 
42
56
  The receiver namespace *is* the API — discover it, then call anything:
@@ -121,6 +135,20 @@ one approve <requestId> # owner answers (--reject to refuse
121
135
 
122
136
  Bare `one` prints this door beside the new-group one and never prompts. `approve` needs `manage_members`, so an owner answers with a `one login` key — an agent-class key is refused. Every verb takes `--json` and `--api`; with no key it exits 1 pointing at `one login`.
123
137
 
138
+ ## Your key — `one key`
139
+
140
+ A key is 24 words you write on paper. ONE never holds it and cannot recover it. Every verb here runs on your machine; only `verify` calls the network, and it cannot send the key.
141
+
142
+ ```bash
143
+ one key new # mint 24 words, printed ONCE, for paper (v2: standard BIP-44 paths — what one.ie mints)
144
+ one key new --derivation v1 # the original ONE derivation (HKDF labels)
145
+ one key recover # rebuild from your words — prints BOTH address sets
146
+ one key public # the public identity + four chain addresses; both sets unless you name --derivation
147
+ one key verify # compare this key's public identity with the server: locked | verified | mismatch | unregistered
148
+ ```
149
+
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
+
124
152
  ## Wallets
125
153
 
126
154
  Every actor — human or agent — gets real, self-custodied multi-chain wallets. The CLI reads and writes the same `wallet:*` receivers `/w` uses:
@@ -132,6 +160,8 @@ one wallet register --from keys.json --workspace <slug> # register the PU
132
160
  one wallet transactions --workspace <slug> --limit 50 # unified feed across every settlement rail
133
161
  one wallet faucet <address> --chain sui # fund from testnet — sui/sol auto-fund, others return a manual URL
134
162
  one wallet send <to> --chain SUI --amount 5 --payment-tx <hash> --workspace <slug>
163
+ one wallet keygen # mint a self-hosted 4-chain wallet locally (a fresh one is v2), offline
164
+ one wallet paper # reprint the 24 words for paper — terminal only, same refusals as `one key new`
135
165
  ```
136
166
 
137
167
  `register` reads a `wallet keygen` output but transmits only its four address fields — the map it sends is built key-by-key from a fixed chain whitelist, so a `mnemonic` or `privateKey` in that file has no route onto the wire. The write is first-write-wins per chain and cannot be corrected afterwards (`address_conflict`), so it prints the addresses and asks for confirmation; `--yes` skips the prompt for scripted provisioning (needed when the JSON arrives on stdin, which leaves no terminal to answer with).
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneie",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "commander": "^12.0.0",
23
- "@oneie/sdk": "^0.16.5"
23
+ "@oneie/sdk": "^0.16.6"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "^0.2.0",
@@ -8,4 +8,47 @@
8
8
  * No prior account or API key required. The server mints everything.
9
9
  */
10
10
  import { Command } from 'commander';
11
+ /** Where the new wallet goes. A vault by default; plaintext only on the flag. */
12
+ export type WalletStore = {
13
+ kind: 'vault';
14
+ dir: string;
15
+ passphrase: string;
16
+ } | {
17
+ kind: 'plaintext';
18
+ file: string;
19
+ };
20
+ /**
21
+ * Can init store a wallet at all, before anything is provisioned? The repo's
22
+ * key-material rule (keygen --out, key new --out): words reach disk in the clear
23
+ * only behind --yes-i-accept-plaintext-file. Otherwise they are SEALED, and
24
+ * sealing needs a passphrase typed at a terminal — so a non-interactive run with
25
+ * no flag is refused by name, never quietly downgraded to plaintext.
26
+ */
27
+ export declare function initWalletRefusal(o: {
28
+ wallet: boolean;
29
+ plaintext: boolean;
30
+ interactive: boolean;
31
+ }): string | null;
32
+ /**
33
+ * Give the new agent a wallet it actually holds: mint a v2 key HERE, store it
34
+ * FIRST (sealed in the `wallet new` vault, or the 0600 plaintext file on the
35
+ * flag), then prove control of each address to the server and register it. The
36
+ * order matters — an address registered before its key is stored is an address
37
+ * nobody can ever spend from.
38
+ *
39
+ * The private key and the words never leave this machine: the server sees the
40
+ * four addresses and one signature per address over its own fresh challenge.
41
+ */
42
+ export declare function provisionLocalWallet(opts: {
43
+ api: string;
44
+ key: string;
45
+ workspace: string;
46
+ store: WalletStore;
47
+ }): Promise<{
48
+ ok: boolean;
49
+ file?: string;
50
+ sealed?: boolean;
51
+ addresses?: Record<string, string>;
52
+ error?: string;
53
+ }>;
11
54
  export declare function initCmd(): Command;
package/dist/src/init.js CHANGED
@@ -8,9 +8,13 @@
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';
12
+ import { resolve, dirname } from 'node:path';
11
13
  import { mergeEnv, writeEnvLocal } from './env.js';
12
14
  import { writeKeyFolder } from './lib/keyfile.js';
13
- import { KEY_FILE, writeMachineKey } from './lib/paths.js';
15
+ import { KEY_FILE, CONFIG_DIR, writeMachineKey } from './lib/paths.js';
16
+ import { walletFor, writeKeysFile, registerAgentWallet, sealWallet, promptSecret } from './wallet.js';
17
+ import { writeVaultFolder, vaultPath } from './lib/vaultfile.js';
14
18
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
15
19
  function out(cmd, data) {
16
20
  const isJson = cmd.parent?.opts().json;
@@ -45,6 +49,61 @@ You are ${name}. Answer questions clearly and helpfully.
45
49
  When you complete a task, summarise what you did in one sentence.
46
50
  `;
47
51
  }
52
+ /**
53
+ * Can init store a wallet at all, before anything is provisioned? The repo's
54
+ * key-material rule (keygen --out, key new --out): words reach disk in the clear
55
+ * only behind --yes-i-accept-plaintext-file. Otherwise they are SEALED, and
56
+ * sealing needs a passphrase typed at a terminal — so a non-interactive run with
57
+ * no flag is refused by name, never quietly downgraded to plaintext.
58
+ */
59
+ export function initWalletRefusal(o) {
60
+ if (!o.wallet || o.plaintext || o.interactive)
61
+ return null;
62
+ return 'wallet_passphrase_unavailable: init seals the new wallet with a passphrase typed at a terminal, and stdin is not one. ' +
63
+ 'Pass --yes-i-accept-plaintext-file to write a 0600 plaintext wallet file instead, or --no-wallet to skip the wallet';
64
+ }
65
+ /**
66
+ * Give the new agent a wallet it actually holds: mint a v2 key HERE, store it
67
+ * FIRST (sealed in the `wallet new` vault, or the 0600 plaintext file on the
68
+ * flag), then prove control of each address to the server and register it. The
69
+ * order matters — an address registered before its key is stored is an address
70
+ * nobody can ever spend from.
71
+ *
72
+ * The private key and the words never leave this machine: the server sees the
73
+ * four addresses and one signature per address over its own fresh challenge.
74
+ */
75
+ export async function provisionLocalWallet(opts) {
76
+ const target = opts.store.kind === 'vault' ? vaultPath(opts.store.dir) : opts.store.file;
77
+ // Never replace a wallet: it may hold the only copy of the words behind
78
+ // addresses already registered and funded (`wallet new` refuses the same way).
79
+ if (existsSync(target)) {
80
+ return { ok: false, file: target, error: 'wallet_file_exists (kept untouched)' };
81
+ }
82
+ try {
83
+ const { wallet, derivation } = await walletFor({}, () => '');
84
+ if (opts.store.kind === 'vault') {
85
+ const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
86
+ const blob = await sealWallet(wallet.mnemonic, opts.store.passphrase, { wrap: 'passphrase', authPub, derivation });
87
+ const written = writeVaultFolder(opts.store.dir, { ...blob });
88
+ if (!written.ok)
89
+ return { ok: false, file: target, error: written.error ?? 'vault not written' };
90
+ }
91
+ else {
92
+ mkdirSync(dirname(opts.store.file), { recursive: true, mode: 0o700 });
93
+ writeKeysFile(opts.store.file, JSON.stringify({ mnemonic: wallet.mnemonic, derivation, keys: wallet.keys, workspace: opts.workspace }, null, 2) + '\n', true);
94
+ }
95
+ const sealed = opts.store.kind === 'vault';
96
+ const res = await registerAgentWallet({
97
+ base: opts.api.replace(/\/$/, ''), key: opts.key, workspace: opts.workspace, actor: opts.workspace, keys: wallet.keys,
98
+ });
99
+ if (!res.ok)
100
+ return { ok: false, file: target, sealed, error: String(res.error ?? 'wallet:create refused') };
101
+ return { ok: true, file: target, sealed, addresses: (res.addresses ?? {}) };
102
+ }
103
+ catch (err) {
104
+ return { ok: false, file: target, error: err.message };
105
+ }
106
+ }
48
107
  export function initCmd() {
49
108
  const cmd = new Command('init')
50
109
  .description('Provision a new workspace in one command — no account required')
@@ -56,8 +115,32 @@ export function initCmd() {
56
115
  .option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory')
57
116
  .option('--dir <path>', 'Write the key into THIS project folder (.oneie/agent.key, 0600, gitignored) instead of the machine-wide ~/.config/one/key')
58
117
  .option('--ttl-days <n>', 'Key lifetime in days (default 90, max 365)')
118
+ .option('--no-wallet', 'Skip minting a local wallet and registering its addresses')
119
+ .option('--yes-i-accept-plaintext-file', 'Write the new wallet as a 0600 PLAINTEXT file instead of sealing it with a passphrase — needed for a non-interactive run')
59
120
  .action(async (opts) => {
60
121
  const dir = process.cwd();
122
+ // Decided BEFORE anything is provisioned: a refusal here creates nothing.
123
+ const plaintext = Boolean(opts.yesIAcceptPlaintextFile);
124
+ const refusal = initWalletRefusal({ wallet: opts.wallet !== false, plaintext, interactive: Boolean(process.stdin.isTTY) });
125
+ if (refusal) {
126
+ out(cmd, { ok: false, error: refusal });
127
+ process.exitCode = 1;
128
+ return;
129
+ }
130
+ let passphrase = '';
131
+ if (opts.wallet !== false && !plaintext) {
132
+ passphrase = await promptSecret('Passphrase to seal the new wallet: ');
133
+ if (passphrase !== (await promptSecret('Repeat it: '))) {
134
+ out(cmd, { ok: false, error: 'passphrases did not match — nothing was created' });
135
+ process.exitCode = 1;
136
+ return;
137
+ }
138
+ if (passphrase.length < 8) {
139
+ out(cmd, { ok: false, error: 'passphrase too short — nothing was created' });
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ }
61
144
  if (opts.writeEnv) {
62
145
  const env = mergeEnv(dir);
63
146
  if (env.ONE_API_KEY) {
@@ -100,6 +183,8 @@ export function initCmd() {
100
183
  // folder is. The ceremony writes the ignore entry BEFORE the key and
101
184
  // refuses to write a key at all if it cannot — see lib/keyfile.ts.
102
185
  let keyLocation;
186
+ let walletFile = resolve(CONFIG_DIR, 'wallets', `${workspace}.json`);
187
+ let vaultDir = dir;
103
188
  if (opts.dir) {
104
189
  const res = writeKeyFolder({
105
190
  dir: opts.dir,
@@ -115,6 +200,9 @@ export function initCmd() {
115
200
  return;
116
201
  }
117
202
  keyLocation = `${res.keyPath} (0600, ignored via ${res.ignorePath})`;
203
+ if (res.keyPath)
204
+ walletFile = resolve(dirname(res.keyPath), 'wallet.json');
205
+ vaultDir = opts.dir;
118
206
  }
119
207
  else {
120
208
  // The MACHINE key is regKey, not apiKey (text/agent-handover.md § 0). regKey's actor
@@ -128,6 +216,15 @@ export function initCmd() {
128
216
  if (opts.writeEnv) {
129
217
  writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: opts.api });
130
218
  }
219
+ // Non-fatal: the workspace exists either way. A refusal is REPORTED, with
220
+ // the file kept, so `one wallet register --kind agent --from <file>` (or
221
+ // `--dir <folder>` for the sealed vault) retries.
222
+ const wallet = opts.wallet !== false
223
+ ? await provisionLocalWallet({
224
+ api: opts.api, key: regKey || apiKey, workspace,
225
+ store: plaintext ? { kind: 'plaintext', file: walletFile } : { kind: 'vault', dir: vaultDir, passphrase },
226
+ })
227
+ : null;
131
228
  out(cmd, {
132
229
  ok: true,
133
230
  workspace,
@@ -136,6 +233,15 @@ export function initCmd() {
136
233
  ...(expiresAt ? { expires: new Date(expiresAt * 1000).toISOString() } : {}),
137
234
  ...(opts.writeEnv ? { env: `${dir}/.env.local`, mcp: 'export ONE_API_KEY before launching Claude Code — MCP reads the shell env, not .env.local directly' } : {}),
138
235
  ...(inviteUrl ? { invite: inviteUrl } : {}),
236
+ ...(wallet ? { wallet: wallet.sealed
237
+ ? `${wallet.file} (sealed with your passphrase — \`one wallet open\` to read it, \`one wallet paper\` to back it up)`
238
+ : `${wallet.file} (0600 PLAINTEXT — the 24 words and keys; back it up, never commit it)` } : {}),
239
+ ...(wallet?.ok ? { addresses: Object.entries(wallet.addresses ?? {}).filter(([, a]) => a).map(([c, a]) => `${c} ${a}`).join(', ') } : {}),
240
+ ...(wallet && !wallet.ok ? { wallet_error: wallet.sealed === false
241
+ ? `${wallet.error} — retry: one wallet register --kind agent --workspace ${workspace} --from ${wallet.file}`
242
+ : wallet.sealed === true
243
+ ? `${wallet.error} — retry: one wallet register --kind agent --workspace ${workspace} --dir ${vaultDir}`
244
+ : `${wallet.error}` } : {}),
139
245
  ...(skills.length ? { skills: skills.join(', ') } : {}),
140
246
  });
141
247
  });
@@ -28,10 +28,13 @@
28
28
  * `agent-wallet-provision.ts` writes `addressed:false` always ("no server-side
29
29
  * key material, ever"), and `isCreditOnlyWallet` keeps such an actor on credits.
30
30
  * Minting a fundable identity from an unauthenticated door would turn a free
31
- * empty-workspace faucet into a wallet faucet. Addresses arrive later, from a
32
- * separate and deliberate human ceremony: `one wallet keygen` (local BIP-39,
33
- * mnemonic never uploaded) then `one wallet register` (public addresses only,
34
- * through the four-key `addressesOnly()` whitelist). Keep the two apart.
31
+ * empty-workspace faucet into a wallet faucet. The SERVER still never does:
32
+ * addresses arrive only from a key generated on the agent's machine, and for
33
+ * an agent row only with a signature over a fresh `wallet:challenge`
34
+ * (`@oneie/sdk/address-proof`). `oneie init` now runs that ceremony itself,
35
+ * after this one, sealing the wallet in the `wallet new` vault beside the key —
36
+ * never into it, and plaintext only behind --yes-i-accept-plaintext-file
37
+ * (`provisionLocalWallet` in init.ts; `--no-wallet` skips it).
35
38
  */
36
39
  import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync, renameSync, rmSync, realpathSync, lstatSync, openSync, writeSync, closeSync, constants as FS, } from 'node:fs';
37
40
  import { randomBytes } from 'node:crypto';
@@ -42,6 +42,48 @@ export declare function faucetOk(results: Array<{
42
42
  }>): boolean;
43
43
  export declare function okWrap(result: Record<string, unknown>): Record<string, unknown>;
44
44
  export declare function walletCmd(): Command;
45
+ /**
46
+ * Register an AGENT's locally generated addresses: fetch a fresh wallet:challenge,
47
+ * sign one statement per address with the local keys, send addresses + proofs.
48
+ * The server refuses an agent address without this (`address_proof_required`).
49
+ *
50
+ * The private keys are read here and go into `proveAddresses` only; the request
51
+ * body is built from its `{ addresses, proofs }` — public bytes — and nothing else.
52
+ */
53
+ export declare function registerAgentWallet(opts: {
54
+ base: string;
55
+ key: string;
56
+ workspace: string;
57
+ actor: string;
58
+ keys: ReadonlyArray<{
59
+ chain: string;
60
+ address: string;
61
+ privateKeyHex: string;
62
+ }>;
63
+ }): Promise<Record<string, unknown>>;
64
+ /**
65
+ * Register the SEALED wallet in `dir` — the vault `oneie init` and `wallet new`
66
+ * write — by the same challenge → sign → register flow. Opens it the way
67
+ * `wallet open` does (Keychain or the typed passphrase), so a sealed agent wallet
68
+ * whose first registration failed can be retried without ever being written out
69
+ * in the clear. The words and keys stay in this process.
70
+ */
71
+ export declare function registerSealedWallet(opts: {
72
+ base: string;
73
+ key: string;
74
+ workspace: string;
75
+ actor: string;
76
+ dir: string;
77
+ io?: UnlockIO;
78
+ /** Shown the addresses before anything is sent; false cancels. */
79
+ confirmAddresses?: (addresses: Record<string, string>) => Promise<boolean>;
80
+ }): Promise<Record<string, unknown>>;
81
+ /** The `keys` array of a keygen file, or [] — read for SIGNING only, never sent. */
82
+ export declare function signingKeys(source: unknown): Array<{
83
+ chain: string;
84
+ address: string;
85
+ privateKeyHex: string;
86
+ }>;
45
87
  /**
46
88
  * Reduce ANY keygen-shaped object to public receiving addresses. This is a
47
89
  * whitelist build, never a spread or a delete-list: the returned object is
@@ -54,3 +96,32 @@ export declare function addressesOnly(source: unknown): Record<string, string>;
54
96
  export declare function writeKeysFile(filePath: string, contents: string, accepted: boolean): void;
55
97
  /** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
56
98
  export declare function promptSecret(prompt: string): Promise<string>;
99
+ type Unlocked = {
100
+ blob: VaultBlob;
101
+ mnemonic: string;
102
+ addresses: Record<string, string>;
103
+ keys: GeneratedWallet['keys'];
104
+ };
105
+ /** Where a vault's passphrase can come from. Injectable so the refusal is testable. */
106
+ export interface UnlockIO {
107
+ interactive: boolean;
108
+ readPassphrase: (prompt: string) => Promise<string>;
109
+ readKeychain: (authPub: string) => {
110
+ ok: boolean;
111
+ value?: string;
112
+ error?: string;
113
+ };
114
+ }
115
+ /**
116
+ * Open the folder's vault, asking Keychain or the human depending on how it was
117
+ * SEALED. `wrap` is what makes this possible: without it a keychain vault is
118
+ * indistinguishable from a passphrase one and the only way to find out is to
119
+ * prompt for a passphrase that was never set.
120
+ *
121
+ * A passphrase vault with no terminal has no passphrase source — the passphrase
122
+ * is never read from argv, env or a pipe — so it is refused BY NAME, the same
123
+ * name `oneie init` refuses with, rather than surfacing promptSecret's throw.
124
+ */
125
+ export declare function unlock(dir: string, io?: UnlockIO): Promise<Unlocked | {
126
+ error: string;
127
+ }>;
@@ -4,6 +4,7 @@ import { writeFileSync, chmodSync, readFileSync, existsSync, rmSync } from 'node
4
4
  import { createInterface } from 'node:readline';
5
5
  import { generateWallet, recoverWallet, readDerivation } from '@oneie/sdk/wallet';
6
6
  import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
7
+ import { proveAddresses } from '@oneie/sdk/address-proof';
7
8
  import { askPath } from './lib/api-path.js';
8
9
  import { wordsStdoutRefusal } from './lib/agent-env.js';
9
10
  import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
@@ -190,9 +191,10 @@ export function walletCmd() {
190
191
  out(cmd, okWrap(result));
191
192
  });
192
193
  cmd.command('register')
193
- .description('Register a keygen output\'s PUBLIC receiving addresses with a workspace — reads addresses only, never a key or a mnemonic. First write wins per chain and is permanent')
194
+ .description('Register a keygen output\'s PUBLIC receiving addresses with a workspace — sends addresses only, never a key or a mnemonic. With --kind agent the keys in --from (or the sealed wallet in --dir) sign a server challenge locally, and only the signatures are sent. First write wins per chain and is permanent')
194
195
  .option('--from <file>', 'A `wallet keygen --out` file (or any JSON with `addresses` / `keys`) — only the address fields are read')
195
196
  .option('--addresses <json>', 'Inline JSON address map, e.g. \'{"sui":"0x…","evm":"0x…"}\'')
197
+ .option('--dir <path>', 'With --kind agent: open the SEALED wallet in this project folder (what `oneie init` / `wallet new` write) — passphrase at the terminal, or Touch ID for a keychain wallet — and register it by proof')
196
198
  .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
197
199
  .option('--actor <id>', 'Actor to register for (defaults to workspace)')
198
200
  .option('--kind <kind>', 'human | agent', 'human')
@@ -202,6 +204,28 @@ export function walletCmd() {
202
204
  .action(async (opts) => {
203
205
  const { base, key } = resolveAuth(opts);
204
206
  const workspace = resolveWorkspace(opts.workspace);
207
+ if (opts.dir !== undefined) {
208
+ if (opts.from || opts.addresses) {
209
+ out(cmd, { ok: false, error: '--dir opens a sealed wallet — pass it alone, not with --from or --addresses' });
210
+ return;
211
+ }
212
+ if (opts.kind !== 'agent') {
213
+ out(cmd, { ok: false, error: '--dir registers by proof, which is the agent path — pass --kind agent' });
214
+ return;
215
+ }
216
+ const actor = opts.actor ?? workspace;
217
+ out(cmd, await registerSealedWallet({
218
+ base, key, workspace, actor, dir: opts.dir,
219
+ confirmAddresses: async (addresses) => {
220
+ process.stderr.write(`Registering PUBLIC receiving addresses for actor '${actor}' in workspace '${workspace}':\n`);
221
+ for (const [chain, addr] of Object.entries(addresses))
222
+ process.stderr.write(` ${chain.padEnd(7)} ${addr}\n`);
223
+ process.stderr.write('This is permanent — the first address written to a chain cannot be changed.\n');
224
+ return Boolean(opts.yes) || confirm('Register these addresses? [y/N] ');
225
+ },
226
+ }));
227
+ return;
228
+ }
205
229
  const source = opts.from
206
230
  ? JSON.parse(readFileSync(opts.from, 'utf8'))
207
231
  : opts.addresses
@@ -224,6 +248,18 @@ export function walletCmd() {
224
248
  out(cmd, { ok: false, error: 'cancelled' });
225
249
  return;
226
250
  }
251
+ // An agent's addresses are taken only with proof of control, so an agent
252
+ // registration signs locally with the keygen file's keys — inline
253
+ // --addresses carries no keys and cannot prove anything.
254
+ if (opts.kind === 'agent') {
255
+ const keys = signingKeys(source);
256
+ if (keys.length === 0) {
257
+ out(cmd, { ok: false, error: 'an agent registration signs a server challenge — pass --from <a `wallet keygen --out` file> holding the keys' });
258
+ return;
259
+ }
260
+ out(cmd, await registerAgentWallet({ base, key, workspace, actor, keys }));
261
+ return;
262
+ }
227
263
  // `actor`, not `opts.actor` — what the operator confirmed on screen is what gets
228
264
  // written, rather than relying on the resolver's own default to agree.
229
265
  const result = await ask(base, key, 'wallet:create', { workspace, actor, kind: opts.kind, addresses });
@@ -386,6 +422,47 @@ export function walletCmd() {
386
422
  });
387
423
  return cmd;
388
424
  }
425
+ /**
426
+ * Register an AGENT's locally generated addresses: fetch a fresh wallet:challenge,
427
+ * sign one statement per address with the local keys, send addresses + proofs.
428
+ * The server refuses an agent address without this (`address_proof_required`).
429
+ *
430
+ * The private keys are read here and go into `proveAddresses` only; the request
431
+ * body is built from its `{ addresses, proofs }` — public bytes — and nothing else.
432
+ */
433
+ export async function registerAgentWallet(opts) {
434
+ const issued = okWrap(await ask(opts.base, opts.key, 'wallet:challenge', { workspace: opts.workspace, actor: opts.actor }));
435
+ if (!issued.ok || typeof issued.challenge !== 'string')
436
+ return { ok: false, error: issued.error ?? 'no challenge issued' };
437
+ const { addresses, proofs } = proveAddresses(opts.keys, {
438
+ challenge: issued.challenge, workspace: opts.workspace, actor: opts.actor,
439
+ });
440
+ if (Object.keys(addresses).length === 0)
441
+ return { ok: false, error: 'no signable keys — expected a `keys` array of { chain, address, privateKeyHex }' };
442
+ return okWrap(await ask(opts.base, opts.key, 'wallet:create', {
443
+ workspace: opts.workspace, actor: opts.actor, kind: 'agent', addresses, challenge: issued.challenge, proofs,
444
+ }));
445
+ }
446
+ /**
447
+ * Register the SEALED wallet in `dir` — the vault `oneie init` and `wallet new`
448
+ * write — by the same challenge → sign → register flow. Opens it the way
449
+ * `wallet open` does (Keychain or the typed passphrase), so a sealed agent wallet
450
+ * whose first registration failed can be retried without ever being written out
451
+ * in the clear. The words and keys stay in this process.
452
+ */
453
+ export async function registerSealedWallet(opts) {
454
+ const opened = await unlock(opts.dir, opts.io);
455
+ if ('error' in opened)
456
+ return { ok: false, error: opened.error };
457
+ if (opts.confirmAddresses && !(await opts.confirmAddresses(opened.addresses)))
458
+ return { ok: false, error: 'cancelled' };
459
+ return registerAgentWallet({ base: opts.base, key: opts.key, workspace: opts.workspace, actor: opts.actor, keys: opened.keys });
460
+ }
461
+ /** The `keys` array of a keygen file, or [] — read for SIGNING only, never sent. */
462
+ export function signingKeys(source) {
463
+ const keys = (source && typeof source === 'object' ? source['keys'] : undefined);
464
+ return (Array.isArray(keys) ? keys : []).filter((k) => !!k && typeof k.chain === 'string' && typeof k.address === 'string' && typeof k.privateKeyHex === 'string');
465
+ }
389
466
  // Chain-name spellings a keygen output may use -> the four columns wallet:create
390
467
  // declares. `eth`/`sol` are the SDK's WalletChain spellings; `evm`/`solana` are the
391
468
  // server's.
@@ -492,26 +569,36 @@ export async function promptSecret(prompt) {
492
569
  orig('\n');
493
570
  }
494
571
  }
572
+ const terminalIO = () => ({
573
+ interactive: Boolean(process.stdin.isTTY), readPassphrase: promptSecret, readKeychain: keychainRead,
574
+ });
495
575
  /**
496
576
  * Open the folder's vault, asking Keychain or the human depending on how it was
497
577
  * SEALED. `wrap` is what makes this possible: without it a keychain vault is
498
578
  * indistinguishable from a passphrase one and the only way to find out is to
499
579
  * prompt for a passphrase that was never set.
580
+ *
581
+ * A passphrase vault with no terminal has no passphrase source — the passphrase
582
+ * is never read from argv, env or a pipe — so it is refused BY NAME, the same
583
+ * name `oneie init` refuses with, rather than surfacing promptSecret's throw.
500
584
  */
501
- async function unlock(dir) {
585
+ export async function unlock(dir, io = terminalIO()) {
502
586
  const raw = readVaultFolder(dir);
503
587
  if (!raw)
504
588
  return { error: `no wallet at ${vaultPath(dir)} — run \`one wallet new\`` };
505
589
  const blob = raw;
506
590
  let passphrase;
507
591
  if (blob.wrap === 'keychain') {
508
- const k = keychainRead(String(blob.authPub ?? ''));
592
+ const k = io.readKeychain(String(blob.authPub ?? ''));
509
593
  if (!k.ok || !k.value)
510
- return { error: k.ok ? 'Keychain returned nothing' : k.error };
594
+ return { error: k.ok ? 'Keychain returned nothing' : String(k.error) };
511
595
  passphrase = k.value;
512
596
  }
513
597
  else {
514
- passphrase = await promptSecret('Passphrase: ');
598
+ if (!io.interactive) {
599
+ return { error: `wallet_passphrase_unavailable: the wallet at ${vaultPath(dir)} is sealed with a passphrase typed at a terminal, and stdin is not one. Run this at a terminal, or move the wallet behind Touch ID with \`one wallet keychain\`` };
600
+ }
601
+ passphrase = await io.readPassphrase('Passphrase: ');
515
602
  }
516
603
  let mnemonic;
517
604
  try {
@@ -521,5 +608,5 @@ async function unlock(dir) {
521
608
  return { error: e.message };
522
609
  }
523
610
  const wallet = await openedWallet(blob, mnemonic);
524
- return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])) };
611
+ return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])), keys: wallet.keys };
525
612
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneie",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "commander": "^12.0.0",
23
- "@oneie/sdk": "^0.16.5"
23
+ "@oneie/sdk": "^0.16.6"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "^0.2.0",