INNER CODE UNIT · Python

is_bitcoin_address

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

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)
    return payload is not None and len(payload) == 21 and payload[0] in BASE58_VERSIONS

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…