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>"
$ yarn
...
pod 'RNTrustVisionRnsdkFramework', path: '../node_modules/react-native-trust-vision-SDK'
$ pod install
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"
}
}
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;
}
}
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
);
After the SDK is initialized, use this method to get list supported ID.
const cardTypes = await RNTrustVisionRnsdkFramework.getCardTypes();
Where:
String
. Card's identification codeString
. Card's nameTVConst.Orientation
. Card's orientationBool
. Card requires backside or notStart transaction should be called when start new user journey.
const referenceId = await RNTrustVisionRnsdkFramework.startTransaction(
referenceID: referenceID
);
Where
String
. Reference identificationThe SDK provides some built in functions to capture id, selfie, liveness...
#####4.1.1. Set config parameters
const config = {
actionMode: TVConst.ActionMode.FULL,
cardType: cardTypes[0],
livenessMode: TVConst.LivenessMode.PASSIVE,
isEnableIDSanityCheck: true,
isEnableSelfieSanityCheck: false,
};
Options:
TVConst.ActionMode
. Action modeCardType
. Card typeTVConst.LivenessMode
. Liveness modebool
. Sound is played or notbool
. Selfie sanity check is enabled or notbool
. Id card sanity check is enabled or notTVConst.SelfieCameraMode
. Camera option#####4.1.2. Start flow
const result = await RNTrustVisionRnsdkFramework.startFlow(config);
const config = {
cardType: cardTypes[0],
cardSide: TVConst.CardSide.FRONT,
isEnableSound: true,
isEnableSanityCheck: true,
isReadBothSide: false,
skipConfirmScreen: true,
};
Options:
CardType
. Card typeTVConst.CardSide
. Card sidebool
. Sound is played or notbool
. Id card sanity check is enabled or notbool
. Read both sides of id card or notbool
. Skip confirmation screen or notconst result = await RNTrustVisionRnsdkFramework.startIdCapturing(config);
const config = {
cameraOption: TVConst.SelfieCameraMode.FRONT,
isEnableSound: true,
isEnableSanityCheck: true,
livenessMode: TVConst.LivenessMode.HYBRID,
skipConfirmScreen: true,
};
Options:
TVConst.SelfieCameraMode
. Camera optionbool
. Sound is played or notbool
. Selfie sanity check is enabled or notTVConst.LivenessMode
. Liveness modebool
. Skip confirmation screen or notconst result = await RNTrustVisionRnsdkFramework.startSelfieCapturing(config);
const result = await RNTrustVisionRnsdkFramework.matchFace(
selfieImageId,
frontIdCardImageId
);
Options:
String
. Id of selfie imageString
. Id of front id card imageconst base64Image = await RNTrustVisionRnsdkFramework.downloadImage(imageId);
Options:
result:
CardType
. Card typeTVConst.ActionMode
. Action ModeCompareImageResult
. Compare face ResultCardInfoResult
. Card information resultLivenessResult
. Liveness resultSanityResult
. Id card sanity resultSanityResult
. Selfie sanity result[SelfieImage]
. List of selfie image objectsImageClass
. Id front image objectImageClass
. Id back image objectLivenessVideo
. List of liveness video objectsjson
LivenessVideo:
String
. Video id on serverString
. Base64 string of video data bytes[LivenessVideoFrame]
. List of liveness video's framesLivenessVideoFrame:
String
. Base64 string of frame image dataString
. LabelIndex
. Frame index in videoSelfieImage:
String
. UP | DOWN | LEFT | RIGHT | FRONTAL
ImageClass
. Frontal image objectImageClass
. Gesture image objectImageClass:
String
. Base64 string of image dataString
. Image idCompareImageResult:
float
. The score from 0 to 1TVConst.CompareImageResult
.String
. Id of requestCardInfoResult:
CardInfo
String
. Id of requestCardInfo:
String
. Name of field example name, address...String
. The value of each fieldLivenessResult:
float
. The score from 0 to 1bool
. Selfie image is live or notString
. Id of requestSanityResult:
bool
. Sanity is good or notfloat
. The score from 0 to 1String
. Id of requestError
. Error objectError:
String
. The specific error codeString
. The human-readable error description can be show to end userif (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;
}
}
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;
}
}
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;
}