import * as RNKeychain from 'react-native-keychain' ; import { Keypair } from 'ssh/keygen' ; import { Token } from 'providers/types/Token' ; import { Server } from 'providers/types/Server' ; export const INITIAL_STATE_KEY = 'INITIAL_STATE_KEY' ; interface State { privacyAccepted : boolean ; providerTokens : Token [ ] ; currentServer : Server | null ; } const Keychain = { setInitialState : ( state ) => { Keychain . set ( INITIAL_STATE_KEY , state ) ; } , getInitialState : async ( ) => { return await Keychain . get ( INITIAL_STATE_KEY ) ; } , setSSHKeyPair : ( name , keypair ) => { Keychain . set ( name , keypair ) ; } , getSSHKeyPair : async ( name ) => { return await Keychain . get ( name ) ; } , set : ( key , value ) => { RNKeychain . setInternetCredentials ( key , '' , JSON . stringify ( value ) ) ; } , get : async ( key ) => { const credentials = await RNKeychain . getInternetCredentials ( key ) ; if ( credentials ) { return JSON . parse ( credentials . password ) ; } return false ; } , } ; export default Keychain ;