Commit graph onionwire/crates/onionwire-sdk
Author SHA1 Message Date
agent
7cf98bb9fe
feat(android): wallet screen and SDK payment surface
Some checks failed
ci / test (pull_request) Failing after 4m1s
ci / sdk (pull_request) Successful in 1m27s
Expose wallet balance/address/transfers plus one-shot invoice and tip on
the UniFFI SDK. Wire a Compose wallet route (QR, composers) without dropping
wipe-chat. Ignore machine-local android/.cargo NDK paths.
2026-09-13 15:27:57 -04:00
rust-dev
7b68cb4a9f
feat(sdk): ChatMessage.id — join a chat row to its outbox row
`OutboxRow::message_id` documents itself as *the* join key (the
`messages.id` a `ChatMessage` belongs to), but the record carried no id,
so the Android client could only pair the two lists positionally.

Add `ChatMessage.id: i64` as the first field, copied straight from the
`messages.id` the store already selects. Additive over UniFFI: Kotlin
consumers only gain a constructor field and the bindings regenerate.

The id mapping moves into a `chat_message` helper so the join property is
testable without a Node: the new test builds a real store, queues an
outbox row for a message, and asserts the id on the message equals the
`message_id` the outbox row reports for that same row.

# Conflicts:
#	crates/onionwire-sdk/src/lib.rs
2026-09-12 19:16:45 -04:00
rust-dev (hermes)
56bd8845e7
feat(sdk): expose the outbox rows behind a queued chat message
The TUI can say why a queued row is still queued ('queued (try n/8,
retry 45s)') because it reads OutboxEntry::attempts and next_attempt_at
directly. The SDK exposed neither: ChatMessage.delivery is a flat
'queued'/'sending'/'failed: <reason>' string and Wire had no outbox
accessor, so an Android chat row could only invent a countdown.

Adds OutboxRow { message_id, status, attempts, next_attempt_at,
last_error } and Wire::outbox(pubkey_hex) over Node::outbox_pending, plus
outbox_max_attempts() so the client renders 'try n/8' against the core's
own budget instead of a hardcoded 8. Additive: Wire::send() and
ChatMessage.delivery are untouched.

# Conflicts:
#	crates/onionwire-sdk/src/lib.rs
2026-09-12 19:16:45 -04:00
agent
f2dcd79d5c
fix(sdk): surface Sent/Queued on send(), and build the SDK in CI
All checks were successful
ci / test (pull_request) Successful in 3m56s
ci / sdk (pull_request) Successful in 53s
Node::send() became Result<OutboxStatus, String> in the local-outbox work,
which broke crates/onionwire-sdk — and nothing noticed, because the SDK is a
separate cargo workspace that root CI never compiles.

- Wire::send() returns WResult<SendState> (Sent | Queued)
- ChatMessage.delivery for outgoing rows
- New sdk job in ci.yml (own target volume; rustls workspace)
- Refresh SDK Cargo.lock + README (SQLCipher / outbox facts)

Rebased onto main after #50/#54: no src/node.rs changes (WAL checkpoint lives
in Store now). README at-rest claims kept from #55.
2026-09-12 19:16:42 -04:00
agent
48c06df2cf
docs(sdk): Wire::shutdown doc said the second call returns Ok; it returns Stopped
All checks were successful
ci / test (pull_request) Successful in 4m22s
The handle-level call takes the node out on the first shutdown, so a second
call reports the typed `WireError::Stopped` (covered by
`calls_after_shutdown_are_typed_errors_not_panics`). Only the node-level
`Node::shutdown()` is Ok-idempotent. The rustdoc claimed otherwise.
2026-09-12 15:26:17 -04:00
apk-dev
38fde75d40
feat(core,sdk): explicit Tor lifecycle — stop, flush, observable state
A node had no way to stop. `Wire` was a bare handle over a `Node`: dropping the
Kotlin reference left Arti's client, the hosted v3 onion service, the outbox
retry worker and the sqlite connection alive, and there was no way to ask where
the onion service was. On Android the process is killed without warning by Doze
and the background-process killer, so "drop everything when the process dies" is
not a lifecycle.

