cake_wallet/cw_core/lib/utils/file.dart
Konstantin Ullrich 3b7f9a297c
Bug missing polyseed (#1214)
* Move file.dart

* Add seedFallback for missing polyseeds

* Remove unused dependency of cw_bitcoin

* Minor fix MacOS

* Add more blockheight-date matching

* Scan only last 2 days for new Polyseed wallets
2023-12-02 03:02:55 +02:00

30 lines
904 B
Dart

import 'dart:io';
import 'package:cw_core/key.dart';
import 'package:encrypt/encrypt.dart' as encrypt;
Future<void> write({required String path, required String password, required String data}) async =>
writeData(path: path, password: password, data: data);
Future<void> writeData(
{required String path,
required String password,
required String data}) async {
final keys = extractKeys(password);
final key = encrypt.Key.fromBase64(keys.first);
final iv = encrypt.IV.fromBase64(keys.last);
final encrypted = await encode(key: key, iv: iv, data: data);
final f = File(path);
f.writeAsStringSync(encrypted);
}
Future<String> read({required String path, required String password}) async {
final file = File(path);
if (!file.existsSync()) {
file.createSync();
}
final encrypted = file.readAsStringSync();
return decode(password: password, data: encrypted);
}