@sequencemedia/crypto 1.2.36 → 1.2.38
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/crypto.d.mts +3 -3
- package/package.json +13 -4
- package/src/index.d.mts +21 -0
- package/src/index.mjs +18 -0
- package/src/shell/decrypt.d.mts +2 -0
- package/src/shell/encrypt.d.mts +2 -0
- package/tsconfig.json +6 -1
package/crypto.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '@sequencemedia/crypto' {
|
|
2
|
-
export function hashKey(secret: string): string
|
|
3
|
-
export function encrypt(buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
|
4
|
-
export function decrypt(buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
|
2
|
+
export function hashKey (secret: string): string
|
|
3
|
+
export function encrypt (buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
|
4
|
+
export function decrypt (buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
|
5
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/crypto",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.38",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"crypto",
|
|
6
6
|
"node",
|
|
@@ -25,8 +25,13 @@
|
|
|
25
25
|
"url": "git@github.com:sequencemedia/crypto.git"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"lint": "
|
|
29
|
-
"lint:
|
|
28
|
+
"lint": "npm run lint:js && npm run lint:ts",
|
|
29
|
+
"lint:js": "eslint . --ext .mjs,.cjs",
|
|
30
|
+
"lint:ts": "eslint . --ext .mts,.cts",
|
|
31
|
+
"lint:fix": "npm run lint:js:fix && npm run lint:ts:fix",
|
|
32
|
+
"lint:js:fix": "npm run lint:js -- --fix",
|
|
33
|
+
"lint:ts:fix": "npm run lint:ts -- --fix",
|
|
34
|
+
"types": "tsc src/**/*.mjs --declaration --allowJs --emitDeclarationOnly",
|
|
30
35
|
"prepare": "husky install"
|
|
31
36
|
},
|
|
32
37
|
"devDependencies": {
|
|
@@ -36,10 +41,14 @@
|
|
|
36
41
|
"@babel/preset-env": "^7.22.10",
|
|
37
42
|
"@sequencemedia/hooks": "^1.0.446",
|
|
38
43
|
"@types/node": "^20.4.10",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
45
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
39
46
|
"core-js": "^3.32.0",
|
|
40
47
|
"eslint": "^8.47.0",
|
|
41
48
|
"eslint-config-standard": "^17.1.0",
|
|
42
|
-
"
|
|
49
|
+
"eslint-config-standard-with-typescript": "^37.0.0",
|
|
50
|
+
"husky": "^8.0.3",
|
|
51
|
+
"typescript": "^5.1.6"
|
|
43
52
|
},
|
|
44
53
|
"exports": {
|
|
45
54
|
".": "./src/index.mjs"
|
package/src/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} secret
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export function hashKey (secret: string): string
|
|
6
|
+
/**
|
|
7
|
+
* @param {Buffer} buffer
|
|
8
|
+
* @param {string} secret
|
|
9
|
+
* @param {number} [bytes]
|
|
10
|
+
* @param {string} [algorithm]
|
|
11
|
+
* @returns {Buffer}
|
|
12
|
+
*/
|
|
13
|
+
export function encrypt (buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
|
14
|
+
/**
|
|
15
|
+
* @param {Buffer} buffer
|
|
16
|
+
* @param {string} secret
|
|
17
|
+
* @param {number} [bytes]
|
|
18
|
+
* @param {string} [algorithm]
|
|
19
|
+
* @returns {Buffer}
|
|
20
|
+
*/
|
|
21
|
+
export function decrypt (buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer
|
package/src/index.mjs
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} secret
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
3
7
|
export function hashKey (secret) {
|
|
4
8
|
if (!secret) throw new Error('A secret is required')
|
|
5
9
|
|
|
6
10
|
return crypto.createHash('sha256').update(secret).digest('base64').substring(0, 32)
|
|
7
11
|
}
|
|
8
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @param {Buffer} buffer
|
|
15
|
+
* @param {string} secret
|
|
16
|
+
* @param {number} [bytes]
|
|
17
|
+
* @param {string} [algorithm]
|
|
18
|
+
* @returns {Buffer}
|
|
19
|
+
*/
|
|
9
20
|
export function encrypt (buffer, secret, bytes = 16, algorithm = 'aes-256-ctr') {
|
|
10
21
|
const iv = crypto.randomBytes(bytes)
|
|
11
22
|
const cipher = crypto.createCipheriv(algorithm, hashKey(secret), iv)
|
|
12
23
|
return Buffer.concat([iv, cipher.update(buffer), cipher.final()])
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @param {Buffer} buffer
|
|
28
|
+
* @param {string} secret
|
|
29
|
+
* @param {number} [bytes]
|
|
30
|
+
* @param {string} [algorithm]
|
|
31
|
+
* @returns {Buffer}
|
|
32
|
+
*/
|
|
15
33
|
export function decrypt (buffer, secret, bytes = 16, algorithm = 'aes-256-ctr') {
|
|
16
34
|
const iv = buffer.slice(0, bytes)
|
|
17
35
|
const decipher = crypto.createDecipheriv(algorithm, hashKey(secret), iv)
|