@nktkas/hyperliquid 0.17.3 → 0.18.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.
Files changed (126) hide show
  1. package/README.md +49 -36
  2. package/{script/deps/jsr.io/@noble/hashes/1.7.1 → esm/deps/jsr.io/@noble/hashes/1.8.0}/src/_u64.d.ts +1 -1
  3. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/_u64.js +5 -4
  5. package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.d.ts.map +1 -1
  6. package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/sha3.d.ts +6 -5
  7. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/sha3.js +63 -52
  9. package/{script/deps/jsr.io/@noble/hashes/1.7.1 → esm/deps/jsr.io/@noble/hashes/1.8.0}/src/utils.d.ts +60 -19
  10. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/utils.js +94 -25
  12. package/esm/deps/jsr.io/@std/async/1.0.12/delay.d.ts +43 -0
  13. package/esm/deps/jsr.io/@std/async/1.0.12/delay.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/async/1.0.12/delay.js +63 -0
  15. package/{script/deps/jsr.io/@std/encoding/1.0.9 → esm/deps/jsr.io/@std/encoding/1.0.10}/_common16.d.ts +1 -1
  16. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.js +1 -1
  18. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
  21. package/esm/src/clients/wallet.d.ts +22 -12
  22. package/esm/src/clients/wallet.d.ts.map +1 -1
  23. package/esm/src/clients/wallet.js +85 -62
  24. package/esm/src/signing.d.ts +4 -1
  25. package/esm/src/signing.d.ts.map +1 -1
  26. package/esm/src/signing.js +47 -24
  27. package/esm/src/transports/http/http_transport.d.ts +18 -8
  28. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  29. package/esm/src/transports/http/http_transport.js +17 -18
  30. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +3 -12
  31. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  32. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +20 -42
  33. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  34. package/esm/src/transports/websocket/_reconnecting_websocket.js +127 -193
  35. package/esm/src/transports/websocket/websocket_transport.d.ts +6 -0
  36. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  37. package/esm/src/transports/websocket/websocket_transport.js +23 -21
  38. package/esm/src/types/exchange/requests.d.ts +26 -2
  39. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  40. package/esm/src/types/exchange/responses.d.ts +6 -6
  41. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  42. package/esm/src/types/info/accounts.d.ts +14 -0
  43. package/esm/src/types/info/accounts.d.ts.map +1 -1
  44. package/esm/src/types/info/assets.d.ts +20 -0
  45. package/esm/src/types/info/assets.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/{esm/deps/jsr.io/@noble/hashes/1.7.1 → script/deps/jsr.io/@noble/hashes/1.8.0}/src/_u64.d.ts +1 -1
  48. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +1 -0
  49. package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/_u64.js +6 -5
  50. package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.d.ts.map +1 -1
  51. package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/sha3.d.ts +6 -5
  52. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +1 -0
  53. package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/sha3.js +69 -58
  54. package/{esm/deps/jsr.io/@noble/hashes/1.7.1 → script/deps/jsr.io/@noble/hashes/1.8.0}/src/utils.d.ts +60 -19
  55. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +1 -0
  56. package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/utils.js +111 -34
  57. package/script/deps/jsr.io/@std/async/1.0.12/delay.d.ts +43 -0
  58. package/script/deps/jsr.io/@std/async/1.0.12/delay.d.ts.map +1 -0
  59. package/script/deps/jsr.io/@std/async/1.0.12/delay.js +76 -0
  60. package/{esm/deps/jsr.io/@std/encoding/1.0.9 → script/deps/jsr.io/@std/encoding/1.0.10}/_common16.d.ts +1 -1
  61. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
  62. package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.js +1 -1
  63. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +1 -0
  64. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +1 -0
  65. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
  66. package/script/src/clients/wallet.d.ts +22 -12
  67. package/script/src/clients/wallet.d.ts.map +1 -1
  68. package/script/src/clients/wallet.js +85 -62
  69. package/script/src/signing.d.ts +4 -1
  70. package/script/src/signing.d.ts.map +1 -1
  71. package/script/src/signing.js +47 -24
  72. package/script/src/transports/http/http_transport.d.ts +18 -8
  73. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  74. package/script/src/transports/http/http_transport.js +17 -18
  75. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +3 -12
  76. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  77. package/script/src/transports/websocket/_reconnecting_websocket.d.ts +20 -42
  78. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  79. package/script/src/transports/websocket/_reconnecting_websocket.js +129 -195
  80. package/script/src/transports/websocket/websocket_transport.d.ts +6 -0
  81. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  82. package/script/src/transports/websocket/websocket_transport.js +23 -21
  83. package/script/src/types/exchange/requests.d.ts +26 -2
  84. package/script/src/types/exchange/requests.d.ts.map +1 -1
  85. package/script/src/types/exchange/responses.d.ts +6 -6
  86. package/script/src/types/exchange/responses.d.ts.map +1 -1
  87. package/script/src/types/info/accounts.d.ts +14 -0
  88. package/script/src/types/info/accounts.d.ts.map +1 -1
  89. package/script/src/types/info/assets.d.ts +20 -0
  90. package/script/src/types/info/assets.d.ts.map +1 -1
  91. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +0 -23
  92. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +0 -1
  93. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +0 -43
  94. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +0 -1
  95. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +0 -1
  96. package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +0 -1
  97. package/esm/deps/jsr.io/@std/encoding/1.0.9/_common16.d.ts.map +0 -1
  98. package/esm/deps/jsr.io/@std/encoding/1.0.9/_common_detach.d.ts.map +0 -1
  99. package/esm/deps/jsr.io/@std/encoding/1.0.9/_types.d.ts.map +0 -1
  100. package/esm/deps/jsr.io/@std/encoding/1.0.9/hex.d.ts.map +0 -1
  101. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +0 -23
  102. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +0 -1
  103. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +0 -59
  104. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +0 -1
  105. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +0 -1
  106. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +0 -1
  107. package/script/deps/jsr.io/@std/encoding/1.0.9/_common16.d.ts.map +0 -1
  108. package/script/deps/jsr.io/@std/encoding/1.0.9/_common_detach.d.ts.map +0 -1
  109. package/script/deps/jsr.io/@std/encoding/1.0.9/_types.d.ts.map +0 -1
  110. package/script/deps/jsr.io/@std/encoding/1.0.9/hex.d.ts.map +0 -1
  111. /package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.d.ts +0 -0
  112. /package/esm/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.js +0 -0
  113. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.d.ts +0 -0
  114. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.js +0 -0
  115. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.d.ts +0 -0
  116. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.js +0 -0
  117. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.d.ts +0 -0
  118. /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.js +0 -0
  119. /package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.d.ts +0 -0
  120. /package/script/deps/jsr.io/@noble/hashes/{1.7.1 → 1.8.0}/src/crypto.js +0 -0
  121. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.d.ts +0 -0
  122. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.js +0 -0
  123. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.d.ts +0 -0
  124. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.js +0 -0
  125. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.d.ts +0 -0
  126. /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.js +0 -0
@@ -3,10 +3,27 @@
3
3
  * @module
4
4
  */
5
5
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
6
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
6
7
  export declare function isBytes(a: unknown): a is Uint8Array;
8
+ /** Asserts something is positive integer. */
9
+ export declare function anumber(n: number): void;
10
+ /** Asserts something is Uint8Array. */
11
+ export declare function abytes(b: Uint8Array | undefined, ...lengths: number[]): void;
12
+ /** Asserts something is hash */
13
+ export declare function ahash(h: IHash): void;
14
+ /** Asserts a hash instance has not been destroyed / finished */
15
+ export declare function aexists(instance: any, checkFinished?: boolean): void;
16
+ /** Asserts output is properly-sized byte array */
17
+ export declare function aoutput(out: any, instance: any): void;
18
+ /** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */
7
19
  export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
20
+ /** Cast u8 / u16 / u32 to u8. */
8
21
  export declare function u8(arr: TypedArray): Uint8Array;
22
+ /** Cast u8 / u16 / u32 to u32. */
9
23
  export declare function u32(arr: TypedArray): Uint32Array;
24
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
25
+ export declare function clean(...arrays: TypedArray[]): void;
26
+ /** Create DataView of an array for easy byte-level manipulation. */
10
27
  export declare function createView(arr: TypedArray): DataView;
11
28
  /** The rotate right (circular right shift) operation for uint32 */
12
29
  export declare function rotr(word: number, shift: number): number;
@@ -14,18 +31,22 @@ export declare function rotr(word: number, shift: number): number;
14
31
  export declare function rotl(word: number, shift: number): number;
15
32
  /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
16
33
  export declare const isLE: boolean;
34
+ /** The byte swap operation for uint32 */
17
35
  export declare function byteSwap(word: number): number;
18
36
  /** Conditionally byte swap if on a big-endian platform */
19
- export declare const byteSwapIfBE: (n: number) => number;
37
+ export declare const swap8IfBE: (n: number) => number;
38
+ /** @deprecated */
39
+ export declare const byteSwapIfBE: typeof swap8IfBE;
20
40
  /** In place byte swap for Uint32Array */
21
- export declare function byteSwap32(arr: Uint32Array): void;
41
+ export declare function byteSwap32(arr: Uint32Array): Uint32Array;
42
+ export declare const swap32IfBE: (u: Uint32Array) => Uint32Array;
22
43
  /**
23
- * Convert byte array to hex string.
44
+ * Convert byte array to hex string. Uses built-in function, when available.
24
45
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
25
46
  */
26
47
  export declare function bytesToHex(bytes: Uint8Array): string;
27
48
  /**
28
- * Convert hex string to byte array.
49
+ * Convert hex string to byte array. Uses built-in function, when available.
29
50
  * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
30
51
  */
31
52
  export declare function hexToBytes(hex: string): Uint8Array;
@@ -38,22 +59,41 @@ export declare const nextTick: () => Promise<void>;
38
59
  /** Returns control to thread each 'tick' ms to avoid blocking. */
39
60
  export declare function asyncLoop(iters: number, tick: number, cb: (i: number) => void): Promise<void>;
40
61
  /**
41
- * Convert JS string to byte array.
42
- * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
62
+ * Converts string to bytes using UTF8 encoding.
63
+ * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
43
64
  */
44
65
  export declare function utf8ToBytes(str: string): Uint8Array;
66
+ /**
67
+ * Converts bytes to string using UTF8 encoding.
68
+ * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
69
+ */
70
+ export declare function bytesToUtf8(bytes: Uint8Array): string;
45
71
  /** Accepted input of hash functions. Strings are converted to byte arrays. */
46
- export type Input = Uint8Array | string;
72
+ export type Input = string | Uint8Array;
47
73
  /**
48
74
  * Normalizes (non-hex) string or Uint8Array to Uint8Array.
49
75
  * Warning: when Uint8Array is passed, it would NOT get copied.
50
76
  * Keep in mind for future mutable operations.
51
77
  */
52
78
  export declare function toBytes(data: Input): Uint8Array;
79
+ /** KDFs can accept string or Uint8Array for user convenience. */
80
+ export type KDFInput = string | Uint8Array;
53
81
  /**
54
- * Copies several Uint8Arrays into one.
82
+ * Helper for KDFs: consumes uint8array or string.
83
+ * When string is passed, does utf8 decoding, using TextDecoder.
55
84
  */
85
+ export declare function kdfInputToBytes(data: KDFInput): Uint8Array;
86
+ /** Copies several Uint8Arrays into one. */
56
87
  export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
88
+ type EmptyObj = {};
89
+ export declare function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(defaults: T1, opts?: T2): T1 & T2;
90
+ /** Hash interface. */
91
+ export type IHash = {
92
+ (data: Uint8Array): Uint8Array;
93
+ blockLen: number;
94
+ outputLen: number;
95
+ create: any;
96
+ };
57
97
  /** For runtime check if class implements interface */
