secrez 1.1.1 → 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 (68) hide show
  1. package/README.md +414 -291
  2. package/bin/secrez.js +50 -47
  3. package/coverage.report +63 -305
  4. package/package.json +10 -12
  5. package/src/Command.js +78 -57
  6. package/src/PreCommand.js +74 -70
  7. package/src/Welcome.js +144 -134
  8. package/src/cliConfig.js +14 -14
  9. package/src/commands/Alias.js +123 -100
  10. package/src/commands/Bash.js +10 -12
  11. package/src/commands/Cat.js +117 -107
  12. package/src/commands/Cd.js +39 -42
  13. package/src/commands/Chat.js +75 -63
  14. package/src/commands/Conf.js +123 -99
  15. package/src/commands/Contacts.js +189 -171
  16. package/src/commands/Copy.js +132 -113
  17. package/src/commands/Courier.js +123 -105
  18. package/src/commands/Ds.js +88 -76
  19. package/src/commands/Edit.js +122 -103
  20. package/src/commands/Export.js +153 -114
  21. package/src/commands/Find.js +115 -110
  22. package/src/commands/Help.js +20 -23
  23. package/src/commands/Import.js +296 -225
  24. package/src/commands/Lcat.js +36 -39
  25. package/src/commands/Lcd.js +38 -39
  26. package/src/commands/Lls.js +58 -55
  27. package/src/commands/Lpwd.js +20 -24
  28. package/src/commands/Ls.js +107 -97
  29. package/src/commands/Mkdir.js +35 -38
  30. package/src/commands/Mv.js +147 -114
  31. package/src/commands/Paste.js +68 -65
  32. package/src/commands/Pwd.js +18 -23
  33. package/src/commands/Quit.js +22 -24
  34. package/src/commands/Rm.js +78 -70
  35. package/src/commands/Shell.js +31 -32
  36. package/src/commands/Ssh.js +77 -63
  37. package/src/commands/Tag.js +133 -112
  38. package/src/commands/Totp.js +166 -136
  39. package/src/commands/Touch.js +169 -56
  40. package/src/commands/Use.js +44 -41
  41. package/src/commands/Ver.js +16 -18
  42. package/src/commands/Whoami.js +34 -37
  43. package/src/commands/chat/Contacts.js +41 -44
  44. package/src/commands/chat/Help.js +20 -23
  45. package/src/commands/chat/Join.js +59 -55
  46. package/src/commands/chat/Leave.js +16 -22
  47. package/src/commands/chat/Quit.js +19 -24
  48. package/src/commands/chat/Send.js +58 -57
  49. package/src/commands/chat/Show.js +60 -51
  50. package/src/commands/chat/Whoami.js +18 -22
  51. package/src/commands/index.js +20 -22
  52. package/src/index.js +3 -3
  53. package/src/prompts/ChatPrompt.js +87 -82
  54. package/src/prompts/ChatPromptMock.js +11 -17
  55. package/src/prompts/CommandPrompt.js +146 -138
  56. package/src/prompts/Completion.js +64 -69
  57. package/src/prompts/MainPrompt.js +84 -77
  58. package/src/prompts/MainPromptMock.js +19 -30
  59. package/src/prompts/MultiEditorPrompt.js +21 -22
  60. package/src/prompts/SigintManager.js +21 -24
  61. package/src/utils/AliasManager.js +16 -18
  62. package/src/utils/ContactManager.js +15 -17
  63. package/src/utils/Fido2Client.js +59 -49
  64. package/src/utils/HelpProto.js +130 -117
  65. package/src/utils/Logger.js +48 -50
  66. package/.eslintignore +0 -0
  67. package/.eslintrc +0 -33
  68. package/.jshintrc +0 -3
@@ -1,197 +1,236 @@
1
- const fs = require('fs-extra')
2
- const path = require('path')
3
- const chalk = require('chalk')
1
+ const fs = require("fs-extra");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
4
 
5
- const Crypto = require('@secrez/crypto')
6
- const {sleep} = require('@secrez/utils')
5
+ const Crypto = require("@secrez/crypto");
6
+ const { sleep } = require("@secrez/utils");
7
7
 
