validate method

void validate(
  1. Mnemonic mnemonic, {
  2. String password = "",
})

Validates the given mnemonic string, optionally with a password.

Implementation

void validate(Mnemonic mnemonic, {String password = ""}) {
  /// Validates the number of words in the mnemonic.
  TonMnemonicGeneratorUtils.validateWordsNum(mnemonic.wordsCount());

  /// Checks if the mnemonic requires a passphrase but one is not provided.
  if (password.isNotEmpty &&
      !TonEntropyGeneratorUtils.isPasswordNeed(mnemonic)) {
    throw ArgumentException.invalidOperationArguments(
      "validate",
      name: "mnemonic",
      reason: "Invalid ton mnemonic.",
    );
  }

  /// Generates entropy from the mnemonic and passphrase, then checks if it is a basic seed.
  if (!TonEntropyGeneratorUtils.isBasicSeed(
    TonEntropyGeneratorUtils.generateEnteropy(mnemonic, password: password),
  )) {
    throw ArgumentException.invalidOperationArguments(
      "validate",
      name: "mnemonic",
      reason: "Invalid ton mnemonic.",
    );
  }
}