@warlock.js/core 4.0.136 → 4.0.137
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.
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hashes a password using bcrypt (async — does not block the event loop).
|
|
3
3
|
*
|
|
4
|
-
* Salt rounds are read from
|
|
4
|
+
* Salt rounds are read from \`encryption.password.saltRounds\` config,
|
|
5
5
|
* defaulting to 12.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* import { hashPassword } from "@warlock.js/core";
|
|
9
9
|
*
|
|
10
10
|
* const hashed = await hashPassword("user-password-123");
|
|
11
|
-
* // Store
|
|
11
|
+
* // Store \`hashed\` in the database
|
|
12
12
|
*/
|
|
13
13
|
export declare function hashPassword(password: string): Promise<string>;
|
|
14
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/encryption/password.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/encryption/password.ts"],"names":[],"mappings":"AAgDA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWpE;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAMlB"}
|
|
@@ -1,22 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {config}from'../config/config-getter.js';import'../config/config-handlers.js';/**
|
|
2
2
|
* Default bcrypt salt rounds.
|
|
3
3
|
*/
|
|
4
4
|
const DEFAULT_SALT_ROUNDS = 12;
|
|
5
|
+
// ============================================================
|
|
6
|
+
// Lazy-loaded bcryptjs SDK Types
|
|
7
|
+
// ============================================================
|
|
8
|
+
/**
|
|
9
|
+
* Cached bcryptjs module (loaded once, reused)
|
|
10
|
+
*/
|
|
11
|
+
let Bcryptjs;
|
|
12
|
+
let isModuleExists = null;
|
|
13
|
+
/**
|
|
14
|
+
* Installation instructions for bcryptjs package
|
|
15
|
+
*/
|
|
16
|
+
const BCRYPTJS_INSTALL_INSTRUCTIONS = `
|
|
17
|
+
Password encryption requires the bcryptjs package.
|
|
18
|
+
Install it with:
|
|
19
|
+
|
|
20
|
+
npm install bcryptjs
|
|
21
|
+
|
|
22
|
+
Or with your preferred package manager:
|
|
23
|
+
|
|
24
|
+
pnpm add bcryptjs
|
|
25
|
+
yarn add bcryptjs
|
|
26
|
+
`.trim();
|
|
27
|
+
/**
|
|
28
|
+
* Load bcryptjs module
|
|
29
|
+
*/
|
|
30
|
+
async function loadBcryptjs() {
|
|
31
|
+
try {
|
|
32
|
+
Bcryptjs = await import('bcryptjs');
|
|
33
|
+
isModuleExists = true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
isModuleExists = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
loadBcryptjs();
|
|
5
40
|
/**
|
|
6
41
|
* Hashes a password using bcrypt (async — does not block the event loop).
|
|
7
42
|
*
|
|
8
|
-
* Salt rounds are read from
|
|
43
|
+
* Salt rounds are read from \`encryption.password.saltRounds\` config,
|
|
9
44
|
* defaulting to 12.
|
|
10
45
|
*
|
|
11
46
|
* @example
|
|
12
47
|
* import { hashPassword } from "@warlock.js/core";
|
|
13
48
|
*
|
|
14
49
|
* const hashed = await hashPassword("user-password-123");
|
|
15
|
-
* // Store
|
|
50
|
+
* // Store \`hashed\` in the database
|
|
16
51
|
*/
|
|
17
52
|
async function hashPassword(password) {
|
|
53
|
+
if (!isModuleExists) {
|
|
54
|
+
throw new Error(BCRYPTJS_INSTALL_INSTRUCTIONS);
|
|
55
|
+
}
|
|
18
56
|
const saltRounds = config.key("encryption.password.salt", DEFAULT_SALT_ROUNDS);
|
|
19
|
-
return hash(String(password), saltRounds);
|
|
57
|
+
return Bcryptjs.hash(String(password), saltRounds);
|
|
20
58
|
}
|
|
21
59
|
/**
|
|
22
60
|
* Verifies a plain password against a bcrypt hash (async — does not block the event loop).
|
|
@@ -27,5 +65,8 @@ async function hashPassword(password) {
|
|
|
27
65
|
* const isValid = await verifyPassword("user-password-123", storedHash);
|
|
28
66
|
*/
|
|
29
67
|
async function verifyPassword(plainPassword, hashedPassword) {
|
|
30
|
-
|
|
68
|
+
if (!isModuleExists) {
|
|
69
|
+
throw new Error(BCRYPTJS_INSTALL_INSTRUCTIONS);
|
|
70
|
+
}
|
|
71
|
+
return Bcryptjs.compare(String(plainPassword), String(hashedPassword));
|
|
31
72
|
}export{hashPassword,verifyPassword};//# sourceMappingURL=password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.js","sources":["../../src/encryption/password.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password.js","sources":["../../src/encryption/password.ts"],"sourcesContent":[null],"names":[],"mappings":"qFAGA;;AAEG;AACH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;AACA;AACA;AAEA;;AAEG;AACH,IAAI,QAAmC,CAAC;AAExC,IAAI,cAAc,GAAmB,IAAI,CAAC;AAE1C;;AAEG;AACH,MAAM,6BAA6B,GAAG,CAAA;;;;;;;;;;CAUrC,CAAC,IAAI,EAAE,CAAC;AAET;;AAEG;AACH,eAAe,YAAY,GAAA;IACzB,IAAI;AACF,QAAA,QAAQ,GAAG,MAAM,OAAO,UAAU,CAAC,CAAC;QACpC,cAAc,GAAG,IAAI,CAAC;AACvB,KAAA;IAAC,MAAM;QACN,cAAc,GAAG,KAAK,CAAC;AACxB,KAAA;AACH,CAAC;AAED,YAAY,EAAE,CAAC;AAEf;;;;;;;;;;;AAWG;AACI,eAAe,YAAY,CAAC,QAAgB,EAAA;IACjD,IAAI,CAAC,cAAc,EAAE;AACnB,QAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAChD,KAAA;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAC3B,0BAA0B,EAC1B,mBAAmB,CACnB,CAAC;IAEH,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;AAOG;AACI,eAAe,cAAc,CAClC,aAAqB,EACrB,cAAsB,EAAA;IAEtB,IAAI,CAAC,cAAc,EAAE;AACnB,QAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAChD,KAAA;AAED,IAAA,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;AACzE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warlock.js/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.137",
|
|
4
4
|
"description": "A robust nodejs framework for building blazing fast applications",
|
|
5
5
|
"main": "./esm/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"@mongez/slug": "^1.0.7",
|
|
28
28
|
"@mongez/supportive-is": "^2.0.4",
|
|
29
29
|
"@mongez/time-wizard": "^1.0.6",
|
|
30
|
-
"@warlock.js/auth": "4.0.
|
|
31
|
-
"@warlock.js/cache": "4.0.
|
|
32
|
-
"@warlock.js/cascade": "4.0.
|
|
33
|
-
"@warlock.js/context": "4.0.
|
|
34
|
-
"@warlock.js/logger": "4.0.
|
|
35
|
-
"@warlock.js/seal": "4.0.
|
|
30
|
+
"@warlock.js/auth": "4.0.137",
|
|
31
|
+
"@warlock.js/cache": "4.0.137",
|
|
32
|
+
"@warlock.js/cascade": "4.0.137",
|
|
33
|
+
"@warlock.js/context": "4.0.137",
|
|
34
|
+
"@warlock.js/logger": "4.0.137",
|
|
35
|
+
"@warlock.js/seal": "4.0.137",
|
|
36
36
|
"axios": "^1.7.9",
|
|
37
37
|
"chokidar": "^5.0.0",
|
|
38
38
|
"dayjs": "^1.11.19",
|