@nktkas/hyperliquid 0.13.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 +59 -0
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/SECURITY.md +7 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +10 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +43 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +65 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +283 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +211 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.js +32 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +26 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js +109 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.js +237 -0
- package/esm/mod.d.ts +24 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +9 -0
- package/esm/package.json +3 -0
- package/esm/src/clients/event.d.ts +374 -0
- package/esm/src/clients/event.d.ts.map +1 -0
- package/esm/src/clients/event.js +490 -0
- package/esm/src/clients/public.d.ts +695 -0
- package/esm/src/clients/public.d.ts.map +1 -0
- package/esm/src/clients/public.js +704 -0
- package/esm/src/clients/wallet.d.ts +682 -0
- package/esm/src/clients/wallet.d.ts.map +1 -0
- package/esm/src/clients/wallet.js +984 -0
- package/esm/src/transports/base.d.ts +55 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +14 -0
- package/esm/src/transports/http/http_transport.d.ts +78 -0
- package/esm/src/transports/http/http_transport.d.ts.map +1 -0
- package/esm/src/transports/http/http_transport.js +170 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.js +33 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/reconnecting_websocket.js +370 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.js +201 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_transport.js +233 -0
- package/esm/src/utils/key_sort.d.ts +21 -0
- package/esm/src/utils/key_sort.d.ts.map +1 -0
- package/esm/src/utils/key_sort.js +124 -0
- package/esm/src/utils/signing.d.ts +109 -0
- package/esm/src/utils/signing.d.ts.map +1 -0
- package/esm/src/utils/signing.js +164 -0
- package/package.json +34 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +17 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +14 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +49 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +88 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +4 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +235 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +35 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +29 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +113 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +240 -0
- package/script/mod.d.ts +24 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +27 -0
- package/script/package.json +3 -0
- package/script/src/clients/event.d.ts +374 -0
- package/script/src/clients/event.d.ts.map +1 -0
- package/script/src/clients/event.js +494 -0
- package/script/src/clients/public.d.ts +695 -0
- package/script/src/clients/public.d.ts.map +1 -0
- package/script/src/clients/public.js +708 -0
- package/script/src/clients/wallet.d.ts +682 -0
- package/script/src/clients/wallet.d.ts.map +1 -0
- package/script/src/clients/wallet.js +989 -0
- package/script/src/transports/base.d.ts +55 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +18 -0
- package/script/src/transports/http/http_transport.d.ts +78 -0
- package/script/src/transports/http/http_transport.d.ts.map +1 -0
- package/script/src/transports/http/http_transport.js +175 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/hyperliquid_event_target.js +37 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/reconnecting_websocket.js +374 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.js +206 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_transport.js +237 -0
- package/script/src/utils/key_sort.d.ts +21 -0
- package/script/src/utils/key_sort.d.ts.map +1 -0
- package/script/src/utils/key_sort.js +127 -0
- package/script/src/utils/signing.d.ts +109 -0
- package/script/src/utils/signing.d.ts.map +1 -0
- package/script/src/utils/signing.js +172 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ReconnectingWebSocket, type ReconnectingWebSocketOptions } from "./reconnecting_websocket.js";
|
|
2
|
+
import { HyperliquidEventTarget } from "./hyperliquid_event_target.js";
|
|
3
|
+
import { WebSocketRequestDispatcher } from "./websocket_request_dispatcher.js";
|
|
4
|
+
import type { IRequestTransport, ISubscriptionTransport, Subscription } from "../base.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the WebSocket transport layer.
|
|
7
|
+
*/
|
|
8
|
+
export interface WebSocketTransportOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The WebSocket URL.
|
|
11
|
+
* - Mainnet: `wss://api.hyperliquid.xyz/ws`
|
|
12
|
+
* - Testnet: `wss://api.hyperliquid-testnet.xyz/ws`
|
|
13
|
+
* @defaultValue `wss://api.hyperliquid.xyz/ws`
|
|
14
|
+
*/
|
|
15
|
+
url?: string | URL;
|
|
16
|
+
/**
|
|
17
|
+
* Request timeout in ms.
|
|
18
|
+
* Set to `null` to disable.
|
|
19
|
+
* @defaultValue `10_000`
|
|
20
|
+
*/
|
|
21
|
+
timeout?: number | null;
|
|
22
|
+
/**
|
|
23
|
+
* Keep-alive configuration.
|
|
24
|
+
* @defaultValue `{ interval: 20_000 }`
|
|
25
|
+
*/
|
|
26
|
+
keepAlive?: {
|
|
27
|
+
/**
|
|
28
|
+
* The interval in ms to send keep-alive messages.
|
|
29
|
+
* Set to `null` to disable.
|
|
30
|
+
* @defaultValue `20_000`
|
|
31
|
+
*/
|
|
32
|
+
interval?: number | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Reconnection policy configuration for closed connections.
|
|
36
|
+
*/
|
|
37
|
+
reconnect?: ReconnectingWebSocketOptions;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* WebSocket implementation of the REST and Subscription transport interfaces.
|
|
41
|
+
*/
|
|
42
|
+
export declare class WebSocketTransport implements IRequestTransport, ISubscriptionTransport {
|
|
43
|
+
/** The interval timer ID for keep-alive messages. */
|
|
44
|
+
protected _keepAliveTimer: number | undefined;
|
|
45
|
+
/** The WebSocket request dispatcher instance. */
|
|
46
|
+
protected _wsRequester: WebSocketRequestDispatcher;
|
|
47
|
+
/** The Hyperliquid event target instance. */
|
|
48
|
+
protected _hlEvents: HyperliquidEventTarget;
|
|
49
|
+
/**
|
|
50
|
+
* Map of active subscriptions.
|
|
51
|
+
* - Key: Unique subscription identifier (stringified payload)
|
|
52
|
+
* - Value: Subscription info containing payload and listener mappings
|
|
53
|
+
*/
|
|
54
|
+
protected _subscriptions: Map<string, {
|
|
55
|
+
channel: string;
|
|
56
|
+
listeners: Map<(data: CustomEvent) => void, () => Promise<void>>;
|
|
57
|
+
requestPromise: Promise<unknown>;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Request timeout in ms.
|
|
61
|
+
* Set to `null` to disable.
|
|
62
|
+
*/
|
|
63
|
+
timeout: number | null;
|
|
64
|
+
/** Keep-alive configuration settings. */
|
|
65
|
+
readonly keepAlive: {
|
|
66
|
+
/**
|
|
67
|
+
* The interval in ms to send keep-alive messages.
|
|
68
|
+
* Set to `null` to disable.
|
|
69
|
+
*/
|
|
70
|
+
readonly interval: number | null;
|
|
71
|
+
};
|
|
72
|
+
/** The WebSocket that is used for communication. */
|
|
73
|
+
readonly socket: ReconnectingWebSocket;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new WebSocket transport instance.
|
|
76
|
+
* @param options - Configuration options for the WebSocket transport layer.
|
|
77
|
+
*/
|
|
78
|
+
constructor(options?: WebSocketTransportOptions);
|
|
79
|
+
/**
|
|
80
|
+
* Sends a request to the Hyperliquid API via WebSocket.
|
|
81
|
+
* @param endpoint - The API endpoint to send the request to.
|
|
82
|
+
* @param payload - The payload to send with the request.
|
|
83
|
+
* @param signal - An optional abort signal.
|
|
84
|
+
* @returns A promise that resolves with parsed JSON response body.
|
|
85
|
+
* @throws {WebSocketRequestError} - An error that occurs when a WebSocket request fails.
|
|
86
|
+
* @note Explorer requests are not supported in the Hyperliquid WebSocket API.
|
|
87
|
+
*/
|
|
88
|
+
request(type: "info" | "action" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Subscribes to a Hyperliquid event channel.
|
|
91
|
+
* @param channel - The event channel to listen to.
|
|
92
|
+
* @param payload - A payload to send with the subscription request.
|
|
93
|
+
* @param listener - A function to call when the event is dispatched.
|
|
94
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
95
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
96
|
+
*/
|
|
97
|
+
subscribe(channel: string, payload: unknown, listener: (data: CustomEvent) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
98
|
+
/**
|
|
99
|
+
* Waits until the WebSocket connection is ready.
|
|
100
|
+
* @param signal - An optional abort signal.
|
|
101
|
+
* @returns A promise that resolves when the connection is ready.
|
|
102
|
+
*/
|
|
103
|
+
ready(signal?: AbortSignal): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Closes the WebSocket connection and waits until it is fully closed.
|
|
106
|
+
* @param signal - An optional abort signal.
|
|
107
|
+
* @returns A promise that resolves when the connection is fully closed.
|
|
108
|
+
*/
|
|
109
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Combines timeout and user-provided signal.
|
|
112
|
+
* @param signal - A user-provided signal.
|
|
113
|
+
* @returns An AbortSignal that triggers when either the timeout or user-provided signal aborts.
|
|
114
|
+
*/
|
|
115
|
+
protected combineSignals(signal?: AbortSignal): AbortSignal;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=websocket_transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC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,qBAAqB,CAAC;IAEvC;;;OAGG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAwC/C;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvG;;;;;;;OAOG;IACG,SAAS,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EACrC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAqDxB;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB1C;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB1C;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW;CAM9D"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { ReconnectingWebSocket } from "./reconnecting_websocket.js";
|
|
2
|
+
import { HyperliquidEventTarget } from "./hyperliquid_event_target.js";
|
|
3
|
+
import { WebSocketRequestDispatcher } from "./websocket_request_dispatcher.js";
|
|
4
|
+
/**
|
|
5
|
+
* WebSocket implementation of the REST and Subscription transport interfaces.
|
|
6
|
+
*/
|
|
7
|
+
export class WebSocketTransport {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new WebSocket transport instance.
|
|
10
|
+
* @param options - Configuration options for the WebSocket transport layer.
|
|
11
|
+
*/
|
|
12
|
+
constructor(options) {
|
|
13
|
+
/** The interval timer ID for keep-alive messages. */
|
|
14
|
+
Object.defineProperty(this, "_keepAliveTimer", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
/** The WebSocket request dispatcher instance. */
|
|
21
|
+
Object.defineProperty(this, "_wsRequester", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
/** The Hyperliquid event target instance. */
|
|
28
|
+
Object.defineProperty(this, "_hlEvents", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Map of active subscriptions.
|
|
36
|
+
* - Key: Unique subscription identifier (stringified payload)
|
|
37
|
+
* - Value: Subscription info containing payload and listener mappings
|
|
38
|
+
*/
|
|
39
|
+
Object.defineProperty(this, "_subscriptions", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: new Map()
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Request timeout in ms.
|
|
47
|
+
* Set to `null` to disable.
|
|
48
|
+
*/
|
|
49
|
+
Object.defineProperty(this, "timeout", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
/** Keep-alive configuration settings. */
|
|
56
|
+
Object.defineProperty(this, "keepAlive", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
/** The WebSocket that is used for communication. */
|
|
63
|
+
Object.defineProperty(this, "socket", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
this.socket = new ReconnectingWebSocket(options?.url ?? "wss://api.hyperliquid.xyz/ws", undefined, options?.reconnect);
|
|
70
|
+
this._hlEvents = new HyperliquidEventTarget(this.socket);
|
|
71
|
+
this._wsRequester = new WebSocketRequestDispatcher(this.socket, this._hlEvents);
|
|
72
|
+
this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
|
|
73
|
+
this.keepAlive = {
|
|
74
|
+
interval: options?.keepAlive?.interval === undefined ? 20_000 : options.keepAlive.interval,
|
|
75
|
+
};
|
|
76
|
+
// Initialize listeners
|
|
77
|
+
this.socket.addEventListener("open", () => {
|
|
78
|
+
// Start keep-alive timer
|
|
79
|
+
if (this.keepAlive.interval && !this._keepAliveTimer) {
|
|
80
|
+
this._keepAliveTimer = setInterval(() => {
|
|
81
|
+
this.socket.send(JSON.stringify({ method: "ping" }));
|
|
82
|
+
}, this.keepAlive.interval);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
this.socket.addEventListener("close", () => {
|
|
86
|
+
// Clear keep-alive timer
|
|
87
|
+
if (this._keepAliveTimer) {
|
|
88
|
+
clearInterval(this._keepAliveTimer);
|
|
89
|
+
this._keepAliveTimer = undefined;
|
|
90
|
+
}
|
|
91
|
+
// Clear all subscriptions
|
|
92
|
+
for (const [_, { channel, listeners }] of this._subscriptions.entries()) {
|
|
93
|
+
for (const [listener] of listeners) {
|
|
94
|
+
this._hlEvents.removeEventListener(channel, listener);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this._subscriptions.clear();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sends a request to the Hyperliquid API via WebSocket.
|
|
102
|
+
* @param endpoint - The API endpoint to send the request to.
|
|
103
|
+
* @param payload - The payload to send with the request.
|
|
104
|
+
* @param signal - An optional abort signal.
|
|
105
|
+
* @returns A promise that resolves with parsed JSON response body.
|
|
106
|
+
* @throws {WebSocketRequestError} - An error that occurs when a WebSocket request fails.
|
|
107
|
+
* @note Explorer requests are not supported in the Hyperliquid WebSocket API.
|
|
108
|
+
*/
|
|
109
|
+
request(type, payload, signal) {
|
|
110
|
+
// Reject explorer requests because they are not supported by the Hyperliquid WebSocket API
|
|
111
|
+
if (type === "explorer") {
|
|
112
|
+
throw new Error("Explorer requests are not supported in the Hyperliquid WebSocket API.");
|
|
113
|
+
}
|
|
114
|
+
// Send the request and wait for a response
|
|
115
|
+
return this._wsRequester.request("post", { type, payload }, this.combineSignals(signal));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Subscribes to a Hyperliquid event channel.
|
|
119
|
+
* @param channel - The event channel to listen to.
|
|
120
|
+
* @param payload - A payload to send with the subscription request.
|
|
121
|
+
* @param listener - A function to call when the event is dispatched.
|
|
122
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
123
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
124
|
+
*/
|
|
125
|
+
async subscribe(channel, payload, listener, signal) {
|
|
126
|
+
// Create a unique identifier for the subscription
|
|
127
|
+
const id = `${channel}::${WebSocketRequestDispatcher.requestToId(payload)}`;
|
|
128
|
+
// Initialize new subscription, if it doesn't exist
|
|
129
|
+
let subscriptionInfo = this._subscriptions.get(id);
|
|
130
|
+
if (!subscriptionInfo) {
|
|
131
|
+
// Send subscription request
|
|
132
|
+
const requestPromise = this._wsRequester.request("subscribe", payload, this.combineSignals(signal))
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
this._subscriptions.delete(id);
|
|
135
|
+
throw error;
|
|
136
|
+
});
|
|
137
|
+
// Cache subscription info
|
|
138
|
+
subscriptionInfo = { channel, listeners: new Map(), requestPromise };
|
|
139
|
+
this._subscriptions.set(id, subscriptionInfo);
|
|
140
|
+
}
|
|
141
|
+
// Check if we already have an unsubscribe function for this listener
|
|
142
|
+
let unsubscribe = subscriptionInfo.listeners.get(listener);
|
|
143
|
+
if (!unsubscribe) {
|
|
144
|
+
// Create new unsubscribe function if none exists
|
|
145
|
+
unsubscribe = async (signal) => {
|
|
146
|
+
// Remove listener and cleanup
|
|
147
|
+
this._hlEvents.removeEventListener(channel, listener);
|
|
148
|
+
const isDeleted = subscriptionInfo.listeners.delete(listener);
|
|
149
|
+
// If no listeners remain, remove subscription entirely
|
|
150
|
+
// `isDeleted` means that the map had a listener before and became 0 after that
|
|
151
|
+
if (subscriptionInfo.listeners.size === 0 && isDeleted) {
|
|
152
|
+
this._subscriptions.delete(id);
|
|
153
|
+
await this._wsRequester.request("unsubscribe", payload, this.combineSignals(signal));
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// Add event listener & Cache unsubscribe function
|
|
157
|
+
this._hlEvents.addEventListener(channel, listener);
|
|
158
|
+
subscriptionInfo.listeners.set(listener, unsubscribe);
|
|
159
|
+
}
|
|
160
|
+
// Wait for the initial subscription request to complete
|
|
161
|
+
await subscriptionInfo.requestPromise.catch((error) => {
|
|
162
|
+
// Cleanup the subscription and rethrow the error
|
|
163
|
+
this._hlEvents.removeEventListener(channel, listener);
|
|
164
|
+
subscriptionInfo.listeners.delete(listener);
|
|
165
|
+
throw error;
|
|
166
|
+
});
|
|
167
|
+
// Return subscription control object
|
|
168
|
+
return { unsubscribe };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Waits until the WebSocket connection is ready.
|
|
172
|
+
* @param signal - An optional abort signal.
|
|
173
|
+
* @returns A promise that resolves when the connection is ready.
|
|
174
|
+
*/
|
|
175
|
+
ready(signal) {
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
const combinedSignal = signal
|
|
178
|
+
? AbortSignal.any([this.socket.terminationSignal, signal])
|
|
179
|
+
: this.socket.terminationSignal;
|
|
180
|
+
if (combinedSignal.aborted)
|
|
181
|
+
return reject(combinedSignal.reason);
|
|
182
|
+
if (this.socket.readyState === WebSocket.OPEN)
|
|
183
|
+
return resolve();
|
|
184
|
+
const handleOpen = () => {
|
|
185
|
+
combinedSignal.removeEventListener("abort", handleAbort);
|
|
186
|
+
resolve();
|
|
187
|
+
};
|
|
188
|
+
const handleAbort = () => {
|
|
189
|
+
this.socket.removeEventListener("open", handleOpen);
|
|
190
|
+
reject(combinedSignal.reason);
|
|
191
|
+
};
|
|
192
|
+
this.socket.addEventListener("open", handleOpen, { once: true });
|
|
193
|
+
combinedSignal.addEventListener("abort", handleAbort, { once: true });
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Closes the WebSocket connection and waits until it is fully closed.
|
|
198
|
+
* @param signal - An optional abort signal.
|
|
199
|
+
* @returns A promise that resolves when the connection is fully closed.
|
|
200
|
+
*/
|
|
201
|
+
close(signal) {
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
if (signal?.aborted)
|
|
204
|
+
return reject(signal.reason);
|
|
205
|
+
if (this.socket.readyState === WebSocket.CLOSED)
|
|
206
|
+
return resolve();
|
|
207
|
+
const handleClose = () => {
|
|
208
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
209
|
+
resolve();
|
|
210
|
+
};
|
|
211
|
+
const handleAbort = () => {
|
|
212
|
+
this.socket.removeEventListener("close", handleClose);
|
|
213
|
+
reject(signal?.reason);
|
|
214
|
+
};
|
|
215
|
+
this.socket.addEventListener("close", handleClose, { once: true });
|
|
216
|
+
signal?.addEventListener("abort", handleAbort, { once: true });
|
|
217
|
+
this.socket.close();
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Combines timeout and user-provided signal.
|
|
222
|
+
* @param signal - A user-provided signal.
|
|
223
|
+
* @returns An AbortSignal that triggers when either the timeout or user-provided signal aborts.
|
|
224
|
+
*/
|
|
225
|
+
combineSignals(signal) {
|
|
226
|
+
const signals = [];
|
|
227
|
+
if (this.timeout)
|
|
228
|
+
signals.push(AbortSignal.timeout(this.timeout));
|
|
229
|
+
if (signal)
|
|
230
|
+
signals.push(signal);
|
|
231
|
+
return signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BatchModifyRequest, CancelByCloidRequest, CancelRequest, CreateSubAccountRequest, ModifyRequest, OrderRequest, ScheduleCancelRequest, SetReferrerRequest, SubAccountTransferRequest, TwapCancelRequest, TwapOrderRequest, UpdateIsolatedMarginRequest, UpdateLeverageRequest, VaultTransferRequest } from "../types/exchange/requests";
|
|
2
|
+
import type { OrderParms } from "../types/exchange/common";
|
|
3
|
+
/** Record of action types and their corresponding sorters. */
|
|
4
|
+
export declare const sorters: {
|
|
5
|
+
batchModify: (action: BatchModifyRequest["action"]) => BatchModifyRequest["action"];
|
|
6
|
+
cancel: (action: CancelRequest["action"]) => CancelRequest["action"];
|
|
7
|
+
cancelByCloid: (action: CancelByCloidRequest["action"]) => CancelByCloidRequest["action"];
|
|
8
|
+
createSubAccount: (action: CreateSubAccountRequest["action"]) => CreateSubAccountRequest["action"];
|
|
9
|
+
modify: (action: ModifyRequest["action"]) => ModifyRequest["action"];
|
|
10
|
+
order: (action: OrderRequest["action"]) => OrderRequest["action"];
|
|
11
|
+
scheduleCancel: (action: ScheduleCancelRequest["action"]) => ScheduleCancelRequest["action"];
|
|
12
|
+
setReferrer: (action: SetReferrerRequest["action"]) => SetReferrerRequest["action"];
|
|
13
|
+
subAccountTransfer: (action: SubAccountTransferRequest["action"]) => SubAccountTransferRequest["action"];
|
|
14
|
+
twapCancel: (action: TwapCancelRequest["action"]) => TwapCancelRequest["action"];
|
|
15
|
+
twapOrder: (action: TwapOrderRequest["action"]) => TwapOrderRequest["action"];
|
|
16
|
+
updateIsolatedMargin: (action: UpdateIsolatedMarginRequest["action"]) => UpdateIsolatedMarginRequest["action"];
|
|
17
|
+
updateLeverage: (action: UpdateLeverageRequest["action"]) => UpdateLeverageRequest["action"];
|
|
18
|
+
vaultTransfer: (action: VaultTransferRequest["action"]) => VaultTransferRequest["action"];
|
|
19
|
+
_order: (order: OrderParms) => OrderParms;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=key_sort.d.ts.map
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,KAAG,2BAA2B,CAAC,QAAQ,CAAC;6BAMnF,qBAAqB,CAAC,QAAQ,CAAC,KAAG,qBAAqB,CAAC,QAAQ,CAAC;4BAMlE,oBAAoB,CAAC,QAAQ,CAAC,KAAG,oBAAoB,CAAC,QAAQ,CAAC;oBAOvE,UAAU,KAAG,UAAU;CAyB1C,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** Record of action types and their corresponding sorters. */
|
|
2
|
+
// NOTE: An object after sorting must not contain undefined values.
|
|
3
|
+
export const sorters = {
|
|
4
|
+
batchModify: (action) => ({
|
|
5
|
+
type: action.type,
|
|
6
|
+
modifies: action.modifies.map((m) => ({
|
|
7
|
+
oid: m.oid,
|
|
8
|
+
order: sorters._order(m.order),
|
|
9
|
+
})),
|
|
10
|
+
}),
|
|
11
|
+
cancel: (action) => ({
|
|
12
|
+
type: action.type,
|
|
13
|
+
cancels: action.cancels.map((c) => ({
|
|
14
|
+
a: c.a,
|
|
15
|
+
o: c.o,
|
|
16
|
+
})),
|
|
17
|
+
}),
|
|
18
|
+
cancelByCloid: (action) => ({
|
|
19
|
+
type: action.type,
|
|
20
|
+
cancels: action.cancels.map((cancel) => ({
|
|
21
|
+
asset: cancel.asset,
|
|
22
|
+
cloid: cancel.cloid,
|
|
23
|
+
})),
|
|
24
|
+
}),
|
|
25
|
+
createSubAccount: (action) => ({
|
|
26
|
+
type: action.type,
|
|
27
|
+
name: action.name,
|
|
28
|
+
}),
|
|
29
|
+
modify: (action) => ({
|
|
30
|
+
type: action.type,
|
|
31
|
+
oid: action.oid,
|
|
32
|
+
order: sorters._order(action.order),
|
|
33
|
+
}),
|
|
34
|
+
order: (action) => {
|
|
35
|
+
const sortedAction = {
|
|
36
|
+
type: action.type,
|
|
37
|
+
orders: action.orders.map(sorters._order),
|
|
38
|
+
grouping: action.grouping,
|
|
39
|
+
builder: action.builder ? { b: action.builder.b, f: action.builder.f } : undefined,
|
|
40
|
+
};
|
|
41
|
+
if (action.builder === undefined)
|
|
42
|
+
delete sortedAction.builder;
|
|
43
|
+
return sortedAction;
|
|
44
|
+
},
|
|
45
|
+
scheduleCancel: (action) => {
|
|
46
|
+
const sortedAction = {
|
|
47
|
+
type: action.type,
|
|
48
|
+
time: action.time,
|
|
49
|
+
};
|
|
50
|
+
if (action.time === undefined)
|
|
51
|
+
delete sortedAction.time;
|
|
52
|
+
return sortedAction;
|
|
53
|
+
},
|
|
54
|
+
setReferrer: (action) => ({
|
|
55
|
+
type: action.type,
|
|
56
|
+
code: action.code,
|
|
57
|
+
}),
|
|
58
|
+
subAccountTransfer: (action) => ({
|
|
59
|
+
type: action.type,
|
|
60
|
+
subAccountUser: action.subAccountUser,
|
|
61
|
+
isDeposit: action.isDeposit,
|
|
62
|
+
usd: action.usd,
|
|
63
|
+
}),
|
|
64
|
+
twapCancel: (action) => ({
|
|
65
|
+
type: action.type,
|
|
66
|
+
a: action.a,
|
|
67
|
+
t: action.t,
|
|
68
|
+
}),
|
|
69
|
+
twapOrder: (action) => ({
|
|
70
|
+
type: action.type,
|
|
71
|
+
twap: {
|
|
72
|
+
a: action.twap.a,
|
|
73
|
+
b: action.twap.b,
|
|
74
|
+
s: action.twap.s,
|
|
75
|
+
r: action.twap.r,
|
|
76
|
+
m: action.twap.m,
|
|
77
|
+
t: action.twap.t,
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
updateIsolatedMargin: (action) => ({
|
|
81
|
+
type: action.type,
|
|
82
|
+
asset: action.asset,
|
|
83
|
+
isBuy: action.isBuy,
|
|
84
|
+
ntli: action.ntli,
|
|
85
|
+
}),
|
|
86
|
+
updateLeverage: (action) => ({
|
|
87
|
+
type: action.type,
|
|
88
|
+
asset: action.asset,
|
|
89
|
+
isCross: action.isCross,
|
|
90
|
+
leverage: action.leverage,
|
|
91
|
+
}),
|
|
92
|
+
vaultTransfer: (action) => ({
|
|
93
|
+
type: action.type,
|
|
94
|
+
vaultAddress: action.vaultAddress,
|
|
95
|
+
isDeposit: action.isDeposit,
|
|
96
|
+
usd: action.usd,
|
|
97
|
+
}),
|
|
98
|
+
_order: (order) => {
|
|
99
|
+
const sortedOrder = {
|
|
100
|
+
a: order.a,
|
|
101
|
+
b: order.b,
|
|
102
|
+
p: order.p,
|
|
103
|
+
s: order.s,
|
|
104
|
+
r: order.r,
|
|
105
|
+
t: "limit" in order.t
|
|
106
|
+
? {
|
|
107
|
+
limit: {
|
|
108
|
+
tif: order.t.limit.tif,
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
: {
|
|
112
|
+
trigger: {
|
|
113
|
+
isMarket: order.t.trigger.isMarket,
|
|
114
|
+
triggerPx: order.t.trigger.triggerPx,
|
|
115
|
+
tpsl: order.t.trigger.tpsl,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
c: order.c,
|
|
119
|
+
};
|
|
120
|
+
if (order.c === undefined)
|
|
121
|
+
delete sortedOrder.c;
|
|
122
|
+
return sortedOrder;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type ValueType } from "../../deps/jsr.io/@std/msgpack/1.0.2/encode.js";
|
|
2
|
+
type Hex = `0x${string}`;
|
|
3
|
+
/** Abstract interface for a [ethers.js](https://docs.ethers.org/v6/api/providers/#Signer) signer. */
|
|
4
|
+
export interface AbstractEthersSigner {
|
|
5
|
+
signTypedData(domain: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
chainId: number;
|
|
9
|
+
verifyingContract: string;
|
|
10
|
+
}, types: {
|
|
11
|
+
[key: string]: {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}[];
|
|
15
|
+
}, value: Record<string, unknown>): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
/** Abstract interface for a [ethers.js v5](https://docs.ethers.org/v5/api/providers/#Signer) signer. */
|
|
18
|
+
export interface AbstractEthersV5Signer {
|
|
19
|
+
_signTypedData(domain: {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
verifyingContract: string;
|
|
24
|
+
}, types: {
|
|
25
|
+
[key: string]: {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}[];
|
|
29
|
+
}, value: Record<string, unknown>): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
/** Abstract interface for a [viem](https://viem.sh/docs/clients/wallet) wallet client. */
|
|
32
|
+
export interface AbstractViemWalletClient {
|
|
33
|
+
signTypedData(params: {
|
|
34
|
+
domain: {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
chainId: number;
|
|
38
|
+
verifyingContract: Hex;
|
|
39
|
+
};
|
|
40
|
+
types: {
|
|
41
|
+
[key: string]: {
|
|
42
|
+
name: string;
|
|
43
|
+
type: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
primaryType: string;
|
|
47
|
+
message: Record<string, unknown>;
|
|
48
|
+
}): Promise<Hex>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a hash of the action.
|
|
52
|
+
* @param action - The action to hash.
|
|
53
|
+
* @param nonce - The nonce of the action.
|
|
54
|
+
* @param vaultAddress - Optional vault address.
|
|
55
|
+
* @returns The hash of the action.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createActionHash(action: ValueType, nonce: number, vaultAddress?: Hex): Hex;
|
|
58
|
+
/**
|
|
59
|
+
* Sign an L1 action.
|
|
60
|
+
* @param wallet - The wallet to sign with.
|
|
61
|
+
* @param isTestnet - A boolean indicating if the action is for the testnet.
|
|
62
|
+
* @param action - The action to sign.
|
|
63
|
+
* @param nonce - The nonce of the action.
|
|
64
|
+
* @param vaultAddress - Optional vault address.
|
|
65
|
+
* @returns The signature.
|
|
66
|
+
*/
|
|
67
|
+
export declare function signL1Action(wallet: AbstractEthersSigner | AbstractEthersV5Signer | AbstractViemWalletClient, isTestnet: boolean, action: ValueType, nonce: number, vaultAddress?: Hex): Promise<{
|
|
68
|
+
r: Hex;
|
|
69
|
+
s: Hex;
|
|
70
|
+
v: number;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Sign a user-signed action.
|
|
74
|
+
* @param wallet - The wallet to sign with.
|
|
75
|
+
* @param action - The action to sign.
|
|
76
|
+
* @param types - The types of the action.
|
|
77
|
+
* @param chainId - The chain ID of the action.
|
|
78
|
+
* @returns The signature.
|
|
79
|
+
*/
|
|
80
|
+
export declare function signUserSignedAction(wallet: AbstractEthersSigner | AbstractEthersV5Signer | AbstractViemWalletClient, action: Record<string, unknown>, types: {
|
|
81
|
+
[key: string]: {
|
|
82
|
+
name: string;
|
|
83
|
+
type: string;
|
|
84
|
+
}[];
|
|
85
|
+
}, chainId: number): Promise<{
|
|
86
|
+
r: Hex;
|
|
87
|
+
s: Hex;
|
|
88
|
+
v: number;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the given client is an abstract signer (ethers.js).
|
|
92
|
+
* @param client - The client to check.
|
|
93
|
+
* @returns A boolean indicating if the client is an abstract signer.
|
|
94
|
+
*/
|
|
95
|
+
export declare function isAbstractEthersSigner(client: unknown): client is AbstractEthersSigner;
|
|
96
|
+
/**
|
|
97
|
+
* Checks if the given client is an abstract signer (ethers.js v5).
|
|
98
|
+
* @param client - The client to check.
|
|
99
|
+
* @returns A boolean indicating if the client is an abstract signer.
|
|
100
|
+
*/
|
|
101
|
+
export declare function isAbstractEthersV5Signer(client: unknown): client is AbstractEthersV5Signer;
|
|
102
|
+
/**
|
|
103
|
+
* Checks if the given client is an abstract wallet client (viem).
|
|
104
|
+
* @param client - The client to check.
|
|
105
|
+
* @returns A boolean indicating if the client is an abstract wallet client.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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