Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

docs-verifier-sdk

Notifications You must be signed in to change notification settings

mattrglobal/docs-verifier-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mattr Verifier SDK React Native / Exports

verifier-sdk-react-native

Table of Contents

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

How to get access to MATTR Pi Verifier SDK

To gain access to the MATTR Pi Verifier SDK, please follow these steps:

  1. Request or download the "Terms of Agreement".
  2. Read the "Terms of Agreement", sign it, and return it to us.
  3. Create an account at NPMJS - Node package manager for JavaScript.
  4. Ensure multi-factor authentication (MFA) is configured on NPMJS Account.
  5. Create a personal access token Create a personal access token.
  6. Supply the NPMJS (Node package manager for JavaScript) account name back to MATTR.
  7. MATTR will process the request and provision access to the MATTR Pi Verifier SDK if approved.

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

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.0.0 react-native-securerandom@^1.0.0 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.5.1

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.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.getCacheExpiry();

Refresh 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 Resut.isErr() is true.

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

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

Licensing

See here for licence information

About

docs-verifier-sdk

Resources

Stars

Watchers

Forks

Packages

No packages published