store method

Future<void> store(
  1. String type,
  2. String secret,
  3. String keyId,
  4. Uint8List key, {
  5. bool add = false,
})

Implementation

Future<void> store(String type, String secret, String keyId, Uint8List key,
    {bool add = false}) async {
  final encrypted = await encryptAes(secret, key, type);
  Map<String, dynamic>? content;
  if (add && client.accountData[type] != null) {
    content = client.accountData[type]!.content.copy();
    if (content['encrypted'] is! Map) {
      content['encrypted'] = <String, dynamic>{};
    }
  }
  content ??= <String, dynamic>{
    'encrypted': <String, dynamic>{},
  };
  content['encrypted'][keyId] = <String, dynamic>{
    'iv': encrypted.iv,
    'ciphertext': encrypted.ciphertext,
    'mac': encrypted.mac,
  };
  // store the thing in your account data
  await client.setAccountData(client.userID!, type, content);
  final db = client.database;
  if (cacheTypes.contains(type) && db != null) {
    // cache the thing
    await db.storeSSSSCache(type, keyId, encrypted.ciphertext, secret);
    onSecretStored.add(keyId);
    if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
      _cacheCallbacks[type]!(secret);
    }
  }
}