@nktkas/hyperliquid 0.13.2 → 0.15.0
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.
- package/CONTRIBUTING.md +4 -7
- package/README.md +297 -103
- package/esm/mod.d.ts +3 -12
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -2
- package/esm/src/{transports/base.d.ts → base.d.ts} +11 -14
- package/esm/src/base.d.ts.map +1 -0
- package/esm/src/base.js +14 -0
- package/esm/src/clients/event.d.ts +4 -4
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +2 -2
- package/esm/src/clients/public.d.ts +109 -6
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +106 -3
- package/esm/src/clients/wallet.d.ts +232 -29
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +859 -243
- package/esm/src/signing.d.ts +135 -0
- package/esm/src/signing.d.ts.map +1 -0
- package/esm/src/signing.js +188 -0
- package/esm/src/transports/http/http_transport.d.ts +2 -4
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +8 -13
- package/{script/src/transports/websocket/hyperliquid_event_target.d.ts → esm/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
- package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +91 -76
- package/esm/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +3 -7
- package/esm/src/transports/websocket/websocket_transport.d.ts +13 -16
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +49 -49
- package/esm/src/types/exchange/requests.d.ts +172 -20
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +32 -32
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +12 -12
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +36 -1
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +130 -105
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +154 -152
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +20 -20
- package/esm/src/types/info/delegations.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +55 -55
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +73 -10
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +1 -1
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +14 -0
- package/esm/src/types/mod.d.ts.map +1 -0
- package/esm/src/types/subscriptions/requests.d.ts +1 -1
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{script/src/types/subscriptions/common.d.ts → esm/src/types/subscriptions/responses.d.ts} +16 -4
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -0
- package/package.json +20 -4
- package/script/mod.d.ts +3 -12
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +3 -5
- package/script/src/{transports/base.d.ts → base.d.ts} +11 -14
- package/script/src/base.d.ts.map +1 -0
- package/script/src/{transports/base.js → base.js} +13 -12
- package/script/src/clients/event.d.ts +4 -4
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +2 -2
- package/script/src/clients/public.d.ts +109 -6
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +106 -3
- package/script/src/clients/wallet.d.ts +232 -29
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +860 -244
- package/script/src/signing.d.ts +135 -0
- package/script/src/signing.d.ts.map +1 -0
- package/script/src/signing.js +203 -0
- package/script/src/transports/http/http_transport.d.ts +2 -4
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +9 -14
- package/{esm/src/transports/websocket/hyperliquid_event_target.d.ts → script/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
- package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +94 -78
- package/script/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +4 -8
- package/script/src/transports/websocket/websocket_transport.d.ts +13 -16
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +55 -55
- package/script/src/types/exchange/requests.d.ts +172 -20
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +32 -32
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/explorer/requests.d.ts +12 -12
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/responses.d.ts +36 -1
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +130 -105
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +154 -152
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/delegations.d.ts +20 -20
- package/script/src/types/info/delegations.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +55 -55
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +73 -10
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/vaults.d.ts +1 -1
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +14 -0
- package/script/src/types/mod.d.ts.map +1 -0
- package/script/src/types/subscriptions/requests.d.ts +1 -1
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{esm/src/types/subscriptions/common.d.ts → script/src/types/subscriptions/responses.d.ts} +16 -4
- package/script/src/types/subscriptions/responses.d.ts.map +1 -0
- package/esm/src/transports/base.d.ts.map +0 -1
- package/esm/src/transports/base.js +0 -14
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/esm/src/types/common.d.ts +0 -3
- package/esm/src/types/common.d.ts.map +0 -1
- package/esm/src/types/exchange/common.d.ts +0 -36
- package/esm/src/types/exchange/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.d.ts +0 -37
- package/esm/src/types/explorer/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.js +0 -1
- package/esm/src/types/subscriptions/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.js +0 -1
- package/esm/src/utils/key_sort.d.ts +0 -21
- package/esm/src/utils/key_sort.d.ts.map +0 -1
- package/esm/src/utils/key_sort.js +0 -124
- package/esm/src/utils/signing.d.ts +0 -109
- package/esm/src/utils/signing.d.ts.map +0 -1
- package/esm/src/utils/signing.js +0 -164
- package/script/src/transports/base.d.ts.map +0 -1
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/script/src/types/common.d.ts +0 -3
- package/script/src/types/common.d.ts.map +0 -1
- package/script/src/types/exchange/common.d.ts +0 -36
- package/script/src/types/exchange/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.d.ts +0 -37
- package/script/src/types/explorer/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.js +0 -12
- package/script/src/types/subscriptions/common.d.ts.map +0 -1
- package/script/src/types/subscriptions/common.js +0 -12
- package/script/src/utils/key_sort.d.ts +0 -21
- package/script/src/utils/key_sort.d.ts.map +0 -1
- package/script/src/utils/key_sort.js +0 -137
- package/script/src/utils/signing.d.ts +0 -109
- package/script/src/utils/signing.d.ts.map +0 -1
- package/script/src/utils/signing.js +0 -182
- /package/esm/src/types/{common.js → mod.js} +0 -0
- /package/esm/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
- /package/script/src/types/{common.js → mod.js} +0 -0
- /package/script/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { type ValueType } from "../../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
2
|
-
type Hex = `0x${string}`;
|
|
3
|
-
/** Abstract interface for a [ethers.js](https://docs.ethers.org/v6/api/providers/#Signer) signer. */
|
|
4
|
-
export interface AbstractEthersSigner {
|
|
5
|
-
signTypedData(domain: {
|
|
6
|
-
name: string;
|
|
7
|
-
version: string;
|
|
8
|
-
chainId: number;
|
|
9
|
-
verifyingContract: string;
|
|
10
|
-
}, types: {
|
|
11
|
-
[key: string]: {
|
|
12
|
-
name: string;
|
|
13
|
-
type: string;
|
|
14
|
-
}[];
|
|
15
|
-
}, value: Record<string, unknown>): Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
/** Abstract interface for a [ethers.js v5](https://docs.ethers.org/v5/api/providers/#Signer) signer. */
|
|
18
|
-
export interface AbstractEthersV5Signer {
|
|
19
|
-
_signTypedData(domain: {
|
|
20
|
-
name: string;
|
|
21
|
-
version: string;
|
|
22
|
-
chainId: number;
|
|
23
|
-
verifyingContract: string;
|
|
24
|
-
}, types: {
|
|
25
|
-
[key: string]: {
|
|
26
|
-
name: string;
|
|
27
|
-
type: string;
|
|
28
|
-
}[];
|
|
29
|
-
}, value: Record<string, unknown>): Promise<string>;
|
|
30
|
-
}
|
|
31
|
-
/** Abstract interface for a [viem](https://viem.sh/docs/clients/wallet) wallet client. */
|
|
32
|
-
export interface AbstractViemWalletClient {
|
|
33
|
-
signTypedData(params: {
|
|
34
|
-
domain: {
|
|
35
|
-
name: string;
|
|
36
|
-
version: string;
|
|
37
|
-
chainId: number;
|
|
38
|
-
verifyingContract: Hex;
|
|
39
|
-
};
|
|
40
|
-
types: {
|
|
41
|
-
[key: string]: {
|
|
42
|
-
name: string;
|
|
43
|
-
type: string;
|
|
44
|
-
}[];
|
|
45
|
-
};
|
|
46
|
-
primaryType: string;
|
|
47
|
-
message: Record<string, unknown>;
|
|
48
|
-
}): Promise<Hex>;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a hash of the action.
|
|
52
|
-
* @param action - The action to hash.
|
|
53
|
-
* @param nonce - The nonce of the action.
|
|
54
|
-
* @param vaultAddress - Optional vault address.
|
|
55
|
-
* @returns The hash of the action.
|
|
56
|
-
*/
|
|
57
|
-
export declare function createActionHash(action: ValueType, nonce: number, vaultAddress?: Hex): Hex;
|
|
58
|
-
/**
|
|
59
|
-
* Sign an L1 action.
|
|
60
|
-
* @param wallet - The wallet to sign with.
|
|
61
|
-
* @param isTestnet - A boolean indicating if the action is for the testnet.
|
|
62
|
-
* @param action - The action to sign.
|
|
63
|
-
* @param nonce - The nonce of the action.
|
|
64
|
-
* @param vaultAddress - Optional vault address.
|
|
65
|
-
* @returns The signature.
|
|
66
|
-
*/
|
|
67
|
-
export declare function signL1Action(wallet: AbstractEthersSigner | AbstractEthersV5Signer | AbstractViemWalletClient, isTestnet: boolean, action: ValueType, nonce: number, vaultAddress?: Hex): Promise<{
|
|
68
|
-
r: Hex;
|
|
69
|
-
s: Hex;
|
|
70
|
-
v: number;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* Sign a user-signed action.
|
|
74
|
-
* @param wallet - The wallet to sign with.
|
|
75
|
-
* @param action - The action to sign.
|
|
76
|
-
* @param types - The types of the action.
|
|
77
|
-
* @param chainId - The chain ID of the action.
|
|
78
|
-
* @returns The signature.
|
|
79
|
-
*/
|
|
80
|
-
export declare function signUserSignedAction(wallet: AbstractEthersSigner | AbstractEthersV5Signer | AbstractViemWalletClient, action: Record<string, unknown>, types: {
|
|
81
|
-
[key: string]: {
|
|
82
|
-
name: string;
|
|
83
|
-
type: string;
|
|
84
|
-
}[];
|
|
85
|
-
}, chainId: number): Promise<{
|
|
86
|
-
r: Hex;
|
|
87
|
-
s: Hex;
|
|
88
|
-
v: number;
|
|
89
|
-
}>;
|
|
90
|
-
/**
|
|
91
|
-
* Checks if the given client is an abstract signer (ethers.js).
|
|
92
|
-
* @param client - The client to check.
|
|
93
|
-
* @returns A boolean indicating if the client is an abstract signer.
|
|
94
|
-
*/
|
|
95
|
-
export declare function isAbstractEthersSigner(client: unknown): client is AbstractEthersSigner;
|
|
96
|
-
/**
|
|
97
|
-
* Checks if the given client is an abstract signer (ethers.js v5).
|
|
98
|
-
* @param client - The client to check.
|
|
99
|
-
* @returns A boolean indicating if the client is an abstract signer.
|
|
100
|
-
*/
|
|
101
|
-
export declare function isAbstractEthersV5Signer(client: unknown): client is AbstractEthersV5Signer;
|
|
102
|
-
/**
|
|
103
|
-
* Checks if the given client is an abstract wallet client (viem).
|
|
104
|
-
* @param client - The client to check.
|
|
105
|
-
* @returns A boolean indicating if the client is an abstract wallet client.
|
|
106
|
-
*/
|
|
107
|
-
export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
|
|
108
|
-
export {};
|
|
109
|
-
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/src/utils/signing.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../../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);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createActionHash = createActionHash;
|
|
13
|
-
exports.signL1Action = signL1Action;
|
|
14
|
-
exports.signUserSignedAction = signUserSignedAction;
|
|
15
|
-
exports.isAbstractEthersSigner = isAbstractEthersSigner;
|
|
16
|
-
exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
|
|
17
|
-
exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
|
|
18
|
-
const sha3_js_1 = require("../../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js");
|
|
19
|
-
const encode_js_1 = require("../../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
|
|
20
|
-
const hex_js_1 = require("../../deps/jsr.io/@std/encoding/1.0.7/hex.js");
|
|
21
|
-
/**
|
|
22
|
-
* Create a hash of the action.
|
|
23
|
-
* @param action - The action to hash.
|
|
24
|
-
* @param nonce - The nonce of the action.
|
|
25
|
-
* @param vaultAddress - Optional vault address.
|
|
26
|
-
* @returns The hash of the action.
|
|
27
|
-
*/
|
|
28
|
-
function createActionHash(action, nonce, vaultAddress) {
|
|
29
|
-
const normalizedAction = normalizeIntegersForMsgPack(action);
|
|
30
|
-
const msgPackBytes = (0, encode_js_1.encode)(normalizedAction);
|
|
31
|
-
const additionalBytesLength = vaultAddress ? 29 : 9;
|
|
32
|
-
const data = new Uint8Array(msgPackBytes.length + additionalBytesLength);
|
|
33
|
-
data.set(msgPackBytes);
|
|
34
|
-
const view = new DataView(data.buffer);
|
|
35
|
-
view.setBigUint64(msgPackBytes.length, BigInt(nonce));
|
|
36
|
-
if (vaultAddress) {
|
|
37
|
-
view.setUint8(msgPackBytes.length + 8, 1);
|
|
38
|
-
const normalizedVaultAddress = vaultAddress.startsWith("0x") ? vaultAddress.slice(2) : vaultAddress;
|
|
39
|
-
data.set((0, hex_js_1.decodeHex)(normalizedVaultAddress), msgPackBytes.length + 9);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
view.setUint8(msgPackBytes.length + 8, 0);
|
|
43
|
-
}
|
|
44
|
-
return `0x${(0, hex_js_1.encodeHex)((0, sha3_js_1.keccak_256)(data))}`;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}.
|
|
48
|
-
* @returns A new object with integers normalized.
|
|
49
|
-
*/
|
|
50
|
-
function normalizeIntegersForMsgPack(obj) {
|
|
51
|
-
const THIRTY_ONE_BITS = 2147483648;
|
|
52
|
-
const THIRTY_TWO_BITS = 4294967296;
|
|
53
|
-
if (typeof obj === "number" && Number.isInteger(obj) &&
|
|
54
|
-
obj <= Number.MAX_SAFE_INTEGER && obj >= Number.MIN_SAFE_INTEGER &&
|
|
55
|
-
(obj >= THIRTY_TWO_BITS || obj < -THIRTY_ONE_BITS)) {
|
|
56
|
-
return BigInt(obj);
|
|
57
|
-
}
|
|
58
|
-
if (Array.isArray(obj)) {
|
|
59
|
-
return obj.map(normalizeIntegersForMsgPack);
|
|
60
|
-
}
|
|
61
|
-
if (obj && typeof obj === "object" && obj !== null) {
|
|
62
|
-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, normalizeIntegersForMsgPack(value)]));
|
|
63
|
-
}
|
|
64
|
-
return obj;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Sign an L1 action.
|
|
68
|
-
* @param wallet - The wallet to sign with.
|
|
69
|
-
* @param isTestnet - A boolean indicating if the action is for the testnet.
|
|
70
|
-
* @param action - The action to sign.
|
|
71
|
-
* @param nonce - The nonce of the action.
|
|
72
|
-
* @param vaultAddress - Optional vault address.
|
|
73
|
-
* @returns The signature.
|
|
74
|
-
*/
|
|
75
|
-
async function signL1Action(wallet, isTestnet, action, nonce, vaultAddress) {
|
|
76
|
-
const domain = {
|
|
77
|
-
name: "Exchange",
|
|
78
|
-
version: "1",
|
|
79
|
-
chainId: 1337,
|
|
80
|
-
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
81
|
-
};
|
|
82
|
-
const types = {
|
|
83
|
-
Agent: [
|
|
84
|
-
{ name: "source", type: "string" },
|
|
85
|
-
{ name: "connectionId", type: "bytes32" },
|
|
86
|
-
],
|
|
87
|
-
};
|
|
88
|
-
const actionHash = createActionHash(action, nonce, vaultAddress);
|
|
89
|
-
const message = {
|
|
90
|
-
source: isTestnet ? "b" : "a",
|
|
91
|
-
connectionId: actionHash,
|
|
92
|
-
};
|
|
93
|
-
let signature;
|
|
94
|
-
if (isAbstractViemWalletClient(wallet)) {
|
|
95
|
-
signature = await wallet.signTypedData({ domain, types, primaryType: "Agent", message });
|
|
96
|
-
}
|
|
97
|
-
else if (isAbstractEthersSigner(wallet)) {
|
|
98
|
-
signature = await wallet.signTypedData(domain, types, message);
|
|
99
|
-
}
|
|
100
|
-
else if (isAbstractEthersV5Signer(wallet)) {
|
|
101
|
-
signature = await wallet._signTypedData(domain, types, message);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
|
|
105
|
-
}
|
|
106
|
-
return parseSignature(signature);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Sign a user-signed action.
|
|
110
|
-
* @param wallet - The wallet to sign with.
|
|
111
|
-
* @param action - The action to sign.
|
|
112
|
-
* @param types - The types of the action.
|
|
113
|
-
* @param chainId - The chain ID of the action.
|
|
114
|
-
* @returns The signature.
|
|
115
|
-
*/
|
|
116
|
-
async function signUserSignedAction(wallet, action, types, chainId) {
|
|
117
|
-
const domain = {
|
|
118
|
-
name: "HyperliquidSignTransaction",
|
|
119
|
-
version: "1",
|
|
120
|
-
chainId,
|
|
121
|
-
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
122
|
-
};
|
|
123
|
-
let signature;
|
|
124
|
-
if (isAbstractViemWalletClient(wallet)) {
|
|
125
|
-
const primaryType = Object.keys(types)[0];
|
|
126
|
-
signature = await wallet.signTypedData({ domain, types, primaryType, message: action });
|
|
127
|
-
}
|
|
128
|
-
else if (isAbstractEthersSigner(wallet)) {
|
|
129
|
-
signature = await wallet.signTypedData(domain, types, action);
|
|
130
|
-
}
|
|
131
|
-
else if (isAbstractEthersV5Signer(wallet)) {
|
|
132
|
-
signature = await wallet._signTypedData(domain, types, action);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
throw new Error("Unsupported wallet for signing typed data", { cause: wallet });
|
|
136
|
-
}
|
|
137
|
-
return parseSignature(signature);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Parses a signature hexadecimal string into its components.
|
|
141
|
-
*/
|
|
142
|
-
function parseSignature(signature) {
|
|
143
|
-
const normalizedSignature = signature.startsWith("0x") ? signature.slice(2) : signature;
|
|
144
|
-
if (normalizedSignature.length !== 130) {
|
|
145
|
-
throw new Error(`Invalid signature length. Expected 130 characters. Received ${normalizedSignature.length}.`);
|
|
146
|
-
}
|
|
147
|
-
const r = `0x${normalizedSignature.slice(0, 64)}`;
|
|
148
|
-
const s = `0x${normalizedSignature.slice(64, 128)}`;
|
|
149
|
-
const v = parseInt(normalizedSignature.slice(128, 130), 16);
|
|
150
|
-
return { r, s, v };
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Checks if the given client is an abstract signer (ethers.js).
|
|
154
|
-
* @param client - The client to check.
|
|
155
|
-
* @returns A boolean indicating if the client is an abstract signer.
|
|
156
|
-
*/
|
|
157
|
-
function isAbstractEthersSigner(client) {
|
|
158
|
-
return typeof client === "object" && client !== null &&
|
|
159
|
-
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
160
|
-
client.signTypedData.length === 3;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Checks if the given client is an abstract signer (ethers.js v5).
|
|
164
|
-
* @param client - The client to check.
|
|
165
|
-
* @returns A boolean indicating if the client is an abstract signer.
|
|
166
|
-
*/
|
|
167
|
-
function isAbstractEthersV5Signer(client) {
|
|
168
|
-
return typeof client === "object" && client !== null &&
|
|
169
|
-
"_signTypedData" in client && typeof client._signTypedData === "function" &&
|
|
170
|
-
client._signTypedData.length === 3;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Checks if the given client is an abstract wallet client (viem).
|
|
174
|
-
* @param client - The client to check.
|
|
175
|
-
* @returns A boolean indicating if the client is an abstract wallet client.
|
|
176
|
-
*/
|
|
177
|
-
function isAbstractViemWalletClient(client) {
|
|
178
|
-
return typeof client === "object" && client !== null &&
|
|
179
|
-
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
180
|
-
client.signTypedData.length === 1;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|