diff --git a/web/utils/device-uuid.js b/web/utils/device-uuid.js new file mode 100644 --- /dev/null +++ b/web/utils/device-uuid.js @@ -0,0 +1,24 @@ +// @flow +import crypto from 'crypto'; + +export const deviceUUIDTypes = Object.freeze({ + KEYSERVER: 0, + WEB: 1, + MOBILE: 2, +}); +export type DeviceUUIDType = $Values; + +function getDeviceUUID(type: DeviceUUIDType): string { + const uuidSuffix = crypto.randomBytes(32).toString('hex'); + + if (type === deviceUUIDTypes.KEYSERVER) { + return `ks-${uuidSuffix}`; + } else if (type === deviceUUIDTypes.WEB) { + return `web-${uuidSuffix}`; + } else if (type === deviceUUIDTypes.MOBILE) { + return `mobile-${uuidSuffix}`; + } + return ''; +} + +export { getDeviceUUID };