8
- const {Node, FileCipher} = require('@secrez/fs')
9
-
10
- class Export extends require('../Command') {
8
+ const { Node, FileCipher } = require("@secrez/fs");
11
9
 
10
+ class Export extends require("../Command") {
12
11
  setHelpAndCompletion() {
13
12
  this.cliConfig.completion.export = {
14
13
  _func: this.selfCompletion(this),
15
- _self: this
16
- }
17
- this.cliConfig.completion.help.export = true
14
+ _self: this,
15
+ };
16
+ this.cliConfig.completion.help.export = true;
18
17
  this.optionDefinitions = [
19
18
  {
20
- name: 'help',
21
- alias: 'h',
22
- type: Boolean
19
+ name: "help",
20
+ alias: "h",
21
+ type: Boolean,
23
22
  },
24
23
  {
25
- name: 'path',
26
- completionType: 'file',
27
- alias: 'p',
24
+ name: "path",
25
+ completionType: "file",
26
+ alias: "p",
28
27
  defaultOption: true,
29
- type: String
28
+ type: String,
30
29
  },
31
30
  {
32
- name: 'version',
33
- alias: 'v',
34
- type: Boolean
31
+ name: "version",
32
+ alias: "v",
33
+ type: Boolean,
35
34
  },
36
35
  {
37
- name: 'duration',
38
- alias: 'd',
39
- type: Number
36
+ name: "duration",
37
+ alias: "d",
38
+ type: Number,
40
39
  },
41
40
  {
42
- name: 'encrypt',
43
- alias: 'e',
44
- type: Boolean
41
+ name: "encrypt",
42
+ alias: "e",
43
+ type: Boolean,
45
44
  },
46
45
  {
47
- name: 'contacts',
48
- alias: 'c',
46
+ name: "contacts",
47
+ alias: "c",
49
48
  multiple: true,
50
- type: String
49
+ type: String,
51
50
  },
52
51
  {
53
- name: 'public-keys',
52
+ name: "public-keys",
54
53
  multiple: true,
55
- type: String
54
+ type: String,
56
55
  },
57
56
  {
58
- name: 'password',
59
- type: String
57
+ name: "password",
58
+ type: String,
60
59
  },
61
60
  {
62
- name: 'include-me',
63
- type: Boolean
64
- }
65
- ]
61
+ name: "include-me",
62
+ type: Boolean,
63
+ },
64
+ ];
66
65
  }
67
66
 
68
67
  help() {
69
68
  return {
70
69
  description: [
71
- 'Export encrypted data to the OS in the current local folder',
72
- 'Files and folders are decrypted during the process.'
70
+ "Export encrypted data to the OS in the current local folder",
71
+ "Files and folders are decrypted during the process.",
73
72
  ],
74
73
  examples: [
75
- ['export seed.json', 'decrypts and copies seed.json to the disk'],
76
- ['export seed.json -d 30', 'export seed.json and remove it from disk after 30 seconds'],
77
- ['export ethKeys -v 8uW3', 'exports version 8uW3 of the file'],
78
- ['export seed.json -e', 'asks for a password and encrypts seed.json before exporting it. The final file will have the extension ".secrez"'],
79
- ['export seed.json -e --password "some strong password"', 'uses the typed password to encrypt seed.json before exporting it'],
80
- ['export seed.json -ec bob alice', 'encrypts seed.json using a key shared with the contacts Bob and Alice, before exporting it'],
81
- ['export seed.json -e --public-keys TCpDvTiVpHwNiS....', 'encrypts seed.json using shared keys generated from the specified public keys'],
82
- ['export seed.json -e --include-me', 'encrypts seed.json also using your key'],
83
- ]
84
- }
74
+ ["export seed.json", "decrypts and copies seed.json to the disk"],
75
+ [
76
+ "export seed.json -d 30",
77
+ "export seed.json and remove it from disk after 30 seconds",
78
+ ],
79
+ ["export ethKeys -v 8uW3", "exports version 8uW3 of the file"],
80
+ [
81
+ "export seed.json -e",
82
+ 'asks for a password and encrypts seed.json before exporting it. The final file will have the extension ".secrez"',
83
+ ],
84
+ [
85
+ 'export seed.json -e --password "some strong password"',
86
+ "uses the typed password to encrypt seed.json before exporting it",
87
+ ],
88
+ [
89
+ "export seed.json -ec bob alice",
90
+ "encrypts seed.json using a key shared with the contacts Bob and Alice, before exporting it",
91
+ ],
92
+ [
93
+ "export seed.json -e --public-keys TCpDvTiVpHwNiS....",
94
+ "encrypts seed.json using shared keys generated from the specified public keys",
95
+ ],
96
+ [
97
+ "export seed.json -e --include-me",
98
+ "encrypts seed.json also using your key",
99
+ ],
100
+ ],
101
+ };
85
102
  }
