A Go module to help building privacy apps


3 min read

A couple of weeks ago, we released a Go module, named the NymSocketManager. This module aims to simplify the development of Go application that uses the Nym Mixnet by abstracting the networking aspects.

Some context

Nym currently proposes two SDKs (Software Development Kit): one in Rust and one in Typescript. Programs that use these SDK can directly communicate with the mixnet, they do not need to connect to a nym-client via web sockets. However, at NoTrustVerify, we fancy Python or Golang for our applications and for these, as there is no SDK (yet) for these languages, we rely on an external nym-client to communicate with other actors on the mixnet. Since some of this code is often similar throughout our applications, we developed this networking component to modularize our code and ease the development of future applications. The module can be found on our Github repository.

How to use it?

The nymsocketmanager module can be added to your project by running from your Golang project:

go get -u github.com/notrustverify/nymsocketmanager

and including the library in your code as follows:

import NymSocketManager "github.com/notrustverify/nymsocketmanager"

In your project, you can now create a NymSocketManager instance as follows:

nymSocketManager := NymSocketManager.NewNymSocketManager(NYM_CLIENT_WS, handlingFunction, logger)

with the following arguments:

  • NYM_CLIENT_WS: The web socket address of the nym-client that your program will be using, e.g. "ws://"

  • handlingFunction: This function will be called upon reception of a new message and will handle the message according to your desire. This is where the logic of your application interacts with the mixnet. handlingFunction needs to have the following signature: func (NymSocketManager.NymReceived, func(NymSocketManager.NymMessage) error). The first argument is the message that your application could process and the second argument is a function that can be called to send a reply (or other messages) through the mixnet. Feel free to check our repo to understand the Nym Messages types we defined.

  • logger: finally, a zerolog.Logger has to be provided. This allows to log the behavior of the NymSocketManager according to your needs (with distinct log level, writing in a file, sending to a log aggregator,...).

Once the nymSocketManager is defined, you can start it using:

stoppedSocketManager, err := nymSocketManager.Start()
if nil != err {

Where the first returned parameter is a channel that indicates when the underlying socket is closed (if the nym-client closes the connection), allowing you to react to such an event (restart the nym-client, close other resources, shutdown program,...). The other parameter indicates if an error occurred during the startup.

A running NymSocketManager will call the provided handlingFunction upon reception of Nym messages. You can also use the Send(msg NymSocketManager.NymMessage) error function of the NymSocketManager to freely send messages (not upon reception of messages).

The nymSocketManager can be stopped by calling nymSocketManager.Stop(), which will close the connection to the mixnet and free the associated resources.

Additionally, our module includes a regular SocketManager to handle network communication with any web socket, for convenience.


We included examples of code for using both our NymSocketManager and the regular SocketManager in our repo in the Examples folder (here). You can also check our last application using this piece of code: the NostrNym Proxy, which we already introduced in this article.