Skip to content

Commit 342e779

Browse files
author
ayaanoncrypto
committed
fix: harden config and keystore handling
1 parent 3396474 commit 342e779

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/commands/config/getSetReset.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export class ConfigActions extends BaseAction {
4444
return;
4545
}
4646

47-
delete config[key];
48-
this.writeConfig(key, undefined);
47+
this.removeConfig(key);
4948
this.succeedSpinner(`Configuration successfully reset`);
5049
}
5150
}

‎src/lib/actions/BaseAction.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ export class BaseAction extends ConfigFileManager {
9191

9292
return wallet.privateKey;
9393
} catch (error) {
94+
const message = error instanceof Error ? error.message : String(error);
95+
const isPasswordError = /password|decrypt/i.test(message);
96+
if (!isPasswordError) {
97+
throw error;
98+
}
9499
if (attempt >= BaseAction.MAX_PASSWORD_ATTEMPTS) {
95100
this.failSpinner(`Maximum password attempts exceeded (${BaseAction.MAX_PASSWORD_ATTEMPTS}/${BaseAction.MAX_PASSWORD_ATTEMPTS}).`);
101+
throw new Error("Maximum password attempts exceeded");
96102
}
97103
return await this.decryptKeystore(keystoreJson, attempt + 1);
98104
}
@@ -149,6 +155,10 @@ export class BaseAction extends ConfigFileManager {
149155
if (!existsSync(keystorePath)) {
150156
await this.confirmPrompt(`Account '${accountName}' not found. Would you like to create it?`);
151157
decryptedPrivateKey = await this.createKeypairByName(accountName, false);
158+
if (!existsSync(keystorePath)) {
159+
this.failSpinner(`Failed to create keystore file for account '${accountName}'.`, undefined, false);
160+
throw new Error(`Failed to create keystore file for account '${accountName}'.`);
161+
}
152162
}
153163

154164
keystoreJson = readFileSync(keystorePath, "utf-8");

0 commit comments

Comments
 (0)