ECKeypair.fromRandom constructor

ECKeypair.fromRandom()

Generate a random ECKeypair on the secp256k1-Curve

Implementation

ECKeypair.fromRandom() {
  final keyParams =
      pointy.ECKeyGeneratorParameters(pointy.ECCurve_secp256k1());

  final generator = pointy.ECKeyGenerator();
  generator.init(withRandom(keyParams));

  final pair = generator.generateKeyPair();
  final publicKey = pair.publicKey as pointy.ECPublicKey;
  final privateKey = pair.privateKey as pointy.ECPrivateKey;

  final Q = publicKey.Q!;
  _publicKey = ECPublicKey(Q.x!.toBigInteger()!, Q.y!.toBigInteger()!);
  _privateKey = ECPrivateKey(privateKey.d!);
}