Esempio n. 1
0
#1 Calculate the SHA256 of 2 of 3 public key
data1 = '21026ccfb8061f235cc110697c0bfb3afb99d82c886672f6b9b5393b25a434c0cbf3'
data2 = '2103befa190c0c22e2f53720b1be9476dcf11917da4665c44c9c71c3a2d28a933c35'
data3 = '2102be46dc245f58085743b1cc37c82f0d63a960efa43b5336534275fc469b49f4ac'
data = '52' + data1 + data2 + data3 + '53' + 'ae'
data = hash256(data.decode('hex')).encode('hex')
#print data
#2 Create P2SH redeemScript as OP_PUSH publicKeyHash
redeemScript = '0020' + data

#3 Generate scriptPubKey as OP_HASH160 hash160(redeemScript) OP_EQUAL
data = hash160(redeemScript.decode('hex')).encode('hex')
print data
scriptPubKey = 'a914' + data + '87'

version = '05'  #mainnet
version = 'c4'  #testnet
data = version + data

#print EncodeBase58Check(data.decode('hex'))
#4 Generate address with 0x05 prefix and double SHA256 hash checksum(=4bytes)
checksum = dhash256(data.decode('hex'))
checksum = checksum.encode('hex')[0:8]
addressHash = data + checksum

#5 bash58encode
address = b58encode(addressHash.decode('hex'))
print address

#33voQqbNAYyig272KjcX8GkucWn2x25WEg
Esempio n. 2
0
__unit = 100000000
sig_hash_all = '01000000'
n_locktime = '00000000'

n_version = '02000000'
segwit_marker = '00'
segwit_flag = '01'

#txins
n_inputs = '01'
hash_inputs = '680d20d9ef5f2bd0cb09190a99dbefd9e1cb6e00054cc51588bc56a819b876e6'
hash_inputs = reverse_byte_order(hash_inputs)
nth_inputs = '00000000'
outpoint = hash_inputs + nth_inputs
#hash outpoint=prev_tx_id+nth
hashPrevouts = dhash256(outpoint.decode('hex')).encode('hex')

#sequence
sequence = 'ffffffff'
hashSequence = dhash256(sequence.decode('hex')).encode('hex')

#txouts
n_outputs = '01'
amount = 1.2997
amount_satoshi = long(round(float(amount * __unit)))
amount = formatamount(amount_satoshi)
#print output_amount
pay_to_hash = '1976a914' + 'ecebae831bbfbd7827542a82da4dc136e1288f71' + '88ac'
outputs = amount + pay_to_hash
#amount+dest_script
hashOutputs = dhash256(outputs.decode('hex')).encode('hex')
#!/usr/bin/python3.6

from hash_util import ripemd160, hash160, hash256, dhash256
from base58 import b58encode, b58encode_check, b58decode
import binascii

filepath = 'btc.txt'
with open(filepath) as fp:
    line = fp.readline()
    while line:
        #print(line.strip())
        address = line.strip()
        addressHash = b58decode(address)
        pubkeyHash = addressHash.hex()[2:42]

        data = pubkeyHash
        version = '26'
        #version='00'
        data = version + data

        checksum = dhash256(bytes.fromhex(data))
        checksum = checksum.hex()[0:8]
        addressHash = data + checksum

        address = b58encode(bytes.fromhex(addressHash))
        print(line.strip(), address.decode('utf-8'))
        line = fp.readline()
print "n_version   :", n_version
print "n_inputs    :", n_inputs
print "hash_inputs :", hash_inputs
print "nth_inputs  :", nth_inputs
print "scriptSig   :", scriptSig
print "sequence    :", sequence
print "n_outputs   :", n_outputs
print "amount      :", amount
print "scriptPubKey:", pay_to_hash
print "n_locktime  :", n_locktime
print "sig_hash_all:", sig_hash_all

signed_tx = n_version + n_inputs + hash_inputs + nth_inputs + scriptSig + sequence + n_outputs + amount + pay_to_hash + n_locktime + sig_hash_all
#print signed_tx
sk = SigningKey.from_string(binascii.unhexlify(priv_key), curve=SECP256k1)
sign_data_hash_d2 = dhash256(signed_tx.decode('hex'))
print reverse_byte_order(sign_data_hash_d2.encode('hex'))
signature = sk.sign_digest_deterministic(sign_data_hash_d2,
                                         hashfunc=hashlib.sha256,
                                         sigencode=sigencode_der_canonize)
#print signature.encode('hex')

signature = signature.encode('hex')
sig_hash_type = '01'
signature = signature + sig_hash_type

#print signature
p_len = (len(signature)) / 2
p_len = hex(p_len).lstrip('0x')
signature = p_len + signature
#print signature
Esempio n. 5
0
__unit = 100000000
sig_hash_all = '01000000'
n_locktime = '00000000'

n_version = '02000000'
segwit_marker = '00'
segwit_flag = '01'

#txins
n_inputs = '01'
hash_inputs = 'be6c81f1b184c242d8c70a051264d6281183a9cf603742490ce7f129c48f1465'
hash_inputs = reverse_byte_order(hash_inputs)
nth_inputs = '00000000'
outpoint = hash_inputs + nth_inputs
#hash outpoint=prev_tx_id+nth
hashPrevouts = dhash256(outpoint.decode('hex')).encode('hex')

#sequence
sequence = 'ffffffff'
hashSequence = dhash256(sequence.decode('hex')).encode('hex')

#txouts
n_outputs = '02'
amount = 0.0
amount_satoshi = long(round(float(amount * __unit)))
amount = formatamount(amount_satoshi)
#print output_amount
#pay_to_hash='1976a914'+'ecebae831bbfbd7827542a82da4dc136e1288f71'+'88ac'
pay_to_hash = '0d' + '6a' + '0b' + '70617373696f6e6f667663'
outputs = amount + pay_to_hash