Foreign language bindings for BDK (bdk-ffi)

This repository contains source code for generating foreign language bindings for the rust library bdk for the Bitcoin Dev Kit (BDK) project.

Supported target languages and platforms

Language Platform Status
Kotlin JVM WIP
Kotlin Android WIP
Swift iOS WIP

Getting Started

This project uses rust. A basic knowledge of the rust ecosystem is helpful.

General

  1. Install uniffi-bindgen
    cargo install uniffi_bindgen
    
  2. See the UniFFI User Guide for more info

Kotlin Bindings for JVM (OSX / Linux)

  1. Install required targets
      rustup target add x86_64-apple-darwin x86_64-unknown-linux-gnu
    
  2. Build kotlin (JVM) bindings
      ./build.sh -k
    
  3. Generated kotlin bindings are available at /bindings/bdk-kotlin/
  4. A demo app is available at /bindings/bdk-kotlin/demo/. It uses stdin for inputs and can be run from gradle.
    cd bindings/bdk-kotlin
    ./gradlew :demo:run
    

Kotlin bindings for Android

  1. Install required targets
    rustup target add x86_64-linux-android aarch64-linux-android
    armv7-linux-androideabi i686-linux-android
    
  2. Install Android SDK and Build-Tools for API level 30+
  3. Setup $ANDROID_NDK_HOME and $ANDROID_SDK_ROOT path variables (which are required by the build scripts)
  4. Build kotlin (Android) bindings
    ./build.sh -a
    
  5. A demo android app is available at notmandatory/bdk-sample-app

Swift bindings for iOS

  1. Install the latest version of xcode, download and install the advanced tools.
  2. Ensure Swift is installed
  3. Install required targets
    rustup target add aarch64-apple-ios x86_64-apple-ios
    
  4. Build swift (iOS) bindings
    ./build.sh -s
    
  5. Example iOS app can be found in /examples/iOS which can be run by xcode.

Notes

Adding new structs and functions

See the UniFFI User Guide

For pass by value objects

  1. create new rust struct with only fields that are supported UniFFI types
  2. update mapping bdk.udl file with new dictionary

For pass by reference values

  1. create wrapper rust struct/impl with only fields that are Sync + Send
  2. update mapping bdk.udl file with new interface

Goals

  1. Language bindings should feel idiomatic in target languages/platforms
  2. Adding new targets should be easy
  3. Getting up and running should be easy
  4. Contributing should be easy
  5. Get it right, then automate

Thanks

This project is made possible thanks to the wonderful work on mozilla/uniffi-rs

Description
Frost experimentation on bdk-ffi
Readme 22 MiB
Languages
Rust 64.6%
Kotlin 18.1%
Swift 9.5%
Python 4.6%
Shell 2.2%
Other 1%