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 userUUIDTypes = Object.freeze({ + KEYSERVER: 0, + WEB: 1, + MOBILE: 2, +}); +export type UserUUIDType = $Values; -export { getUUID }; +function getUserUUID(type: UserUUIDType): string { + const uuidSuffix = crypto.randomBytes(32).toString('hex'); + if (type === userUUIDTypes.KEYSERVER) { + return `ks-${uuidSuffix}`; + } else if (type === userUUIDTypes.WEB) { + return `web-${uuidSuffix}`; + } else if (type === userUUIDTypes.MOBILE) { + return `mobile-${uuidSuffix}`; + } + return ''; +} + +export { getUUID, getUserUUID };