@sequencemedia/pbkdf2 1.0.273 → 1.0.275
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/eslint.config.mjs +30 -0
- package/package.json +7 -7
- package/test/utils/common.spec.mjs +71 -0
- package/test/utils/compare.spec.mjs +81 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import merge from '@sequencemedia/eslint-config-standard/merge'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
|
|
4
|
+
export default (
|
|
5
|
+
merge({
|
|
6
|
+
files: [
|
|
7
|
+
'**/*.{cjs,mjs}'
|
|
8
|
+
],
|
|
9
|
+
ignores: [
|
|
10
|
+
'test'
|
|
11
|
+
],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
globals: {
|
|
14
|
+
...globals.node
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.concat(
|
|
19
|
+
merge({
|
|
20
|
+
files: [
|
|
21
|
+
'test/**/*.{cjs,mjs}'
|
|
22
|
+
],
|
|
23
|
+
languageOptions: {
|
|
24
|
+
globals: {
|
|
25
|
+
...globals.mocha
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
)
|
|
30
|
+
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/pbkdf2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.275",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"pbkdf2",
|
|
6
6
|
"crypto",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"compare": "node scripts/compare.mjs",
|
|
28
28
|
"hash": "node scripts/hash.mjs",
|
|
29
|
-
"lint": "eslint .
|
|
29
|
+
"lint": "eslint .",
|
|
30
30
|
"lint:fix": "npm run lint -- --fix",
|
|
31
31
|
"prepare": "husky",
|
|
32
32
|
"salt": "node scripts/salt.mjs",
|
|
33
|
-
"test": "cross-env NODE_ENV=test mocha
|
|
33
|
+
"test": "cross-env NODE_ENV=test mocha test --recursive --verbose --color"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"debug": "^4.3.5",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@babel/core": "^7.24.7",
|
|
41
|
-
"@babel/eslint-parser": "^7.24.7",
|
|
42
41
|
"@babel/preset-env": "^7.24.7",
|
|
43
|
-
"@sequencemedia/
|
|
42
|
+
"@sequencemedia/eslint-config-standard": "^0.0.10",
|
|
43
|
+
"@sequencemedia/hooks": "^1.0.500",
|
|
44
44
|
"@types/node": "^20.14.10",
|
|
45
45
|
"chai": "^5.1.1",
|
|
46
46
|
"core-js": "^3.37.1",
|
|
47
47
|
"cross-env": "^7.0.3",
|
|
48
|
-
"eslint": "
|
|
49
|
-
"
|
|
48
|
+
"eslint": "^9.6.0",
|
|
49
|
+
"globals": "^15.8.0",
|
|
50
50
|
"husky": "^9.0.11",
|
|
51
51
|
"mocha": "^10.6.0"
|
|
52
52
|
},
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
expect
|
|
3
|
+
} from 'chai'
|
|
4
|
+
import {
|
|
5
|
+
fromBase64ToBuffer,
|
|
6
|
+
fromBufferToBase64
|
|
7
|
+
} from '#utils/common'
|
|
8
|
+
|
|
9
|
+
describe('`#utils/common`', () => {
|
|
10
|
+
describe('fromBase64ToBuffer', () => it('is a function', () => expect(fromBase64ToBuffer).to.be.a('function')))
|
|
11
|
+
|
|
12
|
+
describe('fromBufferToBase64', () => it('is a function', () => expect(fromBufferToBase64).to.be.a('function')))
|
|
13
|
+
|
|
14
|
+
describe('fromBase64ToBuffer()', () => {
|
|
15
|
+
describe('User 1', () => {
|
|
16
|
+
it('returns a buffer', () => {
|
|
17
|
+
const BASE64 = 'YzFjMTY4MmMyMWE4MjFkYjRhNWE5YjJmNDY0OTUzM2Q='
|
|
18
|
+
const BUFFER = Buffer.from('c1c1682c21a821db4a5a9b2f4649533d')
|
|
19
|
+
|
|
20
|
+
return expect(Buffer.compare(fromBase64ToBuffer(BASE64), BUFFER)).to.equal(0)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('User 2', () => {
|
|
25
|
+
it('returns a buffer', () => {
|
|
26
|
+
const BASE64 = 'MDI2OGM0MDU4NWJiOTgxNWEyYzQwN2RkYjM1YTY5YWU='
|
|
27
|
+
const BUFFER = Buffer.from('0268c40585bb9815a2c407ddb35a69ae')
|
|
28
|
+
|
|
29
|
+
return expect(Buffer.compare(fromBase64ToBuffer(BASE64), BUFFER)).to.equal(0)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('User 3', () => {
|
|
34
|
+
it('returns a buffer', () => {
|
|
35
|
+
const BASE64 = 'ZDI3OTZmZWU3M2I3M2Y3MTgxMmYyNGM3MjU4NDE2NDM='
|
|
36
|
+
const BUFFER = Buffer.from('d2796fee73b73f71812f24c725841643')
|
|
37
|
+
|
|
38
|
+
return expect(Buffer.compare(fromBase64ToBuffer(BASE64), BUFFER)).to.equal(0)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('fromBufferToBase64()', () => {
|
|
44
|
+
describe('User 1', () => {
|
|
45
|
+
it('returns a string', () => {
|
|
46
|
+
const BUFFER = Buffer.from('c1c1682c21a821db4a5a9b2f4649533d')
|
|
47
|
+
const BASE64 = 'YzFjMTY4MmMyMWE4MjFkYjRhNWE5YjJmNDY0OTUzM2Q='
|
|
48
|
+
|
|
49
|
+
return expect(fromBufferToBase64(BUFFER)).to.equal(BASE64)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('User 2', () => {
|
|
54
|
+
it('returns a string', () => {
|
|
55
|
+
const BUFFER = Buffer.from('0268c40585bb9815a2c407ddb35a69ae')
|
|
56
|
+
const BASE64 = 'MDI2OGM0MDU4NWJiOTgxNWEyYzQwN2RkYjM1YTY5YWU='
|
|
57
|
+
|
|
58
|
+
return expect(fromBufferToBase64(BUFFER)).to.equal(BASE64)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('User 3', () => {
|
|
63
|
+
it('returns a string', () => {
|
|
64
|
+
const BUFFER = Buffer.from('d2796fee73b73f71812f24c725841643')
|
|
65
|
+
const BASE64 = 'ZDI3OTZmZWU3M2I3M2Y3MTgxMmYyNGM3MjU4NDE2NDM='
|
|
66
|
+
|
|
67
|
+
return expect(fromBufferToBase64(BUFFER)).to.equal(BASE64)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
expect
|
|
3
|
+
} from 'chai'
|
|
4
|
+
import compare from '#utils/compare'
|
|
5
|
+
|
|
6
|
+
describe('`#utils/compare`', () => {
|
|
7
|
+
describe('compare', () => it('is a function', () => expect(compare).to.be.a('function')))
|
|
8
|
+
|
|
9
|
+
describe('compare()', () => {
|
|
10
|
+
const ITERATIONS = 32768
|
|
11
|
+
|
|
12
|
+
describe('User 1', () => {
|
|
13
|
+
const HASH = Buffer.from('kOhpM7//M4I9+WcWLH7vbb/yN2+8qKyxQ0xAfI4JzamcRMdwwl7vAh0ch7UJ0JoBe9AqaAGuUJZF/mVA9EqaLQ==', 'base64')
|
|
14
|
+
const SALT = 'c1c1682c21a821db4a5a9b2f4649533d'
|
|
15
|
+
|
|
16
|
+
describe('`password` is valid', () => {
|
|
17
|
+
it('returns true', async () => {
|
|
18
|
+
const password = '^49pPaRdVSNC'
|
|
19
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
20
|
+
|
|
21
|
+
return expect(isValid).to.be.true
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('`password` is not valid', () => {
|
|
26
|
+
it('returns false', async () => {
|
|
27
|
+
const password = 'not password'
|
|
28
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
29
|
+
|
|
30
|
+
return expect(isValid).to.be.false
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('User 2', () => {
|
|
36
|
+
const HASH = Buffer.from('BrtOel2qy5HrYWn45jBKf5b3HUKdVeQfIj1ljhGxQ/SiWsmMMuOl756H4MXkMOnVJKrgFfHFy7cgFXUaSFA2ow==', 'base64')
|
|
37
|
+
const SALT = '0268c40585bb9815a2c407ddb35a69ae'
|
|
38
|
+
|
|
39
|
+
describe('`password` is valid', () => {
|
|
40
|
+
it('returns true', async () => {
|
|
41
|
+
const password = 'S0uSaC&FzDOO'
|
|
42
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
43
|
+
|
|
44
|
+
return expect(isValid).to.be.true
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('`password` is not valid', () => {
|
|
49
|
+
it('returns false', async () => {
|
|
50
|
+
const password = 'not password'
|
|
51
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
52
|
+
|
|
53
|
+
return expect(isValid).to.be.false
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('User 3', () => {
|
|
59
|
+
const HASH = Buffer.from('bV76sVqsM0doKBFnaHsZQC9OgcVnF/+gzkG7HFXdD7jyQdN1PqCVijyXKMijmYQPWJohi5f7sVxhoLJ5kf8aQA==', 'base64')
|
|
60
|
+
const SALT = 'd2796fee73b73f71812f24c725841643'
|
|
61
|
+
|
|
62
|
+
describe('`password` is valid', () => {
|
|
63
|
+
it('returns true', async () => {
|
|
64
|
+
const password = '@^EJmdlkt5A#'
|
|
65
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
66
|
+
|
|
67
|
+
return expect(isValid).to.be.true
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('`password` is not valid', () => {
|
|
72
|
+
it('returns false', async () => {
|
|
73
|
+
const password = 'not password'
|
|
74
|
+
const isValid = await compare(password, { hash: HASH, salt: SALT, iterations: ITERATIONS })
|
|
75
|
+
|
|
76
|
+
return expect(isValid).to.be.false
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|