sharedSecretKey method

  1. @override
Future<SecretKey> sharedSecretKey({
  1. required KeyPair keyPair,
  2. required PublicKey remotePublicKey,
})

Calculates a shared SecretKey.

Implementation

@override
Future<SecretKey> sharedSecretKey({
  required KeyPair keyPair,
  required PublicKey remotePublicKey,
}) async {
  if (!kIsWeb) {
    if (isSupportedPlatform &&
        keyPair is SimpleKeyPairData &&
        remotePublicKey is SimplePublicKey) {
      final privateKey = await keyPair.extractPrivateKeyBytes();
      final publicKey = remotePublicKey.bytes;
      final result = await invokeMethod('X25519.sharedSecretKey', {
        'privateKey': asUint8List(privateKey),
        'publicKey': asUint8List(publicKey),
      });
      return SecretKey(
        result['sharedSecretKey'] as Uint8List,
      );
    }
  }
  return await fallback.sharedSecretKey(
    keyPair: keyPair,
    remotePublicKey: remotePublicKey,
  );
}