This guide covers the did:ethr method integration for TrustWeave. The did:ethr plugin provides Ethereum DID resolution with blockchain anchoring support.
Overview
The did/plugins/ethr module provides an implementation of TrustWeave’s DidMethod interface using the Ethereum DID method. This integration enables you to:
Create and resolve DIDs on Ethereum blockchain
Store DID documents via blockchain anchoring
Support Ethereum mainnet and testnets (Sepolia, etc.)
Use secp256k1 keys compatible with Ethereum addresses
Integrate with ERC1056 registry contracts (via blockchain anchoring)
Installation
Add the did:ethr module to your dependencies:
1
2
3
4
5
6
7
8
9
10
11
12
13
dependencies{implementation("com.trustweave.did:ethr:1.0.0-SNAPSHOT")implementation("com.trustweave:trustweave-did:1.0.0-SNAPSHOT")implementation("com.trustweave.did:base:1.0.0-SNAPSHOT")implementation("com.trustweave:trustweave-anchor:1.0.0-SNAPSHOT")implementation("com.trustweave:trustweave-common:1.0.0-SNAPSHOT")// Web3j for Ethereum blockchainimplementation("org.web3j:core:4.10.0")// Optional: Polygon client for EVM-compatible chainsimplementation("com.trustweave.chains:polygon:1.0.0-SNAPSHOT")}
When the module is on the classpath, did:ethr is automatically available:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
importcom.trustweave.did.*importcom.trustweave.anchor.*importjava.util.ServiceLoader// Discover did:ethr providervalproviders=ServiceLoader.load(DidMethodProvider::class.java)valethrProvider=providers.find{it.supportedMethods.contains("ethr")}// Create method with required optionsvaloptions=didCreationOptions{property("rpcUrl","https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY")property("chainId","eip155:11155111")property("anchorClient",anchorClient)// Required: provide anchor client}valmethod=ethrProvider?.create("ethr",options)
Usage Examples
Creating a did:ethr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
valconfig=EthrDidConfig.sepolia("https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY")valanchorClient=PolygonBlockchainAnchorClient(config.chainId,config.toMap())valkms=InMemoryKeyManagementService()valmethod=EthrDidMethod(kms,anchorClient,config)// Create DID (uses secp256k1 for Ethereum compatibility)valoptions=didCreationOptions{algorithm=KeyAlgorithm.SECP256K1purpose(KeyPurpose.AUTHENTICATION)purpose(KeyPurpose.ASSERTION)}valdocument=method.createDid(options)println("Created: ${document.id}")// did:ethr:sepolia:0x... or did:ethr:0x...
did:ethr stores DID documents on the Ethereum blockchain using the BlockchainAnchorClient infrastructure. Documents are anchored to the blockchain via transactions, and the transaction hash is used for resolution.
For production use, consider integrating with ERC1056 registry contracts for standard DID resolution.
importcom.trustweave.TrustWeaveimportcom.trustweave.ethrdid.*importcom.trustweave.anchor.*importcom.trustweave.polygon.PolygonBlockchainAnchorClientvalconfig=EthrDidConfig.sepolia("https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY")valanchorClient=PolygonBlockchainAnchorClient(config.chainId,config.toMap())valTrustWeave=TrustWeave.create{kms=InMemoryKeyManagementService()blockchain{register(config.chainId,anchorClient)}didMethods{+EthrDidMethod(kms!!,anchorClient,config)}}// Use did:ethrvaldid=TrustWeave.createDid("ethr"){algorithm=KeyAlgorithm.SECP256K1}.getOrThrow()valresolved=TrustWeave.resolveDid(did.id).getOrThrow()
ERC1056 Compatibility
This implementation uses blockchain anchoring for document storage. For full ERC1056 compatibility, integrate with an ERC1056 registry contract that provides standard DID resolution methods.
Future enhancements:
Direct ERC1056 registry contract integration
Standard identity() and changed() event handlers
Registry contract deployment support
Error Handling
Common errors and solutions:
Error
Cause
Solution
rpcUrl is required
Missing RPC endpoint
Provide Ethereum RPC URL
chainId is required
Missing chain ID
Specify chain ID (eip155:1, etc.)
BlockchainAnchorClient is required
Missing anchor client
Provide anchor client in options
Failed to anchor document
Transaction failed
Check private key, gas, network connectivity
DID document not found
Not anchored yet
Anchor document first or check blockchain
Testing
For testing without actual blockchain:
1
2
3
4
5
6
7
8
9
importcom.trustweave.testkit.anchor.InMemoryBlockchainAnchorClientvalconfig=EthrDidConfig.sepolia("https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY")valanchorClient=InMemoryBlockchainAnchorClient(config.chainId)valmethod=EthrDidMethod(kms,anchorClient,config)// Create and resolve (stored in memory)valdocument=method.createDid(options)valresult=method.resolveDid(document.id)
Best Practices
Use testnets for development: Sepolia testnet for testing
Private key security: Never hardcode private keys, use environment variables or secure storage
Gas management: Monitor gas prices for transaction costs
Chain ID validation: Always validate chain ID matches network
Error handling: Implement proper error handling for blockchain operations
Troubleshooting
Transaction Failures
Check private key is valid and has sufficient funds