58
98
  export declare abstract class Hash<T extends Hash<T>> {
59
99
  abstract blockLen: number;
@@ -75,7 +115,7 @@ export declare abstract class Hash<T extends Hash<T>> {
75
115
  * There are no guarantees for clean-up because it's impossible in JS.
76
116
  */
77
117
  abstract _cloneInto(to?: T): T;
78
- clone(): T;
118
+ abstract clone(): T;
79
119
  }
80
120
  /**
81
121
  * XOF: streaming API to read digest in chunks.
@@ -87,33 +127,34 @@ export type HashXOF<T extends Hash<T>> = Hash<T> & {
87
127
  xof(bytes: number): Uint8Array;
88
128
  xofInto(buf: Uint8Array): Uint8Array;
89
129
  };
90
- type EmptyObj = {};
91
- export declare function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(defaults: T1, opts?: T2): T1 & T2;
92
130
  /** Hash function */
93
- export type CHash = ReturnType<typeof wrapConstructor>;
131
+ export type CHash = ReturnType<typeof createHasher>;
94
132
  /** Hash function with output */
95
- export type CHashO = ReturnType<typeof wrapConstructorWithOpts>;
133
+ export type CHashO = ReturnType<typeof createOptHasher>;
96
134
  /** XOF with output */
97
- export type CHashXO = ReturnType<typeof wrapXOFConstructorWithOpts>;
135
+ export type CHashXO = ReturnType<typeof createXOFer>;
98
136
  /** Wraps hash function, creating an interface on top of it */
99
- export declare function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>): {
137
+ export declare function createHasher<T extends Hash<T>>(hashCons: () => Hash<T>): {
100
138
  (msg: Input): Uint8Array;
101
139
  outputLen: number;
102
140
  blockLen: number;
103
141
  create(): Hash<T>;
104
142
  };
105
- export declare function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(hashCons: (opts?: T) => Hash<H>): {
143
+ export declare function createOptHasher<H extends Hash<H>, T extends Object>(hashCons: (opts?: T) => Hash<H>): {
106
144
  (msg: Input, opts?: T): Uint8Array;
107
145
  outputLen: number;
108
146
  blockLen: number;
109
- create(opts: T): Hash<H>;
147
+ create(opts?: T): Hash<H>;
110
148
  };
111
- export declare function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(hashCons: (opts?: T) => HashXOF<H>): {
149
+ export declare function createXOFer<H extends HashXOF<H>, T extends Object>(hashCons: (opts?: T) => HashXOF<H>): {
112
150
  (msg: Input, opts?: T): Uint8Array;
113
151
  outputLen: number;
114
152
  blockLen: number;
115
- create(opts: T): HashXOF<H>;
153
+ create(opts?: T): HashXOF<H>;
116
154
  };
155
+ export declare const wrapConstructor: typeof createHasher;
156
+ export declare const wrapConstructorWithOpts: typeof createOptHasher;
157
+ export declare const wrapXOFConstructorWithOpts: typeof createXOFer;
117
158
  /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
118
159
  export declare function randomBytes(bytesLength?: number): Uint8Array;
119
160
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.8.0/src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AAUtE,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAEnD;AAED,6CAA6C;AAC7C,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAEvC;AAED,uCAAuC;AACvC,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAI5E;AAED,gCAAgC;AAChC,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAKpC;AAED,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,UAAO,GAAG,IAAI,CAGjE;AAED,kDAAkD;AAClD,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI,CAMrD;AAED,uEAAuE;AAEvE,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,iBAAiB,GAAG,UAAU,GACjE,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;AAEtD,iCAAiC;AACjC,wBAAgB,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAE9C;AAED,kCAAkC;AAClC,wBAAgB,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,CAEhD;AAED,gEAAgE;AAChE,wBAAgB,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAInD;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,QAAQ,CAEpD;AAED,mEAAmE;AACnE,wBAAgB,IAA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E,CAAC,SAAS,MAAM,EAChE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACjC;IACD,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9B,CAOA;AACD,eAAO,MAAM,eAAe,EAAE,OAAO,YAA2B,CAAC;AACjE,eAAO,MAAM,uBAAuB,EAAE,OAAO,eAAiC,CAAC;AAC/E,eAAO,MAAM,0BAA0B,EAAE,OAAO,WAAyB,CAAC;AAE1E,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,WAAW,SAAK,GAAG,UAAU,CASxD"}
@@ -10,20 +10,59 @@
10
10
  // Makes the utils un-importable in browsers without a bundler.
11
11
  // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
12
12
  import { crypto } from './crypto.js';
13
- import { abytes } from './_assert.js';
14
- // export { isBytes } from './_assert.js';
15
- // We can't reuse isBytes from _assert, because somehow this causes huge perf issues
13
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
16
14
  export function isBytes(a) {
17
15
  return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
18
16
  }
19
- // Cast array to different type
17
+ /** Asserts something is positive integer. */
18
+ export function anumber(n) {
19
+ if (!Number.isSafeInteger(n) || n < 0)
20
+ throw new Error('positive integer expected, got ' + n);
21
+ }
22
+ /** Asserts something is Uint8Array. */
23
+ export function abytes(b, ...lengths) {
24
+ if (!isBytes(b))
25
+ throw new Error('Uint8Array expected');
26
+ if (lengths.length > 0 && !lengths.includes(b.length))
27
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
28
+ }
29
+ /** Asserts something is hash */
30
+ export function ahash(h) {
31
+ if (typeof h !== 'function' || typeof h.create !== 'function')
32
+ throw new Error('Hash should be wrapped by utils.createHasher');
33
+ anumber(h.outputLen);
34
+ anumber(h.blockLen);
35
+ }
36
+ /** Asserts a hash instance has not been destroyed / finished */
37
+ export function aexists(instance, checkFinished = true) {
38
+ if (instance.destroyed)
39
+ throw new Error('Hash instance has been destroyed');
40
+ if (checkFinished && instance.finished)
41
+ throw new Error('Hash#digest() has already been called');
42
+ }
43
+ /** Asserts output is properly-sized byte array */
44
+ export function aoutput(out, instance) {
45
+ abytes(out);
46
+ const min = instance.outputLen;
47
+ if (out.length < min) {
48
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
49
+ }
50
+ }
51
+ /** Cast u8 / u16 / u32 to u8. */
20
52
  export function u8(arr) {
21
53
  return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
22
54
  }
55
+ /** Cast u8 / u16 / u32 to u32. */
23
56
  export function u32(arr) {
24
57
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
25
58
  }
26
- // Cast array to view
59
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
60
+ export function clean(...arrays) {
61
+ for (let i = 0; i < arrays.length; i++) {
62
+ arrays[i].fill(0);
63
+ }
64
+ }
65
+ /** Create DataView of an array for easy byte-level manipulation. */
27
66
  export function createView(arr) {
28
67
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
29
68
  }
@@ -37,7 +76,7 @@ export function rotl(word, shift) {
37
76
  }
38
77
  /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
39
78
  export const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
40
- // The byte swap operation for uint32
79
+ /** The byte swap operation for uint32 */
41
80
  export function byteSwap(word) {
42
81
  return (((word << 24) & 0xff000000) |
43
82
  ((word << 8) & 0xff0000) |
@@ -45,23 +84,36 @@ export function byteSwap(word) {
45
84
  ((word >>> 24) & 0xff));
46
85
  }
47
86
  /** Conditionally byte swap if on a big-endian platform */
48
- export const byteSwapIfBE = isLE
87
+ export const swap8IfBE = isLE
49
88
  ? (n) => n
50
89
  : (n) => byteSwap(n);
90
+ /** @deprecated */
91
+ export const byteSwapIfBE = swap8IfBE;
51
92
  /** In place byte swap for Uint32Array */
52
93
  export function byteSwap32(arr) {
53
94
  for (let i = 0; i < arr.length; i++) {
54
95
  arr[i] = byteSwap(arr[i]);
55
96
  }
97
+ return arr;
56
98
  }
99
+ export const swap32IfBE = isLE
100
+ ? (u) => u
101
+ : byteSwap32;
102
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
103
+ const hasHexBuiltin = /* @__PURE__ */ (() =>
104
+ // @ts-ignore
105
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
57
106
  // Array where index 0xf0 (240) is mapped to string 'f0'
58
107
  const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
59
108
  /**
60
- * Convert byte array to hex string.
109
+ * Convert byte array to hex string. Uses built-in function, when available.
61
110
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
62
111
  */
63
112
  export function bytesToHex(bytes) {
64
113
  abytes(bytes);
114
+ // @ts-ignore
115
+ if (hasHexBuiltin)
116
+ return bytes.toHex();
65
117
  // pre-caching improves the speed 6x
66
118
  let hex = '';
67
119
  for (let i = 0; i < bytes.length; i++) {
@@ -81,12 +133,15 @@ function asciiToBase16(ch) {
81
133
  return;
82
134
  }
83
135
  /**
84
- * Convert hex string to byte array.
136
+ * Convert hex string to byte array. Uses built-in function, when available.
85
137
  * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
86
138
  */
87
139
  export function hexToBytes(hex) {
88
140
  if (typeof hex !== 'string')
89
141
  throw new Error('hex string expected, got ' + typeof hex);
142
+ // @ts-ignore
143
+ if (hasHexBuiltin)
144
+ return Uint8Array.fromHex(hex);
90
145
  const hl = hex.length;
91
146
  const al = hl / 2;
92
147
  if (hl % 2)
@@ -123,14 +178,21 @@ export async function asyncLoop(iters, tick, cb) {
123
178
  }
124
179
  }
125
180
  /**
126
- * Convert JS string to byte array.
127
- * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
181
+ * Converts string to bytes using UTF8 encoding.
182
+ * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
128
183
  */
129
184
  export function utf8ToBytes(str) {
130
185
  if (typeof str !== 'string')
131
- throw new Error('utf8ToBytes expected string, got ' + typeof str);
186
+ throw new Error('string expected');
132
187
  return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
133
188
  }
189
+ /**
190
+ * Converts bytes to string using UTF8 encoding.
191
+ * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
192
+ */
193
+ export function bytesToUtf8(bytes) {
194
+ return new TextDecoder().decode(bytes);
195
+ }
134
196
  /**
135
197
  * Normalizes (non-hex) string or Uint8Array to Uint8Array.
136
198
  * Warning: when Uint8Array is passed, it would NOT get copied.
@@ -143,8 +205,16 @@ export function toBytes(data) {
143
205
  return data;
144
206
  }
145
207
  /**
146
- * Copies several Uint8Arrays into one.
208
+ * Helper for KDFs: consumes uint8array or string.
209
+ * When string is passed, does utf8 decoding, using TextDecoder.
147
210
  */
211
+ export function kdfInputToBytes(data) {
212
+ if (typeof data === 'string')
213
+ data = utf8ToBytes(data);
214
+ abytes(data);
215
+ return data;
216
+ }
217
+ /** Copies several Uint8Arrays into one. */
148
218
  export function concatBytes(...arrays) {
149
219
  let sum = 0;
150
220
  for (let i = 0; i < arrays.length; i++) {
@@ -160,21 +230,17 @@ export function concatBytes(...arrays) {
160
230
  }
161
231
  return res;
162
232
  }
163
- /** For runtime check if class implements interface */
164
- export class Hash {
165
- // Safe version that clones internal state
166
- clone() {
167
- return this._cloneInto();
168
- }
169
- }
170
233
  export function checkOpts(defaults, opts) {
171
234
  if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')
172
- throw new Error('Options should be object or undefined');
235
+ throw new Error('options should be object or undefined');
173
236
  const merged = Object.assign(defaults, opts);
174
237
  return merged;
175
238
  }
239
+ /** For runtime check if class implements interface */
240
+ export class Hash {
241
+ }
176
242
  /** Wraps hash function, creating an interface on top of it */
177
- export function wrapConstructor(hashCons) {
243
+ export function createHasher(hashCons) {
178
244
  const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
179
245
  const tmp = hashCons();
180
246
  hashC.outputLen = tmp.outputLen;
@@ -182,7 +248,7 @@ export function wrapConstructor(hashCons) {
182
248
  hashC.create = () => hashCons();
183
249
  return hashC;
184
250
  }
185
- export function wrapConstructorWithOpts(hashCons) {
251
+ export function createOptHasher(hashCons) {
186
252
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
187
253
  const tmp = hashCons({});
188
254
  hashC.outputLen = tmp.outputLen;
@@ -190,7 +256,7 @@ export function wrapConstructorWithOpts(hashCons) {
190
256
  hashC.create = (opts) => hashCons(opts);
191
257
  return hashC;
192
258
  }
193
- export function wrapXOFConstructorWithOpts(hashCons) {
259
+ export function createXOFer(hashCons) {
194
260
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
195
261
  const tmp = hashCons({});
196
262
  hashC.outputLen = tmp.outputLen;
@@ -198,6 +264,9 @@ export function wrapXOFConstructorWithOpts(hashCons) {
198
264
  hashC.create = (opts) => hashCons(opts);
199
265
  return hashC;
200
266
  }
267
+ export const wrapConstructor = createHasher;
268
+ export const wrapConstructorWithOpts = createOptHasher;
269
+ export const wrapXOFConstructorWithOpts = createXOFer;
201
270
  /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
202
271
  export function randomBytes(bytesLength = 32) {
203
272
  if (crypto && typeof crypto.getRandomValues === 'function') {
@@ -205,7 +274,7 @@ export function randomBytes(bytesLength = 32) {
205
274
  }
206
275
  // Legacy Node.js compatibility
207
276
  if (crypto && typeof crypto.randomBytes === 'function') {
208
- return crypto.randomBytes(bytesLength);
277
+ return Uint8Array.from(crypto.randomBytes(bytesLength));
209
278
  }
210
279
  throw new Error('crypto.getRandomValues must be defined');
211
280
  }
@@ -0,0 +1,43 @@
1
+ /** Options for {@linkcode delay}. */
2
+ export interface DelayOptions {
3
+ /** Signal used to abort the delay. */
4
+ signal?: AbortSignal;
5
+ /** Indicates whether the process should continue to run as long as the timer exists.
6
+ *
7
+ * @default {true}
8
+ */
9
+ persistent?: boolean;
10
+ }
11
+ /**
12
+ * Resolve a {@linkcode Promise} after a given amount of milliseconds.
13
+ *
14
+ * @throws {DOMException} If the optional signal is aborted before the delay
15
+ * duration, and `signal.reason` is undefined.
16
+ * @param ms Duration in milliseconds for how long the delay should last.
17
+ * @param options Additional options.
18
+ *
19
+ * @example Basic usage
20
+ * ```ts no-assert
21
+ * import { delay } from "@std/async/delay";
22
+ *
23
+ * // ...
24
+ * const delayedPromise = delay(100);
25
+ * const result = await delayedPromise;
26
+ * // ...
27
+ * ```
28
+ *
29
+ * @example Disable persistence
30
+ *
31
+ * Setting `persistent` to `false` will allow the process to continue to run as
32
+ * long as the timer exists.
33
+ *
34
+ * ```ts no-assert ignore
35
+ * import { delay } from "@std/async/delay";
36
+ *
37
+ * // ...
38
+ * await delay(100, { persistent: false });
39
+ * // ...
40
+ * ```
41
+ */
42
+ export declare function delay(ms: number, options?: DelayOptions): Promise<void>;
43
+ //# sourceMappingURL=delay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.0.12/delay.ts"],"names":[],"mappings":"AAGA,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B3E"}
@@ -0,0 +1,63 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Resolve a {@linkcode Promise} after a given amount of milliseconds.
5
+ *
6
+ * @throws {DOMException} If the optional signal is aborted before the delay
7
+ * duration, and `signal.reason` is undefined.
8
+ * @param ms Duration in milliseconds for how long the delay should last.
9
+ * @param options Additional options.
10
+ *
11
+ * @example Basic usage
12
+ * ```ts no-assert
13
+ * import { delay } from "@std/async/delay";
14
+ *
15
+ * // ...
16
+ * const delayedPromise = delay(100);
17
+ * const result = await delayedPromise;
18
+ * // ...
19
+ * ```
20
+ *
21
+ * @example Disable persistence
22
+ *
23
+ * Setting `persistent` to `false` will allow the process to continue to run as
24
+ * long as the timer exists.
25
+ *
26
+ * ```ts no-assert ignore
27
+ * import { delay } from "@std/async/delay";
28
+ *
29
+ * // ...
30
+ * await delay(100, { persistent: false });
31
+ * // ...
32
+ * ```
33
+ */
34
+ export function delay(ms, options = {}) {
35
+ const { signal, persistent = true } = options;
36
+ if (signal?.aborted)
37
+ return Promise.reject(signal.reason);
38
+ return new Promise((resolve, reject) => {
39
+ const abort = () => {
40
+ clearTimeout(i);
41
+ reject(signal?.reason);
42
+ };
43
+ const done = () => {
44
+ signal?.removeEventListener("abort", abort);
45
+ resolve();
46
+ };
47
+ const i = setTimeout(done, ms);
48
+ signal?.addEventListener("abort", abort, { once: true });
49
+ if (persistent === false) {
50
+ try {
51
+ // @ts-ignore For browser compatibility
52
+ Deno.unrefTimer(i);
53
+ }
54
+ catch (error) {
55
+ if (!(error instanceof ReferenceError)) {
56
+ throw error;
57
+ }
58
+ // deno-lint-ignore no-console
59
+ console.error("`persistent` option is only available in Deno");
60
+ }
61
+ }
62
+ });
63
+ }
@@ -4,7 +4,7 @@ export declare const alphabet: Uint8Array;
4
4
  export declare const rAlphabet: Uint8Array;
5
5
  /**
6
6
  * Calculate the output size needed to encode a given input size for
7
- * {@linkcode encodeRawHex}.
7
+ * {@linkcode encodeIntoHex}.
8
8
  *
9
9
  * @param originalSize The size of the input buffer.
10
10
  * @returns The size of the output buffer.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_common16.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common16.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,QAAQ,YAA+C,CAAC;AACrE,eAAO,MAAM,SAAS,YAA+B,CAAC;AAMtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAOR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAeR"}
@@ -7,7 +7,7 @@ new TextEncoder()
7
7
  .forEach((byte, i) => rAlphabet[byte] = i + 10);
8
8
  /**
9
9
  * Calculate the output size needed to encode a given input size for
10
- * {@linkcode encodeRawHex}.
10
+ * {@linkcode encodeIntoHex}.
11
11
  *
12
12
  * @param originalSize The size of the input buffer.
13
13
  * @returns The size of the output buffer.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_common_detach.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common_detach.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,GACd,CAAC,WAAW,EAAE,MAAM,CAAC,CAWvB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_types.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_types.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/hex.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAU5B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAWxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAKlD"}
@@ -16,6 +16,8 @@ export interface WalletClientParameters<T extends IRequestTransport = IRequestTr
16
16
  isTestnet?: boolean;
17
17
  /** Sets a default vaultAddress to be used if no vaultAddress is explicitly passed to a method. */
18
18
  defaultVaultAddress?: Hex;
19
+ /** Sets a default expiresAfter to be used if no expiresAfter is explicitly passed to a method. */
20
+ defaultExpiresAfter?: number | (() => MaybePromise<number>);
19
21
  /**
20
22
  * The network that will be used to sign transactions.
21
23
  * Must match the network of the {@link wallet}.
@@ -35,11 +37,11 @@ export type ApproveAgentParameters = Omit<ApproveAgentRequest["action"], "type"
35
37
  /** Parameters for the {@linkcode WalletClient.approveBuilderFee} method. */
36
38
  export type ApproveBuilderFeeParameters = Omit<ApproveBuilderFeeRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">;
37
39
  /** Parameters for the {@linkcode WalletClient.batchModify} method. */
38
- export type BatchModifyParameters = Omit<BatchModifyRequest["action"], "type"> & Partial<Pick<BatchModifyRequest, "vaultAddress">>;
40
+ export type BatchModifyParameters = Omit<BatchModifyRequest["action"], "type"> & Partial<Pick<BatchModifyRequest, "vaultAddress">> & Partial<Pick<BatchModifyRequest, "expiresAfter">>;
39
41
  /** Parameters for the {@linkcode WalletClient.cancel} method. */
40
- export type CancelParameters = Omit<CancelRequest["action"], "type"> & Partial<Pick<CancelRequest, "vaultAddress">>;
42
+ export type CancelParameters = Omit<CancelRequest["action"], "type"> & Partial<Pick<CancelRequest, "vaultAddress">> & Partial<Pick<CancelRequest, "expiresAfter">>;
41
43
  /** Parameters for the {@linkcode WalletClient.cancelByCloid} method. */
42
- export type CancelByCloidParameters = Omit<CancelByCloidRequest["action"], "type"> & Partial<Pick<CancelByCloidRequest, "vaultAddress">>;
44
+ export type CancelByCloidParameters = Omit<CancelByCloidRequest["action"], "type"> & Partial<Pick<CancelByCloidRequest, "vaultAddress">> & Partial<Pick<CancelByCloidRequest, "expiresAfter">>;
43
45
  /** Parameters for the {@linkcode WalletClient.cDeposit} method. */
44
46
  export type CDepositParameters = Omit<CDepositRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">;
45
47
  /** Parameters for the {@linkcode WalletClient.createSubAccount} method. */
@@ -51,15 +53,15 @@ export type CWithdrawParameters = Omit<CWithdrawRequest["action"], "type" | "hyp
51
53
  /** Parameters for the {@linkcode WalletClient.evmUserModify} method. */
52
54
  export type EvmUserModifyParameters = Omit<EvmUserModifyRequest["action"], "type">;
53
55
  /** Parameters for the {@linkcode WalletClient.modify} method. */
54
- export type ModifyParameters = Omit<ModifyRequest["action"], "type"> & Partial<Pick<ModifyRequest, "vaultAddress">>;
56
+ export type ModifyParameters = Omit<ModifyRequest["action"], "type"> & Partial<Pick<ModifyRequest, "vaultAddress">> & Partial<Pick<ModifyRequest, "expiresAfter">>;
55
57
  /** Parameters for the {@linkcode WalletClient.order} method. */
56
- export type OrderParameters = Omit<OrderRequest["action"], "type"> & Partial<Pick<OrderRequest, "vaultAddress">>;
58
+ export type OrderParameters = Omit<OrderRequest["action"], "type"> & Partial<Pick<OrderRequest, "vaultAddress">> & Partial<Pick<OrderRequest, "expiresAfter">>;
57
59
  /** Parameters for the {@linkcode WalletClient.registerReferrer} method. */
58
60
  export type RegisterReferrerParameters = Omit<RegisterReferrerRequest["action"], "type">;
59
61
  /** Parameters for the {@linkcode WalletClient.reserveRequestWeight} method. */
60
- export type ReserveRequestWeightParameters = Omit<ReserveRequestWeightRequest["action"], "type">;
62
+ export type ReserveRequestWeightParameters = Omit<ReserveRequestWeightRequest["action"], "type"> & Partial<Pick<ReserveRequestWeightRequest, "expiresAfter">>;
61
63
  /** Parameters for the {@linkcode WalletClient.scheduleCancel} method. */
62
- export type ScheduleCancelParameters = Omit<ScheduleCancelRequest["action"], "type"> & Partial<Pick<ScheduleCancelRequest, "vaultAddress">>;
64
+ export type ScheduleCancelParameters = Omit<ScheduleCancelRequest["action"], "type"> & Partial<Pick<ScheduleCancelRequest, "vaultAddress">> & Partial<Pick<ScheduleCancelRequest, "expiresAfter">>;
63
65
  /** Parameters for the {@linkcode WalletClient.setDisplayName} method. */
64
66
  export type SetDisplayNameParameters = Omit<SetDisplayNameRequest["action"], "type">;
65
67
  /** Parameters for the {@linkcode WalletClient.setReferrer} method. */
@@ -87,13 +89,13 @@ export type SubAccountTransferParameters = Omit<SubAccountTransferRequest["actio
87
89
  /** Parameters for the {@linkcode WalletClient.tokenDelegate} method. */
88
90
  export type TokenDelegateParameters = Omit<TokenDelegateRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">;
89
91
  /** Parameters for the {@linkcode WalletClient.twapCancel} method. */
90
- export type TwapCancelParameters = Omit<TwapCancelRequest["action"], "type"> & Partial<Pick<TwapCancelRequest, "vaultAddress">>;
92
+ export type TwapCancelParameters = Omit<TwapCancelRequest["action"], "type"> & Partial<Pick<TwapCancelRequest, "vaultAddress">> & Partial<Pick<TwapCancelRequest, "expiresAfter">>;
91
93
  /** Parameters for the {@linkcode WalletClient.twapOrder} method. */
92
- export type TwapOrderParameters = TwapOrderRequest["action"]["twap"] & Partial<Pick<TwapOrderRequest, "vaultAddress">>;
94
+ export type TwapOrderParameters = TwapOrderRequest["action"]["twap"] & Partial<Pick<TwapOrderRequest, "vaultAddress">> & Partial<Pick<TwapOrderRequest, "expiresAfter">>;
93
95
  /** Parameters for the {@linkcode WalletClient.updateIsolatedMargin} method. */
94
- export type UpdateIsolatedMarginParameters = Omit<UpdateIsolatedMarginRequest["action"], "type"> & Partial<Pick<UpdateIsolatedMarginRequest, "vaultAddress">>;
96
+ export type UpdateIsolatedMarginParameters = Omit<UpdateIsolatedMarginRequest["action"], "type"> & Partial<Pick<UpdateIsolatedMarginRequest, "vaultAddress">> & Partial<Pick<UpdateIsolatedMarginRequest, "expiresAfter">>;
95
97
  /** Parameters for the {@linkcode WalletClient.updateLeverage} method. */
96
- export type UpdateLeverageParameters = Omit<UpdateLeverageRequest["action"], "type"> & Partial<Pick<UpdateLeverageRequest, "vaultAddress">>;
98
+ export type UpdateLeverageParameters = Omit<UpdateLeverageRequest["action"], "type"> & Partial<Pick<UpdateLeverageRequest, "vaultAddress">> & Partial<Pick<UpdateLeverageRequest, "expiresAfter">>;
97
99
  /** Parameters for the {@linkcode WalletClient.usdClassTransfer} method. */
98
100
  export type UsdClassTransferParameters = Omit<UsdClassTransferRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">;
99
101
  /** Parameters for the {@linkcode WalletClient.usdSend} method. */
@@ -103,7 +105,7 @@ export type VaultDistributeParameters = Omit<VaultDistributeRequest["action"], "
103
105
  /** Parameters for the {@linkcode WalletClient.vaultModify} method. */
104
106
  export type VaultModifyParameters = Omit<VaultModifyRequest["action"], "type">;
105
107
  /** Parameters for the {@linkcode WalletClient.vaultTransfer} method. */
106
- export type VaultTransferParameters = Omit<VaultTransferRequest["action"], "type">;
108
+ export type VaultTransferParameters = Omit<VaultTransferRequest["action"], "type"> & Partial<Pick<VaultTransferRequest, "expiresAfter">>;
107
109
  /** Parameters for the {@linkcode WalletClient.withdraw3} method. */
108
110
  export type Withdraw3Parameters = Omit<Withdraw3Request["action"], "type" | "hyperliquidChain" | "signatureChainId" | "time">;
109
111
  /** Successful variant of {@linkcode CancelResponse} without error statuses. */
@@ -165,6 +167,8 @@ export declare class WalletClient<T extends IRequestTransport = IRequestTranspor
165
167
  isTestnet: boolean;
166
168
  /** Sets a default vaultAddress to be used if no vaultAddress is explicitly passed to a method. */
167
169
  defaultVaultAddress?: Hex;
170
+ /** Sets a default expiresAfter to be used if no expiresAfter is explicitly passed to a method. */
171
+ defaultExpiresAfter?: number | (() => MaybePromise<number>);
168
172
  /**
169
173
  * The network that will be used to sign transactions.
170
174
  * Must match the network of the {@link wallet}.
@@ -1043,6 +1047,12 @@ export declare class WalletClient<T extends IRequestTransport = IRequestTranspor
1043
1047
  protected _formatDecimal(numStr: string): string;
1044
1048
  /** Guesses the chain ID based on the wallet type or the isTestnet flag. */
1045
1049
  protected _guessSignatureChainId(): Promise<Hex>;
1050
+ /** Get the default expiration time for an action. */
1051
+ protected _getDefaultExpiresAfter(): Promise<number | undefined>;
1052
+ /** Get the signature chain ID for the wallet. */
1053
+ protected _getSignatureChainId(): Promise<Hex>;
1054
+ /** Get the Hyperliquid chain based on the isTestnet flag. */
1055
+ protected _getHyperliquidChain(): "Mainnet" | "Testnet";
1046
1056
  /** Validate a response from the API. */
1047
1057
  protected _validateResponse(response: SuccessResponse | ErrorResponse | CancelResponse | CreateSubAccountResponse | CreateVaultResponse | OrderResponse | TwapOrderResponse | TwapCancelResponse): asserts response is SuccessResponse | CancelResponseSuccess | CreateSubAccountResponse | CreateVaultResponse | OrderResponseSuccess | TwapOrderResponseSuccess | TwapCancelResponseSuccess;
1048
1058
  }