Author

Topic: bitcoin Perl library (Read 4584 times)

legendary
Activity: 1120
Merit: 1037
฿ → ∞
July 28, 2016, 10:35:25 AM
#14
It seems "grondilu" also contributed code that is part of the library to the Rosetta Code site, so I took the liberty of rewriting it.

Result is code which is about 40 times faster (orig vs pcun)

Code:
# packunpack.pl
Benchmark: timing 10000 iterations of orig, pcun...
      orig: 42 wallclock secs (42.15 usr +  0.00 sys = 42.15 CPU) @   NaN/s (n=10000)
      pcun:  1 wallclock secs ( 1.26 usr +  0.00 sys =  1.26 CPU) @   NaN/s (n=10000)

So I may finally ditch that Go implementation in my Collision Attack Study.

Rico
legendary
Activity: 1120
Merit: 1037
฿ → ∞
July 24, 2016, 06:16:45 AM
#13
I fetched the library, squashed some bugs and silenced some others.

At least it "runs" now with Perl 5.24 without immediately breaking. Unfortunately it runs, but doesn't "work" yet. (Wrong computations).
I'll dig into that deeper.

The original author did a great job, but one can see that the code has been mostly lying around for 4+ years and that is never a good thing.
I'm confident I'll be able to shape it up again and will publish then. Stay tuned.


Rico
legendary
Activity: 1288
Merit: 1080
June 18, 2012, 06:58:43 AM
#12
Why have you chosen Perl6 over Perl5?

I haven't.  I kind of felt stuck in Perl5 as I was reaching the point where I should implement networking.  Yet I don't know much about networking programming, I have difficulties understanding Satoshi's code about it, and I don't have a regular internet access so I could not make as many tests as I wanted.   So I felt like starting a Perl6 implementation until I get a regular internet access.

Quote
Has Perl6 been even finalize yet?

Specifications are pretty much done, yes.  Implementations have done very impressive progress lately.  Rakudo is pretty much usable now, for instance.

Quote
I am assuming that perl 6 would be backwards compatible.

No.  Perl6 will NOT be backwards compatible.   At all.

Still, it will be (and is already) an awesome programming language.
sr. member
Activity: 448
Merit: 250
June 17, 2012, 10:00:13 PM
#11
Why have you chosen Perl6 over Perl5? Has Perl6 been even finalize yet?

I am assuming that perl 6 would be backwards compatible.
legendary
Activity: 1288
Merit: 1080
June 13, 2012, 04:25:40 AM
#10
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:

Code:
use Bitcoin;

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:

Code:
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:

Code:
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':

Code:
say random Bitcoin::Key;

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):

Code:
$ export BITCOIN_TEST=yes
$ perl -wE 'use Bitcoin; [your code here...]'
or
Code:
$ BITCOIN_TEST= perl -wE 'use Bitcoin;'


More will come.
legendary
Activity: 1288
Merit: 1080
June 12, 2012, 08:03:54 AM
#9


Developping a bitcoin library in Perl6 gave me a lot of ideas about how to improve this library in Perl5.

I can't publish just yet but it's gonna come out soon.  Stay tuned.
vip
Activity: 447
Merit: 258
January 23, 2012, 10:06:13 AM
#8
I must say I am a bit disappointed by the lack of interest in this project.  I know much people here only love python, but still...

I too hear little from users of Finance::MtGox module or my Haskell interface to Bitcoin RPC.  However, I occasionally get an email or bug report, so I know there are some users.  They're just mostly quiet.  I bet your project is similar.  Many Perl developers I've worked with only search CPAN for modules.  Perhaps uploading it there could draw more attention.

Anyway, keep up the good work.
legendary
Activity: 1288
Merit: 1080
January 23, 2012, 02:21:01 AM
#7

The scripting mecanism is now implemented.  It hasn't been tested much though.

Also, a "master key" class has been created.  So it is possible to derive a key from an other one, using a 32 bytes string.

Code:
my $master_key = new Bitcoin::Key::Master;
my $slave_key = $master_key << "some string identifying an account";


Information is completely included in the secret exponent, in a reversible way (I used the master key as a symmetric encryption key to do so):

Code:
my $account_name = $master_key >> $slave_key;


I must say I am a bit disappointed by the lack of interest in this project.  I know much people here only love python, but still...
legendary
Activity: 1288
Merit: 1080
January 05, 2012, 11:04:11 AM
#6

This gave me a crazy idea recently.  I was planning on writing a CGI script so I can browse the block chain with my local thttpd web server (kind of a local bitcoinexplorer), and then I thought that it would be cool if I could do it all inside Vim, as I spend so much time inside this text editor anyway.  Vim has a help syntax with hyperlink-like capabilities.  I'm pretty sure it can be done.

Also, Vim has support for both Perl and Python scripting, so if the thing works with one language, it should work with the other.

PS.  By the way, the regex search should work now.

legendary
Activity: 1221
Merit: 1025
e-ducat.fr
January 04, 2012, 07:12:54 AM
#5
Thanks Grondilu this is awesome!
legendary
Activity: 1288
Merit: 1080
January 04, 2012, 05:25:11 AM
#4
Until I publish to CPAN, I set up a github repo:
https://github.com/grondilu/libbitcoin-perl

It now ships a bitcoin block dumper !!

To my amazement, it does actually fly pretty well:

Code:
# I want to check out the 100,000th block:

use Bitcoin::Block;
use Data::Dumper;

print +Dumper new Bitcoin::Block 100_000;

legendary
Activity: 1288
Merit: 1080
December 20, 2011, 07:18:57 AM
#3
Publish to CPAN?

Yeah I will eventually but I don't know CPAN much and I don't have a regular internet access so it might take some time.
vip
Activity: 447
Merit: 258
December 19, 2011, 01:08:58 PM
#2
Publish to CPAN?
legendary
Activity: 1288
Merit: 1080
December 19, 2011, 03:10:28 AM
#1
I know you guys you all like Python and do plenty of bitcoin-related stuff in this language and that's cool.

But for people like me who are much more script lovers, a complete Perl bitcoin library would be great.

So, while I was translating ThomasV's Electrum client, I happened to had written such a library. I think it is already awesome, so I think it worth publishing it.

You can see the main POD in html here.

The tgz is there


In a nutshell, you can do stuffs such as:

Code:
use Bitcoin qw(BTC);

printf "you owe me %d%s.\n", 10, BTC;

use Bitcoin::Address;

my $addr = new Bitcoin::Address '1DxH3bjYeCKbSKvVEsXQUBjsTcxagmWjHy'; # this does checksum verif

use Bitcoin::PrivateKey;

my $key = new Bitcoin::PrivateKey; # generates a random private key
print $key->address; # prints the corresponding bitcoin address
Jump to: