Secp256r1Keypair constructor

Secp256r1Keypair([
  1. Secp256KeypairData? keypair
])

Create a new keypair instance. Generate random keypair if no Secp256r1Keypair is provided.

Implementation

Secp256r1Keypair([Secp256KeypairData? keypair]) {
  if (keypair != null) {
    if (keypair.secretKey.length != 32) {
      throw ArgumentError('Invalid private key.');
    }
    _keypair = keypair;
  } else {
   Uint8List secretKey = secp256r1.generatePrivateKeyBytes();
   Uint8List publicKey = secp256r1.getPublicKeyFromPrivateKeyBytes(secretKey);
    _keypair = Secp256KeypairData(publicKey, secretKey);
  }
}