# Path: reversecoin/bitcoin/key.py
# class CKey:
#     def __init__(self):
#         self.POINT_CONVERSION_COMPRESSED = 2
#         self.POINT_CONVERSION_UNCOMPRESSED = 4
#         self.k = ssl.EC_KEY_new_by_curve_name(NID_secp256k1)
# 
#     def __del__(self):
#         if ssl:
#             ssl.EC_KEY_free(self.k)
#         self.k = None
# 
#     def generate(self, secret=None):
#         if secret:
#             self.prikey = secret
#             priv_key = ssl.BN_bin2bn(secret, 32, ssl.BN_new())
#             group = ssl.EC_KEY_get0_group(self.k)
#             pub_key = ssl.EC_POINT_new(group)
#             ctx = ssl.BN_CTX_new()
#             if not ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx):
#                 raise ValueError("Could not derive public key from the supplied secret.")
#             ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx)
#             ssl.EC_KEY_set_private_key(self.k, priv_key)
#             ssl.EC_KEY_set_public_key(self.k, pub_key)
#             ssl.EC_POINT_free(pub_key)
#             ssl.BN_CTX_free(ctx)
#             return self.k
#         else:
#             return ssl.EC_KEY_generate_key(self.k)
# 
#     def set_privkey(self, key):
#         self.mb = ctypes.create_string_buffer(key)
#         ssl.d2i_ECPrivateKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key))
# 
#     def set_pubkey(self, key):
#         self.mb = ctypes.create_string_buffer(key)
#         ssl.o2i_ECPublicKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key))
# 
#     def get_privkey(self):
#         size = ssl.i2d_ECPrivateKey(self.k, 0)
#         mb_pri = ctypes.create_string_buffer(size)
#         ssl.i2d_ECPrivateKey(self.k, ctypes.byref(ctypes.pointer(mb_pri)))
#         return mb_pri.raw
# 
#     def get_pubkey(self):
#         size = ssl.i2o_ECPublicKey(self.k, 0)
#         mb = ctypes.create_string_buffer(size)
#         ssl.i2o_ECPublicKey(self.k, ctypes.byref(ctypes.pointer(mb)))
#         return mb.raw
#         
#     def sign(self, hash):
#         sig_size0 = ctypes.c_uint32()
#         sig_size0.value = ssl.ECDSA_size(self.k)
#         mb_sig = ctypes.create_string_buffer(sig_size0.value)
#         result = ssl.ECDSA_sign(0, hash, len(hash), mb_sig, ctypes.byref(sig_size0), self.k)
#         assert 1 == result
#         return mb_sig.raw[:sig_size0.value]
# 
#     def verify(self, hash, sig):
#         return ssl.ECDSA_verify(0, hash, len(hash), sig, len(sig), self.k) == 1
# 
#     def set_compressed(self, compressed):
#         if compressed:
#             form = self.POINT_CONVERSION_COMPRESSED
#         else:
#             form = self.POINT_CONVERSION_UNCOMPRESSED
#         ssl.EC_KEY_set_conv_form(self.k, form)
# 
# Path: reversecoin/bitcoin/base58.py
# def encode(b):
#     """Encode bytes to a base58-encoded string"""
# 
#     # Convert big-endian bytes to integer
#     n = int('0x0' + hexlify(b).decode('utf8'), 16)
# 
#     # Divide that integer into bas58
#     res = []
#     while n > 0:
#         n, r = divmod (n, 58)
#         res.append(b58_digits[r])
#     res = ''.join(res[::-1])
# 
#     # Encode leading zeros as base58 zeros
#     import sys
#     czero = b'\x00'
#     if sys.version > '3':
#         # In Python3 indexing a bytes returns numbers, not characters.
#         czero = 0
#     pad = 0
#     for c in b:
#         if c == czero: pad += 1
#         else: break
#     return b58_digits[0] * pad + res
# 
# def decode(s):
#     """Decode a base58-encoding string, returning bytes"""
#     if not s:
#         return b''
# 
#     # Convert the string to an integer
#     n = 0
#     for c in s:
#         n *= 58
#         if c not in b58_digits:
#             raise InvalidBase58Error('Character %r is not a valid base58 character' % c)
#         digit = b58_digits.index(c)
#         n += digit
# 
#     # Convert the integer to bytes
#     h = '%x' % n
#     if len(h) % 2:
#         h = '0' + h
#     res = unhexlify(h.encode('utf8'))
# 
#     # Add padding back.
#     pad = 0
#     for c in s[:-1]:
#         if c == b58_digits[0]: pad += 1
#         else: break
#     return b'\x00' * pad + res


import binascii
import hashlib
from reversecoin.bitcoin.key import CKey as Key
from reversecoin.bitcoin.base58 import encode, decode
#!/usr/bin/env python


def myhash(s):
    return hashlib.sha256(hashlib.sha256(s).digest()).digest()

def myhash160(s):
    h = hashlib.new('ripemd160')
    h.update(hashlib.sha256(s).digest())
    return h.digest()

def getnewaddress():
    # Generate public and private keys
    key = Key()

