@oneie/cli 5.8.0 → 5.9.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.
Files changed (270) hide show
  1. package/README.md +114 -6
  2. package/dist/package.json +37 -11
  3. package/dist/src/age-1k8hs4ec.js +1 -0
  4. package/dist/src/client-n6fpnd9f.js +1 -0
  5. package/dist/src/evm-tx-cqhm9rtt.js +1 -0
  6. package/dist/src/hl-run-0pv1e0p2.js +1 -0
  7. package/dist/src/index-f5vhzspa.js +12 -0
  8. package/dist/src/index-h3nrt8bx.js +4 -0
  9. package/dist/src/index-st6k9vhc.js +2062 -0
  10. package/dist/src/index.js +1122 -134
  11. package/dist/src/message-key-yczrxszr.js +1 -0
  12. package/dist/src/message-lock-thr851d5.js +5 -0
  13. package/dist/src/sweep-order-jrq2hkye.js +1 -0
  14. package/dist/src/sweep-runner-jftw9em7.js +1 -0
  15. package/package.json +37 -11
  16. package/dist/src/agent.d.ts +0 -75
  17. package/dist/src/agent.js +0 -1334
  18. package/dist/src/agentverse.d.ts +0 -26
  19. package/dist/src/agentverse.js +0 -171
  20. package/dist/src/args.d.ts +0 -9
  21. package/dist/src/args.js +0 -61
  22. package/dist/src/auth.d.ts +0 -6
  23. package/dist/src/auth.js +0 -121
  24. package/dist/src/balances.d.ts +0 -89
  25. package/dist/src/balances.js +0 -202
  26. package/dist/src/banner.d.ts +0 -1
  27. package/dist/src/banner.js +0 -17
  28. package/dist/src/broadcast.d.ts +0 -8
  29. package/dist/src/broadcast.js +0 -175
  30. package/dist/src/catalog.d.ts +0 -12
  31. package/dist/src/catalog.js +0 -76
  32. package/dist/src/ceiling.d.ts +0 -36
  33. package/dist/src/ceiling.js +0 -189
  34. package/dist/src/chat.d.ts +0 -2
  35. package/dist/src/chat.js +0 -92
  36. package/dist/src/check.d.ts +0 -11
  37. package/dist/src/check.js +0 -53
  38. package/dist/src/client.d.ts +0 -5
  39. package/dist/src/client.js +0 -157
  40. package/dist/src/compiler.d.ts +0 -36
  41. package/dist/src/compiler.js +0 -366
  42. package/dist/src/config.d.ts +0 -24
  43. package/dist/src/config.js +0 -70
  44. package/dist/src/connect.d.ts +0 -2
  45. package/dist/src/connect.js +0 -64
  46. package/dist/src/coordinate.d.ts +0 -3
  47. package/dist/src/coordinate.js +0 -58
  48. package/dist/src/create.d.ts +0 -2
  49. package/dist/src/create.js +0 -113
  50. package/dist/src/credits.d.ts +0 -29
  51. package/dist/src/credits.js +0 -88
  52. package/dist/src/deploy.d.ts +0 -2
  53. package/dist/src/deploy.js +0 -19
  54. package/dist/src/dev.d.ts +0 -2
  55. package/dist/src/dev.js +0 -75
  56. package/dist/src/device-flow.d.ts +0 -57
  57. package/dist/src/device-flow.js +0 -173
  58. package/dist/src/doctor.d.ts +0 -26
  59. package/dist/src/doctor.js +0 -146
  60. package/dist/src/draw.d.ts +0 -18
  61. package/dist/src/draw.js +0 -156
  62. package/dist/src/endpoint.d.ts +0 -2
  63. package/dist/src/endpoint.js +0 -250
  64. package/dist/src/env.d.ts +0 -3
  65. package/dist/src/env.js +0 -37
  66. package/dist/src/eval.d.ts +0 -2
  67. package/dist/src/eval.js +0 -43
  68. package/dist/src/fn.d.ts +0 -2
  69. package/dist/src/fn.js +0 -70
  70. package/dist/src/group.d.ts +0 -2
  71. package/dist/src/group.js +0 -117
  72. package/dist/src/hl-run.d.ts +0 -119
  73. package/dist/src/hl-run.js +0 -480
  74. package/dist/src/hl.d.ts +0 -17
  75. package/dist/src/hl.js +0 -148
  76. package/dist/src/index.d.ts +0 -2
  77. package/dist/src/init.d.ts +0 -76
  78. package/dist/src/init.js +0 -278
  79. package/dist/src/join.d.ts +0 -11
  80. package/dist/src/join.js +0 -297
  81. package/dist/src/key-publish.d.ts +0 -40
  82. package/dist/src/key-publish.js +0 -232
  83. package/dist/src/key-seal.d.ts +0 -21
  84. package/dist/src/key-seal.js +0 -142
  85. package/dist/src/key-sweep.d.ts +0 -93
  86. package/dist/src/key-sweep.js +0 -270
  87. package/dist/src/key.d.ts +0 -26
  88. package/dist/src/key.js +0 -338
  89. package/dist/src/lib/age-plugin.d.ts +0 -51
  90. package/dist/src/lib/age-plugin.js +0 -130
  91. package/dist/src/lib/agent-env.d.ts +0 -12
  92. package/dist/src/lib/agent-env.js +0 -48
  93. package/dist/src/lib/api-path.d.ts +0 -2
  94. package/dist/src/lib/api-path.js +0 -40
  95. package/dist/src/lib/asker.d.ts +0 -34
  96. package/dist/src/lib/asker.js +0 -126
  97. package/dist/src/lib/check-words.d.ts +0 -57
  98. package/dist/src/lib/check-words.js +0 -144
  99. package/dist/src/lib/client.d.ts +0 -20
  100. package/dist/src/lib/client.js +0 -71
  101. package/dist/src/lib/env-sealed.d.ts +0 -53
  102. package/dist/src/lib/env-sealed.js +0 -184
  103. package/dist/src/lib/flow-tag.d.ts +0 -86
  104. package/dist/src/lib/flow-tag.js +0 -230
  105. package/dist/src/lib/hl-core/actions.d.ts +0 -99
  106. package/dist/src/lib/hl-core/actions.js +0 -69
  107. package/dist/src/lib/hl-core/eip712.d.ts +0 -33
  108. package/dist/src/lib/hl-core/eip712.js +0 -107
  109. package/dist/src/lib/hl-core/errors.d.ts +0 -10
  110. package/dist/src/lib/hl-core/errors.js +0 -15
  111. package/dist/src/lib/hl-core/exchange.d.ts +0 -24
  112. package/dist/src/lib/hl-core/exchange.js +0 -47
  113. package/dist/src/lib/hl-core/index.d.ts +0 -13
  114. package/dist/src/lib/hl-core/index.js +0 -14
  115. package/dist/src/lib/hl-core/meta.d.ts +0 -57
  116. package/dist/src/lib/hl-core/meta.js +0 -110
  117. package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
  118. package/dist/src/lib/hl-core/msgpack.js +0 -136
  119. package/dist/src/lib/hl-core/net.d.ts +0 -2
  120. package/dist/src/lib/hl-core/net.js +0 -7
  121. package/dist/src/lib/hl-core/signing.d.ts +0 -103
  122. package/dist/src/lib/hl-core/signing.js +0 -295
  123. package/dist/src/lib/hl-core/wire.d.ts +0 -34
  124. package/dist/src/lib/hl-core/wire.js +0 -81
  125. package/dist/src/lib/invoked-as.d.ts +0 -2
  126. package/dist/src/lib/invoked-as.js +0 -24
  127. package/dist/src/lib/journey-words.d.ts +0 -84
  128. package/dist/src/lib/journey-words.js +0 -363
  129. package/dist/src/lib/journey.d.ts +0 -150
  130. package/dist/src/lib/journey.js +0 -264
  131. package/dist/src/lib/key-receipt.d.ts +0 -48
  132. package/dist/src/lib/key-receipt.js +0 -116
  133. package/dist/src/lib/key-source.d.ts +0 -9
  134. package/dist/src/lib/key-source.js +0 -33
  135. package/dist/src/lib/keyfile.d.ts +0 -136
  136. package/dist/src/lib/keyfile.js +0 -397
  137. package/dist/src/lib/launch-claude.d.ts +0 -5
  138. package/dist/src/lib/launch-claude.js +0 -45
  139. package/dist/src/lib/lock-lookup.d.ts +0 -40
  140. package/dist/src/lib/lock-lookup.js +0 -92
  141. package/dist/src/lib/message-seal.d.ts +0 -63
  142. package/dist/src/lib/message-seal.js +0 -150
  143. package/dist/src/lib/net-choice.d.ts +0 -28
  144. package/dist/src/lib/net-choice.js +0 -72
  145. package/dist/src/lib/network.d.ts +0 -22
  146. package/dist/src/lib/network.js +0 -50
  147. package/dist/src/lib/next-words.d.ts +0 -105
  148. package/dist/src/lib/next-words.js +0 -298
  149. package/dist/src/lib/paths.d.ts +0 -41
  150. package/dist/src/lib/paths.js +0 -91
  151. package/dist/src/lib/plan-draw.d.ts +0 -56
  152. package/dist/src/lib/plan-draw.js +0 -219
  153. package/dist/src/lib/plan-live.d.ts +0 -20
  154. package/dist/src/lib/plan-live.js +0 -192
  155. package/dist/src/lib/qr.d.ts +0 -21
  156. package/dist/src/lib/qr.js +0 -402
  157. package/dist/src/lib/roster.d.ts +0 -20
  158. package/dist/src/lib/roster.js +0 -79
  159. package/dist/src/lib/sale-card.d.ts +0 -117
  160. package/dist/src/lib/sale-card.js +0 -261
  161. package/dist/src/lib/shop-init.d.ts +0 -62
  162. package/dist/src/lib/shop-init.js +0 -63
  163. package/dist/src/lib/sui-grpc-send.d.ts +0 -90
  164. package/dist/src/lib/sui-grpc-send.js +0 -128
  165. package/dist/src/lib/swap-core.d.ts +0 -163
  166. package/dist/src/lib/swap-core.js +0 -405
  167. package/dist/src/lib/tasks-digest.d.ts +0 -66
  168. package/dist/src/lib/tasks-digest.js +0 -200
  169. package/dist/src/lib/tasks-graph.d.ts +0 -79
  170. package/dist/src/lib/tasks-graph.js +0 -463
  171. package/dist/src/lib/tasks-lens.d.ts +0 -31
  172. package/dist/src/lib/tasks-lens.js +0 -47
  173. package/dist/src/lib/tasks-next.d.ts +0 -25
  174. package/dist/src/lib/tasks-next.js +0 -103
  175. package/dist/src/lib/tasks-prove.d.ts +0 -15
  176. package/dist/src/lib/tasks-prove.js +0 -68
  177. package/dist/src/lib/tasks-route.d.ts +0 -29
  178. package/dist/src/lib/tasks-route.js +0 -151
  179. package/dist/src/lib/tasks-score.d.ts +0 -36
  180. package/dist/src/lib/tasks-score.js +0 -152
  181. package/dist/src/lib/tasks-workspace.d.ts +0 -18
  182. package/dist/src/lib/tasks-workspace.js +0 -73
  183. package/dist/src/lib/timed-fetch.d.ts +0 -33
  184. package/dist/src/lib/timed-fetch.js +0 -59
  185. package/dist/src/lib/vault-read.d.ts +0 -24
  186. package/dist/src/lib/vault-read.js +0 -77
  187. package/dist/src/lib/vaultfile.d.ts +0 -103
  188. package/dist/src/lib/vaultfile.js +0 -249
  189. package/dist/src/lib/wallet-money.d.ts +0 -222
  190. package/dist/src/lib/wallet-money.js +0 -578
  191. package/dist/src/lib/wallet-request.d.ts +0 -50
  192. package/dist/src/lib/wallet-request.js +0 -86
  193. package/dist/src/links.d.ts +0 -5
  194. package/dist/src/links.js +0 -45
  195. package/dist/src/media.d.ts +0 -29
  196. package/dist/src/media.js +0 -487
  197. package/dist/src/message-receipt.d.ts +0 -25
  198. package/dist/src/message-receipt.js +0 -71
  199. package/dist/src/message.d.ts +0 -13
  200. package/dist/src/message.js +0 -92
  201. package/dist/src/move.d.ts +0 -36
  202. package/dist/src/move.js +0 -152
  203. package/dist/src/network-cmd.d.ts +0 -17
  204. package/dist/src/network-cmd.js +0 -74
  205. package/dist/src/next.d.ts +0 -12
  206. package/dist/src/next.js +0 -67
  207. package/dist/src/onboard.d.ts +0 -16
  208. package/dist/src/onboard.js +0 -149
  209. package/dist/src/plugin.d.ts +0 -2
  210. package/dist/src/plugin.js +0 -193
  211. package/dist/src/push.d.ts +0 -2
  212. package/dist/src/push.js +0 -115
  213. package/dist/src/render.d.ts +0 -21
  214. package/dist/src/render.js +0 -32
  215. package/dist/src/secrets-device.d.ts +0 -32
  216. package/dist/src/secrets-device.js +0 -127
  217. package/dist/src/secrets-give.d.ts +0 -125
  218. package/dist/src/secrets-give.js +0 -236
  219. package/dist/src/secrets-list.d.ts +0 -27
  220. package/dist/src/secrets-list.js +0 -84
  221. package/dist/src/secrets-run.d.ts +0 -31
  222. package/dist/src/secrets-run.js +0 -182
  223. package/dist/src/secrets.d.ts +0 -33
  224. package/dist/src/secrets.js +0 -200
  225. package/dist/src/setup.d.ts +0 -6
  226. package/dist/src/setup.js +0 -127
  227. package/dist/src/ship.d.ts +0 -2
  228. package/dist/src/ship.js +0 -18
  229. package/dist/src/shop-buy.d.ts +0 -16
  230. package/dist/src/shop-buy.js +0 -101
  231. package/dist/src/shop.d.ts +0 -10
  232. package/dist/src/shop.js +0 -112
  233. package/dist/src/skill-parser.d.ts +0 -14
  234. package/dist/src/skill-parser.js +0 -113
  235. package/dist/src/skill.d.ts +0 -2
  236. package/dist/src/skill.js +0 -493
  237. package/dist/src/slug.d.ts +0 -2
  238. package/dist/src/slug.js +0 -6
  239. package/dist/src/social.d.ts +0 -2
  240. package/dist/src/social.js +0 -106
  241. package/dist/src/staff.d.ts +0 -2
  242. package/dist/src/staff.js +0 -104
  243. package/dist/src/start.d.ts +0 -27
  244. package/dist/src/start.js +0 -225
  245. package/dist/src/status.d.ts +0 -2
  246. package/dist/src/status.js +0 -52
  247. package/dist/src/substrate.d.ts +0 -2
  248. package/dist/src/substrate.js +0 -258
  249. package/dist/src/swap.d.ts +0 -93
  250. package/dist/src/swap.js +0 -622
  251. package/dist/src/tasks.d.ts +0 -2
  252. package/dist/src/tasks.js +0 -743
  253. package/dist/src/templates.d.ts +0 -1
  254. package/dist/src/templates.js +0 -213
  255. package/dist/src/thread.d.ts +0 -2
  256. package/dist/src/thread.js +0 -52
  257. package/dist/src/trade.d.ts +0 -2
  258. package/dist/src/trade.js +0 -91
  259. package/dist/src/trail.d.ts +0 -2
  260. package/dist/src/trail.js +0 -41
  261. package/dist/src/validate.d.ts +0 -13
  262. package/dist/src/validate.js +0 -35
  263. package/dist/src/wallet-money.d.ts +0 -158
  264. package/dist/src/wallet-money.js +0 -664
  265. package/dist/src/wallet.d.ts +0 -169
  266. package/dist/src/wallet.js +0 -973
  267. package/dist/src/workflow.d.ts +0 -2
  268. package/dist/src/workflow.js +0 -169
  269. package/dist/src/write.d.ts +0 -43
  270. package/dist/src/write.js +0 -180
