newKeyPair method

  1. @override
Future<EcKeyPair> newKeyPair()

Generates a new KeyPair for this algorithm.

Implementation

@override
Future<EcKeyPair> newKeyPair() async {
  if (isSupportedPlatform) {
    final result = await invokeMethod(
      'Ecdsa.newKeyPair',
      {
        if (isAndroid) 'androidProvider': androidCryptoProvider,
        'curve': keyPairType.name,
      },
    );
    final der = result['der'] as Uint8List?;
    if (der != null) {
      // if (keyPairType==KeyPairType.p384) {
      //   throw StateError('public key DER:\n${hexFromBytes(generatedPublicDer!)}');
      // }
      return EcKeyPairData.parseDer(
        der,
        type: keyPairType,
      );
    }
    final d = result['d'] as Uint8List;
    final x = result['x'] as Uint8List;
    final y = result['y'] as Uint8List;
    return EcKeyPairData(
      d: d,
      x: x,
      y: y,
      type: keyPairType,
    );
  }
  final fallback = this.fallback;
  if (fallback == null) {
    throw UnsupportedError('Unsupported and no fallback implementation');
  }
  return fallback.newKeyPair();
}