trustweave-common
The trustweave-common module provides domain-agnostic core infrastructure for TrustWeave:
- Plugin Infrastructure – Plugin registry, metadata, configuration, and provider chains
- Error Handling – Structured error types with rich context (
TrustWeaveErrorhierarchy) - JSON Utilities – JSON canonicalization and SHA-256 digest computation
- Result Utilities – Extension functions for
Result<T>error handling - Validation Infrastructure – Generic validation framework (domain-specific validators are in their respective modules)
Important: This module is intentionally domain-agnostic. Domain-specific functionality (DID validation, credential errors, blockchain errors, etc.) is located in their respective domain modules (trustweave-did, trustweave-credentials, trustweave-anchor, etc.).
Key Components
Plugin Infrastructure (org.trustweave.core.plugin)
PluginRegistry– Thread-safe, capability-based plugin discovery and registrationPluginMetadata– Plugin metadata with domain-agnostic capabilitiesPluginConfiguration– Configuration loaded from YAML/JSON filesProviderChain– Provider chain with automatic fallback supportPluginType– Framework-level plugin type enumeration (BLOCKCHAIN, CREDENTIAL_SERVICE, DID_METHOD, etc.)PluginLifecycle– Lifecycle interface for plugin initialization, startup, shutdown, and cleanup
Error Handling (org.trustweave.core.exception)
TrustWeaveException– Base exception for TrustWeave operationsTrustWeaveError– Sealed hierarchy of structured errors with rich context:- 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
- Plugin Errors:
Utilities (org.trustweave.core.util)
DigestUtils– JSON canonicalization and SHA-256 digest computation with multibase encoding (base58btc)- Optimized JSON canonicalization with lexicographical key sorting
- Efficient SHA-256 digest computation
- Multibase encoding (base58btc) support
ResultExtensions– Extension functions forResult<T>(mapError, combine, mapSequential, trustweaveCatching, etc.)- Functional-style error handling
- Automatic conversion of
ThrowabletoTrustWeaveException - Error code extraction and categorization
Validation– Generic validation infrastructure (ValidationResultsealed class)- Type-safe validation results
- Reusable validation patterns
TrustWeaveConstants– Common constants
Identifiers (org.trustweave.core.identifiers)
Iri– RFC 3987 compliant Internationalized Resource IdentifierKeyId– Type-safe key identifier with fragment supportDid,VerificationMethodId,DidUrl– DID-related identifiers (intrustweave-didmodule)- Extension functions for safe parsing (
toIriOrNull,toKeyIdOrNull, etc.)
Serialization (org.trustweave.core.serialization)
- Custom Serializers:
IriSerializer,KeyIdSerializer,InstantSerializer,DidSerializer,VerificationMethodIdSerializer,DidUrlSerializer - SerializationModule: Centralized serialization configuration
- Optimized JSON serialization for TrustWeave types
Note: Domain-specific validators (DID, Chain ID) are in their respective domain modules:
- DID validation →
org.trustweave.did.validation.DidValidator - Chain ID validation →
org.trustweave.anchor.validation.ChainIdValidator
Add the module alongside any DID/KMS components you require:
1
2
3
dependencies {
implementation("org.trustweave:trustweave-common:1.0.0-SNAPSHOT")
}
Result: Gradle exposes the core infrastructure APIs for plugin management, error handling, and JSON utilities:
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
import org.trustweave.core.plugin.*
import org.trustweave.core.exception.TrustWeaveError
import org.trustweave.core.util.*
// Register a plugin
val metadata = PluginMetadata(
id = "my-plugin",
name = "My Plugin",
version = "1.0.0",
provider = "custom",
capabilities = PluginCapabilities(
features = setOf("credential-storage")
)
)
try {
PluginRegistry.register(metadata, pluginInstance)
} catch (e: TrustWeaveError.BlankPluginId) {
println("Plugin ID cannot be blank")
} catch (e: TrustWeaveError.PluginAlreadyRegistered) {
println("Plugin already registered: ${e.pluginId}")
}
// Use JSON utilities
val digest = DigestUtils.sha256DigestMultibase(jsonElement)
// Handle errors with Result utilities
val result: Result<String> = someOperation()
result.fold(
onSuccess = { value -> println("Success: $value") },
onFailure = { error ->
when (error) {
is TrustWeaveError.InvalidJson -> {
println("Invalid JSON: ${error.parseError}")
}
is TrustWeaveError.ConfigNotFound -> {
println("Config not found: ${error.path}")
}
else -> println("Error: ${error.message}")
}
}
)
Why it matters: trustweave-common provides the foundational infrastructure that all TrustWeave modules depend on. It’s domain-agnostic, meaning it contains no business logic specific to DIDs, credentials, or blockchains—those are handled by their respective domain modules.
Dependencies
- Minimal dependencies: Only Kotlin standard library, kotlinx.serialization, and kotlinx.coroutines
- No domain dependencies: This module does not depend on DID, credential, blockchain, or wallet modules
- Upstream modules (
trustweave-did,trustweave-credentials,trustweave-anchor, etc.) depend ontrustweave-commonand add domain-specific functionality
Next Steps
- SPI interfaces are included in this module. See SPI Documentation to understand adapter/service expectations.
- Explore
trustweave-trustfor trust registry runtime components. - See JSON Utilities (now part of common module) and
trustweave-kmsfor supporting utilities. - See Package Structure for detailed package organization.
Package Structure
The trustweave-common module is organized into logical packages:
org.trustweave.core.exception– Exception types and error handlingTrustWeaveException,NotFoundException,InvalidOperationExceptionTrustWeaveError(sealed class hierarchy with 13+ specific error types)
org.trustweave.core.plugin– Plugin infrastructurePluginRegistry(thread-safe, capability-based discovery)PluginMetadata,PluginCapabilities(domain-agnostic)PluginConfiguration,PluginType(framework-level plugin types)ProviderChain(fallback support)PluginLifecycle(lifecycle management)
org.trustweave.core.util– General utilitiesDigestUtils(JSON canonicalization and SHA-256 digest computation)ResultExtensions(Resultextension functions) TrustWeaveConstantsValidation(generic validation infrastructure -ValidationResult)
org.trustweave.core.identifiers– Identifier typesIri(RFC 3987 compliant Internationalized Resource Identifier)KeyId(type-safe key identifier)- Extension functions for safe parsing
org.trustweave.core.serialization– Serialization support- Custom serializers for TrustWeave types (Iri, KeyId, Instant, Did, etc.)
SerializationModulefor centralized configuration
Note: Domain-specific components are in their respective modules:
- DID validation →
org.trustweave.did.validation.DidValidator(intrustweave-did) - Chain ID validation →
org.trustweave.anchor.validation.ChainIdValidator(intrustweave-anchor) - Credential errors →
org.trustweave.credential.exception.CredentialError(intrustweave-credentials) - Proof types →
org.trustweave.credential.proof.ProofType(intrustweave-credentials)