@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.
Files changed (145) hide show
  1. package/CONTRIBUTING.md +59 -0
  2. package/LICENSE +21 -0
  3. package/README.md +363 -0
  4. package/SECURITY.md +7 -0
  5. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
  6. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +1 -0
  8. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
  9. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
  10. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +10 -0
  11. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
  12. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
  13. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +43 -0
  14. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
  15. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +65 -0
  17. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
  18. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +1 -0
  20. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
  21. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +283 -0
  23. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
  24. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
  25. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +211 -0
  26. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
  27. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
  28. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.js +32 -0
  29. package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
  30. package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +26 -0
  32. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
  33. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
  34. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js +109 -0
  35. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
  36. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
  37. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.js +237 -0
  38. package/esm/mod.d.ts +24 -0
  39. package/esm/mod.d.ts.map +1 -0
  40. package/esm/mod.js +9 -0
  41. package/esm/package.json +3 -0
  42. package/esm/src/clients/event.d.ts +374 -0
  43. package/esm/src/clients/event.d.ts.map +1 -0
  44. package/esm/src/clients/event.js +490 -0
  45. package/esm/src/clients/public.d.ts +695 -0
  46. package/esm/src/clients/public.d.ts.map +1 -0
  47. package/esm/src/clients/public.js +704 -0
  48. package/esm/src/clients/wallet.d.ts +682 -0
  49. package/esm/src/clients/wallet.d.ts.map +1 -0
  50. package/esm/src/clients/wallet.js +984 -0
  51. package/esm/src/transports/base.d.ts +55 -0
  52. package/esm/src/transports/base.d.ts.map +1 -0
  53. package/esm/src/transports/base.js +14 -0
  54. package/esm/src/transports/http/http_transport.d.ts +78 -0
  55. package/esm/src/transports/http/http_transport.d.ts.map +1 -0
  56. package/esm/src/transports/http/http_transport.js +170 -0
  57. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
  58. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
  59. package/esm/src/transports/websocket/hyperliquid_event_target.js +33 -0
  60. package/esm/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
  61. package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
  62. package/esm/src/transports/websocket/reconnecting_websocket.js +370 -0
  63. package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
  64. package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
  65. package/esm/src/transports/websocket/websocket_request_dispatcher.js +201 -0
  66. package/esm/src/transports/websocket/websocket_transport.d.ts +117 -0
  67. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -0
  68. package/esm/src/transports/websocket/websocket_transport.js +233 -0
  69. package/esm/src/utils/key_sort.d.ts +21 -0
  70. package/esm/src/utils/key_sort.d.ts.map +1 -0
  71. package/esm/src/utils/key_sort.js +124 -0
  72. package/esm/src/utils/signing.d.ts +109 -0
  73. package/esm/src/utils/signing.d.ts.map +1 -0
  74. package/esm/src/utils/signing.js +164 -0
  75. package/package.json +34 -0
  76. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
  77. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
  78. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +17 -0
  79. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
  80. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
  81. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +14 -0
  82. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
  83. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
  84. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +49 -0
  85. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
  86. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
  87. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +88 -0
  88. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
  89. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
  90. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +4 -0
  91. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
  92. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
  93. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -0
  94. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
  95. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
  96. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +235 -0
  97. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
  98. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
  99. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +35 -0
  100. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
  101. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
  102. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +29 -0
  103. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
  104. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
  105. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +113 -0
  106. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
  107. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
  108. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +240 -0
  109. package/script/mod.d.ts +24 -0
  110. package/script/mod.d.ts.map +1 -0
  111. package/script/mod.js +27 -0
  112. package/script/package.json +3 -0
  113. package/script/src/clients/event.d.ts +374 -0
  114. package/script/src/clients/event.d.ts.map +1 -0
  115. package/script/src/clients/event.js +494 -0
  116. package/script/src/clients/public.d.ts +695 -0
  117. package/script/src/clients/public.d.ts.map +1 -0
  118. package/script/src/clients/public.js +708 -0
  119. package/script/src/clients/wallet.d.ts +682 -0
  120. package/script/src/clients/wallet.d.ts.map +1 -0
  121. package/script/src/clients/wallet.js +989 -0
  122. package/script/src/transports/base.d.ts +55 -0
  123. package/script/src/transports/base.d.ts.map +1 -0
  124. package/script/src/transports/base.js +18 -0
  125. package/script/src/transports/http/http_transport.d.ts +78 -0
  126. package/script/src/transports/http/http_transport.d.ts.map +1 -0
  127. package/script/src/transports/http/http_transport.js +175 -0
  128. package/script/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
  129. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
  130. package/script/src/transports/websocket/hyperliquid_event_target.js +37 -0
  131. package/script/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
  132. package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
  133. package/script/src/transports/websocket/reconnecting_websocket.js +374 -0
  134. package/script/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
  135. package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
  136. package/script/src/transports/websocket/websocket_request_dispatcher.js +206 -0
  137. package/script/src/transports/websocket/websocket_transport.d.ts +117 -0
  138. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -0
  139. package/script/src/transports/websocket/websocket_transport.js +237 -0
  140. package/script/src/utils/key_sort.d.ts +21 -0
  141. package/script/src/utils/key_sort.d.ts.map +1 -0
  142. package/script/src/utils/key_sort.js +127 -0
  143. package/script/src/utils/signing.d.ts +109 -0
  144. package/script/src/utils/signing.d.ts.map +1 -0
  145. package/script/src/utils/signing.js +172 -0
