oneie 5.7.6 → 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 -1
- package/dist/package.json +1 -1
- 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/index.js +13 -0
- package/dist/src/join.js +4 -0
- package/dist/src/key-sweep.js +15 -8
- package/dist/src/lib/check-words.d.ts +57 -0
- package/dist/src/lib/check-words.js +144 -0
- package/dist/src/lib/journey-words.js +6 -3
- package/dist/src/lib/journey.d.ts +2 -0
- package/dist/src/lib/journey.js +20 -1
- 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 +7 -0
- package/dist/src/lib/network.js +13 -4
- package/dist/src/lib/next-words.d.ts +105 -0
- package/dist/src/lib/next-words.js +298 -0
- package/dist/src/lib/sui-grpc-send.d.ts +41 -1
- package/dist/src/lib/sui-grpc-send.js +44 -5
- 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/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/shop-buy.d.ts +16 -0
- package/dist/src/shop-buy.js +101 -0
- package/dist/src/shop.js +2 -0
- package/dist/src/start.d.ts +12 -0
- package/dist/src/start.js +37 -15
- package/dist/src/thread.d.ts +2 -0
- package/dist/src/thread.js +52 -0
- package/dist/src/wallet-money.d.ts +7 -1
- package/dist/src/wallet-money.js +131 -31
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +122 -4
- package/dist/src/workflow.js +4 -1
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { Command } from 'commander';
|
|
21
21
|
import { type Fetch } from './balances.js';
|
|
22
22
|
import { type SuiSendReq, type SuiSendDone } from './lib/sui-grpc-send.js';
|
|
23
|
-
import { type Net, type Obj, type SendPlan, type SendAsset, type SendChain } from './lib/wallet-money.js';
|
|
23
|
+
import { type Addresses, type Net, type Obj, type SendPlan, type SendAsset, type SendChain } from './lib/wallet-money.js';
|
|
24
24
|
type Ask = (receiver: string, data: Obj) => Promise<Obj>;
|
|
25
25
|
type VaultKey = {
|
|
26
26
|
chain: string;
|
|
@@ -125,6 +125,7 @@ export declare function executeSend(plan: SendPlan, own: {
|
|
|
125
125
|
to: string;
|
|
126
126
|
net: Net;
|
|
127
127
|
suiRpc?: string;
|
|
128
|
+
split?: number;
|
|
128
129
|
}, d: LiveDeps): Promise<Obj>;
|
|
129
130
|
export type Who = {
|
|
130
131
|
actor?: string;
|
|
@@ -146,6 +147,11 @@ export declare function noFromCause(io: MoneyIO, o: {
|
|
|
146
147
|
*/
|
|
147
148
|
export declare function upgradeBalances(balances: Command, io: MoneyIO): void;
|
|
148
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
|
+
}>;
|
|
149
155
|
export declare function requestCmd(io: MoneyIO): Command;
|
|
150
156
|
export declare function sendCmd(io: MoneyIO): Command;
|
|
151
157
|
/** The vault's Sui address from its PUBLIC authPub — read without opening it. */
|
package/dist/src/wallet-money.js
CHANGED
|
@@ -20,17 +20,19 @@
|
|
|
20
20
|
import { Command } from 'commander';
|
|
21
21
|
import { createInterface } from 'node:readline';
|
|
22
22
|
import { suiAddressFromPubkey } from '@oneie/sdk/wallet';
|
|
23
|
-
import { readHyperliquid,
|
|
23
|
+
import { readHyperliquid, isEvmAddress, isSuiAddress } from './balances.js';
|
|
24
|
+
import { netLine, resolveNet } from './lib/net-choice.js';
|
|
24
25
|
import { agentType } from './lib/agent-env.js';
|
|
25
26
|
import { cliPrefix } from './lib/invoked-as.js';
|
|
26
27
|
import { qrTerminal } from './lib/qr.js';
|
|
27
28
|
import { spawnSync } from 'node:child_process';
|
|
28
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
29
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
30
|
+
import { homedir } from 'node:os';
|
|
29
31
|
import { join } from 'node:path';
|
|
30
32
|
import { amountOk, latestSuiDigest, linkFor, parseRequestAsset, sentenceFor, shortAddr } from './lib/wallet-request.js';
|
|
31
33
|
import { suiSendGrpc, SuiSendError, mistToSui } from './lib/sui-grpc-send.js';
|
|
32
34
|
import { readVaultFolder, vaultPath } from './lib/vaultfile.js';
|
|
33
|
-
import { addressesFor, addressShape, chainLabel, clientCheck, DECIMALS, EVM, evmRpc, invoiceCents, parseAmount, readAsset, moneyBalances, moneyLines, parseAssetWord,
|
|
35
|
+
import { addressesFor, addressShape, chainLabel, clientCheck, DECIMALS, EVM, evmRpc, invoiceCents, parseAmount, readAsset, moneyBalances, moneyLines, parseAssetWord, planJson, planLines, planSend, receivePlan, recordLine, SUI_NATIVE, } from './lib/wallet-money.js';
|
|
34
36
|
/** fetch with a deadline: a node that hangs is a failed read, not a hung CLI. */
|
|
35
37
|
export const deadlineFetch = (ms = 10_000) => async (url, init) => {
|
|
36
38
|
const ctl = new AbortController();
|
|
@@ -175,7 +177,7 @@ export async function executeSend(plan, own, d) {
|
|
|
175
177
|
return { ok: false, error: 'vault_not_sender', message: `This vault does not hold ${plan.from}. Open the vault that does (--dir). Nothing was signed.` };
|
|
176
178
|
if (plan.chain === 'sui') {
|
|
177
179
|
try {
|
|
178
|
-
const done = await (d.suiSend ?? suiSendDefault)({ asset: plan.asset, coinType: plan.coinType ?? SUI_NATIVE, from: plan.from, to: plan.to, amountUnits: plan.amountUnits, privateKeyHex: key.privateKeyHex, rpc: own.suiRpc, net: plan.network });
|
|
180
|
+
const done = await (d.suiSend ?? suiSendDefault)({ asset: plan.asset, coinType: plan.coinType ?? SUI_NATIVE, from: plan.from, to: plan.to, amountUnits: plan.amountUnits, privateKeyHex: key.privateKeyHex, rpc: own.suiRpc, net: plan.network, ...(own.split ? { split: own.split } : {}) });
|
|
179
181
|
const { digest, gasMist, finalMs } = typeof done === 'string' ? { digest: done, gasMist: undefined, finalMs: undefined } : done;
|
|
180
182
|
return {
|
|
181
183
|
ok: true, sent: true, chain: 'sui', network: plan.network, digest, explorer: `${plan.explorer}/tx/${digest}`,
|
|
@@ -248,8 +250,8 @@ function common(c, defaultApi) {
|
|
|
248
250
|
.option('--api <url>', 'API base URL', defaultApi)
|
|
249
251
|
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)');
|
|
250
252
|
}
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
+
/** --net, ONE_NETWORK, `one network`, then the deploy (lib/net-choice.ts) — never a hard default. */
|
|
254
|
+
const pickNet = (raw, api) => resolveNet(raw, api);
|
|
253
255
|
/** The loaded wallet: wallet:get for the workspace (and actor), reduced to its addresses. */
|
|
254
256
|
async function loaded(io, o, net, self) {
|
|
255
257
|
const workspace = io.workspace(o.workspace);
|
|
@@ -270,24 +272,28 @@ async function loaded(io, o, net, self) {
|
|
|
270
272
|
export function upgradeBalances(balances, io) {
|
|
271
273
|
// Guarded: commander throws on a duplicate flag at startup, which would take every `one` command down.
|
|
272
274
|
if (!balances.options.some((x) => x.long === '--net'))
|
|
273
|
-
balances.option('--net <network>', 'mainnet (default
|
|
275
|
+
balances.option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)');
|
|
276
|
+
if (!balances.options.some((x) => x.long === '--all'))
|
|
277
|
+
balances.option('--all', 'Every wallet on this machine in one table: each vault folder under ~/.one (the owner, every agent, the gas key), every chain, with totals');
|
|
274
278
|
balances
|
|
275
279
|
.description('Every balance of your wallet on one network: ETH + USDC on Ethereum, Base, Arbitrum; SUI + USDC; SOL; BTC; Hyperliquid perps and spot. wallet:get first, the chains for what it does not read. A failed read says unavailable, never 0')
|
|
276
280
|
.action(async function (address, o) {
|
|
277
281
|
const f = io.fetch ?? deadlineFetch();
|
|
278
|
-
const
|
|
279
|
-
if (!
|
|
280
|
-
return emit(this,
|
|
282
|
+
const nc = await pickNet(o.net, o.api);
|
|
283
|
+
if (!nc.ok)
|
|
284
|
+
return emit(this, nc);
|
|
285
|
+
const net = nc.net;
|
|
286
|
+
if (o.all)
|
|
287
|
+
return balancesAll(this, f, net);
|
|
281
288
|
if (address) {
|
|
282
289
|
const a = address.trim();
|
|
283
290
|
if (!isEvmAddress(a) && !isSuiAddress(a))
|
|
284
291
|
return emit(this, { ok: false, error: 'bad_address', message: 'Pass a 0x EVM address (40 hex) or a Sui address (64 hex).' });
|
|
285
292
|
const addrs = isEvmAddress(a) ? { evm: a } : { sui: a };
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
const r = await moneyBalances({ walletGet: null, actor: '', addresses: addrs, net }, f);
|
|
293
|
+
// One reader for every network. The mainnet branch used to take balances.ts's SUI-only read,
|
|
294
|
+
// so an address holding Sui USDC printed SUI alone (2026-11-12: 21.43 and 20 USDC missing).
|
|
295
|
+
const hlRead = net === 'mainnet' && addrs.evm ? (x) => readHyperliquid(x, f) : undefined;
|
|
296
|
+
const r = await moneyBalances({ walletGet: null, actor: '', addresses: addrs, net }, f, hlRead);
|
|
291
297
|
return emit(this, { ...r }, moneyLines(r));
|
|
292
298
|
}
|
|
293
299
|
let l;
|
|
@@ -308,12 +314,13 @@ export function receiveCmd(io) {
|
|
|
308
314
|
return common(new Command('receive'), io.defaultApi)
|
|
309
315
|
.description('Your address on ONE chain, with a QR to scan — the same 0x address is three chains, so --chain is required')
|
|
310
316
|
.option('--chain <chain>', 'ethereum | base | arbitrum | sui | solana | bitcoin')
|
|
311
|
-
.option('--net <network>', 'mainnet
|
|
317
|
+
.option('--net <network>', 'mainnet | testnet — sets the chain id in the QR (default: ONE_NETWORK, `one network`, the deploy)')
|
|
312
318
|
.option('--no-qr', 'Print the address only')
|
|
313
319
|
.action(async function (o) {
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
316
|
-
return emit(this,
|
|
320
|
+
const nc = await pickNet(o.net, o.api);
|
|
321
|
+
if (!nc.ok)
|
|
322
|
+
return emit(this, nc);
|
|
323
|
+
const net = nc.net;
|
|
317
324
|
let l;
|
|
318
325
|
try {
|
|
319
326
|
l = await loaded(io, o);
|
|
@@ -349,6 +356,91 @@ function publicAddresses(dir) {
|
|
|
349
356
|
out.sui = fromVault;
|
|
350
357
|
return out;
|
|
351
358
|
}
|
|
359
|
+
/** Every wallet this machine holds a sealed key or a public sidecar for, by its PUBLIC addresses only. */
|
|
360
|
+
export function localWallets(root = join(homedir(), '.one')) {
|
|
361
|
+
const found = [];
|
|
362
|
+
const shaped = (j) => {
|
|
363
|
+
const a = {};
|
|
364
|
+
for (const [k, key] of [['evm', 'evm'], ['sui', 'sui'], ['sol', 'solana'], ['solana', 'solana'], ['btc', 'btc']]) {
|
|
365
|
+
const v = j?.[k];
|
|
366
|
+
if (typeof v === 'string' && addressShape(v) === key)
|
|
367
|
+
a[key] = v;
|
|
368
|
+
}
|
|
369
|
+
return a;
|
|
370
|
+
};
|
|
371
|
+
const sidecar = (dir, label) => {
|
|
372
|
+
try {
|
|
373
|
+
const j = JSON.parse(readFileSync(join(dir, 'addresses.json'), 'utf8'));
|
|
374
|
+
const a = shaped(j.addresses);
|
|
375
|
+
if (Object.keys(a).length)
|
|
376
|
+
found.push({ label, addresses: a });
|
|
377
|
+
}
|
|
378
|
+
catch { /* no sidecar */ }
|
|
379
|
+
};
|
|
380
|
+
let names = [];
|
|
381
|
+
try {
|
|
382
|
+
names = readdirSync(root);
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return found;
|
|
386
|
+
}
|
|
387
|
+
for (const n of names.sort()) {
|
|
388
|
+
if (n === 'agents') {
|
|
389
|
+
let agents = [];
|
|
390
|
+
try {
|
|
391
|
+
agents = readdirSync(join(root, n)).sort();
|
|
392
|
+
}
|
|
393
|
+
catch { /* none */ }
|
|
394
|
+
for (const a of agents)
|
|
395
|
+
sidecar(join(root, n, a), `agent ${a}`);
|
|
396
|
+
}
|
|
397
|
+
else if (existsSync(join(root, n, 'addresses.json')))
|
|
398
|
+
sidecar(join(root, n), n);
|
|
399
|
+
else {
|
|
400
|
+
let files = [];
|
|
401
|
+
try {
|
|
402
|
+
files = readdirSync(join(root, n)).filter((f) => f.endsWith('.address')).sort();
|
|
403
|
+
}
|
|
404
|
+
catch { /* not a folder */ }
|
|
405
|
+
for (const f of files) {
|
|
406
|
+
const v = readFileSync(join(root, n, f), 'utf8').trim();
|
|
407
|
+
const shape = addressShape(v);
|
|
408
|
+
if (shape === 'sui' || shape === 'evm')
|
|
409
|
+
found.push({ label: `${n} ${f.replace(/\.address$/, '')}`, addresses: { [shape]: v } });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return found;
|
|
414
|
+
}
|
|
415
|
+
/** `balances --all`: one read per wallet, all at once, one table and a total per asset. */
|
|
416
|
+
async function balancesAll(c, f, net) {
|
|
417
|
+
const t0 = Date.now();
|
|
418
|
+
const wallets = localWallets();
|
|
419
|
+
if (!wallets.length)
|
|
420
|
+
return emit(c, { ok: false, error: 'no_local_wallets', message: 'No wallet folder under ~/.one — pass an address instead' });
|
|
421
|
+
// One wallet at a time: the public nodes rate-limit a burst, and a refused read prints as unavailable.
|
|
422
|
+
const reads = [];
|
|
423
|
+
for (const w of wallets)
|
|
424
|
+
reads.push({ ...w, read: await moneyBalances({ walletGet: null, actor: '', addresses: w.addresses, net }, f) });
|
|
425
|
+
const totals = {};
|
|
426
|
+
const lines = [`network ${net}${net === 'mainnet' ? ' (real money)' : ' (practice money)'} · ${wallets.length} wallets`];
|
|
427
|
+
for (const w of reads) {
|
|
428
|
+
lines.push('', w.label);
|
|
429
|
+
let shown = 0;
|
|
430
|
+
for (const r of w.read.rows) {
|
|
431
|
+
if (r.amount === '0')
|
|
432
|
+
continue;
|
|
433
|
+
shown++;
|
|
434
|
+
lines.push(` ${r.chain.padEnd(10)}${r.asset.padEnd(6)}${r.amount === null ? `unavailable (${r.unavailable ?? 'read_failed'})` : r.amount}`);
|
|
435
|
+
if (r.amount !== null)
|
|
436
|
+
totals[r.asset] = (totals[r.asset] ?? 0) + Number(r.amount);
|
|
437
|
+
}
|
|
438
|
+
if (!shown)
|
|
439
|
+
lines.push(' (every read answered: nothing here)');
|
|
440
|
+
}
|
|
441
|
+
lines.push('', `total ${Object.entries(totals).map(([a, v]) => `${Number(v.toFixed(9))} ${a}`).join(' · ') || 'nothing'}`, `read in ${Date.now() - t0} ms`);
|
|
442
|
+
emit(c, { ok: true, network: net, wallets: reads.map((w) => ({ label: w.label, addresses: w.addresses, rows: w.read.rows })), totals, ms: Date.now() - t0 }, lines);
|
|
443
|
+
}
|
|
352
444
|
/** `request <amount> <asset>[@chain]`: a link the OWNER opens, and a fingerprint only they can give. */
|
|
353
445
|
async function requestMoney(c, io, amount, assetWord, o) {
|
|
354
446
|
const a = parseRequestAsset(assetWord);
|
|
@@ -357,9 +449,10 @@ async function requestMoney(c, io, amount, assetWord, o) {
|
|
|
357
449
|
const units = amountOk(amount) ? parseAmount(amount, DECIMALS[a.asset]) : null;
|
|
358
450
|
if (units === null)
|
|
359
451
|
return emit(c, { ok: false, error: 'bad_amount', message: `"${amount}" is not an amount of ${a.asset} (above zero, at most ${DECIMALS[a.asset]} decimals).` });
|
|
360
|
-
const
|
|
361
|
-
if (!
|
|
362
|
-
return emit(c,
|
|
452
|
+
const nc = await pickNet(o.net, o.api);
|
|
453
|
+
if (!nc.ok)
|
|
454
|
+
return emit(c, nc);
|
|
455
|
+
const net = nc.net;
|
|
363
456
|
let seconds = 0;
|
|
364
457
|
if (o.wait !== undefined) {
|
|
365
458
|
seconds = o.wait === true ? 300 : Number(o.wait);
|
|
@@ -429,7 +522,7 @@ export function requestCmd(io) {
|
|
|
429
522
|
.option('--from <slug>', '(invoice) Who you are asking — named in the output; wallet:invoice has no payer field, so you hand them the link')
|
|
430
523
|
.option('--invoice', 'USDC as a wallet:invoice payment link (cents) instead of an owner link')
|
|
431
524
|
.option('--dir <path>', 'The agent\'s folder: its sealed vault\'s PUBLIC address is read — the key never opens', '.')
|
|
432
|
-
.option('--net <network>', 'Which network --wait watches: mainnet (default
|
|
525
|
+
.option('--net <network>', 'Which network --wait watches: mainnet | testnet (default: ONE_NETWORK, `one network`, the deploy). The link itself carries none')
|
|
433
526
|
.option('--wait [seconds]', 'Poll the chain until the balance rises by the amount (default 300 s); exit 75 on timeout')
|
|
434
527
|
.option('--open', 'Open the link in the default browser (macOS)')
|
|
435
528
|
.action(async function (amount, asset, o) {
|
|
@@ -452,7 +545,7 @@ export function requestCmd(io) {
|
|
|
452
545
|
return emit(this, { ok: false, error: String(r['error'] ?? 'no_link'), message: 'wallet:invoice minted no link.', result: r });
|
|
453
546
|
const data = {
|
|
454
547
|
ok: true, url: r['url'], linkId: r['linkId'], custody: r['custody'], amountCents: c.cents, actor,
|
|
455
|
-
network: 'the deploy\'s
|
|
548
|
+
network: typeof r['network'] === 'string' ? r['network'] : 'the deploy\'s (read it: https://pay.one.ie/status)',
|
|
456
549
|
...(o.from ? { from: o.from, note: `wallet:invoice has no payer field: send ${o.from} this link yourself (one message, a sealed note, or chat).` } : {}),
|
|
457
550
|
};
|
|
458
551
|
emit(this, data, [`Pay ${actor} $${(c.cents / 100).toFixed(2)}: ${String(r['url'])}`, `network ${data.network}`, ...(o.from ? [data.note] : [])]);
|
|
@@ -462,12 +555,13 @@ export function sendCmd(io) {
|
|
|
462
555
|
return common(new Command('send'), io.defaultApi)
|
|
463
556
|
.description('Send from your wallet: `send <amount> <asset>[@chain] <to>` — DRY by default (prints exactly what would be signed, the fee, the chain picked); --live signs with the sealed vault in --dir. ETH + USDC on Ethereum, Base, Arbitrum; SUI + USDC on Sui. <to> = an address, a workspace slug or an agent id. The old form `send <to> --chain --amount --payment-tx` still records a transfer you signed elsewhere')
|
|
464
557
|
.argument('<words...>', '<amount> <asset>[@chain] <to> (or <to> with --payment-tx)')
|
|
465
|
-
.option('--net <network>', 'mainnet (default
|
|
558
|
+
.option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)')
|
|
466
559
|
.option('--live', 'Sign and broadcast. Without it nothing is signed')
|
|
467
560
|
.option('--yes', 'Skip the y/N prompt. Required in an agent shell, where only the agent\'s own vault may sign')
|
|
468
561
|
.option('--dir <path>', 'The folder whose sealed vault (.one/wallet.json) signs', '.')
|
|
469
562
|
.option('--to-address <addr>', 'Your own copy of a recipient found by name — must equal what was resolved')
|
|
470
563
|
.option('--rpc <url>', 'Sui gRPC base URL for a --live Sui send (default: Mysten\'s public fullnode for --net)')
|
|
564
|
+
.option('--split <n>', 'Sui only: arrive as <n> equal coins (2–100) in the one transaction — e.g. gas coins for a sponsor, so it never signs a split itself')
|
|
471
565
|
.option('--chain <chain>', '(relay form) SUI | ETH | BASE | ARB | OPT | SOL | BTC')
|
|
472
566
|
.option('--amount <n>', '(relay form) amount')
|
|
473
567
|
.option('--payment-tx <hash>', '(relay form) the hash of a transfer you already signed and broadcast — records it, signs nothing')
|
|
@@ -484,9 +578,13 @@ export function sendCmd(io) {
|
|
|
484
578
|
if (words.length !== 3)
|
|
485
579
|
return emit(this, { ok: false, error: 'usage', message: 'send <amount> <asset>[@chain] <to> e.g. send 1 USDC@base 0x…' });
|
|
486
580
|
const [amount, assetWord, to] = words;
|
|
487
|
-
const
|
|
488
|
-
if (!
|
|
489
|
-
return emit(this,
|
|
581
|
+
const nc = await pickNet(o.net, o.api);
|
|
582
|
+
if (!nc.ok)
|
|
583
|
+
return emit(this, nc);
|
|
584
|
+
const net = nc.net;
|
|
585
|
+
const split = o.split === undefined ? undefined : Number(o.split);
|
|
586
|
+
if (split !== undefined && (!Number.isInteger(split) || split < 2 || split > 100))
|
|
587
|
+
return emit(this, { ok: false, error: 'bad_split', message: '--split takes a whole number from 2 to 100' });
|
|
490
588
|
const f = io.fetch ?? deadlineFetch();
|
|
491
589
|
// Who this key is comes first: a folder key scoped to another workspace makes wallet:get refuse, and that refusal must still say whose key it was.
|
|
492
590
|
const me = await io.identity?.(o, 'resolved').catch(() => null);
|
|
@@ -525,10 +623,12 @@ export function sendCmd(io) {
|
|
|
525
623
|
return emit(this, { ...planned, ...(cause ? { message: cause } : {}), dry: true, ...who }, header ? [header] : undefined);
|
|
526
624
|
}
|
|
527
625
|
const plan = planned.plan;
|
|
528
|
-
|
|
626
|
+
if (split && plan.chain !== 'sui')
|
|
627
|
+
return emit(this, { ok: false, error: 'split_sui_only', message: '--split is a Sui send only' });
|
|
628
|
+
const lines = [...(header ? [header] : []), ...planLines(plan), `chosen ${netLine(nc).replace(/^network\s+/, '')}`, ...(split ? [`split ${split} coins of ${Number(amount) / split} ${plan.asset} (the first carries any remainder)`] : [])];
|
|
529
629
|
if (!o.live) {
|
|
530
630
|
const pin = plan.toSource !== 'typed' ? ` --to-address ${plan.to}` : '';
|
|
531
|
-
const liveCmd = `${cliPrefix()} wallet send ${shq(amount)} ${plan.asset}@${plan.chain} ${shq(to)} --net ${net} --live --dir <your vault folder>${pin}`;
|
|
631
|
+
const liveCmd = `${cliPrefix()} wallet send ${shq(amount)} ${plan.asset}@${plan.chain} ${shq(to)} --net ${net} --live --dir <your vault folder>${pin}${split ? ` --split ${split}` : ''}`;
|
|
532
632
|
return emit(this, { ok: true, dry: true, plan: planJson(plan), next: liveCmd, ...who }, [...lines, '', 'DRY RUN — nothing was signed or sent.', `To send it: ${liveCmd}`]);
|
|
533
633
|
}
|
|
534
634
|
if (!isJson(this))
|
|
@@ -537,7 +637,7 @@ export function sendCmd(io) {
|
|
|
537
637
|
if (!gate.ok)
|
|
538
638
|
return emit(this, { ...gate, ...who });
|
|
539
639
|
const parsed = parseAssetWord(assetWord);
|
|
540
|
-
const own = { amount, asset: plan.asset, chain: parsed.ok && parsed.chain ? parsed.chain : plan.chain, to: plan.toSource === 'typed' ? to : (o.toAddress ?? plan.to), net, suiRpc: o.rpc };
|
|
640
|
+
const own = { amount, asset: plan.asset, chain: parsed.ok && parsed.chain ? parsed.chain : plan.chain, to: plan.toSource === 'typed' ? to : (o.toAddress ?? plan.to), net, suiRpc: o.rpc, ...(split ? { split } : {}) };
|
|
541
641
|
const r = await executeSend(plan, own, { fetch: f, unlock: () => io.unlock(o.dir) });
|
|
542
642
|
emit(this, r, r['ok'] ? sentLines(r) : undefined);
|
|
543
643
|
});
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -130,6 +130,8 @@ export interface UnlockIO {
|
|
|
130
130
|
value?: string;
|
|
131
131
|
error?: string;
|
|
132
132
|
};
|
|
133
|
+
/** Open the passphrase sealed to the Secure Enclave — the chip asks for the finger here. */
|
|
134
|
+
openSe?: (sealedPath: string, identityPath: string) => string;
|
|
133
135
|
}
|
|
134
136
|
/**
|
|
135
137
|
* Open the folder's vault, asking Keychain or the human depending on how it was
|
package/dist/src/wallet.js
CHANGED
|
@@ -13,8 +13,11 @@ import { keySourceOf } from './lib/key-source.js';
|
|
|
13
13
|
import { readMachineKey } from './lib/paths.js';
|
|
14
14
|
import { wordsStdoutRefusal, agentType } from './lib/agent-env.js';
|
|
15
15
|
import { cliPrefix } from './lib/invoked-as.js';
|
|
16
|
-
import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
|
|
16
|
+
import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, keychainDelete, seSealPath, seIdentityPath, } from './lib/vaultfile.js';
|
|
17
|
+
import { keygen, openWithAge, recipientOf, sealWithAge } from './lib/age-plugin.js';
|
|
17
18
|
import { receiveCmd, requestCmd, sendCmd, upgradeBalances } from './wallet-money.js';
|
|
19
|
+
import { ceilingCmd } from './ceiling.js';
|
|
20
|
+
import { savedNet } from './lib/net-choice.js';
|
|
18
21
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
19
22
|
// Re-exported for existing callers/tests — canonical implementation now lives
|
|
20
23
|
// in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
|
|
@@ -32,11 +35,19 @@ export function refusalMessage(receiver, envelope) {
|
|
|
32
35
|
const hint = typeof r.hint === 'string' ? ` — ${r.hint}` : '';
|
|
33
36
|
return `${receiver} → ${envelope.outcome}${why.length ? `: ${why.join(' · ')}` : ''}${hint}`;
|
|
34
37
|
}
|
|
38
|
+
/** A wallet receiver that has not answered in this long is not going to: say so, never wait forever (lib/timed-fetch.ts). */
|
|
39
|
+
const WALLET_ASK_TIMEOUT_MS = 60_000;
|
|
35
40
|
async function ask(base, key, receiver, data) {
|
|
41
|
+
const signal = AbortSignal.timeout(WALLET_ASK_TIMEOUT_MS);
|
|
36
42
|
const res = await fetch(askPath(base, receiver), {
|
|
37
43
|
method: 'POST',
|
|
38
44
|
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
39
45
|
body: JSON.stringify({ data }),
|
|
46
|
+
signal,
|
|
47
|
+
}).catch((e) => {
|
|
48
|
+
if (signal.aborted)
|
|
49
|
+
throw new Error(`${receiver} did not answer in ${WALLET_ASK_TIMEOUT_MS / 1000} s`);
|
|
50
|
+
throw e;
|
|
40
51
|
});
|
|
41
52
|
if (!res.ok) {
|
|
42
53
|
const body = await res.text().catch(() => '');
|
|
@@ -141,10 +152,13 @@ export function walletCmd() {
|
|
|
141
152
|
.description('Credits, spend ceiling, wallet rows, live chain balances (sui · evm · solana · btc · hyperliquid), delegated wallets')
|
|
142
153
|
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
143
154
|
.option('--actor <id>', 'Actor within the workspace (defaults to workspace)')
|
|
144
|
-
.option('--net <network>', 'mainnet | testnet — the one network every balance is read on (
|
|
155
|
+
.option('--net <network>', 'mainnet | testnet — the one network every balance is read on (default: ONE_NETWORK, then `one network`, then the deploy\'s)')
|
|
145
156
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
146
157
|
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
147
158
|
.action(async (opts) => {
|
|
159
|
+
// The server already defaults to its own deploy; send a network only when one is NAMED here.
|
|
160
|
+
if (!opts.net)
|
|
161
|
+
opts.net = process.env.ONE_NETWORK?.trim() || savedNet() || undefined;
|
|
148
162
|
if (opts.net && opts.net !== 'mainnet' && opts.net !== 'testnet') {
|
|
149
163
|
out(cmd, { ok: false, error: '--net must be mainnet or testnet' });
|
|
150
164
|
process.exitCode = 1;
|
|
@@ -155,6 +169,8 @@ export function walletCmd() {
|
|
|
155
169
|
const result = await ask(base, key, 'wallet:get', { workspace, actor: opts.actor, ...(opts.net ? { net: opts.net } : {}) });
|
|
156
170
|
out(cmd, okWrap(result));
|
|
157
171
|
});
|
|
172
|
+
// ceiling — the agent's on-chain spend ceiling (src/ceiling.ts): owner-signed create/set, show, register with pay.
|
|
173
|
+
cmd.addCommand(ceilingCmd());
|
|
158
174
|
// balances — the REAL mainnet balances of the loaded wallet, read from the chains (src/balances.ts).
|
|
159
175
|
// `get` above is ONE's own ledger and shows test money for most chains.
|
|
160
176
|
cmd.addCommand(balancesCmd({
|
|
@@ -521,6 +537,91 @@ export function walletCmd() {
|
|
|
521
537
|
const k = keychainStore(String(blob.authPub ?? ''), pass);
|
|
522
538
|
out(cmd, k.ok ? { ok: true, note: 'Touch ID now opens this wallet' } : { ok: false, error: k.error });
|
|
523
539
|
});
|
|
540
|
+
cmd.command('secure')
|
|
541
|
+
.description("Put this wallet behind the Secure Enclave: its passphrase is sealed to a chip key that only the CURRENT fingerprint opens, so no process can sign without Touch ID. wallet.json is not rewritten. Then --drop-keychain, after one Touch ID open proves it, deletes the Keychain copy")
|
|
542
|
+
.option('--dir <path>', 'Project directory', '.')
|
|
543
|
+
.option('--drop-keychain', 'Open once through the Secure Enclave (Touch ID), prove it opens the vault, then delete the Keychain copy')
|
|
544
|
+
.option('--access <rule>', 'age-plugin-se access control', 'current-biometry')
|
|
545
|
+
.action(async (opts) => {
|
|
546
|
+
const t0 = Date.now();
|
|
547
|
+
const blob = readVaultFolder(opts.dir);
|
|
548
|
+
if (!blob) {
|
|
549
|
+
out(cmd, { ok: false, error: `no wallet at ${vaultPath(opts.dir)}` });
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (blob.wrap !== 'keychain') {
|
|
553
|
+
out(cmd, { ok: false, error: 'not_a_keychain_wallet', detail: 'only a Keychain-wrapped wallet moves to the Secure Enclave' });
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const authPub = String(blob.authPub ?? '');
|
|
557
|
+
const sealed = seSealPath(opts.dir), identity = seIdentityPath(opts.dir);
|
|
558
|
+
if (!existsSync(sealed)) {
|
|
559
|
+
const k = keychainRead(authPub);
|
|
560
|
+
if (!k.ok || !k.value) {
|
|
561
|
+
out(cmd, { ok: false, error: 'keychain_unreadable', detail: k.ok ? 'empty' : k.error });
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
// Prove the Keychain copy opens THIS vault before sealing it anywhere.
|
|
565
|
+
try {
|
|
566
|
+
await openVault(blob, k.value);
|
|
567
|
+
}
|
|
568
|
+
catch {
|
|
569
|
+
out(cmd, { ok: false, error: 'keychain_copy_does_not_open_vault' });
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const made = keygen(identity, opts.access);
|
|
573
|
+
if (made !== true) {
|
|
574
|
+
out(cmd, { ok: false, error: typeof made === 'string' ? made : 'se_keygen_failed' });
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
chmodSync(identity, 0o600);
|
|
578
|
+
const lock = recipientOf(identity);
|
|
579
|
+
if (!lock) {
|
|
580
|
+
rmSync(identity, { force: true });
|
|
581
|
+
out(cmd, { ok: false, error: 'se_lock_unreadable' });
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
writeFileSync(sealed, sealWithAge(new TextEncoder().encode(k.value), [lock]), { mode: 0o600 });
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
rmSync(identity, { force: true });
|
|
589
|
+
out(cmd, { ok: false, error: 'se_seal_failed' });
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (!opts.dropKeychain) {
|
|
593
|
+
out(cmd, { ok: true, sealed: true, lock, access: opts.access, keychain: 'kept until proven', next: `${cliPrefix()} wallet secure --dir ${opts.dir} --drop-keychain (Touch ID once, then the Keychain copy is deleted)`, ms: Date.now() - t0 });
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (!opts.dropKeychain) {
|
|
598
|
+
out(cmd, { ok: true, sealed: true, note: 'already behind the Secure Enclave', next: `${cliPrefix()} wallet secure --dir ${opts.dir} --drop-keychain` });
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
// The proof: open through the chip (this is where Touch ID asks), and the result must open the vault.
|
|
602
|
+
let pass;
|
|
603
|
+
try {
|
|
604
|
+
pass = openSeDefault(sealed, identity);
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
out(cmd, { ok: false, error: 'touch_id_not_given', detail: 'the Secure Enclave did not open — the Keychain copy is KEPT, nothing was deleted' });
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
try {
|
|
611
|
+
await openVault(blob, pass);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
out(cmd, { ok: false, error: 'se_copy_does_not_open_vault', detail: 'the Keychain copy is KEPT' });
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const d = keychainDelete(authPub);
|
|
618
|
+
if (!d.ok) {
|
|
619
|
+
out(cmd, { ok: false, error: 'keychain_delete_failed', detail: d.error });
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const after = keychainRead(authPub);
|
|
623
|
+
out(cmd, { ok: !after.ok || !after.value, provedWithTouchId: true, keychainCopy: after.ok && after.value ? 'STILL PRESENT' : 'deleted', ms: Date.now() - t0 });
|
|
624
|
+
});
|
|
524
625
|
// The browser's /w/restore "Key file" door opens a vault sealed with a TYPED
|
|
525
626
|
// passphrase — it cannot read this machine's Keychain. This writes that copy:
|
|
526
627
|
// the same 24 words, the same derivation, a passphrase the person types twice.
|
|
@@ -783,8 +884,9 @@ export async function paperFor(dir, io = terminalIO(), cli = cliPrefix()) {
|
|
|
783
884
|
// absent marker is v1 — so the sheet names the derivation those addresses are.
|
|
784
885
|
return { sheet: paperSheet(r.mnemonic, r.addresses, { derivation: readDerivation(r.blob.derivation), cli }) };
|
|
785
886
|
}
|
|
887
|
+
const openSeDefault = (sealedPath, identityPath) => new TextDecoder().decode(openWithAge(new Uint8Array(readFileSync(sealedPath)), identityPath));
|
|
786
888
|
const terminalIO = () => ({
|
|
787
|
-
interactive: Boolean(process.stdin.isTTY), readPassphrase: promptSecret, readKeychain: keychainRead,
|
|
889
|
+
interactive: Boolean(process.stdin.isTTY), readPassphrase: promptSecret, readKeychain: keychainRead, openSe: openSeDefault,
|
|
788
890
|
});
|
|
789
891
|
/**
|
|
790
892
|
* Open the folder's vault, asking Keychain or the human depending on how it was
|
|
@@ -802,7 +904,23 @@ export async function unlock(dir, io = terminalIO()) {
|
|
|
802
904
|
return { error: `no wallet at ${vaultPath(dir)} — run \`${cliPrefix()} wallet new\`` };
|
|
803
905
|
const blob = raw;
|
|
804
906
|
let passphrase;
|
|
805
|
-
if (
|
|
907
|
+
if (existsSync(seSealPath(dir))) {
|
|
908
|
+
// Sealed to the Secure Enclave (`wallet secure`): the chip opens it with the current
|
|
909
|
+
// finger, or nothing does. Keychain is never consulted, even if a copy is still there.
|
|
910
|
+
// The moment a person meets their key. Said on the terminal only (stderr, a TTY), never in --json.
|
|
911
|
+
const say = (line) => { if (process.stderr.isTTY)
|
|
912
|
+
process.stderr.write(line + '\n'); };
|
|
913
|
+
say('\n ◉ Touch ID — your finger is the key. It never leaves this Mac.');
|
|
914
|
+
try {
|
|
915
|
+
passphrase = (io.openSe ?? openSeDefault)(seSealPath(dir), seIdentityPath(dir));
|
|
916
|
+
say(' ✓ That was you. Opened, and signing now.\n');
|
|
917
|
+
}
|
|
918
|
+
catch {
|
|
919
|
+
say(' · Not opened — nothing was signed, nothing moved. Run it again when you are ready.\n');
|
|
920
|
+
return { error: 'touch_id_required: this wallet opens only with Touch ID on this Mac, and the Secure Enclave did not open it (no finger, cancelled, or a fingerprint changed). Recover from the 24 words if this Mac is gone' };
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
else if (blob.wrap === 'keychain') {
|
|
806
924
|
const k = io.readKeychain(String(blob.authPub ?? ''));
|
|
807
925
|
if (!k.ok || !k.value)
|
|
808
926
|
return { error: k.ok ? 'Keychain returned nothing' : String(k.error) };
|
package/dist/src/workflow.js
CHANGED
|
@@ -55,7 +55,10 @@ export function workflowCmd() {
|
|
|
55
55
|
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
56
56
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
57
57
|
.action(async (opts) => {
|
|
58
|
-
|
|
58
|
+
// The receiver lists `data.slug` when the key controls it, else the KEY's own
|
|
59
|
+
// workspace. Sending {} dropped --slug, so a key minted for another workspace
|
|
60
|
+
// printed 0 for `--slug one` while workflow:list answered 22 for one.
|
|
61
|
+
const r = await call(opts.api, opts.slug, 'workflow:list', { slug: opts.slug });
|
|
59
62
|
out(cmd, { ok: !r.error, ...r });
|
|
60
63
|
});
|
|
61
64
|
cmd.command('pull <id>')
|