oneie 5.7.5 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +19 -0
  2. package/dist/package.json +5 -2
  3. package/dist/src/balances.d.ts +89 -0
  4. package/dist/src/balances.js +202 -0
  5. package/dist/src/ceiling.d.ts +36 -0
  6. package/dist/src/ceiling.js +189 -0
  7. package/dist/src/check.d.ts +11 -0
  8. package/dist/src/check.js +53 -0
  9. package/dist/src/credits.d.ts +29 -0
  10. package/dist/src/credits.js +88 -0
  11. package/dist/src/hl-run.d.ts +119 -0
  12. package/dist/src/hl-run.js +480 -0
  13. package/dist/src/hl.d.ts +17 -0
  14. package/dist/src/hl.js +148 -0
  15. package/dist/src/index.js +15 -1
  16. package/dist/src/join.js +4 -0
  17. package/dist/src/key-sweep.d.ts +19 -3
  18. package/dist/src/key-sweep.js +70 -20
  19. package/dist/src/lib/check-words.d.ts +57 -0
  20. package/dist/src/lib/check-words.js +144 -0
  21. package/dist/src/lib/hl-core/actions.d.ts +99 -0
  22. package/dist/src/lib/hl-core/actions.js +69 -0
  23. package/dist/src/lib/hl-core/eip712.d.ts +33 -0
  24. package/dist/src/lib/hl-core/eip712.js +107 -0
  25. package/dist/src/lib/hl-core/errors.d.ts +10 -0
  26. package/dist/src/lib/hl-core/errors.js +15 -0
  27. package/dist/src/lib/hl-core/exchange.d.ts +24 -0
  28. package/dist/src/lib/hl-core/exchange.js +47 -0
  29. package/dist/src/lib/hl-core/index.d.ts +13 -0
  30. package/dist/src/lib/hl-core/index.js +14 -0
  31. package/dist/src/lib/hl-core/meta.d.ts +57 -0
  32. package/dist/src/lib/hl-core/meta.js +110 -0
  33. package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
  34. package/dist/src/lib/hl-core/msgpack.js +136 -0
  35. package/dist/src/lib/hl-core/net.d.ts +2 -0
  36. package/dist/src/lib/hl-core/net.js +7 -0
  37. package/dist/src/lib/hl-core/signing.d.ts +103 -0
  38. package/dist/src/lib/hl-core/signing.js +295 -0
  39. package/dist/src/lib/hl-core/wire.d.ts +34 -0
  40. package/dist/src/lib/hl-core/wire.js +81 -0
  41. package/dist/src/lib/journey-words.d.ts +54 -3
  42. package/dist/src/lib/journey-words.js +162 -20
  43. package/dist/src/lib/journey.d.ts +2 -0
  44. package/dist/src/lib/journey.js +21 -2
  45. package/dist/src/lib/key-source.d.ts +9 -0
  46. package/dist/src/lib/key-source.js +33 -0
  47. package/dist/src/lib/net-choice.d.ts +28 -0
  48. package/dist/src/lib/net-choice.js +72 -0
  49. package/dist/src/lib/network.d.ts +22 -0
  50. package/dist/src/lib/network.js +50 -0
  51. package/dist/src/lib/next-words.d.ts +105 -0
  52. package/dist/src/lib/next-words.js +298 -0
  53. package/dist/src/lib/qr.d.ts +21 -0
  54. package/dist/src/lib/qr.js +402 -0
  55. package/dist/src/lib/sale-card.d.ts +117 -0
  56. package/dist/src/lib/sale-card.js +261 -0
  57. package/dist/src/lib/sui-grpc-send.d.ts +90 -0
  58. package/dist/src/lib/sui-grpc-send.js +128 -0
  59. package/dist/src/lib/timed-fetch.d.ts +33 -0
  60. package/dist/src/lib/timed-fetch.js +59 -0
  61. package/dist/src/lib/vaultfile.d.ts +15 -0
  62. package/dist/src/lib/vaultfile.js +28 -1
  63. package/dist/src/lib/wallet-money.d.ts +222 -0
  64. package/dist/src/lib/wallet-money.js +578 -0
  65. package/dist/src/lib/wallet-request.d.ts +50 -0
  66. package/dist/src/lib/wallet-request.js +86 -0
  67. package/dist/src/move.d.ts +36 -0
  68. package/dist/src/move.js +152 -0
  69. package/dist/src/network-cmd.d.ts +17 -0
  70. package/dist/src/network-cmd.js +74 -0
  71. package/dist/src/next.d.ts +12 -0
  72. package/dist/src/next.js +67 -0
  73. package/dist/src/onboard.js +4 -3
  74. package/dist/src/shop-buy.d.ts +16 -0
  75. package/dist/src/shop-buy.js +101 -0
  76. package/dist/src/shop.js +40 -1
  77. package/dist/src/staff.js +10 -0
  78. package/dist/src/start.d.ts +12 -0
  79. package/dist/src/start.js +51 -21
  80. package/dist/src/thread.d.ts +2 -0
  81. package/dist/src/thread.js +52 -0
  82. package/dist/src/wallet-money.d.ts +158 -0
  83. package/dist/src/wallet-money.js +664 -0
  84. package/dist/src/wallet.d.ts +2 -0
  85. package/dist/src/wallet.js +290 -27
  86. package/dist/src/workflow.js +4 -1
  87. package/package.json +5 -2
