Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clear local storage data store #241

Merged
merged 8 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cosmos_ui_components/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ class BiometricDataStore implements SecureDataStore {
return left(BiometricCredentialsStorageFailure.unsupported());
}
}

@override
Future<Either<CredentialsStorageFailure, bool>> clearAllData() async {
try {
final biometricStorage = BiometricStorage();
final storageFile = await biometricStorage.getStorage(
storageFileName,
options: _storageFileInitOptions,
promptInfo: promptInfo,
);
await storageFile.delete();
return right(true);
} catch (ex, stack) {
logError(ex, stack);
return left(
CredentialsStorageFailure(
'Error while clearing data in Biometric storage',
cause: ex,
stack: stack,
),
);
}
}
}

Map<String, String?> _decodeMap(String json) => (json.trim().isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ class FlutterSecureStorageDataStore implements SecureDataStore {
}) : _store = storage ?? const FlutterSecureStorage();

final FlutterSecureStorage _store;
static const iosOptions = IOSOptions(accessibility: IOSAccessibility.passcode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also update other methods to use those constants aswell?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

static const androidOptions = AndroidOptions(encryptedSharedPreferences: true);

@override
Future<Either<CredentialsStorageFailure, String?>> readSecureText({required String key}) async {
try {
return right(
await _store.read(
key: key,
iOptions: const IOSOptions(accessibility: IOSAccessibility.passcode),
aOptions: const AndroidOptions(encryptedSharedPreferences: true),
iOptions: iosOptions,
aOptions: androidOptions,
),
);
} catch (ex, stack) {
Expand Down Expand Up @@ -52,4 +54,24 @@ class FlutterSecureStorageDataStore implements SecureDataStore {
);
}
}

@override
Future<Either<CredentialsStorageFailure, bool>> clearAllData() async {
try {
await _store.deleteAll(
iOptions: iosOptions,
aOptions: androidOptions,
);
return right(true);
} catch (ex, stack) {
logError(ex, stack);
return left(
CredentialsStorageFailure(
"Could not delete secure data'",
cause: ex,
stack: stack,
),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,21 @@ class SharedPrefsPlainDataStore implements PlainDataStore {
);
}
}

@override
Future<Either<CredentialsStorageFailure, bool>> clearAllData() async {
try {
final prefs = await sharedPreferencesProvider();
return right(await prefs.clear());
} catch (ex, stack) {
logError(ex, stack);
return left(
CredentialsStorageFailure(
'Error while clearing all data',
cause: ex,
stack: stack,
),
);
}
}
}
4 changes: 2 additions & 2 deletions packages/transaction_signing_gateway/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -673,7 +673,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.4"
xdg_directories:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class TestMemoryStore implements PlainDataStore, SecureDataStore {
@override
Future<Either<CredentialsStorageFailure, Map<String, String?>>> readAllPlainText() async => right({..._values});

@override
Future<Either<CredentialsStorageFailure, bool>> clearAllData() async {
_values.clear();
return right(true);
}

@override
Future<Either<CredentialsStorageFailure, String?>> readPlainText({
required String key,
Expand Down
18 changes: 9 additions & 9 deletions starport_template/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ packages:
description:
path: "packages/cosmos_auth"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand All @@ -162,7 +162,7 @@ packages:
description:
path: "packages/cosmos_ui_components"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand All @@ -171,7 +171,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -651,14 +651,14 @@ packages:
name: share_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.1.0"
share_plus_web:
dependency: transitive
description:
Expand Down Expand Up @@ -788,7 +788,7 @@ packages:
description:
path: "packages/transaction_signing_gateway"
ref: main
resolved-ref: "2946ddfdab692a9d9f4752c4af83c2b1083f51e6"
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -847,7 +847,7 @@ packages:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
version: "2.0.9"
url_launcher_windows:
dependency: transitive
description:
Expand Down Expand Up @@ -882,7 +882,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.4"
xdg_directories:
dependency: transitive
description:
Expand All @@ -906,4 +906,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.15.0 <3.0.0"
flutter: ">=2.8.0"
flutter: ">=2.10.0"