INNER CODE UNIT · Python

zeros

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

    zeros = len(text) - len(text.lstrip(BASE58_ALPHABET[0]))
    return bytes(zeros) + number.to_bytes((number.bit_length() + 7) // 8, "big")


def base58check_decode(text: str) -> Optional[bytes]:
    """The payload of Base58Check text, or None if its checksum is wrong."""
    try:
        decoded = base58_decode(text)
    except ValueError:
        return None
    if len(decoded) < 4:
        return None
    payload, checksum = decoded[:-4], decoded[-4:]
    if hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] != checksum:
        return None
    return payload

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…