validateMnemonic method

bool validateMnemonic(
  1. String mnemonic
)

Validates a BIP-39 mnemonic phrase. Validates a BIP-39 mnemonic phrase.

This method checks whether a given BIP-39 mnemonic phrase is valid. A valid mnemonic phrase conforms to the BIP-39 specification and can be successfully converted back to entropy.

Parameters:

  • mnemonic: The BIP-39 mnemonic phrase to validate.

Returns: true if the mnemonic is valid, false otherwise. Note: This method will return false if the mnemonic is invalid or if any errors occur during the validation process.

Implementation

bool validateMnemonic(String mnemonic) {
  try {
    /// Attempt to convert the mnemonic back to entropy.
    mnemonicToEntropy(mnemonic);
  } on Exception {
    rethrow;

    /// Rethrow exceptions to be caught by the caller.
  } catch (e) {
    return false;

    /// Catch other errors and return false.
  }
  return true;

  /// If no exceptions or errors occur, the mnemonic is valid.
}