@oneie/cli 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
@@ -0,0 +1,261 @@
1
+ /**
2
+ * The sale, drawn for a terminal — `one shop card`. The same four offers, two rails and six channels the
3
+ * home band, the chat and the film draw, as text no wider than 70 characters.
4
+ *
5
+ * SOURCE: one.ie/web/src/lib/sale/showcase.ts. The CLI is published on its own and cannot import the web
6
+ * package at runtime, so the words are copied here. tests/sale-card.test.ts reads that file as text and
7
+ * goes red when a name, price, cadence, rail or channel label drifts — change both together.
8
+ *
9
+ * Every line is a picture: nothing here mints, fetches or charges. A monthly subscription is card only.
10
+ * Card money goes to the seller's Stripe; USDC to the seller's own wallet. ONE holds neither.
11
+ */
12
+ import { asciiOf } from './journey-words.js';
13
+ // Copied from showcase.ts SALE_OFFERS (href dropped: a terminal never opens a route).
14
+ export const SALE_OFFERS = [
15
+ {
16
+ kind: 'product', kindLabel: 'Product', name: 'Sold, the book', detail: 'The playbook, every chapter',
17
+ price: '$20', cents: 2000, cadence: '', verb: 'Buy', stamp: 'Paid',
18
+ link: 'one.ie/books/sold', live: false, rails: ['card', 'crypto'],
19
+ },
20
+ {
21
+ kind: 'service', kindLabel: 'Service', name: 'Strategy call', detail: '30 minutes · Thursday 10:00',
22
+ price: '$100', cents: 10000, cadence: '', verb: 'Book', stamp: 'Booked',
23
+ link: 'one.ie/call', live: false, rails: ['card', 'crypto'],
24
+ },
25
+ {
26
+ kind: 'subscription', kindLabel: 'Subscription', name: 'The Sold community', detail: 'People and agents, selling together',
27
+ price: '$100', cents: 10000, cadence: '/month', verb: 'Join', stamp: 'Joined',
28
+ link: 'one.ie/sold', live: true, rails: ['card'],
29
+ },
30
+ {
31
+ kind: 'course', kindLabel: 'Course', name: 'Sold', detail: 'The course, with a month of the community',
32
+ price: '$100', cents: 10000, cadence: '', verb: 'Enrol', stamp: 'Enrolled',
33
+ link: 'one.ie/sold', live: true, rails: ['card', 'crypto'],
34
+ },
35
+ ];
36
+ export const SALE_RAILS = [
37
+ { id: 'card', label: 'Card', issuer: 'ONE', lands: "Paid into the seller's Stripe" },
38
+ { id: 'crypto', label: 'USDC', issuer: 'USDC · Sui', lands: "Paid to the seller's own wallet" },
39
+ ];
40
+ export const SALE_CHANNELS = [
41
+ { id: 'web', label: 'Web page', bar: 'yourshop.example', native: true },
42
+ { id: 'chat', label: 'Chat', bar: 'Chat', native: true },
43
+ { id: 'whatsapp', label: 'WhatsApp', bar: 'WhatsApp', native: false },
44
+ { id: 'instagram', label: 'Instagram', bar: 'Instagram', native: false },
45
+ { id: 'sms', label: 'SMS', bar: 'Messages', native: false },
46
+ { id: 'email', label: 'Email', bar: 'Inbox', native: false },
47
+ ];
48
+ export const SALE_COPY = {
49
+ opens: 'the link opens on the card',
50
+ cardOnly: 'Monthly is card only.',
51
+ example: 'Example sale. Nothing here is a real payment.',
52
+ exampleOffer: 'Example price.',
53
+ address: '0x5a1e…0e01',
54
+ settled: 'On Sui',
55
+ shop: 'Your shop',
56
+ from: 'hello@yourshop.example',
57
+ ask: 'How much is it?',
58
+ time: '10:02',
59
+ emailFrom: 'From',
60
+ emailSubject: 'Subject',
61
+ emailPay: 'Pay',
62
+ };
63
+ export const SALE_KIND_IDS = SALE_OFFERS.map((o) => o.kind);
64
+ export const SALE_RAIL_IDS = SALE_RAILS.map((r) => r.id);
65
+ export const SALE_CHANNEL_IDS = SALE_CHANNELS.map((c) => c.id);
66
+ export const saleOffer = (kind) => SALE_OFFERS.find((o) => o.kind === kind) ?? SALE_OFFERS[0];
67
+ export const saleRail = (id) => SALE_RAILS.find((r) => r.id === id) ?? SALE_RAILS[0];
68
+ export const saleChannel = (id) => SALE_CHANNELS.find((c) => c.id === id) ?? SALE_CHANNELS[0];
69
+ /** Asking a card-only offer for crypto gives card — the same rule the web face follows. */
70
+ export const saleRailFor = (offer, rail) => (offer.rails.includes(rail) ? rail : offer.rails[0]);
71
+ export const salePrice = (offer) => `${offer.price}${offer.cadence}`;
72
+ export const salePay = (offer) => `${offer.verb} · ${salePrice(offer)}`;
73
+ /** From cents, so a dollar price never rounds into a different coin amount. */
74
+ export function saleUsdc(offer) {
75
+ const whole = offer.cents % 100 === 0;
76
+ return `${whole ? offer.cents / 100 : (offer.cents / 100).toFixed(2)} USDC`;
77
+ }
78
+ export const salePayOn = (offer, rail) => saleRailFor(offer, rail) === 'crypto' ? `${offer.verb} · ${saleUsdc(offer)}` : salePay(offer);
79
+ export function saleMessage(channel, offer) {
80
+ const p = salePrice(offer);
81
+ switch (channel) {
82
+ case 'chat': return `${offer.name} is ${p}. Pay here.`;
83
+ case 'email': return `${offer.name}, ${p}. Pay with the button below.`;
84
+ case 'sms': return `${offer.name} is ${p}. Pay here:`;
85
+ case 'instagram': return `It's ${p}. Here's the link:`;
86
+ case 'whatsapp': return `${offer.name} is ${p}. Pay here:`;
87
+ default: return `${offer.name}, ${p}.`;
88
+ }
89
+ }
90
+ export const saleSubject = (offer) => `Your ${offer.kindLabel.toLowerCase()}: ${offer.name}`;
91
+ /** The `?via=` tag is how /sales counts which channel a sale came through. */
92
+ export const saleLink = (offer, channel) => channel === 'web' || channel === 'chat' ? offer.link : `${offer.link}?via=${channel}`;
93
+ /** A string from a flag, or null: the CLI refuses a word it does not know rather than drawing the default. */
94
+ export const saleKindOf = (v) => pick(v, SALE_KIND_IDS);
95
+ export const saleRailOf = (v) => pick(v, SALE_RAIL_IDS);
96
+ export const saleChannelOf = (v) => pick(v, SALE_CHANNEL_IDS);
97
+ function pick(v, ids) {
98
+ const s = typeof v === 'string' ? v.trim().toLowerCase() : '';
99
+ return ids.includes(s) ? s : null;
100
+ }
101
+ // ── drawing ──────────────────────────────────────────────────────────────────
102
+ /** The skill's limit (.claude/skills/ascii): every line fits a phone and a chat panel. */
103
+ export const SALE_MAX_WIDTH = 70;
104
+ const CARD_IN = 44; // card content; the card is 48 wide
105
+ const FRAME_IN = 62; // frame content; the frame is 66 wide
106
+ const INDENT = ' ';
107
+ const len = (s) => [...s].length;
108
+ function wrap(text, width) {
109
+ const lines = [];
110
+ let line = '';
111
+ for (const w of text.split(' ')) {
112
+ if (line && len(line) + 1 + len(w) > width) {
113
+ lines.push(line);
114
+ line = w;
115
+ }
116
+ else
117
+ line = line ? `${line} ${w}` : w;
118
+ }
119
+ if (line)
120
+ lines.push(line);
121
+ return lines;
122
+ }
123
+ /**
124
+ * Boxes are padded AFTER each cell is made ASCII, so "…" becoming "..." widens the cell, not the border.
125
+ */
126
+ function boxer(inner, ascii) {
127
+ const g = (s) => (ascii ? asciiOf(s) : s);
128
+ const [tl, tr, bl, br, h, v] = ascii ? ['+', '+', '+', '+', '-', '|'] : ['╭', '╮', '╰', '╯', '─', '│'];
129
+ const fit = (s) => {
130
+ const t = g(s);
131
+ return len(t) > inner ? [...t].slice(0, inner).join('') : t;
132
+ };
133
+ const row = (s = '') => { const t = fit(s); return `${v} ${t}${' '.repeat(inner - len(t))} ${v}`; };
134
+ return {
135
+ top: `${tl}${h.repeat(inner + 2)}${tr}`,
136
+ bottom: `${bl}${h.repeat(inner + 2)}${br}`,
137
+ row,
138
+ /** Left and right in one row, at least two spaces apart. */
139
+ split: (l, r) => {
140
+ const a = g(l), b = g(r);
141
+ return row(`${a}${' '.repeat(Math.max(2, inner - len(a) - len(b)))}${b}`);
142
+ },
143
+ right: (s) => { const t = fit(s); return `${v} ${' '.repeat(inner - len(t))}${t} ${v}`; },
144
+ center: (s) => {
145
+ const t = fit(s), pad = inner - len(t), left = Math.floor(pad / 2);
146
+ return `${v} ${' '.repeat(left)}${t}${' '.repeat(pad - left)} ${v}`;
147
+ },
148
+ };
149
+ }
150
+ /** One offer as a payment card, on the rail it can really take. */
151
+ export function saleCardLines(kind, opts = {}) {
152
+ const offer = saleOffer(kind);
153
+ const asked = opts.rail ?? 'card';
154
+ const rail = saleRailFor(offer, asked);
155
+ const copy = saleRail(rail);
156
+ const b = boxer(CARD_IN, Boolean(opts.ascii));
157
+ const crypto = rail === 'crypto';
158
+ const price = crypto ? saleUsdc(offer) : salePrice(offer);
159
+ const paid = opts.phase === 'paid';
160
+ const stamp = `✓ ${offer.stamp}${paid && crypto ? ` · ${SALE_COPY.settled}` : ''}`;
161
+ return [
162
+ b.top,
163
+ b.split(copy.issuer, offer.kindLabel),
164
+ b.row(),
165
+ b.row(offer.name),
166
+ ...wrap(offer.detail, CARD_IN).map((l) => b.row(l)),
167
+ b.row(),
168
+ offer.live ? b.row(price) : b.split(price, SALE_COPY.exampleOffer),
169
+ ...(crypto ? [b.row(SALE_COPY.address)] : []),
170
+ b.row(),
171
+ b.row(paid ? stamp : `[ ${salePayOn(offer, rail)} ]`),
172
+ b.row(),
173
+ // Asked for USDC on a monthly offer: say why the card face is drawn, not silently swap.
174
+ ...(rail !== asked ? [b.row(SALE_COPY.cardOnly)] : []),
175
+ b.row(`${copy.label} · ${copy.lands}`),
176
+ b.bottom,
177
+ ];
178
+ }
179
+ /** The card inside a channel's thread: who, the agent's words and link, then the card it opens on. */
180
+ export function saleFrameLines(kind, channel, opts = {}) {
181
+ const offer = saleOffer(kind);
182
+ const c = saleChannel(channel);
183
+ const b = boxer(FRAME_IN, Boolean(opts.ascii));
184
+ const msg = saleMessage(channel, offer);
185
+ const link = saleLink(offer, channel);
186
+ const said = (text) => wrap(text, FRAME_IN).map((l) => b.row(l));
187
+ const head = (() => {
188
+ switch (channel) {
189
+ case 'web': return [b.row(c.bar)];
190
+ case 'chat': return [b.row(c.bar)];
191
+ case 'sms': return [b.center(SALE_COPY.shop), b.center(c.bar)];
192
+ case 'email': return [b.split(c.bar, SALE_COPY.time)];
193
+ default: return [b.row(`${SALE_COPY.shop} · ${c.bar}`)];
194
+ }
195
+ })();
196
+ const body = (() => {
197
+ switch (channel) {
198
+ case 'web': return [];
199
+ case 'chat': return said(msg);
200
+ case 'whatsapp':
201
+ case 'instagram':
202
+ return [b.right(SALE_COPY.ask), b.row(), ...said(msg), b.row(link), b.row(SALE_COPY.time)];
203
+ case 'sms':
204
+ return [b.center(SALE_COPY.time), b.row(), ...said(msg), b.row(link)];
205
+ case 'email':
206
+ return [
207
+ b.row(`${SALE_COPY.emailFrom.padEnd(8)}${SALE_COPY.shop} ${SALE_COPY.from}`),
208
+ b.row(`${SALE_COPY.emailSubject.padEnd(8)}${saleSubject(offer)}`),
209
+ b.row(),
210
+ ...said(msg),
211
+ ...said(offer.detail),
212
+ b.row(),
213
+ b.row(`[ ${SALE_COPY.emailPay} ${salePrice(offer)} ] ${link}`),
214
+ ];
215
+ }
216
+ })();
217
+ return [
218
+ b.top,
219
+ ...head,
220
+ b.row(),
221
+ ...body,
222
+ ...(body.length ? [b.row()] : []),
223
+ ...(c.native ? [] : [b.row(`↓ ${SALE_COPY.opens}`), b.row()]),
224
+ ...saleCardLines(kind, opts).map((l) => b.row(INDENT + l)),
225
+ b.bottom,
226
+ ];
227
+ }
228
+ /** The whole drawing: one offer or several, framed or bare, with the example line once at the end. */
229
+ export function drawSale(kinds, opts = {}) {
230
+ const blocks = kinds.map((k) => (opts.channel ? saleFrameLines(k, opts.channel, opts) : saleCardLines(k, opts)).join('\n'));
231
+ return [...blocks, opts.ascii ? asciiOf(SALE_COPY.example) : SALE_COPY.example].join('\n\n') + '\n';
232
+ }
233
+ /** The same sale as data, for --json and for an agent: what would be drawn, never a payment. */
234
+ export function saleJson(kinds, opts = {}) {
235
+ const asked = opts.rail ?? 'card';
236
+ return {
237
+ ok: true,
238
+ example: true,
239
+ note: SALE_COPY.example,
240
+ offers: kinds.map((k) => {
241
+ const offer = saleOffer(k);
242
+ const rail = saleRailFor(offer, asked);
243
+ return {
244
+ kind: offer.kind,
245
+ name: offer.name,
246
+ price: salePrice(offer),
247
+ cents: offer.cents,
248
+ live: offer.live,
249
+ rail,
250
+ ...(rail !== asked ? { cardOnly: SALE_COPY.cardOnly } : {}),
251
+ pay: salePayOn(offer, rail),
252
+ // --paid must change the data too, or an agent reading --json sees a flag it passed do nothing.
253
+ ...(opts.phase === 'paid' ? { stamp: `${offer.stamp}${rail === 'crypto' ? ` · ${SALE_COPY.settled}` : ''}` } : {}),
254
+ lands: saleRail(rail).lands,
255
+ ...(opts.channel
256
+ ? { channel: opts.channel, message: saleMessage(opts.channel, offer), link: saleLink(offer, opts.channel) }
257
+ : { link: offer.link }),
258
+ };
259
+ }),
260
+ };
261
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * sui-grpc-send.ts — every Sui transaction the CLI signs, over gRPC (suiExecGrpc); a transfer is one build of it.
3
+ *
4
+ * Sui JSON-RPC is switched off on every public fullnode ("JSON-RPC on public fullnodes has
5
+ * been deprecated"), so the send goes over Mysten's gRPC fullnodes — the same endpoints and
6
+ * `client.core.executeTransaction` shape one.ie/web/src/lib/sui-transport.ts uses (copied, never
7
+ * imported: the CLI ships alone). `@mysten/sui` loads on demand so a command that never sends
8
+ * pays nothing for it.
9
+ *
10
+ * Never hangs, never re-sends: the digest is known BEFORE the node is asked (it is the hash of
11
+ * the bytes we signed), so a node that goes quiet is refused by name with that digest in hand.
12
+ */
13
+ import type { Net } from './wallet-money.js';
14
+ export declare const SUI_GRPC: Record<Net, string>;
15
+ export interface SuiSendReq {
16
+ asset: 'SUI' | 'USDC' | 'ETH';
17
+ coinType: string;
18
+ from: string;
19
+ to: string;
20
+ amountUnits: bigint;
21
+ privateKeyHex: string;
22
+ /** An optional gRPC base URL override; default is Mysten's public fullnode for `net`. */
23
+ rpc?: string;
24
+ net: Net;
25
+ /** Arrive as this many equal coins (the first carries the remainder). Absent or 1 = one coin. */
26
+ split?: number;
27
+ }
28
+ export interface SuiSendDone {
29
+ digest: string;
30
+ /** computation + storage − rebate, in MIST (never below 0). */
31
+ gasMist: bigint;
32
+ /** Wall-clock from signing to the node returning the certified effects, in ms. */
33
+ finalMs: number;
34
+ }
35
+ type Loader = (spec: string) => Promise<Record<string, unknown>>;
36
+ /** A variable specifier: no bundler or typechecker pulls @mysten/sui in; it loads from the person's own install. */
37
+ export declare const loadSpec: Loader;
38
+ /** A named failure that may carry the digest of a transaction that might still land. */
39
+ export declare class SuiSendError extends Error {
40
+ code: string;
41
+ digest?: string | undefined;
42
+ constructor(code: string, message: string, digest?: string | undefined);
43
+ }
44
+ export declare const gasMistOf: (g: {
45
+ computationCost?: string;
46
+ storageCost?: string;
47
+ storageRebate?: string;
48
+ } | undefined) => bigint;
49
+ /** Any Sui transaction this CLI signs: `build` adds the commands, the vault key signs here. */
50
+ export interface SuiExecReq {
51
+ net: Net;
52
+ from: string;
53
+ privateKeyHex: string;
54
+ /** An optional gRPC base URL override; default is Mysten's public fullnode for `net`. */
55
+ rpc?: string;
56
+ build: (tx: any, txm: any, sender: string) => void;
57
+ }
58
+ /** An object the transaction created, with its type and where it went. */
59
+ export interface SuiCreated {
60
+ objectId: string;
61
+ type: string;
62
+ /** The address that holds it, `shared`, `package`, or `other`. */
63
+ owner: string;
64
+ }
65
+ export interface SuiExecDone extends SuiSendDone {
66
+ created: SuiCreated[];
67
+ }
68
+ /**
69
+ * The one Sui signer. Build, sign, execute over gRPC, read back the effects. Every Sui act the
70
+ * CLI does — a send, a publish, a ceiling call — is this function with a different `build`.
71
+ */
72
+ export declare function suiExecGrpc(r: SuiExecReq, load?: Loader, deadlineMs?: number): Promise<SuiExecDone>;
73
+ /** One transfer of `amountUnits` of `coinType` — suiExecGrpc with a one-line build. */
74
+ export declare function suiSendGrpc(r: SuiSendReq, load?: Loader, deadlineMs?: number): Promise<SuiSendDone>;
75
+ /** What the chain says about some objects right now: type, holder and (when asked) the Move fields. */
76
+ export interface SuiObjectRead {
77
+ objectId: string;
78
+ type: string;
79
+ owner: string;
80
+ json?: Record<string, unknown> | null;
81
+ error?: string;
82
+ }
83
+ /** Read objects back over gRPC — a digest you did not read back is not proof. */
84
+ export declare function suiReadObjects(net: Net, objectIds: string[], opts?: {
85
+ rpc?: string;
86
+ json?: boolean;
87
+ }, load?: Loader): Promise<SuiObjectRead[]>;
88
+ /** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
89
+ export declare function mistToSui(mist: bigint): string;
90
+ export {};
@@ -0,0 +1,128 @@
1
+ export const SUI_GRPC = {
2
+ mainnet: 'https://fullnode.mainnet.sui.io:443',
3
+ testnet: 'https://fullnode.testnet.sui.io:443',
4
+ };
5
+ /** A variable specifier: no bundler or typechecker pulls @mysten/sui in; it loads from the person's own install. */
6
+ export const loadSpec = (spec) => import(spec);
7
+ /** A named failure that may carry the digest of a transaction that might still land. */
8
+ export class SuiSendError extends Error {
9
+ code;
10
+ digest;
11
+ constructor(code, message, digest) {
12
+ super(message);
13
+ this.code = code;
14
+ this.digest = digest;
15
+ }
16
+ }
17
+ const withDeadline = (p, ms, code, digest) => new Promise((resolve, reject) => {
18
+ const t = setTimeout(() => reject(new SuiSendError(code, `the node did not answer within ${Math.round(ms / 1000)} s`, digest)), ms);
19
+ p.then((v) => { clearTimeout(t); resolve(v); }, (e) => { clearTimeout(t); reject(e); });
20
+ });
21
+ export const gasMistOf = (g) => {
22
+ if (!g)
23
+ return 0n;
24
+ const n = BigInt(g.computationCost ?? 0) + BigInt(g.storageCost ?? 0) - BigInt(g.storageRebate ?? 0);
25
+ return n > 0n ? n : 0n;
26
+ };
27
+ const ownerOf = (o, state) => state === 'PackageWrite' ? 'package' : o?.$kind === 'AddressOwner' ? String(o.AddressOwner) : o?.$kind === 'Shared' ? 'shared' : 'other';
28
+ /**
29
+ * The one Sui signer. Build, sign, execute over gRPC, read back the effects. Every Sui act the
30
+ * CLI does — a send, a publish, a ceiling call — is this function with a different `build`.
31
+ */
32
+ export async function suiExecGrpc(r, load = loadSpec, deadlineMs = 30_000) {
33
+ let kp, grpc, txm; // eslint-disable-line @typescript-eslint/no-explicit-any
34
+ try {
35
+ ;
36
+ [kp, grpc, txm] = await Promise.all([load('@mysten/sui/keypairs/ed25519'), load('@mysten/sui/grpc'), load('@mysten/sui/transactions')]);
37
+ }
38
+ catch {
39
+ throw new SuiSendError('sui_signer_unavailable', 'install @mysten/sui beside oneie (npm i @mysten/sui)');
40
+ }
41
+ const hex = r.privateKeyHex.replace(/^0x/, '');
42
+ const keypair = kp.Ed25519Keypair.fromSecretKey(Uint8Array.from((hex.match(/.{2}/g) ?? []).map((x) => parseInt(x, 16))));
43
+ if (String(keypair.toSuiAddress()).toLowerCase() !== r.from.toLowerCase())
44
+ throw new SuiSendError('vault_key_mismatch', 'the vault key does not derive the sending address');
45
+ const baseUrl = (r.rpc ?? SUI_GRPC[r.net]).replace(/\/$/, '');
46
+ const client = new grpc.SuiGrpcClient({ network: r.net, baseUrl });
47
+ const tx = new txm.Transaction();
48
+ tx.setSender(keypair.toSuiAddress());
49
+ r.build(tx, txm, keypair.toSuiAddress());
50
+ let bytes;
51
+ try {
52
+ bytes = await withDeadline(tx.build({ client }), deadlineMs, 'sui_node_unreachable');
53
+ }
54
+ catch (e) {
55
+ if (e instanceof SuiSendError)
56
+ throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${e.message}. Nothing was signed.`);
57
+ const m = e.message ?? String(e);
58
+ if (/fetch failed|ECONN|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|unavailable|network/i.test(m))
59
+ throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${m}. Nothing was signed. Pass --rpc <a gRPC base URL> to use another node.`);
60
+ throw new SuiSendError('sui_build_failed', `${m}. Nothing was signed.`);
61
+ }
62
+ // The digest of the very bytes we are about to sign — derived from them, never asked of a node, so it cannot hang.
63
+ const digest = String(txm.TransactionDataBuilder.getDigestFromBytes(bytes));
64
+ const t0 = Date.now();
65
+ const { signature } = await keypair.signTransaction(bytes);
66
+ let res; // eslint-disable-line @typescript-eslint/no-explicit-any
67
+ try {
68
+ res = await withDeadline(client.core.executeTransaction({ transaction: bytes, signatures: [signature], include: { effects: true, objectTypes: true } }), deadlineMs, 'sui_unconfirmed', digest);
69
+ }
70
+ catch (e) {
71
+ if (e instanceof SuiSendError)
72
+ throw e;
73
+ // Did the network take it anyway? Ask by digest before telling anyone it failed.
74
+ throw new SuiSendError('sui_unconfirmed', `${e.message}. It may still have landed`, digest);
75
+ }
76
+ const finalMs = Date.now() - t0;
77
+ const done = res?.Transaction ?? res?.FailedTransaction;
78
+ if (!done)
79
+ throw new SuiSendError('sui_unconfirmed', 'the node answered without a transaction', digest);
80
+ if (done.status?.success !== true)
81
+ throw new SuiSendError('sui_transfer_failed', String(done.status?.error?.message ?? 'the transaction failed on chain'), String(done.digest ?? digest));
82
+ // Read-your-write for whoever looks next; not part of finalMs and never allowed to fail a landed send.
83
+ try {
84
+ await withDeadline(client.core.waitForTransaction({ digest: String(done.digest ?? digest) }), 10_000, 'wait_timeout');
85
+ }
86
+ catch { /* landed already */ }
87
+ const types = done.objectTypes ?? {};
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ const created = (done.effects?.changedObjects ?? [])
90
+ .filter((c) => c.idOperation === 'Created')
91
+ .map((c) => ({ objectId: String(c.objectId), type: String(types[c.objectId] ?? (c.outputState === 'PackageWrite' ? 'package' : '')), owner: ownerOf(c.outputOwner, c.outputState) }));
92
+ return { digest: String(done.digest ?? digest), gasMist: gasMistOf(done.effects?.gasUsed), finalMs, created };
93
+ }
94
+ /** One transfer of `amountUnits` of `coinType` — suiExecGrpc with a one-line build. */
95
+ export async function suiSendGrpc(r, load = loadSpec, deadlineMs = 30_000) {
96
+ const { digest, gasMist, finalMs } = await suiExecGrpc({
97
+ net: r.net, rpc: r.rpc, from: r.from, privateKeyHex: r.privateKeyHex,
98
+ build: (tx, txm) => {
99
+ const coin = txm.coinWithBalance({ type: r.coinType, balance: r.amountUnits });
100
+ const n = r.split && r.split > 1 ? r.split : 1;
101
+ if (n === 1)
102
+ return tx.transferObjects([coin], tx.pure.address(r.to));
103
+ const amounts = Array.from({ length: n - 1 }, () => r.amountUnits / BigInt(n));
104
+ const parts = tx.splitCoins(coin, amounts.map((a) => tx.pure.u64(a)));
105
+ tx.transferObjects([coin, ...amounts.map((_, i) => parts[i])], tx.pure.address(r.to));
106
+ },
107
+ }, load, deadlineMs);
108
+ return { digest, gasMist, finalMs };
109
+ }
110
+ /** Read objects back over gRPC — a digest you did not read back is not proof. */
111
+ export async function suiReadObjects(net, objectIds, opts = {}, load = loadSpec) {
112
+ const grpc = await load('@mysten/sui/grpc').catch(() => { throw new SuiSendError('sui_signer_unavailable', 'install @mysten/sui beside oneie (npm i @mysten/sui)'); });
113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ const client = new grpc.SuiGrpcClient({ network: net, baseUrl: (opts.rpc ?? SUI_GRPC[net]).replace(/\/$/, '') });
115
+ const res = await withDeadline(client.core.getObjects({ objectIds, include: opts.json ? { json: true } : {} }), 20_000, 'sui_node_unreachable');
116
+ return res.objects.map((o, i) => {
117
+ if (o instanceof Error)
118
+ return { objectId: objectIds[i], type: '', owner: '', error: o.message };
119
+ const ob = o;
120
+ return { objectId: ob.objectId, type: String(ob.type ?? ''), owner: ownerOf(ob.owner), ...(opts.json ? { json: ob.json ?? null } : {}) };
121
+ });
122
+ }
123
+ /** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
124
+ export function mistToSui(mist) {
125
+ const w = (mist / 1000000000n).toString();
126
+ const f = (mist % 1000000000n).toString().padStart(9, '0').replace(/0+$/, '');
127
+ return f ? `${w}.${f}` : w;
128
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A fetch that cannot wait forever.
3
+ *
4
+ * Bare `npx oneie` made every round trip with a plain `fetch` and no signal, so one
5
+ * connection that opened and never answered held the run until undici gave up (about
6
+ * five minutes), with nothing on screen after "Picking up where you left off".
7
+ * Reproduced 2026-11-12 against a server that accepts and never replies: killed at
8
+ * 75 s, still waiting. A re-run makes about ten calls while it waits for the test
9
+ * sale, so on a link that drops one connect in ten, the third run is the one that
10
+ * stops.
11
+ *
12
+ * Every call on the journey path goes through here, so a silent server becomes a
13
+ * named answer ("… did not answer in 15 s") instead of a hang.
14
+ */
15
+ /** One read or one receiver call. Measured answers are under 3.1 s, even with the Mac at load 150. */
16
+ export declare const ASK_TIMEOUT_MS = 15000;
17
+ /** `/api/provision/agent` registers, bootstraps, publishes and invites: 6.7–10.2 s measured. A write: never retried. */
18
+ export declare const PROVISION_TIMEOUT_MS = 60000;
19
+ export declare class NoAnswerError extends Error {
20
+ readonly what: string;
21
+ readonly ms: number;
22
+ constructor(what: string, ms: number);
23
+ }
24
+ /**
25
+ * `f(url, init)` bounded by `ms` — headers AND body. Returns the parsed JSON body
26
+ * (or `{}` when the body is not JSON) with the status, so the caller never holds a
27
+ * half-read stream past the deadline.
28
+ */
29
+ export declare function fetchJson(f: typeof fetch, url: string, init: RequestInit, ms: number, what: string): Promise<{
30
+ ok: boolean;
31
+ status: number;
32
+ json: Record<string, unknown>;
33
+ }>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A fetch that cannot wait forever.
3
+ *
4
+ * Bare `npx oneie` made every round trip with a plain `fetch` and no signal, so one
5
+ * connection that opened and never answered held the run until undici gave up (about
6
+ * five minutes), with nothing on screen after "Picking up where you left off".
7
+ * Reproduced 2026-11-12 against a server that accepts and never replies: killed at
8
+ * 75 s, still waiting. A re-run makes about ten calls while it waits for the test
9
+ * sale, so on a link that drops one connect in ten, the third run is the one that
10
+ * stops.
11
+ *
12
+ * Every call on the journey path goes through here, so a silent server becomes a
13
+ * named answer ("… did not answer in 15 s") instead of a hang.
14
+ */
15
+ /** One read or one receiver call. Measured answers are under 3.1 s, even with the Mac at load 150. */
16
+ export const ASK_TIMEOUT_MS = 15_000;
17
+ /** `/api/provision/agent` registers, bootstraps, publishes and invites: 6.7–10.2 s measured. A write: never retried. */
18
+ export const PROVISION_TIMEOUT_MS = 60_000;
19
+ export class NoAnswerError extends Error {
20
+ what;
21
+ ms;
22
+ constructor(what, ms) {
23
+ super(`${what} did not answer in ${Math.round(ms / 1000)} s`);
24
+ this.what = what;
25
+ this.ms = ms;
26
+ this.name = 'NoAnswerError';
27
+ }
28
+ }
29
+ const isAbort = (e) => {
30
+ const n = e?.name;
31
+ return n === 'TimeoutError' || n === 'AbortError';
32
+ };
33
+ /**
34
+ * `f(url, init)` bounded by `ms` — headers AND body. Returns the parsed JSON body
35
+ * (or `{}` when the body is not JSON) with the status, so the caller never holds a
36
+ * half-read stream past the deadline.
37
+ */
38
+ export async function fetchJson(f, url, init, ms, what) {
39
+ const signal = AbortSignal.timeout(ms);
40
+ try {
41
+ const res = await f(url, { ...init, signal });
42
+ const text = await res.text();
43
+ let json = {};
44
+ try {
45
+ const parsed = JSON.parse(text);
46
+ if (parsed && typeof parsed === 'object')
47
+ json = parsed;
48
+ }
49
+ catch {
50
+ /* not JSON: an empty body stands in */
51
+ }
52
+ return { ok: res.ok, status: res.status, json };
53
+ }
54
+ catch (e) {
55
+ if (isAbort(e) || signal.aborted)
56
+ throw new NoAnswerError(what, ms);
57
+ throw e;
58
+ }
59
+ }
@@ -40,6 +40,21 @@ export declare function readVaultFolder(dir: string): SealedVault | null;
40
40
  * secret cannot silently unlock another's.
41
41
  */
42
42
  export declare function keychainService(authPub: string): string;
43
+ /**
44
+ * The vault's passphrase sealed to a Secure Enclave key (`age-plugin-se`, access control
45
+ * `current-biometry`), and that key's identity file. Both sit BESIDE wallet.json, which is
46
+ * never rewritten: `wrap` is bound into the vault's AAD, so the vault keeps saying
47
+ * `keychain` and only the holder of its passphrase changes. When the sealed file exists,
48
+ * unlock opens it through the enclave and never reads Keychain.
49
+ *
50
+ * Why: a `security add-generic-password` item opened with no prompt for any process
51
+ * running as the user (measured 2026-11-12, task:01a1cd90d9ec7b99cb18fd33). An enclave key
52
+ * with a biometry rule cannot be used without the finger — the chip refuses, not a policy.
53
+ */
54
+ export declare function seSealPath(dir: string): string;
55
+ export declare function seIdentityPath(dir: string): string;
56
+ /** Delete the vault's Keychain copy. Absent already counts as deleted. */
57
+ export declare function keychainDelete(authPub: string): KeychainResult;
43
58
  export type KeychainResult = {
44
59
  ok: true;
45
60
  value?: string;
@@ -30,7 +30,7 @@
30
30
  * A second implementation of that is a second thing to get wrong.
31
31
  */
32
32
  import { existsSync, readFileSync, lstatSync } from 'node:fs';
33
- import { join } from 'node:path';
33
+ import { dirname, join } from 'node:path';
34
34
  import { spawnSync } from 'node:child_process';
35
35
  import { ensureIgnored, KEY_DIR_NAME, LEGACY_KEY_DIR_NAME, writeSecret, canonicalDir } from './keyfile.js';
36
36
  export const VAULT_FILE_NAME = 'wallet.json';
@@ -104,6 +104,33 @@ export function readVaultFolder(dir) {
104
104
  export function keychainService(authPub) {
105
105
  return `one.ie.wallet.${authPub}`;
106
106
  }
107
+ // ─── Secure Enclave wrap (2026-11-12) ───────────────────────────────────────
108
+ /**
109
+ * The vault's passphrase sealed to a Secure Enclave key (`age-plugin-se`, access control
110
+ * `current-biometry`), and that key's identity file. Both sit BESIDE wallet.json, which is
111
+ * never rewritten: `wrap` is bound into the vault's AAD, so the vault keeps saying
112
+ * `keychain` and only the holder of its passphrase changes. When the sealed file exists,
113
+ * unlock opens it through the enclave and never reads Keychain.
114
+ *
115
+ * Why: a `security add-generic-password` item opened with no prompt for any process
116
+ * running as the user (measured 2026-11-12, task:01a1cd90d9ec7b99cb18fd33). An enclave key
117
+ * with a biometry rule cannot be used without the finger — the chip refuses, not a policy.
118
+ */
119
+ export function seSealPath(dir) {
120
+ return join(dirname(vaultPath(dir)), 'passphrase.se.age');
121
+ }
122
+ export function seIdentityPath(dir) {
123
+ return join(dirname(vaultPath(dir)), 'se-identity.txt');
124
+ }
125
+ /** Delete the vault's Keychain copy. Absent already counts as deleted. */
126
+ export function keychainDelete(authPub) {
127
+ if (!keychainAvailable())
128
+ return { ok: false, error: 'Keychain is macOS-only' };
129
+ const r = spawnSync('security', ['delete-generic-password', '-a', process.env.USER ?? 'one', '-s', keychainService(authPub)], { stdio: ['ignore', 'ignore', 'pipe'] });
130
+ if (r.status === 0 || r.status === 44)
131
+ return { ok: true };
132
+ return { ok: false, error: 'security delete-generic-password failed' };
133
+ }
107
134
  /** macOS only — every other platform gets a clear refusal, never a silent no-op. */
108
135
  export function keychainAvailable() {
109
136
  return process.platform === 'darwin' && spawnSync('which', ['security']).status === 0;