TrustWeave

TrustWeave - The main facade for trust and identity operations.

TrustWeave provides a unified interface for all trust-related operations including credential issuance/verification, DID management, trust anchor management, and wallet operations. It serves as the primary entry point for applications using TrustWeave.

Concurrency Model:

  • All operations are suspend functions and use structured concurrency

  • I/O-bound operations use configurable dispatchers (default: Dispatchers.IO)

  • All operations support cancellation via coroutine cancellation

  • Timeout support is built-in for all I/O operations

  • Operations are non-blocking and can be safely called from coroutine scopes

Example Usage:

// Quick start (in-memory, did:key)
val trustWeave = TrustWeave.quickStart()

// Or custom configuration
val trustWeave = TrustWeave.build {
keys { provider("inMemory"); algorithm("Ed25519") }
did { method("key") { algorithm("Ed25519") } }
trust { provider("inMemory") }
}

val issuerDid = trustWeave.createDid().getOrThrowDid()

// Issue credentials (key ID auto-extracted via signedBy(issuerDid))
val credential = trustWeave.issue {
credential {
type("EducationCredential")
issuer(issuerDid)
subject("did:key:student") { "degree" to "Bachelor of Science" }
}
signedBy(issuerDid)
}.getOrThrow()

// Verify (simple overload)
val result = trustWeave.verify(credential)

// Or use DSL for advanced options
val result = trustWeave.verify {
credential(credential)
checkRevocation()
validateSchema("https://example.com/schemas/degree.json")
}

Types

Link copied to clipboard
object Companion

Build a TrustWeave instance with the given configuration. Static factories TrustWeave.inMemory and TrustWeave.from are in TrustWeaveFactories.kt.

Properties

Link copied to clipboard

Active TrustedDomainManager for this facade, or null when no domain { ... } block was configured.

Link copied to clipboard

Blockchain anchoring service.

Link copied to clipboard
open override val configuration: TrustWeaveConfig

The underlying configuration.

Link copied to clipboard

Smart contract operations service.

Functions

Link copied to clipboard
suspend fun anchorThroughDomain(operationKind: String, chainId: String, payload: JsonElement, feeStrategy: FeeStrategy = FeeStrategy.DomainPays, maxFee: TokenAmount? = null, mediaType: String = "application/json"): AnchorResult

Anchor payload through the active TrustedDomainManager. Throws IllegalStateException when no domain { ... } was configured; otherwise delegates to TrustedDomainManager.anchor verbatim.

Link copied to clipboard
open override fun close()

Close and cleanup resources held by this TrustWeave instance.

Link copied to clipboard
suspend fun closeAsync()

Suspending form of close with the same ownership, error-handling and idempotence semantics: stop() + cleanup() of PluginLifecycle components are awaited instead of blocking the calling thread. Calling either close or closeAsync more than once (in any combination) closes the components only once.

Link copied to clipboard
suspend fun TrustWeave.completeWorkflow(didBlock: DidBuilder.() -> Unit, credentialBlock: suspend (String) -> IssuanceResult, wallet: Wallet, organizeBlock: suspend (StoredCredential) -> OrganizationResult? = null): Result<WorkflowResult>

Extension function for complete workflow: create DID, issue, store, organize, verify.

Link copied to clipboard
suspend fun createDid(method: String? = null, timeout: Duration = 10.seconds, block: DidBuilder.() -> Unit = {}): DidCreationResult
Link copied to clipboard
suspend fun TrustWeave.createDidAndIssue(didBlock: DidBuilder.() -> Unit, credentialBlock: suspend (String) -> IssuanceResult): IssuanceResult

Extension function to create DID and issue credential in one workflow.

Link copied to clipboard
suspend fun TrustWeave.createDidIssueAndStore(didBlock: DidBuilder.() -> Unit, credentialBlock: suspend (String) -> IssuanceResult, wallet: Wallet): Result<StoredCredential>

Extension function to create DID, issue credential, and store in wallet.

Link copied to clipboard
suspend fun createDidWithKey(method: String? = null, timeout: Duration = 10.seconds, block: DidBuilder.() -> Unit = {}): DidCreationWithKeyResult
Link copied to clipboard
suspend fun delegate(timeout: Duration = 30.seconds, block: suspend DelegationBuilder.() -> Unit): DelegationChainResult
Link copied to clipboard

Extension function to get a delegation builder (any DidDslContext, including org.trustweave.trust.TrustWeave).

