@nktkas/hyperliquid 0.17.0 → 0.17.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 (99) hide show
  1. package/README.md +16 -14
  2. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts +21 -0
  3. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.js +45 -0
  5. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts +4 -0
  6. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.js +13 -0
  8. package/{script/deps/jsr.io/@std/encoding/1.0.7 → esm/deps/jsr.io/@std/encoding/1.0.8}/_types.d.ts.map +1 -1
  9. package/esm/deps/jsr.io/@std/encoding/1.0.8/hex.d.ts.map +1 -0
  10. package/esm/deps/jsr.io/@std/encoding/1.0.8/hex.js +87 -0
  11. package/esm/src/clients/event.d.ts +25 -2
  12. package/esm/src/clients/event.d.ts.map +1 -1
  13. package/esm/src/clients/event.js +31 -1
  14. package/esm/src/clients/public.d.ts +9 -9
  15. package/esm/src/clients/public.d.ts.map +1 -1
  16. package/esm/src/clients/public.js +9 -12
  17. package/esm/src/clients/wallet.d.ts +52 -59
  18. package/esm/src/clients/wallet.d.ts.map +1 -1
  19. package/esm/src/clients/wallet.js +69 -62
  20. package/esm/src/signing.d.ts +44 -0
  21. package/esm/src/signing.d.ts.map +1 -1
  22. package/esm/src/signing.js +45 -1
  23. package/esm/src/types/exchange/requests.d.ts +57 -43
  24. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  25. package/esm/src/types/explorer/requests.d.ts +3 -3
  26. package/esm/src/types/info/accounts.d.ts +13 -1
  27. package/esm/src/types/info/accounts.d.ts.map +1 -1
  28. package/esm/src/types/info/assets.d.ts +2 -6
  29. package/esm/src/types/info/assets.d.ts.map +1 -1
  30. package/esm/src/types/info/orders.d.ts +3 -1
  31. package/esm/src/types/info/orders.d.ts.map +1 -1
  32. package/esm/src/types/info/requests.d.ts +10 -10
  33. package/esm/src/types/info/requests.d.ts.map +1 -1
  34. package/esm/src/types/info/vaults.d.ts +22 -17
  35. package/esm/src/types/info/vaults.d.ts.map +1 -1
  36. package/esm/src/types/mod.d.ts +0 -2
  37. package/esm/src/types/mod.d.ts.map +1 -1
  38. package/esm/src/types/mod.js +0 -2
  39. package/esm/src/types/subscriptions/requests.d.ts +34 -36
  40. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  41. package/esm/src/types/subscriptions/responses.d.ts +48 -48
  42. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts +21 -0
  45. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts.map +1 -0
  46. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.js +60 -0
  47. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts +4 -0
  48. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts.map +1 -0
  49. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.js +26 -0
  50. package/{esm/deps/jsr.io/@std/encoding/1.0.7 → script/deps/jsr.io/@std/encoding/1.0.8}/_types.d.ts.map +1 -1
  51. package/script/deps/jsr.io/@std/encoding/1.0.8/hex.d.ts.map +1 -0
  52. package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.js +23 -45
  53. package/script/src/clients/event.d.ts +25 -2
  54. package/script/src/clients/event.d.ts.map +1 -1
  55. package/script/src/clients/event.js +31 -1
  56. package/script/src/clients/public.d.ts +9 -9
  57. package/script/src/clients/public.d.ts.map +1 -1
  58. package/script/src/clients/public.js +9 -12
  59. package/script/src/clients/wallet.d.ts +52 -59
  60. package/script/src/clients/wallet.d.ts.map +1 -1
  61. package/script/src/clients/wallet.js +69 -62
  62. package/script/src/signing.d.ts +44 -0
  63. package/script/src/signing.d.ts.map +1 -1
  64. package/script/src/signing.js +46 -2
  65. package/script/src/types/exchange/requests.d.ts +57 -43
  66. package/script/src/types/exchange/requests.d.ts.map +1 -1
  67. package/script/src/types/explorer/requests.d.ts +3 -3
  68. package/script/src/types/info/accounts.d.ts +13 -1
  69. package/script/src/types/info/accounts.d.ts.map +1 -1
  70. package/script/src/types/info/assets.d.ts +2 -6
  71. package/script/src/types/info/assets.d.ts.map +1 -1
  72. package/script/src/types/info/orders.d.ts +3 -1
  73. package/script/src/types/info/orders.d.ts.map +1 -1
  74. package/script/src/types/info/requests.d.ts +10 -10
  75. package/script/src/types/info/requests.d.ts.map +1 -1
  76. package/script/src/types/info/vaults.d.ts +22 -17
  77. package/script/src/types/info/vaults.d.ts.map +1 -1
  78. package/script/src/types/mod.d.ts +0 -2
  79. package/script/src/types/mod.d.ts.map +1 -1
  80. package/script/src/types/mod.js +0 -2
  81. package/script/src/types/subscriptions/requests.d.ts +34 -36
  82. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  83. package/script/src/types/subscriptions/responses.d.ts +48 -48
  84. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  85. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts +0 -2
  86. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts.map +0 -1
  87. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +0 -26
  88. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +0 -1
  89. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.js +0 -109
  90. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts +0 -2
  91. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts.map +0 -1
  92. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +0 -39
  93. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +0 -1
  94. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.d.ts +0 -0
  95. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.js +0 -0
  96. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.d.ts +0 -0
  97. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.d.ts +0 -0
  98. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.js +0 -0
  99. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.d.ts +0 -0
