rapidhash-js 2.2.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +100 -53
  3. package/lib/common.d.mts +7 -0
  4. package/lib/common.d.ts +7 -0
  5. package/lib/common.js +167 -0
  6. package/lib/common.js.map +1 -0
  7. package/lib/common.mjs +96 -0
  8. package/lib/common.mjs.map +1 -0
  9. package/lib/common_v2.js +26 -0
  10. package/lib/common_v2.js.map +1 -0
  11. package/lib/common_v2.mjs +15 -0
  12. package/lib/common_v2.mjs.map +1 -0
  13. package/lib/index.d.mts +2 -91
  14. package/lib/index.d.ts +2 -91
  15. package/lib/index.js +11 -467
  16. package/lib/index.mjs +1 -429
  17. package/lib/v1.0/index.d.mts +30 -0
  18. package/lib/v1.0/index.d.ts +30 -0
  19. package/lib/v1.0/index.js +106 -0
  20. package/lib/v1.0/index.js.map +1 -0
  21. package/lib/v1.0/index.mjs +103 -0
  22. package/lib/v1.0/index.mjs.map +1 -0
  23. package/lib/v2.0/index.d.mts +30 -0
  24. package/lib/v2.0/index.d.ts +30 -0
  25. package/lib/v2.0/index.js +128 -0
  26. package/lib/v2.0/index.js.map +1 -0
  27. package/lib/v2.0/index.mjs +125 -0
  28. package/lib/v2.0/index.mjs.map +1 -0
  29. package/lib/v2.2/index.d.mts +30 -0
  30. package/lib/v2.2/index.d.ts +30 -0
  31. package/lib/v2.2/index.js +128 -0
  32. package/lib/v2.2/index.js.map +1 -0
  33. package/lib/v2.2/index.mjs +125 -0
  34. package/lib/v2.2/index.mjs.map +1 -0
  35. package/lib/v3.0/index.d.mts +86 -0
  36. package/lib/v3.0/index.d.ts +86 -0
  37. package/lib/v3.0/index.js +11 -0
  38. package/lib/v3.0/index.mjs +1 -0
  39. package/lib/v3.0.js +407 -0
  40. package/lib/v3.0.js.map +1 -0
  41. package/lib/v3.0.mjs +354 -0
  42. package/lib/v3.0.mjs.map +1 -0
  43. package/package.json +23 -15
  44. package/lib/index.js.map +0 -1
  45. package/lib/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.1] - 2026-11-16
