validate static method
Validates a mnemonic phrase according to BIP-39 specification.
Returns true if the mnemonic is valid (correct length, valid words, valid checksum).
Implementation
static bool validate(List<String> mnemonic) {
try {
if (mnemonic.length % 3 != 0 ||
mnemonic.length < 12 ||
mnemonic.length > 24) {
return false;
}
// Check if all words are in the wordlist
for (final word in mnemonic) {
if (!_englishWordlist.contains(word)) {
return false;
}
}
// Convert mnemonic to entropy and validate checksum
final entropy = _mnemonicToEntropy(mnemonic);
final regeneratedMnemonic = _entropyToMnemonic(entropy);
return _listEquals(mnemonic, regeneratedMnemonic);
} on Exception catch (_) {
return false;
}
}