@oneie/cli 5.7.5 → 5.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/package.json +5 -2
- package/dist/src/balances.d.ts +89 -0
- package/dist/src/balances.js +202 -0
- package/dist/src/hl-run.d.ts +119 -0
- package/dist/src/hl-run.js +480 -0
- package/dist/src/hl.d.ts +17 -0
- package/dist/src/hl.js +148 -0
- package/dist/src/index.js +2 -1
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +63 -20
- package/dist/src/lib/hl-core/actions.d.ts +99 -0
- package/dist/src/lib/hl-core/actions.js +69 -0
- package/dist/src/lib/hl-core/eip712.d.ts +33 -0
- package/dist/src/lib/hl-core/eip712.js +107 -0
- package/dist/src/lib/hl-core/errors.d.ts +10 -0
- package/dist/src/lib/hl-core/errors.js +15 -0
- package/dist/src/lib/hl-core/exchange.d.ts +24 -0
- package/dist/src/lib/hl-core/exchange.js +47 -0
- package/dist/src/lib/hl-core/index.d.ts +13 -0
- package/dist/src/lib/hl-core/index.js +14 -0
- package/dist/src/lib/hl-core/meta.d.ts +57 -0
- package/dist/src/lib/hl-core/meta.js +110 -0
- package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
- package/dist/src/lib/hl-core/msgpack.js +136 -0
- package/dist/src/lib/hl-core/net.d.ts +2 -0
- package/dist/src/lib/hl-core/net.js +7 -0
- package/dist/src/lib/hl-core/signing.d.ts +103 -0
- package/dist/src/lib/hl-core/signing.js +295 -0
- package/dist/src/lib/hl-core/wire.d.ts +34 -0
- package/dist/src/lib/hl-core/wire.js +81 -0
- package/dist/src/lib/journey-words.d.ts +54 -3
- package/dist/src/lib/journey-words.js +159 -20
- package/dist/src/lib/journey.js +1 -1
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/network.d.ts +15 -0
- package/dist/src/lib/network.js +41 -0
- package/dist/src/lib/qr.d.ts +21 -0
- package/dist/src/lib/qr.js +402 -0
- package/dist/src/lib/sale-card.d.ts +117 -0
- package/dist/src/lib/sale-card.js +261 -0
- package/dist/src/lib/sui-grpc-send.d.ts +50 -0
- package/dist/src/lib/sui-grpc-send.js +89 -0
- package/dist/src/lib/wallet-money.d.ts +222 -0
- package/dist/src/lib/wallet-money.js +578 -0
- package/dist/src/lib/wallet-request.d.ts +50 -0
- package/dist/src/lib/wallet-request.js +86 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop.js +38 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.js +14 -6
- package/dist/src/wallet-money.d.ts +152 -0
- package/dist/src/wallet-money.js +564 -0
- package/dist/src/wallet.js +169 -24
- 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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sui-grpc-send.ts — one Sui transfer (SUI or any coin type) over gRPC.
|
|
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
|
+
}
|
|
26
|
+
export interface SuiSendDone {
|
|
27
|
+
digest: string;
|
|
28
|
+
/** computation + storage − rebate, in MIST (never below 0). */
|
|
29
|
+
gasMist: bigint;
|
|
30
|
+
/** Wall-clock from signing to the node returning the certified effects, in ms. */
|
|
31
|
+
finalMs: number;
|
|
32
|
+
}
|
|
33
|
+
type Loader = (spec: string) => Promise<Record<string, unknown>>;
|
|
34
|
+
/** A variable specifier: no bundler or typechecker pulls @mysten/sui in; it loads from the person's own install. */
|
|
35
|
+
export declare const loadSpec: Loader;
|
|
36
|
+
/** A named failure that may carry the digest of a transaction that might still land. */
|
|
37
|
+
export declare class SuiSendError extends Error {
|
|
38
|
+
code: string;
|
|
39
|
+
digest?: string | undefined;
|
|
40
|
+
constructor(code: string, message: string, digest?: string | undefined);
|
|
41
|
+
}
|
|
42
|
+
export declare const gasMistOf: (g: {
|
|
43
|
+
computationCost?: string;
|
|
44
|
+
storageCost?: string;
|
|
45
|
+
storageRebate?: string;
|
|
46
|
+
} | undefined) => bigint;
|
|
47
|
+
export declare function suiSendGrpc(r: SuiSendReq, load?: Loader, deadlineMs?: number): Promise<SuiSendDone>;
|
|
48
|
+
/** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
|
|
49
|
+
export declare function mistToSui(mist: bigint): string;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
export async function suiSendGrpc(r, load = loadSpec, deadlineMs = 30_000) {
|
|
28
|
+
let kp, grpc, txm; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
29
|
+
try {
|
|
30
|
+
;
|
|
31
|
+
[kp, grpc, txm] = await Promise.all([load('@mysten/sui/keypairs/ed25519'), load('@mysten/sui/grpc'), load('@mysten/sui/transactions')]);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new SuiSendError('sui_signer_unavailable', 'install @mysten/sui beside oneie (npm i @mysten/sui)');
|
|
35
|
+
}
|
|
36
|
+
const hex = r.privateKeyHex.replace(/^0x/, '');
|
|
37
|
+
const keypair = kp.Ed25519Keypair.fromSecretKey(Uint8Array.from((hex.match(/.{2}/g) ?? []).map((x) => parseInt(x, 16))));
|
|
38
|
+
if (String(keypair.toSuiAddress()).toLowerCase() !== r.from.toLowerCase())
|
|
39
|
+
throw new SuiSendError('vault_key_mismatch', 'the vault key does not derive the sending address');
|
|
40
|
+
const baseUrl = (r.rpc ?? SUI_GRPC[r.net]).replace(/\/$/, '');
|
|
41
|
+
const client = new grpc.SuiGrpcClient({ network: r.net, baseUrl });
|
|
42
|
+
const tx = new txm.Transaction();
|
|
43
|
+
tx.setSender(keypair.toSuiAddress());
|
|
44
|
+
tx.transferObjects([txm.coinWithBalance({ type: r.coinType, balance: r.amountUnits })], tx.pure.address(r.to));
|
|
45
|
+
let bytes;
|
|
46
|
+
try {
|
|
47
|
+
bytes = await withDeadline(tx.build({ client }), deadlineMs, 'sui_node_unreachable');
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e instanceof SuiSendError)
|
|
51
|
+
throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${e.message}. Nothing was signed.`);
|
|
52
|
+
const m = e.message ?? String(e);
|
|
53
|
+
if (/fetch failed|ECONN|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|unavailable|network/i.test(m))
|
|
54
|
+
throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${m}. Nothing was signed. Pass --rpc <a gRPC base URL> to use another node.`);
|
|
55
|
+
throw new SuiSendError('sui_build_failed', `${m}. Nothing was signed.`);
|
|
56
|
+
}
|
|
57
|
+
// The digest of the very bytes we are about to sign — derived from them, never asked of a node, so it cannot hang.
|
|
58
|
+
const digest = String(txm.TransactionDataBuilder.getDigestFromBytes(bytes));
|
|
59
|
+
const t0 = Date.now();
|
|
60
|
+
const { signature } = await keypair.signTransaction(bytes);
|
|
61
|
+
let res; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
62
|
+
try {
|
|
63
|
+
res = await withDeadline(client.core.executeTransaction({ transaction: bytes, signatures: [signature], include: { effects: true } }), deadlineMs, 'sui_unconfirmed', digest);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e instanceof SuiSendError)
|
|
67
|
+
throw e;
|
|
68
|
+
// Did the network take it anyway? Ask by digest before telling anyone it failed.
|
|
69
|
+
throw new SuiSendError('sui_unconfirmed', `${e.message}. It may still have landed`, digest);
|
|
70
|
+
}
|
|
71
|
+
const finalMs = Date.now() - t0;
|
|
72
|
+
const done = res?.Transaction ?? res?.FailedTransaction;
|
|
73
|
+
if (!done)
|
|
74
|
+
throw new SuiSendError('sui_unconfirmed', 'the node answered without a transaction', digest);
|
|
75
|
+
if (done.status?.success !== true)
|
|
76
|
+
throw new SuiSendError('sui_transfer_failed', String(done.status?.error?.message ?? 'the transfer failed on chain'), String(done.digest ?? digest));
|
|
77
|
+
// Read-your-write for whoever looks next; not part of finalMs and never allowed to fail a landed send.
|
|
78
|
+
try {
|
|
79
|
+
await withDeadline(client.core.waitForTransaction({ digest: String(done.digest ?? digest) }), 10_000, 'wait_timeout');
|
|
80
|
+
}
|
|
81
|
+
catch { /* landed already */ }
|
|
82
|
+
return { digest: String(done.digest ?? digest), gasMist: gasMistOf(done.effects?.gasUsed), finalMs };
|
|
83
|
+
}
|
|
84
|
+
/** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
|
|
85
|
+
export function mistToSui(mist) {
|
|
86
|
+
const w = (mist / 1000000000n).toString();
|
|
87
|
+
const f = (mist % 1000000000n).toString().padStart(9, '0').replace(/0+$/, '');
|
|
88
|
+
return f ? `${w}.${f}` : w;
|
|
89
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wallet-money.ts — the pure half of `one wallet balances | receive | send | request`:
|
|
3
|
+
* the chain table, the words a person types, the reads, which chain a bare `USDC`
|
|
4
|
+
* means, the plan a send would sign, and the client check (R16) run before it does.
|
|
5
|
+
*
|
|
6
|
+
* Every chain read takes `Fetch` as an argument (tests hand in a fake; the command
|
|
7
|
+
* hands in a fetch with a deadline). A read that fails is null, never 0.
|
|
8
|
+
* Nothing here opens a vault or holds a key.
|
|
9
|
+
*/
|
|
10
|
+
import { type BalanceRow, type Fetch, type HlRead } from '../balances.js';
|
|
11
|
+
export type Net = 'mainnet' | 'testnet';
|
|
12
|
+
export type EvmChain = 'ethereum' | 'base' | 'arbitrum';
|
|
13
|
+
export type SendChain = EvmChain | 'sui';
|
|
14
|
+
export type SendAsset = 'ETH' | 'USDC' | 'SUI';
|
|
15
|
+
export type Obj = Record<string, unknown>;
|
|
16
|
+
export interface EvmNet {
|
|
17
|
+
chainId: number;
|
|
18
|
+
rpc: string;
|
|
19
|
+
usdc: string;
|
|
20
|
+
explorer: string;
|
|
21
|
+
label: string;
|
|
22
|
+
}
|
|
23
|
+
/** The three EVM chains on each network. Testnet USDC contracts read back `symbol() = USDC` (2026-11-09). */
|
|
24
|
+
export declare const EVM: Record<EvmChain, Record<Net, EvmNet>>;
|
|
25
|
+
export declare const EVM_CHAIN_NAMES: readonly EvmChain[];
|
|
26
|
+
/** Sui's public JSON-RPC answers "deprecated" on mainnet and testnet (measured 2026-11-09); GraphQL is the public read. */
|
|
27
|
+
export declare const SUI: Record<Net, {
|
|
28
|
+
graphql: string;
|
|
29
|
+
usdc: string;
|
|
30
|
+
explorer: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const SUI_NATIVE = "0x2::sui::SUI";
|
|
34
|
+
export declare const DECIMALS: Record<SendAsset, number>;
|
|
35
|
+
export declare function parseNet(v: unknown): Net | null;
|
|
36
|
+
/** "0.5" → base units; anything that is not a plain positive decimal within `decimals` places → null. */
|
|
37
|
+
export declare function parseAmount(input: string, decimals: number): bigint | null;
|
|
38
|
+
export type AssetWord = {
|
|
39
|
+
ok: true;
|
|
40
|
+
asset: SendAsset;
|
|
41
|
+
chain?: SendChain;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: string;
|
|
45
|
+
message: string;
|
|
46
|
+
};
|
|
47
|
+
/** `ETH` · `USDC@base` · `SUI` — the asset and, when named, the chain. */
|
|
48
|
+
export declare function parseAssetWord(word: string): AssetWord;
|
|
49
|
+
/** The chains a bare asset could mean, in a fixed order. */
|
|
50
|
+
export declare function candidateChains(asset: SendAsset): SendChain[];
|
|
51
|
+
export declare const familyOf: (chain: SendChain) => "evm" | "sui";
|
|
52
|
+
export declare const chainLabel: (chain: SendChain, net: Net) => string;
|
|
53
|
+
export declare function addressShape(addr: string): 'evm' | 'sui' | null;
|
|
54
|
+
export declare function evmRpc(f: Fetch, rpc: string, method: string, params: unknown[]): Promise<string>;
|
|
55
|
+
export declare function readEvmAsset(f: Fetch, chain: EvmChain, net: Net, asset: 'ETH' | 'USDC', address: string): Promise<bigint | null>;
|
|
56
|
+
/** A coin balance on Sui via GraphQL; an address that never held the coin answers a null balance — a real zero. */
|
|
57
|
+
export declare function readSuiCoin(f: Fetch, net: Net, address: string, coinType: string): Promise<bigint | null>;
|
|
58
|
+
export declare function readAsset(f: Fetch, asset: SendAsset, chain: SendChain, net: Net, address: string): Promise<bigint | null>;
|
|
59
|
+
/** SOL in lamports from a public Solana node (testnet = devnet, where ONE's test money lives). */
|
|
60
|
+
export declare const SOL_RPC: Record<Net, string>;
|
|
61
|
+
export declare function readSol(f: Fetch, net: Net, address: string): Promise<bigint | null>;
|
|
62
|
+
/** BTC in satoshis from mempool.space: confirmed + unconfirmed, funded minus spent. */
|
|
63
|
+
export declare const BTC_API: Record<Net, string>;
|
|
64
|
+
export declare function readBtc(f: Fetch, net: Net, address: string): Promise<bigint | null>;
|
|
65
|
+
export interface Addresses {
|
|
66
|
+
evm?: string;
|
|
67
|
+
sui?: string;
|
|
68
|
+
solana?: string;
|
|
69
|
+
btc?: string;
|
|
70
|
+
}
|
|
71
|
+
export type MoneyRow = BalanceRow & {
|
|
72
|
+
source: 'wallet:get' | 'chain';
|
|
73
|
+
};
|
|
74
|
+
export interface MoneyBalances {
|
|
75
|
+
ok: true;
|
|
76
|
+
network: Net;
|
|
77
|
+
addresses: Addresses;
|
|
78
|
+
rows: MoneyRow[];
|
|
79
|
+
hyperliquid?: HlRead;
|
|
80
|
+
note: string;
|
|
81
|
+
}
|
|
82
|
+
/** What a server-given address must look like before it is used, printed or pasted anywhere. */
|
|
83
|
+
export declare const ADDRESS_SHAPE: Record<'evm' | 'sui' | 'solana' | 'btc', RegExp>;
|
|
84
|
+
/** wallet:get's rows for one actor → the addresses it holds. A row whose address is not its chain's shape is dropped. */
|
|
85
|
+
export declare function addressesFor(walletGet: Obj, actor: string): Addresses;
|
|
86
|
+
/**
|
|
87
|
+
* Every balance of one actor on ONE network. A wallet:get row is used only when it says
|
|
88
|
+
* it was read on the network asked (a server that ignores `net` answers the deploy's —
|
|
89
|
+
* production's is testnet — and such a row is dropped, never shown under the wrong label).
|
|
90
|
+
* What wallet:get does not read — USDC everywhere, ETH on Base and Arbitrum, USDT on
|
|
91
|
+
* mainnet, and SOL/BTC when the server gave no row — is read from the chains here.
|
|
92
|
+
*/
|
|
93
|
+
export declare function moneyBalances(args: {
|
|
94
|
+
walletGet: Obj | null;
|
|
95
|
+
actor: string;
|
|
96
|
+
addresses: Addresses;
|
|
97
|
+
net: Net;
|
|
98
|
+
}, f: Fetch, hlRead?: (address: string) => Promise<HlRead>): Promise<MoneyBalances>;
|
|
99
|
+
export declare function moneyLines(r: MoneyBalances): string[];
|
|
100
|
+
export type ReceiveChain = EvmChain | 'sui' | 'solana' | 'bitcoin';
|
|
101
|
+
export type ReceivePlan = {
|
|
102
|
+
ok: true;
|
|
103
|
+
chain: ReceiveChain;
|
|
104
|
+
network: Net;
|
|
105
|
+
address: string;
|
|
106
|
+
uri: string;
|
|
107
|
+
label: string;
|
|
108
|
+
accepts: string;
|
|
109
|
+
warning: string;
|
|
110
|
+
} | {
|
|
111
|
+
ok: false;
|
|
112
|
+
error: string;
|
|
113
|
+
message: string;
|
|
114
|
+
options?: string[];
|
|
115
|
+
};
|
|
116
|
+
/** Which chains these addresses can receive on — the list a refusal names. */
|
|
117
|
+
export declare function receivableChains(a: Addresses): ReceiveChain[];
|
|
118
|
+
/** One chain, one address, one QR payload. No chain = refused: one 0x address is three chains. */
|
|
119
|
+
export declare function receivePlan(chainWord: string | undefined, a: Addresses, net: Net): ReceivePlan;
|
|
120
|
+
/** wallet:invoice takes cents: USD or USDC, at most 2 decimals. Anything else is refused by name. */
|
|
121
|
+
export declare function invoiceCents(amount: string, asset: string): {
|
|
122
|
+
ok: true;
|
|
123
|
+
cents: number;
|
|
124
|
+
} | {
|
|
125
|
+
ok: false;
|
|
126
|
+
error: string;
|
|
127
|
+
message: string;
|
|
128
|
+
};
|
|
129
|
+
export interface EvmTxFields {
|
|
130
|
+
chainId: number;
|
|
131
|
+
nonce: bigint;
|
|
132
|
+
maxPriorityFeePerGas: bigint;
|
|
133
|
+
maxFeePerGas: bigint;
|
|
134
|
+
gasLimit: bigint;
|
|
135
|
+
to: string;
|
|
136
|
+
value: bigint;
|
|
137
|
+
data: string;
|
|
138
|
+
}
|
|
139
|
+
export interface SendPlan {
|
|
140
|
+
network: Net;
|
|
141
|
+
chain: SendChain;
|
|
142
|
+
chainLabel: string;
|
|
143
|
+
asset: SendAsset;
|
|
144
|
+
amount: string;
|
|
145
|
+
amountUnits: bigint;
|
|
146
|
+
from: string;
|
|
147
|
+
to: string;
|
|
148
|
+
/** How `to` was found: typed (an address in argv), or resolved from a name. */
|
|
149
|
+
toSource: 'typed' | 'wallet:get' | 'identity:address';
|
|
150
|
+
/** Why this chain — named, or the only one holding it. */
|
|
151
|
+
choice: string;
|
|
152
|
+
balanceUnits: bigint;
|
|
153
|
+
/** EVM: the transaction exactly as it would be signed. */
|
|
154
|
+
tx?: EvmTxFields;
|
|
155
|
+
/** EVM: gasLimit × maxFeePerGas — the most the fee can be, in wei. */
|
|
156
|
+
feeMaxUnits?: bigint;
|
|
157
|
+
/** Sui: the coin type moved. */
|
|
158
|
+
coinType?: string;
|
|
159
|
+
explorer: string;
|
|
160
|
+
}
|
|
161
|
+
export interface PlanDeps {
|
|
162
|
+
fetch: Fetch;
|
|
163
|
+
/** The sender's registered addresses (wallet:get), read once. */
|
|
164
|
+
from: Addresses;
|
|
165
|
+
/** Resolves a name (slug or agent id) to an address of `family`; null = none. */
|
|
166
|
+
resolve: (name: string, family: 'evm' | 'sui') => Promise<{
|
|
167
|
+
address: string;
|
|
168
|
+
source: 'wallet:get' | 'identity:address';
|
|
169
|
+
} | null>;
|
|
170
|
+
}
|
|
171
|
+
export type PlanResult = {
|
|
172
|
+
ok: true;
|
|
173
|
+
plan: SendPlan;
|
|
174
|
+
} | {
|
|
175
|
+
ok: false;
|
|
176
|
+
error: string;
|
|
177
|
+
message: string;
|
|
178
|
+
options?: Obj[];
|
|
179
|
+
};
|
|
180
|
+
/** A bare asset → the one chain that holds it. Two → refused with the list; a failed read → refused (it might be a second). */
|
|
181
|
+
export declare function pickChain(asset: SendAsset, from: Addresses, net: Net, f: Fetch): Promise<{
|
|
182
|
+
ok: true;
|
|
183
|
+
chain: SendChain;
|
|
184
|
+
choice: string;
|
|
185
|
+
} | {
|
|
186
|
+
ok: false;
|
|
187
|
+
error: string;
|
|
188
|
+
message: string;
|
|
189
|
+
options: Obj[];
|
|
190
|
+
}>;
|
|
191
|
+
/** Everything a send would sign, read and checked — nothing signed, nothing sent. */
|
|
192
|
+
export declare function planSend(intent: {
|
|
193
|
+
amount: string;
|
|
194
|
+
asset: string;
|
|
195
|
+
to: string;
|
|
196
|
+
net: Net;
|
|
197
|
+
}, deps: PlanDeps): Promise<PlanResult>;
|
|
198
|
+
/** ERC-20 transfer(address,uint256) — the same bytes as @oneie/sdk/evm-tx encodeErc20Transfer, kept here so a dry run needs no SDK upgrade. */
|
|
199
|
+
export declare function erc20TransferData(to: string, amount: bigint): string;
|
|
200
|
+
/**
|
|
201
|
+
* R16 — before a key signs, rebuild what the transaction MUST be from the person's own inputs
|
|
202
|
+
* (argv, and the address they confirmed), never from a server answer or the plan's echo, and
|
|
203
|
+
* compare. Any difference refuses.
|
|
204
|
+
*/
|
|
205
|
+
export declare function clientCheck(plan: SendPlan, own: {
|
|
206
|
+
amount: string;
|
|
207
|
+
asset: SendAsset;
|
|
208
|
+
chain: SendChain;
|
|
209
|
+
to: string;
|
|
210
|
+
net: Net;
|
|
211
|
+
}): {
|
|
212
|
+
ok: true;
|
|
213
|
+
} | {
|
|
214
|
+
ok: false;
|
|
215
|
+
field: string;
|
|
216
|
+
};
|
|
217
|
+
/** What a person reads before anything is signed. */
|
|
218
|
+
export declare function planLines(p: SendPlan): string[];
|
|
219
|
+
/** A plan as JSON-safe values (bigints as decimal strings). */
|
|
220
|
+
export declare function planJson(p: SendPlan): Obj;
|
|
221
|
+
/** The `wallet send … --payment-tx` line that records a broadcast transfer in ONE's ledger. */
|
|
222
|
+
export declare function recordLine(p: SendPlan, hash: string, cli: string): string;
|