mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-21 21:52:07 +00:00
Code optimization
This commit is contained in:
parent
9660242234
commit
b259ac76d6
@ -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)));
|
||||
}
|
||||
};
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user