MATTR mDocs Verifier React Native - v4.0.0

MATTR mDocs Verifier React Native

Table of Contents

General

Licensing

Request or download the MATTR Pi SDK Trial Licence Agreement and the MATTR Customer Agreement and review these terms.

Features

  • Manage trusted issuers.
  • Request and verify mDocs.

In this SDK mDocs are referred to as Mobile Credentials.

Supported operating systems

  • iOS 15 or higher.
  • Android 7 or higher.

Getting started

How to get access to MATTR Pi mDocs verifier SDK

Refer to our SDK Docs landing page for step-by-step instructions to gain access to any of our SDKs.

Please reach out to us in case you need any assistance Get in touch.

Install dependencies

Add this SDK as a dependency to your react native app:

yarn add @mattrglobal/mobile-credential-verifier-react-native

Platform iOS

mDocs presentation utilises Bluetooth connection. Make sure the NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription descriptions are configured inside Info.plist.

Platform Android

Additional configuration steps are required to bundle the native libraries.

Local Maven Repository

The precompiled MATTR mDocs verifier Android SDK is provided in the published NPM package.

Open the android/build.gradle script and apply the following changes:

 allprojects {
repositories {

google()
+ maven {
+ url = "$rootDir/../node_modules/@mattrglobal/mobile-credential-verifier-react-native/android/frameworks"
+ }
}
}

Usage

Initialise

Initialise the SDK:

[!NOTE] SDK must be initialised first, otherwise other methods will throw an exception when invoked.

import { initialise } from "@mattrglobal/mobile-credential-verifier-react-native";

await initialise();

Trusted issuers

The SDK only verifies credentials that were issued by a trusted issuer. The trusted issuer certificates list can be managed directly with the following functions:

Manage trusted issuer certificates

import {
addTrustedIssuerCertificates,
getTrustedIssuerCertificates,
deleteTrustedIssuerCertificate,
} from "@mattrglobal/mobile-credential-verifier-react-native";

// Add a new certificate
const addCertificateResult = await addTrustedIssuerCertificates([
"MIIBwzCCAWmgAwIBAgILAOZSe5t+MOzXtX8wCgYIKoZIzj0EAwIwIDEeMAkGA1UEBhMCTlowEQYDVQQDEwpNQVRUUiBJQUNBMB4XDTIzMDcxODIwMDYzM1oXDTMzMDcxNTIwMDYzM1owIDEeMAkGA1UEBhMCTlowEQYDVQQDEwpNQVRUUiBJQUNBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE0XWwfvFPzbBHiDVLefOueGG1DMHc8WRfXfZqD6748kLZNTOBysm635yM7YCMlkUxDEIHVkLeyV6KoAOM2o0i5qOBiTCBhjASBgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIABjAdBgNVHQ4EFgQUypKEavotsICoAsXypAUUlsVUylMwHAYDVR0SBBUwE4ERaW5mb0BtYXR0ci5nbG9iYWwwIwYDVR0fBBwwGjAYohaGFGh0dHBzOi8vbWF0dHIuZ2xvYmFsMAoGCCqGSM49BAMCA0gAMEUCIClmASfWcf/K2WbClaERQfA38TNTSgYZu2SdNeNFdQyGAiEAhfk+FloZkNOb6TOLcDGqSNwXf+NzvPX0yl+8aq+rMKQ=",
]);

if (addCertificateResult.isErr()) {
const { error } = addCertificateResult;
// handle error scenarios
return;
}

// Get list of all stored certificates
const certificates = await getTrustedIssuerCertificates();

// Delete certificate by id
await deleteTrustedIssuerCertificate(certificateId);

Request credentials

The mDocs verifier supports requesting a credential from a holder device via Bluetooth. The following example shows how you could start a session and request a credential presentation from a holder device:

Only one presentation session is allowed at a time. You must terminate the existing session before starting a new one.


import {
createProximityPresentationSession,
sendProximityPresentationRequest,
terminateProximityPresentationSession,
} from "@mattrglobal/mobile-credential-verifier-react-native";

// start a new presentation session
const createSessionResult = await createProximityPresentationSession({
deviceEngagement: "mdoc:owBjMS4wAYIB2BhYS6QBAiABIVgg_t9K0BaXU27ynODS5q8OcvBZ4m1HFEQwl61lhRD2rdciWCA7hKLr_xN6_bdznDePa_yY1tGdHsc8ni_88uVuehRU-QKBgwIBowD1AfQKUMW8DfgLrUclmxp2InJCddk" // proximity presentation device engagement string
onConnected: () => {
// handle onConnect event
},
onSessionTerminated: () => {
// handle onSessionTerminated event
},
});

