Changeset View
Changeset View
Standalone View
Standalone View
web/shared-worker/worker/worker-crypto.js
// @flow | // @flow | ||||
import olm from '@commapp/olm'; | import olm from '@commapp/olm'; | ||||
import uuid from 'uuid'; | import uuid from 'uuid'; | ||||
import type { | import type { | ||||
CryptoStore, | CryptoStore, | ||||
PickledOLMAccount, | PickledOLMAccount, | ||||
IdentityKeysBlob, | IdentityKeysBlob, | ||||
SignedIdentityKeysBlob, | SignedIdentityKeysBlob, | ||||
} from 'lib/types/crypto-types.js'; | } from 'lib/types/crypto-types.js'; | ||||
import type { IdentityDeviceKeyUpload } from 'lib/types/identity-service-types.js'; | import type { IdentityNewDeviceKeyUpload } from 'lib/types/identity-service-types.js'; | ||||
import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js'; | import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js'; | ||||
import { getProcessingStoreOpsExceptionMessage } from './process-operations.js'; | import { getProcessingStoreOpsExceptionMessage } from './process-operations.js'; | ||||
import { getDBModule, getSQLiteQueryExecutor } from './worker-database.js'; | import { getDBModule, getSQLiteQueryExecutor } from './worker-database.js'; | ||||
import { | import { | ||||
type WorkerRequestMessage, | type WorkerRequestMessage, | ||||
type WorkerResponseMessage, | type WorkerResponseMessage, | ||||
workerRequestMessageTypes, | workerRequestMessageTypes, | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | function getSignedIdentityKeysBlob(): SignedIdentityKeysBlob { | ||||
const signedIdentityKeysBlob: SignedIdentityKeysBlob = { | const signedIdentityKeysBlob: SignedIdentityKeysBlob = { | ||||
payload: payloadToBeSigned, | payload: payloadToBeSigned, | ||||
signature: contentAccount.sign(payloadToBeSigned), | signature: contentAccount.sign(payloadToBeSigned), | ||||
}; | }; | ||||
return signedIdentityKeysBlob; | return signedIdentityKeysBlob; | ||||
} | } | ||||
function getDeviceKeyUpload(): IdentityDeviceKeyUpload { | function getNewDeviceKeyUpload(): IdentityNewDeviceKeyUpload { | ||||
if (!cryptoStore) { | if (!cryptoStore) { | ||||
throw new Error('Crypto account not initialized'); | throw new Error('Crypto account not initialized'); | ||||
} | } | ||||
const { contentAccount, notificationAccount } = cryptoStore; | const { contentAccount, notificationAccount } = cryptoStore; | ||||
const signedIdentityKeysBlob = getSignedIdentityKeysBlob(); | const signedIdentityKeysBlob = getSignedIdentityKeysBlob(); | ||||
const primaryAccountKeysSet = retrieveAccountKeysSet(contentAccount); | const primaryAccountKeysSet = retrieveAccountKeysSet(contentAccount); | ||||
Show All 13 Lines | return { | ||||
notifOneTimeKeys: notificationAccountKeysSet.oneTimeKeys, | notifOneTimeKeys: notificationAccountKeysSet.oneTimeKeys, | ||||
}; | }; | ||||
} | } | ||||
export { | export { | ||||
clearCryptoStore, | clearCryptoStore, | ||||
processAppOlmApiRequest, | processAppOlmApiRequest, | ||||
getSignedIdentityKeysBlob, | getSignedIdentityKeysBlob, | ||||
getDeviceKeyUpload, | getNewDeviceKeyUpload, | ||||
}; | }; |