import keystore from 'keystore-idb' import RSAKeyStore from 'keystore-idb/rsa/keystore' import { CryptoSystem } from 'keystore-idb/types' const KEYSTORE_CFG = { type: CryptoSystem.RSA } let ks: RSAKeyStore | null = null export const clear = async (): Promise => { ks = await get() await ks.destroy() ks = null } export const create = async (): Promise => { return (await keystore.init(KEYSTORE_CFG)) as RSAKeyStore } export const set = async (userKeystore: RSAKeyStore): Promise => { ks = userKeystore } export const get = async (): Promise => { if (ks) return ks ks = (await keystore.init(KEYSTORE_CFG)) as RSAKeyStore return ks }