DIDComm V2 Implementation Summary

Overview

This document summarizes the DIDComm V2 implementation for TrustWeave.

Implementation Status

Complete - Core implementation is complete with the following components:

Core Components

  1. Message Models (models/)
    • DidCommMessage: JWM-format message structure
    • DidCommEnvelope: Encrypted message envelope
    • DidCommAttachment: Message attachments for credentials/presentations
  2. Cryptography (crypto/)
    • DidCommCrypto: ECDH-1PU key agreement and AES-256-GCM encryption
    • ⚠️ Note: Uses placeholder implementations for ECDH-1PU. For production, integrate a full DIDComm library.
  3. Message Packing (packing/)
    • DidCommPacker: Packs/unpacks messages (encryption/decryption)
  4. Service Interface (DidCommService.kt)
    • DidCommService: Interface for messaging operations
    • InMemoryDidCommService: In-memory implementation
  5. Protocol Helpers (protocol/)
    • CredentialProtocol: Issue Credential protocol messages
    • ProofProtocol: Present Proof protocol messages
    • BasicMessageProtocol: Basic message protocol
  6. Utilities (utils/)
    • DidCommUtils: Helper functions for DID document operations
  7. Exceptions (exceptions/)
    • Custom exception types for DIDComm operations
  8. Factory (DidCommFactory.kt)
    • Factory methods for creating services
  9. Examples (examples/)
    • Usage examples for common scenarios

File Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
credentials/plugins/didcomm/
├── build.gradle.kts
├── README.md
├── IMPLEMENTATION.md
└── src/
    ├── main/
    │   └── kotlin/
    │       └── org.trustweave/didcomm/
    │           ├── crypto/
    │           │   └── DidCommCrypto.kt
    │           ├── models/
    │           │   ├── DidCommMessage.kt
    │           │   └── DidCommEnvelope.kt
    │           ├── packing/
    │           │   └── DidCommPacker.kt
    │           ├── protocol/
    │           │   ├── BasicMessageProtocol.kt
    │           │   ├── CredentialProtocol.kt
    │           │   └── ProofProtocol.kt
    │           ├── utils/
    │           │   └── DidCommUtils.kt
    │           ├── exceptions/
    │           │   └── DidCommExceptions.kt
    │           ├── examples/
    │           │   └── DidCommExamples.kt
    │           ├── DidCommFactory.kt
    │           └── DidCommService.kt
    └── test/
        └── kotlin/
            └── org.trustweave/didcomm/
                └── DidCommServiceTest.kt

Supported Protocols

Issue Credential Protocol

  • offer-credential: Credential offer message
  • request-credential: Credential request message
  • issue-credential: Credential issue message
  • ack: Acknowledgment message

Present Proof Protocol

  • request-presentation: Proof request message
  • presentation: Proof presentation message
  • ack: Acknowledgment message

Basic Message Protocol

  • message: Simple text messages

Features

  • ✅ JWM (JSON Web Message) format support
  • ✅ Message encryption structure (ECDH-1PU placeholder)
  • ✅ AES-256-GCM content encryption
  • ✅ Message packing/unpacking
  • ✅ Protocol message builders
  • ✅ Message threading support
  • ✅ In-memory message storage
  • ✅ DID document utilities
  • ✅ Comprehensive exception handling
  • ✅ Usage examples and tests

Dependencies

  • credentials:credential-core - For credential models
  • did:did-core - For DID document models
  • kms:kms-core - For key management
  • common - For common utilities
  • bouncycastle - For cryptographic operations
  • nimbus-jose-jwt - For JWT/JWS operations
  • okhttp - For HTTP operations (future use)

Usage Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.trustweave.credential.didcomm.*
import org.trustweave.credential.didcomm.protocol.*
import org.trustweave.testkit.InMemoryKeyManagementService

val kms = InMemoryKeyManagementService()
val resolveDid: suspend (String) -> DidDocument? = { /* resolve DID */ }

val didcomm = DidCommFactory.createInMemoryService(kms, resolveDid)

// Send a basic message
val message = BasicMessageProtocol.createBasicMessage(
    fromDid = "did:key:alice",
    toDid = "did:key:bob",
    content = "Hello!"
)

didcomm.sendMessage(
    message = message,
    fromDid = "did:key:alice",
    fromKeyId = "did:key:alice#key-1",
    toDid = "did:key:bob",
    toKeyId = "did:key:bob#key-1"
)

Production Readiness

✅ Ready

  • Message structure and models
  • Protocol message builders
  • Message packing/unpacking structure
  • Service interface and in-memory implementation
  • Utility functions
  • Exception handling
  • Tests and examples

⚠️ Needs Production Implementation

  1. Cryptography: Replace placeholder ECDH-1PU with full implementation
    • Consider using didcomm-java library
    • Or implement full ECDH-1PU key agreement
  2. Message Delivery: Implement actual message transport
    • HTTP POST to DIDComm service endpoints
    • WebSocket support
    • Message queue integration
  3. Persistent Storage: Replace in-memory storage
    • Database-backed message storage
    • Message indexing and search
    • Thread management
  4. Key Management: Enhance key handling
    • Private key access for decryption
    • Key rotation support
    • Key derivation from KMS
  5. Error Handling: Expand error scenarios
    • Network failures
    • Invalid message formats
    • Missing keys
    • DID resolution failures

Next Steps

  1. Integrate Full DIDComm Library
    • Evaluate didcomm-java or similar libraries
    • Replace placeholder crypto implementations
    • Ensure full DIDComm V2 compliance
  2. Add Message Transport
    • HTTP client for DIDComm service endpoints
    • WebSocket support for real-time messaging
    • Message queue integration
  3. Enhance Storage
    • Database-backed message storage
    • Message search and filtering
    • Thread management
  4. Add Integration Tests
    • End-to-end credential exchange tests
    • Proof presentation tests
    • Error scenario tests
  5. Documentation
    • API reference
    • Integration guide
    • Protocol-specific guides

References


This site uses Just the Docs, a documentation theme for Jekyll.