Exemple #1
0
def get_xpub_unspent_addrs(*args):
    """Takes bip32 xpub (or xprv) and returns addresses with balance"""
    from bitcoin.main import multiaccess, pubtoaddr
    from bitcoin.deterministic import bip32_descend, bip32_ckd, bip32_privtopub
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    data = {"addr": " ".join(xpubs)}
    jdata = json.loads(
        make_request("https://www.blockonomics.co/api/balance",
                     json.dumps(data)))
    jdata = jdata.get("response")
    addrs, values = multiaccess(jdata, "addr"), multiaccess(jdata, "confirmed")
    d = dict.fromkeys(xpubs, {})
    for xpub in xpubs:
        c, i = 0, 0
        while c <= 1:
            addr = pubtoaddr(bip32_descend(bip32_ckd(xpub, c), i))
            if addr in addrs:
                d[xpub].update({
                    "m/%d/%d" % (c, i):
                    "%s:%d" % (addr, values[addrs.index(addr)])
                })
            else:
                c += 1
            i += 1
    return d.values()[0] if len(d) == 1 else d
 def __init__(self, network, bargain_uri = ''):
     '''
     Constructor
     '''
     self.bargain_uri    = bargain_uri
     magicbytes          = MAGIC_BYTES_TESTNET if network == TESTNET else MAGIC_BYTES_MAINNET
     
     self._privkey1    = sha256('This is a private key')
     self._pubkey1     = privtopub(self._privkey1)  
     self.addr1        = pubtoaddr(self._pubkey1, magicbytes)  # mryyjA6YpPCJ24MsSN7YnCK6M3NZoUAwxb
     self._script1     = address_to_script(self.addr1) 
     
     self._privkeysign = sha256('This is a private key used to sign messages sent by the buyer')
     self._pubkeysign  = privtopub(self._privkeysign)  
Exemple #3
0
def get_xpub_unspent_addrs(*args):
    """Takes bip32 xpub (or xprv) and returns addresses with balance"""
    from bitcoin.main import multiaccess, pubtoaddr
    from bitcoin.deterministic import bip32_descend, bip32_ckd, bip32_privtopub
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    data = {"addr": " ".join(xpubs)}
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", json.dumps(data)))
    jdata = jdata.get("response")
    addrs, values = multiaccess(jdata,"addr"), multiaccess(jdata,"confirmed")
    d = dict.fromkeys(xpubs, {})
    for xpub in xpubs:
        c, i = 0, 0
        while c <= 1:
            addr = pubtoaddr(bip32_descend(bip32_ckd(xpub, c), i))
            if addr in addrs:
                d[xpub].update({
                                "m/%d/%d" % (c, i): "%s:%d" % (addr, values[addrs.index(addr)])
                                })
            else:
                c += 1
            i += 1
    return d.values()[0] if len(d) ==1 else d
Exemple #4
0
def mk_privpubaddr(privkey, compressed=False, magicbyte=0):
    global priv, pub, addr
    priv = encode_privkey(decode_privkey(privkey), 'hex')
    pub = privtopub(compress(priv)) if compressed else privtopub(priv)
    addr = pubtoaddr(pub, int(magicbyte))
Exemple #5
0
        return is_txobj(txobj[0]) if isinstance(txobj[0], dict) else False
    return set(['locktime', 'version']).issubset(set(txobj.keys()))

def is_tx(txobj):
    if isinstance(txobj, dict):
        return is_txobj(txobj)
    elif isinstance(txobj, string_types):
        return is_txhex(txobj)

#SIG64="G8kH/WEgiATGXSy78yToe36IF9AUlluY3bMdkDFD1XyyDciIbXkfiZxk/qmjGdMeP6/BQJ/C5U/pbQUZv1HGkn8="

tpriv = hashlib.sha256(b"mrbubby"*3+b"!").hexdigest()
tpub = privtopub(tpriv)
taddr = privtoaddr(tpriv, 111)
#tpkh = pkh = mk_pubkey_script(addr)[6:-4]

masterpriv = hashlib.sha256(b"master"*42).hexdigest()
masterpub = compress(privtopub(masterpriv))
masteraddr = pubtoaddr(masterpub, 111)

