@oneie/cli 4.0.7 → 4.2.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.
@@ -1,9 +1,11 @@
1
1
  import { Command } from 'commander';
2
2
  import { mergeEnv } from './env.js';
3
- import { writeFileSync, chmodSync, readFileSync } from 'node:fs';
3
+ import { writeFileSync, chmodSync, readFileSync, existsSync, rmSync } from 'node:fs';
4
4
  import { createInterface } from 'node:readline';
5
5
  import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
6
+ import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
6
7
  import { askPath } from './lib/api-path.js';
8
+ import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
7
9
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
8
10
  // Re-exported for existing callers/tests — canonical implementation now lives
9
11
  // in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
@@ -205,6 +207,125 @@ export function walletCmd() {
205
207
  out(cmd, { ok: true, mnemonic: wallet.mnemonic, addresses, keys: wallet.keys });
206
208
  }
207
209
  });
210
+ // ── the encrypted wallet folder ────────────────────────────────────────────
211
+ cmd.command('new')
212
+ .description('Create an encrypted wallet in this folder — 24 words sealed with a passphrase, four chains, fully offline')
213
+ .option('--dir <path>', 'Project directory', '.')
214
+ .option('--recover', 'Seal an EXISTING 24-word phrase instead of generating a new one (ONE_WALLET_MNEMONIC or stdin)')
215
+ .option('--keychain', 'Seal with a random secret stored in Apple Keychain, so Touch ID opens it instead of a passphrase')
216
+ .action(async (opts) => {
217
+ // Refuse BEFORE generating. Minting a wallet and then failing to store it
218
+ // is the one outcome that loses money: the words would exist only in a
219
+ // process about to exit.
220
+ if (existsSync(vaultPath(opts.dir))) {
221
+ out(cmd, { ok: false, error: `a wallet already exists at ${vaultPath(opts.dir)} — move it aside first` });
222
+ return;
223
+ }
224
+ if (opts.keychain && !keychainAvailable()) {
225
+ out(cmd, { ok: false, error: 'Keychain is macOS-only — omit --keychain to seal with a passphrase' });
226
+ return;
227
+ }
228
+ let passphrase;
229
+ let wrap;
230
+ if (opts.keychain) {
231
+ passphrase = mintKeychainSecret();
232
+ wrap = 'keychain';
233
+ }
234
+ else {
235
+ passphrase = await promptSecret('Passphrase for this wallet: ');
236
+ const again = await promptSecret('Repeat it: ');
237
+ if (passphrase !== again) {
238
+ out(cmd, { ok: false, error: 'passphrases did not match — nothing was written' });
239
+ return;
240
+ }
241
+ if (passphrase.length < 8) {
242
+ out(cmd, { ok: false, error: 'passphrase too short — this is the only thing between a stolen laptop and the wallet' });
243
+ return;
244
+ }
245
+ wrap = 'passphrase';
246
+ }
247
+ const wallet = opts.recover ? await recoverWallet(readMnemonic()) : await generateWallet();
248
+ const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
249
+ const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
250
+ const blob = await sealVault(wallet.mnemonic, passphrase, { wrap, authPub });
251
+ const res = writeVaultFolder(opts.dir, { ...blob });
252
+ if (!res.ok) {
253
+ out(cmd, { ok: false, error: res.error });
254
+ return;
255
+ }
256
+ if (opts.keychain) {
257
+ const k = keychainStore(authPub, passphrase);
258
+ if (!k.ok) {
259
+ // The vault is sealed with a secret nobody can now produce. Remove it
260
+ // rather than leaving an unopenable file that looks like a wallet.
261
+ rmSync(res.path, { force: true });
262
+ out(cmd, { ok: false, error: `Keychain write failed (${k.error}) — the wallet was removed rather than left unopenable` });
263
+ return;
264
+ }
265
+ }
266
+ out(cmd, {
267
+ ok: true,
268
+ wallet: res.path,
269
+ wrap,
270
+ addresses,
271
+ next: 'one wallet paper # write the 24 words down — this is the ONLY backup',
272
+ });
273
+ });
274
+ cmd.command('open')
275
+ .description('Unlock the wallet in this folder and show its addresses — the phrase never leaves this machine')
276
+ .option('--dir <path>', 'Project directory', '.')
277
+ .action(async (opts) => {
278
+ const r = await unlock(opts.dir);
279
+ if ('error' in r) {
280
+ out(cmd, { ok: false, error: r.error });
281
+ return;
282
+ }
283
+ out(cmd, { ok: true, wrap: r.blob.wrap, addresses: r.addresses });
284
+ });
285
+ cmd.command('paper')
286
+ .description('Print the recovery sheet — 24 numbered words plus the public addresses. Print it, then close the terminal')
287
+ .option('--dir <path>', 'Project directory', '.')
288
+ .action(async (opts) => {
289
+ const r = await unlock(opts.dir);
290
+ if ('error' in r) {
291
+ out(cmd, { ok: false, error: r.error });
292
+ return;
293
+ }
294
+ // Straight to stdout, never through out(): a --json receipt carrying 24
295
+ // words would put the whole wallet into any pipeline or CI log that
296
+ // captured it.
297
+ process.stdout.write(paperSheet(r.mnemonic, r.addresses) + '\n');
298
+ });
299
+ cmd.command('keychain')
300
+ .description('Move this wallet behind Touch ID — stores its passphrase in Apple Keychain so biometrics open it')
301
+ .option('--dir <path>', 'Project directory', '.')
302
+ .action(async (opts) => {
303
+ if (!keychainAvailable()) {
304
+ out(cmd, { ok: false, error: 'Keychain is macOS-only' });
305
+ return;
306
+ }
307
+ const blob = readVaultFolder(opts.dir);
308
+ if (!blob) {
309
+ out(cmd, { ok: false, error: `no wallet at ${vaultPath(opts.dir)}` });
310
+ return;
311
+ }
312
+ if (blob.wrap === 'keychain') {
313
+ out(cmd, { ok: true, note: 'already opened by Keychain' });
314
+ return;
315
+ }
316
+ const pass = await promptSecret('Current passphrase: ');
317
+ // Prove the passphrase before storing it — storing an unverified string
318
+ // would put a secret in Keychain that opens nothing.
319
+ try {
320
+ await openVault(blob, pass);
321
+ }
322
+ catch {
323
+ out(cmd, { ok: false, error: 'wrong passphrase — nothing was stored' });
324
+ return;
325
+ }
326
+ const k = keychainStore(String(blob.authPub ?? ''), pass);
327
+ out(cmd, k.ok ? { ok: true, note: 'Touch ID now opens this wallet' } : { ok: false, error: k.error });
328
+ });
208
329
  return cmd;
