@byline/admin 2.3.3 → 2.4.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 (177) hide show
  1. package/dist/abilities.js +5 -24
  2. package/dist/index.js +8 -30
  3. package/dist/lib/assert-admin-actor.js +13 -74
  4. package/dist/lib/create-command.js +6 -16
  5. package/dist/modules/admin-account/commands.js +35 -24
  6. package/dist/modules/admin-account/components/change-password.d.ts +8 -0
  7. package/dist/modules/admin-account/components/change-password.js +192 -0
  8. package/dist/modules/admin-account/components/change-password.module.js +8 -0
  9. package/dist/modules/admin-account/components/change-password_module.css +27 -0
  10. package/dist/modules/admin-account/components/container.d.ts +29 -0
  11. package/dist/modules/admin-account/components/container.js +298 -0
  12. package/dist/modules/admin-account/components/container.module.js +28 -0
  13. package/dist/modules/admin-account/components/container_module.css +106 -0
  14. package/dist/modules/admin-account/components/update.d.ts +8 -0
  15. package/dist/modules/admin-account/components/update.js +207 -0
  16. package/dist/modules/admin-account/components/update.module.js +8 -0
  17. package/dist/modules/admin-account/components/update_module.css +27 -0
  18. package/dist/modules/admin-account/errors.js +14 -45
  19. package/dist/modules/admin-account/index.js +4 -34
  20. package/dist/modules/admin-account/schemas.js +25 -59
  21. package/dist/modules/admin-account/service.js +56 -61
  22. package/dist/modules/admin-permissions/abilities.js +6 -24
  23. package/dist/modules/admin-permissions/commands.js +42 -28
  24. package/dist/modules/admin-permissions/components/inspector.d.ts +4 -0
  25. package/dist/modules/admin-permissions/components/inspector.js +284 -0
  26. package/dist/modules/admin-permissions/components/inspector.module.js +56 -0
  27. package/dist/modules/admin-permissions/components/inspector_module.css +238 -0
  28. package/dist/modules/admin-permissions/dto.js +3 -16
  29. package/dist/modules/admin-permissions/errors.js +14 -27
  30. package/dist/modules/admin-permissions/index.js +6 -26
  31. package/dist/modules/admin-permissions/repository.js +1 -8
  32. package/dist/modules/admin-permissions/schemas.js +33 -70
  33. package/dist/modules/admin-permissions/service.js +88 -92
  34. package/dist/modules/admin-roles/abilities.js +8 -30
  35. package/dist/modules/admin-roles/commands.js +89 -55
  36. package/dist/modules/admin-roles/components/create.d.ts +7 -0
  37. package/dist/modules/admin-roles/components/create.js +177 -0
  38. package/dist/modules/admin-roles/components/create.module.js +8 -0
  39. package/dist/modules/admin-roles/components/create_module.css +27 -0
  40. package/dist/modules/admin-roles/components/permissions.d.ts +10 -0
  41. package/dist/modules/admin-roles/components/permissions.js +303 -0
  42. package/dist/modules/admin-roles/components/permissions.module.js +44 -0
  43. package/dist/modules/admin-roles/components/permissions_module.css +192 -0
  44. package/dist/modules/admin-roles/components/update.d.ts +8 -0
  45. package/dist/modules/admin-roles/components/update.js +166 -0
  46. package/dist/modules/admin-roles/components/update.module.js +8 -0
  47. package/dist/modules/admin-roles/components/update_module.css +27 -0
  48. package/dist/modules/admin-roles/dto.js +3 -16
  49. package/dist/modules/admin-roles/errors.js +16 -40
  50. package/dist/modules/admin-roles/index.js +6 -26
  51. package/dist/modules/admin-roles/repository.js +1 -8
  52. package/dist/modules/admin-roles/schemas.js +41 -71
  53. package/dist/modules/admin-roles/service.js +79 -82
  54. package/dist/modules/admin-users/abilities.js +9 -38
  55. package/dist/modules/admin-users/commands.js +92 -50
  56. package/dist/modules/admin-users/components/create.d.ts +8 -0
  57. package/dist/modules/admin-users/components/create.js +268 -0
  58. package/dist/modules/admin-users/components/create.module.js +10 -0
  59. package/dist/modules/admin-users/components/create_module.css +45 -0
  60. package/dist/modules/admin-users/components/roles.d.ts +11 -0
  61. package/dist/modules/admin-users/components/roles.js +148 -0
  62. package/dist/modules/admin-users/components/roles.module.js +18 -0
  63. package/dist/modules/admin-users/components/roles_module.css +75 -0
  64. package/dist/modules/admin-users/components/set-password.d.ts +8 -0
  65. package/dist/modules/admin-users/components/set-password.js +170 -0
  66. package/dist/modules/admin-users/components/set-password.module.js +9 -0
  67. package/dist/modules/admin-users/components/set-password_module.css +31 -0
  68. package/dist/modules/admin-users/components/update.d.ts +8 -0
  69. package/dist/modules/admin-users/components/update.js +254 -0
  70. package/dist/modules/admin-users/components/update.module.js +9 -0
  71. package/dist/modules/admin-users/components/update_module.css +34 -0
  72. package/dist/modules/admin-users/dto.js +3 -18
  73. package/dist/modules/admin-users/errors.js +17 -43
  74. package/dist/modules/admin-users/index.js +7 -27
  75. package/dist/modules/admin-users/repository.js +1 -8
  76. package/dist/modules/admin-users/schemas.js +44 -75
  77. package/dist/modules/admin-users/seed-super-admin.js +9 -34
  78. package/dist/modules/admin-users/service.js +76 -91
  79. package/dist/modules/auth/components/sign-in-form.d.ts +12 -0
  80. package/dist/modules/auth/components/sign-in-form.js +115 -0
  81. package/dist/modules/auth/components/sign-in-form.module.js +12 -0
  82. package/dist/modules/auth/components/sign-in-form_module.css +41 -0
  83. package/dist/modules/auth/index.js +3 -24
  84. package/dist/modules/auth/jwt-session-provider.js +179 -149
  85. package/dist/modules/auth/password.js +11 -53
  86. package/dist/modules/auth/phc.js +21 -54
  87. package/dist/modules/auth/refresh-tokens-repository.js +1 -8
  88. package/dist/modules/auth/resolve-actor.js +6 -28
  89. package/dist/services/admin-services-context.d.ts +16 -0
  90. package/dist/services/admin-services-context.js +13 -0
  91. package/dist/services/admin-services-types.d.ts +129 -0
  92. package/dist/services/admin-services-types.js +1 -0
  93. package/dist/store.js +1 -8
  94. package/dist/vendor/noble-argon2/_blake.js +277 -45
  95. package/dist/vendor/noble-argon2/_md.js +81 -136
  96. package/dist/vendor/noble-argon2/_u64.js +65 -67
  97. package/dist/vendor/noble-argon2/argon2.js +181 -342
  98. package/dist/vendor/noble-argon2/blake2.js +252 -327
  99. package/dist/vendor/noble-argon2/utils.js +110 -490
  100. package/dist/vendor/noble-argon2/utils.js.LICENSE.txt +1 -0
  101. package/package.json +89 -10
  102. package/src/abilities.ts +32 -0
  103. package/src/declarations.d.ts +4 -0
  104. package/src/index.ts +39 -0
  105. package/src/lib/assert-admin-actor.ts +90 -0
  106. package/src/lib/create-command.ts +109 -0
  107. package/src/modules/admin-account/commands.ts +76 -0
  108. package/src/modules/admin-account/components/change-password.module.css +40 -0
  109. package/src/modules/admin-account/components/change-password.tsx +232 -0
  110. package/src/modules/admin-account/components/container.module.css +158 -0
  111. package/src/modules/admin-account/components/container.tsx +229 -0
  112. package/src/modules/admin-account/components/update.module.css +40 -0
  113. package/src/modules/admin-account/components/update.tsx +263 -0
  114. package/src/modules/admin-account/errors.ts +75 -0
  115. package/src/modules/admin-account/index.ts +60 -0
  116. package/src/modules/admin-account/schemas.ts +84 -0
  117. package/src/modules/admin-account/service.ts +92 -0
  118. package/src/modules/admin-permissions/abilities.ts +46 -0
  119. package/src/modules/admin-permissions/commands.ts +103 -0
  120. package/src/modules/admin-permissions/components/inspector.module.css +326 -0
  121. package/src/modules/admin-permissions/components/inspector.tsx +298 -0
  122. package/src/modules/admin-permissions/dto.ts +28 -0
  123. package/src/modules/admin-permissions/errors.ts +57 -0
  124. package/src/modules/admin-permissions/index.ts +72 -0
  125. package/src/modules/admin-permissions/repository.ts +49 -0
  126. package/src/modules/admin-permissions/schemas.ts +128 -0
  127. package/src/modules/admin-permissions/service.ts +137 -0
  128. package/src/modules/admin-roles/abilities.ts +62 -0
  129. package/src/modules/admin-roles/commands.ts +161 -0
  130. package/src/modules/admin-roles/components/create.module.css +40 -0
  131. package/src/modules/admin-roles/components/create.tsx +218 -0
  132. package/src/modules/admin-roles/components/permissions.module.css +279 -0
  133. package/src/modules/admin-roles/components/permissions.tsx +396 -0
  134. package/src/modules/admin-roles/components/update.module.css +40 -0
  135. package/src/modules/admin-roles/components/update.tsx +218 -0
  136. package/src/modules/admin-roles/dto.ts +30 -0
  137. package/src/modules/admin-roles/errors.ts +76 -0
  138. package/src/modules/admin-roles/index.ts +81 -0
  139. package/src/modules/admin-roles/repository.ts +96 -0
  140. package/src/modules/admin-roles/schemas.ts +139 -0
  141. package/src/modules/admin-roles/service.ts +136 -0
  142. package/src/modules/admin-users/abilities.ts +76 -0
  143. package/src/modules/admin-users/commands.ts +157 -0
  144. package/src/modules/admin-users/components/create.module.css +63 -0
  145. package/src/modules/admin-users/components/create.tsx +323 -0
  146. package/src/modules/admin-users/components/roles.module.css +119 -0
  147. package/src/modules/admin-users/components/roles.tsx +172 -0
  148. package/src/modules/admin-users/components/set-password.module.css +46 -0
  149. package/src/modules/admin-users/components/set-password.tsx +199 -0
  150. package/src/modules/admin-users/components/update.module.css +49 -0
  151. package/src/modules/admin-users/components/update.tsx +328 -0
  152. package/src/modules/admin-users/dto.ts +39 -0
  153. package/src/modules/admin-users/errors.ts +84 -0
  154. package/src/modules/admin-users/index.ts +91 -0
  155. package/src/modules/admin-users/repository.ts +161 -0
  156. package/src/modules/admin-users/schemas.ts +168 -0
  157. package/src/modules/admin-users/seed-super-admin.ts +102 -0
  158. package/src/modules/admin-users/service.ts +166 -0
  159. package/src/modules/auth/components/sign-in-form.module.css +62 -0
  160. package/src/modules/auth/components/sign-in-form.tsx +132 -0
  161. package/src/modules/auth/index.ts +31 -0
  162. package/src/modules/auth/jwt-session-provider.ts +301 -0
  163. package/src/modules/auth/password.ts +94 -0
  164. package/src/modules/auth/phc.ts +121 -0
  165. package/src/modules/auth/refresh-tokens-repository.ts +74 -0
  166. package/src/modules/auth/resolve-actor.ts +42 -0
  167. package/src/services/admin-services-context.tsx +52 -0
  168. package/src/services/admin-services-types.ts +177 -0
  169. package/src/store.ts +32 -0
  170. package/src/vendor/noble-argon2/LICENSE +21 -0
  171. package/src/vendor/noble-argon2/README.md +87 -0
  172. package/src/vendor/noble-argon2/_blake.ts +58 -0
  173. package/src/vendor/noble-argon2/_md.ts +223 -0
  174. package/src/vendor/noble-argon2/_u64.ts +118 -0
  175. package/src/vendor/noble-argon2/argon2.ts +668 -0
  176. package/src/vendor/noble-argon2/blake2.ts +583 -0
  177. package/src/vendor/noble-argon2/utils.ts +849 -0
