@sequencemedia/crypto 1.2.35 → 1.2.37

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 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.35",
3
+ "version": "1.2.37",
4
4
  "keywords": [
5
5
  "crypto",
6
6
  "node",
@@ -25,7 +25,7 @@
25
25
  "url": "git@github.com:sequencemedia/crypto.git"
26
26
  },
27
27
  "scripts": {
28
- "lint": "eslint . --ext .mjs,.cjs",
28
+ "lint": "eslint . --ext .mjs,.cjs,.mts,.cts",
29
29
  "lint:fix": "npm run lint -- --fix",
30
30
  "prepare": "husky install"
31
31
  },
@@ -34,11 +34,14 @@
34
34
  "@babel/core": "^7.22.10",
35
35
  "@babel/eslint-parser": "^7.22.10",
36
36
  "@babel/preset-env": "^7.22.10",
37
- "@sequencemedia/hooks": "^1.0.445",
38
- "@types/node": "^20.4.9",
37
+ "@sequencemedia/hooks": "^1.0.446",
38
+ "@types/node": "^20.4.10",
39
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
40
+ "@typescript-eslint/parser": "^5.62.0",
39
41
  "core-js": "^3.32.0",
40
42
  "eslint": "^8.47.0",
41
43
  "eslint-config-standard": "^17.1.0",
44
+ "eslint-config-standard-with-typescript": "^37.0.0",
42
45
  "husky": "^8.0.3"
43
46
  },
44
47
  "exports": {
@@ -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)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {}
package/tsconfig.json CHANGED
@@ -1,5 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "nodenext"
3
+ "module": "nodenext",
4
+ "allowJs": true,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "declarationMap": true,
8
+ "strictNullChecks": true
4
9
  }
5
10
  }