@oobit/react-native-sdk 1.0.6 → 1.1.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.
@@ -1,183 +0,0 @@
1
- /**
2
- * Biometric Authentication Utilities
3
- *
4
- * Provides cross-platform biometric authentication for card details access.
5
- * Uses expo-local-authentication which works in Expo Go without native modules.
6
- *
7
- * @requires expo-local-authentication - included in Expo SDK
8
- */
9
-
10
- import * as LocalAuthentication from 'expo-local-authentication';
11
-
12
- /**
13
- * Result of a biometric authentication attempt
14
- */
15
- export interface BiometricResult {
16
- /** Whether authentication was successful */
17
- success: boolean;
18
- /** Error details if authentication failed */
19
- error?: {
20
- reason: 'cancelled' | 'failed' | 'not_available' | 'not_enrolled';
21
- message?: string;
22
- };
23
- }
24
-
25
- /**
26
- * Information about biometric capabilities on the device
27
- */
28
- export interface BiometricAvailability {
29
- /** Whether any biometric authentication is available */
30
- available: boolean;
31
- /** The types of biometry available */
32
- biometryTypes: LocalAuthentication.AuthenticationType[];
33
- }
34
-
35
- /**
36
- * Checks if biometric authentication is available on the device
37
- *
38
- * @returns Object containing availability status and biometry types
39
- */
40
- export async function isBiometricAvailable(): Promise<BiometricAvailability> {
41
- try {
42
- const hasHardware = await LocalAuthentication.hasHardwareAsync();
43
- const isEnrolled = await LocalAuthentication.isEnrolledAsync();
44
- const supportedTypes = await LocalAuthentication.supportedAuthenticationTypesAsync();
45
-
46
- return {
47
- available: hasHardware && isEnrolled,
48
- biometryTypes: supportedTypes,
49
- };
50
- } catch (error) {
51
- console.error('[BiometricUtils] Error checking biometric availability:', error);
52
- return {
53
- available: false,
54
- biometryTypes: [],
55
- };
56
- }
57
- }
58
-
59
- /**
60
- * Prompts the user for biometric authentication
61
- *
62
- * This function should be called before generating session credentials
63
- * for viewing card details. It ensures proper user verification before
64
- * accessing sensitive payment card information.
65
- *
66
- * @param promptMessage - Message to display in the biometric prompt
67
- * @returns Result indicating success or failure with reason
68
- *
69
- * @example
70
- * ```typescript
71
- * const result = await authenticateWithBiometrics('Authenticate to view card details');
72
- * if (result.success) {
73
- * // Proceed with generating session credentials
74
- * } else {
75
- * // Handle failure based on result.error.reason
76
- * }
77
- * ```
78
- */
79
- export async function authenticateWithBiometrics(
80
- promptMessage: string = 'Authenticate to view card details'
81
- ): Promise<BiometricResult> {
82
- try {
83
- // First check if biometrics are available
84
- const hasHardware = await LocalAuthentication.hasHardwareAsync();
85
-
86
- if (!hasHardware) {
87
- console.log('[BiometricUtils] Biometrics not available on device');
88
- return {
89
- success: false,
90
- error: {
91
- reason: 'not_available',
92
- message: 'Biometric authentication is not available on this device',
93
- },
94
- };
95
- }
96
-
97
- // Check if biometrics are enrolled
98
- const isEnrolled = await LocalAuthentication.isEnrolledAsync();
99
-
100
- if (!isEnrolled) {
101
- console.log('[BiometricUtils] No biometrics enrolled');
102
- return {
103
- success: false,
104
- error: {
105
- reason: 'not_enrolled',
106
- message: 'No biometric authentication is set up on this device',
107
- },
108
- };
109
- }
110
-
111
- console.log('[BiometricUtils] Attempting biometric authentication...');
112
-
113
- // Perform the biometric authentication
114
- const result = await LocalAuthentication.authenticateAsync({
115
- promptMessage,
116
- cancelLabel: 'Cancel',
117
- disableDeviceFallback: false, // Allow PIN/password fallback
118
- fallbackLabel: 'Use Passcode',
119
- });
120
-
121
- if (result.success) {
122
- console.log('[BiometricUtils] Biometric authentication successful');
123
- return { success: true };
124
- }
125
-
126
- // Handle various failure reasons
127
- console.log('[BiometricUtils] Biometric authentication failed:', result.error);
128
-
129
- let reason: 'cancelled' | 'failed' | 'not_available' | 'not_enrolled' = 'failed';
130
-
131
- if (result.error === 'user_cancel' || result.error === 'system_cancel') {
132
- reason = 'cancelled';
133
- } else if (result.error === 'not_enrolled') {
134
- reason = 'not_enrolled';
135
- } else if (result.error === 'not_available') {
136
- reason = 'not_available';
137
- }
138
-
139
- return {
140
- success: false,
141
- error: {
142
- reason,
143
- message: result.warning || 'Authentication failed',
144
- },
145
- };
146
- } catch (error) {
147
- console.error('[BiometricUtils] Biometric authentication error:', error);
148
-
149
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
150
-
151
- return {
152
- success: false,
153
- error: {
154
- reason: 'failed',
155
- message: errorMessage,
156
- },
157
- };
158
- }
159
- }
160
-
161
- /**
162
- * Gets a user-friendly description of the biometric type
163
- *
164
- * @param biometryType - The biometry type from the device
165
- * @returns Human-readable string for the biometry type
166
- */
167
- export function getBiometryTypeLabel(
168
- biometryType: LocalAuthentication.AuthenticationType
169
- ): string {
170
- switch (biometryType) {
171
- case LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION:
172
- return 'Face ID';
173
- case LocalAuthentication.AuthenticationType.FINGERPRINT:
174
- return 'Touch ID';
175
- case LocalAuthentication.AuthenticationType.IRIS:
176
- return 'Iris';
177
- default:
178
- return 'Biometric Authentication';
179
- }
180
- }
181
-
182
- // Re-export AuthenticationType for convenience
183
- export { AuthenticationType } from 'expo-local-authentication';