oneie 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,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hyperliquid/meta — asset index, szDecimals and tick kind from `meta` (perps) and `spotMeta`
|
|
3
|
+
* (spot), and the keyless info reads behind them (text/hyperliquid-plan.md H5).
|
|
4
|
+
*
|
|
5
|
+
* Indexing, as the python SDK's Info.__init__ does it:
|
|
6
|
+
* perp asset = position in meta.universe (0 = BTC on mainnet)
|
|
7
|
+
* spot asset = 10000 + spotMeta.universe[i].index (the `index` FIELD, not the array position)
|
|
8
|
+
* spot szDecimals = the BASE token's szDecimals
|
|
9
|
+
* spot names = the pair's own name ("PURR/USDC", "@107") plus "BASE/QUOTE" as an alias
|
|
10
|
+
* Builder-deployed perp dexs (110000+) are not read here and are refused by index.
|
|
11
|
+
*
|
|
12
|
+
* Reads go through a `fetchImpl` seam and a failed read is `{ok:false}` — never an empty table.
|
|
13
|
+
*/
|
|
14
|
+
import { type HlNet } from './net.js';
|
|
15
|
+
import type { AssetKind } from './wire.js';
|
|
16
|
+
export interface AssetInfo {
|
|
17
|
+
/** The coin name orders and mids use: "BTC", "PURR/USDC", "@107". */
|
|
18
|
+
coin: string;
|
|
19
|
+
/** Human label: "BTC", "HYPE/USDC". */
|
|
20
|
+
label: string;
|
|
21
|
+
asset: number;
|
|
22
|
+
szDecimals: number;
|
|
23
|
+
kind: AssetKind;
|
|
24
|
+
delisted: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface AssetTable {
|
|
27
|
+
byName: Map<string, AssetInfo>;
|
|
28
|
+
byIndex: Map<number, AssetInfo>;
|
|
29
|
+
}
|
|
30
|
+
export declare const SPOT_OFFSET = 10000;
|
|
31
|
+
export declare const BUILDER_DEX_OFFSET = 110000;
|
|
32
|
+
export declare function buildAssetTable(meta: unknown, spotMeta: unknown): AssetTable;
|
|
33
|
+
/** "BTC" is the perp; spot bitcoin is "UBTC/USDC" (or its "@142" pair name). */
|
|
34
|
+
export declare function resolveCoin(table: AssetTable, coin: string): AssetInfo;
|
|
35
|
+
export declare function assetByIndex(table: AssetTable, asset: number): AssetInfo;
|
|
36
|
+
export type InfoRead<T> = {
|
|
37
|
+
ok: true;
|
|
38
|
+
data: T;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
error: 'hyperliquid_unavailable';
|
|
42
|
+
detail: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function readInfo<T = unknown>(body: Record<string, unknown>, net: HlNet, o?: {
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
}): Promise<InfoRead<T>>;
|
|
48
|
+
/** meta + spotMeta in one go. Either read failing fails the table — half a table is not a table. */
|
|
49
|
+
export declare function readAssetTable(net: HlNet, o?: {
|
|
50
|
+
fetchImpl?: typeof fetch;
|
|
51
|
+
timeoutMs?: number;
|
|
52
|
+
}): Promise<InfoRead<AssetTable>>;
|
|
53
|
+
/** Mid prices by coin name. A coin absent from the answer is absent here — never 0. */
|
|
54
|
+
export declare function readMids(net: HlNet, o?: {
|
|
55
|
+
fetchImpl?: typeof fetch;
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
}): Promise<InfoRead<Record<string, string>>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// VENDORED from one.ie/web/src/lib/hyperliquid/meta.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
+
/**
|
|
3
|
+
* hyperliquid/meta — asset index, szDecimals and tick kind from `meta` (perps) and `spotMeta`
|
|
4
|
+
* (spot), and the keyless info reads behind them (text/hyperliquid-plan.md H5).
|
|
5
|
+
*
|
|
6
|
+
* Indexing, as the python SDK's Info.__init__ does it:
|
|
7
|
+
* perp asset = position in meta.universe (0 = BTC on mainnet)
|
|
8
|
+
* spot asset = 10000 + spotMeta.universe[i].index (the `index` FIELD, not the array position)
|
|
9
|
+
* spot szDecimals = the BASE token's szDecimals
|
|
10
|
+
* spot names = the pair's own name ("PURR/USDC", "@107") plus "BASE/QUOTE" as an alias
|
|
11
|
+
* Builder-deployed perp dexs (110000+) are not read here and are refused by index.
|
|
12
|
+
*
|
|
13
|
+
* Reads go through a `fetchImpl` seam and a failed read is `{ok:false}` — never an empty table.
|
|
14
|
+
*/
|
|
15
|
+
import { HL_INFO } from './net.js';
|
|
16
|
+
import { HlRefusal } from './errors.js';
|
|
17
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
18
|
+
export const SPOT_OFFSET = 10_000;
|
|
19
|
+
export const BUILDER_DEX_OFFSET = 110_000;
|
|
20
|
+
export function buildAssetTable(meta, spotMeta) {
|
|
21
|
+
const byName = new Map();
|
|
22
|
+
const byIndex = new Map();
|
|
23
|
+
const add = (a, ...names) => {
|
|
24
|
+
byIndex.set(a.asset, a);
|
|
25
|
+
for (const n of names)
|
|
26
|
+
if (!byName.has(n))
|
|
27
|
+
byName.set(n, a);
|
|
28
|
+
};
|
|
29
|
+
// Perps first: a perp name wins over any spot alias spelled the same.
|
|
30
|
+
const m = isObj(meta) ? meta : {};
|
|
31
|
+
const universe = Array.isArray(m['universe']) ? m['universe'] : [];
|
|
32
|
+
universe.forEach((p, i) => {
|
|
33
|
+
if (!isObj(p) || typeof p['name'] !== 'string' || typeof p['szDecimals'] !== 'number')
|
|
34
|
+
return;
|
|
35
|
+
add({ coin: p['name'], label: p['name'], asset: i, szDecimals: p['szDecimals'], kind: 'perp', delisted: p['isDelisted'] === true }, p['name']);
|
|
36
|
+
});
|
|
37
|
+
const sm = isObj(spotMeta) ? spotMeta : {};
|
|
38
|
+
const tokens = new Map();
|
|
39
|
+
for (const t of Array.isArray(sm['tokens']) ? sm['tokens'] : []) {
|
|
40
|
+
if (isObj(t) && typeof t['index'] === 'number')
|
|
41
|
+
tokens.set(t['index'], t);
|
|
42
|
+
}
|
|
43
|
+
for (const u of Array.isArray(sm['universe']) ? sm['universe'] : []) {
|
|
44
|
+
if (!isObj(u) || typeof u['index'] !== 'number' || typeof u['name'] !== 'string' || !Array.isArray(u['tokens']))
|
|
45
|
+
continue;
|
|
46
|
+
const [b, q] = u['tokens'];
|
|
47
|
+
const base = tokens.get(b);
|
|
48
|
+
const quote = tokens.get(q);
|
|
49
|
+
if (!base || typeof base['szDecimals'] !== 'number')
|
|
50
|
+
continue;
|
|
51
|
+
const label = `${String(base['name'])}/${String(quote?.['name'] ?? '?')}`;
|
|
52
|
+
add({ coin: u['name'], label, asset: SPOT_OFFSET + u['index'], szDecimals: base['szDecimals'], kind: 'spot', delisted: false }, u['name'], label);
|
|
53
|
+
}
|
|
54
|
+
return { byName, byIndex };
|
|
55
|
+
}
|
|
56
|
+
/** "BTC" is the perp; spot bitcoin is "UBTC/USDC" (or its "@142" pair name). */
|
|
57
|
+
export function resolveCoin(table, coin) {
|
|
58
|
+
const hit = table.byName.get(coin);
|
|
59
|
+
if (!hit)
|
|
60
|
+
throw new HlRefusal('unknown_asset', coin);
|
|
61
|
+
if (hit.delisted)
|
|
62
|
+
throw new HlRefusal('asset_delisted', coin);
|
|
63
|
+
return hit;
|
|
64
|
+
}
|
|
65
|
+
export function assetByIndex(table, asset) {
|
|
66
|
+
if (asset >= BUILDER_DEX_OFFSET)
|
|
67
|
+
throw new HlRefusal('builder_dex_unsupported', String(asset));
|
|
68
|
+
const hit = table.byIndex.get(asset);
|
|
69
|
+
if (!hit)
|
|
70
|
+
throw new HlRefusal('unknown_asset', String(asset));
|
|
71
|
+
return hit;
|
|
72
|
+
}
|
|
73
|
+
export async function readInfo(body, net, o = {}) {
|
|
74
|
+
const f = o.fetchImpl ?? fetch;
|
|
75
|
+
try {
|
|
76
|
+
const res = await f(HL_INFO[net], {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'content-type': 'application/json' },
|
|
79
|
+
body: JSON.stringify(body),
|
|
80
|
+
signal: AbortSignal.timeout(o.timeoutMs ?? 5000),
|
|
81
|
+
});
|
|
82
|
+
if (!res.ok)
|
|
83
|
+
return { ok: false, error: 'hyperliquid_unavailable', detail: `status_${res.status}` };
|
|
84
|
+
return { ok: true, data: (await res.json()) };
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return { ok: false, error: 'hyperliquid_unavailable', detail: e.message };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** meta + spotMeta in one go. Either read failing fails the table — half a table is not a table. */
|
|
91
|
+
export async function readAssetTable(net, o = {}) {
|
|
92
|
+
const [meta, spot] = await Promise.all([readInfo({ type: 'meta' }, net, o), readInfo({ type: 'spotMeta' }, net, o)]);
|
|
93
|
+
if (!meta.ok)
|
|
94
|
+
return meta;
|
|
95
|
+
if (!spot.ok)
|
|
96
|
+
return spot;
|
|
97
|
+
return { ok: true, data: buildAssetTable(meta.data, spot.data) };
|
|
98
|
+
}
|
|
99
|
+
/** Mid prices by coin name. A coin absent from the answer is absent here — never 0. */
|
|
100
|
+
export async function readMids(net, o = {}) {
|
|
101
|
+
const r = await readInfo({ type: 'allMids' }, net, o);
|
|
102
|
+
if (!r.ok)
|
|
103
|
+
return r;
|
|
104
|
+
const out = {};
|
|
105
|
+
if (isObj(r.data))
|
|
106
|
+
for (const [k, v] of Object.entries(r.data))
|
|
107
|
+
if (typeof v === 'string' && /^\d+(\.\d+)?$/.test(v))
|
|
108
|
+
out[k] = v;
|
|
109
|
+
return { ok: true, data: out };
|
|
110
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hyperliquid/msgpack — the exact msgpack bytes Hyperliquid hashes for an L1 action
|
|
3
|
+
* (text/hyperliquid-plan.md § The hash). A port of what python `msgpack.packb(action)` emits
|
|
4
|
+
* for the shapes an action can hold, and nothing else:
|
|
5
|
+
*
|
|
6
|
+
* null → nil · boolean → c2/c3 · integer → smallest fixint/uint/int · string → fixstr/str8/16/32
|
|
7
|
+
* array → fixarray/array16/32 · plain object → fixmap/map16/32, keys in INSERTION order
|
|
8
|
+
*
|
|
9
|
+
* A JS float is REFUSED (`msgpack_float`): Hyperliquid's wire carries prices and sizes as decimal
|
|
10
|
+
* strings, so a float here means a builder bug — and python would emit float64, a different hash.
|
|
11
|
+
* `undefined` is refused too: python never sees it, so silently dropping a key would hash a
|
|
12
|
+
* different action than the one the caller thinks it built.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MsgpackError extends Error {
|
|
15
|
+
code: 'msgpack_float' | 'msgpack_undefined' | 'msgpack_type' | 'msgpack_int_range';
|
|
16
|
+
constructor(code: 'msgpack_float' | 'msgpack_undefined' | 'msgpack_type' | 'msgpack_int_range', detail: string);
|
|
17
|
+
}
|
|
18
|
+
export declare function packb(value: unknown): Uint8Array;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// VENDORED from one.ie/web/src/lib/hyperliquid/msgpack.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
+
/**
|
|
3
|
+
* hyperliquid/msgpack — the exact msgpack bytes Hyperliquid hashes for an L1 action
|
|
4
|
+
* (text/hyperliquid-plan.md § The hash). A port of what python `msgpack.packb(action)` emits
|
|
5
|
+
* for the shapes an action can hold, and nothing else:
|
|
6
|
+
*
|
|
7
|
+
* null → nil · boolean → c2/c3 · integer → smallest fixint/uint/int · string → fixstr/str8/16/32
|
|
8
|
+
* array → fixarray/array16/32 · plain object → fixmap/map16/32, keys in INSERTION order
|
|
9
|
+
*
|
|
10
|
+
* A JS float is REFUSED (`msgpack_float`): Hyperliquid's wire carries prices and sizes as decimal
|
|
11
|
+
* strings, so a float here means a builder bug — and python would emit float64, a different hash.
|
|
12
|
+
* `undefined` is refused too: python never sees it, so silently dropping a key would hash a
|
|
13
|
+
* different action than the one the caller thinks it built.
|
|
14
|
+
*/
|
|
15
|
+
export class MsgpackError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
constructor(code, detail) {
|
|
18
|
+
super(`${code}: ${detail}`);
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
23
|
+
const I64_MIN = -(1n << 63n);
|
|
24
|
+
export function packb(value) {
|
|
25
|
+
const out = [];
|
|
26
|
+
write(out, value, '$');
|
|
27
|
+
return Uint8Array.from(out);
|
|
28
|
+
}
|
|
29
|
+
function be(out, n, bytes) {
|
|
30
|
+
for (let i = bytes - 1; i >= 0; i--)
|
|
31
|
+
out.push(Number((n >> BigInt(8 * i)) & 0xffn));
|
|
32
|
+
}
|
|
33
|
+
function writeInt(out, n, at) {
|
|
34
|
+
if (n > U64_MAX || n < I64_MIN)
|
|
35
|
+
throw new MsgpackError('msgpack_int_range', at);
|
|
36
|
+
if (n >= 0n) {
|
|
37
|
+
if (n <= 0x7fn)
|
|
38
|
+
out.push(Number(n));
|
|
39
|
+
else if (n <= 0xffn) {
|
|
40
|
+
out.push(0xcc);
|
|
41
|
+
be(out, n, 1);
|
|
42
|
+
}
|
|
43
|
+
else if (n <= 0xffffn) {
|
|
44
|
+
out.push(0xcd);
|
|
45
|
+
be(out, n, 2);
|
|
46
|
+
}
|
|
47
|
+
else if (n <= 0xffffffffn) {
|
|
48
|
+
out.push(0xce);
|
|
49
|
+
be(out, n, 4);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
out.push(0xcf);
|
|
53
|
+
be(out, n, 8);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const u = (bits) => (n + (1n << BigInt(bits))); // two's complement
|
|
58
|
+
if (n >= -32n)
|
|
59
|
+
out.push(Number(u(8)));
|
|
60
|
+
else if (n >= -128n) {
|
|
61
|
+
out.push(0xd0);
|
|
62
|
+
be(out, u(8), 1);
|
|
63
|
+
}
|
|
64
|
+
else if (n >= -32768n) {
|
|
65
|
+
out.push(0xd1);
|
|
66
|
+
be(out, u(16), 2);
|
|
67
|
+
}
|
|
68
|
+
else if (n >= -2147483648n) {
|
|
69
|
+
out.push(0xd2);
|
|
70
|
+
be(out, u(32), 4);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
out.push(0xd3);
|
|
74
|
+
be(out, u(64), 8);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function writeLen(out, len, fix, fixMax, codes) {
|
|
78
|
+
if (len <= fixMax)
|
|
79
|
+
out.push(fix | len);
|
|
80
|
+
else if (codes[0] !== null && len <= 0xff) {
|
|
81
|
+
out.push(codes[0]);
|
|
82
|
+
be(out, BigInt(len), 1);
|
|
83
|
+
}
|
|
84
|
+
else if (len <= 0xffff) {
|
|
85
|
+
out.push(codes[1]);
|
|
86
|
+
be(out, BigInt(len), 2);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
out.push(codes[2]);
|
|
90
|
+
be(out, BigInt(len), 4);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function write(out, v, at) {
|
|
94
|
+
if (v === null) {
|
|
95
|
+
out.push(0xc0);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (v === undefined)
|
|
99
|
+
throw new MsgpackError('msgpack_undefined', at);
|
|
100
|
+
if (typeof v === 'boolean') {
|
|
101
|
+
out.push(v ? 0xc3 : 0xc2);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof v === 'bigint') {
|
|
105
|
+
writeInt(out, v, at);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (typeof v === 'number') {
|
|
109
|
+
if (!Number.isSafeInteger(v))
|
|
110
|
+
throw new MsgpackError('msgpack_float', `${at}=${v}`);
|
|
111
|
+
writeInt(out, BigInt(v), at);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (typeof v === 'string') {
|
|
115
|
+
const b = new TextEncoder().encode(v);
|
|
116
|
+
writeLen(out, b.length, 0xa0, 31, [0xd9, 0xda, 0xdb]);
|
|
117
|
+
for (const x of b)
|
|
118
|
+
out.push(x);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(v)) {
|
|
122
|
+
writeLen(out, v.length, 0x90, 15, [null, 0xdc, 0xdd]);
|
|
123
|
+
v.forEach((x, i) => write(out, x, `${at}[${i}]`));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype) {
|
|
127
|
+
const keys = Object.keys(v);
|
|
128
|
+
writeLen(out, keys.length, 0x80, 15, [null, 0xde, 0xdf]);
|
|
129
|
+
for (const k of keys) {
|
|
130
|
+
write(out, k, at);
|
|
131
|
+
write(out, v[k], `${at}.${k}`);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
throw new MsgpackError('msgpack_type', `${at}: ${typeof v}`);
|
|
136
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The two names the vendored core imports from one.ie/web/src/lib/swap/hyperliquid.ts.
|
|
2
|
+
// Hand-written (that web file carries more than the core needs); tests/hl-core-parity.test.ts
|
|
3
|
+
// pins HL_INFO to the web original value for value.
|
|
4
|
+
export const HL_INFO = {
|
|
5
|
+
mainnet: 'https://api.hyperliquid.xyz/info',
|
|
6
|
+
testnet: 'https://api.hyperliquid-testnet.xyz/info',
|
|
7
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hyperliquid/signing — what Hyperliquid's /exchange expects to be signed, and the seam a key
|
|
3
|
+
* plugs into (text/hyperliquid-plan.md § The hash, § The signer seam). A port of the python SDK's
|
|
4
|
+
* `utils/signing.py` (hyperliquid-dex/hyperliquid-python-sdk @ 2fdb18f9):
|
|
5
|
+
*
|
|
6
|
+
* L1 action connectionId = keccak(msgpack(action) ‖ nonce u64be ‖ 00 | 01‖vault ‖ [00‖expiresAfter u64be])
|
|
7
|
+
* signed as Agent{source:'a'|'b', connectionId} under domain Exchange/1/1337/0x0
|
|
8
|
+
* user-signed the action's own fields under domain HyperliquidSignTransaction/1/<signatureChainId>/0x0,
|
|
9
|
+
* with hyperliquidChain 'Mainnet'|'Testnet' inside the message
|
|
10
|
+
*
|
|
11
|
+
* NO KEY MATERIAL LIVES HERE. `dryRun` is pure — it takes no fetch and cannot reach the exchange.
|
|
12
|
+
* `signAction` recomputes the dry run itself (it never trusts typed data handed to it), asks the
|
|
13
|
+
* `Signer`, and recovers the signature back to `signer.address` before anything may be posted.
|
|
14
|
+
*/
|
|
15
|
+
import type { HlNet } from './net.js';
|
|
16
|
+
import { type HlAction } from './actions.js';
|
|
17
|
+
import { type Eip712Domain, type TypedData, type TypedField } from './eip712.js';
|
|
18
|
+
import { type AssetTable } from './meta.js';
|
|
19
|
+
export declare const HL_EXCHANGE: Record<HlNet, string>;
|
|
20
|
+
/** Arbitrum Sepolia — the python SDK's fixed value. Any chain id may sign; hyperliquidChain picks the network. */
|
|
21
|
+
export declare const DEFAULT_SIGNATURE_CHAIN_ID = "0x66eee";
|
|
22
|
+
/** The bytes that are keccak'd into the connectionId (python `action_hash`, before keccak). */
|
|
23
|
+
export declare function actionHashInput(action: unknown, vaultAddress: string | null, nonce: number, expiresAfter: number | null): Uint8Array;
|
|
24
|
+
export declare const actionHash: (action: unknown, vaultAddress: string | null, nonce: number, expiresAfter: number | null) => Uint8Array;
|
|
25
|
+
export declare const L1_DOMAIN: Eip712Domain;
|
|
26
|
+
export declare const AGENT_FIELDS: TypedField[];
|
|
27
|
+
export declare function l1TypedData(connectionId: Uint8Array, net: HlNet): TypedData;
|
|
28
|
+
export declare const USER_SIGNED: Record<'usdClassTransfer' | 'withdraw3', {
|
|
29
|
+
primaryType: string;
|
|
30
|
+
fields: TypedField[];
|
|
31
|
+
nonceField: 'nonce' | 'time';
|
|
32
|
+
}>;
|
|
33
|
+
/** python `user_signed_payload`. `message` keeps only the declared fields. */
|
|
34
|
+
export declare function userSignedTypedData(primaryType: string, fields: TypedField[], action: Record<string, unknown>, net: HlNet, signatureChainId?: string): TypedData;
|
|
35
|
+
export interface DryRunOpts {
|
|
36
|
+
net: HlNet;
|
|
37
|
+
/** Required for L1 actions (ms timestamp). A user-signed action carries its own (nonce / time). */
|
|
38
|
+
nonce?: number;
|
|
39
|
+
/** L1 only: trade on behalf of a vault / sub-account. */
|
|
40
|
+
vaultAddress?: string;
|
|
41
|
+
/** L1 only: the exchange rejects the action after this ms timestamp. */
|
|
42
|
+
expiresAfter?: number;
|
|
43
|
+
/** User-signed only. Default 0x66eee. */
|
|
44
|
+
signatureChainId?: string;
|
|
45
|
+
/** Required for `order`: the tick rules are re-checked against it before anything is signed. */
|
|
46
|
+
assets?: AssetTable;
|
|
47
|
+
}
|
|
48
|
+
export interface DryRun {
|
|
49
|
+
kind: 'l1' | 'user';
|
|
50
|
+
network: HlNet;
|
|
51
|
+
/** Exactly what will be POSTed as `action`. */
|
|
52
|
+
action: Record<string, unknown>;
|
|
53
|
+
nonce: number;
|
|
54
|
+
vaultAddress: string | null;
|
|
55
|
+
expiresAfter: number | null;
|
|
56
|
+
/** L1 only: msgpack(action). */
|
|
57
|
+
msgpackHex: string | null;
|
|
58
|
+
/** L1 only: the full keccak input (msgpack ‖ nonce ‖ vault flag ‖ expiresAfter). */
|
|
59
|
+
hashInputHex: string | null;
|
|
60
|
+
/** L1 only: keccak of the input — the phantom agent's connectionId. */
|
|
61
|
+
connectionId: `0x${string}` | null;
|
|
62
|
+
/** The eth_signTypedData_v4 payload (types include EIP712Domain). */
|
|
63
|
+
typedData: TypedData;
|
|
64
|
+
/** The EIP-712 digest a raw secp256k1 key signs. */
|
|
65
|
+
digest: `0x${string}`;
|
|
66
|
+
exchangeUrl: string;
|
|
67
|
+
posted: false;
|
|
68
|
+
}
|
|
69
|
+
export declare function dryRun(action: HlAction, opts: DryRunOpts): DryRun;
|
|
70
|
+
/**
|
|
71
|
+
* Anything that can sign EIP-712 for one address: the browser's PRF-derived key, the CLI vault,
|
|
72
|
+
* an ethers Wallet. `types` EXCLUDES EIP712Domain (the ethers convention); the primary type is the
|
|
73
|
+
* one non-domain entry. Returns a 65-byte 0x signature (r ‖ s ‖ v).
|
|
74
|
+
*/
|
|
75
|
+
export interface Signer {
|
|
76
|
+
address: string;
|
|
77
|
+
signTypedData(domain: Eip712Domain, types: Record<string, TypedField[]>, message: Record<string, unknown>): Promise<string>;
|
|
78
|
+
}
|
|
79
|
+
export interface HlSignature {
|
|
80
|
+
r: `0x${string}`;
|
|
81
|
+
s: `0x${string}`;
|
|
82
|
+
v: 27 | 28;
|
|
83
|
+
}
|
|
84
|
+
export interface ExchangeRequest {
|
|
85
|
+
action: Record<string, unknown>;
|
|
86
|
+
nonce: number;
|
|
87
|
+
signature: HlSignature;
|
|
88
|
+
vaultAddress: string | null;
|
|
89
|
+
expiresAfter: number | null;
|
|
90
|
+
}
|
|
91
|
+
export declare function splitSignature(sig: string): HlSignature;
|
|
92
|
+
/** Accepts python's unpadded r/s ("0x5374…298") as well as 32-byte hex. */
|
|
93
|
+
export declare function recoverAddress(digest: Uint8Array | string, sig: {
|
|
94
|
+
r: string;
|
|
95
|
+
s: string;
|
|
96
|
+
v: number;
|
|
97
|
+
}): `0x${string}`;
|
|
98
|
+
export declare function signAction(action: HlAction, opts: DryRunOpts, signer: Signer, o?: {
|
|
99
|
+
expectDigest?: string;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
request: ExchangeRequest;
|
|
102
|
+
dry: DryRun;
|
|
103
|
+
}>;
|