valregistry=DidMethodRegistry()// Bracket notation for accessvalmethod=registry["key"]// `in` operator for checking existenceif("key"inregistry){// Method is registered}// Assignment operatorregistry["new"]=NewDidMethod()
Extension Functions
DidResolutionResult extensions
DidResolutionResult is a sealed class (not Result<T>) with three top-level cases —
Success, Deactivated, and Failure — since the DID Resolution 1.0 migration. Use when,
resolveOrNull / resolveOrThrow on Did, or the small did-core helpers below.
importorg.trustweave.did.resolver.DidResolutionResultimportorg.trustweave.did.resolver.errorTypeimportorg.trustweave.did.resolver.errorMessageimportorg.trustweave.did.resolver.hasErrorimportorg.trustweave.did.resolver.isDeactivatedimportorg.trustweave.did.resolver.isNotFoundimportorg.trustweave.did.resolver.isSuccessvalresult:DidResolutionResult=// ... from resolver.resolve(did)// Diagnosticsif(result.isSuccess){/* ... */}if(result.isDeactivated){/* treat as revoked, not "not found" */}if(result.hasError){// true only for Failure — deactivation is NOT an errorprintln(result.errorMessage)println(result.errorType)// the RFC 9457 error type URI, e.g. DidErrorType.NOT_FOUND}if(result.isNotFound){/* ... */}// Document extraction — `documentOrNull` is also available as a built-in extensionvaldocumentOrNull:DidDocument?=when(result){isDidResolutionResult.Success->result.documentelse->null// Deactivated and Failure both have no document}valmessage=when(result){isDidResolutionResult.Success->"Success: ${result.document.id}"isDidResolutionResult.Deactivated->"Deactivated: ${result.did.value}"isDidResolutionResult.Failure->"Failed: ${result.errorMessage}"}
importorg.trustweave.did.identifiers.Didimportorg.trustweave.did.dsl.resolveWithimportorg.trustweave.did.dsl.resolveOrNullimportorg.trustweave.did.dsl.resolveOrThrowimportorg.trustweave.did.dsl.resolveOrDefaultvaldid=Did("did:key:123")valresolver:DidResolver=// ... resolver// Resolve to document (throws DidException on failure)valdocument=did.resolveOrThrow(resolver)valdoc=did.resolveOrNull(resolver)valdocOrDefault=did.resolveOrDefault(resolver,defaultDocument)// Deactivation: resolveOrNull/resolveOrDefault do NOT fold a deactivated DID into// null/the default — a revoked identity is not an absent one. Both throw// DidException.DidResolutionFailed in that case, matching resolveOrThrow.// With callbackdid.resolveWith(resolver){document->println("Resolved: ${document.id}")}
valregistry=didMethodRegistry{register(KeyDidMethod(kms))}valmethod=registry["key"]// Operator overloadvalresolver=universalResolver("https://dev.uniresolver.io"){timeout=60retry{maxRetries=3}}valdocument=Did("did:key:123").resolveOrNull(resolver)// null for not-found/invalid/error; throws DidException.DidResolutionFailed if deactivated
Best Practices
Use builder DSLs for complex configurations
Use extension functions for fluent, readable code (resolveOrThrow, resolveOrNull, resolveOrDefault)
Use operator overloads for intuitive API usage
Configure retry logic for production environments
Handle the sealed DidResolutionResult with when when you need per-failure behaviour