@nktkas/hyperliquid 0.13.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 +59 -0
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/SECURITY.md +7 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +10 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +43 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +65 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +283 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +211 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.js +32 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +26 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js +109 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.js +237 -0
- package/esm/mod.d.ts +24 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +9 -0
- package/esm/package.json +3 -0
- package/esm/src/clients/event.d.ts +374 -0
- package/esm/src/clients/event.d.ts.map +1 -0
- package/esm/src/clients/event.js +490 -0
- package/esm/src/clients/public.d.ts +695 -0
- package/esm/src/clients/public.d.ts.map +1 -0
- package/esm/src/clients/public.js +704 -0
- package/esm/src/clients/wallet.d.ts +682 -0
- package/esm/src/clients/wallet.d.ts.map +1 -0
- package/esm/src/clients/wallet.js +984 -0
- package/esm/src/transports/base.d.ts +55 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +14 -0
- package/esm/src/transports/http/http_transport.d.ts +78 -0
- package/esm/src/transports/http/http_transport.d.ts.map +1 -0
- package/esm/src/transports/http/http_transport.js +170 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.js +33 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/reconnecting_websocket.js +370 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.js +201 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_transport.js +233 -0
- package/esm/src/utils/key_sort.d.ts +21 -0
- package/esm/src/utils/key_sort.d.ts.map +1 -0
- package/esm/src/utils/key_sort.js +124 -0
- package/esm/src/utils/signing.d.ts +109 -0
- package/esm/src/utils/signing.d.ts.map +1 -0
- package/esm/src/utils/signing.js +164 -0
- package/package.json +34 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +17 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +14 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +49 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +88 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +4 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +235 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +35 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +29 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +113 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +240 -0
- package/script/mod.d.ts +24 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +27 -0
- package/script/package.json +3 -0
- package/script/src/clients/event.d.ts +374 -0
- package/script/src/clients/event.d.ts.map +1 -0
- package/script/src/clients/event.js +494 -0
- package/script/src/clients/public.d.ts +695 -0
- package/script/src/clients/public.d.ts.map +1 -0
- package/script/src/clients/public.js +708 -0
- package/script/src/clients/wallet.d.ts +682 -0
- package/script/src/clients/wallet.d.ts.map +1 -0
- package/script/src/clients/wallet.js +989 -0
- package/script/src/transports/base.d.ts +55 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +18 -0
- package/script/src/transports/http/http_transport.d.ts +78 -0
- package/script/src/transports/http/http_transport.d.ts.map +1 -0
- package/script/src/transports/http/http_transport.js +175 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/hyperliquid_event_target.js +37 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/reconnecting_websocket.js +374 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.js +206 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_transport.js +237 -0
- package/script/src/utils/key_sort.d.ts +21 -0
- package/script/src/utils/key_sort.d.ts.map +1 -0
- package/script/src/utils/key_sort.js +127 -0
- package/script/src/utils/signing.d.ts +109 -0
- package/script/src/utils/signing.d.ts.map +1 -0
- package/script/src/utils/signing.js +172 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
declare function fromBig(n: bigint, le?: boolean): {
|
|
2
|
+
h: number;
|
|
3
|
+
l: number;
|
|
4
|
+
};
|
|
5
|
+
declare function split(lst: bigint[], le?: boolean): Uint32Array[];
|
|
6
|
+
declare const toBig: (h: number, l: number) => bigint;
|
|
7
|
+
declare const shrSH: (h: number, _l: number, s: number) => number;
|
|
8
|
+
declare const shrSL: (h: number, l: number, s: number) => number;
|
|
9
|
+
declare const rotrSH: (h: number, l: number, s: number) => number;
|
|
10
|
+
declare const rotrSL: (h: number, l: number, s: number) => number;
|
|
11
|
+
declare const rotrBH: (h: number, l: number, s: number) => number;
|
|
12
|
+
declare const rotrBL: (h: number, l: number, s: number) => number;
|
|
13
|
+
declare const rotr32H: (_h: number, l: number) => number;
|
|
14
|
+
declare const rotr32L: (h: number, _l: number) => number;
|
|
15
|
+
declare const rotlSH: (h: number, l: number, s: number) => number;
|
|
16
|
+
declare const rotlSL: (h: number, l: number, s: number) => number;
|
|
17
|
+
declare const rotlBH: (h: number, l: number, s: number) => number;
|
|
18
|
+
declare const rotlBL: (h: number, l: number, s: number) => number;
|
|
19
|
+
declare function add(Ah: number, Al: number, Bh: number, Bl: number): {
|
|
20
|
+
h: number;
|
|
21
|
+
l: number;
|
|
22
|
+
};
|
|
23
|
+
declare const add3L: (Al: number, Bl: number, Cl: number) => number;
|
|
24
|
+
declare const add3H: (low: number, Ah: number, Bh: number, Ch: number) => number;
|
|
25
|
+
declare const add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number;
|
|
26
|
+
declare const add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number;
|
|
27
|
+
declare const add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number;
|
|
28
|
+
declare const add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number;
|
|
29
|
+
export { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, };
|
|
30
|
+
declare const u64: {
|
|
31
|
+
fromBig: typeof fromBig;
|
|
32
|
+
split: typeof split;
|
|
33
|
+
toBig: (h: number, l: number) => bigint;
|
|
34
|
+
shrSH: (h: number, _l: number, s: number) => number;
|
|
35
|
+
shrSL: (h: number, l: number, s: number) => number;
|
|
36
|
+
rotrSH: (h: number, l: number, s: number) => number;
|
|
37
|
+
rotrSL: (h: number, l: number, s: number) => number;
|
|
38
|
+
rotrBH: (h: number, l: number, s: number) => number;
|
|
39
|
+
rotrBL: (h: number, l: number, s: number) => number;
|
|
40
|
+
rotr32H: (_h: number, l: number) => number;
|
|
41
|
+
rotr32L: (h: number, _l: number) => number;
|
|
42
|
+
rotlSH: (h: number, l: number, s: number) => number;
|
|
43
|
+
rotlSL: (h: number, l: number, s: number) => number;
|
|
44
|
+
rotlBH: (h: number, l: number, s: number) => number;
|
|
45
|
+
rotlBL: (h: number, l: number, s: number) => number;
|
|
46
|
+
add: typeof add;
|
|
47
|
+
add3L: (Al: number, Bl: number, Cl: number) => number;
|
|
48
|
+
add3H: (low: number, Ah: number, Bh: number, Ch: number) => number;
|
|
49
|
+
add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number;
|
|
50
|
+
add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number;
|
|
51
|
+
add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number;
|
|
52
|
+
add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number;
|
|
53
|
+
};
|
|
54
|
+
export default u64;
|
|
55
|
+
//# sourceMappingURL=_u64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_u64.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.ts"],"names":[],"mappings":"AAQA,iBAAS,OAAO,CACd,CAAC,EAAE,MAAM,EACT,EAAE,UAAQ,GACT;IACD,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAGA;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E,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;CAOrpC,CAAC;AACF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
3
|
+
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
7
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
8
|
+
function fromBig(n, le = false) {
|
|
9
|
+
if (le)
|
|
10
|
+
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
11
|
+
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
12
|
+
}
|
|
13
|
+
function split(lst, le = false) {
|
|
14
|
+
let Ah = new Uint32Array(lst.length);
|
|
15
|
+
let Al = new Uint32Array(lst.length);
|
|
16
|
+
for (let i = 0; i < lst.length; i++) {
|
|
17
|
+
const { h, l } = fromBig(lst[i], le);
|
|
18
|
+
[Ah[i], Al[i]] = [h, l];
|
|
19
|
+
}
|
|
20
|
+
return [Ah, Al];
|
|
21
|
+
}
|
|
22
|
+
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
|
|
23
|
+
// for Shift in [0, 32)
|
|
24
|
+
const shrSH = (h, _l, s) => h >>> s;
|
|
25
|
+
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
26
|
+
// Right rotate for Shift in [1, 32)
|
|
27
|
+
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
|
|
28
|
+
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
29
|
+
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
30
|
+
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
31
|
+
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
32
|
+
// Right rotate for shift===32 (just swaps l&h)
|
|
33
|
+
const rotr32H = (_h, l) => l;
|
|
34
|
+
const rotr32L = (h, _l) => h;
|
|
35
|
+
// Left rotate for Shift in [1, 32)
|
|
36
|
+
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
37
|
+
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
38
|
+
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
39
|
+
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
40
|
+
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
41
|
+
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
42
|
+
// simple take carry out of low bit sum by shift, we need to use division.
|
|
43
|
+
function add(Ah, Al, Bh, Bl) {
|
|
44
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
45
|
+
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
46
|
+
}
|
|
47
|
+
// Addition with more than 2 elements
|
|
48
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
49
|
+
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
50
|
+
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
51
|
+
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
|
|
52
|
+
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
53
|
+
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
export { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, };
|
|
56
|
+
// prettier-ignore
|
|
57
|
+
const u64 = {
|
|
58
|
+
fromBig, split, toBig,
|
|
59
|
+
shrSH, shrSL,
|
|
60
|
+
rotrSH, rotrSL, rotrBH, rotrBL,
|
|
61
|
+
rotr32H, rotr32L,
|
|
62
|
+
rotlSH, rotlSL, rotlBH, rotlBL,
|
|
63
|
+
add, add3L, add3H, add4L, add4H, add5H, add5L,
|
|
64
|
+
};
|
|
65
|
+
export default u64;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,MAAM,EAAE,GACqE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
blockLen: number;
|
|
7
|
+
suffix: number;
|
|
8
|
+
outputLen: number;
|
|
9
|
+
protected enableXOF: boolean;
|
|
10
|
+
protected rounds: number;
|
|
11
|
+
protected state: Uint8Array;
|
|
12
|
+
protected pos: number;
|
|
13
|
+
protected posOut: number;
|
|
14
|
+
protected finished: boolean;
|
|
15
|
+
protected state32: Uint32Array;
|
|
16
|
+
protected destroyed: boolean;
|
|
17
|
+
constructor(blockLen: number, suffix: number, outputLen: number, enableXOF?: boolean, rounds?: number);
|
|
18
|
+
protected keccak(): void;
|
|
19
|
+
update(data: Input): this;
|
|
20
|
+
protected finish(): void;
|
|
21
|
+
protected writeInto(out: Uint8Array): Uint8Array;
|
|
22
|
+
xofInto(out: Uint8Array): Uint8Array;
|
|
23
|
+
xof(bytes: number): Uint8Array;
|
|
24
|
+
digestInto(out: Uint8Array): Uint8Array;
|
|
25
|
+
digest(): Uint8Array;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
_cloneInto(to?: Keccak): Keccak;
|
|
28
|
+
}
|
|
29
|
+
/** SHA3-224 hash function. */
|
|
30
|
+
export declare const sha3_224: CHash;
|
|
31
|
+
/** SHA3-256 hash function. Different from keccak-256. */
|
|
32
|
+
export declare const sha3_256: CHash;
|
|
33
|
+
/** SHA3-384 hash function. */
|
|
34
|
+
export declare const sha3_384: CHash;
|
|
35
|
+
/** SHA3-512 hash function. */
|
|
36
|
+
export declare const sha3_512: CHash;
|
|
37
|
+
/** keccak-224 hash function. */
|
|
38
|
+
export declare const keccak_224: CHash;
|
|
39
|
+
/** keccak-256 hash function. Different from SHA3-256. */
|
|
40
|
+
export declare const keccak_256: CHash;
|
|
41
|
+
/** keccak-384 hash function. */
|
|
42
|
+
export declare const keccak_384: CHash;
|
|
43
|
+
/** keccak-512 hash function. */
|
|
44
|
+
export declare const keccak_512: CHash;
|
|
45
|
+
export type ShakeOpts = {
|
|
46
|
+
dkLen?: number;
|
|
47
|
+
};
|
|
48
|
+
/** SHAKE128 XOF with 128-bit security. */
|
|
49
|
+
export declare const shake128: CHashXO;
|
|
50
|
+
/** SHAKE256 XOF with 256-bit security. */
|
|
51
|
+
export declare const shake256: CHashXO;
|
|
52
|
+
//# sourceMappingURL=sha3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha3.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,IAAI,EAMJ,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAgCpB,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAE,MAAW,GAAG,IAAI,CAyCjE;AAED,8BAA8B;AAC9B,qBAAa,MAAO,SAAQ,IAAI,CAAC,MAAM,CAAE,YAAW,OAAO,CAAC,MAAM,CAAC;IASxD,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,MAAM;IACd,SAAS,EAAE,MAAM;IACxB,S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CAAC;AACzE,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAE,KAA8C,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ3C,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,EAAE,OAAsD,CAAC;AAC9E,0CAA0C;AAC1C,eAAO,MAAM,QAAQ,EAAE,OAAsD,CAAC"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA3 (keccak) hash function, based on a new "Sponge function" design.
|
|
3
|
+
* Different from older hashes, the internal state is bigger than output size.
|
|
4
|
+
*
|
|
5
|
+
* Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
|
|
6
|
+
* [Website](https://keccak.team/keccak.html),
|
|
7
|
+
* [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).
|
|
8
|
+
*
|
|
9
|
+
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { abytes, aexists, anumber, aoutput } from './_assert.js';
|
|
13
|
+
import { rotlBH, rotlBL, rotlSH, rotlSL, split } from './_u64.js';
|
|
14
|
+
import { byteSwap32, Hash, isLE, toBytes, u32, wrapConstructor, wrapXOFConstructorWithOpts, } from './utils.js';
|
|
15
|
+
// Various per round constants calculations
|
|
16
|
+
const SHA3_PI = [];
|
|
17
|
+
const SHA3_ROTL = [];
|
|
18
|
+
const _SHA3_IOTA = [];
|
|
19
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
20
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
21
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
22
|
+
const _7n = /* @__PURE__ */ BigInt(7);
|
|
23
|
+
const _256n = /* @__PURE__ */ BigInt(256);
|
|
24
|
+
const _0x71n = /* @__PURE__ */ BigInt(0x71);
|
|
25
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
26
|
+
// Pi
|
|
27
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
28
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
29
|
+
// Rotational
|
|
30
|
+
SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
|
|
31
|
+
// Iota
|
|
32
|
+
let t = _0n;
|
|
33
|
+
for (let j = 0; j < 7; j++) {
|
|
34
|
+
R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
|
|
35
|
+
if (R & _2n)
|
|
36
|
+
t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
|
|
37
|
+
}
|
|
38
|
+
_SHA3_IOTA.push(t);
|
|
39
|
+
}
|
|
40
|
+
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
|
|
41
|
+
// Left rotation (without 0, 32, 64)
|
|
42
|
+
const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
|
|
43
|
+
const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
|
|
44
|
+
/** `keccakf1600` internal function, additionally allows to adjust round count. */
|
|
45
|
+
export function keccakP(s, rounds = 24) {
|
|
46
|
+
const B = new Uint32Array(5 * 2);
|
|
47
|
+
// NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
|
|
48
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
49
|
+
// Theta θ
|
|
50
|
+
for (let x = 0; x < 10; x++)
|
|
51
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
52
|
+
for (let x = 0; x < 10; x += 2) {
|
|
53
|
+
const idx1 = (x + 8) % 10;
|
|
54
|
+
const idx0 = (x + 2) % 10;
|
|
55
|
+
const B0 = B[idx0];
|
|
56
|
+
const B1 = B[idx0 + 1];
|
|
57
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
58
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
59
|
+
for (let y = 0; y < 50; y += 10) {
|
|
60
|
+
s[x + y] ^= Th;
|
|
61
|
+
s[x + y + 1] ^= Tl;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Rho (ρ) and Pi (π)
|
|
65
|
+
let curH = s[2];
|
|
66
|
+
let curL = s[3];
|
|
67
|
+
for (let t = 0; t < 24; t++) {
|
|
68
|
+
const shift = SHA3_ROTL[t];
|
|
69
|
+
const Th = rotlH(curH, curL, shift);
|
|
70
|
+
const Tl = rotlL(curH, curL, shift);
|
|
71
|
+
const PI = SHA3_PI[t];
|
|
72
|
+
curH = s[PI];
|
|
73
|
+
curL = s[PI + 1];
|
|
74
|
+
s[PI] = Th;
|
|
75
|
+
s[PI + 1] = Tl;
|
|
76
|
+
}
|
|
77
|
+
// Chi (χ)
|
|
78
|
+
for (let y = 0; y < 50; y += 10) {
|
|
79
|
+
for (let x = 0; x < 10; x++)
|
|
80
|
+
B[x] = s[y + x];
|
|
81
|
+
for (let x = 0; x < 10; x++)
|
|
82
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
83
|
+
}
|
|
84
|
+
// Iota (ι)
|
|
85
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
86
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
87
|
+
}
|
|
88
|
+
B.fill(0);
|
|
89
|
+
}
|
|
90
|
+
/** Keccak sponge function. */
|
|
91
|
+
export class Keccak extends Hash {
|
|
92
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
93
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
94
|
+
super();
|
|
95
|
+
Object.defineProperty(this, "blockLen", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: blockLen
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "suffix", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: suffix
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "outputLen", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: outputLen
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "enableXOF", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: enableXOF
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "rounds", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: rounds
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "state", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: void 0
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(this, "pos", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: true,
|
|
134
|
+
writable: true,
|
|
135
|
+
value: 0
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(this, "posOut", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true,
|
|
140
|
+
writable: true,
|
|
141
|
+
value: 0
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(this, "finished", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: false
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(this, "state32", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: void 0
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(this, "destroyed", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
value: false
|
|
160
|
+
});
|
|
161
|
+
// Can be passed from user as dkLen
|
|
162
|
+
anumber(outputLen);
|
|
163
|
+
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
164
|
+
// 0 < blockLen < 200
|
|
165
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
166
|
+
throw new Error('Sha3 supports only keccak-f1600 function');
|
|
167
|
+
this.state = new Uint8Array(200);
|
|
168
|
+
this.state32 = u32(this.state);
|
|
169
|
+
}
|
|
170
|
+
keccak() {
|
|
171
|
+
if (!isLE)
|
|
172
|
+
byteSwap32(this.state32);
|
|
173
|
+
keccakP(this.state32, this.rounds);
|
|
174
|
+
if (!isLE)
|
|
175
|
+
byteSwap32(this.state32);
|
|
176
|
+
this.posOut = 0;
|
|
177
|
+
this.pos = 0;
|
|
178
|
+
}
|
|
179
|
+
update(data) {
|
|
180
|
+
aexists(this);
|
|
181
|
+
const { blockLen, state } = this;
|
|
182
|
+
data = toBytes(data);
|
|
183
|
+
const len = data.length;
|
|
184
|
+
for (let pos = 0; pos < len;) {
|
|
185
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
186
|
+
for (let i = 0; i < take; i++)
|
|
187
|
+
state[this.pos++] ^= data[pos++];
|
|
188
|
+
if (this.pos === blockLen)
|
|
189
|
+
this.keccak();
|
|
190
|
+
}
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
finish() {
|
|
194
|
+
if (this.finished)
|
|
195
|
+
return;
|
|
196
|
+
this.finished = true;
|
|
197
|
+
const { state, suffix, pos, blockLen } = this;
|
|
198
|
+
// Do the padding
|
|
199
|
+
state[pos] ^= suffix;
|
|
200
|
+
if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
|
|
201
|
+
this.keccak();
|
|
202
|
+
state[blockLen - 1] ^= 0x80;
|
|
203
|
+
this.keccak();
|
|
204
|
+
}
|
|
205
|
+
writeInto(out) {
|
|
206
|
+
aexists(this, false);
|
|
207
|
+
abytes(out);
|
|
208
|
+
this.finish();
|
|
209
|
+
const bufferOut = this.state;
|
|
210
|
+
const { blockLen } = this;
|
|
211
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
212
|
+
if (this.posOut >= blockLen)
|
|
213
|
+
this.keccak();
|
|
214
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
215
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
216
|
+
this.posOut += take;
|
|
217
|
+
pos += take;
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
xofInto(out) {
|
|
222
|
+
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
|
223
|
+
if (!this.enableXOF)
|
|
224
|
+
throw new Error('XOF is not possible for this instance');
|
|
225
|
+
return this.writeInto(out);
|
|
226
|
+
}
|
|
227
|
+
xof(bytes) {
|
|
228
|
+
anumber(bytes);
|
|
229
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
230
|
+
}
|
|
231
|
+
digestInto(out) {
|
|
232
|
+
aoutput(out, this);
|
|
233
|
+
if (this.finished)
|
|
234
|
+
throw new Error('digest() was already called');
|
|
235
|
+
this.writeInto(out);
|
|
236
|
+
this.destroy();
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
digest() {
|
|
240
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
241
|
+
}
|
|
242
|
+
destroy() {
|
|
243
|
+
this.destroyed = true;
|
|
244
|
+
this.state.fill(0);
|
|
245
|
+
}
|
|
246
|
+
_cloneInto(to) {
|
|
247
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
248
|
+
to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
249
|
+
to.state32.set(this.state32);
|
|
250
|
+
to.pos = this.pos;
|
|
251
|
+
to.posOut = this.posOut;
|
|
252
|
+
to.finished = this.finished;
|
|
253
|
+
to.rounds = rounds;
|
|
254
|
+
// Suffix can change in cSHAKE
|
|
255
|
+
to.suffix = suffix;
|
|
256
|
+
to.outputLen = outputLen;
|
|
257
|
+
to.enableXOF = enableXOF;
|
|
258
|
+
to.destroyed = this.destroyed;
|
|
259
|
+
return to;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
|
|
263
|
+
/** SHA3-224 hash function. */
|
|
264
|
+
export const sha3_224 = /* @__PURE__ */ gen(0x06, 144, 224 / 8);
|
|
265
|
+
/** SHA3-256 hash function. Different from keccak-256. */
|
|
266
|
+
export const sha3_256 = /* @__PURE__ */ gen(0x06, 136, 256 / 8);
|
|
267
|
+
/** SHA3-384 hash function. */
|
|
268
|
+
export const sha3_384 = /* @__PURE__ */ gen(0x06, 104, 384 / 8);
|
|
269
|
+
/** SHA3-512 hash function. */
|
|
270
|
+
export const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
|
|
271
|
+
/** keccak-224 hash function. */
|
|
272
|
+
export const keccak_224 = /* @__PURE__ */ gen(0x01, 144, 224 / 8);
|
|
273
|
+
/** keccak-256 hash function. Different from SHA3-256. */
|
|
274
|
+
export const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
|
|
275
|
+
/** keccak-384 hash function. */
|
|
276
|
+
export const keccak_384 = /* @__PURE__ */ gen(0x01, 104, 384 / 8);
|
|
277
|
+
/** keccak-512 hash function. */
|
|
278
|
+
export const keccak_512 = /* @__PURE__ */ gen(0x01, 72, 512 / 8);
|
|
279
|
+
const genShake = (suffix, blockLen, outputLen) => wrapXOFConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
|
|
280
|
+
/** SHAKE128 XOF with 128-bit security. */
|
|
281
|
+
export const shake128 = /* @__PURE__ */ genShake(0x1f, 168, 128 / 8);
|
|
282
|
+
/** SHAKE256 XOF with 256-bit security. */
|
|
283
|
+
export const shake256 = /* @__PURE__ */ genShake(0x1f, 136, 256 / 8);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for hex, bytes, CSPRNG.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
+
export declare function isBytes(a: unknown): a is Uint8Array;
|
|
7
|
+
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
|
|
8
|
+
export declare function u8(arr: TypedArray): Uint8Array;
|
|
9
|
+
export declare function u32(arr: TypedArray): Uint32Array;
|
|
10
|
+
export declare function createView(arr: TypedArray): DataView;
|
|
11
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
|
12
|
+
export declare function rotr(word: number, shift: number): number;
|
|
13
|
+
/** The rotate left (circular left shift) operation for uint32 */
|
|
14
|
+
export declare function rotl(word: number, shift: number): number;
|
|
15
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
16
|
+
export declare const isLE: boolean;
|
|
17
|
+
export declare function byteSwap(word: number): number;
|
|
18
|
+
/** Conditionally byte swap if on a big-endian platform */
|
|
19
|
+
export declare const byteSwapIfBE: (n: number) => number;
|
|
20
|
+
/** In place byte swap for Uint32Array */
|
|
21
|
+
export declare function byteSwap32(arr: Uint32Array): void;
|
|
22
|
+
/**
|
|
23
|
+
* Convert byte array to hex string.
|
|
24
|
+
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
25
|
+
*/
|
|
26
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
27
|
+
/**
|
|
28
|
+
* Convert hex string to byte array.
|
|
29
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
30
|
+
*/
|
|
31
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* There is no setImmediate in browser and setTimeout is slow.
|
|
34
|
+
* Call of async fn will return Promise, which will be fullfiled only on
|
|
35
|
+
* next scheduler queue processing step and this is exactly what we need.
|
|
36
|
+
*/
|
|
37
|
+
export declare const nextTick: () => Promise<void>;
|
|
38
|
+
/** Returns control to thread each 'tick' ms to avoid blocking. */
|
|
39
|
+
export declare function asyncLoop(iters: number, tick: number, cb: (i: number) => void): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Convert JS string to byte array.
|
|
42
|
+
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
43
|
+
*/
|
|
44
|
+
export declare function utf8ToBytes(str: string): Uint8Array;
|
|
45
|
+
/** Accepted input of hash functions. Strings are converted to byte arrays. */
|
|
46
|
+
export type Input = Uint8Array | string;
|
|
47
|
+
/**
|
|
48
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
49
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
50
|
+
* Keep in mind for future mutable operations.
|
|
51
|
+
*/
|
|
52
|
+
export declare function toBytes(data: Input): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* Copies several Uint8Arrays into one.
|
|
55
|
+
*/
|
|
56
|
+
export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
57
|
+
/** For runtime check if class implements interface */
|
|
58
|
+
export declare abstract class Hash<T extends Hash<T>> {
|
|
59
|
+
abstract blockLen: number;
|
|
60
|
+
abstract outputLen: number;
|
|
61
|
+
abstract update(buf: Input): this;
|
|
62
|
+
abstract digestInto(buf: Uint8Array): void;
|
|
63
|
+
abstract digest(): Uint8Array;
|
|
64
|
+
/**
|
|
65
|
+
* Resets internal state. Makes Hash instance unusable.
|
|
66
|
+
* Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
|
|
67
|
+
* by user, they will need to manually call `destroy()` when zeroing is necessary.
|
|
68
|
+
*/
|
|
69
|
+
abstract destroy(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`
|
|
72
|
+
* when no options are passed.
|
|
73
|
+
* Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal
|
|
74
|
+
* buffers are overwritten => causes buffer overwrite which is used for digest in some cases.
|
|
75
|
+
* There are no guarantees for clean-up because it's impossible in JS.
|
|
76
|
+
*/
|
|
77
|
+
abstract _cloneInto(to?: T): T;
|
|
78
|
+
clone(): T;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* XOF: streaming API to read digest in chunks.
|
|
82
|
+
* Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.
|
|
83
|
+
* When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot
|
|
84
|
+
* destroy state, next call can require more bytes.
|
|
85
|
+
*/
|
|
86
|
+
export type HashXOF<T extends Hash<T>> = Hash<T> & {
|
|
87
|
+
xof(bytes: number): Uint8Array;
|
|
88
|
+
xofInto(buf: Uint8Array): Uint8Array;
|
|
89
|
+
};
|
|
90
|
+
type EmptyObj = {};
|
|
91
|
+
export declare function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(defaults: T1, opts?: T2): T1 & T2;
|
|
92
|
+
/** Hash function */
|
|
93
|
+
export type CHash = ReturnType<typeof wrapConstructor>;
|
|
94
|
+
/** Hash function with output */
|
|
95
|
+
export type CHashO = ReturnType<typeof wrapConstructorWithOpts>;
|
|
96
|
+
/** XOF with output */
|
|
97
|
+
export type CHashXO = ReturnType<typeof wrapXOFConstructorWithOpts>;
|
|
98
|
+
/** Wraps hash function, creating an interface on top of it */
|
|
99
|
+
export declare function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>): {
|
|
100
|
+
(msg: Input): Uint8Array;
|
|
101
|
+
outputLen: number;
|
|
102
|
+
blockLen: number;
|
|
103
|
+
create(): Hash<T>;
|
|
104
|
+
};
|
|
105
|
+
export declare function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(hashCons: (opts?: T) => Hash<H>): {
|
|
106
|
+
(msg: Input, opts?: T): Uint8Array;
|
|
107
|
+
outputLen: number;
|
|
108
|
+
blockLen: number;
|
|
109
|
+
create(opts: T): Hash<H>;
|
|
110
|
+
};
|
|
111
|
+
export declare function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(hashCons: (opts?: T) => HashXOF<H>): {
|
|
112
|
+
(msg: Input, opts?: T): Uint8Array;
|
|
113
|
+
outputLen: number;
|
|
114
|
+
blockLen: number;
|
|
115
|
+
create(opts: T): HashXOF<H>;
|
|
116
|
+
};
|
|
117
|
+
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
118
|
+
export declare function randomBytes(bytesLength?: number): Uint8Array;
|
|
119
|
+
export {};
|
|
120
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@noble/hashes/1.7.1/src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AAYtE,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAEnD;AAGD,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,iBAAiB,GAAG,UAAU,GACjE,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;AAGtD,wBAAgB,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAE9C;AACD,wBAAgB,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,CAEhD;AAGD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,QAAQ,CAEpD;AAED,mEAAmE;AACnE,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAA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