@sequencemedia/pbkdf2 1.0.405 → 1.1.0

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,17 +1,26 @@
1
1
  import argsMap from '#utils/args-map'
2
2
 
3
+ /**
4
+ * @type {number}
5
+ */
3
6
  export const ITERATIONS = (
4
7
  argsMap.has('ITERATIONS')
5
8
  ? argsMap.get('ITERATIONS')
6
9
  : 10
7
10
  )
8
11
 
12
+ /**
13
+ * @type {number}
14
+ */
9
15
  export const KEYLEN = (
10
16
  argsMap.has('KEYLEN')
11
17
  ? argsMap.get('KEYLEN')
12
18
  : 64
13
19
  )
14
20
 
21
+ /**
22
+ * @type {string}
23
+ */
15
24
  export const DIGEST = (
16
25
  argsMap.has('DIGEST')
17
26
  ? argsMap.get('DIGEST')
package/index.d.mts CHANGED
@@ -1,5 +1,22 @@
1
- declare module '@sequencemedia/pbkdf2' {
2
- export function compare(password: string, params: { salt: string, hash: Buffer, iteration?: number, keylen?: number, digest?: string }): Promise<boolean>
3
- export function hash (password: string, params: { salt: string, iteration?: number, keylen?: number, digest?: string }): Promise<Buffer>
4
- export function salt (size: number): Promise<Buffer>
1
+ import type {
2
+ BinaryLike
3
+ } from 'node:crypto'
4
+
5
+ export type CompareParams = {
6
+ salt: BinaryLike,
7
+ hash: Buffer,
8
+ iterations?: number,
9
+ keylen?: number,
10
+ digest?: string
5
11
  }
12
+
13
+ export type HashParams = {
14
+ salt: BinaryLike,
15
+ iterations?: number,
16
+ keylen?: number,
17
+ digest?: string
18
+ }
19
+
20
+ export function compare(password: BinaryLike, params: CompareParams): Promise<boolean>
21
+ export function hash (password: BinaryLike, params: HashParams): Promise<Buffer>
22
+ export function salt (size: number): Promise<Buffer>
package/jsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "."
4
+ }
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/pbkdf2",
3
- "version": "1.0.405",
3
+ "version": "1.1.0",
4
4
  "keywords": [
5
5
  "pbkdf2",
6
6
  "crypto",
@@ -37,12 +37,12 @@
37
37
  "yargs-parser": "^21.1.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@babel/core": "^7.26.9",
41
- "@babel/preset-env": "^7.26.9",
42
- "@sequencemedia/eslint-config-standard": "^0.2.34",
40
+ "@sequencemedia/eslint-config-standard": "^0.2.35",
41
+ "@types/chai": "^5.0.1",
42
+ "@types/mocha": "^10.0.10",
43
43
  "@types/node": "^22.13.5",
44
+ "@types/yargs-parser": "^21.0.3",
44
45
  "chai": "^5.2.0",
45
- "core-js": "^3.40.0",
46
46
  "cross-env": "^7.0.3",
47
47
  "eslint": "^9.21.0",
48
48
  "globals": "^16.0.0",
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  expect
3
3
  } from 'chai'
4
+
4
5
  import {
5
6
  fromBase64ToBuffer,
6
7
  fromBufferToBase64
package/tsconfig.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "types": [
4
- "node"
5
- ]
3
+ "module": "NodeNext",
4
+ "target": "ESNext",
5
+ "allowJs": true,
6
+ "checkJs": true,
7
+ "noEmit": true,
8
+ "strict": true,
9
+ "isolatedModules": true,
10
+ "baseUrl": "."
6
11
  }
7
12
  }
@@ -0,0 +1,3 @@
1
+ export function fromBase64ToBuffer (string: string): Buffer
2
+
3
+ export function fromBufferToBase64 (buffer: Buffer): string
package/utils/common.mjs CHANGED
@@ -1,7 +1,15 @@
1
+ /**
2
+ * @param {string} string
3
+ * @returns {Buffer}
4
+ */
1
5
  export function fromBase64ToBuffer (string) {
2
6
  return Buffer.from(string, 'base64')
3
7
  }
4
8
 
9
+ /**
10
+ * @param {Buffer} buffer
11
+ * @returns {string}
12
+ */
5
13
  export function fromBufferToBase64 (buffer) {
6
14
  return buffer.toString('base64')
7
15
  }
