initiateSession method
Initiates a session establishment process with remote peer. Returns the handshake message to send to the remote peer.
Implementation
@override
Future<Map<String, dynamic>> initiateSession(
CryptoPeerCapabilities localCapabilities) async {
// Generate ECDH key pair for session
final keyPairData = await ECDHKeyExchange.generateKeyPair();
_keyExchange = ECDHKeyExchange(
InputECDHKeyExchange(
parent: InputKeyExchangeBase(
algorithm: KeyExchangeAlgorithm.ecdh,
expirationDate: DateTime.now().add(const Duration(hours: 24)),
expirationTimes: null,
),
publicKey: keyPairData['publicKey']!,
privateKey: keyPairData['privateKey']!,
curve: keyPairData['curve']!,
),
);
// Create handshake message
final handshakeMessage = _negotiator.createHandshakeMessage(localCapabilities);
// Add key exchange information
handshakeMessage['keyExchangeData'] = {
'type': 'ecdh',
'publicKey': _keyExchange!.getPublicKey(),
'curve': _keyExchange!.curve,
};
return handshakeMessage;
}