Git Product home page Git Product logo

libnunchuk's Introduction

Nunchuk Logo

About

libnunchuk is a lean & cross-platform C++ multisig library powered by Bitcoin Core.

libnunchuk is used by the Nunchuk Desktop and Mobile applications.

Why Bitcoin Core

Why does libnunchuk reuse Bitcoin Core code?

  • Bitcoin Core is the unofficial spec of the Bitcoin protocol.
  • Bitcoin Core is the most peer-reviewed and battle-tested in all of Bitcoin.
  • Bitcoin Core has important protocol upgrades coming, such as Schnorr signatures and Taproot.

By leveraging Core, libnunchuk can gain access to powerful and reliable Bitcoin tools, while staying lean and cutting down on the number of dependencies.

Usage

Include <nunchuk.h> where you want to use libnunchuk.

#include <nunchuk.h>

using namespace nunchuk;

Create a Nunchuk instance.

// Create an AppSettings object to pass into the Nunchuk instance
AppSettings settings;
settings.set_chain(Chain::TESTNET);
settings.set_hwi_path("bin/hwi");
settings.enable_proxy(false);
settings.set_testnet_servers({"127.0.0.1:50001"});

auto nunchuk = MakeNunchuk(settings);
// ... use nunchuk as you like, see examples below

Examples

Get a list of plugged-in hardware devices.

auto devices = nunchuk.get()->GetDevices();

Create a new signer.

// ... using the first device returned from above
auto master_signer = nunchuk.get()->CreateMasterSigner(
    "signer_name", devices[0], [](int percent) { 
        // libnunchuk caches xpubs when adding a new master signer, so this method will take some time
        // Use this callback to check on the progress
        return true;
    });

Create a new multisig wallet.

// Nunchuk supports legacy, nested-segwit and native segwit addresses
AddressType address_type = AddressType::NATIVE_SEGWIT;

// Nunchuk supports multisig, singlesig and escrow wallets
WalletType wallet_type = WalletType::MULTI_SIG;

// Get a list of master signers that we manage
auto master_signers = nunchuk.get()->GetMasterSigners();

// Create 2 signers from the first 2 master signers
auto signer0 = nunchuk.get()->GetUnusedSignerFromMasterSigner(
    master_signers[0].get_id(), wallet_type, address_type);
auto signer1 = nunchuk.get()->GetUnusedSignerFromMasterSigner(
    master_signers[1].get_id(), wallet_type, address_type);

// Create a multisig (2/2) wallet
auto wallet = nunchuk.get()->CreateWallet("wallet_name", 2, 2,
    {signer0, signer1}, address_type, false);

Convenient util methods are also available in nunchuk::Utils.

auto xpub = Utils::SanitizeBIP32Input(Ypub, "xpub");
auto is_valid = Utils::IsValidXPub(xpub);
auto script_pub_key = Utils::AddressToScriptPubKey(address);

For more examples, see a simple multisig cli less than 300 LOC.

Setup

Generally we recommend using libnunchuk as a submodule in a larger CMake project.

$ cd your_project/
$ git submodule add https://github.com/nunchuk-io/libnunchuk
$ git submodule update --init --recursive

Add the following to your CMakeLists.txt.

add_subdirectory(libnunchuk)
target_link_libraries("${PROJECT_NAME}" PUBLIC nunchuk)

Build Bitcoin Core (details).

$ pushd libnunchuk/contrib/bitcoin
$ ./autogen.sh
$ ./configure --without-gui --disable-zmq --with-miniupnpc=no --enable-module-ecdh # important
$ make -j8
$ popd

Build Sqlcipher (details).

$ pushd libnunchuk/contrib/sqlcipher
$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
$ make -j8
$ popd

Build your project.

$ mkdir build && cd build
$ cmake ..
$ cmake --build .

HWI

A HWI binary is needed to interact with hardware devices.

Set the HWI path by calling set_hwi_path() on AppSettings.

Contributing

Run tests.

$ ctest

Install clang-format.

$ brew install clang-format

Config hooks directory.

$ git config core.hooksPath hooks

For VSCode user

Install clang-format plugins.

Format files using this shortcut: Ctrl+⇧+F on Windows, Ctrl+⇧+I on Linux, and ⇧+⌥+F on macOS.

(Optional) Enable formatOnSave in .vscode/settings.json.

{
    "editor.formatOnSave": true
}

Nunchuk Applications

The Nunchuk Desktop and Mobile apps are available at https://nunchuk.io.

Read about our design philosophy at:

License

libnunchuk is released under the terms of the GPLv3 license. See COPYING for more information or see http://www.gnu.org/licenses/.

libnunchuk's People

Contributors

bakaoh avatar batatsar avatar giahuy98 avatar hugohn avatar giahuyng98 avatar maxhillebrand avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.