36
libbitcoin

Libbitcoin slides

Embed Size (px)

Citation preview

Page 1: Libbitcoin slides

libbitcoin

Page 2: Libbitcoin slides

Typical Bitcoin Company

ApplicationCentralized

APIProvider

Gem, Chain,Blockchain.info,

Coinbase,BlockCypher, ...

Shopping, Escrow,Smart contracts,

Tipping, etc...

Page 3: Libbitcoin slides

libbitcoin is a Blockchain API

Applicationlibbitcoin-

server

Open Source,Decentralized

Shopping, Escrow,Smart contracts,

Tipping, etc...

Page 4: Libbitcoin slides

libbitcoin is a Power-user CLI Tool

libbitcoin-explorer

(BX)

libbitcoin-server

Scripting, Research,Exploration, ...

$ bx fetch-height345896

Page 5: Libbitcoin slides

libbitcoin is a Blockchain Toolkit

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 6: Libbitcoin slides

Why does this matter?

● Right now, most of the network runs a single piece of software (the Satoshi node)

● The Bitcoin Foundation controls this software

● Monocultures are bad!

● libbitcoin is a complete third-party Bitcoin Blockchain implementation

Page 7: Libbitcoin slides

libbitcoin Users

● DarkWallet

● OpenBazaar

● AirBitz

Page 8: Libbitcoin slides

libbitcoin Tour

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 9: Libbitcoin slides

libbitcoin

● Modern C++11 codebase.

● Designed as a collection of simple, decoupled classes

● You can use as much or as little funtionality as you like

Page 10: Libbitcoin slides

libbitcoin

● Basic blockchain types– Blocks, Transactions, Scripts, Crypto primitives, ...

● Wallet types– Base58, Addresses, URLs, HD keys, Message signing, …

● P2P Protocol

Page 11: Libbitcoin slides

libbitcoin Tour

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 12: Libbitcoin slides

libbitcoin-blockchain

● High-performance blockchain database

● Custom-designed on-disk hash table

● Rich indexes for high-speed queries– Transactions

– Addresses

– Stealth

Page 13: Libbitcoin slides

libbitcoin Tour

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 14: Libbitcoin slides

libbitcoin-server

● Formerly known as “obelisk”

● Provides a low-level Blockchain API

● Uses ZeroMQ

Page 15: Libbitcoin slides

libbitcoin-server

● fetch_history

● fetch_transaction

● fetch_last_height

● fetch_block_header

● fetch_transaction_index

● fetch_stealth

● broadcast_transaction

● subscribe

Page 16: Libbitcoin slides

libbitcoin Tour

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 17: Libbitcoin slides

libbitcoin-client

● C++ wrapper around the libbitcoin-server RPC interface

● Server API calls are as easy as calling a C++ function

Page 18: Libbitcoin slides

darkwallet/python-obelisk

● For those who want to use libbitcoin-server from python

Page 19: Libbitcoin slides

darkwallet/gateway

● Bridges libbitcoin-server to Websockets

● For those who want to use libbitcoin-server from Javascript

Page 20: Libbitcoin slides

libbitcoin Tour

libbitcoin

libbitcoin-blockchain libbitcoin-client

libbitcoin-node

libbitcoin-server

libbitcoin-explorer

Server Stack Client Stack

Page 21: Libbitcoin slides

libbitcoin-explorer

● Short name is “bx”

● Replaces an earlier project called “sx”

● Command-line interface to lots of Bitcoin goodies

Page 22: Libbitcoin slides

libbitcoin-explorer

● Server Commands– fetch-balance, fetch-header, fetch-height, fetch-history, fetch-public-key, fetch-stealth, fetch-tx, fetch-tx-index, fetch-utxo

● Wallet– input-set, input-sign, input-validate, message-sign, message-validate, send-tx, send-tx-node, send-tx-p2p, tx-decode, tx-encode, tx-sign

Page 23: Libbitcoin slides

libbitcoin-explorer

● HD Keys– hd-new, hd-private, hd-public, hd-to-address, hd-to-ec, hd-to-public, hd-to-wif

