Pubky SDK (Rust)
Ergonomic building blocks for Pubky apps: a tiny HTTP/PKARR client, session-bound agent, a drive API, signer helpers, and a pairing-based auth flow for keyless apps.
Rust implementation of Pubky SDK.
Install
# Cargo.toml
[]
= "0.x" # this crate
# Optional helpers used in examples:
# pubky-testnet = "0.x"
Quick start
use *; // pulls in the common types
# async
Concepts at a glance
Transport:
PubkyHttpClientstateless transport: PKARR-aware HTTP with sane defaults.
High level actors:
PubkySignerhigh-level signer (keypair holder) withsignup,signin, publishing, and pairing auth approval.PubkyAgentsession-bound identity (holds aSession& cookie). Useagent.drive()for reads/writes.PubkyPairingAuthpairing auth flow for keyless apps via an HTTP relay.PubkyDrivesimple file-like API:get/put/post/patch/delete, plusexists(),stats()andlist().Pkdnsresolve/publish_pubkyPkarr records (read-only viaPkdns::new(), publishing when created from aPubkySigner).
Pairing auth (keyless apps)
# use *;
# async
Relay & reliability
- If you don’t pass a relay, we default to a Synonym-hosted instance. If that relay is down, logins won’t complete.
- For production and bigger apps, run your own relay (MIT, dockerable): https://httprelay.io
Derive the channel as
base64url(hash(secret)); the token is end-to-end encrypted with thesecret.
Drive API (session & public)
# use *;
# async
PKDNS (_pubky) Pkarr publishing
# use *;
# async
Paths & addressing
Use absolute paths for agent-scoped I/O ("/pub/…"), or user-qualified forms when public:
# use *;
#
Features
jsonenabledrive::jsonhelpers (get_json/put_json) and serde on certain types.
Testing locally
Spin up an ephemeral testnet (DHT + homeserver + relay) and run your tests fully offline:
# use ;
# async
Session persistence (scripts that restart)
Export a compact bearer token and import it later to avoid re-auth:
# use *;
# async
Security: the cookie secret is a bearer token. Anyone holding it can act as the user within the granted capabilities. Treat it like a password.
Design notes
- Blocking vs managed pairing: prefer
subscribe()/wait_for_agent()(starts polling immediately when you get the URL) to avoid missing approvals. If you manually fetch the URL before polling, you can race the signer and miss the one-shot response. - Stateless client, stateful agent:
PubkyHttpClientnever holds identity;PubkyAgentdoes.
Example code
Check more examples using the Pubky SDK.
JS bindings
Find a wrapper of this crate using wasm_bindgen in pubky-sdk/bindings/js
License: MIT Relay: https://httprelay.io (open source; run your own for production)