decryptEncryptionKeys method

  1. @override
Future<Set<String>> decryptEncryptionKeys(
  1. String myId,
  2. Map<String, Set<DelegationDto>> keys
)
override

Implementation

@override
Future<Set<String>> decryptEncryptionKeys(String myId, Map<String, Set<DelegationDto>> keys) async {
  final keysWithMe = keys.values.flattened.where((element) => element.delegatedTo == myId || element.owner == myId).toSet();
  List<String?> decryptedKeys = await Future.wait((keysWithMe).map((d) async {
    try {
      final delegateHcPartyKey = await getDelegateHcPartyKey(d.delegatedTo!, d.owner!, null);
      if (delegateHcPartyKey == null) {
        throw FormatException("Cannot find a hc party key");
      }
      return String.fromCharCodes(d.key!.keyFromHexString().decryptAES(delegateHcPartyKey)).split(":")[1];
    } catch (e) {
      return Future.value(null);
    }
  }));

  var parentId = (await dataOwnerResolver.getDataOwner(myId))?.parentId;
  if (parentId != null) {
    decryptEncryptionKeys(parentId, keys);
    return decryptedKeys.whereType<String>().toSet()..addAll(await decryptEncryptionKeys(parentId, keys));
  }
  return decryptedKeys.whereType<String>().toSet();
}