@stacksjs/security 0.37.8 → 0.38.3

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/README.md CHANGED
@@ -1,32 +1,30 @@
1
- # Stacks Router
1
+ # Stacks Path
2
2
 
3
- This package contains the Stacks Security.
3
+ Easily work with encryptions, decryptions, and hashing.
4
4
 
5
5
  ## ☘️ Features
6
6
 
7
- wip
8
-
9
- - ⚡️
10
-
11
- wip
7
+ - Base64 support
8
+ - Bcrypt support
9
+ - Argon support
10
+ - Implements the Advanced Encryption Standard (AES)
11
+ - Written in modern ESM/TypeScript
12
12
 
13
13
  ## 🤖 Usage
14
14
 
15
- wip
16
-
17
15
  ```bash
18
16
  pnpm i -D @stacksjs/security
19
17
  ```
20
18
 
21
- Now, you can use it in your project:
19
+ Now, you can easily access it in your project:
22
20
 
23
21
  ```js
24
- import * as security from '@stacksjs/security'
22
+ import { base64Encode, base64Verify, bcryptEncode, bcryptVerify, decrypt, encrypt, makeHash, md5Encode, verifyHash } from '@stacksjs/security'
25
23
 
26
- // wip
24
+ // and more...
27
25
  ```
28
26
 
29
- Learn more in the docs.
27
+ To view the full documentation, please visit [https://stacksjs.dev/security](https://stacksjs.dev/security).
30
28
 
31
29
  ## 🧪 Testing
32
30
 
@@ -36,7 +34,7 @@ pnpm test
36
34
 
37
35
  ## 📈 Changelog
38
36
 
39
- Please see our [releases](https://github.com/stacksjs/stacksjs/releases) page for more information on what has changed recently.
37
+ Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
40
38
 
41
39
  ## 💪🏼 Contributing
42
40
 
@@ -52,6 +50,15 @@ For casual chit-chat with others using this package:
52
50
 
53
51
  [Join the Open Web Discord Server](https://discord.ow3.org)
54
52
 
53
+ ## 🙏🏼 Credits
54
+
55
+ Many thanks to the following core technologies & people who have contributed to this package:
56
+
57
+ - [crypto-js](https://github.com/brix/crypto-js)
58
+ - [js-base64](https://www.npmjs.com/package/js-base64)
59
+ - [Chris Breuer](https://github.com/chrisbbreuer)
60
+ - [All Contributors](../../contributors)
61
+
55
62
  ## 📄 License
56
63
 
57
64
  The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
package/dist/hash.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import bcryptjs from "bcryptjs";
2
2
  import { Base64 } from "js-base64";
3
3
  import md5 from "crypto-js/md5";
4
- import { hashing } from "../../../config";
4
+ import { hashing } from "@stacksjs/config";
5
5
  async function make(password, algorithm = "bcrypt") {
6
6
  if (algorithm === "bcrypt")
7
7
  return bcryptEncode(password);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/security",
3
3
  "type": "module",
4
- "version": "0.37.8",
5
- "packageManager": "pnpm@7.14.0",
4
+ "version": "0.38.3",
5
+ "packageManager": "pnpm@7.15.0",
6
6
  "description": "The Stacks framework security.",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -30,22 +30,22 @@
30
30
  ],
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "README.md"
35
34
  ],
36
35
  "engines": {
37
- "node": ">=v18.10.0",
38
- "pnpm": ">=7.14.0"
36
+ "node": ">=v18.12.1",
37
+ "pnpm": ">=7.15.0"
39
38
  },
40
- "dependencies": {
41
- "@types/bcryptjs": "^2.4.2",
42
- "@types/crypto-js": "^4.1.1",
39
+ "peerDependencies": {
40
+ "@stacksjs/config": "0.38.3",
41
+ "@stacksjs/types": "0.38.3",
43
42
  "bcryptjs": "^2.4.3",
44
43
  "crypto-js": "^4.1.1",
45
44
  "js-base64": "^3.7.2"
46
45
  },
47
46
  "devDependencies": {
48
- "mkdist": "^0.3.13"
47
+ "mkdist": "^0.4.0",
48
+ "typescript": "^4.8.4"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "mkdist -d",
package/src/crypt.ts DELETED
@@ -1,14 +0,0 @@
1
- import aes from 'crypto-js/aes'
2
- import utf8 from 'crypto-js/enc-utf8'
3
-
4
- const passphrase = import.meta.env.APP_KEY as string
5
-
6
- function encrypt(message: string): string {
7
- return aes.encrypt(message, passphrase).toString()
8
- }
9
-
10
- function decrypt(encrypted: string): string {
11
- return aes.decrypt(encrypted, passphrase).toString(utf8)
12
- }
13
-
14
- export { encrypt, decrypt }
package/src/hash.ts DELETED
@@ -1,52 +0,0 @@
1
- import bcryptjs from 'bcryptjs'
2
- import { Base64 } from 'js-base64'
3
- import md5 from 'crypto-js/md5'
4
- import { hashing } from '../../../config'
5
-
6
- async function make(password: string, algorithm = 'bcrypt') {
7
- if (algorithm === 'bcrypt')
8
- return bcryptEncode(password)
9
-
10
- if (algorithm === 'base64')
11
- return base64Encode(password)
12
-
13
- throw new Error('Unsupported algorithm')
14
- }
15
-
16
- async function verify(password: string, hash: string, algorithm = 'bcrypt') {
17
- if (algorithm === 'bcrypt')
18
- return bcryptVerify(password, hash)
19
-
20
- if (algorithm === 'base64')
21
- return base64Verify(password, hash)
22
-
23
- throw new Error('Unsupported algorithm')
24
- }
25
-
26
- async function bcryptEncode(password: string) {
27
- if (!hashing.bcrypt)
28
- throw new Error('Bcrypt hashing is not configured')
29
-
30
- const salt = await bcryptjs.genSaltSync(hashing.bcrypt.rounds)
31
- const hash = await bcryptjs.hash(password, salt)
32
-
33
- return hash
34
- }
35
-
36
- async function bcryptVerify(password: string, hash: string) {
37
- return await bcryptjs.compare(password, hash)
38
- }
39
-
40
- async function base64Encode(password: string) {
41
- return await Base64.encode(password)
42
- }
43
-
44
- async function base64Verify(password: string, hash: string) {
45
- return Base64.decode(hash) === password
46
- }
47
-
48
- async function md5Encode(password: string) {
49
- return md5(password)
50
- }
51
-
52
- export { make as makeHash, verify as verifyHash, base64Encode, base64Verify, bcryptEncode, bcryptVerify, md5Encode }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './key'
2
- export * from './crypt'
3
- export * from './hash'
package/src/key.ts DELETED
@@ -1,11 +0,0 @@
1
- import { getRandomValues } from 'node:crypto'
2
- import utf8 from 'crypto-js/enc-utf8'
3
- import base64 from 'crypto-js/enc-base64'
4
-
5
- export async function generateAppKey() {
6
- const random = getRandomValues(new Uint8Array(32))
7
- const encodedWord = utf8.parse(random.toString())
8
- const key = base64.stringify(encodedWord)
9
-
10
- return `base64:${key}`
11
- }