validateCheckSum method
Validates the checksum of a list of Monero mnemonic words.
This method checks whether the provided Monero mnemonic words have a valid checksum by comparing them to the expected checksum. If the checksum is invalid, it throws a MnemonicException.
words
: The list of Monero mnemonic words to validate.
language
: The Monero language used in the mnemonic.
Implementation
void validateCheckSum(List<String> words, MoneroLanguages language) {
try {
MoneroMnemonicConst.mnemonicWordNumChecksum
.firstWhere((element) => element.value == words.length);
final checkSum = MoneroMnemonicUtils.computeChecksum(
words.sublist(0, words.length - 1), language);
if (words.last != checkSum) {
throw MnemonicException(
'Invalid checksum (expected $checkSum, got ${words.last})');
}
// ignore: empty_catches
} on StateError {}
}