def get_address(seed):
    h = hashlib.new('SHA256')
    h.update(seed)
    privateExponent = h.digest().encode('hex')
    print 'Private exponent: ', privateExponent
    print 'Wallet import format: ', private_exponent_to_WIF(privateExponent)
    # 0 Private ECDSA Key - 256 bits
    # print 'Now let us convert them to public keys by doing an elliptic curve point multiplication.'
    # 1 Public
    publicEncryptionKey = arithmetic.privtopub(privateExponent)
    # print 'publicEncryptionKey =', publicEncryptionKey
    publicEncryptionKeyBinary = arithmetic.changebase(publicEncryptionKey,
                                                      16,
                                                      256,
                                                      minlen=64)
    ripe = hashlib.new('ripemd160')
    sha = hashlib.new('SHA256')
    # 2 Sha-256 of 1
    sha.update(publicEncryptionKeyBinary)
    # print 'Sha-256: ', sha.digest().encode('hex')
    # 3 RIPEMD of 2
    ripe.update(sha.digest())
    # 4 add network bytes
    network_bytes = 00
    # print 'Ripe digest that we will encode in the address:',
    # ripe.digest().encode('hex')
    returnedAddress = encodeAddress(network_bytes, ripe.digest())
    print 'Encoded BTC address:', returnedAddress
    # Checksum does not validate
    return returnedAddress
예제 #2
0
        return False

    streamNumber, bytesUsedByStreamNumber = decodeVarint(data[bytesUsedByVersionNumber:9+bytesUsedByVersionNumber])
    #print streamNumber
    status = 'success'
    return streamNumber


if __name__ == "__main__":
    print 'Let us make an address from scratch. Suppose we generate two random 32 byte values and call the first one the signing key and the second one the encryption key:'
    privateSigningKey = '93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
    privateEncryptionKey = '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
    print 'privateSigningKey =', privateSigningKey
    print 'privateEncryptionKey =', privateEncryptionKey
    print 'Now let us convert them to public keys by doing an elliptic curve point multiplication.'
    publicSigningKey = arithmetic.privtopub(privateSigningKey)
    publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey)
    print 'publicSigningKey =', publicSigningKey
    print 'publicEncryptionKey =', publicEncryptionKey

    print 'Notice that they both begin with the \\x04 which specifies the encoding type. This prefix is not send over the wire. You must strip if off before you send your public key across the wire, and you must add it back when you receive a public key.'

    publicSigningKeyBinary = arithmetic.changebase(publicSigningKey,16,256,minlen=64)
    publicEncryptionKeyBinary = arithmetic.changebase(publicEncryptionKey,16,256,minlen=64)

    ripe = hashlib.new('ripemd160')
    sha = hashlib.new('sha512')
    sha.update(publicSigningKeyBinary+publicEncryptionKeyBinary)

    ripe.update(sha.digest())
    addressVersionNumber = 2
예제 #3
0
def makeCryptor(privkey):
  privkey_bin = '\x02\xca\x00 '+a.changebase(privkey,16,256,minlen=32)
  pubkey = a.changebase(a.privtopub(privkey),16,256,minlen=65)[1:]
  pubkey_bin = '\x02\xca\x00 '+pubkey[:32]+'\x00 '+pubkey[32:]
  cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin)
  return cryptor
예제 #4
0
def privToPub(privkey):
  return a.privtopub(privkey)
예제 #5
0
def addBMIfNotPresent(address):
    address = str(address).strip()
    if address[:3] != 'BM-':
        return 'BM-' + address
    else:
        return address


if __name__ == "__main__":
    print 'Let us make an address from scratch. Suppose we generate two random 32 byte values and call the first one the signing key and the second one the encryption key:'
    privateSigningKey = '93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
    privateEncryptionKey = '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
    print 'privateSigningKey =', privateSigningKey
    print 'privateEncryptionKey =', privateEncryptionKey
    print 'Now let us convert them to public keys by doing an elliptic curve point multiplication.'
    publicSigningKey = arithmetic.privtopub(privateSigningKey)
    publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey)
    print 'publicSigningKey =', publicSigningKey
    print 'publicEncryptionKey =', publicEncryptionKey

    print 'Notice that they both begin with the \\x04 which specifies the encoding type. This prefix is not send over the wire. You must strip if off before you send your public key across the wire, and you must add it back when you receive a public key.'

    publicSigningKeyBinary = arithmetic.changebase(publicSigningKey,
                                                   16,
                                                   256,
                                                   minlen=64)
    publicEncryptionKeyBinary = arithmetic.changebase(publicEncryptionKey,
                                                      16,
                                                      256,
                                                      minlen=64)