diff --git a/lib/utils/uuid.js b/lib/utils/uuid.js --- a/lib/utils/uuid.js +++ b/lib/utils/uuid.js @@ -1,9 +1,28 @@ // @flow +import crypto from 'crypto'; const uniqueBaseID = Date.now(); let uuidCount = 0; function getUUID(): string { return `${uniqueBaseID}-${uuidCount++}`; } +export const deviceUUIDTypes = Object.freeze({ + KEYSERVER: 0, + WEB: 1, + MOBILE: 2, +}); +export type DeviceUUIDType = $Values; -export { getUUID }; +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 { getUUID, getDeviceUUID };