SoftwareEs256Signer.generate constructor

SoftwareEs256Signer.generate({
  1. Random? random,
  2. KeyAttestation? attestor(
    1. String nonce
    )?,
})

Generates a fresh key. Pass a seeded random for reproducible keys, and attestor to exercise the optional attest path.

Implementation

factory SoftwareEs256Signer.generate({
  Random? random,
  KeyAttestation? Function(String nonce)? attestor,
}) {
  final entropy = random ?? Random.secure();
  final seed = Uint8List.fromList(
    List<int>.generate(32, (_) => entropy.nextInt(256)),
  );
  final generator = ECKeyGenerator()
    ..init(
      ParametersWithRandom(
        ECKeyGeneratorParameters(ECCurve_secp256r1()),
        FortunaRandom()..seed(KeyParameter(seed)),
      ),
    );
  // Type the pair as the generic Private/PublicKey — pointycastle 3.9.x infers
  // those, 4.x narrows them — so the downcast below is genuinely needed (and
  // thus warning-free) on both versions.
  final AsymmetricKeyPair<PublicKey, PrivateKey> pair =
      generator.generateKeyPair();
  return SoftwareEs256Signer._(
    pair.privateKey as ECPrivateKey,
    pair.publicKey as ECPublicKey,
    attestor,
  );
}