react-native-mdl-verification 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/PUBLISHING.md ADDED
@@ -0,0 +1,143 @@
1
+ # Publishing to NPM
2
+
3
+ Follow these steps to publish your `react-native-mdl-verification` package to npm:
4
+
5
+ ## Prerequisites
6
+
7
+ 1. **NPM Account**: Create an account at [npmjs.com](https://www.npmjs.com/) if you don't have one
8
+ 2. **Login to NPM**: Run `npm login` in your terminal and enter your credentials
9
+
10
+ ## Pre-Publishing Checklist
11
+
12
+ 1. **Update package.json**: Make sure all fields are correct
13
+ - `name`: Should be unique on npm (check availability at npmjs.com)
14
+ - `version`: Start with `1.0.0` for first release
15
+ - `description`: Clear description of what the package does
16
+ - `author`: Your name or organization
17
+ - `repository`: Your git repository URL
18
+ - `license`: Typically MIT
19
+
20
+ 2. **Verify AAR files are included**:
21
+ ```bash
22
+ ls android/libs/
23
+ ```
24
+ Should show:
25
+ - `checkmdl-mvalid-sdk-1.6.0-release.aar`
26
+ - `mvalid-sdk-1.6.0-SNAPSHOT.aar`
27
+
28
+ 3. **Test the package locally** (optional but recommended):
29
+ ```bash
30
+ npm pack
31
+ ```
32
+ This creates a `.tgz` file you can test in another project:
33
+ ```bash
34
+ npm install /path/to/react-native-mdl-verification-1.0.0.tgz
35
+ ```
36
+
37
+ ## Publishing Steps
38
+
39
+ ### 1. Navigate to package directory
40
+ ```bash
41
+ cd C:\src_send\projects\react-native\react-native-mdl-verification
42
+ ```
43
+
44
+ ### 2. Review what will be published
45
+ ```bash
46
+ npm pack --dry-run
47
+ ```
48
+ This shows all files that will be included in the package.
49
+
50
+ ### 3. Publish to npm
51
+ ```bash
52
+ npm publish
53
+ ```
54
+
55
+ If your package name is scoped (e.g., `@yourorg/react-native-mdl-verification`), use:
56
+ ```bash
57
+ npm publish --access public
58
+ ```
59
+
60
+ ## After Publishing
61
+
62
+ ### Update version for future releases
63
+ Follow [Semantic Versioning](https://semver.org/):
64
+ - **Patch** (1.0.1): Bug fixes - `npm version patch`
65
+ - **Minor** (1.1.0): New features (backwards compatible) - `npm version minor`
66
+ - **Major** (2.0.0): Breaking changes - `npm version major`
67
+
68
+ Then publish again:
69
+ ```bash
70
+ npm publish
71
+ ```
72
+
73
+ ## Using the Published Package
74
+
75
+ In your React Native project:
76
+
77
+ ```bash
78
+ npm install react-native-mdl-verification
79
+ # or
80
+ yarn add react-native-mdl-verification
81
+ ```
82
+
83
+ For React Native 0.60+, the package will auto-link.
84
+
85
+ ## Alternative: Private NPM Registry
86
+
87
+ If you want to keep the package private:
88
+
89
+ ### Option 1: NPM Private Packages (Paid)
90
+ ```bash
91
+ npm publish --access restricted
92
+ ```
93
+
94
+ ### Option 2: GitHub Packages
95
+ 1. Update package.json:
96
+ ```json
97
+ {
98
+ "name": "@yourusername/react-native-mdl-verification",
99
+ "publishConfig": {
100
+ "registry": "https://npm.pkg.github.com"
101
+ }
102
+ }
103
+ ```
104
+
105
+ 2. Authenticate with GitHub:
106
+ ```bash
107
+ npm login --registry=https://npm.pkg.github.com
108
+ ```
109
+
110
+ 3. Publish:
111
+ ```bash
112
+ npm publish
113
+ ```
114
+
115
+ ### Option 3: Local/File-based Install
116
+ Instead of publishing, use a local path or git URL:
117
+ ```bash
118
+ npm install /path/to/react-native-mdl-verification
119
+ # or
120
+ npm install git+https://github.com/yourusername/react-native-mdl-verification.git
121
+ ```
122
+
123
+ ## Troubleshooting
124
+
125
+ ### Error: Package name already exists
126
+ - Choose a different name in package.json
127
+ - Or use a scoped package: `@yourorg/react-native-mdl-verification`
128
+
129
+ ### Error: Not logged in
130
+ ```bash
131
+ npm login
132
+ ```
133
+
134
+ ### Error: Access denied
135
+ Make sure you have permission to publish under that package name.
136
+
137
+ ## Documentation
138
+
139
+ After publishing, your package will be available at:
140
+ - https://www.npmjs.com/package/react-native-mdl-verification
141
+ - Can be installed with: `npm install react-native-mdl-verification`
142
+
143
+ The README.md will be displayed on the npm package page automatically.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # react-native-mdl-verification
2
+
3
+ React Native bridge for MDL (Mobile Driver's License) verification using CheckMDL SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install react-native-mdl-verification
9
+ # or
10
+ yarn add react-native-mdl-verification
11
+ ```
12
+
13
+ ### Android Setup
14
+
15
+ The package includes the required AAR files for the CheckMDL SDK. No additional manual linking is needed for React Native 0.60+.
16
+
17
+ #### Required Permissions
18
+
19
+ Add the following permissions to your `android/app/src/main/AndroidManifest.xml`:
20
+
21
+ ```xml
22
+ <uses-permission android:name="android.permission.INTERNET" />
23
+ <uses-permission android:name="android.permission.BLUETOOTH" />
24
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
25
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
26
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
27
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
28
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
29
+ <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Initialize the SDK
35
+
36
+ ```javascript
37
+ import MdlVerification from 'react-native-mdl-verification';
38
+
39
+ // Initialize with your license key
40
+ await MdlVerification.initialize('YOUR_LICENSE_KEY');
41
+ ```
42
+
43
+ ### Start Verification
44
+
45
+ ```javascript
46
+ try {
47
+ const result = await MdlVerification.startVerification({
48
+ stan: '000001',
49
+ terminalId: 'TERMINAL_001',
50
+ merchantId: 'MERCHANT_001'
51
+ });
52
+
53
+ if (result.isSuccessful) {
54
+ console.log('Verification successful!');
55
+ console.log('MDL Token:', result.mdlToken);
56
+ console.log('Document Type:', result.docType);
57
+ console.log('Document Valid:', result.docValid);
58
+ } else {
59
+ console.log('Verification failed:', result.successMesg);
60
+ }
61
+ } catch (error) {
62
+ console.error('Verification error:', error);
63
+ }
64
+ ```
65
+
66
+ ### Get Detailed Verification Data
67
+
68
+ ```javascript
69
+ try {
70
+ const detailedData = await MdlVerification.getDetailedVerificationData(mdlToken);
71
+ console.log('Detailed data:', detailedData);
72
+ } catch (error) {
73
+ console.error('Error getting detailed data:', error);
74
+ }
75
+ ```
76
+
77
+ ### Listen to Verification Events
78
+
79
+ ```javascript
80
+ // Listen for progress updates
81
+ const progressListener = MdlVerification.addListener(
82
+ MdlVerification.Events.VERIFICATION_PROGRESS,
83
+ (progress) => {
84
+ console.log('Progress:', progress.status);
85
+ console.log('Log:', progress.logData);
86
+ }
87
+ );
88
+
89
+ // Listen for completion
90
+ const completeListener = MdlVerification.addListener(
91
+ MdlVerification.Events.VERIFICATION_COMPLETE,
92
+ (result) => {
93
+ console.log('Verification complete:', result);
94
+ }
95
+ );
96
+
97
+ // Clean up listeners when done
98
+ progressListener.remove();
99
+ completeListener.remove();
100
+
101
+ // Or remove all listeners for an event
102
+ MdlVerification.removeAllListeners(MdlVerification.Events.VERIFICATION_PROGRESS);
103
+ ```
104
+
105
+ ## API
106
+
107
+ ### Methods
108
+
109
+ #### `initialize(licenseKey: string): Promise<void>`
110
+
111
+ Initialize the MDL verification SDK with your license key.
112
+
113
+ #### `startVerification(options: VerificationOptions): Promise<VerificationResponse>`
114
+
115
+ Start the MDL verification process.
116
+
117
+ **Options:**
118
+ - `stan` (string): Station number
119
+ - `terminalId` (string): Terminal ID
120
+ - `merchantId` (string): Merchant ID
121
+
122
+ **Returns:** `VerificationResponse` object
123
+
124
+ #### `getDetailedVerificationData(mdlToken: string): Promise<DetailedVerificationData>`
125
+
126
+ Get detailed verification data using the MDL token from the verification response.
127
+
128
+ #### `addListener(eventName: string, listener: Function): Subscription`
129
+
130
+ Add an event listener for verification events.
131
+
132
+ **Events:**
133
+ - `MdlVerification.Events.VERIFICATION_PROGRESS` - Progress updates during verification
134
+ - `MdlVerification.Events.VERIFICATION_COMPLETE` - Verification completed
135
+
136
+ ### Types
137
+
138
+ #### `VerificationResponse`
139
+
140
+ ```typescript
141
+ interface VerificationResponse {
142
+ command?: string;
143
+ stan?: string;
144
+ terminalId?: string;
145
+ merchantId?: string;
146
+ success?: string;
147
+ successMesg?: string;
148
+ status?: number;
149
+ mdlToken?: string;
150
+ docType?: string;
151
+ docValid?: string;
152
+ authMethod?: string;
153
+ authSuccess?: string;
154
+ msoValid?: string;
155
+ cert?: string;
156
+ ica_cert?: string;
157
+ isSuccessful?: boolean;
158
+ }
159
+ ```
160
+
161
+ #### `ProgressResponse`
162
+
163
+ ```typescript
164
+ interface ProgressResponse {
165
+ command?: string;
166
+ status?: string;
167
+ logData?: string;
168
+ logLevel?: string;
169
+ }
170
+ ```
171
+
172
+ ## License
173
+
174
+ MIT
175
+
176
+ ## Support
177
+
178
+ For issues and questions, please visit the [GitHub repository](https://github.com/yourusername/react-native-mdl-verification).
@@ -0,0 +1,97 @@
1
+ buildscript {
2
+ ext.kotlin_version = '1.9.22'
3
+
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+
9
+ dependencies {
10
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
11
+ }
12
+ }
13
+
14
+ apply plugin: 'com.android.library'
15
+ apply plugin: 'kotlin-android'
16
+
17
+ def safeExtGet(prop, fallback) {
18
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19
+ }
20
+
21
+ android {
22
+ compileSdkVersion safeExtGet('compileSdkVersion', 34)
23
+ buildToolsVersion safeExtGet('buildToolsVersion', '34.0.0')
24
+
25
+ namespace "com.mdlverification"
26
+
27
+ defaultConfig {
28
+ minSdkVersion safeExtGet('minSdkVersion', 26)
29
+ targetSdkVersion safeExtGet('targetSdkVersion', 34)
30
+ versionCode 1
31
+ versionName "1.0.0"
32
+ }
33
+
34
+ buildTypes {
35
+ release {
36
+ minifyEnabled false
37
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38
+ }
39
+ }
40
+
41
+ compileOptions {
42
+ sourceCompatibility JavaVersion.VERSION_17
43
+ targetCompatibility JavaVersion.VERSION_17
44
+ }
45
+
46
+ kotlinOptions {
47
+ jvmTarget = '17'
48
+ }
49
+ }
50
+
51
+ repositories {
52
+ google()
53
+ mavenCentral()
54
+ flatDir {
55
+ dirs 'libs'
56
+ }
57
+ }
58
+
59
+ dependencies {
60
+ // React Native
61
+ implementation 'com.facebook.react:react-native:+'
62
+
63
+ // Material Components required by checkmdl-verifier
64
+ implementation "com.google.android.material:material:1.11.0"
65
+
66
+ // AndroidX ViewModel dependencies required by checkmdl SDK
67
+ implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
68
+ implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
69
+ implementation "androidx.activity:activity-ktx:1.8.2"
70
+ implementation "androidx.core:core-ktx:1.12.0"
71
+ implementation "androidx.appcompat:appcompat:1.6.1"
72
+
73
+ // Compose dependencies required by checkmdl SDK
74
+ implementation platform("androidx.compose:compose-bom:2024.02.00")
75
+ implementation "androidx.activity:activity-compose:1.8.2"
76
+ implementation "androidx.compose.ui:ui"
77
+ implementation "androidx.compose.material:material"
78
+
79
+ // Additional dependencies required by mvalid SDK
80
+ implementation "com.google.code.gson:gson:2.10.1"
81
+ implementation "com.upokecenter:cbor:4.5.2"
82
+ implementation "commons-codec:commons-codec:1.15"
83
+ implementation "org.bouncycastle:bcprov-jdk15on:1.70"
84
+ implementation "org.bouncycastle:bcpkix-jdk15on:1.70"
85
+ implementation "com.nimbusds:nimbus-jose-jwt:9.31"
86
+ implementation "org.apache.commons:commons-lang3:3.12.0"
87
+
88
+ // Ktor dependencies
89
+ implementation "io.ktor:ktor-client-core:2.3.8"
90
+ implementation "io.ktor:ktor-client-android:2.3.8"
91
+ implementation "io.ktor:ktor-client-content-negotiation:2.3.8"
92
+ implementation "io.ktor:ktor-serialization-gson:2.3.8"
93
+
94
+ // CheckMDL SDK (AAR files)
95
+ implementation(name: 'checkmdl-mvalid-sdk-1.6.0-release', ext: 'aar')
96
+ implementation(name: 'mvalid-sdk-1.6.0-SNAPSHOT', ext: 'aar')
97
+ }
@@ -0,0 +1,16 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # Keep CheckMDL SDK classes
9
+ -keep class com.checkmdl.mdlvalid.sdk.** { *; }
10
+ -keep class com.scytales.mvalid.sdk.** { *; }
11
+
12
+ # Keep React Native classes
13
+ -keep class com.facebook.react.** { *; }
14
+
15
+ # Keep module classes
16
+ -keep class com.mdlverification.** { *; }
@@ -0,0 +1,13 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+ <uses-permission android:name="android.permission.INTERNET" />
4
+ <uses-permission android:name="android.permission.BLUETOOTH" />
5
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
6
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
7
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
8
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
9
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
10
+
11
+ <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
12
+
13
+ </manifest>
@@ -0,0 +1,214 @@
1
+ package com.mdlverification
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.WritableMap
9
+ import com.facebook.react.bridge.WritableArray
10
+ import com.facebook.react.bridge.Arguments
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule
12
+ import android.util.Log
13
+ import com.checkmdl.mdlvalid.sdk.*
14
+ import com.scytales.mvalid.sdk.*
15
+ import androidx.activity.ComponentActivity
16
+
17
+ class MdlVerificationBridge(reactContext: ReactApplicationContext) :
18
+ ReactContextBaseJavaModule(reactContext) {
19
+ private lateinit var coordinator: MdlVerificationCoordinator
20
+
21
+ companion object {
22
+ private const val TAG = "MdlVerificationBridge"
23
+ }
24
+
25
+ override fun getName(): String {
26
+ return "MdlVerification"
27
+ }
28
+
29
+ private fun sendEvent(eventName: String, params: WritableMap?) {
30
+ reactApplicationContext
31
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
32
+ .emit(eventName, params)
33
+ }
34
+
35
+ private fun convertVerificationResponseToWritableMap(response: VerificationResponse): WritableMap {
36
+ val map = Arguments.createMap()
37
+
38
+ try {
39
+ map.putString("command", response.command ?: "")
40
+ map.putString("stan", response.stan ?: "")
41
+ map.putString("terminalId", response.terminalId ?: "")
42
+ map.putString("merchantId", response.merchantId ?: "")
43
+ map.putString("success", response.success ?: "")
44
+ map.putString("successMesg", response.successMesg ?: "")
45
+ map.putInt("status", response.status ?: 0)
46
+ map.putString("mdlToken", response.mdlToken ?: "")
47
+ map.putString("docType", response.docType ?: "")
48
+ map.putString("docValid", response.docValid ?: "")
49
+ map.putString("authMethod", response.authMethod ?: "")
50
+ map.putString("authSuccess", response.authSuccess ?: "")
51
+ map.putString("msoValid", response.msoValid ?: "")
52
+ map.putString("cert", response.cert ?: "")
53
+ map.putString("ica_cert", response.ica_cert ?: "")
54
+
55
+ // Add convenience boolean for easy checking
56
+ map.putBoolean("isSuccessful", response.success == "Y")
57
+
58
+ } catch (e: Exception) {
59
+ Log.e(TAG, "Error converting VerificationResponse to WritableMap: ${e.message}", e)
60
+ map.putString("error", "Error processing verification response")
61
+ }
62
+
63
+ return map
64
+ }
65
+
66
+ private fun convertProgressResponseToWritableMap(progress: ProgressResponse): WritableMap {
67
+ val map = Arguments.createMap()
68
+
69
+ try {
70
+ map.putString("command", progress.command ?: "")
71
+ map.putString("status", progress.status ?: "")
72
+ map.putString("logData", progress.logData ?: "")
73
+ map.putString("logLevel", progress.logLevel ?: "")
74
+
75
+ } catch (e: Exception) {
76
+ Log.e(TAG, "Error converting ProgressResponse to WritableMap: ${e.message}", e)
77
+ map.putString("error", "Error processing progress response")
78
+ }
79
+
80
+ return map
81
+ }
82
+
83
+ @ReactMethod
84
+ fun initialize(licenseKey: String, promise: Promise) {
85
+ try {
86
+ Log.d(TAG, "Initializing SDK with license key: $licenseKey")
87
+
88
+ // Get the current activity from React context
89
+ val currentActivity = reactApplicationContext.currentActivity
90
+ if (currentActivity == null) {
91
+ promise.reject("INIT_ERROR", "Activity not available")
92
+ return
93
+ }
94
+
95
+ if (currentActivity !is ComponentActivity) {
96
+ promise.reject("INIT_ERROR", "Activity is not a ComponentActivity")
97
+ return
98
+ }
99
+
100
+ coordinator = MdlVerificationCoordinator(currentActivity)
101
+ coordinator.initSDK(licenseKey)
102
+
103
+ promise.resolve("SDK initialized successfully")
104
+ Log.d(TAG, "SDK initialized successfully")
105
+ } catch (e: Exception) {
106
+ Log.e(TAG, "Error initializing SDK: ${e.message}", e)
107
+ promise.reject("INIT_ERROR", e.message, e)
108
+ }
109
+ }
110
+
111
+ @ReactMethod
112
+ fun startVerification(config: ReadableMap, promise: Promise) {
113
+ try {
114
+ Log.d(TAG, "Starting verification")
115
+
116
+ if (!::coordinator.isInitialized) {
117
+ promise.reject("NOT_INITIALIZED", "SDK not initialized. Call initialize() first.")
118
+ return
119
+ }
120
+
121
+ var minAge: String = config.getString("minAge") ?: "18"
122
+ var command: String? = config.getString("command")
123
+ var stan: String? = config.getString("stan")
124
+ var terminalId: String? = config.getString("terminalId")
125
+ var merchantId: String? = config.getString("merchantId")
126
+ var testHostResponse: String? = config.getString("testHostResponse")
127
+ var mdlToken: String? = config.getString("mdlToken")
128
+ var timeout: String? = config.getString("timeout")
129
+ var demoMode: Boolean? = if (config.hasKey("demoMode")) config.getBoolean("demoMode") else null
130
+ var onlyVerified: Boolean? = if (config.hasKey("onlyVerified")) config.getBoolean("onlyVerified") else null
131
+
132
+ val request = VerificationRequest(
133
+ command = command,
134
+ stan = stan,
135
+ terminalId = terminalId,
136
+ merchantId = merchantId,
137
+ testHostResponse = testHostResponse,
138
+ minAge = minAge,
139
+ mdlToken = mdlToken,
140
+ timeout = timeout,
141
+ demoMode = demoMode,
142
+ onlyVerified = onlyVerified
143
+ )
144
+
145
+ coordinator.startVerification(
146
+ request = request,
147
+ onVerificationComplete = { response: VerificationResponse ->
148
+ Log.d(TAG, "Verification complete: $response")
149
+
150
+ // Create separate WritableMap instances for event and promise
151
+ val eventResponseMap = convertVerificationResponseToWritableMap(response)
152
+ val promiseResponseMap = convertVerificationResponseToWritableMap(response)
153
+
154
+ sendEvent("onVerificationComplete", eventResponseMap)
155
+ promise.resolve(promiseResponseMap)
156
+ },
157
+ onProgressUpdate = { progress: ProgressResponse ->
158
+ Log.d(TAG, "Progress: $progress")
159
+
160
+ // Convert the progress object to a proper WritableMap
161
+ val progressMap = convertProgressResponseToWritableMap(progress)
162
+ sendEvent("onVerificationProgress", progressMap)
163
+ }
164
+ )
165
+
166
+ Log.d(TAG, "Verification started")
167
+ } catch (e: Exception) {
168
+ Log.e(TAG, "Error starting verification: ${e.message}", e)
169
+ promise.reject("START_ERROR", e.message, e)
170
+ }
171
+ }
172
+
173
+ @ReactMethod
174
+ fun getDetailedVerificationData(mdlToken: String, promise: Promise) {
175
+ try {
176
+ Log.d(TAG, "Getting detailed verification data for token: $mdlToken")
177
+
178
+ if (!::coordinator.isInitialized) {
179
+ promise.reject("NOT_INITIALIZED", "SDK not initialized. Call initialize() first.")
180
+ return
181
+ }
182
+
183
+ coordinator.getDetailedVerificationData(
184
+ mdlToken = mdlToken,
185
+ onDataReceived = { data ->
186
+ Log.d(TAG, "Detailed data received: $data")
187
+
188
+ // Convert the data map to WritableMap
189
+ val resultMap = Arguments.createMap()
190
+ data.forEach { (key, value) ->
191
+ when (value) {
192
+ is String -> resultMap.putString(key, value)
193
+ is Int -> resultMap.putInt(key, value)
194
+ is Double -> resultMap.putDouble(key, value)
195
+ is Boolean -> resultMap.putBoolean(key, value)
196
+ else -> resultMap.putString(key, value.toString())
197
+ }
198
+ }
199
+
200
+ promise.resolve(resultMap)
201
+ },
202
+ onError = { error ->
203
+ Log.e(TAG, "Error getting detailed data: $error")
204
+ promise.reject("DATA_ERROR", error.message ?: "Unknown error", error)
205
+ }
206
+ )
207
+
208
+ Log.d(TAG, "Requested detailed verification data")
209
+ } catch (e: Exception) {
210
+ Log.e(TAG, "Error requesting detailed data: ${e.message}", e)
211
+ promise.reject("DATA_ERROR", e.message, e)
212
+ }
213
+ }
214
+ }
@@ -0,0 +1,16 @@
1
+ package com.mdlverification
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class MdlVerificationPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(MdlVerificationBridge(reactContext))
11
+ }
12
+
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ return emptyList()
15
+ }
16
+ }
package/example.js ADDED
@@ -0,0 +1,194 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { View, Text, Button, Alert, StyleSheet, ScrollView } from 'react-native';
3
+ import MdlVerification from 'react-native-mdl-verification';
4
+
5
+ const App = () => {
6
+ const [isInitialized, setIsInitialized] = useState(false);
7
+ const [verificationResult, setVerificationResult] = useState(null);
8
+ const [progress, setProgress] = useState('');
9
+
10
+ useEffect(() => {
11
+ // Add event listeners
12
+ const progressListener = MdlVerification.addListener(
13
+ MdlVerification.Events.VERIFICATION_PROGRESS,
14
+ (progressData) => {
15
+ console.log('Progress:', progressData);
16
+ setProgress(progressData.status || progressData.logData || '');
17
+ }
18
+ );
19
+
20
+ const completeListener = MdlVerification.addListener(
21
+ MdlVerification.Events.VERIFICATION_COMPLETE,
22
+ (result) => {
23
+ console.log('Verification complete:', result);
24
+ setVerificationResult(result);
25
+ }
26
+ );
27
+
28
+ // Cleanup listeners on unmount
29
+ return () => {
30
+ progressListener.remove();
31
+ completeListener.remove();
32
+ };
33
+ }, []);
34
+
35
+ const initializeSDK = async () => {
36
+ try {
37
+ await MdlVerification.initialize('YOUR_LICENSE_KEY_HERE');
38
+ setIsInitialized(true);
39
+ Alert.alert('Success', 'SDK initialized successfully');
40
+ } catch (error) {
41
+ console.error('Initialization error:', error);
42
+ Alert.alert('Error', `Failed to initialize SDK: ${error.message}`);
43
+ }
44
+ };
45
+
46
+ const startVerification = async () => {
47
+ if (!isInitialized) {
48
+ Alert.alert('Error', 'Please initialize SDK first');
49
+ return;
50
+ }
51
+
52
+ try {
53
+ setProgress('Starting verification...');
54
+ setVerificationResult(null);
55
+
56
+ const result = await MdlVerification.startVerification({
57
+ stan: '000001',
58
+ terminalId: 'TERMINAL_001',
59
+ merchantId: 'MERCHANT_001',
60
+ minAge: '18',
61
+ demoMode: false,
62
+ onlyVerified: true,
63
+ });
64
+
65
+ if (result.isSuccessful) {
66
+ Alert.alert('Success', 'Verification completed successfully!');
67
+
68
+ // Get detailed data if mdlToken is available
69
+ if (result.mdlToken) {
70
+ const detailedData = await MdlVerification.getDetailedVerificationData(result.mdlToken);
71
+ console.log('Detailed data:', detailedData);
72
+ }
73
+ } else {
74
+ Alert.alert('Verification Failed', result.successMesg || 'Unknown error');
75
+ }
76
+ } catch (error) {
77
+ console.error('Verification error:', error);
78
+ Alert.alert('Error', `Verification failed: ${error.message}`);
79
+ }
80
+ };
81
+
82
+ return (
83
+ <ScrollView style={styles.container}>
84
+ <View style={styles.content}>
85
+ <Text style={styles.title}>MDL Verification Example</Text>
86
+
87
+ <View style={styles.buttonContainer}>
88
+ <Button
89
+ title={isInitialized ? 'SDK Initialized ✓' : 'Initialize SDK'}
90
+ onPress={initializeSDK}
91
+ disabled={isInitialized}
92
+ />
93
+ </View>
94
+
95
+ <View style={styles.buttonContainer}>
96
+ <Button
97
+ title="Start Verification"
98
+ onPress={startVerification}
99
+ disabled={!isInitialized}
100
+ />
101
+ </View>
102
+
103
+ {progress ? (
104
+ <View style={styles.progressContainer}>
105
+ <Text style={styles.progressTitle}>Progress:</Text>
106
+ <Text style={styles.progressText}>{progress}</Text>
107
+ </View>
108
+ ) : null}
109
+
110
+ {verificationResult ? (
111
+ <View style={styles.resultContainer}>
112
+ <Text style={styles.resultTitle}>Verification Result:</Text>
113
+ <Text style={styles.resultText}>
114
+ Success: {verificationResult.success}
115
+ </Text>
116
+ <Text style={styles.resultText}>
117
+ Message: {verificationResult.successMesg}
118
+ </Text>
119
+ <Text style={styles.resultText}>
120
+ Doc Type: {verificationResult.docType}
121
+ </Text>
122
+ <Text style={styles.resultText}>
123
+ Doc Valid: {verificationResult.docValid}
124
+ </Text>
125
+ <Text style={styles.resultText}>
126
+ Auth Method: {verificationResult.authMethod}
127
+ </Text>
128
+ <Text style={styles.resultText}>
129
+ Auth Success: {verificationResult.authSuccess}
130
+ </Text>
131
+ {verificationResult.mdlToken ? (
132
+ <Text style={styles.resultText}>
133
+ MDL Token: {verificationResult.mdlToken.substring(0, 20)}...
134
+ </Text>
135
+ ) : null}
136
+ </View>
137
+ ) : null}
138
+ </View>
139
+ </ScrollView>
140
+ );
141
+ };
142
+
143
+ const styles = StyleSheet.create({
144
+ container: {
145
+ flex: 1,
146
+ backgroundColor: '#f5f5f5',
147
+ },
148
+ content: {
149
+ padding: 20,
150
+ },
151
+ title: {
152
+ fontSize: 24,
153
+ fontWeight: 'bold',
154
+ marginBottom: 20,
155
+ textAlign: 'center',
156
+ },
157
+ buttonContainer: {
158
+ marginVertical: 10,
159
+ },
160
+ progressContainer: {
161
+ marginTop: 20,
162
+ padding: 15,
163
+ backgroundColor: '#e3f2fd',
164
+ borderRadius: 8,
165
+ },
166
+ progressTitle: {
167
+ fontSize: 16,
168
+ fontWeight: 'bold',
169
+ marginBottom: 5,
170
+ },
171
+ progressText: {
172
+ fontSize: 14,
173
+ color: '#1976d2',
174
+ },
175
+ resultContainer: {
176
+ marginTop: 20,
177
+ padding: 15,
178
+ backgroundColor: '#fff',
179
+ borderRadius: 8,
180
+ borderWidth: 1,
181
+ borderColor: '#ddd',
182
+ },
183
+ resultTitle: {
184
+ fontSize: 18,
185
+ fontWeight: 'bold',
186
+ marginBottom: 10,
187
+ },
188
+ resultText: {
189
+ fontSize: 14,
190
+ marginVertical: 3,
191
+ },
192
+ });
193
+
194
+ export default App;
package/index.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ declare module 'react-native-mdl-verification' {
2
+ export interface VerificationOptions {
3
+ stan: string;
4
+ terminalId: string;
5
+ merchantId: string;
6
+ }
7
+
8
+ export interface VerificationResponse {
9
+ command?: string;
10
+ stan?: string;
11
+ terminalId?: string;
12
+ merchantId?: string;
13
+ success?: string;
14
+ successMesg?: string;
15
+ status?: number;
16
+ mdlToken?: string;
17
+ docType?: string;
18
+ docValid?: string;
19
+ authMethod?: string;
20
+ authSuccess?: string;
21
+ msoValid?: string;
22
+ cert?: string;
23
+ ica_cert?: string;
24
+ isSuccessful?: boolean;
25
+ }
26
+
27
+ export interface ProgressResponse {
28
+ command?: string;
29
+ status?: string;
30
+ logData?: string;
31
+ logLevel?: string;
32
+ }
33
+
34
+ export interface DetailedVerificationData {
35
+ [key: string]: any;
36
+ }
37
+
38
+ export interface MdlVerificationModule {
39
+ initialize(licenseKey: string): Promise<void>;
40
+ startVerification(options: VerificationOptions): Promise<VerificationResponse>;
41
+ getDetailedVerificationData(mdlToken: string): Promise<DetailedVerificationData>;
42
+ addListener(eventName: string, listener: (event: any) => void): { remove: () => void };
43
+ removeAllListeners(eventName: string): void;
44
+ Events: {
45
+ VERIFICATION_PROGRESS: 'onVerificationProgress';
46
+ VERIFICATION_COMPLETE: 'onVerificationComplete';
47
+ };
48
+ }
49
+
50
+ const MdlVerification: MdlVerificationModule;
51
+ export default MdlVerification;
52
+ }
package/index.js ADDED
@@ -0,0 +1,71 @@
1
+ import { NativeModules, NativeEventEmitter } from 'react-native';
2
+
3
+ const { MdlVerification } = NativeModules;
4
+
5
+ if (!MdlVerification) {
6
+ throw new Error(
7
+ 'MdlVerification native module is not available. Make sure the native module is properly linked.'
8
+ );
9
+ }
10
+
11
+ const mdlEventEmitter = new NativeEventEmitter(MdlVerification);
12
+
13
+ /**
14
+ * MDL Verification Module
15
+ * Provides methods for verifying Mobile Driver's Licenses
16
+ */
17
+ export default {
18
+ /**
19
+ * Initialize the MDL verification SDK
20
+ * @param {string} licenseKey - The license key for the SDK
21
+ * @returns {Promise<void>}
22
+ */
23
+ initialize(licenseKey) {
24
+ return MdlVerification.initialize(licenseKey);
25
+ },
26
+
27
+ /**
28
+ * Start MDL verification
29
+ * @param {Object} options - Verification options
30
+ * @param {string} options.stan - Station number
31
+ * @param {string} options.terminalId - Terminal ID
32
+ * @param {string} options.merchantId - Merchant ID
33
+ * @returns {Promise<Object>} Verification response
34
+ */
35
+ startVerification(options) {
36
+ return MdlVerification.startVerification(options);
37
+ },
38
+
39
+ /**
40
+ * Get detailed verification data
41
+ * @param {string} mdlToken - The MDL token from verification response
42
+ * @returns {Promise<Object>} Detailed verification data
43
+ */
44
+ getDetailedVerificationData(mdlToken) {
45
+ return MdlVerification.getDetailedVerificationData(mdlToken);
46
+ },
47
+
48
+ /**
49
+ * Add event listener for verification events
50
+ * @param {string} eventName - Event name ('onVerificationProgress' or 'onVerificationComplete')
51
+ * @param {function} listener - Event listener function
52
+ * @returns {Object} Subscription object with remove() method
53
+ */
54
+ addListener(eventName, listener) {
55
+ return mdlEventEmitter.addListener(eventName, listener);
56
+ },
57
+
58
+ /**
59
+ * Remove all listeners for a specific event
60
+ * @param {string} eventName - Event name to remove listeners from
61
+ */
62
+ removeAllListeners(eventName) {
63
+ mdlEventEmitter.removeAllListeners(eventName);
64
+ },
65
+
66
+ // Event names constants
67
+ Events: {
68
+ VERIFICATION_PROGRESS: 'onVerificationProgress',
69
+ VERIFICATION_COMPLETE: 'onVerificationComplete',
70
+ },
71
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "react-native-mdl-verification",
3
+ "version": "1.0.0",
4
+ "description": "React Native bridge for MDL (Mobile Driver's License) verification using CheckMDL SDK",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [
11
+ "react-native",
12
+ "mdl",
13
+ "mobile-drivers-license",
14
+ "verification",
15
+ "checkmdl",
16
+ "android"
17
+ ],
18
+ "author": "Naresh Bangia",
19
+ "license": "MIT",
20
+ "peerDependencies": {
21
+ "react": "*",
22
+ "react-native": "*"
23
+ },
24
+ "devDependencies": {
25
+ "react": "*",
26
+ "react-native": "*"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/yourusername/react-native-mdl-verification.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/yourusername/react-native-mdl-verification/issues"
34
+ },
35
+ "homepage": "https://github.com/yourusername/react-native-mdl-verification#readme"
36
+ }