getHcPartyKeyByOwner method

Future<Uint8List?> getHcPartyKeyByOwner(
  1. String delegateId,
  2. String ownerId,
  3. RSAPrivateKey? myPrivateKey
)

Implementation

Future<Uint8List?> getHcPartyKeyByOwner(String delegateId, String ownerId, RSAPrivateKey? myPrivateKey) async {
  RSAPrivateKey? privateKey = myPrivateKey ?? rsaKeyPairs[ownerId]?.privateKey;
  if (privateKey == null) {
    throw FormatException("Missing key for hcp $delegateId");
  }

  Future<Map<String, Tuple2<String, Uint8List>>?>? keyMapFuture = dataOwnerResolver.getDataOwner(ownerId).then((hcp) {
    var hcpnn = Map<String, String>.fromEntries(findKeysToDecrypt(hcp));
    return decryptHcPartyKeys(hcpnn, delegateId, privateKey);
  });

  final Map<String, Tuple2<String, Uint8List>>? keyMap = await keyMapFuture;

  if (keyMap == null) {
    throw FormatException("Unknown hcp $ownerId");
  }

  return keyMap[delegateId]?.item2;
}