# Path: reversecoin/bitcoin/key.py
# class CKey:
#     def __init__(self):
#         self.POINT_CONVERSION_COMPRESSED = 2
#         self.POINT_CONVERSION_UNCOMPRESSED = 4
#         self.k = ssl.EC_KEY_new_by_curve_name(NID_secp256k1)
# 
#     def __del__(self):
#         if ssl:
#             ssl.EC_KEY_free(self.k)
#         self.k = None
# 
#     def generate(self, secret=None):
#         if secret:
#             self.prikey = secret
#             priv_key = ssl.BN_bin2bn(secret, 32, ssl.BN_new())
#             group = ssl.EC_KEY_get0_group(self.k)
#             pub_key = ssl.EC_POINT_new(group)
#             ctx = ssl.BN_CTX_new()
#             if not ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx):
#                 raise ValueError("Could not derive public key from the supplied secret.")
#             ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx)
#             ssl.EC_KEY_set_private_key(self.k, priv_key)
#             ssl.EC_KEY_set_public_key(self.k, pub_key)
#             ssl.EC_POINT_free(pub_key)
#             ssl.BN_CTX_free(ctx)
#             return self.k
#         else:
#             return ssl.EC_KEY_generate_key(self.k)
# 
#     def set_privkey(self, key):
#         self.mb = ctypes.create_string_buffer(key)
#         ssl.d2i_ECPrivateKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key))
# 
#     def set_pubkey(self, key):
#         self.mb = ctypes.create_string_buffer(key)
#         ssl.o2i_ECPublicKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key))
# 
#     def get_privkey(self):
#         size = ssl.i2d_ECPrivateKey(self.k, 0)
#         mb_pri = ctypes.create_string_buffer(size)
#         ssl.i2d_ECPrivateKey(self.k, ctypes.byref(ctypes.pointer(mb_pri)))
#         return mb_pri.raw
# 
#     def get_pubkey(self):
#         size = ssl.i2o_ECPublicKey(self.k, 0)
#         mb = ctypes.create_string_buffer(size)
#         ssl.i2o_ECPublicKey(self.k, ctypes.byref(ctypes.pointer(mb)))
#         return mb.raw
#         
#     def sign(self, hash):
#         sig_size0 = ctypes.c_uint32()
#         sig_size0.value = ssl.ECDSA_size(self.k)
#         mb_sig = ctypes.create_string_buffer(sig_size0.value)
#         result = ssl.ECDSA_sign(0, hash, len(hash), mb_sig, ctypes.byref(sig_size0), self.k)
#         assert 1 == result
#         return mb_sig.raw[:sig_size0.value]
# 
#     def verify(self, hash, sig):
#         return ssl.ECDSA_verify(0, hash, len(hash), sig, len(sig), self.k) == 1
# 
#     def set_compressed(self, compressed):
#         if compressed:
#             form = self.POINT_CONVERSION_COMPRESSED
#         else:
#             form = self.POINT_CONVERSION_UNCOMPRESSED
#         ssl.EC_KEY_set_conv_form(self.k, form)
# 
# Path: reversecoin/bitcoin/base58.py
# def encode(b):
#     """Encode bytes to a base58-encoded string"""
# 
#     # Convert big-endian bytes to integer
#     n = int('0x0' + hexlify(b).decode('utf8'), 16)
# 
#     # Divide that integer into bas58
#     res = []
#     while n > 0:
#         n, r = divmod (n, 58)
#         res.append(b58_digits[r])
#     res = ''.join(res[::-1])
# 
#     # Encode leading zeros as base58 zeros
#     import sys
#     czero = b'\x00'
#     if sys.version > '3':
#         # In Python3 indexing a bytes returns numbers, not characters.
#         czero = 0
#     pad = 0
#     for c in b:
#         if c == czero: pad += 1
#         else: break
#     return b58_digits[0] * pad + res
# 
# def decode(s):
#     """Decode a base58-encoding string, returning bytes"""
#     if not s:
#         return b''
# 
#     # Convert the string to an integer
#     n = 0
#     for c in s:
#         n *= 58
#         if c not in b58_digits:
#             raise InvalidBase58Error('Character %r is not a valid base58 character' % c)
#         digit = b58_digits.index(c)
#         n += digit
# 
#     # Convert the integer to bytes
#     h = '%x' % n
#     if len(h) % 2:
#         h = '0' + h
#     res = unhexlify(h.encode('utf8'))
# 
#     # Add padding back.
#     pad = 0
#     for c in s[:-1]:
#         if c == b58_digits[0]: pad += 1
#         else: break
#     return b'\x00' * pad + res


# Path: reversecoin/bitcoin/utils.py
import binascii
import hashlib
from reversecoin.bitcoin.key import CKey as Key
from reversecoin.bitcoin.base58 import encode, decode

#!/usr/bin/env python


def myhash(s):
    return hashlib.sha256(hashlib.sha256(s).digest()).digest()

def myhash160(s):
    h = hashlib.new('ripemd160')
    h.update(hashlib.sha256(s).digest())
    return h.digest()

def getnewaddress():
    # Generate public and private keys
    key = Key()

    key.generate()