Thursday, July 16, 2015

Adding Census Protocol wallets to the network

So now that we have a wallet – that's pretty cool, but adding to the network needs some extra work.

We can send anything we want (within reason) to the network to add to the wallet. The network will blindly send whatever your want – so if you do something really dumb like send your own private key to the network it will happily share it to every person on Earth as the data is replicated. The Python library has a handy function call that removes the private data from the common CWIF format - cwif_to_wallet.

Using this function:

__author__ = 'lpreimesberger'
import  os
import censusprotocollib
print "Let's make a wallet!"
email = raw_input( "What is your email address? : " )
fake_seed = raw_input( "Enter something for a brainwallet: " )
new_wallet = censusprotocollib.generate_wallet(fake_seed, email)
cp_wallet = censusprotocollib.cwif_to_wallet(new_wallet)
print cp_wallet

Which outputs:

$ python createwallet.py
Let's make a wallet!
What is your email address? : ilovecats@cathuggers.com
Enter something for a brainwallet: correct horse battery staple
{'balance': 0, 'version': 1, 'created': 1436734011857, 'rsa_keys': ['-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAseG7lt/JwOHyzG0hKbKQ\niDmiQ0bTY+mg6AQq8wdZx3lQF0BOWCtnYYxVL+zWr2fqMqjtsc6rC11p4VvmojBm\nGZAEMH1um+sUAzMLKellAdfRNH1XRA5Ag/treaWOlmY/2ilTfq2raSgq/Ed/kGix\nl+NynzgNiKqFVbBbCZ4rvPmkiyEmygpuLXU5MO8qOSpX1cegauByciKxcdqcBLjg\nQgj7XLO9eqGCX/ypzysXPAIgdWIUrZci8gjdJf65eQBywaQ1jLTpASV3kzY4pB4d\n3lBWZuIe5Ck65ZVQjeaPXgYVDLUFp+R2eERWAWydaKLqaSaL3NGg6XMuqoFzx0Ex\nrQIDAQAB\n-----END PUBLIC KEY-----'], 'txid': '433225d2-e843-4448-a97d-aefaf4b5d5a0', 'item_type': 'wallet', 'tag': 'generated by censusprotocollib', 'source': '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T', 'signature': '', 'block_in': '', 'email': 'ilovecats@cathuggers.com'}

Which is all public key data and is safe to send out. The actually call to submit the new wallet to the network is .

Making a bunch of changes to save the local CWIF and the to send the data we get this:

__author__ = 'lpreimesberger'
import os
import json
import censusprotocollib
print "Let's make a wallet!"
email = raw_input( "What is your email address? : ")
fake_seed = raw_input( "Enter something for a brainwallet: ")
name_of_cwif = raw_input( "Enter name of CWIF file: ")
new_wallet = censusprotocollib.generate_wallet(fake_seed, email)
cp_wallet = censusprotocollib.cwif_to_wallet(new_wallet)
f = open( name_of_cwif + ".cwif", "w " )
f.write( json.dumps(new_wallet) )
f.close() 
signed    = censusprotocollib.sign(cp_wallet, new_wallet["private"])
print censusprotocollib.wallet("localhost", signed )
Which will generate, clear, and submit the wallet to the local network. It doesn't become real until the server processes it – but more on that soon.


No comments:

Post a Comment