oneie 5.7.6 → 5.8.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 +19 -1
- package/dist/package.json +7 -8
- package/dist/src/age-yefbe8pe.js +1 -0
- package/dist/src/evm-tx-ee2q0e3w.js +1 -0
- package/dist/src/hl-run-tgrkrk69.js +1 -0
- package/dist/src/index-0rj9wdk9.js +4 -0
- package/dist/src/index-91y484c2.js +2052 -0
- package/dist/src/index-940y3rnv.js +12 -0
- package/dist/src/index.js +1047 -121
- package/dist/src/message-key-db1xjdkw.js +1 -0
- package/dist/src/message-lock-5vr8079x.js +5 -0
- package/dist/src/sweep-order-c2p6rk8c.js +1 -0
- package/dist/src/sweep-runner-t68xe7vx.js +1 -0
- package/package.json +7 -8
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -293
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -263
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -360
- package/dist/src/lib/journey.d.ts +0 -148
- package/dist/src/lib/journey.js +0 -245
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/network.d.ts +0 -15
- package/dist/src/lib/network.js +0 -41
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -50
- package/dist/src/lib/sui-grpc-send.js +0 -89
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -88
- package/dist/src/lib/vaultfile.js +0 -222
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -110
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -15
- package/dist/src/start.js +0 -203
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -152
- package/dist/src/wallet-money.js +0 -564
- package/dist/src/wallet.d.ts +0 -167
- package/dist/src/wallet.js +0 -855
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -166
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
package/dist/src/wallet.js
DELETED
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { mergeEnv } from './env.js';
|
|
3
|
-
import { writeFileSync, chmodSync, readFileSync, existsSync, rmSync } from 'node:fs';
|
|
4
|
-
import { createInterface } from 'node:readline';
|
|
5
|
-
import { generateWallet, recoverWallet, readDerivation } from '@oneie/sdk/wallet';
|
|
6
|
-
import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
|
|
7
|
-
import { proveAddresses } from '@oneie/sdk/address-proof';
|
|
8
|
-
import { askPath } from './lib/api-path.js';
|
|
9
|
-
import { balancesCmd } from './balances.js';
|
|
10
|
-
import { workspaceFor } from './lib/keyfile.js';
|
|
11
|
-
import { resolveKey } from './lib/client.js';
|
|
12
|
-
import { keySourceOf } from './lib/key-source.js';
|
|
13
|
-
import { readMachineKey } from './lib/paths.js';
|
|
14
|
-
import { wordsStdoutRefusal, agentType } from './lib/agent-env.js';
|
|
15
|
-
import { cliPrefix } from './lib/invoked-as.js';
|
|
16
|
-
import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
|
|
17
|
-
import { receiveCmd, requestCmd, sendCmd, upgradeBalances } from './wallet-money.js';
|
|
18
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
19
|
-
// Re-exported for existing callers/tests — canonical implementation now lives
|
|
20
|
-
// in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
|
|
21
|
-
// it instead of each hardcoding /api/ask/<receiver> against DEFAULT_API.
|
|
22
|
-
export { askPath };
|
|
23
|
-
/**
|
|
24
|
-
* The refusal as the server said it. `wallet:send → failure` alone hid the reason —
|
|
25
|
-
* measured 2026-11-03 (text/agent-path.md § Stop 8): the server had answered
|
|
26
|
-
* `forbidden · requires manage_workspace · callerRole agent · "Requires the owner role"`.
|
|
27
|
-
*/
|
|
28
|
-
export function refusalMessage(receiver, envelope) {
|
|
29
|
-
const r = envelope.result ?? {};
|
|
30
|
-
const why = [r.error ?? envelope.error, r.required && `requires ${String(r.required)}`, r.callerRole && `you are ${String(r.callerRole)}`]
|
|
31
|
-
.filter(Boolean).map(String);
|
|
32
|
-
const hint = typeof r.hint === 'string' ? ` — ${r.hint}` : '';
|
|
33
|
-
return `${receiver} → ${envelope.outcome}${why.length ? `: ${why.join(' · ')}` : ''}${hint}`;
|
|
34
|
-
}
|
|
35
|
-
async function ask(base, key, receiver, data) {
|
|
36
|
-
const res = await fetch(askPath(base, receiver), {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
39
|
-
body: JSON.stringify({ data }),
|
|
40
|
-
});
|
|
41
|
-
if (!res.ok) {
|
|
42
|
-
const body = await res.text().catch(() => '');
|
|
43
|
-
throw new Error(`${receiver} → ${res.status}\n${body}`);
|
|
44
|
-
}
|
|
45
|
-
const envelope = (await res.json());
|
|
46
|
-
if (envelope.outcome && envelope.outcome !== 'result')
|
|
47
|
-
throw new Error(refusalMessage(receiver, envelope));
|
|
48
|
-
return envelope.result ?? envelope;
|
|
49
|
-
}
|
|
50
|
-
const DEFAULT_PAY = process.env.ONEIE_PAY_URL ?? 'https://pay.one.ie';
|
|
51
|
-
// pay.one.ie is a separate service from the gateway/one.ie ask surface above —
|
|
52
|
-
// its own protocol envelope, POST <payUrl>/ { protocol, data } → { success, data,
|
|
53
|
-
// error? }. faucet_request is public (no credential), matching the threat model:
|
|
54
|
-
// funding ≠ ownership, anyone can fund any address (wallet-plan.md).
|
|
55
|
-
async function payProtocol(payUrl, protocol, data) {
|
|
56
|
-
const res = await fetch(`${payUrl.replace(/\/$/, '')}/`, {
|
|
57
|
-
method: 'POST',
|
|
58
|
-
headers: { 'Content-Type': 'application/json' },
|
|
59
|
-
body: JSON.stringify({ protocol, data }),
|
|
60
|
-
});
|
|
61
|
-
const body = (await res.json().catch(() => ({})));
|
|
62
|
-
if (!res.ok || !body.success) {
|
|
63
|
-
throw new Error(`${protocol} → ${body.error?.message ?? body.error?.code ?? res.status}`);
|
|
64
|
-
}
|
|
65
|
-
return body.data ?? {};
|
|
66
|
-
}
|
|
67
|
-
// ── which derivation a wallet is born under ─────────────────────────────────
|
|
68
|
-
/**
|
|
69
|
-
* A FRESH mint is born v2 — the same as one.ie (`NEW_MASTER_DERIVATION` in
|
|
70
|
-
* one.ie/web/src/lib/derive-multichain.ts). Before this the CLI minted v1 and the
|
|
71
|
-
* browser v2, so the same 24 words opened a different, empty wallet on each
|
|
72
|
-
* surface and nothing errored (task:01a0c33a93bbebfc8e2ebba0).
|
|
73
|
-
*
|
|
74
|
-
* A RECOVER has no marker to read, so it takes `--derivation` and an absent one is
|
|
75
|
-
* v1: the words may belong to a v1 key, and a v1 key recovers its v1 addresses
|
|
76
|
-
* forever. Guessing v2 here would recreate the same silent divergence in reverse.
|
|
77
|
-
*/
|
|
78
|
-
export const MINT_DERIVATION = 'v2';
|
|
79
|
-
export function walletDerivation(opts) {
|
|
80
|
-
if (opts.derivation === undefined)
|
|
81
|
-
return opts.recover ? 'v1' : MINT_DERIVATION;
|
|
82
|
-
return readDerivation(opts.derivation);
|
|
83
|
-
}
|
|
84
|
-
/** Mint or recover, under the derivation named above — the one door both commands use. */
|
|
85
|
-
export async function walletFor(opts, words) {
|
|
86
|
-
const derivation = walletDerivation(opts);
|
|
87
|
-
const wallet = opts.recover ? await recoverWallet(words(), derivation) : await generateWallet(derivation);
|
|
88
|
-
return { wallet, derivation };
|
|
89
|
-
}
|
|
90
|
-
/** Seal the words WITH their derivation. v1 is the field's absence (it rides the
|
|
91
|
-
* AAD only when present), so a v1 vault stays byte-compatible with every one
|
|
92
|
-
* written before the marker existed. */
|
|
93
|
-
export async function sealWallet(mnemonic, passphrase, opts) {
|
|
94
|
-
return sealVault(mnemonic, passphrase, {
|
|
95
|
-
wrap: opts.wrap,
|
|
96
|
-
authPub: opts.authPub,
|
|
97
|
-
kdf: opts.kdf,
|
|
98
|
-
...(opts.derivation === 'v2' ? { derivation: 'v2' } : {}),
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/** The addresses a sealed vault holds, read under ITS marker — absent is v1. */
|
|
102
|
-
export async function openedWallet(blob, mnemonic) {
|
|
103
|
-
return recoverWallet(mnemonic, readDerivation(blob.derivation));
|
|
104
|
-
}
|
|
105
|
-
function resolveAuth(opts) {
|
|
106
|
-
const env = mergeEnv(process.cwd());
|
|
107
|
-
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? resolveKey();
|
|
108
|
-
return { base: opts.api.replace(/\/$/, ''), key };
|
|
109
|
-
}
|
|
110
|
-
export { workspaceFor };
|
|
111
|
-
function resolveWorkspace(explicit) {
|
|
112
|
-
const workspace = workspaceFor(explicit, process.cwd(), mergeEnv(process.cwd()));
|
|
113
|
-
if (!workspace) {
|
|
114
|
-
process.stderr.write('--workspace required (or set AGENCY_SLUG, or run from the folder `npx oneie` made)\n');
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
return workspace;
|
|
118
|
-
}
|
|
119
|
-
// A chain with no auto-fund path (ETH/USDC/BTC) legitimately returns success:false
|
|
120
|
-
// with a manualUrls fallback — that's documented, expected behavior (wallet-plan.md:
|
|
121
|
-
// "SUI/SOL auto-fund; ETH/USDC/BTC return a manual URL"), never a call failure.
|
|
122
|
-
// `ok` here means "the request was answered" (payProtocol already throws on a real
|
|
123
|
-
// failure) — per-chain funded/manual status lives in `results`, read that, not `ok`.
|
|
124
|
-
export function faucetOk(results) {
|
|
125
|
-
return results.length > 0;
|
|
126
|
-
}
|
|
127
|
-
// wallet:get/create/transactions return bare data or { error } — no `ok` field
|
|
128
|
-
// of their own. wallet:send already returns { ok, ... }. Normalize both to the
|
|
129
|
-
// { ok, ... } shape out() expects without ever overwriting a real error/false
|
|
130
|
-
// with a hardcoded ok:true.
|
|
131
|
-
export function okWrap(result) {
|
|
132
|
-
if ('ok' in result)
|
|
133
|
-
return result;
|
|
134
|
-
if ('error' in result)
|
|
135
|
-
return { ok: false, ...result };
|
|
136
|
-
return { ok: true, ...result };
|
|
137
|
-
}
|
|
138
|
-
export function walletCmd() {
|
|
139
|
-
const cmd = new Command('wallet').description('Read balances, provision a wallet row, fund from testnet, send crypto — wallet:* receivers + pay.one.ie');
|
|
140
|
-
cmd.command('get')
|
|
141
|
-
.description('Credits, spend ceiling, wallet rows, live chain balances (sui · evm · solana · btc · hyperliquid), delegated wallets')
|
|
142
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
143
|
-
.option('--actor <id>', 'Actor within the workspace (defaults to workspace)')
|
|
144
|
-
.option('--net <network>', 'mainnet | testnet — the one network every balance is read on (defaults to the deploy\'s; ask mainnet for real money)')
|
|
145
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
146
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
147
|
-
.action(async (opts) => {
|
|
148
|
-
if (opts.net && opts.net !== 'mainnet' && opts.net !== 'testnet') {
|
|
149
|
-
out(cmd, { ok: false, error: '--net must be mainnet or testnet' });
|
|
150
|
-
process.exitCode = 1;
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const { base, key } = resolveAuth(opts);
|
|
154
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
155
|
-
const result = await ask(base, key, 'wallet:get', { workspace, actor: opts.actor, ...(opts.net ? { net: opts.net } : {}) });
|
|
156
|
-
out(cmd, okWrap(result));
|
|
157
|
-
});
|
|
158
|
-
// balances — the REAL mainnet balances of the loaded wallet, read from the chains (src/balances.ts).
|
|
159
|
-
// `get` above is ONE's own ledger and shows test money for most chains.
|
|
160
|
-
cmd.addCommand(balancesCmd({
|
|
161
|
-
fetch: (url, init) => fetch(url, init),
|
|
162
|
-
addresses: async (opts) => {
|
|
163
|
-
const { base, key } = resolveAuth(opts);
|
|
164
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
165
|
-
const w = await ask(base, key, 'wallet:get', { workspace, actor: opts.actor });
|
|
166
|
-
const rows = Array.isArray(w['addresses']) ? w['addresses'] : [];
|
|
167
|
-
const who = opts.actor ?? workspace;
|
|
168
|
-
const mine = (chain) => rows.find((x) => x.chain === chain && x.actor === who && typeof x.address === 'string')?.address;
|
|
169
|
-
return { evm: mine('evm'), sui: mine('sui') };
|
|
170
|
-
},
|
|
171
|
-
}, DEFAULT_API));
|
|
172
|
-
// list — every wallet in the workspace with the words it wears (treasury · agent · person ·
|
|
173
|
-
// limit · paused · no-limit · sweep · vault · no-address). The tags are wallet:get's own,
|
|
174
|
-
// derived on the server from the rows, the caps and the signed sweep rules.
|
|
175
|
-
cmd.command('list')
|
|
176
|
-
.description('Every wallet in the workspace with its tags, limit and sweep rule')
|
|
177
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
178
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
179
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
180
|
-
.action(async (opts) => {
|
|
181
|
-
const { base, key } = resolveAuth(opts);
|
|
182
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
183
|
-
const result = await ask(base, key, 'wallet:get', { workspace });
|
|
184
|
-
const wallets = Array.isArray(result.wallets) ? result.wallets : [];
|
|
185
|
-
const rows = wallets.map(walletLine);
|
|
186
|
-
if (cmd.parent?.opts().json) {
|
|
187
|
-
process.stdout.write(JSON.stringify({ ok: !result.error, workspace, wallets: rows, ...(result.error ? { error: result.error } : {}) }) + '\n');
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (result.error)
|
|
191
|
-
return out(cmd, okWrap(result));
|
|
192
|
-
if (!rows.length)
|
|
193
|
-
return console.log(`no wallets in ${workspace} yet`);
|
|
194
|
-
for (const r of rows)
|
|
195
|
-
console.log(formatWalletLine(r));
|
|
196
|
-
});
|
|
197
|
-
// limit — the owner's one number for an agent: credits a month, 0 pauses it. Lowering is
|
|
198
|
-
// open to anyone who controls the workspace; raising needs a person (this CLI's own human
|
|
199
|
-
// key counts, an agent key never does). The server decides — this only sends the number.
|
|
200
|
-
cmd.command('limit <agent> <credits>')
|
|
201
|
-
.description('Set an agent\'s spending limit in credits a month (1000 = $1). 0 pauses it')
|
|
202
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
203
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
204
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
205
|
-
.action(async (agent, raw, opts) => {
|
|
206
|
-
const credits = parseCredits(raw);
|
|
207
|
-
if (credits === null) {
|
|
208
|
-
out(cmd, { ok: false, error: 'credits must be a whole number from 0 to 10000000' });
|
|
209
|
-
process.exitCode = 1;
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const { base, key } = resolveAuth(opts);
|
|
213
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
214
|
-
const result = await ask(base, key, 'wallet:update', { workspace, actor: agent, limit: credits });
|
|
215
|
-
if (!result.ok)
|
|
216
|
-
process.exitCode = 1;
|
|
217
|
-
out(cmd, okWrap(result));
|
|
218
|
-
});
|
|
219
|
-
cmd.command('create')
|
|
220
|
-
.description('Provision a wallet row for an actor (idempotent)')
|
|
221
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
222
|
-
.option('--actor <id>', 'Actor to provision (defaults to workspace)')
|
|
223
|
-
.option('--kind <kind>', 'human | agent', 'human')
|
|
224
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
225
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
226
|
-
.action(async (opts) => {
|
|
227
|
-
const { base, key } = resolveAuth(opts);
|
|
228
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
229
|
-
const result = await ask(base, key, 'wallet:create', { workspace, actor: opts.actor, kind: opts.kind });
|
|
230
|
-
out(cmd, okWrap(result));
|
|
231
|
-
});
|
|
232
|
-
cmd.command('transactions')
|
|
233
|
-
.description('Unified transaction feed across every settlement rail')
|
|
234
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
235
|
-
.option('--limit <n>', 'Max rows (default 100, max 500)', '100')
|
|
236
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
237
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
238
|
-
.action(async (opts) => {
|
|
239
|
-
const { base, key } = resolveAuth(opts);
|
|
240
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
241
|
-
const result = await ask(base, key, 'wallet:transactions', { workspace, limit: Number(opts.limit) });
|
|
242
|
-
out(cmd, okWrap(result));
|
|
243
|
-
});
|
|
244
|
-
cmd.command('faucet <address>')
|
|
245
|
-
.description('Fund an address from a testnet tap — Sui and Solana auto-fund; ETH/USDC/BTC return a manual faucet URL')
|
|
246
|
-
.requiredOption('--chain <chain>', 'sui | sol | eth | usdc | btc | all')
|
|
247
|
-
.option('--network <network>', 'testnet | devnet (Sui only)')
|
|
248
|
-
.option('--pay-url <url>', 'pay.one.ie base URL', DEFAULT_PAY)
|
|
249
|
-
.action(async (address, opts) => {
|
|
250
|
-
const data = await payProtocol(opts.payUrl, 'faucet_request', { chain: opts.chain, address, network: opts.network });
|
|
251
|
-
const results = (data.results ?? []);
|
|
252
|
-
out(cmd, { ok: faucetOk(results), results, manualFaucets: data.manualFaucets });
|
|
253
|
-
});
|
|
254
|
-
// receive · send · request, and --net on balances — the loaded wallet's money (src/wallet-money.ts).
|
|
255
|
-
// `send <amount> <asset>[@chain] <to>` signs with the sealed vault on --live; the older
|
|
256
|
-
// `send <to> --chain --amount --payment-tx` form still records a transfer signed elsewhere.
|
|
257
|
-
const money = {
|
|
258
|
-
ask: (o, receiver, data) => { const { base, key } = resolveAuth(o); return ask(base, key, receiver, data); },
|
|
259
|
-
workspace: resolveWorkspace,
|
|
260
|
-
// Who the key acts as and where it came from — wallet:challenge names the actor; the key itself is never printed.
|
|
261
|
-
identity: async (o, which) => {
|
|
262
|
-
const src = keySourceOf(o);
|
|
263
|
-
if (which === 'machine' && !src.local)
|
|
264
|
-
return null;
|
|
265
|
-
const { base, key } = resolveAuth(o);
|
|
266
|
-
const useKey = which === 'machine' ? readMachineKey() : key;
|
|
267
|
-
const from = which === 'machine' ? keySourceOf({}, '/nonexistent-folder', {}).label : src.label;
|
|
268
|
-
let actor;
|
|
269
|
-
try {
|
|
270
|
-
actor = String((await ask(base, useKey, 'wallet:challenge', {}))['actor'] ?? '') || undefined;
|
|
271
|
-
}
|
|
272
|
-
catch { /* unread: the header says so */ }
|
|
273
|
-
return { actor, from, local: which === 'machine' ? false : src.local };
|
|
274
|
-
},
|
|
275
|
-
unlock: (dir) => unlock(dir),
|
|
276
|
-
defaultApi: DEFAULT_API,
|
|
277
|
-
relay: async (_c, to, o) => {
|
|
278
|
-
const opts = o;
|
|
279
|
-
const { base, key } = resolveAuth(opts);
|
|
280
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
281
|
-
const result = await ask(base, key, 'wallet:send', {
|
|
282
|
-
workspace, to, chain: opts.chain, amount: Number(opts.amount), paymentTx: opts.paymentTx,
|
|
283
|
-
unit: opts.unit, currency: opts.currency, userAddress: opts.userAddress, memo: opts.memo,
|
|
284
|
-
});
|
|
285
|
-
out(cmd, okWrap(result));
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
const balances = cmd.commands.find((c) => c.name() === 'balances');
|
|
289
|
-
if (balances)
|
|
290
|
-
upgradeBalances(balances, money);
|
|
291
|
-
cmd.addCommand(receiveCmd(money));
|
|
292
|
-
cmd.addCommand(sendCmd(money));
|
|
293
|
-
cmd.addCommand(requestCmd(money));
|
|
294
|
-
cmd.command('register')
|
|
295
|
-
.description('Register a keygen output\'s PUBLIC receiving addresses with a workspace — sends addresses only, never a key or a mnemonic. With --kind agent the keys in --from (or the sealed wallet in --dir) sign a server challenge locally, and only the signatures are sent. First write wins per chain and is permanent')
|
|
296
|
-
.option('--from <file>', 'A `wallet keygen --out` file (or any JSON with `addresses` / `keys`) — only the address fields are read')
|
|
297
|
-
.option('--addresses <json>', 'Inline JSON address map, e.g. \'{"sui":"0x…","evm":"0x…"}\'')
|
|
298
|
-
.option('--dir <path>', 'With --kind agent: open the SEALED wallet in this project folder (what `oneie init` / `wallet new` write) — passphrase at the terminal, or Touch ID for a keychain wallet — and register it by proof')
|
|
299
|
-
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
300
|
-
.option('--actor <id>', 'Actor to register for (defaults to workspace)')
|
|
301
|
-
.option('--kind <kind>', 'human | agent', 'human')
|
|
302
|
-
.option('--yes', 'Skip the confirmation prompt (for scripted provisioning)')
|
|
303
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
304
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
305
|
-
.action(async (opts) => {
|
|
306
|
-
const { base, key } = resolveAuth(opts);
|
|
307
|
-
const workspace = resolveWorkspace(opts.workspace);
|
|
308
|
-
if (opts.dir !== undefined) {
|
|
309
|
-
if (opts.from || opts.addresses) {
|
|
310
|
-
out(cmd, { ok: false, error: '--dir opens a sealed wallet — pass it alone, not with --from or --addresses' });
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if (opts.kind !== 'agent') {
|
|
314
|
-
out(cmd, { ok: false, error: '--dir registers by proof, which is the agent path — pass --kind agent' });
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const actor = opts.actor ?? workspace;
|
|
318
|
-
out(cmd, await registerSealedWallet({
|
|
319
|
-
base, key, workspace, actor, dir: opts.dir,
|
|
320
|
-
confirmAddresses: async (addresses) => {
|
|
321
|
-
process.stderr.write(`Registering PUBLIC receiving addresses for actor '${actor}' in workspace '${workspace}':\n`);
|
|
322
|
-
for (const [chain, addr] of Object.entries(addresses))
|
|
323
|
-
process.stderr.write(` ${chain.padEnd(7)} ${addr}\n`);
|
|
324
|
-
process.stderr.write('This is permanent — the first address written to a chain cannot be changed.\n');
|
|
325
|
-
return Boolean(opts.yes) || confirm('Register these addresses? [y/N] ');
|
|
326
|
-
},
|
|
327
|
-
}));
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
const source = opts.from
|
|
331
|
-
? JSON.parse(readFileSync(opts.from, 'utf8'))
|
|
332
|
-
: opts.addresses
|
|
333
|
-
? JSON.parse(opts.addresses)
|
|
334
|
-
: (() => { throw new Error('register needs --from <file> or --addresses <json>'); })();
|
|
335
|
-
const addresses = addressesOnly(source);
|
|
336
|
-
if (Object.keys(addresses).length === 0) {
|
|
337
|
-
throw new Error('no addresses found — expected an `addresses` map or a `keys` array of { chain, address }');
|
|
338
|
-
}
|
|
339
|
-
// mergeAddresses is FIRST-WRITE-WINS: a wrong address here is where every future
|
|
340
|
-
// payment lands, and the row refuses to change it afterwards (address_conflict).
|
|
341
|
-
// So the operator reads the exact strings back before anything is sent.
|
|
342
|
-
const actor = opts.actor ?? workspace;
|
|
343
|
-
process.stderr.write(`Registering PUBLIC receiving addresses for actor '${actor}' in workspace '${workspace}':\n`);
|
|
344
|
-
for (const [chain, addr] of Object.entries(addresses)) {
|
|
345
|
-
process.stderr.write(` ${chain.padEnd(7)} ${addr}\n`);
|
|
346
|
-
}
|
|
347
|
-
process.stderr.write('This is permanent — the first address written to a chain cannot be changed.\n');
|
|
348
|
-
if (!opts.yes && !(await confirm('Register these addresses? [y/N] '))) {
|
|
349
|
-
out(cmd, { ok: false, error: 'cancelled' });
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
// An agent's addresses are taken only with proof of control, so an agent
|
|
353
|
-
// registration signs locally with the keygen file's keys — inline
|
|
354
|
-
// --addresses carries no keys and cannot prove anything.
|
|
355
|
-
if (opts.kind === 'agent') {
|
|
356
|
-
const keys = signingKeys(source);
|
|
357
|
-
if (keys.length === 0) {
|
|
358
|
-
out(cmd, { ok: false, error: 'an agent registration signs a server challenge — pass --from <a `wallet keygen --out` file> holding the keys' });
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
out(cmd, await registerAgentWallet({ base, key, workspace, actor, keys }));
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
// `actor`, not `opts.actor` — what the operator confirmed on screen is what gets
|
|
365
|
-
// written, rather than relying on the resolver's own default to agree.
|
|
366
|
-
const result = await ask(base, key, 'wallet:create', { workspace, actor, kind: opts.kind, addresses });
|
|
367
|
-
out(cmd, okWrap(result));
|
|
368
|
-
});
|
|
369
|
-
cmd.command('keygen')
|
|
370
|
-
.description('Generate or recover a self-hosted wallet locally — Sui/EVM/Sol/BTC, plus ASI under v2, fully offline, never touches the network or a server. Prints once by default; use --out for scripted bulk provisioning')
|
|
371
|
-
.option('--recover', 'Recover from a 24-word BIP-39 mnemonic (ONE_WALLET_MNEMONIC env or stdin) instead of generating a fresh one')
|
|
372
|
-
.option('--derivation <v>', 'v2 (default for a fresh key — what one.ie mints) or v1. With --recover the default is v1: the words carry no marker, and a v1 key recovers its v1 addresses forever')
|
|
373
|
-
.option('--out <file>', 'Write the mnemonic + keys to a file at mode 0600 instead of printing once')
|
|
374
|
-
.option('--yes-i-accept-plaintext-file', 'Required with --out — acknowledge that unencrypted key material will be written to disk')
|
|
375
|
-
.action(async (opts) => {
|
|
376
|
-
const { wallet, derivation } = await walletFor(opts, readMnemonic);
|
|
377
|
-
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
378
|
-
if (opts.out) {
|
|
379
|
-
const contents = JSON.stringify({ mnemonic: wallet.mnemonic, derivation, keys: wallet.keys }, null, 2) + '\n';
|
|
380
|
-
writeKeysFile(opts.out, contents, Boolean(opts.yesIAcceptPlaintextFile));
|
|
381
|
-
out(cmd, { ok: true, out: opts.out, derivation, chains: wallet.keys.map((k) => k.chain), addresses });
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
out(cmd, { ok: true, mnemonic: wallet.mnemonic, derivation, addresses, keys: wallet.keys });
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
// ── the encrypted wallet folder ────────────────────────────────────────────
|
|
388
|
-
cmd.command('new')
|
|
389
|
-
.description('Create an encrypted wallet in this folder — 24 words sealed with a passphrase, four chains (five under v2, with ASI), fully offline')
|
|
390
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
391
|
-
.option('--recover', 'Seal an EXISTING 24-word phrase instead of generating a new one (ONE_WALLET_MNEMONIC or stdin)')
|
|
392
|
-
.option('--derivation <v>', 'v2 (default for a fresh wallet — what one.ie mints) or v1. With --recover the default is v1: the words carry no marker, and a v1 key recovers its v1 addresses forever')
|
|
393
|
-
.option('--keychain', 'Seal with a random secret stored in Apple Keychain, so Touch ID opens it instead of a passphrase')
|
|
394
|
-
.action(async (opts) => {
|
|
395
|
-
// Refuse BEFORE generating. Minting a wallet and then failing to store it
|
|
396
|
-
// is the one outcome that loses money: the words would exist only in a
|
|
397
|
-
// process about to exit.
|
|
398
|
-
if (existsSync(vaultPath(opts.dir))) {
|
|
399
|
-
out(cmd, { ok: false, error: `a wallet already exists at ${vaultPath(opts.dir)} — move it aside first` });
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (opts.keychain && !keychainAvailable()) {
|
|
403
|
-
out(cmd, { ok: false, error: 'Keychain is macOS-only — omit --keychain to seal with a passphrase' });
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
// A bad --derivation is refused before the passphrase is asked for, not after.
|
|
407
|
-
try {
|
|
408
|
-
walletDerivation(opts);
|
|
409
|
-
}
|
|
410
|
-
catch {
|
|
411
|
-
out(cmd, { ok: false, error: '--derivation must be v1 or v2' });
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
let passphrase;
|
|
415
|
-
let wrap;
|
|
416
|
-
if (opts.keychain) {
|
|
417
|
-
passphrase = mintKeychainSecret();
|
|
418
|
-
wrap = 'keychain';
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
passphrase = await promptSecret('Passphrase for this wallet: ');
|
|
422
|
-
const again = await promptSecret('Repeat it: ');
|
|
423
|
-
if (passphrase !== again) {
|
|
424
|
-
out(cmd, { ok: false, error: 'passphrases did not match — nothing was written' });
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (passphrase.length < 8) {
|
|
428
|
-
out(cmd, { ok: false, error: 'passphrase too short — this is the only thing between a stolen laptop and the wallet' });
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
wrap = 'passphrase';
|
|
432
|
-
}
|
|
433
|
-
const { wallet, derivation } = await walletFor(opts, readMnemonic);
|
|
434
|
-
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
435
|
-
const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
|
|
436
|
-
const blob = await sealWallet(wallet.mnemonic, passphrase, { wrap, authPub, derivation });
|
|
437
|
-
const res = writeVaultFolder(opts.dir, { ...blob });
|
|
438
|
-
if (!res.ok) {
|
|
439
|
-
out(cmd, { ok: false, error: res.error });
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
if (opts.keychain) {
|
|
443
|
-
const k = keychainStore(authPub, passphrase);
|
|
444
|
-
if (!k.ok) {
|
|
445
|
-
// The vault is sealed with a secret nobody can now produce. Remove it
|
|
446
|
-
// rather than leaving an unopenable file that looks like a wallet.
|
|
447
|
-
rmSync(res.path, { force: true });
|
|
448
|
-
out(cmd, { ok: false, error: `Keychain write failed (${k.error}) — the wallet was removed rather than left unopenable` });
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
out(cmd, {
|
|
453
|
-
ok: true,
|
|
454
|
-
wallet: res.path,
|
|
455
|
-
wrap,
|
|
456
|
-
derivation,
|
|
457
|
-
addresses,
|
|
458
|
-
next: `${cliPrefix()} wallet paper${opts.dir === '.' ? '' : ` --dir ${opts.dir}`} # write the 24 words down — this is the ONLY backup`,
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
cmd.command('open')
|
|
462
|
-
.description('Unlock the wallet in this folder and show its addresses — the phrase never leaves this machine')
|
|
463
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
464
|
-
.action(async (opts) => {
|
|
465
|
-
const r = await unlock(opts.dir);
|
|
466
|
-
if ('error' in r) {
|
|
467
|
-
out(cmd, { ok: false, error: r.error });
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
out(cmd, { ok: true, wrap: r.blob.wrap, addresses: r.addresses });
|
|
471
|
-
});
|
|
472
|
-
cmd.command('paper')
|
|
473
|
-
.description('Print the recovery sheet — 24 numbered words plus the public addresses. Print it, then close the terminal')
|
|
474
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
475
|
-
.option('--yes-print-to-pipe', 'Print the words even though stdout is not a terminal — a printer, on purpose. An agent shell is refused regardless')
|
|
476
|
-
.action(async (opts) => {
|
|
477
|
-
// Refuse BEFORE unlock: no passphrase prompt, no Touch ID, when the words could not be shown.
|
|
478
|
-
const why = wordsStdoutRefusal(process.env, Boolean(process.stdout.isTTY), Boolean(opts.yesPrintToPipe));
|
|
479
|
-
if (why) {
|
|
480
|
-
out(cmd, { ok: false, error: why });
|
|
481
|
-
process.exitCode = 1;
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const r = await paperFor(opts.dir);
|
|
485
|
-
if ('error' in r) {
|
|
486
|
-
out(cmd, { ok: false, error: r.error });
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
// Straight to stdout, never through out(): a --json receipt carrying 24
|
|
490
|
-
// words would put the whole wallet into any pipeline or CI log that
|
|
491
|
-
// captured it.
|
|
492
|
-
process.stdout.write(r.sheet + '\n');
|
|
493
|
-
});
|
|
494
|
-
cmd.command('keychain')
|
|
495
|
-
.description('Move this wallet behind Touch ID — stores its passphrase in Apple Keychain so biometrics open it')
|
|
496
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
497
|
-
.action(async (opts) => {
|
|
498
|
-
if (!keychainAvailable()) {
|
|
499
|
-
out(cmd, { ok: false, error: 'Keychain is macOS-only' });
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
const blob = readVaultFolder(opts.dir);
|
|
503
|
-
if (!blob) {
|
|
504
|
-
out(cmd, { ok: false, error: `no wallet at ${vaultPath(opts.dir)}` });
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (blob.wrap === 'keychain') {
|
|
508
|
-
out(cmd, { ok: true, note: 'already opened by Keychain' });
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const pass = await promptSecret('Current passphrase: ');
|
|
512
|
-
// Prove the passphrase before storing it — storing an unverified string
|
|
513
|
-
// would put a secret in Keychain that opens nothing.
|
|
514
|
-
try {
|
|
515
|
-
await openVault(blob, pass);
|
|
516
|
-
}
|
|
517
|
-
catch {
|
|
518
|
-
out(cmd, { ok: false, error: 'wrong passphrase — nothing was stored' });
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const k = keychainStore(String(blob.authPub ?? ''), pass);
|
|
522
|
-
out(cmd, k.ok ? { ok: true, note: 'Touch ID now opens this wallet' } : { ok: false, error: k.error });
|
|
523
|
-
});
|
|
524
|
-
// The browser's /w/restore "Key file" door opens a vault sealed with a TYPED
|
|
525
|
-
// passphrase — it cannot read this machine's Keychain. This writes that copy:
|
|
526
|
-
// the same 24 words, the same derivation, a passphrase the person types twice.
|
|
527
|
-
// Nothing secret reaches stdout; the file is useless without the passphrase.
|
|
528
|
-
cmd.command('file')
|
|
529
|
-
.description('Write a browser copy of this wallet — the same key re-sealed with a passphrase you type, for the Key file door on /w/restore (drag and drop). Prints only the path and the addresses')
|
|
530
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
531
|
-
.option('--out <path>', 'Where to write it', '')
|
|
532
|
-
.action(async (opts) => {
|
|
533
|
-
if (!process.stdin.isTTY) {
|
|
534
|
-
out(cmd, { ok: false, error: 'a passphrase is typed at a terminal, never piped — run this yourself' });
|
|
535
|
-
process.exitCode = 1;
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const agentHere = agentType(process.env);
|
|
539
|
-
if (agentHere) {
|
|
540
|
-
out(cmd, { ok: false, error: `refusing: this shell is driven by ${agentHere}. Run it yourself in a terminal no agent drives` });
|
|
541
|
-
process.exitCode = 1;
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
const r = await unlock(opts.dir);
|
|
545
|
-
if ('error' in r) {
|
|
546
|
-
out(cmd, { ok: false, error: r.error });
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
const p1 = await promptSecret('Passphrase for the browser copy (12+ characters): ');
|
|
550
|
-
if (p1.length < 12) {
|
|
551
|
-
out(cmd, { ok: false, error: 'too short — nothing written' });
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
const p2 = await promptSecret('Again: ');
|
|
555
|
-
if (p1 !== p2) {
|
|
556
|
-
out(cmd, { ok: false, error: 'they differ — nothing written' });
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
const blob = await sealVault(r.mnemonic, p1, { wrap: 'passphrase', derivation: r.blob.derivation });
|
|
560
|
-
const target = opts.out || `${opts.dir.replace(/\/$/, '')}/wallet-file.json`;
|
|
561
|
-
writeFileSync(target, JSON.stringify(blob, null, 1) + '\n');
|
|
562
|
-
chmodSync(target, 0o600);
|
|
563
|
-
out(cmd, { ok: true, out: target, addresses: r.addresses, next: 'drop it on /w/restore → Key file, type the passphrase; delete the copy once the browser holds the key' });
|
|
564
|
-
});
|
|
565
|
-
// One chain's private key, to the CLIPBOARD and nowhere else — for MetaMask,
|
|
566
|
-
// Phantom, Slush, Sparrow. Never stdout: a terminal scrollback, a CI log or an
|
|
567
|
-
// agent transcript would keep it. The key is derived on demand and dropped.
|
|
568
|
-
cmd.command('key')
|
|
569
|
-
.description('Copy one chain\'s private key to the clipboard for another wallet app (MetaMask, Phantom, Slush, Sparrow). Clipboard only — it is never printed. Prints the address it belongs to')
|
|
570
|
-
.option('--dir <path>', 'Project directory', '.')
|
|
571
|
-
.option('--chain <chain>', 'evm | sui | sol | btc | asi', 'evm')
|
|
572
|
-
.option('--clipboard', 'Required: the only destination this command has')
|
|
573
|
-
.action(async (opts) => {
|
|
574
|
-
if (!opts.clipboard) {
|
|
575
|
-
out(cmd, { ok: false, error: 'add --clipboard — the key goes to the clipboard, never to the screen' });
|
|
576
|
-
process.exitCode = 1;
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
// The same gate as `paper`, BEFORE unlock: a shell an agent drives must not
|
|
580
|
-
// move a private key anywhere — a clipboard is one paste from a transcript.
|
|
581
|
-
// And a terminal, so the hand on the keyboard is a person's.
|
|
582
|
-
const agent = agentType(process.env);
|
|
583
|
-
if (agent) {
|
|
584
|
-
out(cmd, { ok: false, error: `refusing: this shell is driven by ${agent}. Run it yourself in a terminal no agent drives` });
|
|
585
|
-
process.exitCode = 1;
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
589
|
-
out(cmd, { ok: false, error: 'refusing: not a terminal (a pipe, a file or a log)' });
|
|
590
|
-
process.exitCode = 1;
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
const want = opts.chain.toLowerCase();
|
|
594
|
-
const r = await unlock(opts.dir);
|
|
595
|
-
if ('error' in r) {
|
|
596
|
-
out(cmd, { ok: false, error: r.error });
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
const k = r.keys.find((x) => String(x.chain).toLowerCase() === want || (want === 'evm' && ['eth', 'ethereum'].includes(String(x.chain).toLowerCase())) || (want === 'sol' && String(x.chain).toLowerCase() === 'solana'));
|
|
600
|
-
if (!k) {
|
|
601
|
-
out(cmd, { ok: false, error: `no ${want} key in this wallet` });
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
const { spawnSync, spawn } = await import('node:child_process');
|
|
605
|
-
// Fixed system paths only — never a PATH or cwd lookup, which a project-local
|
|
606
|
-
// `pbcopy` could shadow and read the key.
|
|
607
|
-
const copier = process.platform === 'darwin' ? ['/usr/bin/pbcopy']
|
|
608
|
-
: process.platform === 'win32' ? [`${process.env.SystemRoot ?? 'C:\\Windows'}\\System32\\clip.exe`]
|
|
609
|
-
: existsSync('/usr/bin/wl-copy') ? ['/usr/bin/wl-copy'] : ['/usr/bin/xclip', '-selection', 'clipboard'];
|
|
610
|
-
if (!existsSync(copier[0])) {
|
|
611
|
-
out(cmd, { ok: false, error: `no clipboard tool at ${copier[0]} — nothing was printed` });
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
const p = spawnSync(copier[0], copier.slice(1), { input: k.privateKeyHex.replace(/^0x/, '') });
|
|
615
|
-
if (p.status !== 0) {
|
|
616
|
-
out(cmd, { ok: false, error: `clipboard tool ${copier[0]} failed — nothing was printed` });
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
// Clear it after the paste window: the key must not sit on the clipboard.
|
|
620
|
-
// --clear-after defaults to 60 s; the clear is a second spawn of the same tool.
|
|
621
|
-
const seconds = 60;
|
|
622
|
-
const sweeper = spawn(process.execPath, ['-e', `setTimeout(()=>{require('child_process').spawnSync(${JSON.stringify(copier[0])},${JSON.stringify(copier.slice(1))},{input:'cleared'})},${seconds * 1000})`], { detached: true, stdio: 'ignore' });
|
|
623
|
-
sweeper.unref();
|
|
624
|
-
out(cmd, { ok: true, chain: want, address: k.address, note: `private key on the clipboard for ${seconds} s — paste it into the wallet app now; it clears itself after` });
|
|
625
|
-
});
|
|
626
|
-
return cmd;
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Register an AGENT's locally generated addresses: fetch a fresh wallet:challenge,
|
|
630
|
-
* sign one statement per address with the local keys, send addresses + proofs.
|
|
631
|
-
* The server refuses an agent address without this (`address_proof_required`).
|
|
632
|
-
*
|
|
633
|
-
* The private keys are read here and go into `proveAddresses` only; the request
|
|
634
|
-
* body is built from its `{ addresses, proofs }` — public bytes — and nothing else.
|
|
635
|
-
*/
|
|
636
|
-
export async function registerAgentWallet(opts) {
|
|
637
|
-
const issued = okWrap(await ask(opts.base, opts.key, 'wallet:challenge', { workspace: opts.workspace, actor: opts.actor }));
|
|
638
|
-
if (!issued.ok || typeof issued.challenge !== 'string')
|
|
639
|
-
return { ok: false, error: issued.error ?? 'no challenge issued' };
|
|
640
|
-
const { addresses, proofs } = proveAddresses(opts.keys, {
|
|
641
|
-
challenge: issued.challenge, workspace: opts.workspace, actor: opts.actor,
|
|
642
|
-
});
|
|
643
|
-
if (Object.keys(addresses).length === 0)
|
|
644
|
-
return { ok: false, error: 'no signable keys — expected a `keys` array of { chain, address, privateKeyHex }' };
|
|
645
|
-
return okWrap(await ask(opts.base, opts.key, 'wallet:create', {
|
|
646
|
-
workspace: opts.workspace, actor: opts.actor, kind: 'agent', addresses, challenge: issued.challenge, proofs,
|
|
647
|
-
}));
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Register the SEALED wallet in `dir` — the vault `oneie init` and `wallet new`
|
|
651
|
-
* write — by the same challenge → sign → register flow. Opens it the way
|
|
652
|
-
* `wallet open` does (Keychain or the typed passphrase), so a sealed agent wallet
|
|
653
|
-
* whose first registration failed can be retried without ever being written out
|
|
654
|
-
* in the clear. The words and keys stay in this process.
|
|
655
|
-
*/
|
|
656
|
-
export async function registerSealedWallet(opts) {
|
|
657
|
-
const opened = await unlock(opts.dir, opts.io);
|
|
658
|
-
if ('error' in opened)
|
|
659
|
-
return { ok: false, error: opened.error };
|
|
660
|
-
if (opts.confirmAddresses && !(await opts.confirmAddresses(opened.addresses)))
|
|
661
|
-
return { ok: false, error: 'cancelled' };
|
|
662
|
-
return registerAgentWallet({ base: opts.base, key: opts.key, workspace: opts.workspace, actor: opts.actor, keys: opened.keys });
|
|
663
|
-
}
|
|
664
|
-
/** The `keys` array of a keygen file, or [] — read for SIGNING only, never sent. */
|
|
665
|
-
export function signingKeys(source) {
|
|
666
|
-
const keys = (source && typeof source === 'object' ? source['keys'] : undefined);
|
|
667
|
-
return (Array.isArray(keys) ? keys : []).filter((k) => !!k && typeof k.chain === 'string' && typeof k.address === 'string' && typeof k.privateKeyHex === 'string');
|
|
668
|
-
}
|
|
669
|
-
// Chain-name spellings a keygen output may use -> the five columns wallet:create
|
|
670
|
-
// declares. `eth`/`sol` are the SDK's WalletChain spellings; `evm`/`solana` are the
|
|
671
|
-
// server's. Must cover every chain proveAddresses signs, or the confirm screen
|
|
672
|
-
// shows fewer addresses than the agent registration sends.
|
|
673
|
-
const REGISTER_CHAINS = {
|
|
674
|
-
sui: 'sui', evm: 'evm', eth: 'evm', ethereum: 'evm',
|
|
675
|
-
sol: 'solana', solana: 'solana', btc: 'btc', bitcoin: 'btc',
|
|
676
|
-
asi: 'asi', fetch: 'asi',
|
|
677
|
-
};
|
|
678
|
-
/**
|
|
679
|
-
* Reduce ANY keygen-shaped object to public receiving addresses. This is a
|
|
680
|
-
* whitelist build, never a spread or a delete-list: the returned object is
|
|
681
|
-
* constructed field-by-field from four known chain keys whose values must be
|
|
682
|
-
* strings, so a `privateKey`, `secretKey`, `mnemonic` or any other field on the
|
|
683
|
-
* input has no route into the value this command transmits. The custody
|
|
684
|
-
* invariant here is structural, not a policy the caller has to remember.
|
|
685
|
-
*/
|
|
686
|
-
export function addressesOnly(source) {
|
|
687
|
-
const addresses = {};
|
|
688
|
-
const put = (rawChain, rawAddress) => {
|
|
689
|
-
const chain = REGISTER_CHAINS[String(rawChain).toLowerCase()];
|
|
690
|
-
if (!chain || typeof rawAddress !== 'string' || !rawAddress)
|
|
691
|
-
return;
|
|
692
|
-
addresses[chain] = rawAddress;
|
|
693
|
-
};
|
|
694
|
-
const src = (source && typeof source === 'object' ? source : {});
|
|
695
|
-
const nested = (src['addresses'] && typeof src['addresses'] === 'object' ? src['addresses'] : {});
|
|
696
|
-
for (const [chain, value] of Object.entries(src))
|
|
697
|
-
put(chain, value);
|
|
698
|
-
for (const [chain, value] of Object.entries(nested))
|
|
699
|
-
put(chain, value);
|
|
700
|
-
for (const k of (Array.isArray(src['keys']) ? src['keys'] : [])) {
|
|
701
|
-
put(k?.['chain'], k?.['address']);
|
|
702
|
-
}
|
|
703
|
-
return addresses;
|
|
704
|
-
}
|
|
705
|
-
// Ask the operator on the terminal. Used only for the permanent, first-write-wins
|
|
706
|
-
// address registration — every other verb is non-destructive.
|
|
707
|
-
async function confirm(prompt) {
|
|
708
|
-
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
709
|
-
try {
|
|
710
|
-
const answer = await new Promise((resolve) => rl.question(prompt, resolve));
|
|
711
|
-
return /^y(es)?$/i.test(answer.trim());
|
|
712
|
-
}
|
|
713
|
-
finally {
|
|
714
|
-
rl.close();
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
// Read the recovery mnemonic for `keygen --recover`: ONE_WALLET_MNEMONIC env first
|
|
718
|
-
// (scriptable), else stdin (fd 0). Never a CLI arg — keeps the phrase out of the
|
|
719
|
-
// process table / shell history.
|
|
720
|
-
function readMnemonic() {
|
|
721
|
-
const fromEnv = process.env.ONE_WALLET_MNEMONIC?.trim();
|
|
722
|
-
if (fromEnv)
|
|
723
|
-
return fromEnv;
|
|
724
|
-
try {
|
|
725
|
-
return readFileSync(0, 'utf8').trim();
|
|
726
|
-
}
|
|
727
|
-
catch {
|
|
728
|
-
throw new Error('--recover needs a mnemonic — set ONE_WALLET_MNEMONIC or pipe the phrase on stdin');
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
// Write key material to a plaintext file at mode 0600, and ONLY when the operator
|
|
732
|
-
// explicitly accepted the risk. chmod after write in case umask stripped bits at
|
|
733
|
-
// create time. Exported for the demo gate.
|
|
734
|
-
export function writeKeysFile(filePath, contents, accepted) {
|
|
735
|
-
if (!accepted) {
|
|
736
|
-
throw new Error('refusing to write plaintext key material to disk — pass --yes-i-accept-plaintext-file to override');
|
|
737
|
-
}
|
|
738
|
-
writeFileSync(filePath, contents, { mode: 0o600 });
|
|
739
|
-
chmodSync(filePath, 0o600);
|
|
740
|
-
}
|
|
741
|
-
function out(cmd, data) {
|
|
742
|
-
const isJson = cmd.parent?.opts().json;
|
|
743
|
-
if (isJson) {
|
|
744
|
-
process.stdout.write(JSON.stringify(data) + '\n');
|
|
745
|
-
}
|
|
746
|
-
else if (data.ok) {
|
|
747
|
-
const pairs = Object.entries(data)
|
|
748
|
-
.filter(([k]) => k !== 'ok')
|
|
749
|
-
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
750
|
-
.join(' ');
|
|
751
|
-
console.log('✓', pairs);
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
const detail = data.error ?? data.errors ?? data.issues ?? data;
|
|
755
|
-
console.error('✗', typeof detail === 'string' ? detail : JSON.stringify(detail));
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
/** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
|
|
759
|
-
export async function promptSecret(prompt) {
|
|
760
|
-
if (!process.stdin.isTTY)
|
|
761
|
-
throw new Error('a passphrase must be typed at a terminal — refusing to read one from a pipe');
|
|
762
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
763
|
-
const stdout = process.stdout;
|
|
764
|
-
const orig = stdout.write.bind(stdout);
|
|
765
|
-
process.stdout.write(prompt);
|
|
766
|
-
stdout.write = () => true;
|
|
767
|
-
try {
|
|
768
|
-
return await new Promise((resolve) => rl.question('', (a) => { resolve(a); }));
|
|
769
|
-
}
|
|
770
|
-
finally {
|
|
771
|
-
;
|
|
772
|
-
stdout.write = orig;
|
|
773
|
-
rl.close();
|
|
774
|
-
orig('\n');
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
/** The sheet `wallet paper` prints — unlock, then lay out what restore needs. */
|
|
778
|
-
export async function paperFor(dir, io = terminalIO(), cli = cliPrefix()) {
|
|
779
|
-
const r = await unlock(dir, io);
|
|
780
|
-
if ('error' in r)
|
|
781
|
-
return { error: r.error };
|
|
782
|
-
// The vault's OWN marker, read the way unlock derived the addresses above — an
|
|
783
|
-
// absent marker is v1 — so the sheet names the derivation those addresses are.
|
|
784
|
-
return { sheet: paperSheet(r.mnemonic, r.addresses, { derivation: readDerivation(r.blob.derivation), cli }) };
|
|
785
|
-
}
|
|
786
|
-
const terminalIO = () => ({
|
|
787
|
-
interactive: Boolean(process.stdin.isTTY), readPassphrase: promptSecret, readKeychain: keychainRead,
|
|
788
|
-
});
|
|
789
|
-
/**
|
|
790
|
-
* Open the folder's vault, asking Keychain or the human depending on how it was
|
|
791
|
-
* SEALED. `wrap` is what makes this possible: without it a keychain vault is
|
|
792
|
-
* indistinguishable from a passphrase one and the only way to find out is to
|
|
793
|
-
* prompt for a passphrase that was never set.
|
|
794
|
-
*
|
|
795
|
-
* A passphrase vault with no terminal has no passphrase source — the passphrase
|
|
796
|
-
* is never read from argv, env or a pipe — so it is refused BY NAME, the same
|
|
797
|
-
* name `oneie init` refuses with, rather than surfacing promptSecret's throw.
|
|
798
|
-
*/
|
|
799
|
-
export async function unlock(dir, io = terminalIO()) {
|
|
800
|
-
const raw = readVaultFolder(dir);
|
|
801
|
-
if (!raw)
|
|
802
|
-
return { error: `no wallet at ${vaultPath(dir)} — run \`${cliPrefix()} wallet new\`` };
|
|
803
|
-
const blob = raw;
|
|
804
|
-
let passphrase;
|
|
805
|
-
if (blob.wrap === 'keychain') {
|
|
806
|
-
const k = io.readKeychain(String(blob.authPub ?? ''));
|
|
807
|
-
if (!k.ok || !k.value)
|
|
808
|
-
return { error: k.ok ? 'Keychain returned nothing' : String(k.error) };
|
|
809
|
-
passphrase = k.value;
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
if (!io.interactive) {
|
|
813
|
-
return { error: `wallet_passphrase_unavailable: the wallet at ${vaultPath(dir)} is sealed with a passphrase typed at a terminal, and stdin is not one. Run this at a terminal, or move the wallet behind Touch ID with \`${cliPrefix()} wallet keychain\`` };
|
|
814
|
-
}
|
|
815
|
-
passphrase = await io.readPassphrase('Passphrase: ');
|
|
816
|
-
}
|
|
817
|
-
let mnemonic;
|
|
818
|
-
try {
|
|
819
|
-
mnemonic = await openVault(blob, passphrase);
|
|
820
|
-
}
|
|
821
|
-
catch (e) {
|
|
822
|
-
return { error: e.message };
|
|
823
|
-
}
|
|
824
|
-
const wallet = await openedWallet(blob, mnemonic);
|
|
825
|
-
return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])), keys: wallet.keys };
|
|
826
|
-
}
|
|
827
|
-
/** "5000" → 5000; anything that is not a whole number in 0..10M → null (the server checks again). */
|
|
828
|
-
export function parseCredits(raw) {
|
|
829
|
-
if (!/^\d{1,8}$/.test(raw.trim()))
|
|
830
|
-
return null;
|
|
831
|
-
const n = Number(raw.trim());
|
|
832
|
-
return n <= 10_000_000 ? n : null;
|
|
833
|
-
}
|
|
834
|
-
/** One wallet:get row reduced to what a person reads: who, the tags, the first address, the limit, the sweep. */
|
|
835
|
-
export function walletLine(w) {
|
|
836
|
-
const address = ['sui_address', 'evm_address', 'solana_address', 'btc_address', 'asi_address']
|
|
837
|
-
.map((k) => w[k]).find((v) => typeof v === 'string' && v.length > 0) ?? null;
|
|
838
|
-
return {
|
|
839
|
-
actor: String(w.actor ?? ''),
|
|
840
|
-
tags: Array.isArray(w.tags) ? w.tags.map(String) : [],
|
|
841
|
-
address,
|
|
842
|
-
limit: w.limit ?? null,
|
|
843
|
-
sweep: w.sweep ?? null,
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
export function formatWalletLine(r) {
|
|
847
|
-
const parts = [r.actor.padEnd(24), `[${r.tags.join(' ')}]`];
|
|
848
|
-
if (r.limit)
|
|
849
|
-
parts.push(r.limit.paused ? 'paused' : `limit ${r.limit.spentCredits}/${r.limit.monthlyCredits} credits`);
|
|
850
|
-
if (r.sweep)
|
|
851
|
-
parts.push(`sweeps ${r.sweep.chain} above ${r.sweep.thresholdUnits} keeping ${r.sweep.floatUnits}`);
|
|
852
|
-
if (r.address)
|
|
853
|
-
parts.push(r.address);
|
|
854
|
-
return parts.join(' ');
|
|
855
|
-
}
|