Skip to main content

Crate nym_sdk

Crate nym_sdk 

Source
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

ModulePurpose
mixnetCore client — messages, streams, builder, storage
client_poolPre-warmed pool of ephemeral clients
tcp_proxyTCP tunnelling over the mixnet (deprecated — prefer streams)
bandwidthBandwidth 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§

ChainDetails
Cosmos chain configuration (chain ID, RPC, gas).
DebugConfig
Debug/development configuration for mixnet clients.
DenomDetails
Token denomination details (borrowed).
DenomDetailsOwned
Token denomination details (owned).
ErasedGatewayError
LocalGateway
Gateway running within the same process.
MockGateway
MockGatewayError
NymApiTopologyProvider
Fetches network topology from the Nym API.
NymApiTopologyProviderConfig
Configuration for NymApiTopologyProvider.
NymContracts
Nym smart contract addresses.
NymNetworkDetails
Complete network configuration (endpoints, contracts, chain details).
PacketRouter
RememberMe
Controls whether client identity persists across restarts.
RemoteGateway
Gateway to which the client is connected through a socket. Most likely through a websocket.
ShutdownToken
Cancellation token for graceful shutdown. A wrapped CancellationToken that is used for signalling and listening for cancellation requests.
ShutdownTracker
Tracks spawned tasks for coordinated shutdown. Extracted TaskTracker and ShutdownToken to more easily allow tracking nested tasks without having to pass whole ShutdownManager around.
UserAgent
Client identification sent with Nym API requests. Characteristic elements sent to the API providing basic context information of the requesting client.
ValidatorDetails
Validator/API endpoint configuration.

Enums§

Error
Top-level Error enum for the mixnet client and its relevant types.
LocalGatewayError

Traits§

GatewayPacketRouter
GatewayReceiver
this trait defines the functionality of being able to correctly route packets received from the mixnet, i.e. acks and ‘proper’ messages.
GatewaySender
This trait defines the functionality of sending MixPacket into the mixnet, usually through a gateway.
GatewayTransceiver
This combines the functionalities of being able to send and receive mix packets.
TopologyProvider
Trait for custom topology providers. Implement this to fetch topology from alternative sources (see custom_topology_provider example).

Type Aliases§

Result
A Result type alias with Error as the default error type.