@pirxpilot/argon2 0.44.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/argon2.js +7 -13
- package/package.json +1 -1
package/argon2.js
CHANGED
|
@@ -2,6 +2,7 @@ import { argon2, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { deserialize, serialize } from '@phc/format';
|
|
4
4
|
|
|
5
|
+
/** @type {(id: string, options: object) => Promise<Buffer>} */
|
|
5
6
|
const asyncArgon2 = promisify(argon2);
|
|
6
7
|
|
|
7
8
|
/** @type {(size: number) => Promise<Buffer>} */
|
|
@@ -11,15 +12,7 @@ export const argon2d = 0;
|
|
|
11
12
|
export const argon2i = 1;
|
|
12
13
|
export const argon2id = 2;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
const types = Object.freeze({ argon2d, argon2i, argon2id });
|
|
16
|
-
|
|
17
|
-
/** @enum {'argon2d' | 'argon2i' | 'argon2id'} */
|
|
18
|
-
const names = Object.freeze({
|
|
19
|
-
[types.argon2d]: 'argon2d',
|
|
20
|
-
[types.argon2i]: 'argon2i',
|
|
21
|
-
[types.argon2id]: 'argon2id'
|
|
22
|
-
});
|
|
15
|
+
const names = ['argon2d', 'argon2i', 'argon2id'];
|
|
23
16
|
|
|
24
17
|
const defaults = {
|
|
25
18
|
hashLength: 32,
|
|
@@ -36,8 +29,8 @@ const defaults = {
|
|
|
36
29
|
* @property {number} [timeCost=3]
|
|
37
30
|
* @property {number} [memoryCost=65536]
|
|
38
31
|
* @property {number} [parallelism=4]
|
|
39
|
-
* @property {
|
|
40
|
-
* @property {number} [version=
|
|
32
|
+
* @property {argon2d | argon2i | argon2id} [type=argon2id]
|
|
33
|
+
* @property {number} [version=0x13]
|
|
41
34
|
* @property {Buffer} [salt]
|
|
42
35
|
* @property {Buffer} [associatedData]
|
|
43
36
|
* @property {Buffer} [secret]
|
|
@@ -150,7 +143,8 @@ export function needsRehash(digest, options = {}) {
|
|
|
150
143
|
*/
|
|
151
144
|
export async function verify(digest, password, options = {}) {
|
|
152
145
|
const { id, ...rest } = deserialize(digest);
|
|
153
|
-
if (!(id
|
|
146
|
+
if (!names.includes(id)) {
|
|
147
|
+
console.error(`Unknown Argon2 id: ${id}`);
|
|
154
148
|
return false;
|
|
155
149
|
}
|
|
156
150
|
|
|
@@ -163,7 +157,7 @@ export async function verify(digest, password, options = {}) {
|
|
|
163
157
|
const { secret = Buffer.alloc(0) } = options;
|
|
164
158
|
|
|
165
159
|
return timingSafeEqual(
|
|
166
|
-
await asyncArgon2(
|
|
160
|
+
await asyncArgon2(id, {
|
|
167
161
|
message: Buffer.from(password),
|
|
168
162
|
nonce: salt,
|
|
169
163
|
tagLength: hash.byteLength,
|