Expand description
§Nym SDK
Rust SDK for building privacy-preserving applications on the Nym mixnet, a decentralized network that provides network-level privacy through packet mixing, timing obfuscation, and Sphinx packet encryption.
For tutorials and conceptual guides, see the Nym developer portal.
§Getting started
Start with mixnet::MixnetClient::connect_new for a quick ephemeral client, or
mixnet::MixnetClientBuilder when you need to configure storage, gateway selection,
or network settings.
use nym_sdk::mixnet::{self, MixnetMessageSender};
let mut client = mixnet::MixnetClient::connect_new().await.unwrap();
let addr = *client.nym_address();
client.send_plain_message(addr, "hello mixnet!").await.unwrap();
// Always disconnect for clean shutdown
client.disconnect().await;§Stream I/O
For persistent bidirectional byte channels (like a TCP socket), use
MixnetClient::open_stream and
MixnetClient::listener.
Streams implement AsyncRead +
AsyncWrite — see mixnet::stream for
the full API:
use nym_sdk::mixnet;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
let mut sender = mixnet::MixnetClient::connect_new().await.unwrap();
let mut receiver = mixnet::MixnetClient::connect_new().await.unwrap();
let recv_addr = *receiver.nym_address();
let mut listener = receiver.listener().unwrap();
let mut tx = sender.open_stream(recv_addr, None).await.unwrap();
let mut rx = listener.accept().await.unwrap();
tx.write_all(b"hello via stream").await.unwrap();
tx.flush().await.unwrap();
let mut buf = vec![0u8; 1024];
let n = rx.read(&mut buf).await.unwrap();
sender.disconnect().await;
receiver.disconnect().await;See mixnet::stream for the full stream API, and the
stream tutorial
for a step-by-step walkthrough.
§Modules
| Module | Purpose |
|---|---|
mixnet | Core client — messages, streams, builder, storage |
client_pool | Pre-warmed pool of ephemeral clients |
tcp_proxy | TCP tunnelling over the mixnet (deprecated — prefer streams) |
bandwidth | Bandwidth credential management |
§Feature flags
Feature gates are not yet implemented. Importing nym-sdk currently pulls in all
modules and their full dependency trees. Work is planned to gate modules behind Cargo
features so you can import only what you need.
§Network configuration
By default, the SDK connects to the Nym mainnet. Customize with
NymNetworkDetails or environment variables.
Modules§
- bandwidth
- The coconut bandwidth component of the Rust SDK for the Nym platform
- client_
pool - A variable-sized pool of ephemeral Mixnet clients for higher-throughput applications.
- ip_
packet_ client - IPR helpers for
IpMixStream. - ipr_
wrapper - High-level IPR (IP Packet Router) stream wrapper.
- mixnet
- The mixnet component of the Rust SDK for the Nym platform.
- tcp_
proxy - TCP proxy functionality for routing socket connections through the Nym mixnet.
Structs§
- Chain
Details - Cosmos chain configuration (chain ID, RPC, gas).
- Debug
Config - Debug/development configuration for mixnet clients.
- Denom
Details - Token denomination details (borrowed).
- Denom
Details Owned - Token denomination details (owned).
- Erased
Gateway Error - Local
Gateway - Gateway running within the same process.
- Mock
Gateway - Mock
Gateway Error - NymApi
Topology Provider - Fetches network topology from the Nym API.
- NymApi
Topology Provider Config - Configuration for
NymApiTopologyProvider. - NymContracts
- Nym smart contract addresses.
- NymNetwork
Details - Complete network configuration (endpoints, contracts, chain details).
- Packet
Router - Remember
Me - Controls whether client identity persists across restarts.
- Remote
Gateway - Gateway to which the client is connected through a socket. Most likely through a websocket.
- Shutdown
Token - Cancellation token for graceful shutdown. A wrapped CancellationToken that is used for signalling and listening for cancellation requests.
- Shutdown
Tracker - Tracks spawned tasks for coordinated shutdown. Extracted TaskTracker and ShutdownToken to more easily allow tracking nested tasks without having to pass whole ShutdownManager around.
- User
Agent - Client identification sent with Nym API requests. Characteristic elements sent to the API providing basic context information of the requesting client.
- Validator
Details - Validator/API endpoint configuration.
Enums§
- Error
- Top-level Error enum for the mixnet client and its relevant types.
- Local
Gateway Error
Traits§
- Gateway
Packet Router - Gateway
Receiver - this trait defines the functionality of being able to correctly route packets received from the mixnet, i.e. acks and ‘proper’ messages.
- Gateway
Sender - This trait defines the functionality of sending
MixPacketinto the mixnet, usually through a gateway. - Gateway
Transceiver - This combines the functionalities of being able to send and receive mix packets.
- Topology
Provider - Trait for custom topology providers. Implement this to fetch topology
from alternative sources (see
custom_topology_providerexample).