# Path: pycoind/util/hash.py
# def sha256d(data):
#     return sha256(sha256(data))


from .hash import sha256d
    while long_value >= 256:
        (div, mod) = divmod(long_value, 256)
        result = chr(mod) + result
        long_value = div
    result = chr(long_value) + result

    nPad = 0
    for c in v:
        if c == __b58chars[0]:
            nPad += 1
        else:
            break

    result = chr(0) * nPad + result
    if length is not None and len(result) != length:
        return None

    return result


def encode_check(payload):
    'Returns the base58 encoding with a 4-byte checksum.'

    checksum = sha256d(payload)[:4]
    return b58encode(payload + checksum)


def decode_check(payload):
    'Returns the base58 decoded value, verifying the checksum.'
    payload = b58decode(payload, None)

# Path: pycoind/util/hash.py
# def sha256d(data):
#     return sha256(sha256(data))


# Path: pycoind/util/base58.py
from .hash import sha256d

    while long_value >= 256:
        (div, mod) = divmod(long_value, 256)
        result = chr(mod) + result
        long_value = div
    result = chr(long_value) + result

    nPad = 0
    for c in v:
        if c == __b58chars[0]:
            nPad += 1
        else:
            break

    result = chr(0) * nPad + result
    if length is not None and len(result) != length:
        return None

    return result


def encode_check(payload):
    'Returns the base58 encoding with a 4-byte checksum.'

    checksum = sha256d(payload)[:4]
    return b58encode(payload + checksum)


def decode_check(payload):
    'Returns the base58 decoded value, verifying the checksum.'
    payload = b58decode(payload, None)

    if payload and sha256d(payload[:-4])[:4] == payload[-4:]: