This guide covers the did:ens method integration for TrustWeave. The did:ens plugin provides human-readable DID resolution using Ethereum Name Service (ENS).
Overview
The did/plugins/ens module provides an implementation of TrustWeave’s DidMethod interface using the Ethereum Name Service (ENS) resolver. This integration enables you to:
Resolve human-readable DID identifiers (e.g., did:ens:example.eth)
Map ENS domain names to Ethereum addresses
Integrate with ENS resolver contracts
Convert ENS names to did:ethr DIDs for resolution
Installation
Add the did:ens module to your dependencies:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
dependencies{implementation("org.trustweave.did:ens:1.0.0-SNAPSHOT")implementation("org.trustweave:trustweave-did:1.0.0-SNAPSHOT")implementation("org.trustweave.did:base:1.0.0-SNAPSHOT")implementation("org.trustweave.did:ethr:1.0.0-SNAPSHOT")implementation("org.trustweave:trustweave-anchor:1.0.0-SNAPSHOT")implementation("org.trustweave:distribution-all:1.0.0-SNAPSHOT")// Web3j for Ethereum blockchainimplementation("org.web3j:core:4.10.0")// Optional: Polygon client for EVM-compatible chainsimplementation("org.trustweave.chains:polygon:1.0.0-SNAPSHOT")}
valconfig=EnsDidConfig.mainnet("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY")valanchorClient=PolygonBlockchainAnchorClient(config.chainId,config.toMap())valkms=InMemoryKeyManagementService()valmethod=EnsDidMethod(kms,anchorClient,config)importorg.trustweave.did.identifiers.Didimportorg.trustweave.did.resolver.DidResolutionResult// Resolve ENS domain to DID documentvaldid=Did("did:ens:example.eth")valresult=method.resolveDid(did)when(result){isDidResolutionResult.Success->{println("Resolved: ${result.document.id}")println("Verification methods: ${result.document.verificationMethod.size}")}isDidResolutionResult.Failure.NotFound->{println("DID not found: ${result.did.value}")}else->println("Resolution failed")}
How it Works
Extract ENS domain: From did:ens:example.eth, extract example.eth
Resolve ENS to address: Query ENS registry to resolve example.eth to Ethereum address
Convert to did:ethr: Convert Ethereum address to did:ethr:0x...
Resolve did:ethr: Use did:ethr method to resolve the DID document
Return did:ens document: Return document with did:ens:example.eth as the ID
importorg.trustweave.testkit.anchor.InMemoryBlockchainAnchorClientvalconfig=EnsDidConfig.mainnet("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY")valanchorClient=InMemoryBlockchainAnchorClient(config.chainId)valmethod=EnsDidMethod(kms,anchorClient,config)// Note: ENS resolution requires actual ENS registry interaction// For full testing, use a testnet or local Ethereum node
Best Practices
Use ENS for readability: did:ens provides human-readable identifiers
Link to did:ethr: Ensure ENS domain is linked to an address with did:ethr DID
Test on testnets: Use Sepolia testnet for development
Cache resolutions: Cache ENS-to-address mappings for performance
Error handling: Handle cases where ENS domain doesn’t exist or isn’t linked