light-mode-image
Learn

Credential claiming mDocs Holder SDK Cheatsheet

This cheatsheet provides an overview of how to use the MATTR mDocs Holder SDKs to claim mDocs issued through an OID4VCI workflow.

Use these guides as a quick reference to get started. For detailed information, explore the tutorials and reference documentation tailored for each platform.

Core usage

Initialize the SDK

Initialize the SDK
try mobileCredentialHolder.initialize(
    userAuthenticationConfiguration: UserAuthenticationConfiguration( 
        userAuthenticationBehavior: .always, 
        userAuthenticationType: .biometricOrPasscode, 
        presentationTimeoutSeconds: 20
    ),
    credentialIssuanceConfiguration: CredentialIssuanceConfiguration(
        redirectUri: "<WalletRedirectUri>", 
        autoTrustMobileCredentialIaca: true
    )
)
  • userAuthenticationConfiguration: Optional. Configures when the SDK requires user authentication to access or present credentials. The example shows the default values. Refer to the reference documentation for additional details about the available configuration options.
  • redirectUri : Provide a URL that corresponds to a specific path in your application. The SDK will redirect the user to this path after they successfully complete authentication. Required for the Authorization Code flow.
  • autoTrustMobileCredentialIaca : Set to true if you trust the credential issuer(s) for any offer. Defaults to false.
Initialize the SDK
mobileCredentialHolder.initialize(
    activity,
    userAuthenticationConfiguration = UserAuthenticationConfiguration( 
        behavior = UserAuthenticationBehavior.Always, 
        presentationTimeoutSeconds = 20
    ),
    credentialIssuanceConfiguration = CredentialIssuanceConfiguration(
        redirectUri = "<WalletRedirectUri>", 
        autoTrustMobileCredentialIaca = true
    )
)
  • userAuthenticationConfiguration: Optional. Configures when the SDK requires user authentication to access or present credentials. The example shows the default values. Refer to the reference documentation for additional details about the available configuration options.
  • redirectUri : Provide a URL that corresponds to a specific path in your application. The SDK will redirect the user to this path after they successfully complete authentication. Required for the Authorization Code flow.
  • autoTrustMobileCredentialIaca : Set to true if you trust the credential issuer(s) for any offer. Defaults to false.
Initialize the SDK
const initialiseResult = await mobileCredentialHolder.initialise()
if (initialiseResult.isErr()) {
    const { error } = initialiseResult
    // handle error scenarios
    return
}

Discover credential offer

Discover credential offer
    let discoveredOffer = try await mobileCredentialHolder.discoverCredentialOffer(offerUrl: String)
  • offerUrl : Pass the OID4VCI initiation URL.

The discoverCredentialOffer method returns a DiscoveredCredentialOffer object containing the offer details.

Discover credential offer
val discoveredOffer = mobileCredentialHolder.discoverCredentialOffer(offerUri)
  • offerUrl : Pass the OID4VCI initiation URL as a string.

The discoverCredentialOffer method returns an instance of DiscoveredCredentialOffer containing the offer details.

Discover credential offer
const discoveredOfferResult = await mobileCredentialHolder.discoverCredentialOffer(offerUrl) 
if (discoveredOfferResult.isErr()) {
    const { error } = discoveredOfferResult
    // handle error scenarios
    return
}
const credentialOffer = discoveredOfferResult.value
  • offerUrl : Pass the OID4VCI initiation URL.

The discoverCredentialOffer method returns a Result<CredentialOfferResponse, Error> (using the neverthrow pattern) object containing the offer details and/or any errors.

Claim and store credentials

Claim credentials
let retrievedCredentialResults = try await mobileCredentialHolder.retrieveCredentials(
    credentialOffer: String, 
    clientId: "<WalletClientID>", 
    transactionCode: nil
)
  • credentialOffer : Pass the OID4VCI credential offer URI.
  • clientId : Pass a string that identifies your wallet application with the issuer.
  • transactionCode : Provide a transaction code if the Pre-Authorization Code flow offer requires a transaction code.

The retrieveCredentials method returns an array of RetrieveCredentialResult objects, each containing the metadata of the retrieved credentials, including the credential ID (credentialId).

Claim credentials
val credentialResults = mobileCredentialHolder.retrieveCredentials(
    activity = activity,
    credentialOffer = offerUri, 
    clientId = "<WalletClientID>", 
    transactionCode = null
)
  • credentialOffer : Pass the OID4VCI credential offer URI.
  • clientId : Pass a string that identifies your wallet application with the issuer.
  • transactionCode : Provide a transaction code if claiming a credential using a Pre-authorized Code flow that requires a transaction code.

The retrieveCredentials method returns an array of RetrieveCredentialResult objects, each containing the metadata of the retrieved credentials, including the credential ID (credentialId).

Claim credentials
const retrievedCredentialsResults = await mobileCredentialHolder.retrieveCredentials({
    credentialOffer, 
    clientId: '<WalletClientID>', 
    redirectUri: '<WalletDeepLink>', 
    autoTrustMobileIaca: true
})
if (retrievedCredentialsResults.isErr()) {
    const { error } = retrievedCredentialsResults
    // handle error scenarios
    return
}
const retrievedCredentials = retrievedCredentialsResults.value

const retrievedCredential = retrievedCredentials[0]
if (retrievedCredential?.error || !retrievedCredential?.credentialId) {
    // handle error scenarios
    return
}
const credentialId = retrievedCredential.credentialId
  • credentialOffer : Pass the discovered credential offer object.
  • clientId : Pass a string that identifies your wallet application with the issuer.
  • redirectUri : Provide a URL that corresponds to a specific path in your application. The SDK will redirect the user to this path after they successfully complete authentication. Required for the Authorization Code flow.
  • autoTrustMobileIaca: Set to true if you want the SDK to trust the credential issuer(s) for any offer. Defaults to false.

The retrieveCredentials method returns a Result<RetrieveCredentialsResponse, Error> (using the neverthrow pattern) object containing the metadata of the retrieved credentials, including the credential ID (credentialId).

Access credential

Access credential
let credential = try mobileCredentialHolder.getCredential(credentialId: String)
  • credentialId : Pass the credential ID of the credential you want to access.
Access credential
val credential = mobileCredentialHolder.getCredential(credentialId)
  • credentialId : Pass the credential ID of the credential you want to access, as a string.
Access credential
const credentialResult = await mobileCredentialHolder.getCredential(credentialId) 
if (credentialResult.isErr()) {
    const { error } = credentialResult
    // handle error scenarios
    return
}
const credential = credentialResult.value
  • credentialId : Pass the credential ID of the credential you want to access.

How would you rate this page?