generateKeyPair static method

AsymmetricKeyPair<PublicKey, PrivateKey> generateKeyPair({
  1. Uint8List? seed,
})

Generate Keypair

Implementation

static AsymmetricKeyPair<PublicKey, PrivateKey> generateKeyPair({
  Uint8List? seed,
}) {
  var keyParams = ECCurve_secp256k1();
  var random = FortunaRandom();
  if (seed == null) {
    random.seed(KeyParameter(_seed(32)));
  } else {
    random.seed(KeyParameter(seed));
  }
  BigInt n = keyParams.n;
  int nBitLength = n.bitLength;
  BigInt d;
  do {
    d = random.nextBigInteger(nBitLength);
  } while (d == BigInt.zero || (d >= n));
  ECPoint q = scalarMultiple(d, keyParams.G);
  return AsymmetricKeyPair(
    ECPublicKey(q, keyParams),
    ECPrivateKey(d, keyParams),
  );
}