• About TrustVision
  • Android SDK
  • iOS SDK
  • Flutter SDK
  • Web SDK
  • API Client Libraries
  • eKYC Platform
  • Integration Case Studies
  • TS eKYC/FA App
TrustVision API Documentation

React Native 1.x.x

Installation

Common

1. Add Trust Vision React Native lib

Add to package.json file under dependencies group:

"react-native-trust-vision-SDK": "git+https://github.com/tsocial/react-native-trust-vision-SDK"

2. Run

$ yarn

iOS

1. Add to podfile

...
pod 'RNTrustVisionRnsdkFramework', path: '../node_modules/react-native-trust-vision-SDK'

2. Run

$ pod install

Android

Add to root-level build.gradle file (host app):

maven {
     url("$rootDir/../node_modules/react-native-trust-vision-SDK/android/repo")
}

eg:

allprojects {
    repositories {
        mavenLocal()
        ...
        maven {
             url("$rootDir/../node_modules/react-native-trust-vision-SDK/android/repo")
        }
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

Usage

javascript
import RNTrustVisionRnsdkFramework, {
  TVConst,
  TVErrorCode,
} from "react-native-trust-vision-SDK";

Full steps:

javascript
try {
  await RNTrustVisionRnsdkFramework.initialize(
    "input_your_access_key",
    "input_your_secret_key",
    true
  );
  const cardTypes = await RNTrustVisionRnsdkFramework.getCardTypes();
  const config = {
    actionMode: TVConst.ActionMode.FULL,
    cardType: cardTypes[0],
    livenessMode: TVConst.LivenessMode.PASSIVE,
    isEnableIDSanityCheck: true,
    isEnableSelfieSanityCheck: false,
  };
  console.log("Config", config);
  const result = await RNTrustVisionRnsdkFramework.startFlow(config);
  console.log("Result", result);
} catch (e) {
  switch (e.code) {
    // local error
    case TVErrorCode.UNAUTHORIZED:
    case TVErrorCode.NETWORK_ERROR:
    case TVErrorCode.INTERNAL_ERROR:
    case TVErrorCode.TIMEOUT_ERROR:
    case TVErrorCode.CANCELATION_ERROR:
      console.log("Error: ", e.code, " - ", e.message);
      break;
    default:
      // error from backend
      console.log("Error: ", e.code, " - ", e.message);
      break;
  }
}

1. Initialize SDK

SDK needs to be initialized first

javascript
await RNTrustVisionRnsdkFramework.initialize(
  "input_your_access_key",
  "input_your_secret_key",
  true
);

2. Get supported ID cards list

After the SDK is initalized, use this method to get list supported ID.

javascript
const cardTypes = await RNTrustVisionRnsdkFramework.getCardTypes();

Where:

  • cardTypes: array of CardType objects
  • CardType objects:
    • id: String. Card's identification code
    • name: String. Card's name
    • orientation: TVConst.Orientation. Card's orientation
    • hasBackSide: Bool. Card requires backside or not

3. Start transaction (optional step)

Start transaction should be called when start new user journey.

javascript
const referenceId = await RNTrustVisionRnsdkFramework.startTransaction(
        referenceID: referenceID
);

Where

  • referenceId: String. Reference identification

4. Start the SDK

The SDK provides some built in functions to capture id, selfie, liveness...

4.1. Full flow

#####4.1.1. Set config parameters

javascript
const config = {
  actionMode: TVConst.ActionMode.FULL,
  cardType: cardTypes[0],
  livenessMode: TVConst.LivenessMode.PASSIVE,
  isEnableIDSanityCheck: true,
  isEnableSelfieSanityCheck: false,
};

Options:

  • actionMode: TVConst.ActionMode. Action mode
  • cardType: CardType. Card type
  • livenessMode: TVConst.LivenessMode. Liveness mode
  • isEnableSound: bool. Sound is played or not
  • isEnableSelfieSanityCheck: bool. Selfie sanity check is enabled or not
  • isEnableIDSanityCheck: bool. Id card sanity check is enabled or not
  • cameraOption: TVConst.SelfieCameraMode. Camera option

#####4.1.2. Start flow

javascript
const result = await RNTrustVisionRnsdkFramework.startFlow(config);

4.2. Start ID card capturing

4.2.1. Set config parameters
javascript
const config = {
  cardType: cardTypes[0],
  cardSide: TVConst.CardSide.FRONT,
  isEnableSound: true,
  isEnableSanityCheck: true,
};

Options:

  • cardType: CardType. Card type
  • cardSide: TVConst.CardSide. Card side
  • isEnableSound: bool. Sound is played or not
  • isEnableSanityCheck: bool. Id card sanity check is enabled or not
4.2.2. Start flow
javascript
const result = await RNTrustVisionRnsdkFramework.startIdCapturing(config);

4.3. Start selfie capturing

4.3.1. Set config parameters
javascript
const config = {
  cameraOption: TVConst.SelfieCameraMode.FRONT,
  isEnableSound: true,
  isEnableSanityCheck: true,
  livenessMode: TVConst.LivenessMode.PASSIVE,
};

Options:

  • cameraOption: TVConst.SelfieCameraMode. Camera option
  • isEnableSound: bool. Sound is played or not
  • isEnableSanityCheck: bool. Selfie sanity check is enabled or not
  • livenessMode: TVConst.LivenessMode. Liveness mode
4.3.2. Start flow
javascript
const result = await RNTrustVisionRnsdkFramework.startSelfieCapturing(config);

4.4. Match face

javascript
const result = await RNTrustVisionRnsdkFramework.matchFace(
  selfieImageId,
  frontIdCardImageId
);

Options:

  • selfieImageId: String. Id of selfie image
  • frontIdCardImageId: String. Id of front id card image

4.5. Download image

javascript
const base64Image = await RNTrustVisionRnsdkFramework.downloadImage(imageId);

Options:

  • imageId: String. id of Image to download

6. Result Handling:

6.1. Result object:

  • result:

    • cardType: CardType. Card type
    • actionMode: TVConst.ActionMode. Action Mode
    • compareFaceResult: CompareImageResult. Compare face Result
    • cardInfoResult: CardInfoResult. Card information result
    • livenessResult: LivenessResult. Liveness result
    • idSanityResult: SanityResult. Id card sanity result
    • selfieSanityResult: SanityResult. Selfie sanity result
    • selfieImage: <Base64 String>. Selfie image base64 string
    • idFrontImage: <Base64 String>. Id card's front side image base64 string
    • idBackImage: <Base64 String>. Id card's back side image base64 string
    • selfieImageId: String. Selfie image id
    • idFrontImageId: String. Id card's front side image id
    • idBackImageId: String. Id card's back side image id
    • croppedIdFrontImageId: String. Cropped front side id card' image id
    • croppedIdBackImageId: String. Cropped back side id card' image id
  • CompareImageResult:

    • score: float. The score from 0 to 1
    • matchResult: TVConst.CompareImageResult.
    • requestId: String. Id of request
  • CardInfoResult:

    • infos: array of CardInfo
    • requestId: String. Id of request
  • CardInfo:

    • field: String. Name of field example name, address...
    • value: String. The value of each field
  • LivenessResult:

    • score: float. The score from 0 to 1
    • isLive: bool. Selfie image is live or not
    • requestId: String. Id of request
  • SanityResult:

    • isGood: bool. Sanity is good or not
    • score: float. The score from 0 to 1
    • requestId: String. Id of request
    • error: Error. Error object
  • Error:

    • errorCode: String. The specific error code
    • description: String. The human-readable error description can be show to end user

6.2. Sanity result error handling

6.2.1. Id sanity
javascript
if (result.idSanityResult && result.idSanityResult.error) {
  switch (result.idSanityResult.error) {
    case "image_too_blur":
      // Image is too blurry
      break;
    case "image_too_dark":
      // Image is too dark
      break;
    case "image_too_bright":
      // Image is too bright
      break;
    case "image_has_hole":
      // Image has holes
      break;
    case "image_has_cut":
      // Images has been cut
      break;
    case "image_has_hole_and_cut":
      // Images has holes and has been cut
      break;
  }
}
6.2.2. Selfie sanity
javascript
if (result.selfieSanityResult && result.selfieSanityResult.error) {
  switch (result.selfieSanityResult.error) {
    case "image_too_blur":
      // Image is too blurry
      break;
    case "image_too_dark":
      // Image is too dark
      break;
    case "image_too_bright":
      // Image is too bright
      break;
    case "not_white_background":
      // The background is not white enough
      break;
    case "not_qualified":
      // The face is not qualified, could be occluded, covered or having something unusal
      break;
    case "image_has_multiple_faces":
      // Image has multiple faces
      break;
    case "image_has_no_faces":
      // Image does not have any face
      break;
    case "right":
      // Face is looking to the right
      break;
    case "left":
      // Face is looking to the left
      break;
    case "open_eye,closed_eye":
      // Right eye is closed
      break;
    case "closed_eye,open_eye":
      // Left eye is closed
      break;
    case "open_eye,sunglasses":
      // Sunglass covers the right eye
      break;
    case "sunglasses,open_eye":
      // Sunglass covers the left eye
      break;
    case "closed_eye,closed_eye":
      // Both eyes are closed
      break;
    case "closed_eye,sunglasses":
      // Left eye is closed, sunglass covers the right eye
      break;
    case "sunglasses,closed_eye":
      // Sunglass covers the right eye, right eye is closed
      break;
    case "sunglasses,sunglasses":
      // Sunglasses cover both eyes
      break;
  }
}

7. Error handling

javascript
switch (e.code) {
  // local error
  case TVErrorCode.UNAUTHORIZED:
  case TVErrorCode.INTERNAL_ERROR:
  case TVErrorCode.CANCELATION_ERROR:
    console.log("Error: ", e.code, " - ", e.message);
    break;
  default:
    // error from backend
    console.log("Error: ", e.code, " - ", e.message);

    switch (e.code) {
      // connection errors
      case "timeout_error":
      // Network timeout. Poor internet connection.
      case "network_error":
      // Network error. No internet connection

      // Id capturing
      case "incorrect_card_type":
        // the input image is not same type with selected card
        break;
      case "nocard_or_multicard_image":
        // the input image is no card or multicard detected
        break;

      // Selfie capturing
      case "image_has_no_faces":
        // face not detected in selfie image
        break;
      case "image_has_multipe_faces":
        // multiple faces are detected in selfie image
        break;

      // Common errors
      case "access_denied_exception":
        break;
      case "invalid_parameter_exception":
        break;
      case "rate_limit_exception":
        break;
      case "internal_server_error":
        break;
    }

    break;
}