# Path: lib/bitcoin.py
# DUST_THRESHOLD = 0
# DUST_SOFT_LIMIT = 100000
# MIN_RELAY_TX_FEE = 100000
# RECOMMENDED_FEE = 100000
# COINBASE_MATURITY = 100
#     ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z')
#         G = curve.generator
#         R = Point(curveFp, x, y, order)
#         Q = inv_r * ( s * R + minus_e * G )
# BIP32_PRIME = 0x80000000
#     K = public_key.to_string()
#     I = hmac.new(c, data, hashlib.sha512).digest()
#     I = hmac.new(c, cK + s, hashlib.sha512).digest()
# BITCOIN_HEADER_PRIV = "0488ade4"
# BITCOIN_HEADER_PUB = "0488b21e"
# TESTNET_HEADER_PRIV = "04358394"
# TESTNET_HEADER_PUB = "043587cf"
# BITCOIN_HEADERS = (BITCOIN_HEADER_PUB, BITCOIN_HEADER_PRIV)
# TESTNET_HEADERS = (TESTNET_HEADER_PUB, TESTNET_HEADER_PRIV)
#     I = hmac.new("Bitcoin seed", seed, hashlib.sha512).digest()
# def strip_PKCS7_padding(s):
# def aes_encrypt_with_iv(key, iv, data):
# def aes_decrypt_with_iv(key, iv, data):
# def pw_encode(s, password):
# def pw_decode(s, password):
# def rev_hex(s):
# def int_to_hex(i, length=1):
# def var_int(i):
# def op_push(i):
# def sha256(x):
# def Hash(x):
# def is_new_seed(x, prefix=version.SEED_BIP44):
# def is_old_seed(seed):
# def i2d_ECPrivateKey(pkey, compressed=False):
# def i2o_ECPublicKey(pubkey, compressed=False):
# def hash_160(public_key):
# def public_key_to_bc_address(public_key):
# def hash_160_to_bc_address(h160, addrtype = 50):
# def bc_address_to_hash_160(addr):
# def b58encode(v):
# def b58decode(v, length):
# def EncodeBase58Check(vchIn):
# def DecodeBase58Check(psz):
# def PrivKeyToSecret(privkey):
# def SecretToASecret(secret, compressed=False, addrtype=50):
# def ASecretToSecret(key, addrtype=50):
# def regenerate_key(sec):
# def GetPubKey(pubkey, compressed=False):
# def GetPrivKey(pkey, compressed=False):
# def GetSecret(pkey):
# def is_compressed(sec):
# def public_key_from_private_key(sec):
# def address_from_private_key(sec):
# def is_valid(addr):
# def is_address(addr):
# def is_private_key(key):
# def msg_magic(message):
# def verify_message(address, signature, message):
# def encrypt_message(message, pubkey):
# def chunks(l, n):
# def ECC_YfromX(x,curved=curve_secp256k1, odd=True):
# def negative_point(P):
# def point_to_ser(P, comp=True ):
# def ser_to_point(Aser):
#     def from_signature(klass, sig, recid, h, curve):
#     def __init__( self, k ):
#     def get_public_key(self, compressed=True):
#     def sign_message(self, message, compressed, address):
#     def verify_message(self, address, signature, message):
#     def encrypt_message(self, message, pubkey):
#     def decrypt_message(self, encrypted):
# def get_pubkeys_from_secret(secret):
# def CKD_priv(k, c, n):
# def _CKD_priv(k, c, s, is_prime):
# def CKD_pub(cK, c, n):
# def _CKD_pub(cK, c, s):
# def _get_headers(testnet):
# def deserialize_xkey(xkey):
# def get_xkey_name(xkey, testnet=False):
# def xpub_from_xprv(xprv, testnet=False):
# def bip32_root(seed, testnet=False):
# def bip32_private_derivation(xprv, branch, sequence, testnet=False):
# def bip32_public_derivation(xpub, branch, sequence, testnet=False):
# def bip32_private_key(sequence, k, chain):
# class MyVerifyingKey(ecdsa.VerifyingKey):
# class EC_KEY(object):


import unittest
import sys
    import ecdsa
from ecdsa.util import number_to_string
from lib.bitcoin import (
    generator_secp256k1, point_to_ser, public_key_to_bc_address, EC_KEY,
    bip32_root, bip32_public_derivation, bip32_private_derivation, pw_encode,
    pw_decode, Hash, public_key_from_private_key, address_from_private_key,
    is_valid, is_private_key, xpub_from_xprv)


try:
except ImportError:
    sys.exit("Error: python-ecdsa does not seem to be installed. Try 'sudo pip install ecdsa'")


class Test_bitcoin(unittest.TestCase):

    def test_crypto(self):
        for message in ["Chancellor on brink of second bailout for banks", chr(255)*512]:
            self._do_test_crypto(message)

    def _do_test_crypto(self, message):
        G = generator_secp256k1
        _r  = G.order()
        pvk = ecdsa.util.randrange( pow(2,256) ) %_r

        Pub = pvk*G
        pubkey_c = point_to_ser(Pub,True)
        #pubkey_u = point_to_ser(Pub,False)

