@nktkas/hyperliquid 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +4 -2
- package/README.md +36 -35
- package/esm/_dnt.polyfills.d.ts +20 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +12 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/src/base.d.ts +1 -47
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +1 -8
- package/esm/src/clients/event.d.ts +6 -4
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +58 -77
- package/esm/src/clients/public.d.ts +26 -5
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +29 -41
- package/esm/src/clients/wallet.d.ts +200 -26
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +306 -284
- package/esm/src/signing.d.ts +80 -5
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +96 -7
- package/esm/src/transports/base.d.ts +49 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +8 -0
- package/esm/src/transports/http/http_transport.d.ts +8 -5
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +15 -62
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +80 -179
- package/{script/src/transports/websocket/_websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/esm/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +42 -75
- package/esm/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +61 -76
- package/esm/src/types/exchange/requests.d.ts +278 -66
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +0 -48
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +52 -0
- package/esm/src/types/info/markets.d.ts.map +1 -0
- package/esm/src/types/info/markets.js +1 -0
- package/esm/src/types/info/orders.d.ts +1 -1
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +14 -5
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +4 -0
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +3 -1
- package/esm/src/types/subscriptions/requests.d.ts +2 -0
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/package.json +12 -9
- package/script/_dnt.polyfills.d.ts +20 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +23 -0
- package/script/mod.d.ts +3 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +3 -1
- package/script/src/base.d.ts +1 -47
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +2 -10
- package/script/src/clients/event.d.ts +6 -4
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +58 -77
- package/script/src/clients/public.d.ts +26 -5
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +29 -41
- package/script/src/clients/wallet.d.ts +200 -26
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +305 -283
- package/script/src/signing.d.ts +80 -5
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +148 -58
- package/script/src/transports/base.d.ts +49 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +22 -0
- package/script/src/transports/http/http_transport.d.ts +8 -5
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +16 -63
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +81 -180
- package/{esm/src/transports/websocket/_websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/script/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +45 -78
- package/script/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +63 -78
- package/script/src/types/exchange/requests.d.ts +278 -66
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +0 -48
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +52 -0
- package/script/src/types/info/markets.d.ts.map +1 -0
- package/script/{deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js → src/types/info/markets.js} +0 -2
- package/script/src/types/info/orders.d.ts +1 -1
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +14 -5
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +4 -0
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +25 -22
- package/script/src/types/subscriptions/requests.d.ts +2 -0
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -66
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -294
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -280
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -99
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -309
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -322
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
package/script/src/signing.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
3
|
* and interfaces to various wallet implementations.
|
|
4
|
+
*
|
|
4
5
|
* @example
|
|
5
6
|
* ```ts
|
|
6
7
|
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
@@ -45,12 +46,16 @@
|
|
|
45
46
|
* chainId: parseInt(action.signatureChainId, 16),
|
|
46
47
|
* });
|
|
47
48
|
* ```
|
|
49
|
+
*
|
|
48
50
|
* @module
|
|
49
51
|
*/
|
|
52
|
+
import "../_dnt.polyfills.js";
|
|
50
53
|
import { type ValueMap, type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
51
54
|
import type { Hex } from "./base.js";
|
|
52
55
|
export type { Hex };
|
|
53
56
|
export type { ValueMap, ValueType };
|
|
57
|
+
/** Abstract interface for a wallet that can sign typed data. */
|
|
58
|
+
export type AbstractWallet = AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
|
|
54
59
|
/** Abstract interface for a [viem wallet](https://viem.sh/docs/clients/wallet). */
|
|
55
60
|
export interface AbstractViemWalletClient {
|
|
56
61
|
signTypedData(params: {
|
|
@@ -98,7 +103,7 @@ export interface AbstractEthersV5Signer {
|
|
|
98
103
|
}[];
|
|
99
104
|
}, value: Record<string, unknown>): Promise<string>;
|
|
100
105
|
}
|
|
101
|
-
/** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/
|
|
106
|
+
/** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/wallets/using-wallets/ethereum/sign-typed-data)). */
|
|
102
107
|
export interface AbstractExtendedViemWalletClient {
|
|
103
108
|
signTypedData(params: {
|
|
104
109
|
domain: {
|
|
@@ -146,7 +151,7 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
|
|
|
146
151
|
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
147
152
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
148
153
|
*
|
|
149
|
-
* const wallet = privateKeyToAccount("0x..."); //
|
|
154
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
150
155
|
*
|
|
151
156
|
* const action = {
|
|
152
157
|
* type: "cancel",
|
|
@@ -173,7 +178,7 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
|
|
|
173
178
|
*/
|
|
174
179
|
export declare function signL1Action(args: {
|
|
175
180
|
/** Wallet to sign the action. */
|
|
176
|
-
wallet:
|
|
181
|
+
wallet: AbstractWallet;
|
|
177
182
|
/** The action to be signed. */
|
|
178
183
|
action: ValueType;
|
|
179
184
|
/** Unique request identifier (recommended current timestamp in ms). */
|
|
@@ -193,6 +198,7 @@ export declare function signL1Action(args: {
|
|
|
193
198
|
* Sign a user-signed action.
|
|
194
199
|
*
|
|
195
200
|
* Note: Signature generation depends on the order of types.
|
|
201
|
+
*
|
|
196
202
|
* @param args - Arguments for signing the action.
|
|
197
203
|
* @returns The signature components r, s, and v.
|
|
198
204
|
* @example
|
|
@@ -200,7 +206,7 @@ export declare function signL1Action(args: {
|
|
|
200
206
|
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
201
207
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
202
208
|
*
|
|
203
|
-
* const wallet = privateKeyToAccount("0x..."); //
|
|
209
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
204
210
|
*
|
|
205
211
|
* const action = {
|
|
206
212
|
* type: "approveAgent",
|
|
@@ -235,7 +241,7 @@ export declare function signL1Action(args: {
|
|
|
235
241
|
*/
|
|
236
242
|
export declare function signUserSignedAction(args: {
|
|
237
243
|
/** Wallet to sign the action. */
|
|
238
|
-
wallet:
|
|
244
|
+
wallet: AbstractWallet;
|
|
239
245
|
/** The action to be signed. */
|
|
240
246
|
action: Record<string, unknown>;
|
|
241
247
|
/** The types of the action. */
|
|
@@ -252,6 +258,75 @@ export declare function signUserSignedAction(args: {
|
|
|
252
258
|
s: Hex;
|
|
253
259
|
v: number;
|
|
254
260
|
}>;
|
|
261
|
+
/**
|
|
262
|
+
* Sign a multi-signature action.
|
|
263
|
+
*
|
|
264
|
+
* Note: Signature generation depends on the order of the action keys.
|
|
265
|
+
*
|
|
266
|
+
* @param args - Arguments for signing the action.
|
|
267
|
+
* @returns The signature components r, s, and v.
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* import { signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
271
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
272
|
+
*
|
|
273
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
274
|
+
* const multiSigUser = "0x..."; // Multi-sig user address
|
|
275
|
+
*
|
|
276
|
+
* const nonce = Date.now();
|
|
277
|
+
* const action = { // Example action
|
|
278
|
+
* type: "scheduleCancel",
|
|
279
|
+
* time: Date.now() + 10000
|
|
280
|
+
* };
|
|
281
|
+
*
|
|
282
|
+
* // First, create signature from one of the authorized signers
|
|
283
|
+
* const signature = await signL1Action({
|
|
284
|
+
* wallet,
|
|
285
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
286
|
+
* nonce,
|
|
287
|
+
* isTestnet: true,
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Then use it in the multi-sig action
|
|
291
|
+
* const multiSigSignature = await signMultiSigAction({
|
|
292
|
+
* wallet,
|
|
293
|
+
* action: {
|
|
294
|
+
* type: "multiSig",
|
|
295
|
+
* signatureChainId: "0x66eee",
|
|
296
|
+
* signatures: [signature],
|
|
297
|
+
* payload: {
|
|
298
|
+
* multiSigUser,
|
|
299
|
+
* outerSigner: wallet.address,
|
|
300
|
+
* action,
|
|
301
|
+
* }
|
|
302
|
+
* },
|
|
303
|
+
* nonce,
|
|
304
|
+
* hyperliquidChain: "Testnet",
|
|
305
|
+
* signatureChainId: "0x66eee",
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
* @unstable May not behave as expected and the interface may change in the future.
|
|
309
|
+
*/
|
|
310
|
+
export declare function signMultiSigAction(args: {
|
|
311
|
+
/** Wallet to sign the action. */
|
|
312
|
+
wallet: AbstractWallet;
|
|
313
|
+
/** The action to be signed. */
|
|
314
|
+
action: ValueMap;
|
|
315
|
+
/** Unique request identifier (recommended current timestamp in ms). */
|
|
316
|
+
nonce: number;
|
|
317
|
+
/** Optional vault address used in the action. */
|
|
318
|
+
vaultAddress?: Hex;
|
|
319
|
+
/** Optional expiration time of the action in milliseconds since the epoch. */
|
|
320
|
+
expiresAfter?: number;
|
|
321
|
+
/** HyperLiquid network ("Mainnet" or "Testnet"). */
|
|
322
|
+
hyperliquidChain: "Mainnet" | "Testnet";
|
|
323
|
+
/** Chain ID used for signing. */
|
|
324
|
+
signatureChainId: Hex;
|
|
325
|
+
}): Promise<{
|
|
326
|
+
r: Hex;
|
|
327
|
+
s: Hex;
|
|
328
|
+
v: number;
|
|
329
|
+
}>;
|
|
255
330
|
/** Checks if the given value is an abstract viem wallet. */
|
|
256
331
|
export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
|
|
257
332
|
/** Checks if the given value is an abstract ethers signer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,OAAO,sBAAsB,CAAC;AAI9B,OAAO,EAA2B,KAAK,QAAQ,EAAE,KA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,CAAC,IAAI,EAAE;IAC3C,iCAAiC;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,+BAA+B;IAC/B,MAAM,EAAE,QAAQ,CAAC;IACjB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC;IACxC,iCAAiC;IACjC,gBAAgB,EAAE,GAAG,CAAC;CACzB,GAAG,OAAO,CAAC;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA+BzC;AAoGD,4DAA4D;AAC5D,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAI9F;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,oBAAoB,CAItF;AAED,iEAAiE;AACjE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F;AAED,qGAAqG;AACrG,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAItG;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F"}
|
package/script/src/signing.js
CHANGED
|
@@ -1,59 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
|
-
* and interfaces to various wallet implementations.
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
7
|
-
*
|
|
8
|
-
* const action = {
|
|
9
|
-
* type: "cancel",
|
|
10
|
-
* cancels: [{ a: 0, o: 12345 }],
|
|
11
|
-
* };
|
|
12
|
-
* const nonce = Date.now();
|
|
13
|
-
*
|
|
14
|
-
* const signature = await signL1Action({
|
|
15
|
-
* wallet,
|
|
16
|
-
* action,
|
|
17
|
-
* nonce,
|
|
18
|
-
* isTestnet: true, // Change to false for mainnet
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
24
|
-
*
|
|
25
|
-
* const action = {
|
|
26
|
-
* type: "approveAgent",
|
|
27
|
-
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
28
|
-
* signatureChainId: "0x66eee",
|
|
29
|
-
* nonce: Date.now(),
|
|
30
|
-
* agentAddress: "0x...",
|
|
31
|
-
* agentName: "Agent",
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* const signature = await signUserSignedAction({
|
|
35
|
-
* wallet,
|
|
36
|
-
* action,
|
|
37
|
-
* types: {
|
|
38
|
-
* "HyperliquidTransaction:ApproveAgent": [
|
|
39
|
-
* { name: "hyperliquidChain", type: "string" },
|
|
40
|
-
* { name: "agentAddress", type: "address" },
|
|
41
|
-
* { name: "agentName", type: "string" },
|
|
42
|
-
* { name: "nonce", type: "uint64" },
|
|
43
|
-
* ],
|
|
44
|
-
* },
|
|
45
|
-
* chainId: parseInt(action.signatureChainId, 16),
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
* @module
|
|
49
|
-
*/
|
|
50
1
|
(function (factory) {
|
|
51
2
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
52
3
|
var v = factory(require, exports);
|
|
53
4
|
if (v !== undefined) module.exports = v;
|
|
54
5
|
}
|
|
55
6
|
else if (typeof define === "function" && define.amd) {
|
|
56
|
-
define(["require", "exports", "../
|
|
7
|
+
define(["require", "exports", "../_dnt.polyfills.js", "@noble/hashes/sha3", "../deps/jsr.io/@std/msgpack/1.0.3/encode.js", "../deps/jsr.io/@std/encoding/1.0.10/hex.js", "../deps/jsr.io/@std/bytes/1.0.6/concat.js"], factory);
|
|
57
8
|
}
|
|
58
9
|
})(function (require, exports) {
|
|
59
10
|
"use strict";
|
|
@@ -61,12 +12,65 @@
|
|
|
61
12
|
exports.createL1ActionHash = createL1ActionHash;
|
|
62
13
|
exports.signL1Action = signL1Action;
|
|
63
14
|
exports.signUserSignedAction = signUserSignedAction;
|
|
15
|
+
exports.signMultiSigAction = signMultiSigAction;
|
|
64
16
|
exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
|
|
65
17
|
exports.isAbstractEthersSigner = isAbstractEthersSigner;
|
|
66
18
|
exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
|
|
67
19
|
exports.isAbstractExtendedViemWalletClient = isAbstractExtendedViemWalletClient;
|
|
68
20
|
exports.isAbstractWindowEthereum = isAbstractWindowEthereum;
|
|
69
|
-
|
|
21
|
+
/**
|
|
22
|
+
* This module contains functions for generating Hyperliquid transaction signatures
|
|
23
|
+
* and interfaces to various wallet implementations.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
28
|
+
*
|
|
29
|
+
* const action = {
|
|
30
|
+
* type: "cancel",
|
|
31
|
+
* cancels: [{ a: 0, o: 12345 }],
|
|
32
|
+
* };
|
|
33
|
+
* const nonce = Date.now();
|
|
34
|
+
*
|
|
35
|
+
* const signature = await signL1Action({
|
|
36
|
+
* wallet,
|
|
37
|
+
* action,
|
|
38
|
+
* nonce,
|
|
39
|
+
* isTestnet: true, // Change to false for mainnet
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
45
|
+
*
|
|
46
|
+
* const action = {
|
|
47
|
+
* type: "approveAgent",
|
|
48
|
+
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
49
|
+
* signatureChainId: "0x66eee",
|
|
50
|
+
* nonce: Date.now(),
|
|
51
|
+
* agentAddress: "0x...",
|
|
52
|
+
* agentName: "Agent",
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* const signature = await signUserSignedAction({
|
|
56
|
+
* wallet,
|
|
57
|
+
* action,
|
|
58
|
+
* types: {
|
|
59
|
+
* "HyperliquidTransaction:ApproveAgent": [
|
|
60
|
+
* { name: "hyperliquidChain", type: "string" },
|
|
61
|
+
* { name: "agentAddress", type: "address" },
|
|
62
|
+
* { name: "agentName", type: "string" },
|
|
63
|
+
* { name: "nonce", type: "uint64" },
|
|
64
|
+
* ],
|
|
65
|
+
* },
|
|
66
|
+
* chainId: parseInt(action.signatureChainId, 16),
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
require("../_dnt.polyfills.js");
|
|
73
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
70
74
|
const encode_js_1 = require("../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
|
|
71
75
|
const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.10/hex.js");
|
|
72
76
|
const concat_js_1 = require("../deps/jsr.io/@std/bytes/1.0.6/concat.js");
|
|
@@ -87,14 +91,28 @@
|
|
|
87
91
|
const nonceBytes = new Uint8Array(8);
|
|
88
92
|
new DataView(nonceBytes.buffer).setBigUint64(0, BigInt(nonce));
|
|
89
93
|
// 3. Vault address
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
let vaultMarker;
|
|
95
|
+
let vaultBytes;
|
|
96
|
+
if (vaultAddress) {
|
|
97
|
+
vaultMarker = Uint8Array.of(1);
|
|
98
|
+
vaultBytes = (0, hex_js_1.decodeHex)(vaultAddress.slice(2));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
vaultMarker = new Uint8Array(1);
|
|
102
|
+
vaultBytes = new Uint8Array();
|
|
103
|
+
}
|
|
92
104
|
// 4. Expires after
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
let expiresMarker;
|
|
106
|
+
let expiresBytes;
|
|
95
107
|
if (expiresAfter !== undefined) {
|
|
108
|
+
expiresMarker = new Uint8Array(1);
|
|
109
|
+
expiresBytes = new Uint8Array(8);
|
|
96
110
|
new DataView(expiresBytes.buffer).setBigUint64(0, BigInt(expiresAfter));
|
|
97
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
expiresMarker = new Uint8Array();
|
|
114
|
+
expiresBytes = new Uint8Array();
|
|
115
|
+
}
|
|
98
116
|
// Create a keccak256 hash
|
|
99
117
|
const chunks = [
|
|
100
118
|
actionBytes,
|
|
@@ -105,7 +123,7 @@
|
|
|
105
123
|
expiresBytes,
|
|
106
124
|
];
|
|
107
125
|
const bytes = (0, concat_js_1.concat)(chunks);
|
|
108
|
-
const hash = (0,
|
|
126
|
+
const hash = (0, sha3_1.keccak_256)(bytes);
|
|
109
127
|
return `0x${(0, hex_js_1.encodeHex)(hash)}`;
|
|
110
128
|
}
|
|
111
129
|
/** Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}. */
|
|
@@ -136,7 +154,7 @@
|
|
|
136
154
|
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
137
155
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
138
156
|
*
|
|
139
|
-
* const wallet = privateKeyToAccount("0x..."); //
|
|
157
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
140
158
|
*
|
|
141
159
|
* const action = {
|
|
142
160
|
* type: "cancel",
|
|
@@ -187,6 +205,7 @@
|
|
|
187
205
|
* Sign a user-signed action.
|
|
188
206
|
*
|
|
189
207
|
* Note: Signature generation depends on the order of types.
|
|
208
|
+
*
|
|
190
209
|
* @param args - Arguments for signing the action.
|
|
191
210
|
* @returns The signature components r, s, and v.
|
|
192
211
|
* @example
|
|
@@ -194,7 +213,7 @@
|
|
|
194
213
|
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
195
214
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
196
215
|
*
|
|
197
|
-
* const wallet = privateKeyToAccount("0x..."); //
|
|
216
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
198
217
|
*
|
|
199
218
|
* const action = {
|
|
200
219
|
* type: "approveAgent",
|
|
@@ -238,6 +257,77 @@
|
|
|
238
257
|
const signature = await abstractSignTypedData({ wallet, domain, types, message: action });
|
|
239
258
|
return splitSignature(signature);
|
|
240
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Sign a multi-signature action.
|
|
262
|
+
*
|
|
263
|
+
* Note: Signature generation depends on the order of the action keys.
|
|
264
|
+
*
|
|
265
|
+
* @param args - Arguments for signing the action.
|
|
266
|
+
* @returns The signature components r, s, and v.
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* import { signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
270
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
271
|
+
*
|
|
272
|
+
* const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
273
|
+
* const multiSigUser = "0x..."; // Multi-sig user address
|
|
274
|
+
*
|
|
275
|
+
* const nonce = Date.now();
|
|
276
|
+
* const action = { // Example action
|
|
277
|
+
* type: "scheduleCancel",
|
|
278
|
+
* time: Date.now() + 10000
|
|
279
|
+
* };
|
|
280
|
+
*
|
|
281
|
+
* // First, create signature from one of the authorized signers
|
|
282
|
+
* const signature = await signL1Action({
|
|
283
|
+
* wallet,
|
|
284
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
285
|
+
* nonce,
|
|
286
|
+
* isTestnet: true,
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* // Then use it in the multi-sig action
|
|
290
|
+
* const multiSigSignature = await signMultiSigAction({
|
|
291
|
+
* wallet,
|
|
292
|
+
* action: {
|
|
293
|
+
* type: "multiSig",
|
|
294
|
+
* signatureChainId: "0x66eee",
|
|
295
|
+
* signatures: [signature],
|
|
296
|
+
* payload: {
|
|
297
|
+
* multiSigUser,
|
|
298
|
+
* outerSigner: wallet.address,
|
|
299
|
+
* action,
|
|
300
|
+
* }
|
|
301
|
+
* },
|
|
302
|
+
* nonce,
|
|
303
|
+
* hyperliquidChain: "Testnet",
|
|
304
|
+
* signatureChainId: "0x66eee",
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
* @unstable May not behave as expected and the interface may change in the future.
|
|
308
|
+
*/
|
|
309
|
+
async function signMultiSigAction(args) {
|
|
310
|
+
const { wallet, action, nonce, hyperliquidChain, signatureChainId, vaultAddress, expiresAfter, } = args;
|
|
311
|
+
const multiSigActionHash = createL1ActionHash(action, nonce, vaultAddress, expiresAfter);
|
|
312
|
+
const message = {
|
|
313
|
+
multiSigActionHash,
|
|
314
|
+
hyperliquidChain,
|
|
315
|
+
signatureChainId,
|
|
316
|
+
nonce,
|
|
317
|
+
};
|
|
318
|
+
return await signUserSignedAction({
|
|
319
|
+
wallet,
|
|
320
|
+
action: message,
|
|
321
|
+
types: {
|
|
322
|
+
"HyperliquidTransaction:SendMultiSig": [
|
|
323
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
324
|
+
{ name: "multiSigActionHash", type: "bytes32" },
|
|
325
|
+
{ name: "nonce", type: "uint64" },
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
chainId: parseInt(signatureChainId, 16),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
241
331
|
/** Signs typed data with the provided wallet using EIP-712. */
|
|
242
332
|
async function abstractSignTypedData(args) {
|
|
243
333
|
const { wallet, domain, types, message } = args;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HyperliquidError } from "../base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a REST transport.
|
|
4
|
+
*
|
|
5
|
+
* Handles communication with Hyperliquid API endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint | Info endpoint}
|
|
8
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint | Exchange endpoint}
|
|
9
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests | Websocket post requests}
|
|
10
|
+
*/
|
|
11
|
+
export interface IRequestTransport extends Partial<AsyncDisposable> {
|
|
12
|
+
/**
|
|
13
|
+
* Sends a request to the Hyperliquid API.
|
|
14
|
+
* @param endpoint - The API endpoint to send the request to.
|
|
15
|
+
* @param payload - The payload to send with the request.
|
|
16
|
+
* @param signal - An ptional abort signal.
|
|
17
|
+
* @returns A promise that resolves with parsed JSON response body.
|
|
18
|
+
*/
|
|
19
|
+
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Interface representing an event subscription transport.
|
|
23
|
+
* Handles WebSocket subscriptions for real-time updates.
|
|
24
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Websocket subscriptions}
|
|
25
|
+
*/
|
|
26
|
+
export interface ISubscriptionTransport extends Partial<AsyncDisposable> {
|
|
27
|
+
/**
|
|
28
|
+
* Subscribes to a Hyperliquid event channel.
|
|
29
|
+
* @param channel - The event channel to listen to.
|
|
30
|
+
* @param payload - The payload to send with the subscription request.
|
|
31
|
+
* @param listener - The function to call when the event is dispatched.
|
|
32
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
33
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
34
|
+
*/
|
|
35
|
+
subscribe<T>(channel: string, payload: unknown, listener: (data: CustomEvent<T>) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
36
|
+
}
|
|
37
|
+
/** Controls event subscription lifecycle. */
|
|
38
|
+
export interface Subscription {
|
|
39
|
+
/**
|
|
40
|
+
* Unsubscribes from the event and sends an unsubscribe request to the server.
|
|
41
|
+
* @param signal - An optional abort signal for canceling the unsubscribe request.
|
|
42
|
+
*/
|
|
43
|
+
unsubscribe(signal?: AbortSignal): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/** Base class for all transport-related errors. */
|
|
46
|
+
export declare class TransportError extends HyperliquidError {
|
|
47
|
+
constructor(message?: string);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC/D;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9G;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,eAAe,CAAC;IACpE;;;;;;;OAOG;IACH,SAAS,CAAC,CAAC,EACP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EACxC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5B;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED,mDAAmD;AACnD,qBAAa,cAAe,SAAQ,gBAAgB;gBACpC,OAAO,CAAC,EAAE,MAAM;CAI/B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../base.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TransportError = void 0;
|
|
13
|
+
const base_js_1 = require("../base.js");
|
|
14
|
+
/** Base class for all transport-related errors. */
|
|
15
|
+
class TransportError extends base_js_1.HyperliquidError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "TransportError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TransportError = TransportError;
|
|
22
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { MaybePromise } from "../../base.js";
|
|
2
|
+
import { type IRequestTransport, TransportError } from "../base.js";
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when an HTTP response is deemed invalid:
|
|
4
5
|
* - Non-200 status code
|
|
@@ -22,12 +23,14 @@ export interface HttpTransportOptions {
|
|
|
22
23
|
*/
|
|
23
24
|
isTestnet?: boolean;
|
|
24
25
|
/**
|
|
25
|
-
* Request timeout in ms.
|
|
26
|
-
* Set to `null` to disable.
|
|
26
|
+
* Request timeout in ms. Set to `null` to disable.
|
|
27
27
|
* @defaultValue `10_000`
|
|
28
28
|
*/
|
|
29
29
|
timeout?: number | null;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Custom server to use for API requests.
|
|
32
|
+
* @defaultValue `https://api.hyperliquid.xyz` for mainnet and `https://api.hyperliquid-testnet.xyz` for testnet.
|
|
33
|
+
*/
|
|
31
34
|
server?: {
|
|
32
35
|
mainnet?: {
|
|
33
36
|
api?: string | URL;
|
|
@@ -84,6 +87,6 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
84
87
|
* @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
|
|
85
88
|
* @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
|
|
86
89
|
*/
|
|
87
|
-
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<
|
|
90
|
+
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
88
91
|
}
|
|
89
92
|
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc;IAM7B,QAAQ,EAAE,QAAQ;IAAS,YAAY,CAAC,EAAE,MAAM;IALnE;;;;OAIG;gBACgB,QAAQ,EAAE,QAAQ,EAAS,YAAY,CAAC,EAAE,MAAM,YAAA;CAOtE;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;O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