Open source (self-hosted)
Build and run the DIDComm Mediator from its open-source code, the affinidi-messaging-mediator repository, on a machine or server you control.
Self-hosting gives you the mediator’s configuration, its storage, and its administrator DID, so you manage accounts and DID-level ACLs directly. Use this guide when:
- You want a local mediator to develop and test against.
- You want to run the mediator on your own servers or in your own containers.
For a mediator that Affinidi runs for you, see Affinidi Portal (Affinidi-hosted). To deploy one in your own AWS account from a ready-made template, see AWS Marketplace (self-hosted).
The steps follow the repository’s latest release.
Prerequisites
- Git and Rust 1.95.0 or later.
- Storage for the mediator’s messages, either:
- Redis: Redis 7.1 or later, below 9.0, which the mediator checks at startup. Docker is the simplest way to run it locally. Redis is needed to run several mediators as a cluster.
- Fjall: an embedded store for a single mediator, with no separate service to run.
Step 1: Get the source
Clone the repository and check out its latest release. This guide walks you through setting up and testing the newest version of the mediator, and each release tag is tested as a whole.
git clone https://github.com/affinidi/affinidi-messaging-mediator.git
cd affinidi-messaging-mediator
git checkout "$(git tag --list 'v*' --sort=-v:refname | grep -v -- '-rc' | head -n 1)"These steps were tested with release v0.53.0. To match them exactly, check out v0.53.0 instead. Run every remaining command from this folder, the repository root. The setup writes its files to conf/ relative to where it runs.
Step 2: Start Redis
If you chose Redis, start it in Docker:
docker run --name=redis-local --publish=6379:6379 --detach redis:7-alpineIf you chose Fjall, skip this step.
Step 3: Generate the configuration and keys
Run the mediator’s setup tool, mediator-setup, without prompts. The mediator listens on every network interface by default, so other machines on your network can reach it. For a mediator that only this machine uses, add --listen-address 127.0.0.1:7037.
cargo run --locked -p affinidi-messaging-mediator-setup --no-default-features -- \
--non-interactive --did-method peer --secret-storage file \
--public-url http://localhost:7037This sets up a local development mediator. It creates a did:peer DID for the mediator, with http://localhost:7037/mediator/v1 as its service endpoint, so that clients can find the mediator from its DID. It also creates an administrator DID and the key the mediator signs its access tokens with. For Fjall instead of Redis, add --set storage.backend=fjall.
It writes these files to conf/:
| File | What it holds |
|---|---|
mediator.toml | The mediator’s configuration. It holds no secrets. |
secrets.json | The mediator’s private keys and the administrator’s key, in plain text. The setup accepts a plaintext file only for a local deployment, unless you pass --allow-plaintext-file. |
admin-monitor.json | A profile for the mediator console, with the administrator DID’s private key. |
mediator-build.toml | The choices this run made, to repeat the same setup with --from conf/mediator-build.toml. |
atm-functions.lua | The functions the mediator loads into Redis. |
secrets.json and admin-monitor.json control the mediator, so keep them on this machine only. Git ignores both.
Keep secrets.json and admin-monitor.json out of tickets, chat and logs. The setup keeps the administrator’s private key in these files and prints only the DID. For a mediator that others use, keep its keys in a secrets manager rather than a plaintext file, as Server and container deployments describes. To replace every key, run the setup again with --force-reprovision.
The network posture decides which DIDs may use the mediator:
- Open: any DID may connect, and new DIDs get every permission. The setup writes
mediator_acl_mode = "explicit_deny"andglobal_acl_default = "ALLOW_ALL". It is the default for a local deployment, and the test samples need it, because they create new DIDs on each run. - Closed: only DIDs that an administrator has added may connect. The setup writes
mediator_acl_mode = "explicit_allow"with a default ACL that lets those DIDs message other local accounts and denies everything else. It is the default for a server or container deployment.
To choose the posture, add --set security.network_mode=open or --set security.network_mode=closed. For what each permission allows, see Supported ACLs.
To choose each option in turn instead, run the setup with no options: cargo run --locked -p affinidi-messaging-mediator-setup --no-default-features. This lighter build stores keys in a file. To choose the OS keyring, AWS, GCP, Azure, HashiCorp Vault, Kubernetes or the Verifiable Trust Agent (VTA) options in the wizard, run it without --no-default-features. The mediator’s README in your checkout, crates/affinidi-messaging-mediator/README.md, describes each choice and the build features they need for your release.
Step 4: Run the mediator
The setup prints a build command for the options you chose. For the options in Step 3, these commands also work:
Redis: the default features are enough.
cargo run --release --locked -p affinidi-messaging-mediator -- -c conf/mediator.tomlFjall: add the
fjall-backendfeature, which a Fjall configuration needs.cargo run --release --locked -p affinidi-messaging-mediator --features fjall-backend -- -c conf/mediator.toml
The first build takes several minutes. The mediator listens on port 7037, on the address set by listen_address in conf/mediator.toml. To change it after setup, edit that value and restart the mediator.
Confirm the mediator is running
Test 1: Check the mediator’s health
curl -s http://localhost:7037/mediator/v1/livez
curl -s http://localhost:7037/mediator/v1/readyzlivez answers {"status":"alive"} while the process runs. readyz answers "status":"ready" once storage and the secrets answer, along with the release the mediator runs, for example "version":"0.53.0".
Test 2: Get the mediator’s DID
curl -s http://localhost:7037/mediator/v1/.well-known/didThe mediator answers with its DID in the data field. A did:peer DID carries its keys and its service endpoint in the DID itself, so clients need only this value. It is also the mediator_did value in conf/mediator.toml, after the did:// prefix.
Test 3: Send a test message
Follow Test the mediator connection with the mediator’s DID, on an open mediator. The Rust sample connects over http://, so it works with the mediator from Step 3. The Dart sample connects only over https://. To use it, put the mediator behind a TLS proxy with an RSA or ECDSA certificate, then run the setup again with --public-url https://<proxy-host> and --force-reprovision, so the DID lists the https:// endpoint. Otherwise use the Rust sample.
Manage the mediator
The mediator console shows the mediator’s health, every account’s queues, ACLs and queue limits, the audit log, and live traffic. Connect it as the administrator with the profile from Step 3:
cargo run --release --locked -p affinidi-messaging-mediator-tui -- --profile conf/admin-monitor.jsonTroubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
The setup stops with Refusing to overwrite an existing mediator setup. | conf/ already holds a mediator’s keys, and a new setup would replace them, so its clients would have to authenticate again. | Keep the existing setup. To replace it, run the setup again with --force-reprovision, which creates new keys. To remove it, run cargo run --locked -p affinidi-messaging-mediator-setup --no-default-features -- --uninstall --config conf/mediator.toml and type DELETE to confirm. |
The test samples fail with e.p.authentication.blocked. | The mediator’s network posture is closed, so it accepts only DIDs an administrator has added. | For testing, run the setup with --set security.network_mode=open. See the network posture in Step 3. |
| A client cannot find the mediator’s endpoint from its DID. | The setup ran without --public-url, so the mediator’s did:peer DID has no service endpoint. | Run the setup again with --public-url and --force-reprovision. |
readyz returns HTTP 503. | The mediator cannot reach its storage or its secrets yet. | Check that Redis is running, then check the mediator’s log for the failing component. |
curl or the Dart sample fails the TLS handshake with a self-signed mediator. | The setup’s self-signed certificate uses an Ed25519 key, which some TLS clients, including macOS curl and Dart, do not accept. | Serve the mediator behind a TLS proxy with an RSA or ECDSA certificate, then run the setup again with --public-url https://<proxy-host> and --force-reprovision, so the mediator’s DID lists the proxy’s https:// endpoint. |
Server and container deployments
The setup takes the same options for a server or a container: --deployment server or --deployment container, the mediator’s public URL, and a secrets manager for its keys, such as --secret-storage aws. Build the setup without --no-default-features to use a secrets manager. Both are closed by default. Put the mediator behind a TLS proxy or load balancer with a certificate that clients trust. The mediator’s repository covers the rest. The links below open its main branch, which can run ahead of your release. For the options your release has, read the same files in your checkout:
- Non-interactive setup: every setup option, including a
did:webvhDID for a public host. - Docker guide: the container quick start,
docker compose -f docker/quickstart/docker-compose.yml up --build, and running the published image,ghcr.io/affinidi/messaging-mediator, with your own identity. - Behind a load balancer: the settings for client addresses and metrics.
What’s next
Related
Glad to hear it. Thanks for letting us know.
Sorry to hear that. Thanks for letting us know.
Still stuck? Ask the community on Discord or contact us.