The implementation is based on the proposal BIP 0032 and is currently in audit mode. Please do not use in production yet. Testing welcome.
A common problem for Bitcoin enabled webservices is secure storage of user funds. Usually one generates for each new user an own address to track what user owns which coins.
In python i'm using the Crypto package to generate a random number of length 256 bit. The function for doing so is import Crypto.Random.random as rand key = rand.getrandbits(256.
The classic generation of a new bitcoin address requires basically 3 steps:
If the webserver gets hacked and the private keys are stored on it an attacker can steal all user funds.
However, it is not possible to use the private key in the place of the public key. If the locking key is private, this system makes it possible to verify that the owner locked those documents. The reason is that a message encrypted by the sender can only be opened by a person with the matching public key, thus verifying that the sender did actually hold the private key.
Based on the mathematical properties of ECC we can apply equivalent operations on a private key and its public key. The resulting keys will be a new corresponding keypair. In pseudocode:
We apply the operation on the public key on the webserver to generate new bitcoin addresses no private key is needed.To spend the funds later, we derive the private for the address in a secure, offline environment.
For creating a hierachical wallet structure we use the child derivation function described in BIP 0032.
The code above produces the following output