omnipay-reactnative-sdk 1.2.2-beta.9 → 1.2.3-beta.10
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/README.md +58 -48
- package/android/build.gradle +4 -7
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/com/omniretail/omnipay/FaceVerificationFrameProcessor.kt +111 -0
- package/android/src/main/java/com/omniretail/omnipay/OmnipayActivityPackage.java +6 -4
- package/ios/FaceVerificationFrameProcessor.swift +138 -0
- package/ios/FaceVerificationFrameProcessorPlugin.m +4 -0
- package/ios/OmnipayReactnativeSdk.m +5 -0
- package/ios/OmnipayReactnativeSdk.swift +10 -0
- package/ios/omnipay_reactnative_sdk.h +6 -0
- package/lib/commonjs/components/Button.js +68 -0
- package/lib/commonjs/components/Button.js.map +1 -0
- package/lib/commonjs/components/OmnipayProvider.js +7 -23
- package/lib/commonjs/components/OmnipayProvider.js.map +1 -1
- package/lib/commonjs/components/biometrics/FaceVerification.js +294 -270
- package/lib/commonjs/components/biometrics/FaceVerification.js.map +1 -1
- package/lib/commonjs/components/biometrics/useFaceVerification.js +85 -0
- package/lib/commonjs/components/biometrics/useFaceVerification.js.map +1 -0
- package/lib/commonjs/components/biometrics/useFaceVerificationFlow.js +157 -0
- package/lib/commonjs/components/biometrics/useFaceVerificationFlow.js.map +1 -0
- package/lib/commonjs/index.js +0 -33
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/Button.js +61 -0
- package/lib/module/components/Button.js.map +1 -0
- package/lib/module/components/OmnipayProvider.js +7 -23
- package/lib/module/components/OmnipayProvider.js.map +1 -1
- package/lib/module/components/biometrics/FaceVerification.js +294 -271
- package/lib/module/components/biometrics/FaceVerification.js.map +1 -1
- package/lib/module/components/biometrics/useFaceVerification.js +78 -0
- package/lib/module/components/biometrics/useFaceVerification.js.map +1 -0
- package/lib/module/components/biometrics/useFaceVerificationFlow.js +150 -0
- package/lib/module/components/biometrics/useFaceVerificationFlow.js.map +1 -0
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/Button.d.ts +17 -0
- package/lib/typescript/components/Button.d.ts.map +1 -0
- package/lib/typescript/components/OmnipayProvider.d.ts.map +1 -1
- package/lib/typescript/components/biometrics/FaceVerification.d.ts +1 -3
- package/lib/typescript/components/biometrics/FaceVerification.d.ts.map +1 -1
- package/lib/typescript/components/biometrics/useFaceVerification.d.ts +38 -0
- package/lib/typescript/components/biometrics/useFaceVerification.d.ts.map +1 -0
- package/lib/typescript/components/biometrics/useFaceVerificationFlow.d.ts +29 -0
- package/lib/typescript/components/biometrics/useFaceVerificationFlow.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +0 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/omnipay_reactnative_sdk.podspec +46 -0
- package/package.json +5 -8
- package/src/components/Button.tsx +86 -0
- package/src/components/OmnipayProvider.tsx +7 -24
- package/src/components/biometrics/FaceVerification.tsx +315 -309
- package/src/components/biometrics/useFaceVerification.ts +120 -0
- package/src/components/biometrics/useFaceVerificationFlow.ts +224 -0
- package/src/index.tsx +0 -7
- package/android/src/main/java/com/omniretail/omnipay/OmnipayLivenessCameraView.java +0 -153
- package/android/src/main/java/com/omniretail/omnipay/OmnipayLivenessCameraViewManager.java +0 -49
- package/android/src/main/java/com/omniretail/omnipay/OmnipayLivenessModule.java +0 -557
- package/ios/OmnipayLivenessCameraView.h +0 -15
- package/ios/OmnipayLivenessCameraView.m +0 -80
- package/ios/OmnipayLivenessCameraViewManager.m +0 -19
- package/ios/OmnipayLivenessModule.h +0 -38
- package/ios/OmnipayLivenessModule.m +0 -615
- package/lib/commonjs/components/biometrics/LivenessDetection.js +0 -149
- package/lib/commonjs/components/biometrics/LivenessDetection.js.map +0 -1
- package/lib/commonjs/components/biometrics/OmnipayLivenessCameraView.js +0 -15
- package/lib/commonjs/components/biometrics/OmnipayLivenessCameraView.js.map +0 -1
- package/lib/commonjs/components/biometrics/PermissionManager.js +0 -279
- package/lib/commonjs/components/biometrics/PermissionManager.js.map +0 -1
- package/lib/commonjs/components/biometrics/index.js +0 -45
- package/lib/commonjs/components/biometrics/index.js.map +0 -1
- package/lib/commonjs/components/biometrics/types.js +0 -17
- package/lib/commonjs/components/biometrics/types.js.map +0 -1
- package/lib/module/components/biometrics/LivenessDetection.js +0 -129
- package/lib/module/components/biometrics/LivenessDetection.js.map +0 -1
- package/lib/module/components/biometrics/OmnipayLivenessCameraView.js +0 -7
- package/lib/module/components/biometrics/OmnipayLivenessCameraView.js.map +0 -1
- package/lib/module/components/biometrics/PermissionManager.js +0 -272
- package/lib/module/components/biometrics/PermissionManager.js.map +0 -1
- package/lib/module/components/biometrics/index.js +0 -12
- package/lib/module/components/biometrics/index.js.map +0 -1
- package/lib/module/components/biometrics/types.js +0 -16
- package/lib/module/components/biometrics/types.js.map +0 -1
- package/lib/typescript/components/biometrics/LivenessDetection.d.ts +0 -33
- package/lib/typescript/components/biometrics/LivenessDetection.d.ts.map +0 -1
- package/lib/typescript/components/biometrics/OmnipayLivenessCameraView.d.ts +0 -18
- package/lib/typescript/components/biometrics/OmnipayLivenessCameraView.d.ts.map +0 -1
- package/lib/typescript/components/biometrics/PermissionManager.d.ts +0 -58
- package/lib/typescript/components/biometrics/PermissionManager.d.ts.map +0 -1
- package/lib/typescript/components/biometrics/index.d.ts +0 -5
- package/lib/typescript/components/biometrics/index.d.ts.map +0 -1
- package/lib/typescript/components/biometrics/types.d.ts +0 -73
- package/lib/typescript/components/biometrics/types.d.ts.map +0 -1
- package/omnipay-reactnative-sdk.podspec +0 -50
- package/src/components/biometrics/LivenessDetection.ts +0 -178
- package/src/components/biometrics/OmnipayLivenessCameraView.tsx +0 -19
- package/src/components/biometrics/PermissionManager.ts +0 -317
- package/src/components/biometrics/index.ts +0 -11
- package/src/components/biometrics/types.ts +0 -86
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
|
-
import type {
|
|
3
|
-
LivenessConfig,
|
|
4
|
-
LivenessResult,
|
|
5
|
-
LivenessChallenge,
|
|
6
|
-
ChallengeResult,
|
|
7
|
-
LivenessEventCallbacks,
|
|
8
|
-
} from './types';
|
|
9
|
-
|
|
10
|
-
const { OmnipayLivenessModule } = NativeModules;
|
|
11
|
-
|
|
12
|
-
class LivenessDetectionManager {
|
|
13
|
-
private eventEmitter?: NativeEventEmitter;
|
|
14
|
-
private eventListeners: { [key: string]: any } = {};
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
if (OmnipayLivenessModule) {
|
|
18
|
-
this.eventEmitter = new NativeEventEmitter(OmnipayLivenessModule);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Check if liveness detection is supported on this device
|
|
24
|
-
*/
|
|
25
|
-
async isSupported(): Promise<boolean> {
|
|
26
|
-
console.log('🔧 LivenessDetection.isSupported() called');
|
|
27
|
-
|
|
28
|
-
if (!OmnipayLivenessModule) {
|
|
29
|
-
console.log('❌ OmnipayLivenessModule not available in NativeModules');
|
|
30
|
-
console.log('📋 Available modules:', Object.keys(NativeModules));
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
console.log(
|
|
35
|
-
'✅ OmnipayLivenessModule found, calling native isSupported...'
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const result = await OmnipayLivenessModule.isSupported();
|
|
40
|
-
console.log('📋 Native isSupported result:', result);
|
|
41
|
-
return result;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error('💥 Liveness detection support check failed:', error);
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Start liveness detection with given configuration
|
|
50
|
-
*/
|
|
51
|
-
async startDetection(
|
|
52
|
-
config: LivenessConfig,
|
|
53
|
-
callbacks?: LivenessEventCallbacks
|
|
54
|
-
): Promise<LivenessResult> {
|
|
55
|
-
if (!OmnipayLivenessModule) {
|
|
56
|
-
throw new Error('Liveness detection module not available');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Set up event listeners if callbacks provided
|
|
60
|
-
if (callbacks) {
|
|
61
|
-
this.setupEventListeners(callbacks);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const result = await OmnipayLivenessModule.startLivenessDetection(config);
|
|
66
|
-
return result;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
this.cleanupEventListeners();
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Stop the current detection
|
|
75
|
-
*/
|
|
76
|
-
async stopDetection(): Promise<void> {
|
|
77
|
-
if (!OmnipayLivenessModule) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
await OmnipayLivenessModule.stopDetection();
|
|
83
|
-
} finally {
|
|
84
|
-
this.cleanupEventListeners();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Set up event listeners for detection callbacks
|
|
90
|
-
*/
|
|
91
|
-
private setupEventListeners(callbacks: LivenessEventCallbacks) {
|
|
92
|
-
this.cleanupEventListeners(); // Clean up any existing listeners
|
|
93
|
-
|
|
94
|
-
if (!this.eventEmitter) {
|
|
95
|
-
console.warn('Event emitter not available for liveness detection');
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (callbacks.onChallengeStart) {
|
|
100
|
-
this.eventListeners.challengeStart = this.eventEmitter.addListener(
|
|
101
|
-
'onChallengeStart',
|
|
102
|
-
(challenge: LivenessChallenge) => callbacks.onChallengeStart!(challenge)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (callbacks.onChallengeSuccess) {
|
|
107
|
-
this.eventListeners.challengeSuccess = this.eventEmitter.addListener(
|
|
108
|
-
'onChallengeSuccess',
|
|
109
|
-
(data: { challenge: LivenessChallenge; result: ChallengeResult }) =>
|
|
110
|
-
callbacks.onChallengeSuccess!(data.challenge, data.result)
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (callbacks.onChallengeFailure) {
|
|
115
|
-
this.eventListeners.challengeFailure = this.eventEmitter.addListener(
|
|
116
|
-
'onChallengeFailure',
|
|
117
|
-
(data: { challenge: LivenessChallenge; reason: string }) =>
|
|
118
|
-
callbacks.onChallengeFailure!(data.challenge, data.reason)
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (callbacks.onAllChallengesComplete) {
|
|
123
|
-
this.eventListeners.allComplete = this.eventEmitter.addListener(
|
|
124
|
-
'onAllChallengesComplete',
|
|
125
|
-
() => callbacks.onAllChallengesComplete!()
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (callbacks.onScreenshotCaptured) {
|
|
130
|
-
this.eventListeners.screenshot = this.eventEmitter.addListener(
|
|
131
|
-
'onScreenshotCaptured',
|
|
132
|
-
(screenshot: string) => callbacks.onScreenshotCaptured!(screenshot)
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (callbacks.onDetectionFailed) {
|
|
137
|
-
this.eventListeners.failed = this.eventEmitter.addListener(
|
|
138
|
-
'onDetectionFailed',
|
|
139
|
-
(reason: string) => callbacks.onDetectionFailed!(reason)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Clean up all event listeners
|
|
146
|
-
*/
|
|
147
|
-
private cleanupEventListeners() {
|
|
148
|
-
Object.values(this.eventListeners).forEach((listener) => {
|
|
149
|
-
if (listener && listener.remove) {
|
|
150
|
-
listener.remove();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
this.eventListeners = {};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Get default configuration
|
|
158
|
-
*/
|
|
159
|
-
getDefaultConfig(): LivenessConfig {
|
|
160
|
-
return {
|
|
161
|
-
challenges: [
|
|
162
|
-
'smile',
|
|
163
|
-
'blink',
|
|
164
|
-
'turnLeft',
|
|
165
|
-
'turnRight',
|
|
166
|
-
] as LivenessChallenge[],
|
|
167
|
-
challengeTimeout: 10,
|
|
168
|
-
totalTimeout: 60,
|
|
169
|
-
debugMode: __DEV__,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Export singleton instance
|
|
175
|
-
export const LivenessDetection = new LivenessDetectionManager();
|
|
176
|
-
|
|
177
|
-
// Export types for convenience
|
|
178
|
-
export * from './types';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { requireNativeComponent, ViewStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
interface OmnipayLivenessCameraViewProps {
|
|
5
|
-
style?: ViewStyle;
|
|
6
|
-
onCameraReady?: (event: { nativeEvent: { ready: boolean } }) => void;
|
|
7
|
-
onCameraError?: (event: { nativeEvent: { error: string } }) => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const NativeOmnipayLivenessCameraView =
|
|
11
|
-
requireNativeComponent<OmnipayLivenessCameraViewProps>(
|
|
12
|
-
'OmnipayLivenessCameraView'
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export const OmnipayLivenessCameraView: React.FC<
|
|
16
|
-
OmnipayLivenessCameraViewProps
|
|
17
|
-
> = (props) => {
|
|
18
|
-
return <NativeOmnipayLivenessCameraView {...props} />;
|
|
19
|
-
};
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { Platform, Alert, Linking, PermissionsAndroid } from 'react-native';
|
|
2
|
-
import { LivenessDetection } from './LivenessDetection';
|
|
3
|
-
|
|
4
|
-
export enum PermissionResult {
|
|
5
|
-
GRANTED = 'granted',
|
|
6
|
-
DENIED = 'denied',
|
|
7
|
-
BLOCKED = 'blocked',
|
|
8
|
-
UNAVAILABLE = 'unavailable',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface PermissionResponse {
|
|
12
|
-
result: PermissionResult;
|
|
13
|
-
canRequest: boolean;
|
|
14
|
-
message?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class CameraPermissionManager {
|
|
18
|
-
/**
|
|
19
|
-
* Check current camera permission status
|
|
20
|
-
*/
|
|
21
|
-
static async checkCameraPermission(): Promise<PermissionResponse> {
|
|
22
|
-
try {
|
|
23
|
-
if (Platform.OS === 'android') {
|
|
24
|
-
return await this.checkAndroidCameraPermission();
|
|
25
|
-
} else {
|
|
26
|
-
// For iOS, we'll check through the native module
|
|
27
|
-
return await this.checkIOSCameraPermission();
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error('Error checking camera permission:', error);
|
|
31
|
-
return {
|
|
32
|
-
result: PermissionResult.UNAVAILABLE,
|
|
33
|
-
canRequest: false,
|
|
34
|
-
message: 'Unable to check camera permission',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Request camera permission with user-friendly flow
|
|
41
|
-
*/
|
|
42
|
-
static async requestCameraPermission(
|
|
43
|
-
showRationale: boolean = true
|
|
44
|
-
): Promise<PermissionResponse> {
|
|
45
|
-
try {
|
|
46
|
-
// First check current status
|
|
47
|
-
const currentStatus = await this.checkCameraPermission();
|
|
48
|
-
|
|
49
|
-
if (currentStatus.result === PermissionResult.GRANTED) {
|
|
50
|
-
return currentStatus;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (currentStatus.result === PermissionResult.BLOCKED) {
|
|
54
|
-
if (showRationale) {
|
|
55
|
-
this.showPermissionBlockedAlert();
|
|
56
|
-
}
|
|
57
|
-
return currentStatus;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Show rationale if needed
|
|
61
|
-
if (showRationale && currentStatus.result === PermissionResult.DENIED) {
|
|
62
|
-
const shouldProceed = await this.showPermissionRationale();
|
|
63
|
-
if (!shouldProceed) {
|
|
64
|
-
return {
|
|
65
|
-
result: PermissionResult.DENIED,
|
|
66
|
-
canRequest: true,
|
|
67
|
-
message: 'User declined to grant permission',
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Request permission based on platform
|
|
73
|
-
if (Platform.OS === 'android') {
|
|
74
|
-
return await this.requestAndroidCameraPermission();
|
|
75
|
-
} else {
|
|
76
|
-
return await this.requestIOSCameraPermission();
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error('Error requesting camera permission:', error);
|
|
80
|
-
return {
|
|
81
|
-
result: PermissionResult.UNAVAILABLE,
|
|
82
|
-
canRequest: false,
|
|
83
|
-
message: 'Unable to request camera permission',
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Check Android camera permission using PermissionsAndroid
|
|
90
|
-
*/
|
|
91
|
-
private static async checkAndroidCameraPermission(): Promise<PermissionResponse> {
|
|
92
|
-
const hasPermission = await PermissionsAndroid.check(
|
|
93
|
-
PermissionsAndroid.PERMISSIONS.CAMERA
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
if (hasPermission) {
|
|
97
|
-
return {
|
|
98
|
-
result: PermissionResult.GRANTED,
|
|
99
|
-
canRequest: false,
|
|
100
|
-
message: 'Camera permission granted',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
result: PermissionResult.DENIED,
|
|
106
|
-
canRequest: true,
|
|
107
|
-
message: 'Camera permission not granted',
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Request Android camera permission
|
|
113
|
-
*/
|
|
114
|
-
private static async requestAndroidCameraPermission(): Promise<PermissionResponse> {
|
|
115
|
-
try {
|
|
116
|
-
const granted = await PermissionsAndroid.request(
|
|
117
|
-
PermissionsAndroid.PERMISSIONS.CAMERA,
|
|
118
|
-
{
|
|
119
|
-
title: 'Camera Permission Required',
|
|
120
|
-
message:
|
|
121
|
-
'Face verification requires camera access to capture your image and perform liveness detection.',
|
|
122
|
-
buttonNeutral: 'Ask Me Later',
|
|
123
|
-
buttonNegative: 'Cancel',
|
|
124
|
-
buttonPositive: 'OK',
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
switch (granted) {
|
|
129
|
-
case PermissionsAndroid.RESULTS.GRANTED:
|
|
130
|
-
return {
|
|
131
|
-
result: PermissionResult.GRANTED,
|
|
132
|
-
canRequest: false,
|
|
133
|
-
message: 'Camera permission granted',
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
case PermissionsAndroid.RESULTS.DENIED:
|
|
137
|
-
return {
|
|
138
|
-
result: PermissionResult.DENIED,
|
|
139
|
-
canRequest: true,
|
|
140
|
-
message: 'Camera permission denied',
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
case PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN:
|
|
144
|
-
return {
|
|
145
|
-
result: PermissionResult.BLOCKED,
|
|
146
|
-
canRequest: false,
|
|
147
|
-
message: 'Camera permission permanently blocked',
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
default:
|
|
151
|
-
return {
|
|
152
|
-
result: PermissionResult.DENIED,
|
|
153
|
-
canRequest: true,
|
|
154
|
-
message: 'Camera permission denied',
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error('Error requesting Android camera permission:', error);
|
|
159
|
-
return {
|
|
160
|
-
result: PermissionResult.UNAVAILABLE,
|
|
161
|
-
canRequest: false,
|
|
162
|
-
message: 'Unable to request camera permission',
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Check iOS camera permission through native module
|
|
169
|
-
*/
|
|
170
|
-
private static async checkIOSCameraPermission(): Promise<PermissionResponse> {
|
|
171
|
-
try {
|
|
172
|
-
// iOS permissions are handled automatically by AVCaptureDevice
|
|
173
|
-
// We'll use the liveness detection module to check support
|
|
174
|
-
const isSupported = await LivenessDetection.isSupported();
|
|
175
|
-
|
|
176
|
-
if (isSupported) {
|
|
177
|
-
return {
|
|
178
|
-
result: PermissionResult.GRANTED,
|
|
179
|
-
canRequest: false,
|
|
180
|
-
message: 'Camera access available',
|
|
181
|
-
};
|
|
182
|
-
} else {
|
|
183
|
-
return {
|
|
184
|
-
result: PermissionResult.UNAVAILABLE,
|
|
185
|
-
canRequest: false,
|
|
186
|
-
message: 'Camera not available',
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
} catch (error) {
|
|
190
|
-
return {
|
|
191
|
-
result: PermissionResult.UNAVAILABLE,
|
|
192
|
-
canRequest: false,
|
|
193
|
-
message: 'Unable to check camera availability',
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Request iOS camera permission through native module
|
|
200
|
-
*/
|
|
201
|
-
private static async requestIOSCameraPermission(): Promise<PermissionResponse> {
|
|
202
|
-
// iOS camera permissions are handled automatically by the native module
|
|
203
|
-
// when startLivenessDetection is called. The system will show the permission
|
|
204
|
-
// dialog automatically if needed.
|
|
205
|
-
return {
|
|
206
|
-
result: PermissionResult.GRANTED,
|
|
207
|
-
canRequest: false,
|
|
208
|
-
message: 'iOS camera permission will be requested automatically',
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Request permission with retry logic
|
|
214
|
-
*/
|
|
215
|
-
static async requestWithRetry(
|
|
216
|
-
maxRetries: number = 2
|
|
217
|
-
): Promise<PermissionResponse> {
|
|
218
|
-
let lastResponse: PermissionResponse;
|
|
219
|
-
|
|
220
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
221
|
-
const isFirstAttempt = attempt === 0;
|
|
222
|
-
lastResponse = await this.requestCameraPermission(isFirstAttempt);
|
|
223
|
-
|
|
224
|
-
if (lastResponse.result === PermissionResult.GRANTED) {
|
|
225
|
-
return lastResponse;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
lastResponse.result === PermissionResult.BLOCKED ||
|
|
230
|
-
lastResponse.result === PermissionResult.UNAVAILABLE
|
|
231
|
-
) {
|
|
232
|
-
break; // No point in retrying
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Wait a bit before retry
|
|
236
|
-
if (attempt < maxRetries) {
|
|
237
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return lastResponse!;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Show rationale dialog explaining why camera permission is needed
|
|
246
|
-
*/
|
|
247
|
-
private static showPermissionRationale(): Promise<boolean> {
|
|
248
|
-
return new Promise((resolve) => {
|
|
249
|
-
Alert.alert(
|
|
250
|
-
'Camera Permission Required',
|
|
251
|
-
'Face verification requires camera access to capture your image and perform liveness detection. This ensures secure identity verification.',
|
|
252
|
-
[
|
|
253
|
-
{
|
|
254
|
-
text: 'Not Now',
|
|
255
|
-
style: 'cancel',
|
|
256
|
-
onPress: () => resolve(false),
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
text: 'Allow Camera',
|
|
260
|
-
onPress: () => resolve(true),
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
{ cancelable: false }
|
|
264
|
-
);
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Show alert when permission is permanently blocked
|
|
270
|
-
*/
|
|
271
|
-
private static showPermissionBlockedAlert(): void {
|
|
272
|
-
Alert.alert(
|
|
273
|
-
'Camera Permission Blocked',
|
|
274
|
-
'Camera access has been blocked. To use face verification, please enable camera permission in your device settings.',
|
|
275
|
-
[
|
|
276
|
-
{
|
|
277
|
-
text: 'Cancel',
|
|
278
|
-
style: 'cancel',
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
text: 'Open Settings',
|
|
282
|
-
onPress: () => Linking.openSettings(),
|
|
283
|
-
},
|
|
284
|
-
]
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Get user-friendly permission status message
|
|
290
|
-
*/
|
|
291
|
-
static getPermissionStatusMessage(result: PermissionResult): string {
|
|
292
|
-
switch (result) {
|
|
293
|
-
case PermissionResult.GRANTED:
|
|
294
|
-
return 'Camera access granted';
|
|
295
|
-
case PermissionResult.DENIED:
|
|
296
|
-
return 'Camera access denied. Tap to allow camera permission.';
|
|
297
|
-
case PermissionResult.BLOCKED:
|
|
298
|
-
return 'Camera access blocked. Please enable in device settings.';
|
|
299
|
-
case PermissionResult.UNAVAILABLE:
|
|
300
|
-
return 'Camera not available on this device';
|
|
301
|
-
default:
|
|
302
|
-
return 'Unknown permission status';
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Check if the device has camera capability
|
|
308
|
-
*/
|
|
309
|
-
static async hasCamera(): Promise<boolean> {
|
|
310
|
-
try {
|
|
311
|
-
const status = await this.checkCameraPermission();
|
|
312
|
-
return status.result !== PermissionResult.UNAVAILABLE;
|
|
313
|
-
} catch {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Export the main face verification component with liveness detection
|
|
2
|
-
export { default as FaceVerification } from './FaceVerification';
|
|
3
|
-
|
|
4
|
-
// Export the liveness detection manager
|
|
5
|
-
export { LivenessDetection } from './LivenessDetection';
|
|
6
|
-
|
|
7
|
-
// Export the native camera view
|
|
8
|
-
export { OmnipayLivenessCameraView } from './OmnipayLivenessCameraView';
|
|
9
|
-
|
|
10
|
-
// Export all types
|
|
11
|
-
export * from './types';
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// Liveness Detection Types
|
|
2
|
-
|
|
3
|
-
export enum LivenessChallenge {
|
|
4
|
-
SMILE = 'smile',
|
|
5
|
-
BLINK = 'blink',
|
|
6
|
-
TURN_LEFT = 'turnLeft',
|
|
7
|
-
TURN_RIGHT = 'turnRight',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface LivenessConfig {
|
|
11
|
-
/** Which challenges to include in the detection flow */
|
|
12
|
-
challenges?: LivenessChallenge[];
|
|
13
|
-
/** Timeout in seconds for each challenge (default: 10) */
|
|
14
|
-
challengeTimeout?: number;
|
|
15
|
-
/** Total timeout in seconds for entire flow (default: 60) */
|
|
16
|
-
totalTimeout?: number;
|
|
17
|
-
/** Enable debug mode with visual feedback */
|
|
18
|
-
debugMode?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LivenessResult {
|
|
22
|
-
/** Whether all challenges were completed successfully */
|
|
23
|
-
success: boolean;
|
|
24
|
-
/** Base64 encoded final screenshot after completion */
|
|
25
|
-
screenshot?: string;
|
|
26
|
-
/** Results for each individual challenge */
|
|
27
|
-
challengeResults: ChallengeResult[];
|
|
28
|
-
/** Total time taken in milliseconds */
|
|
29
|
-
totalDuration: number;
|
|
30
|
-
/** Reason for failure if unsuccessful */
|
|
31
|
-
failureReason?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ChallengeResult {
|
|
35
|
-
/** The challenge that was performed */
|
|
36
|
-
challenge: LivenessChallenge;
|
|
37
|
-
/** Whether this specific challenge was successful */
|
|
38
|
-
success: boolean;
|
|
39
|
-
/** Time taken for this challenge in milliseconds */
|
|
40
|
-
duration: number;
|
|
41
|
-
/** Confidence score (0-1) if available */
|
|
42
|
-
confidence?: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Event callback types
|
|
46
|
-
export interface LivenessEventCallbacks {
|
|
47
|
-
/** Called when a challenge starts */
|
|
48
|
-
onChallengeStart?: (challenge: LivenessChallenge) => void;
|
|
49
|
-
/** Called when a challenge is completed successfully */
|
|
50
|
-
onChallengeSuccess?: (
|
|
51
|
-
challenge: LivenessChallenge,
|
|
52
|
-
result: ChallengeResult
|
|
53
|
-
) => void;
|
|
54
|
-
/** Called when a challenge fails */
|
|
55
|
-
onChallengeFailure?: (challenge: LivenessChallenge, reason: string) => void;
|
|
56
|
-
/** Called when all challenges are completed */
|
|
57
|
-
onAllChallengesComplete?: () => void;
|
|
58
|
-
/** Called when the final screenshot is captured */
|
|
59
|
-
onScreenshotCaptured?: (screenshot: string) => void;
|
|
60
|
-
/** Called when detection is cancelled or fails */
|
|
61
|
-
onDetectionFailed?: (reason: string) => void;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Native module interface
|
|
65
|
-
export interface LivenessNativeModule {
|
|
66
|
-
/** Start the liveness detection flow */
|
|
67
|
-
startLivenessDetection(config: LivenessConfig): Promise<LivenessResult>;
|
|
68
|
-
/** Stop the current detection */
|
|
69
|
-
stopDetection(): Promise<void>;
|
|
70
|
-
/** Check if the device supports liveness detection */
|
|
71
|
-
isSupported(): Promise<boolean>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Component props
|
|
75
|
-
export interface LivenessDetectionProps extends LivenessEventCallbacks {
|
|
76
|
-
/** Whether the liveness detection modal is visible */
|
|
77
|
-
visible: boolean;
|
|
78
|
-
/** Called when user closes the modal */
|
|
79
|
-
onClose: () => void;
|
|
80
|
-
/** Called when liveness detection completes successfully */
|
|
81
|
-
onSuccess: (result: LivenessResult) => void;
|
|
82
|
-
/** Configuration for the liveness detection */
|
|
83
|
-
config?: LivenessConfig;
|
|
84
|
-
/** Primary color for UI elements */
|
|
85
|
-
primaryColor?: string;
|
|
86
|
-
}
|