oneie 5.0.0 → 5.2.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/README.md +44 -0
- package/dist/package.json +2 -2
- package/dist/src/draw.d.ts +18 -0
- package/dist/src/draw.js +156 -0
- package/dist/src/group.js +2 -0
- package/dist/src/index.js +9 -6
- package/dist/src/init.d.ts +1 -1
- package/dist/src/init.js +9 -17
- package/dist/src/join.d.ts +11 -0
- package/dist/src/join.js +292 -0
- package/dist/src/key.d.ts +23 -0
- package/dist/src/key.js +270 -0
- package/dist/src/lib/paths.d.ts +8 -0
- package/dist/src/lib/paths.js +16 -2
- package/dist/src/lib/plan-draw.d.ts +56 -0
- package/dist/src/lib/plan-draw.js +219 -0
- package/dist/src/lib/plan-live.d.ts +20 -0
- package/dist/src/lib/plan-live.js +192 -0
- package/dist/src/onboard.js +16 -15
- package/dist/src/tasks.js +52 -0
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +1 -1
- package/package.json +2 -2
- package/dist/src/templates/_node/site/one.config.d.ts +0 -2
- package/dist/src/templates/_node/site/one.config.js +0 -22
package/dist/src/join.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
|
|
2
|
+
import { askPath } from './lib/api-path.js';
|
|
3
|
+
// The existing-group door (text/join-existing-plan.md § W2). A newcomer — person
|
|
4
|
+
// or agent — becomes someone (`oneie login`), asks a group's owner to let them
|
|
5
|
+
// in, and the owner answers. Each verb is one receiver through the ask door; the
|
|
6
|
+
// receiver owns authority, validation and the owner notice.
|
|
7
|
+
//
|
|
8
|
+
// `follow <group>` is NOT a top-level verb: `oneie follow <type>` is already the
|
|
9
|
+
// path-selection verb (substrate.ts), and commander 12 throws on a duplicate
|
|
10
|
+
// name at registration — before index.ts reaches the bare-argv check — so a
|
|
11
|
+
// second `follow` would crash every invocation, bare `oneie` included. Watching
|
|
12
|
+
// a group is `oneie group follow <group>` (watchCommands, mounted by group.ts).
|
|
13
|
+
const DEFAULT_API = 'https://one.ie';
|
|
14
|
+
const ROLES = ['viewer', 'member', 'admin'];
|
|
15
|
+
const STATUSES = ['pending', 'approved', 'rejected'];
|
|
16
|
+
export const JOIN_VERBS = ['request', 'requests', 'approve'];
|
|
17
|
+
/** The door block bare `oneie` prints — contract #10: printed, never prompted. */
|
|
18
|
+
export function bareDoors(agent) {
|
|
19
|
+
const newGroup = agent
|
|
20
|
+
? ' oneie init --write-env # provision a group, no account required\n' +
|
|
21
|
+
' oneie onboard # provision + walk the lifecycle stages\n'
|
|
22
|
+
: ' npx oneie create <name> # scaffold a new group\n';
|
|
23
|
+
return ('new group:\n' +
|
|
24
|
+
newGroup +
|
|
25
|
+
'existing group:\n' +
|
|
26
|
+
' oneie login # become someone — no new group\n' +
|
|
27
|
+
" oneie request <group> [--reason] # ask the owner to let you in\n" +
|
|
28
|
+
" oneie requests [--group <g>] # your asks, or an owner's queue\n" +
|
|
29
|
+
' oneie approve <requestId> [--reject]\n' +
|
|
30
|
+
' oneie group follow <group> # watch a public group\n' +
|
|
31
|
+
' oneie --help # full command reference\n');
|
|
32
|
+
}
|
|
33
|
+
const NO_KEY = 'no API key — run `oneie login` (or set ONE_API_KEY)';
|
|
34
|
+
function fail(cmd, error) {
|
|
35
|
+
if (jsonMode(cmd))
|
|
36
|
+
process.stdout.write(JSON.stringify({ ok: false, error }) + '\n');
|
|
37
|
+
else
|
|
38
|
+
process.stderr.write(`error ${error}\n`);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
|
41
|
+
/** One receiver through the ask door. Throws with the receiver's own reason on any refusal. */
|
|
42
|
+
async function ask(api, key, receiver, data) {
|
|
43
|
+
const base = resolveBase({ api }, DEFAULT_API);
|
|
44
|
+
const res = await fetch(askPath(base, receiver), {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
47
|
+
body: JSON.stringify({ data }),
|
|
48
|
+
});
|
|
49
|
+
const text = await res.text();
|
|
50
|
+
let body;
|
|
51
|
+
try {
|
|
52
|
+
body = text ? JSON.parse(text) : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
56
|
+
}
|
|
57
|
+
if (!body || !('outcome' in body)) {
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
60
|
+
return body ?? {};
|
|
61
|
+
}
|
|
62
|
+
if (body.outcome === 'result') {
|
|
63
|
+
const r = (body.result ?? {});
|
|
64
|
+
if (r.ok === false)
|
|
65
|
+
throw new Error(String(r.error ?? `${receiver} refused`));
|
|
66
|
+
return r;
|
|
67
|
+
}
|
|
68
|
+
// A dissolve answers 200 — the signal reached nobody. Name it, never read it as ok.
|
|
69
|
+
if (body.outcome === 'dissolved') {
|
|
70
|
+
throw new Error(`${receiver} is not live on ${base} yet (dissolved: ${String(body.reason ?? 'no handler')})`);
|
|
71
|
+
}
|
|
72
|
+
const inner = body.result;
|
|
73
|
+
throw new Error(String(inner?.error ?? body.error ?? `${receiver}: ${String(body.outcome)}`));
|
|
74
|
+
}
|
|
75
|
+
// An unregistered `world:<name>` is not a dissolve on the web door: it is read as
|
|
76
|
+
// `world:<tag-expr>` and routed (measured on prod 2026-09-26 — world:list-requests
|
|
77
|
+
// answered outcome "result" {routed:"learned", actor:"ceo"}). So an answer missing
|
|
78
|
+
// the field the verb exists to return is refused, never printed as empty.
|
|
79
|
+
function notLive(receiver, missing, r) {
|
|
80
|
+
const routed = r.routed ? ` — routed as a world tag (routed=${String(r.routed)}, actor=${String(r.actor ?? '?')})` : '';
|
|
81
|
+
return `${receiver} is not live here yet: answer carried ${missing}${routed}`;
|
|
82
|
+
}
|
|
83
|
+
/** Resolve the key or refuse; every verb here acts as someone. */
|
|
84
|
+
function keyOrFail(cmd) {
|
|
85
|
+
const key = resolveKey();
|
|
86
|
+
if (!key)
|
|
87
|
+
fail(cmd, NO_KEY);
|
|
88
|
+
return key || undefined;
|
|
89
|
+
}
|
|
90
|
+
function cell(v) {
|
|
91
|
+
if (v === undefined || v === null || v === '')
|
|
92
|
+
return '-';
|
|
93
|
+
// A cell is receiver data, and a reason is a stranger's text: no control
|
|
94
|
+
// character (ESC, BEL, CR) reaches the terminal.
|
|
95
|
+
return String(v).replace(/\p{Cc}+/gu, ' ').replace(/\s+/g, ' ').slice(0, 40);
|
|
96
|
+
}
|
|
97
|
+
export function joinCommands(program) {
|
|
98
|
+
program
|
|
99
|
+
.command('request <group>')
|
|
100
|
+
.description("Ask a group's owner to let you in — always pends, never auto-grants")
|
|
101
|
+
.option('--role <role>', 'Role to ask for: viewer | member | admin')
|
|
102
|
+
.option('--reason <text>', 'Why — shown to the owner')
|
|
103
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
104
|
+
.action(async (group, opts, cmd) => {
|
|
105
|
+
if (opts.role && !ROLES.includes(opts.role)) {
|
|
106
|
+
return fail(cmd, `--role must be one of ${ROLES.join(' | ')} (got "${opts.role}")`);
|
|
107
|
+
}
|
|
108
|
+
const key = keyOrFail(cmd);
|
|
109
|
+
if (!key)
|
|
110
|
+
return;
|
|
111
|
+
const data = { group };
|
|
112
|
+
if (opts.role)
|
|
113
|
+
data.role = opts.role;
|
|
114
|
+
if (opts.reason)
|
|
115
|
+
data.reason = opts.reason;
|
|
116
|
+
let r;
|
|
117
|
+
try {
|
|
118
|
+
r = await ask(opts.api, key, 'world:request-access', data);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
return fail(cmd, e.message);
|
|
122
|
+
}
|
|
123
|
+
if (typeof r.requestId !== 'string')
|
|
124
|
+
return fail(cmd, notLive('world:request-access', 'no requestId', r));
|
|
125
|
+
if (jsonMode(cmd)) {
|
|
126
|
+
process.stdout.write(JSON.stringify({ ok: true, ...r, group }) + '\n');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
process.stdout.write(`ok requestId=${JSON.stringify(r.requestId)} group=${JSON.stringify(group)}\n`);
|
|
130
|
+
if (r.existing === true)
|
|
131
|
+
process.stdout.write(`an ask to ${group} was already pending — no new notice sent; check with: oneie requests\n`);
|
|
132
|
+
else if (r.notified === true)
|
|
133
|
+
process.stdout.write(`the owner of ${group} has been notified — follow the answer with: oneie requests\n`);
|
|
134
|
+
else if (r.notified === false)
|
|
135
|
+
process.stdout.write(`the owner of ${group} was NOT notified — send them the requestId\n`);
|
|
136
|
+
else
|
|
137
|
+
process.stdout.write(`pending — the owner answers from their queue; check with: oneie requests\n`);
|
|
138
|
+
});
|
|
139
|
+
program
|
|
140
|
+
.command('requests')
|
|
141
|
+
.description("List access requests — your own asks, or an owner's queue for a group")
|
|
142
|
+
.option('--group <g>', "Group whose queue to list (owner/admin)")
|
|
143
|
+
.option('--status <s>', 'pending | approved | rejected')
|
|
144
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
145
|
+
.action(async (opts, cmd) => {
|
|
146
|
+
if (opts.status && !STATUSES.includes(opts.status)) {
|
|
147
|
+
return fail(cmd, `--status must be one of ${STATUSES.join(' | ')} (got "${opts.status}")`);
|
|
148
|
+
}
|
|
149
|
+
const key = keyOrFail(cmd);
|
|
150
|
+
if (!key)
|
|
151
|
+
return;
|
|
152
|
+
const data = {};
|
|
153
|
+
if (opts.group)
|
|
154
|
+
data.group = opts.group;
|
|
155
|
+
if (opts.status)
|
|
156
|
+
data.status = opts.status;
|
|
157
|
+
let r;
|
|
158
|
+
try {
|
|
159
|
+
r = await ask(opts.api, key, 'world:list-requests', data);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
return fail(cmd, e.message);
|
|
163
|
+
}
|
|
164
|
+
const list = r.requests ?? r.rows;
|
|
165
|
+
if (!Array.isArray(list))
|
|
166
|
+
return fail(cmd, notLive('world:list-requests', 'no request list', r));
|
|
167
|
+
if (jsonMode(cmd)) {
|
|
168
|
+
process.stdout.write(JSON.stringify({ ok: true, ...r }) + '\n');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const rows = list;
|
|
172
|
+
const total = typeof r.total === 'number' ? r.total : rows.length;
|
|
173
|
+
if (rows.length === 0)
|
|
174
|
+
process.stdout.write('no requests\n');
|
|
175
|
+
else {
|
|
176
|
+
const head = ['requestId', 'group', 'role', 'status', 'requester', 'reason'];
|
|
177
|
+
const body = rows.map((x) => [
|
|
178
|
+
cell(x.requestId ?? x.id),
|
|
179
|
+
cell(x.group ?? x.gid),
|
|
180
|
+
cell(x.role),
|
|
181
|
+
cell(x.status),
|
|
182
|
+
cell(x.requester ?? x.actor ?? x.aid ?? x.uid),
|
|
183
|
+
cell(x.reason),
|
|
184
|
+
]);
|
|
185
|
+
const w = head.map((h, i) => Math.max(h.length, ...body.map((b) => b[i].length)));
|
|
186
|
+
for (const line of [head, ...body])
|
|
187
|
+
process.stdout.write(line.map((c, i) => c.padEnd(w[i])).join(' ').trimEnd() + '\n');
|
|
188
|
+
}
|
|
189
|
+
// Absent is not false: only a present `truncated` makes total a floor.
|
|
190
|
+
if (r.truncated !== undefined && r.truncated !== false) {
|
|
191
|
+
process.stdout.write(`total=${total} truncated — at least ${total}; ${JSON.stringify(r.truncated)}\n`);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
process.stdout.write(`total=${total}\n`);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
program
|
|
198
|
+
.command('approve <requestId>')
|
|
199
|
+
.description('Answer an access request — approve by default, --reject to refuse')
|
|
200
|
+
.option('--reject', 'Reject instead of approve')
|
|
201
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
202
|
+
.action(async (requestId, opts, cmd) => {
|
|
203
|
+
const key = keyOrFail(cmd);
|
|
204
|
+
if (!key)
|
|
205
|
+
return;
|
|
206
|
+
const decision = opts.reject ? 'rejected' : 'approved';
|
|
207
|
+
let r;
|
|
208
|
+
try {
|
|
209
|
+
r = await ask(opts.api, key, 'world:approve-request', { requestId, decision });
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
return fail(cmd, e.message);
|
|
213
|
+
}
|
|
214
|
+
// W1 answers `membership` = setMembership's verdict. `failed` (the write
|
|
215
|
+
// did not land) or `refused` (the owner guard said no) means the D1
|
|
216
|
+
// decision is recorded while the requester still holds no role — the one
|
|
217
|
+
// outcome an "ok" line would turn into a lie.
|
|
218
|
+
const membership = typeof r.membership === 'string' ? r.membership : undefined;
|
|
219
|
+
if (membership === 'failed' || membership === 'refused') {
|
|
220
|
+
const error = `approval recorded, but membership was not written (membership=${membership}) — the requester cannot act in the group yet; re-run \`oneie approve ${requestId}\``;
|
|
221
|
+
process.exitCode = 1;
|
|
222
|
+
if (jsonMode(cmd)) {
|
|
223
|
+
process.stdout.write(JSON.stringify({ ...r, ok: false, requestId, decision, error }) + '\n');
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
process.stderr.write(`error ${error}\n`);
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (jsonMode(cmd)) {
|
|
231
|
+
process.stdout.write(JSON.stringify({ ...r, ok: true, requestId, decision }) + '\n');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const verdict = membership ? ` membership=${membership}` : '';
|
|
235
|
+
process.stdout.write(`ok requestId=${JSON.stringify(requestId)} decision=${JSON.stringify(decision)}${verdict}\n`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* `oneie group follow|unfollow <group>` — watch a PUBLIC group
|
|
240
|
+
* (text/join-existing-plan.md W3 D2). Mounted on the existing `group` command
|
|
241
|
+
* by group.ts, because a top-level `follow` is taken.
|
|
242
|
+
*/
|
|
243
|
+
export function watchCommands(group) {
|
|
244
|
+
group
|
|
245
|
+
.command('follow <group>')
|
|
246
|
+
.description("Watch a public group — its announces reach your inbox (no membership, no role)")
|
|
247
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
248
|
+
.action(async (target, opts, cmd) => {
|
|
249
|
+
const key = keyOrFail(cmd);
|
|
250
|
+
if (!key)
|
|
251
|
+
return;
|
|
252
|
+
let r;
|
|
253
|
+
try {
|
|
254
|
+
r = await ask(opts.api, key, 'groups:follow', { group: target });
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
return fail(cmd, e.message);
|
|
258
|
+
}
|
|
259
|
+
if (r.following !== true)
|
|
260
|
+
return fail(cmd, notLive('groups:follow', 'no following:true', r));
|
|
261
|
+
const slug = typeof r.group === 'string' ? r.group : target;
|
|
262
|
+
if (jsonMode(cmd)) {
|
|
263
|
+
process.stdout.write(JSON.stringify({ ok: true, ...r, group: slug }) + '\n');
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
process.stdout.write(`ok following ${JSON.stringify(slug)} — its announces now reach your inbox; stop with: oneie group unfollow ${slug}\n`);
|
|
267
|
+
});
|
|
268
|
+
group
|
|
269
|
+
.command('unfollow <group>')
|
|
270
|
+
.description('Stop watching a group (a declared subscription on it is left alone)')
|
|
271
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
272
|
+
.action(async (target, opts, cmd) => {
|
|
273
|
+
const key = keyOrFail(cmd);
|
|
274
|
+
if (!key)
|
|
275
|
+
return;
|
|
276
|
+
let r;
|
|
277
|
+
try {
|
|
278
|
+
r = await ask(opts.api, key, 'groups:unfollow', { group: target });
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
return fail(cmd, e.message);
|
|
282
|
+
}
|
|
283
|
+
if (r.following !== false)
|
|
284
|
+
return fail(cmd, notLive('groups:unfollow', 'no following:false', r));
|
|
285
|
+
const slug = typeof r.group === 'string' ? r.group : target;
|
|
286
|
+
if (jsonMode(cmd)) {
|
|
287
|
+
process.stdout.write(JSON.stringify({ ok: true, ...r, group: slug }) + '\n');
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
process.stdout.write(`ok not following ${JSON.stringify(slug)}\n`);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key.ts — `one key new | recover | public | verify`, the text/key.md door on a terminal.
|
|
3
|
+
*
|
|
4
|
+
* A VERB OVER WALLET KEYGEN, NOT A SECOND DERIVATION. Every address comes from
|
|
5
|
+
* `@oneie/sdk/wallet` — the same core `one wallet keygen`, packages/recover and
|
|
6
|
+
* the browser (by parity test) derive with. The public identity is the SDK's
|
|
7
|
+
* `@oneie/sdk/key-identity`, byte-identical to one.ie/web's `deriveUserIdPub`.
|
|
8
|
+
*
|
|
9
|
+
* THE KEY NEVER LEAVES THIS MACHINE.
|
|
10
|
+
* • new · recover · public make no network call at all.
|
|
11
|
+
* • verify makes one kind of call — `fetchReferences(base, apiKey)` — and it is
|
|
12
|
+
* structurally unable to send the key: its only inputs are a URL and the API
|
|
13
|
+
* key. It reads the public identities the server holds and the comparison
|
|
14
|
+
* happens HERE, so not even the public identity is transmitted.
|
|
15
|
+
* • The words never come from argv (shell history, `ps`): env or stdin, or a
|
|
16
|
+
* hidden prompt on a terminal. An argv token is never echoed — it may BE the
|
|
17
|
+
* phrase.
|
|
18
|
+
* • Under --json the words never reach stdout (an agent's stdout is a model
|
|
19
|
+
* context and a session log). They reach disk only behind keygen's own
|
|
20
|
+
* --yes-i-accept-plaintext-file, at 0600.
|
|
21
|
+
*/
|
|
22
|
+
import { Command } from 'commander';
|
|
23
|
+
export declare function keyCmd(): Command;
|
package/dist/src/key.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key.ts — `one key new | recover | public | verify`, the text/key.md door on a terminal.
|
|
3
|
+
*
|
|
4
|
+
* A VERB OVER WALLET KEYGEN, NOT A SECOND DERIVATION. Every address comes from
|
|
5
|
+
* `@oneie/sdk/wallet` — the same core `one wallet keygen`, packages/recover and
|
|
6
|
+
* the browser (by parity test) derive with. The public identity is the SDK's
|
|
7
|
+
* `@oneie/sdk/key-identity`, byte-identical to one.ie/web's `deriveUserIdPub`.
|
|
8
|
+
*
|
|
9
|
+
* THE KEY NEVER LEAVES THIS MACHINE.
|
|
10
|
+
* • new · recover · public make no network call at all.
|
|
11
|
+
* • verify makes one kind of call — `fetchReferences(base, apiKey)` — and it is
|
|
12
|
+
* structurally unable to send the key: its only inputs are a URL and the API
|
|
13
|
+
* key. It reads the public identities the server holds and the comparison
|
|
14
|
+
* happens HERE, so not even the public identity is transmitted.
|
|
15
|
+
* • The words never come from argv (shell history, `ps`): env or stdin, or a
|
|
16
|
+
* hidden prompt on a terminal. An argv token is never echoed — it may BE the
|
|
17
|
+
* phrase.
|
|
18
|
+
* • Under --json the words never reach stdout (an agent's stdout is a model
|
|
19
|
+
* context and a session log). They reach disk only behind keygen's own
|
|
20
|
+
* --yes-i-accept-plaintext-file, at 0600.
|
|
21
|
+
*/
|
|
22
|
+
import { Command } from 'commander';
|
|
23
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
24
|
+
import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
25
|
+
import { userIdPubFromPhrase } from '@oneie/sdk/key-identity';
|
|
26
|
+
import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
|
|
27
|
+
import { promptSecret, writeKeysFile } from './wallet.js';
|
|
28
|
+
const REFUSE_ARGV_SECRET = 'A secret on the command line is refused on purpose: it is written to your shell history and is ' +
|
|
29
|
+
'visible in `ps` to every user on this machine. Set ONE_WALLET_MNEMONIC or pipe the words on stdin.';
|
|
30
|
+
const REFUSE_ARGV = 'Unrecognised argument. It is not repeated here on purpose — it may BE your recovery phrase. ' +
|
|
31
|
+
'Words go on stdin or in ONE_WALLET_MNEMONIC, never on the command line. Run --help.';
|
|
32
|
+
const INVALID_PHRASE = 'That is not a valid 24-word BIP-39 recovery phrase. Nothing was derived.';
|
|
33
|
+
// text/key.md, verbatim in substance: the difference is silent and it costs money.
|
|
34
|
+
const NOT_SUI = 'These 24 words are not a Sui wallet mnemonic under v1: ONE derives every chain by HKDF from their ' +
|
|
35
|
+
'32 bytes of entropy, while a standard wallet derives by BIP-44/SLIP-0010 from the same phrase. ' +
|
|
36
|
+
'Both succeed; the standard one shows different, empty addresses. Recover them here, at /key, or with @oneie/recover.';
|
|
37
|
+
const PAPER = 'Write these on paper. The paper is the only backup — ONE never holds this key and cannot recover it.';
|
|
38
|
+
function labelFor(d) {
|
|
39
|
+
return d === 'v2'
|
|
40
|
+
? 'v2 — standard paths (BIP-44 / SLIP-0010). Any BIP-39 wallet recovers these.'
|
|
41
|
+
: 'v1 — original ONE derivation (HKDF labels). Only one.ie and @oneie/recover derive these.';
|
|
42
|
+
}
|
|
43
|
+
/** Field by field from the four chains — a private key has no route into the value. */
|
|
44
|
+
function addressesOf(w) {
|
|
45
|
+
const pick = (c) => w.keys.find((k) => k.chain === c)?.address ?? '';
|
|
46
|
+
return { sui: pick('sui'), evm: pick('evm'), sol: pick('sol'), btc: pick('btc') };
|
|
47
|
+
}
|
|
48
|
+
function fail(cmd, error) {
|
|
49
|
+
if (jsonMode(cmd))
|
|
50
|
+
process.stdout.write(JSON.stringify({ ok: false, error }) + '\n');
|
|
51
|
+
else
|
|
52
|
+
process.stderr.write(`error ${error}\n`);
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
}
|
|
55
|
+
function done(cmd, data) {
|
|
56
|
+
if (jsonMode(cmd)) {
|
|
57
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const lines = Object.entries(data)
|
|
61
|
+
.filter(([k]) => k !== 'ok')
|
|
62
|
+
.map(([k, v]) => ` ${k}: ${typeof v === 'string' ? v : JSON.stringify(v)}`);
|
|
63
|
+
process.stdout.write(`ok\n${lines.join('\n')}\n`);
|
|
64
|
+
}
|
|
65
|
+
function readDerivationOpt(v) {
|
|
66
|
+
if (v === undefined || v === 'v1')
|
|
67
|
+
return 'v1';
|
|
68
|
+
if (v === 'v2')
|
|
69
|
+
return 'v2';
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/** Refuse a secret-bearing flag or any stray argv token, never echoing it. */
|
|
73
|
+
function refuseArgv(cmd, opts, rest) {
|
|
74
|
+
if (opts.phrase !== undefined || opts.mnemonic !== undefined) {
|
|
75
|
+
fail(cmd, REFUSE_ARGV_SECRET);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (rest.length > 0) {
|
|
79
|
+
fail(cmd, REFUSE_ARGV);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
/** The words: ONE_WALLET_MNEMONIC, else stdin when piped, else a hidden prompt. '' = none given. */
|
|
85
|
+
async function readWords() {
|
|
86
|
+
const fromEnv = process.env.ONE_WALLET_MNEMONIC?.trim();
|
|
87
|
+
if (fromEnv)
|
|
88
|
+
return fromEnv;
|
|
89
|
+
if (!process.stdin.isTTY) {
|
|
90
|
+
try {
|
|
91
|
+
return readFileSync(0, 'utf8').trim();
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return '';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return (await promptSecret('Your 24 words (hidden): ')).trim();
|
|
98
|
+
}
|
|
99
|
+
/** Adds the two refused secret flags and the argv catch-all every word-reading verb shares. */
|
|
100
|
+
function wordsCommand(name, description) {
|
|
101
|
+
return new Command(name)
|
|
102
|
+
.description(description)
|
|
103
|
+
.argument('[refused...]')
|
|
104
|
+
.allowUnknownOption()
|
|
105
|
+
.option('--phrase [words]', 'REFUSED — never put the words on the command line')
|
|
106
|
+
.option('--mnemonic [words]', 'REFUSED — never put the words on the command line');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The public identities the server holds for the caller: `vault_blob.user_id_pub`
|
|
110
|
+
* and every `vault_passkey_hints.user_id_pub` (the same two sources /keys reads).
|
|
111
|
+
* Its only inputs are a URL and the API key — nothing derived from the key can
|
|
112
|
+
* reach the request, by signature.
|
|
113
|
+
*/
|
|
114
|
+
async function fetchReferences(base, apiKey) {
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const path of ['/api/vault/sync', '/api/vault/devices']) {
|
|
117
|
+
try {
|
|
118
|
+
const res = await fetch(base + path, { headers: { Authorization: `Bearer ${apiKey}` } });
|
|
119
|
+
if (path === '/api/vault/sync' && res.status === 404) {
|
|
120
|
+
out.push({ answered: true, ids: [] });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
out.push({ answered: false, ids: [] });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const body = (await res.json());
|
|
128
|
+
const raw = path === '/api/vault/sync' ? [body.userIdPub] : (body.devices ?? []).map((d) => d?.userIdPub);
|
|
129
|
+
out.push({ answered: true, ids: raw.filter((r) => typeof r === 'string' && r.length > 0) });
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
out.push({ answered: false, ids: [] });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
function verdictOf(local, refs) {
|
|
138
|
+
if (!local)
|
|
139
|
+
return 'locked';
|
|
140
|
+
if (refs.length === 0)
|
|
141
|
+
return 'unregistered';
|
|
142
|
+
return refs.includes(local) ? 'verified' : 'mismatch';
|
|
143
|
+
}
|
|
144
|
+
// ── the command ──────────────────────────────────────────────────────────────
|
|
145
|
+
export function keyCmd() {
|
|
146
|
+
const cmd = new Command('key').description('One key — new · recover · public · verify. Offline except verify, which sends only your API key');
|
|
147
|
+
cmd.command('new')
|
|
148
|
+
.description('Mint a key on this machine: 24 words, printed ONCE, for paper. No network')
|
|
149
|
+
.option('--derivation <v>', 'v1 (default — what one.ie mints) or v2 (standard BIP-44 paths)', 'v1')
|
|
150
|
+
.option('--out <file>', 'Write the words + keys to a file at mode 0600 instead of printing them')
|
|
151
|
+
.option('--yes-i-accept-plaintext-file', 'Required with --out — acknowledge that unencrypted key material will be written to disk')
|
|
152
|
+
.action(async (opts, sub) => {
|
|
153
|
+
const derivation = readDerivationOpt(opts.derivation);
|
|
154
|
+
if (!derivation)
|
|
155
|
+
return fail(sub, '--derivation must be v1 or v2');
|
|
156
|
+
// Refuse BEFORE minting: words that exist only in a process about to exit are lost money.
|
|
157
|
+
if (opts.out && !opts.yesIAcceptPlaintextFile) {
|
|
158
|
+
return fail(sub, 'refusing to write plaintext key material to disk — pass --yes-i-accept-plaintext-file to override');
|
|
159
|
+
}
|
|
160
|
+
if (opts.out && existsSync(opts.out))
|
|
161
|
+
return fail(sub, 'that file already exists — move it aside first; a key file is never overwritten');
|
|
162
|
+
if (!opts.out && jsonMode(sub)) {
|
|
163
|
+
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
|
+
}
|
|
165
|
+
const wallet = await generateWallet(derivation);
|
|
166
|
+
const addresses = addressesOf(wallet);
|
|
167
|
+
const userIdPub = await userIdPubFromPhrase(wallet.mnemonic);
|
|
168
|
+
if (opts.out) {
|
|
169
|
+
const contents = JSON.stringify({ mnemonic: wallet.mnemonic, derivation, userIdPub, addresses, keys: wallet.keys }, null, 2) + '\n';
|
|
170
|
+
writeKeysFile(opts.out, contents, true);
|
|
171
|
+
return done(sub, { ok: true, out: opts.out, derivation, label: labelFor(derivation), addresses, userIdPub });
|
|
172
|
+
}
|
|
173
|
+
// Straight to stdout, never through a JSON receipt (refused above).
|
|
174
|
+
const words = wallet.mnemonic.split(' ');
|
|
175
|
+
const sheet = words.map((w, i) => `${String(i + 1).padStart(4)}. ${w}`).join('\n');
|
|
176
|
+
process.stdout.write(`\n${PAPER}\n\n${sheet}\n\n${NOT_SUI}\n\n` +
|
|
177
|
+
`derivation ${labelFor(derivation)}\n` +
|
|
178
|
+
Object.entries(addresses).map(([c, a]) => `${c.padEnd(11)} ${a}`).join('\n') +
|
|
179
|
+
`\nidentity ${userIdPub}\n\nThis is the only time the words are shown. Close the terminal when they are on paper.\n`);
|
|
180
|
+
});
|
|
181
|
+
cmd.addCommand(wordsCommand('recover', 'Rebuild a key from its 24 words (stdin or ONE_WALLET_MNEMONIC) — both address sets, no network')
|
|
182
|
+
.option('--derivation <v>', 'which set --out writes: v1 (default) or v2', 'v1')
|
|
183
|
+
.option('--out <file>', 'Write the words + keys to a file at mode 0600')
|
|
184
|
+
.option('--yes-i-accept-plaintext-file', 'Required with --out')
|
|
185
|
+
.action(async (rest, opts, sub) => {
|
|
186
|
+
if (refuseArgv(sub, opts, rest))
|
|
187
|
+
return;
|
|
188
|
+
const derivation = readDerivationOpt(opts.derivation);
|
|
189
|
+
if (!derivation)
|
|
190
|
+
return fail(sub, '--derivation must be v1 or v2');
|
|
191
|
+
if (opts.out && !opts.yesIAcceptPlaintextFile) {
|
|
192
|
+
return fail(sub, 'refusing to write plaintext key material to disk — pass --yes-i-accept-plaintext-file to override');
|
|
193
|
+
}
|
|
194
|
+
const words = await readWords();
|
|
195
|
+
let v1, v2, userIdPub;
|
|
196
|
+
try {
|
|
197
|
+
v1 = await recoverWallet(words, 'v1');
|
|
198
|
+
v2 = await recoverWallet(words, 'v2');
|
|
199
|
+
userIdPub = await userIdPubFromPhrase(words);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return fail(sub, INVALID_PHRASE);
|
|
203
|
+
}
|
|
204
|
+
if (opts.out) {
|
|
205
|
+
if (existsSync(opts.out))
|
|
206
|
+
return fail(sub, 'that file already exists — move it aside first; a key file is never overwritten');
|
|
207
|
+
const w = derivation === 'v2' ? v2 : v1;
|
|
208
|
+
writeKeysFile(opts.out, JSON.stringify({ mnemonic: w.mnemonic, derivation, userIdPub, addresses: addressesOf(w), keys: w.keys }, null, 2) + '\n', true);
|
|
209
|
+
}
|
|
210
|
+
done(sub, {
|
|
211
|
+
ok: true,
|
|
212
|
+
userIdPub,
|
|
213
|
+
v1: { label: labelFor('v1'), addresses: addressesOf(v1) },
|
|
214
|
+
v2: { label: labelFor('v2'), addresses: addressesOf(v2) },
|
|
215
|
+
...(opts.out ? { out: opts.out, wrote: derivation } : {}),
|
|
216
|
+
});
|
|
217
|
+
}));
|
|
218
|
+
cmd.addCommand(wordsCommand('public', 'The public identity + the four chain addresses for your words — nothing secret, no network')
|
|
219
|
+
.option('--derivation <v>', 'v1 (default) or v2', 'v1')
|
|
220
|
+
.action(async (rest, opts, sub) => {
|
|
221
|
+
if (refuseArgv(sub, opts, rest))
|
|
222
|
+
return;
|
|
223
|
+
const derivation = readDerivationOpt(opts.derivation);
|
|
224
|
+
if (!derivation)
|
|
225
|
+
return fail(sub, '--derivation must be v1 or v2');
|
|
226
|
+
const words = await readWords();
|
|
227
|
+
let wallet, userIdPub;
|
|
228
|
+
try {
|
|
229
|
+
wallet = await recoverWallet(words, derivation);
|
|
230
|
+
userIdPub = await userIdPubFromPhrase(words);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return fail(sub, INVALID_PHRASE);
|
|
234
|
+
}
|
|
235
|
+
done(sub, { ok: true, derivation, label: labelFor(derivation), addresses: addressesOf(wallet), userIdPub });
|
|
236
|
+
}));
|
|
237
|
+
cmd.addCommand(wordsCommand('verify', "Compare this key's public identity with what the server holds — locked | verified | mismatch | unregistered")
|
|
238
|
+
.option('--api <url>', 'API base URL (default https://one.ie)')
|
|
239
|
+
.action(async (rest, opts, sub) => {
|
|
240
|
+
if (refuseArgv(sub, opts, rest))
|
|
241
|
+
return;
|
|
242
|
+
const words = await readWords();
|
|
243
|
+
if (!words) {
|
|
244
|
+
done(sub, { ok: true, verdict: 'locked', note: 'no words given — nothing to compare, and no request was made' });
|
|
245
|
+
process.exitCode = 1;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
let local;
|
|
249
|
+
try {
|
|
250
|
+
local = await userIdPubFromPhrase(words);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return fail(sub, INVALID_PHRASE);
|
|
254
|
+
}
|
|
255
|
+
const apiKey = resolveKey();
|
|
256
|
+
if (!apiKey)
|
|
257
|
+
return fail(sub, 'no API key — set ONE_API_KEY or run: one login');
|
|
258
|
+
const refs = await fetchReferences(resolveBase({ api: opts.api }, 'https://one.ie'), apiKey);
|
|
259
|
+
const verdict = verdictOf(local, refs.flatMap((r) => r.ids));
|
|
260
|
+
// `unregistered` is a claim about ABSENCE: believable only when every source
|
|
261
|
+
// answered. A refused or failed probe is inconclusive, never "not registered".
|
|
262
|
+
if (verdict === 'unregistered' && refs.some((r) => !r.answered)) {
|
|
263
|
+
return fail(sub, 'inconclusive — the server did not answer (auth refused or unreachable), so absence cannot be claimed. A key that is not a person\'s own login also reads as nothing here');
|
|
264
|
+
}
|
|
265
|
+
done(sub, { ok: true, verdict, userIdPub: local });
|
|
266
|
+
if (verdict === 'mismatch')
|
|
267
|
+
process.exitCode = 1;
|
|
268
|
+
}));
|
|
269
|
+
return cmd;
|
|
270
|
+
}
|
package/dist/src/lib/paths.d.ts
CHANGED
|
@@ -31,3 +31,11 @@ export declare function firstExisting(...candidates: string[]): string | null;
|
|
|
31
31
|
export declare function readMachineKey(): string;
|
|
32
32
|
/** Which path the machine-wide key actually came from — for `doctor`, never for auth. */
|
|
33
33
|
export declare function machineKeyPath(): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Write the machine-wide key: atomically (temp + rename, so a concurrent reader
|
|
36
|
+
* never sees half a key), 0600, always at the NEW path. The one writer — `onboard`
|
|
37
|
+
* and `init` each carried their own copy pointed at the legacy `~/.config/oneie`,
|
|
38
|
+
* so a key minted by `onboard` sat where only the CLI's read fallback could find it
|
|
39
|
+
* and the MCP server, which reads the same ladder, was one rename away from missing it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function writeMachineKey(value: string): void;
|
package/dist/src/lib/paths.js
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
* back — `one auth login` rewrites at the new path on its own, and the old file
|
|
17
17
|
* is theirs to remove.
|
|
18
18
|
*/
|
|
19
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
19
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
20
20
|
import { homedir } from 'node:os';
|
|
21
|
-
import { resolve } from 'node:path';
|
|
21
|
+
import { join, resolve } from 'node:path';
|
|
22
22
|
/** `~/.config/one` — the current home for CLI state. */
|
|
23
23
|
export const CONFIG_DIR = resolve(homedir(), '.config', 'one');
|
|
24
24
|
/**
|
|
@@ -75,3 +75,17 @@ export function readMachineKey() {
|
|
|
75
75
|
export function machineKeyPath() {
|
|
76
76
|
return firstExisting(KEY_FILE, LEGACY_KEY_FILE);
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Write the machine-wide key: atomically (temp + rename, so a concurrent reader
|
|
80
|
+
* never sees half a key), 0600, always at the NEW path. The one writer — `onboard`
|
|
81
|
+
* and `init` each carried their own copy pointed at the legacy `~/.config/oneie`,
|
|
82
|
+
* so a key minted by `onboard` sat where only the CLI's read fallback could find it
|
|
83
|
+
* and the MCP server, which reads the same ladder, was one rename away from missing it.
|
|
84
|
+
*/
|
|
85
|
+
export function writeMachineKey(value) {
|
|
86
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
87
|
+
const tmp = join(CONFIG_DIR, '.key.tmp');
|
|
88
|
+
writeFileSync(tmp, value, { mode: 0o600 });
|
|
89
|
+
chmodSync(tmp, 0o600);
|
|
90
|
+
renameSync(tmp, KEY_FILE);
|
|
91
|
+
}
|