@nktkas/hyperliquid 0.13.2 → 0.15.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 -7
- package/README.md +297 -103
- package/esm/mod.d.ts +3 -12
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -2
- package/esm/src/{transports/base.d.ts → base.d.ts} +11 -14
- package/esm/src/base.d.ts.map +1 -0
- package/esm/src/base.js +14 -0
- package/esm/src/clients/event.d.ts +4 -4
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +2 -2
- package/esm/src/clients/public.d.ts +109 -6
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +106 -3
- package/esm/src/clients/wallet.d.ts +232 -29
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +859 -243
- package/esm/src/signing.d.ts +135 -0
- package/esm/src/signing.d.ts.map +1 -0
- package/esm/src/signing.js +188 -0
- package/esm/src/transports/http/http_transport.d.ts +2 -4
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +8 -13
- package/{script/src/transports/websocket/hyperliquid_event_target.d.ts → esm/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
- package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +91 -76
- package/esm/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +3 -7
- package/esm/src/transports/websocket/websocket_transport.d.ts +13 -16
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +49 -49
- package/esm/src/types/exchange/requests.d.ts +172 -20
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +32 -32
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +12 -12
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +36 -1
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +130 -105
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +154 -152
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +20 -20
- package/esm/src/types/info/delegations.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +55 -55
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +73 -10
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +1 -1
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +14 -0
- package/esm/src/types/mod.d.ts.map +1 -0
- package/esm/src/types/subscriptions/requests.d.ts +1 -1
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{script/src/types/subscriptions/common.d.ts → esm/src/types/subscriptions/responses.d.ts} +16 -4
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -0
- package/package.json +20 -4
- package/script/mod.d.ts +3 -12
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +3 -5
- package/script/src/{transports/base.d.ts → base.d.ts} +11 -14
- package/script/src/base.d.ts.map +1 -0
- package/script/src/{transports/base.js → base.js} +13 -12
- package/script/src/clients/event.d.ts +4 -4
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +2 -2
- package/script/src/clients/public.d.ts +109 -6
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +106 -3
- package/script/src/clients/wallet.d.ts +232 -29
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +860 -244
- package/script/src/signing.d.ts +135 -0
- package/script/src/signing.d.ts.map +1 -0
- package/script/src/signing.js +203 -0
- package/script/src/transports/http/http_transport.d.ts +2 -4
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +9 -14
- package/{esm/src/transports/websocket/hyperliquid_event_target.d.ts → script/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
- package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +94 -78
- package/script/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +4 -8
- package/script/src/transports/websocket/websocket_transport.d.ts +13 -16
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +55 -55
- package/script/src/types/exchange/requests.d.ts +172 -20
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +32 -32
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/explorer/requests.d.ts +12 -12
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/responses.d.ts +36 -1
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +130 -105
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +154 -152
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/delegations.d.ts +20 -20
- package/script/src/types/info/delegations.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +55 -55
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +73 -10
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/vaults.d.ts +1 -1
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +14 -0
- package/script/src/types/mod.d.ts.map +1 -0
- package/script/src/types/subscriptions/requests.d.ts +1 -1
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{esm/src/types/subscriptions/common.d.ts → script/src/types/subscriptions/responses.d.ts} +16 -4
- package/script/src/types/subscriptions/responses.d.ts.map +1 -0
- package/esm/src/transports/base.d.ts.map +0 -1
- package/esm/src/transports/base.js +0 -14
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/esm/src/types/common.d.ts +0 -3
- package/esm/src/types/common.d.ts.map +0 -1
- package/esm/src/types/exchange/common.d.ts +0 -36
- package/esm/src/types/exchange/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.d.ts +0 -37
- package/esm/src/types/explorer/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.js +0 -1
- package/esm/src/types/subscriptions/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.js +0 -1
- package/esm/src/utils/key_sort.d.ts +0 -21
- package/esm/src/utils/key_sort.d.ts.map +0 -1
- package/esm/src/utils/key_sort.js +0 -124
- package/esm/src/utils/signing.d.ts +0 -109
- package/esm/src/utils/signing.d.ts.map +0 -1
- package/esm/src/utils/signing.js +0 -164
- package/script/src/transports/base.d.ts.map +0 -1
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/script/src/types/common.d.ts +0 -3
- package/script/src/types/common.d.ts.map +0 -1
- package/script/src/types/exchange/common.d.ts +0 -36
- package/script/src/types/exchange/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.d.ts +0 -37
- package/script/src/types/explorer/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.js +0 -12
- package/script/src/types/subscriptions/common.d.ts.map +0 -1
- package/script/src/types/subscriptions/common.js +0 -12
- package/script/src/utils/key_sort.d.ts +0 -21
- package/script/src/utils/key_sort.d.ts.map +0 -1
- package/script/src/utils/key_sort.js +0 -137
- package/script/src/utils/signing.d.ts +0 -109
- package/script/src/utils/signing.d.ts.map +0 -1
- package/script/src/utils/signing.js +0 -182
- /package/esm/src/types/{common.js → mod.js} +0 -0
- /package/esm/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
- /package/script/src/types/{common.js → mod.js} +0 -0
- /package/script/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
2
|
+
import type { Hex } from "./base.js";
|
|
3
|
+
export type { Hex } from "./base.js";
|
|
4
|
+
export type { ValueMap, ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
5
|
+
/** Abstract interface for a [viem wallet](https://viem.sh/docs/clients/wallet). */
|
|
6
|
+
export interface AbstractViemWalletClient {
|
|
7
|
+
signTypedData(params: {
|
|
8
|
+
domain: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
chainId: number;
|
|
12
|
+
verifyingContract: Hex;
|
|
13
|
+
};
|
|
14
|
+
types: {
|
|
15
|
+
[key: string]: {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
primaryType: string;
|
|
21
|
+
message: Record<string, unknown>;
|
|
22
|
+
}): Promise<Hex>;
|
|
23
|
+
}
|
|
24
|
+
/** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/reference/sdk/react-auth/functions/useSignTypedData#returns)). */
|
|
25
|
+
export interface AbstractExtendedViemWalletClient {
|
|
26
|
+
signTypedData(params: {
|
|
27
|
+
domain: {
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
chainId: number;
|
|
31
|
+
verifyingContract: Hex;
|
|
32
|
+
};
|
|
33
|
+
types: {
|
|
34
|
+
[key: string]: {
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
primaryType: string;
|
|
40
|
+
message: Record<string, unknown>;
|
|
41
|
+
}, options?: unknown): Promise<Hex>;
|
|
42
|
+
}
|
|
43
|
+
/** Abstract interface for an [ethers.js signer](https://docs.ethers.org/v6/api/providers/#Signer). */
|
|
44
|
+
export interface AbstractEthersSigner {
|
|
45
|
+
signTypedData(domain: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
chainId: number;
|
|
49
|
+
verifyingContract: string;
|
|
50
|
+
}, types: {
|
|
51
|
+
[key: string]: {
|
|
52
|
+
name: string;
|
|
53
|
+
type: string;
|
|
54
|
+
}[];
|
|
55
|
+
}, value: Record<string, unknown>): Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
/** Abstract interface for an [ethers.js v5 signer](https://docs.ethers.org/v5/api/providers/#Signer). */
|
|
58
|
+
export interface AbstractEthersV5Signer {
|
|
59
|
+
_signTypedData(domain: {
|
|
60
|
+
name: string;
|
|
61
|
+
version: string;
|
|
62
|
+
chainId: number;
|
|
63
|
+
verifyingContract: string;
|
|
64
|
+
}, types: {
|
|
65
|
+
[key: string]: {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
}[];
|
|
69
|
+
}, value: Record<string, unknown>): Promise<string>;
|
|
70
|
+
}
|
|
71
|
+
/** Abstract interface for a [window.ethereum](https://eips.ethereum.org/EIPS/eip-1193) object. */
|
|
72
|
+
export interface AbstractWindowEthereum {
|
|
73
|
+
request: (args: {
|
|
74
|
+
method: string;
|
|
75
|
+
params: unknown[];
|
|
76
|
+
}) => Promise<unknown>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a hash of the L1 action.
|
|
80
|
+
*
|
|
81
|
+
* Note: Hash generation depends on the order of the action keys.
|
|
82
|
+
* @param action - The action to be hashed.
|
|
83
|
+
* @param nonce - Unique request identifier (recommended current timestamp in ms).
|
|
84
|
+
* @param vaultAddress - Optional vault address used in the action.
|
|
85
|
+
* @returns The hash of the action.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createL1ActionHash(action: ValueType, nonce: number, vaultAddress?: Hex): Hex;
|
|
88
|
+
/**
|
|
89
|
+
* Sign an L1 action.
|
|
90
|
+
*
|
|
91
|
+
* Note: Signature generation depends on the order of the action keys.
|
|
92
|
+
* @param args.wallet - Wallet to sign the action.
|
|
93
|
+
* @param args.action - The action to be signed.
|
|
94
|
+
* @param args.nonce - Unique request identifier (recommended current timestamp in ms).
|
|
95
|
+
* @param args.isTestnet - Indicates if the action is for the testnet. Default is `false`.
|
|
96
|
+
* @param args.vaultAddress - Optional vault address used in the action.
|
|
97
|
+
* @returns The signature components r, s, and v.
|
|
98
|
+
*/
|
|
99
|
+
export declare function signL1Action(args: {
|
|
100
|
+
wallet: AbstractViemWalletClient | AbstractExtendedViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractWindowEthereum;
|
|
101
|
+
action: ValueType;
|
|
102
|
+
nonce: number;
|
|
103
|
+
isTestnet?: boolean;
|
|
104
|
+
vaultAddress?: Hex;
|
|
105
|
+
}): Promise<{
|
|
106
|
+
r: Hex;
|
|
107
|
+
s: Hex;
|
|
108
|
+
v: number;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Sign a user-signed action.
|
|
112
|
+
*
|
|
113
|
+
* Note: Signature generation depends on the order of types.
|
|
114
|
+
* @param args.wallet - Wallet to sign the action.
|
|
115
|
+
* @param args.action - The action to be signed.
|
|
116
|
+
* @param args.types - The types of the action.
|
|
117
|
+
* @param args.chainId - The chain ID.
|
|
118
|
+
* @returns The signature components r, s, and v.
|
|
119
|
+
*/
|
|
120
|
+
export declare function signUserSignedAction(args: {
|
|
121
|
+
wallet: AbstractViemWalletClient | AbstractExtendedViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractWindowEthereum;
|
|
122
|
+
action: Record<string, unknown>;
|
|
123
|
+
types: {
|
|
124
|
+
[key: string]: {
|
|
125
|
+
name: string;
|
|
126
|
+
type: string;
|
|
127
|
+
}[];
|
|
128
|
+
};
|
|
129
|
+
chainId: number;
|
|
130
|
+
}): Promise<{
|
|
131
|
+
r: Hex;
|
|
132
|
+
s: Hex;
|
|
133
|
+
v: number;
|
|
134
|
+
}>;
|
|
135
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAErF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAEvF,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,MAAM,EAAE;QAClB,MAAM,EAAE;YACJ,IAAI,EAAE,MAA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CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BzC;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC7C,MAAM,EACA,wBAAwB,GACxB,gCAAgC,GAChC,oBAAoB,GACpB,sBAAsB,GACtB,sBAAsB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAYzC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { keccak_256 } from "../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js";
|
|
2
|
+
import { encode } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
3
|
+
import { decodeHex, encodeHex } from "../deps/jsr.io/@std/encoding/1.0.7/hex.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create a hash of the L1 action.
|
|
6
|
+
*
|
|
7
|
+
* Note: Hash generation depends on the order of the action keys.
|
|
8
|
+
* @param action - The action to be hashed.
|
|
9
|
+
* @param nonce - Unique request identifier (recommended current timestamp in ms).
|
|
10
|
+
* @param vaultAddress - Optional vault address used in the action.
|
|
11
|
+
* @returns The hash of the action.
|
|
12
|
+
*/
|
|
13
|
+
export function createL1ActionHash(action, nonce, vaultAddress) {
|
|
14
|
+
const normalizedAction = normalizeIntegersForMsgPack(action);
|
|
15
|
+
const msgPackBytes = encode(normalizedAction);
|
|
16
|
+
const additionalBytesLength = vaultAddress ? 29 : 9;
|
|
17
|
+
const data = new Uint8Array(msgPackBytes.length + additionalBytesLength);
|
|
18
|
+
data.set(msgPackBytes);
|
|
19
|
+
const view = new DataView(data.buffer);
|
|
20
|
+
view.setBigUint64(msgPackBytes.length, BigInt(nonce));
|
|
21
|
+
if (vaultAddress) {
|
|
22
|
+
view.setUint8(msgPackBytes.length + 8, 1);
|
|
23
|
+
data.set(decodeHex(vaultAddress.slice(2)), msgPackBytes.length + 9);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
view.setUint8(msgPackBytes.length + 8, 0);
|
|
27
|
+
}
|
|
28
|
+
const hashBytes = keccak_256(data);
|
|
29
|
+
const hashHex = encodeHex(hashBytes);
|
|
30
|
+
return `0x${hashHex}`;
|
|
31
|
+
}
|
|
32
|
+
/** Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}. */
|
|
33
|
+
function normalizeIntegersForMsgPack(obj) {
|
|
34
|
+
const THIRTY_ONE_BITS = 2147483648;
|
|
35
|
+
const THIRTY_TWO_BITS = 4294967296;
|
|
36
|
+
if (typeof obj === "number" && Number.isInteger(obj) &&
|
|
37
|
+
obj <= Number.MAX_SAFE_INTEGER && obj >= Number.MIN_SAFE_INTEGER &&
|
|
38
|
+
(obj >= THIRTY_TWO_BITS || obj < -THIRTY_ONE_BITS)) {
|
|
39
|
+
return BigInt(obj);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return obj.map(normalizeIntegersForMsgPack);
|
|
43
|
+
}
|
|
44
|
+
if (obj && typeof obj === "object" && obj !== null) {
|
|
45
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, normalizeIntegersForMsgPack(value)]));
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sign an L1 action.
|
|
51
|
+
*
|
|
52
|
+
* Note: Signature generation depends on the order of the action keys.
|
|
53
|
+
* @param args.wallet - Wallet to sign the action.
|
|
54
|
+
* @param args.action - The action to be signed.
|
|
55
|
+
* @param args.nonce - Unique request identifier (recommended current timestamp in ms).
|
|
56
|
+
* @param args.isTestnet - Indicates if the action is for the testnet. Default is `false`.
|
|
57
|
+
* @param args.vaultAddress - Optional vault address used in the action.
|
|
58
|
+
* @returns The signature components r, s, and v.
|
|
59
|
+
*/
|
|
60
|
+
export async function signL1Action(args) {
|
|
61
|
+
const { wallet, action, nonce, isTestnet = false, vaultAddress, } = args;
|
|
62
|
+
const domain = {
|
|
63
|
+
name: "Exchange",
|
|
64
|
+
version: "1",
|
|
65
|
+
chainId: 1337,
|
|
66
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
67
|
+
};
|
|
68
|
+
const types = {
|
|
69
|
+
Agent: [
|
|
70
|
+
{ name: "source", type: "string" },
|
|
71
|
+
{ name: "connectionId", type: "bytes32" },
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
const actionHash = createL1ActionHash(action, nonce, vaultAddress);
|
|
75
|
+
const message = {
|
|
76
|
+
source: isTestnet ? "b" : "a",
|
|
77
|
+
connectionId: actionHash,
|
|
78
|
+
};
|
|
79
|
+
const signature = await abstractSignTypedData({ wallet, domain, types, message });
|
|
80
|
+
return splitSignature(signature);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sign a user-signed action.
|
|
84
|
+
*
|
|
85
|
+
* Note: Signature generation depends on the order of types.
|
|
86
|
+
* @param args.wallet - Wallet to sign the action.
|
|
87
|
+
* @param args.action - The action to be signed.
|
|
88
|
+
* @param args.types - The types of the action.
|
|
89
|
+
* @param args.chainId - The chain ID.
|
|
90
|
+
* @returns The signature components r, s, and v.
|
|
91
|
+
*/
|
|
92
|
+
export async function signUserSignedAction(args) {
|
|
93
|
+
const { wallet, action, types, chainId } = args;
|
|
94
|
+
const domain = {
|
|
95
|
+
name: "HyperliquidSignTransaction",
|
|
96
|
+
version: "1",
|
|
97
|
+
chainId,
|
|
98
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
99
|
+
};
|
|
100
|
+
const signature = await abstractSignTypedData({ wallet, domain, types, message: action });
|
|
101
|
+
return splitSignature(signature);
|
|
102
|
+
}
|
|
103
|
+
/** Signs typed data with the provided wallet using EIP-712. */
|
|
104
|
+
async function abstractSignTypedData(args) {
|
|
105
|
+
const { wallet, domain, types, message } = args;
|
|
106
|
+
if (isAbstractViemWalletClient(wallet) || isAbstractExtendedViemWalletClient(wallet)) {
|
|
107
|
+
const primaryType = Object.keys(types)[0];
|
|
108
|
+
return await wallet.signTypedData({ domain, types, primaryType, message });
|
|
109
|
+
}
|
|
110
|
+
else if (isAbstractEthersSigner(wallet)) {
|
|
111
|
+
return await wallet.signTypedData(domain, types, message);
|
|
112
|
+
}
|
|
113
|
+
else if (isAbstractEthersV5Signer(wallet)) {
|
|
114
|
+
return await wallet._signTypedData(domain, types, message);
|
|
115
|
+
}
|
|
116
|
+
else if (isAbstractWindowEthereum(wallet)) {
|
|
117
|
+
return await signTypedDataWithWindowEthereum(wallet, domain, types, message);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error("Unsupported wallet for signing typed data");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Signs typed data using `window.ethereum` (EIP-1193) with `eth_signTypedData_v4` (EIP-712). */
|
|
124
|
+
async function signTypedDataWithWindowEthereum(ethereum, domain, types, message) {
|
|
125
|
+
const accounts = await ethereum.request({
|
|
126
|
+
method: "eth_requestAccounts",
|
|
127
|
+
params: [],
|
|
128
|
+
});
|
|
129
|
+
if (!Array.isArray(accounts) || accounts.length === 0) {
|
|
130
|
+
throw new Error("No Ethereum accounts available");
|
|
131
|
+
}
|
|
132
|
+
const from = accounts[0];
|
|
133
|
+
const dataToSign = JSON.stringify({
|
|
134
|
+
domain,
|
|
135
|
+
types: {
|
|
136
|
+
EIP712Domain: [
|
|
137
|
+
{ name: "name", type: "string" },
|
|
138
|
+
{ name: "version", type: "string" },
|
|
139
|
+
{ name: "chainId", type: "uint256" },
|
|
140
|
+
{ name: "verifyingContract", type: "address" },
|
|
141
|
+
],
|
|
142
|
+
...types,
|
|
143
|
+
},
|
|
144
|
+
primaryType: Object.keys(types)[0],
|
|
145
|
+
message,
|
|
146
|
+
});
|
|
147
|
+
return await ethereum.request({
|
|
148
|
+
method: "eth_signTypedData_v4",
|
|
149
|
+
params: [from, dataToSign],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** Splits a signature hexadecimal string into its components. */
|
|
153
|
+
function splitSignature(signature) {
|
|
154
|
+
const r = `0x${signature.slice(2, 66)}`;
|
|
155
|
+
const s = `0x${signature.slice(66, 130)}`;
|
|
156
|
+
const v = parseInt(signature.slice(130, 132), 16);
|
|
157
|
+
return { r, s, v };
|
|
158
|
+
}
|
|
159
|
+
/** Checks if the given value is an abstract viem wallet. */
|
|
160
|
+
function isAbstractViemWalletClient(client) {
|
|
161
|
+
return typeof client === "object" && client !== null &&
|
|
162
|
+
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
163
|
+
client.signTypedData.length === 1;
|
|
164
|
+
}
|
|
165
|
+
/** Checks if the given value is an abstract extended viem wallet (e.g. privy `useSignTypedData`). */
|
|
166
|
+
function isAbstractExtendedViemWalletClient(client) {
|
|
167
|
+
return typeof client === "object" && client !== null &&
|
|
168
|
+
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
169
|
+
client.signTypedData.length === 2;
|
|
170
|
+
}
|
|
171
|
+
/** Checks if the given value is an abstract ethers signer. */
|
|
172
|
+
function isAbstractEthersSigner(client) {
|
|
173
|
+
return typeof client === "object" && client !== null &&
|
|
174
|
+
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
175
|
+
client.signTypedData.length === 3;
|
|
176
|
+
}
|
|
177
|
+
/** Checks if the given value is an abstract ethers v5 signer. */
|
|
178
|
+
function isAbstractEthersV5Signer(client) {
|
|
179
|
+
return typeof client === "object" && client !== null &&
|
|
180
|
+
"_signTypedData" in client && typeof client._signTypedData === "function" &&
|
|
181
|
+
client._signTypedData.length === 3;
|
|
182
|
+
}
|
|
183
|
+
/** Checks if the given value is an abstract `window.ethereum` object. */
|
|
184
|
+
function isAbstractWindowEthereum(client) {
|
|
185
|
+
return typeof client === "object" && client !== null &&
|
|
186
|
+
"request" in client && typeof client.request === "function" &&
|
|
187
|
+
client.request.length >= 1;
|
|
188
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IRequestTransport, TransportError } from "
|
|
1
|
+
import { type IRequestTransport, TransportError } from "../../base.js";
|
|
2
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
3
3
|
/**
|
|
4
4
|
* Error thrown when an HTTP response is deemed invalid:
|
|
@@ -56,8 +56,6 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
56
56
|
fetchOptions: Omit<RequestInit, "body" | "method">;
|
|
57
57
|
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>;
|
|
58
58
|
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>;
|
|
59
|
-
/** Mapping of endpoint types to their API paths. */
|
|
60
|
-
protected _endpointPaths: Record<"info" | "action" | "explorer", string>;
|
|
61
59
|
/**
|
|
62
60
|
* Creates a new HTTP transport instance.
|
|
63
61
|
* @param options - Configuration options for the HTTP transport layer.
|
|
@@ -72,7 +70,7 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
72
70
|
* @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
|
|
73
71
|
* @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
|
|
74
72
|
*/
|
|
75
|
-
request(endpoint: "info" | "
|
|
73
|
+
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
76
74
|
}
|
|
77
75
|
export {};
|
|
78
76
|
//# 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,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEvE,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC;;;;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;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB,2IAA2I;IAC3I,YAAY,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IAEpD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAElF;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACzF;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,iBAAiB,EAAE,oBAAoB;IACzE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAClF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAEtF;;;OAGG;gBACS,OAAO,CAAC,EAAE,oBAAoB;IAQ1C;;;;;;;;OAQG;IACG,OAAO,CACT,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAC1C,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,OAAO,CAAC;CAqDtB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransportError } from "
|
|
1
|
+
import { TransportError } from "../../base.js";
|
|
2
2
|
/**
|
|
3
3
|
* Error thrown when an HTTP response is deemed invalid:
|
|
4
4
|
* - Non-200 status code
|
|
@@ -69,17 +69,6 @@ export class HttpTransport {
|
|
|
69
69
|
writable: true,
|
|
70
70
|
value: void 0
|
|
71
71
|
});
|
|
72
|
-
/** Mapping of endpoint types to their API paths. */
|
|
73
|
-
Object.defineProperty(this, "_endpointPaths", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: {
|
|
78
|
-
info: "/info",
|
|
79
|
-
action: "/exchange",
|
|
80
|
-
explorer: "/explorer",
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
72
|
this.url = options?.url ?? "https://api.hyperliquid.xyz";
|
|
84
73
|
this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
|
|
85
74
|
this.fetchOptions = options?.fetchOptions ?? {};
|
|
@@ -97,7 +86,13 @@ export class HttpTransport {
|
|
|
97
86
|
*/
|
|
98
87
|
async request(endpoint, payload, signal) {
|
|
99
88
|
// Construct a Request
|
|
100
|
-
const url = new URL(
|
|
89
|
+
const url = new URL(endpoint, this.url);
|
|
90
|
+
// FIXME: Temporary hack: replace `api.hyperliquid-testnet.xyz/explorer` with `rpc.hyperliquid-testnet.xyz/explorer`
|
|
91
|
+
// until the new rpc url becomes the standard for mainnet.
|
|
92
|
+
// Maybe after that should split the url property into api and rpc variants.
|
|
93
|
+
if (url.hostname === "api.hyperliquid-testnet.xyz" && url.pathname === "/explorer") {
|
|
94
|
+
url.hostname = "rpc.hyperliquid-testnet.xyz";
|
|
95
|
+
}
|
|
101
96
|
const init = mergeRequestInit({
|
|
102
97
|
body: JSON.stringify(payload),
|
|
103
98
|
headers: {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { TypedEventTarget } from "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js";
|
|
2
|
-
import type { TxDetails } from "../../types/explorer/
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Base system events and dynamic channel events for Hyperliquid WebSocket API.
|
|
6
|
-
*/
|
|
7
|
-
export interface HyperliquidEventMap {
|
|
2
|
+
import type { BlockDetails, TxDetails } from "../../types/explorer/responses.js";
|
|
3
|
+
/** Base system events and dynamic channel events for Hyperliquid WebSocket API. */
|
|
4
|
+
interface HyperliquidEventMap {
|
|
8
5
|
/** Subscription created/removed event. */
|
|
9
6
|
subscriptionResponse: CustomEvent<{
|
|
10
7
|
/** Type of subscription operation. */
|
|
@@ -53,20 +50,15 @@ export interface HyperliquidEventMap {
|
|
|
53
50
|
/** Pong response event. */
|
|
54
51
|
pong: CustomEvent<undefined>;
|
|
55
52
|
/** Block explorer update event. */
|
|
56
|
-
_explorerBlock: CustomEvent<
|
|
53
|
+
_explorerBlock: CustomEvent<Omit<BlockDetails, "txs">[]>;
|
|
57
54
|
/** Transaction explorer update event. */
|
|
58
55
|
_explorerTxs: CustomEvent<TxDetails[]>;
|
|
59
56
|
/** Subscribed channel event. */
|
|
60
57
|
[key: string]: CustomEvent<unknown>;
|
|
61
58
|
}
|
|
62
|
-
/**
|
|
63
|
-
* A class that listens to WebSocket messages and dispatches them as Hyperliquid typed events.
|
|
64
|
-
*/
|
|
59
|
+
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
65
60
|
export declare class HyperliquidEventTarget extends TypedEventTarget<HyperliquidEventMap> {
|
|
66
|
-
/**
|
|
67
|
-
* Creates a new Hyperliquid event target.
|
|
68
|
-
* @param socket - The WebSocket to listen to.
|
|
69
|
-
*/
|
|
70
61
|
constructor(socket: WebSocket);
|
|
71
62
|
}
|
|
72
|
-
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=_hyperliquid_event_target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_hyperliquid_event_target.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_hyperliquid_event_target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oEAAoE,CAAC;AACtG,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAUjF,mFAAmF;AACnF,UAAU,mBAAmB;IACzB,0CAA0C;IAC1C,oBAAoB,EAAE,WAAW,CAAC;QAC9B,sCAAsC;QACtC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;QACpC,qCAAqC;QACrC,YAAY,EAAE,OAAO,CAAC;KACzB,CAAC,CAAC;IAEH,sCAAsC;IACtC,IAAI,EAAE,WAAW,CAAC;QACd,iCAAiC;QACjC,EAAE,EAAE,MAAM,CAAC;QACX,uBAAuB;QACvB,QAAQ;QACJ,iDAAiD;QAC/C;YACE,wDAAwD;YACxD,IAAI,EAAE,MAAM,CAAC;YACb,qCAAqC;YACrC,OAAO,EAAE;gBACL,0CAA0C;gBAC1C,IAAI,EAAE,MAAM,CAAC;gBACb,iCAAiC;gBACjC,IAAI,EAAE,OAAO,CAAC;aACjB,CAAC;SACL;QACD,yCAAyC;WACvC;YACE,iDAAiD;YACjD,IAAI,EAAE,QAAQ,CAAC;YACf,uCAAuC;YACvC,OAAO,EAAE;gBACL,mEAAmE;gBACnE,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;gBACrB,qCAAqC;gBACrC,QAAQ,EACF;oBACE,yBAAyB;oBACzB,IAAI,EAAE,MAAM,CAAC;oBACb,uCAAuC;oBACvC,IAAI,CAAC,EAAE,OAAO,CAAC;iBAClB,GACC,MAAM,CAAC;aAChB,CAAC;SACL,CAAC;KACT,CAAC,CAAC;IAEH,wCAAwC;IACxC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAE3B,2BAA2B;IAC3B,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAE7B,mCAAmC;IACnC,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;IAEzD,yCAAyC;IACzC,YAAY,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;IAEvC,gCAAgC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;CACvC;AAED,iFAAiF;AACjF,qBAAa,sBAAuB,SAAQ,gBAAgB,CAAC,mBAAmB,CAAC;gBACjE,MAAM,EAAE,SAAS;CAiBhC"}
|
package/esm/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js}
RENAMED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { TypedEventTarget } from "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js";
|
|
2
|
-
/**
|
|
3
|
-
* A class that listens to WebSocket messages and dispatches them as Hyperliquid typed events.
|
|
4
|
-
*/
|
|
2
|
+
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
5
3
|
export class HyperliquidEventTarget extends TypedEventTarget {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new Hyperliquid event target.
|
|
8
|
-
* @param socket - The WebSocket to listen to.
|
|
9
|
-
*/
|
|
10
4
|
constructor(socket) {
|
|
11
5
|
super();
|
|
12
6
|
socket.addEventListener("message", (event) => {
|
|
@@ -28,20 +22,12 @@ export class HyperliquidEventTarget extends TypedEventTarget {
|
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Type guard for Hyperliquid messages.
|
|
33
|
-
* @param value - The value to check.
|
|
34
|
-
* @returns True if the value is a Hyperliquid message.
|
|
35
|
-
*/
|
|
25
|
+
/** Type guard for Hyperliquid messages. */
|
|
36
26
|
function isHyperliquidMsg(value) {
|
|
37
27
|
return typeof value === "object" && value !== null &&
|
|
38
28
|
"channel" in value && typeof value.channel === "string";
|
|
39
29
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Type guard for explorer block messages.
|
|
42
|
-
* @param value - The value to check.
|
|
43
|
-
* @returns True if the value is an array of block details.
|
|
44
|
-
*/
|
|
30
|
+
/** Type guard for explorer block messages. */
|
|
45
31
|
function isExplorerBlockMsg(value) {
|
|
46
32
|
return Array.isArray(value) && value.length > 0 &&
|
|
47
33
|
value.every((block) => typeof block === "object" && block !== null && !Array.isArray(block) &&
|
|
@@ -51,11 +37,7 @@ function isExplorerBlockMsg(value) {
|
|
|
51
37
|
"proposer" in block && typeof block.proposer === "string" &&
|
|
52
38
|
"numTxs" in block && typeof block.numTxs === "number");
|
|
53
39
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Type guard for explorer transactions messages.
|
|
56
|
-
* @param value - The value to check.
|
|
57
|
-
* @returns True if the value is an array of transaction details.
|
|
58
|
-
*/
|
|
40
|
+
/** Type guard for explorer transactions messages. */
|
|
59
41
|
function isExplorerTxsMsg(value) {
|
|
60
42
|
return Array.isArray(value) && value.length > 0 &&
|
|
61
43
|
value.every((tx) => {
|
package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts}
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { TransportError } from "../../base.js";
|
|
1
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for the `ReconnectingWebSocket`.
|
|
4
|
-
*/
|
|
3
|
+
/** Configuration options for the `ReconnectingWebSocket`. */
|
|
5
4
|
export interface ReconnectingWebSocketOptions {
|
|
6
5
|
/**
|
|
7
6
|
* Maximum number of reconnection attempts.
|
|
@@ -33,15 +32,8 @@ export interface ReconnectingWebSocketOptions {
|
|
|
33
32
|
* @defaultValue `new FIFOMessageBuffer()`
|
|
34
33
|
*/
|
|
35
34
|
messageBuffer?: MessageBufferStrategy;
|
|
36
|
-
/**
|
|
37
|
-
* Custom WebSocket constructor to use.
|
|
38
|
-
* @defaultValue `new WebSocket(url, protocols)`
|
|
39
|
-
*/
|
|
40
|
-
WebSocketConstructor?: typeof WebSocket;
|
|
41
35
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Message buffer strategy interface.
|
|
44
|
-
*/
|
|
36
|
+
/** Message buffer strategy interface. */
|
|
45
37
|
export interface MessageBufferStrategy {
|
|
46
38
|
/** Array of buffered messages. */
|
|
47
39
|
messages: (string | ArrayBufferLike | Blob | ArrayBufferView)[];
|
|
@@ -58,21 +50,27 @@ export interface MessageBufferStrategy {
|
|
|
58
50
|
/** Clear all buffered messages. */
|
|
59
51
|
clear(): void;
|
|
60
52
|
}
|
|
53
|
+
/** Error thrown when reconnection problems occur. */
|
|
54
|
+
export declare class ReconnectingWebSocketError extends TransportError {
|
|
55
|
+
code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR";
|
|
56
|
+
originalError?: unknown | undefined;
|
|
57
|
+
constructor(code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR", originalError?: unknown | undefined);
|
|
58
|
+
}
|
|
61
59
|
/**
|
|
62
60
|
* A WebSocket that automatically reconnects when disconnected.
|
|
63
61
|
* Fully compatible with standard WebSocket API.
|
|
64
62
|
*/
|
|
65
63
|
export declare class ReconnectingWebSocket implements WebSocket {
|
|
66
64
|
/** Controller for handling connection termination */
|
|
67
|
-
protected
|
|
65
|
+
protected _terminationController: AbortController;
|
|
68
66
|
/** WebSocket protocols */
|
|
69
|
-
protected
|
|
67
|
+
protected _protocols?: string | string[];
|
|
70
68
|
/** The underlying WebSocket instance */
|
|
71
|
-
protected
|
|
69
|
+
protected _socket: WebSocket;
|
|
72
70
|
/** Current number of reconnection attempts */
|
|
73
|
-
protected
|
|
71
|
+
protected _reconnectCount: number;
|
|
74
72
|
/** Array of registered event listeners */
|
|
75
|
-
protected
|
|
73
|
+
protected _eventListeners: {
|
|
76
74
|
type: string;
|
|
77
75
|
listener: EventListenerOrEventListenerObject;
|
|
78
76
|
options?: boolean | AddEventListenerOptions;
|
|
@@ -96,23 +94,21 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
96
94
|
* @param timeout - The connection timeout in ms.
|
|
97
95
|
* @returns A new WebSocket instance.
|
|
98
96
|
*/
|
|
99
|
-
protected
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
*/
|
|
103
|
-
protected initEventListeners(): void;
|
|
97
|
+
protected _connectWithTimeout(url: string | URL, protocols: string | string[] | undefined, timeout: number): WebSocket;
|
|
98
|
+
/** Initializes the internal event listeners for the WebSocket. */
|
|
99
|
+
protected _initEventListeners(): void;
|
|
104
100
|
/**
|
|
105
101
|
* Clean up internal resources.
|
|
106
102
|
* @param reason - The reason for cleanup.
|
|
107
103
|
*/
|
|
108
|
-
protected
|
|
104
|
+
protected _cleanup(reason: unknown): void;
|
|
109
105
|
/**
|
|
110
106
|
* Check if two event listeners are the same (just like EventTarget).
|
|
111
107
|
* @param a - First event listener configuration.
|
|
112
108
|
* @param b - Second event listener configuration.
|
|
113
109
|
* @returns True if the listeners match.
|
|
114
110
|
*/
|
|
115
|
-
protected
|
|
111
|
+
protected _isListenerMatch(a: {
|
|
116
112
|
type: string;
|
|
117
113
|
listener: EventListenerOrEventListenerObject;
|
|
118
114
|
options?: boolean | AddEventListenerOptions;
|
|
@@ -152,9 +148,13 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
152
148
|
* @note If the connection is not open, the data will be buffered and sent when the connection is established.
|
|
153
149
|
*/
|
|
154
150
|
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
155
|
-
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any
|
|
156
|
-
|
|
151
|
+
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any) | {
|
|
152
|
+
handleEvent: (event: WebSocketEventMap[K]) => any;
|
|
153
|
+
}, options?: boolean | AddEventListenerOptions): void;
|
|
154
|
+
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any) | {
|
|
155
|
+
handleEvent: (event: WebSocketEventMap[K]) => any;
|
|
156
|
+
}, options?: boolean | EventListenerOptions): void;
|
|
157
157
|
dispatchEvent(event: Event): boolean;
|
|
158
158
|
}
|
|
159
159
|
export {};
|
|
160
|
-
//# sourceMappingURL=
|
|
160
|
+
//# sourceMappingURL=_reconnecting_websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,6DAA6D;AAC7D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