Credentials

A credential, called Attestation in the SDK context, is a collection of information. They could be of type PID, meaning Person Identification Data or MDL, a mobile driver's license. As long as a Credential Issuer is compatible with the EUDI Wallet Advanced Reference Framework it can issue credentials for EUDI wallet apps.

All saved Attestations of a viewabel type can be observed by the app. They are delivered as a Flow and are updated each time there are changes in the SDK’s database.

val atttestations = WalletSdkApi.attestations.attestations

There are different ways to start a credential download, a so called CredentialOffer. In every case the information where to download a credential and how to authorize one self to download a credential has to be provided to the app. The SDK provides one function to start from a valid credential offer as a string.

In most cases a credential issuer provides either a deeplink or a QR-Code containing a credential offer url -> credentialOfferIntentData in the following code snippet. This URL has to be passed to the SDK’s attestations.retrieveFromCredentialOffer function. The function will return a flow of CredentialOfferEvent objects. The InfoEvent contains information on the credential offered to the user. By completing the event’s result of type CompletableDeferred the flow can be continued.


private val infoResult: CompleteableDeferred<Unit>?  = null

suspend fun retrieveCredentialFromOffer(credentialOfferIntentData: String) {
     WalletSdkApi.attestations.retrieveFromCredentialOffer(credentialOfferIntentData).collect { event -> 
         when (event) {
             is CredentialOfferEvent.InfoEvent -> {
                 // this contains information about the credential offered to the app 
                 credentialOfferInfo = event.credentialOfferInfo
                 // save this event's result, it needs to be completed to continue the flow
                 infoResult = event.result
             }
             CredentialOfferEvent.InfoParsingError, // credential info not parsable
             CredentialOfferEvent.ParsingError, // credential not parsable
             CredentialOfferEvent.IssuanceError, // credential issuance fails
             CredentialOfferEvent.NotImplementedError, // trying to issue a credential type no implemented yet
                 -> {
                 // handle the error in the app
             }
             is CredentialOfferEvent.OpenUrlForAuthEvent -> {
                 // open url returned by event in browser or handle login process in the app
                 val url = event.authoriztationUrl
             }
         }
     }
}

// if current flow item is InfoEvent, go on with completing the InfoResult -> next (success)
// event will be CredentialOfferEvent.OpenUrlForAuthEvent
fun approveDownloadOfferedCredential() {
    infoResult?.complete(Unit)
    infoResult = null
}

The authorizationUrl returned by CredentialOfferEvent.OpenUrlForAuthEvent has to be opened to authenticate the user at the credential issuer. This doesn’t have to be the same credentials used to register the app.

[!NOTE] The Credential Issuer and the WalletProvider do not have to be the same authority, e.g. the WalletProvider is the government of a European country, the credential issuer could be a university providing a credential about a user’s degree.

After a successful authorization the resulting callback has to be handed to the continueWithAuthCodeUrl function to start the actual download of the credential.

suspend fun resumeOnAuthToken(intentData: String) { 
    WalletSdkApi.attestations.continueWithAuthCodeUrl(intentData).collect { event ->
        when (event) {
                CredentialDownloadEvent.InvalidAppData,
                CredentialDownloadEvent.ParsingError,
                CredentialDownloadEvent.SavingError,
                -> {
                    // handle error in the app
                }
                CredentialDownloadEvent.Success -> {
                    // show success in app
                }
            }
    }
}

The SDK saves the credential and updates the list of Attestations Flow. If the Credential was the app’s first PID, the WalletState changes to Valid.