secrez 1.1.0 → 1.1.2

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +414 -291
  3. package/bin/secrez.js +50 -47
  4. package/coverage.report +81 -0
  5. package/package.json +18 -20
  6. package/src/Command.js +78 -57
  7. package/src/PreCommand.js +74 -70
  8. package/src/Welcome.js +144 -134
  9. package/src/cliConfig.js +14 -14
  10. package/src/commands/Alias.js +123 -100
  11. package/src/commands/Bash.js +10 -12
  12. package/src/commands/Cat.js +117 -107
  13. package/src/commands/Cd.js +39 -42
  14. package/src/commands/Chat.js +75 -63
  15. package/src/commands/Conf.js +123 -99
  16. package/src/commands/Contacts.js +189 -171
  17. package/src/commands/Copy.js +132 -113
  18. package/src/commands/Courier.js +123 -105
  19. package/src/commands/Ds.js +88 -76
  20. package/src/commands/Edit.js +122 -103
  21. package/src/commands/Export.js +153 -114
  22. package/src/commands/Find.js +115 -110
  23. package/src/commands/Help.js +20 -23
  24. package/src/commands/Import.js +296 -225
  25. package/src/commands/Lcat.js +36 -39
  26. package/src/commands/Lcd.js +38 -39
  27. package/src/commands/Lls.js +58 -55
  28. package/src/commands/Lpwd.js +20 -24
  29. package/src/commands/Ls.js +107 -97
  30. package/src/commands/Mkdir.js +35 -38
  31. package/src/commands/Mv.js +147 -114
  32. package/src/commands/Paste.js +68 -65
  33. package/src/commands/Pwd.js +18 -23
  34. package/src/commands/Quit.js +22 -24
  35. package/src/commands/Rm.js +78 -70
  36. package/src/commands/Shell.js +31 -32
  37. package/src/commands/Ssh.js +77 -63
  38. package/src/commands/Tag.js +133 -112
  39. package/src/commands/Totp.js +166 -136
  40. package/src/commands/Touch.js +169 -56
  41. package/src/commands/Use.js +44 -41
  42. package/src/commands/Ver.js +16 -18
  43. package/src/commands/Whoami.js +34 -37
  44. package/src/commands/chat/Contacts.js +41 -44
  45. package/src/commands/chat/Help.js +20 -23
  46. package/src/commands/chat/Join.js +59 -55
  47. package/src/commands/chat/Leave.js +16 -22
  48. package/src/commands/chat/Quit.js +19 -24
  49. package/src/commands/chat/Send.js +58 -57
  50. package/src/commands/chat/Show.js +60 -51
  51. package/src/commands/chat/Whoami.js +18 -22
  52. package/src/commands/index.js +20 -22
  53. package/src/index.js +3 -3
  54. package/src/prompts/ChatPrompt.js +87 -82
  55. package/src/prompts/ChatPromptMock.js +11 -17
  56. package/src/prompts/CommandPrompt.js +146 -138
  57. package/src/prompts/Completion.js +64 -69
  58. package/src/prompts/MainPrompt.js +84 -77
  59. package/src/prompts/MainPromptMock.js +19 -30
  60. package/src/prompts/MultiEditorPrompt.js +21 -22
  61. package/src/prompts/SigintManager.js +21 -24
  62. package/src/utils/AliasManager.js +16 -18
  63. package/src/utils/ContactManager.js +15 -17
  64. package/src/utils/Fido2Client.js +59 -49
  65. package/src/utils/HelpProto.js +130 -117
  66. package/src/utils/Logger.js +48 -50
  67. package/.eslintignore +0 -0
  68. package/.eslintrc +0 -33
  69. package/.jshintrc +0 -3
package/src/PreCommand.js CHANGED
@@ -1,116 +1,120 @@
1
- const {chalk} = require('./utils/Logger')
2
- const Crypto = require('@secrez/crypto')
3
- const {utils: hubUtils} = require('@secrez/hub')
4
- const superagent = require('superagent')
1
+ const { chalk } = require("./utils/Logger");
2
+ const Crypto = require("@secrez/crypto");
3
+ const { utils: hubUtils } = require("@secrez/hub");
4
+ const superagent = require("superagent");
5
5
 
