Skip to content

Repository files navigation

astrid-ws

WebSocket support for Astrid capsules (wasm32-unknown-unknown), built in user space over the net host function: rustls (RustCrypto provider, host-clock TimeProvider) + WebSocket framing over astrid_sdk::net::TcpStream. No host-ABI changes: WS/HTTP live in system space, not host space.

Layout

  • spikes/hello-wss — feasibility spike (PASSED 2026-07-11): from inside a capsule #[astrid::run] loop — TCP → TLS 1.3 → tungstenite HTTP 101 upgrade → NOSTR REQ → live EVENT from the Unicity relay in ~1.1 s, plus nostr::Keys::generate() at runtime.
  • vendor/ (repo root) — vendored patches required on wasm32-unknown-unknown, both upstreamable:
    • rustls-pki-types: compile UnixTime::now() (panicking stub) so rustls's std feature builds; clients with a custom TimeProvider never call it.
    • nostr: drop the browser-only wasm deps (getrandom+js, instant+wasm-bindgen) that break ComponentEncoder. Never call Timestamp::now() on wasm — feed time from the host clock.

The crate

astrid-ws/ — poll-friendly WebSocket client for Astrid capsules.

  • Core (WsClient<S: Read + Write>): resumable handshake, poll() that maps WouldBlockPending, queued sends flushed by later polls, auto-pong, graceful close. Unit-tested on the host against a real tungstenite server over an in-memory pipe.
  • astrid feature (wasm32 only): connect_ws / connect_wss over astrid_sdk::net::TcpStream, TLS via rustls (RustCrypto provider, webpki roots, host-clock TimeProvider).
  • getrandom02-shim feature: exposes getrandom02_fill (getrandom 0.2 → astrid:sys host CSPRNG). Registration must happen in YOUR capsule crate — getrandom 0.2 backends only register from the wasm root: getrandom02::register_custom_getrandom!(astrid_ws::getrandom02_fill) (full snippet in astrid-ws/src/rng.rs docs).

Consumers need the vendored rustls-pki-types patch in their workspace ([patch.crates-io]vendor/rustls-pki-types) until it is upstreamed.

Run-loop rule: capsules are single-threaded — call poll() on a tick (the stream read timeout is the tick length) and interleave your IPC handling. Never block forever.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages