{"record":{"id":"861a0c685804c952","repo":"FuelLabs/fuels-ts","slug":"hd-wallet-error","errorCode":"HD_WALLET_ERROR","errorMessage":"invalid path - ${path}","messagePattern":"invalid path - (.+?)","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/hdwallet/hdwallet.ts","lineNumber":45,"sourceCode":"  }\n  return testnet ? TestnetPRV : MainnetPRV;\n}\n\nfunction isPublicExtendedKey(extendedKey: Uint8Array) {\n  return [MainnetPUB, TestnetPUB].includes(hexlify(extendedKey.slice(0, 4)));\n}\n\nfunction isValidExtendedKey(extendedKey: Uint8Array) {\n  return [MainnetPRV, TestnetPRV, MainnetPUB, TestnetPUB].includes(\n    hexlify(extendedKey.slice(0, 4))\n  );\n}\n\nfunction parsePath(path: string, depth: number = 0) {\n  const components = path.split('/');\n\n  if (components.length === 0 || (components[0] === 'm' && depth !== 0)) {\n    throw new FuelError(ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);\n  }\n\n  if (components[0] === 'm') {\n    components.shift();\n  }\n\n  return components.map((p) =>\n    ~p.indexOf(`'`) ? parseInt(p, 10) + HARDENED_INDEX : parseInt(p, 10)\n  );\n}\n\ntype HDWalletConfig = {\n  privateKey?: BytesLike;\n  publicKey?: BytesLike;\n  chainCode: BytesLike;\n  depth?: number;\n  index?: number;\n  parentFingerprint?: string;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/hdwallet/hdwallet.ts#L27-L63","documentation":"Thrown by parsePath when a BIP-32 derivation path is malformed: either it has no components after splitting on '/', or it begins with 'm' at a non-zero depth (you cannot re-anchor an already-derived wallet). HDWallet.derivePath uses this to convert a string path into numeric child indices. The path must follow the m/44'/117'/0'/0/0 convention.","triggerScenarios":"Calling hdwallet.derivePath('') (empty), hdwallet.derivePath('m/...') on a wallet whose depth is already > 0 (re-deriving from 'm' on a child), or a path like '//0/0' that splits to empty segments.","commonSituations":"Reusing an already-derived HDWallet and calling derivePath with an absolute 'm/...' path, passing a user-typed path with stray slashes, or building a path string incorrectly (concatenation bugs).","solutions":["Use absolute paths only on a master (depth 0) HDWallet from fromSeed/fromExtendedKey; on children, use relative paths without the 'm' prefix.","Validate the path format before calling derivePath: /^m(\\/[0-9]+'?)+$/ for a master wallet.","Keep a reference to the master wallet and derive fresh from it rather than chaining off arbitrary nodes."],"exampleFix":"// before\nconst child = master.derivePath(\"m/44'/117'/0'\");\nchild.derivePath(\"m/0/0\"); // 'm' at depth > 0\n\n// after\nconst child = master.derivePath(\"m/44'/117'/0'\");\nchild.derivePath(\"0/0\"); // relative path","handlingStrategy":"validation","validationCode":"// Validate a BIP-32 path before deriving\nfunction isValidPath(path: string, isMaster: boolean): boolean {\n  if (!path) return false;\n  const re = isMaster ? /^(m)(\\/[0-9]+['\\h]?)*$/ : /^([0-9]+['\\h]?)(\\/[0-9]+['\\h]?)*$/;\n  return re.test(path);\n}\n\nif (isValidPath(path, master.depth === 0)) master.derivePath(path);","typeGuard":"function isAbsolutePath(path: string): boolean {\n  return path.startsWith('m');\n}","tryCatchPattern":"try {\n  child.derivePath(path);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.HD_WALLET_ERROR && /invalid path/.test(e.message)) {\n    // strip leading 'm' for child wallets, or re-derive from master\n  } else throw e;\n}","preventionTips":["Only use 'm'-prefixed absolute paths on the master node (depth 0).","On derived nodes, use relative paths without 'm'.","Derive from a cached master rather than chaining off arbitrary nodes."],"tags":["hd-wallet","bip32","derivation","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}