This guide covers the did:web method integration for TrustWeave. The did:web plugin provides W3C-compliant DID resolution from HTTPS endpoints.
Overview
The did/plugins/web module provides a complete implementation of TrustWeave’s DidMethod interface using the W3C did:web specification. This integration enables you to:
Create and resolve DIDs from HTTPS endpoints
Host DID documents at standard web locations (/.well-known/did.json)
Support domain-based and path-based did:web identifiers
valkms=InMemoryKeyManagementService()valhttpClient=OkHttpClient()valmethod=WebDidMethod.create(kms,httpClient)// Create DID for a domainvaloptions=didCreationOptions{algorithm=KeyAlgorithm.ED25519purpose(KeyPurpose.AUTHENTICATION)purpose(KeyPurpose.ASSERTION)property("domain","example.com")property("hostingUrl","https://example.com")// Optional: publish immediately}valdocument=method.createDid(options)println("Created: ${document.id}")// did:web:example.com
Resolving a did:web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
importorg.trustweave.did.identifiers.Didimportorg.trustweave.did.resolver.DidResolutionResultvaldid=Did("did:web:example.com")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")}
Creating did:web with Path
1
2
3
4
5
6
7
8
9
// Create DID for did:web:example.com:user:alicevaloptions=didCreationOptions{property("domain","example.com")property("path","user:alice")property("hostingUrl","https://example.com")}valdocument=method.createDid(options)// Resolves from: https://example.com/user/alice/.well-known/did.json
Host it at the appropriate URL path (/.well-known/did.json)
Ensure HTTPS is enabled
Set proper Content-Type: application/json
Example: Publishing to AWS S3
1
2
3
4
5
6
7
8
9
10
11
// After creating the DID documentvaldocument=method.createDid(options)// Upload to S3 or your hosting servicevals3Client=AmazonS3Client.builder().build()valjson=Json.encodeToString(documentToJsonElement(document))s3Client.putObject("my-bucket",".well-known/did.json",json)
For testing without actual web hosting, the method supports in-memory storage:
1
2
3
4
5
6
7
valmethod=WebDidMethod.create(kms,OkHttpClient())// Create DID (stored in memory)valdocument=method.createDid(options)// Resolve from memory (if not published to web)valresult=method.resolveDid(document.id)