def test_makeSignedTransaction(self): # Transaction from # https://blockchain.info/tx/901a53e7a3ca96ed0b733c0233aad15f11b0c9e436294aa30c367bf06c3b7be8 # From 133t to 1KKKK privateKey = keyUtils.wifToPrivateKey( "5Kb6aGpijtrb8X28GzmWtbcGZCG8jHQWFJcWugqo3MwKRvC8zyu") #133t signed_txn = makeSignedTransaction( privateKey, "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey( "133txdxQmwECTmXqAr9RWNHnzQ175jGb7e"), [ [ 24321, #satoshis keyUtils.addrHashToScriptPubKey( "1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa") ], [ 20000, keyUtils.addrHashToScriptPubKey( "15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7") ] ]) verifyTxnSignature(signed_txn)
def test_makeSignedTransaction(self): # Transaction from # https://blockchain.info/tx/901a53e7a3ca96ed0b733c0233aad15f11b0c9e436294aa30c367bf06c3b7be8 # From 133t to 1KKKK privateKey = keyUtils.wifToPrivateKey("5Kb6aGpijtrb8X28GzmWtbcGZCG8jHQWFJcWugqo3MwKRvC8zyu") #133t signed_txn = makeSignedTransaction(privateKey, "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("133txdxQmwECTmXqAr9RWNHnzQ175jGb7e"), [[24321, #satoshis keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")], [20000, keyUtils.addrHashToScriptPubKey("15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7")]] ) verifyTxnSignature(signed_txn)
def test_makeSignedTransaction(self): privateKey = keyUtils.wifToPrivateKey( "5KawhzxJoVhw1hw75WTtXPUtsLVXFHLYZXDAWGRQxo597X4EwFX") signed_txn = makeSignedTransaction( privateKey, "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9", # output (prev) transaction hash 0, keyUtils.addrHashToScriptPubKey( "167WXe5yJXqsX8bcmPUMR3CzMib89NU3da"), #input address [[ 00001, keyUtils.addrHashToScriptPubKey( "1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa") ] #output address #, [20000, # keyUtils.addrHashToScriptPubKey("15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7")] ]) showTxn(signed_txn)
import utils import keyUtils import txnUtils privateKey = keyUtils.wifToPrivateKey( "5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD") #1MMMM signed_txn = txnUtils.makeSignedTransaction( privateKey, "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5"), [[ 91234, #satoshis keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa") ]]) txnUtils.verifyTxnSignature(signed_txn) print 'SIGNED TXN', signed_txn
print('2 - Convert it to a byte string using Base58Check encoding') leadingOnes = utils.countLeadingChars(wif, '1') s = utils.base256encode(utils.base58decode(wif)) #print(codecs.decode( s[:-4], 'hex' ).decode()) result = '\0' * leadingOnes + binascii.hexlify(s[:-4]).decode() print(' ', result.upper()) print('3 - Drop the last 4 checksum bytes from the byte string') print(' ', result[:-4].upper()) chk = s[-4:] checksum = hashlib.sha256(hashlib.sha256( result.encode('utf-8')).digest()).hexdigest()[0:8] print('4 - Dropping first byte. This is the private key') private_key = result[1:-4].upper() print(' ', result[1:-4].upper()) private_key = codecs.encode(keyUtils.wifToPrivateKey(wif), 'hex').decode() print(' ', codecs.encode(keyUtils.wifToPrivateKey(wif), 'hex').decode()) print(' ', codecs.encode(keyUtils.wifToPrivateKey(wif), 'hex')) print('****************************************') print('***** WIF checksum ***************') print('****************************************') #wif = '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ' #wif = "cMeNhXd7qUrAc9LpkCDfXpziQczdVrRdMVsauNTDhU1c4K5cptNk" print('1 - Take a Wallet Import Format string') print(' ', wif) print('2 - Convert it to a byte string using Base58Check encoding') leadingOnes = utils.countLeadingChars(s, '1') s = utils.base256encode(utils.base58decode(wif)) result = '\0' * leadingOnes + binascii.hexlify(s).decode() print(' ', result.upper())
# cU1UcuA7HRMNoJMamquHLpGMnkDQtwhSt8d3Z2UpGFdx1E4osE7D # 5JhuTf9i4fXU8nkonyWDuY8B9vq3LiqQ6vCKH7VpLib4f7hty42 # privateKey = keyUtils.wifToPrivateKey("cU1UcuA7HRMNoJMamquHLpGMnkDQtwhSt8d3Z2UpGFdx1E4osE7D") #1MMMM # signed_txn = makeSignedTransaction(privateKey, # "d70cd6ad2c0a8211b2e22954b3e450a6eaffc4b22d4c35fd760805aae08269a3", # output (prev) transaction hash # 0, # sourceIndex # keyUtils.addrHashToScriptPubKey("mvTpAzhJZQs2FVBR33WdTyYVWakvKNNkLh"), # [[100, #satoshis # keyUtils.addrHashToScriptPubKey("mtdynEM1zSiSiYQntprR8kep5NEeAqQfco")]] # ) # privateKey = keyUtils.wifToPrivateKey("cPk3QpypBp6qvmFgcM6zAQ6ZEw7FHaWwixmgBQ92LE5nzkBE9TKi") #1MMMM # privateKey = keyUtils.wifToPrivateKey("cRqUESTM4izdtd1p8wsZVYeLwqPP2zgRvBjLnzhUGwK4FwRTncUr") #1MMMM privateKey = keyUtils.wifToPrivateKey( "cVdRR5qP9UW7D3Gf6s6sFKmVzxD7z5cPu6eLtnBP49FPEFrViNvc") #1MMMM print "privateKey", [privateKey] # signed_txn = makeSignedTransaction(privateKey, # "c0e9e5a845cf222cc78220685fcc295db73608c64bde5d32689ef85e27c72fb5", # output (prev) transaction hash # 0, # sourceIndex # keyUtils.addrHashToScriptPubKey("mxh1vzqUYPT3Udi8c7u2Gu62uj3CnQX5cG"), # [[30000000, #satoshis # keyUtils.addrHashToScriptPubKey("mrWrZGUatJUdcuF3hcnQSjZVcLaw3g1VAi")], # [550000000, # keyUtils.addrHashToScriptPubKey("mxh1vzqUYPT3Udi8c7u2Gu62uj3CnQX5cG")]] # ) signed_txn = makeSignedTransaction( privateKey, "73cb8c38c3f0ea7a022bc3d93a78d2b45fc2ed0b44664c17c0225c59f06f490d", # output (prev) transaction hash
for nums in my_list: print(nums, nums&0xff, nums&0xff >>4, (nums&0xff)&0xf, digits[nums&0xff >>4], digits[(nums&0xff)&0xf],0xff >>4, 0xf ) keyUtils.addrHashToScriptPubKey("mwAnSj8gvAkDHbW5wTN67DRQETdmTVDdHz").decode() keyUtils.addrHashToScriptPubKey("moRsbz4GMe99KFSzq8XsSfkS2gmPfQ3GpC").decode() k=keyUtils.wifToPrivateKey("5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn") print('privk ', codecs.encode(k,'hex').decode().upper()) print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) ) pk = keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) print('pubk ', codecs.encode(pk, 'hex').decode() ) print('addr ', keyUtils.keyToAddr("754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa")) k=keyUtils.wifToPrivateKey("KzTg2wn6Z8s7ai5NA9MVX4vstHRsqP26QKJCzLg4JvFrp6mMaGB9") print('privk ', codecs.encode(k,'hex').decode().upper()) #print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) ) pk = keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) print('pubk ', codecs.encode(pk, 'hex').decode() ) print('addr ', keyUtils.pubKeyToAddr("0328592df0ad9de33919e38caa7ff567b708699f9c2f67d8e91ff7185f1e8158b3"))
print(' ',wif) print('2 - Convert it to a byte string using Base58Check encoding') leadingOnes = utils.countLeadingChars(wif, '1') s = utils.base256encode(utils.base58decode(wif)) #print(codecs.decode( s[:-4], 'hex' ).decode()) result = '\0' * leadingOnes + binascii.hexlify( s[:-4] ).decode() print(' ',result.upper()) print('3 - Drop the last 4 checksum bytes from the byte string') print(' ',result[:-4].upper()) chk = s[-4:] checksum = hashlib.sha256(hashlib.sha256(result.encode('utf-8')).digest()).hexdigest()[0:8] print('4 - Dropping first byte. This is the private key') private_key = result[1:-4].upper() print(' ',result[1:-4].upper()) private_key = codecs.encode(keyUtils.wifToPrivateKey(wif),'hex').decode() print(' ',codecs.encode(keyUtils.wifToPrivateKey(wif),'hex').decode()) print(' ',codecs.encode(keyUtils.wifToPrivateKey(wif),'hex')) print('****************************************') print('***** WIF checksum ***************') print('****************************************') #wif = '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ' #wif = "cMeNhXd7qUrAc9LpkCDfXpziQczdVrRdMVsauNTDhU1c4K5cptNk" print('1 - Take a Wallet Import Format string') print(' ',wif) print('2 - Convert it to a byte string using Base58Check encoding') leadingOnes = utils.countLeadingChars(s, '1') s = utils.base256encode(utils.base58decode(wif)) result = '\0' * leadingOnes + binascii.hexlify( s ).decode() print(' ',result.upper())
import keyUtils import utils import hashlib import txnUtils import pickle txnBuffer = [] #User frist provides the WIF private key which is converted to the private key wifPrivateKey = raw_input( 'Enter your wif private key: ' ) #5Kb6aGpijtrb8X28GzmWtbcGZCG8jHQWFJcWugqo3MwKRvC8zyu print "Received wif private key is:", wifPrivateKey privateKey = keyUtils.wifToPrivateKey(wifPrivateKey) print "Private key is :", privateKey #E97174E793C7524C0A68EDA86458682BD9C5510E6E3614CC5CECDFFE966C925B #user provides the previous transaction hash #c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9 outputTransactionHash = raw_input('Enter previous transaction hash: ') print "Received previous transaction hash is: ", outputTransactionHash #user provides recipient's address #1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa addrHash = raw_input('Enter recepient address: ') print "Received recipient address:", addrHash print "length:", len(addrHash) #public key is generated from the private key using Ellicptic Curve Cryptography (ECC) #392B964E911955ED50E4E368A9476BC3F9DCC134280E15636430EB91145DAB739F0D68B82CF33003379D885A0B212AC95E9CDDFD2D391807934D25995468BC55 pubKey = keyUtils.privateKeyToPublicKey(privateKey) print "Sender's Public Key: ", pubKey #public keys is hashed
import keyUtils import txnUtils privateKey = keyUtils.wifToPrivateKey("5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD") # 1MMMM signed_txn = txnUtils.makeSignedTransaction(privateKey, "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5"), [[91234, # satoshis keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")]] ) txnUtils.verifyTxnSignature(signed_txn) print 'SIGNED TXN', signed_txn
import hashlib import base64 import ecdsa import keyUtils my_address = "mji6tgw9ZnrRAXN49uy8y2AXc7M5BGfxRx" hash_utxo = "4be05aaad356e4258bbb85818df836137c1246602cbccecf052f34e989a14865" private_key_base58check = "93UexCJHWp59BXxb2YrixM6NEkMxe7omrGz2mPifQGvQjGtDcuz" private_key = keyUtils.wifToPrivateKey(private_key_base58check) recipient_address = "n3GNqMveyvaPvUbH469vDRadqpJMPc84JA" change_address = "mji6tgw9ZnrRAXN49uy8y2AXc7M5BGfxRx" def pack_int(number, bytes_number): format = "%" + str(2 * bytes_number) + "s" return (format % hex(number)[2:]).replace(" ", "0") def to_little_endian(hash): # return reversed hash return hash def scriptPubKey(address): script = "76a9" + address + "88ac" script_len = pack_int(len(script), 1) return (script_len + script) ## OP_DUP OP_HASH <Address> OP_EQUALVERIFY OP_CHECKSIG
import utils import keyUtils import txnUtils import codecs import binascii privateKey = codecs.encode(keyUtils.wifToPrivateKey("5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD"),'hex').decode() #1MMMM print('privateKey', privateKey) signed_txn = txnUtils.makeSignedTransaction( privateKey, "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5", net='main', compressed='no').decode(), [[91234, #satoshis keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa", net='main', compressed='no').decode()]] ) txnUtils.verifyTxnSignature(signed_txn) print ('SIGNED TXN', signed_txn)
import utils, codecs, struct, hashlib, base58, keyUtils, binascii, ecdsa, txnUtils my_list = [ 0, 17, 34, 51, 68, 85, 102, 119, -120, -103, -86, -69, -52, -35, -18, -1 ] digits = "0123456789abcdef" for nums in my_list: print(nums, nums & 0xff, nums & 0xff >> 4, (nums & 0xff) & 0xf, digits[nums & 0xff >> 4], digits[(nums & 0xff) & 0xf], 0xff >> 4, 0xf) keyUtils.addrHashToScriptPubKey("mwAnSj8gvAkDHbW5wTN67DRQETdmTVDdHz").decode() keyUtils.addrHashToScriptPubKey("moRsbz4GMe99KFSzq8XsSfkS2gmPfQ3GpC").decode() k = keyUtils.wifToPrivateKey( "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn") print('privk ', codecs.encode(k, 'hex').decode().upper()) print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode())) pk = keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode()) print('pubk ', codecs.encode(pk, 'hex').decode()) print( 'addr ', keyUtils.keyToAddr( "754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa")) k = keyUtils.wifToPrivateKey( "KzTg2wn6Z8s7ai5NA9MVX4vstHRsqP26QKJCzLg4JvFrp6mMaGB9") print('privk ', codecs.encode(k, 'hex').decode().upper()) #print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) ) pk = keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode()) print('pubk ', codecs.encode(pk, 'hex').decode())
import utils import keyUtils import txnUtils import codecs import binascii privateKey = codecs.encode( keyUtils.wifToPrivateKey( "cQFK8Vqwanamn194EscN3zUMyvPTVc39Dubx5BYccvjXjrwS9mBG"), 'hex').decode() #1MMMM privateKey = codecs.encode( keyUtils.wifToPrivateKey( "92BwrjLFBNf1dUfyvSWmC6miTVQfdPSQcYrc8kAt7nFcy3JDoL8"), 'hex').decode() #1MMMM print('privateKey: ', privateKey) #1MMMM #F01E3C2210E1DD106399CD20D2D059412EEC856ABB3AD63E66749F24B6AA9DF signed_txn = txnUtils.makeSignedTransaction( privateKey, "acf7496e7262fb977e78bd3c0692722b428bf828c8c2033caa859f8ed582f8b1", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK", net='test', compressed='yes').decode(), #keyUtils.addrHashToScriptPubKey("mpCWzuKvmqHSoyPo3BQzsaSSp3hqqZEfic", net='test', compressed='no').decode(), #Source of funds [[ 100000, #satoshis keyUtils.addrHashToScriptPubKey("n22NLZeQMATUChs2BDPrKC8RJbgHTewjm7", net='test', compressed='yes').decode() ]], net='test', #Destination of funds
def _wif_to_priv(self): if self.priv_wif != None: self.priv_key = keyUtils.wifToPrivateKey( self.priv_wif).decode('hex') else: print("[!]Setup private key WiF first")
import utils import keyUtils import txnUtils import codecs import binascii privateKey = codecs.encode(keyUtils.wifToPrivateKey("cQFK8Vqwanamn194EscN3zUMyvPTVc39Dubx5BYccvjXjrwS9mBG"),'hex').decode() #1MMMM privateKey = codecs.encode(keyUtils.wifToPrivateKey("92BwrjLFBNf1dUfyvSWmC6miTVQfdPSQcYrc8kAt7nFcy3JDoL8"),'hex').decode() #1MMMM print('privateKey: ', privateKey) #1MMMM #F01E3C2210E1DD106399CD20D2D059412EEC856ABB3AD63E66749F24B6AA9DF signed_txn = txnUtils.makeSignedTransaction(privateKey, "acf7496e7262fb977e78bd3c0692722b428bf828c8c2033caa859f8ed582f8b1", # output (prev) transaction hash 0, # sourceIndex keyUtils.addrHashToScriptPubKey("muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK", net='test', compressed='yes').decode(), #keyUtils.addrHashToScriptPubKey("mpCWzuKvmqHSoyPo3BQzsaSSp3hqqZEfic", net='test', compressed='no').decode(), #Source of funds [[100000, #satoshis keyUtils.addrHashToScriptPubKey("n22NLZeQMATUChs2BDPrKC8RJbgHTewjm7", net='test', compressed='yes').decode()]],net='test', #Destination of funds #keyUtils.addrHashToScriptPubKey("mtv5Zge8zK8r3UCb1ZVC5P3JkDccJEEB21", net='test', compressed='no').decode()]],net='test', compressed='yes' ) #txnUtils.verifyTxnSignature(signed_txn) print ('SIGNED TXN', signed_txn)