onionwire/crates/onionwire-sdk
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Hermes rust-dev 08a4accf37
All checks were successful
ci / test (pull_request) Successful in 3m37s
ci / sdk (pull_request) Successful in 10m7s
fix(sdk): surface Sent/Queued on send(), and build the SDK in CI
`Node::send()` became `Result<OutboxStatus, String>` in the local-outbox work,
which broke `crates/onionwire-sdk` (E0308 at src/lib.rs:195) — and nothing
noticed, because the SDK is a separate cargo workspace that root CI never
compiles and android-release.yml only builds on a v*.*.* tag.

- `Wire::send()` now returns `WResult<SendState>` (`Sent` | `Queued`) instead
  of swallowing the outcome as `()`. A queued send is local-only until the
  retry worker gets a circuit through, so the Kotlin boundary must be able to
  tell it apart from a delivered one.
- `ChatMessage` gains `delivery: Option<String>` ("sent" | "queued" |
  "sending" | "failed: <reason>"), populated from the message's outbox row;
  `None` for incoming messages. An outgoing row with no outbox row was accepted
  on the first attempt, so it reads "sent".
- New `sdk` job in `.forgejo/workflows/ci.yml`: `cargo test --locked` +
  `cargo clippy --locked --all-targets -- -D warnings` in `crates/onionwire-sdk`
  in the same rust:1.91-bookworm container, with its own target volume (the SDK
  resolves the root crate with rustls, so sharing the root job's target dir
  would thrash feature-unified artifacts).
- Drift found while un-rotting it: the SDK `Cargo.lock` was stale (missing
  `sha2`, added to the root crate by the zeroize work), so `--locked` failed;
  and the SDK README still said "no outbox, no spool in v1" and "identity keys
  in sqlite are plaintext", both untrue since the outbox and SQLCipher landed.

Tests: crates/onionwire-sdk 4 passed (2 new unit tests over the status
mapping), clippy clean; root `cargo test --locked` clean. The CI job body was
smoke-run locally in the same container image before being committed.
2026-09-12 15:16:38 -04:00
..
src fix(sdk): surface Sent/Queued on send(), and build the SDK in CI 2026-09-12 15:16:38 -04:00
tests fix(sdk): enable rustls' ring provider and install it in the init path 2026-09-10 22:03:40 -04:00
Cargo.lock fix(sdk): surface Sent/Queued on send(), and build the SDK in CI 2026-09-12 15:16:38 -04:00
Cargo.toml fix(sdk): enable rustls' ring provider and install it in the init path 2026-09-10 22:03:40 -04:00
README.md fix(sdk): surface Sent/Queued on send(), and build the SDK in CI 2026-09-12 15:16:38 -04:00
uniffi.toml feat(android): SDK AAR (UniFFI) + Compose APK, Arti rustls feature split 2026-09-10 18:20:19 -04:00

onionwire-sdk (Android)

Kotlin-facing UniFFI bindings over the same Rust crate the OnionWire Linux TUI runs on. An Android peer and a Linux peer that exchange invites interoperate — there is one protocol, not two.

This is not a WebView wrapper and not a client for a hosted service. Each install runs Arti in-process (arti-client 0.46, onion-service-client + onion-service-service), hosts its own v3 onion service, and dials friends' onions directly. There is no tor binary, no torrc, no Orbot as the pipe.

Locked protocol facts

Piece Rule
Identity ed25519 keypair. The pubkey is who you are.
Roster key friends.pubkey, UNIQUE. Petnames are local only.
Onion A locator, not an identity. It rotates.
Invite onionwire:v1:k=…:o=…:spk=…:sig=…
Crypto Noise IK (Noise_IK_25519_ChaChaPoly_BLAKE2s). spk is x25519.
Chat send Unreachable peer onion → the message goes to the local outbox and is retried with backoff. send() returns SendState.Sent or SendState.Queued. File transfer and payments stay fail-closed.
At rest The whole sqlite file is SQLCipher (key = Argon2id of the store passphrase), and chat bodies carry a second per-row ChaCha20-Poly1305 layer with row-bound AAD. Identity keys live in that same encrypted file.

Invite string

