@stacksjs/security 0.56.35 → 0.57.2
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/crypt.d.ts +3 -0
- package/dist/crypt.mjs +16 -0
- package/dist/hash.d.ts +8 -0
- package/dist/hash.mjs +38 -0
- package/dist/index.d.ts +3 -14
- package/dist/index.mjs +3 -65
- package/dist/key.d.ts +1 -0
- package/dist/key.mjs +9 -0
- package/package.json +5 -5
package/dist/crypt.d.ts
ADDED
package/dist/crypt.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import aes from "crypto-js/aes";
|
|
2
|
+
import utf8 from "crypto-js/enc-utf8";
|
|
3
|
+
import { env } from "@stacksjs/validation";
|
|
4
|
+
function encrypt(message) {
|
|
5
|
+
const passphrase = env.APP_KEY;
|
|
6
|
+
if (!passphrase)
|
|
7
|
+
throw new Error("APP_KEY is not defined");
|
|
8
|
+
return aes.encrypt(message, passphrase).toString();
|
|
9
|
+
}
|
|
10
|
+
function decrypt(encrypted) {
|
|
11
|
+
const passphrase = env.APP_KEY;
|
|
12
|
+
if (!passphrase)
|
|
13
|
+
throw new Error("APP_KEY is not defined");
|
|
14
|
+
return aes.decrypt(encrypted, passphrase).toString(utf8);
|
|
15
|
+
}
|
|
16
|
+
export { encrypt, decrypt };
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function make(password: string, algorithm?: string): Promise<any>;
|
|
2
|
+
declare function verify(password: string, hash: string, algorithm?: string): Promise<any>;
|
|
3
|
+
declare function bcryptEncode(password: string): Promise<any>;
|
|
4
|
+
declare function bcryptVerify(password: string, hash: string): Promise<any>;
|
|
5
|
+
declare function base64Encode(password: string): Promise<string>;
|
|
6
|
+
declare function base64Verify(password: string, hash: string): Promise<boolean>;
|
|
7
|
+
declare function md5Encode(password: string): Promise<any>;
|
|
8
|
+
export { make as makeHash, verify as verifyHash, base64Encode, base64Verify, bcryptEncode, bcryptVerify, md5Encode };
|
package/dist/hash.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import bcryptjs from "bcryptjs";
|
|
2
|
+
import { Base64 } from "js-base64";
|
|
3
|
+
import md5 from "crypto-js/md5";
|
|
4
|
+
import { hashing } from "@stacksjs/config";
|
|
5
|
+
async function make(password, algorithm = "bcrypt") {
|
|
6
|
+
if (algorithm === "bcrypt")
|
|
7
|
+
return bcryptEncode(password);
|
|
8
|
+
if (algorithm === "base64")
|
|
9
|
+
return base64Encode(password);
|
|
10
|
+
throw new Error("Unsupported algorithm");
|
|
11
|
+
}
|
|
12
|
+
async function verify(password, hash, algorithm = "bcrypt") {
|
|
13
|
+
if (algorithm === "bcrypt")
|
|
14
|
+
return bcryptVerify(password, hash);
|
|
15
|
+
if (algorithm === "base64")
|
|
16
|
+
return base64Verify(password, hash);
|
|
17
|
+
throw new Error("Unsupported algorithm");
|
|
18
|
+
}
|
|
19
|
+
async function bcryptEncode(password) {
|
|
20
|
+
if (!hashing.bcrypt)
|
|
21
|
+
throw new Error("Bcrypt hashing is not configured");
|
|
22
|
+
const salt = await bcryptjs.genSaltSync(hashing.bcrypt.rounds);
|
|
23
|
+
const hash = await bcryptjs.hash(password, salt);
|
|
24
|
+
return hash;
|
|
25
|
+
}
|
|
26
|
+
async function bcryptVerify(password, hash) {
|
|
27
|
+
return await bcryptjs.compare(password, hash);
|
|
28
|
+
}
|
|
29
|
+
async function base64Encode(password) {
|
|
30
|
+
return await Base64.encode(password);
|
|
31
|
+
}
|
|
32
|
+
async function base64Verify(password, hash) {
|
|
33
|
+
return Base64.decode(hash) === password;
|
|
34
|
+
}
|
|
35
|
+
async function md5Encode(password) {
|
|
36
|
+
return md5(password);
|
|
37
|
+
}
|
|
38
|
+
export { make as makeHash, verify as verifyHash, base64Encode, base64Verify, bcryptEncode, bcryptVerify, md5Encode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function decrypt(encrypted: string): string;
|
|
5
|
-
|
|
6
|
-
declare function make(password: string, algorithm?: string): Promise<string>;
|
|
7
|
-
declare function verify(password: string, hash: string, algorithm?: string): Promise<boolean>;
|
|
8
|
-
declare function bcryptEncode(password: string): Promise<string>;
|
|
9
|
-
declare function bcryptVerify(password: string, hash: string): Promise<boolean>;
|
|
10
|
-
declare function base64Encode(password: string): Promise<string>;
|
|
11
|
-
declare function base64Verify(password: string, hash: string): Promise<boolean>;
|
|
12
|
-
declare function md5Encode(password: string): Promise<CryptoJS.lib.WordArray>;
|
|
13
|
-
|
|
14
|
-
export { base64Encode, base64Verify, bcryptEncode, bcryptVerify, decrypt, encrypt, generateAppKey, make as makeHash, md5Encode, verify as verifyHash };
|
|
1
|
+
export * from './key';
|
|
2
|
+
export * from './crypt';
|
|
3
|
+
export * from './hash';
|
package/dist/index.mjs
CHANGED
|
@@ -1,65 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import aes from 'crypto-js/aes';
|
|
5
|
-
import { env } from '@stacksjs/validation';
|
|
6
|
-
import bcryptjs from 'bcryptjs';
|
|
7
|
-
import { Base64 } from 'js-base64';
|
|
8
|
-
import md5 from 'crypto-js/md5';
|
|
9
|
-
import { hashing } from '@stacksjs/config';
|
|
10
|
-
|
|
11
|
-
async function generateAppKey() {
|
|
12
|
-
const random = getRandomValues(new Uint8Array(32));
|
|
13
|
-
const encodedWord = utf8.parse(random.toString());
|
|
14
|
-
const key = base64.stringify(encodedWord);
|
|
15
|
-
return `base64:${key}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function encrypt(message) {
|
|
19
|
-
const passphrase = env.APP_KEY;
|
|
20
|
-
if (!passphrase)
|
|
21
|
-
throw new Error("APP_KEY is not defined");
|
|
22
|
-
return aes.encrypt(message, passphrase).toString();
|
|
23
|
-
}
|
|
24
|
-
function decrypt(encrypted) {
|
|
25
|
-
const passphrase = env.APP_KEY;
|
|
26
|
-
if (!passphrase)
|
|
27
|
-
throw new Error("APP_KEY is not defined");
|
|
28
|
-
return aes.decrypt(encrypted, passphrase).toString(utf8);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function make(password, algorithm = "bcrypt") {
|
|
32
|
-
if (algorithm === "bcrypt")
|
|
33
|
-
return bcryptEncode(password);
|
|
34
|
-
if (algorithm === "base64")
|
|
35
|
-
return base64Encode(password);
|
|
36
|
-
throw new Error("Unsupported algorithm");
|
|
37
|
-
}
|
|
38
|
-
async function verify(password, hash, algorithm = "bcrypt") {
|
|
39
|
-
if (algorithm === "bcrypt")
|
|
40
|
-
return bcryptVerify(password, hash);
|
|
41
|
-
if (algorithm === "base64")
|
|
42
|
-
return base64Verify(password, hash);
|
|
43
|
-
throw new Error("Unsupported algorithm");
|
|
44
|
-
}
|
|
45
|
-
async function bcryptEncode(password) {
|
|
46
|
-
if (!hashing.bcrypt)
|
|
47
|
-
throw new Error("Bcrypt hashing is not configured");
|
|
48
|
-
const salt = await bcryptjs.genSaltSync(hashing.bcrypt.rounds);
|
|
49
|
-
const hash = await bcryptjs.hash(password, salt);
|
|
50
|
-
return hash;
|
|
51
|
-
}
|
|
52
|
-
async function bcryptVerify(password, hash) {
|
|
53
|
-
return await bcryptjs.compare(password, hash);
|
|
54
|
-
}
|
|
55
|
-
async function base64Encode(password) {
|
|
56
|
-
return await Base64.encode(password);
|
|
57
|
-
}
|
|
58
|
-
async function base64Verify(password, hash) {
|
|
59
|
-
return Base64.decode(hash) === password;
|
|
60
|
-
}
|
|
61
|
-
async function md5Encode(password) {
|
|
62
|
-
return md5(password);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { base64Encode, base64Verify, bcryptEncode, bcryptVerify, decrypt, encrypt, generateAppKey, make as makeHash, md5Encode, verify as verifyHash };
|
|
1
|
+
export * from "./key.mjs";
|
|
2
|
+
export * from "./crypt.mjs";
|
|
3
|
+
export * from "./hash.mjs";
|
package/dist/key.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateAppKey(): Promise<string>;
|
package/dist/key.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getRandomValues } from "node:crypto";
|
|
2
|
+
import utf8 from "crypto-js/enc-utf8";
|
|
3
|
+
import base64 from "crypto-js/enc-base64";
|
|
4
|
+
export async function generateAppKey() {
|
|
5
|
+
const random = getRandomValues(new Uint8Array(32));
|
|
6
|
+
const encodedWord = utf8.parse(random.toString());
|
|
7
|
+
const key = base64.stringify(encodedWord);
|
|
8
|
+
return `base64:${key}`;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/security",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.57.2",
|
|
5
5
|
"packageManager": "pnpm@8.6.5",
|
|
6
6
|
"description": "The Stacks framework security.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"bcryptjs": "^2.4.3",
|
|
42
42
|
"crypto-js": "^4.1.1",
|
|
43
43
|
"js-base64": "^3.7.5",
|
|
44
|
-
"@stacksjs/config": "0.
|
|
45
|
-
"@stacksjs/types": "0.
|
|
46
|
-
"@stacksjs/validation": "0.
|
|
44
|
+
"@stacksjs/config": "0.57.2",
|
|
45
|
+
"@stacksjs/types": "0.57.2",
|
|
46
|
+
"@stacksjs/validation": "0.57.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@stacksjs/development": "0.
|
|
49
|
+
"@stacksjs/development": "0.57.2"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "unbuild",
|