@nktkas/hyperliquid 0.22.1 → 0.22.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 (58) hide show
  1. package/README.md +84 -27
  2. package/esm/mod.d.ts +1 -1
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/src/clients/exchange.d.ts +136 -166
  5. package/esm/src/clients/exchange.d.ts.map +1 -1
  6. package/esm/src/clients/exchange.js +121 -146
  7. package/esm/src/clients/multiSign.d.ts +121 -280
  8. package/esm/src/clients/multiSign.d.ts.map +1 -1
  9. package/esm/src/clients/multiSign.js +123 -246
  10. package/esm/src/signing/_ethers.d.ts +33 -0
  11. package/esm/src/signing/_ethers.d.ts.map +1 -0
  12. package/esm/src/signing/_ethers.js +12 -0
  13. package/esm/src/signing/_private_key.d.ts +22 -0
  14. package/esm/src/signing/_private_key.d.ts.map +1 -0
  15. package/esm/src/signing/_private_key.js +124 -0
  16. package/esm/src/signing/_sorter.d.ts +154 -0
  17. package/esm/src/signing/_sorter.d.ts.map +1 -0
  18. package/esm/src/{signing.js → signing/_sorter.js} +0 -400
  19. package/esm/src/signing/_viem.d.ts +23 -0
  20. package/esm/src/signing/_viem.d.ts.map +1 -0
  21. package/esm/src/signing/_viem.js +6 -0
  22. package/esm/src/signing/_window.d.ts +23 -0
  23. package/esm/src/signing/_window.d.ts.map +1 -0
  24. package/esm/src/signing/_window.js +29 -0
  25. package/esm/src/signing/mod.d.ts +251 -0
  26. package/esm/src/signing/mod.d.ts.map +1 -0
  27. package/esm/src/signing/mod.js +352 -0
  28. package/package.json +6 -5
  29. package/script/mod.d.ts +1 -1
  30. package/script/mod.d.ts.map +1 -1
  31. package/script/src/clients/exchange.d.ts +136 -166
  32. package/script/src/clients/exchange.d.ts.map +1 -1
  33. package/script/src/clients/exchange.js +205 -230
  34. package/script/src/clients/multiSign.d.ts +121 -280
  35. package/script/src/clients/multiSign.d.ts.map +1 -1
  36. package/script/src/clients/multiSign.js +168 -291
  37. package/script/src/signing/_ethers.d.ts +33 -0
  38. package/script/src/signing/_ethers.d.ts.map +1 -0
  39. package/script/src/signing/_ethers.js +26 -0
  40. package/script/src/signing/_private_key.d.ts +22 -0
  41. package/script/src/signing/_private_key.d.ts.map +1 -0
  42. package/script/src/signing/_private_key.js +138 -0
  43. package/script/src/signing/_sorter.d.ts +154 -0
  44. package/script/src/signing/_sorter.d.ts.map +1 -0
  45. package/script/src/{signing.js → signing/_sorter.js} +1 -409
  46. package/script/src/signing/_viem.d.ts +23 -0
  47. package/script/src/signing/_viem.d.ts.map +1 -0
  48. package/script/src/signing/_viem.js +19 -0
  49. package/script/src/signing/_window.d.ts +23 -0
  50. package/script/src/signing/_window.d.ts.map +1 -0
  51. package/script/src/signing/_window.js +43 -0
  52. package/script/src/signing/mod.d.ts +251 -0
  53. package/script/src/signing/mod.d.ts.map +1 -0
  54. package/script/src/signing/mod.js +387 -0
  55. package/esm/src/signing.d.ts +0 -463
  56. package/esm/src/signing.d.ts.map +0 -1
  57. package/script/src/signing.d.ts +0 -463
  58. package/script/src/signing.d.ts.map +0 -1
@@ -1,4 +1,7 @@
1
- import { actionSorter, isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, signL1Action, signUserSignedAction, userSignedActionEip712Types, } from "../signing.js";
1
+ import { keccak_256 } from "@noble/hashes/sha3";
2
+ import { getPublicKey } from "@noble/secp256k1";
3
+ import { encodeHex } from "../../deps/jsr.io/@std/encoding/1.0.10/hex.js";
4
+ import { actionSorter, isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, isValidPrivateKey, signL1Action, signUserSignedAction, userSignedActionEip712Types, } from "../signing/mod.js";
2
5
  import { ExchangeClient, } from "./exchange.js";
