2024-04-25 17:18:03 +00:00
|
|
|
import 'package:cake_wallet/core/secure_storage.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2023-08-15 00:47:25 +00:00
|
|
|
import 'package:cw_core/cake_hive.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
Future<List<int>> getEncryptionKey(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required String forKey, required FlutterSecureStorage secureStorage}) async {
|
2023-08-15 00:47:25 +00:00
|
|
|
final stringifiedKey = await secureStorage.read(key: 'transactionDescriptionsBoxKey');
|
2020-01-04 19:31:52 +00:00
|
|
|
List<int> key;
|
|
|
|
|
|
|
|
if (stringifiedKey == null) {
|
2023-08-15 00:47:25 +00:00
|
|
|
key = CakeHive.generateSecureKey();
|
2020-01-04 19:31:52 +00:00
|
|
|
final keyStringified = key.join(',');
|
2023-11-27 13:28:34 +00:00
|
|
|
String storageKey = 'transactionDescriptionsBoxKey';
|
2024-04-25 17:18:03 +00:00
|
|
|
await writeSecureStorage(secureStorage, key: storageKey, value: keyStringified);
|
2020-01-04 19:31:52 +00:00
|
|
|
} else {
|
2023-08-15 00:47:25 +00:00
|
|
|
key = stringifiedKey.split(',').map((i) => int.parse(i)).toList();
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
2023-08-15 00:47:25 +00:00
|
|
|
}
|