Link copied to clipboard
suspend fun findTrustPath(verifier: VerifierIdentity, issuer: IssuerIdentity, timeout: Duration = 10.seconds): TrustPath

Find a trust path between verifier and issuer (first-class type).

Link copied to clipboard
open override fun getDidMethod(name: String): DidMethod?

Get a DID method by name.

Link copied to clipboard
open override fun getDidRegistry(): DidMethodRegistry

Get the DID registry.

Link copied to clipboard
open override fun getDidResolver(): DidResolver

Get a DID resolver for delegation operations. This returns the native DID resolver interface used by did:core.

Link copied to clipboard
suspend fun getKeyId(did: Did): Result<String>

The ID of the key did issues with: its first assertionMethod, else its first authentication method, else its first verification method not reserved for keyAgreement.

Link copied to clipboard
suspend fun getKeyIdResult(did: Did): KeyIdResult

Sealed-result form of getKeyId: the ID of the key did issues with (first assertionMethod, else first authentication, else first verification method not reserved for keyAgreement). Never throws for domain failures; coroutine cancellation is rethrown.

Link copied to clipboard

Get the underlying KMS.

Link copied to clipboard
open override fun getWalletFactory(): WalletFactory?

Get wallet factory.

Link copied to clipboard
suspend fun issue(timeout: Duration = 30.seconds, block: IssuanceBuilder.() -> Unit): IssuanceResult

Issue a verifiable credential using the configured TrustWeave instance.

Link copied to clipboard

Issue multiple credentials using Flow for reactive processing.

Link copied to clipboard

Create a presentation from wallet credentials, returning PresentationResult.

Link copied to clipboard

Create a verifiable presentation, returning PresentationResult for exhaustive error handling.

Link copied to clipboard

Extension function to register a schema.

Link copied to clipboard

Returns the configured KeyManagementService as a non-null reference.

Link copied to clipboard
open suspend fun resolve(did: Did, options: ResolutionOptions): DidResolutionResult
open suspend override fun resolve(did: Did): DidResolutionResult
Link copied to clipboard
suspend fun resolveDid(did: String, timeout: Duration = 30.seconds): DidResolutionResult
suspend fun resolveDid(did: Did, timeout: Duration = 30.seconds): DidResolutionResult
Link copied to clipboard

Extension function to access revocation operations using TrustWeave.

Link copied to clipboard
suspend fun revoke(timeout: Duration = 10.seconds, block: RevocationBuilder.() -> Unit): Boolean

Revoke a credential using the configured TrustWeave instance.

Link copied to clipboard
suspend fun revokeResult(timeout: Duration = 10.seconds, block: RevocationBuilder.() -> Unit): RevocationResult

Sealed-result form of revoke. Missing configuration, incomplete requests and timeouts are variants instead of exceptions; coroutine cancellation is rethrown.

Link copied to clipboard
suspend fun rotateKey(timeout: Duration = 30.seconds, block: KeyRotationBuilder.() -> Unit): DidResult
Link copied to clipboard
fun TrustWeave.schema(schemaId: String? = null, block: SchemaBuilder.() -> Unit = {}): SchemaBuilder

Extension function to access schema operations.

Link copied to clipboard
suspend fun trust(block: suspend TrustBuilder.() -> Unit): TrustPath.NotConfigured?

Perform trust operations using the trust DSL.

Link copied to clipboard
suspend fun trustResult(block: suspend TrustBuilder.() -> Unit): TrustOperationResult

Sealed-result form of trust: TrustOperationResult.Completed when block ran, TrustOperationResult.NotConfigured without a trust registry (block not run) and TrustOperationResult.Failure when block or the registry threw. Coroutine cancellation is rethrown.

Link copied to clipboard
suspend fun updateDid(timeout: Duration = 30.seconds, block: DidDocumentBuilder.() -> Unit): DidResult
Link copied to clipboard
suspend fun verify(timeout: Duration = 10.seconds, block: VerificationBuilder.() -> Unit): VerificationResult

Verify a verifiable credential using the configured TrustWeave instance.

suspend fun verify(credential: VerifiableCredential, checkRevocation: Boolean = true, checkExpiration: Boolean = true, timeout: Duration = 10.seconds): VerificationResult

Verify a verifiable credential (convenience overload).

Link copied to clipboard

Verify multiple credentials using Flow for reactive processing.

Link copied to clipboard
suspend fun wallet(block: WalletBuilder.() -> Unit): WalletCreationResult

Create a wallet using the configured TrustWeave instance.