9866649fdc5ffe0203f5a76082d789a22e5214bf Added Mnemonic Interface (dhruvbaliyan) Pull request description: ### Description This PR adds `interface Mnemonic` which will make the API to generate new DescriptorSecretKey have type-safe arguments. <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ### Notes to the reviewers This PR doesn't have any issue linked to it, as it was discusses on a call during the implementation of `DescriptorSecretKey` (PR #154). It was discussed to make `Mnemonic` an interface and use that instead of string `Mnemonic` so that the API to generate `DescriptorSecretKey` doesn't have any potential failure (like in case it's provided with incorrect Mnemonic words). APIs added ``` // generates and returns Mnemonic with random entropy Mnemonic::new(word_count: WordCount) -> Self { ... } // converts string Mnemonic to Mnemonic type with error (in case of incorrect string Mnemonic) Mnemonic::from_str(mnemonic: String) -> Result<Self, BdkError> { ... } // generates and returns Mnemonic with given entropy Mnemonic::from_entropy(entropy: Vec<u8>) -> Result<Self, BdkError> {...} // view mnemonic as string Mnemonic::as_string(&self) -> String { ... } ``` Along with some changes to `DescriptorSecretKey::new()` to fit these new APIs ### Changelog notice ``` - Added Struct Mnemonic with following methods [#219] - new(word_count: WordCount) generates and returns Mnemonic with random entropy - from_str(mnemonic: String) converts string Mnemonic to Mnemonic type with error - from_entropy(entropy: Vec<u8>) generates and returns Mnemonic with given entropy - as_string() view Mnemonic as string - API removed [#219] - generate_mnemonic(word_count: WordCount) [#219](https://github.com/bitcoindevkit/bdk-ffi/pull/219) ``` ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added docs for the new feature #### Bugfixes: * [x] This pull request breaks the existing API * Top level function `generate_mnemonic(...)` was removed ACKs for top commit: thunderbiscuit: ACK 9866649fdc5ffe0203f5a76082d789a22e5214bf. notmandatory: ACK 9866649fdc5ffe0203f5a76082d789a22e5214bf Tree-SHA512: 45f9158beb6fe7bfe2a901c3f17126db855fe0b4b479ecb2a16381e06a415eed295fe6be3c840bd1d1fc8cffaf58bd97dc27bdc1e82699367a827d700e8fd09b
Native language bindings for BDK
The workspace in this repository creates the libbdkffi
multi-language library for the rust based
bdk library from the Bitcoin Dev Kit project. The bdk-ffi-bindgen
package builds a tool for
generating the actual language binding code used to access the libbdkffi
library.
Each supported language has its own repository that includes this project as a git submodule. The rust code in this project is a wrapper around the bdk library to expose it's APIs in a uniform way using the mozilla/uniffi-rs bindings generator for each supported target language.
Supported target languages and platforms
The below repositories include instructions for using, building, and publishing the native language binding for bdk supported by this project.
Language | Platform | Repository |
---|---|---|
Kotlin | jvm | bdk-kotlin |
Kotlin | android | bdk-kotlin |
Swift | iOS, macOS | bdk-swift |
Python | linux, macOS | bdk-python |
Language bindings generator tool
Use the bdk-ffi-bindgen
tool to generate language binding code for the above supported languages.
To run bdk-ffi-bindgen
and see the available options use the command:
cargo run -p bdk-ffi-bindgen -- --help
Contributing
Adding new structs and functions
See the UniFFI User Guide
For pass by value objects
- create new rust struct with only fields that are supported UniFFI types
- update mapping
bdk.udl
file with newdictionary
For pass by reference values
- create wrapper rust struct/impl with only fields that are
Sync + Send
- update mapping
bdk.udl
file with newinterface
Goals
- Language bindings should feel idiomatic in target languages/platforms
- Adding new targets should be easy
- Getting up and running should be easy
- Contributing should be easy
- Get it right, then automate
Thanks
This project is made possible thanks to the wonderful work by the mozilla/uniffi-rs team.