@nktkas/hyperliquid 0.19.2 → 0.20.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 (123) hide show
  1. package/README.md +21 -29
  2. package/esm/_dnt.polyfills.d.ts +20 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +12 -0
  5. package/esm/mod.d.ts +3 -0
  6. package/esm/mod.d.ts.map +1 -1
  7. package/esm/mod.js +2 -0
  8. package/esm/src/base.d.ts +1 -47
  9. package/esm/src/base.d.ts.map +1 -1
  10. package/esm/src/base.js +1 -8
  11. package/esm/src/clients/event.d.ts +2 -3
  12. package/esm/src/clients/event.d.ts.map +1 -1
  13. package/esm/src/clients/event.js +49 -57
  14. package/esm/src/clients/public.d.ts +24 -5
  15. package/esm/src/clients/public.d.ts.map +1 -1
  16. package/esm/src/clients/public.js +23 -7
  17. package/esm/src/clients/wallet.d.ts +12 -13
  18. package/esm/src/clients/wallet.d.ts.map +1 -1
  19. package/esm/src/clients/wallet.js +55 -265
  20. package/esm/src/signing.d.ts +5 -0
  21. package/esm/src/signing.d.ts.map +1 -1
  22. package/esm/src/signing.js +24 -5
  23. package/esm/src/transports/base.d.ts +49 -0
  24. package/esm/src/transports/base.d.ts.map +1 -0
  25. package/esm/src/transports/base.js +8 -0
  26. package/esm/src/transports/http/http_transport.d.ts +8 -5
  27. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  28. package/esm/src/transports/http/http_transport.js +15 -62
  29. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
  30. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  31. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
  32. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  33. package/esm/src/transports/websocket/_reconnecting_websocket.js +80 -179
  34. package/{script/src/transports/websocket/_websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
  35. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
  36. package/esm/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +41 -74
  37. package/esm/src/transports/websocket/websocket_transport.d.ts +38 -28
  38. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  39. package/esm/src/transports/websocket/websocket_transport.js +61 -76
  40. package/esm/src/types/info/assets.d.ts +0 -48
  41. package/esm/src/types/info/assets.d.ts.map +1 -1
  42. package/esm/src/types/info/markets.d.ts +52 -0
  43. package/esm/src/types/info/markets.d.ts.map +1 -0
  44. package/esm/src/types/info/markets.js +1 -0
  45. package/esm/src/types/info/requests.d.ts +9 -0
  46. package/esm/src/types/info/requests.d.ts.map +1 -1
  47. package/esm/src/types/mod.d.ts +4 -0
  48. package/esm/src/types/mod.d.ts.map +1 -1
  49. package/esm/src/types/mod.js +3 -1
  50. package/package.json +12 -9
  51. package/script/_dnt.polyfills.d.ts +20 -0
  52. package/script/_dnt.polyfills.d.ts.map +1 -0
  53. package/script/_dnt.polyfills.js +23 -0
  54. package/script/mod.d.ts +3 -0
  55. package/script/mod.d.ts.map +1 -1
  56. package/script/mod.js +3 -1
  57. package/script/src/base.d.ts +1 -47
  58. package/script/src/base.d.ts.map +1 -1
  59. package/script/src/base.js +2 -10
  60. package/script/src/clients/event.d.ts +2 -3
  61. package/script/src/clients/event.d.ts.map +1 -1
  62. package/script/src/clients/event.js +49 -57
  63. package/script/src/clients/public.d.ts +24 -5
  64. package/script/src/clients/public.d.ts.map +1 -1
  65. package/script/src/clients/public.js +23 -7
  66. package/script/src/clients/wallet.d.ts +12 -13
  67. package/script/src/clients/wallet.d.ts.map +1 -1
  68. package/script/src/clients/wallet.js +55 -265
  69. package/script/src/signing.d.ts +5 -0
  70. package/script/src/signing.d.ts.map +1 -1
  71. package/script/src/signing.js +75 -56
  72. package/script/src/transports/base.d.ts +49 -0
  73. package/script/src/transports/base.d.ts.map +1 -0
  74. package/script/src/transports/base.js +22 -0
  75. package/script/src/transports/http/http_transport.d.ts +8 -5
  76. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  77. package/script/src/transports/http/http_transport.js +16 -63
  78. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
  79. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  80. package/script/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
  81. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  82. package/script/src/transports/websocket/_reconnecting_websocket.js +81 -180
  83. package/{esm/src/transports/websocket/_websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
  84. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
  85. package/script/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +44 -77
  86. package/script/src/transports/websocket/websocket_transport.d.ts +38 -28
  87. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  88. package/script/src/transports/websocket/websocket_transport.js +63 -78
  89. package/script/src/types/info/assets.d.ts +0 -48
  90. package/script/src/types/info/assets.d.ts.map +1 -1
  91. package/script/src/types/info/markets.d.ts +52 -0
  92. package/script/src/types/info/markets.d.ts.map +1 -0
  93. package/script/{deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js → src/types/info/markets.js} +0 -2
  94. package/script/src/types/info/requests.d.ts +9 -0
  95. package/script/src/types/info/requests.d.ts.map +1 -1
  96. package/script/src/types/mod.d.ts +4 -0
  97. package/script/src/types/mod.d.ts.map +1 -1
  98. package/script/src/types/mod.js +25 -22
  99. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
  100. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
  101. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -66
  102. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
  103. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
  104. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js +0 -1
  105. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
  106. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
  107. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -294
  108. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
  109. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
  110. package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -280
  111. package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
  112. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
  113. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
  114. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -99
  115. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
  116. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
  117. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
  118. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
  119. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -309
  120. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
  121. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
  122. package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -322
  123. package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
@@ -1,53 +0,0 @@
1
- import { Hash, type CHash, type CHashXO, type HashXOF, type Input } from './utils.js';
2
- /** `keccakf1600` internal function, additionally allows to adjust round count. */
3
- export declare function keccakP(s: Uint32Array, rounds?: number): void;
4
- /** Keccak sponge function. */
5
- export declare class Keccak extends Hash<Keccak> implements HashXOF<Keccak> {
6
- protected state: Uint8Array;
7
- protected pos: number;
8
- protected posOut: number;
9
- protected finished: boolean;
10
- protected state32: Uint32Array;
11
- protected destroyed: boolean;
12
- blockLen: number;
13
- suffix: number;
14
- outputLen: number;
15
- protected enableXOF: boolean;
16
- protected rounds: number;
17
- constructor(blockLen: number, suffix: number, outputLen: number, enableXOF?: boolean, rounds?: number);
18
- clone(): Keccak;
19
- protected keccak(): void;
20
- update(data: Input): this;
21
- protected finish(): void;
22
- protected writeInto(out: Uint8Array): Uint8Array;
23
- xofInto(out: Uint8Array): Uint8Array;
24
- xof(bytes: number): Uint8Array;
25
- digestInto(out: Uint8Array): Uint8Array;
26
- digest(): Uint8Array;
27
- destroy(): void;
28
- _cloneInto(to?: Keccak): Keccak;
29
- }
30
- /** SHA3-224 hash function. */
31
- export declare const sha3_224: CHash;
32
- /** SHA3-256 hash function. Different from keccak-256. */
33
- export declare const sha3_256: CHash;
34
- /** SHA3-384 hash function. */
35
- export declare const sha3_384: CHash;
36
- /** SHA3-512 hash function. */
37
- export declare const sha3_512: CHash;
38
- /** keccak-224 hash function. */
39
- export declare const keccak_224: CHash;
40
- /** keccak-256 hash function. Different from SHA3-256. */
41
- export declare const keccak_256: CHash;
42
- /** keccak-384 hash function. */
43
- export declare const keccak_384: CHash;
44
- /** keccak-512 hash function. */
45
- export declare const keccak_512: CHash;
46
- export type ShakeOpts = {
47
- dkLen?: number;
48
- };
49
- /** SHAKE128 XOF with 128-bit security. */
50
- export declare const shake128: CHashXO;
51
- /** SHAKE256 XOF with 256-bit security. */
52
- export declare const shake256: CHashXO;
53
- //# sourceMappingURL=sha3.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sha3.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.8.0/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O,IAAI,IAAI;IAIf,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;CAehC;AAKD,8BAA8B;AAC9B,eAAO,MAAM,QAAQ,EAAE,KAAyD,CAAC;AACjF,yDAAyD;AACzD,eAAO,MAAM,QAAQ,EAAE,KAAyD,CAAC;AACjF,8BAA8B;AAC9B,eAAO,MAAM,QAAQ,EAAE,KAAyD,CAAC;AACjF,8BAA8B;AAC9B,eAAO,MAAM,QAAQ,EAAE,KAAwD,CAAC;AAEhF,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAE,KAAyD,CAAC;AACnF,yDAAyD;AACzD,eAAO,MAAM,UAAU,EAAE,KAAyD,CAAC;AACnF,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAE,KAAyD,CAAC;AACnF,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAE,KAAwD,CAAC;AAElF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ3C,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,EAAE,OAAgE,CAAC;AACxF,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,EAAE,OAAgE,CAAC"}
@@ -1,309 +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", "./_u64.js", "./utils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.shake256 = exports.shake128 = exports.keccak_512 = exports.keccak_384 = exports.keccak_256 = exports.keccak_224 = exports.sha3_512 = exports.sha3_384 = exports.sha3_256 = exports.sha3_224 = exports.Keccak = void 0;
13
- exports.keccakP = keccakP;
14
- /**
15
- * SHA3 (keccak) hash function, based on a new "Sponge function" design.
16
- * Different from older hashes, the internal state is bigger than output size.
17
- *
18
- * Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
19
- * [Website](https://keccak.team/keccak.html),
20
- * [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
21
- *
22
- * Check out `sha3-addons` module for cSHAKE, k12, and others.
23
- * @module
24
- */
25
- const _u64_js_1 = require("./_u64.js");
26
- // prettier-ignore
27
- const utils_js_1 = require("./utils.js");
28
- // No __PURE__ annotations in sha3 header:
29
- // EVERYTHING is in fact used on every export.
30
- // Various per round constants calculations
31
- const _0n = BigInt(0);
32
- const _1n = BigInt(1);
33
- const _2n = BigInt(2);
34
- const _7n = BigInt(7);
35
- const _256n = BigInt(256);
36
- const _0x71n = BigInt(0x71);
37
- const SHA3_PI = [];
38
- const SHA3_ROTL = [];
39
- const _SHA3_IOTA = [];
40
- for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
41
- // Pi
42
- [x, y] = [y, (2 * x + 3 * y) % 5];
43
- SHA3_PI.push(2 * (5 * y + x));
44
- // Rotational
45
- SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
46
- // Iota
47
- let t = _0n;
48
- for (let j = 0; j < 7; j++) {
49
- R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
50
- if (R & _2n)
51
- t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
52
- }
53
- _SHA3_IOTA.push(t);
54
- }
55
- const IOTAS = (0, _u64_js_1.split)(_SHA3_IOTA, true);
56
- const SHA3_IOTA_H = IOTAS[0];
57
- const SHA3_IOTA_L = IOTAS[1];
58
- // Left rotation (without 0, 32, 64)
59
- const rotlH = (h, l, s) => (s > 32 ? (0, _u64_js_1.rotlBH)(h, l, s) : (0, _u64_js_1.rotlSH)(h, l, s));
60
- const rotlL = (h, l, s) => (s > 32 ? (0, _u64_js_1.rotlBL)(h, l, s) : (0, _u64_js_1.rotlSL)(h, l, s));
61
- /** `keccakf1600` internal function, additionally allows to adjust round count. */
62
- function keccakP(s, rounds = 24) {
63
- const B = new Uint32Array(5 * 2);
64
- // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
65
- for (let round = 24 - rounds; round < 24; round++) {
66
- // Theta θ
67
- for (let x = 0; x < 10; x++)
68
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
69
- for (let x = 0; x < 10; x += 2) {
70
- const idx1 = (x + 8) % 10;
71
- const idx0 = (x + 2) % 10;
72
- const B0 = B[idx0];
73
- const B1 = B[idx0 + 1];
74
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
75
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
76
- for (let y = 0; y < 50; y += 10) {
77
- s[x + y] ^= Th;
78
- s[x + y + 1] ^= Tl;
79
- }
80
- }
81
- // Rho (ρ) and Pi (π)
82
- let curH = s[2];
83
- let curL = s[3];
84
- for (let t = 0; t < 24; t++) {
85
- const shift = SHA3_ROTL[t];
86
- const Th = rotlH(curH, curL, shift);
87
- const Tl = rotlL(curH, curL, shift);
88
- const PI = SHA3_PI[t];
89
- curH = s[PI];
90
- curL = s[PI + 1];
91
- s[PI] = Th;
92
- s[PI + 1] = Tl;
93
- }
94
- // Chi (χ)
95
- for (let y = 0; y < 50; y += 10) {
96
- for (let x = 0; x < 10; x++)
97
- B[x] = s[y + x];
98
- for (let x = 0; x < 10; x++)
99
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
100
- }
101
- // Iota (ι)
102
- s[0] ^= SHA3_IOTA_H[round];
103
- s[1] ^= SHA3_IOTA_L[round];
104
- }
105
- (0, utils_js_1.clean)(B);
106
- }
107
- /** Keccak sponge function. */
108
- class Keccak extends utils_js_1.Hash {
109
- // NOTE: we accept arguments in bytes instead of bits here.
110
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
111
- super();
112
- Object.defineProperty(this, "state", {
113
- enumerable: true,
114
- configurable: true,
115
- writable: true,
116
- value: void 0
117
- });
118
- Object.defineProperty(this, "pos", {
119
- enumerable: true,
120
- configurable: true,
121
- writable: true,
122
- value: 0
123
- });
124
- Object.defineProperty(this, "posOut", {
125
- enumerable: true,
126
- configurable: true,
127
- writable: true,
128
- value: 0
129
- });
130
- Object.defineProperty(this, "finished", {
131
- enumerable: true,
132
- configurable: true,
133
- writable: true,
134
- value: false
135
- });
136
- Object.defineProperty(this, "state32", {
137
- enumerable: true,
138
- configurable: true,
139
- writable: true,
140
- value: void 0
141
- });
142
- Object.defineProperty(this, "destroyed", {
143
- enumerable: true,
144
- configurable: true,
145
- writable: true,
146
- value: false
147
- });
148
- Object.defineProperty(this, "blockLen", {
149
- enumerable: true,
150
- configurable: true,
151
- writable: true,
152
- value: void 0
153
- });
154
- Object.defineProperty(this, "suffix", {
155
- enumerable: true,
156
- configurable: true,
157
- writable: true,
158
- value: void 0
159
- });
160
- Object.defineProperty(this, "outputLen", {
161
- enumerable: true,
162
- configurable: true,
163
- writable: true,
164
- value: void 0
165
- });
166
- Object.defineProperty(this, "enableXOF", {
167
- enumerable: true,
168
- configurable: true,
169
- writable: true,
170
- value: false
171
- });
172
- Object.defineProperty(this, "rounds", {
173
- enumerable: true,
174
- configurable: true,
175
- writable: true,
176
- value: void 0
177
- });
178
- this.blockLen = blockLen;
179
- this.suffix = suffix;
180
- this.outputLen = outputLen;
181
- this.enableXOF = enableXOF;
182
- this.rounds = rounds;
183
- // Can be passed from user as dkLen
184
- (0, utils_js_1.anumber)(outputLen);
185
- // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
186
- // 0 < blockLen < 200
187
- if (!(0 < blockLen && blockLen < 200))
188
- throw new Error('only keccak-f1600 function is supported');
189
- this.state = new Uint8Array(200);
190
- this.state32 = (0, utils_js_1.u32)(this.state);
191
- }
192
- clone() {
193
- return this._cloneInto();
194
- }
195
- keccak() {
196
- (0, utils_js_1.swap32IfBE)(this.state32);
197
- keccakP(this.state32, this.rounds);
198
- (0, utils_js_1.swap32IfBE)(this.state32);
199
- this.posOut = 0;
200
- this.pos = 0;
201
- }
202
- update(data) {
203
- (0, utils_js_1.aexists)(this);
204
- data = (0, utils_js_1.toBytes)(data);
205
- (0, utils_js_1.abytes)(data);
206
- const { blockLen, state } = this;
207
- const len = data.length;
208
- for (let pos = 0; pos < len;) {
209
- const take = Math.min(blockLen - this.pos, len - pos);
210
- for (let i = 0; i < take; i++)
211
- state[this.pos++] ^= data[pos++];
212
- if (this.pos === blockLen)
213
- this.keccak();
214
- }
215
- return this;
216
- }
217
- finish() {
218
- if (this.finished)
219
- return;
220
- this.finished = true;
221
- const { state, suffix, pos, blockLen } = this;
222
- // Do the padding
223
- state[pos] ^= suffix;
224
- if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
225
- this.keccak();
226
- state[blockLen - 1] ^= 0x80;
227
- this.keccak();
228
- }
229
- writeInto(out) {
230
- (0, utils_js_1.aexists)(this, false);
231
- (0, utils_js_1.abytes)(out);
232
- this.finish();
233
- const bufferOut = this.state;
234
- const { blockLen } = this;
235
- for (let pos = 0, len = out.length; pos < len;) {
236
- if (this.posOut >= blockLen)
237
- this.keccak();
238
- const take = Math.min(blockLen - this.posOut, len - pos);
239
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
240
- this.posOut += take;
241
- pos += take;
242
- }
243
- return out;
244
- }
245
- xofInto(out) {
246
- // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
247
- if (!this.enableXOF)
248
- throw new Error('XOF is not possible for this instance');
249
- return this.writeInto(out);
250
- }
251
- xof(bytes) {
252
- (0, utils_js_1.anumber)(bytes);
253
- return this.xofInto(new Uint8Array(bytes));
254
- }
255
- digestInto(out) {
256
- (0, utils_js_1.aoutput)(out, this);
257
- if (this.finished)
258
- throw new Error('digest() was already called');
259
- this.writeInto(out);
260
- this.destroy();
261
- return out;
262
- }
263
- digest() {
264
- return this.digestInto(new Uint8Array(this.outputLen));
265
- }
266
- destroy() {
267
- this.destroyed = true;
268
- (0, utils_js_1.clean)(this.state);
269
- }
270
- _cloneInto(to) {
271
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
272
- to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
273
- to.state32.set(this.state32);
274
- to.pos = this.pos;
275
- to.posOut = this.posOut;
276
- to.finished = this.finished;
277
- to.rounds = rounds;
278
- // Suffix can change in cSHAKE
279
- to.suffix = suffix;
280
- to.outputLen = outputLen;
281
- to.enableXOF = enableXOF;
282
- to.destroyed = this.destroyed;
283
- return to;
284
- }
285
- }
286
- exports.Keccak = Keccak;
287
- const gen = (suffix, blockLen, outputLen) => (0, utils_js_1.createHasher)(() => new Keccak(blockLen, suffix, outputLen));
288
- /** SHA3-224 hash function. */
289
- exports.sha3_224 = (() => gen(0x06, 144, 224 / 8))();
290
- /** SHA3-256 hash function. Different from keccak-256. */
291
- exports.sha3_256 = (() => gen(0x06, 136, 256 / 8))();
292
- /** SHA3-384 hash function. */
293
- exports.sha3_384 = (() => gen(0x06, 104, 384 / 8))();
294
- /** SHA3-512 hash function. */
295
- exports.sha3_512 = (() => gen(0x06, 72, 512 / 8))();
296
- /** keccak-224 hash function. */
297
- exports.keccak_224 = (() => gen(0x01, 144, 224 / 8))();
298
- /** keccak-256 hash function. Different from SHA3-256. */
299
- exports.keccak_256 = (() => gen(0x01, 136, 256 / 8))();
300
- /** keccak-384 hash function. */
301
- exports.keccak_384 = (() => gen(0x01, 104, 384 / 8))();
302
- /** keccak-512 hash function. */
303
- exports.keccak_512 = (() => gen(0x01, 72, 512 / 8))();
304
- const genShake = (suffix, blockLen, outputLen) => (0, utils_js_1.createXOFer)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
305
- /** SHAKE128 XOF with 128-bit security. */
306
- exports.shake128 = (() => genShake(0x1f, 168, 128 / 8))();
307
- /** SHAKE256 XOF with 256-bit security. */
308
- exports.shake256 = (() => genShake(0x1f, 136, 256 / 8))();
309
- });
@@ -1,161 +0,0 @@
1
- /**
2
- * Utilities for hex, bytes, CSPRNG.
3
- * @module
4
- */
5
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
6
- /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
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. */
19
- export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
20
- /** Cast u8 / u16 / u32 to u8. */
21
- export declare function u8(arr: TypedArray): Uint8Array;
22
- /** Cast u8 / u16 / u32 to u32. */
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. */
27
- export declare function createView(arr: TypedArray): DataView;
28
- /** The rotate right (circular right shift) operation for uint32 */
29
- export declare function rotr(word: number, shift: number): number;
30
- /** The rotate left (circular left shift) operation for uint32 */
31
- export declare function rotl(word: number, shift: number): number;
32
- /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
33
- export declare const isLE: boolean;
34
- /** The byte swap operation for uint32 */
35
- export declare function byteSwap(word: number): number;
36
- /** Conditionally byte swap if on a big-endian platform */
37
- export declare const swap8IfBE: (n: number) => number;
38
- /** @deprecated */
39
- export declare const byteSwapIfBE: typeof swap8IfBE;
40
- /** In place byte swap for Uint32Array */
41
- export declare function byteSwap32(arr: Uint32Array): Uint32Array;
42
- export declare const swap32IfBE: (u: Uint32Array) => Uint32Array;
43
- /**
44
- * Convert byte array to hex string. Uses built-in function, when available.
45
- * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
46
- */
47
- export declare function bytesToHex(bytes: Uint8Array): string;
48
- /**
49
- * Convert hex string to byte array. Uses built-in function, when available.
50
- * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
51
- */
52
- export declare function hexToBytes(hex: string): Uint8Array;
53
- /**
54
- * There is no setImmediate in browser and setTimeout is slow.
55
- * Call of async fn will return Promise, which will be fullfiled only on
56
- * next scheduler queue processing step and this is exactly what we need.
57
- */
58
- export declare const nextTick: () => Promise<void>;
59
- /** Returns control to thread each 'tick' ms to avoid blocking. */
60
- export declare function asyncLoop(iters: number, tick: number, cb: (i: number) => void): Promise<void>;
61
- /**
62
- * Converts string to bytes using UTF8 encoding.
63
- * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
64
- */
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;
71
- /** Accepted input of hash functions. Strings are converted to byte arrays. */
72
- export type Input = string | Uint8Array;
73
- /**
74
- * Normalizes (non-hex) string or Uint8Array to Uint8Array.
75
- * Warning: when Uint8Array is passed, it would NOT get copied.
76
- * Keep in mind for future mutable operations.
77
- */
78
- export declare function toBytes(data: Input): Uint8Array;
79
- /** KDFs can accept string or Uint8Array for user convenience. */
80
- export type KDFInput = string | Uint8Array;
81
- /**
82
- * Helper for KDFs: consumes uint8array or string.
83
- * When string is passed, does utf8 decoding, using TextDecoder.
84
- */
85
- export declare function kdfInputToBytes(data: KDFInput): Uint8Array;
86
- /** Copies several Uint8Arrays into one. */
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
- };
97
- /** For runtime check if class implements interface */
98
- export declare abstract class Hash<T extends Hash<T>> {
99
- abstract blockLen: number;
100
- abstract outputLen: number;
101
- abstract update(buf: Input): this;
102
- abstract digestInto(buf: Uint8Array): void;
103
- abstract digest(): Uint8Array;
104
- /**
105
- * Resets internal state. Makes Hash instance unusable.
106
- * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
107
- * by user, they will need to manually call `destroy()` when zeroing is necessary.
108
- */
109
- abstract destroy(): void;
110
- /**
111
- * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`
112
- * when no options are passed.
113
- * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal
114
- * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.
115
- * There are no guarantees for clean-up because it's impossible in JS.
116
- */
117
- abstract _cloneInto(to?: T): T;
118
- abstract clone(): T;
119
- }
120
- /**
121
- * XOF: streaming API to read digest in chunks.
122
- * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.
123
- * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot
124
- * destroy state, next call can require more bytes.
125
- */
126
- export type HashXOF<T extends Hash<T>> = Hash<T> & {
127
- xof(bytes: number): Uint8Array;
128
- xofInto(buf: Uint8Array): Uint8Array;
129
- };
130
- /** Hash function */
131
- export type CHash = ReturnType<typeof createHasher>;
132
- /** Hash function with output */
133
- export type CHashO = ReturnType<typeof createOptHasher>;
134
- /** XOF with output */
135
- export type CHashXO = ReturnType<typeof createXOFer>;
136
- /** Wraps hash function, creating an interface on top of it */
137
- export declare function createHasher<T extends Hash<T>>(hashCons: () => Hash<T>): {
138
- (msg: Input): Uint8Array;
139
- outputLen: number;
140
- blockLen: number;
141
- create(): Hash<T>;
142
- };
143
- export declare function createOptHasher<H extends Hash<H>, T extends Object>(hashCons: (opts?: T) => Hash<H>): {
144
- (msg: Input, opts?: T): Uint8Array;
145
- outputLen: number;
146
- blockLen: number;
147
- create(opts?: T): Hash<H>;
148
- };
149
- export declare function createXOFer<H extends HashXOF<H>, T extends Object>(hashCons: (opts?: T) => HashXOF<H>): {
150
- (msg: Input, opts?: T): Uint8Array;
151
- outputLen: number;
152
- blockLen: number;
153
- create(opts?: T): HashXOF<H>;
154
- };
155
- export declare const wrapConstructor: typeof createHasher;
156
- export declare const wrapConstructorWithOpts: typeof createOptHasher;
157
- export declare const wrapXOFConstructorWithOpts: typeof createXOFer;
158
- /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
159
- export declare function randomBytes(bytesLength?: number): Uint8Array;
160
- export {};
161
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
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,IAA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