{"record":{"id":"ea2bf0e4c48a62fd","repo":"gchq/CyberChef","slug":"invalid-bech32-string-no-separator-1-found","errorCode":null,"errorMessage":"Invalid Bech32 string: no separator '1' found.","messagePattern":"Invalid Bech32 string: no separator '1' found\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/Bech32.mjs","lineNumber":260,"sourceCode":"    // Check maximum length\n    if (str.length > 90) {\n        throw new OperationError(`Invalid Bech32 string: exceeds maximum length of 90 characters (got ${str.length}).`);\n    }\n\n    // Check for mixed case\n    const hasUpper = /[A-Z]/.test(str);\n    const hasLower = /[a-z]/.test(str);\n    if (hasUpper && hasLower) {\n        throw new OperationError(\"Invalid Bech32 string: mixed case is not allowed. Use all uppercase or all lowercase.\");\n    }\n\n    // Convert to lowercase for processing\n    str = str.toLowerCase();\n\n    // Find separator (last occurrence of '1')\n    const sepIndex = str.lastIndexOf(\"1\");\n    if (sepIndex === -1) {\n        throw new OperationError(\"Invalid Bech32 string: no separator '1' found.\");\n    }\n\n    if (sepIndex === 0) {\n        throw new OperationError(\"Invalid Bech32 string: Human-Readable Part (HRP) cannot be empty.\");\n    }\n\n    if (sepIndex + 7 > str.length) {\n        throw new OperationError(\"Invalid Bech32 string: data part is too short (minimum 6 characters for checksum).\");\n    }\n\n    // Extract HRP and data part\n    const hrp = str.substring(0, sepIndex);\n    const dataPart = str.substring(sepIndex + 1);\n\n    // Validate HRP characters\n    for (let i = 0; i < hrp.length; i++) {\n        const c = hrp.charCodeAt(i);\n        if (c < 33 || c > 126) {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Bech32.mjs#L242-L278","documentation":"Thrown by decode() in src/core/lib/Bech32.mjs:260 when the input contains no '1' character at all, found via str.lastIndexOf('1') === -1. In Bech32 the '1' is the separator between the HRP and the data+checksum part; its absence means the structure of the string is unrecognisable. Note the separator search is case-sensitive but runs after lowercasing, and '1' is also a valid data character, so lastIndexOf finds the rightmost occurrence.","triggerScenarios":"decode('bcrtq...') with no '1' anywhere; decode of a hex string, Base58 address, or other format that happens to contain no '1'. Also a Bech32 string where the separator was stripped or replaced.","commonSituations":"Decoding a Base58 (legacy Bitcoin) address which has no positional '1' separator; feeding raw hex; a mangled address where '1' was deleted; HRP-only string with no data part and no separator.","solutions":["Confirm the input is actually Bech32/Bech32m (native SegWit) and not a legacy Base58 address.","If the address was edited, restore the separator '1' between HRP and data.","Detect format before decoding and route Base58 to a Base58 decoder.","Check str.includes('1') before calling decode and give a clear error."],"exampleFix":"// before - legacy Base58 address has no Bech32 separator\ndecode(base58Address);\n\n// after - route by format\nif (base58Address.startsWith('bc1') || base58Address.includes('1') /* bech32-ish */) {\n  decode(base58Address);\n} else {\n  decodeBase58(base58Address); // legacy path\n}","handlingStrategy":"validation","validationCode":"function looksLikeBech32(str) {\n  return typeof str === 'string' && str.lastIndexOf('1') !== -1;\n}\n// if (!looksLikeBech32(input)) route to a Base58 decoder","typeGuard":"function hasBech32Separator(s) {\n  return typeof s === 'string' && s.includes('1');\n}","tryCatchPattern":"try {\n  decode(input);\n} catch (e) {\n  if (e instanceof OperationError && /no separator '1' found/.test(e.message)) {\n    // input is probably not Bech32; try legacy Base58\n  }\n}","preventionTips":["Detect address format before choosing a decoder.","Bech32 native SegWit addresses start with a known HRP + '1' (e.g. 'bc1').","Do not feed legacy Base58 addresses into the Bech32 decoder."],"tags":["bech32","decoding","separator","format-detection","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}