diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -18,9 +18,9 @@ type BindServerCallsParams, } from 'lib/utils/action-utils.js'; -import { commCoreModule } from '../native-modules.js'; import { useSelector } from '../redux/redux-utils.js'; import Alert from '../utils/alert.js'; +import { getContentSigningKey } from '../utils/crypto-utils.js'; import { defaultLandingURLPrefix } from '../utils/url-utils.js'; const commSIWE = `${defaultLandingURLPrefix}/siwe`; @@ -79,10 +79,7 @@ setNonce(response); })(), ); - await commCoreModule.initializeCryptoAccount(); - const { - primaryIdentityPublicKeys: { ed25519 }, - } = await commCoreModule.getUserPublicKey(); + const ed25519 = await getContentSigningKey(); setPrimaryIdentityPublicKey(ed25519); })(); }, [dispatchActionPromise, getSIWENonceCall]); diff --git a/native/backup/use-client-backup.js b/native/backup/use-client-backup.js --- a/native/backup/use-client-backup.js +++ b/native/backup/use-client-backup.js @@ -12,6 +12,7 @@ import { encryptBackup } from './encryption.js'; import { commCoreModule } from '../native-modules.js'; import { generateKey } from '../utils/aes-crypto-module.js'; +import { getContentSigningKey } from '../utils/crypto-utils.js'; type ClientBackup = { +uploadBackupProtocol: (userData: UserData) => Promise, @@ -32,19 +33,17 @@ console.info('Start uploading backup...'); const backupDataKey = generateKey(); - await commCoreModule.initializeCryptoAccount(); - const { - primaryIdentityPublicKeys: { ed25519 }, - } = await commCoreModule.getUserPublicKey(); + + const [ed25519, backupID] = await Promise.all([ + getContentSigningKey(), + commCoreModule.generateRandomString(BACKUP_ID_LENGTH), + ]); + const userKeys: UserKeys = { backupDataKey: uintArrayToHexString(backupDataKey), ed25519, }; - const backupID = await commCoreModule.generateRandomString( - BACKUP_ID_LENGTH, - ); - const encryptedBackup = await encryptBackup({ backupID, userKeys, diff --git a/native/utils/crypto-utils.js b/native/utils/crypto-utils.js --- a/native/utils/crypto-utils.js +++ b/native/utils/crypto-utils.js @@ -52,4 +52,12 @@ ); } -export { useInitialNotificationsEncryptedMessage }; +async function getContentSigningKey(): Promise { + await commCoreModule.initializeCryptoAccount(); + const { + primaryIdentityPublicKeys: { ed25519 }, + } = await commCoreModule.getUserPublicKey(); + return ed25519; +} + +export { useInitialNotificationsEncryptedMessage, getContentSigningKey };