Mattr Verifier SDK React Native - v1.0.1

verifier-sdk-react-native

Table of Contents

Licensing

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

Features

  • Verify credentials
  • Refresh cached revocation lists and trusted issuers
  • Get the expiry date of the most-soon-to-expire item in the cache

Getting started

Install dependencies

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

yarn add @mattrglobal/verifier-sdk-react-native

The SDK relies on a set of peer dependencies that contain native libraries and iOS pods. With React Native >=0.60 these dependencies will be autolinked.

Install the peer dependencies:

yarn add @mattrglobal/react-native-cryptography@^1.1.0 react-native-securerandom@^1.0.1 react-native-fs@^2.20.0 react-native-secure-key-store@^2.0.10 react-native-get-random-values@^1.8.0 react-native-mmkv@^2.10.1

Note: we tested with react-native 0.71.12, previous supported react-native version 0.70.6, 0.68.5

Usage

Verifier

Create a verifier:

import { init } from "@mattrglobal/verifier-sdk-react-native";

const initOptions: InitOptions = {
issuerCacheTtl: 60000,
revocationListCacheTtl: 60000,
trustedIssuers: ["did:web:example.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);

Verify a credential:

const verifyResult = await verifier.compact.verify({ payload });

if (verifyResult.isErr()) {
// Handle error from verifyResult.error
return;
}

const { verified } = verifyResult.value;

Close the verifier:

console.log(verifier.isOpen()); // true

const closeVerifierResult = await verifier.close();

if (closeVerifierResult.isErr()) {
// Handle error from closeVerifierResult.error
return;
}

console.log(verifier.isOpen()); // false

Destroy the verifier:

await verifier.destroy();

console.log(verifier.isOpen()); // false

Cache

Get the cache expiry date:

const expiry = await verifier.compact.getCacheExpiry();

Refresh the items in the cache:

const refreshCacheResult = await verifier.compact.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;

Refresh only issuer items in the cache:

const refreshIssuerCacheResult = await verifier.compact.refreshIssuerCache();

if (refreshIssuerCacheResult.isErr()) {
/**
* The error contains the cache expiry date
* This date may have changed after partial refresh
*/
console.log(refreshIssuerCacheResult.error.expiryDate);
// Handle error from refreshIssuerCacheResult.error
return;
}

// New expiry date of the issuers cache
const { expiryDate } = refreshIssuerCacheResult.value;

Refresh only revocation list items in the cache:

const refreshRevocationListCacheResult = await verifier.compact.refreshRevocationCache();

if (refreshRevocationListCacheResult.isErr()) {
/**
* The error contains the cache expiry date
* This date may have changed after partial refresh
*/
console.log(refreshRevocationListCacheResult.error.expiryDate);
// Handle error from refreshRevocationListCacheResult.error
return;
}

// New expiry date of the revocation list cache
const { expiryDate } = refreshRevocationListCacheResult.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 Resut.isErr() is true.

import { unwrap } from "@mattrglobal/verifier-sdk-react-native";

try {
const verifier = unwrap(await open());
} catch (error) {
// Handle thrown error
}

Change Log

[Unreleased]

Features

  • feat(verifier-sdk-core): verifier core sdk refresh methods for refreshing cache separately (#525) (9d7f33f)

1.0.1

Features

  • improve performance on using uncompressed public key (#84) (8208971)
  • react native 0.70 upgrade (#79) (c2681b1)
  • add cache functions and destroy on example app (89765ce)
  • add destroy function for verifier (71cceec)
  • upgrade opencore dependencies (#6) (aa18f62)
  • use native verify function (#34) (8e4c0b9)
  • use react-native-bignumber for speedups (#43) (2d17934)
  • verifier-sdk-react-native: add support for assertExpiry, assertNotBefore and checkRevocation (0a49571)
  • verifier-sdk-react-native: reimplement react native init function (0e3d735)

Bug Fixes

  • remove bbs-signatures peer requirement (07672d8)
  • verifier-sdk-react-native: android crashes with unsupported 0x hex number syntax (5632562)
  • verifier-sdk-react-native: remove opencore dependency from main bundle (3549de6)

Generated using TypeDoc