OpenId4VciClient

class OpenId4VciClient @JvmOverloads constructor(clientId: String = "https://wallet.a-sit.at/app", remoteResourceRetriever: RemoteResourceRetrieverFunction = { null }, encryptionService: WalletEncryptionService = WalletEncryptionService(), proofCreators: List<ProofCreator>)(source)

Client service to retrieve credentials using OID4VCI

Implemented from OpenID for Verifiable Credential Issuance 1.0 from 2025-09-16.

Constructors

Link copied to clipboard
constructor(clientId: String = "https://wallet.a-sit.at/app", remoteResourceRetriever: RemoteResourceRetrieverFunction = { null }, encryptionService: WalletEncryptionService = WalletEncryptionService(), proofCreators: List<ProofCreator>)
constructor(clientId: String = "https://wallet.a-sit.at/app", keyMaterial: KeyMaterial = EphemeralKeyWithoutCert(), remoteResourceRetriever: RemoteResourceRetrieverFunction = { null }, encryptionService: WalletEncryptionService = WalletEncryptionService(), loadKeyAttestation: suspend (OpenId4VciClient.KeyAttestationInput) -> KmmResult<JwsCompactTyped<KeyAttestationJwt>>? = null, selectProofJwtKeyBinding: suspend (KeyMaterial) -> Pair<JsonWebKey?, String?> = { key -> Pair(key.jsonWebKey, null) }, clock: Clock = Clock.System)

Types

Link copied to clipboard
sealed interface CredentialRequest
Link copied to clipboard
data class KeyAttestationInput(val credentialIssuer: String?, val clientNonce: String?, val supportedAlgorithms: Collection<String>?, val preferredKeyStorageStatusPeriod: Duration?, val requirements: KeyAttestationRequired?)

What JwtProofCreator and AttestationProofCreator pass to their loadKeyAttestation, to load a key attestation (OpenID4VCI 1.0, Appendix D) that the credential issuer accepts for the requested credential.

Link copied to clipboard
data class PreparedCredentialRequest(val credentialConfigurationId: String, val credentialRequestParameters: CredentialRequestParameters, val credentialFormat: SupportedCredentialFormat)

Prepared credential request from prepareCredentialRequests, to be put one-by-one into createCredential after fetching the client nonce

Link copied to clipboard
data class RequestOptions @JvmOverloads constructor(val credentialScheme: CredentialScheme, val representation: CredentialRepresentation = PLAIN_JWT, val state: String = uuid4().toString())

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun buildAuthorizationDetails(credentialConfigurationId: String, authorizationServers: Set<String>? = null): Set<OpenIdAuthorizationDetails>
fun buildAuthorizationDetails(credentialConfigurationIds: Set<String>, authorizationServers: Set<String>? = null): Set<OpenIdAuthorizationDetails>

Build authorization details for use in OAuth2Client.createAuthRequest.

Link copied to clipboard
suspend fun createCredential(metadata: IssuerMetadata, credentialConfigurationId: String, clientNonce: String? = null, clientId: String = defaultClientId): KmmResult<OpenId4VciClient.CredentialRequest>

Creates the credential request for exactly one credential, to be sent to the credential issuer. Send it with OpenId4VciProtocolClient.credentialRequest, which adds the access token and, for DPoP-bound tokens, the DPoP proof, and parses the response.

suspend fun createCredential(request: OpenId4VciClient.PreparedCredentialRequest, metadata: IssuerMetadata, clientNonce: String? = null, clientId: String = defaultClientId): KmmResult<OpenId4VciClient.CredentialRequest>

Creates the credential request for request, prepared with prepareCredentialRequests, with a proof for its PreparedCredentialRequest.credentialFormat (see ProofCreator) and, if the credential issuer supports it, the encryption of request and response (OpenID4VCI 1.0, 10). Create it right before sending it with OpenId4VciProtocolClient.credentialRequest, each with a fresh clientNonce, as the credential issuer decides how long a c_nonce can be used (13.8), and may accept each one only once.

suspend fun createCredential(tokenResponse: TokenResponseParameters, metadata: IssuerMetadata, credentialFormat: SupportedCredentialFormat, clientNonce: String? = null, previouslyRequestedScope: String? = null, clientId: String = defaultClientId): KmmResult<Collection<OpenId4VciClient.CredentialRequest>>

Creates the credential request to be sent to the credential issuer. Send each request with OpenId4VciProtocolClient.credentialRequest, which adds the access token from tokenResponse and, for DPoP-bound tokens, the DPoP proof, and parses the response.

Link copied to clipboard

Decodes response received from the credential issuer for request into one ReceivedCredential per credential, encoded in representation, also for one that can not be decoded, so that no member of a batch goes unnoticed. Validates nothing: prepare the storage of each one with ReceivedCredential.prepareCredentialStorage, which validates it with the holder's key and validator.

suspend fun decodeCredentialResponse(response: String, isEncrypted: Boolean, request: OpenId4VciClient.CredentialRequest, representation: CredentialRepresentation): KmmResult<Collection<ReceivedCredential>>

Decodes response received from the credential issuer like decodeCredentialResponse, reading it as a compact JWE if isEncrypted, i.e. if its media type is application/jwt.

Link copied to clipboard
suspend fun parseCredentialOffer(input: String): KmmResult<CredentialOffer>

Parses input as either a JSON-encoded CredentialOffer or a credential offer URL.

Link copied to clipboard

Parses response received from the credential issuer, mapping to Holder.StoreCredentialInput, rejecting encrypted responses because they require the originating CredentialRequest.

Parses a response and binds its encryption to the exact request that caused it.

Link copied to clipboard

Prepares one credential request per entry of credentialConfigurationIds, each with its configuration from IssuerMetadata.supportedCredentialConfigurations of metadata, still without proofs and encryption, see createCredential.

fun prepareCredentialRequests(tokenResponse: TokenResponseParameters, metadata: IssuerMetadata, previouslyRequestedScope: String? = null): KmmResult<Collection<OpenId4VciClient.PreparedCredentialRequest>>

Prepares the credential requests the access token of tokenResponse grants for all its credentials, each with the configuration its proof and response depend on, still without proofs and encryption. Create each request with its own c_nonce right before sending it with OpenId4VciProtocolClient.credentialRequest, which adds the access token from tokenResponse and, for DPoP-bound tokens, the DPoP proof, and parses the response.

fun prepareCredentialRequests(tokenResponse: TokenResponseParameters, metadata: IssuerMetadata, credentialFormats: Collection<SupportedCredentialFormat>, previouslyRequestedScope: String? = null): KmmResult<Collection<OpenId4VciClient.PreparedCredentialRequest>>

Prepares the credential requests the access token of tokenResponse grants for the credentials of credentialFormats, each with the configuration its proof and response depend on, still without proofs and encryption. Create each request with its own c_nonce right before sending it with OpenId4VciProtocolClient.credentialRequest, which adds the access token from tokenResponse and, for DPoP-bound tokens, the DPoP proof, and parses the response.