3
6
  /**
4
7
  * Multi-signature exchange client for interacting with the Hyperliquid API.
@@ -15,14 +18,11 @@ export class MultiSignClient extends ExchangeClient {
15
18
  * @example
16
19
  * ```ts
17
20
  * import * as hl from "@nktkas/hyperliquid";
18
- * import { privateKeyToAccount } from "viem/accounts";
19
21
  *
20
22
  * const multiSignAddress = "0x...";
21
23
  * const signers = [
22
- * privateKeyToAccount("0x..."), // first is leader
23
- * privateKeyToAccount("0x..."),
24
- * privateKeyToAccount("0x..."),
25
- * ];
24
+ * "0x...", // Private key; or any other wallet libraries
25
+ * ] as const;
26
26
  *
27
27
  * const transport = new hl.HttpTransport();
28
28
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
@@ -53,17 +53,13 @@ export class MultiSignClient extends ExchangeClient {
53
53
  * @example
54
54
  * ```ts
55
55
  * import * as hl from "@nktkas/hyperliquid";
56
- * import { privateKeyToAccount } from "viem/accounts";
57
56
  *
58
57
  * const multiSignAddress = "0x...";
59
58
  * const signers = [
60
- * privateKeyToAccount("0x..."), // first is leader
61
- * privateKeyToAccount("0x..."),
62
- * // ...
63
- * privateKeyToAccount("0x..."),
64
- * ];
59
+ * "0x...", // Private key; or any other wallet libraries
60
+ * ] as const;
65
61
  *
66
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
62
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
67
63
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
68
64
  *
69
65
  * const data = await multiSignClient.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
@@ -109,17 +105,13 @@ export class MultiSignClient extends ExchangeClient {
109
105
  * @example
110
106
  * ```ts
111
107
  * import * as hl from "@nktkas/hyperliquid";
112
- * import { privateKeyToAccount } from "viem/accounts";
113
108
  *
114
109
  * const multiSignAddress = "0x...";
115
110
  * const signers = [
116
- * privateKeyToAccount("0x..."), // first is leader
117
- * privateKeyToAccount("0x..."),
118
- * // ...
119
- * privateKeyToAccount("0x..."),
120
- * ];
111
+ * "0x...", // Private key; or any other wallet libraries
112
+ * ] as const;
121
113
  *
122
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
114
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
123
115
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
124
116
  *
125
117
  * const data = await multiSignClient.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
@@ -162,17 +154,13 @@ export class MultiSignClient extends ExchangeClient {
162
154
  * @example
163
155
  * ```ts
164
156
  * import * as hl from "@nktkas/hyperliquid";
165
- * import { privateKeyToAccount } from "viem/accounts";
166
157
  *
167
158
  * const multiSignAddress = "0x...";
168
159
  * const signers = [
169
- * privateKeyToAccount("0x..."), // first is leader
170
- * privateKeyToAccount("0x..."),
171
- * // ...
172
- * privateKeyToAccount("0x..."),
173
- * ];
160
+ * "0x...", // Private key; or any other wallet libraries
161
+ * ] as const;
174
162
  *
175
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
163
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
176
164
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
177
165
  *
178
166
  * const data = await multiSignClient.batchModify({
@@ -237,17 +225,13 @@ export class MultiSignClient extends ExchangeClient {
237
225
  * @example
238
226
  * ```ts
239
227
  * import * as hl from "@nktkas/hyperliquid";
240
- * import { privateKeyToAccount } from "viem/accounts";
241
228
  *
242
229
  * const multiSignAddress = "0x...";
243
230
  * const signers = [
244
- * privateKeyToAccount("0x..."), // first is leader
245
- * privateKeyToAccount("0x..."),
246
- * // ...
247
- * privateKeyToAccount("0x..."),
248
- * ];
231
+ * "0x...", // Private key; or any other wallet libraries
232
+ * ] as const;
249
233
  *
250
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
234
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
251
235
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
252
236
  *
253
237
  * const data = await multiSignClient.cancel({
@@ -300,17 +284,13 @@ export class MultiSignClient extends ExchangeClient {
300
284
  * @example
301
285
  * ```ts
302
286
  * import * as hl from "@nktkas/hyperliquid";
303
- * import { privateKeyToAccount } from "viem/accounts";
304
287
  *
305
288
  * const multiSignAddress = "0x...";
306
289
  * const signers = [
307
- * privateKeyToAccount("0x..."), // first is leader
308
- * privateKeyToAccount("0x..."),
309
- * // ...
310
- * privateKeyToAccount("0x..."),
311
- * ];
290
+ * "0x...", // Private key; or any other wallet libraries
291
+ * ] as const;
312
292
  *
313
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
293
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
314
294
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
315
295
  *
316
296
  * const data = await multiSignClient.cancelByCloid({
@@ -362,17 +342,13 @@ export class MultiSignClient extends ExchangeClient {
362
342
  * @example
363
343
  * ```ts
364
344
  * import * as hl from "@nktkas/hyperliquid";
365
- * import { privateKeyToAccount } from "viem/accounts";
366
345
  *
367
346
  * const multiSignAddress = "0x...";
368
347
  * const signers = [
369
- * privateKeyToAccount("0x..."), // first is leader
370
- * privateKeyToAccount("0x..."),
371
- * // ...
372
- * privateKeyToAccount("0x..."),
373
- * ];
348
+ * "0x...", // Private key; or any other wallet libraries
349
+ * ] as const;
374
350
  *
375
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
351
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
376
352
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
377
353
  *
378
354
  * const data = await multiSignClient.cDeposit({ wei: 1 * 1e8 });
@@ -415,17 +391,13 @@ export class MultiSignClient extends ExchangeClient {
415
391
  * @example
416
392
  * ```ts
417
393
  * import * as hl from "@nktkas/hyperliquid";
418
- * import { privateKeyToAccount } from "viem/accounts";
419
394
  *
420
395
  * const multiSignAddress = "0x...";
421
396
  * const signers = [
422
- * privateKeyToAccount("0x..."), // first is leader
423
- * privateKeyToAccount("0x..."),
424
- * // ...
425
- * privateKeyToAccount("0x..."),
426
- * ];
397
+ * "0x...", // Private key; or any other wallet libraries
398
+ * ] as const;
427
399
  *
428
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
400
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
429
401
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
430
402
  *
431
403
  * const data = await multiSignClient.claimRewards();
@@ -462,17 +434,13 @@ export class MultiSignClient extends ExchangeClient {
462
434
  * @example
463
435
  * ```ts
464
436
  * import * as hl from "@nktkas/hyperliquid";
465
- * import { privateKeyToAccount } from "viem/accounts";
466
437
  *
467
438
  * const multiSignAddress = "0x...";
468
439
  * const signers = [
469
- * privateKeyToAccount("0x..."), // first is leader
470
- * privateKeyToAccount("0x..."),
471
- * // ...
472
- * privateKeyToAccount("0x..."),
473
- * ];
440
+ * "0x...", // Private key; or any other wallet libraries
441
+ * ] as const;
474
442
  *
475
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
443
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
476
444
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
477
445
  *
478
446
  * const data = await multiSignClient.convertToMultiSigUser({ // convert to normal user
@@ -483,7 +451,7 @@ export class MultiSignClient extends ExchangeClient {
483
451
  */