4
+
5
+ - Export `rapidhashMicro` and `rapidhashNano` (and their `_fast` / `_protected` functions) from the package root. The README documented importing them from `rapidhash-js`, but they were only available from `rapidhash-js/v3.0` ([#4](https://github.com/komiya-atsushi/rapidhash-js/issues/4)).
6
+
7
+ ## [3.0.0] - 2025-11-24
8
+
9
+ - Implement [rapidhash v3.0](https://github.com/Nicoshev/rapidhash).
10
+ - Add `rapidhashMicro` and `rapidhashNano` variants (v3.0 only).
11
+ - Add version-specific entry points: `rapidhash-js/v1.0`, `rapidhash-js/v2.0`, `rapidhash-js/v2.2`, and `rapidhash-js/v3.0`.
12
+ - **Breaking:** The functions `rapidhash()`, `rapidhash_fast()`, and `rapidhash_protected()` are now implemented with the v3.0 algorithm. To use v2.2, import from `rapidhash-js/v2.2`.
13
+
3
14
  ## [2.2.0] - 2025-05-29
4
15
 
5
16
  - Implement [rapidhash v2.2](https://github.com/Nicoshev/rapidhash/pull/23).
package/README.md CHANGED
@@ -19,94 +19,141 @@ npm install rapidhash-js
19
19
 
20
20
  ```typescript
21
21
  import {
22
- // The functions rapidhash, rapidhash_fast, and rapidhash_protected currently implement the v2.2 algorithm.
22
+ // These functions currently use the v3.0 implementation.
23
23
  rapidhash,
24
24
  rapidhash_fast,
25
25
  rapidhash_protected,
26
- // To use the old v1 algorithm, import rapidhash_v1 (or rapidhash_v1_fast, rapidhash_v1_protected) instead.
27
- rapidhash_v1,
26
+ // rapidhashMicro and rapidhashNano are additional variants in v3.0
27
+ rapidhashMicro,
28
+ rapidhashNano,
28
29
  } from 'rapidhash-js';
29
30
 
30
31
  // rapidhash() returns a 64-bit hash value represented as bigint.
31
- console.log(rapidhash('hello world')); // Output: 1722744455612372674n
32
+ console.log(rapidhash('hello world'));
32
33
 
33
34
  // You can specify a 64-bit seed value with the 'seed' option.
34
- console.log(rapidhash('hello world', {seed: 0x0123_4567_89AB_CDEFn})); // Output: 13409940373860458135n
35
+ console.log(rapidhash('hello world', {seed: 0x0123_4567_89AB_CDEFn}));
35
36
 
36
- // You can specify the behavior of the rapid_mum() function
37
- // with the rapidMumBehaviour option (default is 'fast').
38
- console.log(rapidhash('hello world', {rapidMumBehaviour: 'protected'})); // Output: 12365338091610779222n
37
+ // You can control rapid_mum() behavior with the rapidMumBehaviour option (default: 'fast').
38
+ console.log(rapidhash('hello world', {rapidMumBehaviour: 'protected'}));
39
39
 
40
40
  // Instead of specifying the rapidMumBehaviour option,
41
41
  // you can call rapidhash_fast() or rapidhash_protected().
42
42
  console.log(rapidhash_protected('hello world'));
43
+
44
+ // rapidhashMicro and rapidhashNano are optimized variants with smaller loop blocks
45
+ console.log(rapidhashMicro('hello world'));
46
+ console.log(rapidhashNano('hello world'));
47
+ ```
48
+
49
+ ### Using older versions
50
+
51
+ To use older versions of the algorithm, import from version-specific entry points:
52
+
53
+ ```typescript
54
+ // v2.2
55
+ import { rapidhash, rapidhash_fast, rapidhash_protected } from 'rapidhash-js/v2.2';
56
+
57
+ // v2.0
58
+ import { rapidhash, rapidhash_fast, rapidhash_protected } from 'rapidhash-js/v2.0';
59
+
60
+ // v1.0
61
+ import { rapidhash, rapidhash_fast, rapidhash_protected } from 'rapidhash-js/v1.0';
43
62
  ```
44
63
 
45
64
  ## Benchmark
46
65
 
47
66
  <details>
48
- <summary>Apple M3 Max</summary>
67
+ <summary>GitHub Actions runner</summary>
49
68
 
50
69
  ```
51
70
  [Benchmark Environment]
52
- Node.js: v22.15.1
53
- CPU: Apple M3 Max (16 cores, 2400 MHz)
71
+ Node.js: v22.21.1
72
+ CPU: AMD EPYC 7763 64-Core Processor (4 cores, 0 MHz)
54
73
 
55
74
  [1-4 bytes]
56
- [v1.0] rapidhash (fast) : 6,285,122.13 ops/s (159.11 ns/iter)
57
- [v1.0] rapidhash (protected) : 5,358,496.06 ops/s (186.62 ns/iter)
58
- [v2.0] rapidhash (fast) : 6,751,586.61 ops/s (148.11 ns/iter)
59
- [v2.0] rapidhash (protected) : 5,503,585.53 ops/s (181.70 ns/iter)
60
- [v2.2] rapidhash (fast) : 6,713,669.81 ops/s (148.95 ns/iter)
61
- [v2.2] rapidhash (protected) : 5,474,441.63 ops/s (182.67 ns/iter)
75
+ [v1.0] rapidhash (fast) : 2,420,375.33 ops/s (413.16 ns/iter)
76
+ [v1.0] rapidhash (protected) : 2,030,644.31 ops/s (492.45 ns/iter)
77
+ [v2.2] rapidhash (fast) : 2,734,729.69 ops/s (365.67 ns/iter)
78
+ [v2.2] rapidhash (protected) : 2,197,545.98 ops/s (455.05 ns/iter)
79
+ [v3.0] rapidhash (fast) : 2,674,325.05 ops/s (373.93 ns/iter)
80
+ [v3.0] rapidhash (protected) : 2,226,115.44 ops/s (449.21 ns/iter)
81
+ [v3.0] rapidhashMicro (fast) : 2,710,931.05 ops/s (368.88 ns/iter)
82
+ [v3.0] rapidhashMicro (protected) : 2,213,185.82 ops/s (451.84 ns/iter)
83
+ [v3.0] rapidhashNano (fast) : 2,655,616.94 ops/s (376.56 ns/iter)
84
+ [v3.0] rapidhashNano (protected) : 2,231,395.19 ops/s (448.15 ns/iter)
62
85
 
63
86
  [5-8 bytes]
64
- [v1.0] rapidhash (fast) : 5,995,195.47 ops/s (166.80 ns/iter)
65
- [v1.0] rapidhash (protected) : 5,129,620.76 ops/s (194.95 ns/iter)
66
- [v2.0] rapidhash (fast) : 6,217,065.60 ops/s (160.85 ns/iter)
67
- [v2.0] rapidhash (protected) : 5,326,035.89 ops/s (187.76 ns/iter)
68
- [v2.2] rapidhash (fast) : 6,050,308.59 ops/s (165.28 ns/iter)
69
- [v2.2] rapidhash (protected) : 5,344,429.93 ops/s (187.11 ns/iter)
87
+ [v1.0] rapidhash (fast) : 2,371,330.83 ops/s (421.70 ns/iter)
88
+ [v1.0] rapidhash (protected) : 2,015,037.92 ops/s (496.27 ns/iter)
89
+ [v2.2] rapidhash (fast) : 2,525,306.66 ops/s (395.99 ns/iter)
90
+ [v2.2] rapidhash (protected) : 2,151,700.91 ops/s (464.75 ns/iter)
91
+ [v3.0] rapidhash (fast) : 2,398,649.67 ops/s (416.90 ns/iter)
92
+ [v3.0] rapidhash (protected) : 2,115,376.44 ops/s (472.73 ns/iter)
93
+ [v3.0] rapidhashMicro (fast) : 2,419,115.71 ops/s (413.37 ns/iter)
94
+ [v3.0] rapidhashMicro (protected) : 2,112,217.87 ops/s (473.44 ns/iter)
95
+ [v3.0] rapidhashNano (fast) : 2,464,902.12 ops/s (405.70 ns/iter)
96
+ [v3.0] rapidhashNano (protected) : 2,139,688.49 ops/s (467.36 ns/iter)
70
97
 
71
98
  [9-16 bytes]
72
- [v1.0] rapidhash (fast) : 5,986,726.82 ops/s (167.04 ns/iter)
73
- [v1.0] rapidhash (protected) : 5,154,979.68 ops/s (193.99 ns/iter)
74
- [v2.0] rapidhash (fast) : 6,131,914.48 ops/s (163.08 ns/iter)
75
- [v2.0] rapidhash (protected) : 5,321,633.57 ops/s (187.91 ns/iter)
76
- [v2.2] rapidhash (fast) : 6,247,440.63 ops/s (160.07 ns/iter)
77
- [v2.2] rapidhash (protected) : 5,351,510.81 ops/s (186.86 ns/iter)
99
+ [v1.0] rapidhash (fast) : 2,373,128.45 ops/s (421.38 ns/iter)
100
+ [v1.0] rapidhash (protected) : 2,019,580.56 ops/s (495.15 ns/iter)
101
+ [v2.2] rapidhash (fast) : 2,494,555.85 ops/s (400.87 ns/iter)
102
+ [v2.2] rapidhash (protected) : 2,164,351.62 ops/s (462.03 ns/iter)
103
+ [v3.0] rapidhash (fast) : 2,445,111.08 ops/s (408.98 ns/iter)
104
+ [v3.0] rapidhash (protected) : 2,124,576.46 ops/s (470.68 ns/iter)
105
+ [v3.0] rapidhashMicro (fast) : 2,534,830.67 ops/s (394.50 ns/iter)
106
+ [v3.0] rapidhashMicro (protected) : 2,144,787.46 ops/s (466.25 ns/iter)
107
+ [v3.0] rapidhashNano (fast) : 2,507,392.59 ops/s (398.82 ns/iter)
108
+ [v3.0] rapidhashNano (protected) : 2,159,198.42 ops/s (463.13 ns/iter)
78
109
 
79
110
  [17-64 bytes]
80
- [v1.0] rapidhash (fast) : 3,843,646.47 ops/s (260.17 ns/iter)
81
- [v1.0] rapidhash (protected) : 3,312,988.79 ops/s (301.84 ns/iter)
82
- [v2.0] rapidhash (fast) : 3,947,650.45 ops/s (253.32 ns/iter)
83
- [v2.0] rapidhash (protected) : 3,390,062.69 ops/s (294.98 ns/iter)
84
- [v2.2] rapidhash (fast) : 4,039,784.70 ops/s (247.54 ns/iter)
85
- [v2.2] rapidhash (protected) : 3,400,339.38 ops/s (294.09 ns/iter)
111
+ [v1.0] rapidhash (fast) : 1,519,363.59 ops/s (658.17 ns/iter)
112
+ [v1.0] rapidhash (protected) : 1,308,565.57 ops/s (764.20 ns/iter)
113
+ [v2.2] rapidhash (fast) : 1,627,131.71 ops/s (614.58 ns/iter)
114
+ [v2.2] rapidhash (protected) : 1,358,146.83 ops/s (736.30 ns/iter)
115
+ [v3.0] rapidhash (fast) : 1,557,365.74 ops/s (642.11 ns/iter)
116
+ [v3.0] rapidhash (protected) : 1,278,365.66 ops/s (782.25 ns/iter)
117
+ [v3.0] rapidhashMicro (fast) : 1,566,121.67 ops/s (638.52 ns/iter)
118
+ [v3.0] rapidhashMicro (protected) : 1,309,712.62 ops/s (763.53 ns/iter)
119
+ [v3.0] rapidhashNano (fast) : 1,522,941.99 ops/s (656.62 ns/iter)
120
+ [v3.0] rapidhashNano (protected) : 1,287,697.13 ops/s (776.58 ns/iter)
86
121
 
87
122
  [65-111 bytes]
88
- [v1.0] rapidhash (fast) : 2,539,382.14 ops/s (393.80 ns/iter)
89
- [v1.0] rapidhash (protected) : 2,156,257.28 ops/s (463.77 ns/iter)
90
- [v2.0] rapidhash (fast) : 2,580,829.71 ops/s (387.47 ns/iter)
91
- [v2.0] rapidhash (protected) : 2,186,335.35 ops/s (457.39 ns/iter)
92
- [v2.2] rapidhash (fast) : 2,545,090.54 ops/s (392.91 ns/iter)
93
- [v2.2] rapidhash (protected) : 2,189,080.78 ops/s (456.81 ns/iter)
123
+ [v1.0] rapidhash (fast) : 1,012,019.84 ops/s (988.12 ns/iter)
124
+ [v1.0] rapidhash (protected) : 851,571.85 ops/s (1174.30 ns/iter)
125
+ [v2.2] rapidhash (fast) : 1,032,261.69 ops/s (968.75 ns/iter)
126
+ [v2.2] rapidhash (protected) : 873,368.59 ops/s (1144.99 ns/iter)
127
+ [v3.0] rapidhash (fast) : 1,049,513.86 ops/s (952.82 ns/iter)
128
+ [v3.0] rapidhash (protected) : 875,091.75 ops/s (1142.74 ns/iter)
129
+ [v3.0] rapidhashMicro (fast) : 1,008,137.11 ops/s (991.93 ns/iter)
130
+ [v3.0] rapidhashMicro (protected) : 843,635.34 ops/s (1185.35 ns/iter)
131
+ [v3.0] rapidhashNano (fast) : 1,019,000.92 ops/s (981.35 ns/iter)
132
+ [v3.0] rapidhashNano (protected) : 846,423.68 ops/s (1181.44 ns/iter)
94
133
 
95
134
  [112-256 bytes]
96
- [v1.0] rapidhash (fast) : 1,518,423.71 ops/s (658.58 ns/iter)
97
- [v1.0] rapidhash (protected) : 1,274,445.41 ops/s (784.66 ns/iter)
98
- [v2.0] rapidhash (fast) : 1,484,277.31 ops/s (673.73 ns/iter)
99
- [v2.0] rapidhash (protected) : 1,258,892.94 ops/s (794.35 ns/iter)
100
- [v2.2] rapidhash (fast) : 1,525,211.09 ops/s (655.65 ns/iter)
101
- [v2.2] rapidhash (protected) : 1,293,585.65 ops/s (773.05 ns/iter)
135
+ [v1.0] rapidhash (fast) : 614,172.98 ops/s (1.63 µs/iter)
136
+ [v1.0] rapidhash (protected) : 513,971.04 ops/s (1.95 µs/iter)
137
+ [v2.2] rapidhash (fast) : 610,816.92 ops/s (1.64 µs/iter)
138
+ [v2.2] rapidhash (protected) : 517,844.27 ops/s (1.93 µs/iter)
139
+ [v3.0] rapidhash (fast) : 594,643.45 ops/s (1.68 µs/iter)
140
+ [v3.0] rapidhash (protected) : 499,762.62 ops/s (2.00 µs/iter)
141
+ [v3.0] rapidhashMicro (fast) : 617,073.02 ops/s (1.62 µs/iter)
142
+ [v3.0] rapidhashMicro (protected) : 505,441.57 ops/s (1.98 µs/iter)
143
+ [v3.0] rapidhashNano (fast) : 625,289.65 ops/s (1.60 µs/iter)
144
+ [v3.0] rapidhashNano (protected) : 511,777.23 ops/s (1.95 µs/iter)
102
145
 
103
146
  [1M bytes]
104
- [v1.0] rapidhash (fast) : 356.49 ops/s (2.81 ms/iter)
105
- [v1.0] rapidhash (protected) : 296.16 ops/s (3.38 ms/iter)
106
- [v2.0] rapidhash (fast) : 375.05 ops/s (2.67 ms/iter)
107
- [v2.0] rapidhash (protected) : 309.03 ops/s (3.24 ms/iter)
108
- [v2.2] rapidhash (fast) : 374.26 ops/s (2.67 ms/iter)
109
- [v2.2] rapidhash (protected) : 309.25 ops/s (3.23 ms/iter)
147
+ [v1.0] rapidhash (fast) : 147.45 ops/s (6.78 ms/iter)
148
+ [v1.0] rapidhash (protected) : 121.19 ops/s (8.25 ms/iter)
149
+ [v2.2] rapidhash (fast) : 152.66 ops/s (6.55 ms/iter)
150
+ [v2.2] rapidhash (protected) : 125.51 ops/s (7.97 ms/iter)
151
+ [v3.0] rapidhash (fast) : 153.71 ops/s (6.51 ms/iter)
152
+ [v3.0] rapidhash (protected) : 121.11 ops/s (8.26 ms/iter)
153
+ [v3.0] rapidhashMicro (fast) : 153.73 ops/s (6.50 ms/iter)
154
+ [v3.0] rapidhashMicro (protected) : 121.58 ops/s (8.23 ms/iter)
155
+ [v3.0] rapidhashNano (fast) : 152.79 ops/s (6.54 ms/iter)
156
+ [v3.0] rapidhashNano (protected) : 120.72 ops/s (8.28 ms/iter)
110
157
  ```
111
158
 
112
159
  </details>
@@ -0,0 +1,7 @@
1
+ type RapidMumBehaviour = 'fast' | 'protected';
2
+ interface RapidhashOptions {
3
+ seed: bigint;
4
+ rapidMumBehaviour: RapidMumBehaviour;
5
+ }
6
+ export { RapidhashOptions as t };
7
+ //# sourceMappingURL=common.d.mts.map
@@ -0,0 +1,7 @@
1
+ type RapidMumBehaviour = 'fast' | 'protected';
2
+ interface RapidhashOptions {
3
+ seed: bigint;
4
+ rapidMumBehaviour: RapidMumBehaviour;
5
+ }
6
+ export { RapidhashOptions as t };
7
+ //# sourceMappingURL=common.d.ts.map
package/lib/common.js ADDED
@@ -0,0 +1,167 @@
1
+ // src/common.ts
2
+ function rapid_mix_fast(a, b) {
3
+ const m = a * b;
4
+ return BigInt.asUintN(64, m) ^ m >> 64n;
5
+ }
6
+ function rapidhash_epilogue_fast(a, b, secretA, secretB, len) {
7
+ const m0 = a * b;
8
+ const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * (m0 >> 64n ^ secretB);
9
+ return BigInt.asUintN(64, m1) ^ m1 >> 64n;
10
+ }
11
+ function rapid_mix_protected(a, b) {
12
+ const m = a * b;
13
+ return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
14
+ }
15
+ function rapidhash_epilogue_protected(a0, b0, secretA, secretB, len) {
16
+ const m0 = a0 * b0;
17
+ const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;
18
+ const b1 = m0 >> 64n ^ secretB ^ b0;
19
+ const m1 = a1 * b1;
20
+ return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
21
+ }
22
+ const read32x2View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
23
+ function rapid_read32x2(buf, offset1, offset2) {
24
+ read32x2View.setUint32(4, buf.getUint32(offset1, true), true);
25
+ read32x2View.setUint32(0, buf.getUint32(offset2, true), true);
26
+ return read32x2View.getBigUint64(0, true);
27
+ }
28
+ const read32View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
29
+ function rapid_read32(buf, offset) {
30
+ read32View.setUint32(0, buf.getUint32(offset, true), true);
31
+ return read32View.getBigUint64(0, true);
32
+ }
33
+ function rapid_read64(buf, offset) {
34
+ return buf.getBigUint64(offset, true);
35
+ }
36
+ const readSmallBuffer = /* @__PURE__ */ new Uint8Array(8);
37
+ const readSmallView = new DataView(readSmallBuffer.buffer);
38
+ function rapid_readSmall(buf, offset, k) {
39
+ readSmallBuffer[7] = buf.getUint8(offset);
40
+ readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));
41
+ readSmallBuffer[0] = buf.getUint8(offset + k - 1);
42
+ return readSmallView.getBigUint64(0, true);
43
+ }
44
+ const readBytesBuffer = /* @__PURE__ */ new Uint8Array(8);
45
+ const readBytesView = new DataView(readBytesBuffer.buffer);
46
+ function rapid_readBytes(buf, offset1, offset2) {
47
+ readBytesBuffer[0] = buf.getUint8(offset2);
48
+ readBytesBuffer[7] = buf.getUint8(offset1);
49
+ return readBytesView.getBigUint64(0, true);
50
+ }
51
+ const textEncoder = new TextEncoder();
52
+ const utf8BufferSize = 2048;
53
+ const stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
54
+ const utf8Buffer = new Uint8Array(utf8BufferSize);
55
+ function toDataView(message) {
56
+ if (typeof message === "string") {
57
+ if (message.length <= stringLengthThresholdToUseBuffer) {
58
+ const { written } = textEncoder.encodeInto(message, utf8Buffer);
59
+ return new DataView(utf8Buffer.buffer, 0, written);
60
+ }
61
+ const utf8bytes = textEncoder.encode(message);
62
+ return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
63
+ }
64
+ if (message instanceof Uint8Array) return new DataView(message.buffer, message.byteOffset, message.byteLength);
65
+ return message;
66
+ }
67
+ const defaultRapidMumBehaviour = "fast";
68
+ const rapidMumImplementations = {
69
+ fast: {
70
+ rapid_mix: rapid_mix_fast,
71
+ rapidhash_epilogue: rapidhash_epilogue_fast
72
+ },
73
+ protected: {
74
+ rapid_mix: rapid_mix_protected,
75
+ rapidhash_epilogue: rapidhash_epilogue_protected
76
+ }
77
+ };
78
+ function isBigUint64(value) {
79
+ return value >= 0n && value <= 18446744073709551615n;
80
+ }
81
+ function validateOptions(options, defaultSeed) {
82
+ const result = {
83
+ seed: defaultSeed,
84
+ rapidMumBehaviour: defaultRapidMumBehaviour
85
+ };
86
+ if (options === void 0) return result;
87
+ if (options.seed !== void 0) {
88
+ if (!isBigUint64(options.seed)) throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
89
+ result.seed = options.seed;
90
+ }
91
+ if (options.rapidMumBehaviour !== void 0) result.rapidMumBehaviour = options.rapidMumBehaviour;
92
+ return result;
93
+ }
94
+ Object.defineProperty(exports, "rapidMumImplementations", {
95
+ enumerable: true,
96
+ get: function() {
97
+ return rapidMumImplementations;
98
+ }
99
+ });
100
+ Object.defineProperty(exports, "rapid_mix_fast", {
101
+ enumerable: true,
102
+ get: function() {
103
+ return rapid_mix_fast;
104
+ }
105
+ });
106
+ Object.defineProperty(exports, "rapid_mix_protected", {
107
+ enumerable: true,
108
+ get: function() {
109
+ return rapid_mix_protected;
110
+ }
111
+ });
112
+ Object.defineProperty(exports, "rapid_read32", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return rapid_read32;
116
+ }
117
+ });
118
+ Object.defineProperty(exports, "rapid_read32x2", {
119
+ enumerable: true,
120
+ get: function() {
121
+ return rapid_read32x2;
122
+ }
123
+ });
124
+ Object.defineProperty(exports, "rapid_read64", {
125
+ enumerable: true,
126
+ get: function() {
127
+ return rapid_read64;
128
+ }
129
+ });
130
+ Object.defineProperty(exports, "rapid_readBytes", {
131
+ enumerable: true,
132
+ get: function() {
133
+ return rapid_readBytes;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, "rapid_readSmall", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return rapid_readSmall;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, "rapidhash_epilogue_fast", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return rapidhash_epilogue_fast;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "rapidhash_epilogue_protected", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return rapidhash_epilogue_protected;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "toDataView", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return toDataView;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, "validateOptions", {
161
+ enumerable: true,
162
+ get: function() {
163
+ return validateOptions;
164
+ }
165
+ });
166
+
167
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","names":[],"sources":["../src/common.ts"],"sourcesContent":["export type RapidMix = (a: bigint, b: bigint) => bigint;\nexport type RapidhashEpilogue = (a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint) => bigint;\n\nexport function rapid_mix_fast(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n);\n}\n\nexport function rapidhash_epilogue_fast(a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint): bigint {\n const m0 = a * b;\n const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * ((m0 >> 64n) ^ secretB);\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n);\n}\n\nexport function rapid_mix_protected(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n) ^ a ^ b;\n}\n\nexport function rapidhash_epilogue_protected(\n a0: bigint,\n b0: bigint,\n secretA: bigint,\n secretB: bigint,\n len: bigint,\n): bigint {\n const m0 = a0 * b0;\n const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;\n const b1 = (m0 >> 64n) ^ secretB ^ b0;\n const m1 = a1 * b1;\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n) ^ a1 ^ b1;\n}\n\n// ---\n\nconst read32x2Buffer = new Uint8Array(8);\nconst read32x2View = new DataView(read32x2Buffer.buffer);\n\nexport function rapid_read32x2(buf: DataView, offset1: number, offset2: number): bigint {\n read32x2View.setUint32(4, buf.getUint32(offset1, true), true);\n read32x2View.setUint32(0, buf.getUint32(offset2, true), true);\n return read32x2View.getBigUint64(0, true);\n}\n\nconst read32Buffer = new Uint8Array(8);\nconst read32View = new DataView(read32Buffer.buffer);\n\nexport function rapid_read32(buf: DataView, offset: number): bigint {\n read32View.setUint32(0, buf.getUint32(offset, true), true);\n return read32View.getBigUint64(0, true);\n}\n\nexport function rapid_read64(buf: DataView, offset: number): bigint {\n return buf.getBigUint64(offset, true);\n}\n\nconst readSmallBuffer = new Uint8Array(8);\nconst readSmallView = new DataView(readSmallBuffer.buffer);\n\nexport function rapid_readSmall(buf: DataView, offset: number, k: number): bigint {\n readSmallBuffer[7] = buf.getUint8(offset);\n readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));\n readSmallBuffer[0] = buf.getUint8(offset + k - 1);\n return readSmallView.getBigUint64(0, true);\n}\n\nconst readBytesBuffer = new Uint8Array(8);\nconst readBytesView = new DataView(readBytesBuffer.buffer);\n\nexport function rapid_readBytes(buf: DataView, offset1: number, offset2: number): bigint {\n readBytesBuffer[0] = buf.getUint8(offset2);\n readBytesBuffer[7] = buf.getUint8(offset1);\n return readBytesView.getBigUint64(0, true);\n}\n\n// ---\n\nconst textEncoder = new TextEncoder();\nconst utf8BufferSize = 2048;\nconst stringLengthThresholdToUseBuffer = utf8BufferSize / 3;\nconst utf8Buffer = new Uint8Array(utf8BufferSize);\n\nexport function toDataView(message: string | Uint8Array | DataView): DataView {\n if (typeof message === 'string') {\n if (message.length <= stringLengthThresholdToUseBuffer) {\n const {written} = textEncoder.encodeInto(message, utf8Buffer);\n return new DataView(utf8Buffer.buffer, 0, written);\n }\n\n const utf8bytes = textEncoder.encode(message);\n return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);\n }\n\n if (message instanceof Uint8Array) {\n return new DataView(message.buffer, message.byteOffset, message.byteLength);\n }\n\n return message;\n}\n\n// ---\n\nexport type RapidMumBehaviour = 'fast' | 'protected';\nconst defaultRapidMumBehaviour: RapidMumBehaviour = 'fast';\n\nexport interface RapidhashOptions {\n seed: bigint;\n rapidMumBehaviour: RapidMumBehaviour;\n}\n\nexport const rapidMumImplementations: {\n [behaviour in RapidMumBehaviour]: {\n rapid_mix: RapidMix;\n rapidhash_epilogue: RapidhashEpilogue;\n };\n} = {\n fast: {\n rapid_mix: rapid_mix_fast,\n rapidhash_epilogue: rapidhash_epilogue_fast,\n },\n protected: {\n rapid_mix: rapid_mix_protected,\n rapidhash_epilogue: rapidhash_epilogue_protected,\n },\n};\n\nfunction isBigUint64(value: bigint): boolean {\n return value >= 0n && value <= 0xffff_ffff_ffff_ffffn;\n}\n\nexport function validateOptions(options: Partial<RapidhashOptions> | undefined, defaultSeed: bigint): RapidhashOptions {\n const result: RapidhashOptions = {\n seed: defaultSeed,\n rapidMumBehaviour: defaultRapidMumBehaviour,\n };\n\n if (options === undefined) {\n return result;\n }\n\n if (options.seed !== undefined) {\n if (!isBigUint64(options.seed)) {\n throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);\n }\n result.seed = options.seed;\n }\n\n if (options.rapidMumBehaviour !== undefined) {\n result.rapidMumBehaviour = options.rapidMumBehaviour;\n }\n\n return result;\n}\n"],"mappings":";AAGA,SAAgB,eAAe,GAAW,GAAmB;CAC3D,MAAM,IAAI,IAAI;CACd,OAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK;AACvC;AAEA,SAAgB,wBAAwB,GAAW,GAAW,SAAiB,SAAiB,KAAqB;CACnH,MAAM,KAAK,IAAI;CACf,MAAM,MAAM,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,QAAS,MAAM,MAAO;CACrE,OAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM;AACzC;AAEA,SAAgB,oBAAoB,GAAW,GAAmB;CAChE,MAAM,IAAI,IAAI;CACd,OAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK,MAAO,IAAI;AAClD;AAEA,SAAgB,6BACd,IACA,IACA,SACA,SACA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id_mix_fast(a, b) {
3
+ const m = a * b;
4
+ return BigInt.asUintN(64, m) ^ m >> 64n;
5
+ }
6
+ function rapidhash_epilogue_fast(a, b, secretA, secretB, len) {
7
+ const m0 = a * b;
8
+ const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * (m0 >> 64n ^ secretB);
9
+ return BigInt.asUintN(64, m1) ^ m1 >> 64n;
10
+ }
11
+ function rapid_mix_protected(a, b) {
12
+ const m = a * b;
13
+ return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
14
+ }
15
+ function rapidhash_epilogue_protected(a0, b0, secretA, secretB, len) {
16
+ const m0 = a0 * b0;
17
+ const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;
18
+ const b1 = m0 >> 64n ^ secretB ^ b0;
19
+ const m1 = a1 * b1;
20
+ return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
21
+ }
22
+ const read32x2View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
23
+ function rapid_read32x2(buf, offset1, offset2) {
24
+ read32x2View.setUint32(4, buf.getUint32(offset1, true), true);
25
+ read32x2View.setUint32(0, buf.getUint32(offset2, true), true);
26
+ return read32x2View.getBigUint64(0, true);
27
+ }
28
+ const read32View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
29
+ function rapid_read32(buf, offset) {
30
+ read32View.setUint32(0, buf.getUint32(offset, true), true);
31
+ return read32View.getBigUint64(0, true);
32
+ }
33
+ function rapid_read64(buf, offset) {
34
+ return buf.getBigUint64(offset, true);
35
+ }
36
+ const readSmallBuffer = /* @__PURE__ */ new Uint8Array(8);
37
+ const readSmallView = new DataView(readSmallBuffer.buffer);
38
+ function rapid_readSmall(buf, offset, k) {
39
+ readSmallBuffer[7] = buf.getUint8(offset);
40
+ readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));
41
+ readSmallBuffer[0] = buf.getUint8(offset + k - 1);
42
+ return readSmallView.getBigUint64(0, true);
43
+ }
44
+ const readBytesBuffer = /* @__PURE__ */ new Uint8Array(8);
45
+ const readBytesView = new DataView(readBytesBuffer.buffer);
46
+ function rapid_readBytes(buf, offset1, offset2) {
47
+ readBytesBuffer[0] = buf.getUint8(offset2);
48
+ readBytesBuffer[7] = buf.getUint8(offset1);
49
+ return readBytesView.getBigUint64(0, true);
50
+ }
51
+ const textEncoder = new TextEncoder();
52
+ const utf8BufferSize = 2048;
53
+ const stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
54
+ const utf8Buffer = new Uint8Array(utf8BufferSize);
55
+ function toDataView(message) {
56
+ if (typeof message === "string") {
57
+ if (message.length <= stringLengthThresholdToUseBuffer) {
58
+ const { written } = textEncoder.encodeInto(message, utf8Buffer);
59
+ return new DataView(utf8Buffer.buffer, 0, written);
60
+ }
61
+ const utf8bytes = textEncoder.encode(message);
62
+ return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
63
+ }
64
+ if (message instanceof Uint8Array) return new DataView(message.buffer, message.byteOffset, message.byteLength);
65
+ return message;
66
+ }
67
+ const defaultRapidMumBehaviour = "fast";
68
+ const rapidMumImplementations = {
69
+ fast: {
70
+ rapid_mix: rapid_mix_fast,
71
+ rapidhash_epilogue: rapidhash_epilogue_fast
72
+ },
73
+ protected: {
74
+ rapid_mix: rapid_mix_protected,
75
+ rapidhash_epilogue: rapidhash_epilogue_protected
76
+ }
77
+ };
78
+ function isBigUint64(value) {
79
+ return value >= 0n && value <= 18446744073709551615n;
80
+ }
81
+ function validateOptions(options, defaultSeed) {
82
+ const result = {
83
+ seed: defaultSeed,
84
+ rapidMumBehaviour: defaultRapidMumBehaviour
85
+ };
86
+ if (options === void 0) return result;
87
+ if (options.seed !== void 0) {
88
+ if (!isBigUint64(options.seed)) throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
89
+ result.seed = options.seed;
90
+ }
91
+ if (options.rapidMumBehaviour !== void 0) result.rapidMumBehaviour = options.rapidMumBehaviour;
92
+ return result;
93
+ }
94
+ export { rapid_read32x2 as a, rapid_readSmall as c, toDataView as d, validateOptions as f, rapid_read32 as i, rapidhash_epilogue_fast as l, rapid_mix_fast as n, rapid_read64 as o, rapid_mix_protected as r, rapid_readBytes as s, rapidMumImplementations as t, rapidhash_epilogue_protected as u };
95
+
96
+ //# sourceMappingURL=common.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.mjs","names":[],"sources":["../src/common.ts"],"sourcesContent":["export type RapidMix = (a: bigint, b: bigint) => bigint;\nexport type RapidhashEpilogue = (a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint) => bigint;\n\nexport function rapid_mix_fast(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n);\n}\n\nexport function rapidhash_epilogue_fast(a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint): bigint {\n const m0 = a * b;\n const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * ((m0 >> 64n) ^ secretB);\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n);\n}\n\nexport function rapid_mix_protected(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n) ^ a ^ b;\n}\n\nexport function rapidhash_epilogue_protected(\n a0: bigint,\n b0: bigint,\n secretA: bigint,\n secretB: bigint,\n len: bigint,\n): bigint {\n const m0 = a0 * b0;\n const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;\n const b1 = (m0 >> 64n) ^ secretB ^ b0;\n const m1 = a1 * b1;\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n) ^ a1 ^ b1;\n}\n\n// ---\n\nconst read32x2Buffer = new Uint8Array(8);\nconst read32x2View = new DataView(read32x2Buffer.buffer);\n\nexport function rapid_read32x2(buf: DataView, offset1: number, offset2: number): bigint {\n read32x2View.setUint32(4, buf.getUint32(offset1, true), true);\n read32x2View.setUint32(0, buf.getUint32(offset2, true), true);\n return read32x2View.getBigUint64(0, true);\n}\n\nconst read32Buffer = new Uint8Array(8);\nconst read32View = new DataView(read32Buffer.buffer);\n\nexport function rapid_read32(buf: DataView, offset: number): bigint {\n read32View.setUint32(0, buf.getUint32(offset, true), true);\n return read32View.getBigUint64(0, true);\n}\n\nexport function rapid_read64(buf: DataView, offset: number): bigint {\n return buf.getBigUint64(offset, true);\n}\n\nconst readSmallBuffer = new Uint8Array(8);\nconst readSmallView = new DataView(readSmallBuffer.buffer);\n\nexport function rapid_readSmall(buf: DataView, offset: number, k: number): bigint {\n readSmallBuffer[7] = buf.getUint8(offset);\n readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));\n readSmallBuffer[0] = buf.getUint8(offset + k - 1);\n return readSmallView.getBigUint64(0, true);\n}\n\nconst readBytesBuffer = new Uint8Array(8);\nconst readBytesView = new DataView(readBytesBuffer.buffer);\n\nexport function rapid_readBytes(buf: DataView, offset1: number, offset2: number): bigint {\n readBytesBuffer[0] = buf.getUint8(offset2);\n readBytesBuffer[7] = buf.getUint8(offset1);\n return readBytesView.getBigUint64(0, true);\n}\n\n// ---\n\nconst textEncoder = new TextEncoder();\nconst utf8BufferSize = 2048;\nconst stringLengthThresholdToUseBuffer = utf8BufferSize / 3;\nconst utf8Buffer = new Uint8Array(utf8BufferSize);\n\nexport function toDataView(message: string | Uint8Array | DataView): DataView {\n if (typeof message === 'string') {\n if (message.length <= stringLengthThresholdToUseBuffer) {\n const {written} = textEncoder.encodeInto(message, utf8Buffer);\n return new DataView(utf8Buffer.buffer, 0, written);\n }\n\n const utf8bytes = textEncoder.encode(message);\n return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);\n }\n\n if (message instanceof Uint8Array) {\n return new DataView(message.buffer, message.byteOffset, message.byteLength);\n }\n\n return message;\n}\n\n// ---\n\nexport type RapidMumBehaviour = 'fast' | 'protected';\nconst defaultRapidMumBehaviour: RapidMumBehaviour = 'fast';\n\nexport interface RapidhashOptions {\n seed: bigint;\n rapidMumBehaviour: RapidMumBehaviour;\n}\n\nexport const rapidMumImplementations: {\n [behaviour in RapidMumBehaviour]: {\n rapid_mix: RapidMix;\n rapidhash_epilogue: RapidhashEpilogue;\n };\n} = {\n fast: {\n rapid_mix: rapid_mix_fast,\n rapidhash_epilogue: rapidhash_epilogue_fast,\n },\n protected: {\n rapid_mix: rapid_mix_protected,\n rapidhash_epilogue: rapidhash_epilogue_protected,\n },\n};\n\nfunction isBigUint64(value: bigint): boolean {\n return value >= 0n && value <= 0xffff_ffff_ffff_ffffn;\n}\n\nexport function validateOptions(options: Partial<RapidhashOptions> | undefined, defaultSeed: bigint): RapidhashOptions {\n const result: RapidhashOptions = {\n seed: defaultSeed,\n rapidMumBehaviour: defaultRapidMumBehaviour,\n };\n\n if (options === undefined) {\n return result;\n }\n\n if (options.seed !== undefined) {\n if (!isBigUint64(options.seed)) {\n throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);\n }\n result.seed = options.seed;\n }\n\n if (options.rapidMumBehaviour !== undefined) {\n result.rapidMumBehaviour = options.rapidMumBehaviour;\n }\n\n return result;\n}\n"],"mappings":";AAGA,SAAgB,eAAe,GAAW,GAAmB;CAC3D,MAAM,IAAI,IAAI;CACd,OAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK;AACvC;AAEA,SAAgB,wBAAwB,GAAW,GAAW,SAAiB,SAAiB,KAAqB;CACnH,MAAM,KAAK,IAAI;CACf,MAAM,MAAM,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,QAAS,MAAM,MAAO;CACrE,OAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM;AACzC;AAEA,SAAgB,oBAAoB,GAAW,GAAmB;CAChE,MAAM,IAAI,IAAI;CACd,OAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK,MAAO,IAAI;AAClD;AAEA,SAAgB,6BACd,IACA,IACA,SACA,SACA,KACQ;CACR,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,OAAO,QAAQ,IAA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711651n,
7
+ 5573817676018592327n,
8
+ 11562461410679940143n,
9
+ 16646288086500911323n,
10
+ 10443028834174122124n,
11
+ 12297829382473034410n
12
+ ];
13
+ Object.defineProperty(exports, "RAPID_SEED", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return RAPID_SEED;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "rapid_secret", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return rapid_secret;
23
+ }
24
+ });
25
+
26
+ //# sourceMappingURL=common_v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common_v2.js","names":[],"sources":["../src/common_v2.ts"],"sourcesContent":["export type RapidSecret = [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];\n\nexport const RAPID_SEED = 0n;\nexport const rapid_secret: RapidSecret = [\n 0x2d358dccaa6c78a5n,\n 0x8bb84b93962eacc9n,\n 0x4b33a62ed433d4a3n,\n 0x4d5a2da51de1aa47n,\n 0xa0761d6478bd642fn,\n 0xe7037ed1a0b428dbn,\n 0x90ed1765281c388cn,\n 0xaaaaaaaaaaaaaaaan,\n];\n"],"mappings":";AAEA,MAAa,aAAa;AAC1B,MAAa,eAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,15 @@
1
+ // src/common_v2.ts
2
+ const RAPID_SEED = 0n;
3
+ const rapid_secret = [
4
+ 3257665815644502181n,
5
+ 10067880064238660809n,
6
+ 5418857496715711651n,
7
+ 5573817676018592327n,
8
+ 11562461410679940143n,
9
+ 16646288086500911323n,
10
+ 10443028834174122124n,
11
+ 12297829382473034410n
12
+ ];
13
+ export { rapid_secret as n, RAPID_SEED as t };
14
+
15
+ //# sourceMappingURL=common_v2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common_v2.mjs","names":[],"sources":["../src/common_v2.ts"],"sourcesContent":["export type RapidSecret = [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];\n\nexport const RAPID_SEED = 0n;\nexport const rapid_secret: RapidSecret = [\n 0x2d358dccaa6c78a5n,\n 0x8bb84b93962eacc9n,\n 0x4b33a62ed433d4a3n,\n 0x4d5a2da51de1aa47n,\n 0xa0761d6478bd642fn,\n 0xe7037ed1a0b428dbn,\n 0x90ed1765281c388cn,\n 0xaaaaaaaaaaaaaaaan,\n];\n"],"mappings":";AAEA,MAAa,aAAa;AAC1B,MAAa,eAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}