oneie 5.7.5 → 5.7.6
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 +1 -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/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 +2 -1
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +63 -20
- 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 +159 -20
- package/dist/src/lib/journey.js +1 -1
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/network.d.ts +15 -0
- package/dist/src/lib/network.js +41 -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 +50 -0
- package/dist/src/lib/sui-grpc-send.js +89 -0
- 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/onboard.js +4 -3
- package/dist/src/shop.js +38 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.js +14 -6
- package/dist/src/wallet-money.d.ts +152 -0
- package/dist/src/wallet-money.js +564 -0
- package/dist/src/wallet.js +169 -24
- package/package.json +5 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const STEPS = [
|
|
2
|
-
{ step: 'key', title: 'Your key', line: 'Your agent makes its own key on this machine, and its wallets.',
|
|
2
|
+
{ step: 'key', title: 'Your key', line: 'Your agent makes its own key on this machine, and its wallets. On a Mac it locks in the Keychain; at a terminal you type a passphrase.',
|
|
3
3
|
why: 'Whoever holds the key holds the money. Here that is this machine, not ONE.' },
|
|
4
4
|
{ step: 'products', title: 'Your product', line: 'It opens a shop and makes a product with its own checkout page.',
|
|
5
5
|
why: 'A checkout page is how anyone, a person or an agent, pays you.' },
|
|
@@ -25,25 +25,45 @@ export function box(lines) {
|
|
|
25
25
|
const w = Math.max(...lines.map((l) => [...l].length));
|
|
26
26
|
return ['╭' + '─'.repeat(w + 4) + '╮', ...lines.map((l) => `│ ${l}${' '.repeat(w - [...l].length)} │`), '╰' + '─'.repeat(w + 4) + '╯'];
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// Line two is beat 1's line in text/one.md § The VSL: the benefit, before any step.
|
|
29
|
+
const HEADER = box(['ONE · Give your agents financial superpowers', 'Your agent can sell and be paid. Here is how.']);
|
|
30
|
+
/**
|
|
31
|
+
* The eight beats of text/one.md § The VSL, in the script's order and words: the same story the home
|
|
32
|
+
* page, its chat and its film tell. Each carries the one command that does it where the CLI has one
|
|
33
|
+
* (a beat without one is told, not run). Beat 4's send is a screen: the CLI never signs a send.
|
|
34
|
+
* Lines the script holds back until their row is true (Apple Pay, "earnings come back") are not said here.
|
|
35
|
+
* `journey-words.test.ts` reads the beat names from the script, so a reorder there goes red here.
|
|
36
|
+
*/
|
|
37
|
+
const BEATS = [
|
|
38
|
+
{ label: 'The sale', line: 'Your agent sells on your site, in a chat, or by link.' },
|
|
39
|
+
{ label: 'The call', line: 'Tell it what you sell. It makes a link for each.', run: (c) => `${c} --product "Mug=12.50"` },
|
|
40
|
+
{ label: 'Cards', line: 'You pay Stripe\'s cost. ONE adds nothing.' },
|
|
41
|
+
{ label: 'Crypto', line: 'By default USDC goes straight to you. ONE takes 0%.', run: () => 'https://one.ie/wallets, once you own it' },
|
|
42
|
+
{ label: 'The key', line: 'Your machine makes it. Nobody else has it.', run: (c) => `${c} wallet paper` },
|
|
43
|
+
{ label: 'Your agents', line: 'Its own wallet, and a credit limit only you can raise.', run: (c) => `${c} wallet get` },
|
|
44
|
+
{ label: 'Do it now', line: 'Pay your own link with a test card. Watch it land.', run: (c) => c },
|
|
45
|
+
{ label: 'The gift', line: 'It was free. Then Sold, the course.', run: () => 'https://one.ie/sold' },
|
|
46
|
+
];
|
|
47
|
+
/** Shown before a first run: the story in eight lines, then what the run does. Nothing here waits on the network. */
|
|
30
48
|
export function journeyIntro(cli) {
|
|
31
|
-
const
|
|
49
|
+
const w = Math.max(...BEATS.map((s) => s.label.length));
|
|
50
|
+
const pad = ' '.repeat(w + 7);
|
|
32
51
|
return [
|
|
33
52
|
...HEADER,
|
|
34
53
|
'',
|
|
35
|
-
|
|
36
|
-
'',
|
|
37
|
-
...STEPS.map((s, i) => ` ${i + 1}. ${s.title.padEnd(width)} ${s.line}`),
|
|
54
|
+
...BEATS.flatMap((s, i) => [` ${i + 1} ${s.label.padEnd(w)} ${s.line}`, ...(s.run ? [`${pad}${s.run(cli)}`] : [])]),
|
|
38
55
|
'',
|
|
39
|
-
|
|
56
|
+
`Run ${cli}. It walks four checks:`,
|
|
57
|
+
` ${STEPS.map((s) => s.title).join(', ')}.`,
|
|
58
|
+
'You are in control. The sale is a test card, so no real money moves.',
|
|
59
|
+
'Nothing secret is printed.',
|
|
40
60
|
`Stop at any step. Run ${cli} again and it picks up where it left off.`,
|
|
41
61
|
'',
|
|
42
62
|
].join('\n') + '\n';
|
|
43
63
|
}
|
|
44
64
|
/** Shown before a re-run. */
|
|
45
|
-
export function journeyResume(
|
|
46
|
-
return [...HEADER, '', `Picking up where you left off,
|
|
65
|
+
export function journeyResume(group) {
|
|
66
|
+
return [...HEADER, '', `Picking up where you left off, in group ${group}.`, '', ''].join('\n');
|
|
47
67
|
}
|
|
48
68
|
function addressLines(addresses) {
|
|
49
69
|
const seen = new Set();
|
|
@@ -88,7 +108,7 @@ function keyLines(s, cli) {
|
|
|
88
108
|
];
|
|
89
109
|
}
|
|
90
110
|
return [
|
|
91
|
-
'Your agent made its own key, here on this machine. ONE never saw it.',
|
|
111
|
+
'Your agent made its own wallet key, here on this machine. ONE never saw it. ONE issued a separate API key.',
|
|
92
112
|
keychain ? 'It is locked in your Apple Keychain. Touch ID opens it.' : 'It is locked with the passphrase you chose.',
|
|
93
113
|
'',
|
|
94
114
|
n > 0
|
|
@@ -116,16 +136,17 @@ function productLines(s, cli) {
|
|
|
116
136
|
}),
|
|
117
137
|
];
|
|
118
138
|
}
|
|
119
|
-
function saleLines(s, cli) {
|
|
139
|
+
function saleLines(s, cli, net = 'testnet') {
|
|
120
140
|
if (s.status === 'failed')
|
|
121
141
|
return failed(s, cli);
|
|
122
142
|
if (s.status === 'done') {
|
|
123
143
|
const n = Number(s.detail.purchases ?? 1);
|
|
124
|
-
return [`${n === 1 ? 'One sale' : `${n} sales`} counted, read back from your shop. Test money: nothing real moved.`];
|
|
144
|
+
return [`${n === 1 ? 'One sale' : `${n} sales`} counted, read back from your shop. ${net === 'testnet' ? 'Test money' : 'Test sale'}: nothing real moved.`];
|
|
125
145
|
}
|
|
126
146
|
const [number, ...rest] = String(s.detail.card ?? '').split(' · ');
|
|
127
147
|
return [
|
|
128
|
-
|
|
148
|
+
// Two whole lines, not a template: home-journey.test.ts holds the page's mirror of this line to the source text.
|
|
149
|
+
net === 'testnet' ? 'Nothing sold yet. Make the first sale yourself, with test money:' : 'Nothing sold yet. Make the first sale yourself, with a test card:',
|
|
129
150
|
'',
|
|
130
151
|
` 1. Open this page ${String(s.detail.pay ?? '')}`,
|
|
131
152
|
` 2. Pay with test card ${number}`,
|
|
@@ -135,7 +156,7 @@ function saleLines(s, cli) {
|
|
|
135
156
|
'No real card is charged. The sale counts only once your shop reads it back.',
|
|
136
157
|
];
|
|
137
158
|
}
|
|
138
|
-
function handoverLines(s, cli) {
|
|
159
|
+
function handoverLines(s, cli, net = 'testnet') {
|
|
139
160
|
if (s.status === 'failed')
|
|
140
161
|
return failed(s, cli);
|
|
141
162
|
if (s.status === 'waiting')
|
|
@@ -147,14 +168,16 @@ function handoverLines(s, cli) {
|
|
|
147
168
|
...(s.detail.emailed ? [`We also sent it to ${String(s.detail.emailed)}.`] : []),
|
|
148
169
|
'',
|
|
149
170
|
'Keep it private. Anyone with this link can claim the owner seat.',
|
|
150
|
-
|
|
171
|
+
`It works once and lasts 7 days. Sales stay ${net === 'testnet' ? 'on test money' : 'in test mode'} until you take the shop live.`,
|
|
151
172
|
];
|
|
152
173
|
}
|
|
153
174
|
const LINES = {
|
|
154
175
|
key: keyLines, products: productLines, sale: saleLines, handover: handoverLines,
|
|
155
176
|
};
|
|
156
177
|
/** The whole report, in words. */
|
|
178
|
+
/** `opts.net` is the network the API runs on (lib/network.ts); unset reads as testnet, today's words. */
|
|
157
179
|
export function journeyWords(r, cli, opts = {}) {
|
|
180
|
+
const net = opts.net ?? 'testnet';
|
|
158
181
|
const out = [];
|
|
159
182
|
r.steps.forEach((s) => {
|
|
160
183
|
const n = STEPS.findIndex((x) => x.step === s.step);
|
|
@@ -163,13 +186,16 @@ export function journeyWords(r, cli, opts = {}) {
|
|
|
163
186
|
out.push(`${MARK[s.status] ?? '?'} ${n + 1} of ${STEPS.length} ${title}${tag}`);
|
|
164
187
|
if (STEPS[n] && !s.reused && s.status !== 'failed')
|
|
165
188
|
out.push(` Why it matters: ${STEPS[n].why}`, '');
|
|
166
|
-
out.push(...indent((LINES[s.step] ?? ((x) => failed(x, cli)))(s, cli)), '');
|
|
189
|
+
out.push(...indent((LINES[s.step] ?? ((x) => failed(x, cli)))(s, cli, net)), '');
|
|
167
190
|
});
|
|
168
191
|
// Steps never reached (an early stop) still show, so the person sees the whole path.
|
|
169
192
|
for (let i = r.steps.length; i < STEPS.length; i++) {
|
|
170
193
|
out.push(`· ${i + 1} of ${STEPS.length} ${STEPS[i].title}`, ` Not started. ${STEPS[i].line}`, '');
|
|
171
194
|
}
|
|
172
|
-
const
|
|
195
|
+
const have = haveLines(haveNow(r, cli, { net }), cli, r);
|
|
196
|
+
if (have.length)
|
|
197
|
+
out.push(...have, '');
|
|
198
|
+
const panel = superpowers(r, cli, net);
|
|
173
199
|
if (panel.length)
|
|
174
200
|
out.push(...panel, '');
|
|
175
201
|
// The one thing to do now goes last, under everything, where the eye lands.
|
|
@@ -192,7 +218,7 @@ export function journeyWords(r, cli, opts = {}) {
|
|
|
192
218
|
* key and the group are read from .one/). Sending is the one move the CLI does not
|
|
193
219
|
* sign, so it is told as the screen that does, never as a command.
|
|
194
220
|
*/
|
|
195
|
-
export function superpowers(r, cli) {
|
|
221
|
+
export function superpowers(r, cli, net = 'testnet') {
|
|
196
222
|
const key = r.steps.find((s) => s.step === 'key');
|
|
197
223
|
if (!key || key.status !== 'done')
|
|
198
224
|
return [];
|
|
@@ -200,7 +226,10 @@ export function superpowers(r, cli) {
|
|
|
200
226
|
const sui = addresses.sui ?? '<your Sui address>';
|
|
201
227
|
const moves = [
|
|
202
228
|
{ what: 'See your balances', say: 'show my balances', run: `${cli} wallet get` },
|
|
203
|
-
|
|
229
|
+
// Testnet has a faucet. Mainnet has none: the wallet starts empty, and about 0.005 SUI covers a send.
|
|
230
|
+
net === 'testnet'
|
|
231
|
+
? { what: 'Get free test coins', say: 'fill my wallet with test coins', run: `${cli} wallet faucet ${sui} --chain sui --network testnet` }
|
|
232
|
+
: { what: 'Fund your wallet', say: 'what does my wallet need?', run: `Send SUI to ${sui}` }, // the "starts empty, 0.005 SUI" line is the panel's Network row
|
|
204
233
|
{ what: 'Sell something new', say: 'sell a mug for $12.50', run: `${cli} --product "Mug=12.50"` },
|
|
205
234
|
{ what: 'See what came in', say: 'what payments came in?', run: `${cli} wallet transactions` },
|
|
206
235
|
{ what: 'Ask ONE anything', say: 'how do I get paid in USDC?', run: `${cli} message "how do I get paid in USDC?"` },
|
|
@@ -219,3 +248,113 @@ export function superpowers(r, cli) {
|
|
|
219
248
|
` Every command: ${cli} --help`,
|
|
220
249
|
];
|
|
221
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* The line a person pastes into Claude Code, Codex or any other agent to start it. It opens on the
|
|
253
|
+
* benefit and ends on the page's command (one.ie `START_COMMAND`); the middle is the page's own
|
|
254
|
+
* `launchHandoff().short`: "Read https://one.ie/llms.txt, then run: npx oneie". `npx`, never `one`:
|
|
255
|
+
* the agent it goes to may not have this install.
|
|
256
|
+
*/
|
|
257
|
+
export const AGENT_PROMPT = 'Your agent can sell and be paid. Read https://one.ie/llms.txt, then run: npx oneie';
|
|
258
|
+
const HAVE_CHAINS = [
|
|
259
|
+
['sui', 'Sui', 'sui'], ['evm', 'EVM', 'evm'], ['sol', 'Solana', 'sol'], ['btc', 'Bitcoin', 'btc'], ['asi', 'ASI', 'asi'],
|
|
260
|
+
];
|
|
261
|
+
/** Read from the report and nothing else: a fact the run did not produce is null, never filled in. */
|
|
262
|
+
export function haveNow(r, cli, opts = {}) {
|
|
263
|
+
const get = (step) => r.steps.find((s) => s.step === step);
|
|
264
|
+
const key = get('key');
|
|
265
|
+
const kd = key?.detail ?? {};
|
|
266
|
+
const found = (kd.addresses && typeof kd.addresses === 'object' ? kd.addresses : {});
|
|
267
|
+
const pick = (k) => {
|
|
268
|
+
const names = CHAINS.find((c) => c.keys.includes(k)).keys;
|
|
269
|
+
const hit = names.find((n) => typeof found[n] === 'string' && found[n]);
|
|
270
|
+
return hit ? found[hit] : null;
|
|
271
|
+
};
|
|
272
|
+
const wallet = key?.status === 'done' && typeof kd.wallet === 'string' && kd.wallet ? kd.wallet : null;
|
|
273
|
+
const group = typeof kd.workspace === 'string' && kd.workspace ? kd.workspace : (r.workspace ?? null);
|
|
274
|
+
const products = (Array.isArray(get('products')?.detail.products) ? get('products').detail.products.map(String) : []).flatMap((p) => {
|
|
275
|
+
const m = /^(.*) (\d+\.\d{2}) ([A-Z]{3}) (\S+)$/.exec(p);
|
|
276
|
+
return m ? [{ name: m[1], price: m[2], currency: m[3], url: m[4] }] : [];
|
|
277
|
+
});
|
|
278
|
+
const sale = get('sale');
|
|
279
|
+
const next = !key || key.status !== 'done' || get('products')?.status !== 'done'
|
|
280
|
+
? cli
|
|
281
|
+
: sale?.status === 'done' ? `${cli} --product "Mug=12.50"` : cli;
|
|
282
|
+
return {
|
|
283
|
+
key: { file: wallet ? wallet.split(/[\\/]/).slice(-2).join('/') : null, sealed: wallet && typeof kd.sealed === 'string' ? kd.sealed : null },
|
|
284
|
+
addresses: { sui: pick('sui'), evm: pick('evm'), sol: pick('sol'), btc: pick('btc'), asi: pick('asi') },
|
|
285
|
+
group,
|
|
286
|
+
shop: { products },
|
|
287
|
+
limit: { credits: typeof kd.limit === 'number' ? kd.limit : null, command: `${cli} wallet limit ${group ?? '<group>'} <credits>` },
|
|
288
|
+
network: opts.net ?? 'testnet',
|
|
289
|
+
next,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
const shorten = (a) => (a.length > 14 ? `${a.slice(0, 6)}\u2026${a.slice(-4)}` : a);
|
|
293
|
+
/** "text" cut into lines of at most `w` columns, on spaces. */
|
|
294
|
+
function wrap(text, w) {
|
|
295
|
+
const out = [];
|
|
296
|
+
for (const word of text.split(' ')) {
|
|
297
|
+
const last = out.at(-1);
|
|
298
|
+
if (last !== undefined && [...last].length + 1 + [...word].length <= w)
|
|
299
|
+
out[out.length - 1] = `${last} ${word}`;
|
|
300
|
+
else
|
|
301
|
+
out.push(word);
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* "What you have now": a compact inventory of what this run made, told again on every later run.
|
|
307
|
+
* One row per fact, short enough for 72 columns; an unknown row says "not yet" and the command that fills it.
|
|
308
|
+
* A run that made no group at all (the first call refused) has nothing to inventory, so nothing prints.
|
|
309
|
+
*/
|
|
310
|
+
export function haveLines(h, cli, r) {
|
|
311
|
+
if (!h.group)
|
|
312
|
+
return [];
|
|
313
|
+
const row = (label, value) => ` ${label.padEnd(9)}${value}`;
|
|
314
|
+
const cont = (value) => ` ${' '.repeat(9)}${value}`;
|
|
315
|
+
const none = (cmd) => `not yet. ${cmd}`;
|
|
316
|
+
const rows = [];
|
|
317
|
+
rows.push(row('Key', h.key.file ? `${h.key.file}, on this machine. Nobody else has it.` : none(cli)));
|
|
318
|
+
const known = HAVE_CHAINS.filter(([k]) => h.addresses[k]);
|
|
319
|
+
if (known.length === 0)
|
|
320
|
+
rows.push(row('Wallets', none(cli)));
|
|
321
|
+
else
|
|
322
|
+
for (const [k, label] of HAVE_CHAINS)
|
|
323
|
+
rows.push(row(label, h.addresses[k] ? shorten(h.addresses[k]) : none(`${cli} wallet get`)));
|
|
324
|
+
rows.push(row('Group', h.group));
|
|
325
|
+
const [first, ...more] = h.shop.products;
|
|
326
|
+
if (!first)
|
|
327
|
+
rows.push(row('Shop', none(`${cli} --product "Mug=12.50"`)));
|
|
328
|
+
else {
|
|
329
|
+
rows.push(row('Shop', `${first.name} ${first.price} ${first.currency}${more.length ? ` and ${more.length} more` : ''}`), cont(first.url));
|
|
330
|
+
}
|
|
331
|
+
rows.push(row('Limit', h.limit.credits !== null ? `${h.limit.credits} credits a month` : none(h.limit.command)));
|
|
332
|
+
rows.push(row('Network', h.network === 'testnet' ? 'testnet. Test coins are free. No real money moves.' : 'mainnet. It starts empty. About 0.005 SUI covers a send.'));
|
|
333
|
+
const salePending = r.steps.find((s) => s.step === 'sale')?.status === 'pending';
|
|
334
|
+
rows.push(row('Next', salePending ? `${h.next} after you pay the test link` : h.next));
|
|
335
|
+
return [
|
|
336
|
+
...box(['What you have now']),
|
|
337
|
+
'',
|
|
338
|
+
...rows,
|
|
339
|
+
'',
|
|
340
|
+
// The wallet a first run makes is empty; this is the way to fill it without the agent ever holding the owner's key.
|
|
341
|
+
` Needs money? ${cli} wallet request 5 USDC`,
|
|
342
|
+
' Your owner gets a link and presses Touch ID.',
|
|
343
|
+
'',
|
|
344
|
+
' Another agent? Paste this into it:',
|
|
345
|
+
...wrap(AGENT_PROMPT, 62).map((l) => ` ${l}`),
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
/** The same words for a terminal that cannot draw boxes or glyphs: a pipe, NO_COLOR, a log. */
|
|
349
|
+
export function asciiOf(text) {
|
|
350
|
+
return text
|
|
351
|
+
.replace(/[\u256d\u256e\u2570\u256f]/g, '+')
|
|
352
|
+
.replace(/\u2500/g, '-')
|
|
353
|
+
.replace(/\u2502/g, '|')
|
|
354
|
+
.replace(/\u2026/g, '...')
|
|
355
|
+
.replace(/\u2713/g, 'ok')
|
|
356
|
+
.replace(/\u2717/g, 'x')
|
|
357
|
+
.replace(/\u00b7/g, '-')
|
|
358
|
+
.replace(/\u2193/g, 'v')
|
|
359
|
+
.replace(/[^\x00-\x7f]/g, '?');
|
|
360
|
+
}
|
package/dist/src/lib/journey.js
CHANGED
|
@@ -239,7 +239,7 @@ export async function runJourney(deps, o) {
|
|
|
239
239
|
steps.push(handover);
|
|
240
240
|
const failed = steps.some((s) => s.status === 'failed');
|
|
241
241
|
const next = sale.status === 'pending'
|
|
242
|
-
?
|
|
242
|
+
? `pay with the test card at the link above, then run \`npx oneie\` again. It waits up to ${RERUN_WAIT_S} seconds for the sale to land. Or run \`npx oneie --wait 30\` to wait here while you pay`
|
|
243
243
|
: undefined;
|
|
244
244
|
return { ok: !failed, workspace: state.workspace, steps, ...(next ? { next } : {}) };
|
|
245
245
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface KeySource {
|
|
2
|
+
/** Human words: `--key`, `$ONE_API_KEY`, `~/.config/one/key`, `./.env.local` … — a place, never a value. */
|
|
3
|
+
label: string;
|
|
4
|
+
/** True when the key was found in the current folder (.env.local, .env, .one/key). */
|
|
5
|
+
local: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function keySourceOf(opts: {
|
|
8
|
+
key?: string;
|
|
9
|
+
}, cwd?: string, env?: NodeJS.ProcessEnv): KeySource;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-source.ts — WHERE the key a money command acts with came from, never the key itself.
|
|
3
|
+
*
|
|
4
|
+
* The wallet commands resolve their key in this order (wallet.ts `resolveAuth`): --key, then
|
|
5
|
+
* ONEIE_API_KEY / ONE_API_KEY from the shell, `<cwd>/.env.local`, `<cwd>/.env` (shell wins per
|
|
6
|
+
* variable), then the folder's own `.one/key`, then the machine login. Four of the six are read
|
|
7
|
+
* from the CURRENT FOLDER — so the same command can act as a different actor from a different
|
|
8
|
+
* directory. That order is kept (`one init --write-env` writes `.env.local` on purpose); this file
|
|
9
|
+
* only makes the choice visible: a label for the header, and whether it came from the folder.
|
|
10
|
+
*/
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { readEnvFile } from '../env.js';
|
|
14
|
+
import { readKeyFolder } from './keyfile.js';
|
|
15
|
+
import { firstExisting, KEY_FILE, LEGACY_KEY_FILE } from './paths.js';
|
|
16
|
+
const tilde = (p) => (p.startsWith(homedir()) ? `~${p.slice(homedir().length)}` : p);
|
|
17
|
+
export function keySourceOf(opts, cwd = process.cwd(), env = process.env) {
|
|
18
|
+
if (opts.key)
|
|
19
|
+
return { label: '--key', local: false };
|
|
20
|
+
const files = [join(cwd, '.env.local'), join(cwd, '.env')];
|
|
21
|
+
const parsed = files.map((f) => ({ f, vars: readEnvFile(f) }));
|
|
22
|
+
for (const name of ['ONEIE_API_KEY', 'ONE_API_KEY']) {
|
|
23
|
+
if (env[name])
|
|
24
|
+
return { label: `$${name}`, local: false };
|
|
25
|
+
const hit = parsed.find((p) => p.vars[name]);
|
|
26
|
+
if (hit)
|
|
27
|
+
return { label: `./${hit.f.split('/').pop()}`, local: true };
|
|
28
|
+
}
|
|
29
|
+
if (readKeyFolder(cwd))
|
|
30
|
+
return { label: './.one/key', local: true };
|
|
31
|
+
const machine = firstExisting(KEY_FILE, LEGACY_KEY_FILE);
|
|
32
|
+
return { label: machine ? tilde(machine) : 'no key', local: false };
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which Sui network is the API this CLI is talking to on? One's answer is the deploy's own: Layout.astro
|
|
3
|
+
* writes `<meta name="one:network" content="testnet|mainnet">` into every page from the worker's `NETWORK`
|
|
4
|
+
* (one.ie/web/src/lib/sui-network.ts `DEPLOY_NET_META_NAME`), so the CLI asks the home page — the one door
|
|
5
|
+
* that carries it today. There is no status route for it.
|
|
6
|
+
*
|
|
7
|
+
* It only ever shapes the WORDS of a first run (the faucet line, "test money"), never a command's
|
|
8
|
+
* behaviour, and it must never block or fail a run: a slow, failing or unreadable answer is `testnet`
|
|
9
|
+
* (the display rule: show the network where a mistake costs nothing). The home page is large, so the
|
|
10
|
+
* body is read only until the meta tag or `</head>` appears, then dropped.
|
|
11
|
+
*/
|
|
12
|
+
export type Net = 'testnet' | 'mainnet';
|
|
13
|
+
/** Parse the meta tag out of the start of a page. Null when it is not there (yet). */
|
|
14
|
+
export declare function netFromHtml(html: string): Net | null;
|
|
15
|
+
export declare function learnNetwork(api: string, f?: typeof fetch, timeoutMs?: number): Promise<Net>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Parse the meta tag out of the start of a page. Null when it is not there (yet). */
|
|
2
|
+
export function netFromHtml(html) {
|
|
3
|
+
const tag = /<meta\b[^>]*\bname=["']one:network["'][^>]*>/i.exec(html)?.[0];
|
|
4
|
+
const content = tag ? /\bcontent=["']([^"']*)["']/i.exec(tag)?.[1] : undefined;
|
|
5
|
+
if (content === 'mainnet' || content === 'testnet')
|
|
6
|
+
return content;
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
export async function learnNetwork(api, f = fetch, timeoutMs = 3000) {
|
|
10
|
+
const ctl = new AbortController();
|
|
11
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
12
|
+
try {
|
|
13
|
+
const res = await f(`${api.replace(/\/$/, '')}/`, { signal: ctl.signal, headers: { accept: 'text/html' } });
|
|
14
|
+
if (!res.ok || !res.body)
|
|
15
|
+
return 'testnet';
|
|
16
|
+
const reader = res.body.getReader();
|
|
17
|
+
const dec = new TextDecoder();
|
|
18
|
+
let seen = '';
|
|
19
|
+
while (seen.length < 131_072) {
|
|
20
|
+
const { done, value } = await reader.read();
|
|
21
|
+
if (done)
|
|
22
|
+
break;
|
|
23
|
+
seen += dec.decode(value, { stream: true });
|
|
24
|
+
const net = netFromHtml(seen);
|
|
25
|
+
if (net) {
|
|
26
|
+
void reader.cancel().catch(() => { });
|
|
27
|
+
return net;
|
|
28
|
+
}
|
|
29
|
+
if (seen.includes('</head>'))
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
void reader.cancel().catch(() => { });
|
|
33
|
+
return 'testnet';
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return 'testnet';
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qr.ts — a QR code for a terminal, with no dependency.
|
|
3
|
+
*
|
|
4
|
+
* The encoder is Project Nayuki's QR Code generator (MIT), trimmed to the one mode an
|
|
5
|
+
* address needs (byte), taken from the copy qrcode.react bundles for one.ie/web — so the
|
|
6
|
+
* /w QR and `one wallet receive` draw from the same algorithm. Unchanged apart from the
|
|
7
|
+
* trim and the types: version and mask selection, the Reed-Solomon code, the penalty rule.
|
|
8
|
+
* tests/wallet-receive.test.ts pins the module matrix to that bundled copy's output.
|
|
9
|
+
*
|
|
10
|
+
* @license QR Code generator library (TypeScript)
|
|
11
|
+
* Copyright (c) Project Nayuki.
|
|
12
|
+
* SPDX-License-Identifier: MIT
|
|
13
|
+
*/
|
|
14
|
+
/** Byte mode, error-correction MEDIUM boosted when it fits for free — Nayuki's encodeBinary. */
|
|
15
|
+
export declare function qrMatrix(text: string): boolean[][];
|
|
16
|
+
/**
|
|
17
|
+
* The matrix as terminal text: two module rows per line with half blocks, a 2-module quiet
|
|
18
|
+
* zone, dark modules drawn as the terminal's background so it scans on a dark or light theme
|
|
19
|
+
* alike (light = '█'). Plain characters only — no colour codes, so it survives a pipe.
|
|
20
|
+
*/
|
|
21
|
+
export declare function qrTerminal(text: string): string;
|