@nktkas/hyperliquid 0.19.0 → 0.19.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 (45) hide show
  1. package/CONTRIBUTING.md +4 -2
  2. package/README.md +15 -6
  3. package/esm/src/clients/event.d.ts +4 -1
  4. package/esm/src/clients/event.d.ts.map +1 -1
  5. package/esm/src/clients/event.js +9 -20
  6. package/esm/src/clients/public.d.ts +2 -0
  7. package/esm/src/clients/public.d.ts.map +1 -1
  8. package/esm/src/clients/public.js +6 -34
  9. package/esm/src/clients/wallet.d.ts +190 -15
  10. package/esm/src/clients/wallet.d.ts.map +1 -1
  11. package/esm/src/clients/wallet.js +276 -44
  12. package/esm/src/signing.d.ts +75 -5
  13. package/esm/src/signing.d.ts.map +1 -1
  14. package/esm/src/signing.js +72 -2
  15. package/esm/src/transports/websocket/_websocket_request_dispatcher.js +28 -14
  16. package/esm/src/types/exchange/requests.d.ts +278 -66
  17. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  18. package/esm/src/types/info/orders.d.ts +1 -1
  19. package/esm/src/types/info/orders.d.ts.map +1 -1
  20. package/esm/src/types/info/requests.d.ts +5 -5
  21. package/esm/src/types/info/requests.d.ts.map +1 -1
  22. package/esm/src/types/subscriptions/requests.d.ts +2 -0
  23. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/script/src/clients/event.d.ts +4 -1
  26. package/script/src/clients/event.d.ts.map +1 -1
  27. package/script/src/clients/event.js +9 -20
  28. package/script/src/clients/public.d.ts +2 -0
  29. package/script/src/clients/public.d.ts.map +1 -1
  30. package/script/src/clients/public.js +6 -34
  31. package/script/src/clients/wallet.d.ts +190 -15
  32. package/script/src/clients/wallet.d.ts.map +1 -1
  33. package/script/src/clients/wallet.js +275 -43
  34. package/script/src/signing.d.ts +75 -5
  35. package/script/src/signing.d.ts.map +1 -1
  36. package/script/src/signing.js +73 -2
  37. package/script/src/transports/websocket/_websocket_request_dispatcher.js +28 -14
  38. package/script/src/types/exchange/requests.d.ts +278 -66
  39. package/script/src/types/exchange/requests.d.ts.map +1 -1
  40. package/script/src/types/info/orders.d.ts +1 -1
  41. package/script/src/types/info/orders.d.ts.map +1 -1
  42. package/script/src/types/info/requests.d.ts +5 -5
  43. package/script/src/types/info/requests.d.ts.map +1 -1
  44. package/script/src/types/subscriptions/requests.d.ts +2 -0
  45. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
@@ -575,6 +575,58 @@
575
575
  this._validateResponse(response);
576
576
  return response;
577
577
  }
578
+ /**
579
+ * Convert a single-signature account to a multi-signature account.
580
+ * @param args - The parameters for the request.
581
+ * @param signal - An optional abort signal.
582
+ * @returns Successful response without specific data.
583
+ * @throws {ApiRequestError} When the API returns an error response.
584
+ *
585
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig
586
+ * @example
587
+ * ```ts
588
+ * import * as hl from "@nktkas/hyperliquid";
589
+ * import { privateKeyToAccount } from "viem/accounts";
590
+ *
591
+ * const wallet = privateKeyToAccount("0x...");
592
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
593
+ * const client = new hl.WalletClient({ wallet, transport });
594
+ *
595
+ * const result = await client.convertToMultiSigUser({
596
+ * authorizedUsers: ["0x...", "0x..."],
597
+ * threshold: 2,
598
+ * });
599
+ * ```
600
+ */
601
+ async convertToMultiSigUser(args, signal) {
602
+ // Construct an action
603
+ const action = {
604
+ type: "convertToMultiSigUser",
605
+ hyperliquidChain: this._getHyperliquidChain(),
606
+ signatureChainId: await this._getSignatureChainId(),
607
+ signers: JSON.stringify(args),
608
+ nonce: await this.nonceManager(),
609
+ };
610
+ // Sign the action
611
+ const signature = await (0, signing_js_1.signUserSignedAction)({
612
+ wallet: this.wallet,
613
+ action,
614
+ types: {
615
+ "HyperliquidTransaction:ConvertToMultiSigUser": [
616
+ { name: "hyperliquidChain", type: "string" },
617
+ { name: "signers", type: "string" },
618
+ { name: "nonce", type: "uint64" },
619
+ ],
620
+ },
621
+ chainId: parseInt(action.signatureChainId, 16),
622
+ });
623
+ // Send a request
624
+ const request = { action, signature, nonce: action.nonce };
625
+ const response = await this.transport.request("exchange", request, signal);
626
+ // Validate a response
627
+ this._validateResponse(response);
628
+ return response;
629
+ }
578
630
  /**
579
631
  * Create a sub-account.
580
632
  * @param args - The parameters for the request.
@@ -664,6 +716,88 @@
664
716
  this._validateResponse(response);
665
717
  return response;
666
718
  }
719
+ async cSignerAction(args, signal) {
720
+ // Destructure the parameters
721
+ const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
722
+ // Construct an action
723
+ const nonce = await this.nonceManager();
724
+ const action = {
725
+ type: "CSignerAction",
726
+ ...actionArgs,
727
+ };
728
+ // Sign the action
729
+ const signature = await (0, signing_js_1.signL1Action)({
730
+ wallet: this.wallet,
731
+ action,
732
+ nonce,
733
+ isTestnet: this.isTestnet,
734
+ expiresAfter,
735
+ });
736
+ // Send a request
737
+ const request = { action, signature, nonce, expiresAfter };
738
+ const response = await this.transport.request("exchange", request, signal);
739
+ // Validate a response
740
+ this._validateResponse(response);
741
+ return response;
742
+ }
743
+ async cValidatorAction(args, signal) {
744
+ // Destructure the parameters
745
+ const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
746
+ // Construct an action
747
+ const nonce = await this.nonceManager();
748
+ let action;
749
+ if ("changeProfile" in actionArgs) {
750
+ action = {
751
+ type: "CValidatorAction",
752
+ changeProfile: {
753
+ node_ip: actionArgs.changeProfile.node_ip ?? null,
754
+ name: actionArgs.changeProfile.name ?? null,
755
+ description: actionArgs.changeProfile.description ?? null,
756
+ unjailed: actionArgs.changeProfile.unjailed,
757
+ disable_delegations: actionArgs.changeProfile.disable_delegations ?? null,
758
+ commission_bps: actionArgs.changeProfile.commission_bps ?? null,
759
+ signer: actionArgs.changeProfile.signer?.toLowerCase() ?? null,
760
+ },
761
+ };
762
+ }
763
+ else if ("register" in actionArgs) {
764
+ action = {
765
+ type: "CValidatorAction",
766
+ register: {
767
+ profile: {
768
+ node_ip: { Ip: actionArgs.register.profile.node_ip.Ip },
769
+ name: actionArgs.register.profile.name,
770
+ description: actionArgs.register.profile.description,
771
+ delegations_disabled: actionArgs.register.profile.delegations_disabled,
772
+ commission_bps: actionArgs.register.profile.commission_bps,
773
+ signer: actionArgs.register.profile.signer?.toLowerCase(),
774
+ },
775
+ unjailed: actionArgs.register.unjailed,
776
+ initial_wei: actionArgs.register.initial_wei,
777
+ },
778
+ };
779
+ }
780
+ else {
781
+ action = {
782
+ type: "CValidatorAction",
783
+ unregister: actionArgs.unregister,
784
+ };
785
+ }
786
+ // Sign the action
787
+ const signature = await (0, signing_js_1.signL1Action)({
788
+ wallet: this.wallet,
789
+ action,
790
+ nonce,
791
+ isTestnet: this.isTestnet,
792
+ expiresAfter,
793
+ });
794
+ // Send a request
795
+ const request = { action, signature, nonce, expiresAfter };
796
+ const response = await this.transport.request("exchange", request, signal);
797
+ // Validate a response
798
+ this._validateResponse(response);
799
+ return response;
800
+ }
667
801
  /**
668
802
  * Transfer native token from staking into the user's spot account.
669
803
  * @param args - The parameters for the request.
@@ -837,6 +971,85 @@
837
971
  this._validateResponse(response);
838
972
  return response;
839
973
  }
974
+ /**
975
+ * A multi-signature request.
976
+ * @param args - The parameters for the request.
977
+ * @param signal - An optional abort signal.
978
+ * @returns Successful response without specific data.
979
+ * @throws {ApiRequestError} When the API returns an error response.
980
+ *
981
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig
982
+ * @example
983
+ * ```ts
984
+ * import * as hl from "@nktkas/hyperliquid";
985
+ * import { privateKeyToAccount } from "viem/accounts";
986
+ *
987
+ * const wallet = privateKeyToAccount("0x...");
988
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
989
+ * const client = new hl.WalletClient({ wallet, transport });
990
+ *
991
+ * const multiSigUser = "0x..."; // Multi-sig user address
992
+ *
993
+ * const nonce = Date.now();
994
+ * const action = { type: "scheduleCancel", time: Date.now() + 10000 };
995
+ *
996
+ * const signature = await hl.signL1Action({
997
+ * wallet,
998
+ * action: [multiSigUser.toLowerCase(), signer1.address.toLowerCase(), action],
999
+ * nonce,
1000
+ * isTestnet: true,
1001
+ * });
1002
+ *
1003
+ * const result = await client.multiSig({
1004
+ * signatures: [signature],
1005
+ * payload: {
1006
+ * multiSigUser,
1007
+ * outerSigner: wallet.address,
1008
+ * action,
1009
+ * },
1010
+ * nonce,
1011
+ * });
1012
+ * ```
1013
+ * @unstable May not behave as expected and the interface may change in the future.
1014
+ */
1015
+ async multiSig(args, signal) {
1016
+ // Destructure the parameters
1017
+ const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), nonce, ...actionArgs } = args;
1018
+ // Construct an action
1019
+ const hyperliquidChain = this._getHyperliquidChain();
1020
+ const action = {
1021
+ type: "multiSig",
1022
+ signatureChainId: await this._getSignatureChainId(),
1023
+ signatures: actionArgs.signatures.map((signature) => ({
1024
+ r: signature.r.replace(/^0x0+/, "0x").toLowerCase(),
1025
+ s: signature.s.replace(/^0x0+/, "0x").toLowerCase(),
1026
+ v: signature.v,
1027
+ })),
1028
+ payload: {
1029
+ multiSigUser: actionArgs.payload.multiSigUser.toLowerCase(),
1030
+ outerSigner: actionArgs.payload.outerSigner.toLowerCase(),
1031
+ action: actionArgs.payload.action,
1032
+ },
1033
+ };
1034
+ // Sign the action
1035
+ const actionForMultiSig = structuredClone(action);
1036
+ delete actionForMultiSig.type;
1037
+ const signature = await (0, signing_js_1.signMultiSigAction)({
1038
+ wallet: this.wallet,
1039
+ action: actionForMultiSig,
1040
+ nonce,
1041
+ vaultAddress,
1042
+ expiresAfter,
1043
+ hyperliquidChain,
1044
+ signatureChainId: action.signatureChainId,
1045
+ });
1046
+ // Send a request
1047
+ const request = { action, signature, nonce, vaultAddress, expiresAfter };
1048
+ const response = await this.transport.request("exchange", request, signal);
1049
+ // Validate a response
1050
+ this._validateResponse(response);
1051
+ return response;
1052
+ }
840
1053
  /**
841
1054
  * Place an order(s).
842
1055
  * @param args - The parameters for the request.
@@ -931,16 +1144,6 @@
931
1144
  this._validateResponse(response);
932
1145
  return response;
933
1146
  }
934
- /**
935
- * Deploying HIP-3 assets.
936
- * @param args - The parameters for the request.
937
- * @param signal - An optional abort signal.
938
- * @returns Successful response without specific data.
939
- * @throws {ApiRequestError} When the API returns an error response.
940
- *
941
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-3-assets
942
- * @untested
943
- */
944
1147
  async perpDeploy(args, signal) {
945
1148
  // Construct an action
946
1149
  const nonce = await this.nonceManager();
@@ -993,6 +1196,63 @@
993
1196
  this._validateResponse(response);
994
1197
  return response;
995
1198
  }
