@nktkas/hyperliquid 0.13.0 → 0.13.2

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 (206) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +42 -17
  3. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  4. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  5. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
  6. package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  7. package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
  9. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  10. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
  12. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  13. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
  14. package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  15. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
  17. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  18. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
  20. package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  21. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
  23. package/esm/mod.d.ts +15 -14
  24. package/esm/mod.d.ts.map +1 -1
  25. package/esm/src/clients/event.d.ts +64 -21
  26. package/esm/src/clients/event.d.ts.map +1 -1
  27. package/esm/src/clients/event.js +76 -18
  28. package/esm/src/clients/public.d.ts +244 -52
  29. package/esm/src/clients/public.d.ts.map +1 -1
  30. package/esm/src/clients/public.js +243 -47
  31. package/esm/src/clients/wallet.d.ts +122 -53
  32. package/esm/src/clients/wallet.d.ts.map +1 -1
  33. package/esm/src/clients/wallet.js +201 -65
  34. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  35. package/esm/src/transports/http/http_transport.js +4 -1
  36. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  37. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  38. package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
  39. package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
  40. package/esm/src/transports/websocket/websocket_request_dispatcher.js +4 -4
  41. package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
  42. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  43. package/esm/src/transports/websocket/websocket_transport.js +41 -35
  44. package/esm/src/types/common.d.ts +3 -0
  45. package/esm/src/types/common.d.ts.map +1 -0
  46. package/esm/src/types/common.js +1 -0
  47. package/esm/src/types/exchange/common.d.ts +36 -0
  48. package/esm/src/types/exchange/common.d.ts.map +1 -0
  49. package/esm/src/types/exchange/common.js +1 -0
  50. package/esm/src/types/exchange/requests.d.ts +502 -0
  51. package/esm/src/types/exchange/requests.d.ts.map +1 -0
  52. package/esm/src/types/exchange/requests.js +1 -0
  53. package/esm/src/types/exchange/responses.d.ts +141 -0
  54. package/esm/src/types/exchange/responses.d.ts.map +1 -0
  55. package/esm/src/types/exchange/responses.js +1 -0
  56. package/esm/src/types/explorer/common.d.ts +37 -0
  57. package/esm/src/types/explorer/common.d.ts.map +1 -0
  58. package/esm/src/types/explorer/common.js +1 -0
  59. package/esm/src/types/explorer/requests.d.ts +35 -0
  60. package/esm/src/types/explorer/requests.d.ts.map +1 -0
  61. package/esm/src/types/explorer/requests.js +1 -0
  62. package/esm/src/types/explorer/responses.d.ts +23 -0
  63. package/esm/src/types/explorer/responses.d.ts.map +1 -0
  64. package/esm/src/types/explorer/responses.js +1 -0
  65. package/esm/src/types/info/accounts.d.ts +489 -0
  66. package/esm/src/types/info/accounts.d.ts.map +1 -0
  67. package/esm/src/types/info/accounts.js +1 -0
  68. package/esm/src/types/info/assets.d.ts +275 -0
  69. package/esm/src/types/info/assets.d.ts.map +1 -0
  70. package/esm/src/types/info/assets.js +1 -0
  71. package/esm/src/types/info/delegations.d.ts +117 -0
  72. package/esm/src/types/info/delegations.d.ts.map +1 -0
  73. package/esm/src/types/info/delegations.js +1 -0
  74. package/esm/src/types/info/orders.d.ts +209 -0
  75. package/esm/src/types/info/orders.d.ts.map +1 -0
  76. package/esm/src/types/info/orders.js +1 -0
  77. package/esm/src/types/info/requests.d.ts +445 -0
  78. package/esm/src/types/info/requests.d.ts.map +1 -0
  79. package/esm/src/types/info/requests.js +1 -0
  80. package/esm/src/types/info/vaults.d.ts +90 -0
  81. package/esm/src/types/info/vaults.d.ts.map +1 -0
  82. package/esm/src/types/info/vaults.js +1 -0
  83. package/esm/src/types/subscriptions/common.d.ts +208 -0
  84. package/esm/src/types/subscriptions/common.d.ts.map +1 -0
  85. package/esm/src/types/subscriptions/common.js +1 -0
  86. package/esm/src/types/subscriptions/requests.d.ts +134 -0
  87. package/esm/src/types/subscriptions/requests.d.ts.map +1 -0
  88. package/esm/src/types/subscriptions/requests.js +1 -0
  89. package/esm/src/utils/key_sort.d.ts +3 -3
  90. package/esm/src/utils/key_sort.d.ts.map +1 -1
  91. package/esm/src/utils/signing.d.ts +1 -1
  92. package/esm/src/utils/signing.js +2 -2
  93. package/package.json +2 -2
  94. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
  95. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
  96. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
  97. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
  98. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
  99. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
  100. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
  101. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  102. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  103. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
  104. package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  105. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  106. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
  107. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  108. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  109. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
  110. package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  111. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
  112. package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  113. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  114. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
  115. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  116. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  117. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
  118. package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  119. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  120. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
  121. package/script/mod.d.ts +15 -14
  122. package/script/mod.d.ts.map +1 -1
  123. package/script/mod.js +23 -13
  124. package/script/src/clients/event.d.ts +64 -21
  125. package/script/src/clients/event.d.ts.map +1 -1
  126. package/script/src/clients/event.js +551 -483
  127. package/script/src/clients/public.d.ts +244 -52
  128. package/script/src/clients/public.d.ts.map +1 -1
  129. package/script/src/clients/public.js +914 -708
  130. package/script/src/clients/wallet.d.ts +122 -53
  131. package/script/src/clients/wallet.d.ts.map +1 -1
  132. package/script/src/clients/wallet.js +1121 -975
  133. package/script/src/transports/base.js +25 -15
  134. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  135. package/script/src/transports/http/http_transport.js +174 -161
  136. package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  137. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  138. package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
  139. package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
  140. package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
  141. package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
  142. package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
  143. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  144. package/script/src/transports/websocket/websocket_transport.js +236 -220
  145. package/script/src/types/common.d.ts +3 -0
  146. package/script/src/types/common.d.ts.map +1 -0
  147. package/script/src/types/common.js +12 -0
  148. package/script/src/types/exchange/common.d.ts +36 -0
  149. package/script/src/types/exchange/common.d.ts.map +1 -0
  150. package/script/src/types/exchange/common.js +12 -0
  151. package/script/src/types/exchange/requests.d.ts +502 -0
  152. package/script/src/types/exchange/requests.d.ts.map +1 -0
  153. package/script/src/types/exchange/requests.js +12 -0
  154. package/script/src/types/exchange/responses.d.ts +141 -0
  155. package/script/src/types/exchange/responses.d.ts.map +1 -0
  156. package/script/src/types/exchange/responses.js +12 -0
  157. package/script/src/types/explorer/common.d.ts +37 -0
  158. package/script/src/types/explorer/common.d.ts.map +1 -0
  159. package/script/src/types/explorer/common.js +12 -0
  160. package/script/src/types/explorer/requests.d.ts +35 -0
  161. package/script/src/types/explorer/requests.d.ts.map +1 -0
  162. package/script/src/types/explorer/requests.js +12 -0
  163. package/script/src/types/explorer/responses.d.ts +23 -0
  164. package/script/src/types/explorer/responses.d.ts.map +1 -0
  165. package/script/src/types/explorer/responses.js +12 -0
  166. package/script/src/types/info/accounts.d.ts +489 -0
  167. package/script/src/types/info/accounts.d.ts.map +1 -0
  168. package/script/src/types/info/accounts.js +12 -0
  169. package/script/src/types/info/assets.d.ts +275 -0
  170. package/script/src/types/info/assets.d.ts.map +1 -0
  171. package/script/src/types/info/assets.js +12 -0
  172. package/script/src/types/info/delegations.d.ts +117 -0
  173. package/script/src/types/info/delegations.d.ts.map +1 -0
  174. package/script/src/types/info/delegations.js +12 -0
  175. package/script/src/types/info/orders.d.ts +209 -0
  176. package/script/src/types/info/orders.d.ts.map +1 -0
  177. package/script/src/types/info/orders.js +12 -0
  178. package/script/src/types/info/requests.d.ts +445 -0
  179. package/script/src/types/info/requests.d.ts.map +1 -0
  180. package/script/src/types/info/requests.js +12 -0
  181. package/script/src/types/info/vaults.d.ts +90 -0
  182. package/script/src/types/info/vaults.d.ts.map +1 -0
  183. package/script/src/types/info/vaults.js +12 -0
  184. package/script/src/types/subscriptions/common.d.ts +208 -0
  185. package/script/src/types/subscriptions/common.d.ts.map +1 -0
  186. package/script/src/types/subscriptions/common.js +12 -0
  187. package/script/src/types/subscriptions/requests.d.ts +134 -0
  188. package/script/src/types/subscriptions/requests.d.ts.map +1 -0
  189. package/script/src/types/subscriptions/requests.js +12 -0
  190. package/script/src/utils/key_sort.d.ts +3 -3
  191. package/script/src/utils/key_sort.d.ts.map +1 -1
  192. package/script/src/utils/key_sort.js +133 -123
  193. package/script/src/utils/signing.d.ts +1 -1
  194. package/script/src/utils/signing.js +172 -162
  195. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  196. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  197. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  198. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  199. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
  200. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
  201. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  202. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
  203. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  204. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
  205. /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
  206. /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
@@ -1,127 +1,137 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sorters = void 0;
4
- /** Record of action types and their corresponding sorters. */
5
- // NOTE: An object after sorting must not contain undefined values.
6
- exports.sorters = {
7
- batchModify: (action) => ({
8
- type: action.type,
9
- modifies: action.modifies.map((m) => ({
10
- oid: m.oid,
11
- order: exports.sorters._order(m.order),
12
- })),
13
- }),
14
- cancel: (action) => ({
15
- type: action.type,
16
- cancels: action.cancels.map((c) => ({
17
- a: c.a,
18
- o: c.o,
19
- })),
20
- }),
21
- cancelByCloid: (action) => ({
22
- type: action.type,
23
- cancels: action.cancels.map((cancel) => ({
24
- asset: cancel.asset,
25
- cloid: cancel.cloid,
26
- })),
27
- }),
28
- createSubAccount: (action) => ({
29
- type: action.type,
30
- name: action.name,
31
- }),
32
- modify: (action) => ({
33
- type: action.type,
34
- oid: action.oid,
35
- order: exports.sorters._order(action.order),
36
- }),
37
- order: (action) => {
38
- const sortedAction = {
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sorters = void 0;
13
+ /** Record of action types and their corresponding sorters. */
14
+ // NOTE: An object after sorting must not contain undefined values.
15
+ exports.sorters = {
16
+ batchModify: (action) => ({
39
17
  type: action.type,
40
- orders: action.orders.map(exports.sorters._order),
41
- grouping: action.grouping,
42
- builder: action.builder ? { b: action.builder.b, f: action.builder.f } : undefined,
43
- };
44
- if (action.builder === undefined)
45
- delete sortedAction.builder;
46
- return sortedAction;
47
- },
48
- scheduleCancel: (action) => {
49
- const sortedAction = {
18
+ modifies: action.modifies.map((m) => ({
19
+ oid: m.oid,
20
+ order: exports.sorters._order(m.order),
21
+ })),
22
+ }),
23
+ cancel: (action) => ({
50
24
  type: action.type,
51
- time: action.time,
52
- };
53
- if (action.time === undefined)
54
- delete sortedAction.time;
55
- return sortedAction;
56
- },
57
- setReferrer: (action) => ({
58
- type: action.type,
59
- code: action.code,
60
- }),
61
- subAccountTransfer: (action) => ({
62
- type: action.type,
63
- subAccountUser: action.subAccountUser,
64
- isDeposit: action.isDeposit,
65
- usd: action.usd,
66
- }),
67
- twapCancel: (action) => ({
68
- type: action.type,
69
- a: action.a,
70
- t: action.t,
71
- }),
72
- twapOrder: (action) => ({
73
- type: action.type,
74
- twap: {
75
- a: action.twap.a,
76
- b: action.twap.b,
77
- s: action.twap.s,
78
- r: action.twap.r,
79
- m: action.twap.m,
80
- t: action.twap.t,
25
+ cancels: action.cancels.map((c) => ({
26
+ a: c.a,
27
+ o: c.o,
28
+ })),
29
+ }),
30
+ cancelByCloid: (action) => ({
31
+ type: action.type,
32
+ cancels: action.cancels.map((cancel) => ({
33
+ asset: cancel.asset,
34
+ cloid: cancel.cloid,
35
+ })),
36
+ }),
37
+ createSubAccount: (action) => ({
38
+ type: action.type,
39
+ name: action.name,
40
+ }),
41
+ modify: (action) => ({
42
+ type: action.type,
43
+ oid: action.oid,
44
+ order: exports.sorters._order(action.order),
45
+ }),
46
+ order: (action) => {
47
+ const sortedAction = {
48
+ type: action.type,
49
+ orders: action.orders.map(exports.sorters._order),
50
+ grouping: action.grouping,
51
+ builder: action.builder ? { b: action.builder.b, f: action.builder.f } : undefined,
52
+ };
53
+ if (action.builder === undefined)
54
+ delete sortedAction.builder;
55
+ return sortedAction;
81
56
  },
82
- }),
83
- updateIsolatedMargin: (action) => ({
84
- type: action.type,
85
- asset: action.asset,
86
- isBuy: action.isBuy,
87
- ntli: action.ntli,
88
- }),
89
- updateLeverage: (action) => ({
90
- type: action.type,
91
- asset: action.asset,
92
- isCross: action.isCross,
93
- leverage: action.leverage,
94
- }),
95
- vaultTransfer: (action) => ({
96
- type: action.type,
97
- vaultAddress: action.vaultAddress,
98
- isDeposit: action.isDeposit,
99
- usd: action.usd,
100
- }),
101
- _order: (order) => {
102
- const sortedOrder = {
103
- a: order.a,
104
- b: order.b,
105
- p: order.p,
106
- s: order.s,
107
- r: order.r,
108
- t: "limit" in order.t
109
- ? {
110
- limit: {
111
- tif: order.t.limit.tif,
112
- },
113
- }
114
- : {
115
- trigger: {
116
- isMarket: order.t.trigger.isMarket,
117
- triggerPx: order.t.trigger.triggerPx,
118
- tpsl: order.t.trigger.tpsl,
57
+ scheduleCancel: (action) => {
58
+ const sortedAction = {
59
+ type: action.type,
60
+ time: action.time,
61
+ };
62
+ if (action.time === undefined)
63
+ delete sortedAction.time;
64
+ return sortedAction;
65
+ },
66
+ setReferrer: (action) => ({
67
+ type: action.type,
68
+ code: action.code,
69
+ }),
70
+ subAccountTransfer: (action) => ({
71
+ type: action.type,
72
+ subAccountUser: action.subAccountUser,
73
+ isDeposit: action.isDeposit,
74
+ usd: action.usd,
75
+ }),
76
+ twapCancel: (action) => ({
77
+ type: action.type,
78
+ a: action.a,
79
+ t: action.t,
80
+ }),
81
+ twapOrder: (action) => ({
82
+ type: action.type,
83
+ twap: {
84
+ a: action.twap.a,
85
+ b: action.twap.b,
86
+ s: action.twap.s,
87
+ r: action.twap.r,
88
+ m: action.twap.m,
89
+ t: action.twap.t,
90
+ },
91
+ }),
92
+ updateIsolatedMargin: (action) => ({
93
+ type: action.type,
94
+ asset: action.asset,
95
+ isBuy: action.isBuy,
96
+ ntli: action.ntli,
97
+ }),
98
+ updateLeverage: (action) => ({
99
+ type: action.type,
100
+ asset: action.asset,
101
+ isCross: action.isCross,
102
+ leverage: action.leverage,
103
+ }),
104
+ vaultTransfer: (action) => ({
105
+ type: action.type,
106
+ vaultAddress: action.vaultAddress,
107
+ isDeposit: action.isDeposit,
108
+ usd: action.usd,
109
+ }),
110
+ _order: (order) => {
111
+ const sortedOrder = {
112
+ a: order.a,
113
+ b: order.b,
114
+ p: order.p,
115
+ s: order.s,
116
+ r: order.r,
117
+ t: "limit" in order.t
118
+ ? {
119
+ limit: {
120
+ tif: order.t.limit.tif,
121
+ },
122
+ }
123
+ : {
124
+ trigger: {
125
+ isMarket: order.t.trigger.isMarket,
126
+ triggerPx: order.t.trigger.triggerPx,
127
+ tpsl: order.t.trigger.tpsl,
128
+ },
119
129
  },
120
- },
121
- c: order.c,
122
- };
123
- if (order.c === undefined)
124
- delete sortedOrder.c;
125
- return sortedOrder;
126
- },
127
- };
130
+ c: order.c,
131
+ };
132
+ if (order.c === undefined)
133
+ delete sortedOrder.c;
134
+ return sortedOrder;
135
+ },
136
+ };
137
+ });
@@ -1,4 +1,4 @@
1
- import { type ValueType } from "../../deps/jsr.io/@std/msgpack/1.0.2/encode.js";
1
+ import { type ValueType } from "../../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
2
2
  type Hex = `0x${string}`;