onionwire:v1:k=<ed25519 pubkey hex64>:o=<v3 onion address>:spk=<x25519 prekey hex64>:sig=<ed25519 sig hex128>
  • sig is ed25519 over onionwire-invite-v1 + 0x00-separated k, o, spk (hex/onion as they appear in the string). Decode still accepts the legacy raw concatenation so old invites verify. See docs/PROTOCOL.md.
  • A malformed, unsigned, or tampered invite is rejected before anything is stored.
  • Same k never creates a second friend. It updates the stored locator on the existing row. That is the whole point of keying the roster on the pubkey.
  • The invite carries no display name and no Monero address — those arrive later over the wire as signed prf frames, not through the invite.

Adding the AAR to another Android app

The SDK ships as onionwire-sdk-<version>.aar on the Forgejo release, with a matching .sha256.

// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        flatDir { dirs("libs") }   // or however you vendor the AAR
    }
}

// app/build.gradle.kts
dependencies {
    implementation(files("libs/onionwire-sdk-0.1.0.aar"))
}

Requirements:

  • minSdk >= 26. The AAR is built with the NDK against android-26.
  • abiFilters must include an ABI the AAR ships. The release AAR includes arm64-v8a. Add x86_64 at build time with -Ponionwire.abis=arm64-v8a,x86_64 if you need an emulator.
  • Keep uniffi.onionwire_sdk.** (see the AAR's consumer-rules.pro, applied automatically by AGP) if you enable R8.

Kotlin surface

Everything is a suspend fun — Arti bootstrap and onion publish take minutes. A send that cannot reach the peer comes back immediately as QUEUED (it is not a long retry inside the call): the message is stored locally and a background worker in the core keeps retrying it.

import uniffi.onionwire_sdk.*

// 1. Open (or create) the identity inside app-private storage.
//    `filesDir`, never external storage. Empty passphrase fails closed.
val wire: Wire = openWire(File(context.filesDir, "onionwire").absolutePath, passphrase)

// 2. Who you are, and where you are right now.
val fingerprint: String = wire.fingerprint()   // stable forever
val onion: String = wire.onion()               // changes on rotate

// 3. Invite out / invite in.
val mine: String = wire.invite()
val preview: InviteInfo = decodeInvite(pasted)  // verifies sig, stores nothing
val friend: FriendInfo = wire.addFriend(pasted)

// 4. Roster and chat.
val roster: List<FriendInfo> = wire.friends()
wire.setPetname(friend.pubkeyHex, "ada")
when (wire.send(friend.pubkeyHex, "hello wire")) {
    SendState.SENT   -> { /* the peer's onion took the frame */ }
    SendState.QUEUED -> { /* unreachable: stored in the local outbox and
                            retried in the background. Show it as pending —
                            it is local-only until a circuit takes it. */ }
}
val msgs: List<ChatMessage> = wire.messages(friend.pubkeyHex)
// msgs[i].direction == "out" -> msgs[i].delivery is "sent" | "queued" |
//   "sending" | "failed: <reason>"; null for incoming messages. Render the
//   queued and failed states distinctly from sent.

// 5. Locator rotation. Do NOT wire this to a single tap — the app that embeds
//    the SDK owns the typed confirmation.
val out: RotateOutcome = wire.rotateOnion()   // out.notified / out.friends

All peer references are lowercase hex strings so nothing Rust-shaped leaks into the AAR.

Building the bindings yourself

The Gradle task :sdk:uniffiBindgen runs, inside crates/onionwire-sdk:

cargo build --release --lib                       # host cdylib
cargo run --release --bin uniffi-bindgen -- generate \
  --library target/release/libonionwire_sdk.so \
  --language kotlin --out-dir <generated dir>

Do not hand-edit anything under android/sdk/build/generated/; it is a build output.

Why this crate has its own Cargo workspace

Arti's TLS backends are non-additive: exactly one of native-tls and rustls may be enabled in a given feature resolution. The Linux TUI keeps native-tls (OpenSSL, as it always has). Android has no OpenSSL in the NDK, so this crate selects rustls plus static-sqlite (no system libsqlite3 on Android). Two separate workspaces keep the two resolutions from colliding.