Dev Raj Dungana

Writing didcomm, digital identity, infrastructure

DIDComm in production: what it gives you, and what it costs

Bhutan’s national digital identity wallet talks to the world over DIDComm. What that buys you, where the costs land, and how to decide whether it is right for your system.

Bhutan NDI, the country’s national digital identity, keeps citizens’ credentials in a wallet on their phone. Credential offers, proof requests and the replies between that wallet and the banks, telecoms and government services it deals with travel as DIDComm messages. I run the infrastructure those messages pass through.

DIDComm tends to be described in one of two ways: as the secure, decentralised messaging layer that self-sovereign identity needs, or as a complicated protocol that nobody outside a small community uses. Both are partly true. This is what I would tell a team deciding whether to adopt it: what it is, what it is genuinely good at, what it costs to run, and when I would choose something else.

What DIDComm is

DIDComm is a way for two parties identified by decentralised identifiers (DIDs) to send each other encrypted, authenticated messages. A DID resolves to a document that lists the party’s public keys and where to reach it, its service endpoint. To send a message, you look up the recipient’s DID document, encrypt the message to their key, and deliver it to their endpoint.

There are two generations. DIDComm v1 is defined by the Aries RFCs (now maintained at the Decentralized Identity Foundation) and is what most production identity wallets run today, through frameworks such as Credo (formerly Aries Framework JavaScript) and ACA-Py, both now under the OpenWallet Foundation. DIDComm v2 is a specification from the Decentralized Identity Foundation that rebuilds the envelope on standard JOSE formats (JWE for encryption, JWS for signatures). The ideas are the same. The wire formats are not compatible, which matters later.

DIDComm on its own only moves messages. What the messages mean is defined by protocols layered on top: setting up a connection (DID Exchange), issuing a credential, requesting a proof, plain messages, discovering what the other side supports. Each protocol is a small state machine, and every message carries a thread ID so both sides know which conversation it belongs to.

How a message travels

A phone is not a server. It has no stable address, it is offline much of the time, and its operating system suspends apps in the background. So a wallet does not publish an endpoint of its own. It registers with a mediator: an always-on service that receives messages on the wallet’s behalf and holds them until the wallet collects them.

When a bank sends the wallet a credential offer, three things happen (Figure 1):

  1. The bank’s agent encrypts the offer to the wallet’s key. Only the wallet can decrypt it.
  2. It wraps that ciphertext in a second envelope, a forward message encrypted to the mediator, which says only which wallet key the inner message is for (Figure 2), and posts it to the mediator.
  3. The mediator opens the outer envelope, queues the inner one, and delivers it when the wallet connects: at once over an open WebSocket if the app is in the foreground, or after a push notification wakes it.
A credential offer travels from the issuer agent through the mediator to the wallet. TLS protects each hop separately; DIDComm encryption covers the whole path, and the mediator routes the message without being able to read it. TLS ENDS AT EVERY LOAD BALANCER, GATEWAY AND PROXY TLS · HOP 1 TLS · HOP 2 SENDER Issuer agent Bank, telecom or ministry ALWAYS ON Mediator Holds messages for the wallet RECIPIENT Wallet A phone, often offline POST WEBSOCKET DIDComm encryption: end to end, issuer to wallet The mediator routes the message but cannot read it.
Fig. 1 A credential offer from issuer to wallet. TLS protects each hop separately; DIDComm encryption covers the whole path.
A plaintext message sits inside an envelope encrypted to the wallet, which sits inside a forward envelope encrypted to the mediator. The mediator can open only the outer one, which holds routing data; only the wallet can open the message envelope. FORWARD ENVELOPE Encrypted to the mediator. Says only: deliver this to wallet key 7Hx… MESSAGE ENVELOPE Encrypted to the wallet, authenticated as the issuer (authcrypt). PLAINTEXT MESSAGE "type": "…/issue-credential/2.0/offer-credential", "id": "6a1f…", "~thread": { "thid": "6a1f…" }, "credential_preview": { … } The mediator can open Routing data only: which key, how large, when. Only the wallet can open And it can verify which issuer key sealed it. What the protocol reads Message type, thread and payload.
Fig. 2 Envelopes inside envelopes. The mediator can open only the outer one.

