SpruceKit
SpruceID
  • 🌲SpruceKit Introduction
    • Decentralized Identity Overview
    • Glossary
  • ⚡Quickstart
  • SpruceKit Mobile
    • SpruceKit Showcase App
      • Installation
      • Getting Started
      • Issue a Showcase Credential
      • Present a Showcase Credential
    • SpruceKit Mobile SDK
      • Introduction
      • Core Components
        • StorageManager
        • KeyManager
        • CredentialPack
        • Card
        • IsoMdlPresentation
        • mDocReader/IsomDLReader
        • Document Scanner
      • SpruceKit iOS SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
      • SpruceKit Android SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present an mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
  • Verifiable Digital Credentials
    • ⚙️DIDKit
      • Installation
      • Core Concepts
      • DID Methods
      • Runtime Configuration
      • Specifications and Dependencies
      • Quickstart
      • DIDKit Packages
        • Command Line Interface
        • HTTP Server
        • Rust Crate
        • C Interface
        • Java and Android
        • Python
        • Javascript
      • DIDKit Examples
        • Core Functions (CLI)
        • Core Functions (HTTP)
        • did-web in minutes
        • Batch Generation & Verification
    • 🪪ISO mDL
      • Quickstart
      • Core Concepts
      • User Guide
  • Schema Definition Language
    • 🔗TreeLDR
      • TreeLDR Quickstart
        • First Schema
        • Compilation into JSON Schema
        • Compilation into JSON-LD Context
        • Writing a Layout
        • Simple Rust Integration
      • Types
        • Literal Types
      • Layouts
        • Primitive Layouts
        • Literal Layouts
        • Enumeration
        • Array Layout
        • References
      • Compiling
        • Schema Definition Formats
          • JSON Schema
          • JSON-LD Context
          • Resource Description Framework (RDF)
        • Programming Languages
          • Compiling to Rust
      • RDF Vocabulary
      • 💡TreeLDR Basics
        • Types and Layouts
        • Properties
        • Syntax
  • Witness for Credential Claims
    • 🔭Rebase
      • Core Library
      • Rust Client/Witness SDK
      • WASM Client SDK
      • Simple "Basic Post" Schema
      • DNS Witness Flow Schema
  • References
    • Contributing
    • Code of Conduct
Powered by GitBook
On this page
  • 1. Start a Session by generating a QR-Code
  • 2. Define your Session Delegate
  • 3. Define your Mdl Sharing View

Was this helpful?

  1. SpruceKit Mobile
  2. SpruceKit Mobile SDK
  3. SpruceKit iOS SDK
  4. Build a Wallet

Present mDL in-person/offline

Present an ISO/IEC 18013-5 mDL over BlueTooth Low Energy

PreviousPresent a W3C VCNextPresent an mDL over the internet

Last updated 2 months ago

Was this helpful?

This guide is for iOS applications. Building for Android? Look here: Present an mDL in-person/offline

To present an mDL over BLE, you will need to use the following components:

  • The CredentialStore Component

  • The IsoMdlPresentation Component

To use these components in your mobile application, we encourage you to define:

  • A Delegate class that holds the BLESessionState and the ISO mDL SessionManager

    • This class should implement the BLESessionState protocol.

  • A View that manages the UI based on the BLESessionState

    • The View holds an instance of your delegate class.

During the presentation, you will have to manage the . The BLESessionState definition is repeated here to show the stages that the presentation goes through. The View that manages your UI should deal with each one of these listed cases. Again, we have an to give you some inspiration.

// The different Wallet-side states of an mDL presentation.

public enum BLESessionState {
    /// App should display the error message
    case error(BleSessionError)
    /// App should display the QR code
    case engagingQRCode(Data)
    /// App should indicate to the user that BLE connection has been made
    case connected
    /// App should display an interactive page for the user to chose which values to reveal
    case selectNamespaces([ItemsRequest])
    /// App should display the fact that a certain percentage of data has been sent
    /// - Parameters:
    ///   - 0: The number of chunks sent to far
    ///   - 1: The total number of chunks to be sent
    case uploadProgress(Int, Int)
    /// App should display a success message and offer to close the page
    case success
}

1. Start a Session by generating a QR-Code

import SpruceIDMobileSdk
import SpruceIDMobileSdkRs

let credentialPack = CredentialPack()
// Retrieve mdoc(s) from the credentialPack by their ID.
let credentials = credentialPack.get(credentialIds: [mdocId])
// The CredentialStore is a wrapper for in-person mdoc presentment.
// Initiate your CredentialStore with an array of ParsedCredentials
let credentialStore = CredentialStore(credentials: credentials)

/*
Start an ISO/IEC 18013-5 SessionManager from your credential store.
Here, the deviceEngagement is an enum, currently only supporting QRCode engagement
The callback should be an instance of the class that implementes the BLESessionStateDelagate Protocol.
*/
let sessionManager = await credentialStore.presentMdocBLE(deviceEngagement: .QRCode, callback: <yourSessionDelegate> )!

/*
submit user selected datafields through the sessionManager. 
*/
let _ = sessionManager.submitNameSpaces(items: )

In the delegate class, make sure you can call the presentMdocBLE and submitNamespaces methods on the IsoMdlPresentation component.

2. Define your Session Delegate

// Your Delegate Class
import SpruceIDMobileSdk
import SpruceIDMobileSdkRs

class MDLDelegate: ObservableObject {
    @Published var state: BLESessionState = .connected
    private var sessionManager: IsoMdlPresentation?
    
    init(credentials: CredentialStore) async {
        self.sessionManager = await credentials.presentMdocBLE(deviceEngagement: .QRCode, callback: self)!
    }
    
    func cancel() {
        self.sessionManager?.cancel()
    }
    
    func submitItems(items: [String: [String: [String: Bool]]], key: SecKey) {
        self.sessionManager?.submitNamespaces(items: items.mapValues { namespaces in
            return namespaces.mapValues { items in
                Array(items.filter { $0.value }.keys)
            }
        }, signingKey: key)
    }
}

Now that you have your Delegate to manage the BLESessionSate and your SessionManager, you can define the View that defines what your presentation flow looks like.

3. Define your Mdl Sharing View

// Your mDL Sharing View

public struct MDLSharing: View {
    var credentials: CredentialStore
    @State var proceed = true
    @StateObject var delegate: MDLDelegate
    
    init(credentials: [ParsedCredential]) async {
        let credentialStore = CredentialStore(credentials: credentials)
        self.credentials = credentialStore
        let viewDelegate = await ShareViewDelegate(credentials: credentialStore)
        self._delegate = StateObject(wrappedValue: viewDelegate)
    }
    
    public var body: some View {
        VStack {
            if proceed {
                switch self.delegate.state {
                // Manage the UI for your BleSessionStates here
            } else {
                Text("Operation Canceled")
            }
        }
    }
}

That's it! You manage the UI, and SpruceKit takes care of all the nitty gritty underneath.

You will need a UI component that allows the user to select which fields of the mDL they are willing to share. In our SpruceKit Showcase App, we call that the

BLESessionState
example
Credential Selector