bitcoindevkit / bitcoindevkit.org

BDK project home page (originally magicalbitcoin.org 🧙)

Home Page:https://bitcoindevkit.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

High level write-up of what you can do with bdk-ffi

thunderbiscuit opened this issue · comments

I was discussing with someone what you could do with bdk and bdk-kotlin at the moment, and it occurred to me that the API is currently small enough that you could write it all up in a single, simple, high-level-plain-english list. I'm not sure if this issue is the best place to host such a thing, but I figured we could discuss where else to put it if it really mattered, or simply point people to it here.

Please let me know if I can add/adjust things in there.

What can you do with bdk-ffi as of 0.3.0?

Keys

  • Generate a BIP32 Root Key, with or without a passphrase, choosing from 12, 15, 18, 21, or 24 words
  • Restore a BIP32 Root Key (root xprv) from a set of 12, 15, 18, 21, or 24 word recovery phrase, including with or without a passphrase.

Wallets

  • Load up a wallet using a descriptor
  • Sync a wallet using Electrum or Esplora
  • Query the library to know what network it is using
  • Get the balance of a wallet
  • Query the wallet to get the last unused receive address is knows about
  • Query the wallet to get a new receive address
  • Create watch-only wallets

Transactions

  • Create a PSBT with:
    • 1 recipient
    • variable fee rate
  • Sign a PSBT
  • Broadcast a signed PSBT
  • Get a list of transactions the wallet knows about. Each transaction is either confirmed or unconfirmed, and comes with transaction details, namely:
    • fees
    • sats sent
    • sats received
    • txid
  • If the transaction is confirmed, it also has a data structure which contains:
    • block height
    • block timestamp

Here is a rough list of features other popular mobile wallets offer that you currently cannot do with bdk-ffi:

  • Display derivation path for given address (Green, Samourai, Blue)
  • Sign/Verify message (Blue)
  • Add accounts to wallets (Blue, Green)
  • Request amount (Green, Samourai)
  • Enable Replace-by-Fee (BIP125) (Samourai)
  • UTXO selection (Samourai)
  • BIP47 (Samourai)
  • Add entropy (dice for example) to your wallet creation (Blue)
  • Pay to multiple recipients (Blue, Samourai)
  • Send all (Green)

Chatted with @thunderbiscuit and would like to make this a feature matrix section in the web docs. Showing feature supported for: bdk, bdk-cli(?), bdk-kotlin, bdk-swift, bdk-python.

FYI I did a high level write up for my talk at BitDevsLA this weekend. It might be useful info for this discussion on how to document BDK features. I broke the BDK features into two groups, I called them "Basic" and "Advanced", the "Basic" ones are supported on all platforms, and the "Advanced" only in Rust. Over time features should be moving from the "Advanced" to "Basic" (maybe I should have called it "Multi-platform"?) side.

Basic Features (Rust, Kotlin, Swift, Python)

  • Descriptor defined spending conditions
  • Top level descriptor and address types
    • Legacy: PK, PKH, SH(WPKH), SH(WSH), SH
    • Segwitv0 (Bech32): WPKH, WSH
    • Segwitv1 (Bech32m, Taproot): TR
  • Hierarchical Deterministic (HD) key paths
  • Networks: regtest, signet, testnet, bitcoin
  • Pluggable blockchain clients
    • Electrum, optional SOCKS5 proxy
    • Esplora, optional SOCKS5 proxy
    • Received TX verified against core consensus rules
    • SOCKS5 Proxy configuration
  • Generate/restore master key mnemonic
    • 12-24 words with optional password
  • Pluggable databases for wallet data
    • SQLite
    • Memory
  • Wallet functions
    • Get new address
    • List Transactions
    • Get Balance
    • Create, sign, combine and Finalize PSBT
    • Branch and bound coin selection
    • Sync blockchain data
    • Manual coin control
    • Drain wallet
    • Replace by Fee
    • Single recipient and amount
    • Multiple recipients and amounts (batch payment)
    • Add OP_RETURN output
    • Set TX fee rate or absolute fee
    • Supported Operating Systems: Linux, MacOS, Android, iOS

Advanced Features (Rust Only)

  • Descriptor templates: BIP44 (PKH), BIP49 (SH_WPKH), BIP84 (WPKH)
  • More pluggable blockchain clients
    • Compact block filters, single peer
    • Core RPC, cookie or passwd auth
  • Pluggable coin selection
    • Custom user provided algorithm
    • Oldest first
    • Largest first
  • Pluggable signers
    • HWI (desktop)
  • Create bump fee transaction PSBT
  • Extract and display spending policies
  • More wallet functions
    • RBF with optional output shrinking
    • Select descriptor spending policy path
    • Add foreign UTXOs
  • Compile spending policy to miniscript
  • View descriptor spending policy
  • Blocking or async IO support
  • Wasm compatible (Esplora blockchain client only)
  • Supported Operating Systems: Linux, MacOS

Oh that's a nice way to think about them. Eases the burden of thinking of 5 different sets of features, and simplifies the mental model. "The full thing is in Rust, the other languages have access to a subset".

I agree with you over time the name "Basic" might not reflect properly the set of features, but for now I think it's ok. I have other ideas but nothing that really hits the nail on the head so far:

  • All supported languages
  • Rust

  • Rust
  • All libraries

How about "Rust" and "Language Bindings"?

We can have a few words on how the core of the library is written and Rust, and that we are porting some of it to other languages through language bindings. Then right into the high-level write-up of what you can do with it.

BDK is meant for application developers to leverage bitcoin, including developers whose primary expertise is not the bitcoin protocol (through the availability of high-level constructs and the removal of footguns in the lower-level constructs bdk leverages). Let's keep this idea moving, because I really think a page like this would add to the offering of the library, by speaking the language of the devs coming on the website and shopping for a library to use for bitcoin work.

Not even a few hours apart on the Discord server:
Dev 1:
Screen Shot 2022-04-11 at 1 28 41 PM

Dev 2:
Screen Shot 2022-04-11 at 1 28 55 PM
Screen Shot 2022-04-11 at 1 29 07 PM