Ok, maybe it's a bit early to push to github but I did it anyway because I really like what I've done and I want to show it to people. I should have created an 'experimental' branch but I totally forgot and I don't master git enough to revert the process. So it's still in the main branch.
I went back to basics, got rid of unnecessary stuff (such as encryption and master keys) and focus on dealing efficiently with keys and addresses.
Now, you don't have to 'use Bitcoin::Key' or 'use Bitcoin::Address', just:
You don't have to explicitely call a constructor, either. I overloaded the constants interpretation with the overload pragma and its overload::constants function. So now when you type a string litteral that looks like a bitcoin address or a bitcoin key in WIF, perl checks it and see what it is exacly (while verifying the checksum, of course).
This allows you to write something like:
say "5KFtidLNEgFicv1QWGjMUECprKEQdLEqDGA7V5F8PJDZxaazRG7"->address;
Perl will magically recognize this is a bitcoin key so it will create the corresponding object before calling its address method. This should normally print "1NZunrMgUVoe7H46GZW3x1NUxGPSyJUCSL".
Also, now
Bitcoin::Key inherits from
Math::BigInt, so you can transparently do arithmetics on them and you'll get a derived key. This can be usefull for defining a master key or for Diffie-Hellman like schemes:
say "5KFtidLNEgFicv1QWGjMUECprKEQdLEqDGA7V5F8PJDZxaazRG7" * 2;
One thing that still needs to be done is having this arithmetics being modular, but it should not be too difficult.
Random generation of a new key is done with a special constructor called 'random':
It is actually a constructor for
EC::DSA::PrivateKey, from whom
Bitcoin::Key inherits too (yes, I've done multiple inheritance). I think it makes sense since a bitcoin key is both a Base58 encoded data and a ECDSA privatekey.
Also, I've decided to use environment variables to tune the behavior of the library. For instance, if you want to work with the test network, just define the BITCOIN_TEST env var (you can put anything in it, it doesn't matter):
$ export BITCOIN_TEST=yes
$ perl -wE 'use Bitcoin; [your code here...]'
or
$ BITCOIN_TEST= perl -wE 'use Bitcoin;'
More will come.