mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-25 07:32:06 +00:00
Code optimization
This commit is contained in:
parent
9660242234
commit
b259ac76d6
@ -125,9 +125,13 @@ module.exports = class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async keys() {
|
async keys() {
|
||||||
const keysString = await this._readKeys();
|
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() {
|
_generateKeys() {
|
||||||
@ -143,21 +147,11 @@ module.exports = class Client {
|
|||||||
await this._writeKeys(keysObject);
|
await this._writeKeys(keysObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _readKeys() {
|
_readKeys() {
|
||||||
try {
|
return this.keyStorage.read();
|
||||||
const keys = await this.keyStorage.read();
|
|
||||||
|
|
||||||
return keys;
|
|
||||||
} catch (err) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _writeKeys(keysObject) {
|
_writeKeys(keysObject) {
|
||||||
try {
|
return this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
|
||||||
await this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ module.exports = (pathToFile) => {
|
|||||||
write(data) {
|
write(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.writeFile(path, data, { encoding: 'utf8' }, (error) => {
|
fs.writeFile(path, data, { encoding: 'utf8' }, (error) => {
|
||||||
if (error) throw error;
|
if (error) reject(error);
|
||||||
|
|
||||||
return resolve();
|
return resolve();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user