Changeset View
Changeset View
Standalone View
Standalone View
web/account/account-hooks.js
Show All 14 Lines | |||||
import type { | import type { | ||||
SignedIdentityKeysBlob, | SignedIdentityKeysBlob, | ||||
CryptoStore, | CryptoStore, | ||||
IdentityKeysBlob, | IdentityKeysBlob, | ||||
CryptoStoreContextType, | CryptoStoreContextType, | ||||
OLMIdentityKeys, | OLMIdentityKeys, | ||||
NotificationsOlmDataType, | NotificationsOlmDataType, | ||||
} 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 type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; | import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; | ||||
import { getConfig } from 'lib/utils/config.js'; | import { getConfig } from 'lib/utils/config.js'; | ||||
import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js'; | import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js'; | ||||
import { useDispatch } from 'lib/utils/redux-utils.js'; | import { useDispatch } from 'lib/utils/redux-utils.js'; | ||||
import { | import { | ||||
generateCryptoKey, | generateCryptoKey, | ||||
encryptData, | encryptData, | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | const signedIdentityKeysBlob: SignedIdentityKeysBlob = { | ||||
payload: payloadToBeSigned, | payload: payloadToBeSigned, | ||||
signature: primaryOLMAccount.sign(payloadToBeSigned), | signature: primaryOLMAccount.sign(payloadToBeSigned), | ||||
}; | }; | ||||
return signedIdentityKeysBlob; | return signedIdentityKeysBlob; | ||||
}, [getOrCreateCryptoStore]); | }, [getOrCreateCryptoStore]); | ||||
} | } | ||||
function useGetDeviceKeyUpload(): () => Promise<IdentityDeviceKeyUpload> { | function useGetNewDeviceKeyUpload(): () => Promise<IdentityNewDeviceKeyUpload> { | ||||
const getOrCreateCryptoStore = useGetOrCreateCryptoStore(); | const getOrCreateCryptoStore = useGetOrCreateCryptoStore(); | ||||
// `getSignedIdentityKeysBlob()` will initialize OLM, so no need to do it | // `getSignedIdentityKeysBlob()` will initialize OLM, so no need to do it | ||||
// again | // again | ||||
const getSignedIdentityKeysBlob = useGetSignedIdentityKeysBlob(); | const getSignedIdentityKeysBlob = useGetSignedIdentityKeysBlob(); | ||||
const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
return React.useCallback(async () => { | return React.useCallback(async () => { | ||||
const [signedIdentityKeysBlob, cryptoStore] = await Promise.all([ | const [signedIdentityKeysBlob, cryptoStore] = await Promise.all([ | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | function OlmSessionCreatorProvider(props: Props): React.Node { | ||||
); | ); | ||||
} | } | ||||
export { | export { | ||||
useGetSignedIdentityKeysBlob, | useGetSignedIdentityKeysBlob, | ||||
useGetOrCreateCryptoStore, | useGetOrCreateCryptoStore, | ||||
OlmSessionCreatorProvider, | OlmSessionCreatorProvider, | ||||
GetOrCreateCryptoStoreProvider, | GetOrCreateCryptoStoreProvider, | ||||
useGetDeviceKeyUpload, | useGetNewDeviceKeyUpload, | ||||
}; | }; |