6
6
  class PreCommand {
7
-
8
7
  async useEditor(options) {
9
- let message = 'your OS default editor.'
8
+ let message = "your OS default editor.";
10
9
  if (options.internal) {
11
- message = 'the minimalistic internal editor.'
10
+ message = "the minimalistic internal editor.";
12
11
  } else if (options.editor) {
13
- message = `${options.editor}.`
12
+ message = `${options.editor}.`;
14
13
  }
15
- let extraMessage = chalk.dim('Press <enter> to launch ')
16
- + message
17
- + chalk.reset(
18
- options.internal ? chalk.green('\n Ctrl-d to save the changes. Ctrl-c to abort.') : ''
19
- )
20
- let {result} = await this.prompt.inquirer.prompt([{
21
- type: 'multiEditor',
22
- name: 'result',
23
- message: 'Editing...',
24
- default: options.content,
25
- tempDir: this.cliConfig.tmpPath,
26
- validate: function (text) {
27
- return true
14
+ let extraMessage =
15
+ chalk.dim("Press <enter> to launch ") +
16
+ message +
17
+ chalk.reset(
18
+ options.internal
19
+ ? chalk.green("\n Ctrl-d to save the changes. Ctrl-c to abort.")
20
+ : ""
21
+ );
22
+ let { result } = await this.prompt.inquirer.prompt([
23
+ {
24
+ type: "multiEditor",
25
+ name: "result",
26
+ message: "Editing...",
27
+ default: options.content,
28
+ tempDir: this.cliConfig.tmpPath,
29
+ validate: function (text) {
30
+ return true;
31
+ },
32
+ extraMessage,
28
33
  },
29
- extraMessage
30
- }])
31
- return result
32
-
34
+ ]);
35
+ return result;
33
36
  }
34
37
 
35
-
36
38
  async useSelect(options) {
37
- let cancel = '(cancel)'
39
+ let cancel = "(cancel)";
38
40
  if (!options.dontCancel) {
39
- options.choices = options.choices.concat([cancel])
41
+ options.choices = options.choices.concat([cancel]);
40
42
  }
41
- let {result} = await this.prompt.inquirer.prompt([
43
+ let { result } = await this.prompt.inquirer.prompt([
42
44
  {
43
- type: 'list',
44
- name: 'result',
45
+ type: "list",
46
+ name: "result",
45
47
  message: options.message,
46
- choices: options.choices
47
- }
48
- ])
48
+ choices: options.choices,
49
+ },
50
+ ]);
49
51
  if (result === cancel) {
50
- return
52
+ return;
51
53
  } else {
52
- return result
54
+ return result;
53
55
  }
54
-
55
56
  }
56
57
 
57
58
  async useConfirm(options) {
58
- let {result} = await this.prompt.inquirer.prompt([
59
+ let { result } = await this.prompt.inquirer.prompt([
59
60
  {
60
- type: 'confirm',
61
- name: 'result',
61
+ type: "confirm",
62
+ name: "result",
62
63
  message: options.message,
63
- default: options.default
64
- }
65
- ])
66
- return result
67
-
64
+ default: options.default,
65
+ },
66
+ ]);
67
+ return result;
68
68
  }
69
69
 