@@ -12,7 +12,6 @@
12
12
  exports.WalletClient = exports.ApiRequestError = void 0;
13
13
  const base_js_1 = require("../base.js");
14
14
  const signing_js_1 = require("../signing.js");
15
- // ——————————————— Errors ———————————————
16
15
  /** Error thrown when the API returns an error response. */
17
16
  class ApiRequestError extends base_js_1.HyperliquidError {
18
17
  constructor(response) {
@@ -52,7 +51,6 @@
52
51
  }
53
52
  }
54
53
  exports.ApiRequestError = ApiRequestError;
55
- // ——————————————— Client ———————————————
56
54
  /** Nonce manager for generating unique nonces for signing transactions. */
57
55
  class NonceManager {
58
56
  constructor() {
@@ -184,9 +182,8 @@
184
182
  this.signatureChainId = args.signatureChainId ?? this._guessSignatureChainId;
185
183
  this.nonceManager = args.nonceManager ?? new NonceManager().getNonce;
186
184
  }
187
- // ——————————————— Exchange API ———————————————
188
185
  /**
189
- * Approve an agent to sign on behalf of the master or sub-accounts.
186
+ * Approve an agent to sign on behalf of the master account.
190
187
  * @param args - The parameters for the request.
191
188
  * @param signal - An optional abort signal
192
189
  * @returns Successful response without specific data.
@@ -202,10 +199,7 @@
202
199
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
203
200
  * const client = new hl.WalletClient({ wallet, transport });
204
201
  *
205
- * const result = await client.approveAgent({
206
- * agentAddress: "0x...",
207
- * agentName: "agentName",
208
- * });
202
+ * const result = await client.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
209
203
  * ```
210
204
  */
211
205
  async approveAgent(args, signal) {
@@ -241,7 +235,7 @@
241
235
  return response;
242
236
  }
243
237
  /**
244
- * Approve a max fee rate for a builder address.
238
+ * Approve a maximum fee rate for a builder.
245
239
  * @param args - The parameters for the request.
246
240
  * @param signal - An optional abort signal.
247
241
  * @returns Successful response without specific data.
@@ -257,10 +251,7 @@
257
251
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
258
252
  * const client = new hl.WalletClient({ wallet, transport });
259
253
  *
260
- * const result = await client.approveBuilderFee({
261
- * maxFeeRate: "0.01%",
262
- * builder: "0x...",
263
- * });
254
+ * const result = await client.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
264
255
  * ```
265
256
  */
266
257
  async approveBuilderFee(args, signal) {
@@ -314,7 +305,7 @@
314
305
  *
315
306
  * const result = await client.batchModify({
316
307
  * modifies: [{
317
- * oid: 123, // Order ID
308
+ * oid: 123,
318
309
  * order: {
319
310
  * a: 0, // Asset index
320
311
  * b: true, // Buy order
@@ -454,10 +445,9 @@
454
445
  * const client = new hl.WalletClient({ wallet, transport });
455
446
  *
456
447
  * const result = await client.cancelByCloid({
457
- * cancels: [{
458
- * asset: 0,
459
- * cloid: "0x...", // Client Order ID
460
- * }],
448
+ * cancels: [
449
+ * { asset: 0, cloid: "0x..." },
450
+ * ],
461
451
  * });
462
452
  * ```
463
453
  */
@@ -489,7 +479,7 @@
489
479
  return response;
490
480
  }
491
481
  /**
492
- * Deposit into staking balance.
482
+ * Transfer native token from the user's spot account into staking for delegating to validators.
493
483
  * @param args - The parameters for the request.
494
484
  * @param signal - An optional abort signal.
495
485
  * @returns Successful response without specific data.
@@ -667,7 +657,7 @@
667
657
  return response;
668
658
  }
669
659
  /**
670
- * Withdraw from staking balance.
660
+ * Transfer native token from staking into the user's spot account.
671
661
  * @param args - The parameters for the request.
672
662
  * @param signal - An optional abort signal.
673
663
  * @returns Successful response without specific data.
@@ -776,7 +766,7 @@
776
766
  * const client = new hl.WalletClient({ wallet, transport });
777
767
  *
778
768
  * const result = await client.modify({
779
- * oid: 123, // Order ID
769
+ * oid: 123,
780
770
  * order: {
781
771
  * a: 0, // Asset index
782
772
  * b: true, // Buy order
@@ -933,11 +923,52 @@
933
923
  this._validateResponse(response);
934
924
  return response;
935
925
  }
926
+ /**
927
+ * Create a referral code.
928
+ * @param args - The parameters for the request.
929
+ * @param signal - An optional abort signal.
930
+ * @returns Successful response without specific data.
931
+ * @throws {ApiRequestError} When the API returns an error response.
932
+ *
933
+ * @see null - no documentation
934
+ * @example
935
+ * ```ts
936
+ * import * as hl from "@nktkas/hyperliquid";
937
+ * import { privateKeyToAccount } from "viem/accounts";
938
+ *
939
+ * const wallet = privateKeyToAccount("0x...");
940
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
941
+ * const client = new hl.WalletClient({ wallet, transport });
942
+ *
943
+ * const result = await client.registerReferrer({ code: "TEST" });
944
+ * ```
945
+ */
946
+ async registerReferrer(args, signal) {
947
+ // Construct an action
948
+ const nonce = await this.nonceManager();
949
+ const action = {
950
+ type: "registerReferrer",
951
+ code: args.code,
952
+ };
953
+ // Sign the action
954
+ const signature = await (0, signing_js_1.signL1Action)({
955
+ wallet: this.wallet,
956
+ action,
957
+ nonce,
958
+ isTestnet: this.isTestnet,
959
+ });
960
+ // Send a request
961
+ const request = { action, signature, nonce };
962
+ const response = await this.transport.request("exchange", request, signal);
963
+ // Validate a response
964
+ this._validateResponse(response);
965
+ return response;
966
+ }
936
967
  /**
937
968
  * Reserve additional rate-limited actions for a fee.
938
969
  * @param args - The parameters for the request.
939
970
  * @param signal - An optional abort signal.
940
- * @returns Successful response indicating the weight reservation.
971
+ * @returns Successful response without specific data.
941
972
  * @throws {ApiRequestError} When the API returns an error response.
942
973
  *
943
974
  * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
@@ -975,7 +1006,7 @@
975
1006
  return response;
976
1007
  }
977
1008
  /**
978
- * Schedule a time to cancel all open orders.
1009
+ * Schedule a cancel-all operation at a future time.
979
1010
  * @param args - The parameters for the request.
980
1011
  * @param signal - An optional abort signal.
981
1012
  * @returns Successful response without specific data.
@@ -1120,7 +1151,6 @@
1120
1151
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1121
1152
  * const client = new hl.WalletClient({ wallet, transport });
1122
1153
  *
1123
- * // Unknown what the successful response will be
1124
1154
  * const result = await client.spotDeploy({
1125
1155
  * registerToken2: {
1126
1156
  * spec: {
@@ -1206,13 +1236,13 @@
1206
1236
  return response;
1207
1237
  }
1208
1238
  /**
1209
- * Transfer a spot asset on L1 to another address.
1239
+ * Send spot assets to another address.
1210
1240
  * @param args - The parameters for the request.
1211
1241
  * @param signal - An optional abort signal.
1212
1242
  * @returns Successful response without specific data.
1213
1243
  * @throws {ApiRequestError} When the API returns an error response.
1214
1244
  *
1215
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer
1245
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer
1216
1246
  * @example
1217
1247
  * ```ts
1218
1248
  * import * as hl from "@nktkas/hyperliquid";
@@ -1279,9 +1309,7 @@
1279
1309
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1280
1310
  * const client = new hl.WalletClient({ wallet, transport });
1281
1311
  *
1282
- * const result = await client.spotUser({
1283
- * toggleSpotDusting: { optOut: false },
1284
- * });
1312
+ * const result = await client.spotUser({ toggleSpotDusting: { optOut: false } });
1285
1313
  * ```
1286
1314
  */
1287
1315
  async spotUser(args, signal) {
@@ -1404,7 +1432,7 @@
1404
1432
  return response;
1405
1433
  }
1406
1434
  /**
1407
- * Delegate or undelegate stake from a validator.
1435
+ * Delegate or undelegate native tokens to or from a validator.
1408
1436
  * @param args - The parameters for the request.
1409
1437
  * @param signal - An optional abort signal.
1410
1438
  * @returns Successful response without specific data.
@@ -1567,7 +1595,7 @@
1567
1595
  return response;
1568
1596
  }
1569
1597
  /**
1570
- * Update isolated margin for a position.
1598
+ * Add or remove margin from isolated position.
1571
1599
  * @param args - The parameters for the request.
1572
1600
  * @param signal - An optional abort signal.
1573
1601
  * @returns Successful response without specific data.
@@ -1583,11 +1611,7 @@
1583
1611
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1584
1612
  * const client = new hl.WalletClient({ wallet, transport });
1585
1613
  *
1586
- * const result = await client.updateIsolatedMargin({
1587
- * asset: 0,
1588
- * isBuy: true, // Add to long position
1589
- * ntli: 1, // Add 1 USD margin (integer only)
1590
- * });
1614
+ * const result = await client.updateIsolatedMargin({ asset: 0, isBuy: true, ntli: 1 * 1e6 });
1591
1615
  * ```
1592
1616
  */
1593
1617
  async updateIsolatedMargin(args, signal) {
@@ -1617,7 +1641,7 @@
1617
1641
  return response;
1618
1642
  }
1619
1643
  /**
1620
- * Update leverage for cross or isolated margin.
1644
+ * Update cross or isolated leverage on a coin.
1621
1645
  * @param args - The parameters for the request.
1622
1646
  * @param signal - An optional abort signal.
1623
1647
  * @returns Successful response without specific data.
@@ -1633,11 +1657,7 @@
1633
1657
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1634
1658
  * const client = new hl.WalletClient({ wallet, transport });
1635
1659
  *
1636
- * const result = await client.updateLeverage({
1637
- * asset: 0,
1638
- * isCross: true,
1639
- * leverage: 5,
1640
- * });
1660
+ * const result = await client.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
1641
1661
  * ```
1642
1662
  */
1643
1663
  async updateLeverage(args, signal) {
@@ -1683,10 +1703,7 @@
1683
1703
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1684
1704
  * const client = new hl.WalletClient({ wallet, transport });
1685
1705
  *
1686
- * const result = await client.usdClassTransfer({
1687
- * amount: "1",
1688
- * toPerp: true, // Transfer from Spot to Perp
1689
- * });
1706
+ * const result = await client.usdClassTransfer({ amount: "1", toPerp: true });
1690
1707
  * ```
1691
1708
  */
1692
1709
  async usdClassTransfer(args, signal) {
@@ -1722,13 +1739,13 @@
1722
1739
  return response;
1723
1740
  }
1724
1741
  /**
1725
- * Transfer USDC on L1 to another address.
1742
+ * Send usd to another address.
1726
1743
  * @param args - The parameters for the request.
1727
1744
  * @param signal - An optional abort signal.
1728
1745
  * @returns Successful response without specific data.
1729
1746
  * @throws {ApiRequestError} When the API returns an error response.
1730
1747
  *
1731
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
1748
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-usdc-transfer
1732
1749
  * @example
1733
1750
  * ```ts
1734
1751
  * import * as hl from "@nktkas/hyperliquid";
@@ -1738,10 +1755,7 @@
1738
1755
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1739
1756
  * const client = new hl.WalletClient({ wallet, transport });
1740
1757
  *
1741
- * const result = await client.usdSend({
1742
- * destination: "0x...",
1743
- * amount: "1",
1744
- * });
1758
+ * const result = await client.usdSend({ destination: "0x...", amount: "1" });
1745
1759
  * ```
1746
1760
  */
1747
1761
  async usdSend(args, signal) {
@@ -1793,10 +1807,7 @@
1793
1807
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1794
1808
  * const client = new hl.WalletClient({ wallet, transport });
1795
1809
  *
1796
- * const result = await client.vaultDistribute({
1797
- * vaultAddress: "0x...",
1798
- * usd: 10 * 1e6,
1799
- * });
1810
+ * const result = await client.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
1800
1811
  * ```
1801
1812
  */
1802
1813
  async vaultDistribute(args, signal) {
@@ -1869,7 +1880,7 @@
1869
1880
  return response;
1870
1881
  }
1871
1882
  /**
1872
- * Add or remove funds from a vault.
1883
+ * Deposit or withdraw from a vault.
1873
1884
  * @param args - The parameters for the request.
1874
1885
  * @param signal - An optional abort signal.
1875
1886
  * @returns Successful response without specific data.
@@ -1932,10 +1943,7 @@
1932
1943
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1933
1944
  * const client = new hl.WalletClient({ wallet, transport });
1934
1945
  *
1935
- * const result = await client.withdraw3({
1936
- * destination: "0x...",
1937
- * amount: "1",
1938
- * });
1946
+ * const result = await client.withdraw3({ destination: "0x...", amount: "1" });
1939
1947
  * ```
1940
1948
  */
1941
1949
  async withdraw3(args, signal) {
@@ -1970,7 +1978,6 @@
1970
1978
  this._validateResponse(response);
1971
1979
  return response;
1972
1980
  }
1973
- // ——————————————— Private methods ———————————————
1974
1981
  /** Formats a decimal number as a string, removing trailing zeros. */
1975
1982
  _formatDecimal(numStr) {
1976
1983
  if (!numStr.includes("."))
@@ -1,6 +1,50 @@
1
1
  /**
2
2
  * This module contains functions for generating Hyperliquid transaction signatures
3
3
  * and interfaces to various wallet implementations.
4
+ * @example
5
+ * ```ts
6
+ * import { signL1Action } from "@nktkas/hyperliquid/signing";
7
+ *
8
+ * const action = {
9
+ * type: "cancel",
10
+ * cancels: [{ a: 0, o: 12345 }],
11
+ * };
12
+ * const nonce = Date.now();
13
+ *
14
+ * const signature = await signL1Action({
15
+ * wallet,
16
+ * action,
17
+ * nonce,
18
+ * isTestnet: true, // Change to false for mainnet
19
+ * });
20
+ * ```
21
+ * @example
22
+ * ```ts
23
+ * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
24
+ *
25
+ * const action = {
26
+ * type: "approveAgent",
27
+ * hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
28
+ * signatureChainId: "0x66eee",
29
+ * nonce: Date.now(),
30
+ * agentAddress: "0x...",
31
+ * agentName: "Agent",
32
+ * };
33
+ *
34
+ * const signature = await signUserSignedAction({
35
+ * wallet,
36
+ * action,
37
+ * types: {
38
+ * "HyperliquidTransaction:ApproveAgent": [
39
+ * { name: "hyperliquidChain", type: "string" },
40
+ * { name: "agentAddress", type: "address" },
41
+ * { name: "agentName", type: "string" },
42
+ * { name: "nonce", type: "uint64" },
43
+ * ],
44
+ * },
45
+ * chainId: parseInt(action.signatureChainId, 16),
46
+ * });
47
+ * ```
4
48
  * @module
5
49
  */
6
50
  import { type ValueMap, type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAEpG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEpC,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,MAAM,EAAE;QAClB,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,GAAG,CAAC;SAC1B,CAAC;QACF,KAAK,EAAE;YACH,CAAC,GAAG,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;SACP,CAAC;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACpB;AAED,sGAAsG;AACtG,MAAM,WAAW,oBAAoB;IACjC,aAAa,CACT,MAAM,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,iBAAiB,EAAE,MAAM,CAAC;KAC7B,EACD,KAAK,EAAE;QACH,CAAC,GAAG,EAAE,MAAM,GAAG;YACX,IA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC7C,iCAAiC;IACjC,MAAM,EACA,wBAAwB,GACxB,oBAAoB,GACpB,sBAAsB,GACtB,gCAAgC,GAChC,sBAAsB,CAAC;IAC7B,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,+BAA+B;IAC/B,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IAC3D,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAYzC;AA6FD,4DAA4D;AAC5D,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAI9F;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,oBAAoB,CAItF;AAED,iEAAiE;AACjE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F;AAED,qGAAqG;AACrG,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAItG;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F"}
@@ -1,6 +1,50 @@
1
1
  /**
2
2
  * This module contains functions for generating Hyperliquid transaction signatures
3
3
  * and interfaces to various wallet implementations.
4
+ * @example
5
+ * ```ts
6
+ * import { signL1Action } from "@nktkas/hyperliquid/signing";
7
+ *
8
+ * const action = {
9
+ * type: "cancel",
10
+ * cancels: [{ a: 0, o: 12345 }],
11
+ * };
12
+ * const nonce = Date.now();
13
+ *
14
+ * const signature = await signL1Action({
15
+ * wallet,
16
+ * action,
17
+ * nonce,
18
+ * isTestnet: true, // Change to false for mainnet
19
+ * });
20
+ * ```
21
+ * @example
22
+ * ```ts
23
+ * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
24
+ *
25
+ * const action = {
26
+ * type: "approveAgent",
27
+ * hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
28
+ * signatureChainId: "0x66eee",
29
+ * nonce: Date.now(),
30
+ * agentAddress: "0x...",
31
+ * agentName: "Agent",
32
+ * };
33
+ *
34
+ * const signature = await signUserSignedAction({
35
+ * wallet,
36
+ * action,
37
+ * types: {
38
+ * "HyperliquidTransaction:ApproveAgent": [
39
+ * { name: "hyperliquidChain", type: "string" },
40
+ * { name: "agentAddress", type: "address" },
41
+ * { name: "agentName", type: "string" },
42
+ * { name: "nonce", type: "uint64" },
43
+ * ],
44
+ * },
45
+ * chainId: parseInt(action.signatureChainId, 16),
46
+ * });
47
+ * ```
4
48
  * @module
5
49
  */
6
50
  (function (factory) {
@@ -9,7 +53,7 @@
9
53
  if (v !== undefined) module.exports = v;
10
54
  }
11
55
  else if (typeof define === "function" && define.amd) {
12
- 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);
56
+ 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.8/hex.js"], factory);
13
57
  }
14
58
  })(function (require, exports) {
15
59
  "use strict";
@@ -24,7 +68,7 @@
24
68
  exports.isAbstractWindowEthereum = isAbstractWindowEthereum;
25
69
  const sha3_js_1 = require("../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js");
26
70
  const encode_js_1 = require("../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
27
- const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.7/hex.js");
71
+ const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.8/hex.js");
28
72
  /**
29
73
  * Create a hash of the L1 action.
30
74
  *