AbstractBlockchainDidMethod
Abstract base class for blockchain-based DID method implementations.
Provides common functionality for DID methods that store documents on blockchain:
Integration with BlockchainAnchorClient for on-chain storage
Document anchoring to blockchain
Document resolution from blockchain
Fallback to in-memory storage for testing
Local deactivation is authoritative, even over a successful chain read. The DID Resolution 1.0 CR does not settle where a blockchain-backed method should learn of deactivation from, so resolveFromBlockchain makes an explicit, fail-safe choice: once this instance has recorded a DID as deactivated (via deactivateDocumentOnBlockchain), every subsequent resolution returns DidResolutionResult.Deactivated for that DID — whether the chain read fails and falls back to the stored document, or the chain read succeeds and returns a live, still-anchored (pre-deactivation) document. A revoked DID must never verify; treating the chain as authoritative over local state would let a stale or unpruned on-chain anchor silently resurrect a DID TrustWeave believes is dead. The accepted tradeoff is that a DID deactivated on one instance still resolves live on another instance that never observed the deactivation, since this state is local and is not propagated to, or re-derived from, the chain. This mirrors the same rule applied to did:web in AbstractWebDidMethod.resolveFromHttp.
Subclasses should implement:
createDid: Create a new DID and anchor its document
resolveDid: Resolve DID from blockchain
getBlockchainAnchorClient: Provide the blockchain anchor client
getChainId: Provide the blockchain chain ID
Pattern: Reuses existing blockchain anchoring infrastructure.
Example Usage:
class EthrDidMethod(
kms: KeyManagementService,
private val anchorClient: BlockchainAnchorClient,
private val chainId: String = "eip155:1"
) : AbstractBlockchainDidMethod("ethr", kms) {
override fun getBlockchainAnchorClient(): BlockchainAnchorClient = anchorClient
override fun getChainId(): String = chainId
override suspend fun createDid(options: DidCreationOptions): DidDocument {
// Create DID document
val document = createDocument(options)
// Anchor to blockchain
anchorDocument(document)
return document
}
override suspend fun resolveDid(did: String): DidResolutionResult {
// Resolve from blockchain
return resolveFromBlockchain(did)
}
}