@secrez/core 1.0.2 → 1.0.4

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/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -4,15 +4,15 @@ Secrez is the secrets manager for the cryptocurrencies era.
4
4
 
5
5
  @secrez/core is the basic library.
6
6
 
7
- It exposes
8
- * Secrez
9
- * Crypto
10
- * Entry
11
- * config
12
- * ConfigUtils
7
+ It exposes
13
8
 
14
- Those classes are used by other Secrez packages to interact with the encrypted database.
9
+ - Secrez
10
+ - Crypto
11
+ - Entry
12
+ - config
13
+ - ConfigUtils
15
14
 
15
+ Those classes are used by other Secrez packages to interact with the encrypted database.
16
16
 
17
17
  ## TODO
18
18
 
@@ -20,32 +20,31 @@ API documentation
20
20
 
21
21
  ## History
22
22
 
23
- __0.8.5__
24
- * improve _Secrez and Secrez encapsulation of private data
25
- * when changing the password, compares the existent password with the derivated one to avoid brute force attacks from inside Secrez (for example, in a future plugin)
23
+ **0.8.5**
26
24
 
25
+ - improve \_Secrez and Secrez encapsulation of private data
26
+ - when changing the password, compares the existent password with the derivated one to avoid brute force attacks from inside Secrez (for example, in a future plugin)
27
27
 
28
28
  ## Test coverage
29
29
 
30
30
  ```
31
- 60 passing (2s)
31
+ 60 passing (1s)
32
32
 
33
33
  -----------------|---------|----------|---------|---------|-------------------
34
34
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
35
35
  -----------------|---------|----------|---------|---------|-------------------
36
36
  All files | 99.75 | 94.31 | 100 | 99.75 |
37
37
  src | 100 | 96.07 | 100 | 100 |
38
- Entry.js | 100 | 95.65 | 100 | 100 | 40
39
- Secrez.js | 100 | 96.95 | 100 | 100 | 132,287,405
40
- _Secrez.js | 100 | 91.67 | 100 | 100 | 18,218
41
- src/config | 98.57 | 84.85 | 100 | 98.55 |
42
- ConfigUtils.js | 98.48 | 84.85 | 100 | 98.46 | 116
38
+ Entry.js | 100 | 95.65 | 100 | 100 | 39
39
+ Secrez.js | 100 | 96.95 | 100 | 100 | 154,319,442
40
+ _Secrez.js | 100 | 91.67 | 100 | 100 | 14,226
41
+ src/config | 98.57 | 84.85 | 100 | 98.57 |
42
+ ConfigUtils.js | 98.48 | 84.85 | 100 | 98.48 | 137
43
43
  booleans.js | 100 | 100 | 100 | 100 |
44
44
  index.js | 100 | 100 | 100 | 100 |
45
45
  -----------------|---------|----------|---------|---------|-------------------
46
46
  ```
47
47
 
48
-
49
48
  ## Copyright
50
49
 
