forwardKey method
Implementation
Future<void> forwardKey([int? index]) async {
if (request.canceled) {
keyManager.incomingShareRequests.remove(request.requestId);
return; // request is canceled, don't send anything
}
final room = this.room;
final session =
await keyManager.loadInboundGroupSession(room.id, request.sessionId);
if (session?.inboundGroupSession == null) {
Logs().v("[KeyManager] Not forwarding key we don't have");
return;
}
final message = session!.content.copy();
message['forwarding_curve25519_key_chain'] =
List<String>.from(session.forwardingCurve25519KeyChain);
if (session.senderKey.isNotEmpty) {
message['sender_key'] = session.senderKey;
}
message['sender_claimed_ed25519_key'] =
session.senderClaimedKeys['ed25519'] ??
(session.forwardingCurve25519KeyChain.isEmpty
? keyManager.encryption.fingerprintKey
: null);
message['session_key'] = session.inboundGroupSession!.export_session(
index ?? session.inboundGroupSession!.first_known_index(),
);
// send the actual reply of the key back to the requester
await keyManager.client.sendToDeviceEncrypted(
[requestingDevice],
EventTypes.ForwardedRoomKey,
message,
);
keyManager.incomingShareRequests.remove(request.requestId);
}