Core (`src/node.rs`, `src/hs.rs`):

* `Node::shutdown()` — bounded outbox drain (10s), stop the onion service (the
  rendezvous task is aborted and the RunningOnionService dropped), abort the
  retry worker, checkpoint the sqlite WAL. Idempotent at this level: the flag is
  swapped first, so a racing second call is a no-op.
* `Node::flush() -> FlushOutcome { attempted, delivered, remaining }` — one
  delivery attempt for every queued outbox row, ignoring backoff, then a WAL
  checkpoint. Bounded by 30s because a dead peer's onion holds a dial for ~20s
  and the caller is a UI thread. A timeout leaves rows in `sending`;
  `Outbox::reset_stale` requeues them on the next unlock, same as a process that
  died mid-attempt.
* `Node::tor_state() -> TorState` (`Bootstrapping` / `Published` /
  `DegradedReachable` / `Stopped`) and `hs::tor_state_of(state, stopped,
  reachable)`, which mirrors `hs_is_ready` exactly instead of re-deriving
  readiness.
* Every network entry point (`send`, `send_once`, `connect_onion`, `rotate`,
  `flush`) fails with a typed error after the node stops, rather than dialing a
  dead client.
* `checkpoint_wal` reaches the database through a short-lived second connection:
  `Store` owns the write connection and does not lend it out, and a checkpoint is
  a property of the database, not of one connection. Best effort — WAL replay on
  open recovers anything committed.

The `WorkerHandle` moved into a `Mutex<Option<...>>` so the teardown can *abort*
the retry worker instead of only dropping it when the whole `Node` dies.

SDK (`crates/onionwire-sdk/src/lib.rs`):

* `Wire.shutdown()`, `Wire.flush(): FlushOutcome`, `Wire.torState(): TorState`.
  `Wire` now holds `Mutex<Option<Arc<Node>>>`, so teardown drops the last
  reference to the Tor client and the store instead of keeping them alive behind
  a JNI handle.
* `WireError::Stopped` — a second flat variant, so "you must unlock again" is a
  typed `WireException.Stopped` in Kotlin, not a string match on `Failed`.
* No `unwrap()` on a poisoned mutex anywhere: a poisoned handle reports
  `Stopped`, which is the correct recovery (unlock again).
* Fixes the crate not compiling on this base at all: `Node::send` has returned
  `Result<OutboxStatus, String>` since the outbox landed, and the SDK still
  mapped it to `Result<(), String>` (E0308). CI's path allowlist excludes
  `crates/**` from the Rust job, which is why it stayed green.

The live Tor test found a real bug in the first version of `tor_state`: Arti's
combined status is still `Bootstrapping` after a *successful* probe of our own
onion (that mismatch is what the 360s publish wait exists for), and a freshly
launched service reports `Shutdown` before its publish reactor starts — so a
node that was live and reachable reported `Bootstrapping`, and briefly
`Stopped`, right after unlock. `Node` now tracks an `onion_reachable` flag set
when the publish bar is crossed and cleared when `rotate` hard-cuts the service,
and `Shutdown`/`Broken` on a live node read `Bootstrapping` (transient) rather
than terminal.
2026-09-12 15:10:29 -04:00
Sirius DevOps
22b3a0062a
docs: add PROTOCOL.md and retire the stale audit writeup
All checks were successful
ci / test (pull_request) Successful in 3m7s
Wire format lives in docs/PROTOCOL.md so the handshake, invite, and
frames can be read without the Rust. Threat model points at it. The
in-house audit notes are a finding-status table, not a third-party
audit. SDK README no longer claims the legacy concat invite signature
is what we encode.
2026-09-11 13:15:51 -04:00
Sirius DevOps
d2d3b0c827
fix(sdk): enable rustls' ring provider and install it in the init path
All checks were successful
ci / test (pull_request) Successful in 3m30s
GREEN. rustls 0.23 selects its CryptoProvider from its own 'ring' /
'aws-lc-rs' crate features. Arti reaches rustls through tor-rtcompat with
default-features = false and nothing in this workspace turned a provider
feature on, so rustls was compiled with zero providers and the first TLS
config built from the process default panicked:

    Could not automatically determine the process-level CryptoProvider from
    Rustls crate features. ...