51
50
  (c) 2020-present [Francesco Sullo](https://francesco.sullo.co) (<francesco@sullo.co>)
package/_sullof/mom.js ADDED
@@ -0,0 +1,23 @@
1
+ const Crypto = require('@secrez/crypto')
2
+ let a = `function kriminal(ts) {
3
+ ts = ts % 1e4
4
+ const R = []
5
+ const is = {}
6
+ for (; ;) {
7
+ let h = ethers.utils.id('' + ts)
8
+ for (let i = 2; i < h.length; i++) {
9
+ let v = parseInt(h.substring(i, i + 1))
10
+ if (!isNaN(v) && v < 7 && !is[v]) {
11
+ R.push(v)
12
+ if (~R.length === -4) {
13
+ return R
14
+ }
15
+ is[v] = 1
16
+ }
17
+ ts++
18
+ }
19
+ }
20
+ }`
21
+
22
+ console.log(Crypto.toBase64(a))
23
+
package/coverage.report CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
- > @secrez/core@1.0.2 test /Users/sullof/Projects/Personal/secrez/packages/core
3
- > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ./node_modules/.bin/_mocha test/*.test.js test/**/*.test.js --exit
2
+ > @secrez/core@1.0.4 test /Users/francescosullo/Projects/Personal/secrez/packages/core
3
+ > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
4
4
 
5
5
 
6
6
 
@@ -26,13 +26,13 @@
26
26
  derivePassword
27
27
  ✓ should derive a password and obtain a predeterminded hash
28
28
  signup and signin
29
- ✓ should signup the user and signin without saving the iterations (69ms)
30
- ✓ should signup in two instances without conflicts (46ms)
31
- ✓ should signup the user and signin saved the iterations (43ms)
32
- ✓ should signup with version one, and signin and upgrade to version two (83ms)
33
- ✓ should signup the user, change password and signin (90ms)
34
- ✓ should signup the user, change iterations and signin (58ms)
35
- ✓ should signup the user, change password and iterations and signin (69ms)
29
+ ✓ should signup the user and signin without saving the iterations (71ms)
30
+ ✓ should signup in two instances without conflicts (41ms)
31
+ ✓ should signup the user and signin saved the iterations (38ms)
32
+ ✓ should signup with version one, and signin and upgrade to version two (68ms)
33
+ ✓ should signup the user, change password and signin (56ms)
34
+ ✓ should signup the user, change iterations and signin (49ms)
35
+ ✓ should signup the user, change password and iterations and signin (67ms)
36
36
  should throw an error
37
37
  ✓ trying to signup if Secrez has not been initiated
38
38
  ✓ trying to signin if Secrez has not been initiated
@@ -40,7 +40,7 @@
40
40
  ✓ trying to signin if account is not set yet
41
41
  ✓ trying to signin with missed iterations
42
42
  ✓ trying to signin with the wrong password
43
- ✓ trying to signin with the right password but wrong number of iterations (50ms)
43
+ ✓ trying to signin with the right password but wrong number of iterations
44
44
  ✓ trying to signin with the right password but using a wrong hash on file
45
45
  ✓ trying to sign out if never signed-in
46
46
  encryptEntry and decryptEntry
@@ -62,22 +62,22 @@
62
62
  ✓ should encrypt some data with the derivedPassword and decrypt it
63
63
  ✓ should throw trying to get the master key
64
64
  generateSharedSecrets && recoverSharedSecrets
65
- ✓ should set up a second factor (66ms)
66
- ✓ should set up a second factor and then upgrade from derivationVersion 1 to 2 (61ms)
67
- ✓ should set up a second factor and a recovery code and remove them (70ms)
68
- ✓ should set up a second factor and a recovery code and remove the recovery code (84ms)
69
- ✓ should throw if wrong secret (40ms)
65
+ ✓ should set up a second factor (57ms)
66
+ ✓ should set up a second factor and then upgrade from derivationVersion 1 to 2
67
+ ✓ should set up a second factor and a recovery code and remove them (58ms)
68
+ ✓ should set up a second factor and a recovery code and remove the recovery code (58ms)
69
+ ✓ should throw if wrong secret
70
70
  ✓ should throw if wrong authenticator
71
71
  #readConf
72
72
  ✓ should encrypt some data with the derivedPassword and decrypt it
73
73
  ✓ should throw trying to get the master key
74
74
  ✓ should throw trying to get the master key
75
75
  #signMessage
76
- ✓ should sign a message and verify it (45ms)
76
+ ✓ should sign a message and verify it (40ms)
77
77
  #getPublicKey
78
- ✓ should sign a message and verify it (42ms)
78
+ ✓ should sign a message and verify it
79
79
  #encrypt and decrypt shared data
80
- ✓ should get a shared ket (63ms)
80
+ ✓ should get a shared ket (50ms)
81
81
 
82
82
  #config
83
83
  ✓ all field should be correctly configured
@@ -91,22 +91,18 @@
91
91
  ✓ #getEnv should return the environment
92
92
 
93
93
 
94
- 60 passing (2s)
94
+ 60 passing (1s)
95
95
 
96
96
  -----------------|---------|----------|---------|---------|-------------------
97
97
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
98
98
  -----------------|---------|----------|---------|---------|-------------------
99
99
  All files | 99.75 | 94.31 | 100 | 99.75 |
100
100
  src | 100 | 96.07 | 100 | 100 |
101
- Entry.js | 100 | 95.65 | 100 | 100 | 40
102
- Secrez.js | 100 | 96.95 | 100 | 100 | 132,287,405
103
- _Secrez.js | 100 | 91.67 | 100 | 100 | 18,218
104
- src/config | 98.57 | 84.85 | 100 | 98.55 |
105
- ConfigUtils.js | 98.48 | 84.85 | 100 | 98.46 | 116
101
+ Entry.js | 100 | 95.65 | 100 | 100 | 39
102
+ Secrez.js | 100 | 96.95 | 100 | 100 | 154,319,442
103
+ _Secrez.js | 100 | 91.67 | 100 | 100 | 14,226
104
+ src/config | 98.57 | 84.85 | 100 | 98.57 |
105
+ ConfigUtils.js | 98.48 | 84.85 | 100 | 98.48 | 137
106
106
  booleans.js | 100 | 100 | 100 | 100 |
107
107
  index.js | 100 | 100 | 100 | 100 |
108
108
  -----------------|---------|----------|---------|---------|-------------------
109
-
110
- > @secrez/core@1.0.2 posttest /Users/sullof/Projects/Personal/secrez/packages/core
111
- > nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99
112
-
package/package.json CHANGED
@@ -1,44 +1,41 @@
1
1
  {
2
- "name": "@secrez/core",
3
- "version": "1.0.2",
4
- "license": "MIT",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "scripts": {
9
- "lint": "eslint -c .eslintrc 'src/**/*.js' 'test/**/*.js'",
10
- "all-tests": "find test/** -name '*.test.js' | xargs ./node_modules/.bin/mocha -R spec",
11
- "test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js --exit",
12
- "test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ./node_modules/.bin/_mocha test/*.test.js test/**/*.test.js --exit",
13
- "posttest": "nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99"
14
- },
15
- "dependencies": {
16
- "@secrez/crypto": "~1.0.1",
17
- "@secrez/utils": "~1.0.0",
18
- "fs-extra": "^9.1.0",
19
- "homedir": "^0.6.0",
20
- "lodash": "^4.17.15"
21
- },
22
- "devDependencies": {
23
- "@secrez/test-helpers": "~1.0.1",
24
- "chai": "^4.2.0",
25
- "cross-env": "^7.0.2",
26
- "eslint": "^6.8.0",
27
- "eslint-plugin-node": "^11.1.0",
28
- "mocha": "^7.1.2",
29
- "nyc": "^15.1.0"
30
- },
31
- "description": "The Secrez core library.",
32
- "main": "src/index.js",
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/secrez/secrez.git"
36
- },
37
- "author": {
38
- "name": "Francesco Sullo",
39
- "email": "francesco@sullo.co"
40
- },
41
- "engines": {
42
- "node": ">=10.0.0"
43
- }
44
- }
2
+ "name": "@secrez/core",
3
+ "version": "1.0.4",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "dependencies": {
9
+ "@secrez/crypto": "~1.0.3",
10
+ "@secrez/utils": "~1.0.3",
11
+ "fs-extra": "^9.1.0",
12
+ "homedir": "^0.6.0",
13
+ "lodash": "^4.17.15"
14
+ },
15
+ "devDependencies": {
16
+ "@secrez/test-helpers": "~2.0.0",
17
+ "chai": "^4.2.0",
18
+ "cross-env": "^7.0.2",
19
+ "mocha": "^7.1.2",
20
+ "nyc": "^15.1.0"
21
+ },
22
+ "description": "The Secrez core library.",
23
+ "main": "src/index.js",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/secrez/secrez.git"
27
+ },
28
+ "author": {
29
+ "name": "Francesco Sullo",
30
+ "email": "francesco@sullo.co"
31
+ },
32
+ "engines": {
33
+ "node": ">=10.0.0"
34
+ },
35
+ "scripts": {
36
+ "all-tests": "find test/** -name '*.test.js' | xargs ./node_modules/.bin/mocha -R spec",
37
+ "test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js --exit",
38
+ "test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit",
39
+ "posttest": "nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99"
40
+ }
41
+ }
package/src/Entry.js CHANGED
@@ -1,89 +1,91 @@
1
- const {removeNotPrintableChars} = require('@secrez/utils')
1
+ const { removeNotPrintableChars } = require("@secrez/utils");
2
2
 
