Implementation
Uint8List derivePrivateKey(seed, int index) {
if (isHex(seed)) {
seed = hexToUint8List(seed);
}
//Derive master keys
final Digest sha512 = Digest('SHA-512');
Uint8List buf = sha512.process(seed);
final Uint8List masterKey = buf.sublist(0, 32);
final Uint8List masterEntropy = buf.sublist(32, 64);
//Derive the final seed
crypto.Hmac hmac = crypto.Hmac(crypto.sha512, masterEntropy);
final Uint8List indexBuf = encodeInt32(index);
final Uint8List extendedSeed = concatUint8List([masterKey, indexBuf]);
crypto.Digest digest = hmac.convert(extendedSeed);
final Uint8List hmacBuf = Uint8List.fromList(digest.bytes.sublist(0, 32));
return hmacBuf;
}