3
3
  /** Abstract interface for a [ethers.js](https://docs.ethers.org/v6/api/providers/#Signer) signer. */
4
4
  export interface AbstractEthersSigner {
@@ -1,172 +1,182 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createActionHash = createActionHash;
4
- exports.signL1Action = signL1Action;
5
- exports.signUserSignedAction = signUserSignedAction;
6
- exports.isAbstractEthersSigner = isAbstractEthersSigner;
7
- exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
8
- exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
9
- const sha3_js_1 = require("../../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js");
10
- const encode_js_1 = require("../../deps/jsr.io/@std/msgpack/1.0.2/encode.js");
11
- const hex_js_1 = require("../../deps/jsr.io/@std/encoding/1.0.6/hex.js");
12
- /**
13
- * Create a hash of the action.
14
- * @param action - The action to hash.
15
- * @param nonce - The nonce of the action.
16
- * @param vaultAddress - Optional vault address.
17
- * @returns The hash of the action.
18
- */
19
- function createActionHash(action, nonce, vaultAddress) {
20
- const normalizedAction = normalizeIntegersForMsgPack(action);
21
- const msgPackBytes = (0, encode_js_1.encode)(normalizedAction);
22
- const additionalBytesLength = vaultAddress ? 29 : 9;
23
- const data = new Uint8Array(msgPackBytes.length + additionalBytesLength);
24
- data.set(msgPackBytes);
25
- const view = new DataView(data.buffer);
26
- view.setBigUint64(msgPackBytes.length, BigInt(nonce));
27
- if (vaultAddress) {
28
- view.setUint8(msgPackBytes.length + 8, 1);
29
- const normalizedVaultAddress = vaultAddress.startsWith("0x") ? vaultAddress.slice(2) : vaultAddress;
30
- data.set((0, hex_js_1.decodeHex)(normalizedVaultAddress), msgPackBytes.length + 9);
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
31
5
  }
32
- else {
33
- view.setUint8(msgPackBytes.length + 8, 0);
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js", "../../deps/jsr.io/@std/msgpack/1.0.3/encode.js", "../../deps/jsr.io/@std/encoding/1.0.7/hex.js"], factory);
34
8
  }
35
- return `0x${(0, hex_js_1.encodeHex)((0, sha3_js_1.keccak_256)(data))}`;
36
- }
37
- /**
38
- * Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}.
39
- * @returns A new object with integers normalized.
40
- */
41
- function normalizeIntegersForMsgPack(obj) {
42
- const THIRTY_ONE_BITS = 2147483648;
43
- const THIRTY_TWO_BITS = 4294967296;
44
- if (typeof obj === "number" && Number.isInteger(obj) &&
45
- obj <= Number.MAX_SAFE_INTEGER && obj >= Number.MIN_SAFE_INTEGER &&
46
- (obj >= THIRTY_TWO_BITS || obj < -THIRTY_ONE_BITS)) {
47
- return BigInt(obj);
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createActionHash = createActionHash;
13
+ exports.signL1Action = signL1Action;
14
+ exports.signUserSignedAction = signUserSignedAction;
15
+ exports.isAbstractEthersSigner = isAbstractEthersSigner;
16
+ exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
17
+ exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
18
+ const sha3_js_1 = require("../../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js");
19
+ const encode_js_1 = require("../../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
20
+ const hex_js_1 = require("../../deps/jsr.io/@std/encoding/1.0.7/hex.js");
21
+ /**
22
+ * Create a hash of the action.
23
+ * @param action - The action to hash.
24
+ * @param nonce - The nonce of the action.
25
+ * @param vaultAddress - Optional vault address.
26
+ * @returns The hash of the action.
27
+ */
28
+ function createActionHash(action, nonce, vaultAddress) {
29
+ const normalizedAction = normalizeIntegersForMsgPack(action);
30
+ const msgPackBytes = (0, encode_js_1.encode)(normalizedAction);
31
+ const additionalBytesLength = vaultAddress ? 29 : 9;
32
+ const data = new Uint8Array(msgPackBytes.length + additionalBytesLength);
33
+ data.set(msgPackBytes);
34
+ const view = new DataView(data.buffer);
35
+ view.setBigUint64(msgPackBytes.length, BigInt(nonce));
36
+ if (vaultAddress) {
37
+ view.setUint8(msgPackBytes.length + 8, 1);
38
+ const normalizedVaultAddress = vaultAddress.startsWith("0x") ? vaultAddress.slice(2) : vaultAddress;
39
+ data.set((0, hex_js_1.decodeHex)(normalizedVaultAddress), msgPackBytes.length + 9);
40
+ }
41
+ else {
42
+ view.setUint8(msgPackBytes.length + 8, 0);
43
+ }
44
+ return `0x${(0, hex_js_1.encodeHex)((0, sha3_js_1.keccak_256)(data))}`;
48
45
  }
49
- if (Array.isArray(obj)) {
50
- return obj.map(normalizeIntegersForMsgPack);
46
+ /**
47
+ * Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}.
48
+ * @returns A new object with integers normalized.
49
+ */
50
+ function normalizeIntegersForMsgPack(obj) {
51
+ const THIRTY_ONE_BITS = 2147483648;
52
+ const THIRTY_TWO_BITS = 4294967296;
53
+ if (typeof obj === "number" && Number.isInteger(obj) &&
54
+ obj <= Number.MAX_SAFE_INTEGER && obj >= Number.MIN_SAFE_INTEGER &&
55
+ (obj >= THIRTY_TWO_BITS || obj < -THIRTY_ONE_BITS)) {
56
+ return BigInt(obj);
57
+ }
58
+ if (Array.isArray(obj)) {
59
+ return obj.map(normalizeIntegersForMsgPack);
60
+ }
61
+ if (obj && typeof obj === "object" && obj !== null) {
62
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, normalizeIntegersForMsgPack(value)]));
63
+ }
64
+ return obj;
51
65
  }
52
- if (obj && typeof obj === "object" && obj !== null) {
53
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, normalizeIntegersForMsgPack(value)]));
66
+ /**
67
+ * Sign an L1 action.
68
+ * @param wallet - The wallet to sign with.
69
+ * @param isTestnet - A boolean indicating if the action is for the testnet.
70
+ * @param action - The action to sign.
71
+ * @param nonce - The nonce of the action.
72
+ * @param vaultAddress - Optional vault address.
73
+ * @returns The signature.
74
+ */
75
+ async function signL1Action(wallet, isTestnet, action, nonce, vaultAddress) {
76
+ const domain = {
77
+ name: "Exchange",
78
+ version: "1",
79
+ chainId: 1337,
80
+ verifyingContract: "0x0000000000000000000000000000000000000000",
81
+ };
82
+ const types = {
83
+ Agent: [
84
+ { name: "source", type: "string" },
85
+ { name: "connectionId", type: "bytes32" },
86
+ ],
87
+ };
88
+ const actionHash = createActionHash(action, nonce, vaultAddress);
89
+ const message = {
90
+ source: isTestnet ? "b" : "a",
91
+ connectionId: actionHash,
92
+ };
93
+ let signature;
94
+ if (isAbstractViemWalletClient(wallet)) {
95
+ signature = await wallet.signTypedData({ domain, types, primaryType: "Agent", message });
96
+ }
97
+ else if (isAbstractEthersSigner(wallet)) {
98
+ signature = await wallet.signTypedData(domain, types, message);
99
+ }
100
+ else if (isAbstractEthersV5Signer(wallet)) {
101
+ signature = await wallet._signTypedData(domain, types, message);
102
+ }
103
+ else {
104
+ throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
105
+ }
106
+ return parseSignature(signature);
54
107
  }