3
3
  class Entry {
4
-
5
4
  isValid(option) {
6
- return Entry.validOptions.includes(option)
5
+ return Entry.validOptions.includes(option);
7
6
  }
8
7
 
9
8
  constructor(options) {
10
- this.set(options)
9
+ this.set(options);
11
10
  }
12
11
 
13
12
  get(options = Entry.validOptions) {
14
- let obj = {}
13
+ let obj = {};
15
14
  for (let o of options) {
16
- if (this.isValid(o) && typeof this[o] !== 'undefined') {
17
- obj[o] = this[o]
15
+ if (this.isValid(o) && typeof this[o] !== "undefined") {
16
+ obj[o] = this[o];
18
17
  }
19
18
  }
20
- return obj
19
+ return obj;
21
20
  }
22
21
 
23
22
  set(key, value) {
24
- let options = {}
25
- if (typeof key === 'object') {
26
- options = key
23
+ let options = {};
24
+ if (typeof key === "object") {
25
+ options = key;
27
26
  } else {
28
- options[key] = value
27
+ options[key] = value;
29
28
  }
30
29
  if (options.name) {
31
- options.name = Entry.sanitizeName(options.name)
30
+ options.name = Entry.sanitizeName(options.name);
32
31
  }
33
32
  for (let o in options) {
34
- if (this.isValid(o) && typeof options[o] !== 'undefined') {
35
- this[o] = options[o]
33
+ if (this.isValid(o) && typeof options[o] !== "undefined") {
34
+ this[o] = options[o];
36
35
  }
37
36
  }
38
37
  }
39
38
 
40
39
  unset(options = []) {
41
40
  if (!Array.isArray(options)) {
42
- options = [options]
41
+ options = [options];
43
42
  }
44
43
  for (let o of options) {
45
- if (this.isValid(o) && typeof this[o] !== 'undefined') {
46
- delete this[o]
44
+ if (this.isValid(o) && typeof this[o] !== "undefined") {
45
+ delete this[o];
47
46
  }
48
47
  }
49
48
  }
50
49
 
51
- static sanitizeName(name, subst = '') {
50
+ static sanitizeName(name, subst = "") {
52
51
  // removes character forbidden by operating systems
53
52
  // eslint-disable-next-line no-useless-escape
54
- return removeNotPrintableChars(name).replace(/[\\\/\>\<\|\:\&\?\*\^\$]/ig, subst)
53
+ return removeNotPrintableChars(name).replace(
54
+ /[\\\/\>\<\|\:\&\?\*\^\$]/gi,
55
+ subst
56
+ );
55
57
  }
56
58
 
57
59
  static sanitizePath(p, subst) {
58
- if (typeof p === 'string') {
60
+ if (typeof p === "string") {
59
61
  // removes character forbidden by operating systems
60
62
  // eslint-disable-next-line no-useless-escape
61
- return p.split('/').map(e => Entry.sanitizeName(e, subst)).join('/')
63
+ return p
64
+ .split("/")
65
+ .map((e) => Entry.sanitizeName(e, subst))
66
+ .join("/");
62
67
  } else {
63
- throw new Error('Path must be a string')
68
+ throw new Error("Path must be a string");
64
69
  }
65
70
  }
66
-
67
-
68
71
  }
69
72
 
70
73
  Entry.validOptions = [
71
- 'type',
72
- 'id',
73
- 'ts',
74
+ "type",
75
+ "id",
76
+ "ts",
74
77
  // 'scrambledTs',
75
- 'name',
76
- 'content',
77
- 'encryptedName',
78
- 'encryptedContent',
79
- 'microseconds',
80
- 'extraName',
81
- 'nameId',
82
- 'nameTs',
83
- 'preserveContent',
84
- 'parent',
85
- 'treeIndex'
86
- ]
87
-
78
+ "name",
79
+ "content",
80
+ "encryptedName",
81
+ "encryptedContent",
82
+ "microseconds",
83
+ "extraName",
84
+ "nameId",
85
+ "nameTs",
86
+ "preserveContent",
87
+ "parent",
88
+ "treeIndex",
89
+ ];
88
90
 
89
- module.exports = Entry
91
+ module.exports = Entry;