Bitcoin Forum
December 10, 2016, 10:31:09 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: bitcoin Perl library  (Read 3642 times)
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
December 19, 2011, 08: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
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481409069
Hero Member
*
Offline Offline

Posts: 1481409069

View Profile Personal Message (Offline)

Ignore
1481409069
Reply with quote  #2

1481409069
Report to moderator
1481409069
Hero Member
*
Offline Offline

Posts: 1481409069

View Profile Personal Message (Offline)

Ignore
1481409069
Reply with quote  #2

1481409069
Report to moderator
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447


View Profile
December 19, 2011, 06:08:58 PM
 #2

Publish to CPAN?
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
December 20, 2011, 12:18:57 PM
 #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.
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 04, 2012, 10: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;

Boussac
Legendary
*
Offline Offline

Activity: 1173


e-ducat.fr


View Profile WWW
January 04, 2012, 12:12:54 PM
 #5

Thanks Grondilu this is awesome!

grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 05, 2012, 04:04:11 PM
 #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.

grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 23, 2012, 07: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...
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447


View Profile
January 23, 2012, 03:06:13 PM
 #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.
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
June 12, 2012, 01:03:54 PM
 #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.
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
June 13, 2012, 09: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.
AndyRossy
Sr. Member
****
Offline Offline

Activity: 448


View Profile
June 18, 2012, 03:00:13 AM
 #11

Why have you chosen Perl6 over Perl5? Has Perl6 been even finalize yet?

I am assuming that perl 6 would be backwards compatible.
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
June 18, 2012, 11: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.
rico666
Sr. Member
****
Offline Offline

Activity: 448


฿ → ∞


View Profile
July 24, 2016, 11: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

all non self-referential signatures except mine are lame ... oh wait ...   "Your maximum speed is 596511 keys/s per CPU core."
rico666
Sr. Member
****
Offline Offline

Activity: 448


฿ → ∞


View Profile
July 28, 2016, 03:35:25 PM
 #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

all non self-referential signatures except mine are lame ... oh wait ...   "Your maximum speed is 596511 keys/s per CPU core."
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!