Add to package.json file under dependencies group:
"react-native-trust-vision-SDK": "git+https://<github_token>:[email protected]/tsocial/<repo_name>#<version_tag_name>"
$ yarn
...
pod 'RNTrustVisionRnsdkFramework', path: '../node_modules/react-native-trust-vision-SDK'
...
# Add below lines to the end of podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -no-verify-emitted-module-interface'
end
// you can add more modules which have the error "Undefined symbol" into the list
if ['TensorFlowLiteC', 'TensorFlowLiteSwift', 'PromiseKit', 'CryptoSwift'].include? "#{target}"
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end
$ 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"
}
// Support 16KB https://developer.android.com/guide/practices/page-sizes
ndk {
abiFilters "arm64-v8a", "armeabi-v7a"
}
}
import { NativeEventEmitter } from "react-native";
import RNTrustVisionRnsdkFramework, {
TVConst,
TVErrorCode,
} from "react-native-trust-vision-SDK";
Full steps:
try {
const initConfig = {
jsonConfigurationByServer: jsonConfigurationByServer,
languageCode: languageCode,
};
await RNTrustVisionRnsdkFramework.initializeWithConfig(initConfig);
const tvsdkEmitter = new NativeEventEmitter(RNTrustVisionRnsdkFramework);
// Listen to the frame batches recorded during the capturing
const subscription = tvsdkEmitter.addListener(
"TVSDKFrameBatch",
(frameBatch) => {
console.log("TVSDK - FrameBatch:", frameBatch.batchId);
}
);
// (Android only) image read from the chip during NFC face authentication:
// tvsdkEmitter.addListener("TVSDKReadIdCardImage", (image) => { /* ... */ });
const selfieConfig = {
cameraOption: TVConst.SelfieCameraMode.FRONT,
livenessMode: TVConst.LivenessMode.FLASH_ADVANCED,
skipConfirmScreen: true,
isEnableSound: false,
};
const faceAuthConfig = {
cusUserId: "cusUserId",
authType: TVConst.AuthenType.REGISTRATION,
authMode: TVConst.AuthenMode.FLASH_8,
selfieConfig: selfieConfig,
};
const faceAuthResult =
await RNTrustVisionRnsdkFramework.startFaceAuthentication(faceAuthConfig);
} catch (e) {}
SDK needs to be initialized first
const initConfig = {
jsonConfigurationByServer: jsonConfigurationByServer,
languageCode: languageCode,
theme: theme,
endpoint: endpoint,
accessKeyId: accessKeyId,
accessKeySecret: accessKeySecret,
endpointLogger: endpointLogger,
accessKeyIdLogger: accessKeyIdLogger,
accessKeySecretLogger: accessKeySecretLogger,
xRequestId: xRequestId,
xRequestId2: xRequestId2,
imageEncryptionKey: imageEncryptionKey,
securityPublicKey: securityPublicKey,
flowId: flowId,
headers: headers,
};
await RNTrustVisionRnsdkFramework.initializeWithConfig(initConfig);
Options:
String the code of the language that will show and sound to user. E.g Vietnamese (vi), English (
en).String (optional). the key to encrypt image data. It's optional. If it's null or empty then the image data
will not be encrypted.String (optional). the key to encrypt exif data. It's optional. If it's null or empty then the exif data
will be encrypted by the default key.TVTheme (optional, iOS only). The theme of the SDK. If it's null then the SDK will use the default theme or the theme that we customized for the client. On Android this key is ignored.To call the APIs in the SDK, the host app needs to set the following parameters:
String. The endpoint of the server.String. The access key id of the server.String. The secret key of the server.String (optional) https://ekyc.trustingsocial.com/api-reference/customer-api#api-reconciliationString (optional)Map<String, String> (optional). The headers to be added to the request.String (optional). The flow id of the APIThe host app will call the APIs itself, set the following parameters:
String. set this parameter if the host app will call the APIs itself. The jsonConfigurationByServer
is the setting specialized for each client from TS server.
It's the response json string get by
API https://ekyc.trustingsocial.com/api-reference/customer-api/#get-client-settings.
When it's null or unmatched with the expected type then the default setting in the SDK will be used.If the log event feature is used, set the following parameters:
String. The endpoint of the log event server.String. The access key id of the log event server.String. The secret key of the log event server.boolean (Android only). Enable fetching the client settings from the server during initialization. Ignored on iOS.The SDK provides some built in functions to capture id, selfie, liveness...
const idConfig = {
cardTypes: [cardType],
cardSide: TVConst.CardSide.FRONT,
isEnableSound: true,
isReadBothSide: false,
skipConfirmScreen: true,
isEnablePhotoGalleryPicker: false,
isEnableUploadFrames: true,
isEnableUploadImages: true,
isEnableSanityCheck: true,
isEnableDetectingIdCardTampering: true,
isEnableReadCardInfo: true,
isEnableCheckNfcData: true,
isEnableVerifyNfc: true,
};
Options:
[CardType]. Card types allowed to capture. The list of supported cards can be retrieved via await RNTrustVisionRnsdkFramework.getCardTypes() after you initialize the SDK with the clientSettingsJsonString. If not, use :const cardType = {
id: "vn.national_id",
name: "CMND cũ / CMND mới / CCCD",
orientation: TVConst.Orientation.HORIZONTAL,
hasBackSide: true,
frontQr: {
exist: true,
type: "qr_code",
widthHeightRatio: 1,
},
};
TVConst.CardSide. Card sidebool. Sound is played or notbool. Read both sides of id card or notbool. Skip confirmation screen or notbool. Allow user select id card image from phone gallerybool. Allow user scan QR code or notbool. Allow user scan NFC or notboolean. Enable upload video frames or not. If it's false then the SDK won't call the API to upload
the frames and the APIs that need the video frames will be skipped or called with empty frames data.boolean. Enable upload images or not. If it's false then the SDK won't call the API to upload
the images and the APIs that need the image will be skipped.boolean. Enable sanity check or not. If it's true then the SDK will call
the API to check the sanity of the id card.boolean. Enable ID Tampering Verification or not. If it's true then the SDK
will call the API to
check the tampering of the id card.boolean. Enable read card info or not. If it's true then the SDK will call
the API to read the card info.boolean. Enable check NFC data or not. If it's true then the SDK will call
the API to get sod and cached fields of the NFC data.boolean. Enable verify NFC or not. If it's true then the SDK will call
the API to verify the NFC.startIdCapturing also reads these options:
String. ID tampering sensitivity level (passed through as-is).boolean. Capture-only mode (skip verification APIs).Int. Maximum NFC scan retries.boolean. Request NFC chip integrity check.boolean. Request NFC clone detection.boolean. Request reading the chip image.Additional ID config fields
The ID config also accepts these keys (newly mapped by the wrapper):
| Key | Type | Default | Requirement | Description |
|---|---|---|---|---|
isEnableQrScanGuideline | bool | true | optional | Show the QR-scan guideline popup |
isAutoShowGuideline | bool | true | optional | Auto-show the capture guideline |
isShowProgressBarHeader | bool | true | optional | Show the step/progress header bar |
isEnableCallApiOcrNfc | bool | true | optional | Call the OCR-from-NFC API |
isEnableTiltChecking | bool | false | optional | Tilt/parallel check before capture (Android) |
const result = await RNTrustVisionRnsdkFramework.startIdCapturing(config);
If the APIs is called by the SDK, please skip the image upload step.
if result.frontIdQr.is_required is true then result.frontIdQr.images array should be non-empty. Otherwise, clients should be warned to re-capture id card photos.
QR imagegs will be uploaded with this api: https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
result.frontIdQr.images[i].raw_image_base64result.frontIdQr.images[i].labelresult.frontIdQr.images[i].metadata*The same logic will be applied to result.backIdQr
const config = {
cameraOption: TVConst.SelfieCameraMode.FRONT,
isEnableSound: true,
livenessMode: TVConst.LivenessMode.FLASH_16,
skipConfirmScreen: true,
isEnableUploadFrames: true,
isEnableUploadImages: true,
isEnableSanityCheck: true,
isEnableVerifyLiveness: true,
};
Options:
TVConst.SelfieCameraMode. Camera optionbool. Sound is played or notTVConst.LivenessMode. Liveness modebool. Skip confirmation screen or notboolean. Enable upload video frames or not. If it's false then
the SDK won't call the API to upload the frames and the APIs that need the video frames will be skipped or called with empty frames data.boolean. Enable upload images or not. If it's false then
the SDK won't call the API to upload the images and the APIs that need the image will be skipped.boolean. Enable sanity check or not. If it's true then the SDK will call
the API to check the sanity of the selfie.boolean. Enable liveness verification or not. If it's true
then the SDK will call the API to verify the liveness of the selfie.Additional selfie config fields
The selfie config also accepts these keys (newly mapped by the wrapper):
| Key | Type | Default | Requirement | Description |
|---|---|---|---|---|
isAutoShowGuideline | bool | true | optional | Auto-show the capture guideline |
isShowProgressBarHeader | bool | true | optional | Show the step/progress header bar |
isEnableExitConfirmPopup | bool | false | optional | Confirm popup when the user exits |
isEnableVerticalChecking | bool | false | optional | Check phone is vertical first |
defaultCameraSide | TVDefaultCameraSide | FRONT | optional | Default camera side |
selfieType | String | null | optional | Selfie capture type |
const selfieCapturingResult =
await RNTrustVisionRnsdkFramework.startSelfieCapturing(config);
If the APIs is called by the SDK, please skip this step.
Note: Ignore this section if Frame recording is disabled by client settings.
var frameBatchIdsDictionary = []; // this dictionary will be used for liveness verification
// frameBatchIdsDictionary.push({
// key: <id_returned_from_sdk>,
// value: <id_returned_from_server>
// });
// Listen to the frame batches recorded during the capturing
const framesRecordedSubscription = tvsdkEmitter.addListener(
"TVSDKFrameBatch",
async (frameBatch) => {
console.log("TVSDK - " + "FrameBatch: ", frameBatch);
// upload frame batch to server using this api:
// https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-videoaudioframes
const uploadingResult = await uploadFrameBatch(frameBatch);
frameBatchIdsDictionary.push({
key: frameBatch.batchId,
value: uploadingResult.fileId,
});
}
);
If the APIs is called by the SDK, please skip this step.
Note: Ignore this section if Frame recording is disabled by client settings.
Only frame batches of Selfie capturing which id is containing in selfieCapturingResult.livenessFrameBatchIds are valid to be used for liveness verification.
// Remove all invalid batch ids:
Object.entries(frameBatchIdsDictionary).map(
([id_returned_from_sdk, id_returned_from_server]) => {
if (
!selfieCapturingResult.livenessFrameBatchIds.includes(
id_returned_from_sdk
)
) {
delete frameBatchIdsDictionary[id_returned_from_sdk];
}
}
);
https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
id of frontal image i = image id of selfieCapturingResult.selfieImages[i].frontal_image.raw_image_base64
id of gesture image i = image id of selfieCapturingResult.selfieImages[i].gesture_image.raw_image_base64
https://ekyc.trustingsocial.com/api-reference/customer-api/#verify-face-liveness with params
images field, each element contains:{
"id": "<id of frontal image i>"
}
gesture_images field, each element contains:{
"gesture": "lower case string of <selfieCapturingResult.selfieImages[i].gesture_type>",
"images": [
{
"id": "<id of gesture image i>"
}
]
}
videos field is the list of frame batch ids returned from server, which are the values of frameBatchIdsDictionary
Note: Ignore this field if Frame recording is disabled by client settings.{
"id": "<frameBatchIdsDictionary's values[0]>"
},
{
"id": "<frameBatchIdsDictionary's values[1]>"
}
...
metadata field is selfieCapturingResult.livenessMetadataconst config = {
cardType: cardType,
cardTypes: [cardType],
isEnableSound: false,
skipConfirmScreen: true,
cardSide: TVConst.CardSide.FRONT,
isEnableUploadFrames: true,
isEnableUploadImages: true,
};
Options:
CardType. Card type[CardType]. List of Card type, please init with one item.TVConst.CardSide. Card sidebool. Sound is played or notbool. Skip confirmation screen or notboolean. Enable upload video frames or notboolean. Enable upload images or notAdditional QR config field
The QR config also accepts this key (newly mapped by the wrapper):
| Key | Type | Default | Requirement | Description |
|---|---|---|---|---|
isEnableQrScanGuideline | bool | true | optional | Show the QR-scan guideline popup |
const result = await RNTrustVisionRnsdkFramework.startQRScanning(config);
If the APIs is called by the SDK, please skip this step.
if result.frontIdQr.isRequired is true then result.frontIdQr.images array should be non-empty. Otherwise, clients should be warned to re-scan QR code.
QR images will be uploaded with this api: https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
const frontQrImage = result.frontIdQr.images[i];
const metadata = frontQrImage.metadata;
const label = frontQrImage.label;
const data = frontQrImage.imageByteArray;
*The same logic will be applied to result.backIdQr
const config = {
nfcCode: nfcCode,
nfcSod: sod,
cardIssueDate: issueDate,
nfcCacheFields: cachedFields,
isRequestReadImageNfc: true,
isRequestIntegrityCheckNfc: true,
isRequestCloneDetectionNfc: true,
nfcMaxRetries: 5,
isEnableCheckNfcData: true,
isEnableVerifyNfc: true,
};
Options:
String is the id number of ID cardString (optional) is the hash of SODString (optional) is the issue date of ID card (DD/MM/YYYY)List<String> (optional) is the list of fields that was cached from previous scanningboolean (optional) read image in the chip when scan nfc or notboolean (optional) check integrity of the chip when scanning nfc or notboolean (optional) check clone of the chip when scanning nfc or notInt. (optional) The maximum number of times the SDK retries an NFC scanning before giving upboolean. Enable check NFC data or not. If it's true then the SDK will call
the API to get sod and cached fields of the NFC data.boolean. Enable verify NFC or not. If it's true then the SDK will call
the API to verify the NFC data.Additional NFC config fields
The NFC config also accepts these keys (newly mapped by the wrapper):
| Key | Type | Default | Requirement | Description |
|---|---|---|---|---|
dateOfBirth | String | "" | optional ¹ | Holder date of birth (MRZ key) |
dateOfExpiry | String | "" | optional ¹ | Document expiry date (MRZ key) |
nfcDocumentType | String | "" | optional ¹ | NFC document type |
nfcInputMode | String | MANUAL | optional ¹ | NFC input mode (MANUAL / MRZ / QR) |
isEnableQrScanGuideline | bool | true | optional | Show the QR-scan guideline popup |
¹ Optional in general, but required for the passport / eMRTD MRZ input flow.
const result = await RNTrustVisionRnsdkFramework.startNfcScanning(config);
const selfieConfig = {
cameraOption: TVConst.SelfieCameraMode.FRONT,
livenessMode: TVConst.LivenessMode.FLASH_ADVANCED,
skipConfirmScreen: true,
isEnableSound: false,
};
const cardTypes = await RNTrustVisionRnsdkFramework.getCardTypes();
const config = {
cusUserId: "cusUserId",
authType: TVConst.AuthenType.REGISTRATION,
authMode: TVConst.AuthenMode.FLASH_ADVANCED,
isEnableFaceAuthentication: true,
isEnableFaceRegistration: true,
selfieConfig: selfieConfig,
cardConfig: {
cardTypes,
isEnableSound: true,
isReadBothSide: true,
skipConfirmScreen: true,
isEnablePhotoGalleryPicker: false,
cardSide: TVConst.CardSide.FRONT,
},
};
String. The customer user idAuthType. Type of authentication, AUTH or REGISTRATIONTVConst.AuthenMode. The authentication source — see the AuthenMode table. Can be NFC or a selfie/liveness mode.cardTypes (from getCardTypes()), cardSide, isReadBothSide, skipConfirmScreen, isEnablePhotoGalleryPicker, isEnableSound, … On Android it is consumed only when authMode is TVConst.AuthenMode.NFC (ignored for selfie/liveness modes).TVSelfieConfiguration. The configuration of selfie capturingboolean. Enable call API face authentication or notboolean. Enable call API face registration or notTVConst.AuthenMode values
| Constant | Value |
|---|---|
PASSIVE | passive |
ACTIVE | active |
NFC | nfc |
FLASH_EDGE | flash_edge |
FLASH_ADVANCED | flash_advanced |
FLASH | flash |
FLASH_8 | flash_8 |
FLASH_16 | flash_16 |
FLASH_32 | flash_32 |
LIGHT | light |
await RNTrustVisionRnsdkFramework.startFaceAuthentication(config);
If the APIs is called by the SDK, please skip this step.
var frameBatchIdsDictionary = []; // this dictionary will be used for liveness verification
// frameBatchIdsDictionary.push({
// key: <id_returned_from_sdk>,
// value: <id_returned_from_server>
// });
// Listen to the frame batches recorded during the capturing
const framesRecordedSubscription = tvsdkEmitter.addListener(
"TVSDKFrameBatch",
async (frameBatch) => {
console.log("TVSDK - " + "FrameBatch: ", frameBatch);
// upload frame batch to server using this api:
// https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-videoaudioframes
const uploadingResult = await uploadFrameBatch(frameBatch);
frameBatchIdsDictionary.push({
key: frameBatch.batchId,
value: uploadingResult.fileId,
});
}
);
result:
cardType: CardType. Card type
actionMode: TVConst.ActionMode. Action Mode
selfieImages: [SelfieImage]. List of selfie image objects
livenessVideos: [Base64 String]. List of liveness videos data base64
livenessMetadata: json
livenessVideoFramesList: [json]
idFrontImage: ImageClass. Id front image object
idBackImage: ImageClass. Id back image object
frontIdQr: TVCardQr. Front Id card's QR info
backIdQr: TVCardQr. Back Id card's QR info
frontIdCapturingVideoFramesList: json
backIdCapturingVideoFramesList: json
nfcInfoResult: TVNfcInfoResult. NFC info result
faceAuthRegisterResult: TVFaceAuthRegisterResult
faceAuthResult: TVFaceAuthResult
SelfieImage:
String — lowercase value (e.g. up, down, left, right, frontal)ImageClass. Frontal image objectImageClass. Gesture image objectImageClass:
String. Base64 string of image dataString. Encrypted image as hex stringString. Server image idjson. Image metadataTVCardQr:
Bool. This side of card contains QR or not[ImageClass]. QR imagesError:
String. The specific error codeString. The human-readable error description can be show to end userTVErrorCode values (possible errorCode)
| Value |
|---|
authentication_missing_error |
network_error |
internal_error |
timeout_error |
sdk_canceled |
TVNfcInfoResult:
StringStringStringStringStringStringStringTVNfcVerificationResultTVNfcVerificationResult:
TVNfcVerificationResultStatusTVNfcVerificationResultStatus:
TVErrorTVNfcVerdict. TVNfcVerdict.notChecked | TVNfcVerdict.alert | TVNfcVerdict.good | TVNfcVerdict.errorTVFaceAuthRegisterResult:
StringString. success | failureTVFaceAuthResult:
StringString. success | failureFloatMatchResult. MatchResult.match | MatchResult.unmatched | MatchResult.unsureAll enums are exported from react-native-trust-vision-SDK (TVConst.*, plus the top-level TVErrorCode).
| Enum | Values |
|---|---|
TVConst.Orientation | vertical, horizontal |
TVConst.QRType | qrCode, barCode |
TVConst.ActionMode | FACE_MATCHING, FULL, LIVENESS, EXTRACT_ID_INFO (= READ_CARD_INFO) |
TVConst.LivenessMode | active, passive, hybrid, none, flash, flash_edge, flash_advanced, flash_8, flash_16, flash_32 |
TVConst.SelfieCameraMode | front, back, both |
TVConst.CompareImageResult | matched, unmatched, unsure |
TVConst.CardSide | front, back |
TVConst.AuthenType | AUTH, REGISTRATION |
TVConst.AuthenMode | 10 values — see the AuthenMode table |
TVErrorCode | 5 values — see the TVErrorCode table |