# ops = [OPname['IF'], masterpub, OPname['CHECKSIGVERIFY'], OPname['ELSE'], '80bf07', #binascii.hexlify(from_int_to_le_bytes(507776)), # '80bf07' OPname['NOP2'], OPname['DROP'], OPname['ENDIF'], tpub, OPname['CHECKSIG']]


#wif_re = re.compile(r"[1-9a-km-zA-LMNP-Z]{51,111}")


PK = "3081d30201010420{0:064x}a081a53081a2020101302c06072a8648ce3d0101022100" \
     "{1:064x}3006040100040107042102{2:064x}022100{3:064x}020101a124032200"
#PK.strip().format(rki, P, Gx, N)+ compress(privtopub(rk))
# https://gist.github.com/simcity4242/b0bb0f0281fcf58deec2
Exemple #6
0
def mk_privpubaddr(privkey, compressed=False, magicbyte=0):
    global priv, pub, addr
    priv = encode_privkey(decode_privkey(privkey), 'hex')
    pub = privtopub(compress(priv)) if compressed else privtopub(priv)
    addr = pubtoaddr(pub, int(magicbyte))
    return priv, pub, addr
Exemple #7
0
    elif isinstance(txobj, string_types):
        return is_txhex(txobj)
    else:
        return False

sig64="G8kH/WEgiATGXSy78yToe36IF9AUlluY3bMdkDFD1XyyDciIbXkfiZxk/qmjGdMeP6/BQJ/C5U/pbQUZv1HGkn8="

#tpriv = hashlib.sha256(b"mrbubby"*3+b"!").hexdigest()
#tpriv2 = tpriv+"01"
#tpub, tpub2 = privtopub(tpriv), privtopub(tpriv2)
#taddr, taddr2 = privtoaddr(tpriv, 111), privtoaddr(tpriv2, 111)
#tpkh = pkh = mk_pubkey_script(addr)[6:-4]

masterpriv = hashlib.sha256(b"master"*42).hexdigest()
masterpub = compress(privtopub(masterpriv))
masteraddr = pubtoaddr(masterpub, 111)

# ops = [OPname['IF'], masterpub, OPname['CHECKSIGVERIFY'], OPname['ELSE'], '80bf07', #binascii.hexlify(from_int_to_le_bytes(507776)), # '80bf07' OPname['NOP2'], OPname['DROP'], OPname['ENDIF'], tpub, OPname['CHECKSIG']]


#wif_re = re.compile(r"[1-9a-km-zA-LMNP-Z]{51,111}")


PK = "3081d30201010420{0:064x}a081a53081a2020101302c06072a8648ce3d0101022100" \
     "{1:064x}3006040100040107042102{2:064x}022100{3:064x}020101a124032200"
#PK.strip().format(rki, P, Gx, N)+ compress(privtopub(rk))
# https://gist.github.com/simcity4242/b0bb0f0281fcf58deec2


def little_endian_varint(integer):
    """Convert an integer to the Bitcoin variable length integer.
# -*- coding: utf-8 -*-
'''
Version: 0.0.1
Python library for the bargaining protocol
'''
import json
from bitcoin import address_to_script
from bitcoin.main import sha256, privtopub, pubtoaddr
from pybargain_protocol.constants import MAGIC_BYTES_TESTNET

'''
TEST VALUES
'''
TEST_PRIV1          = sha256('This is a private key')       
TEST_PUB1           = privtopub(TEST_PRIV1)                 
TEST_ADDR1          = pubtoaddr(TEST_PUB1, MAGIC_BYTES_TESTNET) # mryyjA6YpPCJ24MsSN7YnCK6M3NZoUAwxb

TEST_PRIV2          = sha256('This is another private key')
TEST_PUB2           = privtopub(TEST_PRIV2)
TEST_ADDR2          = pubtoaddr(TEST_PUB2, MAGIC_BYTES_TESTNET) # mftfwza9ZBwQRF2VW3YLuBhe8AkR2c2vrL

VALID_TIME1         = 1400100000L
VALID_TIME2         = 1400200000L
VALID_TIME3         = 1400300000L
VALID_TIME4         = 1400400000L
VALID_TIME5         = 1400500000L
VALID_TIME6         = 1400600000L
VALID_EXPIRES1      = 1401100000L
VALID_EXPIRES2      = 1401200000L

VALID_MEMO          = 'Ceci est le contenu d\'un memo.'