484
452
  async convertToMultiSigUser(...[args, signal]) {
485
453
  // Destructure the parameters
486
- const { ...actionArgs } = args;
454
+ const actionArgs = args;
487
455
  // Construct an action
488
456
  const nonce = await this.nonceManager();
489
457
  const action = {
@@ -518,17 +486,13 @@ export class MultiSignClient extends ExchangeClient {
518
486
  * @example
519
487
  * ```ts
520
488
  * import * as hl from "@nktkas/hyperliquid";
521
- * import { privateKeyToAccount } from "viem/accounts";
522
489
  *
523
490
  * const multiSignAddress = "0x...";
524
491
  * const signers = [
525
- * privateKeyToAccount("0x..."), // first is leader
526
- * privateKeyToAccount("0x..."),
527
- * // ...
528
- * privateKeyToAccount("0x..."),
529
- * ];
492
+ * "0x...", // Private key; or any other wallet libraries
493
+ * ] as const;
530
494
  *
531
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
495
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
532
496
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
533
497
  *
534
498
  * const data = await multiSignClient.createSubAccount({ name: "subAccountName" });
@@ -568,17 +532,13 @@ export class MultiSignClient extends ExchangeClient {
568
532
  * @example
569
533
  * ```ts
570
534
  * import * as hl from "@nktkas/hyperliquid";
571
- * import { privateKeyToAccount } from "viem/accounts";
572
535
  *
573
536
  * const multiSignAddress = "0x...";
574
537
  * const signers = [
575
- * privateKeyToAccount("0x..."), // first is leader
576
- * privateKeyToAccount("0x..."),
577
- * // ...
578
- * privateKeyToAccount("0x..."),
579
- * ];
538
+ * "0x...", // Private key; or any other wallet libraries
539
+ * ] as const;
580
540
  *
581
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
541
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
582
542
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
583
543
  *
584
544
  * const data = await multiSignClient.createVault({
@@ -673,17 +633,13 @@ export class MultiSignClient extends ExchangeClient {
673
633
  * @example
674
634
  * ```ts
675
635
  * import * as hl from "@nktkas/hyperliquid";
676
- * import { privateKeyToAccount } from "viem/accounts";
677
636
  *
678
637
  * const multiSignAddress = "0x...";
679
638
  * const signers = [
680
- * privateKeyToAccount("0x..."), // first is leader
681
- * privateKeyToAccount("0x..."),
682
- * // ...
683
- * privateKeyToAccount("0x..."),
684
- * ];
639
+ * "0x...", // Private key; or any other wallet libraries
640
+ * ] as const;
685
641
  *
686
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
642
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
687
643
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
688
644
  *
689
645
  * const data = await multiSignClient.cWithdraw({ wei: 1 * 1e8 });
@@ -726,17 +682,13 @@ export class MultiSignClient extends ExchangeClient {
726
682
  * @example
727
683
  * ```ts
728
684
  * import * as hl from "@nktkas/hyperliquid";
729
- * import { privateKeyToAccount } from "viem/accounts";
730
685
  *
731
686
  * const multiSignAddress = "0x...";
732
687
  * const signers = [
733
- * privateKeyToAccount("0x..."), // first is leader
734
- * privateKeyToAccount("0x..."),
735
- * // ...
736
- * privateKeyToAccount("0x..."),
737
- * ];
688
+ * "0x...", // Private key; or any other wallet libraries
689
+ * ] as const;
738
690
  *
739
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
691
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
740
692
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
741
693
  *
742
694
  * const data = await multiSignClient.evmUserModify({ usingBigBlocks: true });
@@ -776,17 +728,13 @@ export class MultiSignClient extends ExchangeClient {
776
728
  * @example
777
729
  * ```ts
778
730
  * import * as hl from "@nktkas/hyperliquid";
779
- * import { privateKeyToAccount } from "viem/accounts";
780
731
  *
781
732
  * const multiSignAddress = "0x...";
782
733
  * const signers = [
783
- * privateKeyToAccount("0x..."), // first is leader
784
- * privateKeyToAccount("0x..."),
785
- * // ...
786
- * privateKeyToAccount("0x..."),
787
- * ];
734
+ * "0x...", // Private key; or any other wallet libraries
735
+ * ] as const;
788
736
  *
789
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
737
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
790
738
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
791
739
  *
792
740
  * const data = await multiSignClient.modify({
@@ -855,17 +803,13 @@ export class MultiSignClient extends ExchangeClient {
855
803
  * @example
856
804
  * ```ts
857
805
  * import * as hl from "@nktkas/hyperliquid";
858
- * import { privateKeyToAccount } from "viem/accounts";
859
806
  *
860
807
  * const multiSignAddress = "0x...";
861
808
  * const signers = [
862
- * privateKeyToAccount("0x..."), // first is leader
863
- * privateKeyToAccount("0x..."),
864
- * // ...
865
- * privateKeyToAccount("0x..."),
866
- * ];
809
+ * "0x...", // Private key; or any other wallet libraries
810
+ * ] as const;
867
811
  *
868
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
812
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
869
813
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
870
814
  *
871
815
  * const data = await multiSignClient.order({
@@ -952,17 +896,13 @@ export class MultiSignClient extends ExchangeClient {
952
896
  * @example
953
897
  * ```ts
954
898
  * import * as hl from "@nktkas/hyperliquid";
955
- * import { privateKeyToAccount } from "viem/accounts";
956
899
  *
957
900
  * const multiSignAddress = "0x...";
958
901
  * const signers = [
959
- * privateKeyToAccount("0x..."), // first is leader
960
- * privateKeyToAccount("0x..."),
961
- * // ...
962
- * privateKeyToAccount("0x..."),
963
- * ];
902
+ * "0x...", // Private key; or any other wallet libraries
903
+ * ] as const;
964
904
  *
965
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
905
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
966
906
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
967
907
  *
968
908
  * const data = await multiSignClient.perpDexClassTransfer({
@@ -1010,17 +950,13 @@ export class MultiSignClient extends ExchangeClient {
1010
950
  * @example
1011
951
  * ```ts
1012
952
  * import * as hl from "@nktkas/hyperliquid";
1013
- * import { privateKeyToAccount } from "viem/accounts";
1014
953
  *
1015
954
  * const multiSignAddress = "0x...";
1016
955
  * const signers = [
1017
- * privateKeyToAccount("0x..."), // first is leader
1018
- * privateKeyToAccount("0x..."),
1019
- * // ...
1020
- * privateKeyToAccount("0x..."),
1021
- * ];
956
+ * "0x...", // Private key; or any other wallet libraries
957
+ * ] as const;
1022
958
  *
1023
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
959
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1024
960
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1025
961
  *
1026
962
  * const data = await multiSignClient.registerReferrer({ code: "TEST" });
@@ -1060,17 +996,13 @@ export class MultiSignClient extends ExchangeClient {
1060
996
  * @example
1061
997
  * ```ts
1062
998
  * import * as hl from "@nktkas/hyperliquid";
1063
- * import { privateKeyToAccount } from "viem/accounts";
1064
999
  *
1065
1000
  * const multiSignAddress = "0x...";
1066
1001
  * const signers = [
1067
- * privateKeyToAccount("0x..."), // first is leader
1068
- * privateKeyToAccount("0x..."),
1069
- * // ...
1070
- * privateKeyToAccount("0x..."),
1071
- * ];
1002
+ * "0x...", // Private key; or any other wallet libraries
1003
+ * ] as const;
1072
1004
  *
1073
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1005
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1074
1006
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1075
1007
  *
1076
1008
  * const data = await multiSignClient.reserveRequestWeight({ weight: 10 });
@@ -1145,17 +1077,13 @@ export class MultiSignClient extends ExchangeClient {
1145
1077
  * @example
1146
1078
  * ```ts
1147
1079
  * import * as hl from "@nktkas/hyperliquid";
1148
- * import { privateKeyToAccount } from "viem/accounts";
1149
1080
  *
1150
1081
  * const multiSignAddress = "0x...";
1151
1082
  * const signers = [
1152
- * privateKeyToAccount("0x..."), // first is leader
1153
- * privateKeyToAccount("0x..."),
1154
- * // ...
1155
- * privateKeyToAccount("0x..."),
1156
- * ];
1083
+ * "0x...", // Private key; or any other wallet libraries
1084
+ * ] as const;
1157
1085
  *
1158
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1086
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1159
1087
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1160
1088
  *
1161
1089
  * const data = await multiSignClient.setDisplayName({ displayName: "My Name" });
@@ -1195,17 +1123,13 @@ export class MultiSignClient extends ExchangeClient {
1195
1123
  * @example
1196
1124
  * ```ts
1197
1125
  * import * as hl from "@nktkas/hyperliquid";
1198
- * import { privateKeyToAccount } from "viem/accounts";
1199
1126
  *
1200
1127
  * const multiSignAddress = "0x...";
1201
1128
  * const signers = [
1202
- * privateKeyToAccount("0x..."), // first is leader
1203
- * privateKeyToAccount("0x..."),
1204
- * // ...
1205
- * privateKeyToAccount("0x..."),
1206
- * ];
1129
+ * "0x...", // Private key; or any other wallet libraries
1130
+ * ] as const;
1207
1131
  *
1208
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1132
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1209
1133
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1210
1134
  *
1211
1135
  * const data = await multiSignClient.setReferrer({ code: "TEST" });
@@ -1269,17 +1193,13 @@ export class MultiSignClient extends ExchangeClient {
1269
1193
  * @example
1270
1194
  * ```ts
1271
1195
  * import * as hl from "@nktkas/hyperliquid";
1272
- * import { privateKeyToAccount } from "viem/accounts";
1273
1196
  *
1274
1197
  * const multiSignAddress = "0x...";
1275
1198
  * const signers = [
1276
- * privateKeyToAccount("0x..."), // first is leader
1277
- * privateKeyToAccount("0x..."),
1278
- * // ...
1279
- * privateKeyToAccount("0x..."),
1280
- * ];
1199
+ * "0x...", // Private key; or any other wallet libraries
1200
+ * ] as const;
1281
1201
  *
1282
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1202
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1283
1203
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1284
1204
  *
1285
1205
  * const data = await multiSignClient.spotSend({
@@ -1326,17 +1246,13 @@ export class MultiSignClient extends ExchangeClient {
1326
1246
  * @example
1327
1247
  * ```ts
1328
1248
  * import * as hl from "@nktkas/hyperliquid";
1329
- * import { privateKeyToAccount } from "viem/accounts";
1330
1249
  *
1331
1250
  * const multiSignAddress = "0x...";
1332
1251
  * const signers = [
1333
- * privateKeyToAccount("0x..."), // first is leader
1334
- * privateKeyToAccount("0x..."),
1335
- * // ...
1336
- * privateKeyToAccount("0x..."),
1337
- * ];
1252
+ * "0x...", // Private key; or any other wallet libraries
1253
+ * ] as const;
1338
1254
  *
1339
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1255
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1340
1256
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1341
1257
  *
1342
1258
  * const data = await multiSignClient.spotUser({ toggleSpotDusting: { optOut: false } });
@@ -1376,17 +1292,13 @@ export class MultiSignClient extends ExchangeClient {
1376
1292
  * @example
1377
1293
  * ```ts
1378
1294
  * import * as hl from "@nktkas/hyperliquid";
1379
- * import { privateKeyToAccount } from "viem/accounts";
1380
1295
  *
1381
1296
  * const multiSignAddress = "0x...";
1382
1297
  * const signers = [
1383
- * privateKeyToAccount("0x..."), // first is leader
1384
- * privateKeyToAccount("0x..."),
1385
- * // ...
1386
- * privateKeyToAccount("0x..."),
1387
- * ];
1298
+ * "0x...", // Private key; or any other wallet libraries
1299
+ * ] as const;
1388
1300
  *
1389
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1301
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1390
1302
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1391
1303
  *
1392
1304
  * const data = await multiSignClient.subAccountSpotTransfer({
@@ -1431,17 +1343,13 @@ export class MultiSignClient extends ExchangeClient {
1431
1343
  * @example
1432
1344
  * ```ts
1433
1345
  * import * as hl from "@nktkas/hyperliquid";
1434
- * import { privateKeyToAccount } from "viem/accounts";
1435
1346
  *
1436
1347
  * const multiSignAddress = "0x...";
1437
1348
  * const signers = [
1438
- * privateKeyToAccount("0x..."), // first is leader
1439
- * privateKeyToAccount("0x..."),
1440
- * // ...
1441
- * privateKeyToAccount("0x..."),
1442
- * ];
1349
+ * "0x...", // Private key; or any other wallet libraries
1350
+ * ] as const;
1443
1351
  *
1444
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1352
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1445
1353
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1446
1354
  *
1447
1355
  * const data = await multiSignClient.subAccountTransfer({
@@ -1485,17 +1393,13 @@ export class MultiSignClient extends ExchangeClient {
1485
1393
  * @example
1486
1394
  * ```ts
1487
1395
  * import * as hl from "@nktkas/hyperliquid";
1488
- * import { privateKeyToAccount } from "viem/accounts";
1489
1396
  *
1490
1397
  * const multiSignAddress = "0x...";
1491
1398
  * const signers = [
1492
- * privateKeyToAccount("0x..."), // first is leader
1493
- * privateKeyToAccount("0x..."),
1494
- * // ...
1495
- * privateKeyToAccount("0x..."),
1496
- * ];
1399
+ * "0x...", // Private key; or any other wallet libraries
1400
+ * ] as const;
1497
1401
  *
1498
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1402
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1499
1403
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1500
1404
  *
1501
1405
  * const data = await multiSignClient.tokenDelegate({
@@ -1542,17 +1446,13 @@ export class MultiSignClient extends ExchangeClient {
1542
1446
  * @example
1543
1447
  * ```ts
1544
1448
  * import * as hl from "@nktkas/hyperliquid";
1545
- * import { privateKeyToAccount } from "viem/accounts";
1546
1449
  *
1547
1450
  * const multiSignAddress = "0x...";
1548
1451
  * const signers = [
1549
- * privateKeyToAccount("0x..."), // first is leader
1550
- * privateKeyToAccount("0x..."),
1551
- * // ...
1552
- * privateKeyToAccount("0x..."),
1553
- * ];
1452
+ * "0x...", // Private key; or any other wallet libraries
1453
+ * ] as const;
1554
1454
  *
1555
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1455
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1556
1456
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1557
1457
  *
1558
1458
  * const data = await multiSignClient.twapCancel({
@@ -1603,17 +1503,13 @@ export class MultiSignClient extends ExchangeClient {
1603
1503
  * @example
1604
1504
  * ```ts
1605
1505
  * import * as hl from "@nktkas/hyperliquid";
1606
- * import { privateKeyToAccount } from "viem/accounts";
1607
1506
  *
1608
1507
  * const multiSignAddress = "0x...";
1609
1508
  * const signers = [
1610
- * privateKeyToAccount("0x..."), // first is leader
1611
- * privateKeyToAccount("0x..."),
1612
- * // ...
1613
- * privateKeyToAccount("0x..."),
1614
- * ];
1509
+ * "0x...", // Private key; or any other wallet libraries
1510
+ * ] as const;
1615
1511
  *
1616
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1512
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1617
1513
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1618
1514
  *
1619
1515
  * const data = await multiSignClient.twapOrder({
@@ -1670,17 +1566,13 @@ export class MultiSignClient extends ExchangeClient {
1670
1566
  * @example
1671
1567
  * ```ts
1672
1568
  * import * as hl from "@nktkas/hyperliquid";
1673
- * import { privateKeyToAccount } from "viem/accounts";
1674
1569
  *
1675
1570
  * const multiSignAddress = "0x...";
1676
1571
  * const signers = [
1677
- * privateKeyToAccount("0x..."), // first is leader
1678
- * privateKeyToAccount("0x..."),
1679
- * // ...
1680
- * privateKeyToAccount("0x..."),
1681
- * ];
1572
+ * "0x...", // Private key; or any other wallet libraries
1573
+ * ] as const;
1682
1574
  *
1683
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1575
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1684
1576
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1685
1577
  *
1686
1578
  * const data = await multiSignClient.updateIsolatedMargin({
@@ -1732,17 +1624,13 @@ export class MultiSignClient extends ExchangeClient {
1732
1624
  * @example
1733
1625
  * ```ts
1734
1626
  * import * as hl from "@nktkas/hyperliquid";
1735
- * import { privateKeyToAccount } from "viem/accounts";
1736
1627
  *
1737
1628
  * const multiSignAddress = "0x...";
1738
1629
  * const signers = [
1739
- * privateKeyToAccount("0x..."), // first is leader
1740
- * privateKeyToAccount("0x..."),
1741
- * // ...
1742
- * privateKeyToAccount("0x..."),
1743
- * ];
1630
+ * "0x...", // Private key; or any other wallet libraries
1631
+ * ] as const;
1744
1632
  *
1745
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1633
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1746
1634
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1747
1635
  *
1748
1636
  * const data = await multiSignClient.updateLeverage({
@@ -1794,17 +1682,13 @@ export class MultiSignClient extends ExchangeClient {
1794
1682
  * @example
1795
1683
  * ```ts
1796
1684
  * import * as hl from "@nktkas/hyperliquid";
1797
- * import { privateKeyToAccount } from "viem/accounts";
1798
1685
  *
1799
1686
  * const multiSignAddress = "0x...";
1800
1687
  * const signers = [
1801
- * privateKeyToAccount("0x..."), // first is leader
1802
- * privateKeyToAccount("0x..."),
1803
- * // ...
1804
- * privateKeyToAccount("0x..."),
1805
- * ];
1688
+ * "0x...", // Private key; or any other wallet libraries
1689
+ * ] as const;
1806
1690
  *
1807
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1691
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1808
1692
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1809
1693
  *
1810
1694
  * const data = await multiSignClient.usdClassTransfer({ amount: "1", toPerp: true });
@@ -1847,17 +1731,13 @@ export class MultiSignClient extends ExchangeClient {
1847
1731
  * @example
1848
1732
  * ```ts
1849
1733
  * import * as hl from "@nktkas/hyperliquid";
1850
- * import { privateKeyToAccount } from "viem/accounts";
1851
1734
  *
1852
1735
  * const multiSignAddress = "0x...";
1853
1736
  * const signers = [
1854
- * privateKeyToAccount("0x..."), // first is leader
1855
- * privateKeyToAccount("0x..."),
1856
- * // ...
1857
- * privateKeyToAccount("0x..."),
1858
- * ];
1737
+ * "0x...", // Private key; or any other wallet libraries
1738
+ * ] as const;
1859
1739
  *
1860
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1740
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1861
1741
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1862
1742
  *
1863
1743
  * const data = await multiSignClient.usdSend({ destination: "0x...", amount: "1" });
@@ -1900,17 +1780,13 @@ export class MultiSignClient extends ExchangeClient {
1900
1780
  * @example
1901
1781
  * ```ts
1902
1782
  * import * as hl from "@nktkas/hyperliquid";
1903
- * import { privateKeyToAccount } from "viem/accounts";
1904
1783
  *
1905
1784
  * const multiSignAddress = "0x...";
1906
1785
  * const signers = [
1907
- * privateKeyToAccount("0x..."), // first is leader
1908
- * privateKeyToAccount("0x..."),
1909
- * // ...
1910
- * privateKeyToAccount("0x..."),
1911
- * ];
1786
+ * "0x...", // Private key; or any other wallet libraries
1787
+ * ] as const;
1912
1788
  *
1913
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1789
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1914
1790
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1915
1791
  *
1916
1792
  * const data = await multiSignClient.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
@@ -1950,17 +1826,13 @@ export class MultiSignClient extends ExchangeClient {
1950
1826
  * @example
1951
1827
  * ```ts
1952
1828
  * import * as hl from "@nktkas/hyperliquid";
1953
- * import { privateKeyToAccount } from "viem/accounts";
1954
1829
  *
1955
1830
  * const multiSignAddress = "0x...";
1956
1831
  * const signers = [
1957
- * privateKeyToAccount("0x..."), // first is leader
1958
- * privateKeyToAccount("0x..."),
1959
- * // ...
1960
- * privateKeyToAccount("0x..."),
1961
- * ];
1832
+ * "0x...", // Private key; or any other wallet libraries
1833
+ * ] as const;
1962
1834
  *
1963
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1835
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1964
1836
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1965
1837
  *
1966
1838
  * const data = await multiSignClient.vaultModify({
@@ -2004,17 +1876,13 @@ export class MultiSignClient extends ExchangeClient {
2004
1876
  * @example
2005
1877
  * ```ts
2006
1878
  * import * as hl from "@nktkas/hyperliquid";
2007
- * import { privateKeyToAccount } from "viem/accounts";
2008
1879
  *
2009
1880
  * const multiSignAddress = "0x...";
2010
1881
  * const signers = [
2011
- * privateKeyToAccount("0x..."), // first is leader
2012
- * privateKeyToAccount("0x..."),
2013
- * // ...
2014
- * privateKeyToAccount("0x..."),
2015
- * ];
1882
+ * "0x...", // Private key; or any other wallet libraries
1883
+ * ] as const;
2016
1884
  *
2017
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1885
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
2018
1886
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
2019
1887
  *
2020
1888
  * const data = await multiSignClient.vaultTransfer({
@@ -2059,17 +1927,13 @@ export class MultiSignClient extends ExchangeClient {
2059
1927
  * @example
2060
1928
  * ```ts
2061
1929
  * import * as hl from "@nktkas/hyperliquid";
2062
- * import { privateKeyToAccount } from "viem/accounts";
2063
1930
  *
2064
1931
  * const multiSignAddress = "0x...";
2065
1932
  * const signers = [
2066
- * privateKeyToAccount("0x..."), // first is leader
2067
- * privateKeyToAccount("0x..."),
2068
- * // ...
2069
- * privateKeyToAccount("0x..."),
2070
- * ];
1933
+ * "0x...", // Private key; or any other wallet libraries
1934
+ * ] as const;
2071
1935
  *
2072
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1936
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
2073
1937
  * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
2074
1938
  *
2075
1939
  * const data = await multiSignClient.withdraw3({ destination: "0x...", amount: "1" });
@@ -2104,7 +1968,10 @@ export class MultiSignClient extends ExchangeClient {
2104
1968
  }
2105
1969
  /** Extracts the wallet address from different wallet types. */
2106
1970
  async _getWalletAddress(wallet) {
2107
- if (isAbstractViemWalletClient(wallet)) {
1971
+ if (isValidPrivateKey(wallet)) {
1972
+ return privateKeyToAddress(wallet);
1973
+ }
1974
+ else if (isAbstractViemWalletClient(wallet)) {
2108
1975
  return wallet.address;
2109
1976
  }
2110
1977
  else if (isAbstractEthersSigner(wallet) || isAbstractEthersV5Signer(wallet)) {
@@ -2156,3 +2023,13 @@ export class MultiSignClient extends ExchangeClient {
2156
2023
  }));
2157
2024
  }
2158
2025
  }
2026
+ /** Converts a private key to an Ethereum address. */
2027
+ function privateKeyToAddress(privateKey) {
2028
+ const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
2029
+ const publicKey = getPublicKey(cleanKey, false);
2030
+ const publicKeyWithoutPrefix = publicKey.slice(1);
2031
+ const hash = keccak_256(publicKeyWithoutPrefix);
2032
+ const addressBytes = hash.slice(-20);
2033
+ const address = encodeHex(addressBytes);
2034
+ return `0x${address}`;
2035
+ }