Пример #1
0
def pubKeyToAddr(s, net='main', compressed='no'):
    ripemd160 = hashlib.new('ripemd160')
    ripemd160.update(  hashlib.sha256(codecs.decode(s.encode('utf-8'),'hex')).digest())
    #ripemd160.update(hashlib.sha256(s).digest())
    if (net=='main'):
        return utils.base58CheckEncode(0, ripemd160.digest(), compressed=compressed)
    else:
        return utils.base58CheckEncode(111, ripemd160.digest(), compressed=compressed)
Пример #2
0
def privateKeyToWif(key_hex, net = 'main', compressed='no'):
    if (net == 'main'):
        version = 0x80
    else:
        version = 0xef    
        
    if (compressed=='yes'):
        key_hex = key_hex + '01'
        
            
    return utils.base58CheckEncode(version, codecs.decode(key_hex.encode('utf-8'),'hex'), compressed)
Пример #3
0
def main():
    counter = 0
    try:
        if args.n:
            fp = open("ga1", "a+")
            for i in xrange(args.n):
                print counter
                private_key = "".join(["%x" % randrange(16) for x in range(0, 64)])
                wif = utils.base58CheckEncode(0x80, private_key.decode("hex"))
                address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif)))
                fp.write("PK: " + private_key + "\n" + "WIF: " + wif + "\n" + "ADDR: " + address + "\n")
                counter = counter + 1
            fp.close()
            print "File successfully closed."
    except KeyboardInterrupt:
        print "[!] User Keyboard Interrupt"
        fp.close()
        print "File successfully closed."

    print "Exiting."
    exit()
Пример #4
0
def main():
    counter = 0
    try:
        if args.n:
            fp = open("ga1", 'a+')
            for i in xrange(args.n):
                print counter
                private_key = ''.join(
                    ['%x' % randrange(16) for x in range(0, 64)])
                wif = utils.base58CheckEncode(0x80, private_key.decode('hex'))
                address = utils.pubKeyToAddr(
                    utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif)))
                fp.write("PK: " + private_key + '\n' + "WIF: " + wif + '\n' +
                         "ADDR: " + address + '\n')
                counter = counter + 1
            fp.close()
            print "File successfully closed."
    except KeyboardInterrupt:
        print "[!] User Keyboard Interrupt"
        fp.close()
        print "File successfully closed."

    print "Exiting."
    exit()
Пример #5
0
def pubKeyToAddr(s):
    ripemd160 = hashlib.new('ripemd160')
    ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
    return utils.base58CheckEncode(0, ripemd160.digest())
Пример #6
0
def privateKeyToWif(key_hex):    
    return utils.base58CheckEncode(0x80, key_hex.decode('hex'))
Пример #7
0
def pubKeyToAddr(s):
    ripemd160 = hashlib.new('ripemd160')
    ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
    return utils.base58CheckEncode(0, ripemd160.digest())
Пример #8
0
def privateKeyToWif(key_hex):
    return utils.base58CheckEncode(0x80, key_hex.decode('hex'))
Пример #9
0
public_key = myWallet.createAddress(
    'a2d43efac7e99b7e3cf4c07ebfebb3c349d8f2b5b0e1062d9cef93c170d22d4f')
print 'MyTransaction: public_key calulated using Mywallet lib {}'.format(
    public_key)
print 'public_key type {}'.format(type(public_key))

print ''
print ''
print ''
print 'C library'
from Crypto.Hash import RIPEMD
hash = RIPEMD.new()
pkHashStep00 = hashlib.sha256(public_key.decode('hex')).digest()
hash.update(pkHashStep00)
cdigest = hash.digest()
pkHashStep01 = utils.base58CheckEncode(0, cdigest)
print 'MyTransaction0: pkHash calculated from clib(publickey) {}'.format(
    pkHashStep01)
print ''

print ''
print ''
print ''
print 'Method 1'
pkHash10 = keyUtils.pubKeyToAddr(public_key)
print 'MyTransaction1: pkHash calulated using KeyUtils lib {}'.format(pkHash10)

print ''
print ''
print ''
print 'Method 2'
Пример #10
0
def privkey_to_wif(key_hex):
    return utils.base58CheckEncode(0x80, key_hex.decode('hex'))
Пример #11
0
def pubkey_to_addr(s, p):
    ripemd160 = hashlib.new('ripemd160')
    ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
    return utils.base58CheckEncode(p, ripemd160.digest())
Пример #12
0
#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
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(pubKey.decode('hex')).digest())
digest = (ripemd160.digest()).encode('hex')
print "Digest:", digest  #167c74f7491fe552ce9e1912810a984355b8ee07

#scriptPubKey from hash public key
scriptPubKey = '76a914' + digest + '88ac'

#public key is hashed and then base58 encoded
publKeyToAddress = utils.base58CheckEncode(0, digest.decode('hex'))
pubKeyToAddress = keyUtils.pubKeyToAddr(pubKey)
print "publKeyToAddress: ", publKeyToAddress  #133txdxQmwECTmXqAr9RWNHnzQ175jGb7e
print "pubKeyToAddress:  ", pubKeyToAddress  #133txdxQmwECTmXqAr9RWNHnzQ175jGb7e

signed_txn = txnUtils.makeSignedTransaction(
    privateKey, outputTransactionHash, 0, scriptPubKey,
    [[00001, keyUtils.addrHashToScriptPubKey(addrHash)]])

txnBuffer.append(signed_txn)
#fo = open("txnBuffer.txt","wb")
#for item in txnBuffer:
#  fo.write("%s\n" % item)

#itemlist = ['a','b','c']