if (createSessionResult.isErr()) {
const { error } = createSessionResult;
// handle error scenarios
return;
}

// Send session
const sendRequestResult = await sendProximityPresentationRequest({
mobileCredentialRequests: [{
docType: "org.iso.18013.5.1.mDL",
namespaces: {
"org.iso.18013.5.1": {
family_name: false,
driving_privileges: false,
},
},
}],
});

if (sendRequestResult.isErr()) {
const { error } = sendRequestResult;
// handle error scenarios
return;
}

const response = sendRequestResult.value;

// Terminate current active session
await terminateProximityPresentationSession();

Error handling

Functions that are expected to have an error path return a Neverthrow Result type that represents either success (Ok) or failure (Err).

Although this pattern is more verbose, it encourages the handling of possible errors and reserves throwing exceptions for truly exceptional situations.

import { sendProximityPresentationRequest } from "@mattrglobal/mobile-credential-verifier-react-native";

// Send session
const sendRequestResult = await sendProximityPresentationRequest(...);

if (sendRequestResult.isErr()) {
const { error } = sendRequestResult;
// handle error scenarios
return;
}

const response = sendRequestResult.value;

unwrap

A utility function is provided for convenience if you decide not to handle your errors as results. This function will simply throw an error if the function passed in returns a Result where Result.isErr() is true.

import { unwrap, sendProximityPresentationRequest } from "@mattrglobal/mobile-credential-verifier-react-native";

try {
const sendRequestResult = unwrap(await sendProximityPresentationRequest(...));
} catch (error) {
// Handle thrown error
}

Change Log

4.0.0

BREAKING CHANGES

  • The SDK now require peer dependencies of react native 0.73.x.

  • Realm database has been replaced with a custom storage system. Upgrading to this version will result in all mDocs related data being lost. This includes all trusted issuer certificates and credentials.

  • The addTrustedIssuerCertificates method error types were updated as follows:

    • Added MobileCredentialVerifierErrorType.FailedToStoreCertificate when the given certificate is invalid.
    • Removed MobileCredentialVerifierErrorType.InvalidCertificate.
  • The sendProximityPresentationRequest method error types were updated as follows:

    • Added ProximityPresentationSessionErrorType.UnsupportedCurve.
    • Added ProximityPresentationSessionErrorType.RequestAlreadyInProgress.
    • Removed ProximityPresentationSessionErrorType.MobileCredentialVerificationFailed.
  • The createProximityPresentationSession method error types were updated as follows:

    • Added ProximityPresentationSessionErrorType.UnsupportedCurve.
  • Instead of throwing an exception, the sendProximityPresentationRequest method now returns a MobileCredentialResponse with a credentials[x].verificationResult field to provide a more detailed verification status (e.g. invalid credential, etc.).

Features

  • iOS Platform

    • addTrustedIssuerCertificates can now also accept input in the form of an unformatted PEM string.

3.0.0

BREAKING CHANGES

  • The createProximityPresentationSession method could return the following errors:

    • MobileCredentialVerifierErrorType.BluetoothDisabled when Bluetooth is powered off.
  • The sendProximityPresentationRequest method could return the following errors:

    • MobileCredentialVerifierErrorType.SessionTerminated when the current proximity presentation session is terminated.
  • The onSessionTerminated callback function for createProximityPresentationSession method could be invoked with the following errors:

    • ProximityPresentationSessionTerminationError.ResponseNotReceived when mobile credential response not received from holder.

Features

  • Allow additional extended key usage in a document signer certificate.
  • Allow clock skew tolerance during verification.

Bug Fixes

  • To mitigate a potential race condition issue, we have improved the process of generating new encryption keys.

iOS specific

  • Fixed an issue where Bluetooth sessions might have been terminated before data exchange is completed. This can occur when the developer terminates the session after receiving a single response, but that response doesn't include all the required data. This might happen on devices with lower data transmission speed or when the response size is too big.

Android specific

  • Fixed an issue where the SDK was unable to handle mobile credential presentation responses with floating point claims.

Notes

  • The SDK now supports React Native 0.72.14.

2.0.0

BREAKING CHANGES

  • Refined structure for credential errors in MobileCredentialResponse objects

Features

  • Added support for Android platform

Bug Fixes

  • Fixed error handler for createProximityPresentationSession and sendProximityPresentationRequest functions
  • Fixed createProximityPresentationSession to unregister React Native event listeners on error

Notes

  • Dependency upgrades and vulnerability fixes

1.0.1

Notes

  • Enhance documentation

1.0.0

Features

  • Add support for mobile credential (ISO Only). The current functionality includes

    • Manage mobile credential trusted issuer certificates
    • Request mobile credentials from a credential holder device

Generated using TypeDoc