70
70
  async useInput(options) {
71
-
72
- let prompt = this.prompt
73
- let exitCode = Crypto.getRandomBase58String(2)
74
- let {result} = await prompt.inquirer.prompt([
71
+ let prompt = this.prompt;
72
+ let exitCode = Crypto.getRandomBase58String(2);
73
+ let { result } = await prompt.inquirer.prompt([
75
74
  {
76
- type: options.type || 'input',
77
- name: 'result',
75
+ type: options.type || "input",
76
+ name: "result",
78
77
  message: options.message,
79
78
  default: options.content,
80
- validate: val => {
79
+ validate: (val) => {
81
80
  if (val) {
82
81
  if (val === exitCode) {
83
- return true
82
+ return true;
84
83
  } else if (options.validate) {
85
- return options.validate(val, exitCode)
84
+ return options.validate(val, exitCode);
86
85
  } else if (val.length) {
87
- return true
86
+ return true;
88
87
  }
89
88
  }
90
- return chalk.grey(`Please, type the ${options.name}, or cancel typing ${chalk.bold(exitCode)}`)
91
- }
92
- }
93
- ])
89
+ return chalk.grey(
90
+ `Please, type the ${options.name}, or cancel typing ${chalk.bold(
91
+ exitCode
92
+ )}`
93
+ );
94
+ },
95
+ },
96
+ ]);
94
97
  if (result !== exitCode) {
95
- return result
98
+ return result;
96
99
  }
97
100
  }
98
101
 
99
102
  async callCourier(_payload, port, caCrt, pathname) {
100
- const {payload, signature} = hubUtils.setPayloadAndSignIt(this.secrez, _payload)
103
+ const { payload, signature } = hubUtils.setPayloadAndSignIt(
104
+ this.secrez,
105
+ _payload
106
+ );
101
107
  try {
102
108
  const res = await superagent
103
- .get(`https://localhost:${port}${pathname || ''}`)
104
- .set('Accept', 'application/json')
105
- .query({payload, signature})[caCrt ? 'ca' : 'trustLocalhost'](caCrt)
106
- return res.body
109
+ .get(`https://localhost:${port}${pathname || ""}`)
110
+ .set("Accept", "application/json")
111
+ .query({ payload, signature })
112
+ [caCrt ? "ca" : "trustLocalhost"](caCrt);
113
+ return res.body;
107
114
  } catch (e) {
108
- return {error: e.message}
115
+ return { error: e.message };
109
116
  }
110
117
  }
111
-
112
118
  }
113
119
 
114
- module.exports = PreCommand
115
-
116
-
120
+ module.exports = PreCommand;
package/src/Welcome.js CHANGED
@@ -1,151 +1,157 @@
1
- const chalk = require('chalk')
2
- const inquirer = require('inquirer')
3
- const fs = require('fs-extra')
4
- const Crypto = require('@secrez/crypto')
5
- const Logger = require('./utils/Logger')
6
- const Fido2Client = require('./utils/Fido2Client')
1
+ const chalk = require("chalk");
2
+ const inquirer = require("inquirer");
3
+ const fs = require("fs-extra");
4
+ const Crypto = require("@secrez/crypto");
5
+ const Logger = require("./utils/Logger");
6
+ const Fido2Client = require("./utils/Fido2Client");
7
7
 
