This guide covers the did:ion method integration for TrustWeave. The did:ion plugin provides Microsoft ION (Identity Overlay Network) DID resolution using the Sidetree protocol.
Overview
The did/plugins/ion module provides an implementation of TrustWeave’s DidMethod interface using Microsoft ION and the Sidetree protocol. This integration enables you to:
Create and resolve DIDs using ION network
Store DID operations anchored to Bitcoin blockchain
// ION mainnetvalmainnetConfig=IonDidConfig.mainnet(ionNodeUrl="https://ion-node.tbddev.org"// Optional: uses default if omitted)// ION testnetvaltestnetConfig=IonDidConfig.testnet(ionNodeUrl="https://ion-testnet-node.tbddev.org"// Optional)
SPI Auto-Discovery
When the module is on the classpath, did:ion is automatically available:
1
2
3
4
5
6
7
8
9
10
11
12
13
importcom.trustweave.did.*importjava.util.ServiceLoader// Discover did:ion providervalproviders=ServiceLoader.load(DidMethodProvider::class.java)valionProvider=providers.find{it.supportedMethods.contains("ion")}// Create method with required optionsvaloptions=didCreationOptions{property("ionNodeUrl","https://ion-node.tbddev.org")}valmethod=ionProvider?.create("ion",options)
Usage Examples
Creating a did:ion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
valconfig=IonDidConfig.testnet()valkms=InMemoryKeyManagementService()valmethod=IonDidMethod(kms,config)// Create DIDvaloptions=didCreationOptions{algorithm=KeyAlgorithm.ED25519purpose(KeyPurpose.AUTHENTICATION)purpose(KeyPurpose.ASSERTION)}valdocument=method.createDid(options)println("Created: ${document.id}")// Long-form DID initially// After anchoring, you'll get a short-form DID// Long-form: did:ion:EiA2...:eyJ...// Short-form: did:ion:EiA2...
Resolving a did:ion
1
2
3
4
5
6
7
8
9
10
// Resolve short-form DID (after anchoring)valresult=method.resolveDid("did:ion:EiA2...")// Resolve long-form DID (for newly created DIDs)vallongFormResult=method.resolveDid("did:ion:EiA2...:eyJ...")result.document?.let{doc->println("Resolved: ${doc.id}")println("Verification methods: ${doc.verificationMethod.size}")}?:println("Not found")
Resolves through ION nodes after anchoring to Bitcoin.
Long-form DID
1
did:ion:EiA2...:eyJ...
Contains operation data for newly created DIDs before anchoring.
Sidetree Protocol
ION uses the Sidetree protocol for DID operations:
Create: Create a new DID with initial keys
Update: Update DID document (add/remove keys, services)
Recover: Recover DID with new recovery keys
Deactivate: Permanently deactivate a DID
Operations are batched and anchored to Bitcoin blockchain by ION nodes.
ION Node Integration
This implementation communicates with ION nodes via HTTP:
Operations: Submit operations to /operations endpoint
Resolution: Resolve DIDs through /identifiers/{did} endpoint
ION nodes handle:
Operation batching
Bitcoin anchoring
DID resolution
State management
Configuration Options
IonDidConfig
1
2
3
4
5
6
7
valconfig=IonDidConfig.builder().ionNodeUrl("https://ion-node.tbddev.org")// Required: ION node endpoint.bitcoinRpcUrl("https://btc-mainnet...")// Optional: for direct anchoring.bitcoinNetwork("mainnet")// Optional: mainnet, testnet, regtest.batchSize(10)// Optional: operation batch size.timeoutSeconds(60)// Optional: HTTP timeout.build()
Integration with TrustWeave
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
importcom.trustweave.TrustWeaveimportcom.trustweave.iondid.*valconfig=IonDidConfig.testnet()valTrustWeave=TrustWeave.create{kms=InMemoryKeyManagementService()didMethods{+IonDidMethod(kms!!,config)}}// Use did:ionvaldid=TrustWeave.createDid("ion"){algorithm=KeyAlgorithm.ED25519}.getOrThrow()valresolved=TrustWeave.resolveDid(did.id).getOrThrow()
Long-form vs Short-form DIDs
Long-form DID: Contains operation data, works immediately after creation (before anchoring)
Short-form DID: Compact identifier, works after anchoring to Bitcoin
When creating a DID, you receive a long-form DID. After anchoring (done by ION nodes), you can use the short-form DID.
Error Handling
Common errors and solutions:
Error
Cause
Solution
ionNodeUrl is required
Missing ION node endpoint
Provide ION node URL
DID not found
DID not yet anchored
Use long-form DID or wait for anchoring
Network error
Cannot reach ION node
Check network connectivity and node URL
Operation failed
Invalid operation
Check operation format and keys
Testing
For testing without actual ION node:
1
2
3
4
5
6
// Use testnet ION nodevalconfig=IonDidConfig.testnet()valmethod=IonDidMethod(kms,config)// Operations are submitted to testnet nodevaldocument=method.createDid(options)
Best Practices
Use testnet for development: ION testnet for testing
Handle long-form DIDs: Store long-form DID until short-form is available
Wait for anchoring: Operations take time to be anchored to Bitcoin
Error handling: Implement retry logic for network operations
Key management: Securely store recovery keys for DID recovery