@@ -0,0 +1,223 @@
1
+ // @ts-nocheck — vendored from noble-hashes; see ./README.md
2
+ /**
3
+ * Internal Merkle-Damgard hash utils.
4
+ * @module
5
+ */
6
+ import {
7
+ abytes,
8
+ aexists,
9
+ aoutput,
10
+ clean,
11
+ createView,
12
+ type Hash,
13
+ type TArg,
14
+ type TRet,
15
+ } from './utils.js';
16
+
17
+ /**
18
+ * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
19
+ * Returns bits from `b` when `a` is set, otherwise from `c`.
20
+ * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
21
+ * set the same bit.
22
+ * @param a - selector word
23
+ * @param b - word chosen when selector bit is set
24
+ * @param c - word chosen when selector bit is clear
25
+ * @returns Mixed 32-bit word.
26
+ * @example
27
+ * Combine three words with the shared 32-bit choice primitive.
28
+ * ```ts
29
+ * Chi(0xffffffff, 0x12345678, 0x87654321);
30
+ * ```
31
+ */
32
+ export function Chi(a: number, b: number, c: number): number {
33
+ return (a & b) ^ (~a & c);
34
+ }
35
+
36
+ /**
37
+ * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
38
+ * Returns bits shared by at least two inputs.
39
+ * @param a - first input word
40
+ * @param b - second input word
41
+ * @param c - third input word
42
+ * @returns Mixed 32-bit word.
43
+ * @example
44
+ * Combine three words with the shared 32-bit majority primitive.
45
+ * ```ts
46
+ * Maj(0xffffffff, 0x12345678, 0x87654321);
47
+ * ```
48
+ */
49
+ export function Maj(a: number, b: number, c: number): number {
50
+ return (a & b) ^ (a & c) ^ (b & c);
51
+ }
52
+
53
+ /**
54
+ * Merkle-Damgard hash construction base class.
55
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
56
+ * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
57
+ * strings with partial-byte tails.
58
+ * @param blockLen - internal block size in bytes
59
+ * @param outputLen - digest size in bytes
60
+ * @param padOffset - trailing length field size in bytes
61
+ * @param isLE - whether length and state words are encoded in little-endian
62
+ * @example
63
+ * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
64
+ * ```ts
65
+ * import { _SHA1 } from '@noble/hashes/legacy.js';
66
+ * const hash = new _SHA1();
67
+ * hash.update(new Uint8Array([97, 98, 99]));
68
+ * hash.digest();
69
+ * ```
70
+ */
71
+ export abstract class HashMD<T extends HashMD<T>> implements Hash<T> {
72
+ // Subclasses must treat `buf` as read-only: `update()` may pass a direct view over caller input
73
+ // when it can process whole blocks without buffering first.
74
+ protected abstract process(buf: DataView, offset: number): void;
75
+ protected abstract get(): number[];
76
+ protected abstract set(...args: number[]): void;
77
+ abstract destroy(): void;
78
+ protected abstract roundClean(): void;
79
+
80
+ readonly blockLen: number;
81
+ readonly outputLen: number;
82
+ readonly canXOF = false;
83
+ readonly padOffset: number;
84
+ readonly isLE: boolean;
85
+
86
+ // For partial updates less than block size
87
+ protected buffer: Uint8Array;
88
+ protected view: DataView;
89
+ protected finished = false;
90
+ protected length = 0;
91
+ protected pos = 0;
92
+ protected destroyed = false;
93
+
94
+ constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean) {
95
+ this.blockLen = blockLen;
96
+ this.outputLen = outputLen;
97
+ this.padOffset = padOffset;
98
+ this.isLE = isLE;
99
+ this.buffer = new Uint8Array(blockLen);
100
+ this.view = createView(this.buffer);
101
+ }
102
+ update(data: TArg<Uint8Array>): this {
103
+ aexists(this);
104
+ abytes(data);
105
+ const { view, buffer, blockLen } = this;
106
+ const len = data.length;
107
+ for (let pos = 0; pos < len; ) {
108
+ const take = Math.min(blockLen - this.pos, len - pos);
109
+ // Fast path only when there is no buffered partial block: `take === blockLen` implies
110
+ // `this.pos === 0`, so we can process full blocks directly from the input view.
111
+ if (take === blockLen) {
112
+ const dataView = createView(data);
113
+ for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
114
+ continue;
115
+ }
116
+ buffer.set(data.subarray(pos, pos + take), this.pos);
117
+ this.pos += take;
118
+ pos += take;
119
+ if (this.pos === blockLen) {
120
+ this.process(view, 0);
121
+ this.pos = 0;
122
+ }
123
+ }
124
+ this.length += data.length;
125
+ this.roundClean();
126
+ return this;
127
+ }
128
+ digestInto(out: TArg<Uint8Array>): void {
129
+ aexists(this);
130
+ aoutput(out, this);
131
+ this.finished = true;
132
+ // Padding
133
+ // We can avoid allocation of buffer for padding completely if it
134
+ // was previously not allocated here. But it won't change performance.
135
+ const { buffer, view, blockLen, isLE } = this;
136
+ let { pos } = this;
137
+ // append the bit '1' to the message
138
+ buffer[pos++] = 0b10000000;
139
+ clean(this.buffer.subarray(pos));
140
+ // we have less than padOffset left in buffer, so we cannot put length in
141
+ // current block, need process it and pad again
142
+ if (this.padOffset > blockLen - pos) {
143
+ this.process(view, 0);
144
+ pos = 0;
145
+ }
146
+ // Pad until full block byte with zeros
147
+ for (let i = pos; i < blockLen; i++) buffer[i] = 0;
148
+ // `padOffset` reserves the whole length field. For SHA-384/512 the high 64 bits stay zero from
149
+ // the padding fill above, and JS will overflow before user input can make that half non-zero.
150
+ // So we only need to write the low 64 bits here.
151
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
152
+ this.process(view, 0);
153
+ const oview = createView(out);
154
+ const len = this.outputLen;
155
+ // NOTE: we do division by 4 later, which must be fused in single op with modulo by JIT
156
+ if (len % 4) throw new Error('_sha2: outputLen must be aligned to 32bit');
157
+ const outLen = len / 4;
158
+ const state = this.get();
159
+ if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');
160
+ for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
161
+ }
162
+ digest(): TRet<Uint8Array> {
163
+ const { buffer, outputLen } = this;
164
+ this.digestInto(buffer);
165
+ // Copy before destroy(): subclasses wipe `buffer` during cleanup, but `digest()` must return
166
+ // fresh bytes to the caller.
167
+ const res = buffer.slice(0, outputLen);
168
+ this.destroy();
169
+ return res as TRet<Uint8Array>;
170
+ }
171
+ _cloneInto(to?: T): T {
172
+ to ||= new (this.constructor as any)() as T;
173
+ to.set(...this.get());
174
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
175
+ to.destroyed = destroyed;
176
+ to.finished = finished;
177
+ to.length = length;
178
+ to.pos = pos;
179
+ // Only partial-block bytes need copying: when `length % blockLen === 0`, `pos === 0` and
180
+ // later `update()` / `digestInto()` overwrite `to.buffer` from the start before reading it.
181
+ if (length % blockLen) to.buffer.set(buffer);
182
+ return to as unknown as any;
183
+ }
184
+ clone(): T {
185
+ return this._cloneInto();
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
191
+ * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
192
+ */
193
+
194
+ /** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
195
+ * square roots of the first eight prime numbers. Exported as a shared table; callers must treat
196
+ * it as read-only because constructors copy words from it by index. */
197
+ export const SHA256_IV: TRet<Uint32Array> = /* @__PURE__ */ Uint32Array.from([
198
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
199
+ ]);
200
+
201
+ /** Initial SHA224 state `H(0)` from RFC 6234 §6.1. Exported as a shared table; callers must
202
+ * treat it as read-only because constructors copy words from it by index. */
203
+ export const SHA224_IV: TRet<Uint32Array> = /* @__PURE__ */ Uint32Array.from([
204
+ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
205
+ ]);
206
+
207
+ /** Initial SHA384 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
208
+ * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the ninth
209
+ * through sixteenth prime numbers. Exported as a shared table; callers must treat it as read-only
210
+ * because constructors copy halves from it by index. */
211
+ export const SHA384_IV: TRet<Uint32Array> = /* @__PURE__ */ Uint32Array.from([
212
+ 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,
213
+ 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,
214
+ ]);
215
+
216
+ /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
217
+ * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
218
+ * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
219
+ * constructors copy halves from it by index. */
220
+ export const SHA512_IV: TRet<Uint32Array> = /* @__PURE__ */ Uint32Array.from([
221
+ 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
222
+ 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
223
+ ]);
@@ -0,0 +1,118 @@
1
+ // @ts-nocheck — vendored from noble-hashes; see ./README.md
2
+ /**
3
+ * Internal helpers for u64.
4
+ * BigUint64Array is too slow as per 2026, so we implement it using
5
+ * Uint32Array.
6
+ * @privateRemarks TODO: re-check {@link https://issues.chromium.org/issues/42212588}
7
+ * @module
8
+ */
9
+ import type { TRet } from './utils.js';
10
+
11
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
12
+ const _32n = /* @__PURE__ */ BigInt(32);
13
+
14
+ // Split bigint into two 32-bit halves. With `le=true`, returned fields become `{ h: low, l: high
15
+ // }` to match little-endian word order rather than the property names.
16
+ function fromBig(
17
+ n: bigint,
18
+ le = false
19
+ ): {
20
+ h: number;
21
+ l: number;
22
+ } {
23
+ if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
24
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
25
+ }
26
+
27
+ // Split bigint list into `[highWords, lowWords]` when `le=false`; with `le=true`, the first array
28
+ // holds the low halves because `fromBig(...)` swaps the semantic meaning of `h` and `l`.
29
+ function split(lst: bigint[], le = false): TRet<Uint32Array[]> {
30
+ const len = lst.length;
31
+ let Ah = new Uint32Array(len);
32
+ let Al = new Uint32Array(len);
33
+ for (let i = 0; i < len; i++) {
34
+ const { h, l } = fromBig(lst[i], le);
35
+ [Ah[i], Al[i]] = [h, l];
36
+ }
37
+ return [Ah, Al] as TRet<Uint32Array[]>;
38
+ }
39
+
40
+ // Combine explicit `(high, low)` 32-bit halves into a bigint; `>>> 0` normalizes signed JS
41
+ // bitwise results back to uint32 first, and little-endian callers must swap.
42
+ const toBig = (h: number, l: number): bigint => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
43
+ // High 32-bit half of a 64-bit logical right shift for `s` in `0..31`.
44
+ const shrSH = (h: number, _l: number, s: number): number => h >>> s;
45
+ // Low 32-bit half of a 64-bit logical right shift, valid for `s` in `1..31`.
46
+ const shrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);
47
+ // High 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
48
+ const rotrSH = (h: number, l: number, s: number): number => (h >>> s) | (l << (32 - s));
49
+ // Low 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
50
+ const rotrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);
51
+ // High 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
52
+ const rotrBH = (h: number, l: number, s: number): number => (h << (64 - s)) | (l >>> (s - 32));
53
+ // Low 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
54
+ const rotrBL = (h: number, l: number, s: number): number => (h >>> (s - 32)) | (l << (64 - s));
55
+ // High 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped low half.
56
+ const rotr32H = (_h: number, l: number): number => l;
57
+ // Low 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped high half.
58
+ const rotr32L = (h: number, _l: number): number => h;
59
+ // High 32-bit half of a 64-bit left rotate, valid for `s` in `1..31`.
60
+ const rotlSH = (h: number, l: number, s: number): number => (h << s) | (l >>> (32 - s));
61
+ // Low 32-bit half of a 64-bit left rotate, valid for `s` in `1..31`.
62
+ const rotlSL = (h: number, l: number, s: number): number => (l << s) | (h >>> (32 - s));
63
+ // High 32-bit half of a 64-bit left rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
64
+ const rotlBH = (h: number, l: number, s: number): number => (l << (s - 32)) | (h >>> (64 - s));
65
+ // Low 32-bit half of a 64-bit left rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
66
+ const rotlBL = (h: number, l: number, s: number): number => (h << (s - 32)) | (l >>> (64 - s));
67
+
68
+ // Add two split 64-bit words and return the split `{ h, l }` sum.
69
+ // JS uses 32-bit signed integers for bitwise operations, so we cannot simply shift the carry out
70
+ // of the low sum and instead use division.
71
+ function add(
72
+ Ah: number,
73
+ Al: number,
74
+ Bh: number,
75
+ Bl: number
76
+ ): {
77
+ h: number;
78
+ l: number;
79
+ } {
80
+ const l = (Al >>> 0) + (Bl >>> 0);
81
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
82
+ }
83
+ // Addition with more than 2 elements
84
+ // Unmasked low-word accumulator for 3-way addition; pass the raw result into `add3H(...)`.
85
+ const add3L = (Al: number, Bl: number, Cl: number): number => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
86
+ // High-word finalize step for 3-way addition; `low` must be the untruncated output of `add3L(...)`.
87
+ const add3H = (low: number, Ah: number, Bh: number, Ch: number): number =>
88
+ (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
89
+ // Unmasked low-word accumulator for 4-way addition; pass the raw result into `add4H(...)`.
90
+ const add4L = (Al: number, Bl: number, Cl: number, Dl: number): number =>
91
+ (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
92
+ // High-word finalize step for 4-way addition; `low` must be the untruncated output of `add4L(...)`.
93
+ const add4H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number): number =>
94
+ (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
95
+ // Unmasked low-word accumulator for 5-way addition; pass the raw result into `add5H(...)`.
96
+ const add5L = (Al: number, Bl: number, Cl: number, Dl: number, El: number): number =>
97
+ (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
98
+ // High-word finalize step for 5-way addition; `low` must be the untruncated output of `add5L(...)`.
99
+ const add5H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number): number =>
100
+ (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
101
+
102
+ // prettier-ignore
103
+ export {
104
+ add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, rotlBH, rotlBL, rotlSH, rotlSL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, shrSH, shrSL, split, toBig
105
+ };
106
+ // Canonical grouped namespace for callers that prefer one object.
107
+ // Named exports stay for direct imports.
108
+ // prettier-ignore
109
+ const u64: { fromBig: typeof fromBig; split: typeof split; toBig: (h: number, l: number) => bigint; shrSH: (h: number, _l: number, s: number) => number; shrSL: (h: number, l: number, s: number) => number; rotrSH: (h: number, l: number, s: number) => number; rotrSL: (h: number, l: number, s: number) => number; rotrBH: (h: number, l: number, s: number) => number; rotrBL: (h: number, l: number, s: number) => number; rotr32H: (_h: number, l: number) => number; rotr32L: (h: number, _l: number) => number; rotlSH: (h: number, l: number, s: number) => number; rotlSL: (h: number, l: number, s: number) => number; rotlBH: (h: number, l: number, s: number) => number; rotlBL: (h: number, l: number, s: number) => number; add: typeof add; add3L: (Al: number, Bl: number, Cl: number) => number; add3H: (low: number, Ah: number, Bh: number, Ch: number) => number; add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number; add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number; add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number; add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number; } = {
110
+ fromBig, split, toBig,
111
+ shrSH, shrSL,
112
+ rotrSH, rotrSL, rotrBH, rotrBL,
113
+ rotr32H, rotr32L,
114
+ rotlSH, rotlSL, rotlBH, rotlBL,
115
+ add, add3L, add3H, add4L, add4H, add5H, add5L,
116
+ };
117
+ // Default export mirrors named `u64` for compatibility with object-style imports.
118
+ export default u64;