{"record":{"id":"59afe8bb2c3f8b13","repo":"FuelLabs/fuels-ts","slug":"invalid-entropy","errorCode":"INVALID_ENTROPY","errorMessage":"Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.","messagePattern":"Entropy should be between 16 and 32 bytes and a multiple of 4, but got (.+?) bytes\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/mnemonic/mnemonic.ts","lineNumber":33,"sourceCode":"// \"Bitcoin seed\"\nconst MasterSecret = toUtf8Bytes('Bitcoin seed');\n// 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)\nconst MainnetPRV = '0x0488ade4';\nconst TestnetPRV = '0x04358394';\nexport const MNEMONIC_SIZES = [12, 15, 18, 21, 24];\n\nfunction assertWordList(wordlist: Array<string>) {\n  if (wordlist.length !== 2048) {\n    throw new FuelError(\n      ErrorCode.INVALID_WORD_LIST,\n      `Expected word list length of 2048, but got ${wordlist.length}.`\n    );\n  }\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>;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/mnemonic/mnemonic.ts#L15-L51","documentation":"Thrown by assertEntropy when entropy passed to mnemonic generation violates BIP-39 size rules. Valid entropy must be a multiple of 4 bytes and fall in the 16–32 byte range (i.e. 16, 20, 24, 28, or 32 bytes), which correspond to the 12/15/18/21/24-word mnemonics. The library enforces this so that the resulting mnemonic has a mathematically valid checksum length.","triggerScenarios":"Calling Mnemonic.entropyToMnemonic(entropy) or Mnemonic.generateMnemonic(entropy) with entropy whose byte length is not in {16,20,24,28,32}; passing a hex string or Uint8Array that is e.g. 15, 17, or 33 bytes; passing 12 bytes (too short) or 36 bytes (too long).","commonSituations":"Generating a wallet from a hand-picked entropy buffer; truncating/padding a key incorrectly before seeding a mnemonic; migrating from a library that did not enforce the multiple-of-4 rule; copying a 32-character hex string (16 chars = 8 bytes, mistaken as 16 bytes).","solutions":["Ensure entropy is exactly 16, 20, 24, 28, or 32 bytes (32/40/48/56/64 hex characters respectively).","If you need a random mnemonic, call Mnemonic.generateMnemonic() with no entropy so the library generates a correctly-sized buffer.","Pad/truncate an existing seed only if you understand the security implications, and re-verify the length with entropy.length before passing it.","If deriving entropy from another source, slice to a valid length: e.g. entropy.slice(0, 32) for a 24-word mnemonic."],"exampleFix":"// before\nconst phrase = Mnemonic.entropyToMnemonic('0x00112233445566'); // 7 bytes\n\n// after\nconst entropy = randomBytes(16); // valid: 16 bytes -> 12 words\nconst phrase = Mnemonic.entropyToMnemonic(entropy);","handlingStrategy":"validation","validationCode":"import { arrayify } from '@fuel-ts/utils';\nconst VALID_ENTROPY_LENGTHS = new Set([16, 20, 24, 28, 32]);\nfunction assertValidEntropy(entropy: Uint8Array | string) {\n  const bytes = typeof entropy === 'string' ? arrayify(entropy) : entropy;\n  if (!VALID_ENTROPY_LENGTHS.has(bytes.length)) {\n    throw new Error(`Entropy must be 16/20/24/28/32 bytes; got ${bytes.length}`);\n  }\n}\n// call before Mnemonic.entropyToMnemonic(entropy)","typeGuard":"function isValidEntropy(bytes: Uint8Array): bytes is Uint8Array {\n  return bytes.length >= 16 && bytes.length <= 32 && bytes.length % 4 === 0;\n}","tryCatchPattern":"import { FuelError, ErrorCode } from '@fuel-ts/errors';\ntry {\n  const phrase = Mnemonic.entropyToMnemonic(entropy);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_ENTROPY) {\n    // surface a user-facing message about valid entropy sizes\n  }\n  throw e;\n}","preventionTips":["Generate entropy via crypto.randomBytes with a length from {16,20,24,28,32}.","Centralize mnemonic creation in one helper that validates entropy length.","Add a unit test asserting entropy.length % 4 === 0 and 16..32."],"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"}