{"record":{"id":"5d6e706bd6775a2e","repo":"FuelLabs/fuels-ts","slug":"invalid-mnemonic","errorCode":"INVALID_MNEMONIC","errorMessage":"Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(', ')}] words, but got ${words.length}.","messagePattern":"Invalid mnemonic size\\. Expected one of \\[(.+?)\\] words, but got (.+?)\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/mnemonic/mnemonic.ts","lineNumber":46,"sourceCode":"  }\n}\n\nfunction assertEntropy(entropy: BytesLike) {\n  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {\n    throw new FuelError(\n      ErrorCode.INVALID_ENTROPY,\n      `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`\n    );\n  }\n}\n\nfunction assertMnemonic(words: Array<string>) {\n  if (!MNEMONIC_SIZES.includes(words.length)) {\n    const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(\n      ', '\n    )}] words, but got ${words.length}.`;\n\n    throw new FuelError(ErrorCode.INVALID_MNEMONIC, errorMsg);\n  }\n}\n\nclass Mnemonic {\n  wordlist: Array<string>;\n\n  /**\n   *\n   * @param wordlist - Provide a wordlist with the list of words used to generate the mnemonic phrase. The default value is the English list.\n   * @returns Mnemonic instance\n   */\n  constructor(wordlist: Array<string> = english) {\n    this.wordlist = wordlist;\n\n    assertWordList(this.wordlist);\n  }\n\n  /**","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/mnemonic/mnemonic.ts#L28-L64","documentation":"Thrown by assertMnemonic when an array of mnemonic words does not contain one of the BIP-39 valid word counts. The only accepted lengths are [12, 15, 18, 21, 24] (the MNEMONIC_SIZES constant), because each maps to a fixed entropy+checksum bit layout. Any other count makes entropy recovery mathematically impossible.","triggerScenarios":"Calling Mnemonic.mnemonicToEntropy(words) or mnemonicToEntropy with an array whose length is not 12/15/18/21/24; splitting a phrase incorrectly (e.g. on commas or extra whitespace) producing stray empty entries; passing a partial or truncated phrase; mixing word counts from different sources.","commonSituations":"User edited/copy-pasted a seed phrase and dropped or duplicated a word; splitting on the wrong delimiter (e.g. splitting on newlines that leave empty strings); importing a 12-word phrase into a flow expecting 24 words; concatenating two phrases.","solutions":["Verify the word count is one of 12, 15, 18, 21, or 24 before calling mnemonicToEntropy.","Split the phrase with phrase.trim().split(/\\s+/) to avoid empty tokens from leading/trailing/multiple spaces.","If the phrase came from a user, prompt them to re-enter the complete, unmodified seed phrase.","Use getWords(phrase) from @fuel-ts/account mnemonic utils to normalize string-vs-array input before validation."],"exampleFix":"// before\nconst words = phrase.split(' '); // may produce [''] or wrong count\nconst entropy = Mnemonic.mnemonicToEntropy(words);\n\n// after\nconst words = phrase.trim().split(/\\s+/);\nif (![12, 15, 18, 21, 24].includes(words.length)) {\n  throw new Error(`Expected 12/15/18/21/24 words, got ${words.length}`);\n}\nconst entropy = Mnemonic.mnemonicToEntropy(words);","handlingStrategy":"validation","validationCode":"import { MNEMONIC_SIZES } from '@fuel-ts/account';\nfunction normalizeWords(phrase: string | string[]): string[] {\n  const words = Array.isArray(phrase) ? phrase : phrase.trim().split(/\\s+/);\n  if (!MNEMONIC_SIZES.includes(words.length)) {\n    throw new Error(`Mnemonic must have ${MNEMONIC_SIZES.join('/')} words; got ${words.length}`);\n  }\n  return words;\n}","typeGuard":"function isValidMnemonicLength(words: string[]): boolean {\n  return [12, 15, 18, 21, 24].includes(words.length);\n}","tryCatchPattern":"import { FuelError, ErrorCode } from '@fuel-ts/errors';\ntry {\n  const entropy = Mnemonic.mnemonicToEntropy(words);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_MNEMONIC) {\n    // prompt user for the full, correctly-sized phrase\n  }\n  throw e;\n}","preventionTips":["Always split phrases with trim().split(/\\s+/) to avoid empty tokens.","Validate word count before any mnemonic operation.","Persist the original phrase unchanged; do not reconstruct it from pieces."],"tags":["mnemonic","bip39","validation","wallet"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}