Code optimization

This commit is contained in:
Vladislav Hristov 2018-06-28 11:34:14 +03:00
parent 9660242234
commit b259ac76d6
2 changed files with 11 additions and 17 deletions

View File

@ -125,9 +125,13 @@ module.exports = class Client {
}
async keys() {
try {
const keysString = await this._readKeys();
return keysString ? new Keys(JSON.parse(this.keyEncryptor.decrypt(keysString))) : null;
return new Keys(JSON.parse(this.keyEncryptor.decrypt(keysString)));
} catch (err) {
return null;
}
}
_generateKeys() {
@ -143,21 +147,11 @@ module.exports = class Client {
await this._writeKeys(keysObject);
}
async _readKeys() {
try {
const keys = await this.keyStorage.read();
return keys;
} catch (err) {
return null;
}
_readKeys() {
return this.keyStorage.read();
}
async _writeKeys(keysObject) {
try {
await this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
} catch (err) {
throw err;
}
_writeKeys(keysObject) {
return this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
}
};

View File

@ -9,7 +9,7 @@ module.exports = (pathToFile) => {
write(data) {
return new Promise((resolve, reject) => {
fs.writeFile(path, data, { encoding: 'utf8' }, (error) => {
if (error) throw error;
if (error) reject(error);
return resolve();
});