encryptSeedAndSave method

Future<void> encryptSeedAndSave(
  1. String? pubKey,
  2. dynamic seed,
  3. dynamic seedType,
  4. dynamic password,
)

Implementation

Future<void> encryptSeedAndSave(
    String? pubKey, seed, seedType, password) async {
  final String key = Encrypt.passwordToEncryptKey(password);
  final String? encrypted = await FlutterAesEcbPkcs5.encryptString(seed, key);

  // read old data from storage-old
  final Map stored = await (_storageOld.getSeeds(seedType));
  stored[pubKey] = encrypted;
  // and save to new storage
  if (seedType == KeyType.mnemonic.toString().split('.')[1]) {
    final mnemonics = Map.from(_storage.encryptedMnemonics.val);
    mnemonics.addAll(stored);
    _storage.encryptedMnemonics.val = mnemonics;
    return;
  }
  if (seedType == KeyType.rawSeed.toString().split('.')[1]) {
    final seeds = Map.from(_storage.encryptedRawSeeds.val);
    seeds.addAll(stored);
    _storage.encryptedRawSeeds.val = seeds;
  }
}