What DIDComm does well

Security belongs to the message, not the connection

With an ordinary API, a request is protected by TLS between two machines. In real infrastructure that connection ends early: at a load balancer, a CDN, an API gateway or a service-mesh sidecar. Past that point the payload is plaintext in memory, and too often in logs.

A DIDComm message stays encrypted from sender to recipient, whatever it passes through. Our load balancers, the mediator and its queue only ever handle ciphertext addressed to a wallet key. A careless log line or a breached queue exposes routing metadata, not a citizen’s credential. For a national system, being able to say that about your own infrastructure is worth a great deal.

It works when the other side is offline

Most identity flows assume both parties are online at the same moment. DIDComm does not. Because the mediator holds messages, an issuer can send a credential at three in the morning and the wallet receives it when the phone is next online. Where mobile coverage is patchy, that is a requirement, not a nicety.

Mutual authentication without an identity provider

When a message is encrypted in authenticated mode (authcrypt), the recipient learns which key sent it, and that key is bound to the sender’s DID. Each side authenticates the other directly. No central login service sits in the middle seeing every relationship.

Pairwise identifiers limit tracking

Wallets typically create a fresh peer DID for every relationship. The bank and the telecom see different identifiers for the same citizen, so they cannot link their records through the identifier. They can still link them through the data a citizen discloses, which is why selective disclosure matters too.

A relationship, not a session

Once a connection exists, either side can start a new conversation on it at any time. An issuer can tell a wallet that a credential has been revoked, offer a renewed one or ask for fresh proof, without the citizen scanning another QR code. Request–response protocols, in which every exchange starts from a request the wallet receives, need extra machinery to do this.

Protocols compose

Issuing credentials, presenting proofs, discovering features and exchanging plain messages all run over the same connection with the same security. A new kind of interaction is a new protocol, not a new API with its own authentication.

What it costs

A large, split specification

DIDComm v1 is not one document. It is dozens of Aries RFCs (encryption envelopes, routing, mediator coordination, message pickup, out-of-band invitations, DID Exchange, issuing credentials, presenting proofs) plus interoperability profiles that say which versions to use together. DIDComm v2 replaces the envelope and routing layers but cannot talk to v1, and most deployed wallets still speak v1. A new engineer needs weeks, not days, before they can reason about a failed exchange.

You have to run a mediator, and it is core infrastructure

The mediator is the part of DIDComm that specifications cover in a few pages and operators spend most of their time on (Figure 3). It holds a WebSocket open to every active wallet, stores every undelivered message, and has to wake sleeping phones through Apple’s and Google’s push services. Each of those is a scaling problem of its own:

  • Load balancers close idle connections. If the idle timeout is shorter than the interval at which wallets send keep-alives, live connections drop and reconnect in waves.
  • A wallet’s WebSocket is pinned to one mediator instance, so a message queued through another instance has to find its way to the right one.
  • The queue grows whenever wallets do not collect, because apps get uninstalled and phones get lost. You need expiry rules, and a store that copes with a constant stream of small writes and deletes.
  • After an outage or an app release, every wallet reconnects at once.
Wallets hold WebSockets through a load balancer to several mediator instances, which write to a queue store and wake sleeping phones through Apple and Google push services. Four pressure points are marked: load-balancer idle timeouts, sockets pinned to one instance, a queue that only grows, and push as part of delivery. 1 Idle timeouts must outlast the wallet’s keep-alive, or sockets drop in waves. 2 A socket pins a wallet to one instance; messages queued elsewhere must find it. 3 The queue only grows when wallets never collect. 4 Push is part of delivery, with its own failures. Wallets phones Load balancer N INSTANCES Mediator Decrypts forwards, queues, delivers QUEUE STORE Messages PostgreSQL · DynamoDB Cosmos DB PUSH Notifications Apple APNs · Google FCM WSS WAKE UP: A MESSAGE IS WAITING 1 2 3 4
Fig. 3 Where the operational cost of DIDComm lands: the mediator and everything around it.

None of this is exotic, but it means DIDComm is not a library you add. It is a service you operate. We built a load-testing harness that drives a mediator with real wallet agents for exactly this reason.

Encrypted by design, hard to debug by design

