newKeyFromSeed function
NewKeyFromSeed calculates a private key from a seed. It will throw ArgumentError if seed.length is not SeedSize. This function is provided for interoperability with RFC 8032. RFC 8032's private keys correspond to seeds in this package.
Implementation
PrivateKey newKeyFromSeed(Uint8List seed) {
if (seed.length != SeedSize) {
throw ArgumentError('ed25519: bad seed length ${seed.length}');
}
var h = sha512.convert(seed);
var digest = h.bytes.sublist(0, 32);
digest[0] &= 248;
digest[31] &= 127;
digest[31] |= 64;
var A = ExtendedGroupElement();
var hBytes = digest.sublist(0);
GeScalarMultBase(A, hBytes as Uint8List);
var publicKeyBytes = Uint8List(32);
A.ToBytes(publicKeyBytes);
var privateKey = Uint8List(PrivateKeySize);
arrayCopy(seed, 0, privateKey, 0, 32);
arrayCopy(publicKeyBytes, 0, privateKey, 32, 32);
return PrivateKey(privateKey);
}