Skip to content

Using MdocResponse

TransferEvent

The TransferEvent object contains all the possible events that occurs during the operation. It also contains the possible errors

enum TransferEvent: String {
    case START // Starting transfer
    case CONNECTED // Connected to other device or server
    case SCAN_STARTED // Scan for devices started (BLE only)
    case SCAN_STOPPED // Scan for devices stopped (BLE only)
    case DEVICE_FOUND // Device found (BLE only)
    case NO_DEVICE_FOUND // No device found (BLE only)
    case TRY_RECONNECTION // Try reconnection (BLE only)
    case READER_VERIFIED // Reader verified (BLE only)
    case READER_NOT_VERIFIED // Reader not verified (BLE only)
    case COMPLETE // Complete transfer
    case FORCE_STOP // Transfer was stop
    case SESSION_TERMINATED // Session terminated
}

MdocResponse

The MdocResponse is returned by the didReceiveResponse delegate function and contains the following data:

public struct MdocResponse {
    public let version: String

    /// data documents
    public let documents: [MValidSdk.MdocDocument]?

    public let documentErrors: [MValidSdk.DocumentError]?

    public let status: Int

    /// Portrait retrieved from mDL document
    public let portrait: Data?

    /// Portrait retrieved from mDL document
    public let signature: Data?

    /// Age over info retrieved from mDL document
    public let ageOverXX: [Int : Bool]?
}

The portrait and signature can be converted to an UIImage and display them to your demo like this:

if let ps = vm.response.portrait, let uiImage = UIImage(data: Data(ps)) {
    // convert data to an UIImage and create an Image Object
    Image(uiImage: uiImage).resizable().aspectRatio(contentMode: .fit).frame(height: 100).frame(maxWidth: .infinity, alignment: .center)
}

if let ps = vm.response.signature, let uiImage = UIImage(data: Data(ps)) {
    // convert data to an UIImage and create an Image Object
    Image(uiImage: uiImage).resizable().aspectRatio(contentMode: .fit).frame(height: 50).frame(maxWidth: .infinity, alignment: .center).offset(x: 0, y: -5)
}

MdocDocument

public struct MdocDocument {

    /// Document type
    public let docType: String

    /// Data items for each namespace
    public let items: [MValidSdk.NameSpace : [MValidSdk.MdocDataItem]]

    /// Error items for each namespace
    public let errorItems: [MValidSdk.NameSpace : [String : Int]]?

    /// Security information
    public let securityInfo: MValidSdk.MdocSecurityInfo

    /// Online or offline?
    public let retrievedFromServer: Bool
}

MdocDataItem

public struct MdocDataItem {

    /// Data element identifier
    public let identifier: String

    /// Native typed data value
    public let typedValue: MValidSdk.MdocTypedData

    /// String representation of typedVakye
    public let stringValue: String

    /// numeric order of the item in the document
    public let order: Int

    /// Children data items (if current data item is array or dictionary)
    public let children: [MValidSdk.MdocDataItem]?
}

MdocTypedData

indirect public enum MdocTypedData {

    case boolean(Bool)

    case integer(Int)

    case string(String)

    case date(Date)

    case bytes([UInt8])

    case drivingPrivileges([MValidSdk.DrivingPrivilege])

    case array(MValidSdk.MdocTypedData)
}

MdocSecurityInfo

public struct MdocSecurityInfo {

    case offline(MValidSdk.MdocOfflineSecurityInfo)

    case online(MValidSdk.MdocOnlineSecurityInfo)
}

MdocSecurityInfo contains 2 different cases. The offline and online mode and are rapresented with the following structure:

MdocOfflineSecurityInfo

/// Offline securty info
public struct MdocOfflineSecurityInfo {

    public let signedAt: Date?

    public let validFrom: Date?

    public let validUntil: Date?

    public let expectedUpdate: Date?

    public let deviceDataElementsAuthorized: Bool?

    public let issuerName: String?

    public let dsValidatedWithIACA: Bool

    public let dSCertificateInfo: [String : String]?

    public let iacaCertificateInfo: [String : String]?

    public let msoSignatureVerified: Bool?

    public let deviceAuthHMACVerified: Bool?

    public let deviceAuthECDSAVerified: Bool?

    public let valueDigestsVerified: Bool?

    public let validityΙnfoSignDateValid: Bool?

    public let validityΙnfoValidFromDateValid: Bool?

    public let validityΙnfoValidUntilDateValid: Bool?

    public var securityChecksPassedOK: Bool { get }
}

MdocOnlineSecurityInfo

/// Online security info
public struct MdocOnlineSecurityInfo {

    public let jwsValidatedWithIACA: Bool

    public let jwsSignatureVerified: Bool

    public let jwsCertificateInfo: [String : String]?

    public let iacaCertificateInfo: [String : String]?
}