8
8
  class Welcome {
9
-
10
9
  async start(secrez, options) {
11
- this.secrez = secrez
12
- this.options = options
13
- this.iterations = options.iterations || await this.getIterations()
10
+ this.secrez = secrez;
11
+ this.options = options;
12
+ this.iterations = options.iterations || (await this.getIterations());
14
13
  if (await fs.pathExists(this.secrez.config.oldKeysPath)) {
15
- const oldConf = require(this.secrez.config.oldKeysPath)
14
+ const oldConf = require(this.secrez.config.oldKeysPath);
16
15
  if (!oldConf.data.why) {
17
- Logger.red(chalk.bold(`
16
+ Logger.red(
17
+ chalk.bold(`
18
18
  Your encrypted db is not compatible with this version of Secrez.
19
- `))
19
+ `)
20
+ );
20
21
  Logger.reset(`Install secrez-migrate with
21
22
 
22
- ${chalk.bold('pnpm i -g @secrez/migrate')}
23
+ ${chalk.bold("pnpm i -g @secrez/migrate")}
23
24
 
24
25
  and run it to migrate the db. If you specify the container launching secrez, specify it also launching secrez-migrate.
25
26
  If you need to access your secrets now, revert to a compatible version with
26
27
 
27
- ${chalk.bold('pnpm i -g secrez@0.10.8')}
28
+ ${chalk.bold("pnpm i -g secrez@0.10.8")}
28
29
 
29
30
  and migrate your db later.
30
- Thanks.`)
31
+ Thanks.`);
31
32
  // eslint-disable-next-line no-process-exit
32
- process.exit(0)
33
+ process.exit(0);
33
34
  }
34
35
  }
35
36
 
36
37
  if (await fs.pathExists(this.secrez.config.keysPath)) {
37
- let errorCode = await this.login()
38
+ let errorCode = await this.login();
38
39
  if (errorCode === 1) {
39
- await this.sharedLogin()
40
+ await this.sharedLogin();
40
41
  }
41
42
  } else {
42
- Logger.grey('Please signup to create your local account')
43
- await this.signup()
43
+ Logger.grey("Please signup to create your local account");
44
+ await this.signup();
44
45
  }
45
46
  }
46
47
 
47
48
  async getIterations() {
48
49
  if (await fs.pathExists(this.secrez.config.envPath)) {
49
- let env = require(this.secrez.config.envPath)
50
+ let env = require(this.secrez.config.envPath);
50
51
  if (env.iterations) {
51
- return env.iterations
52
+ return env.iterations;
52
53
  }
53
54
  }
54
- let {iterations} = await inquirer.prompt([{
55
- name: 'iterations',
56
- type: 'input',
57
- message: 'Type the number of iterations for password derivation:',
58
- validate: value => {
59
- if (value.length && parseInt(value) > 0) {
60
- return true
61
- } else {
62
- return 'Please enter a valid number of iterations.'
63
- }
64
- }
65
- }])
66
- return parseInt(iterations)
55
+ let { iterations } = await inquirer.prompt([
56
+ {
57
+ name: "iterations",
58
+ type: "input",
59
+ message: "Type the number of iterations for password derivation:",
60
+ validate: (value) => {
61
+ if (value.length && parseInt(value) > 0) {
62
+ return true;
63
+ } else {
64
+ return "Please enter a valid number of iterations.";
65
+ }
66
+ },
67
+ },
68
+ ]);
69
+ return parseInt(iterations);
67
70
  }
68
71
 
69
- // chimney piano fabric forest curious black hip axis story stool spoil fold
72
+ // chimney piano fabric forest curious black hip axis story stool spoil fold
70
73
  async saveIterations() {
71
74
  if (this.options.saveIterations) {
72
- await this.secrez.saveIterations(this.iterations)
75
+ await this.secrez.saveIterations(this.iterations);
73
76
  }
74
77
  }
75
78
 
76
79
  async login() {
77
- for (; ;) {
80
+ for (;;) {
78
81
  try {
79
- let {password} = await inquirer.prompt([{
80
- name: 'password',
81
- type: 'password',
82
- message: 'Enter your master password:',
83
- validate: value => {
84
- if (value.length) {
85
- return true
86
- } else {
87
- return 'Please enter your master password.'
88
- }
89
- }
90
- }])
82
+ let { password } = await inquirer.prompt([
83
+ {
84
+ name: "password",
85
+ type: "password",
86
+ message: "Enter your master password:",
87
+ validate: (value) => {
88
+ if (value.length) {
89
+ return true;
90
+ } else {
91
+ return "Please enter your master password.";
92
+ }
93
+ },
94
+ },
95
+ ]);
91
96
  try {
92
- await this.secrez.signin(password, this.iterations)
97
+ await this.secrez.signin(password, this.iterations);
93
98
  if (this.secrez.masterKeyHash) {
94
- await this.saveIterations()
99
+ await this.saveIterations();
95
100
  }
96
- return 0
101
+ return 0;
97
102
  } catch (e) {
98
- if (e.message === 'A second factor is required') {
99
- return 1
103
+ if (e.message === "A second factor is required") {
104
+ return 1;
100
105
  }
101
- Logger.red(`${e.message}.Try again or Ctrl - C to exit.`)
106
+ Logger.red(`${e.message}.Try again or Ctrl - C to exit.`);
102
107
  }
103
108
  } catch (e) {
104
- Logger.red('Unrecognized error. Try again or Ctrl-c to exit.')
109
+ Logger.red("Unrecognized error. Try again or Ctrl-c to exit.");
105
110
  }
106
111
  }
107
112
  }
108
113
 
109
114
  async sharedLogin() {
110
- let fido2Client = new Fido2Client(this.secrez)
111
- let authenticator
112
- let list = await fido2Client.getKeys()
113
- const conf = await this.secrez.readConf()
114
- let choices = []
115
+ let fido2Client = new Fido2Client(this.secrez);
116
+ let authenticator;
117
+ let list = await fido2Client.getKeys();
118
+ const conf = await this.secrez.readConf();
119
+ let choices = [];
115
120
  for (let authenticator in conf.data.keys) {
116
- choices.push(authenticator)
121
+ choices.push(authenticator);
117
122
  }
118
- for (; ;) {
123
+ for (;;) {
119
124
  if (list.length === 1) {
120
- authenticator = list[0]
125
+ authenticator = list[0];
121
126
  } else {
122
127
  let p = await inquirer.prompt([
123
128
  {
124
- type: 'list',
125
- name: 'authenticator',
126
- message: 'Which second factor would you like to use?',
127
- choices
128
- }
129
- ])
130
- authenticator = p.authenticator
129
+ type: "list",
130
+ name: "authenticator",
131
+ message: "Which second factor would you like to use?",
132
+ choices,
133
+ },
134
+ ]);
135
+ authenticator = p.authenticator;
131
136
  }
132
- let secret
137
+ let secret;
133
138
  try {
134
139
  try {
135
140
  if (fido2Client.keys[authenticator]) {
136
- Logger.grey('Touch your fido2 authenticator device now...')
137
- secret = await fido2Client.verifySecret(authenticator)
141
+ Logger.grey("Touch your fido2 authenticator device now...");
142
+ secret = await fido2Client.verifySecret(authenticator);
138
143
  } else {
139
- let exitCode = Crypto.getRandomBase58String(2)
140
- let p = await inquirer.prompt([{
141
- name: 'recoveryCode',
142
- type: 'input',
143
- message: 'Type or paste your recovery code:',
144
- validate: value => {
145
- if (value.length) {
146
- return true
147
- } else {
148
- return `
144
+ let exitCode = Crypto.getRandomBase58String(2);
145
+ let p = await inquirer.prompt([
146
+ {
147
+ name: "recoveryCode",
148
+ type: "input",
149
+ message: "Type or paste your recovery code:",
150
+ validate: (value) => {
151
+ if (value.length) {
152
+ return true;
153
+ } else {
154
+ return `
149
155
  Please
150
156
  paste
151
157
  a
@@ -157,84 +163,88 @@ Thanks.`)
157
163
  to
158
164
  choose
159
165
  another
160
- factor.`
161
- }
162
- }
163
- }])
166
+ factor.`;
167
+ }
168
+ },
169
+ },
170
+ ]);
164
171
  if (p.recoveryCode === exitCode) {
165
- continue
172
+ continue;
166
173
  }
167
- secret = p.recoveryCode
174
+ secret = p.recoveryCode;
168
175
  }
169
- let resCode = await this.secrez.sharedSignin(authenticator, secret)
176
+ let resCode = await this.secrez.sharedSignin(authenticator, secret);
170
177
  if (this.secrez.masterKeyHash) {
171
- await this.saveIterations()
178
+ await this.saveIterations();
172
179
  }
173
180
  if (resCode === 1) {
174
- Logger.bold(chalk.red('Your data has been upgraded.'))
175
- Logger.red('To avoid conflicts, any registered second factor has been removed.')
176
- Logger.grey('Please, register them again, thanks.')
181
+ Logger.bold(chalk.red("Your data has been upgraded."));
182
+ Logger.red(
183
+ "To avoid conflicts, any registered second factor has been removed."
184
+ );
185
+ Logger.grey("Please, register them again, thanks.");
177
186
  }
178
- return
187
+ return;
179
188
  } catch (e) {
180
189
  Logger.red(`${e.message}.Try
181
190
  again
182
191
  or
183
192
  Ctrl - C
184
193
  to
185
- exit.`)
194
+ exit.`);
186
195
  }
187
196
  } catch (e) {
188
- Logger.red('Unrecognized error. Try again or Ctrl-C to exit.')
197
+ Logger.red("Unrecognized error. Try again or Ctrl-C to exit.");
189
198
  }
190
199
  }
191
200
  }
192
201
 
193
202
  async signup() {
194
- for (; ;) {
203
+ for (;;) {
195
204
  try {
196
- let p = await inquirer.prompt([{
197
- name: 'password',
198
- type: 'password',
199
- message: 'Enter your password:',
200
- validate: value => {
201
- if (value.length) {
202
- return true
203
- } else {
204
- return 'Please enter your password'
205
- }
206
- }
207
- }, {
208
- name: 'retype',
209
- type: 'password',
210
- message: 'Retype your password:',
211
- validate: value => {
212
- if (value.length) {
213
- return true
214
- } else {
215
- return 'Please enter your password'
216
- }
217
- }
218
- }])
205
+ let p = await inquirer.prompt([
206
+ {
207
+ name: "password",
208
+ type: "password",
209
+ message: "Enter your password:",
210
+ validate: (value) => {
211
+ if (value.length) {
212
+ return true;
213
+ } else {
214
+ return "Please enter your password";
215
+ }
216
+ },
217
+ },
218
+ {
219
+ name: "retype",
220
+ type: "password",
221
+ message: "Retype your password:",
222
+ validate: (value) => {
223
+ if (value.length) {
224
+ return true;
225
+ } else {
226
+ return "Please enter your password";
227
+ }
228
+ },
229
+ },
230
+ ]);
219
231
  if (p.password === p.retype) {
220
232
  try {
221
- await this.secrez.signup(p.password, this.iterations)
222
- await this.saveIterations()
223
- return
233
+ await this.secrez.signup(p.password, this.iterations);
234
+ await this.saveIterations();
235
+ return;
224
236
  } catch (e) {
225
- Logger.red(e.message)
226
- break
237
+ Logger.red(e.message);
238
+ break;
227
239
  }
228
240
  } else {
229
- Logger.red('The two passwords do not match. Try again')
241
+ Logger.red("The two passwords do not match. Try again");
230
242
  }
231
243
  } catch (e) {
232
- Logger.red('Unrecognized error. Try again or Ctrl-c to exit.')
244
+ Logger.red("Unrecognized error. Try again or Ctrl-c to exit.");
233
245
  }
234
246
  }
235
-
236
247
  }
237
-
238
248
  }
239
249
 
240
- module.exports = new Welcome
250
+ module.exports = new Welcome();
package/src/cliConfig.js CHANGED
@@ -1,9 +1,9 @@
1
- const TRUE = 1
2
- const STRING = 2
3
- const ARRAY = 3
4
- const NUMBER = 4
5
- const BOOL = 5
6
- const OBJECT = 6
1
+ const TRUE = 1;
2
+ const STRING = 2;
3
+ const ARRAY = 3;
4
+ const NUMBER = 4;
5
+ const BOOL = 5;
6
+ const OBJECT = 6;
7
7
 
8
8
  const completionTypes = {
9
9
  TRUE,
@@ -11,17 +11,17 @@ const completionTypes = {
11
11
  ARRAY,
12
12
  NUMBER,
13
13
  BOOL,
14
- OBJECT
15
- }
14
+ OBJECT,
15
+ };
16
16
 
17
- const cliConfig = Object.assign(require('@secrez/core').config, {
17
+ const cliConfig = Object.assign(require("@secrez/core").config, {
18
18
  completion: {
19
- help: {}
19
+ help: {},
20
20
  },
21
21
  chatCompletion: {
22
- help: {}
22
+ help: {},
23
23
  },
24
- completionTypes
25
- })
24
+ completionTypes,
25
+ });
26
26
 
27
- module.exports = cliConfig
27
+ module.exports = cliConfig;