@byline/admin 2.4.0 → 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,118 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
import { BSIGMA, G1s, G2s } from './_blake.js';
|
|
8
|
-
import { SHA256_IV } from './_md.js';
|
|
9
|
-
import * as u64 from './_u64.js';
|
|
10
|
-
// prettier-ignore
|
|
11
|
-
import { abytes, aexists, anumber, aoutput, clean, createHasher, swap32IfBE, swap8IfBE, u32 } from './utils.js';
|
|
12
|
-
// Same IV words as `SHA512_IV`, but endian-swapped into LE u32 low/high halves
|
|
13
|
-
// for the BLAKE2b u64 helpers below.
|
|
1
|
+
import { BSIGMA, G1s, G2s } from "./_blake.js";
|
|
2
|
+
import { SHA256_IV } from "./_md.js";
|
|
3
|
+
import { abytes, aexists, anumber, aoutput, clean, createHasher, swap32IfBE, swap8IfBE, u32 } from "./utils.js";
|
|
4
|
+
import * as __rspack_external__u64_js_3c1fe104 from "./_u64.js";
|
|
14
5
|
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
|
15
|
-
0xf3bcc908,
|
|
16
|
-
|
|
6
|
+
0xf3bcc908,
|
|
7
|
+
0x6a09e667,
|
|
8
|
+
0x84caa73b,
|
|
9
|
+
0xbb67ae85,
|
|
10
|
+
0xfe94f82b,
|
|
11
|
+
0x3c6ef372,
|
|
12
|
+
0x5f1d36f1,
|
|
13
|
+
0xa54ff53a,
|
|
14
|
+
0xade682d1,
|
|
15
|
+
0x510e527f,
|
|
16
|
+
0x2b3e6c1f,
|
|
17
|
+
0x9b05688c,
|
|
18
|
+
0xfb41bd6b,
|
|
19
|
+
0x1f83d9ab,
|
|
20
|
+
0x137e2179,
|
|
21
|
+
0x5be0cd19
|
|
17
22
|
]);
|
|
18
|
-
// Shared synchronous BLAKE2b work vector as LE u32 low/high halves.
|
|
19
23
|
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
20
|
-
// BLAKE2b G mix split into two half-rounds over LE u32 low/high limbs.
|
|
21
24
|
function G1b(a, b, c, d, msg, x) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let
|
|
25
|
-
let
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
({ Dh, Dl } = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
({
|
|
39
|
-
({ Bh, Bl } = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(
|
|
25
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
26
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
27
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
28
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
29
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
30
|
+
let ll = __rspack_external__u64_js_3c1fe104.add3L(Al, Bl, Xl);
|
|
31
|
+
Ah = __rspack_external__u64_js_3c1fe104.add3H(ll, Ah, Bh, Xh);
|
|
32
|
+
Al = 0 | ll;
|
|
33
|
+
({ Dh, Dl } = {
|
|
34
|
+
Dh: Dh ^ Ah,
|
|
35
|
+
Dl: Dl ^ Al
|
|
36
|
+
});
|
|
37
|
+
({ Dh, Dl } = {
|
|
38
|
+
Dh: __rspack_external__u64_js_3c1fe104.rotr32H(Dh, Dl),
|
|
39
|
+
Dl: __rspack_external__u64_js_3c1fe104.rotr32L(Dh, Dl)
|
|
40
|
+
});
|
|
41
|
+
({ h: Ch, l: Cl } = __rspack_external__u64_js_3c1fe104.add(Ch, Cl, Dh, Dl));
|
|
42
|
+
({ Bh, Bl } = {
|
|
43
|
+
Bh: Bh ^ Ch,
|
|
44
|
+
Bl: Bl ^ Cl
|
|
45
|
+
});
|
|
46
|
+
({ Bh, Bl } = {
|
|
47
|
+
Bh: __rspack_external__u64_js_3c1fe104.rotrSH(Bh, Bl, 24),
|
|
48
|
+
Bl: __rspack_external__u64_js_3c1fe104.rotrSL(Bh, Bl, 24)
|
|
49
|
+
});
|
|
50
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
51
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
52
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
53
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
44
54
|
}
|
|
45
|
-
// Second half-round of the same LE-limb BLAKE2b G mix; `x` is the message word offset.
|
|
46
55
|
function G2b(a, b, c, d, msg, x) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
let
|
|
51
|
-
let
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
({ Dh, Dl } = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
({
|
|
64
|
-
({ Bh, Bl } = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(
|
|
56
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
57
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
58
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
59
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
60
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
61
|
+
let ll = __rspack_external__u64_js_3c1fe104.add3L(Al, Bl, Xl);
|
|
62
|
+
Ah = __rspack_external__u64_js_3c1fe104.add3H(ll, Ah, Bh, Xh);
|
|
63
|
+
Al = 0 | ll;
|
|
64
|
+
({ Dh, Dl } = {
|
|
65
|
+
Dh: Dh ^ Ah,
|
|
66
|
+
Dl: Dl ^ Al
|
|
67
|
+
});
|
|
68
|
+
({ Dh, Dl } = {
|
|
69
|
+
Dh: __rspack_external__u64_js_3c1fe104.rotrSH(Dh, Dl, 16),
|
|
70
|
+
Dl: __rspack_external__u64_js_3c1fe104.rotrSL(Dh, Dl, 16)
|
|
71
|
+
});
|
|
72
|
+
({ h: Ch, l: Cl } = __rspack_external__u64_js_3c1fe104.add(Ch, Cl, Dh, Dl));
|
|
73
|
+
({ Bh, Bl } = {
|
|
74
|
+
Bh: Bh ^ Ch,
|
|
75
|
+
Bl: Bl ^ Cl
|
|
76
|
+
});
|
|
77
|
+
({ Bh, Bl } = {
|
|
78
|
+
Bh: __rspack_external__u64_js_3c1fe104.rotrBH(Bh, Bl, 63),
|
|
79
|
+
Bl: __rspack_external__u64_js_3c1fe104.rotrBL(Bh, Bl, 63)
|
|
80
|
+
});
|
|
81
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
82
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
83
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
84
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
69
85
|
}
|
|
70
86
|
function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
71
87
|
anumber(keyLen);
|
|
72
|
-
|
|
73
|
-
if (outputLen <= 0 || outputLen > keyLen)
|
|
74
|
-
throw new Error('outputLen bigger than keyLen');
|
|
88
|
+
if (outputLen <= 0 || outputLen > keyLen) throw new Error('outputLen bigger than keyLen');
|
|
75
89
|
const { key, salt, personalization } = opts;
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
if (salt !== undefined)
|
|
80
|
-
abytes(salt, saltLen, 'salt');
|
|
81
|
-
if (personalization !== undefined)
|
|
82
|
-
abytes(personalization, persLen, 'personalization');
|
|
90
|
+
if (void 0 !== key && (key.length < 1 || key.length > keyLen)) throw new Error('"key" expected to be undefined or of length=1..' + keyLen);
|
|
91
|
+
if (void 0 !== salt) abytes(salt, saltLen, 'salt');
|
|
92
|
+
if (void 0 !== personalization) abytes(personalization, persLen, 'personalization');
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
export class _BLAKE2 {
|
|
86
|
-
buffer;
|
|
87
|
-
buffer32;
|
|
88
|
-
finished = false;
|
|
89
|
-
destroyed = false;
|
|
90
|
-
length = 0;
|
|
91
|
-
pos = 0;
|
|
92
|
-
blockLen;
|
|
93
|
-
outputLen;
|
|
94
|
-
canXOF = false;
|
|
95
|
-
constructor(blockLen, outputLen) {
|
|
96
|
-
anumber(blockLen);
|
|
97
|
-
anumber(outputLen);
|
|
98
|
-
this.blockLen = blockLen;
|
|
99
|
-
this.outputLen = outputLen;
|
|
100
|
-
this.buffer = new Uint8Array(blockLen);
|
|
101
|
-
this.buffer32 = u32(this.buffer);
|
|
102
|
-
}
|
|
94
|
+
class _BLAKE2 {
|
|
103
95
|
update(data) {
|
|
104
96
|
aexists(this);
|
|
105
97
|
abytes(data);
|
|
106
|
-
// Main difference with other hashes: there is flag for last block,
|
|
107
|
-
// so we cannot process current block before we know that there
|
|
108
|
-
// is the next one. This significantly complicates logic and reduces ability
|
|
109
|
-
// to do zero-copy processing
|
|
110
98
|
const { blockLen, buffer, buffer32 } = this;
|
|
111
99
|
const len = data.length;
|
|
112
100
|
const offset = data.byteOffset;
|
|
113
101
|
const buf = data.buffer;
|
|
114
|
-
for
|
|
115
|
-
// If buffer is full and we still have input (don't process last block, same as blake2s)
|
|
102
|
+
for(let pos = 0; pos < len;){
|
|
116
103
|
if (this.pos === blockLen) {
|
|
117
104
|
swap32IfBE(buffer32);
|
|
118
105
|
this.compress(buffer32, 0, false);
|
|
@@ -121,11 +108,10 @@ export class _BLAKE2 {
|
|
|
121
108
|
}
|
|
122
109
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
123
110
|
const dataOffset = offset + pos;
|
|
124
|
-
// Zero-copy only for full, 4-byte-aligned, non-final blocks.
|
|
125
111
|
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
126
112
|
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
127
113
|
swap32IfBE(data32);
|
|
128
|
-
for
|
|
114
|
+
for(let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen){
|
|
129
115
|
this.length += blockLen;
|
|
130
116
|
this.compress(data32, pos32, false);
|
|
131
117
|
}
|
|
@@ -144,148 +130,112 @@ export class _BLAKE2 {
|
|
|
144
130
|
aoutput(out, this);
|
|
145
131
|
const { pos, buffer32 } = this;
|
|
146
132
|
this.finished = true;
|
|
147
|
-
// Padding
|
|
148
133
|
clean(this.buffer.subarray(pos));
|
|
149
134
|
swap32IfBE(buffer32);
|
|
150
135
|
this.compress(buffer32, 0, true);
|
|
151
136
|
swap32IfBE(buffer32);
|
|
152
|
-
|
|
153
|
-
if (out.byteOffset & 3)
|
|
154
|
-
throw new RangeError('"digestInto() output" expected 4-byte aligned byteOffset, got ' + out.byteOffset);
|
|
137
|
+
if (3 & out.byteOffset) throw new RangeError('"digestInto() output" expected 4-byte aligned byteOffset, got ' + out.byteOffset);
|
|
155
138
|
const state = this.get();
|
|
156
139
|
const out32 = u32(out);
|
|
157
140
|
const full = Math.floor(this.outputLen / 4);
|
|
158
|
-
for
|
|
159
|
-
out32[i] = swap8IfBE(state[i]);
|
|
141
|
+
for(let i = 0; i < full; i++)out32[i] = swap8IfBE(state[i]);
|
|
160
142
|
const tail = this.outputLen % 4;
|
|
161
|
-
if (!tail)
|
|
162
|
-
|
|
163
|
-
const off = full * 4;
|
|
143
|
+
if (!tail) return;
|
|
144
|
+
const off = 4 * full;
|
|
164
145
|
const word = state[full];
|
|
165
|
-
for
|
|
166
|
-
out[off + i] = word >>> (8 * i);
|
|
146
|
+
for(let i = 0; i < tail; i++)out[off + i] = word >>> 8 * i;
|
|
167
147
|
}
|
|
168
148
|
digest() {
|
|
169
149
|
const { buffer, outputLen } = this;
|
|
170
150
|
this.digestInto(buffer);
|
|
171
|
-
// Return a copy so callers do not alias the instance scratch buffer used during finalization.
|
|
172
151
|
const res = buffer.slice(0, outputLen);
|
|
173
152
|
this.destroy();
|
|
174
153
|
return res;
|
|
175
154
|
}
|
|
176
155
|
_cloneInto(to) {
|
|
177
156
|
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
178
|
-
|
|
179
|
-
|
|
157
|
+
to ||= new this.constructor({
|
|
158
|
+
dkLen: outputLen
|
|
159
|
+
});
|
|
180
160
|
to.set(...this.get());
|
|
181
161
|
to.buffer.set(buffer);
|
|
182
162
|
to.destroyed = destroyed;
|
|
183
163
|
to.finished = finished;
|
|
184
164
|
to.length = length;
|
|
185
165
|
to.pos = pos;
|
|
186
|
-
// @ts-ignore
|
|
187
166
|
to.outputLen = outputLen;
|
|
188
167
|
return to;
|
|
189
168
|
}
|
|
190
169
|
clone() {
|
|
191
170
|
return this._cloneInto();
|
|
192
171
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
v4l = B2B_IV[8] | 0;
|
|
206
|
-
v4h = B2B_IV[9] | 0;
|
|
207
|
-
v5l = B2B_IV[10] | 0;
|
|
208
|
-
v5h = B2B_IV[11] | 0;
|
|
209
|
-
v6l = B2B_IV[12] | 0;
|
|
210
|
-
v6h = B2B_IV[13] | 0;
|
|
211
|
-
v7l = B2B_IV[14] | 0;
|
|
212
|
-
v7h = B2B_IV[15] | 0;
|
|
213
|
-
constructor(opts = {}) {
|
|
214
|
-
const olen = opts.dkLen === undefined ? 64 : opts.dkLen;
|
|
215
|
-
super(128, olen);
|
|
216
|
-
checkBlake2Opts(olen, opts, 64, 16, 16);
|
|
217
|
-
let { key, personalization, salt } = opts;
|
|
218
|
-
let keyLength = 0;
|
|
219
|
-
if (key !== undefined) {
|
|
220
|
-
abytes(key, undefined, 'key');
|
|
221
|
-
keyLength = key.length;
|
|
222
|
-
}
|
|
223
|
-
// RFC 7693 §2.5: xor `p[0] = 0x0101kknn` into the low 32 bits of `h[0]`;
|
|
224
|
-
// the high 32 bits stay at `IV[0]`.
|
|
225
|
-
this.v0l ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
|
226
|
-
if (salt !== undefined) {
|
|
227
|
-
abytes(salt, undefined, 'salt');
|
|
228
|
-
const slt = u32(salt);
|
|
229
|
-
this.v4l ^= swap8IfBE(slt[0]);
|
|
230
|
-
this.v4h ^= swap8IfBE(slt[1]);
|
|
231
|
-
this.v5l ^= swap8IfBE(slt[2]);
|
|
232
|
-
this.v5h ^= swap8IfBE(slt[3]);
|
|
233
|
-
}
|
|
234
|
-
if (personalization !== undefined) {
|
|
235
|
-
abytes(personalization, undefined, 'personalization');
|
|
236
|
-
const pers = u32(personalization);
|
|
237
|
-
this.v6l ^= swap8IfBE(pers[0]);
|
|
238
|
-
this.v6h ^= swap8IfBE(pers[1]);
|
|
239
|
-
this.v7l ^= swap8IfBE(pers[2]);
|
|
240
|
-
this.v7h ^= swap8IfBE(pers[3]);
|
|
241
|
-
}
|
|
242
|
-
if (key !== undefined) {
|
|
243
|
-
// Pad to blockLen and update
|
|
244
|
-
const tmp = new Uint8Array(this.blockLen);
|
|
245
|
-
tmp.set(key);
|
|
246
|
-
this.update(tmp);
|
|
247
|
-
}
|
|
172
|
+
constructor(blockLen, outputLen){
|
|
173
|
+
this.finished = false;
|
|
174
|
+
this.destroyed = false;
|
|
175
|
+
this.length = 0;
|
|
176
|
+
this.pos = 0;
|
|
177
|
+
this.canXOF = false;
|
|
178
|
+
anumber(blockLen);
|
|
179
|
+
anumber(outputLen);
|
|
180
|
+
this.blockLen = blockLen;
|
|
181
|
+
this.outputLen = outputLen;
|
|
182
|
+
this.buffer = new Uint8Array(blockLen);
|
|
183
|
+
this.buffer32 = u32(this.buffer);
|
|
248
184
|
}
|
|
249
|
-
|
|
185
|
+
}
|
|
186
|
+
class _BLAKE2b extends _BLAKE2 {
|
|
250
187
|
get() {
|
|
251
188
|
let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
|
|
252
|
-
return [
|
|
189
|
+
return [
|
|
190
|
+
v0l,
|
|
191
|
+
v0h,
|
|
192
|
+
v1l,
|
|
193
|
+
v1h,
|
|
194
|
+
v2l,
|
|
195
|
+
v2h,
|
|
196
|
+
v3l,
|
|
197
|
+
v3h,
|
|
198
|
+
v4l,
|
|
199
|
+
v4h,
|
|
200
|
+
v5l,
|
|
201
|
+
v5h,
|
|
202
|
+
v6l,
|
|
203
|
+
v6h,
|
|
204
|
+
v7l,
|
|
205
|
+
v7h
|
|
206
|
+
];
|
|
253
207
|
}
|
|
254
|
-
// prettier-ignore
|
|
255
208
|
set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
|
|
256
|
-
this.v0l =
|
|
257
|
-
this.v0h =
|
|
258
|
-
this.v1l =
|
|
259
|
-
this.v1h =
|
|
260
|
-
this.v2l =
|
|
261
|
-
this.v2h =
|
|
262
|
-
this.v3l =
|
|
263
|
-
this.v3h =
|
|
264
|
-
this.v4l =
|
|
265
|
-
this.v4h =
|
|
266
|
-
this.v5l =
|
|
267
|
-
this.v5h =
|
|
268
|
-
this.v6l =
|
|
269
|
-
this.v6h =
|
|
270
|
-
this.v7l =
|
|
271
|
-
this.v7h =
|
|
209
|
+
this.v0l = 0 | v0l;
|
|
210
|
+
this.v0h = 0 | v0h;
|
|
211
|
+
this.v1l = 0 | v1l;
|
|
212
|
+
this.v1h = 0 | v1h;
|
|
213
|
+
this.v2l = 0 | v2l;
|
|
214
|
+
this.v2h = 0 | v2h;
|
|
215
|
+
this.v3l = 0 | v3l;
|
|
216
|
+
this.v3h = 0 | v3h;
|
|
217
|
+
this.v4l = 0 | v4l;
|
|
218
|
+
this.v4h = 0 | v4h;
|
|
219
|
+
this.v5l = 0 | v5l;
|
|
220
|
+
this.v5h = 0 | v5h;
|
|
221
|
+
this.v6l = 0 | v6l;
|
|
222
|
+
this.v6h = 0 | v6h;
|
|
223
|
+
this.v7l = 0 | v7l;
|
|
224
|
+
this.v7h = 0 | v7h;
|
|
272
225
|
}
|
|
273
226
|
compress(msg, offset, isLast) {
|
|
274
|
-
this.get().forEach((v, i)
|
|
275
|
-
BBUF.set(B2B_IV, 16);
|
|
276
|
-
let { h, l } =
|
|
277
|
-
BBUF[24] = B2B_IV[8] ^ l;
|
|
278
|
-
BBUF[25] = B2B_IV[9] ^ h;
|
|
279
|
-
// Invert all bits for last block
|
|
227
|
+
this.get().forEach((v, i)=>BBUF[i] = v);
|
|
228
|
+
BBUF.set(B2B_IV, 16);
|
|
229
|
+
let { h, l } = __rspack_external__u64_js_3c1fe104.fromBig(BigInt(this.length));
|
|
230
|
+
BBUF[24] = B2B_IV[8] ^ l;
|
|
231
|
+
BBUF[25] = B2B_IV[9] ^ h;
|
|
280
232
|
if (isLast) {
|
|
281
233
|
BBUF[28] = ~BBUF[28];
|
|
282
234
|
BBUF[29] = ~BBUF[29];
|
|
283
235
|
}
|
|
284
236
|
let j = 0;
|
|
285
237
|
const s = BSIGMA;
|
|
286
|
-
|
|
287
|
-
// each word as [low32, high32].
|
|
288
|
-
for (let i = 0; i < 12; i++) {
|
|
238
|
+
for(let i = 0; i < 12; i++){
|
|
289
239
|
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
290
240
|
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
291
241
|
G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
@@ -326,65 +276,44 @@ export class _BLAKE2b extends _BLAKE2 {
|
|
|
326
276
|
clean(this.buffer32);
|
|
327
277
|
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
328
278
|
}
|
|
279
|
+
constructor(opts = {}){
|
|
280
|
+
const olen = void 0 === opts.dkLen ? 64 : opts.dkLen;
|
|
281
|
+
super(128, olen), this.v0l = 0 | B2B_IV[0], this.v0h = 0 | B2B_IV[1], this.v1l = 0 | B2B_IV[2], this.v1h = 0 | B2B_IV[3], this.v2l = 0 | B2B_IV[4], this.v2h = 0 | B2B_IV[5], this.v3l = 0 | B2B_IV[6], this.v3h = 0 | B2B_IV[7], this.v4l = 0 | B2B_IV[8], this.v4h = 0 | B2B_IV[9], this.v5l = 0 | B2B_IV[10], this.v5h = 0 | B2B_IV[11], this.v6l = 0 | B2B_IV[12], this.v6h = 0 | B2B_IV[13], this.v7l = 0 | B2B_IV[14], this.v7h = 0 | B2B_IV[15];
|
|
282
|
+
checkBlake2Opts(olen, opts, 64, 16, 16);
|
|
283
|
+
let { key, personalization, salt } = opts;
|
|
284
|
+
let keyLength = 0;
|
|
285
|
+
if (void 0 !== key) {
|
|
286
|
+
abytes(key, void 0, 'key');
|
|
287
|
+
keyLength = key.length;
|
|
288
|
+
}
|
|
289
|
+
this.v0l ^= this.outputLen | keyLength << 8 | 16842752;
|
|
290
|
+
if (void 0 !== salt) {
|
|
291
|
+
abytes(salt, void 0, 'salt');
|
|
292
|
+
const slt = u32(salt);
|
|
293
|
+
this.v4l ^= swap8IfBE(slt[0]);
|
|
294
|
+
this.v4h ^= swap8IfBE(slt[1]);
|
|
295
|
+
this.v5l ^= swap8IfBE(slt[2]);
|
|
296
|
+
this.v5h ^= swap8IfBE(slt[3]);
|
|
297
|
+
}
|
|
298
|
+
if (void 0 !== personalization) {
|
|
299
|
+
abytes(personalization, void 0, 'personalization');
|
|
300
|
+
const pers = u32(personalization);
|
|
301
|
+
this.v6l ^= swap8IfBE(pers[0]);
|
|
302
|
+
this.v6h ^= swap8IfBE(pers[1]);
|
|
303
|
+
this.v7l ^= swap8IfBE(pers[2]);
|
|
304
|
+
this.v7h ^= swap8IfBE(pers[3]);
|
|
305
|
+
}
|
|
306
|
+
if (void 0 !== key) {
|
|
307
|
+
const tmp = new Uint8Array(this.blockLen);
|
|
308
|
+
tmp.set(key);
|
|
309
|
+
this.update(tmp);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
329
312
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
* @param msg - message that would be hashed
|
|
333
|
-
* @param opts - Optional output, MAC, salt, and personalization settings.
|
|
334
|
-
* `dkLen` must be 1..64 bytes; `salt` and `personalization`, if present,
|
|
335
|
-
* must be 16 bytes each. See {@link Blake2Opts}.
|
|
336
|
-
* @returns Digest bytes.
|
|
337
|
-
* @example
|
|
338
|
-
* Hash a message with Blake2b.
|
|
339
|
-
* ```ts
|
|
340
|
-
* blake2b(new Uint8Array([97, 98, 99]));
|
|
341
|
-
* ```
|
|
342
|
-
*/
|
|
343
|
-
export const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
|
|
344
|
-
/**
|
|
345
|
-
* BLAKE2-compress core method.
|
|
346
|
-
* Runs only the round function over a caller-supplied local vector; callers initialize `v0..v15`
|
|
347
|
-
* and apply the final `h[i] ^= v[i] ^ v[i + 8]` fold themselves.
|
|
348
|
-
* @param s - flattened sigma schedule bytes
|
|
349
|
-
* @param offset - starting word offset inside `msg`, not a byte offset
|
|
350
|
-
* @param msg - message words
|
|
351
|
-
* @param rounds - round count to execute
|
|
352
|
-
* @param v0 - state word 0
|
|
353
|
-
* @param v1 - state word 1
|
|
354
|
-
* @param v2 - state word 2
|
|
355
|
-
* @param v3 - state word 3
|
|
356
|
-
* @param v4 - state word 4
|
|
357
|
-
* @param v5 - state word 5
|
|
358
|
-
* @param v6 - state word 6
|
|
359
|
-
* @param v7 - state word 7
|
|
360
|
-
* @param v8 - state word 8
|
|
361
|
-
* @param v9 - state word 9
|
|
362
|
-
* @param v10 - state word 10
|
|
363
|
-
* @param v11 - state word 11
|
|
364
|
-
* @param v12 - state word 12
|
|
365
|
-
* @param v13 - state word 13
|
|
366
|
-
* @param v14 - state word 14
|
|
367
|
-
* @param v15 - state word 15
|
|
368
|
-
* @returns Updated compression state words.
|
|
369
|
-
* @example
|
|
370
|
-
* Run the BLAKE2 compression core on zeroed state and message words.
|
|
371
|
-
* ```ts
|
|
372
|
-
* import { compress } from '@noble/hashes/blake2.js';
|
|
373
|
-
* const state = compress(
|
|
374
|
-
* new Uint8Array(16),
|
|
375
|
-
* 0,
|
|
376
|
-
* new Uint32Array(16),
|
|
377
|
-
* 1,
|
|
378
|
-
* 0, 0, 0, 0, 0, 0, 0, 0,
|
|
379
|
-
* 0, 0, 0, 0, 0, 0, 0, 0
|
|
380
|
-
* );
|
|
381
|
-
* state.v0;
|
|
382
|
-
* ```
|
|
383
|
-
*/
|
|
384
|
-
// prettier-ignore
|
|
385
|
-
export function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
|
|
313
|
+
const blake2b = /* @__PURE__ */ createHasher((opts)=>new _BLAKE2b(opts));
|
|
314
|
+
function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
|
|
386
315
|
let j = 0;
|
|
387
|
-
for
|
|
316
|
+
for(let i = 0; i < rounds; i++){
|
|
388
317
|
({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));
|
|
389
318
|
({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));
|
|
390
319
|
({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
|
|
@@ -402,73 +331,52 @@ export function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7,
|
|
|
402
331
|
({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));
|
|
403
332
|
({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));
|
|
404
333
|
}
|
|
405
|
-
return {
|
|
334
|
+
return {
|
|
335
|
+
v0,
|
|
336
|
+
v1,
|
|
337
|
+
v2,
|
|
338
|
+
v3,
|
|
339
|
+
v4,
|
|
340
|
+
v5,
|
|
341
|
+
v6,
|
|
342
|
+
v7,
|
|
343
|
+
v8,
|
|
344
|
+
v9,
|
|
345
|
+
v10,
|
|
346
|
+
v11,
|
|
347
|
+
v12,
|
|
348
|
+
v13,
|
|
349
|
+
v14,
|
|
350
|
+
v15
|
|
351
|
+
};
|
|
406
352
|
}
|
|
407
|
-
// Blake2s reuses the SHA-256 IV words as-is.
|
|
408
353
|
const B2S_IV = /* @__PURE__ */ SHA256_IV.slice();
|
|
409
|
-
|
|
410
|
-
export class _BLAKE2s extends _BLAKE2 {
|
|
411
|
-
// Internal state, same as SHA-256
|
|
412
|
-
v0 = B2S_IV[0] | 0;
|
|
413
|
-
v1 = B2S_IV[1] | 0;
|
|
414
|
-
v2 = B2S_IV[2] | 0;
|
|
415
|
-
v3 = B2S_IV[3] | 0;
|
|
416
|
-
v4 = B2S_IV[4] | 0;
|
|
417
|
-
v5 = B2S_IV[5] | 0;
|
|
418
|
-
v6 = B2S_IV[6] | 0;
|
|
419
|
-
v7 = B2S_IV[7] | 0;
|
|
420
|
-
constructor(opts = {}) {
|
|
421
|
-
const olen = opts.dkLen === undefined ? 32 : opts.dkLen;
|
|
422
|
-
super(64, olen);
|
|
423
|
-
checkBlake2Opts(olen, opts, 32, 8, 8);
|
|
424
|
-
let { key, personalization, salt } = opts;
|
|
425
|
-
let keyLength = 0;
|
|
426
|
-
if (key !== undefined) {
|
|
427
|
-
abytes(key, undefined, 'key');
|
|
428
|
-
keyLength = key.length;
|
|
429
|
-
}
|
|
430
|
-
// RFC 7693 §2.5: xor `p[0] = 0x0101kknn` directly into `h[0]`, since
|
|
431
|
-
// BLAKE2s stores each state word as one `u32`.
|
|
432
|
-
this.v0 ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
|
433
|
-
if (salt !== undefined) {
|
|
434
|
-
abytes(salt, undefined, 'salt');
|
|
435
|
-
const slt = u32(salt);
|
|
436
|
-
this.v4 ^= swap8IfBE(slt[0]);
|
|
437
|
-
this.v5 ^= swap8IfBE(slt[1]);
|
|
438
|
-
}
|
|
439
|
-
if (personalization !== undefined) {
|
|
440
|
-
abytes(personalization, undefined, 'personalization');
|
|
441
|
-
const pers = u32(personalization);
|
|
442
|
-
this.v6 ^= swap8IfBE(pers[0]);
|
|
443
|
-
this.v7 ^= swap8IfBE(pers[1]);
|
|
444
|
-
}
|
|
445
|
-
if (key !== undefined) {
|
|
446
|
-
// Pad to blockLen and update
|
|
447
|
-
const tmp = new Uint8Array(this.blockLen);
|
|
448
|
-
tmp.set(key);
|
|
449
|
-
this.update(tmp);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
354
|
+
class _BLAKE2s extends _BLAKE2 {
|
|
452
355
|
get() {
|
|
453
356
|
const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;
|
|
454
|
-
return [
|
|
357
|
+
return [
|
|
358
|
+
v0,
|
|
359
|
+
v1,
|
|
360
|
+
v2,
|
|
361
|
+
v3,
|
|
362
|
+
v4,
|
|
363
|
+
v5,
|
|
364
|
+
v6,
|
|
365
|
+
v7
|
|
366
|
+
];
|
|
455
367
|
}
|
|
456
|
-
// prettier-ignore
|
|
457
368
|
set(v0, v1, v2, v3, v4, v5, v6, v7) {
|
|
458
|
-
this.v0 =
|
|
459
|
-
this.v1 =
|
|
460
|
-
this.v2 =
|
|
461
|
-
this.v3 =
|
|
462
|
-
this.v4 =
|
|
463
|
-
this.v5 =
|
|
464
|
-
this.v6 =
|
|
465
|
-
this.v7 =
|
|
369
|
+
this.v0 = 0 | v0;
|
|
370
|
+
this.v1 = 0 | v1;
|
|
371
|
+
this.v2 = 0 | v2;
|
|
372
|
+
this.v3 = 0 | v3;
|
|
373
|
+
this.v4 = 0 | v4;
|
|
374
|
+
this.v5 = 0 | v5;
|
|
375
|
+
this.v6 = 0 | v6;
|
|
376
|
+
this.v7 = 0 | v7;
|
|
466
377
|
}
|
|
467
378
|
compress(msg, offset, isLast) {
|
|
468
|
-
const { h, l } =
|
|
469
|
-
// Seed v8..v15 from the IV, xor the low/high 32-bit byte counter into
|
|
470
|
-
// v12/v13, and invert v14 on the final block.
|
|
471
|
-
// prettier-ignore
|
|
379
|
+
const { h, l } = __rspack_external__u64_js_3c1fe104.fromBig(BigInt(this.length));
|
|
472
380
|
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(BSIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, B2S_IV[0], B2S_IV[1], B2S_IV[2], B2S_IV[3], l ^ B2S_IV[4], h ^ B2S_IV[5], isLast ? ~B2S_IV[6] : B2S_IV[6], B2S_IV[7]);
|
|
473
381
|
this.v0 ^= v0 ^ v8;
|
|
474
382
|
this.v1 ^= v1 ^ v9;
|
|
@@ -484,18 +392,35 @@ export class _BLAKE2s extends _BLAKE2 {
|
|
|
484
392
|
clean(this.buffer32);
|
|
485
393
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
486
394
|
}
|
|
395
|
+
constructor(opts = {}){
|
|
396
|
+
const olen = void 0 === opts.dkLen ? 32 : opts.dkLen;
|
|
397
|
+
super(64, olen), this.v0 = 0 | B2S_IV[0], this.v1 = 0 | B2S_IV[1], this.v2 = 0 | B2S_IV[2], this.v3 = 0 | B2S_IV[3], this.v4 = 0 | B2S_IV[4], this.v5 = 0 | B2S_IV[5], this.v6 = 0 | B2S_IV[6], this.v7 = 0 | B2S_IV[7];
|
|
398
|
+
checkBlake2Opts(olen, opts, 32, 8, 8);
|
|
399
|
+
let { key, personalization, salt } = opts;
|
|
400
|
+
let keyLength = 0;
|
|
401
|
+
if (void 0 !== key) {
|
|
402
|
+
abytes(key, void 0, 'key');
|
|
403
|
+
keyLength = key.length;
|
|
404
|
+
}
|
|
405
|
+
this.v0 ^= this.outputLen | keyLength << 8 | 16842752;
|
|
406
|
+
if (void 0 !== salt) {
|
|
407
|
+
abytes(salt, void 0, 'salt');
|
|
408
|
+
const slt = u32(salt);
|
|
409
|
+
this.v4 ^= swap8IfBE(slt[0]);
|
|
410
|
+
this.v5 ^= swap8IfBE(slt[1]);
|
|
411
|
+
}
|
|
412
|
+
if (void 0 !== personalization) {
|
|
413
|
+
abytes(personalization, void 0, 'personalization');
|
|
414
|
+
const pers = u32(personalization);
|
|
415
|
+
this.v6 ^= swap8IfBE(pers[0]);
|
|
416
|
+
this.v7 ^= swap8IfBE(pers[1]);
|
|
417
|
+
}
|
|
418
|
+
if (void 0 !== key) {
|
|
419
|
+
const tmp = new Uint8Array(this.blockLen);
|
|
420
|
+
tmp.set(key);
|
|
421
|
+
this.update(tmp);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
487
424
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
* @param msg - message that would be hashed
|
|
491
|
-
* @param opts - Optional output, MAC, salt, and personalization settings.
|
|
492
|
-
* `dkLen` must be 1..32 bytes; `salt` and `personalization`, if present,
|
|
493
|
-
* must be 8 bytes each. See {@link Blake2Opts}.
|
|
494
|
-
* @returns Digest bytes.
|
|
495
|
-
* @example
|
|
496
|
-
* Hash a message with Blake2s.
|
|
497
|
-
* ```ts
|
|
498
|
-
* blake2s(new Uint8Array([97, 98, 99]));
|
|
499
|
-
* ```
|
|
500
|
-
*/
|
|
501
|
-
export const blake2s = /* @__PURE__ */ createHasher((opts) => new _BLAKE2s(opts));
|
|
425
|
+
const blake2s = /* @__PURE__ */ createHasher((opts)=>new _BLAKE2s(opts));
|
|
426
|
+
export { _BLAKE2, _BLAKE2b, _BLAKE2s, blake2b, blake2s, compress };
|