validateEntropy function
Implementation
bool validateEntropy(String entropy) {
if (entropy.runtimeType == Null) return false;
try {
// check if entropy is valid
if (!RegExp(r'^[0-9a-fA-F]+$').hasMatch(entropy)) {
throw ArgumentError(_invalidEntropy);
}
final entropyBytes = Uint8List.fromList(HEX.decode(entropy));
// debugPrint("entropyBytes.length: ${entropyBytes.length}");
// debugPrint("entropy.lenth: ${entropy.length}");
if (entropyBytes.length < 16) {
throw ArgumentError(_invalidEntropy);
}
if (entropyBytes.length > 32) {
throw ArgumentError(_invalidEntropy);
}
if (entropyBytes.length % 4 != 0) {
throw ArgumentError(_invalidEntropy);
}
} catch (e) {
return false;
}
return true;
}