forked from MetaMask/bdk-wasm
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: upgrade BDK to 2.3.0 and wrap new APIs #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c953dc
chore(deps): upgrade bdk_wallet to 2.3.0 and bdk_esplora to 0.22.1
23c3e0d
feat: wrap Wallet::create_from_two_path_descriptor (BIP-389)
efc859d
feat: wrap TxBuilder exclude_unconfirmed and exclude_below_confirmations
47cd31a
fix: suppress deprecated SignOptions warnings with allow(deprecated)
82461b4
docs: add CLAUDE.md with agent instructions and project conventions
621e715
docs: add conventional commit types reference to CLAUDE.md
c0cfcb9
fix(tx_builder): delegate exclude_below_confirmations to BDK builder
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # CLAUDE.md - Agent Instructions for bdk-wasm | ||
|
|
||
| ## Overview | ||
|
|
||
| WASM bindings for [BDK](https://github.com/bitcoindevkit/bdk_wallet) (Bitcoin Dev Kit). | ||
| Wraps `bdk_wallet` for use in browsers and Node.js via `wasm-bindgen`. | ||
|
|
||
| **Used in production by MetaMask Bitcoin Snap (~30M+ AUM). Treat all changes with extreme care.** | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── lib.rs # Crate root, re-exports | ||
| ├── bitcoin/ # Core wallet functionality wrappers | ||
| │ ├── wallet.rs # Wallet (create, load, sign, sync, addresses, UTXOs) | ||
| │ ├── tx_builder.rs # Transaction builder | ||
| │ ├── esplora_client.rs # Esplora blockchain client (behind `esplora` feature) | ||
| │ ├── descriptor.rs # Descriptor utilities | ||
| │ └── wallet_tx.rs # Wallet transaction wrapper | ||
| ├── types/ # WASM-compatible type wrappers (From/Into pattern) | ||
| │ ├── address.rs, amount.rs, balance.rs, block.rs, chain.rs, | ||
| │ │ changeset.rs, checkpoint.rs, error.rs, fee.rs, input.rs, | ||
| │ │ keychain.rs, network.rs, output.rs, psbt.rs, script.rs, | ||
| │ │ slip10.rs, transaction.rs | ||
| │ └── mod.rs | ||
| └── utils/ # Helpers (descriptor utils, panic hook, result type) | ||
| ``` | ||
|
|
||
| ### Pattern | ||
|
|
||
| Every BDK type is wrapped with a WASM-compatible struct that: | ||
| 1. Holds the inner BDK type | ||
| 2. Implements `From<BdkType>` and `Into<BdkType>` conversions | ||
| 3. Exposes methods via `#[wasm_bindgen]` | ||
|
|
||
| `Wallet` uses `Rc<RefCell<BdkWallet>>` because `wasm_bindgen` doesn't support Rust lifetimes. | ||
| `TxBuilder` shares the wallet reference via `Rc<RefCell<>>` and builds its own parameter set, | ||
| then calls the real BDK builder in `finish()`. | ||
|
|
||
| ## Building | ||
|
|
||
| Requires: Rust stable, `wasm-pack`, `wasm32-unknown-unknown` target. | ||
|
|
||
| ```bash | ||
| # Browser target (default) | ||
| wasm-pack build --all-features | ||
|
|
||
| # Node.js target | ||
| wasm-pack build --target nodejs --all-features | ||
|
|
||
| # Specific features | ||
| wasm-pack build --features esplora | ||
| wasm-pack build --features debug,esplora | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Browser tests (Rust) | ||
| ```bash | ||
| wasm-pack test --chrome --firefox --headless --features debug,default | ||
| wasm-pack test --chrome --firefox --headless --features debug,esplora | ||
| ``` | ||
|
|
||
| ### Node.js tests (TypeScript/Jest) | ||
| ```bash | ||
| cd tests/node | ||
| yarn install --immutable | ||
| yarn build # runs wasm-pack build --target nodejs --all-features | ||
| yarn test # runs jest | ||
| yarn lint # runs eslint | ||
| ``` | ||
|
|
||
| Node tests are in `tests/node/integration/`: | ||
| - `wallet.test.ts` — Wallet creation, addresses, descriptors | ||
| - `esplora.test.ts` — Esplora sync, full scan, transaction sending (uses **Mutinynet signet**) | ||
| - `utilities.test.ts` — Amount, Script, Address utilities | ||
| - `errors.test.ts` — Error handling and error codes | ||
|
|
||
| **Note:** `esplora.test.ts` depends on Mutinynet signet (`https://mutinynet.com/api`) with a | ||
| pre-funded test wallet. This test can be flaky if the faucet/signet is down. | ||
|
|
||
| ### CI | ||
|
|
||
| GitHub Actions runs on every PR: | ||
| - **Lint:** `cargo fmt --check` + `cargo clippy --all-features --all-targets -- -D warnings` | ||
| - **Browser build:** Three matrix configs (all features, debug+default, debug+esplora) | ||
| - **Node build + test:** Full wasm-pack build + Jest test suite | ||
|
|
||
| CI must be green before merging. Clippy treats warnings as errors (`-D warnings`). | ||
|
|
||
| ## Features | ||
|
|
||
| - `default` — Core wallet functionality only | ||
| - `esplora` — Adds `EsploraClient` for blockchain sync (enables `bdk_esplora` + `wasm-bindgen-futures`) | ||
| - `debug` — Enables `console_error_panic_hook` for better WASM error messages | ||
|
|
||
| ## Dependencies | ||
|
|
||
| Key dependencies (keep these in sync): | ||
| - `bdk_wallet` — Core wallet library | ||
| - `bdk_esplora` — Esplora client (must match `bdk_wallet` version series) | ||
| - `bitcoin` — Bitcoin primitives | ||
| - `wasm-bindgen` — Rust/JS interop | ||
|
|
||
| Check https://crates.io/crates/bdk_wallet/versions for latest releases. | ||
| BDK uses a monorepo-ish approach: `bdk_wallet` and `bdk_esplora` versions must be compatible. | ||
|
|
||
| ## Conventions | ||
|
|
||
| - **Conventional commits** (required for all commits and PR titles): | ||
| - `feat:` — New feature or API wrapper | ||
| - `fix:` — Bug fix | ||
| - `refactor:` — Code restructuring without behavior change | ||
| - `docs:` — Documentation only | ||
| - `test:` — Adding or updating tests | ||
| - `chore:` — Maintenance (deps, config, tooling) | ||
| - `ci:` — CI/CD pipeline changes | ||
| - `build:` — Build system changes | ||
| - Scope is optional but encouraged: `feat(wallet):`, `fix(tx_builder):`, `chore(deps):` | ||
| - Breaking changes: add `!` after type, e.g. `feat!:` or `feat(wallet)!:` | ||
| - These prefixes feed into CHANGELOG.md generation | ||
| - **Formatting:** `cargo fmt` with default settings | ||
| - **All public items must be documented** | ||
| - **Safe Rust only** — no `unsafe` without exceptional justification | ||
| - **New features require tests** | ||
|
|
||
| ## Known Issues | ||
|
|
||
| - `SignOptions` is deprecated in BDK 2.2.0+ (signer module moved to `bitcoin::psbt`). | ||
| We use `#[allow(deprecated)]` until BDK provides a migration path, since `Wallet::sign` | ||
| still requires it internally. | ||
| - Esplora integration tests use Mutinynet signet which can be flaky. | ||
|
|
||
| ## Maintenance Notes | ||
|
|
||
| - This repo is maintained by an AI agent (Toshi) with human review by @darioAnongba | ||
| - All changes go through PRs — never push to main directly | ||
| - One PR at a time to keep review manageable | ||
| - Check BDK releases periodically for new APIs to wrap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.