> For the complete documentation index, see [llms.txt](https://docs.1kosmos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1kosmos.com/mobile-sdk/react-native-integration-guide.md).

# React Native Integration Guide

### Overview&#x20;

The react-native-blockidplugin is a wrapper for the native BlockID SDKs on iOS and Android, designed to simplify API access for React Native projects. This plugin allows you to interact with the native BlockID SDKs on both iOS and Android platforms using React Native code.

The BlockID SDK is a cross-platform dependency compatible with both Android and iOS. You can integrate it into native Android applications using Gradle, while iOS applications can incorporate it using CocoaPods.

Here are the key features of the BlockID SDK:

* **One-Time Passcode**: Generate a one-time passcode displayed in a mobile app, adding an extra layer of Multi-Factor Authentication (MFA).
* **ID Card Verification**: Scan, extract, and verify ID cards from a specified list of countries.
* **Driver’s License Verification**: Scan, extract, and verify driver’s licenses from a specified list of countries.
* **Passport Verification**: Scan, extract, and verify passports from a specified list of countries.
* **Live ID Enrollment**: Allow users to enroll their face for liveness detection.
* **Live ID Verification**: Prompt users to verify their face against a previously enrolled image for identity confirmation.
* **Passwordless Login**: Use a QR code to approve secure login on a trusted device.
* **Enroll TouchID / FaceID**: Leverage the native biometric of the device to unlock the application.
* **License Key Management**: Use a license key to manage the blockidplugin efficiently.

Starting with Release v1.10.70, the BlockID SDK has been integrated with the React Native framework through a plugin/bridge. This plugin serves as a wrapper for the native BlockID SDKs on iOS and Android, facilitating interaction with the SDKs across both platforms so that the BlockID services can be seamlessly used on Android/iOS applications built with React Native.

### System Requirements

Before getting started, make sure you meet the following prerequisites:

* React Native >= 0.75.0 (plugin uses TurboModules and SPM support introduced in 0.75)
* Node.js >= v22.16.0
* Yarn package manager
* Xcode (with command-line tools configured in shell profile)
* Android Studio (with SDK paths configured in shell profile)
* Android API Level 28 / Android OS 9 or higher
* iOS 16.0 or higher
* Java 17
* Gradle 8.14.1
* Android Gradle Plugin (AGP) 8.8.0
* Kotlin 2.3.0

### Installing React Native

To install react native, follow these steps:

1. Make sure you have Node (v22.16.0) installed on your system. If not, download Node.js from the following:<br>

   ```
   https://nodejs.org/en/download/package-manager
   ```
2. Use the following command to install react native.

   ```
   npm install -g react-native-cli
   ```
3. Make sure that Xcode is set up in your bash/zsh profile on Mac, and Android Studio is configured in your profile on Windows.
4. As dependencies are managed via yarn, use the following command to install yarn.

   ```
   npm install --global yarn
   ```

### Integrating react-native-blockidplugin with React Native Project

To integrate react native into your project, follow these steps:

1. Use one of the following commands to create your React Native project.

   ```
   npx react-native init MyProject
   ```

&#x20; or &#x20;

```
npx @react-native-community/cli@latest init MyProject
```

2. Run the yarn command in the project root folder.

   ```
   yarn
   ```
3. Install the react-native BlockID package as a git dependency. The plugin is distributed as an npm package on the 1Kosmos private registry.<br>

   Step 3.1 — Get the read token

   The 1Kosmos mobile team shares the token securely. Contact your 1Kosmos representative if you don't have one.

   \
   **CAUTION:** Do NOT commit this token to source control. Keep it as an environment variable or in a git-ignored .npmrc.<br>

   Step 3.2 — Set the token in your terminal

   \
   In case of macOS / Linux:<br>

   ```
   export NPM_READ_TOKEN="<paste npm-read-token here>"
   ```

   \
   In case of Windows PowerShell:<br>

   ```
   $env:NPM_READ_TOKEN="<paste npm-read-token here>"` 
   ```

   \
   To verify it's set in macOS/Linux, run `echo "length: ${#NPM_READ_TOKEN}"` To verify if it's set in Windows PowerShell, `$env:NPM_READ_TOKEN.Length`

   Both should print a number > 0.<br>

   Step 3.3 — Create .npmrc in your project root

   Create a file called .npmrc at the root of your React Native project (next to package.json):<br>

   For macOS or Linux, run the following command:

   ```
   cat > .npmrc <<'EOF' 
   @1kosmos:registry=https://artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/ 
   //artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/:_authToken=${NPM_READ_TOKEN} 
   //artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/:always-auth=true 
   EOF 

   ```

   \
   For Windows PowerShell, run the following dependencies:

   ```
   @" 
   @1kosmos:registry=https://artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/ 
   //artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/:_authToken=${NPM_READ_TOKEN} 
   //artifactory.1kosmos.net/artifactory/api/npm/react-native-blockidplugin-local/:always-auth=true 
   "@ | Set-Content -Path .npmrc -Encoding utf8 

   ```

   \
   This routes only @1kosmos/\* packages to the private registry. All other dependencies resolve from public npm.<br>

   **Note:** Add .npmrc to your .gitignore so the token is never committed.

   Step 3.4 — Install the package

   ```
   yarn add @1kosmos/react-native-blockidplugin 
   ```

   or with npm:

   ```
   npm install @1kosmos/react-native-blockidplugin
   ```

   Step 3.5 — Verify installation

   ```
   npm list @1kosmos/react-native-blockidplugin
   ```

   \
   Executing the above must show the installed version (e.g., @1kosmos/react-native-blockidplugin\@1.30.60).

{% hint style="info" %}
**Note:**

* The read token is session-only — close the terminal, and it's gone. Re-export next time.
* .npmrc must be in the same directory where you run npm install / yarn add.
* Only the @1kosmos scope routes to JFrog; everything else resolves from public npm.
  {% endhint %}

### Managing Configurations in iOS/Android Platforms

To use Android/iOS React Native applications, you must configure specific dependencies into your React Native project's Android/iOS directories.

#### Configuring iOS Directory

The BlockID SDK (1.30.40+) is distributed via SPM only. The plugin's podspec uses spm\_dependency (available since React Native 0.75) to resolve the SDK. This requires dynamic framework linkage in the consuming app's Podfile. Make the following changes to the `Podfile` in the iOS directory of your React Native project.

{% hint style="info" %}
**Note:**

Check if you already have a `Podfile` in the `iOS` directory. If not, run the `pod init`command in the terminal. This command will initialize a Podfile for your project.
{% endhint %}

1. Open the `Podfile` in the text editor of your choice.
2. Make the following change to the `Podfile`.

```
  platform :ios, '16.0' 
prepare_react_native_project! 
 
# BlockID SDK (1.30.40+) is distributed via SPM only. 
# spm_dependency in the plugin podspec requires dynamic frameworks. 
use_frameworks! :linkage => :dynamic 
 
target 'YourAppName' do 
  config = use_native_modules! 
 
  use_react_native!( 
    :path => config[:reactNativePath], 
    :hermes_enabled => true, 
    :fabric_enabled => true, 
    :app_path => "#{Pod::Config.instance.installation_root}/.." 
  ) 
 
  post_install do |installer| 
    react_native_post_install( 
      installer, 
      config[:reactNativePath], 
      :mac_catalyst_enabled => false, 
    ) 
 
    installer.pods_project.targets.each do |target| 
      target.build_configurations.each do |config| 
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' 
        xcconfig_path = config.base_configuration_reference.real_path 
        xcconfig = File.read(xcconfig_path) 
        xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR") 
        File.open(xcconfig_path, "w") { |file| file << xcconfig_mod } 
      end 
    end 
  end 
end
 
```

3. Then, inside the iOS folder, run the following commands:

   ```
   bundle install    # only one time in your project 
   bundle exec pod install 
   ```
4. Info.plist Permissions

Add the following permissions to your Info.plist:

```
NSCameraUsageDescription` 
NSFaceIDUsageDescription` 

```

### Configuring Android Directory

To configure the files inside the Android directory of your react-native project, follow these steps:

**Step 1**: Navigate to the **build.gradle** file in your react-native project and make the following changes.

```
  buildscript { 
    ext { 
        buildToolsVersion = "36.0.0" 
        minSdkVersion = 28 
        compileSdkVersion = 36 
        targetSdkVersion = 36 
        ndkVersion = "27.1.12297006" 
        kotlinVersion = "2.3.0" 
        agp_version = '8.8.0' 
    } 
    repositories { 
        google() 
        mavenCentral() 
    } 
    dependencies { 
        classpath "com.android.tools.build:gradle:$agp_version" 
        classpath("com.facebook.react:react-native-gradle-plugin") 
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") 
    } 
} 
 
allprojects { 
    repositories { 
        google() 
        mavenCentral() 
        gradlePluginPortal() 
        maven { 
            url 'https://artifactory.1kosmos.net/artifactory/maven-releases-local/' 
            credentials { 
                username = 'developer' 
                password = 'xK9#mPw2$vLq7nBz!' 
 
            } 
        } 
        maven { url "https://jitpack.io" } 
    } 
} 
 
tasks.withType(JavaCompile).configureEach { 
    options.release = 17 
} 

```

**Step 2**: Modify the gradle-wrapper.properties file

Your grade version must be 8.14.1.

```
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip

```

**Step 3**: Modify the Gradle build configurations inside android/app folder.

```
1. Specify the `minSdkVersion` property as 28 (set via rootProject.ext.minSdkVersion from root build.gradle). 
2. Add the following packaging options inside the **Android** section.
   
```

```
     android { 
  packaging { 
      resources { 
          excludes += [ 
              'META-INF/rxjava.properties', 
              'META-INF/INDEX.LIST', 
              'META-INF/LICENSE', 
              'META-INF/LICENSE.txt', 
              'META-INF/LICENSE.md', 
              'META-INF/NOTICE', 
              'META-INF/NOTICE.txt', 
              'META-INF/NOTICE.md', 
              'META-INF/DEPENDENCIES', 
              'META-INF/FastDoubleParser-LICENSE', 
              'META-INF/DISCLAIMER', 
              'META-INF/versions/9/OSGI-INF/MANIFEST.MF', 
              'META-INF/io.netty.versions.properties', 
              'lib/x86_64/darwin/libscrypt.dylib', 
              'lib/x86_64/freebsd/libscrypt.so', 
              'lib/x86_64/linux/libscrypt.so', 
              'AndroidManifest.xml' 
          ] 
          pickFirsts += [ 
              'META-INF/FastDoubleParser-NOTICE', 
              'META-INF/bigint-NOTICE' 
          ] 
      } 
  } 
} 
```

```
3. Add the following configurations to the root level of the build.gradle file.
```

```
     configurations.configureEach { 
 resolutionStrategy.eachDependency { DependencyResolveDetails details -> 
     if (details.requested.group == 'org.bouncycastle') { 
         details.useVersion '1.84' 
     } 
  } 
 } 
```

**Step 4**: Navigate to **AndroidManifest.xml** file under android/app/src/main add tools:replace="android:allowBackup,android:label,android:theme" as shown below.

```
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.CAMERA"/> 
    <application 
        android:label="appname" 
        android:icon="@mipmap/ic_launcher" 
        android:theme="@style/AppTheme" 
        android:allowBackup="true" 
        tools:replace="android:allowBackup,android:theme,android:label"/> 
</manifest> 
```

#### Importing react-native blockID plugin to your Project

Run the following command to import the react-native-blockidplugin into your React Native project.

```
import { setLicenseKey } from '@1kosmos/react-native-blockidplugin';
```

**Sample**

```
setLicenseKey('YOUR_LICENSE_KEY').then((result) => {
      console.log('Success: ', result);
    });
```

### Managing Functionalities in the Sample Project

After creating the sample project, the following BlockID app functionalities can be explored in the React Native Android/iOS applications:

* [SDK Setup functions](#sdk-setup-functions)
* [Get DID](#get-did)
* [Get Version](#get-version)
* [Biometric Enrollment](#biometric-details)
* [Create a one-time passcode](#one-time-passcode)
* [LiveID Enrollment](#liveid-enrollment)
* [LiveID Verification](#liveid-enrollment)
* [Document Enrollment](#document-enrollment)
* [Login with a QR Code](#qr-scanning)
* [Locking and Unlocking SDK](#locking-and-unlocking-sdk)
* [Resetting SDK](#resetting-sdk)

#### SDK Setup Functions

You can set up an SDK to manage the license key, wallet, and tenant. The following table provides information on various SDK functions:

| Function          | Description                           | Container                                                                                                  |
| ----------------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| Set License Key   | Set the license key to set up the SDK | `let result = await setLicenseKey(const_licenseKey);`                                                      |
| Initialize Wallet | Create a wallet for the application   | `let result = await initiateTempWallet();`                                                                 |
| Register Tenant   | Register the tenant with the SDK      | `let result = await registerTenant( <br /> const_tag, <br /> const_community, <br /> const_dns, <br /> );` |

#### Get DID

To retrieve the unique Distributed IDentifier (DID), run the following command. Its response is displayed as a String.

```
let result = await getDID();
```

#### Get Version

To retrieve the version of the currently used BlockID SDK, run the following command.

```
let result = await blockIDSDKVersion();
```

#### Biometric Details

Use this functionality to scan your biometric data, unlock the BlockID SDK, and access its functionality.

To enroll a biometric, run the following command:

```
let result = await enrollDeviceAuth(); 
```

To verify if any biometric data has already been enrolled, run the following command:

```
let result = await verifyDeviceAuth();  
```

To check if the biometric has been registered, run the following command:

```
let result = await isDeviceAuthRegistered(); 
```

The result will be a boolean value indicating whether biometric data is registered or not.

#### One-time passcode

Obtain the time-based OTP from the blockidplugin by running the following command:

```
let result = await totp();
```

Its response will be of the type TOTP and provide the following objects:

| Parameter        | Description                                                                                                     |
| ---------------- | --------------------------------------------------------------------------------------------------------------- |
| totp             | String: Displays a time-based one-time password (OTP).                                                          |
| getRemainingSecs | <p>Int: Displays the time after which the OTP expires.<br>The default expiry time of the OTP is 30 seconds.</p> |

#### LiveID Enrollment

You can perform the following functions during the enrollment of liveID:

a. **Enroll LiveID** – Use the following command to enroll the liveid.

```
await enrollLiveIDScanning( 
  const_dvcID,              // dvcID string 
  random_UUID,              // mobileSessionID (optional, pass null to omit) 
  "liveid_" + random_UUID   // mobileDocumentID (optional, pass null to omit) 
); 

```

**Method Summary**

| Parameter        | Description                  |
| ---------------- | ---------------------------- |
| dvcID            | (Optional) String: DvcID     |
| mobileSessionId  | (Optional)String: random ID  |
| mobileDocumentId | (Optional) String: random ID |

b. **Verify Enrolled LiveID** – Use the following command to verify the enrolled liveID.

```
await verifyLiveIDScanning( 
  const_dvcID,              // dvcID string 
  random_UUID,              // mobileSessionID (optional, pass null to omit) 
  "liveid_" + random_UUID   // mobileDocumentID (optional, pass null to omit) 
); 
```

**Method Summary**

| Parameter        | Description                  |
| ---------------- | ---------------------------- |
| dvcID            | (Optional) String: DvcID     |
| mobileSessionId  | (Optional) String: random ID |
| mobileDocumentId | (Optional) String: random ID |

c. **Verify Face with Liveness** - Use the following command to perform the face liveness check.

```
await verifyFaceWithLiveness( 
  const_dvcID,              // dvcID string 
  random_UUID,              // mobileSessionID (optional, pass null to omit) 
  "liveid_" + random_UUID   // mobileDocumentID (optional, pass null to omit) 
);   
```

| Parameter        | Description                  |
| ---------------- | ---------------------------- |
| dvcID            | (Optional) String: DvcID     |
| mobileSessionId  | (Optional) String: random ID |
| mobileDocumentId | (Optional) String: random ID |

d. **Check if LiveID is registered** – Use the following sample command to check if the liveID has been registered.

```
let result = await isLiveIDRegisterd();
```

The status is a boolean value indicating whether the LiveID is registered.

e. **Stop LiveID Scanning** – Use the following sample command to stop the liveID scanning process.

```
await stopLiveIDScanning();
```

The status is a boolean value indicating whether scanning has stopped.

f. **LiveID Scanning responses** – Displays the responses of the liveID scanning.

| LiveID Status            | Description                                                                                                                                                                                                          |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| FocusOnFaceChanged       | When the user’s face focus changes within the scanner focus area.                                                                                                                                                    |
| faceLivenessCheckStarted | When the LiveID scanner started the liveness check.                                                                                                                                                                  |
| completed                | When the LiveID Scanning is completed.                                                                                                                                                                               |
| failed                   | <p>When the LiveID Scanning fails. This will give the error object as follows:<br><strong>Error</strong>: ErrorResponse which will have the code.<br><strong>Error Code Description</strong>: Error Description.</p> |

#### Document Enrollment

Use this functionality to enroll different types of documents, such as Driver’s Licenses, Passports, and National IDs.

a. **Scanning document** – Use the following command to scan the document.

```
let documentStr = await scanDocument(type);
```

The documentStr will provide a JSON string containing document information. type is a number corresponding to:

* 0 — National ID
* 1 — Driver License
* 2 — Passport

b. **Registering Document** – Use the following sample command to register the document.

```
// Register Driver's License with LiveID 
let response = await registerDrivingLicenceWithLiveID( 
  Object.fromEntries(idCardEntries), 
  face, 
  proofedBy, 
  randomUUID, 
  "dl_with_liveid_" + randomUUID 
); 
 
// Register Passport with LiveID 
let response = await registerPassportWithLiveID( 
  Object.fromEntries(idCardEntries), 
  face, 
  proofedBy, 
  randomUUID, 
  "ppt_with_liveid_" + randomUUID 
); 
 
// Register National ID with LiveID 
let response = await registerNationalIDWithLiveID( 
  Object.fromEntries(idCardEntries), 
  face, 
  proofedBy, 
  randomUUID, 
  "nationalid_with_liveid_" + randomUUID 
);  
```

**Method Summary**

| Parameter        | Description                                                                                                                              |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| data             | data object received after scanning the document                                                                                         |
| face             | string: face object in the string format                                                                                                 |
| proofedBy        | string: This identifies the entity responsible for proofing the document. When you use BlockID SDK Scanners, this defaults to “blockid”. |
| mobileSessionId  | (Optional) String: random ID                                                                                                             |
| mobileDocumentId | (Optional) String: random ID                                                                                                             |

#### QR Scanning

The following functions help with QR scanning.

a. **Start Scan** - To start the scanning process, use the following command:

```
let qrDataString = await startQRScanning();
```

**Method Summary**

| Parameter | Description                          |
| --------- | ------------------------------------ |
| return    | qrDataString: Scanned data as String |

b. **Stop Scan** - To stop the scanning process, use the following command:

```
await stopQRScanning();
```

**Method Summary**

| Parameter | Description                                                      |
| --------- | ---------------------------------------------------------------- |
| return    | Boolean: It will return true if the scanning process is stopped. |

#### Locking and Unlocking SDK&#x20;

The SDK's lock and unlock functionality controls feature access, ensuring SDK capabilities are accessible only when explicitly unlocked.

By default, the BlockID SDK is locked. To access its functionalities, you must first unlock the SDK. You can unlock it using one of the following methods:

To lock the SDK, run the following command:

```
await lockSDK();
```

To unlock the SDK, run the following command:

```
await unLockSDK();
```

#### Resetting SDK

Use this function to purge the SDK wallet and remove all data stored or owned by the SDK.

To reset the SDK, run the following sample command:

```
await resetSDK(
      AppConstants.tag,
      AppConstants.community,
      AppConstants.dns,
      AppConstants.licenseKey,
      'Resetting'
    );
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1kosmos.com/mobile-sdk/react-native-integration-guide.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
