{"record":{"id":"73435562497003f9","repo":"FuelLabs/fuels-ts","slug":"invalid-seed","errorCode":"INVALID_SEED","errorMessage":"Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.","messagePattern":"Seed length should be between 16 and 64 bytes, but received (.+?) bytes\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/mnemonic/mnemonic.ts","lineNumber":192,"sourceCode":"        right = mid - 1;\n      } else {\n        left = mid + 1;\n      }\n    }\n\n    return false;\n  }\n\n  /**\n   * @param seed - BIP39 seed\n   * @param testnet - Inform if should use testnet or mainnet prefix, the default value is true (`mainnet`).\n   * @returns 64-byte array contains privateKey and chainCode as described on BIP39\n   */\n  static masterKeysFromSeed(seed: string): Uint8Array {\n    const seedArray = arrayify(seed);\n\n    if (seedArray.length < 16 || seedArray.length > 64) {\n      throw new FuelError(\n        ErrorCode.INVALID_SEED,\n        `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`\n      );\n    }\n\n    return arrayify(computeHmac('sha512', MasterSecret, seedArray));\n  }\n\n  /**\n   * Get the extendKey as defined on BIP-32 from the provided seed\n   *\n   * @param seed - BIP39 seed\n   * @param testnet - Inform if should use testnet or mainnet prefix, default value is true (`mainnet`).\n   * @returns BIP-32 extended private key\n   */\n  static seedToExtendedKey(seed: string, testnet: boolean = false): string {\n    const masterKey = Mnemonic.masterKeysFromSeed(seed);\n    const prefix = arrayify(testnet ? TestnetPRV : MainnetPRV);","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/mnemonic/mnemonic.ts#L174-L210","documentation":"Thrown by Mnemonic.masterKeysFromSeed when the BIP-39 seed passed to derive a BIP-32 master key is not between 16 and 64 bytes long. The seed is the output of PBKDF2 over the mnemonic phrase and must lie in this range for HMAC-SHA512 master-key derivation to be meaningful. Seeds outside this range indicate a malformed or truncated input.","triggerScenarios":"Calling Mnemonic.masterKeysFromSeed(seed) where seed is a hex string or bytes whose decoded length is < 16 or > 64; passing the mnemonic phrase string itself instead of the PBKDF2-derived seed; passing an empty or undefined value that arrayifies to 0 bytes.","commonSituations":"Confusing the mnemonic phrase with the seed (the seed comes from mnemonicToSeed, not the raw phrase); passing a short hex value like '0x1234' (2 bytes); truncating a 64-byte seed during serialization; using a non-BIP-39 KDF output that is the wrong length.","solutions":["Generate the seed correctly via Mnemonic.mnemonicToSeed(phrase) before calling masterKeysFromSeed.","Confirm the seed buffer length is within 16–64 bytes after decoding (32 and 64 are typical PBKDF2-512 outputs).","If you already have a seed, validate seedArray.length with arrayify before the call.","Do not pass the raw mnemonic string or entropy bytes; pass the derived seed."],"exampleFix":"// before\nconst master = Mnemonic.masterKeysFromSeed(phrase); // phrase is the mnemonic text\n\n// after\nconst seed = Mnemonic.mnemonicToSeed(phrase); // correct 64-byte seed\nconst master = Mnemonic.masterKeysFromSeed(seed);","handlingStrategy":"validation","validationCode":"import { arrayify } from '@fuel-ts/utils';\nfunction assertValidSeedLength(seed: string | Uint8Array) {\n  const len = typeof seed === 'string' ? arrayify(seed).length : seed.length;\n  if (len < 16 || len > 64) {\n    throw new Error(`Seed must be 16..64 bytes; got ${len}`);\n  }\n}","typeGuard":"function isValidSeedLength(seed: Uint8Array): boolean {\n  return seed.length >= 16 && seed.length <= 64;\n}","tryCatchPattern":"import { FuelError, ErrorCode } from '@fuel-ts/errors';\ntry {\n  const master = Mnemonic.masterKeysFromSeed(seed);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_SEED) {\n    // re-derive seed via mnemonicToSeed and retry once\n  }\n  throw e;\n}","preventionTips":["Always derive the seed via mnemonicToSeed before calling masterKeysFromSeed.","Never pass the raw mnemonic phrase where a seed is expected.","Store/cache the 64-byte seed rather than re-deriving with wrong inputs."],"tags":["mnemonic","bip32","bip39","wallet","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}