@secrez/core 1.0.3 → 1.0.5

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,10 +20,10 @@ 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
 
@@ -34,18 +34,17 @@ __0.8.5__
34
34
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
35
35
  -----------------|---------|----------|---------|---------|-------------------
36
36
  All files | 99.75 | 94.31 | 100 | 99.75 |
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
37
+ src | 100 | 96.06 | 100 | 100 |
38
+ Entry.js | 100 | 95.65 | 100 | 100 | 39
39
+ Secrez.js | 100 | 96.94 | 100 | 100 | 154,319,442
40
+ _Secrez.js | 100 | 91.66 | 100 | 100 | 14,226
41
+ src/config | 98.57 | 84.84 | 100 | 98.57 |
42
+ ConfigUtils.js | 98.48 | 84.84 | 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,112 +1,112 @@
1
1
 
2
- > @secrez/core@1.0.3 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.5 test /Users/francescosullo/Projects/Secrez/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
- 
7
-  #Entry
8
-  #constructor
9
-  ✓ should instantiate the Entry
10
-  ✓ should ignore wrong parameters
11
-  #set
12
-  ✓ should set some options for the Entry
13
-  ✓ should skip invalid options
14
-  #unset
15
-  ✓ should unset some options
16
-  ✓ should skip invalid or undefined options
17
-  #sanitizeName
18
-  ✓ should sanitize names
19
-  #sanitizePath
20
-  ✓ should sanitize path
21
6
 
22
-  #Secrez
23
-  default secrez dir
24
-  ✓ should throw trying to test in the default ~/.secrez folder
25
-  custom (testing) secrez dir
26
-  derivePassword
27
-  ✓ should derive a password and obtain a predeterminded hash
28
-  signup and signin
29
-  ✓ should signup the user and signin without saving the iterations (70ms)
30
-  ✓ should signup in two instances without conflicts (47ms)
31
-  ✓ should signup the user and signin saved the iterations (43ms)
32
-  ✓ should signup with version one, and signin and upgrade to version two (64ms)
33
-  ✓ should signup the user, change password and signin (78ms)
34
-  ✓ should signup the user, change iterations and signin (68ms)
35
-  ✓ should signup the user, change password and iterations and signin (71ms)
36
-  should throw an error
37
-  ✓ trying to signup if Secrez has not been initiated
38
-  ✓ trying to signin if Secrez has not been initiated
39
-  ✓ trying to signup if account already exists
40
-  ✓ trying to signin if account is not set yet
41
-  ✓ trying to signin with missed iterations
42
-  ✓ trying to signin with the wrong password (40ms)
43
-  ✓ trying to signin with the right password but wrong number of iterations
44
-  ✓ trying to signin with the right password but using a wrong hash on file (55ms)
45
-  ✓ trying to sign out if never signed-in
46
-  encryptEntry and decryptEntry
47
-  ✓ should encrypt a name and decrypt it
48
-  ✓ should encrypt a very long name and decrypt it
49
-  ✓ should encrypt name and content and decrypt it
50
-  ✓ should encrypt only the content and decrypt it
51
-  ✓ should re-encrypt the content and decrypt it
52
-  ✓ should throw if the user is not logged in
53
-  ✓ should throw if wrong type
54
-  ✓ should throw if no entry is passed
55
-  ✓ should throw if encrypted data are corrupted
56
-  ✓ should throw if content has not the same id of the name
57
-  ✓ should throw if parameters are missed
58
-  encryptData and decryptData
59
-  ✓ should encrypt some data and decrypt it
60
-  ✓ should throw trying to get box and sign secret keys
61
-  preEncryptData and preDecryptData
62
-  ✓ should encrypt some data with the derivedPassword and decrypt it
63
-  ✓ should throw trying to get the master key
64
-  generateSharedSecrets && recoverSharedSecrets
65
-  ✓ should set up a second factor (65ms)
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 (72ms)
68
-  ✓ should set up a second factor and a recovery code and remove the recovery code (70ms)
69
-  ✓ should throw if wrong secret (58ms)
70
-  ✓ should throw if wrong authenticator (38ms)
71
-  #readConf
72
-  ✓ should encrypt some data with the derivedPassword and decrypt it
73
-  ✓ should throw trying to get the master key
74
-  ✓ should throw trying to get the master key
75
-  #signMessage
76
-  ✓ should sign a message and verify it (46ms)
77
-  #getPublicKey
78
-  ✓ should sign a message and verify it (39ms)
79
-  #encrypt and decrypt shared data
80
-  ✓ should get a shared ket (61ms)
7
+ #Entry
8
+ #constructor
9
+ ✓ should instantiate the Entry
10
+ ✓ should ignore wrong parameters
11
+ #set
12
+ ✓ should set some options for the Entry
13
+ ✓ should skip invalid options
14
+ #unset
15
+ ✓ should unset some options
16
+ ✓ should skip invalid or undefined options
17
+ #sanitizeName
18
+ ✓ should sanitize names
19
+ #sanitizePath
20
+ ✓ should sanitize path
81
21
 
