import SInfo from 'react-native-sensitive-info'; import AsyncStorage from '@react-native-async-storage/async-storage'; const _keychainName = 'AuthKeychain'; const _sharedPreferencesName = 'AuthSharedPrefs'; const _privateKey = 'privateKey'; const _publicKey = 'publicKey'; const _pincode = 'pincode'; const _service = 'service'; export class Keychain { static setItem(key: string, item: string) { return SInfo.setItem(key, item, { sharedPreferencesName: _sharedPreferencesName, keychainService: _keychainName, // TODO: remove? // @ts-ignore encrypt: true, }); } static async getItem(key: any) { return SInfo.getItem(key, { sharedPreferencesName: _sharedPreferencesName, keychainService: _keychainName, }); } static deleteItem(key: any) { return SInfo.deleteItem(key, { sharedPreferencesName: _sharedPreferencesName, keychainService: _keychainName, }); } static savePrivateKey(key: string) { Keychain.setItem(_privateKey, key); } static async getPrivateKey() { return Keychain.getItem(_privateKey); } static savePublicKey(key: string) { Keychain.setItem(_publicKey, key); } static async getPublicKey() { return Keychain.getItem(_publicKey); } static savePincode(code: string) { return AsyncStorage.setItem(_pincode, code); } static async getPincode() { return AsyncStorage.getItem(_pincode); } static saveUserId(key: string, value: string) { Keychain.setItem(`${_service}${key}`, value); } static async getUserId(key: string) { return Keychain.getItem(`${_service}${key}`); } static saveUserIdForService(key: string, value: string) { Keychain.setItem(key, value); } static async getUserIdForService(key: string) { return Keychain.getItem(key); } }