@nktkas/hyperliquid 0.13.1 → 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 (183) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +33 -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 +1 -0
  24. package/esm/mod.d.ts.map +1 -1
  25. package/esm/src/clients/event.d.ts +57 -16
  26. package/esm/src/clients/event.d.ts.map +1 -1
  27. package/esm/src/clients/event.js +72 -16
  28. package/esm/src/clients/public.d.ts +241 -49
  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 +120 -51
  32. package/esm/src/clients/wallet.d.ts.map +1 -1
  33. package/esm/src/clients/wallet.js +192 -58
  34. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  35. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  36. package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
  37. package/esm/src/transports/websocket/websocket_request_dispatcher.js +3 -3
  38. package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
  39. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  40. package/esm/src/transports/websocket/websocket_transport.js +41 -35
  41. package/esm/src/types/exchange/common.d.ts +6 -6
  42. package/esm/src/types/exchange/common.d.ts.map +1 -1
  43. package/esm/src/types/exchange/requests.d.ts +131 -64
  44. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  45. package/esm/src/types/exchange/responses.d.ts +7 -7
  46. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  47. package/esm/src/types/explorer/common.d.ts +15 -15
  48. package/esm/src/types/explorer/common.d.ts.map +1 -1
  49. package/esm/src/types/explorer/requests.d.ts +19 -6
  50. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  51. package/esm/src/types/explorer/responses.d.ts +9 -2
  52. package/esm/src/types/explorer/responses.d.ts.map +1 -1
  53. package/esm/src/types/info/accounts.d.ts +189 -124
  54. package/esm/src/types/info/accounts.d.ts.map +1 -1
  55. package/esm/src/types/info/assets.d.ts +82 -78
  56. package/esm/src/types/info/assets.d.ts.map +1 -1
  57. package/esm/src/types/info/delegations.d.ts +117 -0
  58. package/esm/src/types/info/delegations.d.ts.map +1 -0
  59. package/esm/src/types/info/delegations.js +1 -0
  60. package/esm/src/types/info/orders.d.ts +67 -67
  61. package/esm/src/types/info/orders.d.ts.map +1 -1
  62. package/esm/src/types/info/requests.d.ts +128 -63
  63. package/esm/src/types/info/requests.d.ts.map +1 -1
  64. package/esm/src/types/info/vaults.d.ts +41 -84
  65. package/esm/src/types/info/vaults.d.ts.map +1 -1
  66. package/esm/src/types/subscriptions/common.d.ts +3 -0
  67. package/esm/src/types/subscriptions/common.d.ts.map +1 -1
  68. package/esm/src/types/subscriptions/requests.d.ts +10 -0
  69. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  70. package/esm/src/utils/key_sort.d.ts +2 -2
  71. package/esm/src/utils/key_sort.d.ts.map +1 -1
  72. package/esm/src/utils/signing.d.ts +1 -1
  73. package/esm/src/utils/signing.js +2 -2
  74. package/package.json +1 -1
  75. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
  76. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
  77. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
  78. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
  79. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
  80. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
  81. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
  82. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  83. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  84. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
  85. package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  86. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  87. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
  88. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  89. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  90. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
  91. package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  92. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
  93. package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  94. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  95. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
  96. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  97. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  98. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
  99. package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  100. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  101. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
  102. package/script/mod.d.ts +1 -0
  103. package/script/mod.d.ts.map +1 -1
  104. package/script/mod.js +23 -13
  105. package/script/src/clients/event.d.ts +57 -16
  106. package/script/src/clients/event.d.ts.map +1 -1
  107. package/script/src/clients/event.js +551 -485
  108. package/script/src/clients/public.d.ts +241 -49
  109. package/script/src/clients/public.d.ts.map +1 -1
  110. package/script/src/clients/public.js +914 -708
  111. package/script/src/clients/wallet.d.ts +120 -51
  112. package/script/src/clients/wallet.d.ts.map +1 -1
  113. package/script/src/clients/wallet.js +1121 -977
  114. package/script/src/transports/base.js +25 -15
  115. package/script/src/transports/http/http_transport.js +174 -164
  116. package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  117. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  118. package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
  119. package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
  120. package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
  121. package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
  122. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  123. package/script/src/transports/websocket/websocket_transport.js +236 -220
  124. package/script/src/types/common.js +12 -2
  125. package/script/src/types/exchange/common.d.ts +6 -6
  126. package/script/src/types/exchange/common.d.ts.map +1 -1
  127. package/script/src/types/exchange/common.js +12 -2
  128. package/script/src/types/exchange/requests.d.ts +131 -64
  129. package/script/src/types/exchange/requests.d.ts.map +1 -1
  130. package/script/src/types/exchange/requests.js +12 -2
  131. package/script/src/types/exchange/responses.d.ts +7 -7
  132. package/script/src/types/exchange/responses.d.ts.map +1 -1
  133. package/script/src/types/exchange/responses.js +12 -2
  134. package/script/src/types/explorer/common.d.ts +15 -15
  135. package/script/src/types/explorer/common.d.ts.map +1 -1
  136. package/script/src/types/explorer/common.js +12 -2
  137. package/script/src/types/explorer/requests.d.ts +19 -6
  138. package/script/src/types/explorer/requests.d.ts.map +1 -1
  139. package/script/src/types/explorer/requests.js +12 -2
  140. package/script/src/types/explorer/responses.d.ts +9 -2
  141. package/script/src/types/explorer/responses.d.ts.map +1 -1
  142. package/script/src/types/explorer/responses.js +12 -2
  143. package/script/src/types/info/accounts.d.ts +189 -124
  144. package/script/src/types/info/accounts.d.ts.map +1 -1
  145. package/script/src/types/info/accounts.js +12 -2
  146. package/script/src/types/info/assets.d.ts +82 -78
  147. package/script/src/types/info/assets.d.ts.map +1 -1
  148. package/script/src/types/info/assets.js +12 -2
  149. package/script/src/types/info/delegations.d.ts +117 -0
  150. package/script/src/types/info/delegations.d.ts.map +1 -0
  151. package/script/src/types/info/delegations.js +12 -0
  152. package/script/src/types/info/orders.d.ts +67 -67
  153. package/script/src/types/info/orders.d.ts.map +1 -1
  154. package/script/src/types/info/orders.js +12 -2
  155. package/script/src/types/info/requests.d.ts +128 -63
  156. package/script/src/types/info/requests.d.ts.map +1 -1
  157. package/script/src/types/info/requests.js +12 -2
  158. package/script/src/types/info/vaults.d.ts +41 -84
  159. package/script/src/types/info/vaults.d.ts.map +1 -1
  160. package/script/src/types/info/vaults.js +12 -2
  161. package/script/src/types/subscriptions/common.d.ts +3 -0
  162. package/script/src/types/subscriptions/common.d.ts.map +1 -1
  163. package/script/src/types/subscriptions/common.js +12 -2
  164. package/script/src/types/subscriptions/requests.d.ts +10 -0
  165. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  166. package/script/src/types/subscriptions/requests.js +12 -2
  167. package/script/src/utils/key_sort.d.ts +2 -2
  168. package/script/src/utils/key_sort.d.ts.map +1 -1
  169. package/script/src/utils/key_sort.js +133 -123
  170. package/script/src/utils/signing.d.ts +1 -1
  171. package/script/src/utils/signing.js +172 -162
  172. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  173. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  174. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  175. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  176. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
  177. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
  178. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  179. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
  180. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  181. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
  182. /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
  183. /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
