UNPKG

@ideem/zsm-react-native

Version:

ZSM makes 2FA easy and invisible for everyone, all the time, using advanced cryptography like MPC to establish cryptographic proof of the origin of any transaction or login attempt, while eliminating opportunities for social engineering. ZSM has no relian

60 lines (55 loc) 2.67 kB
import RelyingPartyBase from './relying-party-base'; import AsyncStorage from '@react-native-async-storage/async-storage'; import ZSMLogger from './zsm-logger'; /** * React Native implementation of RelyingParty with AsyncStorage for identity mapping * This extends the base class and provides platform-specific storage methods */ class RelyingParty extends RelyingPartyBase { /** * React Native implementation of identity mapping storage using AsyncStorage */ async storeIdentityMapping(userId, identityId) { try { const key = `zsm_identity_mapping_${userId}`; await AsyncStorage.setItem(key, identityId); ZSMLogger.debug(`[IDENTITY-MAPPING] Stored mapping: ${userId} -> ${identityId}`); } catch (error) { ZSMLogger.error(`[IDENTITY-MAPPING] Failed to store mapping: ${error.message}`); } } /** * React Native implementation of identity mapping lookup using AsyncStorage */ async lookupIdentityMapping(userId) { try { const key = `zsm_identity_mapping_${userId}`; ZSMLogger.debug(`[IDENTITY-MAPPING] Looking up key: ${key} for user: ${userId}`); // DEBUG: List all stored keys to see what's in AsyncStorage try { const allKeys = await AsyncStorage.getAllKeys(); const identityKeys = allKeys.filter(k => k.startsWith('zsm_identity_mapping_')); ZSMLogger.debug(`[IDENTITY-MAPPING] All stored identity keys: ${JSON.stringify(identityKeys)}`); for (const debugKey of identityKeys) { const debugValue = await AsyncStorage.getItem(debugKey); ZSMLogger.debug(`[IDENTITY-MAPPING] ${debugKey} = ${debugValue}`); } } catch (debugError) { ZSMLogger.error(`[IDENTITY-MAPPING] Debug listing failed: ${debugError.message}`); } const identityId = await AsyncStorage.getItem(key); ZSMLogger.debug(`[IDENTITY-MAPPING] AsyncStorage returned: ${identityId} for key: ${key}`); if (identityId) { ZSMLogger.debug(`[IDENTITY-MAPPING] Found mapping: ${userId} -> ${identityId}`); return identityId; } else { ZSMLogger.debug(`[IDENTITY-MAPPING] No mapping found for ${userId}, returning original`); return userId; } } catch (error) { ZSMLogger.error(`[IDENTITY-MAPPING] Failed to lookup mapping: ${error.message}`); return userId; } } } export default RelyingParty;