• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    C
  • License
    Other
  • Created over 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Useful primitives for wallets

libwally-core

Wally is a cross-platform, cross-language collection of useful primitives for cryptocurrency wallets.

Read the API documentation at https://wally.readthedocs.io.

Note that library interfaces may change slightly while the library design matures. Please see the CHANGES file to determine if the API has changed when upgrading.

Please report bugs and submit patches to Our github repository. If you wish to report a security issue, please read Our security reporting guidelines.

Documentation Status

Platforms

Wally can currently be built for:

  • Linux
  • Android
  • macOS
  • iOS
  • Windows
  • Embedded (e.g ESP-32)
  • WebAssembly

And can be used from:

  • C and compatible languages which can call C interfaces
  • C++ (see include/wally.hpp for C++ container support)
  • Python 3.x
  • Java
  • Javascript via node.js or web browser.

Building

# Initialise the libsecp sources (Needs to be run only once)
$ git submodule init
$ git submodule sync --recursive
$ git submodule update --init --recursive

# Build
$ ./tools/autogen.sh
$ ./configure <options - see below>
$ make
$ make check

Building on macOS

Using homebrew,

$ brew install gnu-sed

If you wish to enable the SWIG interface, you will need install the Java JDK 8 or newer, and install SWIG:

$ brew install swig

configure options

  • --enable-debug. Enables debugging information and disables compiler optimisations (default: no).
  • --enable-minimal. Minimises library size and memory requirements to target embedded or resource-constrained environments (default: no).
  • --enable-asm. Enables fast assembly language implementations where available. (default: enabled for non-debug builds).
  • --enable-export-all. Export all functions from the wally shared library. Ordinarily only API functions are exported. (default: no). Enable this if you want to test the internal functions of the library or are planning to submit patches.
  • --enable-swig-python. Enable the SWIG Python interface. The resulting shared library can be imported from Python using the generated interface file src/swig_python/wallycore/__init__.py. (default: no).
  • --enable-python-manylinux. Enable manylinux support for building PyPI compatible python wheels. Using the resulting library in non-python programs requires linking with libpython.so.
  • --enable-swig-java. Enable the SWIG Java (JNI) interface. After building, see src/swig_java/src/com/blockstream/libwally/Wally.java for the Java interface definition (default: no).
  • --enable-elements. Enables support for Elements features, including Liquid support.
  • --enabled-standard-secp. Excludes support for features that are unavailable in the standard libsecp256k1 library.
  • --enable-mbed-tls. Use mbed-tls hashing functions if available. This typically results in faster hashing on embedded platforms such as STM32. Note that the user must define MBEDTLS_SHA256_ALT and/or SOC_SHA_SUPPORT_PARALLEL_ENG matching the SOC support when compiling the library. (default: no)
  • --enable-coverage. Enables code coverage (default: no) Note that you will need lcov installed to build with this option enabled and generate coverage reports.
  • --disable-shared. Disables building a shared library and builds a static library instead.
  • --disable-tests. Disables building library tests.
  • --disable-clear-tests. Disables just the test_clear test (required to pass the test suite with some compilers).

Recommended development configure options

$ ./configure --enable-debug --enable-export-all --enable-swig-python --enable-swig-java --enable-coverage

Compiler options

Set CC=clang to use clang for building instead of gcc, when both are installed.

Python

For non-development use, you can install wally with pip as follows:

pip install wallycore==0.9.0

For python development, you can build and install wally using:

$ pip install .

It is suggested you only install this way into a virtualenv while the library is under heavy development.

If you wish to explicitly choose the python version to use, set the PYTHON_VERSION environment variable (to e.g. 3, 3.7 etc) before running pip or (when compiling manually) ./configure.

You can also install the binary wally releases using the released wheel files without having to compile the library, e.g.:

pip install wallycore-0.9.0-cp39-cp39m-linux_x86_64.whl

The script tools/build_python_manylinux_wheels.sh builds the Linux release files and can be used as an example for your own python projects.

Android

Android builds are currently supported for all Android binary targets using the Android NDK. The script tools/android_helpers.sh can be sourced from the shell or scripts to make it easier to produce builds:

$ export ANDROID_NDK=/opt/android-ndk-r23b # r22 is the minimum supported version
$ . ./tools/android_helpers.sh

$ android_get_arch_list
armeabi-v7a arm64-v8a x86 x86_64

# Prepare to build
$ ./tools/cleanup.sh
$ ./tools/autogen.sh

# See the comments in tools/android_helpers.sh for arguments
$ android_build_wally armeabi-v7a $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64 19 "--enable-swig-java"

The script tools/build_android_libraries.sh builds the Android release files and can be used as an example for your own Android projects.

WebAssembly

WebAssembly is available as a preview feature. Users may want to avoid using wally compiled for wasm for signing or encryption/decryption as the transpiled code may not remain constant time.

Building wally as wasm requires following emsdk instructions for your platform and sourcing the emsdk_env.sh file:

# Set up the environment variables for the toolchain
$ source $HOME/emsdk/emsdk_env.sh

# Optionally set the list of wally functions to export to wasm (default: all)
$ export EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_cleanup',...]"

# Build
$ ./tools/build_wasm.sh [--enable-elements]

Note that emsdk v3.1.27 or later is required.