@@ -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"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.concat = concat;
6
- /**
7
- * Concatenate an array of byte slices into a single slice.
8
- *
9
- * @param buffers Array of byte slices to concatenate.
10
- * @returns A new byte slice containing all the input slices concatenated.
11
- *
12
- * @example Basic usage
13
- * ```ts
14
- * import { concat } from "@std/bytes/concat";
15
- * import { assertEquals } from "@std/assert";
16
- *
17
- * const a = new Uint8Array([0, 1, 2]);
18
- * const b = new Uint8Array([3, 4, 5]);
19
- *
20
- * assertEquals(concat([a, b]), new Uint8Array([0, 1, 2, 3, 4, 5]));
21
- * ```
22
- */
23
- function concat(buffers) {
24
- let length = 0;
25
- for (const buffer of buffers) {
26
- length += buffer.length;
27
- }
28
- const output = new Uint8Array(length);
29
- let index = 0;
30
- for (const buffer of buffers) {
31
- output.set(buffer, index);
32
- index += buffer.length;
33
- }
34
- return output;
35
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateBinaryLike = validateBinaryLike;
5
- const encoder = new TextEncoder();
6
- function getTypeName(value) {
7
- const type = typeof value;
8
- if (type !== "object") {
9
- return type;
10
- }
11
- else if (value === null) {
12
- return "null";
13
- }
14
- else {
15
- return value?.constructor?.name ?? "object";
16
- }
17
- }
18
- function validateBinaryLike(source) {
19
- if (typeof source === "string") {
20
- return encoder.encode(source);
21
- }
22
- else if (source instanceof Uint8Array) {
23
- return source;
24
- }
25
- else if (source instanceof ArrayBuffer) {
26
- return new Uint8Array(source);
27
- }
28
- throw new TypeError(`Cannot validate the input as it must be a Uint8Array, a string, or an ArrayBuffer: received a value of the type ${getTypeName(source)}`);
29
- }
@@ -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,113 +0,0 @@
1
- "use strict";
2
- // Copyright 2009 The Go Authors. All rights reserved.
3
- // https://github.com/golang/go/blob/master/LICENSE
4
- // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
5
- // This module is browser compatible.
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.encodeHex = encodeHex;
8
- exports.decodeHex = decodeHex;
9
- /**
10
- * Port of the Go
11
- * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
12
- * library.
13
- *
14
- * ```ts
15
- * import {
16
- * decodeHex,
17
- * encodeHex,
18
- * } from "@std/encoding/hex";
19
- * import { assertEquals } from "@std/assert";
20
- *
21
- * assertEquals(encodeHex("abc"), "616263");
22
- *
23
- * assertEquals(
24
- * decodeHex("616263"),
25
- * new TextEncoder().encode("abc"),
26
- * );
27
- * ```
28
- *
29
- * @module
30
- */
31
- const _validate_binary_like_js_1 = require("./_validate_binary_like.js");
32
- const hexTable = new TextEncoder().encode("0123456789abcdef");
33
- const textEncoder = new TextEncoder();
34
- const textDecoder = new TextDecoder();
35
- function errInvalidByte(byte) {
36
- return new TypeError(`Invalid byte '${String.fromCharCode(byte)}'`);
37
- }
38
- function errLength(len) {
39
- return new RangeError(`Cannot decode the hex string as the input length should be even: length is ${len}`);
40
- }
41
- /** Converts a hex character into its value. */
42
- function fromHexChar(byte) {
43
- // '0' <= byte && byte <= '9'
44
- if (48 <= byte && byte <= 57)
45
- return byte - 48;
46
- // 'a' <= byte && byte <= 'f'
47
- if (97 <= byte && byte <= 102)
48
- return byte - 97 + 10;
49
- // 'A' <= byte && byte <= 'F'
50
- if (65 <= byte && byte <= 70)
51
- return byte - 65 + 10;
52
- throw errInvalidByte(byte);
53
- }
54
- /**
55
- * Converts data into a hex-encoded string.
56
- *
57
- * @param src The data to encode.
58
- *
59
- * @returns The hex-encoded string.
60
- *
61
- * @example Usage
62
- * ```ts
63
- * import { encodeHex } from "@std/encoding/hex";
64
- * import { assertEquals } from "@std/assert";
65
- *
66
- * assertEquals(encodeHex("abc"), "616263");
67
- * ```
68
- */
69
- function encodeHex(src) {
70
- const u8 = (0, _validate_binary_like_js_1.validateBinaryLike)(src);
71
- const dst = new Uint8Array(u8.length * 2);
72
- for (let i = 0; i < u8.length; i++) {
73
- const v = u8[i];
74
- dst[i * 2] = hexTable[v >> 4];
75
- dst[i * 2 + 1] = hexTable[v & 0x0f];
76
- }
77
- return textDecoder.decode(dst);
78
- }
79
- /**
80
- * Decodes the given hex-encoded string. If the input is malformed, an error is
81
- * thrown.
82
- *
83
- * @param src The hex-encoded string to decode.
84
- *
85
- * @returns The decoded data.
86
- *
87
- * @example Usage
88
- * ```ts
89
- * import { decodeHex } from "@std/encoding/hex";
90
- * import { assertEquals } from "@std/assert";
91
- *
92
- * assertEquals(
93
- * decodeHex("616263"),
94
- * new TextEncoder().encode("abc"),
95
- * );
96
- * ```
97
- */
98
- function decodeHex(src) {
99
- const u8 = textEncoder.encode(src);
100
- const dst = new Uint8Array(u8.length / 2);
101
- for (let i = 0; i < dst.length; i++) {
102
- const a = fromHexChar(u8[i * 2]);
103
- const b = fromHexChar(u8[i * 2 + 1]);
104
- dst[i] = (a << 4) | b;
105
- }
106
- if (u8.length % 2 === 1) {
107
- // Check for invalid char before reporting bad length,
108
- // since the invalid char (if present) is an earlier problem.
109
- fromHexChar(u8[dst.length * 2]);
110
- throw errLength(u8.length);
111
- }
112
- return dst;
113
- }
@@ -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"}