Here we provide some implemented code to help you implement a presentation flow as described in the OpenID4VP to present a credential to a verifier (e.g. Bank, government authority or other wallet).
The SDK implements a flow that will handle the OpenID4VP specifics and the app only needs to present a UI flow to the user and provide the needed credentials to the SDK.
The presentation flow interactions are part of the
Presentations object, provided by the wallet SDK.
PresentationsAll current functionality and future functionality for the presentation flow will be performed by this object.
For the presentation flow the app has to register the URL scheme
openid4vp specified in the setup
process. Otherwise it will not get informed about presentation flow
requests.
For the request itself the wallet SDK provides the following interface:
let deepLink = "Received OpenID4VP URL"
WalletSdk.shared.presentations.presentWith(requestUri: deepLink)This interface will provide an AsyncSequence that is providing
wallet_sdk.PresentationEvent objects, which do represent
every step and errors of the flow.
The steps are:
.parsingErrorEvent, .invalidRequestEvent
see the technical documentation for more
details.let presentations = WalletSdk.shared.presentations
for await value in presentations.presentWith(requestUri: requestUri) {
switch onEnum(of: value) {
case .infoEvent(let _info):
// 1st event
// Success, we did received the information the relying party wants from the users credentials
// App should show a UI to present the information too the user
// To continue to the next step the app has to `complete` the event
continue
case .attestationSelectionEvent(let _selection):
// 2nd event
// Success, we did received a list of attestations (downloaded on the device) that do fit the request
// the user should select if he/she wants to send all or only specific credentials
// app should present the credentials to the user
continue
case .presentationSuccessEvent(let _event):
// final step, the presentation flow was successful and the data have been transferred
return
default:
// An error occurred and should be presented to the user
throw an error
}
}The presentationWith(requestUri:) function will only
continue when the current PresentationEvent has been
completed. This has to be done mostly with a user
interaction, since the user has to accept/choose what to send to the
verifier.
The completion of the PresentationEvent varies depending
on the event that has to be completed. Two examples for different
PresentationEvent objects to complete.
PresentationEventInfoEvent to display the requested
information the verifier wants to receive from the wallet:
// Just accepting, no data to provide to the SDK. KotlinUnit is more like Void in this context.
event.result.complete(value: KotlinUnit())PresentationEventAttestationSelectionEvent which tells
the app to provide all the credentials fitting the request and let the
user choose which to send. Where the complete function of
the event does require a list of credentials aka
Attestation objects being returned:
// we have to provide the attestion id(s) that should be returned to the verifier
event.result.complete(value: attestationId)These are only two examples, for all of the
PresentationEvent objects, for more please have a look on
the technical documentation.
When all the events in the presentWith(requestUri)
functions are handled, the presentation flow is completed successfully
or with an error state. The verifier should also have received all the
information needed.
The same and cross device flows are working the same for the usage of the SDK. The only difference between the two is, that the cross device is normally started via a QR code scan and the same device flow is started by the deeplink directly from e.g. the browser on the same device. The app will - in both cases - be informed about the deeplink and forward it to the SDK, which will then handle the processing of the presentation flow steps.
The proximity flow between devices is currently not supported.