EDDSAPrivateKey constructor
Creates an EdDSA private key from a random value using a provided hash method.
The private key is generated from the provided hash method and the provided random value. It prunes the key for improved security.
Parameters:
- generator: The Edwards curve generator point.
- privateKey: The private key bytes.
- hashMethod: A serializable hash function for key generation.
Throws:
- ArgumentException: If the private key size is invalid.
Implementation
factory EDDSAPrivateKey(
EDPoint generator,
List<int> privateKey,
HashFunc hashMethod,
) {
final baselen = (generator.curve.p.bitLength + 1 + 7) ~/ 8;
if (privateKey.length != baselen) {
throw ArgumentException(
'Incorrect size of private key, expected: $baselen bytes');
}
final extendedKey = hashMethod().update(privateKey).digest();
final a = extendedKey.sublist(0, baselen);
final prunedKey = _keyPrune(List<int>.from(a), generator);
final secret = BigintUtils.fromBytes(prunedKey, byteOrder: Endian.little);
return EDDSAPrivateKey._(
generator, baselen, privateKey, secret, extendedKey.sublist(baselen));
}