The property that protects citizens also hides problems. When an exchange fails, the logs show that an envelope of a certain size went to a certain key. To see what was inside you would need the recipient’s keys, which you should not have. Debugging relies on thread IDs, timing and careful structured logging at the agents, and many failures can only be reproduced end to end.

Connections age

A connection is two sets of keys that both sides have to keep. When a citizen reinstalls the app without a backup, the wallet’s keys are gone. Every connection an issuer holds now points to a key nobody controls, and messages queue for a wallet that will never collect them. Key rotation, backup and recovery are your problem, and they are harder than resetting a password.

Every message pays for its cryptography

Each message is encrypted for its recipient and again for each mediator on the route, and decrypted as many times. For one message the cost is negligible. Across millions it shows up in mediator CPU and in agent latency. Measure it under load rather than assume it.

The wider ecosystem is moving elsewhere

The European Union’s digital identity wallet framework is built on OpenID for Verifiable Credential Issuance (OpenID4VCI) and OpenID for Verifiable Presentations (OpenID4VP), alongside the ISO mobile driving licence standards. DIDComm is not part of it. Most relying parties already know OAuth and OpenID Connect, and that is where vendor and tooling investment is going. Choosing DIDComm today means accepting a smaller community and fewer ready-made components, and planning for interoperability with OpenID-based wallets.

Choosing between them

DIDComm and OpenID for Verifiable Credentials solve overlapping but different problems. The question that separates them is what the relationship looks like.

DIDCommOpenID4VCI / OpenID4VP
Who starts an exchangeEither side, at any time, over an existing connectionThe issuer or verifier presents a request (QR code, link, redirect); the wallet responds
Shape of the relationshipA long-lived connection between two DIDsUsually a single transaction
Recipient offlineThe mediator queues messages until the wallet collects themBoth sides take part during the exchange
Security modelMessage-level encryption end to end, mutual authentication by DID keysTLS, OAuth-style tokens, signed requests and responses
Infrastructure to runMediator, message queue, push notificationsWeb endpoints the issuer or verifier largely runs already
Where the ecosystem isAries and OpenWallet Foundation community; national and enterprise deploymentsEU digital identity wallet framework, large vendors, OAuth tooling

Choose DIDComm when the relationship is ongoing and either side needs to start conversations, when recipients are often offline, or when you need confidentiality that holds across every hop of your own infrastructure. Choose OpenID4VC when exchanges are one-off, the counterparties are web services, and alignment with the EU framework matters. Many systems will end up with both (Figure 4): OpenID4VC at the edge, where relying parties integrate, and DIDComm where a long-term relationship justifies it.

A rough way to choose. One-off exchanges, with both sides online and a web service as counterparty, point to OpenID4VCI and OpenID4VP. Ongoing relationships, where either side starts conversations and the phone may be offline, point to DIDComm. Web relying parties at the edge with long-term issuer relationships behind them point to both. What does the relationship look like? ONE-OFF One request, one answer. Both sides online. Counterparty is a web service. BOTH Web relying parties at the edge, long-term relationships with issuers behind them. ONGOING Either side starts conversations. Phone may be offline. Private past every hop you operate. USE OpenID4VCI / VP USE Both, each where it fits USE DIDComm
Fig. 4 A rough way to choose.

If you run DIDComm in production

  • Load-test the mediator with real agents performing DID Exchange, mediation and message pickup, not with synthetic HTTP requests.
  • Set load-balancer idle timeouts comfortably above the wallets’ keep-alive interval.
  • Put connection pooling in front of the agent and mediator databases; every connected wallet turns into database work.
  • Choose the queue store for many small writes and deletes, and expire messages that are never collected.
  • Treat push notifications as part of the delivery path, with their own monitoring.
  • Log thread IDs and message types at the agents, so a failed exchange can be followed without decrypting anything.
  • Know which DIDComm version you run, and plan the move to v2 before the ecosystem forces it.

Closing

DIDComm earns its complexity when you need what only it provides: confidentiality that does not depend on your own infrastructure, and relationships that outlive a single session. If you need neither, it is a lot of machinery to carry. If you need both, as a national identity system does, the cost is real, but it is the cost of doing the job properly.

Further reading