This guide covers the did:peer method integration for TrustWeave. The did:peer plugin provides peer-to-peer DIDs without external registries or blockchains.
Overview
The did/plugins/peer module provides an implementation of TrustWeave’s DidMethod interface using the peer DID method. This integration enables you to:
Create and resolve peer DIDs for P2P communication
Store DID documents locally (no external registry)
Numalgo 2 (Short-form with Multibase, Recommended)
1
did:peer:2...
Numalgo Versions
Numalgo 0: Static numeric algorithm (legacy)
Numalgo 1: Short-form with inception key
Numalgo 2: Short-form with multibase encoding (recommended)
Local Storage
Peer DIDs don’t use external registries or blockchains:
Documents are stored locally in memory or persistent storage
No external dependencies required
Fast resolution from local cache
No network calls needed
Embedded Documents
Long-form peer DIDs can embed documents:
Documents can be encoded in the DID itself
Useful for offline or P2P scenarios
No external resolution needed
Configuration Options
PeerDidConfig
1
2
3
4
valconfig=PeerDidConfig.builder().numalgo(2)// Numalgo version (0, 1, or 2).includeServices(true)// Include service endpoints.build()
Integration with TrustWeave
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
importcom.trustweave.TrustWeaveimportcom.trustweave.peerdid.*valconfig=PeerDidConfig.numalgo2()valTrustWeave=TrustWeave.create{kms=InMemoryKeyManagementService()didMethods{+PeerDidMethod(kms!!,config)}}// Use did:peervaldid=TrustWeave.dids.create("peer"){algorithm=KeyAlgorithm.ED25519}valresolved=TrustWeave.dids.resolve(did.id)
Error Handling
Common errors and solutions:
Error
Cause
Solution
Unsupported numalgo
Invalid numalgo version
Use 0, 1, or 2
DID document not found
Document not stored locally
Create DID first
Public key multibase required
Missing multibase key
Ensure key has multibase format
Testing
Peer DIDs are ideal for testing since they don’t require external services:
1
2
3
4
5
6
valconfig=PeerDidConfig.numalgo2()valmethod=PeerDidMethod(kms,config)// Create and resolve (stored locally)valdocument=method.createDid(options)valresult=method.resolveDid(document.id)
Best Practices
Use numalgo 2: Recommended for new implementations
Local storage: Consider persistent storage for peer DIDs
Service endpoints: Include service endpoints for P2P communication
Key management: Securely store keys for peer DIDs
Document sharing: Share documents explicitly in P2P scenarios
Advantages
No external dependencies: No blockchain or HTTP needed
Fast resolution: Local storage provides instant resolution
P2P ready: Designed for peer-to-peer communication
Privacy: No external registry tracks DIDs
Offline support: Works without network connectivity