1199
+ /**
1200
+ * Transfer funds between Spot account and Perp dex account.
1201
+ * @param args - The parameters for the request.
1202
+ * @param signal - An optional abort signal.
1203
+ * @returns Successful response without specific data.
1204
+ * @throws {ApiRequestError} When the API returns an error response.
1205
+ *
1206
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa
1207
+ * @example
1208
+ * ```ts
1209
+ * import * as hl from "@nktkas/hyperliquid";
1210
+ * import { privateKeyToAccount } from "viem/accounts";
1211
+ *
1212
+ * const wallet = privateKeyToAccount("0x...");
1213
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
1214
+ * const client = new hl.WalletClient({ wallet, transport });
1215
+ *
1216
+ * const result = await client.perpDexClassTransfer({
1217
+ * dex: "test",
1218
+ * token: "USDC",
1219
+ * amount: "1",
1220
+ * toPerp: true,
1221
+ * });
1222
+ * ```
1223
+ */
1224
+ async perpDexClassTransfer(args, signal) {
1225
+ // Construct an action
1226
+ const action = {
1227
+ ...args,
1228
+ type: "PerpDexClassTransfer",
1229
+ hyperliquidChain: this._getHyperliquidChain(),
1230
+ signatureChainId: await this._getSignatureChainId(),
1231
+ nonce: await this.nonceManager(),
1232
+ };
1233
+ // Sign the action
1234
+ const signature = await (0, signing_js_1.signUserSignedAction)({
1235
+ wallet: this.wallet,
1236
+ action,
1237
+ types: {
1238
+ "HyperliquidTransaction:PerpDexClassTransfer": [
1239
+ { name: "hyperliquidChain", type: "string" },
1240
+ { name: "dex", type: "string" },
1241
+ { name: "token", type: "string" },
1242
+ { name: "amount", type: "string" },
1243
+ { name: "toPerp", type: "bool" },
1244
+ { name: "nonce", type: "uint64" },
1245
+ ],
1246
+ },
1247
+ chainId: parseInt(action.signatureChainId, 16),
1248
+ });
1249
+ // Send a request
1250
+ const request = { action, signature, nonce: action.nonce };
1251
+ const response = await this.transport.request("exchange", request, signal);
1252
+ // Validate a response
1253
+ this._validateResponse(response);
1254
+ return response;
1255
+ }
996
1256
  /**
997
1257
  * Create a referral code.
998
1258
  * @param args - The parameters for the request.
@@ -1078,27 +1338,9 @@
1078
1338
  this._validateResponse(response);
1079
1339
  return response;
1080
1340
  }
1081
- /**
1082
- * Schedule a cancel-all operation at a future time.
1083
- * @param args - The parameters for the request.
1084
- * @param signal - An optional abort signal.
1085
- * @returns Successful response without specific data.
1086
- * @throws {ApiRequestError} When the API returns an error response.
1087
- *
1088
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch
1089
- * @example
1090
- * ```ts
1091
- * import * as hl from "@nktkas/hyperliquid";
1092
- * import { privateKeyToAccount } from "viem/accounts";
1093
- *
1094
- * const wallet = privateKeyToAccount("0x...");
1095
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
1096
- * const client = new hl.WalletClient({ wallet, transport });
1097
- *
1098
- * const result = await client.scheduleCancel({ time: Date.now() + 3600000 });
1099
- * ```
1100
- */
1101
- async scheduleCancel(args = {}, signal) {
1341
+ async scheduleCancel(args_or_signal, maybeSignal) {
1342
+ const args = args_or_signal instanceof AbortSignal ? {} : args_or_signal ?? {};
1343
+ const signal = args_or_signal instanceof AbortSignal ? args_or_signal : maybeSignal;
1102
1344
  // Destructure the parameters
1103
1345
  const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1104
1346
  // Construct an action
@@ -1207,16 +1449,6 @@
1207
1449
  this._validateResponse(response);
1208
1450
  return response;
1209
1451
  }
1210
- /**
1211
- * Deploying HIP-1 and HIP-2 assets.
1212
- * @param args - The parameters for the request.
1213
- * @param signal - An optional abort signal.
1214
- * @returns Successful response without specific data.
1215
- * @throws {ApiRequestError} When the API returns an error response.
1216
- *
1217
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets
1218
- * @untested
1219
- */
1220
1452
  async spotDeploy(args, signal) {
1221
1453
  // Construct an action
1222
1454
  const nonce = await this.nonceManager();
@@ -1763,7 +1995,7 @@
1763
1995
  return response;
1764
1996
  }
1765
1997
  /**
1766
- * Transfer funds between Spot and Perp accounts.
1998
+ * Transfer funds between Spot account and Perp account.
1767
1999
  * @param args - The parameters for the request.
1768
2000
  * @param signal - An optional abort signal.
1769
2001
  * @returns Successful response without specific data.
@@ -2062,7 +2294,7 @@
2062
2294
  /** Guesses the chain ID based on the wallet type or the isTestnet flag. */
2063
2295
  async _guessSignatureChainId() {
2064
2296
  // Trying to get chain ID of the wallet
2065
- if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet)) {
2297
+ if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet) || (0, signing_js_1.isAbstractExtendedViemWalletClient)(this.wallet)) {
2066
2298
  if ("getChainId" in this.wallet && typeof this.wallet.getChainId === "function") {
2067
2299
  const chainId = await this.wallet.getChainId();
2068
2300
  return `0x${chainId.toString(16)}`;
@@ -51,6 +51,8 @@ import { type ValueMap, type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3
51
51
  import type { Hex } from "./base.js";
52
52
  export type { Hex };
53
53
  export type { ValueMap, ValueType };
54
+ /** Abstract interface for a wallet that can sign typed data. */
55
+ export type AbstractWallet = AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
54
56
  /** Abstract interface for a [viem wallet](https://viem.sh/docs/clients/wallet). */
55
57
  export interface AbstractViemWalletClient {
56
58
  signTypedData(params: {
@@ -98,7 +100,7 @@ export interface AbstractEthersV5Signer {
98
100
  }[];
99
101
  }, value: Record<string, unknown>): Promise<string>;
100
102
  }
101
- /** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/reference/sdk/react-auth/functions/useSignTypedData#returns)). */
103
+ /** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/wallets/using-wallets/ethereum/sign-typed-data)). */
102
104
  export interface AbstractExtendedViemWalletClient {
103
105
  signTypedData(params: {
104
106
  domain: {
@@ -146,7 +148,7 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
146
148
  * import { signL1Action } from "@nktkas/hyperliquid/signing";
147
149
  * import { privateKeyToAccount } from "viem/accounts";
148
150
  *
149
- * const wallet = privateKeyToAccount("0x..."); // Change to your private key
151
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
150
152
  *
151
153
  * const action = {
152
154
  * type: "cancel",
@@ -173,7 +175,7 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
173
175
  */
174
176
  export declare function signL1Action(args: {
175
177
  /** Wallet to sign the action. */
176
- wallet: AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
178
+ wallet: AbstractWallet;
177
179
  /** The action to be signed. */
178
180
  action: ValueType;
179
181
  /** Unique request identifier (recommended current timestamp in ms). */
@@ -200,7 +202,7 @@ export declare function signL1Action(args: {
200
202
  * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
201
203
  * import { privateKeyToAccount } from "viem/accounts";
202
204
  *
203
- * const wallet = privateKeyToAccount("0x..."); // Change to your private key
205
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
204
206
  *
205
207
  * const action = {
206
208
  * type: "approveAgent",
@@ -235,7 +237,7 @@ export declare function signL1Action(args: {
235
237
  */
236
238
  export declare function signUserSignedAction(args: {
237
239
  /** Wallet to sign the action. */
238
- wallet: AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
240
+ wallet: AbstractWallet;
239
241
  /** The action to be signed. */
240
242
  action: Record<string, unknown>;
241
243
  /** The types of the action. */
@@ -252,6 +254,74 @@ export declare function signUserSignedAction(args: {
252
254
  s: Hex;
253
255
  v: number;
254
256
  }>;
257
+ /**
258
+ * Sign a multi-signature action.
259
+ *
260
+ * Note: Signature generation depends on the order of the action keys.
261
+ * @param args - Arguments for signing the action.
262
+ * @returns The signature components r, s, and v.
263
+ * @example
264
+ * ```ts
265
+ * import { signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
266
+ * import { privateKeyToAccount } from "viem/accounts";
267
+ *
268
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
269
+ * const multiSigUser = "0x..."; // Multi-sig user address
270
+ *
271
+ * const nonce = Date.now();
272
+ * const action = { // Example action
273
+ * type: "scheduleCancel",
274
+ * time: Date.now() + 10000
275
+ * };
276
+ *
277
+ * // First, create signature from one of the authorized signers
278
+ * const signature = await signL1Action({
279
+ * wallet,
280
+ * action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
281
+ * nonce,
282
+ * isTestnet: true,
283
+ * });
284
+ *
285
+ * // Then use it in the multi-sig action
286
+ * const multiSigSignature = await signMultiSigAction({
287
+ * wallet,
288
+ * action: {
289
+ * type: "multiSig",
290
+ * signatureChainId: "0x66eee",
291
+ * signatures: [signature],
292
+ * payload: {
293
+ * multiSigUser,
294
+ * outerSigner: wallet.address,
295
+ * action,
296
+ * }
297
+ * },
298
+ * nonce,
299
+ * hyperliquidChain: "Testnet",
300
+ * signatureChainId: "0x66eee",
301
+ * });
302
+ * ```
303
+ * @unstable May not behave as expected and the interface may change in the future.
304
+ */
305
+ export declare function signMultiSigAction(args: {
306
+ /** Wallet to sign the action. */
307
+ wallet: AbstractWallet;
308
+ /** The action to be signed. */
309
+ action: ValueMap;
310
+ /** Unique request identifier (recommended current timestamp in ms). */
311
+ nonce: number;
312
+ /** Optional vault address used in the action. */
313
+ vaultAddress?: Hex;
314
+ /** Optional expiration time of the action in milliseconds since the epoch. */
315
+ expiresAfter?: number;
316
+ /** HyperLiquid network ("Mainnet" or "Testnet"). */
317
+ hyperliquidChain: "Mainnet" | "Testnet";
318
+ /** Chain ID used for signing. */
319
+ signatureChainId: Hex;
320
+ }): Promise<{
321
+ r: Hex;
322
+ s: Hex;
323
+ v: number;
324
+ }>;
255
325
  /** Checks if the given value is an abstract viem wallet. */
256
326
  export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
257
327
  /** Checks if the given value is an abstract ethers signer. */
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAGH,OAAO,EAA2B,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAGrH,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,EAA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,EAAE,MAAM,CAAA;CAAE,CAAC,CAYzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC3C,iCAAiC;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,+BAA+B;IAC/B,MAAM,EAAE,QAAQ,CAAC;IACjB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC;IACxC,iCAAiC;IACjC,gBAAgB,EAAE,GAAG,CAAC;CACzB,GAAG,OAAO,CAAC;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA+BzC;AAoGD,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"}
@@ -61,6 +61,7 @@
61
61
  exports.createL1ActionHash = createL1ActionHash;
62
62
  exports.signL1Action = signL1Action;
63
63
  exports.signUserSignedAction = signUserSignedAction;
64
+ exports.signMultiSigAction = signMultiSigAction;
64
65
  exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
65
66
  exports.isAbstractEthersSigner = isAbstractEthersSigner;
66
67
  exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
@@ -136,7 +137,7 @@
136
137
  * import { signL1Action } from "@nktkas/hyperliquid/signing";
137
138
  * import { privateKeyToAccount } from "viem/accounts";
138
139
  *
139
- * const wallet = privateKeyToAccount("0x..."); // Change to your private key
140
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
140
141
  *
141
142
  * const action = {
142
143
  * type: "cancel",
@@ -194,7 +195,7 @@
194
195
  * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
195
196
  * import { privateKeyToAccount } from "viem/accounts";
196
197
  *
197
- * const wallet = privateKeyToAccount("0x..."); // Change to your private key
198
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
198
199
  *
199
200
  * const action = {
200
201
  * type: "approveAgent",
@@ -238,6 +239,76 @@
238
239
  const signature = await abstractSignTypedData({ wallet, domain, types, message: action });
239
240
  return splitSignature(signature);
240
241
  }
242
+ /**
243
+ * Sign a multi-signature action.
244
+ *
245
+ * Note: Signature generation depends on the order of the action keys.
246
+ * @param args - Arguments for signing the action.
247
+ * @returns The signature components r, s, and v.
248
+ * @example
249
+ * ```ts
250
+ * import { signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
251
+ * import { privateKeyToAccount } from "viem/accounts";
252
+ *
253
+ * const wallet = privateKeyToAccount("0x..."); // Your private key
254
+ * const multiSigUser = "0x..."; // Multi-sig user address
255
+ *
256
+ * const nonce = Date.now();
257
+ * const action = { // Example action
258
+ * type: "scheduleCancel",
259
+ * time: Date.now() + 10000
260
+ * };
261
+ *
262
+ * // First, create signature from one of the authorized signers
263
+ * const signature = await signL1Action({
264
+ * wallet,
265
+ * action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
266
+ * nonce,
267
+ * isTestnet: true,
268
+ * });
269
+ *
270
+ * // Then use it in the multi-sig action
271
+ * const multiSigSignature = await signMultiSigAction({
272
+ * wallet,
273
+ * action: {
274
+ * type: "multiSig",
275
+ * signatureChainId: "0x66eee",
276
+ * signatures: [signature],
277
+ * payload: {
278
+ * multiSigUser,
279
+ * outerSigner: wallet.address,
280
+ * action,
281
+ * }
282
+ * },
283
+ * nonce,
284
+ * hyperliquidChain: "Testnet",
285
+ * signatureChainId: "0x66eee",
286
+ * });
287
+ * ```
288
+ * @unstable May not behave as expected and the interface may change in the future.
289
+ */
290
+ async function signMultiSigAction(args) {
291
+ const { wallet, action, nonce, hyperliquidChain, signatureChainId, vaultAddress, expiresAfter, } = args;
292
+ const multiSigActionHash = createL1ActionHash(action, nonce, vaultAddress, expiresAfter);
293
+ const message = {
294
+ multiSigActionHash,
295
+ hyperliquidChain,
296
+ signatureChainId,
297
+ nonce,
298
+ };
299
+ return await signUserSignedAction({
300
+ wallet,
301
+ action: message,
302
+ types: {
303
+ "HyperliquidTransaction:SendMultiSig": [
304
+ { name: "hyperliquidChain", type: "string" },
305
+ { name: "multiSigActionHash", type: "bytes32" },
306
+ { name: "nonce", type: "uint64" },
307
+ ],
308
+ },
309
+ chainId: parseInt(signatureChainId, 16),
310
+ });
311
+ }
241
312
  /** Signs typed data with the provided wallet using EIP-712. */
242
313
  async function abstractSignTypedData(args) {
243
314
  const { wallet, domain, types, message } = args;