The script tools/build_wasm.sh builds the wallycore.html example as well as the required wallycore.js and wallycore.wasm files, which can be used as an example for your own WebAssembly projects.

Open wallycore.html in a browser via a webserver like nginx or python2 -m SimpleHTTPServer 8000 to run the example.

Cleaning

$ ./tools/cleanup.sh

Submitting patches

Please use pull requests on github to submit. Before producing your patch you should format your changes using uncrustify version 0.60 or later. The script ./tools/uncrustify will reformat all C sources in the library as needed, with the currently chosen uncrustify options.

To reformat a single source file, use e.g.:

$ ./tools/uncrustify src/transaction.c

Or to reformat all source files, pass no arguments:

$ ./tools/uncrustify

If you have added new API functions in your patch, run tools/update_generated.sh to update the auto-generated support code for various platforms. This requires Python and the jq binary.

You should also make sure the existing tests pass and if possible write tests covering any new functionality, following the existing style. You can run the tests via:

$ make check

Python ctypes tests (in ./src/test/) are strongly preferred, but you can add to the other test suites if your changes target a specific language or your tests need to be written at a higher level of abstraction.

Generating a coverage report

To generate an HTML coverage report, install lcov and use:

$ ./tools/cleanup.sh
$ ./tools/autogen.sh
$ ./configure --enable-debug --enable-export-all --enable-swig-python --enable-swig-java --enable-coverage --enable-elements
$ make
$ ./tools/coverage.sh clean
$ make check
$ ./tools/coverage.sh

For coverage with clang, you need to install llvm-cov, typically via the llvm-<version> package that corresponds to your clang version. Once installed, set the GCOV environment variable to the versioned llvm-cov binary name before running ./tools/coverage.sh, e.g:

$ GCOV=llvm-cov-11 ./tools/coverage.sh clean
$ make check
$ GCOV=llvm-cov-11 ./tools/coverage.sh

The coverage report can be viewed at ./src/lcov/src/index.html. Patches to increase the test coverage are welcome.

Users of libwally-core

Projects and products that are known to depend on or use libwally:

Please note that some of the listed projects may be experimental or superseded.

More Repositories

1

lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
C
2,829
star
2

elements

Open Source implementation of advanced blockchain features extending the Bitcoin protocol
C++
1,044
star
3

lightning-charge

A simple drop-in solution for accepting lightning payments
JavaScript
553
star
4

secp256k1-zkp

Experimental fork of libsecp256k1 with support for pedersen commitments and range proofs.
C
288
star
5

simplicity

Simplicity is a blockchain programming language designed as an alternative to Bitcoin script.
C
243
star
6

paypercall

Charge for HTTP APIs on a pay-per-call basis with Bitcoin and Lightning âš¡
JavaScript
147
star
7

scriptless-scripts

Documentation about scriptless scripts
TeX
130
star
8

filebazaar

Sell digital files with Bitcoin & Lightning âš¡
JavaScript
120
star
9

woocommerce-gateway-lightning

A WooCommerce gateway for lightning payments
PHP
115
star
10

nanopos

A simple Lightning âš¡ point-of-sale system, powered by Lightning Charge
JavaScript
108
star
11

peerswap

Go
96
star
12

elementsproject.org

Source code for the ElementsProject.org website
CSS
90
star
13

nanotip

âš¡ Lightning Tip Box âš¡
JavaScript
85
star
14

lightning-charge-client-js

JavaScript client for lightning-charge
JavaScript
64
star
15

ifpaytt

If Pay Then That âš¡ Trigger IFTTT actions with Bitcoin Lightning payments
JavaScript
56
star
16

wordpress-lightning-publisher

âš¡ Lightning Publisher for WordPress
PHP
54
star
17

rust-elements

Rust support for Elements transaction/block deserialization
Rust
51
star
18

reserves

Proof-of-Reserves tool for Bitcoin
Rust
46
star
19

confidential-assets-demo

Confidential Assets Demo built on the Elements blockchain platform
Go
36
star
20

cross-input-aggregation

Thoughts on cross-input (signature) aggregation for Bitcoin
Rust
35
star
21

lightning-jukebox

A Lightning powered Jukebox âš¡ Pay with Bitcoin to choose your music.
JavaScript
35
star
22

rust-simplicity

C
34
star
23

elementsproject.github.io

https://elementsproject.org website
HTML
28
star
24

dicemix

Rust
24
star
25

lightning-charge-client-php

PHP client for lightning-charge
PHP
24
star
26

rust-secp256k1-zkp

C
23
star
27

cln-application

Core lightning application on Umbrel
TypeScript
21
star
28

ELIPs

Elements Improvement proposals
12
star
29

elements-miniscript

Rust
11
star
30

glightning

Go
7
star
31

peerswap-spec

7
star
32

borromean-signatures-writeup

TeX
6
star
33

elements-assets-exchange-demo

OTC-style exchange based on atomic swaps using Elements and confidential assets
JavaScript
5
star
34

qa-assets

Elements-related blobs used for quality assurance.
3
star
35

elementsbp-api-reference

[DEPRECATED: Moved to https://github.com/ElementsProject/elements/blob/elements-0.14.1/doc/elements-api.md] API Reference Documentation for the Elements Blockchain Platform
3
star
36

lightning-demos

2
star