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