bitcoin

This is an absolutely independent bitcoin research project. The idea of bitcoin is about verification, not trust. I am going to check all of this. It includes java classes for hash functions, elliptic cryptography, bitcoin addresses, hd keys (bip32/39), node communication messages, transaction builder and a console wallet. Everything is written from scratch without using third-party code.

build

Create source and output directories.

$ mkdir -p src/com/aqoleg/bitcoin src/com/aqoleg/crypto src/com/aqoleg/data src/com/aqoleg/keys src/com/aqoleg/messages src/com/aqoleg/utils out

Download source files.

$ cd src/com/aqoleg/bitcoin
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/bitcoin/files.txt
$ cd ../crypto
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/crypto/files.txt
$ cd ../data
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/data/files.txt
$ cd ../keys
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/keys/files.txt
$ cd ../messages
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/messages/files.txt
$ cd ../utils
$ wget -i https://bitcoin.aqoleg.com/src/com/aqoleg/utils/files.txt
$ cd ../../../../

Compile.

$ javac -d out src/com/aqoleg/*/*.java

Create jar file.

$ cd out
$ jar cfe ../Bitcoin.jar com.aqoleg.bitcoin.Main ./
$ cd ../

Directories out, src and file Bitcoin.jar will remain after all.

test

Build the jar file as described above, or download Bitcoin.jar.

$ wget bitcoin.aqoleg.com/Bitcoin.jar

Create test and output directories.

$ mkdir -p test/com/aqoleg/crypto/test test/com/aqoleg/data/test test/com/aqoleg/keys/test test/com/aqoleg/messages/test test/com/aqoleg/utils/test out

Download test files.

$ cd test/com/aqoleg/crypto/test
$ wget -i https://bitcoin.aqoleg.com/test/com/aqoleg/crypto/test/files.txt
$ cd ../../data/test
$ wget -i https://bitcoin.aqoleg.com/test/com/aqoleg/data/test/files.txt
$ cd ../../keys/test
$ wget -i https://bitcoin.aqoleg.com/test/com/aqoleg/keys/test/files.txt
$ cd ../../messages/test
$ wget -i https://bitcoin.aqoleg.com/test/com/aqoleg/messages/test/files.txt
$ cd ../../utils/test
$ wget -i https://bitcoin.aqoleg.com/test/com/aqoleg/utils/test/files.txt
$ cd ../../
$ wget bitcoin.aqoleg.com/test/com/aqoleg/Test.java
$ cd ../../../

Compile.

$ javac -d out -cp Bitcoin.jar test/com/aqoleg/*/test/*.java test/com/aqoleg/Test.java

Run one test or all tests and read results.

$ java -cp out:Bitcoin.jar com.aqoleg.messages.test.ScriptTest
$ java -cp out:Bitcoin.jar com.aqoleg.Test

Directories out, test, ~/.bitcoin.aqoleg.com/ and file Bitcoin.jar will remain after all.

use

Build the jar file as described above, or download Bitcoin.jar.

$ wget bitcoin.aqoleg.com/Bitcoin.jar

Launch the wallet.

$ java -jar Bitcoin.jar

Use the additional functions below. All of them can be run without arguments.

Generate new random key pair or create key pair from the decimal or hex private key (compressed or uncompressed). Decode private key from wif. Be aware about security of your keys!

$ java -cp Bitcoin.jar com.aqoleg.keys.KeyPair compressed
$ java -cp Bitcoin.jar com.aqoleg.keys.KeyPair uncompressed
$ java -cp Bitcoin.jar com.aqoleg.keys.KeyPair 1 compressed
$ java -cp Bitcoin.jar com.aqoleg.keys.KeyPair 0x10 uncompressed
$ java -cp Bitcoin.jar com.aqoleg.keys.KeyPair KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU7BLjN42GK

Print info about public key (compressed or uncompressed).

$ java -cp Bitcoin.jar com.aqoleg.keys.PublicKey 0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352

Check the bitcoin address.

$ java -cp Bitcoin.jar com.aqoleg.keys.Address 14Wu4nRjjTNggBfoZ4Md8t1gZv788cdvqT

Create, decode hd keys.

$ java -cp Bitcoin.jar com.aqoleg.keys.HdKeyPair passphrase mnemonic m/1/1h
$ java -cp Bitcoin.jar com.aqoleg.keys.HdKeyPair xprv9vqn8EWFNT8jkGZsM51WSqWPYjRARtMZBEUMGT4vs9BaEVvvyahcgZND4wome9gN2rnoxjuNw48Po7w27pkw9PyFEL5Q5WrERpmjJzZU6jm

Decode bitcoin script.

$ java -cp Bitcoin.jar com.aqoleg.messages.Script 473044022062a50c4373f0cad58787a4449e0a63a1cd19abe36a0e002a54487ff27d813668022026401ea091ac26bd09a2947acbe7a2b638cb2b98da19dc6c0e36de80a96430e90121039f843adf502df5c13c5f3a851a76bd9de980fbc63a84864b8d70a471030f7520

Decode transaction.

$ java -cp Bitcoin.jar com.aqoleg.messages.Transaction 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000

Download, print block.

$ java -cp Bitcoin.jar com.aqoleg.data.BlockLoader 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

Print info about bitcoin nodes.

$ java -cp Bitcoin.jar com.aqoleg.data.Addresses 20

Directory ~/.bitcoin.aqoleg.com/ with downloaded blocks and addresses, and file Bitcoin.jar will remain after all.