React Native 2.x.x full
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#<version_tag_name>"
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' }
}
}
Add to app/build.gradle
android {
...
aaptOptions {
noCompress "tflite"
noCompress "lite"
}
}
Usage
import RNTrustVisionRnsdkFramework, {
TVConst,
TVErrorCode,
} from "react-native-trust-vision-SDK";
Full steps:
try {
await RNTrustVisionRnsdkFramework.initialize(
"input_your_access_key",
"input_your_secret_key",
"input_your_endpoint",
null,
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
await RNTrustVisionRnsdkFramework.initialize(
"input_your_access_key",
"input_your_secret_key",
"input_your_endpoint",
"input_your_x-request-id",
true
);
2. Get supported ID cards list
After the SDK is initialized, use this method to get list supported ID.
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
- id:
3. Start transaction (optional step)
Start transaction should be called when start new user journey.
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
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
const result = await RNTrustVisionRnsdkFramework.startFlow(config);
4.2. Start ID card capturing
4.2.1. Set config parameters
const config = {
cardType: cardTypes[0],
cardSide: TVConst.CardSide.FRONT,
isEnableSound: true,
isEnableSanityCheck: true,
isReadBothSide: false,
skipConfirmScreen: 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 - isReadBothSide:
bool. Read both sides of id card or not - skipConfirmScreen:
bool. Skip confirmation screen or not
4.2.2. Start flow
const result = await RNTrustVisionRnsdkFramework.startIdCapturing(config);
4.3. Start selfie capturing
4.3.1. Set config parameters
const config = {
cameraOption: TVConst.SelfieCameraMode.FRONT,
isEnableSound: true,
isEnableSanityCheck: true,
livenessMode: TVConst.LivenessMode.HYBRID,
skipConfirmScreen: true,
};
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 - skipConfirmScreen:
bool. Skip confirmation screen or not
4.3.2. Start flow
const result = await RNTrustVisionRnsdkFramework.startSelfieCapturing(config);
4.4. Match face
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
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 - selfieImages:
[SelfieImage]. List of selfie image objects - idFrontImage:
ImageClass. Id front image object - idBackImage:
ImageClass. Id back image object - livenessVideos: (only apply for UI-only clients)
LivenessVideo. List of liveness video objects - livenessMetadata: (only apply for UI-only clients).
json
- cardType:
LivenessVideo:
- id:
String. Video id on server - data:
String. Base64 string of video data bytes - video_frames:
[LivenessVideoFrame]. List of liveness video's frames
- id:
LivenessVideoFrame:
- base64:
String. Base64 string of frame image data - label:
String. Label - index:
Index. Frame index in video
- base64:
SelfieImage:
- gesture_type:
String.UP | DOWN | LEFT | RIGHT | FRONTAL - frontal_image:
ImageClass. Frontal image object - gesture_image:
ImageClass. Gesture image object
- gesture_type:
ImageClass:
- raw_image_base64:
String. Base64 string of image data - image_id:
String. Image id
- raw_image_base64:
CompareImageResult:
- score:
float. The score from 0 to 1 - matchResult:
TVConst.CompareImageResult. - requestId:
String. Id of request
- score:
CardInfoResult:
- infos: array of
CardInfo - requestId:
String. Id of request
- infos: array of
CardInfo:
- field:
String. Name of field example name, address... - value:
String. The value of each field
- field:
LivenessResult:
- score:
float. The score from 0 to 1 - isLive:
bool. Selfie image is live or not - requestId:
String. Id of request
- score:
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
- isGood:
Error:
- errorCode:
String. The specific error code - description:
String. The human-readable error description can be show to end user
- errorCode:
6.2. Sanity result error handling
6.2.1. Id sanity
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
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
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;
}