package/README.md CHANGED
@@ -178,6 +178,24 @@ echo "ship it" | one write brian # no --to: se
178
178
 
179
179
  Exit codes for `publish-lock`, `lock-of` and lookup refusals: 2 no key / no name / bad derivation · 3 not signed in · 4 no Sui address on file, or the wrong key · 5 bad signature, lock or name · 6 server or network (including a lookup that is not live) · 7 nothing published · 8 published but does not verify.
180
180
 
181
+ ## Testnet and mainnet
182
+
183
+ Every command that touches a chain acts on ONE network, chosen the same way everywhere:
184
+
185
+ 1. `--net mainnet|testnet` on the command (`--network` on `key sweep` / `sweep-run`)
186
+ 2. `ONE_NETWORK=mainnet|testnet` in the shell
187
+ 3. `one network mainnet|testnet`, saved in `~/.config/one/network` until you change it
188
+ 4. the deploy: whatever one.ie runs (`<meta name="one:network">`). After the mainnet flip, that is mainnet with no flag.
189
+
190
+ ```bash
191
+ one network # which network a command would use now, and why
192
+ one network testnet # practise: every command uses testnet until you say otherwise
193
+ one network mainnet # real money
194
+ one network auto # forget the choice and follow the deploy again
195
+ ```
196
+
197
+ If nothing names a network and the deploy cannot be read, a command that moves money refuses (`network_unknown`). It never guesses. Every money command prints the network it used, and a mainnet send says `MAINNET — real money`. `swap` is mainnet only (1Click has no testnet), `wallet faucet` is testnet only, and `hl` uses `--testnet` per call, because Hyperliquid is a separate venue.
198
+
181
199
  ## Wallets
182
200
 
183
201
  Every actor — human or agent — gets real, self-custodied multi-chain wallets. The CLI reads and writes the same `wallet:*` receivers `/w` uses:
@@ -185,6 +203,7 @@ Every actor — human or agent — gets real, self-custodied multi-chain wallets
185
203
  ```bash
186
204
  one wallet create --workspace <slug> --kind agent # provision a wallet row (idempotent)
187
205
  one wallet get --workspace <slug> # credits, ceiling, live balances, delegated wallets
206
+ one wallet get --workspace <slug> --net mainnet # the same on mainnet (see Testnet and mainnet)
188
207
  one wallet register --from keys.json --workspace <slug> # register the PUBLIC receiving addresses — first write wins, permanent
189
208
  one wallet transactions --workspace <slug> --limit 50 # unified feed across every settlement rail
190
209
  one wallet faucet <address> --chain sui # fund from testnet — sui/sol auto-fund, others return a manual URL
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneie",
3
- "version": "5.7.5",
3
+ "version": "5.8.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,10 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "commander": "^12.0.0",
23
- "@oneie/sdk": "^0.17.6"
23
+ "@oneie/sdk": "^0.17.6",
24
+ "@noble/curves": "^2.2.0",
25
+ "@noble/hashes": "^2.2.0",
26
+ "@mysten/sui": "^2.20.0"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@oneie/evals": "^0.2.0",
@@ -0,0 +1,89 @@
1
+ /**
2
+ * `one wallet balances [address]` — what is REALLY at the wallet you loaded, on mainnet.
3
+ *
4
+ * `wallet get` reads ONE's own ledger, which for most chains is test money: it printed
5
+ * 0.000000 for an address that held real ETH and USDC (measured 2026-11-09). This reads the
6
+ * chains themselves, through public read-only endpoints, with no key and nothing signed:
7
+ * EVM ETH, USDC, USDT on Ethereum, Base and Arbitrum
8
+ * Sui SUI on mainnet
9
+ * Hyperliquid perps and spot, never summed (HyperCore keeps them apart)
10
+ *
11
+ * A read that FAILS is `unavailable`, never 0: a short answer must say it is short.
12
+ */
13
+ import { Command } from 'commander';
14
+ export type Obj = Record<string, unknown>;
15
+ export type Fetch = (url: string, init?: {
16
+ method?: string;
17
+ headers?: Record<string, string>;
18
+ body?: string;
19
+ }) => Promise<{
20
+ ok: boolean;
21
+ json(): Promise<unknown>;
22
+ }>;
23
+ export declare const isEvmAddress: (s: string) => boolean;
24
+ export declare const isSuiAddress: (s: string) => boolean;
25
+ interface Token {
26
+ symbol: string;
27
+ contract: string;
28
+ decimals: number;
29
+ }
30
+ interface EvmChain {
31
+ name: string;
32
+ rpc: string;
33
+ tokens: Token[];
34
+ }
35
+ export declare const EVM_CHAINS: EvmChain[];
36
+ /** Sui's public JSON-RPC was switched off; GraphQL is the supported public read (measured 2026-11-09). */
37
+ export declare const SUI_GRAPHQL = "https://graphql.mainnet.sui.io/graphql";
38
+ export declare const HL_INFO = "https://api.hyperliquid.xyz/info";
39
+ export interface BalanceRow {
40
+ chain: string;
41
+ asset: string;
42
+ amount: string | null;
43
+ unavailable?: string;
44
+ }
45
+ /** Base units → a plain decimal, no float. */
46
+ export declare function formatUnits(raw: bigint, decimals: number): string;
47
+ export declare function readEvm(address: string, f: Fetch): Promise<BalanceRow[]>;
48
+ export declare function readSui(address: string, f: Fetch): Promise<BalanceRow[]>;
49
+ export interface HlRead {
50
+ perps: string | null;
51
+ withdrawable: string | null;
52
+ spot: {
53
+ coin: string;
54
+ total: string;
55
+ }[] | null;
56
+ unavailable?: string;
57
+ }
58
+ export declare function readHyperliquid(address: string, f: Fetch): Promise<HlRead>;
59
+ export interface BalancesResult {
60
+ ok: true;
61
+ network: 'mainnet';
62
+ rows: BalanceRow[];
63
+ hyperliquid?: HlRead;
64
+ /** Plain words for the person: every empty row is real, every `unavailable` row is not a zero. */
65
+ note: string;
66
+ }
67
+ export declare function readBalances(addresses: {
68
+ evm?: string;
69
+ sui?: string;
70
+ }, f: Fetch): Promise<BalancesResult>;
71
+ export declare function balanceLines(r: BalancesResult, addresses: {
72
+ evm?: string;
73
+ sui?: string;
74
+ }): string[];
75
+ export interface BalancesDeps {
76
+ fetch: Fetch;
77
+ /** The addresses of the loaded wallet — the workspace's own — when none is typed. */
78
+ addresses(opts: {
79
+ workspace?: string;
80
+ actor?: string;
81
+ api: string;
82
+ key?: string;
83
+ }): Promise<{
84
+ evm?: string;
85
+ sui?: string;
86
+ }>;
87
+ }
88
+ export declare function balancesCmd(deps: BalancesDeps, defaultApi: string): Command;
89
+ export {};
@@ -0,0 +1,202 @@
1
+ /**
2
+ * `one wallet balances [address]` — what is REALLY at the wallet you loaded, on mainnet.
3
+ *
4
+ * `wallet get` reads ONE's own ledger, which for most chains is test money: it printed
5
+ * 0.000000 for an address that held real ETH and USDC (measured 2026-11-09). This reads the
6
+ * chains themselves, through public read-only endpoints, with no key and nothing signed:
7
+ * EVM ETH, USDC, USDT on Ethereum, Base and Arbitrum
8
+ * Sui SUI on mainnet
9
+ * Hyperliquid perps and spot, never summed (HyperCore keeps them apart)
10
+ *
11
+ * A read that FAILS is `unavailable`, never 0: a short answer must say it is short.
12
+ */
13
+ import { Command } from 'commander';
14
+ const EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
15
+ const SUI_ADDRESS = /^0x[0-9a-fA-F]{64}$/;
16
+ export const isEvmAddress = (s) => EVM_ADDRESS.test(s);
17
+ export const isSuiAddress = (s) => SUI_ADDRESS.test(s);
18
+ export const EVM_CHAINS = [
19
+ {
20
+ name: 'ethereum', rpc: 'https://ethereum-rpc.publicnode.com',
21
+ tokens: [
22
+ { symbol: 'USDC', contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', decimals: 6 },
23
+ { symbol: 'USDT', contract: '0xdac17f958d2ee523a2206206994597c13d831ec7', decimals: 6 },
24
+ ],
25
+ },
26
+ { name: 'base', rpc: 'https://base-rpc.publicnode.com', tokens: [{ symbol: 'USDC', contract: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', decimals: 6 }] },
27
+ {
28
+ name: 'arbitrum', rpc: 'https://arbitrum-one-rpc.publicnode.com',
29
+ tokens: [
30
+ { symbol: 'USDC', contract: '0xaf88d065e77c8cc2239327c5edb3a432268e5831', decimals: 6 },
31
+ { symbol: 'USDT', contract: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', decimals: 6 },
32
+ ],
33
+ },
34
+ ];
35
+ /** Sui's public JSON-RPC was switched off; GraphQL is the supported public read (measured 2026-11-09). */
36
+ export const SUI_GRAPHQL = 'https://graphql.mainnet.sui.io/graphql';
37
+ export const HL_INFO = 'https://api.hyperliquid.xyz/info';
38
+ /** Base units → a plain decimal, no float. */
39
+ export function formatUnits(raw, decimals) {
40
+ const neg = raw < 0n;
41
+ const s = (neg ? -raw : raw).toString().padStart(decimals + 1, '0');
42
+ const whole = s.slice(0, s.length - decimals);
43
+ const frac = s.slice(s.length - decimals).replace(/0+$/, '');
44
+ return `${neg ? '-' : ''}${whole}${frac ? `.${frac}` : ''}`;
45
+ }
46
+ async function post(f, url, body) {
47
+ const res = await f(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
48
+ if (!res.ok)
49
+ throw new Error('http_error');
50
+ return res.json();
51
+ }
52
+ const row = (chain, asset, read, decimals) => read().then((raw) => ({ chain, asset, amount: formatUnits(raw, decimals) }), (e) => ({ chain, asset, amount: null, unavailable: e instanceof Error ? e.message : 'read_failed' }));
53
+ const rpcHex = async (f, url, method, params) => {
54
+ const r = (await post(f, url, { jsonrpc: '2.0', id: 1, method, params }));
55
+ if (typeof r.result !== 'string' || !/^0x[0-9a-fA-F]*$/.test(r.result))
56
+ throw new Error('bad_answer');
57
+ return r.result === '0x' ? 0n : BigInt(r.result);
58
+ };
59
+ export async function readEvm(address, f) {
60
+ const pad = address.slice(2).toLowerCase().padStart(64, '0');
61
+ const reads = [];
62
+ for (const c of EVM_CHAINS) {
63
+ reads.push(row(c.name, 'ETH', () => rpcHex(f, c.rpc, 'eth_getBalance', [address, 'latest']), 18));
64
+ for (const t of c.tokens) {
65
+ reads.push(row(c.name, t.symbol, () => rpcHex(f, c.rpc, 'eth_call', [{ to: t.contract, data: `0x70a08231${pad}` }, 'latest']), t.decimals));
66
+ }
67
+ }
68
+ return Promise.all(reads);
69
+ }
70
+ export async function readSui(address, f) {
71
+ return [
72
+ await row('sui', 'SUI', async () => {
73
+ const r = (await post(f, SUI_GRAPHQL, {
74
+ query: 'query($a: SuiAddress!) { address(address: $a) { balance(coinType: "0x2::sui::SUI") { totalBalance } } }',
75
+ variables: { a: address },
76
+ }));
77
+ const b = r.data?.address?.balance?.totalBalance;
78
+ // An address that never held SUI has a null balance object: that is a real zero only when the
79
+ // address itself answered.
80
+ if (r.data?.address && r.data.address.balance === null)
81
+ return 0n;
82
+ if (typeof b !== 'string' || !/^\d+$/.test(b))
83
+ throw new Error('bad_answer');
84
+ return BigInt(b);
85
+ }, 9),
86
+ ];
87
+ }
88
+ export async function readHyperliquid(address, f) {
89
+ try {
90
+ const [p, s] = await Promise.all([
91
+ post(f, HL_INFO, { type: 'clearinghouseState', user: address }),
92
+ post(f, HL_INFO, { type: 'spotClearinghouseState', user: address }),
93
+ ]);
94
+ return {
95
+ perps: p.marginSummary?.accountValue ?? null,
96
+ withdrawable: p.withdrawable ?? null,
97
+ spot: (s.balances ?? []).map((b) => ({ coin: b.coin, total: b.total })),
98
+ };
99
+ }
100
+ catch (e) {
101
+ return { perps: null, withdrawable: null, spot: null, unavailable: e instanceof Error ? e.message : 'read_failed' };
102
+ }
103
+ }
104
+ export async function readBalances(addresses, f) {
105
+ const [evm, sui, hl] = await Promise.all([
106
+ addresses.evm ? readEvm(addresses.evm, f) : Promise.resolve([]),
107
+ addresses.sui ? readSui(addresses.sui, f) : Promise.resolve([]),
108
+ addresses.evm ? readHyperliquid(addresses.evm, f) : Promise.resolve(undefined),
109
+ ]);
110
+ return {
111
+ ok: true,
112
+ network: 'mainnet',
113
+ rows: [...evm, ...sui],
114
+ ...(hl ? { hyperliquid: hl } : {}),
115
+ note: 'Mainnet, read from the chains themselves. `wallet get` shows ONE\'s own ledger, which is test money for most chains. A row that says unavailable was not read; it is not zero.',
116
+ };
117
+ }
118
+ export function balanceLines(r, addresses) {
119
+ const lines = [];
120
+ const pad = (s, n) => s.padEnd(n);
121
+ if (addresses.evm)
122
+ lines.push(`evm ${addresses.evm}`);
123
+ if (addresses.sui)
124
+ lines.push(`sui ${addresses.sui}`);
125
+ for (const x of r.rows) {
126
+ const v = x.amount === null ? `unavailable (${x.unavailable ?? 'read_failed'})` : x.amount;
127
+ if (x.amount === '0')
128
+ continue;
129
+ lines.push(`${pad(x.chain, 10)}${pad(x.asset, 6)}${v}`);
130
+ }
131
+ const nonzero = r.rows.filter((x) => x.amount !== '0').length;
132
+ if (nonzero === 0)
133
+ lines.push('(every chain read answered: nothing here)');
134
+ if (r.hyperliquid) {
135
+ const h = r.hyperliquid;
136
+ if (h.unavailable)
137
+ lines.push(`hyperliquid unavailable (${h.unavailable})`);
138
+ else {
139
+ lines.push(`hyperliquid perps ${h.perps ?? '0'} (withdrawable ${h.withdrawable ?? '0'})`);
140
+ lines.push(`hyperliquid spot ${h.spot && h.spot.length ? h.spot.map((b) => `${b.total} ${b.coin}`).join(', ') : 'none'}`);
141
+ lines.push('perps and spot are separate balances; they are not summed');
142
+ }
143
+ }
144
+ return lines;
145
+ }
146
+ export function balancesCmd(deps, defaultApi) {
147
+ return new Command('balances')
148
+ .description('What is really in your wallet on mainnet: ETH, USDC, USDT on Ethereum, Base and Arbitrum; SUI; Hyperliquid perps and spot. No key, nothing signed. No address = your workspace wallet')
149
+ .argument('[address]', 'a 0x EVM address (40 hex) or a Sui address (64 hex)')
150
+ .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
151
+ .option('--actor <id>', 'Actor within the workspace (defaults to workspace)')
152
+ .option('--api <url>', 'API base URL', defaultApi)
153
+ .option('--key <key>', 'API key (needed only without an address)')
154
+ .action(async function (address, opts) {
155
+ const json = Boolean(this.optsWithGlobals().json);
156
+ let addrs;
157
+ if (address) {
158
+ const a = address.trim();
159
+ if (isEvmAddress(a))
160
+ addrs = { evm: a };
161
+ else if (isSuiAddress(a))
162
+ addrs = { sui: a };
163
+ else {
164
+ const err = { ok: false, error: 'bad_address', next: 'Pass a 0x EVM address (40 hex characters) or a Sui address (64).' };
165
+ if (json)
166
+ process.stdout.write(JSON.stringify(err) + '\n');
167
+ else
168
+ console.error('✗', err.next);
169
+ process.exit(1);
170
+ return;
171
+ }
172
+ }
173
+ else {
174
+ try {
175
+ addrs = await deps.addresses(opts);
176
+ }
177
+ catch (e) {
178
+ const msg = e instanceof Error ? e.message : 'wallet_read_failed';
179
+ if (json)
180
+ process.stdout.write(JSON.stringify({ ok: false, error: 'wallet_read_failed', detail: msg, next: 'Pass an address: one wallet balances 0x…' }) + '\n');
181
+ else
182
+ console.error('✗', msg, '\n Pass an address: one wallet balances 0x…');
183
+ process.exit(1);
184
+ return;
185
+ }
186
+ if (!addrs.evm && !addrs.sui) {
187
+ const err = { ok: false, error: 'no_address', next: 'Your workspace has no wallet address registered. Pass one: one wallet balances 0x…' };
188
+ if (json)
189
+ process.stdout.write(JSON.stringify(err) + '\n');
190
+ else
191
+ console.error('✗', err.next);
192
+ process.exit(1);
193
+ return;
194
+ }
195
+ }
196
+ const r = await readBalances(addrs, deps.fetch);
197
+ if (json)
198
+ process.stdout.write(JSON.stringify({ ...r, addresses: addrs }) + '\n');
199
+ else
200
+ console.log(balanceLines(r, addrs).join('\n'));
201
+ });
202
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * ceiling.ts — `one wallet ceiling create | set | show | register`: an agent's on-chain spend
3
+ * ceiling (pay/contracts/spend-cap, `SpendCeiling`), driven from the terminal.
4
+ *
5
+ * create The OWNER's key signs `create_ceiling(agentId, perTx, total)`. The sender becomes
6
+ * the ceiling's owner, so the bound is the owner's from the first block and starts
7
+ * enabled. Signing opens the owner's vault (Touch ID for a Keychain vault).
8
+ * set The OWNER's key signs `update_ceiling` — raise, lower, pause. Over the limit means
9
+ * this: only the owner's biometric moves the bound. An agent cannot.
10
+ * show The chain's own reading of a ceiling: owner, agent, both bounds, spent, enabled.
11
+ * register Hands the ceiling to pay through the `agent:register-ceiling` receiver — the same
12
+ * door the SDK, the MCP `ask` tool and the page call. pay checks the object is a
13
+ * SpendCeiling for that agent, owned by the agent's claimed human.
14
+ *
15
+ * Amounts are dollars on the command line and cents on chain (the contract's unit).
16
+ * Dry by default: without --live, create and set print the call and sign nothing.
17
+ * The package id per network is pay's (pay/backend/src/config.ts `spendCapPackage`);
18
+ * tests/ceiling.test.ts fails if this copy drifts from it.
19
+ */
20
+ import { Command } from 'commander';
21
+ import { type Net } from './lib/wallet-money.js';
22
+ /** pay's spend-cap package per network — a copy, pinned to pay/backend/src/config.ts by test. */
23
+ export declare const SPEND_CAP_PACKAGE: Record<Net, string | undefined>;
24
+ /** "12.34" → 1234 cents; anything else → null. */
25
+ export declare function dollarsToCents(v: string): number | null;
26
+ export interface CeilingFields {
27
+ owner: string;
28
+ agentId: string;
29
+ perTxCents: number;
30
+ totalCents: number;
31
+ spentCents: number;
32
+ enabled: boolean;
33
+ }
34
+ /** The ceiling's Move fields as the gRPC json reading gives them, numbers made numbers. */
35
+ export declare function readCeilingFields(json: Record<string, unknown> | null | undefined): CeilingFields | null;
36
+ export declare function ceilingCmd(): Command;
@@ -0,0 +1,189 @@
1
+ /**
2
+ * ceiling.ts — `one wallet ceiling create | set | show | register`: an agent's on-chain spend
3
+ * ceiling (pay/contracts/spend-cap, `SpendCeiling`), driven from the terminal.
4
+ *
5
+ * create The OWNER's key signs `create_ceiling(agentId, perTx, total)`. The sender becomes
6
+ * the ceiling's owner, so the bound is the owner's from the first block and starts
7
+ * enabled. Signing opens the owner's vault (Touch ID for a Keychain vault).
8
+ * set The OWNER's key signs `update_ceiling` — raise, lower, pause. Over the limit means
9
+ * this: only the owner's biometric moves the bound. An agent cannot.
10
+ * show The chain's own reading of a ceiling: owner, agent, both bounds, spent, enabled.
11
+ * register Hands the ceiling to pay through the `agent:register-ceiling` receiver — the same
12
+ * door the SDK, the MCP `ask` tool and the page call. pay checks the object is a
13
+ * SpendCeiling for that agent, owned by the agent's claimed human.
14
+ *
15
+ * Amounts are dollars on the command line and cents on chain (the contract's unit).
16
+ * Dry by default: without --live, create and set print the call and sign nothing.
17
+ * The package id per network is pay's (pay/backend/src/config.ts `spendCapPackage`);
18
+ * tests/ceiling.test.ts fails if this copy drifts from it.
19
+ */
20
+ import { Command } from 'commander';
21
+ import { addressProofMessage, signAddressProof } from '@oneie/sdk/address-proof';
22
+ import { askPath } from './lib/api-path.js';
23
+ import { authHeaders, out, resolveBase } from './lib/client.js';
24
+ import { suiExecGrpc, suiReadObjects } from './lib/sui-grpc-send.js';
25
+ import { unlock } from './wallet.js';
26
+ import { netLine, resolveNet } from './lib/net-choice.js';
27
+ /** pay's spend-cap package per network — a copy, pinned to pay/backend/src/config.ts by test. */
28
+ export const SPEND_CAP_PACKAGE = {
29
+ testnet: '0xb9665d3555346615460b928ab97cad9d5d1ae84977299e0d92813bd6e7897529',
30
+ mainnet: '0xd2bd9146732b0fbe436aa111981f94b22b6c51485d04a566788e685535548930',
31
+ };
32
+ const OBJ = /^0x[0-9a-f]{64}$/i;
33
+ /** "12.34" → 1234 cents; anything else → null. */
34
+ export function dollarsToCents(v) {
35
+ if (!/^\d{1,9}(\.\d{1,2})?$/.test(v.trim()))
36
+ return null;
37
+ const [w, f = ''] = v.trim().split('.');
38
+ return Number(w) * 100 + Number(f.padEnd(2, '0'));
39
+ }
40
+ /** The ceiling's Move fields as the gRPC json reading gives them, numbers made numbers. */
41
+ export function readCeilingFields(json) {
42
+ if (!json)
43
+ return null;
44
+ const n = (k) => Number(json[k] ?? NaN);
45
+ const f = { owner: String(json.owner ?? ''), agentId: String(json.agent_id ?? ''), perTxCents: n('max_per_tx_usd_cents'), totalCents: n('max_total_usd_cents'), spentCents: n('total_spend_usd_cents'), enabled: json.enabled === true };
46
+ return Number.isFinite(f.perTxCents) && f.owner ? f : null;
47
+ }
48
+ function pkgFor(net, override) {
49
+ const p = override ?? SPEND_CAP_PACKAGE[net];
50
+ return p && OBJ.test(p) ? p : null;
51
+ }
52
+ async function ownerSign(sub, o, call, build) {
53
+ const t0 = Date.now();
54
+ const nc = await resolveNet(o.net);
55
+ if (!nc.ok)
56
+ return out(sub, nc);
57
+ const net = nc.net;
58
+ const pkg = pkgFor(net, o.package);
59
+ if (!pkg)
60
+ return out(sub, { ok: false, error: `not_deployed_on_${net}`, detail: 'no spend-cap package on this network — publish it with `one move publish pay/contracts/spend-cap`, or pass --package' });
61
+ const plan = { net, networkFrom: nc.from, says: netLine(nc), call: `${pkg}::spend_cap::${call.fn}`, ...call.describe };
62
+ if (!o.live)
63
+ return out(sub, { ok: true, dry: true, plan, next: 'add --live --dir <owner vault> to sign' });
64
+ if (!o.dir)
65
+ return out(sub, { ok: false, error: 'dir_required', detail: '--live signs with the OWNER vault in --dir' });
66
+ const opened = await unlock(o.dir);
67
+ if ('error' in opened)
68
+ return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
69
+ const key = opened.keys.find((k) => k.chain === 'sui');
70
+ if (!key)
71
+ return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
72
+ try {
73
+ const done = await suiExecGrpc({ net, rpc: o.rpc, from: key.address, privateKeyHex: key.privateKeyHex, build: (tx) => build(tx, pkg) });
74
+ const ceiling = done.created.find((c) => /::spend_cap::SpendCeiling$/.test(c.type))?.objectId ?? call.describe.ceiling;
75
+ const [read] = ceiling ? await suiReadObjects(net, [ceiling], { rpc: o.rpc, json: true }) : [];
76
+ const fields = readCeilingFields(read?.json);
77
+ const ok = Boolean(fields && fields.owner.toLowerCase() === key.address.toLowerCase());
78
+ return out(sub, { ok, ...(ok ? {} : { error: 'read_back_mismatch' }), net, digest: done.digest, signer: key.address, ceiling, readBack: fields, ms: done.finalMs, wallMs: Date.now() - t0 });
79
+ }
80
+ catch (e) {
81
+ const err = e;
82
+ return out(sub, { ok: false, error: err.code ?? 'ceiling_failed', detail: err.message, ...(err.digest ? { digest: err.digest } : {}) });
83
+ }
84
+ }
85
+ export function ceilingCmd() {
86
+ const cmd = new Command('ceiling').description("An agent's on-chain spend ceiling — the owner's key sets it, the owner's biometric raises it");
87
+ cmd.command('create <agentId>')
88
+ .description("OWNER signs create_ceiling: the agent may spend up to --per-tx dollars a payment and --total in all (0 = no total). Starts enabled, owned by the signer")
89
+ .requiredOption('--per-tx <usd>', 'Most one payment may be, in dollars')
90
+ .option('--total <usd>', 'Cumulative bound in dollars (0 = none)', '0')
91
+ .option('--dir <vault>', "The OWNER's sealed vault folder (Keychain / Touch ID)")
92
+ .option('--net <network>', 'testnet | mainnet (default: ONE_NETWORK, then `one network`, then the deploy)')
93
+ .option('--package <id>', 'spend-cap package id (default: pay\'s for --net)')
94
+ .option('--rpc <url>', 'gRPC base URL override')
95
+ .option('--live', 'Sign and send')
96
+ .action(async (agentId, o, sub) => {
97
+ const per = dollarsToCents(o.perTx), total = dollarsToCents(o.total);
98
+ if (!agentId.trim())
99
+ return out(sub, { ok: false, error: 'agent_id_required' });
100
+ if (!per)
101
+ return out(sub, { ok: false, error: 'per_tx_not_an_amount' });
102
+ if (total === null)
103
+ return out(sub, { ok: false, error: 'total_not_an_amount' });
104
+ return ownerSign(sub, o, { fn: 'create_ceiling', describe: { agentId, perTxCents: per, totalCents: total } }, (tx, pkg) => tx.moveCall({ target: `${pkg}::spend_cap::create_ceiling`, arguments: [tx.pure.string(agentId), tx.pure.u64(per), tx.pure.u64(total)] }));
105
+ });
106
+ cmd.command('set <ceilingId>')
107
+ .description('OWNER signs update_ceiling: new bounds, and --pause to disable. Raising a limit is this command, under the owner\'s Touch ID')
108
+ .requiredOption('--per-tx <usd>', 'Most one payment may be, in dollars')
109
+ .option('--total <usd>', 'Cumulative bound in dollars (0 = none)', '0')
110
+ .option('--pause', 'Disable the ceiling: every spend against it aborts')
111
+ .option('--dir <vault>', "The OWNER's sealed vault folder")
112
+ .option('--net <network>', 'testnet | mainnet (default: ONE_NETWORK, then `one network`, then the deploy)')
113
+ .option('--package <id>', 'spend-cap package id (default: pay\'s for --net)')
114
+ .option('--rpc <url>', 'gRPC base URL override')
115
+ .option('--live', 'Sign and send')
116
+ .action(async (ceilingId, o, sub) => {
117
+ const per = dollarsToCents(o.perTx), total = dollarsToCents(o.total);
118
+ if (!OBJ.test(ceilingId))
119
+ return out(sub, { ok: false, error: 'ceiling_id_not_an_object_id' });
120
+ if (!per)
121
+ return out(sub, { ok: false, error: 'per_tx_not_an_amount' });
122
+ if (total === null)
123
+ return out(sub, { ok: false, error: 'total_not_an_amount' });
124
+ const enabled = !o.pause;
125
+ return ownerSign(sub, o, { fn: 'update_ceiling', describe: { ceiling: ceilingId, perTxCents: per, totalCents: total, enabled } }, (tx, pkg) => tx.moveCall({ target: `${pkg}::spend_cap::update_ceiling`, arguments: [tx.object(ceilingId), tx.pure.u64(per), tx.pure.u64(total), tx.pure.bool(enabled)] }));
126
+ });
127
+ cmd.command('show <ceilingId>')
128
+ .description("The chain's reading of a ceiling: owner, agent, bounds, spent, enabled")
129
+ .option('--net <network>', 'testnet | mainnet (default: ONE_NETWORK, then `one network`, then the deploy)')
130
+ .option('--rpc <url>', 'gRPC base URL override')
131
+ .action(async (ceilingId, o, sub) => {
132
+ const nc = await resolveNet(o.net);
133
+ if (!nc.ok)
134
+ return out(sub, nc);
135
+ const net = nc.net;
136
+ if (!OBJ.test(ceilingId))
137
+ return out(sub, { ok: false, error: 'ceiling_id_not_an_object_id' });
138
+ try {
139
+ const [r] = await suiReadObjects(net, [ceilingId], { rpc: o.rpc, json: true });
140
+ const fields = readCeilingFields(r?.json);
141
+ if (!fields || !/::spend_cap::SpendCeiling$/.test(r.type))
142
+ return out(sub, { ok: false, error: 'not_a_spend_ceiling', type: r?.type ?? null });
143
+ return out(sub, { ok: true, net, ceiling: ceilingId, type: r.type, ...fields });
144
+ }
145
+ catch (e) {
146
+ return out(sub, { ok: false, error: e.code ?? 'read_failed', detail: e.message });
147
+ }
148
+ });
149
+ cmd.command('register <agentId> <ceilingId>')
150
+ .description("Hand the ceiling to pay (agent:register-ceiling) as the agent's claimed owner: with --dir, the owner's vault signs a fresh challenge (Touch ID once it is `wallet secure`d) — no browser needed")
151
+ .option('--dir <vault>', "The OWNER's sealed vault: signs a fresh wallet:challenge, the factor an agent cannot produce")
152
+ .option('--replace', 'Replace a ceiling already registered for this agent')
153
+ .option('--api <url>', 'API base URL')
154
+ .action(async (agentId, ceilingId, o, sub) => {
155
+ const t0 = Date.now();
156
+ if (!OBJ.test(ceilingId))
157
+ return out(sub, { ok: false, error: 'ceiling_id_not_an_object_id' });
158
+ const base = resolveBase({ api: o.api }, 'https://one.ie').replace(/\/$/, '');
159
+ const ask = async (receiver, data) => {
160
+ const res = await fetch(askPath(base, receiver), { method: 'POST', headers: authHeaders(), body: JSON.stringify({ data }) });
161
+ return (await res.json().catch(() => ({})));
162
+ };
163
+ let signed = {};
164
+ if (o.dir) {
165
+ const opened = await unlock(o.dir);
166
+ if ('error' in opened)
167
+ return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
168
+ const key = opened.keys.find((k) => k.chain === 'sui');
169
+ if (!key)
170
+ return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
171
+ const ch = await ask('wallet:challenge', {});
172
+ const c = ch.result ?? {};
173
+ if (c['ok'] !== true || typeof c['challenge'] !== 'string')
174
+ return out(sub, { ok: false, error: 'no_challenge', detail: ch.error ?? c['error'] });
175
+ const message = addressProofMessage({ challenge: c['challenge'], workspace: String(c['workspace']), actor: String(c['actor']), chain: 'sui', address: key.address });
176
+ signed = { challenge: c['challenge'], proof: signAddressProof('sui', key.privateKeyHex, message) };
177
+ }
178
+ try {
179
+ const body = await ask('agent:register-ceiling', { agentId, objectId: ceilingId, ...(o.replace ? { replace: true } : {}), ...signed });
180
+ if (body.outcome !== 'result')
181
+ return out(sub, { ok: false, error: String(body.error ?? body.outcome ?? 'no_answer') });
182
+ return out(sub, { ...(body.result ?? {}), ok: body.result?.ok === true, wallMs: Date.now() - t0 });
183
+ }
184
+ catch (e) {
185
+ return out(sub, { ok: false, error: 'unreachable', detail: e.message });
186
+ }
187
+ });
188
+ return cmd;
189
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `one check "<message>"`: before an agent acts on a message that asks it to pay or to
3
+ * hand something over. Refuse (a secret), ask your person (a payment, or red flags),
4
+ * or nothing to pay. The words are `lib/check-words.ts`.
5
+ *
6
+ * Exit 0 only for "nothing to pay"; ask is 2 and refuse is 3, so `one check … && pay`
7
+ * never goes through. Reads the message from its arguments or --file, never from
8
+ * stdin: a stdin no one writes to would hang an agent shell.
9
+ */
10
+ import { Command } from 'commander';
11
+ export declare function checkCmd(): Command;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `one check "<message>"`: before an agent acts on a message that asks it to pay or to
3
+ * hand something over. Refuse (a secret), ask your person (a payment, or red flags),
4
+ * or nothing to pay. The words are `lib/check-words.ts`.
5
+ *
6
+ * Exit 0 only for "nothing to pay"; ask is 2 and refuse is 3, so `one check … && pay`
7
+ * never goes through. Reads the message from its arguments or --file, never from
8
+ * stdin: a stdin no one writes to would hang an agent shell.
9
+ */
10
+ import { Command } from 'commander';
11
+ import { readFileSync } from 'node:fs';
12
+ import { jsonMode } from './lib/client.js';
13
+ import { cliPrefix } from './lib/invoked-as.js';
14
+ import { asciiOf } from './lib/journey-words.js';
15
+ import { check, checkWords, EXIT } from './lib/check-words.js';
16
+ import { readFacts } from './next.js';
17
+ export function checkCmd() {
18
+ return new Command('check')
19
+ .description('Before you act on a message that asks you to pay or to hand something over: refuse, ask your person, or nothing to pay. Never says pay. Exit 0 only for nothing to pay')
20
+ .argument('[message...]', 'The message, in quotes')
21
+ .option('--file <path>', 'Read the message from a file (an email, an invoice) instead')
22
+ .option('--dir <path>', 'The agent\'s folder: its own addresses are read from it', '.')
23
+ .action((words, opts, cmd) => {
24
+ let text = words.join(' ');
25
+ if (opts.file) {
26
+ try {
27
+ text = readFileSync(opts.file, 'utf8');
28
+ }
29
+ catch (e) {
30
+ text = '';
31
+ process.stderr.write(`cannot read ${opts.file}: ${e.message}\n`);
32
+ }
33
+ }
34
+ if (!text.trim()) {
35
+ const error = 'give the message: one check "<message>" or one check --file <path>';
36
+ if (jsonMode(cmd))
37
+ process.stdout.write(JSON.stringify({ ok: false, error }) + '\n');
38
+ else
39
+ process.stderr.write(`${error}\n`);
40
+ process.exitCode = 1;
41
+ return;
42
+ }
43
+ const own = Object.values(readFacts(opts.dir).state?.wallet?.addresses ?? {}).filter((a) => typeof a === 'string');
44
+ const c = check(text, cliPrefix(), own);
45
+ process.exitCode = EXIT[c.verdict];
46
+ if (jsonMode(cmd)) {
47
+ process.stdout.write(JSON.stringify({ ok: true, ...c }) + '\n');
48
+ return;
49
+ }
50
+ const words2 = checkWords(c);
51
+ process.stdout.write(!process.stdout.isTTY || 'NO_COLOR' in process.env ? asciiOf(words2) : words2);
52
+ });
53
+ }