● EC Math– ec-add, ec-add-secrets, ec-lock, ec-multiply, ec-multiply-secrets, ec-new, ec-to-address, ec-to-public, ec-to-wif, ec-unlock

● Hashes– bitcoin160, bitcoin256, sha160, sha256, sha512, ripemd160

Page 24: Libbitcoin slides

libbitcoin-explorer

● Format conversions– address-decode, address-encode– base16-decode, base16-encode– base58-decode, base58-encode– base64-decode, base64-encode– btc-to-satoshi, satoshi-to-btc– wif-to-ec, wif-to-public

● And lots more…

Page 25: Libbitcoin slides

Installing bx

● Available as a single-file pre-compiled binary:– https://github.com/libbitcoin/libbitcoin-

explorer/wiki/Download-BX

– Linux, OS X, and Windows!

● Or you can compile it yourself:– https://github.com/libbitcoin/libbitcoin-explorer

– Use the install.sh script for an hands-off compile, including dependencies

– Or follow the manual build instructions

Page 26: Libbitcoin slides

Installing libbitcoin-server

● Stable binaries are not yet available– Hopefully soon!

● Source code is here:– https://github.com/libbitcoin/libbitcoin-server

● To run:$ initchain$ bitcoin_server

Page 27: Libbitcoin slides

libbitcoin-server Servers

● https://wiki.unsystem.net/en/index.php/Obelisk/Servers

● The BX default is tcp://obelisk.airbitz.co:9091

● Feel free to use the AirBitz servers!

– If you install your own servers,please let us use them too

Page 28: Libbitcoin slides

Installing libbitcoin

● Source code is here:– https://github.com/libbitcoin/libbitcoin

Page 29: Libbitcoin slides

libbitcoin Example#include <bitcoin/bitcoin.hpp>#include <iostream>#include <string.h>

int main(){ char line[256]; std::cout << "Please enter a secret phrase: "; std::cin.getline(line, 256); bc::data_chunk seed(line, line + strlen(line));

bc::hash_digest hash = bc::sha256_hash(seed); std::cout << "Hash: " << bc::encode_base16(hash) << std::endl; std::cout << "Private key: " << bc::secret_to_wif(hash) << std::endl;

bc::payment_address address; bc::set_public_key_hash(address, bc::bitcoin_short_hash(bc::secret_to_public_key(hash))); std::cout << "Address: " << address.encoded() << std::endl; return 0;}

Page 30: Libbitcoin slides

libbitcoin Example - Header

#include <bitcoin/bitcoin.hpp>

Page 31: Libbitcoin slides

libbitcoin Example – Grab some text

char line[256];

std::cout << "Please enter a secret phrase: ";

std::cin.getline(line, 256);

bc::data_chunk seed(line, line + strlen(line));

Page 32: Libbitcoin slides

libbitcoin Example – Hashing

bc::hash_digest hash = bc::sha256_hash(seed);

std::cout << "Hash: " <<

bc::encode_base16(hash) << std::endl;

std::cout << "Private key: " <<

bc::secret_to_wif(hash) << std::endl;

Page 33: Libbitcoin slides

libbitcoin Example – Addresses

bc::payment_address address;

bc::set_public_key_hash(address,

bc::bitcoin_short_hash(

bc::secret_to_public_key(hash)));

std::cout << "Address: " <<

address.encoded() << std::endl;

Page 34: Libbitcoin slides

libbitcoin Example – Makefile

CXXFLAGS = $(shell pkg-config --cflags libbitcoin)

LIBS = $(shell pkg-config --libs libbitcoin)

test: test.o

$(CXX) -o test test.o $(LIBS)

test.o: test.cpp

$(CXX) -c -o test.o test.cpp $(CXXFLAGS)

Page 35: Libbitcoin slides

Future Plans

● New libbitcoin-server protocol– We want a full query language

– libbitcoin-protocol

● SPV client library– libitcoin-server is fast, so we don't want to lose that

– The client uses block headers to verify server responses

Page 36: Libbitcoin slides

Slides

● Slides are here:– http://www.slideshare.net/swansontec/libbitcoin-

slides