UNPKG

@sbaiahmed1/react-native-biometrics

Version:

React Native biometric authentication library for iOS and Android. Easy integration of Face ID, Touch ID, and Fingerprint authentication with TypeScript support. Compatible with new architecture (TurboModules) and Expo. Secure mobile login solution.

299 lines (289 loc) 9.4 kB
"use strict"; import ReactNativeBiometrics from "./NativeReactNativeBiometrics.js"; import { logger, LogLevel } from "./logger.js"; export function isSensorAvailable() { logger.debug('Checking sensor availability', 'isSensorAvailable'); return ReactNativeBiometrics.isSensorAvailable().then(result => { logger.info('Sensor availability check completed', 'isSensorAvailable', { available: result.available, biometryType: result.biometryType }); return result; }).catch(error => { logger.error('Sensor availability check failed', 'isSensorAvailable', error); throw error; }); } export function simplePrompt(promptMessage) { logger.debug('Starting simple biometric prompt', 'simplePrompt', { promptMessage }); return ReactNativeBiometrics.simplePrompt(promptMessage).then(result => { logger.info('Simple prompt completed', 'simplePrompt', { success: result }); return result; }).catch(error => { logger.error('Simple prompt failed', 'simplePrompt', error, { promptMessage }); throw error; }); } export function authenticateWithOptions(options) { logger.debug('Starting authentication with options', 'authenticateWithOptions', options); return ReactNativeBiometrics.authenticateWithOptions(options).then(result => { logger.info('Authentication completed', 'authenticateWithOptions', { success: result.success, errorCode: result.errorCode }); return result; }).catch(error => { logger.error('Authentication failed', 'authenticateWithOptions', error, options); throw error; }); } export function createKeys(keyAlias) { logger.debug('Creating biometric keys', 'createKeys', { keyAlias }); return ReactNativeBiometrics.createKeys(keyAlias).then(result => { logger.info('Keys created successfully', 'createKeys', { keyAlias, publicKeyLength: result.publicKey?.length }); return result; }).catch(error => { logger.error('Key creation failed', 'createKeys', error, { keyAlias }); throw error; }); } export function deleteKeys(keyAlias) { logger.debug('Deleting biometric keys', 'deleteKeys', { keyAlias }); return ReactNativeBiometrics.deleteKeys(keyAlias).then(result => { logger.info('Keys deletion completed', 'deleteKeys', { keyAlias, success: result.success }); return result; }).catch(error => { logger.error('Key deletion failed', 'deleteKeys', error, { keyAlias }); throw error; }); } export function validateKeyIntegrity(keyAlias) { logger.debug('Validating key integrity', 'validateKeyIntegrity', { keyAlias }); return ReactNativeBiometrics.validateKeyIntegrity(keyAlias).then(result => { logger.info('Key integrity validation completed', 'validateKeyIntegrity', { keyAlias, valid: result.valid, keyExists: result.keyExists, integrityChecks: result.integrityChecks }); return result; }).catch(error => { logger.error('Key integrity validation failed', 'validateKeyIntegrity', error, { keyAlias }); throw error; }); } export function verifyKeySignature(keyAlias = '', data) { logger.debug('Verifying key signature', 'verifyKeySignature', { keyAlias, dataLength: data.length }); return ReactNativeBiometrics.verifyKeySignature(keyAlias, data).then(result => { logger.info('Key signature verification completed', 'verifyKeySignature', { keyAlias, success: result.success, hasSignature: !!result.signature }); return result; }).catch(error => { logger.error('Key signature verification failed', 'verifyKeySignature', error, { keyAlias }); throw error; }); } export function validateSignature(keyAlias = '', data, signature) { logger.debug('Validating signature', 'validateSignature', { keyAlias, dataLength: data.length, signatureLength: signature.length }); return ReactNativeBiometrics.validateSignature(keyAlias, data, signature).then(result => { logger.info('Signature validation completed', 'validateSignature', { keyAlias, valid: result.valid }); return result; }).catch(error => { logger.error('Signature validation failed', 'validateSignature', error, { keyAlias }); throw error; }); } export function getKeyAttributes(keyAlias) { logger.debug('Getting key attributes', 'getKeyAttributes', { keyAlias }); return ReactNativeBiometrics.getKeyAttributes(keyAlias).then(result => { logger.info('Key attributes retrieved', 'getKeyAttributes', { keyAlias, exists: result.exists, attributes: result.attributes }); return result; }).catch(error => { logger.error('Key attributes retrieval failed', 'getKeyAttributes', error, { keyAlias }); throw error; }); } // Key management configuration export function configureKeyAlias(keyAlias) { logger.debug('Configuring key alias', 'configureKeyAlias', { keyAlias }); return ReactNativeBiometrics.configureKeyAlias(keyAlias).then(result => { logger.info('Key alias configured successfully', 'configureKeyAlias', { keyAlias }); return result; }).catch(error => { logger.error('Key alias configuration failed', 'configureKeyAlias', error, { keyAlias }); throw error; }); } export function getDefaultKeyAlias() { logger.debug('Getting default key alias', 'getDefaultKeyAlias'); return ReactNativeBiometrics.getDefaultKeyAlias().then(result => { logger.info('Default key alias retrieved', 'getDefaultKeyAlias', { keyAlias: result }); return result; }).catch(error => { logger.error('Failed to get default key alias', 'getDefaultKeyAlias', error); throw error; }); } export function getAllKeys() { logger.debug('Getting all keys', 'getAllKeys'); return ReactNativeBiometrics.getAllKeys().then(result => { logger.info('All keys retrieved', 'getAllKeys', { keyCount: result.keys?.length || 0 }); return result; }).catch(error => { logger.error('Failed to get all keys', 'getAllKeys', error); throw error; }); } // Debugging utilities export function getDiagnosticInfo() { logger.debug('Getting diagnostic information', 'getDiagnosticInfo'); return ReactNativeBiometrics.getDiagnosticInfo().then(result => { logger.info('Diagnostic information retrieved', 'getDiagnosticInfo', { platform: result.platform, osVersion: result.osVersion, deviceModel: result.deviceModel, biometricCapabilities: result.biometricCapabilities }); return result; }).catch(error => { logger.error('Failed to get diagnostic information', 'getDiagnosticInfo', error); throw error; }); } export function runBiometricTest() { logger.debug('Running biometric test', 'runBiometricTest'); return ReactNativeBiometrics.runBiometricTest().then(result => { logger.info('Biometric test completed', 'runBiometricTest', { success: result.success, errorCount: result.errors?.length || 0, warningCount: result.warnings?.length || 0 }); return result; }).catch(error => { logger.error('Biometric test failed', 'runBiometricTest', error); throw error; }); } export function setDebugMode(enabled) { logger.debug('Setting debug mode', 'setDebugMode', { enabled }); // Enable/disable centralized logging based on debug mode logger.setEnabled(enabled); if (enabled) { logger.setLevel(LogLevel.DEBUG); } else { logger.setLevel(LogLevel.INFO); } return ReactNativeBiometrics.setDebugMode(enabled).then(result => { logger.info('Debug mode updated', 'setDebugMode', { enabled }); return result; }).catch(error => { logger.error('Failed to set debug mode', 'setDebugMode', error, { enabled }); throw error; }); } export function getDeviceIntegrityStatus() { logger.debug('Getting device integrity status', 'getDeviceIntegrityStatus'); return ReactNativeBiometrics.getDeviceIntegrityStatus().then(result => { logger.info('Device integrity status retrieved', 'getDeviceIntegrityStatus', { isCompromised: result.isCompromised, riskLevel: result.riskLevel }); return result; }).catch(error => { logger.error('Failed to get device integrity status', 'getDeviceIntegrityStatus', error); throw error; }); } // Configuration types // Initialize library with configuration export function configure(config) { logger.debug('Configuring library', 'configure', config); if (config.keyAlias) { return configureKeyAlias(config.keyAlias).then(result => { logger.info('Library configuration completed', 'configure', config); return result; }).catch(error => { logger.error('Library configuration failed', 'configure', error, config); throw error; }); } logger.info('Library configuration completed (no key alias)', 'configure', config); return Promise.resolve(); } // Export types for TypeScript users // Export logging utilities export { logger, LogLevel, enableLogging, setLogLevel, configureLogger } from "./logger.js"; // Convenience function to get logs for debugging export function getLogs() { return logger.getLogs(); } // Convenience function to clear logs export function clearLogs() { logger.clearLogs(); } //# sourceMappingURL=index.js.map