@@ -0,0 +1,13 @@
1
+ import type {
2
+ BinaryLike
3
+ } from 'node:crypto'
4
+
5
+ type CompareParams = {
6
+ salt: BinaryLike,
7
+ hash: Buffer,
8
+ iterations?: number,
9
+ keylen?: number,
10
+ digest?: string
11
+ }
12
+
13
+ export default function compare (password: BinaryLike, params: CompareParams): Promise<boolean>
package/utils/compare.mjs CHANGED
@@ -1,22 +1,40 @@
1
+ /**
2
+ * @typedef {import('node:crypto').BinaryLike} BinaryLike
3
+ *
4
+ * @typedef {{
5
+ * salt: BinaryLike,
6
+ * hash: Buffer,
7
+ * iterations?: number,
8
+ * keylen?: number,
9
+ * digest?: string
10
+ * }} CompareParams
11
+ *
12
+ * @typedef {{
13
+ * salt: BinaryLike,
14
+ * iterations?: number,
15
+ * keylen?: number,
16
+ * digest?: string
17
+ * }} HashParams
18
+ */
19
+
1
20
  import {
2
21
  timingSafeEqual
3
22
  } from 'node:crypto'
23
+
4
24
  import hash from './hash.mjs'
5
25
 
6
26
  /**
7
- * function compare (password, salt, h, complete = () => {}) {
8
- * hash(password, salt, (e, v) => {
9
- * if (e) return complete(e)
10
- *
11
- * complete(null, timingSafeEqual(h, v))
12
- * })
13
- * }
27
+ * @param {BinaryLike} password
28
+ * @param {CompareParams} params
29
+ * @returns {Promise<boolean>}
14
30
  */
15
-
16
31
  export default async function compare (password, {
17
32
  hash: alpha,
18
33
  ...params
19
- } = {}) {
34
+ }) {
35
+ /**
36
+ * @type {Buffer<ArrayBufferLike>}
37
+ */
20
38
  const omega = await hash(password, params)
21
39
 
22
40
  return timingSafeEqual(alpha, omega)
@@ -0,0 +1,11 @@
1
+
2
+ import type {BinaryLike} from 'node:crypto'
3
+
4
+ type HashParams = {
5
+ salt: BinaryLike,
6
+ iterations?: number,
7
+ keylen?: number,
8
+ digest?: string
9
+ }
10
+
11
+ export default function hash (password: BinaryLike, params: HashParams): Promise<Buffer>
package/utils/hash.mjs CHANGED
@@ -1,6 +1,17 @@
1
+ /**
2
+ * @typedef {import('node:crypto').BinaryLike} BinaryLike
3
+ * @typedef {{
4
+ * salt: BinaryLike,
5
+ * iterations?: number,
6
+ * keylen?: number,
7
+ * digest?: string
8
+ * }} HashParams
9
+ */
10
+
1
11
  import {
2
12
  pbkdf2
3
13
  } from 'node:crypto'
14
+
4
15
  import {
5
16
  ITERATIONS,
6
17
  KEYLEN,
@@ -8,17 +19,16 @@ import {
8
19
  } from '#config/compare'
9
20
 
10
21
  /**
11
- * function hash (password, salt, complete = () => {}) {
12
- * pbkdf2(password, salt, ITERATIONS, KEYLEN, DIGEST, complete)
13
- * }
22
+ * @param {BinaryLike} password
23
+ * @param {HashParams} params
24
+ * @returns {Promise<Buffer>}
14
25
  */
15
-
16
26
  export default function hash (password, {
17
27
  salt,
18
28
  iterations = ITERATIONS,
19
29
  keylen = KEYLEN,
20
30
  digest = DIGEST
21
- } = {}) {
31
+ }) {
22
32
  return (
23
33
  new Promise((resolve, reject) => {
24
34
  pbkdf2(password, salt, iterations, keylen, digest, (e, buffer) => {
@@ -0,0 +1 @@
1
+ export default function salt (size: number): Promise<Buffer>
package/utils/salt.mjs CHANGED
@@ -3,11 +3,9 @@ import {
3
3
  } from 'node:crypto'
4
4
 
5
5
  /**
6
- * function salt (size, complete = () => {}) {
7
- * randomBytes(size, complete)
8
- * }
6
+ * @param {number} size
7
+ * @returns {Promise<Buffer>}
9
8
  */
10
-
11
9
  export default function salt (size) {
12
10
  return (
13
11
  new Promise((resolve, reject) => {
package/babel.config.cjs DELETED
@@ -1,32 +0,0 @@
1
- const {
2
- env: {
3
- NODE_ENV = 'development'
4
- }
5
- } = process
6
-
7
- function env () {
8
- return (
9
- NODE_ENV === 'production'
10
- )
11
- }
12
-
13
- const presets = [
14
- [
15
- '@babel/env',
16
- {
17
- targets: {
18
- node: 'current'
19
- },
20
- useBuiltIns: 'usage',
21
- corejs: 3
22
- }
23
- ]
24
- ]
25
-
26
- module.exports = (api) => {
27
- if (api) api.cache.using(env)
28
-
29
- return {
30
- presets
31
- }
32
- }