Use the Mobile Credentials Verifier SDK
Install dependencies
Add this SDK as a dependency to the react native app:
1yarn add @mattrglobal/mobile-credential-verifier-react-native
NOTE: mobile credential presentation utilise Bluetooth connection. For iOS make sure the
NSBluetoothAlwaysUsageDescription
andNSBluetoothPeripheralUsageDescription
description are configured insideInfo.plist
.
Verifier
Initialise the verifier SDK
NOTE: SDK must be initialised first, otherwise other methods will throw an exception when invoked.
1iimport { initialise } from "@mattrglobal/mobile-credential-verifier-react-native";
2
3await initialise();
Trusted Issuers
Manage trusted issuer certificates
1import {
2 addTrustedIssuerCertificates,
3 getTrustedIssuerCertificates,
4 deleteTrustedIssuerCertificate,
5} from "@mattrglobal/mobile-credential-verifier-react-native";
6
7// Add a new certificate
8const addCertificateResult = await addTrustedIssuerCertificates([
9 "MIIBwzCCAWmgAwIBAgILAOZSe5t+MOzXtX8wCgYIKoZIzj0EAwIwIDEeMAkGA1UEBhMCTlowEQYDVQQDEwpNQVRUUiBJQUNBMB4XDTIzMDcxODIwMDYzM1oXDTMzMDcxNTIwMDYzM1owIDEeMAkGA1UEBhMCTlowEQYDVQQDEwpNQVRUUiBJQUNBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE0XWwfvFPzbBHiDVLefOueGG1DMHc8WRfXfZqD6748kLZNTOBysm635yM7YCMlkUxDEIHVkLeyV6KoAOM2o0i5qOBiTCBhjASBgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIABjAdBgNVHQ4EFgQUypKEavotsICoAsXypAUUlsVUylMwHAYDVR0SBBUwE4ERaW5mb0BtYXR0ci5nbG9iYWwwIwYDVR0fBBwwGjAYohaGFGh0dHBzOi8vbWF0dHIuZ2xvYmFsMAoGCCqGSM49BAMCA0gAMEUCIClmASfWcf/K2WbClaERQfA38TNTSgYZu2SdNeNFdQyGAiEAhfk+FloZkNOb6TOLcDGqSNwXf+NzvPX0yl+8aq+rMKQ=",
10]);
11
12if (addCertificateResult.isErr()) {
13 const { error } = addCertificateResult;
14 // handle error scenarios
15 return;
16}
17
18// Get list of all stored certificates
19const certificates = await getTrustedIssuerCertificates();
20
21// Delete certificate by id
22await deleteTrustedIssuerCertificate(certificateId);
Request Credentials
Request for mobile credentials
1import {
2 createProximityPresentationSession,
3 sendProximityPresentationRequest,
4 terminateProximityPresentationSession,
5} from "@mattrglobal/mobile-credential-verifier-react-native";
6
7// Create new session
8const createSessionResult = await createProximityPresentationSession({
9 deviceEngagement: "mdoc:owBjMS4wAYIB2BhYS6QBAiABIVgg_t9K0BaXU27ynODS5q8OcvBZ4m1HFEQwl61lhRD2rdciWCA7hKLr_xN6_bdznDePa_yY1tGdHsc8ni_88uVuehRU-QKBgwIBowD1AfQKUMW8DfgLrUclmxp2InJCddk" // proximity presentation device engagement string
10 onConnected: () => {
11 // handle onConnect event
12 },
13 onSessionTerminated: () => {
14 // handle onSessionTerminated event
15 },
16});
17
18if (createSessionResult.isErr()) {
19 const { error } = createSessionResult;
20 // hande error scenarios
21 return;
22}
23
24// Send session
25const sendRequestResult = await sendProximityPresentationRequest({
26 mobileCredentialRequests: [{
27 docType: "org.iso.18013.5.1.mDL",
28 namespaces: {
29 "org.iso.18013.5.1": {
30 family_name: false,
31 driving_privileges: false,
32 },
33 },
34 }],
35});
36
37if (sendRequestResult.isErr()) {
38 const { error } = sendRequestResult;
39 // handle error scenarios
40 return;
41}
42
43const response = sendRequestResult.value;
44
45// Terminate current active session
46await 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.
1import { sendProximityPresentationRequest } from "@mattrglobal/mobile-credential-verifier-react-native";
2
3// Send session
4const sendRequestResult = await sendProximityPresentationRequest(...);
5
6if (sendRequestResult.isErr()) {
7 const { error } = sendRequestResult;
8 // handle error scenarios
9 return;
10}
11
12const 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
1import { unwrap, sendProximityPresentationRequest } from "@mattrglobal/mobile-credential-verifier-react-native";
2
3try {
4 const sendRequestResult = unwrap(await sendProximityPresentationRequest(...));
5} catch (error) {
6 // Handle thrown error
7}
Find the comprehensive SDK interfaces for these examples and others in our Mobile Credentials Verifier SDK Docs.
Get in touch if you wish to find out more about using the MATTR Pi Mobile Credentials Verifier SDK in production.