agree method
The X25519 agreement with peerPublicKey, or null when the peer key
is malformed or of low order (an all-zero result), which would make the
agreement contribute nothing.
Implementation
Future<List<int>?> agree(List<int> peerPublicKey) async {
if (peerPublicKey.length != 32) return null;
try {
final shared = await _x25519.sharedSecretKey(
keyPair: _keyPair,
remotePublicKey: SimplePublicKey(
peerPublicKey,
type: KeyPairType.x25519,
),
);
// A copy the caller owns, so it can wipe it.
final bytes = Uint8List.fromList(await shared.extractBytes());
if (bytes.every((b) => b == 0)) return null;
return bytes;
} catch (_) {
return null;
}
}