upsertKey method

Future<void> upsertKey(
  1. String userId,
  2. String sharedKey, {
  3. String? password,
})

Store or update an encrypted shared key for a user

Implementation

Future<void> upsertKey(String userId, String sharedKey, {String? password}) async {
  final key = password ?? _defaultPassword;
  final encryptedKey = _encryptSharedKey(userId, sharedKey, key);

  _sharedKeysCache[userId] = sharedKey; // Store the decrypted key in the cache

  await _database.insert(
    tableSharedKeys,
    {
      columnUserId: userId,
      columnSharedKey: encryptedKey, // Store the encrypted key
    },
    conflictAlgorithm: ConflictAlgorithm.replace,
  );
}