openBoxes method
Opens storage containers optional encrypted with password
Implementation
Future<bool> openBoxes([String? password]) async {
//password to AES-Key
if (password != null) {
var generator = PBKDF2(hash: sha256);
var aesKey = generator.generateKey(password, "salt", 1000, 32);
//only values are encrypted, keys are stored in plaintext
try {
_keyBox = await Hive.openBox('keyBox_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_credentialBox = await Hive.openBox<Credential>(
'credentialBox_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_configBox = await Hive.openBox('configBox_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_issuingHistory = await Hive.openBox<Credential>(
'issuingHistory_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_connection = await Hive.openBox<Connection>(
'connections_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_exchangeHistory = await Hive.openBox<List<dynamic>>(
'exchangeHistory_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
_didcommConversations = await Hive.openBox<DidcommConversation>(
'didcommConversations_$_nameExpansion',
path: _walletPath,
encryptionCipher: HiveAesCipher(aesKey),
crashRecovery: false);
} catch (e) {
if (e is HiveError && e.message.contains('corrupted')) {
throw WalletException('Cant open boxes. Maybe wrong password?');
} else {
rethrow;
}
}
} else {
_keyBox = await Hive.openBox('keyBox_$_nameExpansion', path: _walletPath);
_credentialBox = await Hive.openBox<Credential>(
'credentialBox_$_nameExpansion',
path: _walletPath);
_configBox =
await Hive.openBox('configBox_$_nameExpansion', path: _walletPath);
_issuingHistory = await Hive.openBox<Credential>(
'issuingHistory_$_nameExpansion',
path: _walletPath);
_connection = await Hive.openBox<Connection>(
'connections_$_nameExpansion',
path: _walletPath);
_exchangeHistory = await Hive.openBox<List<dynamic>>(
'exchangeHistory_$_nameExpansion',
path: _walletPath);
_didcommConversations = await Hive.openBox<DidcommConversation>(
'didcommConversations$_nameExpansion',
path: _walletPath);
}
return _keyBox != null &&
_issuingHistory != null &&
_credentialBox != null &&
_configBox != null &&
_connection != null &&
_exchangeHistory != null &&
_didcommConversations != null;
}