INNER CODE UNIT · Python

program

bee-san/pyWhat · pywhat/bitcoin.py:119

    program = convert_bits(data[1:-6], 5, 8)
    if program is None or not 2 <= len(program) <= 40:
        return None
    if version == 0 and len(program) not in (20, 32):
        return None
    return hrp, version, bytes(program)


def is_bitcoin_address(address: str) -> bool:
    """
    Whether address is a Bitcoin address with a valid checksum: a P2PKH
    ("1...") or P2SH ("3...") address, or a SegWit address on mainnet
    ("bc1...") or testnet ("tb1...").
    """
    if address[:3].lower() in ("bc1", "tb1"):
        decoded = segwit_decode(address)
        return decoded is not None and decoded[0] in SEGWIT_HRPS
    payload = base58check_decode(address)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…