Use the Compact Credentials Verifier SDK
Verifier
Creating a new verifier
import { InitOptions } from "@mattrglobal/verifier-sdk-react-native";
const initOptions: InitOptions = {
issuerCacheTtl: 60000,
revocationListCacheTtl: 60000,
trustedIssuers: ["did:web:organization.com"], // defaults to trust any issuer
assertExpiry: true, // defaults to true
assertNotBefore: true, // defaults to true
checkRevocation: true, // defaults to true
};
const verifier = await init(initOptions);
Verifying a credential
// Verify a credential payload as encoded & signed string
const verifyResult = await verifier.verify({ payload });
if (verifyResult.isErr()) {
// Handle error from verifyResult.error
return;
}
const { 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
const expiry = await verifier.getCacheExpiry();
Refreshing the items in the cache
const refreshCacheResult = await verifierSdk.refreshCache();
if (refreshCacheResult.isErr()) {
/**
* The error contains the cache expiry date
* This date may have changed after partial refresh
*/
console.log(refreshCacheResult.error.expiryDate);
// Handle error from refreshCacheResult.error
return;
}
// New expiry date of the cache
const { 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.
import { open } from "@mattrglobal/verifier-sdk-react-native";
const openVerifierResult = await open();
if (openVerifierResult.isErr()) {
// Handle error from openVerifierResult.error
return;
}
const 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.
import { unwrap } from "@mattrglobal/verifier-sdk-react-native";
try {
const verifier = unwrap(await open());
} catch (error) {
// Handle thrown error
}
Known issues
- 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.
- 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.
Get in touch if you wish to find out more about using the MATTR Pi Compact Credentials Verifier SDK in production.