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)  
Ejemplo n.º 2
0
def uncover_pay_pubkey_receiver(scan_privkey, spend_pubkey, ephem_pubkey):
    shared_secret = shared_secret_receiver(ephem_pubkey, scan_privkey)
    return main.add_pubkeys(spend_pubkey, main.privtopub(shared_secret))
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
    if not isinstance(txobj, dict):
        return False
    elif isinstance(txobj, list) and len(txobj) == 1:
        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"
Ejemplo n.º 5
0
def uncover_pay_pubkey_receiver(scan_privkey, spend_pubkey, ephem_pubkey):
    shared_secret = shared_secret_receiver(ephem_pubkey, scan_privkey)
    return main.add_pubkeys(spend_pubkey, main.privtopub(shared_secret))
Ejemplo n.º 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
Ejemplo n.º 7
0
        return is_txobj(txobj)
    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):
Ejemplo n.º 8
0
    # Return the solution hash as hex.
    return solution_hash


# Generate message hashes.
m1 = b"test1"
m2 = b"test2"
hm1 = hash_as_int("sha3", m1)
hm2 = hash_as_int("sha3", m2)

# Generate a key that can be retrieved.
generated = False
while generated == False:
    # Generate key pairs.
    priv_key = get_priv_key()
    pub_key = int(privtopub(priv_key).encode('hex'), 16)

    # Get sig components.
    v1, r1, s1 = insecure_ecdsa_sign(unhexlify(int_to_hex_str(hm1)), priv_key)
    v2, r2, s2 = insecure_ecdsa_sign(unhexlify(int_to_hex_str(hm2)), priv_key)

    # They should be equal for easy recovery.
    if v1 != v2:
        continue

    # Duplicate R is required for attack.
    if r1 != r2:
        raise Exception("Could not generate duplicate R values.")

    # Sig should be over unique messages.
    if s1 == s2:
Ejemplo n.º 9
0
#!/usr/bin/env python
# -*- 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
Ejemplo n.º 10
0
    if indexUTXO > 0 and indexUTXO <= len(listUTXOs):
        break
    else:
        print("Index is invalid!")

print("\n")

theUTXO = listUTXOs[indexUTXO - 1]

#
# Create a new address for the change
#

changeAddress = rpc.getnewaddress()
privKeyChangeAddress = rpc.dumpprivkey(changeAddress)
pubKeyChangeAddress = vitalik.privtopub(privKeyChangeAddress)
hashPubKeyChangeAddress = vitalik.hash160(pubKeyChangeAddress)
# will result in a legacy address

#
# fee
#

# length of our transaction with 1 input and 2 outputs including one OP_RETURN is around 200 bytes + the message if the input is compressed, around 230 bytes + the message if the input is not compressed. We pessimistically choose 230 bytes and add the size of the message (80 bytes max). There is no need to be more precise here, as the fee / byte is anyway an estimation.
sizeTX = 230 + lengthMsg  # bytes

# estimation of fee as sat/B
feePerByte = rpc._call(
    "estimatesmartfee", 2
)  # second parameter is the number of blocks we are ok to wait. We choose 2. The result from estimatesmartfee is in BTC/kB