{"record":{"id":"d0d6d732dfe49c63","repo":"bytedance/deer-flow","slug":"invalid-bech32-character-in-value-r","errorCode":null,"errorMessage":"invalid bech32 character in {value!r}","messagePattern":"invalid bech32 character in (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/app/channels/buzz_nostr.py","lineNumber":54,"sourceCode":"    chk = 1\n    for v in values:\n        b = chk >> 25\n        chk = (chk & 0x1FFFFFF) << 5 ^ v\n        for i in range(5):\n            chk ^= gen[i] if ((b >> i) & 1) else 0\n    return chk\n\n\ndef _bech32_decode(expected_hrp: str, value: str) -> bytes:\n    if \"1\" not in value:\n        raise ValueError(f\"not bech32: {value!r}\")\n    hrp, data_part = value.rsplit(\"1\", 1)\n    if hrp != expected_hrp:\n        raise ValueError(f\"expected {expected_hrp!r} bech32, got {hrp!r}\")\n    try:\n        data = [_BECH32_CHARSET.index(c) for c in data_part]\n    except ValueError as exc:\n        raise ValueError(f\"invalid bech32 character in {value!r}\") from exc\n    hrp_expanded = [ord(c) >> 5 for c in hrp] + [0] + [ord(c) & 31 for c in hrp]\n    if _bech32_polymod(hrp_expanded + data) != 1:\n        raise ValueError(f\"bad bech32 checksum in {value!r}\")\n    acc = bits = 0\n    out = bytearray()\n    for v in data[:-6]:\n        acc = (acc << 5) | v\n        bits += 5\n        if bits >= 8:\n            bits -= 8\n            out.append((acc >> bits) & 0xFF)\n    if len(out) != 32:\n        raise ValueError(f\"expected 32-byte payload in {value!r}\")\n    return bytes(out)\n\n\ndef _parse_32_bytes(value: str, bech_hrp: str) -> bytes:\n    value = value.strip()","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/channels/buzz_nostr.py#L36-L72","documentation":"The bech32 data part must consist only of characters from the 32-character bech32 charset 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'. If any character after the separator is not in that set (e.g. 'b', 'i', 'o', digits like '1' inside data, uppercase mix issues aside), list.index raises ValueError and the decoder re-raises with this message.","triggerScenarios":"A corrupted or hand-edited key containing invalid characters — e.g. a base58 character ('b', 'i', 'o', '1') in the data part, or an HTML-escaped/truncated paste that introduced stray characters after the '1' separator.","commonSituations":"Key mangled by YAML quoting/escaping; terminal copy that swallowed characters and the user re-typed part of it; pasting a key with line-wrapping newlines embedded inside; OCR of a key.","solutions":["Re-copy the key carefully from the source; bech32 data parts exclude '1', 'b', 'i', 'o'.","Ensure the value in config.yaml is a single quoted string with no embedded newlines.","Validate the key in a Nostr client first — if the client also rejects it, the key itself is corrupted.","Prefer pasting the 64-hex-char form, which avoids bech32 entirely."],"exampleFix":"# before (contains invalid 'b' and a newline)\nprivate_key: \"nsec1abc\ndefb...\"\n\n# after (single line, valid charset)\nprivate_key: \"nsec1qpzry9x8gf2tvdw0s3jn54khce6mua7...\"","handlingStrategy":"validation","validationCode":"BECH32_CHARSET = set('qpzry9x8gf2tvdw0s3jn54khce6mua7l')\n\ndef charset_ok(value: str, hrp: str) -> bool:\n    data = value.strip().lower().rsplit('1', 1)[-1]\n    return bool(data) and all(c in BECH32_CHARSET for c in data)","typeGuard":null,"tryCatchPattern":"try:\n    _parse_32_bytes(value, 'nsec')\nexcept ValueError as e:\n    logger.warning('rejecting malformed buzz key (%s)', type(e).__name__)\n    raise","preventionTips":["Store keys as single-line quoted YAML strings to avoid newline injection.","Copy keys with a clipboard manager that preserves exact contents.","Run a preflight key check in deployment scripts before enabling the channel."],"tags":["buzz","nostr","bech32","validation"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}