# Path: reversecoin/bitcoin/serialize.py
# def Hash(s):
#     return uint256_from_str(hashlib.sha256(hashlib.sha256(s).digest()).digest())
# 
# def ser_uint256(u):
#     rs = b""
#     for i in range(8):
#         rs += struct.pack(b"<I", u & 0xFFFFFFFF)
#         u >>= 32
#     return rs


from reversecoin.bitcoin.serialize import Hash, ser_uint256
from binascii import hexlify, unhexlify
    import sys

    # Add padding back.
    pad = 0
    for c in s[:-1]:
        if c == b58_digits[0]: pad += 1
        else: break
    return b'\x00' * pad + res


class Base58ChecksumError(Base58Error):
    pass

class CBase58Data(bytes):
    def __new__(cls, data, nVersion):
        self = super(CBase58Data, cls).__new__(cls, data)
        self.nVersion = nVersion
        return self

    def __repr__(self):
        return '%s(%s, %d)' % (self.__class__.__name__, bytes.__repr__(self), self.nVersion)

    def __str__(self):
        vs = chr(self.nVersion) + self
        check = ser_uint256(Hash(vs))[0:4]
        return encode(vs + check)

    @classmethod
    def from_str(cls, s):
        k = decode(s)
        addrbyte, data, check0 = k[0], k[1:-4], k[-4:]

# Path: reversecoin/bitcoin/serialize.py
# def Hash(s):
#     return uint256_from_str(hashlib.sha256(hashlib.sha256(s).digest()).digest())
# 
# def ser_uint256(u):
#     rs = b""
#     for i in range(8):
#         rs += struct.pack(b"<I", u & 0xFFFFFFFF)
#         u >>= 32
#     return rs


# Path: reversecoin/bitcoin/base58.py
from reversecoin.bitcoin.serialize import Hash, ser_uint256
from binascii import hexlify, unhexlify
    import sys


    # Add padding back.
    pad = 0
    for c in s[:-1]:
        if c == b58_digits[0]: pad += 1
        else: break
    return b'\x00' * pad + res


class Base58ChecksumError(Base58Error):
    pass

class CBase58Data(bytes):
    def __new__(cls, data, nVersion):
        self = super(CBase58Data, cls).__new__(cls, data)
        self.nVersion = nVersion
        return self

    def __repr__(self):
        return '%s(%s, %d)' % (self.__class__.__name__, bytes.__repr__(self), self.nVersion)

    def __str__(self):
        vs = chr(self.nVersion) + self
        check = ser_uint256(Hash(vs))[0:4]
        return encode(vs + check)

    @classmethod
    def from_str(cls, s):
        k = decode(s)
        addrbyte, data, check0 = k[0], k[1:-4], k[-4:]

        check1 = ser_uint256(Hash(addrbyte + data))[:4]