favacli 0.0.13 → 0.0.14
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.
- package/build/main.mjs +1 -1
- package/build/utils/loadVault.mjs +15 -2
- package/package.json +1 -1
package/build/main.mjs
CHANGED
|
@@ -7,8 +7,21 @@ const twoFaLibVaultCreationUtils = getTwoFaLibVaultCreationUtils(cryptoLib, 'cli
|
|
|
7
7
|
const loadVault = async (vaultData, settings, verbose = false) => {
|
|
8
8
|
const passphrase = (await keytar.getPassword('favacli', 'vault-passphrase'));
|
|
9
9
|
const twoFaLib = await twoFaLibVaultCreationUtils.loadTwoFaLibFromLockedRepesentation(vaultData, passphrase);
|
|
10
|
-
twoFaLib.addEventListener(TwoFaLibEvent.Changed, (ev) => {
|
|
11
|
-
|
|
10
|
+
twoFaLib.addEventListener(TwoFaLibEvent.Changed, async (ev) => {
|
|
11
|
+
const tempFile = `${settings.vaultLocation}.tmp`;
|
|
12
|
+
try {
|
|
13
|
+
// Write to temporary file first, so we don't have to worry about partial writes
|
|
14
|
+
await fs.writeFile(tempFile, ev.detail.newLockedRepresentationString);
|
|
15
|
+
// Atomically rename temp file to target file
|
|
16
|
+
await fs.rename(tempFile, settings.vaultLocation);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
// Clean up temp file if something went wrong
|
|
20
|
+
await fs.unlink(tempFile).catch((err) => {
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
12
25
|
});
|
|
13
26
|
twoFaLib.addEventListener(TwoFaLibEvent.Log, (ev) => {
|
|
14
27
|
if (ev.detail.severity !== 'info' || verbose) {
|