@sequencemedia/pbkdf2 1.0.406 → 1.1.1
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/config/compare.mjs +10 -1
- package/eslint.config.mjs +48 -17
- package/jsconfig.json +5 -0
- package/package.json +11 -7
- package/scripts/compare.mjs +1 -1
- package/scripts/hash.mjs +1 -1
- package/scripts/salt.mjs +1 -1
- package/src/common/index.d.mts +3 -0
- package/{utils/common.mjs → src/common/index.mjs} +8 -0
- package/src/compare.d.mts +13 -0
- package/src/compare.mjs +39 -0
- package/src/hash.d.mts +12 -0
- package/{utils → src}/hash.mjs +15 -5
- package/src/index.d.mts +22 -0
- package/src/index.mjs +3 -0
- package/src/salt.d.mts +1 -0
- package/{utils → src}/salt.mjs +2 -4
- package/test/{utils → src}/common.spec.mjs +3 -2
- package/test/{utils → src}/compare.spec.mjs +2 -2
- package/tsconfig.json +8 -3
- package/babel.config.cjs +0 -32
- package/index.d.mts +0 -5
- package/index.mjs +0 -9
- package/utils/compare.mjs +0 -23
- /package/{utils → config}/args-map.mjs +0 -0
package/config/compare.mjs
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import argsMap from '
|
|
1
|
+
import argsMap from './args-map.mjs'
|
|
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/eslint.config.mjs
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import merge from '@sequencemedia/eslint-config-standard/merge'
|
|
2
1
|
import globals from 'globals'
|
|
2
|
+
import jsdoc from 'eslint-plugin-jsdoc'
|
|
3
|
+
import standard from '@sequencemedia/eslint-config-standard/merge'
|
|
4
|
+
import typescript from '@sequencemedia/eslint-config-typescript/merge'
|
|
3
5
|
|
|
4
|
-
export default
|
|
5
|
-
|
|
6
|
+
export default [
|
|
7
|
+
jsdoc.configs['flat/recommended'],
|
|
8
|
+
{
|
|
9
|
+
languageOptions: {
|
|
10
|
+
globals: {
|
|
11
|
+
ArrayBufferLike: 'readonly'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
...standard({
|
|
16
|
+
files: [
|
|
17
|
+
'**/*.{mjs,cjs,mts,cts}'
|
|
18
|
+
],
|
|
19
|
+
ignores: [
|
|
20
|
+
'test'
|
|
21
|
+
],
|
|
22
|
+
languageOptions: {
|
|
23
|
+
globals: {
|
|
24
|
+
...globals.node
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
...typescript({
|
|
6
29
|
files: [
|
|
7
|
-
'**/*.{
|
|
30
|
+
'**/*.{mts,cts}'
|
|
8
31
|
],
|
|
9
32
|
ignores: [
|
|
10
33
|
'test'
|
|
@@ -14,17 +37,25 @@ export default (
|
|
|
14
37
|
...globals.node
|
|
15
38
|
}
|
|
16
39
|
}
|
|
40
|
+
}),
|
|
41
|
+
...standard({
|
|
42
|
+
files: [
|
|
43
|
+
'test/**/*.{mjs,cjs,mts,cts}'
|
|
44
|
+
],
|
|
45
|
+
languageOptions: {
|
|
46
|
+
globals: {
|
|
47
|
+
...globals.mocha
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
...typescript({
|
|
52
|
+
files: [
|
|
53
|
+
'test/**/*.{mts,cts}'
|
|
54
|
+
],
|
|
55
|
+
languageOptions: {
|
|
56
|
+
globals: {
|
|
57
|
+
...globals.mocha
|
|
58
|
+
}
|
|
59
|
+
}
|
|
17
60
|
})
|
|
18
|
-
|
|
19
|
-
merge({
|
|
20
|
-
files: [
|
|
21
|
-
'test/**/*.{cjs,mjs}'
|
|
22
|
-
],
|
|
23
|
-
languageOptions: {
|
|
24
|
-
globals: {
|
|
25
|
-
...globals.mocha
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
)
|
|
30
|
-
)
|
|
61
|
+
]
|
package/jsconfig.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/pbkdf2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"pbkdf2",
|
|
6
6
|
"crypto",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"ecmascript",
|
|
11
11
|
"typescript"
|
|
12
12
|
],
|
|
13
|
-
"main": "./index.mjs",
|
|
13
|
+
"main": "./src/index.mjs",
|
|
14
14
|
"type": "module",
|
|
15
|
-
"types": "./index.d.mts",
|
|
15
|
+
"types": "./src/index.d.mts",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "Jonathan Perry for Sequence Media Limited",
|
|
18
18
|
"email": "sequencemedia@sequencemedia.net",
|
|
@@ -37,20 +37,24 @@
|
|
|
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
40
|
"@sequencemedia/eslint-config-standard": "^0.2.35",
|
|
41
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.50",
|
|
42
|
+
"@types/chai": "^5.0.1",
|
|
43
|
+
"@types/mocha": "^10.0.10",
|
|
43
44
|
"@types/node": "^22.13.5",
|
|
45
|
+
"@types/yargs-parser": "^21.0.3",
|
|
44
46
|
"chai": "^5.2.0",
|
|
45
|
-
"core-js": "^3.40.0",
|
|
46
47
|
"cross-env": "^7.0.3",
|
|
47
48
|
"eslint": "^9.21.0",
|
|
49
|
+
"eslint-plugin-jsdoc": "^50.6.3",
|
|
48
50
|
"globals": "^16.0.0",
|
|
49
51
|
"husky": "^9.1.7",
|
|
50
52
|
"mocha": "^11.1.0"
|
|
51
53
|
},
|
|
52
54
|
"imports": {
|
|
53
55
|
"#config/*": "./config/*.mjs",
|
|
54
|
-
"#
|
|
56
|
+
"#pbkdf2/*": "./src/*.mjs",
|
|
57
|
+
"#pbkdf2": "./src/index.mjs",
|
|
58
|
+
"#pbkdf2/common": "./src/common/index.mjs"
|
|
55
59
|
}
|
|
56
60
|
}
|
package/scripts/compare.mjs
CHANGED
package/scripts/hash.mjs
CHANGED
package/scripts/salt.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
|
+
interface 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/src/compare.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('node:crypto').BinaryLike} BinaryLike
|
|
3
|
+
* @typedef {{
|
|
4
|
+
* salt: BinaryLike,
|
|
5
|
+
* hash: Buffer,
|
|
6
|
+
* iterations?: number,
|
|
7
|
+
* keylen?: number,
|
|
8
|
+
* digest?: string
|
|
9
|
+
* }} CompareParams
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* salt: BinaryLike,
|
|
12
|
+
* iterations?: number,
|
|
13
|
+
* keylen?: number,
|
|
14
|
+
* digest?: string
|
|
15
|
+
* }} HashParams
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
timingSafeEqual
|
|
20
|
+
} from 'node:crypto'
|
|
21
|
+
|
|
22
|
+
import hash from './hash.mjs'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {BinaryLike} password
|
|
26
|
+
* @param {CompareParams} params
|
|
27
|
+
* @returns {Promise<boolean>}
|
|
28
|
+
*/
|
|
29
|
+
export default async function compare (password, {
|
|
30
|
+
hash: alpha,
|
|
31
|
+
...params
|
|
32
|
+
}) {
|
|
33
|
+
/**
|
|
34
|
+
* @type {Buffer<ArrayBufferLike>}
|
|
35
|
+
*/
|
|
36
|
+
const omega = await hash(password, params)
|
|
37
|
+
|
|
38
|
+
return timingSafeEqual(alpha, omega)
|
|
39
|
+
}
|
package/src/hash.d.mts
ADDED
package/{utils → src}/hash.mjs
RENAMED
|
@@ -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
|
-
*
|
|
12
|
-
*
|
|
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) => {
|
package/src/index.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BinaryLike
|
|
3
|
+
} from 'node:crypto'
|
|
4
|
+
|
|
5
|
+
export interface CompareParams {
|
|
6
|
+
salt: BinaryLike
|
|
7
|
+
hash: Buffer
|
|
8
|
+
iterations?: number
|
|
9
|
+
keylen?: number
|
|
10
|
+
digest?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface 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/src/index.mjs
ADDED
package/src/salt.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function salt (size: number): Promise<Buffer>
|
package/{utils → src}/salt.mjs
RENAMED
|
@@ -3,11 +3,9 @@ import {
|
|
|
3
3
|
} from 'node:crypto'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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) => {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
expect
|
|
3
3
|
} from 'chai'
|
|
4
|
+
|
|
4
5
|
import {
|
|
5
6
|
fromBase64ToBuffer,
|
|
6
7
|
fromBufferToBase64
|
|
7
|
-
} from '#
|
|
8
|
+
} from '#pbkdf2/common'
|
|
8
9
|
|
|
9
|
-
describe('`#
|
|
10
|
+
describe('`#pbkdf2/common`', () => {
|
|
10
11
|
describe('fromBase64ToBuffer', () => it('is a function', () => expect(fromBase64ToBuffer).to.be.a('function')))
|
|
11
12
|
|
|
12
13
|
describe('fromBufferToBase64', () => it('is a function', () => expect(fromBufferToBase64).to.be.a('function')))
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
expect
|
|
3
3
|
} from 'chai'
|
|
4
|
-
import compare from '#
|
|
4
|
+
import compare from '#pbkdf2/compare'
|
|
5
5
|
|
|
6
|
-
describe('`#
|
|
6
|
+
describe('`#pbkdf2/compare`', () => {
|
|
7
7
|
describe('compare', () => it('is a function', () => expect(compare).to.be.a('function')))
|
|
8
8
|
|
|
9
9
|
describe('compare()', () => {
|
package/tsconfig.json
CHANGED
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
|
-
}
|
package/index.d.mts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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>
|
|
5
|
-
}
|
package/index.mjs
DELETED
package/utils/compare.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
timingSafeEqual
|
|
3
|
-
} from 'node:crypto'
|
|
4
|
-
import hash from './hash.mjs'
|
|
5
|
-
|
|
6
|
-
/**
|
|
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
|
-
* }
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export default async function compare (password, {
|
|
17
|
-
hash: alpha,
|
|
18
|
-
...params
|
|
19
|
-
} = {}) {
|
|
20
|
-
const omega = await hash(password, params)
|
|
21
|
-
|
|
22
|
-
return timingSafeEqual(alpha, omega)
|
|
23
|
-
}
|
|
File without changes
|