@blusalt-sdk/react-native-blusalt-liveness
v0.1.21
Published
Liveness SDK for Android and IOS
Downloads
34
Readme
react-native-blusalt-liveness
Facial Comparison and Face Detection SDK for Android and IOS
Get your Liveness credentials from Blusalt
Features
Facial comparison (LivenessFacialComparisonType)
- Dynamic Liveness Detection (Motional): This method verifies liveness by requiring the user to perform specific actions like opening their mouth or shaking their head. It's strict because attempts to bypass the action (like holding a still image) will be detected and likely terminate the process.
- Static Liveness Detection (Still): This approach asks users to position their face within the camera frame and validates liveness based on facial data points. It's less strict than the dynamic method. If users struggle with finding the right camera position, the process might not automatically terminate, allowing them to adjust.
Face Detection (LivenessDetectionOnlyType)
- Dynamic Liveness Detection (Motional)
- Static Liveness Detection (Still)
- Flash Liveness Detection (Flash): This method is only available for facial detection, not facial comparison. It works similarly to the static method but increases the device screen brightness to enhance facial data point detection.
Installation
npm install react-native-blusalt-liveness
Usage
import { startFacialComparisonSDK, startLivenessDetectionOnlySDK, LivenessType } from '@blusalt-sdk/react-native-blusalt-liveness';
// ...
const clientId="";
const appName="";
const apiKey="";
const isDev: boolean=false;
const imageBase64 = "";
const threshold = 85; // Ranges from 0-100. Value can be null or undefined so default can be used
const timeoutDurationInSec = 120; // Custom timeout you want SDK to timeout. Integer only, Can be null or undefined, defaults to 120s
let startFacialComparison = () => {
startFacialComparisonSDK(clientId, appName, apiKey, isDev, imageBase64, LivenessType.motional, threshold, timeoutDurationInSec, (responseJson: any) => {
console.log(responseJson);
});
}
let startLivenessDetectionOnly = () => {
startLivenessDetectionOnlySDK(clientId, appName, apiKey, isDev, LivenessType.still, timeoutDurationInSec, (responseJson: any) => {
console.log(responseJson);
});
}
Android Setup
Android
Step 1
Create a [github.properties] file in root of android folder and put below into content. E.g. "myReactApp/android/github.properties" Replace values with your github credentials from github and make sure to grant necessary permissions especially for github packages
USERNAME_GITHUB=SampleUsername
TOKEN_GITHUB=SampleClassicToken
Step 2
Add below to project level gradle file /android/build.gradle
buildscript {
ext.kotlin_version = '1.9.+'
...
dependencies {
classpath 'com.android.tools.build:gradle:7.3.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
def githubPropertiesFile = rootProject.file("github.properties")
def githubProperties = new Properties()
githubProperties.load(new FileInputStream(githubPropertiesFile))
repositories {
maven {
name "GitHubPackages"
url 'https://maven.pkg.github.com/Blusalt-FS/Liveness-Only-Android-Package'
credentials {
username githubProperties['USERNAME_GITHUB']
password githubProperties['TOKEN_GITHUB']
}
}
}
}
Step 3
Change the minimum Android sdk version to 24 (or higher) in your /android/app/build.gradle
file.
android {
...
defaultConfig {
...
minSdkVersion 24
}
...
}
Step 4
If you're experiencing crashes or timeouts.
Add below to your progaurd.pro file if using progaurd or minify is enabled /android/app/proguard-rules.pro
-keep public class com.megvii.**{*;}
-keep class net.blusalt.liveness_native.** { *; }
Enable proguard in /android/app/build.gradle
file like below.
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
...
}
IOS Setup
Add below to your info.plist file to request camera permission /ios/${AppFolder}/info.plist
<key>NSCameraUsageDescription</key>
<string>Blusalt Reactnative Liveness requires camera for liveness</string>
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library