That is the 'Failed to start' screen on the unlock path. The 'ring' crate
being present in the graph (via snow, for Noise) never had anything to do
with it.

'ring', not 'aws-lc-rs': aws-lc-rs wants CMake and a C toolchain for the
NDK and fights the cross-compile.

Belt and braces: open_wire() now calls install_crypto_provider() before
Node::start_with_passphrase, a OnceLock-guarded
ring::default_provider().install_default() with the already-installed Err
ignored. That keeps the cdylib correct regardless of how a consumer's
feature graph resolves rustls.

aws-lc-rs is absent from the lock, so there is no two-provider conflict to
report.

Evidence:
  cargo test --release --test provider_resolution
    before: panicked at rustls-0.23.44/src/crypto/mod.rs:249 (device message)
    after:  1 passed
  cargo tree -f '{p} [{f}]' -p rustls
    rustls v0.23.44 [log,logging,ring,std,tls12]
2026-09-10 22:03:40 -04:00
Sirius DevOps
411194a8b2
test(sdk): reproduce rustls CryptoProvider panic from the device
RED. The APK builds, installs and opens, but the first rustls config built
from the process default panics one call deep inside Arti's rustls backend:

    Could not automatically determine the process-level CryptoProvider from
    Rustls crate features.
    Call CryptoProvider::install_default() before this point ...

rustls 0.23 picks its provider from its own 'ring' / 'aws-lc-rs' crate
features, not from which crypto crates happen to be linked. Arti reaches
rustls via tor-rtcompat with default-features = false, so neither provider
feature is on and rustls compiles with zero providers. 'ring' does appear in
cargo tree, pulled in by snow for Noise -- unrelated and irrelevant.

This commit adds rustls as an explicit dependency with no provider feature
(no behaviour change: it is already in the graph that way) so the test can
name the type, plus the regression test. On the host it reproduces the
device's panic verbatim.

The SDK lockfile is resynced with the root Cargo.toml on main (onionwire
0.2.1, rpassword, md-5, rtoolbox) in the same commit so the test build is
against a consistent lock.
2026-09-10 22:02:02 -04:00
apk-dev
672f2c9990
feat(android): SDK AAR (UniFFI) + Compose APK, Arti rustls feature split
All checks were successful
ci / test (pull_request) Successful in 3m22s
Adds the Android product alongside the existing Linux TUI, in one repo.

SDK — crates/onionwire-sdk is a UniFFI facade over the very same `onionwire`
crate the TUI runs on. Identity, invite, friend upsert, send/receive, rotate
and wipe all delegate; no protocol is reimplemented, so an Android peer and a
Linux peer interoperate. It is its own Cargo workspace because Arti's TLS
backends are non-additive: the TUI keeps native-tls (OpenSSL), Android needs
rustls + static-sqlite (no OpenSSL, no system libsqlite3 in the NDK).

android/ — Gradle project. :sdk produces the AAR (Kotlin bindings generated at
build time + libonionwire_sdk.so via cargo-ndk), :app is a Kotlin/Compose/M3
messenger depending on :sdk only. minSdk 26, targetSdk/compileSdk 36,
INTERNET-only, data in filesDir, backups excluded.

Root Cargo.toml grows `native-tls` (default) and `rustls` features so exactly
one Arti TLS backend is selected per build graph. The default build is
unchanged: same backend, ratatui still a normal dependency, src/tui.rs
untouched.

Also: Store::self_fingerprint/set_petname + Node wrappers (additive only),
scripts/build-android-local.sh, README sections, .gitignore for local SDK paths.
2026-09-10 18:20:19 -04:00