55
- return obj;
56
- }
57
- /**
58
- * Sign an L1 action.
59
- * @param wallet - The wallet to sign with.
60
- * @param isTestnet - A boolean indicating if the action is for the testnet.
61
- * @param action - The action to sign.
62
- * @param nonce - The nonce of the action.
63
- * @param vaultAddress - Optional vault address.
64
- * @returns The signature.
65
- */
66
- async function signL1Action(wallet, isTestnet, action, nonce, vaultAddress) {
67
- const domain = {
68
- name: "Exchange",
69
- version: "1",
70
- chainId: 1337,
71
- verifyingContract: "0x0000000000000000000000000000000000000000",
72
- };
73
- const types = {
74
- Agent: [
75
- { name: "source", type: "string" },
76
- { name: "connectionId", type: "bytes32" },
77
- ],
78
- };
79
- const actionHash = createActionHash(action, nonce, vaultAddress);
80
- const message = {
81
- source: isTestnet ? "b" : "a",
82
- connectionId: actionHash,
83
- };
84
- let signature;
85
- if (isAbstractViemWalletClient(wallet)) {
86
- signature = await wallet.signTypedData({ domain, types, primaryType: "Agent", message });
108
+ /**
109
+ * Sign a user-signed action.
110
+ * @param wallet - The wallet to sign with.
111
+ * @param action - The action to sign.
112
+ * @param types - The types of the action.
113
+ * @param chainId - The chain ID of the action.
114
+ * @returns The signature.
115
+ */
116
+ async function signUserSignedAction(wallet, action, types, chainId) {
117
+ const domain = {
118
+ name: "HyperliquidSignTransaction",
119
+ version: "1",
120
+ chainId,
121
+ verifyingContract: "0x0000000000000000000000000000000000000000",
122
+ };
123
+ let signature;
124
+ if (isAbstractViemWalletClient(wallet)) {
125
+ const primaryType = Object.keys(types)[0];
126
+ signature = await wallet.signTypedData({ domain, types, primaryType, message: action });
127
+ }
128
+ else if (isAbstractEthersSigner(wallet)) {
129
+ signature = await wallet.signTypedData(domain, types, action);
130
+ }
131
+ else if (isAbstractEthersV5Signer(wallet)) {
132
+ signature = await wallet._signTypedData(domain, types, action);
133
+ }
134
+ else {
135
+ throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
136
+ }
137
+ return parseSignature(signature);
87
138
  }
88
- else if (isAbstractEthersSigner(wallet)) {
89
- signature = await wallet.signTypedData(domain, types, message);
139
+ /**
140
+ * Parses a signature hexadecimal string into its components.
141
+ */
142
+ function parseSignature(signature) {
143
+ const normalizedSignature = signature.startsWith("0x") ? signature.slice(2) : signature;
144
+ if (normalizedSignature.length !== 130) {
145
+ throw new Error(`Invalid signature length. Expected 130 characters. Received ${normalizedSignature.length}.`);
146
+ }
147
+ const r = `0x${normalizedSignature.slice(0, 64)}`;
148
+ const s = `0x${normalizedSignature.slice(64, 128)}`;
149
+ const v = parseInt(normalizedSignature.slice(128, 130), 16);
150
+ return { r, s, v };
90
151
  }
91
- else if (isAbstractEthersV5Signer(wallet)) {
92
- signature = await wallet._signTypedData(domain, types, message);
152
+ /**
153
+ * Checks if the given client is an abstract signer (ethers.js).
154
+ * @param client - The client to check.
155
+ * @returns A boolean indicating if the client is an abstract signer.
156
+ */
157
+ function isAbstractEthersSigner(client) {
158
+ return typeof client === "object" && client !== null &&
159
+ "signTypedData" in client && typeof client.signTypedData === "function" &&
160
+ client.signTypedData.length === 3;
93
161
  }
94
- else {
95
- throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
162
+ /**
163
+ * Checks if the given client is an abstract signer (ethers.js v5).
164
+ * @param client - The client to check.
165
+ * @returns A boolean indicating if the client is an abstract signer.
166
+ */
167
+ function isAbstractEthersV5Signer(client) {
168
+ return typeof client === "object" && client !== null &&
169
+ "_signTypedData" in client && typeof client._signTypedData === "function" &&
170
+ client._signTypedData.length === 3;
96
171
  }
97
- return parseSignature(signature);
98
- }
99
- /**
100
- * Sign a user-signed action.
101
- * @param wallet - The wallet to sign with.
102
- * @param action - The action to sign.
103
- * @param types - The types of the action.
104
- * @param chainId - The chain ID of the action.
105
- * @returns The signature.
106
- */
107
- async function signUserSignedAction(wallet, action, types, chainId) {
108
- const domain = {
109
- name: "HyperliquidSignTransaction",
110
- version: "1",
111
- chainId,
112
- verifyingContract: "0x0000000000000000000000000000000000000000",
113
- };
114
- let signature;
115
- if (isAbstractViemWalletClient(wallet)) {
116
- const primaryType = Object.keys(types)[0];
117
- signature = await wallet.signTypedData({ domain, types, primaryType, message: action });
172
+ /**
173
+ * Checks if the given client is an abstract wallet client (viem).
174
+ * @param client - The client to check.
175
+ * @returns A boolean indicating if the client is an abstract wallet client.
176
+ */
177
+ function isAbstractViemWalletClient(client) {
178
+ return typeof client === "object" && client !== null &&
179
+ "signTypedData" in client && typeof client.signTypedData === "function" &&
180
+ client.signTypedData.length === 1;
118
181
  }
119
- else if (isAbstractEthersSigner(wallet)) {
120
- signature = await wallet.signTypedData(domain, types, action);
121
- }
122
- else if (isAbstractEthersV5Signer(wallet)) {
123
- signature = await wallet._signTypedData(domain, types, action);
124
- }
125
- else {
126
- throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
127
- }
128
- return parseSignature(signature);
129
- }
130
- /**
131
- * Parses a signature hexadecimal string into its components.
132
- */
133
- function parseSignature(signature) {
134
- const normalizedSignature = signature.startsWith("0x") ? signature.slice(2) : signature;
135
- if (normalizedSignature.length !== 130) {
136
- throw new Error(`Invalid signature length. Expected 130 characters. Received ${normalizedSignature.length}.`);
137
- }
138
- const r = `0x${normalizedSignature.slice(0, 64)}`;
139
- const s = `0x${normalizedSignature.slice(64, 128)}`;
140
- const v = parseInt(normalizedSignature.slice(128, 130), 16);
141
- return { r, s, v };
142
- }
143
- /**
144
- * Checks if the given client is an abstract signer (ethers.js).
145
- * @param client - The client to check.
146
- * @returns A boolean indicating if the client is an abstract signer.
147
- */
148
- function isAbstractEthersSigner(client) {
149
- return typeof client === "object" && client !== null &&
150
- "signTypedData" in client && typeof client.signTypedData === "function" &&
151
- client.signTypedData.length === 3;
152
- }
153
- /**
154
- * Checks if the given client is an abstract signer (ethers.js v5).
155
- * @param client - The client to check.
156
- * @returns A boolean indicating if the client is an abstract signer.
157
- */
158
- function isAbstractEthersV5Signer(client) {
159
- return typeof client === "object" && client !== null &&
160
- "_signTypedData" in client && typeof client._signTypedData === "function" &&
161
- client._signTypedData.length === 3;
162
- }
163
- /**
164
- * Checks if the given client is an abstract wallet client (viem).
165
- * @param client - The client to check.
166
- * @returns A boolean indicating if the client is an abstract wallet client.
167
- */
168
- function isAbstractViemWalletClient(client) {
169
- return typeof client === "object" && client !== null &&
170
- "signTypedData" in client && typeof client.signTypedData === "function" &&
171
- client.signTypedData.length === 1;
172
- }
182
+ });
@@ -1 +0,0 @@
1
- {"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.4/concat.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,CAaxD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.6/hex.ts"],"names":[],"mappings":"AAwDA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAUxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAiBjD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/msgpack/1.0.2/encode.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,UAAU,GACV,SAAS,SAAS,EAAE,GACpB,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,sBAAsB;IACtB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACrC;AAeD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAIpD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.4/concat.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,CAaxD"}