Insurance Claims and Verification Scenario
This guide demonstrates how to build a complete insurance claims verification system using TrustWeave. You’ll learn how insurance companies can issue claim credentials, how service providers (repair shops, medical facilities) can issue verification credentials, and how the entire claims process can be streamlined with verifiable credentials while preventing fraud.
What You’ll Build
By the end of this tutorial, you’ll have:
- ✅ Created DIDs for insurance company, policyholder, and service providers
- ✅ Issued Verifiable Credentials for insurance claims
- ✅ Created damage assessment and repair verification credentials
- ✅ Built claim verification workflow
- ✅ Implemented fraud prevention through credential chains
- ✅ Created comprehensive claim presentations
- ✅ Verified all claim-related credentials
Big Picture & Significance
The Insurance Claims Challenge
Insurance claims processing is complex, slow, and vulnerable to fraud. Traditional claims systems require manual verification, are prone to errors, and don’t provide transparency for policyholders.
Industry Context:
- Market Size: Global insurance market exceeds $5 trillion
- Fraud Impact: Insurance fraud costs $80+ billion annually in the US alone
- Processing Time: Average claim processing takes 2-4 weeks
- Verification Costs: Significant resources spent on claim verification
- Customer Experience: Complex processes frustrate policyholders
Why This Matters:
- Fraud Prevention: Cryptographic proof prevents claim fraud
- Speed: Reduce claim processing time by 80%
- Transparency: Policyholders can track claim status
- Verification: Instant verification of service provider credentials
- Cost Reduction: Eliminate expensive manual verification
- Trust: Cryptographic proof builds trust between parties
The Claims Verification Problem
Traditional insurance claims face critical issues:
- Fraud Vulnerability: Fake claims and inflated costs are common
- Slow Processing: Manual verification takes weeks
- High Costs: Verification processes are expensive
- No Transparency: Policyholders can’t track claim status
- Error-Prone: Manual processes prone to mistakes
- Complex Workflows: Multiple parties and documents
Value Proposition
Problems Solved
- Fraud Prevention: Cryptographic proof prevents claim fraud
- Instant Verification: Verify service provider credentials instantly
- Transparency: Policyholders can track claim status
- Cost Reduction: Eliminate expensive manual verification
- Efficiency: Streamlined claims processing
- Trust: Cryptographic proof builds trust
- Compliance: Automated compliance with insurance regulations
Business Benefits
For Insurance Companies:
- Fraud Prevention: Eliminates claim fraud
- Cost Savings: 70-80% reduction in verification costs
- Speed: 80% reduction in processing time
- Trust: Enhanced trust through verifiable credentials
- Compliance: Automated regulatory compliance
For Policyholders:
- Transparency: Track claim status in real-time
- Speed: Faster claim processing
- Trust: Cryptographic proof of claim validity
- Control: Access to claim information
- Efficiency: Streamlined claims process
For Service Providers:
- Verification: Instant credential verification
- Trust: Cryptographic proof of service quality
- Efficiency: Faster payment processing
- Reputation: Enhanced reputation through verifiable credentials
ROI Considerations
- Fraud Prevention: Eliminates billions in fraud losses
- Processing Speed: 80% reduction in processing time
- Cost Reduction: 70-80% reduction in verification costs
- Customer Satisfaction: Improved policyholder experience
- Compliance: Automated regulatory compliance
Understanding the Problem
Traditional insurance claims have several problems:
- Fraud is common: Fake claims and inflated costs
- Processing is slow: Manual verification takes weeks
- High costs: Verification processes are expensive
- No transparency: Policyholders can’t track status
- Error-prone: Manual processes prone to mistakes
TrustWeave solves this by enabling:
- Cryptographic proof: Tamper-proof claim credentials
- Instant verification: Verify service provider credentials instantly
- Transparency: Policyholders can track claim status
- Fraud prevention: Cryptographic proof prevents fraud
- Efficiency: Streamlined claims processing
How It Works: The Claims Flow
flowchart TD
A["Policyholder<br/>Files Insurance Claim"] -->|submits| B["Insurance Company<br/>Issues Claim Credential"]
C["Service Provider<br/>Assesses Damage<br/>Issues Assessment Credential"] -->|verifies| B
D["Repair Shop<br/>Performs Repair<br/>Issues Repair Credential"] -->|verifies| B
B -->|stored in| E["Policyholder Wallet<br/>Stores claim credentials<br/>Tracks claim status"]
E -->|presents| F["Insurance Company<br/>Verifies all credentials<br/>Processes claim<br/>Issues payment"]
style A fill:#1976d2,stroke:#0d47a1,stroke-width:2px,color:#fff
style B fill:#f57c00,stroke:#e65100,stroke-width:2px,color:#fff
style C fill:#7b1fa2,stroke:#4a148c,stroke-width:2px,color:#fff
style D fill:#7b1fa2,stroke:#4a148c,stroke-width:2px,color:#fff
style E fill:#388e3c,stroke:#1b5e20,stroke-width:2px,color:#fff
style F fill:#c2185b,stroke:#880e4f,stroke-width:2px,color:#fff
Prerequisites
- Java 21+
- Kotlin 2.2.0+
- Gradle 8.5+
- Basic understanding of Kotlin and coroutines
Step 1: Add Dependencies
Add TrustWeave dependencies to your build.gradle.kts:
1
2
3
4
5
6
7
8
9
10
dependencies {
// Core TrustWeave modules
implementation("com.trustweave:trustweave-all:1.0.0-SNAPSHOT")
// Kotlinx Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}
Step 2: Complete Runnable Example
Here’s the full insurance claims verification flow using the TrustWeave facade API:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package com.example.insurance.claims
import com.trustweave.TrustWeave
import com.trustweave.core.*
import com.trustweave.credential.PresentationOptions
import com.trustweave.credential.wallet.Wallet
import com.trustweave.spi.services.WalletCreationOptionsBuilder
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import java.time.Instant
import java.time.temporal.ChronoUnit
fun main() = runBlocking {
println("=".repeat(70))
println("Insurance Claims and Verification Scenario - Complete End-to-End Example")
println("=".repeat(70))
// Step 1: Create TrustWeave instance
val TrustWeave = TrustWeave.create()
println("\n✅ TrustWeave initialized")
// Step 2: Create DIDs for all parties
import com.trustweave.trust.types.DidCreationResult
import com.trustweave.trust.types.WalletCreationResult
val insuranceCompanyDidResult = trustWeave.createDid { method("key") }
val insuranceCompanyDid = when (insuranceCompanyDidResult) {
is DidCreationResult.Success -> insuranceCompanyDidResult.did
else -> throw IllegalStateException("Failed to create insurance company DID: ${insuranceCompanyDidResult.reason}")
}
val insuranceCompanyResolution = trustWeave.resolveDid(insuranceCompanyDid)
val insuranceCompanyDoc = when (insuranceCompanyResolution) {
is DidResolutionResult.Success -> insuranceCompanyResolution.document
else -> throw IllegalStateException("Failed to resolve insurance company DID")
}
val insuranceCompanyKeyId = insuranceCompanyDoc.verificationMethod.firstOrNull()?.id?.substringAfter("#")
?: throw IllegalStateException("No verification method found")
val policyholderDidResult = trustWeave.createDid { method("key") }
val policyholderDid = when (policyholderDidResult) {
is DidCreationResult.Success -> policyholderDidResult.did
else -> throw IllegalStateException("Failed to create policyholder DID: ${policyholderDidResult.reason}")
}
val assessorDidResult = trustWeave.createDid { method("key") }
val assessorDid = when (assessorDidResult) {
is DidCreationResult.Success -> assessorDidResult.did
else -> throw IllegalStateException("Failed to create assessor DID: ${assessorDidResult.reason}")
}
val assessorResolution = trustWeave.resolveDid(assessorDid)
val assessorDoc = when (assessorResolution) {
is DidResolutionResult.Success -> assessorResolution.document
else -> throw IllegalStateException("Failed to resolve assessor DID")
}
val assessorKeyId = assessorDoc.verificationMethod.firstOrNull()?.id?.substringAfter("#")
?: throw IllegalStateException("No verification method found")
val repairShopDidResult = trustWeave.createDid { method("key") }
val repairShopDid = when (repairShopDidResult) {
is DidCreationResult.Success -> repairShopDidResult.did
else -> throw IllegalStateException("Failed to create repair shop DID: ${repairShopDidResult.reason}")
}
val repairShopResolution = trustWeave.resolveDid(repairShopDid)
val repairShopDoc = when (repairShopResolution) {
is DidResolutionResult.Success -> repairShopResolution.document
else -> throw IllegalStateException("Failed to resolve repair shop DID")
}
val repairShopKeyId = repairShopDoc.verificationMethod.firstOrNull()?.id?.substringAfter("#")
?: throw IllegalStateException("No verification method found")
println("✅ Insurance Company DID: ${insuranceCompanyDid.value}")
println("✅ Policyholder DID: ${policyholderDid.value}")
println("✅ Damage Assessor DID: ${assessorDid.value}")
println("✅ Repair Shop DID: ${repairShopDid.value}")
// Step 3: Policyholder files claim - Insurance company issues claim credential
val claimCredential = TrustWeave.issueCredential(
issuerDid = insuranceCompanyDid.value,
issuerKeyId = insuranceCompanyKeyId,
credentialSubject = buildJsonObject {
put("id", policyholderDid.value)
put("claim", buildJsonObject {
put("claimNumber", "CLM-2024-001234")
put("claimType", "Auto Damage")
put("incidentDate", "2024-10-15")
put("incidentLocation", "123 Main St, City, State")
put("incidentDescription", "Vehicle collision with another vehicle")
put("policyNumber", "POL-2024-567890")
put("claimStatus", "Filed")
put("filingDate", Instant.now().toString())
put("estimatedDamage", "5000.00")
put("currency", "USD")
})
},
types = listOf("VerifiableCredential", "InsuranceClaimCredential", "ClaimCredential"),
expirationDate = Instant.now().plus(1, ChronoUnit.YEARS).toString()
).getOrThrow()
println("\n✅ Claim credential issued: ${claimCredential.id}")
println(" Claim Number: CLM-2024-001234")
println(" Claim Type: Auto Damage")
println(" Status: Filed")
// Step 4: Damage assessor issues assessment credential
val assessmentCredential = TrustWeave.issueCredential(
issuerDid = assessorDid.value,
issuerKeyId = assessorKeyId,
credentialSubject = buildJsonObject {
put("id", policyholderDid.value)
put("assessment", buildJsonObject {
put("claimNumber", "CLM-2024-001234")
put("assessmentDate", Instant.now().toString())
put("assessorName", "John Smith")
put("assessorLicense", "ASS-12345")
put("damageType", "Vehicle Collision")
put("damageDescription", "Front bumper damage, headlight replacement needed")
put("estimatedRepairCost", "4800.00")
put("currency", "USD")
put("repairRequired", true)
put("totalLoss", false)
put("photosTaken", true)
put("assessmentStatus", "Completed")
})
},
types = listOf("VerifiableCredential", "DamageAssessmentCredential", "AssessmentCredential"),
expirationDate = Instant.now().plus(6, ChronoUnit.MONTHS).toString()
).getOrThrow()
println("✅ Damage assessment credential issued: ${assessmentCredential.id}")
println(" Estimated Repair Cost: $4,800.00")
println(" Assessment Status: Completed")
// Step 5: Repair shop performs repair and issues repair credential
val repairCredential = TrustWeave.issueCredential(
issuerDid = repairShopDid.value,
issuerKeyId = repairShopKeyId,
credentialSubject = buildJsonObject {
put("id", policyholderDid.value)
put("repair", buildJsonObject {
put("claimNumber", "CLM-2024-001234")
put("repairShopName", "Quality Auto Repair")
put("repairShopLicense", "RSH-78901")
put("repairStartDate", "2024-10-20")
put("repairCompletionDate", "2024-10-25")
put("repairDescription", "Replaced front bumper and headlight assembly")
put("partsUsed", listOf(
"Front Bumper - OEM",
"Headlight Assembly - OEM",
"Paint and Materials"
))
put("laborHours", 8.5)
put("laborRate", "125.00")
put("partsCost", "3200.00")
put("laborCost", "1062.50")
put("totalCost", "4262.50")
put("currency", "USD")
put("warrantyProvided", true)
put("warrantyPeriod", "12 months")
put("repairStatus", "Completed")
})
},
types = listOf("VerifiableCredential", "RepairCredential", "ServiceCredential"),
expirationDate = Instant.now().plus(2, ChronoUnit.YEARS).toString()
).getOrThrow()
println("✅ Repair credential issued: ${repairCredential.id}")
println(" Total Repair Cost: $4,262.50")
println(" Repair Status: Completed")
// Step 6: Create policyholder wallet and store all credentials
val walletResult = trustWeave.wallet {
holder(policyholderDid.value)
enableOrganization()
enablePresentation()
}
val policyholderWallet = when (walletResult) {
is WalletCreationResult.Success -> walletResult.wallet
else -> throw IllegalStateException("Failed to create wallet: ${walletResult.reason}")
}
val claimCredentialId = policyholderWallet.store(claimCredential)
val assessmentCredentialId = policyholderWallet.store(assessmentCredential)
val repairCredentialId = policyholderWallet.store(repairCredential)
println("\n✅ All claim credentials stored in policyholder wallet")
// Step 7: Organize credentials
policyholderWallet.withOrganization { org ->
val claimsCollectionId = org.createCollection("Insurance Claims", "Insurance claim credentials")
org.addToCollection(claimCredentialId, claimsCollectionId)
org.addToCollection(assessmentCredentialId, claimsCollectionId)
org.addToCollection(repairCredentialId, claimsCollectionId)
org.tagCredential(claimCredentialId, setOf("claim", "insurance", "auto", "filed"))
org.tagCredential(assessmentCredentialId, setOf("assessment", "damage", "verified"))
org.tagCredential(repairCredentialId, setOf("repair", "completed", "verified"))
println("✅ Claim credentials organized")
}
// Step 8: Insurance company verifies all credentials
println("\n📋 Insurance Company Verification Process:")
val claimVerification = TrustWeave.verifyCredential(claimCredential).getOrThrow()
println("Claim Credential: ${if (claimVerification.valid) "✅ VALID" else "❌ INVALID"}")
val assessmentVerification = TrustWeave.verifyCredential(assessmentCredential).getOrThrow()
println("Assessment Credential: ${if (assessmentVerification.valid) "✅ VALID" else "❌ INVALID"}")
val repairVerification = TrustWeave.verifyCredential(repairCredential).getOrThrow()
println("Repair Credential: ${if (repairVerification.valid) "✅ VALID" else "❌ INVALID"}")
// Step 9: Verify claim consistency and fraud prevention
println("\n🔍 Fraud Prevention Check:")
val claimSubject = claimCredential.credentialSubject.jsonObject["claim"]?.jsonObject
val assessmentSubject = assessmentCredential.credentialSubject.jsonObject["assessment"]?.jsonObject
val repairSubject = repairCredential.credentialSubject.jsonObject["repair"]?.jsonObject
val claimNumber = claimSubject?.get("claimNumber")?.jsonPrimitive?.content
val assessmentClaimNumber = assessmentSubject?.get("claimNumber")?.jsonPrimitive?.content
val repairClaimNumber = repairSubject?.get("claimNumber")?.jsonPrimitive?.content
val claimNumbersMatch = claimNumber == assessmentClaimNumber && claimNumber == repairClaimNumber
if (claimNumbersMatch) {
println("✅ Claim numbers match across all credentials")
} else {
println("❌ Claim numbers do NOT match - Potential fraud detected")
}
// Verify cost consistency
val estimatedCost = assessmentSubject?.get("estimatedRepairCost")?.jsonPrimitive?.content?.toDouble() ?: 0.0
val actualCost = repairSubject?.get("totalCost")?.jsonPrimitive?.content?.toDouble() ?: 0.0
val costVariance = ((actualCost - estimatedCost) / estimatedCost) * 100
println(" Estimated Cost: $$estimatedCost")
println(" Actual Cost: $$actualCost")
println(" Cost Variance: ${String.format("%.2f", costVariance)}%")
if (costVariance <= 10.0) {
println("✅ Cost variance within acceptable range")
} else {
println("⚠️ Cost variance exceeds threshold - Review required")
}
// Step 10: Create comprehensive claim presentation
val claimPresentation = policyholderWallet.withPresentation { pres ->
pres.createPresentation(
credentialIds = listOf(claimCredentialId, assessmentCredentialId, repairCredentialId),
holderDid = policyholderDid.value,
options = PresentationOptions(
holderDid = policyholderDid.value,
challenge = "claim-verification-${System.currentTimeMillis()}"
)
)
} ?: error("Presentation capability not available")
println("\n✅ Comprehensive claim presentation created")
println(" Holder: ${claimPresentation.holder}")
println(" Credentials: ${claimPresentation.verifiableCredential.size}")
// Step 11: Process claim payment (insurance company issues payment credential)
val allCredentialsValid = listOf(claimVerification, assessmentVerification, repairVerification).all { it.valid }
if (allCredentialsValid && claimNumbersMatch && costVariance <= 10.0) {
val paymentCredential = TrustWeave.issueCredential(
issuerDid = insuranceCompanyDid.value,
issuerKeyId = insuranceCompanyKeyId,
credentialSubject = buildJsonObject {
put("id", policyholderDid.value)
put("payment", buildJsonObject {
put("claimNumber", "CLM-2024-001234")
put("paymentAmount", "4262.50")
put("currency", "USD")
put("paymentDate", Instant.now().toString())
put("paymentMethod", "Direct Deposit")
put("paymentStatus", "Processed")
put("deductible", "500.00")
put("netPayment", "3762.50")
})
},
types = listOf("VerifiableCredential", "PaymentCredential", "InsurancePaymentCredential"),
expirationDate = Instant.now().plus(7, ChronoUnit.YEARS).toString()
).getOrThrow()
val paymentCredentialId = policyholderWallet.store(paymentCredential)
policyholderWallet.withOrganization { org ->
org.addToCollection(paymentCredentialId, org.listCollections().firstOrNull()?.id ?: "")
org.tagCredential(paymentCredentialId, setOf("payment", "processed", "claim"))
}
println("\n✅ Payment credential issued: ${paymentCredential.id}")
println(" Payment Amount: $4,262.50")
println(" Payment Status: Processed")
println(" Net Payment (after deductible): $3,762.50")
} else {
println("\n❌ Claim processing failed - Verification issues detected")
}
// Step 12: Display wallet statistics
val stats = policyholderWallet.getStatistics()
println("\n📊 Policyholder Wallet Statistics:")
println(" Total credentials: ${stats.totalCredentials}")
println(" Valid credentials: ${stats.validCredentials}")
println(" Collections: ${stats.collectionsCount}")
println(" Tags: ${stats.tagsCount}")
// Step 13: Summary
println("\n" + "=".repeat(70))
if (allCredentialsValid && claimNumbersMatch) {
println("✅ INSURANCE CLAIM VERIFICATION COMPLETE")
println(" All credentials verified successfully")
println(" Claim processed and payment issued")
println(" Fraud prevention checks passed")
} else {
println("❌ CLAIM VERIFICATION FAILED")
println(" Some credentials could not be verified")
println(" Additional review required")
}
println("=".repeat(70))
}
Expected Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
======================================================================
Insurance Claims and Verification Scenario - Complete End-to-End Example
======================================================================
✅ TrustWeave initialized
✅ Insurance Company DID: did:key:z6Mk...
✅ Policyholder DID: did:key:z6Mk...
✅ Damage Assessor DID: did:key:z6Mk...
✅ Repair Shop DID: did:key:z6Mk...
✅ Claim credential issued: urn:uuid:...
Claim Number: CLM-2024-001234
Claim Type: Auto Damage
Status: Filed
✅ Damage assessment credential issued: urn:uuid:...
Estimated Repair Cost: $4,800.00
Assessment Status: Completed
✅ Repair credential issued: urn:uuid:...
Total Repair Cost: $4,262.50
Repair Status: Completed
✅ All claim credentials stored in policyholder wallet
✅ Claim credentials organized
📋 Insurance Company Verification Process:
Claim Credential: ✅ VALID
Assessment Credential: ✅ VALID
Repair Credential: ✅ VALID
🔍 Fraud Prevention Check:
✅ Claim numbers match across all credentials
Estimated Cost: $4800.0
Actual Cost: $4262.5
Cost Variance: -11.20%
✅ Cost variance within acceptable range
✅ Comprehensive claim presentation created
Holder: did:key:z6Mk...
Credentials: 3
✅ Payment credential issued: urn:uuid:...
Payment Amount: $4,262.50
Payment Status: Processed
Net Payment (after deductible): $3,762.50
📊 Policyholder Wallet Statistics:
Total credentials: 4
Valid credentials: 4
Collections: 1
Tags: 9
======================================================================
✅ INSURANCE CLAIM VERIFICATION COMPLETE
All credentials verified successfully
Claim processed and payment issued
Fraud prevention checks passed
======================================================================
Key Features Demonstrated
- Multi-Party Credentials: Multiple parties issue credentials for the same claim
- Credential Chain: Link claim, assessment, and repair credentials
- Fraud Prevention: Verify consistency across credentials
- Cost Verification: Check cost variance for fraud detection
- Comprehensive Presentations: Multiple credentials in a single presentation
- Payment Processing: Issue payment credentials after verification
Real-World Extensions
- Medical Claims: Support health insurance claims with medical provider credentials
- Property Claims: Support property insurance with inspector credentials
- Blockchain Anchoring: Anchor critical claim credentials for permanent records
- Revocation Lists: Check against revocation lists for invalid credentials
- Multi-Policy Support: Manage claims across multiple insurance policies
- Audit Trails: Track all claim-related events and verifications
Related Documentation
- Quick Start - Get started with TrustWeave
- Common Patterns - Reusable code patterns
- API Reference - Complete API documentation
- Healthcare Medical Records Scenario - Related healthcare scenario
- Troubleshooting - Common issues and solutions