import { logger } from '.' ; export interface KeychainCredential { account : string ; password : string ; } export interface Keychain { deletePassword : ( account : string ) => Promise < boolean > ; findCredentials : ( ) => Promise < KeychainCredential [ ] > ; setPassword : ( account : string , password : string ) => Promise < void > ; } interface Keytar { deletePassword : ( service : string , account : string ) => Promise < boolean > ; findCredentials : ( service : string ) => Promise < KeychainCredential [ ] > ; setPassword : ( service : string , account : string , password : string ) => Promise < void > ; } /**
 * Keytar is required optionally and so may not exist.
 * It will throw an error if a local installation is not found.
 */ export const _getKeytar = ( ) : Keytar => { try { return require ( 'keytar' ) ; } catch ( e ) { if ( ! process . env . CI ) { logger . debug ( 'Failed to require keytar' , e ) ; } } throw new Error ( 'Optional dependency keytar was not installed' ) ; } ; param service export default function keychain ( service ) { const keytar = _getKeytar ( ) ; return { deletePassword : async ( account ) => keytar . deletePassword ( service , account ) , findCredentials : async ( ) => keytar . findCredentials ( service ) , setPassword : async ( account , password ) => keytar . setPassword ( service , account , password ) , } ; }