@oneie/cli 5.3.0 → 5.3.1
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/dist/package.json +2 -2
- package/dist/src/key.d.ts +3 -0
- package/dist/src/key.js +47 -3
- package/dist/src/lib/agent-env.d.ts +7 -0
- package/dist/src/lib/agent-env.js +16 -0
- package/dist/src/lib/tasks-prove.d.ts +15 -0
- package/dist/src/lib/tasks-prove.js +68 -0
- package/dist/src/tasks.js +4 -0
- package/dist/src/wallet.d.ts +36 -0
- package/dist/src/wallet.js +66 -8
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
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.
|
|
23
|
+
"@oneie/sdk": "^0.16.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@oneie/evals": "^0.2.0",
|
package/dist/src/key.d.ts
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
* • Under --json the words never reach stdout (an agent's stdout is a model
|
|
19
19
|
* context and a session log). They reach disk only behind keygen's own
|
|
20
20
|
* --yes-i-accept-plaintext-file, at 0600.
|
|
21
|
+
* • Printed, the words go only to a terminal: a shell whose env names an agent
|
|
22
|
+
* or CI is refused, and a non-TTY stdout needs --yes-print-to-pipe. That is
|
|
23
|
+
* detection, not proof — a pty with no marker is not caught (text/key.md).
|
|
21
24
|
*/
|
|
22
25
|
import { Command } from 'commander';
|
|
23
26
|
export declare function keyCmd(): Command;
|
package/dist/src/key.js
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
* • Under --json the words never reach stdout (an agent's stdout is a model
|
|
19
19
|
* context and a session log). They reach disk only behind keygen's own
|
|
20
20
|
* --yes-i-accept-plaintext-file, at 0600.
|
|
21
|
+
* • Printed, the words go only to a terminal: a shell whose env names an agent
|
|
22
|
+
* or CI is refused, and a non-TTY stdout needs --yes-print-to-pipe. That is
|
|
23
|
+
* detection, not proof — a pty with no marker is not caught (text/key.md).
|
|
21
24
|
*/
|
|
22
25
|
import { Command } from 'commander';
|
|
23
26
|
import { existsSync, readFileSync } from 'node:fs';
|
|
@@ -25,6 +28,7 @@ import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
|
25
28
|
import { userIdPubFromPhrase } from '@oneie/sdk/key-identity';
|
|
26
29
|
import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
|
|
27
30
|
import { promptSecret, writeKeysFile } from './wallet.js';
|
|
31
|
+
import { wordsStdoutRefusal } from './lib/agent-env.js';
|
|
28
32
|
const REFUSE_ARGV_SECRET = 'A secret on the command line is refused on purpose: it is written to your shell history and is ' +
|
|
29
33
|
'visible in `ps` to every user on this machine. Set ONE_WALLET_MNEMONIC or pipe the words on stdin.';
|
|
30
34
|
const REFUSE_ARGV = 'Unrecognised argument. It is not repeated here on purpose — it may BE your recovery phrase. ' +
|
|
@@ -146,10 +150,17 @@ export function keyCmd() {
|
|
|
146
150
|
const cmd = new Command('key').description('One key — new · recover · public · verify. Offline except verify, which sends only your API key');
|
|
147
151
|
cmd.command('new')
|
|
148
152
|
.description('Mint a key on this machine: 24 words, printed ONCE, for paper. No network')
|
|
149
|
-
.
|
|
153
|
+
.argument('[refused...]')
|
|
154
|
+
.allowUnknownOption()
|
|
155
|
+
.option('--phrase [words]', 'REFUSED — never put the words on the command line')
|
|
156
|
+
.option('--mnemonic [words]', 'REFUSED — never put the words on the command line')
|
|
157
|
+
.option('--derivation <v>', 'v2 (default — standard BIP-44 paths, what one.ie mints) or v1 (original ONE HKDF labels)', 'v2')
|
|
150
158
|
.option('--out <file>', 'Write the words + keys to a file at mode 0600 instead of printing them')
|
|
151
159
|
.option('--yes-i-accept-plaintext-file', 'Required with --out — acknowledge that unencrypted key material will be written to disk')
|
|
152
|
-
.
|
|
160
|
+
.option('--yes-print-to-pipe', 'Print the words even though stdout is not a terminal — a printer, on purpose. An agent shell is refused regardless')
|
|
161
|
+
.action(async (rest, opts, sub) => {
|
|
162
|
+
if (refuseArgv(sub, opts, rest))
|
|
163
|
+
return;
|
|
153
164
|
const derivation = readDerivationOpt(opts.derivation);
|
|
154
165
|
if (!derivation)
|
|
155
166
|
return fail(sub, '--derivation must be v1 or v2');
|
|
@@ -162,6 +173,11 @@ export function keyCmd() {
|
|
|
162
173
|
if (!opts.out && jsonMode(sub)) {
|
|
163
174
|
return fail(sub, 'refusing to print the words under --json — stdout may be a log or a model context. Use --out <file> --yes-i-accept-plaintext-file');
|
|
164
175
|
}
|
|
176
|
+
if (!opts.out) {
|
|
177
|
+
const why = wordsStdoutRefusal(process.env, Boolean(process.stdout.isTTY), Boolean(opts.yesPrintToPipe));
|
|
178
|
+
if (why)
|
|
179
|
+
return fail(sub, why);
|
|
180
|
+
}
|
|
165
181
|
const wallet = await generateWallet(derivation);
|
|
166
182
|
const addresses = addressesOf(wallet);
|
|
167
183
|
const userIdPub = await userIdPubFromPhrase(wallet.mnemonic);
|
|
@@ -216,7 +232,7 @@ export function keyCmd() {
|
|
|
216
232
|
});
|
|
217
233
|
}));
|
|
218
234
|
cmd.addCommand(wordsCommand('public', 'The public identity + the four chain addresses for your words — nothing secret, no network')
|
|
219
|
-
.option('--derivation <v>', 'v1
|
|
235
|
+
.option('--derivation <v>', 'v1 or v2 — omit it and both sets print, because the words carry no marker')
|
|
220
236
|
.action(async (rest, opts, sub) => {
|
|
221
237
|
if (refuseArgv(sub, opts, rest))
|
|
222
238
|
return;
|
|
@@ -224,6 +240,27 @@ export function keyCmd() {
|
|
|
224
240
|
if (!derivation)
|
|
225
241
|
return fail(sub, '--derivation must be v1 or v2');
|
|
226
242
|
const words = await readWords();
|
|
243
|
+
// No --derivation: the words say nothing about which set they were minted
|
|
244
|
+
// under, and `key new` mints v2 while every older key is v1. Picking one
|
|
245
|
+
// here is the silent divergence task:01a0c33a93bbebfc8e2ebba0 closed — so
|
|
246
|
+
// both sets print, the way `key recover` already does.
|
|
247
|
+
if (opts.derivation === undefined) {
|
|
248
|
+
let v1, v2, userIdPub;
|
|
249
|
+
try {
|
|
250
|
+
v1 = await recoverWallet(words, 'v1');
|
|
251
|
+
v2 = await recoverWallet(words, 'v2');
|
|
252
|
+
userIdPub = await userIdPubFromPhrase(words);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return fail(sub, INVALID_PHRASE);
|
|
256
|
+
}
|
|
257
|
+
return done(sub, {
|
|
258
|
+
ok: true,
|
|
259
|
+
userIdPub,
|
|
260
|
+
v1: { label: labelFor('v1'), addresses: addressesOf(v1) },
|
|
261
|
+
v2: { label: labelFor('v2'), addresses: addressesOf(v2) },
|
|
262
|
+
});
|
|
263
|
+
}
|
|
227
264
|
let wallet, userIdPub;
|
|
228
265
|
try {
|
|
229
266
|
wallet = await recoverWallet(words, derivation);
|
|
@@ -266,5 +303,12 @@ export function keyCmd() {
|
|
|
266
303
|
if (verdict === 'mismatch')
|
|
267
304
|
process.exitCode = 1;
|
|
268
305
|
}));
|
|
306
|
+
// `one key <token>`: commander would print "unknown command '<token>'" — and the
|
|
307
|
+
// token may BE the first word of a phrase. Refuse it here without repeating it.
|
|
308
|
+
cmd.argument('[refused...]').allowUnknownOption().action((rest, _opts, c) => {
|
|
309
|
+
if (rest.length === 0)
|
|
310
|
+
return c.help({ error: true });
|
|
311
|
+
fail(c, REFUSE_ARGV);
|
|
312
|
+
});
|
|
269
313
|
return cmd;
|
|
270
314
|
}
|
|
@@ -3,3 +3,10 @@ export declare function agentType(env?: NodeJS.ProcessEnv): string | undefined;
|
|
|
3
3
|
/** True when stdout isn't a human's terminal (agent shell, CI, piped) or a
|
|
4
4
|
* known agent env var is set — never used to gate a prompt, only the greeting. */
|
|
5
5
|
export declare function isAgentEnvironment(env?: NodeJS.ProcessEnv, isTTY?: boolean): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Why the 24 recovery words must NOT be written to this stdout, or null when it is
|
|
8
|
+
* a person's terminal. A shell whose env names an agent or CI is refused even with
|
|
9
|
+
* the pipe override: its stdout is a model context and a session log. This is
|
|
10
|
+
* detection, not proof — a pty with no marker set is not caught.
|
|
11
|
+
*/
|
|
12
|
+
export declare function wordsStdoutRefusal(env: NodeJS.ProcessEnv, isTTY: boolean, allowPipe: boolean): string | null;
|
|
@@ -30,3 +30,19 @@ export function agentType(env = process.env) {
|
|
|
30
30
|
export function isAgentEnvironment(env = process.env, isTTY = process.stdout.isTTY) {
|
|
31
31
|
return Boolean(agentType(env)) || !isTTY;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Why the 24 recovery words must NOT be written to this stdout, or null when it is
|
|
35
|
+
* a person's terminal. A shell whose env names an agent or CI is refused even with
|
|
36
|
+
* the pipe override: its stdout is a model context and a session log. This is
|
|
37
|
+
* detection, not proof — a pty with no marker set is not caught.
|
|
38
|
+
*/
|
|
39
|
+
export function wordsStdoutRefusal(env, isTTY, allowPipe) {
|
|
40
|
+
const agent = agentType(env);
|
|
41
|
+
if (agent) {
|
|
42
|
+
return `refusing to print the words: this shell is driven by ${agent}, and its stdout is a model context and a session log. Run it yourself in a terminal no agent drives`;
|
|
43
|
+
}
|
|
44
|
+
if (!isTTY && !allowPipe) {
|
|
45
|
+
return 'refusing to print the words: stdout is not a terminal (a pipe, a file or a log). Pass --yes-print-to-pipe if you are sending them to a printer on purpose';
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Row } from './tasks-digest.js';
|
|
2
|
+
export declare function acceptOf(notes: string): string | null;
|
|
3
|
+
export declare function isHermetic(accept: string): boolean;
|
|
4
|
+
export declare function proveRows(rows: {
|
|
5
|
+
tid: string;
|
|
6
|
+
notes?: string;
|
|
7
|
+
}[], run: (accept: string) => number): {
|
|
8
|
+
tid: string;
|
|
9
|
+
verdict: 'proof-green — close?' | 'red' | 'unproven';
|
|
10
|
+
}[];
|
|
11
|
+
export declare function renderProve(results: {
|
|
12
|
+
tid: string;
|
|
13
|
+
verdict: string;
|
|
14
|
+
}[]): string;
|
|
15
|
+
export declare function proveBoard(rows: Row[]): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export function acceptOf(notes) {
|
|
5
|
+
const acceptLine = notes.split('\n').find(line => line.startsWith('Accept:'));
|
|
6
|
+
if (!acceptLine)
|
|
7
|
+
return null;
|
|
8
|
+
return acceptLine.slice('Accept:'.length).trim();
|
|
9
|
+
}
|
|
10
|
+
export function isHermetic(accept) {
|
|
11
|
+
const falsePatterns = ['curl', 'proof.sh route', '--window', '--since-ship'];
|
|
12
|
+
for (const pat of falsePatterns) {
|
|
13
|
+
if (accept.includes(pat))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return accept.startsWith('bash .claude/scripts/proof.sh test ') || accept.includes('--self-test');
|
|
17
|
+
}
|
|
18
|
+
export function proveRows(rows, run) {
|
|
19
|
+
return rows.map(row => {
|
|
20
|
+
const accept = row.notes ? acceptOf(row.notes) : null;
|
|
21
|
+
if (accept && isHermetic(accept)) {
|
|
22
|
+
const exitCode = run(accept);
|
|
23
|
+
const verdict = exitCode === 0 ? 'proof-green — close?' : 'red';
|
|
24
|
+
return { tid: row.tid, verdict };
|
|
25
|
+
}
|
|
26
|
+
return { tid: row.tid, verdict: 'unproven' };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function renderProve(results) {
|
|
30
|
+
return results.map(r => `${r.tid} ${r.verdict}`).join('\n');
|
|
31
|
+
}
|
|
32
|
+
export async function proveBoard(rows) {
|
|
33
|
+
const TOP = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout.trim();
|
|
34
|
+
const pid = process.pid;
|
|
35
|
+
const worktreeName = `prove-${pid}`;
|
|
36
|
+
const worktreePath = join(TOP, '.claude', 'worktrees', worktreeName);
|
|
37
|
+
const upResult = spawnSync('bash', [
|
|
38
|
+
'-c',
|
|
39
|
+
`bash .claude/scripts/worktree-up.sh ${worktreeName} --no-dev --base origin/dev`
|
|
40
|
+
], {
|
|
41
|
+
cwd: TOP,
|
|
42
|
+
encoding: 'utf8',
|
|
43
|
+
});
|
|
44
|
+
if (upResult.status !== 0) {
|
|
45
|
+
if (upResult.stderr) {
|
|
46
|
+
process.stderr.write(upResult.stderr);
|
|
47
|
+
}
|
|
48
|
+
if (existsSync(worktreePath)) {
|
|
49
|
+
spawnSync('git', ['worktree', 'remove', '--force', worktreePath]);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const run = (accept) => {
|
|
55
|
+
const result = spawnSync('bash', ['-c', accept], {
|
|
56
|
+
cwd: worktreePath,
|
|
57
|
+
encoding: 'utf8',
|
|
58
|
+
});
|
|
59
|
+
return result.status ?? 1;
|
|
60
|
+
};
|
|
61
|
+
const results = proveRows(rows, run);
|
|
62
|
+
const output = renderProve(results);
|
|
63
|
+
process.stdout.write(output + '\n');
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
spawnSync('git', ['worktree', 'remove', '--force', worktreePath]);
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/src/tasks.js
CHANGED
|
@@ -10,6 +10,7 @@ import { runLivePlan } from './lib/plan-live.js';
|
|
|
10
10
|
import { runFlow, FLOWS as FLOW_IDS } from './lib/flow-tag.js';
|
|
11
11
|
import { buildLens, lensRows } from './lib/tasks-lens.js';
|
|
12
12
|
import { loadRoster } from './lib/roster.js';
|
|
13
|
+
import { proveBoard } from './lib/tasks-prove.js';
|
|
13
14
|
import { proposeOwners, routeEdits } from './lib/tasks-route.js';
|
|
14
15
|
import { claimNext, nextCandidates } from './lib/tasks-next.js';
|
|
15
16
|
import { resolveBulkWorkspaces, spreadWarning, workspaceSpread } from './lib/tasks-workspace.js';
|
|
@@ -263,6 +264,7 @@ export function tasksCmd() {
|
|
|
263
264
|
.option('--include <list>', 'Comma list: notes,graph,dates,thread')
|
|
264
265
|
.option('--summary', 'Counts and sets only, no rows')
|
|
265
266
|
.option('--all', 'Follow nextCursor until every page is read (ceiling 20 pages)')
|
|
267
|
+
.option('--prove', "Run each open row's Accept in a clean worktree at origin/dev and mark the ones already green")
|
|
266
268
|
.option('--limit <n>', 'Rows per page (max 2000)')
|
|
267
269
|
.option('--fresh', 'Rebuild the snapshot instead of reading the memo')
|
|
268
270
|
.option('--kind <k>', "work (default) | approval | all — approvals are parked workflow runs; filtered from ROWS here, the server summary still counts them", 'work')
|
|
@@ -310,6 +312,8 @@ export function tasksCmd() {
|
|
|
310
312
|
process.stdout.write(`\n--kind ${kind}: ${excluded} ${kind === 'work' ? 'approval' : 'work'} rows left out of the rows above (the summary is server-side and still counts them). --kind all to include.\n`);
|
|
311
313
|
}
|
|
312
314
|
}
|
|
315
|
+
if (res.ok !== false && sub.opts().prove)
|
|
316
|
+
await proveBoard((res.tasks ?? []));
|
|
313
317
|
if (res.ok === false)
|
|
314
318
|
fail(res.error ?? 'tasks:board failed');
|
|
315
319
|
});
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { type Derivation, type GeneratedWallet } from '@oneie/sdk/wallet';
|
|
3
|
+
import { type VaultBlob, type SealOpts } from '@oneie/sdk/vault-file';
|
|
2
4
|
import { askPath } from './lib/api-path.js';
|
|
3
5
|
export { askPath };
|
|
6
|
+
/**
|
|
7
|
+
* A FRESH mint is born v2 — the same as one.ie (`NEW_MASTER_DERIVATION` in
|
|
8
|
+
* one.ie/web/src/lib/derive-multichain.ts). Before this the CLI minted v1 and the
|
|
9
|
+
* browser v2, so the same 24 words opened a different, empty wallet on each
|
|
10
|
+
* surface and nothing errored (task:01a0c33a93bbebfc8e2ebba0).
|
|
11
|
+
*
|
|
12
|
+
* A RECOVER has no marker to read, so it takes `--derivation` and an absent one is
|
|
13
|
+
* v1: the words may belong to a v1 key, and a v1 key recovers its v1 addresses
|
|
14
|
+
* forever. Guessing v2 here would recreate the same silent divergence in reverse.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MINT_DERIVATION: Derivation;
|
|
17
|
+
export declare function walletDerivation(opts: {
|
|
18
|
+
recover?: boolean;
|
|
19
|
+
derivation?: string;
|
|
20
|
+
}): Derivation;
|
|
21
|
+
/** Mint or recover, under the derivation named above — the one door both commands use. */
|
|
22
|
+
export declare function walletFor(opts: {
|
|
23
|
+
recover?: boolean;
|
|
24
|
+
derivation?: string;
|
|
25
|
+
}, words: () => string): Promise<{
|
|
26
|
+
wallet: GeneratedWallet;
|
|
27
|
+
derivation: Derivation;
|
|
28
|
+
}>;
|
|
29
|
+
/** Seal the words WITH their derivation. v1 is the field's absence (it rides the
|
|
30
|
+
* AAD only when present), so a v1 vault stays byte-compatible with every one
|
|
31
|
+
* written before the marker existed. */
|
|
32
|
+
export declare function sealWallet(mnemonic: string, passphrase: string, opts: {
|
|
33
|
+
wrap: VaultBlob['wrap'];
|
|
34
|
+
authPub: string;
|
|
35
|
+
derivation: Derivation;
|
|
36
|
+
kdf?: SealOpts['kdf'];
|
|
37
|
+
}): Promise<VaultBlob>;
|
|
38
|
+
/** The addresses a sealed vault holds, read under ITS marker — absent is v1. */
|
|
39
|
+
export declare function openedWallet(blob: VaultBlob, mnemonic: string): Promise<GeneratedWallet>;
|
|
4
40
|
export declare function faucetOk(results: Array<{
|
|
5
41
|
success: boolean;
|
|
6
42
|
}>): boolean;
|
package/dist/src/wallet.js
CHANGED
|
@@ -2,9 +2,10 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { mergeEnv } from './env.js';
|
|
3
3
|
import { writeFileSync, chmodSync, readFileSync, existsSync, rmSync } from 'node:fs';
|
|
4
4
|
import { createInterface } from 'node:readline';
|
|
5
|
-
import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
5
|
+
import { generateWallet, recoverWallet, readDerivation } from '@oneie/sdk/wallet';
|
|
6
6
|
import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
|
|
7
7
|
import { askPath } from './lib/api-path.js';
|
|
8
|
+
import { wordsStdoutRefusal } from './lib/agent-env.js';
|
|
8
9
|
import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
|
|
9
10
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
10
11
|
// Re-exported for existing callers/tests — canonical implementation now lives
|
|
@@ -47,6 +48,44 @@ async function payProtocol(payUrl, protocol, data) {
|
|
|
47
48
|
}
|
|
48
49
|
return body.data ?? {};
|
|
49
50
|
}
|
|
51
|
+
// ── which derivation a wallet is born under ─────────────────────────────────
|
|
52
|
+
/**
|
|
53
|
+
* A FRESH mint is born v2 — the same as one.ie (`NEW_MASTER_DERIVATION` in
|
|
54
|
+
* one.ie/web/src/lib/derive-multichain.ts). Before this the CLI minted v1 and the
|
|
55
|
+
* browser v2, so the same 24 words opened a different, empty wallet on each
|
|
56
|
+
* surface and nothing errored (task:01a0c33a93bbebfc8e2ebba0).
|
|
57
|
+
*
|
|
58
|
+
* A RECOVER has no marker to read, so it takes `--derivation` and an absent one is
|
|
59
|
+
* v1: the words may belong to a v1 key, and a v1 key recovers its v1 addresses
|
|
60
|
+
* forever. Guessing v2 here would recreate the same silent divergence in reverse.
|
|
61
|
+
*/
|
|
62
|
+
export const MINT_DERIVATION = 'v2';
|
|
63
|
+
export function walletDerivation(opts) {
|
|
64
|
+
if (opts.derivation === undefined)
|
|
65
|
+
return opts.recover ? 'v1' : MINT_DERIVATION;
|
|
66
|
+
return readDerivation(opts.derivation);
|
|
67
|
+
}
|
|
68
|
+
/** Mint or recover, under the derivation named above — the one door both commands use. */
|
|
69
|
+
export async function walletFor(opts, words) {
|
|
70
|
+
const derivation = walletDerivation(opts);
|
|
71
|
+
const wallet = opts.recover ? await recoverWallet(words(), derivation) : await generateWallet(derivation);
|
|
72
|
+
return { wallet, derivation };
|
|
73
|
+
}
|
|
74
|
+
/** Seal the words WITH their derivation. v1 is the field's absence (it rides the
|
|
75
|
+
* AAD only when present), so a v1 vault stays byte-compatible with every one
|
|
76
|
+
* written before the marker existed. */
|
|
77
|
+
export async function sealWallet(mnemonic, passphrase, opts) {
|
|
78
|
+
return sealVault(mnemonic, passphrase, {
|
|
79
|
+
wrap: opts.wrap,
|
|
80
|
+
authPub: opts.authPub,
|
|
81
|
+
kdf: opts.kdf,
|
|
82
|
+
...(opts.derivation === 'v2' ? { derivation: 'v2' } : {}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** The addresses a sealed vault holds, read under ITS marker — absent is v1. */
|
|
86
|
+
export async function openedWallet(blob, mnemonic) {
|
|
87
|
+
return recoverWallet(mnemonic, readDerivation(blob.derivation));
|
|
88
|
+
}
|
|
50
89
|
function resolveAuth(opts) {
|
|
51
90
|
const env = mergeEnv(process.cwd());
|
|
52
91
|
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
@@ -193,18 +232,19 @@ export function walletCmd() {
|
|
|
193
232
|
cmd.command('keygen')
|
|
194
233
|
.description('Generate or recover a self-hosted wallet locally — 4 chains (Sui/EVM/Sol/BTC), fully offline, never touches the network or a server. Prints once by default; use --out for scripted bulk provisioning')
|
|
195
234
|
.option('--recover', 'Recover from a 24-word BIP-39 mnemonic (ONE_WALLET_MNEMONIC env or stdin) instead of generating a fresh one')
|
|
235
|
+
.option('--derivation <v>', 'v2 (default for a fresh key — what one.ie mints) or v1. With --recover the default is v1: the words carry no marker, and a v1 key recovers its v1 addresses forever')
|
|
196
236
|
.option('--out <file>', 'Write the mnemonic + keys to a file at mode 0600 instead of printing once')
|
|
197
237
|
.option('--yes-i-accept-plaintext-file', 'Required with --out — acknowledge that unencrypted key material will be written to disk')
|
|
198
238
|
.action(async (opts) => {
|
|
199
|
-
const wallet
|
|
239
|
+
const { wallet, derivation } = await walletFor(opts, readMnemonic);
|
|
200
240
|
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
201
241
|
if (opts.out) {
|
|
202
|
-
const contents = JSON.stringify({ mnemonic: wallet.mnemonic, keys: wallet.keys }, null, 2) + '\n';
|
|
242
|
+
const contents = JSON.stringify({ mnemonic: wallet.mnemonic, derivation, keys: wallet.keys }, null, 2) + '\n';
|
|
203
243
|
writeKeysFile(opts.out, contents, Boolean(opts.yesIAcceptPlaintextFile));
|
|
204
|
-
out(cmd, { ok: true, out: opts.out, chains: wallet.keys.map((k) => k.chain), addresses });
|
|
244
|
+
out(cmd, { ok: true, out: opts.out, derivation, chains: wallet.keys.map((k) => k.chain), addresses });
|
|
205
245
|
}
|
|
206
246
|
else {
|
|
207
|
-
out(cmd, { ok: true, mnemonic: wallet.mnemonic, addresses, keys: wallet.keys });
|
|
247
|
+
out(cmd, { ok: true, mnemonic: wallet.mnemonic, derivation, addresses, keys: wallet.keys });
|
|
208
248
|
}
|
|
209
249
|
});
|
|
210
250
|
// ── the encrypted wallet folder ────────────────────────────────────────────
|
|
@@ -212,6 +252,7 @@ export function walletCmd() {
|
|
|
212
252
|
.description('Create an encrypted wallet in this folder — 24 words sealed with a passphrase, four chains, fully offline')
|
|
213
253
|
.option('--dir <path>', 'Project directory', '.')
|
|
214
254
|
.option('--recover', 'Seal an EXISTING 24-word phrase instead of generating a new one (ONE_WALLET_MNEMONIC or stdin)')
|
|
255
|
+
.option('--derivation <v>', 'v2 (default for a fresh wallet — what one.ie mints) or v1. With --recover the default is v1: the words carry no marker, and a v1 key recovers its v1 addresses forever')
|
|
215
256
|
.option('--keychain', 'Seal with a random secret stored in Apple Keychain, so Touch ID opens it instead of a passphrase')
|
|
216
257
|
.action(async (opts) => {
|
|
217
258
|
// Refuse BEFORE generating. Minting a wallet and then failing to store it
|
|
@@ -225,6 +266,14 @@ export function walletCmd() {
|
|
|
225
266
|
out(cmd, { ok: false, error: 'Keychain is macOS-only — omit --keychain to seal with a passphrase' });
|
|
226
267
|
return;
|
|
227
268
|
}
|
|
269
|
+
// A bad --derivation is refused before the passphrase is asked for, not after.
|
|
270
|
+
try {
|
|
271
|
+
walletDerivation(opts);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
out(cmd, { ok: false, error: '--derivation must be v1 or v2' });
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
228
277
|
let passphrase;
|
|
229
278
|
let wrap;
|
|
230
279
|
if (opts.keychain) {
|
|
@@ -244,10 +293,10 @@ export function walletCmd() {
|
|
|
244
293
|
}
|
|
245
294
|
wrap = 'passphrase';
|
|
246
295
|
}
|
|
247
|
-
const wallet
|
|
296
|
+
const { wallet, derivation } = await walletFor(opts, readMnemonic);
|
|
248
297
|
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
249
298
|
const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
|
|
250
|
-
const blob = await
|
|
299
|
+
const blob = await sealWallet(wallet.mnemonic, passphrase, { wrap, authPub, derivation });
|
|
251
300
|
const res = writeVaultFolder(opts.dir, { ...blob });
|
|
252
301
|
if (!res.ok) {
|
|
253
302
|
out(cmd, { ok: false, error: res.error });
|
|
@@ -267,6 +316,7 @@ export function walletCmd() {
|
|
|
267
316
|
ok: true,
|
|
268
317
|
wallet: res.path,
|
|
269
318
|
wrap,
|
|
319
|
+
derivation,
|
|
270
320
|
addresses,
|
|
271
321
|
next: 'one wallet paper # write the 24 words down — this is the ONLY backup',
|
|
272
322
|
});
|
|
@@ -285,7 +335,15 @@ export function walletCmd() {
|
|
|
285
335
|
cmd.command('paper')
|
|
286
336
|
.description('Print the recovery sheet — 24 numbered words plus the public addresses. Print it, then close the terminal')
|
|
287
337
|
.option('--dir <path>', 'Project directory', '.')
|
|
338
|
+
.option('--yes-print-to-pipe', 'Print the words even though stdout is not a terminal — a printer, on purpose. An agent shell is refused regardless')
|
|
288
339
|
.action(async (opts) => {
|
|
340
|
+
// Refuse BEFORE unlock: no passphrase prompt, no Touch ID, when the words could not be shown.
|
|
341
|
+
const why = wordsStdoutRefusal(process.env, Boolean(process.stdout.isTTY), Boolean(opts.yesPrintToPipe));
|
|
342
|
+
if (why) {
|
|
343
|
+
out(cmd, { ok: false, error: why });
|
|
344
|
+
process.exitCode = 1;
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
289
347
|
const r = await unlock(opts.dir);
|
|
290
348
|
if ('error' in r) {
|
|
291
349
|
out(cmd, { ok: false, error: r.error });
|
|
@@ -462,6 +520,6 @@ async function unlock(dir) {
|
|
|
462
520
|
catch (e) {
|
|
463
521
|
return { error: e.message };
|
|
464
522
|
}
|
|
465
|
-
const wallet = await
|
|
523
|
+
const wallet = await openedWallet(blob, mnemonic);
|
|
466
524
|
return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])) };
|
|
467
525
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
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.
|
|
23
|
+
"@oneie/sdk": "^0.16.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@oneie/evals": "^0.2.0",
|