@oneie/cli 5.8.0 → 5.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +7 -8
- package/dist/src/age-yefbe8pe.js +1 -0
- package/dist/src/evm-tx-ee2q0e3w.js +1 -0
- package/dist/src/hl-run-tgrkrk69.js +1 -0
- package/dist/src/index-0rj9wdk9.js +4 -0
- package/dist/src/index-91y484c2.js +2052 -0
- package/dist/src/index-940y3rnv.js +12 -0
- package/dist/src/index.js +1047 -134
- package/dist/src/message-key-db1xjdkw.js +1 -0
- package/dist/src/message-lock-5vr8079x.js +5 -0
- package/dist/src/sweep-order-c2p6rk8c.js +1 -0
- package/dist/src/sweep-runner-t68xe7vx.js +1 -0
- package/package.json +7 -8
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/ceiling.d.ts +0 -36
- package/dist/src/ceiling.js +0 -189
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/check.d.ts +0 -11
- package/dist/src/check.js +0 -53
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/credits.d.ts +0 -29
- package/dist/src/credits.js +0 -88
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -297
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -270
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/check-words.d.ts +0 -57
- package/dist/src/lib/check-words.js +0 -144
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -363
- package/dist/src/lib/journey.d.ts +0 -150
- package/dist/src/lib/journey.js +0 -264
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/net-choice.d.ts +0 -28
- package/dist/src/lib/net-choice.js +0 -72
- package/dist/src/lib/network.d.ts +0 -22
- package/dist/src/lib/network.js +0 -50
- package/dist/src/lib/next-words.d.ts +0 -105
- package/dist/src/lib/next-words.js +0 -298
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -90
- package/dist/src/lib/sui-grpc-send.js +0 -128
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/timed-fetch.d.ts +0 -33
- package/dist/src/lib/timed-fetch.js +0 -59
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -103
- package/dist/src/lib/vaultfile.js +0 -249
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/move.d.ts +0 -36
- package/dist/src/move.js +0 -152
- package/dist/src/network-cmd.d.ts +0 -17
- package/dist/src/network-cmd.js +0 -74
- package/dist/src/next.d.ts +0 -12
- package/dist/src/next.js +0 -67
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop-buy.d.ts +0 -16
- package/dist/src/shop-buy.js +0 -101
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -112
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -27
- package/dist/src/start.js +0 -225
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/thread.d.ts +0 -2
- package/dist/src/thread.js +0 -52
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -158
- package/dist/src/wallet-money.js +0 -664
- package/dist/src/wallet.d.ts +0 -169
- package/dist/src/wallet.js +0 -973
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -169
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
|
@@ -1,136 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
}>;
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/signing.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/signing — what Hyperliquid's /exchange expects to be signed, and the seam a key
|
|
4
|
-
* plugs into (text/hyperliquid-plan.md § The hash, § The signer seam). A port of the python SDK's
|
|
5
|
-
* `utils/signing.py` (hyperliquid-dex/hyperliquid-python-sdk @ 2fdb18f9):
|
|
6
|
-
*
|
|
7
|
-
* L1 action connectionId = keccak(msgpack(action) ‖ nonce u64be ‖ 00 | 01‖vault ‖ [00‖expiresAfter u64be])
|
|
8
|
-
* signed as Agent{source:'a'|'b', connectionId} under domain Exchange/1/1337/0x0
|
|
9
|
-
* user-signed the action's own fields under domain HyperliquidSignTransaction/1/<signatureChainId>/0x0,
|
|
10
|
-
* with hyperliquidChain 'Mainnet'|'Testnet' inside the message
|
|
11
|
-
*
|
|
12
|
-
* NO KEY MATERIAL LIVES HERE. `dryRun` is pure — it takes no fetch and cannot reach the exchange.
|
|
13
|
-
* `signAction` recomputes the dry run itself (it never trusts typed data handed to it), asks the
|
|
14
|
-
* `Signer`, and recovers the signature back to `signer.address` before anything may be posted.
|
|
15
|
-
*/
|
|
16
|
-
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
17
|
-
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
18
|
-
import { buildCancel, buildUsdClassTransfer, buildWithdraw3, orderWire, } from './actions.js';
|
|
19
|
-
import { EIP712_DOMAIN_FIELDS, hex0x, hexToBytes, toHex, typedDataDigest } from './eip712.js';
|
|
20
|
-
import { HlRefusal } from './errors.js';
|
|
21
|
-
import { assetByIndex } from './meta.js';
|
|
22
|
-
import { packb } from './msgpack.js';
|
|
23
|
-
export const HL_EXCHANGE = {
|
|
24
|
-
mainnet: 'https://api.hyperliquid.xyz/exchange',
|
|
25
|
-
testnet: 'https://api.hyperliquid-testnet.xyz/exchange',
|
|
26
|
-
};
|
|
27
|
-
/** Arbitrum Sepolia — the python SDK's fixed value. Any chain id may sign; hyperliquidChain picks the network. */
|
|
28
|
-
export const DEFAULT_SIGNATURE_CHAIN_ID = '0x66eee';
|
|
29
|
-
const ZERO = '0x0000000000000000000000000000000000000000';
|
|
30
|
-
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
31
|
-
// ── L1 ──────────────────────────────────────────────────────────────────────────────────────────
|
|
32
|
-
function u64be(n) {
|
|
33
|
-
let v = BigInt(n);
|
|
34
|
-
if (v < 0n || v >= 1n << 64n)
|
|
35
|
-
throw new HlRefusal('eip712_range', String(n));
|
|
36
|
-
const out = new Uint8Array(8);
|
|
37
|
-
for (let i = 7; i >= 0; i--) {
|
|
38
|
-
out[i] = Number(v & 0xffn);
|
|
39
|
-
v >>= 8n;
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
/** The bytes that are keccak'd into the connectionId (python `action_hash`, before keccak). */
|
|
44
|
-
export function actionHashInput(action, vaultAddress, nonce, expiresAfter) {
|
|
45
|
-
const parts = [packb(action), u64be(nonce)];
|
|
46
|
-
if (vaultAddress === null)
|
|
47
|
-
parts.push(Uint8Array.of(0));
|
|
48
|
-
else
|
|
49
|
-
parts.push(Uint8Array.of(1), hexToBytes(vaultAddress));
|
|
50
|
-
if (expiresAfter !== null)
|
|
51
|
-
parts.push(Uint8Array.of(0), u64be(expiresAfter));
|
|
52
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
53
|
-
let i = 0;
|
|
54
|
-
for (const p of parts) {
|
|
55
|
-
out.set(p, i);
|
|
56
|
-
i += p.length;
|
|
57
|
-
}
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
export const actionHash = (action, vaultAddress, nonce, expiresAfter) => keccak_256(actionHashInput(action, vaultAddress, nonce, expiresAfter));
|
|
61
|
-
export const L1_DOMAIN = { name: 'Exchange', version: '1', chainId: 1337, verifyingContract: ZERO };
|
|
62
|
-
export const AGENT_FIELDS = [
|
|
63
|
-
{ name: 'source', type: 'string' },
|
|
64
|
-
{ name: 'connectionId', type: 'bytes32' },
|
|
65
|
-
];
|
|
66
|
-
export function l1TypedData(connectionId, net) {
|
|
67
|
-
return {
|
|
68
|
-
domain: L1_DOMAIN,
|
|
69
|
-
types: { Agent: AGENT_FIELDS, EIP712Domain: EIP712_DOMAIN_FIELDS },
|
|
70
|
-
primaryType: 'Agent',
|
|
71
|
-
message: { source: net === 'mainnet' ? 'a' : 'b', connectionId: hex0x(connectionId) },
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// ── user-signed ─────────────────────────────────────────────────────────────────────────────────
|
|
75
|
-
export const USER_SIGNED = {
|
|
76
|
-
usdClassTransfer: {
|
|
77
|
-
primaryType: 'HyperliquidTransaction:UsdClassTransfer',
|
|
78
|
-
fields: [
|
|
79
|
-
{ name: 'hyperliquidChain', type: 'string' },
|
|
80
|
-
{ name: 'amount', type: 'string' },
|
|
81
|
-
{ name: 'toPerp', type: 'bool' },
|
|
82
|
-
{ name: 'nonce', type: 'uint64' },
|
|
83
|
-
],
|
|
84
|
-
nonceField: 'nonce',
|
|
85
|
-
},
|
|
86
|
-
withdraw3: {
|
|
87
|
-
primaryType: 'HyperliquidTransaction:Withdraw',
|
|
88
|
-
fields: [
|
|
89
|
-
{ name: 'hyperliquidChain', type: 'string' },
|
|
90
|
-
{ name: 'destination', type: 'string' },
|
|
91
|
-
{ name: 'amount', type: 'string' },
|
|
92
|
-
{ name: 'time', type: 'uint64' },
|
|
93
|
-
],
|
|
94
|
-
nonceField: 'time',
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
/** python `user_signed_payload`. `message` keeps only the declared fields. */
|
|
98
|
-
export function userSignedTypedData(primaryType, fields, action, net, signatureChainId = DEFAULT_SIGNATURE_CHAIN_ID) {
|
|
99
|
-
if (!/^0x[0-9a-fA-F]+$/.test(signatureChainId))
|
|
100
|
-
throw new HlRefusal('bad_hex', signatureChainId);
|
|
101
|
-
const full = { ...action, hyperliquidChain: net === 'mainnet' ? 'Mainnet' : 'Testnet' };
|
|
102
|
-
const message = {};
|
|
103
|
-
for (const f of fields) {
|
|
104
|
-
if (!(f.name in full))
|
|
105
|
-
throw new HlRefusal('eip712_missing', f.name);
|
|
106
|
-
message[f.name] = full[f.name];
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
domain: { name: 'HyperliquidSignTransaction', version: '1', chainId: Number(BigInt(signatureChainId)), verifyingContract: ZERO },
|
|
110
|
-
types: { [primaryType]: fields, EIP712Domain: EIP712_DOMAIN_FIELDS },
|
|
111
|
-
primaryType,
|
|
112
|
-
message,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
// ── the canonical re-derivation (H3: nothing outside the allowlist is ever prepared) ────────────
|
|
116
|
-
const same = (a, b) => toHex(packb(a)) === toHex(packb(b));
|
|
117
|
-
function canonicalOrder(w, assets) {
|
|
118
|
-
const asset = assetByIndex(assets, w.a);
|
|
119
|
-
const tif = w.t?.limit?.tif;
|
|
120
|
-
return orderWire({ asset, isBuy: w.b, sz: w.s, px: w.p, tif, reduceOnly: w.r, cloid: w.c });
|
|
121
|
-
}
|
|
122
|
-
/** The same keys with the same values, in any order — user-signed actions are hashed by field name. */
|
|
123
|
-
const sameFields = (a, b) => {
|
|
124
|
-
const ka = Object.keys(a).sort();
|
|
125
|
-
const kb = Object.keys(b).sort();
|
|
126
|
-
return ka.join() === kb.join() && ka.every((k) => same(a[k], b[k]));
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* A user-signed action handed back from a dry run carries `hyperliquidChain` and
|
|
130
|
-
* `signatureChainId`. They must agree with THIS call's network and chain id, then are stripped
|
|
131
|
-
* so the rebuild compares like with like. A Mainnet action is never re-signed for testnet.
|
|
132
|
-
*/
|
|
133
|
-
function stripPosted(action, opts) {
|
|
134
|
-
const { hyperliquidChain, signatureChainId, ...rest } = action;
|
|
135
|
-
const chain = opts.net === 'mainnet' ? 'Mainnet' : 'Testnet';
|
|
136
|
-
if (hyperliquidChain !== undefined && hyperliquidChain !== chain) {
|
|
137
|
-
throw new HlRefusal('unsupported_action', `hyperliquidChain ${String(hyperliquidChain)} on ${opts.net}`);
|
|
138
|
-
}
|
|
139
|
-
const want = (opts.signatureChainId ?? DEFAULT_SIGNATURE_CHAIN_ID).toLowerCase();
|
|
140
|
-
if (signatureChainId !== undefined && String(signatureChainId).toLowerCase() !== want) {
|
|
141
|
-
throw new HlRefusal('unsupported_action', `signatureChainId ${String(signatureChainId)} ≠ ${want}`);
|
|
142
|
-
}
|
|
143
|
-
return rest;
|
|
144
|
-
}
|
|
145
|
-
/** Rebuild the action from its parts through the builders; anything that differs is refused. */
|
|
146
|
-
function canonicalise(action, opts) {
|
|
147
|
-
const assets = opts.assets;
|
|
148
|
-
if (!action || typeof action !== 'object')
|
|
149
|
-
throw new HlRefusal('unsupported_action', 'not an object');
|
|
150
|
-
let rebuilt;
|
|
151
|
-
let given = action;
|
|
152
|
-
switch (action.type) {
|
|
153
|
-
case 'order': {
|
|
154
|
-
if (!assets)
|
|
155
|
-
throw new HlRefusal('meta_required', 'an order is checked against meta + spotMeta before it is signed');
|
|
156
|
-
const orders = Array.isArray(action.orders) ? action.orders : [];
|
|
157
|
-
if (orders.length === 0)
|
|
158
|
-
throw new HlRefusal('unsupported_action', 'order with no orders');
|
|
159
|
-
rebuilt = { type: 'order', orders: orders.map((w) => canonicalOrder(w, assets)), grouping: 'na' };
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
case 'cancel': {
|
|
163
|
-
const c = action.cancels ?? [];
|
|
164
|
-
if (c.length === 0)
|
|
165
|
-
throw new HlRefusal('unsupported_action', 'cancel with no cancels');
|
|
166
|
-
rebuilt = {
|
|
167
|
-
type: 'cancel',
|
|
168
|
-
cancels: c.map((x) => buildCancel({ asset: assets ? assetByIndex(assets, x.a) : { asset: x.a }, oid: x.o }).cancels[0]),
|
|
169
|
-
};
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case 'usdClassTransfer': {
|
|
173
|
-
given = stripPosted(action, opts);
|
|
174
|
-
const a = given;
|
|
175
|
-
if (typeof a.toPerp !== 'boolean')
|
|
176
|
-
throw new HlRefusal('unsupported_action', 'toPerp');
|
|
177
|
-
rebuilt = buildUsdClassTransfer({ amount: a.amount, toPerp: a.toPerp, nonce: a.nonce });
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case 'withdraw3': {
|
|
181
|
-
given = stripPosted(action, opts);
|
|
182
|
-
const a = given;
|
|
183
|
-
rebuilt = buildWithdraw3({ destination: a.destination, amount: a.amount, time: a.time });
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
default:
|
|
187
|
-
throw new HlRefusal('unsupported_action', String(action.type));
|
|
188
|
-
}
|
|
189
|
-
// L1 key order is part of the hash, so an L1 action must match byte for byte.
|
|
190
|
-
const ok = rebuilt.type === 'order' || rebuilt.type === 'cancel' ? same(rebuilt, given) : sameFields(rebuilt, given);
|
|
191
|
-
if (!ok)
|
|
192
|
-
throw new HlRefusal('unsupported_action', 'action is not in canonical form');
|
|
193
|
-
return rebuilt;
|
|
194
|
-
}
|
|
195
|
-
export function dryRun(action, opts) {
|
|
196
|
-
const canon = canonicalise(action, opts);
|
|
197
|
-
if (canon.type === 'order' || canon.type === 'cancel') {
|
|
198
|
-
if (opts.nonce === undefined || !Number.isSafeInteger(opts.nonce) || opts.nonce < 0)
|
|
199
|
-
throw new HlRefusal('nonce_required');
|
|
200
|
-
if (opts.vaultAddress !== undefined && !ADDRESS.test(opts.vaultAddress))
|
|
201
|
-
throw new HlRefusal('bad_address', opts.vaultAddress);
|
|
202
|
-
if (opts.expiresAfter !== undefined && (!Number.isSafeInteger(opts.expiresAfter) || opts.expiresAfter <= 0)) {
|
|
203
|
-
throw new HlRefusal('expires_unsupported', String(opts.expiresAfter));
|
|
204
|
-
}
|
|
205
|
-
const vault = opts.vaultAddress?.toLowerCase() ?? null;
|
|
206
|
-
const expires = opts.expiresAfter ?? null;
|
|
207
|
-
const input = actionHashInput(canon, vault, opts.nonce, expires);
|
|
208
|
-
const cid = keccak_256(input);
|
|
209
|
-
const typedData = l1TypedData(cid, opts.net);
|
|
210
|
-
return {
|
|
211
|
-
kind: 'l1',
|
|
212
|
-
network: opts.net,
|
|
213
|
-
action: canon,
|
|
214
|
-
nonce: opts.nonce,
|
|
215
|
-
vaultAddress: vault,
|
|
216
|
-
expiresAfter: expires,
|
|
217
|
-
msgpackHex: toHex(packb(canon)),
|
|
218
|
-
hashInputHex: toHex(input),
|
|
219
|
-
connectionId: hex0x(cid),
|
|
220
|
-
typedData,
|
|
221
|
-
digest: hex0x(typedDataDigest(typedData)),
|
|
222
|
-
exchangeUrl: HL_EXCHANGE[opts.net],
|
|
223
|
-
posted: false,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
if (opts.vaultAddress !== undefined)
|
|
227
|
-
throw new HlRefusal('vault_unsupported', canon.type);
|
|
228
|
-
if (opts.expiresAfter !== undefined)
|
|
229
|
-
throw new HlRefusal('expires_unsupported', canon.type);
|
|
230
|
-
const spec = USER_SIGNED[canon.type];
|
|
231
|
-
const nonce = canon[spec.nonceField];
|
|
232
|
-
if (opts.nonce !== undefined && opts.nonce !== nonce)
|
|
233
|
-
throw new HlRefusal('nonce_mismatch', `${opts.nonce} ≠ ${nonce}`);
|
|
234
|
-
const signatureChainId = opts.signatureChainId ?? DEFAULT_SIGNATURE_CHAIN_ID;
|
|
235
|
-
const posted = {
|
|
236
|
-
type: canon.type,
|
|
237
|
-
signatureChainId,
|
|
238
|
-
hyperliquidChain: opts.net === 'mainnet' ? 'Mainnet' : 'Testnet',
|
|
239
|
-
...Object.fromEntries(Object.entries(canon).filter(([k]) => k !== 'type')),
|
|
240
|
-
};
|
|
241
|
-
const typedData = userSignedTypedData(spec.primaryType, spec.fields, posted, opts.net, signatureChainId);
|
|
242
|
-
return {
|
|
243
|
-
kind: 'user',
|
|
244
|
-
network: opts.net,
|
|
245
|
-
action: posted,
|
|
246
|
-
nonce,
|
|
247
|
-
vaultAddress: null,
|
|
248
|
-
expiresAfter: null,
|
|
249
|
-
msgpackHex: null,
|
|
250
|
-
hashInputHex: null,
|
|
251
|
-
connectionId: null,
|
|
252
|
-
typedData,
|
|
253
|
-
digest: hex0x(typedDataDigest(typedData)),
|
|
254
|
-
exchangeUrl: HL_EXCHANGE[opts.net],
|
|
255
|
-
posted: false,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
export function splitSignature(sig) {
|
|
259
|
-
const b = hexToBytes(sig);
|
|
260
|
-
if (b.length !== 65)
|
|
261
|
-
throw new HlRefusal('bad_signature', `length ${b.length}`);
|
|
262
|
-
const v = b[64] < 27 ? b[64] + 27 : b[64];
|
|
263
|
-
if (v !== 27 && v !== 28)
|
|
264
|
-
throw new HlRefusal('bad_signature', `v=${b[64]}`);
|
|
265
|
-
return { r: hex0x(b.slice(0, 32)), s: hex0x(b.slice(32, 64)), v };
|
|
266
|
-
}
|
|
267
|
-
/** Accepts python's unpadded r/s ("0x5374…298") as well as 32-byte hex. */
|
|
268
|
-
export function recoverAddress(digest, sig) {
|
|
269
|
-
const d = typeof digest === 'string' ? hexToBytes(digest) : digest;
|
|
270
|
-
const pad = (h) => BigInt(h).toString(16).padStart(64, '0');
|
|
271
|
-
if (sig.v !== 27 && sig.v !== 28)
|
|
272
|
-
throw new HlRefusal('bad_signature', `v=${sig.v}`);
|
|
273
|
-
const rec = hexToBytes(`${(sig.v - 27).toString(16).padStart(2, '0')}${pad(sig.r)}${pad(sig.s)}`);
|
|
274
|
-
const pub = secp256k1.recoverPublicKey(rec, d, { prehash: false });
|
|
275
|
-
const full = secp256k1.Point.fromBytes(pub).toBytes(false);
|
|
276
|
-
return hex0x(keccak_256(full.slice(1)).slice(12));
|
|
277
|
-
}
|
|
278
|
-
export async function signAction(action, opts, signer, o = {}) {
|
|
279
|
-
const dry = dryRun(action, opts);
|
|
280
|
-
if (o.expectDigest !== undefined && o.expectDigest.toLowerCase() !== dry.digest) {
|
|
281
|
-
throw new HlRefusal('signer_mismatch', 'the digest shown is not the digest being signed');
|
|
282
|
-
}
|
|
283
|
-
if (!ADDRESS.test(signer.address))
|
|
284
|
-
throw new HlRefusal('bad_address', signer.address);
|
|
285
|
-
const { EIP712Domain: _domain, ...types } = dry.typedData.types;
|
|
286
|
-
const raw = await signer.signTypedData(dry.typedData.domain, types, dry.typedData.message);
|
|
287
|
-
const signature = splitSignature(raw);
|
|
288
|
-
const who = recoverAddress(dry.digest, signature);
|
|
289
|
-
if (who !== signer.address.toLowerCase())
|
|
290
|
-
throw new HlRefusal('signer_mismatch', `recovered ${who}, expected ${signer.address}`);
|
|
291
|
-
return {
|
|
292
|
-
dry,
|
|
293
|
-
request: { action: dry.action, nonce: dry.nonce, signature, vaultAddress: dry.vaultAddress, expiresAfter: dry.expiresAfter },
|
|
294
|
-
};
|
|
295
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/wire — prices, sizes and amounts as DECIMAL STRINGS, never JS floats
|
|
3
|
-
* (text/hyperliquid-plan.md H4). The canonical form is python `float_to_wire`'s: no exponent,
|
|
4
|
-
* no trailing zeros, no trailing point, `-0` → `0`. The tick rules (Hyperliquid docs § Tick and
|
|
5
|
-
* lot size, mirrored by the python SDK's `_slippage_price`):
|
|
6
|
-
*
|
|
7
|
-
* size decimals ≤ szDecimals
|
|
8
|
-
* price integer → always allowed; else ≤ 5 significant figures AND
|
|
9
|
-
* decimals ≤ MAX_DECIMALS − szDecimals (MAX_DECIMALS = 6 perps, 8 spot)
|
|
10
|
-
*
|
|
11
|
-
* A breach is REFUSED here, by name, before any action or typed data exists.
|
|
12
|
-
*/
|
|
13
|
-
export declare const MAX_DECIMALS: {
|
|
14
|
-
readonly perp: 6;
|
|
15
|
-
readonly spot: 8;
|
|
16
|
-
};
|
|
17
|
-
export type AssetKind = keyof typeof MAX_DECIMALS;
|
|
18
|
-
/** Canonical decimal string. Accepts only a non-negative plain decimal string. */
|
|
19
|
-
export declare function canonical(s: string, what?: string): string;
|
|
20
|
-
export declare const decimalsOf: (c: string) => number;
|
|
21
|
-
export declare const isZero: (c: string) => boolean;
|
|
22
|
-
export declare const isInteger: (c: string) => boolean;
|
|
23
|
-
/** Significant figures of a canonical decimal (leading zeros never count). */
|
|
24
|
-
export declare function sigFigs(c: string): number;
|
|
25
|
-
export declare function checkSize(sz: string, szDecimals: number): string;
|
|
26
|
-
export declare function checkPrice(px: string, szDecimals: number, kind: AssetKind): string;
|
|
27
|
-
/** USDC amounts for usdClassTransfer / withdraw3: ≤ 6 decimals (the perps USD unit). */
|
|
28
|
-
export declare function checkUsd(amount: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* The price a "market" order carries: an aggressive IOC limit at mid × (1 ± slippage), rounded to
|
|
31
|
-
* 5 significant figures then to the tick's decimals — python `_slippage_price`. The one place a
|
|
32
|
-
* float is used is this arithmetic, as in the SDK; the result is re-checked by `checkPrice`.
|
|
33
|
-
*/
|
|
34
|
-
export declare function marketPrice(mid: string, isBuy: boolean, slippage: number, szDecimals: number, kind: AssetKind): string;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/wire.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/wire — prices, sizes and amounts as DECIMAL STRINGS, never JS floats
|
|
4
|
-
* (text/hyperliquid-plan.md H4). The canonical form is python `float_to_wire`'s: no exponent,
|
|
5
|
-
* no trailing zeros, no trailing point, `-0` → `0`. The tick rules (Hyperliquid docs § Tick and
|
|
6
|
-
* lot size, mirrored by the python SDK's `_slippage_price`):
|
|
7
|
-
*
|
|
8
|
-
* size decimals ≤ szDecimals
|
|
9
|
-
* price integer → always allowed; else ≤ 5 significant figures AND
|
|
10
|
-
* decimals ≤ MAX_DECIMALS − szDecimals (MAX_DECIMALS = 6 perps, 8 spot)
|
|
11
|
-
*
|
|
12
|
-
* A breach is REFUSED here, by name, before any action or typed data exists.
|
|
13
|
-
*/
|
|
14
|
-
import { HlRefusal } from './errors.js';
|
|
15
|
-
export const MAX_DECIMALS = { perp: 6, spot: 8 };
|
|
16
|
-
const DECIMAL = /^\d+(\.\d+)?$/;
|
|
17
|
-
/** Canonical decimal string. Accepts only a non-negative plain decimal string. */
|
|
18
|
-
export function canonical(s, what = 'value') {
|
|
19
|
-
if (typeof s !== 'string' || !DECIMAL.test(s.trim()))
|
|
20
|
-
throw new HlRefusal('bad_decimal', `${what}=${String(s)}`);
|
|
21
|
-
let [int, frac = ''] = s.trim().split('.');
|
|
22
|
-
int = int.replace(/^0+(?=\d)/, '');
|
|
23
|
-
frac = frac.replace(/0+$/, '');
|
|
24
|
-
return frac ? `${int}.${frac}` : int;
|
|
25
|
-
}
|
|
26
|
-
export const decimalsOf = (c) => (c.includes('.') ? c.split('.')[1].length : 0);
|
|
27
|
-
export const isZero = (c) => /^0(\.0*)?$/.test(c);
|
|
28
|
-
export const isInteger = (c) => !c.includes('.');
|
|
29
|
-
/** Significant figures of a canonical decimal (leading zeros never count). */
|
|
30
|
-
export function sigFigs(c) {
|
|
31
|
-
const digits = c.replace('.', '').replace(/^0+/, '');
|
|
32
|
-
if (!c.includes('.'))
|
|
33
|
-
return digits.replace(/0+$/, '').length || 1;
|
|
34
|
-
return digits.length || 1;
|
|
35
|
-
}
|
|
36
|
-
export function checkSize(sz, szDecimals) {
|
|
37
|
-
const c = canonical(sz, 'size');
|
|
38
|
-
if (isZero(c))
|
|
39
|
-
throw new HlRefusal('size_zero');
|
|
40
|
-
if (decimalsOf(c) > szDecimals)
|
|
41
|
-
throw new HlRefusal('size_too_precise', `${c} has ${decimalsOf(c)} decimals, max ${szDecimals}`);
|
|
42
|
-
return c;
|
|
43
|
-
}
|
|
44
|
-
export function checkPrice(px, szDecimals, kind) {
|
|
45
|
-
const c = canonical(px, 'price');
|
|
46
|
-
if (isZero(c))
|
|
47
|
-
throw new HlRefusal('price_zero');
|
|
48
|
-
if (isInteger(c))
|
|
49
|
-
return c;
|
|
50
|
-
if (sigFigs(c) > 5)
|
|
51
|
-
throw new HlRefusal('price_sig_figs', `${c} has ${sigFigs(c)} significant figures, max 5`);
|
|
52
|
-
const max = MAX_DECIMALS[kind] - szDecimals;
|
|
53
|
-
if (decimalsOf(c) > max)
|
|
54
|
-
throw new HlRefusal('price_too_precise', `${c} has ${decimalsOf(c)} decimals, max ${max}`);
|
|
55
|
-
return c;
|
|
56
|
-
}
|
|
57
|
-
/** USDC amounts for usdClassTransfer / withdraw3: ≤ 6 decimals (the perps USD unit). */
|
|
58
|
-
export function checkUsd(amount) {
|
|
59
|
-
const c = canonical(amount, 'amount');
|
|
60
|
-
if (isZero(c))
|
|
61
|
-
throw new HlRefusal('amount_zero');
|
|
62
|
-
if (decimalsOf(c) > 6)
|
|
63
|
-
throw new HlRefusal('amount_too_precise', `${c} has ${decimalsOf(c)} decimals, max 6`);
|
|
64
|
-
return c;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* The price a "market" order carries: an aggressive IOC limit at mid × (1 ± slippage), rounded to
|
|
68
|
-
* 5 significant figures then to the tick's decimals — python `_slippage_price`. The one place a
|
|
69
|
-
* float is used is this arithmetic, as in the SDK; the result is re-checked by `checkPrice`.
|
|
70
|
-
*/
|
|
71
|
-
export function marketPrice(mid, isBuy, slippage, szDecimals, kind) {
|
|
72
|
-
const m = Number(canonical(mid, 'mid'));
|
|
73
|
-
if (!(m > 0))
|
|
74
|
-
throw new HlRefusal('price_zero', 'mid');
|
|
75
|
-
if (!(slippage >= 0 && slippage < 1))
|
|
76
|
-
throw new HlRefusal('bad_slippage', String(slippage));
|
|
77
|
-
const px = m * (isBuy ? 1 + slippage : 1 - slippage);
|
|
78
|
-
const fiveSig = Number(px.toPrecision(5));
|
|
79
|
-
const decimals = Math.max(0, MAX_DECIMALS[kind] - szDecimals);
|
|
80
|
-
return checkPrice(canonical(fiveSig.toFixed(decimals), 'price'), szDecimals, kind);
|
|
81
|
-
}
|