82
-  #config
83
-  ✓ all field should be correctly configured
22
+ #Secrez
23
+ default secrez dir
24
+ ✓ should throw trying to test in the default ~/.secrez folder
25
+ custom (testing) secrez dir
26
+ derivePassword
27
+ ✓ should derive a password and obtain a predeterminded hash
28
+ signup and signin
29
+ ✓ should signup the user and signin without saving the iterations (73ms)
30
+ ✓ should signup in two instances without conflicts (50ms)
31
+ ✓ should signup the user and signin saved the iterations (45ms)
32
+ ✓ should signup with version one, and signin and upgrade to version two (66ms)
33
+ ✓ should signup the user, change password and signin (63ms)
34
+ ✓ should signup the user, change iterations and signin (63ms)
35
+ ✓ should signup the user, change password and iterations and signin (81ms)
36
+ should throw an error
37
+ ✓ trying to signup if Secrez has not been initiated
38
+ ✓ trying to signin if Secrez has not been initiated
39
+ ✓ trying to signup if account already exists
40
+ ✓ trying to signin if account is not set yet
41
+ ✓ trying to signin with missed iterations
42
+ ✓ trying to signin with the wrong password (40ms)
43
+ ✓ trying to signin with the right password but wrong number of iterations (41ms)
44
+ ✓ trying to signin with the right password but using a wrong hash on file (41ms)
45
+ ✓ trying to sign out if never signed-in
46
+ encryptEntry and decryptEntry
47
+ ✓ should encrypt a name and decrypt it
48
+ ✓ should encrypt a very long name and decrypt it
49
+ ✓ should encrypt name and content and decrypt it
50
+ ✓ should encrypt only the content and decrypt it
51
+ ✓ should re-encrypt the content and decrypt it
52
+ ✓ should throw if the user is not logged in
53
+ ✓ should throw if wrong type
54
+ ✓ should throw if no entry is passed
55
+ ✓ should throw if encrypted data are corrupted
56
+ ✓ should throw if content has not the same id of the name
57
+ ✓ should throw if parameters are missed
58
+ encryptData and decryptData
59
+ ✓ should encrypt some data and decrypt it
60
+ ✓ should throw trying to get box and sign secret keys
61
+ preEncryptData and preDecryptData
62
+ ✓ should encrypt some data with the derivedPassword and decrypt it
63
+ ✓ should throw trying to get the master key
64
+ generateSharedSecrets && recoverSharedSecrets
65
+ ✓ should set up a second factor (72ms)
66
+ ✓ should set up a second factor and then upgrade from derivationVersion 1 to 2 (46ms)
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 (69ms)
69
+ ✓ should throw if wrong secret (42ms)
70
+ ✓ should throw if wrong authenticator (43ms)
71
+ #readConf
72
+ ✓ should encrypt some data with the derivedPassword and decrypt it
73
+ ✓ should throw trying to get the master key
74
+ ✓ should throw trying to get the master key
75
+ #signMessage
76
+ ✓ should sign a message and verify it (47ms)
77
+ #getPublicKey
78
+ ✓ should sign a message and verify it (44ms)
79
+ #encrypt and decrypt shared data
80
+ ✓ should get a shared ket (52ms)
84
81
 
85
-  #ConfigUtils
86
-  ✓ should check if a type is valid
87
-  ✓ #setSecrez should configure a secrez environment
88
-  ✓ #setAndGetDataset should set and get a secondary db
89
-  ✓ #deleteDataset should delete a dataset path
90
-  ✓ #getDatasetPath should get a dataset path
91
-  ✓ #getEnv should return the environment
82
+ #config
83
+ ✓ all field should be correctly configured
92
84
 
85
+ #ConfigUtils
86
+ ✓ should check if a type is valid
87
+ ✓ #setSecrez should configure a secrez environment
88
+ ✓ #setAndGetDataset should set and get a secondary db
89
+ ✓ #deleteDataset should delete a dataset path
90
+ ✓ #getDatasetPath should get a dataset path
91
+ ✓ #getEnv should return the environment
93
92
 
94
-   60 passing (2s)
93
+
94
+ 60 passing (2s)
95
95
 
96
96
  -----------------|---------|----------|---------|---------|-------------------
97
97
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
98
98
  -----------------|---------|----------|---------|---------|-------------------
99
- All files  |  99.75 |  94.31 |  100 |  99.75 |  
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 
106
-  booleans.js  |  100 |  100 |  100 |  100 |  
107
-  index.js  |  100 |  100 |  100 |  100 |  
99
+ All files | 99.75 | 94.31 | 100 | 99.75 |
100
+ src | 100 | 96.06 | 100 | 100 |
101
+ Entry.js | 100 | 95.65 | 100 | 100 | 39
102
+ Secrez.js | 100 | 96.94 | 100 | 100 | 154,319,442
103
+ _Secrez.js | 100 | 91.66 | 100 | 100 | 14,226
104
+ src/config | 98.57 | 84.84 | 100 | 98.57 |
105
+ ConfigUtils.js | 98.48 | 84.84 | 100 | 98.48 | 137
106
+ booleans.js | 100 | 100 | 100 | 100 |
107
+ index.js | 100 | 100 | 100 | 100 |
108
108
  -----------------|---------|----------|---------|---------|-------------------
109
109
 
110
- > @secrez/core@1.0.3 posttest /Users/sullof/Projects/Personal/secrez/packages/core
110
+ > @secrez/core@1.0.5 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/core
111
111
  > nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99
112
112
 
package/package.json CHANGED
@@ -1,44 +1,41 @@
1
1
  {
2
- "name": "@secrez/core",
3
- "version": "1.0.3",
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.2",
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.5",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "dependencies": {
9
+ "@secrez/crypto": "~1.0.4",
10
+ "@secrez/utils": "~1.0.4",
11
+ "fs-extra": "^9.1.0",
12
+ "homedir": "^0.6.0",
13
+ "lodash": "^4.17.21"
14
+ },
15
+ "devDependencies": {
16
+ "@secrez/test-helpers": "~2.0.1",
17
+ "chai": "^4.5.0",
18
+ "cross-env": "^7.0.3",
19
+ "mocha": "^7.2.0",
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;