@nktkas/hyperliquid 0.22.2 → 0.23.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/README.md +79 -67
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/base.d.ts +4 -1
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +2 -2
- package/esm/src/clients/exchange.d.ts +289 -207
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +605 -410
- package/esm/src/clients/info.d.ts +264 -48
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +273 -31
- package/esm/src/clients/multiSign.d.ts +285 -204
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +521 -493
- package/esm/src/clients/subscription.d.ts +38 -3
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +36 -3
- package/esm/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.js +59 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/private_key.js +144 -0
- package/esm/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/{script/src/signing/_window.d.ts → esm/src/signing/_signTypedData/window.d.ts} +18 -12
- package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/esm/src/signing/{_window.js → _signTypedData/window.js} +3 -2
- package/esm/src/signing/_sorter.d.ts +56 -82
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +36 -49
- package/esm/src/signing/mod.d.ts +151 -130
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -228
- package/esm/src/transports/base.d.ts +1 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/base.js +2 -2
- package/esm/src/transports/http/http_transport.d.ts +9 -15
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +64 -59
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
- package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +83 -54
- package/esm/src/types/exchange/requests.d.ts +27 -51
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +5 -8
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +5 -5
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +6 -0
- package/esm/src/types/info/markets.d.ts.map +1 -1
- 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 +129 -124
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/{script/src/types/info/delegations.d.ts → esm/src/types/info/validators.d.ts} +2 -2
- package/esm/src/types/info/validators.d.ts.map +1 -0
- package/esm/src/types/info/vaults.d.ts +7 -0
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +1 -1
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +72 -18
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +2 -0
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +8 -5
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +13 -23
- package/script/src/base.d.ts +4 -1
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +10 -20
- package/script/src/clients/exchange.d.ts +289 -207
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +2000 -1815
- package/script/src/clients/info.d.ts +264 -48
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +1442 -1210
- package/script/src/clients/multiSign.d.ts +285 -204
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +2043 -2025
- package/script/src/clients/subscription.d.ts +38 -3
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +568 -545
- package/script/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/ethers.js +16 -0
- package/script/src/signing/_signTypedData/mod.d.ts +35 -0
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/mod.js +67 -0
- package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/private_key.js +148 -0
- package/script/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/viem.js +9 -0
- package/{esm/src/signing/_window.d.ts → script/src/signing/_signTypedData/window.d.ts} +18 -12
- package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/window.js +34 -0
- package/script/src/signing/_sorter.d.ts +56 -82
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +655 -678
- package/script/src/signing/mod.d.ts +151 -130
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +286 -342
- package/script/src/transports/base.d.ts +1 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/base.js +11 -21
- package/script/src/transports/http/http_transport.d.ts +9 -15
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +97 -102
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
- package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +157 -174
- package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +209 -189
- package/script/src/types/exchange/requests.d.ts +27 -51
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +2 -12
- package/script/src/types/exchange/responses.js +2 -12
- package/script/src/types/explorer/requests.d.ts +5 -8
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +2 -12
- package/script/src/types/explorer/responses.js +2 -12
- package/script/src/types/info/accounts.d.ts +5 -5
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +2 -12
- package/script/src/types/info/assets.js +2 -12
- package/script/src/types/info/markets.d.ts +6 -0
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/markets.js +2 -12
- 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/orders.js +2 -12
- package/script/src/types/info/requests.d.ts +129 -124
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +2 -12
- package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +2 -2
- package/script/src/types/info/validators.d.ts.map +1 -0
- package/script/src/types/info/validators.js +2 -0
- package/script/src/types/info/vaults.d.ts +7 -0
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +2 -12
- package/script/src/types/mod.d.ts +1 -1
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +2 -12
- package/script/src/types/subscriptions/requests.d.ts +72 -18
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +2 -12
- package/script/src/types/subscriptions/responses.d.ts +2 -0
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.js +2 -12
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
- package/esm/src/signing/_ethers.d.ts.map +0 -1
- package/esm/src/signing/_private_key.d.ts +0 -22
- package/esm/src/signing/_private_key.d.ts.map +0 -1
- package/esm/src/signing/_private_key.js +0 -124
- package/esm/src/signing/_viem.d.ts.map +0 -1
- package/esm/src/signing/_window.d.ts.map +0 -1
- package/esm/src/types/info/delegations.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
- package/script/src/signing/_ethers.d.ts.map +0 -1
- package/script/src/signing/_ethers.js +0 -26
- package/script/src/signing/_private_key.d.ts +0 -22
- package/script/src/signing/_private_key.d.ts.map +0 -1
- package/script/src/signing/_private_key.js +0 -138
- package/script/src/signing/_viem.d.ts.map +0 -1
- package/script/src/signing/_viem.js +0 -19
- package/script/src/signing/_window.d.ts.map +0 -1
- package/script/src/signing/_window.js +0 -43
- package/script/src/types/info/delegations.d.ts.map +0 -1
- package/script/src/types/info/delegations.js +0 -12
- /package/esm/src/signing/{_ethers.js → _signTypedData/ethers.js} +0 -0
- /package/esm/src/signing/{_viem.js → _signTypedData/viem.js} +0 -0
- /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
package/esm/src/signing/mod.d.ts
CHANGED
|
@@ -2,108 +2,148 @@
|
|
|
2
2
|
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
3
|
* and interfaces to various wallet implementations.
|
|
4
4
|
*
|
|
5
|
-
* @example
|
|
5
|
+
* @example Signing an L1 action
|
|
6
6
|
* ```ts
|
|
7
|
-
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
7
|
+
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
8
|
+
*
|
|
9
|
+
* const privateKey = "0x..."; // or `viem`, `ethers`
|
|
8
10
|
*
|
|
9
|
-
* const action = {
|
|
10
|
-
* type: "cancel",
|
|
11
|
-
* cancels: [{ a: 0, o: 12345 }],
|
|
12
|
-
* };
|
|
13
11
|
* const nonce = Date.now();
|
|
12
|
+
* const action = {
|
|
13
|
+
* type: "cancel",
|
|
14
|
+
* cancels: [
|
|
15
|
+
* { a: 0, o: 12345 },
|
|
16
|
+
* ],
|
|
17
|
+
* } as const;
|
|
14
18
|
*
|
|
15
19
|
* const signature = await signL1Action({
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* isTestnet: true, // Change to false for mainnet
|
|
20
|
+
* wallet: privateKey,
|
|
21
|
+
* action: actionSorter[action.type](action),
|
|
22
|
+
* nonce,
|
|
20
23
|
* });
|
|
21
24
|
* ```
|
|
22
|
-
*
|
|
25
|
+
*
|
|
26
|
+
* @example Signing a user-signed action
|
|
23
27
|
* ```ts
|
|
24
|
-
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
28
|
+
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
29
|
+
*
|
|
30
|
+
* const privateKey = "0x..."; // or `viem`, `ethers`
|
|
25
31
|
*
|
|
26
32
|
* const action = {
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* };
|
|
33
|
+
* type: "approveAgent",
|
|
34
|
+
* signatureChainId: "0x66eee",
|
|
35
|
+
* hyperliquidChain: "Mainnet",
|
|
36
|
+
* agentAddress: "0x...",
|
|
37
|
+
* agentName: "Agent",
|
|
38
|
+
* nonce: Date.now(),
|
|
39
|
+
* } as const;
|
|
34
40
|
*
|
|
35
41
|
* const signature = await signUserSignedAction({
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
42
|
+
* wallet: privateKey,
|
|
43
|
+
* action,
|
|
44
|
+
* types: userSignedActionEip712Types[action.type],
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Signing a multi-signature action
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
51
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
52
|
+
*
|
|
53
|
+
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key with address
|
|
54
|
+
* const multiSigUser = "0x...";
|
|
55
|
+
*
|
|
56
|
+
* const nonce = Date.now();
|
|
57
|
+
* const action = {
|
|
58
|
+
* type: "scheduleCancel",
|
|
59
|
+
* time: Date.now() + 10000,
|
|
60
|
+
* } as const;
|
|
61
|
+
*
|
|
62
|
+
* // First, create the required number of signatures
|
|
63
|
+
* const signature = await signL1Action({
|
|
64
|
+
* wallet,
|
|
65
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
66
|
+
* nonce,
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Then use signatures in the multi-sig action
|
|
70
|
+
* const multiSigSignature = await signMultiSigAction({
|
|
71
|
+
* wallet,
|
|
72
|
+
* action: {
|
|
73
|
+
* signatureChainId: "0x66eee",
|
|
74
|
+
* signatures: [signature],
|
|
75
|
+
* payload: {
|
|
76
|
+
* multiSigUser,
|
|
77
|
+
* outerSigner: wallet.address,
|
|
78
|
+
* action,
|
|
79
|
+
* },
|
|
80
|
+
* },
|
|
81
|
+
* nonce,
|
|
47
82
|
* });
|
|
48
83
|
* ```
|
|
49
84
|
*
|
|
50
85
|
* @module
|
|
51
86
|
*/
|
|
52
|
-
import { type ValueMap, type ValueType } from "../../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
53
|
-
import { type AbstractEthersSigner, type AbstractEthersV5Signer, isAbstractEthersSigner, isAbstractEthersV5Signer } from "./_ethers.js";
|
|
54
|
-
import { isValidPrivateKey } from "./_private_key.js";
|
|
55
|
-
import { type AbstractViemWalletClient, isAbstractViemWalletClient } from "./_viem.js";
|
|
56
|
-
import { type AbstractWindowEthereum, isAbstractWindowEthereum } from "./_window.js";
|
|
57
87
|
import type { Hex } from "../base.js";
|
|
58
|
-
|
|
88
|
+
import { type AbstractEthersSigner, type AbstractEthersV5Signer, type AbstractViemWalletClient, type AbstractWallet, type AbstractWindowEthereum, isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, isValidPrivateKey, type Signature } from "./_signTypedData/mod.js";
|
|
89
|
+
export { type AbstractEthersSigner, type AbstractEthersV5Signer, type AbstractViemWalletClient, type AbstractWallet, type AbstractWindowEthereum, type Hex, isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, isValidPrivateKey, type Signature, };
|
|
59
90
|
export * from "./_sorter.js";
|
|
60
|
-
/** Abstract interface for a wallet that can sign typed data. */
|
|
61
|
-
export type AbstractWallet = Hex | AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractWindowEthereum;
|
|
62
|
-
export interface Signature {
|
|
63
|
-
r: Hex;
|
|
64
|
-
s: Hex;
|
|
65
|
-
v: number;
|
|
66
|
-
}
|
|
67
91
|
/**
|
|
68
92
|
* Create a hash of the L1 action.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { actionSorter, createL1ActionHash } from "@nktkas/hyperliquid/signing";
|
|
69
96
|
*
|
|
70
|
-
*
|
|
97
|
+
* const action = {
|
|
98
|
+
* type: "cancel",
|
|
99
|
+
* cancels: [
|
|
100
|
+
* { a: 0, o: 12345 },
|
|
101
|
+
* ],
|
|
102
|
+
* } as const;
|
|
103
|
+
* const nonce = Date.now();
|
|
71
104
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
105
|
+
* const actionHash = createL1ActionHash({
|
|
106
|
+
* action: actionSorter[action.type](action),
|
|
107
|
+
* nonce,
|
|
108
|
+
* vaultAddress: "0x...", // optional
|
|
109
|
+
* expiresAfter: Date.now() + 10_000, // optional
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
77
112
|
*/
|
|
78
|
-
export declare function createL1ActionHash(
|
|
113
|
+
export declare function createL1ActionHash(args: {
|
|
114
|
+
/** The action to be hashed (hash depends on key order). */
|
|
115
|
+
action: Record<string, unknown> | unknown[];
|
|
116
|
+
/** The current timestamp in ms. */
|
|
117
|
+
nonce: number;
|
|
118
|
+
/** Optional vault address used in the action. */
|
|
119
|
+
vaultAddress?: Hex;
|
|
120
|
+
/** Optional expiration time of the action in ms since the epoch. */
|
|
121
|
+
expiresAfter?: number;
|
|
122
|
+
}): Hex;
|
|
79
123
|
/**
|
|
80
124
|
* Sign an L1 action.
|
|
81
|
-
*
|
|
82
|
-
* Note: Signature generation depends on the order of the action keys.
|
|
83
|
-
* @param args - Arguments for signing the action.
|
|
84
|
-
* @returns The signature components r, s, and v.
|
|
85
125
|
* @example
|
|
86
126
|
* ```ts
|
|
87
|
-
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
127
|
+
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
88
128
|
*
|
|
89
129
|
* const privateKey = "0x..."; // or `viem`, `ethers`
|
|
90
130
|
*
|
|
131
|
+
* const nonce = Date.now();
|
|
91
132
|
* const action = {
|
|
92
133
|
* type: "cancel",
|
|
93
134
|
* cancels: [
|
|
94
|
-
* { a: 0, o: 12345 },
|
|
135
|
+
* { a: 0, o: 12345 },
|
|
95
136
|
* ],
|
|
96
|
-
* };
|
|
97
|
-
* const nonce = Date.now();
|
|
137
|
+
* } as const;
|
|
98
138
|
*
|
|
99
139
|
* const signature = await signL1Action({
|
|
100
140
|
* wallet: privateKey,
|
|
101
|
-
* action,
|
|
141
|
+
* action: actionSorter[action.type](action),
|
|
102
142
|
* nonce,
|
|
103
|
-
* isTestnet: true, // Change to false for mainnet
|
|
104
143
|
* });
|
|
105
144
|
*
|
|
106
|
-
*
|
|
145
|
+
* // Send the signed action to the Hyperliquid API
|
|
146
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
107
147
|
* method: "POST",
|
|
108
148
|
* headers: { "Content-Type": "application/json" },
|
|
109
149
|
* body: JSON.stringify({ action, signature, nonce }),
|
|
@@ -114,54 +154,42 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
|
|
|
114
154
|
export declare function signL1Action(args: {
|
|
115
155
|
/** Wallet to sign the action. */
|
|
116
156
|
wallet: AbstractWallet;
|
|
117
|
-
/** The action to be signed. */
|
|
118
|
-
action:
|
|
119
|
-
/**
|
|
157
|
+
/** The action to be signed (hash depends on key order). */
|
|
158
|
+
action: Record<string, unknown> | unknown[];
|
|
159
|
+
/** The current timestamp in ms. */
|
|
120
160
|
nonce: number;
|
|
121
|
-
/** Indicates if the action is for the testnet.
|
|
161
|
+
/** Indicates if the action is for the testnet. (default: false) */
|
|
122
162
|
isTestnet?: boolean;
|
|
123
163
|
/** Optional vault address used in the action. */
|
|
124
164
|
vaultAddress?: Hex;
|
|
125
|
-
/** Optional expiration time of the action in
|
|
165
|
+
/** Optional expiration time of the action in ms since the epoch. */
|
|
126
166
|
expiresAfter?: number;
|
|
127
167
|
}): Promise<Signature>;
|
|
128
168
|
/**
|
|
129
169
|
* Sign a user-signed action.
|
|
130
|
-
*
|
|
131
|
-
* Note: Signature generation depends on the order of types.
|
|
132
|
-
*
|
|
133
|
-
* @param args - Arguments for signing the action.
|
|
134
|
-
* @returns The signature components r, s, and v.
|
|
135
170
|
* @example
|
|
136
171
|
* ```ts
|
|
137
|
-
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
172
|
+
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
138
173
|
*
|
|
139
174
|
* const privateKey = "0x..."; // or `viem`, `ethers`
|
|
140
175
|
*
|
|
141
176
|
* const action = {
|
|
142
177
|
* type: "approveAgent",
|
|
143
|
-
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
144
178
|
* signatureChainId: "0x66eee",
|
|
145
|
-
*
|
|
146
|
-
* agentAddress: "0x...",
|
|
179
|
+
* hyperliquidChain: "Mainnet",
|
|
180
|
+
* agentAddress: "0x...",
|
|
147
181
|
* agentName: "Agent",
|
|
148
|
-
*
|
|
182
|
+
* nonce: Date.now(),
|
|
183
|
+
* } as const;
|
|
149
184
|
*
|
|
150
185
|
* const signature = await signUserSignedAction({
|
|
151
186
|
* wallet: privateKey,
|
|
152
187
|
* action,
|
|
153
|
-
* types:
|
|
154
|
-
* "HyperliquidTransaction:ApproveAgent": [
|
|
155
|
-
* { name: "hyperliquidChain", type: "string" },
|
|
156
|
-
* { name: "agentAddress", type: "address" },
|
|
157
|
-
* { name: "agentName", type: "string" },
|
|
158
|
-
* { name: "nonce", type: "uint64" },
|
|
159
|
-
* ],
|
|
160
|
-
* },
|
|
161
|
-
* chainId: parseInt(action.signatureChainId, 16),
|
|
188
|
+
* types: userSignedActionEip712Types[action.type],
|
|
162
189
|
* });
|
|
163
190
|
*
|
|
164
|
-
*
|
|
191
|
+
* // Send the signed action to the Hyperliquid API
|
|
192
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
165
193
|
* method: "POST",
|
|
166
194
|
* headers: { "Content-Type": "application/json" },
|
|
167
195
|
* body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
@@ -173,79 +201,72 @@ export declare function signUserSignedAction(args: {
|
|
|
173
201
|
/** Wallet to sign the action. */
|
|
174
202
|
wallet: AbstractWallet;
|
|
175
203
|
/** The action to be signed. */
|
|
176
|
-
action:
|
|
177
|
-
|
|
204
|
+
action: {
|
|
205
|
+
signatureChainId: Hex;
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
};
|
|
208
|
+
/** The types of the action (hash depends on key order). */
|
|
178
209
|
types: {
|
|
179
210
|
[key: string]: {
|
|
180
211
|
name: string;
|
|
181
212
|
type: string;
|
|
182
213
|
}[];
|
|
183
214
|
};
|
|
184
|
-
/** The chain ID. */
|
|
185
|
-
chainId: number;
|
|
186
215
|
}): Promise<Signature>;
|
|
187
216
|
/**
|
|
188
217
|
* Sign a multi-signature action.
|
|
189
|
-
*
|
|
190
|
-
* Note: Signature generation depends on the order of the action keys.
|
|
191
|
-
*
|
|
192
|
-
* @param args - Arguments for signing the action.
|
|
193
|
-
* @returns The signature components r, s, and v.
|
|
194
218
|
* @example
|
|
195
219
|
* ```ts
|
|
196
|
-
* import { signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
220
|
+
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
197
221
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
198
222
|
*
|
|
199
|
-
* const wallet = privateKeyToAccount("0x...");
|
|
200
|
-
* const multiSigUser = "0x...";
|
|
223
|
+
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key with address
|
|
224
|
+
* const multiSigUser = "0x...";
|
|
201
225
|
*
|
|
202
226
|
* const nonce = Date.now();
|
|
203
|
-
* const action = {
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* };
|
|
227
|
+
* const action = {
|
|
228
|
+
* type: "scheduleCancel",
|
|
229
|
+
* time: Date.now() + 10000,
|
|
230
|
+
* } as const;
|
|
207
231
|
*
|
|
208
|
-
* // First, create
|
|
232
|
+
* // First, create the required number of signatures
|
|
209
233
|
* const signature = await signL1Action({
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* isTestnet: true,
|
|
234
|
+
* wallet,
|
|
235
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
236
|
+
* nonce,
|
|
214
237
|
* });
|
|
215
238
|
*
|
|
216
|
-
* // Then use
|
|
239
|
+
* // Then use signatures in the multi-sig action
|
|
217
240
|
* const multiSigSignature = await signMultiSigAction({
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* }
|
|
228
|
-
*
|
|
229
|
-
* nonce,
|
|
230
|
-
* hyperliquidChain: "Testnet",
|
|
231
|
-
* signatureChainId: "0x66eee",
|
|
241
|
+
* wallet,
|
|
242
|
+
* action: {
|
|
243
|
+
* signatureChainId: "0x66eee",
|
|
244
|
+
* signatures: [signature],
|
|
245
|
+
* payload: {
|
|
246
|
+
* multiSigUser,
|
|
247
|
+
* outerSigner: wallet.address,
|
|
248
|
+
* action,
|
|
249
|
+
* },
|
|
250
|
+
* },
|
|
251
|
+
* nonce,
|
|
232
252
|
* });
|
|
233
253
|
* ```
|
|
234
254
|
*/
|
|
235
255
|
export declare function signMultiSigAction(args: {
|
|
236
256
|
/** Wallet to sign the action. */
|
|
237
257
|
wallet: AbstractWallet;
|
|
238
|
-
/** The action to be signed. */
|
|
239
|
-
action:
|
|
240
|
-
|
|
258
|
+
/** The action to be signed (hash depends on key order). */
|
|
259
|
+
action: {
|
|
260
|
+
signatureChainId: Hex;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
/** The current timestamp in ms. */
|
|
241
264
|
nonce: number;
|
|
265
|
+
/** Indicates if the action is for the testnet. (default: false) */
|
|
266
|
+
isTestnet?: boolean;
|
|
242
267
|
/** Optional vault address used in the action. */
|
|
243
268
|
vaultAddress?: Hex;
|
|
244
|
-
/** Optional expiration time of the action in
|
|
269
|
+
/** Optional expiration time of the action in ms since the epoch. */
|
|
245
270
|
expiresAfter?: number;
|
|
246
|
-
/** HyperLiquid network ("Mainnet" or "Testnet"). */
|
|
247
|
-
hyperliquidChain: "Mainnet" | "Testnet";
|
|
248
|
-
/** Chain ID used for signing. */
|
|
249
|
-
signatureChainId: Hex;
|
|
250
271
|
}): Promise<Signature>;
|
|
251
272
|
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/signing/mod.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/signing/mod.ts"],"names":[],"mappings":"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"}
|