Page MenuHomePhabricator

D4587.id14832.diff
No OneTemporary

D4587.id14832.diff

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

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 7:38 AM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574590
Default Alt Text
D4587.id14832.diff (747 B)

Event Timeline