# Path: lib/bitcoin.py
# DUST_THRESHOLD = 0
# DUST_SOFT_LIMIT = 100000
# MIN_RELAY_TX_FEE = 100000
# RECOMMENDED_FEE = 100000
# COINBASE_MATURITY = 100
#     ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z')
#         G = curve.generator
#         R = Point(curveFp, x, y, order)
#         Q = inv_r * ( s * R + minus_e * G )
# BIP32_PRIME = 0x80000000
#     K = public_key.to_string()
#     I = hmac.new(c, data, hashlib.sha512).digest()
#     I = hmac.new(c, cK + s, hashlib.sha512).digest()
# BITCOIN_HEADER_PRIV = "0488ade4"
# BITCOIN_HEADER_PUB = "0488b21e"
# TESTNET_HEADER_PRIV = "04358394"
# TESTNET_HEADER_PUB = "043587cf"
# BITCOIN_HEADERS = (BITCOIN_HEADER_PUB, BITCOIN_HEADER_PRIV)
# TESTNET_HEADERS = (TESTNET_HEADER_PUB, TESTNET_HEADER_PRIV)
#     I = hmac.new("Bitcoin seed", seed, hashlib.sha512).digest()
# def strip_PKCS7_padding(s):
# def aes_encrypt_with_iv(key, iv, data):
# def aes_decrypt_with_iv(key, iv, data):
# def pw_encode(s, password):
# def pw_decode(s, password):
# def rev_hex(s):
# def int_to_hex(i, length=1):
# def var_int(i):
# def op_push(i):
# def sha256(x):
# def Hash(x):
# def is_new_seed(x, prefix=version.SEED_BIP44):
# def is_old_seed(seed):
# def i2d_ECPrivateKey(pkey, compressed=False):
# def i2o_ECPublicKey(pubkey, compressed=False):
# def hash_160(public_key):
# def public_key_to_bc_address(public_key):
# def hash_160_to_bc_address(h160, addrtype = 50):
# def bc_address_to_hash_160(addr):
# def b58encode(v):
# def b58decode(v, length):
# def EncodeBase58Check(vchIn):
# def DecodeBase58Check(psz):
# def PrivKeyToSecret(privkey):
# def SecretToASecret(secret, compressed=False, addrtype=50):
# def ASecretToSecret(key, addrtype=50):
# def regenerate_key(sec):
# def GetPubKey(pubkey, compressed=False):
# def GetPrivKey(pkey, compressed=False):
# def GetSecret(pkey):
# def is_compressed(sec):
# def public_key_from_private_key(sec):
# def address_from_private_key(sec):
# def is_valid(addr):
# def is_address(addr):
# def is_private_key(key):
# def msg_magic(message):
# def verify_message(address, signature, message):
# def encrypt_message(message, pubkey):
# def chunks(l, n):
# def ECC_YfromX(x,curved=curve_secp256k1, odd=True):
# def negative_point(P):
# def point_to_ser(P, comp=True ):
# def ser_to_point(Aser):
#     def from_signature(klass, sig, recid, h, curve):
#     def __init__( self, k ):
#     def get_public_key(self, compressed=True):
#     def sign_message(self, message, compressed, address):
#     def verify_message(self, address, signature, message):
#     def encrypt_message(self, message, pubkey):
#     def decrypt_message(self, encrypted):
# def get_pubkeys_from_secret(secret):
# def CKD_priv(k, c, n):
# def _CKD_priv(k, c, s, is_prime):
# def CKD_pub(cK, c, n):
# def _CKD_pub(cK, c, s):
# def _get_headers(testnet):
# def deserialize_xkey(xkey):
# def get_xkey_name(xkey, testnet=False):
# def xpub_from_xprv(xprv, testnet=False):
# def bip32_root(seed, testnet=False):
# def bip32_private_derivation(xprv, branch, sequence, testnet=False):
# def bip32_public_derivation(xpub, branch, sequence, testnet=False):
# def bip32_private_key(sequence, k, chain):
# class MyVerifyingKey(ecdsa.VerifyingKey):
# class EC_KEY(object):


# Path: lib/tests/test_bitcoin.py
import unittest
import sys
    import ecdsa
from ecdsa.util import number_to_string
from lib.bitcoin import (
    generator_secp256k1, point_to_ser, public_key_to_bc_address, EC_KEY,
    bip32_root, bip32_public_derivation, bip32_private_derivation, pw_encode,
    pw_decode, Hash, public_key_from_private_key, address_from_private_key,
    is_valid, is_private_key, xpub_from_xprv)



try:
except ImportError:
    sys.exit("Error: python-ecdsa does not seem to be installed. Try 'sudo pip install ecdsa'")


class Test_bitcoin(unittest.TestCase):

    def test_crypto(self):
        for message in ["Chancellor on brink of second bailout for banks", chr(255)*512]:
            self._do_test_crypto(message)

    def _do_test_crypto(self, message):
        G = generator_secp256k1
        _r  = G.order()
        pvk = ecdsa.util.randrange( pow(2,256) ) %_r

        Pub = pvk*G
        pubkey_c = point_to_ser(Pub,True)
        #pubkey_u = point_to_ser(Pub,False)

        addr_c = public_key_to_bc_address(pubkey_c)