getKeys method

Future<(String, String)?> getKeys(
  1. QRMode mode
)

Implementation

Future<(String, String)?> getKeys(QRMode mode) async {
  final keys = client.userDeviceKeys;

  final ownKeys = keys[client.userID];
  final otherUserKeys = keys[userId];
  final ownDeviceKey = ownKeys?.getKey(client.deviceID!);
  final ownMasterKey = ownKeys?.getCrossSigningKey('master');
  final otherDeviceKey = otherUserKeys?.getKey(deviceId!);
  final otherMasterKey = otherUserKeys?.getCrossSigningKey('master');

  if (mode == QRMode.verifyOtherUser &&
      ownMasterKey != null &&
      otherMasterKey != null) {
    // we already have this check when sending `knownVerificationMethods`, but
    // just to be safe anyway
    if (ownMasterKey.verified) {
      return (ownMasterKey.ed25519Key!, otherMasterKey.ed25519Key!);
    }
  } else if (mode == QRMode.verifySelfTrusted &&
      ownMasterKey != null &&
      otherDeviceKey != null) {
    if (ownMasterKey.verified) {
      return (ownMasterKey.ed25519Key!, otherDeviceKey.ed25519Key!);
    }
  } else if (mode == QRMode.verifySelfUntrusted &&
      ownMasterKey != null &&
      ownDeviceKey != null) {
    return (ownDeviceKey.ed25519Key!, ownMasterKey.ed25519Key!);
  }
  return null;
}