derivePrivateKey function
Implementation
Uint8List derivePrivateKey(String seed, int index) {
//Derive master keys
crypto.Hmac hmac = new crypto.Hmac(crypto.sha512, Uint8List(0));
crypto.Digest digest = hmac.convert(utf8.encode(seed));
Uint8List masterKey = Uint8List.fromList(digest.bytes.sublist(0, 32));
Uint8List masterEntropy = Uint8List.fromList(digest.bytes.sublist(32, 64));
//Derive the final seed
hmac = new crypto.Hmac(crypto.sha512, masterEntropy);
Uint8List indexBuf = encodeInt32(index);
Uint8List extendedSeed = concatUint8List([masterKey, indexBuf]);
digest = hmac.convert(extendedSeed);
Uint8List hmacBuf = Uint8List.fromList(digest.bytes.sublist(0, 32));
return hmacBuf;
}