Files
speckle-server/packages/frontend-2/lib/common/composables/crypto.ts
T
Kristaps Fabians Geikins 1d2a594f0a chore: upgrade TS 5.2 -> 5.7.3 & ESLint to 9.20.1 (#4032)
* chore: upgrade TS 5.2 -> 5.7.3

* vite dts fix

* lint fix

* resolutions fix

* ui comp build fix

* precommit fix?

* latest eslint version

* autoloader fix

* undo unnecessary viewer change

* eslint fixes fe2 + trying disabled type linting

* lint fixes
2025-02-20 14:18:18 +02:00

42 lines
1.1 KiB
TypeScript

import type { Optional } from '@speckle/shared'
type EncryptionUtilsModule = typeof import('~/lib/common/utils/tweetnacl')
type EncryptionUtilsModulePromise = Promise<EncryptionUtilsModule>
let encryptionUtils: Optional<EncryptionUtilsModule> = undefined
let encryptionUtilsPromise: Optional<EncryptionUtilsModulePromise> = undefined
/**
* Lazy load the heavy encryption utilities. You must invoke ensure() to initialize loading.
*/
export const useEncryptionUtils = () => {
const logger = useLogger()
const utils = shallowRef<Optional<EncryptionUtilsModule>>(undefined)
const ready = computed(() => !!utils.value)
const ensure = async () => {
if (!encryptionUtils) {
try {
encryptionUtilsPromise =
encryptionUtilsPromise || import('~/lib/common/utils/tweetnacl')
encryptionUtils = await encryptionUtilsPromise
utils.value = encryptionUtils
} catch (e) {
logger.error(e, 'Could not load encryption utils')
throw e
}
} else {
utils.value = encryptionUtils
}
return utils.value
}
return {
isReady: ready,
encryption: utils,
ensure
}
}