import { RSA } from '@joplin/lib/services/e2ee/types' ; const RnRSA = require ( 'react-native-rsa-native' ) . RSA ; interface RSAKeyPair { public : string ; private : string ; } const rsa = { generateKeyPair : async ( keySize ) : Promise < RSAKeyPair > => { const keys = await RnRSA . generateKeys ( keySize ) ; if ( ! keys . private ) throw new Error ( 'No private key was generated' ) ; if ( ! keys . public ) throw new Error ( 'No public key was generated' ) ; return keys ; } , loadKeys : async ( publicKey , privateKey ) : Promise < RSAKeyPair > => { return { public : publicKey , private : privateKey } ; } , encrypt : async ( plaintextUtf8 , rsaKeyPair ) : Promise < string > => { return RnRSA . encrypt ( plaintextUtf8 , rsaKeyPair . public ) ; } , decrypt : async ( ciphertextBase64 , rsaKeyPair ) : Promise < string > => { return RnRSA . decrypt ( ciphertextBase64 , rsaKeyPair . private ) ; } , publicKey : ( rsaKeyPair ) : string => { return rsaKeyPair . public ; } , privateKey : ( rsaKeyPair ) : string => { return rsaKeyPair . private ; } , } ; export default rsa ;