oneie 5.7.5 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/package.json +5 -2
- package/dist/src/balances.d.ts +89 -0
- package/dist/src/balances.js +202 -0
- package/dist/src/ceiling.d.ts +36 -0
- package/dist/src/ceiling.js +189 -0
- package/dist/src/check.d.ts +11 -0
- package/dist/src/check.js +53 -0
- package/dist/src/credits.d.ts +29 -0
- package/dist/src/credits.js +88 -0
- package/dist/src/hl-run.d.ts +119 -0
- package/dist/src/hl-run.js +480 -0
- package/dist/src/hl.d.ts +17 -0
- package/dist/src/hl.js +148 -0
- package/dist/src/index.js +15 -1
- package/dist/src/join.js +4 -0
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +70 -20
- package/dist/src/lib/check-words.d.ts +57 -0
- package/dist/src/lib/check-words.js +144 -0
- package/dist/src/lib/hl-core/actions.d.ts +99 -0
- package/dist/src/lib/hl-core/actions.js +69 -0
- package/dist/src/lib/hl-core/eip712.d.ts +33 -0
- package/dist/src/lib/hl-core/eip712.js +107 -0
- package/dist/src/lib/hl-core/errors.d.ts +10 -0
- package/dist/src/lib/hl-core/errors.js +15 -0
- package/dist/src/lib/hl-core/exchange.d.ts +24 -0
- package/dist/src/lib/hl-core/exchange.js +47 -0
- package/dist/src/lib/hl-core/index.d.ts +13 -0
- package/dist/src/lib/hl-core/index.js +14 -0
- package/dist/src/lib/hl-core/meta.d.ts +57 -0
- package/dist/src/lib/hl-core/meta.js +110 -0
- package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
- package/dist/src/lib/hl-core/msgpack.js +136 -0
- package/dist/src/lib/hl-core/net.d.ts +2 -0
- package/dist/src/lib/hl-core/net.js +7 -0
- package/dist/src/lib/hl-core/signing.d.ts +103 -0
- package/dist/src/lib/hl-core/signing.js +295 -0
- package/dist/src/lib/hl-core/wire.d.ts +34 -0
- package/dist/src/lib/hl-core/wire.js +81 -0
- package/dist/src/lib/journey-words.d.ts +54 -3
- package/dist/src/lib/journey-words.js +162 -20
- package/dist/src/lib/journey.d.ts +2 -0
- package/dist/src/lib/journey.js +21 -2
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/net-choice.d.ts +28 -0
- package/dist/src/lib/net-choice.js +72 -0
- package/dist/src/lib/network.d.ts +22 -0
- package/dist/src/lib/network.js +50 -0
- package/dist/src/lib/next-words.d.ts +105 -0
- package/dist/src/lib/next-words.js +298 -0
- package/dist/src/lib/qr.d.ts +21 -0
- package/dist/src/lib/qr.js +402 -0
- package/dist/src/lib/sale-card.d.ts +117 -0
- package/dist/src/lib/sale-card.js +261 -0
- package/dist/src/lib/sui-grpc-send.d.ts +90 -0
- package/dist/src/lib/sui-grpc-send.js +128 -0
- package/dist/src/lib/timed-fetch.d.ts +33 -0
- package/dist/src/lib/timed-fetch.js +59 -0
- package/dist/src/lib/vaultfile.d.ts +15 -0
- package/dist/src/lib/vaultfile.js +28 -1
- package/dist/src/lib/wallet-money.d.ts +222 -0
- package/dist/src/lib/wallet-money.js +578 -0
- package/dist/src/lib/wallet-request.d.ts +50 -0
- package/dist/src/lib/wallet-request.js +86 -0
- package/dist/src/move.d.ts +36 -0
- package/dist/src/move.js +152 -0
- package/dist/src/network-cmd.d.ts +17 -0
- package/dist/src/network-cmd.js +74 -0
- package/dist/src/next.d.ts +12 -0
- package/dist/src/next.js +67 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop-buy.d.ts +16 -0
- package/dist/src/shop-buy.js +101 -0
- package/dist/src/shop.js +40 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.d.ts +12 -0
- package/dist/src/start.js +51 -21
- package/dist/src/thread.d.ts +2 -0
- package/dist/src/thread.js +52 -0
- package/dist/src/wallet-money.d.ts +158 -0
- package/dist/src/wallet-money.js +664 -0
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +290 -27
- package/dist/src/workflow.js +4 -1
- package/package.json +5 -2
package/dist/src/shop.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { shopBuyCmd } from './shop-buy.js';
|
|
2
3
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { authHeaders, out, resolveBase } from './lib/client.js';
|
|
4
|
+
import { authHeaders, jsonMode, out, resolveBase } from './lib/client.js';
|
|
4
5
|
import { askPath } from './lib/api-path.js';
|
|
5
6
|
import { parseFacts, shopInit } from './lib/shop-init.js';
|
|
7
|
+
import { SALE_CHANNEL_IDS, SALE_KIND_IDS, SALE_RAIL_IDS, drawSale, saleChannelOf, saleJson, saleKindOf, saleRailOf, } from './lib/sale-card.js';
|
|
6
8
|
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
9
|
/**
|
|
8
10
|
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
@@ -69,5 +71,42 @@ export function shopCmd() {
|
|
|
69
71
|
if (r.fillRequested && !r.filled)
|
|
70
72
|
process.exitCode = 1;
|
|
71
73
|
});
|
|
74
|
+
// A picture of the sale, drawn locally: no key, no network, nothing charged. The drawing lives in
|
|
75
|
+
// lib/sale-card.ts so it is tested without a terminal.
|
|
76
|
+
cmd
|
|
77
|
+
.command('card')
|
|
78
|
+
.description('Draw how your agent sells: the pay card, alone or inside a WhatsApp, SMS or email thread')
|
|
79
|
+
.option('--kind <kind>', `What is sold: ${SALE_KIND_IDS.join('|')}`, 'course')
|
|
80
|
+
.option('--rail <rail>', `How they pay: ${SALE_RAIL_IDS.join('|')}`, 'card')
|
|
81
|
+
.option('--channel <id>', `Where it is sold: ${SALE_CHANNEL_IDS.join('|')}`)
|
|
82
|
+
.option('--all', 'All four offers')
|
|
83
|
+
.option('--paid', 'Draw the card after the tap')
|
|
84
|
+
.action((opts, c) => {
|
|
85
|
+
const kind = saleKindOf(opts.kind);
|
|
86
|
+
const rail = saleRailOf(opts.rail);
|
|
87
|
+
const channel = opts.channel === undefined ? undefined : saleChannelOf(opts.channel);
|
|
88
|
+
// An unknown word is refused, never drawn as the default: a wrong picture reads as a right one.
|
|
89
|
+
if (!kind) {
|
|
90
|
+
out(c, { ok: false, error: `unknown kind "${opts.kind}" — ${SALE_KIND_IDS.join(', ')}` });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!rail) {
|
|
94
|
+
out(c, { ok: false, error: `unknown rail "${opts.rail}" — ${SALE_RAIL_IDS.join(', ')}` });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (channel === null) {
|
|
98
|
+
out(c, { ok: false, error: `unknown channel "${opts.channel}" — ${SALE_CHANNEL_IDS.join(', ')}` });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const kinds = opts.all ? SALE_KIND_IDS : [kind];
|
|
102
|
+
const draw = { rail, channel, phase: opts.paid ? 'paid' : 'idle' };
|
|
103
|
+
if (jsonMode(c)) {
|
|
104
|
+
out(c, saleJson(kinds, draw));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const ascii = !process.stdout.isTTY || 'NO_COLOR' in process.env;
|
|
108
|
+
process.stdout.write(drawSale(kinds, { ...draw, ascii }));
|
|
109
|
+
});
|
|
110
|
+
cmd.addCommand(shopBuyCmd());
|
|
72
111
|
return cmd;
|
|
73
112
|
}
|
package/dist/src/staff.js
CHANGED
|
@@ -88,6 +88,16 @@ export function staffCmd() {
|
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const result = json.result ?? json;
|
|
91
|
+
// The ask door answers a refusal INSIDE result (`{outcome:"failure", result:{error,reason}}`)
|
|
92
|
+
// with HTTP 200 — read it, or a forbidden prints `aid=undefined key=undefined` as ok.
|
|
93
|
+
if (result.error) {
|
|
94
|
+
out(cmd, { ok: false, error: result.reason ?? result.error });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!result.aid || !result.key) {
|
|
98
|
+
out(cmd, { ok: false, error: 'door answered without aid/key' });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
91
101
|
out(cmd, { ok: true, name, role, aid: result.aid, key: result.key });
|
|
92
102
|
});
|
|
93
103
|
return cmd;
|
package/dist/src/start.d.ts
CHANGED
|
@@ -8,8 +8,20 @@
|
|
|
8
8
|
* replace the machine key someone already logs in with.
|
|
9
9
|
*/
|
|
10
10
|
import { Command } from 'commander';
|
|
11
|
+
import { type JourneyDeps } from './lib/journey.js';
|
|
11
12
|
/** The flags bare `npx oneie --email …` hands to `start` — the journey's own, nothing else. */
|
|
12
13
|
export declare const START_FLAGS: Set<string>;
|
|
13
14
|
/** Bare `oneie`, or `oneie` led by a journey flag, runs `start`. Everything else is untouched. */
|
|
14
15
|
export declare function startArgv(argv: string[]): string[];
|
|
16
|
+
/** A progress line for a person (stderr, so `--json` stdout stays one object). Silent in JSON mode. */
|
|
17
|
+
export type Say = (line: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The journey's wiring. Exported, with `f` and `limits` injectable, so a test can
|
|
20
|
+
* drive these exact round trips against a server that never answers
|
|
21
|
+
* (`tests/journey-no-answer.test.ts`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function journeyDeps(dir: string, api: string, say: Say, f?: typeof fetch, limits?: {
|
|
24
|
+
askMs: number;
|
|
25
|
+
provisionMs: number;
|
|
26
|
+
}): JourneyDeps;
|
|
15
27
|
export declare function startCmd(): Command;
|
package/dist/src/start.js
CHANGED
|
@@ -19,7 +19,9 @@ import { agentType } from './lib/agent-env.js';
|
|
|
19
19
|
import { provisionLocalWallet } from './init.js';
|
|
20
20
|
import { promptSecret, registerSealedWallet } from './wallet.js';
|
|
21
21
|
import { parseProductSpec, runJourney, } from './lib/journey.js';
|
|
22
|
-
import { journeyIntro, journeyResume, journeyWords } from './lib/journey-words.js';
|
|
22
|
+
import { asciiOf, haveNow, journeyIntro, journeyResume, journeyWords } from './lib/journey-words.js';
|
|
23
|
+
import { learnNetwork } from './lib/network.js';
|
|
24
|
+
import { ASK_TIMEOUT_MS, NoAnswerError, PROVISION_TIMEOUT_MS, fetchJson } from './lib/timed-fetch.js';
|
|
23
25
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
24
26
|
/** The flags bare `npx oneie --email …` hands to `start` — the journey's own, nothing else. */
|
|
25
27
|
export const START_FLAGS = new Set(['--name', '--email', '--product', '--currency', '--wait', '--api']);
|
|
@@ -75,8 +77,14 @@ async function walletStore(dir) {
|
|
|
75
77
|
return { error: 'that passphrase is shorter than 8 characters, so no wallet was made. Run it again with a longer one' };
|
|
76
78
|
return { kind: 'vault', dir, passphrase };
|
|
77
79
|
}
|
|
78
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The journey's wiring. Exported, with `f` and `limits` injectable, so a test can
|
|
82
|
+
* drive these exact round trips against a server that never answers
|
|
83
|
+
* (`tests/journey-no-answer.test.ts`).
|
|
84
|
+
*/
|
|
85
|
+
export function journeyDeps(dir, api, say, f = fetch, limits = { askMs: ASK_TIMEOUT_MS, provisionMs: PROVISION_TIMEOUT_MS }) {
|
|
79
86
|
return {
|
|
87
|
+
say,
|
|
80
88
|
load: () => loadState(dir),
|
|
81
89
|
save: (s) => saveState(dir, s),
|
|
82
90
|
key: () => {
|
|
@@ -102,13 +110,19 @@ function deps(dir, api, say) {
|
|
|
102
110
|
},
|
|
103
111
|
provision: async (body) => {
|
|
104
112
|
say('Making your agent\'s key and its own group on one.ie…');
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
// A write, so a silent server is reported and never retried: a second call would make a second group.
|
|
114
|
+
try {
|
|
115
|
+
return await fetchJson(f, `${api}/api/provision/agent`, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: { 'Content-Type': 'application/json' },
|
|
118
|
+
body: JSON.stringify(body),
|
|
119
|
+
}, limits.provisionMs, `${api}/api/provision/agent`);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
if (!(e instanceof NoAnswerError))
|
|
123
|
+
throw e;
|
|
124
|
+
return { ok: false, status: 0, json: { error: `${e.message}. Nothing was saved in this folder, so run \`npx oneie\` again` } };
|
|
125
|
+
}
|
|
112
126
|
},
|
|
113
127
|
saveKey: (p) => writeKeyFolder({ dir, api, ...p }),
|
|
114
128
|
wallet: async ({ key, workspace }) => {
|
|
@@ -131,12 +145,21 @@ function deps(dir, api, say) {
|
|
|
131
145
|
return provisionLocalWallet({ api, key, workspace, store });
|
|
132
146
|
},
|
|
133
147
|
ask: async (key, receiver, data) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
let res;
|
|
149
|
+
try {
|
|
150
|
+
res = await fetchJson(f, askPath(api, receiver), {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
153
|
+
body: JSON.stringify({ data }),
|
|
154
|
+
}, limits.askMs, receiver);
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
// A silent server is its own outcome, so the journey can name it instead of hanging.
|
|
158
|
+
if (e instanceof NoAnswerError)
|
|
159
|
+
return { outcome: 'no_answer', error: e.message };
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
const body = res.json;
|
|
140
163
|
// A transport-level refusal is its own outcome — never read as an empty success.
|
|
141
164
|
if (!res.ok)
|
|
142
165
|
return { outcome: `http_${res.status}`, error: String(body.error ?? body.detail ?? '') };
|
|
@@ -149,7 +172,7 @@ function deps(dir, api, say) {
|
|
|
149
172
|
export function startCmd() {
|
|
150
173
|
const cmd = new Command('start')
|
|
151
174
|
.description('Walk the whole path in this folder: your key, a product, a test sale, then one link that hands it over. Bare `npx oneie` runs it; run it again to pick up where you left off')
|
|
152
|
-
.option('--name <name>', '
|
|
175
|
+
.option('--name <name>', 'Group / agent display name', 'My Shop')
|
|
153
176
|
.option('--email <email>', "The new owner's email — the handover link is sent there as well as printed")
|
|
154
177
|
.option('--product <name=price>', 'A product in major units, e.g. "Mug=12.50" (repeatable; default one Test product at 1.00)', (v, acc) => [...acc, v], [])
|
|
155
178
|
.option('--currency <iso>', 'ISO 4217 for --product prices', 'usd')
|
|
@@ -172,22 +195,29 @@ export function startCmd() {
|
|
|
172
195
|
const api = opts.api.replace(/\/$/, '');
|
|
173
196
|
const json = jsonMode(sub);
|
|
174
197
|
const cli = cliPrefix();
|
|
198
|
+
// A pipe, a log or NO_COLOR gets plain ASCII: the same words, no box or glyph it cannot draw.
|
|
199
|
+
const plain = !process.stdout.isTTY || 'NO_COLOR' in process.env;
|
|
200
|
+
const fmt = (text) => (plain ? asciiOf(text) : text);
|
|
175
201
|
if (!json) {
|
|
176
202
|
const earlier = loadState(process.cwd());
|
|
177
|
-
process.stdout.write(earlier ? journeyResume(earlier.workspace) : journeyIntro(cli));
|
|
203
|
+
process.stdout.write(fmt(earlier ? journeyResume(earlier.workspace) : journeyIntro(cli)));
|
|
178
204
|
}
|
|
179
|
-
|
|
180
|
-
const
|
|
205
|
+
// The network shapes the words and `have.network`; asked now, in parallel with the walk, never blocking it.
|
|
206
|
+
const netP = learnNetwork(api);
|
|
207
|
+
const say = json ? () => { } : (line) => process.stderr.write(` ${fmt(line)}\n`);
|
|
208
|
+
const report = await runJourney(journeyDeps(process.cwd(), api, say), {
|
|
181
209
|
api,
|
|
182
210
|
name: opts.name,
|
|
183
211
|
...(opts.email ? { email: opts.email } : {}),
|
|
184
212
|
products,
|
|
185
213
|
...(opts.wait !== undefined ? { waitSeconds: Math.max(0, Number(opts.wait) || 0) } : {}),
|
|
186
214
|
});
|
|
215
|
+
const net = await netP;
|
|
216
|
+
// `have` is additive: every fact the panel prints, in full, beside the report's own keys.
|
|
187
217
|
if (json)
|
|
188
|
-
process.stdout.write(JSON.stringify(report) + '\n');
|
|
218
|
+
process.stdout.write(JSON.stringify({ ...report, have: haveNow(report, cli, { net }) }) + '\n');
|
|
189
219
|
else
|
|
190
|
-
process.stdout.write('\n' + journeyWords(report, cli, { agent: agentType() }));
|
|
220
|
+
process.stdout.write(fmt('\n' + journeyWords(report, cli, { agent: agentType(), net })));
|
|
191
221
|
if (!report.ok)
|
|
192
222
|
process.exitCode = 1;
|
|
193
223
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { authHeaders, jsonMode, out, resolveBase } from './lib/client.js';
|
|
3
|
+
import { askPath } from './lib/api-path.js';
|
|
4
|
+
// Room text is written by other people (and strangers, through the sealed-note door): strip
|
|
5
|
+
// C0/C1 controls and ESC before it reaches a terminal, so a message cannot rewrite the screen.
|
|
6
|
+
// Newline and tab survive in message bodies; every other field is one line.
|
|
7
|
+
const clean = (v, multiline = false) => String(v ?? '').replace(multiline ? /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g : /[\u0000-\u001f\u007f-\u009f]/g, '');
|
|
8
|
+
export function threadCmd() {
|
|
9
|
+
const cmd = new Command('thread').description('Read a thread (a room, an inbox conversation) a page at a time — members of its group only');
|
|
10
|
+
cmd
|
|
11
|
+
.command('read <threadId>')
|
|
12
|
+
.description('Read one page of a thread, newest messages last (thread:read). Says when the page is short')
|
|
13
|
+
.option('--limit <n>', 'Messages per page (default 50, max 200)')
|
|
14
|
+
.option('--before <cursor>', 'Older page: the nextCursor of the previous read')
|
|
15
|
+
.option('--after <cursor>', 'Only what arrived after this cursor')
|
|
16
|
+
.option('--api <url>', 'API base URL')
|
|
17
|
+
.option('--json', 'One JSON line')
|
|
18
|
+
.action(async (threadId, opts, sub) => {
|
|
19
|
+
const base = resolveBase(opts, 'https://api.one.ie');
|
|
20
|
+
const data = { threadId };
|
|
21
|
+
if (opts.limit)
|
|
22
|
+
data.limit = Number(opts.limit);
|
|
23
|
+
if (opts.before)
|
|
24
|
+
data.before = opts.before;
|
|
25
|
+
if (opts.after)
|
|
26
|
+
data.after = opts.after;
|
|
27
|
+
const res = await fetch(askPath(base, 'thread:read'), { method: 'POST', headers: authHeaders(), body: JSON.stringify({ data }) });
|
|
28
|
+
const body = (await res.json().catch(() => null));
|
|
29
|
+
const ans = body && 'outcome' in body
|
|
30
|
+
? (body.result ?? { ok: false, error: body.reason ?? body.outcome ?? 'no_answer' })
|
|
31
|
+
: (body ?? { ok: false, error: `http_${res.status}` });
|
|
32
|
+
if (!res.ok && ans.ok !== false)
|
|
33
|
+
ans.ok = false;
|
|
34
|
+
if (jsonMode(sub) || ans.ok === false) {
|
|
35
|
+
out(sub, ans);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const msgs = ans.messages ?? [];
|
|
39
|
+
const head = `${clean(ans.thread?.name ?? ans.thread?.id ?? threadId)} · ${clean(ans.thread?.slug)} · ${msgs.length} message${msgs.length === 1 ? '' : 's'}`;
|
|
40
|
+
process.stdout.write(head + '\n');
|
|
41
|
+
if (ans.older && ans.nextCursor)
|
|
42
|
+
process.stdout.write(` … earlier messages exist — one thread read ${threadId} --before ${clean(ans.nextCursor)}\n`);
|
|
43
|
+
for (const m of msgs) {
|
|
44
|
+
const who = clean(m.sender ?? m.role);
|
|
45
|
+
const when = Number.isFinite(m.at) ? new Date(m.at > 1e12 ? m.at : m.at * 1000).toISOString() : '?';
|
|
46
|
+
process.stdout.write(`[${when}] ${who}: ${clean(m.text, true)}\n`);
|
|
47
|
+
}
|
|
48
|
+
if (ans.newer && ans.newerCursor)
|
|
49
|
+
process.stdout.write(` … more arrived — one thread read ${threadId} --after ${clean(ans.newerCursor)}\n`);
|
|
50
|
+
});
|
|
51
|
+
return cmd;
|
|
52
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wallet-money.ts — the loaded wallet's money, one command away:
|
|
3
|
+
*
|
|
4
|
+
* one wallet balances [--net mainnet|testnet] every chain, wallet:get first, chains for the rest
|
|
5
|
+
* one wallet receive --chain base one address, one QR, never ambiguous
|
|
6
|
+
* one wallet send 1 USDC@base 0x… DRY: exactly what would be signed, fees, the chain
|
|
7
|
+
* one wallet send 0.0004 ETH@ethereum 0x… --live --dir ~/.one/tony
|
|
8
|
+
* one wallet request 25 USD a wallet:invoice payment link
|
|
9
|
+
* one wallet request 5 USDC --wait a link the owner opens and signs with Touch ID
|
|
10
|
+
*
|
|
11
|
+
* THE SERVER SIGNS NOTHING (R19). A --live send opens the sealed vault in --dir on THIS
|
|
12
|
+
* machine (Touch ID or a typed passphrase), signs here, broadcasts to a public node, and
|
|
13
|
+
* drops the key. Before the key opens: the gate (an agent shell signs only with its OWN
|
|
14
|
+
* vault and --yes), and the client check (R16) — the transaction is rebuilt from the
|
|
15
|
+
* person's own words and compared, never trusted from an echo.
|
|
16
|
+
*
|
|
17
|
+
* `balances` is the dev session's command (src/balances.ts, kept byte-identical so the two
|
|
18
|
+
* merge cleanly); `upgradeBalances` adds --net and the wallet:get fan-out to it in place.
|
|
19
|
+
*/
|
|
20
|
+
import { Command } from 'commander';
|
|
21
|
+
import { type Fetch } from './balances.js';
|
|
22
|
+
import { type SuiSendReq, type SuiSendDone } from './lib/sui-grpc-send.js';
|
|
23
|
+
import { type Addresses, type Net, type Obj, type SendPlan, type SendAsset, type SendChain } from './lib/wallet-money.js';
|
|
24
|
+
type Ask = (receiver: string, data: Obj) => Promise<Obj>;
|
|
25
|
+
type VaultKey = {
|
|
26
|
+
chain: string;
|
|
27
|
+
address: string;
|
|
28
|
+
privateKeyHex: string;
|
|
29
|
+
};
|
|
30
|
+
export interface MoneyIO {
|
|
31
|
+
/** One receiver call for this command's --api/--key; throws on a refusal. */
|
|
32
|
+
ask: (opts: {
|
|
33
|
+
api: string;
|
|
34
|
+
key?: string;
|
|
35
|
+
}, receiver: string, data: Obj) => Promise<Obj>;
|
|
36
|
+
workspace: (explicit: string | undefined) => string;
|
|
37
|
+
/** Who this command's key acts as, and where it came from (`machine` = the global login, null when it is the same key). */
|
|
38
|
+
identity?: (opts: {
|
|
39
|
+
api: string;
|
|
40
|
+
key?: string;
|
|
41
|
+
}, which: 'resolved' | 'machine') => Promise<{
|
|
42
|
+
actor?: string;
|
|
43
|
+
from: string;
|
|
44
|
+
local: boolean;
|
|
45
|
+
} | null>;
|
|
46
|
+
unlock: (dir: string) => Promise<{
|
|
47
|
+
keys: VaultKey[];
|
|
48
|
+
} | {
|
|
49
|
+
error: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** The pre-signed relay (`send <to> --payment-tx`) — the form `wallet send` had before. */
|
|
52
|
+
relay: (c: Command, to: string, opts: Obj) => Promise<void>;
|
|
53
|
+
defaultApi: string;
|
|
54
|
+
fetch?: Fetch;
|
|
55
|
+
sleep?: (ms: number) => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/** fetch with a deadline: a node that hangs is a failed read, not a hung CLI. */
|
|
58
|
+
export declare const deadlineFetch: (ms?: number) => Fetch;
|
|
59
|
+
/** A word safe to paste into a shell: plain words as they are, anything else single-quoted. */
|
|
60
|
+
export declare const shq: (w: string) => string;
|
|
61
|
+
export interface GateArgs {
|
|
62
|
+
env: NodeJS.ProcessEnv;
|
|
63
|
+
yes: boolean;
|
|
64
|
+
interactive: boolean;
|
|
65
|
+
dir: string;
|
|
66
|
+
plan: SendPlan;
|
|
67
|
+
/** `--to-address`: the person's own copy of a resolved recipient. */
|
|
68
|
+
toAddress?: string;
|
|
69
|
+
/** `--workspace`: where the caller's wallet row lives (an agent's: its owner's workspace). */
|
|
70
|
+
workspace?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface GateDeps {
|
|
73
|
+
ask: Ask;
|
|
74
|
+
/** The vault's Sui address from its public authPub — no unlock, no Touch ID. */
|
|
75
|
+
vaultSuiAddress: (dir: string) => string | null;
|
|
76
|
+
confirm: (prompt: string) => Promise<boolean>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Before any key opens. `--yes` skips the prompt ONLY for a vault proven to be an agent's
|
|
80
|
+
* own (agentOwnVault) — never on an env marker alone, which a shell can simply not set, and
|
|
81
|
+
* never for a person's vault: the Keychain read behind "Touch ID" is `security -w`, which
|
|
82
|
+
* the OS may answer silently. A person's vault is opened only after a y/N typed at a terminal,
|
|
83
|
+
* every time. A shell an agent drives never opens anything but its own vault. A recipient
|
|
84
|
+
* found by name must be pinned with --to-address whenever nobody reads it at a prompt.
|
|
85
|
+
*/
|
|
86
|
+
export declare function liveGate(a: GateArgs, d: GateDeps): Promise<{
|
|
87
|
+
ok: true;
|
|
88
|
+
} | {
|
|
89
|
+
ok: false;
|
|
90
|
+
error: string;
|
|
91
|
+
message: string;
|
|
92
|
+
}>;
|
|
93
|
+
export interface EvmSigner {
|
|
94
|
+
signEip1559: (tx: NonNullable<SendPlan['tx']>, key: Uint8Array) => string;
|
|
95
|
+
evmAddressFromKey: (key: Uint8Array) => string;
|
|
96
|
+
evmTxHash: (raw: string) => string;
|
|
97
|
+
hexToBytes: (h: string) => Uint8Array;
|
|
98
|
+
}
|
|
99
|
+
export type { SuiSendReq, SuiSendDone };
|
|
100
|
+
export interface LiveDeps {
|
|
101
|
+
fetch: Fetch;
|
|
102
|
+
unlock: () => Promise<{
|
|
103
|
+
keys: VaultKey[];
|
|
104
|
+
} | {
|
|
105
|
+
error: string;
|
|
106
|
+
}>;
|
|
107
|
+
loadEvm?: () => Promise<EvmSigner>;
|
|
108
|
+
/** A string is a digest alone (the older shape); SuiSendDone carries the gas and the time to finality too. */
|
|
109
|
+
suiSend?: (r: SuiSendReq) => Promise<SuiSendDone | string>;
|
|
110
|
+
sleep?: (ms: number) => Promise<void>;
|
|
111
|
+
/** Receipt polls after an EVM broadcast (each `sleep(5000)` apart). */
|
|
112
|
+
polls?: number;
|
|
113
|
+
}
|
|
114
|
+
export declare const suiSendDefault: (r: SuiSendReq) => Promise<SuiSendDone>;
|
|
115
|
+
/**
|
|
116
|
+
* Sign and broadcast ONE plan. The client check runs first, against the person's own
|
|
117
|
+
* words; then the vault opens; then its key must derive `from`. One broadcast, never
|
|
118
|
+
* re-sent: on a failure after signing the locally computed hash is returned so the
|
|
119
|
+
* person can look before trying again.
|
|
120
|
+
*/
|
|
121
|
+
export declare function executeSend(plan: SendPlan, own: {
|
|
122
|
+
amount: string;
|
|
123
|
+
asset: SendAsset;
|
|
124
|
+
chain: SendChain;
|
|
125
|
+
to: string;
|
|
126
|
+
net: Net;
|
|
127
|
+
suiRpc?: string;
|
|
128
|
+
split?: number;
|
|
129
|
+
}, d: LiveDeps): Promise<Obj>;
|
|
130
|
+
export type Who = {
|
|
131
|
+
actor?: string;
|
|
132
|
+
from: string;
|
|
133
|
+
local: boolean;
|
|
134
|
+
};
|
|
135
|
+
export declare const actingLine: (w: Who | null | undefined) => string | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* `no_from_address` from a folder-local key that is NOT the global login is the folder changing the
|
|
138
|
+
* answer: name both, and the way out. Any other refusal keeps its own words.
|
|
139
|
+
*/
|
|
140
|
+
export declare function noFromCause(io: MoneyIO, o: {
|
|
141
|
+
api: string;
|
|
142
|
+
key?: string;
|
|
143
|
+
}, me: Who | null | undefined, family: string, workspace: string): Promise<string | undefined>;
|
|
144
|
+
/**
|
|
145
|
+
* Give the dev session's `balances` (src/balances.ts) the network word and the server
|
|
146
|
+
* fan-out. Its explicit-address form on mainnet is left to its own reader, unchanged.
|
|
147
|
+
*/
|
|
148
|
+
export declare function upgradeBalances(balances: Command, io: MoneyIO): void;
|
|
149
|
+
export declare function receiveCmd(io: MoneyIO): Command;
|
|
150
|
+
/** Every wallet this machine holds a sealed key or a public sidecar for, by its PUBLIC addresses only. */
|
|
151
|
+
export declare function localWallets(root?: string): Array<{
|
|
152
|
+
label: string;
|
|
153
|
+
addresses: Addresses;
|
|
154
|
+
}>;
|
|
155
|
+
export declare function requestCmd(io: MoneyIO): Command;
|
|
156
|
+
export declare function sendCmd(io: MoneyIO): Command;
|
|
157
|
+
/** The vault's Sui address from its PUBLIC authPub — read without opening it. */
|
|
158
|
+
export declare function vaultSuiAddressOf(dir: string): string | null;
|