86
103
 
87
104
  async export(options = {}) {
88
- let efs = this.externalFs
89
- let fileCipher = new FileCipher(this.secrez)
90
- let cat = this.prompt.commands.cat
91
- let lpwd = this.prompt.commands.lpwd
92
- let originalPath = options.path
93
- let data = await this.internalFs.getTreeIndexAndPath(options.path)
94
- options.path = data.path
95
- let tree = data.tree
96
- let p = tree.getNormalizedPath(options.path)
97
- let file = tree.root.getChildFromPath(p)
105
+ let efs = this.externalFs;
106
+ let fileCipher = new FileCipher(this.secrez);
107
+ let cat = this.prompt.commands.cat;
108
+ let lpwd = this.prompt.commands.lpwd;
109
+ let originalPath = options.path;
110
+ let data = await this.internalFs.getTreeIndexAndPath(options.path);
111
+ options.path = data.path;
112
+ let tree = data.tree;
113
+ let p = tree.getNormalizedPath(options.path);
114
+ let file = tree.root.getChildFromPath(p);
98
115
  if (Node.isFile(file)) {
99
- let entry = (await cat.cat({
100
- path: originalPath,
101
- version: options.version,
102
- unformatted: true
103
- }))[0]
104
- let dir = await lpwd.lpwd()
105
- let newPath = path.join(dir, path.basename(p) + (options.encrypt ? '.secrez' + (Node.isBinary(entry) ? 'b' : '') : ''))
106
- let name = await efs.getVersionedBasename(newPath)
107
- let content = entry.content
108
- if (Node.isBinary(entry) && typeof content === 'string') {
109
- content = Crypto.bs64.decode(content)
116
+ let entry = (
117
+ await cat.cat({
118
+ path: originalPath,
119
+ version: options.version,
120
+ unformatted: true,
121
+ })
122
+ )[0];
123
+ let dir = await lpwd.lpwd();
124
+ let newPath = path.join(
125
+ dir,
126
+ path.basename(p) +
127
+ (options.encrypt ? ".secrez" + (Node.isBinary(entry) ? "b" : "") : "")
128
+ );
129
+ let name = await efs.getVersionedBasename(newPath);
130
+ let content = entry.content;
131
+ if (Node.isBinary(entry) && typeof content === "string") {
132
+ content = Crypto.bs64.decode(content);
110
133
  }
111
134
  if (options.encrypt) {
112
- const myPublicKey = this.secrez.getPublicKey()
135
+ const myPublicKey = this.secrez.getPublicKey();
113
136
  if (options.publicKeys) {
114
- if (options.includeMe && options.publicKeys.indexOf(myPublicKey) === -1) {
115
- options.publicKeys.push(myPublicKey)
137
+ if (
138
+ options.includeMe &&
139
+ options.publicKeys.indexOf(myPublicKey) === -1
140
+ ) {
141
+ options.publicKeys.push(myPublicKey);
116
142
  }
117
143
  } else if (options.contacts) {
118
- options.publicKeys = await this.getContactsPublicKeys(options)
144
+ options.publicKeys = await this.getContactsPublicKeys(options);
119
145
  if (options.includeMe) {
120
- options.publicKeys.push(myPublicKey)
146
+ options.publicKeys.push(myPublicKey);
121
147
  }
122
148
  } else if (options.includeMe) {
123
- options.publicKeys = [myPublicKey]
149
+ options.publicKeys = [myPublicKey];
124
150
  } else {
125
- let pwd = options.password || await this.useInput({
126
- type: 'password',
127
- message: 'Type the password'
128
- })
151
+ let pwd =
152
+ options.password ||
153
+ (await this.useInput({
154
+ type: "password",
155
+ message: "Type the password",
156
+ }));
129
157
  if (!pwd) {
130
- throw new Error('Operation canceled')
158
+ throw new Error("Operation canceled");
131
159
  }
132
- let pwd2 = options.password || await this.useInput({
133
- type: 'password',
134
- message: 'Retype it'
135
- })
160
+ let pwd2 =
161
+ options.password ||
162
+ (await this.useInput({
163
+ type: "password",
164
+ message: "Retype it",
165
+ }));
136
166
  if (!pwd2) {
137
- throw new Error('Operation canceled')
167
+ throw new Error("Operation canceled");
138
168
  }
139
169
  if (pwd !== pwd2) {
140
- throw new Error('The two password do not match')
170
+ throw new Error("The two password do not match");
141
171
  }
142
- options.password = pwd
172
+ options.password = pwd;
143
173
  }
144
- content = fileCipher.encryptFile(content, options).join(',')
174
+ content = fileCipher.encryptFile(content, options).join(",");
145
175
  }
146
- let fn = path.join(dir, name)
147
- await fs.writeFile(fn, content)
176
+ let fn = path.join(dir, name);
177
+ await fs.writeFile(fn, content);
148
178
  if (options.duration) {
149
- this.deleteFromDisk(fn, options.duration)
179
+ this.deleteFromDisk(fn, options.duration);
150
180
  }
151
- return name
181
+ return name;
152
182
  } else {
153
- throw new Error('Cannot export a folder')
183
+ throw new Error("Cannot export a folder");
154
184
  }
155
185
  }
156
186
 
157
187
  async getContactsPublicKeys(options) {
158
- let contacts = await this.prompt.commands.contacts.contacts({list: true, asIs: true})
159
- let publicKeys = []
188
+ let contacts = await this.prompt.commands.contacts.contacts({
189
+ list: true,
190
+ asIs: true,
191
+ });
192
+ let publicKeys = [];
160
193
  for (let contact of contacts) {
161
194
  if (options.contacts.indexOf(contact[0]) !== -1) {
162
- publicKeys.push(contact[1].publicKey)
195
+ publicKeys.push(contact[1].publicKey);
163
196
  }
164
197
  }
165
- return publicKeys
198
+ return publicKeys;
166
199
  }
167
200
 
168
201
  async deleteFromDisk(fn, duration) {
169
- await sleep(1000 * duration)
202
+ await sleep(1000 * duration);
170
203
  if (await fs.pathExists(fn)) {
171
- fs.unlink(fn)
204
+ fs.unlink(fn);
172
205
  }
173
206
  }
174
207
 
175
208
  async exec(options = {}) {
176
209
  if (options.help) {
177
- return this.showHelp()
210
+ return this.showHelp();
178
211
  }
179
212
  try {
180
- this.validate(options)
181
- let name = await this.export(options)
182
- this.Logger.grey('Exported file:')
183
- this.Logger.reset(name)
184
- if (options.encrypt && !options.password && !options.includeMe && !this.alerted) {
185
- this.Logger.yellow(chalk.red('One time alert: ') + 'Only the users for which you encrypted the data can decrypt it; not even you can decrypt the exported data. Be careful!')
186
- this.alerted = true
213
+ this.validate(options);
214
+ let name = await this.export(options);
215
+ this.Logger.grey("Exported file:");
216
+ this.Logger.reset(name);
217
+ if (
218
+ options.encrypt &&
219
+ !options.password &&
220
+ !options.includeMe &&
221
+ !this.alerted
222
+ ) {
223
+ this.Logger.yellow(
224
+ chalk.red("One time alert: ") +
225
+ "Only the users for which you encrypted the data can decrypt it; not even you can decrypt the exported data. Be careful!"
226
+ );
227
+ this.alerted = true;
187
228
  }
188
229
  } catch (e) {
189
- this.Logger.red(e.message)
230
+ this.Logger.red(e.message);
190
231
  }
191
- await this.prompt.run()
232
+ await this.prompt.run();
192
233
  }
193
234
  }
194
235
 
195
- module.exports = Export
196
-
197
-
236
+ module.exports = Export;