Document

class Document

This class represents a document created in DocumentStore.

Document can be created using DocumentStore.createDocument. Once a Document is created it persists in the storage and can be looked up using DocumentStore.lookupDocument even after the application restarts. Document can be deleted using DocumentStore.deleteDocument method.

Documents in this store are identified by an identifier Document.identifier which is automatically assigned and is unique per document in a DocumentStore.

Arbitrary data can be stored in documents using the AbstractDocumentMetadata returned by metadata. Applications that use this library should supply their AbstractDocumentMetadata factory using DocumentStore.Builder.setDocumentMetadataFactory if there is a need to store custom data alongside the document itself.

Each document may have a number of Credentials associated with it. These credentials are intended to be used in ways specified by the underlying document format but the general idea is that they are created on the device and then sent to the issuer for certification. The issuer then returns some format-specific data related to the credential.

Using Mobile Driving License and MDOCs according to ISO/IEC 18013-5:2021 as an example, the credential plays the role of DeviceKey and the issuer-signed data includes the Mobile Security Object which includes the credential and is signed by the issuer. This is used for anti-cloning and to return data signed by the device. The way it works in this API is that the application can create one of SecureAreaBoundCredential subclasses, typically using a companion create method. With this in hand, the application can use SecureAreaBoundCredential.getAttestation and send the attestation to the issuer for certification. The issuer will then craft document-format specific data (for ISO/IEC 18013-5:2021 it will be a signed MSO which references the public part of the newly created credential) and send it back to the app. The application can then call Credential.certify which would add any issuer provided authentication data to the credential and make it ready for use in presentation. To retrieve all credentials which still require certification, use getPendingCredentials, and to retrieve all certified credentials, use getCertifiedCredentials.

At document presentation time the application first receives the request from a remote reader using a specific document presentation protocol, such as ISO/IEC 18013-5:2021. The details of the document-specific request includes enough information (for example, the DocType if using ISO/IEC 18013-5:2021) for the application to locate a suitable Document from a DocumentStore. See DocumentRequest for more information about how to generate the response for the remote reader given a Document instance.

There is nothing mDL/MDOC specific about this type, it can be used for any kind of document regardless of format, presentation, or issuance protocol used.

Parameters

store

the DocumentStore that holds this Document.

identifier

the persistent id of the document which can be used with DocumentStore.

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Defines default document order: by Document.created, then by Document.identifier.

Link copied to clipboard
class Editor

An interface to edit Document metadata

Link copied to clipboard
data class UsableCredentialResult(val numCredentials: Int, val numCredentialsAvailable: Int)

Properties

Link copied to clipboard
val authorizationData: ByteString?

Saved authorization data to refresh credentials, possibly without requiring user to re-authorize.

Link copied to clipboard
val cardArt: ByteString?

An image that represents this document to the user in the UI. Generally, the aspect ratio of 1.586 is expected (based on ID-1 from the ISO/IEC 7810). PNG format is expected and transparency is supported.

Link copied to clipboard
Link copied to clipboard

User-facing name of this specific Document instance, e.g. "John's Passport".

Link copied to clipboard
Link copied to clipboard
val issuerLogo: ByteString?

An image that represents the issuer of the document in the UI, e.g. passport office logo. PNG format is expected, transparency is supported and square aspect ratio is preferred.

Link copied to clipboard
Link copied to clipboard

Whether the document is provisioned, i.e. issuer is ready to provide credentials.

Link copied to clipboard
val tags: Tags

A Tags for storing application-specific data.

Link copied to clipboard

User-facing name of this document type, e.g. "Utopia Passport".

Functions

Link copied to clipboard
suspend fun countUsableCredentials(at: Instant = Clock.System.now()): Document.UsableCredentialResult

Returns whether an usable credential exists at a given point in time.

Link copied to clipboard
suspend fun deleteCredential(credentialIdentifier: String)

Deletes the credential with the given identifier.

Link copied to clipboard

Goes through all credentials and deletes the ones which are invalidated.

Link copied to clipboard
suspend fun edit(editAction: suspend Document.Editor.() -> Unit)
Link copied to clipboard
suspend fun findCredential(domain: String, now: Instant?): Credential?

Finds a suitable certified credential to use.

Link copied to clipboard

Returns all certified credentials.

Link copied to clipboard

Returns all certified credentials for the given domain.

Link copied to clipboard

Returns the list of identifiers for all credentials for this document.

Link copied to clipboard

Returns the list of all credentials for this document.

Link copied to clipboard

Returns the list of all pending credentials.

Link copied to clipboard

Returns the list of all pending credentials for the given domain.

Link copied to clipboard
suspend fun getReplacementCredentialFor(credentialIdentifier: String): Credential?

Returns the credential which is a replacement for the credential with the given credentialIdentifier.

Link copied to clipboard
suspend fun hasUsableCredential(at: Instant = Clock.System.now()): Boolean

Returns whether a usable credential exists at a given point in time.

Link copied to clipboard
suspend fun lookupCredential(credentialIdentifier: String): Credential?

Returns the credential with the given identifier.