trustweave-common Package Structure
The trustweave-common module is organized into logical packages for better code organization and discoverability.
Package Organization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
com.trustweave.core/
├── exception/ # Exception types and error handling
│ ├── TrustWeaveException.kt
│ └── TrustWeaveErrors.kt
│
├── plugin/ # Plugin infrastructure
│ ├── PluginRegistry.kt
│ ├── PluginMetadata.kt
│ ├── PluginConfiguration.kt
│ └── ProviderChain.kt
│
└── util/ # General utilities
├── DigestUtils.kt # JSON canonicalization and digest computation
├── ResultExtensions.kt # Result<T> extension functions
├── TrustWeaveConstants.kt
└── Validation.kt # Generic validation infrastructure (ValidationResult)
Package Details
com.trustweave.core.exception
Exception types and error handling:
TrustWeaveException– Base exception for TrustWeave operationsNotFoundException– Exception thrown when a requested resource is not foundInvalidOperationException– Exception thrown when an operation is invalidTrustWeaveError– Sealed class hierarchy for structured API errors with context
Error Types in TrustWeaveError:
- Plugin Errors:
BlankPluginId,PluginAlreadyRegistered,PluginNotFound,PluginInitializationFailed - Provider Errors:
NoProvidersFound,PartialProvidersFound,AllProvidersFailed - Configuration Errors:
ConfigNotFound,ConfigReadFailed,InvalidConfigFormat - JSON/Digest Errors:
InvalidJson,JsonEncodeFailed,DigestFailed,EncodeFailed - Generic Errors:
ValidationFailed,InvalidOperation,InvalidState,Unknown,UnsupportedAlgorithm
Example:
1
2
3
4
5
6
7
8
9
10
import com.trustweave.core.exception.TrustWeaveError
import com.trustweave.core.exception.NotFoundException
try {
// operation
} catch (e: NotFoundException) {
// handle not found
} catch (e: TrustWeaveError) {
// handle structured error
}
com.trustweave.core.plugin
Plugin infrastructure for extensibility:
PluginRegistry– Thread-safe, unified plugin registry for capability-based discoveryPluginMetadata– Metadata about plugins (capabilities, dependencies, configuration)PluginCapabilities– Domain-agnostic capabilities (features, extensions)PluginConfiguration– Configuration loaded from YAML/JSON filesPluginType– Framework-level plugin type enumeration (BLOCKCHAIN, CREDENTIAL_SERVICE, DID_METHOD, KMS, etc.)ProviderChain– Provider chain with automatic fallback supportPluginLifecycle– Lifecycle interface for plugin initialization, startup, shutdown, and cleanup
Example:
1
2
3
4
5
import com.trustweave.core.plugin.PluginRegistry
import com.trustweave.core.plugin.PluginMetadata
PluginRegistry.register(metadata, instance)
val plugins = PluginRegistry.findByCapability("credential-storage")
com.trustweave.core.util
General utilities used across TrustWeave:
DigestUtils– JSON canonicalization and SHA-256 digest computation with multibase encoding (base58btc)ResultExtensions– Extension functions forResult<T>(mapError, combine, mapSequential, onSuccess, onFailure, etc.)TrustWeaveConstants– Common constantsValidation– Generic validation infrastructure (ValidationResultsealed class)
Example:
1
2
3
4
5
6
7
8
9
10
11
12
import com.trustweave.core.util.DigestUtils
import com.trustweave.core.util.ValidationResult
val digest = DigestUtils.sha256DigestMultibase(jsonElement)
val canonical = DigestUtils.canonicalizeJson(jsonString)
// Generic validation result
val validation: ValidationResult = someValidation()
if (!validation.isValid()) {
val error = validation as ValidationResult.Invalid
println("Validation failed: ${error.message}")
}
Note: Domain-specific validators are in their respective modules:
DidValidator→com.trustweave.did.validation.DidValidator(intrustweave-did)ChainIdValidator→com.trustweave.anchor.validation.ChainIdValidator(intrustweave-anchor)
Related Packages
Domain-Specific Components
Domain-specific functionality is located in their respective modules:
- Proof Types →
com.trustweave.credential.proof.ProofType(intrustweave-credentials) - Schema Format →
com.trustweave.credential.SchemaFormat(intrustweave-credentials) - DID Validation →
com.trustweave.did.validation.DidValidator(intrustweave-did) - Chain ID Validation →
com.trustweave.anchor.validation.ChainIdValidator(intrustweave-anchor) - Credential Errors →
com.trustweave.credential.exception.CredentialError(intrustweave-credentials) - DID Errors →
com.trustweave.did.exception.DidError(intrustweave-did) - Blockchain Errors →
com.trustweave.anchor.exceptions.BlockchainError(intrustweave-anchor)
Migration Notes
If you’re migrating from an older version:
com.trustweave.json.DigestUtils→com.trustweave.core.util.DigestUtilscom.trustweave.core.TrustWeaveException→com.trustweave.core.exception.TrustWeaveExceptioncom.trustweave.core.TrustWeaveError→com.trustweave.core.exception.TrustWeaveErrorcom.trustweave.core.types.ProofType→com.trustweave.credential.proof.ProofType(intrustweave-credentials)com.trustweave.core.DidValidator→com.trustweave.did.validation.DidValidator(intrustweave-did)com.trustweave.core.ChainIdValidator→com.trustweave.anchor.validation.ChainIdValidator(intrustweave-anchor)com.trustweave.core.ValidationResult→com.trustweave.core.util.ValidationResult(still in common, but validators moved)
Benefits of This Organization
- Clear Separation of Concerns – Related functionality is grouped together
- Easier Discovery – Developers can find related classes more easily
- Better Scalability – New utilities have a clear place to go
- Consistent Naming – Follows common Kotlin/Java package conventions
- Reduced Coupling – Clear boundaries between different concerns