Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3376294
D4587.id14774.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
763 B
Referenced Files
None
Subscribers
None
D4587.id14774.diff
View Options
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<typeof deviceUUIDTypes>;
+
+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 };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 11:10 PM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2592031
Default Alt Text
D4587.id14774.diff (763 B)
Attached To
Mode
D4587: [web] Add function (and an 'enum') for creating unique device ID on web
Attached
Detach File
Event Timeline
Log In to Comment