@@ -0,0 +1,59 @@
1
+ # Contributing to @nktkas/hyperliquid
2
+
3
+ First off, thanks for considering contributing to the Hyperliquid TypeScript SDK!
4
+
5
+ ## How Can You Contribute?
6
+
7
+ ### Report Issues
8
+
9
+ If you find bugs or have suggestions for improvements, please open an issue on GitHub. Provide as much detail as
10
+ possible to help us understand and address the problem.
11
+
12
+ ### Submit Pull Requests
13
+
14
+ - **Fork the Repository**: Click the "Fork" button at the top-right corner of the repository page.
15
+ - **Clone Your Fork**: Clone your forked repository to your local machine.
16
+
17
+ ```bash
18
+ git clone https://github.com/your-username/hyperliquid.git
19
+ ```
20
+
21
+ - **Create a Branch**: Create a new branch for your feature or bug fix.
22
+
23
+ ```bash
24
+ git checkout -b feature/your-feature-name
25
+ ```
26
+
27
+ - **Make Your Changes**: Implement your feature or fix the bug.
28
+ - **Commit Your Changes**:
29
+
30
+ ```bash
31
+ git commit -am "Add new feature or fix"
32
+ ```
33
+
34
+ - **Push to Your Fork**:
35
+
36
+ ```bash
37
+ git push origin feature/your-feature-name
38
+ ```
39
+
40
+ - **Create a Pull Request**: Go to the original repository and click on "New Pull Request". Select your branch and
41
+ submit the pull request.
42
+
43
+ ### Coding Guidelines
44
+
45
+ - **TypeScript**: Ensure your code passes TypeScript compilation without errors.
46
+ - **Style**: Follow existing code style and conventions.
47
+ - **Dependencies**: Avoid adding unnecessary dependencies.
48
+ - **Docs**: Update or add JSDoc comments where appropriate.
49
+
50
+ ### Testing
51
+
52
+ Before submitting your pull request:
53
+
54
+ - Run existing tests to ensure nothing breaks.
55
+ - If you add new features, consider adding tests for them.
56
+
57
+ ### License
58
+
59
+ By contributing, you agree that your contributions will be licensed under the MIT License.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 nktkas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,363 @@
1
+ # Hyperliquid API TypeScript SDK
2
+
3
+ [![JSR](https://jsr.io/badges/@nktkas/hyperliquid)](https://jsr.io/@nktkas/hyperliquid)
4
+ [![JSR Score](https://jsr.io/badges/@nktkas/hyperliquid/score)](https://jsr.io/@nktkas/hyperliquid)
5
+
6
+ Unofficial [Hyperliquid API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api) SDK for all major JS
7
+ runtimes, written in TypeScript and provided with tests.
8
+
9
+ ## Features
10
+
11
+ - 🖋️ **Typed**: Source code is 100% TypeScript.
12
+ - 🧪 **Tested**: Good code coverage and type validation.
13
+ - 📦 **Minimal dependencies**: Few small dependencies, standard JS is favored.
14
+ - 🌐 **Cross-Environment Support**: Compatible with all major JS runtimes, including Node.js, Deno, Bun, and browser
15
+ environments.
16
+ - 🔧 **Extensible**: Easily integrates with [viem](https://github.com/wevm/viem) and
17
+ [ethers](https://github.com/ethers-io/ethers.js).
18
+ - 📚 **Documented**: Comprehensive documentation and usage examples, provided directly in JSDoc annotations within the
19
+ source code.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ # npm
25
+ npx jsr add @nktkas/hyperliquid
26
+
27
+ # yarn
28
+ yarn dlx jsr add @nktkas/hyperliquid
29
+
30
+ # pnpm
31
+ pnpm dlx jsr add @nktkas/hyperliquid
32
+
33
+ # bun
34
+ bunx jsr add @nktkas/hyperliquid
35
+
36
+ # deno
37
+ deno add jsr:@nktkas/hyperliquid
38
+
39
+ # web (import directly)
40
+ import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid"
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### Initialize Transport
46
+
47
+ First, choose and configure your transport layer (more details in the [API Reference](#transports)):
48
+
49
+ ```typescript
50
+ import * as hl from "@nktkas/hyperliquid";
51
+
52
+ // HTTP Transport
53
+ const httpTransport = new hl.HttpTransport({ // All options are optional
54
+ url: "https://api.hyperliquid.xyz", // API base URL for /info, /exchange, /explorer
55
+ timeout: 10_000, // Request timeout in ms
56
+ });
57
+
58
+ // OR WebSocket Transport
59
+ const wsTransport = new hl.WebSocketTransport({ // All options are optional
60
+ url: "wss://api.hyperliquid.xyz/ws", // WebSocket URL
61
+ timeout: 10_000, // Request timeout in ms
62
+ });
63
+ ```
64
+
65
+ ### Initialize Client
66
+
67
+ Next, initialize the client with the transport layer (more details in the [API Reference](#clients)):
68
+
69
+ #### Create PublicClient
70
+
71
+ ```typescript
72
+ import * as hl from "@nktkas/hyperliquid";
73
+
74
+ const transport = new hl.HttpTransport(); // or WebSocketTransport
75
+ const client = new hl.PublicClient({ transport });
76
+ ```
77
+
78
+ #### Create WalletClient
79
+
80
+ ```typescript
81
+ import * as hl from "@nktkas/hyperliquid";
82
+ import { createWalletClient, custom } from "viem";
83
+ import { arbitrum } from "viem/chains";
84
+ import { privateKeyToAccount } from "viem/accounts";
85
+ import { ethers } from "ethers";
86
+
87
+ const transport = new hl.HttpTransport(); // or WebSocketTransport
88
+
89
+ // 1. Using Viem with private key
90
+ const viemAccount = privateKeyToAccount("0x...");
91
+ const viemClient = new hl.WalletClient({ wallet: viemAccount, transport });
92
+
93
+ // 2. Using Ethers (or Ethers V5) with private key
94
+ const ethersWallet = new ethers.Wallet("0x...");
95
+ const ethersClient = new hl.WalletClient({ wallet: ethersWallet, transport });
96
+
97
+ // 3. Using external wallet (e.g. MetaMask) via Viem
98
+ const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
99
+ const externalWallet = createWalletClient({
100
+ account,
101
+ chain: arbitrum,
102
+ transport: custom(window.ethereum),
103
+ });
104
+ const metamaskClient = new hl.WalletClient({ wallet: externalWallet, transport });
105
+ ```
106
+
107
+ ## API Reference
108
+
109
+ ### Clients
110
+
111
+ A **Client** provides access to the Hyperliquid API endpoints.
112
+
113
+ There are three types of **Clients** in the sdk:
114
+
115
+ #### Public Client
116
+
117
+ A Public Client which provides access to
118
+ [Info API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint) and Explorer API, such as
119
+ `l2Book` and `clearinghouseState`.
120
+
121
+ The Public Client class sets up with a given [Transport](#transports).
122
+
123
+ ```typescript
124
+ interface PublicClientParameters<T extends IRequestTransport = IRequestTransport> {
125
+ transport: T; // HttpTransport or WebSocketTransport
126
+ }
127
+
128
+ class PublicClient<T extends IRESTTransport> {
129
+ constructor(args: PublicClientParameters<T>);
130
+
131
+ // Market
132
+ allMids(): Promise<AllMids>;
133
+ candleSnapshot(args: CandleSnapshotParameters): Promise<CandleSnapshot[]>;
134
+ fundingHistory(args: FundingHistoryParameters): Promise<FundingHistory[]>;
135
+ l2Book(args: L2BookParameters): Promise<L2Book>;
136
+ meta(): Promise<Meta>;
137
+ metaAndAssetCtxs(): Promise<MetaAndAssetCtxs>;
138
+ predictedFundings(): Promise<PredictedFunding[]>;
139
+ spotDeployState(args: SpotDeployStateParameters): Promise<SpotDeployState>;
140
+ spotMeta(): Promise<SpotMeta>;
141
+ spotMetaAndAssetCtxs(): Promise<SpotMetaAndAssetCtxs>;
142
+ tokenDetails(args: TokenDetailsParameters): Promise<TokenDetails>;
143
+
144
+ // Account
145
+ clearinghouseState(args: ClearinghouseStateParameters): Promise<ClearinghouseState>;
146
+ extraAgents(args: ExtraAgentsParameters): Promise<ExtraAgent[]>;
147
+ maxBuilderFee(args: MaxBuilderFeeParameters): Promise<number>;
148
+ referral(args: ReferralParameters): Promise<Referral>;
149
+ spotClearinghouseState(args: SpotClearinghouseStateParameters): Promise<SpotClearinghouseState>;
150
+ subAccounts(args: SubAccountsParameters): Promise<SubAccount[]>;
151
+ userFees(args: UserFeesParameters): Promise<UserFees>;
152
+ userFunding(args: UserFundingParameters): Promise<UserFunding[]>;
153
+ userNonFundingLedgerUpdates(args: UserNonFundingLedgerUpdatesParameters): Promise<UserNonFundingLedgerUpdates[]>;
154
+ userRateLimit(args: UserRateLimitParameters): Promise<UserRateLimit>;
155
+
156
+ // Order
157
+ frontendOpenOrders(args: FrontendOpenOrdersParameters): Promise<FrontendOpenOrder[]>;
158
+ historicalOrders(args: HistoricalOrdersParameters): Promise<OrderStatus[]>;
159
+ openOrders(args: OpenOrdersParameters): Promise<OpenOrder[]>;
160
+ orderStatus(args: OrderStatusParameters): Promise<OrderStatusResponse>;
161
+ twapHistory(args: TwapHistoryParameters): Promise<TwapHistory>;
162
+ userFills(args: UserFillsParameters): Promise<UserFill[]>;
163
+ userFillsByTime(args: UserFillsByTimeParameters): Promise<UserFill[]>;
164
+ userTwapSliceFills(args: UserTwapSliceFillsParameters): Promise<UserTwapSliceFill[]>;
165
+
166
+ // Vault
167
+ userVaultEquities(args: UserVaultEquitiesParameters): Promise<UserVaultEquity[]>;
168
+ vaultDetails(args: VaultDetailsParameters): Promise<VaultDetails | null>;
169
+ vaultSummaries(): Promise<VaultSummary[]>;
170
+
171
+ // Blockchain
172
+ blockDetails(args: BlockDetailsParameters): Promise<BlockDetailsResponse>;
173
+ txDetails(args: TxDetailsParameters): Promise<TxDetailsResponse>;
174
+ }
175
+ ```
176
+
177
+ #### Wallet Client
178
+
179
+ A Wallet Client which provides access to
180
+ [Exchange API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint), such as `order`
181
+ and `withdraw3`.
182
+
183
+ The Wallet Client class sets up with a given [Transport](#transports) and a wallet instance, which can be a
184
+ [Viem Wallet](https://viem.sh/docs/clients/wallet) or an
185
+ [Ethers Wallet](https://docs.ethers.org/v6/api/providers/#Signer).
186
+
187
+ ```typescript
188
+ interface WalletClientParameters<
189
+ T extends ISubscriptionTransport,
190
+ W extends AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer,
191
+ > {
192
+ transport: T; // HttpTransport or WebSocketTransport
193
+ wallet: W; // viem, ethers, or ethers v5
194
+ isTestnet?: boolean; // Whether to use testnet API (default: false)
195
+ defaultVaultAddress?: Hex; // Vault address used by default if not provided in method call
196
+ }
197
+
198
+ class WalletClient<
199
+ T extends IRESTTransport,
200
+ W extends AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer,
201
+ > {
202
+ constructor(args: WalletClientParameters<T, W>);
203
+
204
+ // Order Management
205
+ batchModify(args: BatchModifyParameters): Promise<OrderResponseSuccess>;
206
+ cancel(args: CancelParameters): Promise<CancelResponseSuccess>;
207
+ cancelByCloid(args: CancelByCloidParameters): Promise<CancelResponseSuccess>;
208
+ modify(args: ModifyParameters): Promise<SuccessResponse>;
209
+ order(args: OrderParameters): Promise<OrderResponseSuccess>;
210
+ scheduleCancel(args: ScheduleCancelParameters): Promise<SuccessResponse>;
211
+ twapCancel(args: TwapCancelParameters): Promise<TwapCancelResponseSuccess>;
212
+ twapOrder(args: TwapOrderParameters): Promise<TwapOrderResponseSuccess>;
213
+ updateIsolatedMargin(args: UpdateIsolatedMarginParameters): Promise<SuccessResponse>;
214
+ updateLeverage(args: UpdateLeverageParameters): Promise<SuccessResponse>;
215
+
216
+ // Account Management
217
+ approveAgent(args: ApproveAgentParameters): Promise<SuccessResponse>;
218
+ approveBuilderFee(args: ApproveBuilderFeeParameters): Promise<SuccessResponse>;
219
+ createSubAccount(args: CreateSubAccountParameters): Promise<CreateSubAccountResponse>;
220
+ setReferrer(args: SetReferrerParameters): Promise<SuccessResponse>;
221
+
222
+ // Transfers & Withdrawals
223
+ spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
224
+ subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
225
+ usdClassTransfer(args: UsdClassTransferParameters): Promise<SuccessResponse>;
226
+ usdSend(args: UsdSendParameters): Promise<SuccessResponse>;
227
+ vaultTransfer(args: VaultTransferParameters): Promise<SuccessResponse>;
228
+ withdraw3(args: Withdraw3Parameters): Promise<SuccessResponse>;
229
+ }
230
+ ```
231
+
232
+ #### Event Client
233
+
234
+ A Event Client which provides access to
235
+ [Subscriptions API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions), such as
236
+ real-time updates for `l2Book` and `userFills`.
237
+
238
+ The Event Client class sets up with a given [WebSocket Transport](#websocket-transport).
239
+
240
+ <!-- deno-fmt-ignore-start -->
241
+ ```typescript
242
+ interface EventClientParameters<T extends ISubscriptionTransport> {
243
+ transport: T; // WebSocketTransport
244
+ }
245
+
246
+ class EventClient<T extends ISubscriptionTransport> {
247
+ constructor(args: EventClientParameters<T>);
248
+
249
+ // Market Data
250
+ activeAssetCtx(args: EventActiveAssetCtxParameters, listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void): Promise<Subscription>;
251
+ activeAssetData(args: EventActiveAssetDataParameters, listener: (data: WsActiveAssetData) => void): Promise<Subscription>;
252
+ allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
253
+ candle(args: EventCandleParameters, listener: (data: Candle) => void): Promise<Subscription>;
254
+ l2Book(args: EventL2BookParameters, listener: (data: Book) => void): Promise<Subscription>;
255
+ trades(args: EventTradesParameters, listener: (data: WsTrade[]) => void): Promise<Subscription>;
256
+
257
+ // Account/User Data
258
+ notification(args: EventNotificationParameters, listener: (data: WsNotification) => void): Promise<Subscription>;
259
+ userEvents(args: EventUserEventsParameters, listener: (data: WsUserEvent) => void): Promise<Subscription>;
260
+ userFundings(args: EventUserFundingsParameters, listener: (data: WsUserFundings) => void): Promise<Subscription>;
261
+ userNonFundingLedgerUpdates(args: EventUserNonFundingLedgerUpdatesParameters, listener: (data: WsUserNonFundingLedgerUpdates) => void): Promise<Subscription>;
262
+ webData2(args: EventWebData2Parameters, listener: (data: WsWebData2) => void): Promise<Subscription>;
263
+
264
+ // Order Management
265
+ orderUpdates(args: EventOrderUpdatesParameters, listener: (data: OrderStatus) => void): Promise<Subscription>;
266
+ userFills(args: EventUserFillsParameters, listener: (data: WsUserFills) => void): Promise<Subscription>;
267
+ userTwapHistory(args: EventUserTwapHistory, listener: (data: WsUserTwapHistory) => void): Promise<Subscription>;
268
+ userTwapSliceFills(args: EventUserTwapSliceFills, listener: (data: WsUserTwapSliceFills) => void): Promise<Subscription>;
269
+ }
270
+ ```
271
+ <!-- deno-fmt-ignore-end -->
272
+
273
+ ### Transports
274
+
275
+ A [Client](#clients) is instantiated with a **Transport**, which is the intermediary layer that is responsible for
276
+ executing outgoing requests (ie. API calls and event listeners).
277
+
278
+ There are two types of **Transports** in the sdk:
279
+
280
+ #### HTTP Transport
281
+
282
+ A HTTP Transport that executes requests via a [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch)
283
+ API.
284
+
285
+ ```typescript
286
+ class HttpTransport implements IRequestTransport, HttpTransportOptions {
287
+ constructor(options?: HttpTransportOptions);
288
+
289
+ request(endpoint: "info" | "action" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
290
+ }
291
+
292
+ interface HttpTransportOptions {
293
+ url?: string | URL; // Base URL for API endpoints (default: "https://api.hyperliquid.xyz")
294
+ timeout?: number; // Request timeout in ms (default: 10_000)
295
+ fetchOptions?: RequestInit; // A custom fetch options
296
+ onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>; // A callback before request is sent
297
+ onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>; // A callback after response is received
298
+ }
299
+ ```
300
+
301
+ #### WebSocket Transport
302
+
303
+ A WebSocket Transport that executes requests and subscribes to events via a
304
+ [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connection.
305
+
306
+ ```typescript
307
+ class WebSocketTransport implements IRESTTransport, ISubscriptionTransport {
308
+ constructor(options?: WebSocketTransportOptions);
309
+
310
+ request(endpoint: "info" | "action" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
311
+ subscribe(
312
+ channel: string,
313
+ payload: unknown,
314
+ listener: (data: CustomEvent) => void,
315
+ signal?: AbortSignal,
316
+ ): Promise<Subscription>;
317
+
318
+ ready(signal?: AbortSignal): Promise<void>;
319
+ close(signal?: AbortSignal): Promise<void>;
320
+ }
321
+
322
+ interface WebSocketTransportOptions {
323
+ url?: string | URL; // WebSocket URL (default: "wss://api.hyperliquid.xyz/ws")
324
+ timeout?: number; // Request timeout in ms (default: 10_000)
325
+ keepAlive?: { // Keep-alive configuration
326
+ interval?: number; // Ping interval in ms (default: 20_000)
327
+ };
328
+ reconnect?: { // Reconnection policy configuration for closed connections
329
+ maxRetries?: number; // Maximum number of reconnection attempts (default: 3)
330
+ connectionTimeout?: number; // Connection timeout in ms (default: 10_000)
331
+ connectionDelay?: number | ((attempt: number) => number | Promise<number>); // Delay between reconnection (default: Exponential backoff (max 10s))
332
+ shouldReconnect?: (event: CloseEvent) => boolean | Promise<boolean>; // Custom reconnection logic (default: Always reconnect)
333
+ messageBuffer?: MessageBufferStrategy; // Message buffering strategy between reconnection (default: FIFO buffer)
334
+ WebSocketConstructor?: typeof WebSocket; // Custom WebSocket constructor (default: globalThis.WebSocket)
335
+ };
336
+ }
337
+ ```
338
+
339
+ ## Semantic Versioning
340
+
341
+ This library follows [Semantic Versioning](https://semver.org/) (or rather
342
+ [this proposal](https://github.com/semver/semver/pull/923)) for its releases.
343
+
344
+ > [!IMPORTANT]
345
+ > To avoid rapid increase in the main version of the SDK due to changes in Hyperliquid API types, such changes are
346
+ > reflected in updates to the patch version of this SDK.
347
+
348
+ ## CI/CD and Release
349
+
350
+ Before publishing a new version of the SDK, tests are always run in
351
+ [Github Actions](https://github.com/nktkas/hyperliquid/actions). Only if all tests pass successfully, the process of
352
+ publishing the package takes place.
353
+
354
+ For more details, see our [CI/CD configuration files](./.github/workflows/).
355
+
356
+ ## Contributing
357
+
358
+ Contributions are welcome! Please see the [CONTRIBUTING](./CONTRIBUTING.md) file for guidelines on how to contribute to
359
+ this project.
360
+
361
+ ## License
362
+
363
+ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
package/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Security Policy
2
+
3
+ ## For Issues in Hyperliquid
4
+
5
+ If you have discovered a vulnerability or security issue related to the Hyperliquid service (e.g., buffer overflow, SQL
6
+ injection, cross-site scripting, etc.), please refer to the
7
+ [Hyperliquid Security Policy](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/SECURITY.md).
@@ -0,0 +1,2 @@
1
+ export * from './src/TypedEventTarget.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './src/TypedEventTarget.js';
@@ -0,0 +1,95 @@
1
+ /**
2
+ * A function that can be passed to the `listener` parameter of {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
3
+ *
4
+ * @template M A map of event types to their respective event classes.
5
+ * @template T The type of event to listen for (has to be keyof `M`).
6
+ */
7
+ export type TypedEventListener<M, T extends keyof M> = (evt: M[T]) => void | Promise<void>;
8
+ /**
9
+ * An object that can be passed to the `listener` parameter of {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
10
+ *
11
+ * @template M A map of event types to their respective event classes.
12
+ * @template T The type of event to listen for (has to be keyof `M`).
13
+ */
14
+ export interface TypedEventListenerObject<M, T extends keyof M> {
15
+ handleEvent: (evt: M[T]) => void | Promise<void>;
16
+ }
17
+ /**
18
+ * Type of parameter `listener` in {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
19
+ *
20
+ * The object that receives a notification (an object that implements the Event interface) when an event of the specified type occurs.
21
+ *
22
+ * Can be either an object with a handleEvent() method, or a JavaScript function.
23
+ *
24
+ * @template M A map of event types to their respective event classes.
25
+ * @template T The type of event to listen for (has to be keyof `M`).
26
+ */
27
+ export type TypedEventListenerOrEventListenerObject<M, T extends keyof M> = TypedEventListener<M, T> | TypedEventListenerObject<M, T>;
28
+ type ValueIsEvent<T> = {
29
+ [key in keyof T]: Event;
30
+ };
31
+ /**
32
+ * Typescript friendly version of {@link EventTarget}
33
+ *
34
+ * @template M A map of event types to their respective event classes.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * interface MyEventMap {
39
+ * hello: Event;
40
+ * time: CustomEvent<number>;
41
+ * }
42
+ *
43
+ * const eventTarget = new TypedEventTarget<MyEventMap>();
44
+ *
45
+ * eventTarget.addEventListener('time', (event) => {
46
+ * // event is of type CustomEvent<number>
47
+ * });
48
+ * ```
49
+ */
50
+ export interface TypedEventTarget<M extends ValueIsEvent<M>> {
51
+ /** Appends an event listener for events whose type attribute value is type.
52
+ * The callback argument sets the callback that will be invoked when the event
53
+ * is dispatched.
54
+ *
55
+ * The options argument sets listener-specific options. For compatibility this
56
+ * can be a boolean, in which case the method behaves exactly as if the value
57
+ * was specified as options's capture.
58
+ *
59
+ * When set to true, options's capture prevents callback from being invoked
60
+ * when the event's eventPhase attribute value is BUBBLING_PHASE. When false
61
+ * (or not present), callback will not be invoked when event's eventPhase
62
+ * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if
63
+ * event's eventPhase attribute value is AT_TARGET.
64
+ *
65
+ * When set to true, options's passive indicates that the callback will not
66
+ * cancel the event by invoking preventDefault(). This is used to enable
67
+ * performance optimizations described in § 2.8 Observing event listeners.
68
+ *
69
+ * When set to true, options's once indicates that the callback will only be
70
+ * invoked once after which the event listener will be removed.
71
+ *
72
+ * The event listener is appended to target's event listener list and is not
73
+ * appended if it has the same type, callback, and capture. */
74
+ addEventListener: <T extends keyof M & string>(type: T, listener: TypedEventListenerOrEventListenerObject<M, T> | null, options?: boolean | AddEventListenerOptions) => void;
75
+ /** Removes the event listener in target's event listener list with the same
76
+ * type, callback, and options. */
77
+ removeEventListener: <T extends keyof M & string>(type: T, callback: TypedEventListenerOrEventListenerObject<M, T> | null, options?: EventListenerOptions | boolean) => void;
78
+ /**
79
+ * Dispatches a synthetic event event to target and returns true if either
80
+ * event's cancelable attribute value is false or its preventDefault() method
81
+ * was not invoked, and false otherwise.
82
+ * @deprecated To ensure type safety use `dispatchTypedEvent` instead.
83
+ */
84
+ dispatchEvent: (event: Event) => boolean;
85
+ }
86
+ export declare class TypedEventTarget<M extends ValueIsEvent<M>> extends EventTarget {
87
+ /**
88
+ * Dispatches a synthetic event event to target and returns true if either
89
+ * event's cancelable attribute value is false or its preventDefault() method
90
+ * was not invoked, and false otherwise.
91
+ */
92
+ dispatchTypedEvent<T extends keyof M>(_type: T, event: M[T]): boolean;
93
+ }
94
+ export {};
95
+ //# sourceMappingURL=TypedEventTarget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedEventTarget.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CACnD,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,KACR,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC;IAC1D,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,uCAAuC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAClE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GACxB,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAErC,KAAK,YAAY,CAAC,CAAC,IAAI;KAClB,GAAG,IAAI,MAAM,CAAC,GAAG,KAAK;CAC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC;IACvD;;;;;;;;;;;;;;;;;;;;;;kEAsB8D;IAC9D,gBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EACzC,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,uCAAuC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EAC9D,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,KAC1C,IAAI,CAAC;IAEV;sCACkC;IAClC,mBAAmB,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAC5C,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,uCAAuC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EAC9D,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,KACvC,IAAI,CAAC;IAEV;;;;;OAKG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;CAC5C;AACD,qBAAa,gBAAgB,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,CAAE,SAAQ,WAAW;IACxE;;;;OAIG;IACI,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,EACvC,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GACZ,OAAO;CAGb"}
@@ -0,0 +1,10 @@
1
+ export class TypedEventTarget extends EventTarget {
2
+ /**
3
+ * Dispatches a synthetic event event to target and returns true if either
4
+ * event's cancelable attribute value is false or its preventDefault() method
5
+ * was not invoked, and false otherwise.
6
+ */
7
+ dispatchTypedEvent(_type, event) {
8
+ return super.dispatchEvent(event);
9
+ }
10
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Internal assertion helpers.
3
+ * @module
4
+ */
5
+ /** Asserts something is positive integer. */
6
+ declare function anumber(n: number): void;
7
+ /** Asserts something is Uint8Array. */
8
+ declare function abytes(b: Uint8Array | undefined, ...lengths: number[]): void;
9
+ /** Hash interface. */
10
+ export type Hash = {
11
+ (data: Uint8Array): Uint8Array;
12
+ blockLen: number;
13
+ outputLen: number;
14
+ create: any;
15
+ };
16
+ /** Asserts something is hash */
17
+ declare function ahash(h: Hash): void;
18
+ /** Asserts a hash instance has not been destroyed / finished */
19
+ declare function aexists(instance: any, checkFinished?: boolean): void;
20
+ /** Asserts output is properly-sized byte array */
21
+ declare function aoutput(out: any, instance: any): void;
22
+ export { anumber, abytes, ahash, aexists, aoutput };
23
+ //# sourceMappingURL=_assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_assert.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6CAA6C;AAC7C,iBAAS,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAEhC;AAOD,uCAAuC;AACvC,iBAAS,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAIrE;AAED,sBAAsB;AACtB,MAAM,MAAM,IAAI,GAAG;IACjB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,gCAAgC;AAChC,iBAAS,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAK5B;AAED,gEAAgE;AAChE,iBAAS,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,UAAO,GAAG,IAAI,CAG1D;AAED,kDAAkD;AAClD,iBAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI,CAM9C;AAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Internal assertion helpers.
3
+ * @module
4
+ */
5
+ /** Asserts something is positive integer. */
6
+ function anumber(n) {
7
+ if (!Number.isSafeInteger(n) || n < 0)
8
+ throw new Error('positive integer expected, got ' + n);
9
+ }
10
+ /** Is number an Uint8Array? Copied from utils for perf. */
11
+ function isBytes(a) {
12
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
13
+ }
14
+ /** Asserts something is Uint8Array. */
15
+ function abytes(b, ...lengths) {
16
+ if (!isBytes(b))
17
+ throw new Error('Uint8Array expected');
18
+ if (lengths.length > 0 && !lengths.includes(b.length))
19
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
20
+ }
21
+ /** Asserts something is hash */
22
+ function ahash(h) {
23
+ if (typeof h !== 'function' || typeof h.create !== 'function')
24
+ throw new Error('Hash should be wrapped by utils.wrapConstructor');
25
+ anumber(h.outputLen);
26
+ anumber(h.blockLen);
27
+ }
28
+ /** Asserts a hash instance has not been destroyed / finished */
29
+ function aexists(instance, checkFinished = true) {
30
+ if (instance.destroyed)
31
+ throw new Error('Hash instance has been destroyed');
32
+ if (checkFinished && instance.finished)
33
+ throw new Error('Hash#digest() has already been called');
34
+ }
35
+ /** Asserts output is properly-sized byte array */
36
+ function aoutput(out, instance) {
37
+ abytes(out);
38
+ const min = instance.outputLen;
39
+ if (out.length < min) {
40
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
41
+ }
42
+ }
43
+ export { anumber, abytes, ahash, aexists, aoutput };