refactor(mwc): consolidate openWallet calls through _ensureWalletOpen
What changed, and why it matters
This commit is a small internal cleanup for the Mimblewimblecoin wallet code. It replaces several repeated blocks of 'open the wallet' code with a single shared helper, and adds a 60-second timeout to one wallet-opening call so the app doesn't hang forever if something goes wrong. There is no obvious security bug being fixed; it is a code-quality and reliability improvement.
No immediate security action required. Treat as a normal reliability refactor and include in regular regression testing for Mimblewimblecoin wallet open/restore flows.
Security signals we found
Adds a 60-second timeout around libMwc.openWallet to prevent indefinite hangs
Removes duplicated wallet-open logic, reducing risk of inconsistent state handling
No changes to password handling, key storage, or transaction signing
Evidence from the diff
The patch refactors MimblewimblecoinWallet to consolidate duplicated libMwc.openWallet(…) calls behind _ensureWalletOpen(). It also wraps the initial openWallet call in an explicit 60-second Dart Future.timeout(), converting a stuck open into a TimeoutException. The change removes ~35 lines of duplicated code and reduces the chance of inconsistent wallet-open handling. No cryptographic, authentication, or access-control changes are present.
Changed components
lib/wallets/wallet/impl/mimblewimblecoin_wallet.dartInspect captured patch +9 / −44
diff --git a/lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart b/lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart
index d703463..69f925c 100644
--- a/lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart
+++ b/lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart
@@ -109,10 +109,12 @@ class MimblewimblecoinWallet extends Bip39Wallet {
if (password == null) {
throw Exception('Wallet password not found');
}
- final opened = await libMwc.openWallet(
- config: config,
- password: password,
- );
+ final opened = await libMwc
+ .openWallet(config: config, password: password)
+ .timeout(
+ const Duration(seconds: 60),
+ onTimeout: () => throw TimeoutException('openWallet timed out'),
+ );
await secureStorageInterface.write(
key: '${walletId}_wallet',
value: opened,
@@ -914,17 +916,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
);
//Open wallet
- encodedWallet = await _walletOpenMutex.protect(() async {
- final opened = await libMwc.openWallet(
- config: stringConfig,
- password: password,
- );
- await secureStorageInterface.write(
- key: '${walletId}_wallet',
- value: opened,
- );
- return opened;
- });
+ encodedWallet = await _ensureWalletOpen();
//Store MwcMqs address info
await _generateAndStoreReceivingAddressForIndex(0);
@@ -949,25 +941,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
);
} else {
try {
- final config = await _getRealConfig();
- //if (!_logsInitialized) {
- // await libMwc.initLogs(config: config);
- // _logsInitialized = true; // Set flag to true after initializing
- //}
- final password = await secureStorageInterface.read(
- key: '${walletId}_password',
- );
-
- await _walletOpenMutex.protect(() async {
- final walletOpen = await libMwc.openWallet(
- config: config,
- password: password!,
- );
- await secureStorageInterface.write(
- key: '${walletId}_wallet',
- value: walletOpen,
- );
- });
+ await _ensureWalletOpen();
await updateNode();
} catch (e, s) {
@@ -1169,16 +1143,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
);
//Open Wallet
- await _walletOpenMutex.protect(() async {
- final walletOpen = await libMwc.openWallet(
- config: stringConfig,
- password: password,
- );
- await secureStorageInterface.write(
- key: '${walletId}_wallet',
- value: walletOpen,
- );
- });
+ await _ensureWalletOpen();
await _generateAndStoreReceivingAddressForIndex(
mimblewimblecoinData.receivingIndex,
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.