@finos_sdk/sdk-ekyc 1.2.2 → 1.2.9
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 +13 -10
- package/README.md +41 -42
- package/android/build.gradle +42 -11
- package/android/gradle.properties +7 -1
- package/android/settings.gradle +53 -0
- package/android/src/main/java/finos/sdk/ekyc/EKYCModule.kt +791 -81
- package/dist/EKYCModule.d.ts +73 -0
- package/dist/EKYCModule.js +663 -71
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/package.json +31 -21
- package/dist/src/modules/FinosEKYCModule.d.ts +149 -0
- package/dist/src/modules/FinosEKYCModule.js +485 -2
- package/dist/src/modules/FinosESignModule.d.ts +270 -0
- package/dist/src/modules/FinosESignModule.js +752 -0
- package/dist/src/types/ekycESignType.d.ts +67 -0
- package/dist/src/types/ekycESignType.js +2 -0
- package/dist/src/types/ekycSmsOtpType.d.ts +52 -0
- package/dist/src/types/ekycSmsOtpType.js +2 -0
- package/package.json +31 -21
- package/src/modules/FinosEKYCModule.ts +572 -2
- package/src/modules/FinosESignModule.ts +919 -0
- package/src/modules/README.md +3 -3
- package/src/types/ekycESignType.ts +76 -0
- package/src/types/ekycSmsOtpType.ts +59 -0
- package/android/SDKeKYC/finos/sdk/ekyc/c06/1.2.2/c06-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/c06/1.2.2/c06-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/c06/1.2.2/c06-1.2.2.module +0 -110
- package/android/SDKeKYC/finos/sdk/ekyc/c06/1.2.2/c06-1.2.2.pom +0 -37
- package/android/SDKeKYC/finos/sdk/ekyc/c06/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/ekyc/1.2.2/ekyc-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ekyc/1.2.2/ekyc-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ekyc/1.2.2/ekyc-1.2.2.module +0 -201
- package/android/SDKeKYC/finos/sdk/ekyc/ekyc/1.2.2/ekyc-1.2.2.pom +0 -73
- package/android/SDKeKYC/finos/sdk/ekyc/ekyc/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/ekycui/1.2.2/ekycui-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ekycui/1.2.2/ekycui-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ekycui/1.2.2/ekycui-1.2.2.module +0 -131
- package/android/SDKeKYC/finos/sdk/ekyc/ekycui/1.2.2/ekycui-1.2.2.pom +0 -43
- package/android/SDKeKYC/finos/sdk/ekyc/ekycui/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/faceservice/1.2.2/faceservice-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/faceservice/1.2.2/faceservice-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/faceservice/1.2.2/faceservice-1.2.2.module +0 -110
- package/android/SDKeKYC/finos/sdk/ekyc/faceservice/1.2.2/faceservice-1.2.2.pom +0 -37
- package/android/SDKeKYC/finos/sdk/ekyc/faceservice/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/liveness/1.2.2/liveness-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/liveness/1.2.2/liveness-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/liveness/1.2.2/liveness-1.2.2.module +0 -138
- package/android/SDKeKYC/finos/sdk/ekyc/liveness/1.2.2/liveness-1.2.2.pom +0 -55
- package/android/SDKeKYC/finos/sdk/ekyc/liveness/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/nfc/1.2.2/nfc-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/nfc/1.2.2/nfc-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/nfc/1.2.2/nfc-1.2.2.module +0 -131
- package/android/SDKeKYC/finos/sdk/ekyc/nfc/1.2.2/nfc-1.2.2.pom +0 -55
- package/android/SDKeKYC/finos/sdk/ekyc/nfc/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/ocr/1.2.2/ocr-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ocr/1.2.2/ocr-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/ocr/1.2.2/ocr-1.2.2.module +0 -124
- package/android/SDKeKYC/finos/sdk/ekyc/ocr/1.2.2/ocr-1.2.2.pom +0 -43
- package/android/SDKeKYC/finos/sdk/ekyc/ocr/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/qrcode/1.2.2/qrcode-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/qrcode/1.2.2/qrcode-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/qrcode/1.2.2/qrcode-1.2.2.module +0 -138
- package/android/SDKeKYC/finos/sdk/ekyc/qrcode/1.2.2/qrcode-1.2.2.pom +0 -55
- package/android/SDKeKYC/finos/sdk/ekyc/qrcode/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcore/1.2.2/sdkcore-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcore/1.2.2/sdkcore-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcore/1.2.2/sdkcore-1.2.2.module +0 -341
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcore/1.2.2/sdkcore-1.2.2.pom +0 -139
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcore/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcorecamera/1.2.2/sdkcorecamera-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcorecamera/1.2.2/sdkcorecamera-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcorecamera/1.2.2/sdkcorecamera-1.2.2.module +0 -201
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcorecamera/1.2.2/sdkcorecamera-1.2.2.pom +0 -85
- package/android/SDKeKYC/finos/sdk/ekyc/sdkcorecamera/maven-metadata-local.xml +0 -13
- package/android/SDKeKYC/finos/sdk/ekyc/sdkui/1.2.2/sdkui-1.2.2-sources.jar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkui/1.2.2/sdkui-1.2.2.aar +0 -0
- package/android/SDKeKYC/finos/sdk/ekyc/sdkui/1.2.2/sdkui-1.2.2.module +0 -208
- package/android/SDKeKYC/finos/sdk/ekyc/sdkui/1.2.2/sdkui-1.2.2.pom +0 -103
- package/android/SDKeKYC/finos/sdk/ekyc/sdkui/maven-metadata-local.xml +0 -13
- package/android/src/main/AndroidManifest.xml +0 -22
- package/android/src/main/build.gradle +0 -31
- package/dist/App.d.ts +0 -3
- package/dist/App.js +0 -497
- package/dist/finos_sdk-sdk-ekyc-1.2.2.tgz +0 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import sdkEKYC, { SDKeKYC, SDK_VERSION, SDK_NAME } from '../../EKYCModule';
|
|
3
|
+
import { SmsOtpConfig, SmsOtpResult, SmsOtpError } from '../types/ekycSmsOtpType';
|
|
4
|
+
import { UserEsignModel, ESignInitResult, ESignOpenSessionResult, ESignCertificate, ESignSignRequest, ESignError, ESignAuthenticateResult } from '../types/ekycESignType';
|
|
5
|
+
import { LivenessConfig } from '../types/ekycLivenessType';
|
|
6
|
+
import { FaceServiceConfig } from '../types/ekycFaceType';
|
|
7
|
+
import { SDKEkycResultStringWithEvent, SDKEkycResultWithEvent } from '../types/ekycType';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Finos eSign SDK Module
|
|
11
|
+
*
|
|
12
|
+
* A React Native module for eSign (Electronic Signature), SMS OTP, Liveness detection,
|
|
13
|
+
* and Face matching operations. This module excludes NFC, C06, and OCR features.
|
|
14
|
+
*
|
|
15
|
+
* @version Dynamic from package.json
|
|
16
|
+
* @author FinOS
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
export class FinosESignModule {
|
|
20
|
+
private static instance: FinosESignModule;
|
|
21
|
+
private sdk: SDKeKYC;
|
|
22
|
+
private isInitialized: boolean = false;
|
|
23
|
+
private platform: string;
|
|
24
|
+
|
|
25
|
+
private constructor() {
|
|
26
|
+
this.sdk = sdkEKYC;
|
|
27
|
+
this.platform = Platform.OS;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get singleton instance of FinosESignModule
|
|
32
|
+
*/
|
|
33
|
+
public static getInstance(): FinosESignModule {
|
|
34
|
+
if (!FinosESignModule.instance) {
|
|
35
|
+
FinosESignModule.instance = new FinosESignModule();
|
|
36
|
+
}
|
|
37
|
+
return FinosESignModule.instance;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get SDK information
|
|
42
|
+
*/
|
|
43
|
+
public async getSDKInfo(): Promise<{
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
buildNumber: string;
|
|
47
|
+
platform: string;
|
|
48
|
+
isInitialized: boolean;
|
|
49
|
+
}> {
|
|
50
|
+
try {
|
|
51
|
+
const nativeInfo = await this.sdk.getSDKInfo();
|
|
52
|
+
return {
|
|
53
|
+
...nativeInfo,
|
|
54
|
+
platform: this.platform,
|
|
55
|
+
isInitialized: this.isInitialized
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return {
|
|
59
|
+
name: SDK_NAME,
|
|
60
|
+
version: SDK_VERSION,
|
|
61
|
+
buildNumber: '1',
|
|
62
|
+
platform: this.platform,
|
|
63
|
+
isInitialized: this.isInitialized
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the eSign SDK
|
|
70
|
+
* Must be called before using any other methods
|
|
71
|
+
*/
|
|
72
|
+
public async initialize(): Promise<string> {
|
|
73
|
+
try {
|
|
74
|
+
if (this.isInitialized) {
|
|
75
|
+
console.log('✅ SDK already initialized');
|
|
76
|
+
return 'SDK already initialized';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Check if SDK is already initialized on native side
|
|
80
|
+
if (this.sdk.isSDKInitialized()) {
|
|
81
|
+
this.isInitialized = true;
|
|
82
|
+
console.log('✅ SDK already initialized on native side');
|
|
83
|
+
return 'SDK already initialized on native side';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = await this.sdk.initSdkEkyc();
|
|
87
|
+
this.isInitialized = true;
|
|
88
|
+
console.log(`✅ Finos eSign SDK v${SDK_VERSION} initialized successfully`);
|
|
89
|
+
return result;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
// Handle Koin Application already started error
|
|
92
|
+
if (error && error.toString().includes('Koin Application has already been started')) {
|
|
93
|
+
console.log('✅ SDK already initialized (Koin Application started)');
|
|
94
|
+
this.isInitialized = true;
|
|
95
|
+
return 'SDK already initialized (Koin Application started)';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.error('❌ Failed to initialize Finos eSign SDK:', error);
|
|
99
|
+
throw new Error(`SDK initialization failed: ${error}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check if SDK is initialized
|
|
105
|
+
*/
|
|
106
|
+
public isSDKReady(): boolean {
|
|
107
|
+
return this.isInitialized && this.sdk.isSDKInitialized();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ==================== SMS OTP Methods ====================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Send SMS OTP
|
|
114
|
+
* @param config SMS OTP configuration
|
|
115
|
+
*/
|
|
116
|
+
public async sendOtp(config: SmsOtpConfig): Promise<SmsOtpResult> {
|
|
117
|
+
this.validateSDKReady();
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
console.log('📱 Sending SMS OTP...');
|
|
121
|
+
const result = await this.sdk.sendOtp(config);
|
|
122
|
+
console.log('✅ SMS OTP sent successfully');
|
|
123
|
+
return result;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('❌ SMS OTP send failed:', error);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Verify SMS OTP
|
|
132
|
+
* @param config SMS OTP configuration (must include requestId)
|
|
133
|
+
* @param otpCode OTP code from SMS
|
|
134
|
+
*/
|
|
135
|
+
public async verifyOtp(config: SmsOtpConfig, otpCode: string): Promise<SmsOtpResult> {
|
|
136
|
+
this.validateSDKReady();
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
console.log('🔐 Verifying SMS OTP...');
|
|
140
|
+
const result = await this.sdk.verifyOtp(config, otpCode);
|
|
141
|
+
console.log('✅ SMS OTP verified successfully');
|
|
142
|
+
return result;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error('❌ SMS OTP verification failed:', error);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Resend SMS OTP
|
|
151
|
+
* @param config SMS OTP configuration (must include requestId)
|
|
152
|
+
*/
|
|
153
|
+
public async resendOtp(config: SmsOtpConfig): Promise<SmsOtpResult> {
|
|
154
|
+
this.validateSDKReady();
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
console.log('📱 Resending SMS OTP...');
|
|
158
|
+
const result = await this.sdk.resendOtp(config);
|
|
159
|
+
console.log('✅ SMS OTP resent successfully');
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error('❌ SMS OTP resend failed:', error);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// SMS OTP Event Listeners
|
|
168
|
+
public onSmsOtpSendSuccess(callback: (data: SmsOtpResult) => void) {
|
|
169
|
+
const listener = this.sdk.onSmsOtpSendSuccess(callback);
|
|
170
|
+
if (!listener) {
|
|
171
|
+
console.warn('⚠️ onSmsOtpSendSuccess: Event emitter not ready. Make sure SDK is initialized.');
|
|
172
|
+
}
|
|
173
|
+
return listener;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public onSmsOtpVerifySuccess(callback: (data: SmsOtpResult) => void) {
|
|
177
|
+
const listener = this.sdk.onSmsOtpVerifySuccess(callback);
|
|
178
|
+
if (!listener) {
|
|
179
|
+
console.warn('⚠️ onSmsOtpVerifySuccess: Event emitter not ready.');
|
|
180
|
+
}
|
|
181
|
+
return listener;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public onSmsOtpResendSuccess(callback: (data: SmsOtpResult) => void) {
|
|
185
|
+
const listener = this.sdk.onSmsOtpResendSuccess(callback);
|
|
186
|
+
if (!listener) {
|
|
187
|
+
console.warn('⚠️ onSmsOtpResendSuccess: Event emitter not ready.');
|
|
188
|
+
}
|
|
189
|
+
return listener;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public onSmsOtpError(callback: (error: SmsOtpError) => void) {
|
|
193
|
+
const listener = this.sdk.onSmsOtpError(callback);
|
|
194
|
+
if (!listener) {
|
|
195
|
+
console.warn('⚠️ onSmsOtpError: Event emitter not ready.');
|
|
196
|
+
}
|
|
197
|
+
return listener;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ==================== eSign Methods ====================
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Initialize eSign SDK
|
|
204
|
+
*/
|
|
205
|
+
public async initializeESign(): Promise<ESignInitResult> {
|
|
206
|
+
this.validateSDKReady();
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
console.log('🔐 Initializing eSign SDK...');
|
|
210
|
+
const result = await this.sdk.initializeESign();
|
|
211
|
+
console.log('✅ eSign SDK initialized successfully');
|
|
212
|
+
return result;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.error('❌ eSign initialization failed:', error);
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Open eSign session
|
|
221
|
+
* @param accessToken JWT access token (optional if using userEsignModel)
|
|
222
|
+
* @param username Optional username
|
|
223
|
+
* @param rememberMe Remember session
|
|
224
|
+
* @param userEsignModel User info for auto token creation (optional if using accessToken)
|
|
225
|
+
* @param privateKeyFilePath Path to private key file in assets (required if using userEsignModel)
|
|
226
|
+
*/
|
|
227
|
+
public async openSessionId(
|
|
228
|
+
accessToken?: string,
|
|
229
|
+
username?: string,
|
|
230
|
+
rememberMe?: boolean,
|
|
231
|
+
userEsignModel?: UserEsignModel,
|
|
232
|
+
privateKeyFilePath?: string
|
|
233
|
+
): Promise<ESignOpenSessionResult> {
|
|
234
|
+
this.validateSDKReady();
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
console.log('🔓 Opening eSign session...');
|
|
238
|
+
const result = await this.sdk.openSessionId(
|
|
239
|
+
accessToken,
|
|
240
|
+
username,
|
|
241
|
+
rememberMe,
|
|
242
|
+
userEsignModel,
|
|
243
|
+
privateKeyFilePath
|
|
244
|
+
);
|
|
245
|
+
console.log('✅ eSign session opened successfully');
|
|
246
|
+
return result;
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error('❌ eSign session open failed:', error);
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Register device for eSign
|
|
255
|
+
* @param recoverCode 8-digit recovery code
|
|
256
|
+
* @param pinCode 6-digit PIN code
|
|
257
|
+
* @param fcmToken Optional FCM token
|
|
258
|
+
*/
|
|
259
|
+
public async registerDevice(
|
|
260
|
+
recoverCode: string,
|
|
261
|
+
pinCode: string,
|
|
262
|
+
fcmToken?: string
|
|
263
|
+
): Promise<{ code: string; message: string }> {
|
|
264
|
+
this.validateSDKReady();
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
console.log('📱 Registering eSign device...');
|
|
268
|
+
const result = await this.sdk.registerDevice(recoverCode, pinCode, fcmToken);
|
|
269
|
+
console.log('✅ eSign device registered successfully');
|
|
270
|
+
return result;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error('❌ eSign device registration failed:', error);
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* List eSign certificates
|
|
279
|
+
* @param pageNumber Page number (default: 1)
|
|
280
|
+
* @param pageSize Page size (default: 10)
|
|
281
|
+
*/
|
|
282
|
+
public async listCerts(
|
|
283
|
+
pageNumber: number = 1,
|
|
284
|
+
pageSize: number = 10
|
|
285
|
+
): Promise<{ certs: ESignCertificate[] }> {
|
|
286
|
+
this.validateSDKReady();
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
console.log('📋 Listing eSign certificates...');
|
|
290
|
+
const result = await this.sdk.listCerts(pageNumber, pageSize);
|
|
291
|
+
console.log(`✅ Found ${result.certs.length} certificates`);
|
|
292
|
+
return result;
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.error('❌ eSign list certificates failed:', error);
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Verify eSign certificate
|
|
301
|
+
* @param serial Certificate serial number
|
|
302
|
+
*/
|
|
303
|
+
public async verifyCert(serial: string): Promise<{ code: string; message: string }> {
|
|
304
|
+
this.validateSDKReady();
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
console.log('✅ Verifying eSign certificate...');
|
|
308
|
+
const result = await this.sdk.verifyCert(serial);
|
|
309
|
+
console.log('✅ eSign certificate verified successfully');
|
|
310
|
+
return result;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
console.error('❌ eSign certificate verification failed:', error);
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* List eSign sign requests
|
|
319
|
+
* @param pageNumber Page number (default: 1)
|
|
320
|
+
* @param pageSize Page size (default: 10)
|
|
321
|
+
*/
|
|
322
|
+
public async listSignRequest(
|
|
323
|
+
pageNumber: number = 1,
|
|
324
|
+
pageSize: number = 10
|
|
325
|
+
): Promise<{ requests: ESignSignRequest[] }> {
|
|
326
|
+
this.validateSDKReady();
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
console.log('📋 Listing eSign sign requests...');
|
|
330
|
+
const result = await this.sdk.listSignRequest(pageNumber, pageSize);
|
|
331
|
+
console.log(`✅ Found ${result.requests.length} sign requests`);
|
|
332
|
+
return result;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
console.error('❌ eSign list sign requests failed:', error);
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Confirm eSign signature
|
|
341
|
+
* @param signRequestId Sign request ID
|
|
342
|
+
* @param pinCode 6-digit PIN code
|
|
343
|
+
* @param authId Optional auth ID
|
|
344
|
+
* @param authData Optional auth data
|
|
345
|
+
* @param confirm Confirm the signature (default: true)
|
|
346
|
+
*/
|
|
347
|
+
public async confirmSign(
|
|
348
|
+
signRequestId: string,
|
|
349
|
+
pinCode: string,
|
|
350
|
+
authId?: string,
|
|
351
|
+
authData?: string,
|
|
352
|
+
confirm: boolean = true
|
|
353
|
+
): Promise<{ code: string; message: string }> {
|
|
354
|
+
this.validateSDKReady();
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
console.log('✍️ Confirming eSign signature...');
|
|
358
|
+
const result = await this.sdk.confirmSign(signRequestId, pinCode, authId, authData, confirm);
|
|
359
|
+
console.log('✅ eSign signature confirmed successfully');
|
|
360
|
+
return result;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error('❌ eSign signature confirmation failed:', error);
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Authenticate with eSign
|
|
369
|
+
* @param username eSign username
|
|
370
|
+
* @param password eSign password
|
|
371
|
+
*/
|
|
372
|
+
public async authenticate(
|
|
373
|
+
username: string,
|
|
374
|
+
password: string
|
|
375
|
+
): Promise<ESignAuthenticateResult> {
|
|
376
|
+
this.validateSDKReady();
|
|
377
|
+
|
|
378
|
+
try {
|
|
379
|
+
console.log('🔐 Authenticating with eSign...');
|
|
380
|
+
const result = await this.sdk.authenticate(username, password);
|
|
381
|
+
console.log('✅ eSign authentication successful');
|
|
382
|
+
return result;
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error('❌ eSign authentication failed:', error);
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Register remote signing certificate
|
|
391
|
+
* @param accessToken JWT access token
|
|
392
|
+
* @param requestJson JSON request body
|
|
393
|
+
*/
|
|
394
|
+
public async registerRemoteSigning(
|
|
395
|
+
accessToken: string,
|
|
396
|
+
requestJson: string
|
|
397
|
+
): Promise<{ response: string }> {
|
|
398
|
+
this.validateSDKReady();
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
console.log('📝 Registering remote signing certificate...');
|
|
402
|
+
const result = await this.sdk.registerRemoteSigning(accessToken, requestJson);
|
|
403
|
+
console.log('✅ Remote signing certificate registered successfully');
|
|
404
|
+
return result;
|
|
405
|
+
} catch (error) {
|
|
406
|
+
console.error('❌ Remote signing certificate registration failed:', error);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Sign PDF document
|
|
413
|
+
* @param accessToken JWT access token
|
|
414
|
+
* @param requestJson JSON request body
|
|
415
|
+
*/
|
|
416
|
+
public async signPdf(
|
|
417
|
+
accessToken: string,
|
|
418
|
+
requestJson: string
|
|
419
|
+
): Promise<{ response: string }> {
|
|
420
|
+
this.validateSDKReady();
|
|
421
|
+
|
|
422
|
+
try {
|
|
423
|
+
console.log('📄 Signing PDF document...');
|
|
424
|
+
const result = await this.sdk.signPdf(accessToken, requestJson);
|
|
425
|
+
console.log('✅ PDF document signed successfully');
|
|
426
|
+
return result;
|
|
427
|
+
} catch (error) {
|
|
428
|
+
console.error('❌ PDF document signing failed:', error);
|
|
429
|
+
throw error;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Send confirmation document
|
|
435
|
+
* @param accessToken JWT access token
|
|
436
|
+
* @param requestJson JSON string containing request data
|
|
437
|
+
*/
|
|
438
|
+
public async sendConfirmationDocument(
|
|
439
|
+
accessToken: string,
|
|
440
|
+
requestJson: string
|
|
441
|
+
): Promise<{ response: string }> {
|
|
442
|
+
this.validateSDKReady();
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
console.log('📧 Sending confirmation document...');
|
|
446
|
+
const result = await this.sdk.sendConfirmationDocument(accessToken, requestJson);
|
|
447
|
+
console.log('✅ Confirmation document sent successfully');
|
|
448
|
+
return result;
|
|
449
|
+
} catch (error) {
|
|
450
|
+
console.error('❌ Confirmation document sending failed:', error);
|
|
451
|
+
throw error;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Remove all event listeners
|
|
457
|
+
*/
|
|
458
|
+
public removeAllListeners(): void {
|
|
459
|
+
this.sdk.removeAllListeners();
|
|
460
|
+
console.log('🧹 All event listeners removed');
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// eSign Event Listeners
|
|
464
|
+
public onESignInitSuccess(callback: (data: ESignInitResult) => void) {
|
|
465
|
+
const listener = this.sdk.onESignInitSuccess(callback);
|
|
466
|
+
if (!listener) {
|
|
467
|
+
console.warn('⚠️ onESignInitSuccess: Event emitter not ready. Make sure SDK is initialized.');
|
|
468
|
+
}
|
|
469
|
+
return listener;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
public onESignOpenSessionSuccess(callback: (data: ESignOpenSessionResult) => void) {
|
|
473
|
+
const listener = this.sdk.onESignOpenSessionSuccess(callback);
|
|
474
|
+
if (!listener) {
|
|
475
|
+
console.warn('⚠️ onESignOpenSessionSuccess: Event emitter not ready.');
|
|
476
|
+
}
|
|
477
|
+
return listener;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
public onESignRegisterDeviceSuccess(callback: (data: { code: string; message: string }) => void) {
|
|
481
|
+
const listener = this.sdk.onESignRegisterDeviceSuccess(callback);
|
|
482
|
+
if (!listener) {
|
|
483
|
+
console.warn('⚠️ onESignRegisterDeviceSuccess: Event emitter not ready.');
|
|
484
|
+
}
|
|
485
|
+
return listener;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
public onESignListCertsSuccess(callback: (data: { certs: ESignCertificate[] }) => void) {
|
|
489
|
+
const listener = this.sdk.onESignListCertsSuccess(callback);
|
|
490
|
+
if (!listener) {
|
|
491
|
+
console.warn('⚠️ onESignListCertsSuccess: Event emitter not ready.');
|
|
492
|
+
}
|
|
493
|
+
return listener;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
public onESignVerifyCertSuccess(callback: (data: { code: string; message: string }) => void) {
|
|
497
|
+
const listener = this.sdk.onESignVerifyCertSuccess(callback);
|
|
498
|
+
if (!listener) {
|
|
499
|
+
console.warn('⚠️ onESignVerifyCertSuccess: Event emitter not ready.');
|
|
500
|
+
}
|
|
501
|
+
return listener;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
public onESignListSignRequestSuccess(callback: (data: { requests: ESignSignRequest[] }) => void) {
|
|
505
|
+
const listener = this.sdk.onESignListSignRequestSuccess(callback);
|
|
506
|
+
if (!listener) {
|
|
507
|
+
console.warn('⚠️ onESignListSignRequestSuccess: Event emitter not ready.');
|
|
508
|
+
}
|
|
509
|
+
return listener;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
public onESignConfirmSignSuccess(callback: (data: { code: string; message: string }) => void) {
|
|
513
|
+
const listener = this.sdk.onESignConfirmSignSuccess(callback);
|
|
514
|
+
if (!listener) {
|
|
515
|
+
console.warn('⚠️ onESignConfirmSignSuccess: Event emitter not ready.');
|
|
516
|
+
}
|
|
517
|
+
return listener;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
public onESignAuthenticateSuccess(callback: (data: ESignAuthenticateResult) => void) {
|
|
521
|
+
const listener = this.sdk.onESignAuthenticateSuccess(callback);
|
|
522
|
+
if (!listener) {
|
|
523
|
+
console.warn('⚠️ onESignAuthenticateSuccess: Event emitter not ready.');
|
|
524
|
+
}
|
|
525
|
+
return listener;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
public onESignRegisterRemoteSigningSuccess(callback: (data: { response: string }) => void) {
|
|
529
|
+
const listener = this.sdk.onESignRegisterRemoteSigningSuccess(callback);
|
|
530
|
+
if (!listener) {
|
|
531
|
+
console.warn('⚠️ onESignRegisterRemoteSigningSuccess: Event emitter not ready.');
|
|
532
|
+
}
|
|
533
|
+
return listener;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
public onESignSignPdfSuccess(callback: (data: { response: string }) => void) {
|
|
537
|
+
const listener = this.sdk.onESignSignPdfSuccess(callback);
|
|
538
|
+
if (!listener) {
|
|
539
|
+
console.warn('⚠️ onESignSignPdfSuccess: Event emitter not ready.');
|
|
540
|
+
}
|
|
541
|
+
return listener;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
public onESignSendConfirmationDocumentSuccess(callback: (data: { response: string }) => void) {
|
|
545
|
+
const listener = this.sdk.onESignSendConfirmationDocumentSuccess(callback);
|
|
546
|
+
if (!listener) {
|
|
547
|
+
console.warn('⚠️ onESignSendConfirmationDocumentSuccess: Event emitter not ready.');
|
|
548
|
+
}
|
|
549
|
+
return listener;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
public onESignError(callback: (error: ESignError) => void) {
|
|
553
|
+
const listener = this.sdk.onESignError(callback);
|
|
554
|
+
if (!listener) {
|
|
555
|
+
console.warn('⚠️ onESignError: Event emitter not ready.');
|
|
556
|
+
}
|
|
557
|
+
return listener;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// ==================== Liveness Methods ====================
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Start liveness detection
|
|
564
|
+
* @param config Liveness configuration (includes switchFrontCamera for camera control)
|
|
565
|
+
*/
|
|
566
|
+
public async startLiveness(config: LivenessConfig): Promise<SDKEkycResultStringWithEvent> {
|
|
567
|
+
this.validateSDKReady();
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
console.log('👁️ Starting liveness detection...');
|
|
571
|
+
if (config.switchFrontCamera !== undefined) {
|
|
572
|
+
console.log('📷 Front camera setting:', config.switchFrontCamera ? 'ON' : 'OFF');
|
|
573
|
+
}
|
|
574
|
+
const result = await this.sdk.startLiveness(config);
|
|
575
|
+
console.log('✅ Liveness detection completed:', result.event);
|
|
576
|
+
return result;
|
|
577
|
+
} catch (error) {
|
|
578
|
+
console.error('❌ Liveness detection failed:', error);
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Liveness Event Listeners
|
|
584
|
+
public onLivenessSuccess(callback: (data: SDKEkycResultStringWithEvent) => void) {
|
|
585
|
+
return this.sdk.onLivenessSuccess(callback);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
public onLivenessError(callback: (error: any) => void) {
|
|
589
|
+
return this.sdk.onLivenessError(callback);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// ==================== Face Service Methods ====================
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Start face comparison
|
|
596
|
+
* @param config Face service configuration
|
|
597
|
+
*/
|
|
598
|
+
public async startFaceCompare(config: FaceServiceConfig): Promise<SDKEkycResultStringWithEvent> {
|
|
599
|
+
this.validateSDKReady();
|
|
600
|
+
|
|
601
|
+
try {
|
|
602
|
+
console.log('👤 Starting face comparison...');
|
|
603
|
+
const result = await this.sdk.startFaceCompare(config);
|
|
604
|
+
console.log('✅ Face comparison completed:', result.event);
|
|
605
|
+
return result;
|
|
606
|
+
} catch (error) {
|
|
607
|
+
console.error('❌ Face comparison failed:', error);
|
|
608
|
+
throw error;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Face Compare Event Listeners
|
|
613
|
+
public onFaceCompareSuccess(callback: (data: SDKEkycResultWithEvent) => void) {
|
|
614
|
+
return this.sdk.onFaceCompareSuccess(callback);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
public onFaceCompareError(callback: (error: any) => void) {
|
|
618
|
+
return this.sdk.onFaceCompareError(callback);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// ==================== eKYC UI Methods ====================
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Start eKYC UI with flow (excluding NFC, C06, OCR)
|
|
625
|
+
* Only supports LIVENESS and FACE in flowSDK array
|
|
626
|
+
* @param appKey Main app key
|
|
627
|
+
* @param flowSDK Array of SDK types (only 'LIVENESS' and 'FACE' are allowed)
|
|
628
|
+
* @param language Language code (vi/en)
|
|
629
|
+
* @param transactionId Transaction ID
|
|
630
|
+
* @param appKeyConfig App key configuration
|
|
631
|
+
* @param optionConfig Optional configuration settings (includes switchFrontCamera for camera control)
|
|
632
|
+
* @param styleConfig Optional style configuration
|
|
633
|
+
*/
|
|
634
|
+
public async startEkycUI(
|
|
635
|
+
appKey: string,
|
|
636
|
+
flowSDK: string[],
|
|
637
|
+
language: string,
|
|
638
|
+
transactionId: string,
|
|
639
|
+
appKeyConfig: {
|
|
640
|
+
appKey: string;
|
|
641
|
+
appKeyLiveness: string;
|
|
642
|
+
appKeyFaceService: string;
|
|
643
|
+
},
|
|
644
|
+
optionConfig?: {
|
|
645
|
+
baseUrl?: string;
|
|
646
|
+
countMaxRetry?: number;
|
|
647
|
+
language?: string;
|
|
648
|
+
switchFrontCamera?: boolean;
|
|
649
|
+
},
|
|
650
|
+
styleConfig?: {
|
|
651
|
+
textSize?: number;
|
|
652
|
+
textFont?: string;
|
|
653
|
+
textColor?: number;
|
|
654
|
+
statusBarBackground?: number;
|
|
655
|
+
backIcon?: number;
|
|
656
|
+
titleStyle?: {
|
|
657
|
+
textSize?: number;
|
|
658
|
+
textFont?: string;
|
|
659
|
+
textColor?: number;
|
|
660
|
+
};
|
|
661
|
+
toolbarStyle?: {
|
|
662
|
+
textSize?: number;
|
|
663
|
+
textFont?: string;
|
|
664
|
+
textColor?: number;
|
|
665
|
+
};
|
|
666
|
+
instructionStyle?: {
|
|
667
|
+
textSize?: number;
|
|
668
|
+
textFont?: string;
|
|
669
|
+
textColor?: number;
|
|
670
|
+
};
|
|
671
|
+
errorStyle?: {
|
|
672
|
+
textSize?: number;
|
|
673
|
+
textFont?: string;
|
|
674
|
+
textColor?: number;
|
|
675
|
+
};
|
|
676
|
+
successStyle?: {
|
|
677
|
+
textSize?: number;
|
|
678
|
+
textFont?: string;
|
|
679
|
+
textColor?: number;
|
|
680
|
+
};
|
|
681
|
+
warningStyle?: {
|
|
682
|
+
textSize?: number;
|
|
683
|
+
textFont?: string;
|
|
684
|
+
textColor?: number;
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
): Promise<any> {
|
|
688
|
+
this.validateSDKReady();
|
|
689
|
+
|
|
690
|
+
// Validate flowSDK - only allow LIVENESS and FACE
|
|
691
|
+
const allowedTypes = ['LIVENESS', 'FACE'];
|
|
692
|
+
const invalidTypes = flowSDK.filter(type => !allowedTypes.includes(type));
|
|
693
|
+
if (invalidTypes.length > 0) {
|
|
694
|
+
throw new Error(`Invalid SDK types in flowSDK: ${invalidTypes.join(', ')}. Only 'LIVENESS' and 'FACE' are allowed in FinosESignModule.`);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (flowSDK.length === 0) {
|
|
698
|
+
throw new Error('flowSDK must contain at least one SDK type (LIVENESS or FACE)');
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
try {
|
|
702
|
+
console.log('🚀 Starting eKYC UI with flow:', flowSDK);
|
|
703
|
+
console.log('🔧 OptionConfig:', optionConfig);
|
|
704
|
+
if (optionConfig?.switchFrontCamera !== undefined) {
|
|
705
|
+
console.log('📷 Front camera setting:', optionConfig.switchFrontCamera ? 'ON' : 'OFF');
|
|
706
|
+
}
|
|
707
|
+
console.log('🔑 AppKeyConfig:', appKeyConfig);
|
|
708
|
+
console.log('🎨 StyleConfig:', styleConfig);
|
|
709
|
+
|
|
710
|
+
// Create full appKeyConfig with empty values for excluded modules
|
|
711
|
+
const fullAppKeyConfig = {
|
|
712
|
+
appKey: appKeyConfig.appKey,
|
|
713
|
+
appKeyNfc: '',
|
|
714
|
+
appKeyOcr: '',
|
|
715
|
+
appKeyLiveness: appKeyConfig.appKeyLiveness,
|
|
716
|
+
appKeyC06: '',
|
|
717
|
+
appKeyFaceService: appKeyConfig.appKeyFaceService,
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
const result = await this.sdk.startEkycUI(
|
|
721
|
+
appKey,
|
|
722
|
+
flowSDK,
|
|
723
|
+
language,
|
|
724
|
+
transactionId,
|
|
725
|
+
fullAppKeyConfig,
|
|
726
|
+
optionConfig,
|
|
727
|
+
styleConfig
|
|
728
|
+
);
|
|
729
|
+
console.log('✅ eKYC UI started successfully');
|
|
730
|
+
return result;
|
|
731
|
+
} catch (error) {
|
|
732
|
+
console.error('❌ eKYC UI failed:', error);
|
|
733
|
+
throw error;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// Private validation methods
|
|
738
|
+
private validateSDKReady(): void {
|
|
739
|
+
if (!this.isSDKReady()) {
|
|
740
|
+
throw new Error('SDK is not initialized. Please call initialize() first.');
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Export singleton instance - ensure it's always initialized
|
|
746
|
+
let _finosESignInstance: FinosESignModule | null = null;
|
|
747
|
+
|
|
748
|
+
const getFinosESignInstance = (): FinosESignModule => {
|
|
749
|
+
if (!_finosESignInstance) {
|
|
750
|
+
try {
|
|
751
|
+
_finosESignInstance = FinosESignModule.getInstance();
|
|
752
|
+
} catch (error) {
|
|
753
|
+
console.error('Failed to initialize FinosESignModule:', error);
|
|
754
|
+
throw new Error('FinosESignModule initialization failed. Please check native module setup.');
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return _finosESignInstance;
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// Initialize immediately
|
|
761
|
+
try {
|
|
762
|
+
_finosESignInstance = FinosESignModule.getInstance();
|
|
763
|
+
} catch (error) {
|
|
764
|
+
// Silent initialization - will be created on first access
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Helper to check if a property is a method on FinosESignModule
|
|
768
|
+
const isMethod = (prop: string | symbol): boolean => {
|
|
769
|
+
if (typeof prop !== 'string') return false;
|
|
770
|
+
// Check if it's a known method from the class
|
|
771
|
+
const prototype = FinosESignModule.prototype as any;
|
|
772
|
+
return typeof prototype[prop] === 'function' ||
|
|
773
|
+
prop.startsWith('on') ||
|
|
774
|
+
prop === 'initialize' ||
|
|
775
|
+
prop === 'initializeESign' ||
|
|
776
|
+
prop === 'sendOtp' ||
|
|
777
|
+
prop === 'verifyOtp' ||
|
|
778
|
+
prop === 'resendOtp' ||
|
|
779
|
+
prop === 'openSessionId' ||
|
|
780
|
+
prop === 'registerDevice' ||
|
|
781
|
+
prop === 'listCerts' ||
|
|
782
|
+
prop === 'verifyCert' ||
|
|
783
|
+
prop === 'listSignRequest' ||
|
|
784
|
+
prop === 'confirmSign' ||
|
|
785
|
+
prop === 'authenticate' ||
|
|
786
|
+
prop === 'registerRemoteSigning' ||
|
|
787
|
+
prop === 'signPdf' ||
|
|
788
|
+
prop === 'sendConfirmationDocument' ||
|
|
789
|
+
prop === 'startLiveness' ||
|
|
790
|
+
prop === 'startFaceCompare' ||
|
|
791
|
+
prop === 'startEkycUI';
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
// Create a safe wrapper using Proxy - ensure it's always an object
|
|
795
|
+
const createFinosESignProxy = (): FinosESignModule => {
|
|
796
|
+
try {
|
|
797
|
+
return new Proxy({} as FinosESignModule, {
|
|
798
|
+
get(_target, prop) {
|
|
799
|
+
try {
|
|
800
|
+
const instance = getFinosESignInstance();
|
|
801
|
+
const value = (instance as any)[prop];
|
|
802
|
+
if (typeof value === 'function') {
|
|
803
|
+
return value.bind(instance);
|
|
804
|
+
}
|
|
805
|
+
return value;
|
|
806
|
+
} catch (error) {
|
|
807
|
+
console.warn(`⚠️ FinosESign.${String(prop)} is not available:`, error);
|
|
808
|
+
// Always return a function for methods to prevent "undefined" errors
|
|
809
|
+
if (isMethod(prop)) {
|
|
810
|
+
// For event listeners (on* methods), return a function that returns null
|
|
811
|
+
if (typeof prop === 'string' && prop.startsWith('on')) {
|
|
812
|
+
return (callback?: any) => {
|
|
813
|
+
console.warn(`⚠️ FinosESign.${prop} called but module is not initialized`);
|
|
814
|
+
return null;
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
// For other methods, return a no-op async function
|
|
818
|
+
return async (...args: any[]) => {
|
|
819
|
+
console.warn(`⚠️ FinosESign.${String(prop)} called but module is not initialized`);
|
|
820
|
+
throw new Error(`FinosESign.${String(prop)} is not available. Module may not be initialized.`);
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
return undefined;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
} catch (error) {
|
|
828
|
+
console.error('❌ Failed to create FinosESign proxy:', error);
|
|
829
|
+
// Return a comprehensive stub object
|
|
830
|
+
return createFinosESignStub();
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
// Create a comprehensive stub object with all methods to prevent undefined errors
|
|
835
|
+
const createFinosESignStub = (): FinosESignModule => {
|
|
836
|
+
const stub = {} as any;
|
|
837
|
+
|
|
838
|
+
// Add all event listener methods (on* methods)
|
|
839
|
+
const eventListenerMethods = [
|
|
840
|
+
'onSmsOtpSendSuccess', 'onSmsOtpVerifySuccess', 'onSmsOtpResendSuccess', 'onSmsOtpError',
|
|
841
|
+
'onESignInitSuccess', 'onESignOpenSessionSuccess', 'onESignRegisterDeviceSuccess',
|
|
842
|
+
'onESignListCertsSuccess', 'onESignVerifyCertSuccess', 'onESignListSignRequestSuccess',
|
|
843
|
+
'onESignConfirmSignSuccess', 'onESignAuthenticateSuccess', 'onESignRegisterRemoteSigningSuccess',
|
|
844
|
+
'onESignSignPdfSuccess', 'onESignSendConfirmationDocumentSuccess', 'onESignError',
|
|
845
|
+
'onLivenessSuccess', 'onLivenessError', 'onFaceCompareSuccess', 'onFaceCompareError'
|
|
846
|
+
];
|
|
847
|
+
|
|
848
|
+
eventListenerMethods.forEach(method => {
|
|
849
|
+
stub[method] = (callback?: any) => {
|
|
850
|
+
console.warn(`⚠️ FinosESign.${method} called but module is not initialized`);
|
|
851
|
+
return null;
|
|
852
|
+
};
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
// Add all other methods
|
|
856
|
+
const otherMethods = [
|
|
857
|
+
'initialize', 'initializeESign', 'sendOtp', 'verifyOtp', 'resendOtp',
|
|
858
|
+
'openSessionId', 'registerDevice', 'listCerts', 'verifyCert', 'listSignRequest',
|
|
859
|
+
'confirmSign', 'authenticate', 'registerRemoteSigning', 'signPdf', 'sendConfirmationDocument',
|
|
860
|
+
'startLiveness', 'startFaceCompare', 'startEkycUI', 'isSDKReady', 'getSDKInfo'
|
|
861
|
+
];
|
|
862
|
+
|
|
863
|
+
otherMethods.forEach(method => {
|
|
864
|
+
stub[method] = async (...args: any[]) => {
|
|
865
|
+
console.warn(`⚠️ FinosESign.${method} called but module is not initialized`);
|
|
866
|
+
throw new Error(`FinosESign.${method} is not available. Module may not be initialized.`);
|
|
867
|
+
};
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
return stub as FinosESignModule;
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// Create a wrapper that always returns a valid object
|
|
874
|
+
// This ensures FinosESign is NEVER undefined and always has all methods
|
|
875
|
+
const createFinosESignWrapper = (): FinosESignModule => {
|
|
876
|
+
// Always start with stub to ensure all methods exist
|
|
877
|
+
const stub = createFinosESignStub();
|
|
878
|
+
const wrapper = { ...stub } as any;
|
|
879
|
+
|
|
880
|
+
// Try to get real instance and override methods
|
|
881
|
+
try {
|
|
882
|
+
const realInstance = getFinosESignInstance();
|
|
883
|
+
|
|
884
|
+
// Override with real instance methods
|
|
885
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(realInstance)).forEach(key => {
|
|
886
|
+
if (key !== 'constructor' && typeof (realInstance as any)[key] === 'function') {
|
|
887
|
+
wrapper[key] = ((realInstance as any)[key]).bind(realInstance);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
// Also copy any own properties from real instance
|
|
892
|
+
Object.keys(realInstance).forEach(key => {
|
|
893
|
+
if ((realInstance as any)[key] !== undefined) {
|
|
894
|
+
wrapper[key] = (realInstance as any)[key];
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
} catch (error) {
|
|
898
|
+
// If we can't get instance, wrapper already has all stub methods
|
|
899
|
+
// No need to do anything
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return wrapper as FinosESignModule;
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
// Export - this ensures FinosESign is never undefined
|
|
906
|
+
export const FinosESign = createFinosESignWrapper();
|
|
907
|
+
|
|
908
|
+
// Export types
|
|
909
|
+
export type { SmsOtpConfig, SmsOtpResult, SmsOtpError } from '../types/ekycSmsOtpType';
|
|
910
|
+
export type { UserEsignModel, ESignInitResult, ESignOpenSessionResult, ESignCertificate, ESignSignRequest, ESignError, ESignAuthenticateResult } from '../types/ekycESignType';
|
|
911
|
+
export type { LivenessConfig } from '../types/ekycLivenessType';
|
|
912
|
+
export type { FaceServiceConfig } from '../types/ekycFaceType';
|
|
913
|
+
export type { SDKEkycResultStringWithEvent, SDKEkycResultWithEvent } from '../types/ekycType';
|
|
914
|
+
|
|
915
|
+
// Export constants
|
|
916
|
+
export { SDK_VERSION, SDK_NAME };
|
|
917
|
+
|
|
918
|
+
// Default export
|
|
919
|
+
export default FinosESign;
|