209
330
  }
210
331
  // Chain-name spellings a keygen output may use -> the four columns wallet:create
@@ -294,3 +415,53 @@ function out(cmd, data) {
294
415
  console.error('✗', typeof detail === 'string' ? detail : JSON.stringify(detail));
295
416
  }
296
417
  }
418
+ /** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
419
+ async function promptSecret(prompt) {
420
+ if (!process.stdin.isTTY)
421
+ throw new Error('a passphrase must be typed at a terminal — refusing to read one from a pipe');
422
+ const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
423
+ const stdout = process.stdout;
424
+ const orig = stdout.write.bind(stdout);
425
+ process.stdout.write(prompt);
426
+ stdout.write = () => true;
427
+ try {
428
+ return await new Promise((resolve) => rl.question('', (a) => { resolve(a); }));
429
+ }
430
+ finally {
431
+ ;
432
+ stdout.write = orig;
433
+ rl.close();
434
+ orig('\n');
435
+ }
436
+ }
437
+ /**
438
+ * Open the folder's vault, asking Keychain or the human depending on how it was
439
+ * SEALED. `wrap` is what makes this possible: without it a keychain vault is
440
+ * indistinguishable from a passphrase one and the only way to find out is to
441
+ * prompt for a passphrase that was never set.
442
+ */
443
+ async function unlock(dir) {
444
+ const raw = readVaultFolder(dir);
445
+ if (!raw)
446
+ return { error: `no wallet at ${vaultPath(dir)} — run \`one wallet new\`` };
447
+ const blob = raw;
448
+ let passphrase;
449
+ if (blob.wrap === 'keychain') {
450
+ const k = keychainRead(String(blob.authPub ?? ''));
451
+ if (!k.ok || !k.value)
452
+ return { error: k.ok ? 'Keychain returned nothing' : k.error };
453
+ passphrase = k.value;
454
+ }
455
+ else {
456
+ passphrase = await promptSecret('Passphrase: ');
457
+ }
458
+ let mnemonic;
459
+ try {
460
+ mnemonic = await openVault(blob, passphrase);
461
+ }
462
+ catch (e) {
463
+ return { error: e.message };
464
+ }
465
+ const wallet = await recoverWallet(mnemonic);
466
+ return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])) };
467
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "4.0.7",
3
+ "version": "4.2.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,12 +15,12 @@
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": "vitest run",
18
+ "test": "bash ../../.claude/scripts/gate-run.sh test-cli -- vitest run",
19
19
  "prepublishOnly": "bun run build"
20
20
  },
21
21
  "dependencies": {
22
22
  "commander": "^12.0.0",
23
- "@oneie/sdk": "^0.14.12"
23
+ "@oneie/sdk": "^0.16.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "^0.1.1",
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,22 +0,0 @@
1
- // @ts-nocheck — template file; typechecked in the target Astro project, not the CLI
2
- // Install: bun add @oneie/frontend
3
- // After setup: copy ONE_API_KEY from .env.local into backend.apiKey
4
- import { defineOne } from '@oneie/frontend';
5
- // The only per-node configuration:
6
- // - backend.apiKey: your workspace's scoped API key (from one setup)
7
- // - brand.tokens: 6 color tokens to match your brand
8
- export default defineOne({
9
- backend: {
10
- apiKey: process.env.ONE_API_KEY ?? '',
11
- },
12
- brand: {
13
- tokens: {
14
- primary: 'hsl(216 55% 25%)', // your brand primary
15
- secondary: 'hsl(160 40% 45%)', // secondary / accent
16
- tertiary: 'hsl(38 90% 55%)', // highlight / CTA
17
- background: 'hsl(0 0% 100%)', // page background
18
- foreground: 'hsl(220 20% 15%)', // body text
19
- font: 'Inter, system-ui, sans-serif',
20
- },
21
- },
22
- });