oneie 5.7.3 → 5.7.5

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/dist/src/start.js CHANGED
@@ -15,9 +15,11 @@ import { jsonMode } from './lib/client.js';
15
15
  import { KEY_DIR_NAME, KEY_FILE_NAME, LEGACY_KEY_DIR_NAME, META_FILE_NAME, readKeyFolder, writeKeyFolder } from './lib/keyfile.js';
16
16
  import { keychainAvailable, readVaultFolder, vaultPath } from './lib/vaultfile.js';
17
17
  import { cliPrefix } from './lib/invoked-as.js';
18
+ import { agentType } from './lib/agent-env.js';
18
19
  import { provisionLocalWallet } from './init.js';
19
20
  import { promptSecret, registerSealedWallet } from './wallet.js';
20
21
  import { parseProductSpec, runJourney, } from './lib/journey.js';
22
+ import { journeyIntro, journeyResume, journeyWords } from './lib/journey-words.js';
21
23
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
22
24
  /** The flags bare `npx oneie --email …` hands to `start` — the journey's own, nothing else. */
23
25
  export const START_FLAGS = new Set(['--name', '--email', '--product', '--currency', '--wait', '--api']);
@@ -66,14 +68,14 @@ async function walletStore(dir) {
66
68
  if (!process.stdin.isTTY) {
67
69
  return { error: 'no Apple Keychain here and no terminal to type a passphrase into — run `npx oneie wallet new` in your own terminal, then `npx oneie wallet register --kind agent`' };
68
70
  }
69
- const passphrase = await promptSecret('Passphrase to seal the agent wallet: ');
70
- if (passphrase !== (await promptSecret('Repeat it: ')))
71
- return { error: 'passphrases did not match — no wallet was made' };
71
+ const passphrase = await promptSecret('Choose a passphrase to lock your agent\'s wallet (8 characters or more): ');
72
+ if (passphrase !== (await promptSecret('Type it again: ')))
73
+ return { error: 'the two passphrases did not match, so no wallet was made. Run it again and type the same one twice' };
72
74
  if (passphrase.length < 8)
73
- return { error: 'passphrase too short — no wallet was made' };
75
+ return { error: 'that passphrase is shorter than 8 characters, so no wallet was made. Run it again with a longer one' };
74
76
  return { kind: 'vault', dir, passphrase };
75
77
  }
