OpenID Connect for Verifiable Credential Issuance (OIDC4VCI) implementation for TrustWeave.
Overview
OIDC4VCI is a protocol that enables credential issuance using OpenID Connect flows. It provides a standardized way for issuers to offer credentials and for holders to request and receive them.
importorg.trustweave.credential.oidc4vci.Oidc4VciServiceimportorg.trustweave.credential.oidc4vci.exchange.Oidc4VciExchangeProtocolimportorg.trustweave.credential.exchange.*importokhttp3.OkHttpClientvalkms=// Your KMS instancevalhttpClient=OkHttpClient()valoidc4vciService=Oidc4VciService(credentialIssuerUrl="https://issuer.example.com",kms=kms,httpClient=httpClient)valprotocol=Oidc4VciExchangeProtocol(oidc4vciService)importorg.trustweave.credential.exchange.registry.ExchangeProtocolRegistriesimportorg.trustweave.credential.exchange.ExchangeServicesvalregistry=ExchangeProtocolRegistries.default()registry.register(protocol)valexchangeService=ExchangeServices.createExchangeService(protocolRegistry=registry,credentialService=credentialService,didResolver=didResolver)
importorg.trustweave.credential.exchange.*importorg.trustweave.credential.exchange.request.ExchangeRequestimportorg.trustweave.credential.exchange.result.ExchangeResultimportorg.trustweave.credential.exchange.options.ExchangeOptionsimportorg.trustweave.credential.identifiers.*importorg.trustweave.did.identifiers.Didimportkotlinx.serialization.json.JsonPrimitivevalofferResult=exchangeService.offer(ExchangeRequest.Offer(protocolName="oidc4vci".requireExchangeProtocolName(),issuerDid=Did("did:key:issuer"),holderDid=Did("did:key:holder"),credentialPreview=CredentialPreview(attributes=listOf(CredentialAttribute("name","Alice"),CredentialAttribute("email","alice@example.com"))),options=ExchangeOptions.builder().addMetadata("credentialIssuer","https://issuer.example.com").addMetadata("credentialTypes",JsonPrimitive("VerifiableCredential,PersonCredential")).addMetadata("grants",JsonPrimitive("authorization_code")).addMetadata("issuer_state",JsonPrimitive("state123")).build()))valoffer=when(offerResult){isExchangeResult.Success->offerResult.valueelse->throwIllegalStateException("Offer failed: $offerResult")}// The offer contains an offer URI that can be shared with the holdervalofferUri=(offer.offerDataasOidc4VciOffer).offerUri// Format: openid-credential-offer://?credential_issuer=...