# Rust and Dart library

[rust-joinstr](https://github.com/rust-joinstr/joinstr) is a Rust implementation of joinstr for wallet developers. It includes a nostr client, an Electrum client and a P2WPKH signer. It also has Dart and Flutter bindings for mobile wallets. Its research and development is sponsored by [Bull Bitcoin](https://www.bullbitcoin.com/).

| | |
|---|---|
| Language | Rust (2021 edition), Dart bindings with flutter_rust_bridge 2.12.0 |
| Wallet backend | Electrum server |
| Signer | P2WPKH hot signer from a BIP39 mnemonic |
| Tor | Optional SOCKS5 proxy for nostr and Electrum connections |
| License | MIT |
| Source | [github.com/rust-joinstr/joinstr](https://github.com/rust-joinstr/joinstr) |

## Crates

| Crate | Path | Purpose |
|---|---|---|
| `joinstr` | `rust/joinstr` | Pools, coinjoin rounds and the blocking `interface` API |
| `joinstr_wallet` | `rust/joinstr_wallet` | Wallet settings types |
| `simple_nostr_client` | `rust/simple_nostr_client` | Minimal nostr client |
| `simple_electrum_client` | `rust/simple_electrum_client` | Minimal Electrum client |
| `socks5` | `rust/socks5` | SOCKS5 client with remote DNS and a new Tor circuit per connection |
| `joinstr_flutter` | `dart` | Dart and Flutter bindings |

## Rust API

The `joinstr::interface` module has blocking functions that cover a full round.

| Function | Purpose |
|---|---|
| `list_coins(mnemonics, electrum_address, electrum_port, range, network, proxy)` | Scan a range of addresses of a BIP39 wallet for coins |
| `list_pools(back, timeout, relay, proxy)` | List pools announced on a relay in the last `back` seconds |
| `initiate_coinjoin(config: PoolConfig, peer: PeerConfig)` | Create a pool and run it until the coinjoin is broadcast |
| `join_coinjoin(pool: Pool, peer: PeerConfig)` | Join a pool and run it until the coinjoin is broadcast |

`initiate_coinjoin_with_progress` and `join_coinjoin_with_progress` take a callback that receives each step of the round, for a live progress view.

`PoolConfig` sets the denomination, fee rate, maximum duration, number of peers and network. `PeerConfig` sets the mnemonic, the Electrum server, the input coin, the output address, the relay, the network and an optional proxy such as `127.0.0.1:9050`.

Add it from git.

```toml
[dependencies]
joinstr = { git = "https://github.com/rust-joinstr/joinstr" }
```

## Dart and Flutter

`joinstr_flutter` wraps the same four functions through flutter_rust_bridge. Pools cross the boundary as JSON. The generated bridge code is committed, so the package builds as checked out from git. The package ships an Android example app and supports iOS.

```yaml
dependencies:
  joinstr_flutter:
    git:
      url: https://github.com/rust-joinstr/joinstr
      path: dart
```

Android apps that use the package must build with Gradle 8. The vendored cargokit calls `project.exec {}`, which Gradle 9 removed.

## Used by

The [Mutinynet bot](../getting-started/mutinynet.md) runs a joinstr pool every 30 minutes with a copy of rust-joinstr compiled for Cloudflare Workers.