76
- function deps(dir, api) {
78
+ function deps(dir, api, say) {
77
79
  return {
78
80
  load: () => loadState(dir),
79
81
  save: (s) => saveState(dir, s),
@@ -99,6 +101,7 @@ function deps(dir, api) {
99
101
  return null;
100
102
  },
101
103
  provision: async (body) => {
104
+ say('Making your agent\'s key and its own group on one.ie…');
102
105
  const res = await fetch(`${api}/api/provision/agent`, {
103
106
  method: 'POST',
104
107
  headers: { 'Content-Type': 'application/json' },
@@ -113,6 +116,7 @@ function deps(dir, api) {
113
116
  // (Touch ID for a Keychain seal) and register THAT one — minting again would
114
117
  // be refused, and would leave the first wallet's addresses orphaned.
115
118
  if (existsSync(vaultPath(dir))) {
119
+ say('Opening the wallet made on an earlier run. Touch ID may ask you to confirm…');
116
120
  const r = await registerSealedWallet({ base: api, key, workspace, actor: workspace, dir });
117
121
  return r.ok
118
122
  ? { ok: true, file: vaultPath(dir), keychain: readVaultFolder(dir)?.wrap === 'keychain', addresses: (r.addresses ?? {}) }
@@ -121,6 +125,9 @@ function deps(dir, api) {
121
125
  const store = await walletStore(dir);
122
126
  if ('error' in store)
123
127
  return { ok: false, error: store.error };
128
+ say(store.kind === 'keychain'
129
+ ? 'Locking your agent\'s wallet in your Apple Keychain. Touch ID may ask you to confirm…'
130
+ : 'Locking your agent\'s wallet with your passphrase…');
124
131
  return provisionLocalWallet({ api, key, workspace, store });
125
132
  },
126
133
  ask: async (key, receiver, data) => {
@@ -139,32 +146,9 @@ function deps(dir, api) {
139
146
  now: () => Date.now(),
140
147
  };
141
148
  }
142
- const MARK = { done: '✓', pending: '…', waiting: '·', failed: '✗' };
143
- function render(r, cli) {
144
- const lines = ['ONE — key → products → test sale → handover', ''];
145
- for (const s of r.steps) {
146
- lines.push(`${MARK[s.status] ?? '?'} ${s.step.padEnd(9)} ${s.status}${s.reused ? ' (earlier run)' : ''}`);
147
- for (const [k, v] of Object.entries(s.detail)) {
148
- if (Array.isArray(v)) {
149
- lines.push(` ${k}:`);
150
- for (const item of v)
151
- lines.push(` ${String(item)}`);
152
- }
153
- else if (v && typeof v === 'object') {
154
- lines.push(` ${k}: ${Object.entries(v).map(([a, b]) => `${a} ${String(b)}`).join(', ')}`);
155
- }
156
- else if (v !== undefined) {
157
- lines.push(` ${k}: ${String(v)}`);
158
- }
159
- }
160
- }
161
- if (r.next)
162
- lines.push('', `next: ${r.next.replaceAll('npx oneie', cli)}`);
163
- return lines.join('\n') + '\n';
164
- }
165
149
  export function startCmd() {
166
150
  const cmd = new Command('start')
167
- .description('The whole journey in this folder — key → products → test sale → handover link. Bare `npx oneie` runs it; a re-run resumes')
151
+ .description('Walk the whole path in this folder: your key, a product, a test sale, then one link that hands it over. Bare `npx oneie` runs it; run it again to pick up where you left off')
168
152
  .option('--name <name>', 'Workspace / agent display name', 'My Shop')
169
153
  .option('--email <email>', "The new owner's email — the handover link is sent there as well as printed")
170
154
  .option('--product <name=price>', 'A product in major units, e.g. "Mug=12.50" (repeatable; default one Test product at 1.00)', (v, acc) => [...acc, v], [])
@@ -186,17 +170,24 @@ export function startCmd() {
186
170
  products.push(p.product);
187
171
  }
188
172
  const api = opts.api.replace(/\/$/, '');
189
- const report = await runJourney(deps(process.cwd(), api), {
173
+ const json = jsonMode(sub);
174
+ const cli = cliPrefix();
175
+ if (!json) {
176
+ const earlier = loadState(process.cwd());
177
+ process.stdout.write(earlier ? journeyResume(earlier.workspace) : journeyIntro(cli));
178
+ }
179
+ const say = json ? () => { } : (line) => process.stderr.write(` ${line}\n`);
180
+ const report = await runJourney(deps(process.cwd(), api, say), {
190
181
  api,
191
182
  name: opts.name,
192
183
  ...(opts.email ? { email: opts.email } : {}),
193
184
  products,
194
185
  ...(opts.wait !== undefined ? { waitSeconds: Math.max(0, Number(opts.wait) || 0) } : {}),
195
186
  });
196
- if (jsonMode(sub))
187
+ if (json)
197
188
  process.stdout.write(JSON.stringify(report) + '\n');
198
189
  else
199
- process.stdout.write(render(report, cliPrefix()));
190
+ process.stdout.write('\n' + journeyWords(report, cli, { agent: agentType() }));
200
191
  if (!report.ok)
201
192
  process.exitCode = 1;
202
193
  });
@@ -0,0 +1,93 @@
1
+ /**
2
+ * `one swap` and `one hl` — swap any coin to any coin, or send it into Hyperliquid
3
+ * (text/swap-plan.md § CLI (A)).
4
+ *
5
+ * one swap 0.01 BTC hl dry price (default — R11)
6
+ * one swap 10 USDC@base to hl --live a real deposit address, checked with 1Click
7
+ * one swap status <depositAddress> where is it; --watch polls until it lands
8
+ * one swap assets every alias, chain, decimals and signer
9
+ * one hl balance [0x…] a Hyperliquid account: perps and spot, never summed
10
+ *
11
+ * THIS COMMAND NEVER SIGNS AND HOLDS NO KEY. The server only quotes and reads status. On
12
+ * --live, nothing printed as a send instruction comes from the ONE server unchecked: the CLI
13
+ * reads the quote back from 1Click DIRECTLY (a plain fetch to a fixed host) and runs the client
14
+ * check (R16) against its OWN values — asset ids from its own table, the amount from its own
15
+ * parseUnits, its own slippage — then builds the send line and the wallet URI itself from
16
+ * 1Click's record. A mismatch prints `quote_mismatch` and no send line.
17
+ *
18
+ * Everything goes over ask() — no new @oneie/sdk import (R2). Every exit closes with
19
+ * out(cmd, data): one JSON line under --json, an `error <name>` + the reason otherwise, exit 1
20
+ * on ok:false; `status --watch` exits 2 when it stops at its poll cap.
21
+ */
22
+ import { Command } from 'commander';
23
+ import { type SwapRow } from './lib/swap-core.js';
24
+ type Obj = Record<string, unknown>;
25
+ /** `--watch` polls every 5 s and stops after 360 polls (30 min) — then exits 2, still not final. */
26
+ export declare const WATCH_INTERVAL_MS = 5000;
27
+ export declare const WATCH_MAX_POLLS = 360;
28
+ export interface SwapDeps {
29
+ /** One receiver through the ask door; returns the resolver's own answer, or a named HTTP refusal. */
30
+ ask(receiver: string, data: Obj, opts?: {
31
+ anonymous?: boolean;
32
+ }): Promise<Obj>;
33
+ /** GET 1Click's own status record, directly — never through ONE. */
34
+ oneClick(url: string): Promise<{
35
+ ok: true;
36
+ body: unknown;
37
+ } | {
38
+ ok: false;
39
+ error: string;
40
+ status?: number;
41
+ }>;
42
+ now(): Date;
43
+ sleep(ms: number): Promise<void>;
44
+ /** A person at a TTY, not --json, not an agent shell: only then is a [y/N] asked. */
45
+ interactive: boolean;
46
+ confirm(question: string): Promise<boolean>;
47
+ /** Human lines (suppressed under --json by the caller). */
48
+ say(lines: string[]): void;
49
+ }
50
+ export interface Result {
51
+ data: Obj;
52
+ exitCode?: number;
53
+ }
54
+ export interface SwapArgs {
55
+ words: string[];
56
+ live?: boolean;
57
+ sendTo?: string;
58
+ exactOut?: boolean;
59
+ slippage?: string;
60
+ mine?: string;
61
+ }
62
+ export declare function runSwap(args: SwapArgs, deps: SwapDeps): Promise<Result>;
63
+ /** The --mine entries shaped like an address on this chain (several = the person must pick). */
64
+ export declare function mineOn(mine: readonly string[], chain: SwapRow['chain']): string[];
65
+ export interface StatusArgs {
66
+ depositAddress: string;
67
+ tx?: string;
68
+ watch?: boolean;
69
+ mine?: string;
70
+ /** The slippage you asked for when the address was minted (default 100); the record must match. */
71
+ slippage?: string;
72
+ /** The amount you asked to swap, in the from asset. The record must match it, or no send line (R18). */
73
+ amount?: string;
74
+ maxPolls?: number;
75
+ }
76
+ export declare function runStatus(args: StatusArgs, deps: SwapDeps): Promise<Result>;
77
+ /** The server's whole table, read from an `unknown_asset` refusal (R2 — no assets receiver). */
78
+ export declare function runAssets(deps: SwapDeps): Promise<Result>;
79
+ export interface HlArgs {
80
+ address?: string;
81
+ testnet?: boolean;
82
+ actor?: string;
83
+ }
84
+ export declare function runHlBalance(args: HlArgs, deps: SwapDeps): Promise<Result>;
85
+ /** Close the loop: out() for --json and the error head, the reason lines on stderr, the exit code last. */
86
+ export declare function emit(cmd: Command, res: Result): void;
87
+ interface Common {
88
+ api?: string;
89
+ key?: string;
90
+ }
91
+ export declare function swapCmd(deps?: (cmd: Command, o: Common) => SwapDeps): Command;
92
+ export declare function hlCmd(deps?: (cmd: Command, o: Common) => SwapDeps): Command;
93
+ export {};