diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js --- a/native/crypto/olm-api.js +++ b/native/crypto/olm-api.js @@ -14,10 +14,20 @@ import { commCoreModule } from '../native-modules.js'; -const olmAPI: OlmAPI = { - async initializeCryptoAccount(): Promise { +let currentInitializeCryptoAccountPromise: ?Promise; +function initializeCryptoAccount(): Promise { + if (currentInitializeCryptoAccountPromise) { + return currentInitializeCryptoAccountPromise; + } + currentInitializeCryptoAccountPromise = (async () => { await commCoreModule.initializeCryptoAccount(); - }, + currentInitializeCryptoAccountPromise = null; + })(); + return currentInitializeCryptoAccountPromise; +} + +const olmAPI: OlmAPI = { + initializeCryptoAccount, getUserPublicKey: commCoreModule.getUserPublicKey, encrypt: commCoreModule.encrypt, encryptAndPersist: commCoreModule.encryptAndPersist,