UNPKG

@capgo/capacitor-native-biometric

Version:

This plugin gives access to the native biometric apis for android and iOS

110 lines 4.59 kB
import { WebPlugin } from '@capacitor/core'; import { BiometryType, AuthenticationStrength } from './definitions'; export class NativeBiometricWeb extends WebPlugin { constructor() { super(); /** * In-memory credential storage for browser development/testing. * Credentials are stored temporarily and cleared on page refresh. * This is NOT secure storage and should only be used for development purposes. */ this.credentialStore = new Map(); this.dataStore = new Map(); } isAvailable() { // Web platform: return a dummy implementation for development/testing // Using TOUCH_ID as a generic placeholder for simulated biometric authentication return Promise.resolve({ isAvailable: true, authenticationStrength: AuthenticationStrength.STRONG, biometryType: BiometryType.TOUCH_ID, deviceIsSecure: true, strongBiometryIsAvailable: true, }); } // eslint-disable-next-line @typescript-eslint/no-unused-vars async addListener(_eventName, _listener) { // Web platform: no-op, but return a valid handle return { remove: async () => { // Nothing to remove on web }, }; } // eslint-disable-next-line @typescript-eslint/no-unused-vars verifyIdentity(_options) { console.log('verifyIdentity (dummy implementation)'); // Dummy implementation: always succeeds for browser testing return Promise.resolve(); } getCredentials(_options) { console.log('getCredentials (dummy implementation)', { server: _options.server }); const credentials = this.credentialStore.get(_options.server); if (!credentials) { throw new Error('No credentials found for the specified server'); } return Promise.resolve(credentials); } getSecureCredentials(_options) { console.log('getSecureCredentials (dummy implementation)', { server: _options.server }); const credentials = this.credentialStore.get(_options.server); if (!credentials) { throw new Error('No credentials found for the specified server'); } return Promise.resolve(credentials); } setCredentials(_options) { console.log('setCredentials (dummy implementation)', { server: _options.server }); // Dummy implementation: store in memory this.credentialStore.set(_options.server, { username: _options.username, password: _options.password, }); return Promise.resolve(); } deleteCredentials(_options) { console.log('deleteCredentials (dummy implementation)', { server: _options.server }); // Dummy implementation: remove from in-memory store this.credentialStore.delete(_options.server); return Promise.resolve(); } isCredentialsSaved(_options) { console.log('isCredentialsSaved (dummy implementation)', { server: _options.server }); // Dummy implementation: check in-memory store return Promise.resolve({ isSaved: this.credentialStore.has(_options.server) }); } setData(_options) { console.log('setData (dummy implementation)', { key: _options.key }); this.dataStore.set(_options.key, _options.value); return Promise.resolve(); } getData(_options) { console.log('getData (dummy implementation)', { key: _options.key }); const value = this.dataStore.get(_options.key); if (value === undefined) { throw new Error('No data found for the specified key'); } return Promise.resolve({ value }); } getSecureData(_options) { console.log('getSecureData (dummy implementation)', { key: _options.key }); const value = this.dataStore.get(_options.key); if (value === undefined) { throw new Error('No protected data found for the specified key'); } return Promise.resolve({ value }); } deleteData(_options) { console.log('deleteData (dummy implementation)', { key: _options.key }); this.dataStore.delete(_options.key); return Promise.resolve(); } isDataSaved(_options) { console.log('isDataSaved (dummy implementation)', { key: _options.key }); return Promise.resolve({ isSaved: this.dataStore.has(_options.key) }); } async getPluginVersion() { return { version: 'web' }; } } //# sourceMappingURL=web.js.map