deriveServiceSeed function
Implementation
Uint8List deriveServiceSeed(
dynamic seed,
String derivationPath,
int index, {
String pathSuffix = '',
}) {
final sha256 = Digest('SHA-256');
var hashedPath = Uint8List.fromList([]);
if (isPathWithIndex(derivationPath)) {
hashedPath = sha256.process(
Uint8List.fromList(
replaceDerivationPathIndex(derivationPath, pathSuffix, index).codeUnits,
),
);
} else {
final path = derivationPath.split('/');
final serviceName = path.removeLast() + pathSuffix;
hashedPath = sha256.process(
Uint8List.fromList(
utf8.encode('${path.join('/')}/$serviceName'),
),
);
}
final hmac = crypto_lib.Hmac(crypto_lib.sha512, seed);
final digest = hmac.convert(hashedPath);
return Uint8List.fromList(digest.bytes.sublist(0, 32));
}