{"record":{"id":"28c5269ebffffd78","repo":"bytedance/deer-flow","slug":"expected-64-hex-or-bech-hrp-1-value","errorCode":null,"errorMessage":"expected 64-hex or {bech_hrp}1... value","messagePattern":"expected 64-hex or (.+?)1\\.\\.\\. value","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/app/channels/buzz_nostr.py","lineNumber":78,"sourceCode":"    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()\n    if value.lower().startswith(f\"{bech_hrp}1\"):\n        return _bech32_decode(bech_hrp, value.lower())\n    try:\n        raw = bytes.fromhex(value)\n    except ValueError as exc:\n        raise ValueError(f\"expected 64-hex or {bech_hrp}1... value\") from exc\n    if len(raw) != 32:\n        raise ValueError(\"expected exactly 32 bytes\")\n    return raw\n\n\ndef parse_private_key(value: str) -> NostrKeys:\n    secret = _parse_32_bytes(value, \"nsec\")\n    coincurve = _require_coincurve()\n    pubkey = coincurve.PrivateKey(secret).public_key.format(compressed=True)[1:]\n    return NostrKeys(secret=secret, pubkey_hex=pubkey.hex())\n\n\ndef parse_pubkey(value: str) -> str:\n    return _parse_32_bytes(value, \"npub\").hex()\n\n\ndef event_id(pubkey_hex: str, created_at: int, kind: int, tags: list[list[str]], content: str) -> str:\n    payload = json.dumps([0, pubkey_hex, created_at, kind, tags, content], separators=(\",\", \":\"), ensure_ascii=False)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/channels/buzz_nostr.py#L60-L96","documentation":"_parse_32_bytes accepts either a bech32 value (hrp + '1' + data) or a raw hex string. If the input does not start with the expected hrp prefix, it falls back to bytes.fromhex(); when that raises ValueError (non-hex characters, odd length, or an empty string), this error listing both accepted forms is raised.","triggerScenarios":"A value that is neither bech32 (does not start with nsec1/npub1) nor valid hex — e.g. a base64 key, a WIF string, a key with '0x' prefix, an empty string, or odd-length hex after paste truncation.","commonSituations":"Pasting a key exported in the wrong format (base64/WIF/0x-prefixed); empty config value reaching the parser; shell variable expansion mangling the key; using a key from a non-Nostr wallet.","solutions":["Provide the key as either nsec1/npub1 bech32 or plain 64-character hex (no 0x prefix).","Strip any '0x' prefix, quotes, or whitespace before pasting.","If your source wallet only exports other formats, convert it to hex first with a key-conversion tool."],"exampleFix":"# before\nprivate_key: \"0x4c0a5c...\"   # 0x prefix is not hex for this parser\n\n# after\nprivate_key: \"4c0a5c...\"       # exactly 64 hex chars","handlingStrategy":"validation","validationCode":"import re\n\ndef is_hex32(value: str) -> bool:\n    v = value.strip().removeprefix('0x')\n    return bool(re.fullmatch(r'[0-9a-fA-F]{64}', v))\n\ndef is_acceptable_key(value: str, hrp: str) -> bool:\n    return value.strip().lower().startswith(hrp + '1') or is_hex32(value)","typeGuard":null,"tryCatchPattern":"try:\n    _parse_32_bytes(value, 'npub')\nexcept ValueError as e:\n    if '64-hex' in str(e):\n        hint = 'expected nsec1/npub1 bech32 or 64-char hex (no 0x prefix)'\n        raise ConfigError(f'{e}: {hint}') from e\n    raise","preventionTips":["Strip 0x prefixes and quotes before writing keys into config.","Accept only the two documented formats in config validation.","Automate key provisioning instead of manual paste."],"tags":["buzz","nostr","validation","config"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}