@@ -1,664 +0,0 @@
1
- /**
2
- * wallet-money.ts — the loaded wallet's money, one command away:
3
- *
4
- * one wallet balances [--net mainnet|testnet] every chain, wallet:get first, chains for the rest
5
- * one wallet receive --chain base one address, one QR, never ambiguous
6
- * one wallet send 1 USDC@base 0x… DRY: exactly what would be signed, fees, the chain
7
- * one wallet send 0.0004 ETH@ethereum 0x… --live --dir ~/.one/tony
8
- * one wallet request 25 USD a wallet:invoice payment link
9
- * one wallet request 5 USDC --wait a link the owner opens and signs with Touch ID
10
- *
11
- * THE SERVER SIGNS NOTHING (R19). A --live send opens the sealed vault in --dir on THIS
12
- * machine (Touch ID or a typed passphrase), signs here, broadcasts to a public node, and
13
- * drops the key. Before the key opens: the gate (an agent shell signs only with its OWN
14
- * vault and --yes), and the client check (R16) — the transaction is rebuilt from the
15
- * person's own words and compared, never trusted from an echo.
16
- *
17
- * `balances` is the dev session's command (src/balances.ts, kept byte-identical so the two
18
- * merge cleanly); `upgradeBalances` adds --net and the wallet:get fan-out to it in place.
19
- */
20
- import { Command } from 'commander';
21
- import { createInterface } from 'node:readline';
22
- import { suiAddressFromPubkey } from '@oneie/sdk/wallet';
23
- import { readHyperliquid, isEvmAddress, isSuiAddress } from './balances.js';
24
- import { netLine, resolveNet } from './lib/net-choice.js';
25
- import { agentType } from './lib/agent-env.js';
26
- import { cliPrefix } from './lib/invoked-as.js';
27
- import { qrTerminal } from './lib/qr.js';
28
- import { spawnSync } from 'node:child_process';
29
- import { existsSync, readFileSync, readdirSync } from 'node:fs';
30
- import { homedir } from 'node:os';
31
- import { join } from 'node:path';
32
- import { amountOk, latestSuiDigest, linkFor, parseRequestAsset, sentenceFor, shortAddr } from './lib/wallet-request.js';
33
- import { suiSendGrpc, SuiSendError, mistToSui } from './lib/sui-grpc-send.js';
34
- import { readVaultFolder, vaultPath } from './lib/vaultfile.js';
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';
36
- /** fetch with a deadline: a node that hangs is a failed read, not a hung CLI. */
37
- export const deadlineFetch = (ms = 10_000) => async (url, init) => {
38
- const ctl = new AbortController();
39
- const t = setTimeout(() => ctl.abort(), ms);
40
- try {
41
- const r = await fetch(url, { ...init, signal: ctl.signal });
42
- return { ok: r.ok, json: () => r.json() };
43
- }
44
- finally {
45
- clearTimeout(t);
46
- }
47
- };
48
- /** A word safe to paste into a shell: plain words as they are, anything else single-quoted. */
49
- export const shq = (w) => (/^[A-Za-z0-9@._:\/=-]+$/.test(w) ? w : `'${w.replace(/'/g, `'\\''`)}'`);
50
- const isJson = (c) => Boolean(c.optsWithGlobals().json);
51
- function emit(c, data, lines) {
52
- if (data['ok'] === false)
53
- process.exitCode = 1;
54
- if (isJson(c)) {
55
- process.stdout.write(JSON.stringify(data) + '\n');
56
- return;
57
- }
58
- if (data['ok'] === false) {
59
- process.stderr.write(`✗ ${String(data['error'] ?? 'failed')}: ${String(data['message'] ?? '')}\n`);
60
- if (lines?.length)
61
- process.stderr.write(lines.join('\n') + '\n');
62
- return;
63
- }
64
- if (lines)
65
- console.log(lines.join('\n'));
66
- else
67
- console.log('✓', Object.entries(data).filter(([k]) => k !== 'ok').map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(' '));
68
- }
69
- async function confirm(prompt) {
70
- const rl = createInterface({ input: process.stdin, output: process.stderr });
71
- try {
72
- const a = await new Promise((r) => rl.question(prompt, r));
73
- return /^y(es)?$/i.test(a.trim());
74
- }
75
- finally {
76
- rl.close();
77
- }
78
- }
79
- /**
80
- * Is the vault in `dir` an AGENT's own? Its Sui address (from the public authPub, no unlock)
81
- * must be the attested caller's registered address on a wallet row tagged `agent`, and the
82
- * sending address must be on that same row. Read from the server by the caller's own key.
83
- */
84
- async function agentOwnVault(a, d) {
85
- const vaultSui = d.vaultSuiAddress(a.dir);
86
- if (!vaultSui)
87
- return { ok: false, error: 'no_vault', message: `No sealed wallet at ${vaultPath(a.dir)}.` };
88
- let me, w;
89
- try {
90
- me = await d.ask('wallet:challenge', {});
91
- // An agent's row sits in its owner's workspace (--workspace), not in the agent's own: ask
92
- // for this caller's own row there; wallet:get answers an agent key that one row and no other.
93
- w = await d.ask('wallet:get', { workspace: a.workspace ?? String(me['workspace'] ?? ''), actor: String(me['actor'] ?? '') });
94
- }
95
- catch (e) {
96
- return { ok: false, error: 'caller_unread', message: `Could not read who this key is (${e instanceof Error ? e.message : 'failed'}). Nothing was opened.` };
97
- }
98
- const rows = Array.isArray(w['wallets']) ? w['wallets'] : [];
99
- const row = rows.find((r) => r['actor'] === me['actor']);
100
- const tags = Array.isArray(row?.['tags']) ? row['tags'].map(String) : [];
101
- const same = (x, y) => typeof x === 'string' && x.toLowerCase() === y.toLowerCase();
102
- if (!row || !tags.includes('agent') || !same(row['sui_address'], vaultSui)) {
103
- return { ok: false, error: 'not_the_agents_vault', message: `The vault in ${a.dir} is not the agent's own (${String(me['actor'] ?? '?')}).` };
104
- }
105
- if (!same(row['evm_address'], a.plan.from) && !same(row['sui_address'], a.plan.from)) {
106
- return { ok: false, error: 'not_the_agents_money', message: `${a.plan.from} is not on this agent's wallet row. Nothing was opened.` };
107
- }
108
- return { ok: true };
109
- }
110
- /**
111
- * Before any key opens. `--yes` skips the prompt ONLY for a vault proven to be an agent's
112
- * own (agentOwnVault) — never on an env marker alone, which a shell can simply not set, and
113
- * never for a person's vault: the Keychain read behind "Touch ID" is `security -w`, which
114
- * the OS may answer silently. A person's vault is opened only after a y/N typed at a terminal,
115
- * every time. A shell an agent drives never opens anything but its own vault. A recipient
116
- * found by name must be pinned with --to-address whenever nobody reads it at a prompt.
117
- */
118
- export async function liveGate(a, d) {
119
- const p = a.plan;
120
- const resolved = p.toSource !== 'typed';
121
- if (resolved && a.toAddress !== undefined && a.toAddress.toLowerCase() !== p.to.toLowerCase()) {
122
- return { ok: false, error: 'recipient_mismatch', message: `--to-address ${a.toAddress} is not the resolved ${p.to}. Nothing was signed.` };
123
- }
124
- const agent = agentType(a.env);
125
- if (agent && !a.yes)
126
- return { ok: false, error: 'agent_needs_yes', message: `This shell is driven by ${agent}. An agent signs only with its own vault, and only with --yes. Nothing was opened.` };
127
- if (a.yes) {
128
- if (resolved && a.toAddress === undefined)
129
- return { ok: false, error: 'pin_recipient', message: `The recipient was resolved by ${p.toSource}: with --yes, pass --to-address ${p.to} to pin it. Nothing was opened.` };
130
- const own = await agentOwnVault(a, d);
131
- if (own.ok)
132
- return own;
133
- if (agent || !a.interactive) {
134
- return { ok: false, error: own.error, message: `${own.message} --yes signs only with an agent's own vault; a person's vault needs a y/N typed at a terminal. Nothing was opened.` };
135
- }
136
- // A person at a terminal who typed --yes: --yes does not cover a person's vault — ask.
137
- }
138
- if (!a.interactive)
139
- return { ok: false, error: 'confirm_needed', message: 'A person\'s vault opens only after a y/N typed at a terminal. Run it yourself, in a terminal. Nothing was opened.' };
140
- const ok = await d.confirm(`Sign and send ${p.amount} ${p.asset} on ${p.chainLabel} to ${p.to}${resolved ? ` (found by ${p.toSource})` : ''}? [y/N] `);
141
- return ok ? { ok: true } : { ok: false, error: 'cancelled', message: 'Nothing was signed.' };
142
- }
143
- const loadEvmDefault = async () => {
144
- try {
145
- return (await import('@oneie/sdk/evm-tx'));
146
- }
147
- catch {
148
- throw new Error('evm_signer_unavailable: this @oneie/sdk has no evm-tx — update oneie');
149
- }
150
- };
151
- export const suiSendDefault = (r) => suiSendGrpc(r);
152
- /**
153
- * Sign and broadcast ONE plan. The client check runs first, against the person's own
154
- * words; then the vault opens; then its key must derive `from`. One broadcast, never
155
- * re-sent: on a failure after signing the locally computed hash is returned so the
156
- * person can look before trying again.
157
- */
158
- export async function executeSend(plan, own, d) {
159
- const check = clientCheck(plan, own);
160
- if (!check.ok)
161
- return { ok: false, error: 'client_check_failed', field: check.field, message: `The transaction does not match what you typed (${check.field}). Nothing was signed.` };
162
- let evm;
163
- if (plan.tx) {
164
- try {
165
- evm = await (d.loadEvm ?? loadEvmDefault)();
166
- }
167
- catch (e) {
168
- return { ok: false, error: 'evm_signer_unavailable', message: e.message };
169
- }
170
- }
171
- const opened = await d.unlock();
172
- if ('error' in opened)
173
- return { ok: false, error: 'vault_locked', message: opened.error };
174
- const want = plan.chain === 'sui' ? 'sui' : 'evm';
175
- const key = opened.keys.find((k) => k.chain === want && k.address.toLowerCase() === plan.from.toLowerCase());
176
- if (!key)
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.` };
178
- if (plan.chain === 'sui') {
179
- try {
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 } : {}) });
181
- const { digest, gasMist, finalMs } = typeof done === 'string' ? { digest: done, gasMist: undefined, finalMs: undefined } : done;
182
- return {
183
- ok: true, sent: true, chain: 'sui', network: plan.network, digest, explorer: `${plan.explorer}/tx/${digest}`,
184
- ...(gasMist !== undefined ? { gasSui: mistToSui(gasMist) } : {}), ...(finalMs !== undefined ? { finalMs } : {}),
185
- next: recordLine(plan, digest, cliPrefix()),
186
- };
187
- }
188
- catch (e) {
189
- const code = e instanceof SuiSendError ? e.code : 'sui_send_failed';
190
- const dg = e instanceof SuiSendError ? e.digest : undefined;
191
- return { ok: false, error: code, ...(dg ? { digest: dg, explorer: `${plan.explorer}/tx/${dg}` } : {}), message: `${e.message}. Check ${dg ? `${plan.explorer}/tx/${dg}` : `${plan.explorer}/account/${plan.from}`} before trying again. Nothing was re-sent.` };
192
- }
193
- }
194
- const n = EVM[plan.chain][plan.network];
195
- const keyBytes = evm.hexToBytes(key.privateKeyHex.replace(/^0x/, ''));
196
- try {
197
- if (evm.evmAddressFromKey(keyBytes).toLowerCase() !== plan.from.toLowerCase())
198
- return { ok: false, error: 'vault_not_sender', message: 'The vault key does not derive the sending address. Nothing was signed.' };
199
- const cid = Number(BigInt(await evmRpc(d.fetch, n.rpc, 'eth_chainId', [])));
200
- if (cid !== plan.tx.chainId)
201
- return { ok: false, error: 'wrong_chain_rpc', message: `The node answered chain id ${cid}, not ${plan.tx.chainId}. Nothing was signed.` };
202
- const raw = evm.signEip1559(plan.tx, keyBytes);
203
- const hash = evm.evmTxHash(raw);
204
- const explorer = `${n.explorer}/tx/${hash}`;
205
- let answered;
206
- try {
207
- answered = await evmRpc(d.fetch, n.rpc, 'eth_sendRawTransaction', [raw]);
208
- }
209
- catch (e) {
210
- return { ok: false, error: 'broadcast_unconfirmed', hash, explorer, message: `The node did not accept it cleanly (${e.message}). It may still land — look at ${explorer} before trying again. Nothing was re-sent.` };
211
- }
212
- if (answered.toLowerCase() !== hash.toLowerCase())
213
- return { ok: false, error: 'hash_mismatch', hash, answered, explorer, message: 'The node reported a different hash than the one signed. Look at both before doing anything else.' };
214
- let status = 'pending';
215
- const sleep = d.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
216
- for (let i = 0; i < (d.polls ?? 24); i++) {
217
- await sleep(5000);
218
- try {
219
- const r = (await (await d.fetch(n.rpc, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'eth_getTransactionReceipt', params: [hash] }) })).json());
220
- if (r.result?.status) {
221
- status = r.result.status === '0x1' ? 'mined' : 'reverted';
222
- break;
223
- }
224
- }
225
- catch { /* a missed poll is not a result */ }
226
- }
227
- return { ok: status !== 'reverted', sent: true, status, chain: plan.chain, network: plan.network, hash, explorer, ...(status === 'reverted' ? { error: 'reverted', message: 'Mined, but the transaction reverted.' } : {}), next: recordLine(plan, hash, cliPrefix()) };
228
- }
229
- finally {
230
- keyBytes.fill(0);
231
- }
232
- }
233
- export const actingLine = (w) => (w ? `acting as: ${w.actor ?? 'unknown (the key could not be read)'} · key from ${w.from}` : undefined);
234
- /**
235
- * `no_from_address` from a folder-local key that is NOT the global login is the folder changing the
236
- * answer: name both, and the way out. Any other refusal keeps its own words.
237
- */
238
- export async function noFromCause(io, o, me, family, workspace) {
239
- if (!me?.local || !io.identity)
240
- return undefined;
241
- const global = await io.identity(o, 'machine').catch(() => null);
242
- if (!global || global.actor === me.actor)
243
- return undefined;
244
- return `this folder's key (${me.from}) acts as ${me.actor ?? 'an actor that could not be read'}, which has no ${family} address in workspace ${workspace}; the global login acts as ${global.actor ?? 'another actor'}. Run from another folder or pass --key.`;
245
- }
246
- function common(c, defaultApi) {
247
- return c
248
- .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
249
- .option('--actor <id>', 'Actor within the workspace (defaults to workspace)')
250
- .option('--api <url>', 'API base URL', defaultApi)
251
- .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)');
252
- }
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);
255
- /** The loaded wallet: wallet:get for the workspace (and actor), reduced to its addresses. */
256
- async function loaded(io, o, net, self) {
257
- const workspace = io.workspace(o.workspace);
258
- const who = o.actor ?? workspace;
259
- const walletGet = await io.ask(o, 'wallet:get', { workspace, ...(o.actor ? { actor: o.actor } : {}), ...(net ? { net } : {}) });
260
- // An agent key does not control its owner's workspace, only itself: read its own row there.
261
- if (walletGet['error'] === 'forbidden' && !o.actor && self) {
262
- const own = await io.ask(o, 'wallet:get', { workspace, actor: self, ...(net ? { net } : {}) });
263
- if (!own['error'])
264
- return { who: self, walletGet: own, addresses: addressesFor(own, self) };
265
- }
266
- return { who, walletGet, addresses: addressesFor(walletGet, who) };
267
- }
268
- /**
269
- * Give the dev session's `balances` (src/balances.ts) the network word and the server
270
- * fan-out. Its explicit-address form on mainnet is left to its own reader, unchanged.
271
- */
272
- export function upgradeBalances(balances, io) {
273
- // Guarded: commander throws on a duplicate flag at startup, which would take every `one` command down.
274
- if (!balances.options.some((x) => x.long === '--net'))
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');
278
- balances
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')
280
- .action(async function (address, o) {
281
- const f = io.fetch ?? deadlineFetch();
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);
288
- if (address) {
289
- const a = address.trim();
290
- if (!isEvmAddress(a) && !isSuiAddress(a))
291
- return emit(this, { ok: false, error: 'bad_address', message: 'Pass a 0x EVM address (40 hex) or a Sui address (64 hex).' });
292
- const addrs = isEvmAddress(a) ? { evm: a } : { sui: a };
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);
297
- return emit(this, { ...r }, moneyLines(r));
298
- }
299
- let l;
300
- try {
301
- l = await loaded(io, o, net);
302
- }
303
- catch (e) {
304
- return emit(this, { ok: false, error: 'wallet_read_failed', message: `${e.message} — or pass an address: one wallet balances 0x…` });
305
- }
306
- if (!Object.keys(l.addresses).length)
307
- return emit(this, { ok: false, error: 'no_address', message: `${l.who} has no wallet address registered. Pass one: one wallet balances 0x…` });
308
- const hl = net === 'mainnet' ? (a) => readHyperliquid(a, f) : undefined;
309
- const r = await moneyBalances({ walletGet: l.walletGet, actor: l.who, addresses: l.addresses, net }, f, hl);
310
- emit(this, { ...r }, moneyLines(r));
311
- });
312
- }
313
- export function receiveCmd(io) {
314
- return common(new Command('receive'), io.defaultApi)
315
- .description('Your address on ONE chain, with a QR to scan — the same 0x address is three chains, so --chain is required')
316
- .option('--chain <chain>', 'ethereum | base | arbitrum | sui | solana | bitcoin')
317
- .option('--net <network>', 'mainnet | testnet — sets the chain id in the QR (default: ONE_NETWORK, `one network`, the deploy)')
318
- .option('--no-qr', 'Print the address only')
319
- .action(async function (o) {
320
- const nc = await pickNet(o.net, o.api);
321
- if (!nc.ok)
322
- return emit(this, nc);
323
- const net = nc.net;
324
- let l;
325
- try {
326
- l = await loaded(io, o);
327
- }
328
- catch (e) {
329
- return emit(this, { ok: false, error: 'wallet_read_failed', message: e.message });
330
- }
331
- const r = receivePlan(o.chain, l.addresses, net);
332
- if (!r.ok)
333
- return emit(this, { ...r });
334
- const lines = [`${r.label} (${net}) — receives ${r.accepts}`, r.address, ...(o.qr ? ['', qrTerminal(r.uri), ` ${r.uri}`, ''] : []), r.warning];
335
- emit(this, { ...r, actor: l.who }, lines);
336
- });
337
- }
338
- /** The agent's own PUBLIC addresses: authPub gives Sui with no unlock; `addresses.json` beside the vault gives the rest. Never opens a key. */
339
- function publicAddresses(dir) {
340
- const out = {};
341
- const p = join(dir, 'addresses.json');
342
- try {
343
- if (existsSync(p)) {
344
- const j = JSON.parse(readFileSync(p, 'utf8'));
345
- if (typeof j.agent === 'string')
346
- out.agent = j.agent;
347
- if (typeof j.addresses?.['sui'] === 'string' && addressShape(j.addresses['sui']) === 'sui')
348
- out.sui = j.addresses['sui'];
349
- if (typeof j.addresses?.['evm'] === 'string' && addressShape(j.addresses['evm']) === 'evm')
350
- out.evm = j.addresses['evm'];
351
- }
352
- }
353
- catch { /* a sidecar that does not parse is no sidecar */ }
354
- const fromVault = vaultSuiAddressOf(dir);
355
- if (fromVault)
356
- out.sui = fromVault;
357
- return out;
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
- }
444
- /** `request <amount> <asset>[@chain]`: a link the OWNER opens, and a fingerprint only they can give. */
445
- async function requestMoney(c, io, amount, assetWord, o) {
446
- const a = parseRequestAsset(assetWord);
447
- if (!a.ok)
448
- return emit(c, { ...a });
449
- const units = amountOk(amount) ? parseAmount(amount, DECIMALS[a.asset]) : null;
450
- if (units === null)
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).` });
452
- const nc = await pickNet(o.net, o.api);
453
- if (!nc.ok)
454
- return emit(c, nc);
455
- const net = nc.net;
456
- let seconds = 0;
457
- if (o.wait !== undefined) {
458
- seconds = o.wait === true ? 300 : Number(o.wait);
459
- if (!Number.isInteger(seconds) || seconds < 1)
460
- return emit(c, { ok: false, error: 'bad_wait', message: '--wait takes whole seconds, e.g. --wait 120 (default 300).' });
461
- }
462
- const mine = publicAddresses(o.dir);
463
- let to = a.chain === 'sui' ? mine.sui : mine.evm;
464
- if (!to && a.chain !== 'sui') {
465
- try {
466
- to = (await loaded(io, o)).addresses.evm;
467
- }
468
- catch { /* the refusal below names where to look */ }
469
- }
470
- if (!to)
471
- return emit(c, { ok: false, error: 'no_address', message: `No ${a.chain === 'sui' ? 'Sui' : 'EVM'} address found for this wallet: ${a.chain === 'sui' ? `no sealed vault at ${vaultPath(o.dir)}` : `no addresses.json in ${o.dir} and none registered with the workspace`}. Pass --dir <the agent's folder>. Nothing was asked.` });
472
- const who = mine.agent ?? (await io.identity?.(o, 'resolved').catch(() => null))?.actor ?? 'this wallet';
473
- const sentence = sentenceFor(amount, a.asset, a.chain, to);
474
- const link = linkFor(sentence);
475
- const label = chainLabel(a.chain, 'mainnet');
476
- const base = { ok: true, who, amount, asset: a.asset, chain: a.chain, to, sentence, link };
477
- const block = [
478
- `${who} asks for ${amount} ${a.asset} on ${label}.`,
479
- `to ${shortAddr(to)}${a.defaulted ? ` (USDC defaults to Sui; say USDC@base for Base)` : ''}`,
480
- '',
481
- link,
482
- '',
483
- 'Open it and press Touch ID. Nothing moves until you do.',
484
- ];
485
- if (o.open) {
486
- if (process.platform === 'darwin')
487
- spawnSync('open', [link], { stdio: 'ignore' });
488
- else
489
- block.push('(--open works on macOS only — open the link yourself.)');
490
- }
491
- if (!seconds)
492
- return emit(c, base, block);
493
- // Waiting: the human block goes to stderr under --json, so stdout stays one object.
494
- if (isJson(c))
495
- process.stderr.write(block.join('\n') + '\n');
496
- else
497
- console.log(block.join('\n'));
498
- const f = io.fetch ?? deadlineFetch();
499
- const sleep = io.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
500
- const chain = a.chain;
501
- const before = await readAsset(f, a.asset, chain, net, to);
502
- if (before === null)
503
- return emit(c, { ...base, ok: false, error: 'balance_unreadable', message: `Could not read ${shortAddr(to)}'s ${a.asset} balance on ${chainLabel(chain, net)} to watch it. The link above still works; nothing was waited on.` });
504
- process.stderr.write(`Watching ${chainLabel(chain, net)} for up to ${seconds} s…\n`);
505
- const deadline = Date.now() + seconds * 1000;
506
- while (Date.now() < deadline) {
507
- await sleep(Math.min(5000, Math.max(0, deadline - Date.now())));
508
- const now = await readAsset(f, a.asset, chain, net, to);
509
- if (now !== null && now >= before + units) {
510
- const digest = chain === 'sui' ? await latestSuiDigest(f, net, to) : null;
511
- return emit(c, { ...base, received: { amount, asset: a.asset, ...(digest ? { digest } : {}) } }, [`Received ${amount} ${a.asset}.`, ...(digest ? [`digest ${digest}`] : [])]);
512
- }
513
- }
514
- emit(c, { ...base, ok: false, error: 'timeout', message: `Nothing arrived within ${seconds} s. The link still works.` }, ['', link]);
515
- process.exitCode = 75;
516
- }
517
- export function requestCmd(io) {
518
- return common(new Command('request').alias('ask'), io.defaultApi)
519
- .description('Ask to be paid. `request 5 USDC` (or SUI, ETH@base …) prints a link YOUR OWNER opens — it types the ask into ONE\'s chat and shows the send card they approve with Touch ID; --wait watches for the money. `request 25 USD` (or --invoice) mints a wallet:invoice payment link instead: the payer picks card or coin')
520
- .argument('<amount>', 'e.g. 5, 0.01 or 9.99')
521
- .argument('<asset>', 'USDC | SUI | ETH@base … (an owner link) · USD (an invoice link)')
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')
523
- .option('--invoice', 'USDC as a wallet:invoice payment link (cents) instead of an owner link')
524
- .option('--dir <path>', 'The agent\'s folder: its sealed vault\'s PUBLIC address is read — the key never opens', '.')
525
- .option('--net <network>', 'Which network --wait watches: mainnet | testnet (default: ONE_NETWORK, `one network`, the deploy). The link itself carries none')
526
- .option('--wait [seconds]', 'Poll the chain until the balance rises by the amount (default 300 s); exit 75 on timeout')
527
- .option('--open', 'Open the link in the default browser (macOS)')
528
- .action(async function (amount, asset, o) {
529
- const word = asset.trim().split('@')[0].toUpperCase();
530
- if (word !== 'USD' && !o.invoice)
531
- return requestMoney(this, io, amount, asset, o);
532
- const c = invoiceCents(amount, asset);
533
- if (!c.ok)
534
- return emit(this, { ...c });
535
- const workspace = io.workspace(o.workspace);
536
- const actor = o.actor ?? workspace;
537
- let r;
538
- try {
539
- r = await io.ask(o, 'wallet:invoice', { workspace, actor, amountCents: c.cents });
540
- }
541
- catch (e) {
542
- return emit(this, { ok: false, error: 'invoice_refused', message: e.message });
543
- }
544
- if (typeof r['url'] !== 'string')
545
- return emit(this, { ok: false, error: String(r['error'] ?? 'no_link'), message: 'wallet:invoice minted no link.', result: r });
546
- const data = {
547
- ok: true, url: r['url'], linkId: r['linkId'], custody: r['custody'], amountCents: c.cents, actor,
548
- network: typeof r['network'] === 'string' ? r['network'] : 'the deploy\'s (read it: https://pay.one.ie/status)',
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).` } : {}),
550
- };
551
- emit(this, data, [`Pay ${actor} $${(c.cents / 100).toFixed(2)}: ${String(r['url'])}`, `network ${data.network}`, ...(o.from ? [data.note] : [])]);
552
- });
553
- }
554
- export function sendCmd(io) {
555
- return common(new Command('send'), io.defaultApi)
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')
557
- .argument('<words...>', '<amount> <asset>[@chain] <to> (or <to> with --payment-tx)')
558
- .option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)')
559
- .option('--live', 'Sign and broadcast. Without it nothing is signed')
560
- .option('--yes', 'Skip the y/N prompt. Required in an agent shell, where only the agent\'s own vault may sign')
561
- .option('--dir <path>', 'The folder whose sealed vault (.one/wallet.json) signs', '.')
562
- .option('--to-address <addr>', 'Your own copy of a recipient found by name — must equal what was resolved')
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')
565
- .option('--chain <chain>', '(relay form) SUI | ETH | BASE | ARB | OPT | SOL | BTC')
566
- .option('--amount <n>', '(relay form) amount')
567
- .option('--payment-tx <hash>', '(relay form) the hash of a transfer you already signed and broadcast — records it, signs nothing')
568
- .option('--unit <unit>', '(relay form) usd | token', 'usd')
569
- .option('--currency <currency>', '(relay form) NATIVE | USDC', 'NATIVE')
570
- .option('--user-address <address>', '(relay form) sender address')
571
- .option('--memo <text>', '(relay form) payment memo')
572
- .action(async function (words, o) {
573
- if (o.paymentTx !== undefined) {
574
- if (words.length !== 1 || !o.chain || !o.amount)
575
- return emit(this, { ok: false, error: 'relay_form', message: 'Recording a signed transfer: send <to> --chain <c> --amount <n> --payment-tx <hash>' });
576
- return io.relay(this, words[0], o);
577
- }
578
- if (words.length !== 3)
579
- return emit(this, { ok: false, error: 'usage', message: 'send <amount> <asset>[@chain] <to> e.g. send 1 USDC@base 0x…' });
580
- const [amount, assetWord, to] = words;
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' });
588
- const f = io.fetch ?? deadlineFetch();
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.
590
- const me = await io.identity?.(o, 'resolved').catch(() => null);
591
- const header = actingLine(me);
592
- const who = me ? { actingAs: me.actor ?? null, keyFrom: me.from } : {};
593
- let l;
594
- try {
595
- l = await loaded(io, o, undefined, me?.actor ?? undefined);
596
- }
597
- catch (e) {
598
- return emit(this, { ok: false, error: 'wallet_read_failed', message: e.message, ...who }, header ? [header] : undefined);
599
- }
600
- const resolve = async (name, family) => {
601
- const pick = (a) => (family === 'evm' ? a.evm : a.sui);
602
- const mine = pick(addressesFor(l.walletGet, name));
603
- if (mine)
604
- return { address: mine, source: 'wallet:get' };
605
- try {
606
- const v = pick(addressesFor(await io.ask(o, 'wallet:get', { workspace: name }), name));
607
- if (v)
608
- return { address: v, source: 'wallet:get' };
609
- }
610
- catch { /* not a workspace this key reads */ }
611
- try {
612
- const r = await io.ask(o, 'identity:address', { uid: name });
613
- const v = String(r['address'] ?? '');
614
- if (addressShape(v) === family)
615
- return { address: v, source: 'identity:address' };
616
- }
617
- catch { /* no identity row */ }
618
- return null;
619
- };
620
- const planned = await planSend({ amount, asset: assetWord, to, net }, { fetch: f, from: l.addresses, resolve });
621
- if (!planned.ok) {
622
- const cause = planned.error === 'no_from_address' ? await noFromCause(io, o, me, /no sui address/.test(planned.message) ? 'sui' : 'evm', l.who) : undefined;
623
- return emit(this, { ...planned, ...(cause ? { message: cause } : {}), dry: true, ...who }, header ? [header] : undefined);
624
- }
625
- const plan = planned.plan;
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)`] : [])];
629
- if (!o.live) {
630
- const pin = plan.toSource !== 'typed' ? ` --to-address ${plan.to}` : '';
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}` : ''}`;
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}`]);
633
- }
634
- if (!isJson(this))
635
- console.error(lines.join('\n'));
636
- const gate = await liveGate({ env: process.env, yes: Boolean(o.yes), interactive: Boolean(process.stdin.isTTY), dir: o.dir, plan, toAddress: o.toAddress, workspace: o.workspace ? io.workspace(o.workspace) : undefined }, { ask: (r, d) => io.ask(o, r, d), vaultSuiAddress: vaultSuiAddressOf, confirm });
637
- if (!gate.ok)
638
- return emit(this, { ...gate, ...who });
639
- const parsed = parseAssetWord(assetWord);
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 } : {}) };
641
- const r = await executeSend(plan, own, { fetch: f, unlock: () => io.unlock(o.dir) });
642
- emit(this, r, r['ok'] ? sentLines(r) : undefined);
643
- });
644
- }
645
- /** What a landed send prints: where to look, what it cost, how long it took — Sui adds gas and the time to finality. */
646
- function sentLines(r) {
647
- const out = [`sent ${String(r['explorer'])}`];
648
- if (r['digest'] && r['chain'] === 'sui')
649
- out.push(`digest ${String(r['digest'])}`);
650
- if (r['gasSui'] !== undefined)
651
- out.push(`gas ${String(r['gasSui'])} SUI`);
652
- if (r['finalMs'] !== undefined)
653
- out.push(`final in ${String(r['finalMs'])} ms`);
654
- out.push(`status ${String(r['status'] ?? (r['chain'] === 'sui' ? 'final' : 'submitted'))}`, `record it in ONE: ${String(r['next'])}`);
655
- return out;
656
- }
657
- /** The vault's Sui address from its PUBLIC authPub — read without opening it. */
658
- export function vaultSuiAddressOf(dir) {
659
- const blob = readVaultFolder(dir);
660
- const hex = typeof blob?.authPub === 'string' ? blob.authPub.replace(/^0x/, '') : '';
661
- if (!/^[0-9a-fA-F]{64}$/.test(hex))
662
- return null;
663
- return suiAddressFromPubkey(Uint8Array.from((hex.match(/.{2}/g) ?? []).map((x) => parseInt(x, 16))));
664
- }