Use the Compact Credentials Verifier SDK

Verifier

Creating a new verifier

typescript
Copy to clipboard.
1import { InitOptions } from "@mattrglobal/verifier-sdk-react-native";
2
3const initOptions: InitOptions = {
4    issuerCacheTtl: 60000,
5    revocationListCacheTtl: 60000,
6    trustedIssuers: ["did:web:organization.com"], // defaults to trust any issuer
7    assertExpiry: true, // defaults to true
8    assertNotBefore: true, // defaults to true
9    checkRevocation: true, // defaults to true
10};
11
12const verifier = await init(initOptions);

Verifying a credential

typescript
Copy to clipboard.
1// Verify a credential payload as encoded & signed string
2const verifyResult = await verifier.verify({ payload });
3
4if (verifyResult.isErr()) {
5    // Handle error from verifyResult.error
6    return;
7}
8
9const { verified } = verifyResult.value;

Cache

The following allows you to get the expiry date of the cached revocation lists and trusted issuers, and refresh the icache.

Getting expiry date of the cache

typescript
Copy to clipboard.
1const expiry = await verifier.getCacheExpiry();

Refreshing the items in the cache

typescript
Copy to clipboard.
1const refreshCacheResult = await verifierSdk.refreshCache();
2
3if (refreshCacheResult.isErr()) {
4    /**
5     * The error contains the cache expiry date
6     * This date may have changed after partial refresh
7     */
8    console.log(refreshCacheResult.error.expiryDate);
9    // Handle error from refreshCacheResult.error
10    return;
11}
12
13// New expiry date of the cache
14const { expiryDate } = refreshCacheResult.value;

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.

typescript
Copy to clipboard.
1import { open } from "@mattrglobal/verifier-sdk-react-native";
2
3const openVerifierResult = await open();
4
5if (openVerifierResult.isErr()) {
6    // Handle error from openVerifierResult.error
7    return;
8}
9
10const verifier = openVerifierResult.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.

typescript
Copy to clipboard.
1import { unwrap } from "@mattrglobal/verifier-sdk-react-native";
2
3try {
4    const verifier = unwrap(await open());
5} catch (error) {
6    // Handle thrown error
7}

Known issues

1. Build error: "ld: symbol(s) not found for architecture x86_64"

This error can arise when using flipper and react-native-bignumber together. Disabling flipper is the only solution at the moment. See here for more details.

2. Build error: "Plugin with id 'maven' not found."

Currently, react-native-securerandom is not compatible with Gradle 7+ (see issue) and will not build for Android without downgrading Gradle to 6.9 or below.

Find the comprehensive SDK interfaces for these examples and others in our Verifier SDK Docs.

Get in touch if you wish to find out more about using the MATTR Pi Compact Credentials Verifier SDK in production.