1
|
{"version":3,"file":"deviceinfo.js","names":["DeviceVerification","DeviceInfo","fromStorage","obj","deviceId","res","prop","hasOwnProperty","constructor","_defineProperty2","default","Unverified","toStorage","algorithms","keys","verified","known","unsigned","signatures","getFingerprint","getIdentityKey","getDisplayName","device_display_name","isBlocked","Blocked","isVerified","Verified","isUnverified","isKnown","exports","VERIFIED","UNVERIFIED","BLOCKED"],"sources":["../../src/crypto/deviceinfo.ts"],"sourcesContent":["/*\nCopyright 2016 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { ISignatures } from \"../@types/signed\";\n\nexport interface IDevice {\n keys: Record<string, string>;\n algorithms: string[];\n verified: DeviceVerification;\n known: boolean;\n unsigned?: Record<string, any>;\n signatures?: ISignatures;\n}\n\nenum DeviceVerification {\n Blocked = -1,\n Unverified = 0,\n Verified = 1,\n}\n\n/**\n * Information about a user's device\n */\nexport class DeviceInfo {\n /**\n * rehydrate a DeviceInfo from the session store\n *\n * @param obj - raw object from session store\n * @param deviceId - id of the device\n *\n * @returns new DeviceInfo\n */\n public static fromStorage(obj: Partial<IDevice>, deviceId: string): DeviceInfo {\n const res = new DeviceInfo(deviceId);\n for (const prop in obj) {\n if (obj.hasOwnProperty(prop)) {\n // @ts-ignore - this is messy and typescript doesn't like it\n res[prop as keyof IDevice] = obj[prop as keyof IDevice];\n }\n }\n return res;\n }\n\n public static DeviceVerification = {\n VERIFIED: DeviceVerification.Verified,\n UNVERIFIED: DeviceVerification.Unverified,\n BLOCKED: DeviceVerification.Blocked,\n };\n\n /** list of algorithms supported by this device */\n public algorithms: string[] = [];\n /** a map from `<key type>:<id> -> <base64-encoded key>` */\n public keys: Record<string, string> = {};\n /** whether the device has been verified/blocked by the user */\n public verified = DeviceVerification.Unverified;\n /**\n * whether the user knows of this device's existence\n * (useful when warning the user that a user has added new devices)\n */\n public known = false;\n /** additional data from the homeserver */\n public unsigned: Record<string, any> = {};\n public signatures: ISignatures = {};\n\n /**\n * @param deviceId - id of the device\n */\n public constructor(public readonly deviceId: string) {}\n\n /**\n * Prepare a DeviceInfo for JSON serialisation in the session store\n *\n * @returns deviceinfo with non-serialised members removed\n */\n public toStorage(): IDevice {\n return {\n algorithms: this.algorithms,\n keys: this.keys,\n verified: this.verified,\n known: this.known,\n unsigned: this.unsigned,\n signatures: this.signatures,\n };\n }\n\n /**\n * Get the fingerprint for this device (ie, the Ed25519 key)\n *\n * @returns base64-encoded fingerprint of this device\n */\n public getFingerprint(): string {\n return this.keys[\"ed25519:\" + this.deviceId];\n }\n\n /**\n * Get the identity key for this device (ie, the Curve25519 key)\n *\n * @returns base64-encoded identity key of this device\n */\n public getIdentityKey(): string {\n return this.keys[\"curve25519:\" + this.deviceId];\n }\n\n /**\n * Get the configured display name for this device, if any\n *\n * @returns displayname\n */\n public getDisplayName(): string | null {\n return this.unsigned.device_display_name || null;\n }\n\n /**\n * Returns true if this device is blocked\n *\n * @returns true if blocked\n */\n public isBlocked(): boolean {\n return this.verified == DeviceVerification.Blocked;\n }\n\n /**\n * Returns true if this device is verified\n *\n * @returns true if verified\n */\n public isVerified(): boolean {\n return this.verified == DeviceVerification.Verified;\n }\n\n /**\n * Returns true if this device is unverified\n *\n * @returns true if unverified\n */\n public isUnverified(): boolean {\n return this.verified == DeviceVerification.Unverified;\n }\n\n /**\n * Returns true if the user knows about this device's existence\n *\n * @returns true if known\n */\n public isKnown(): boolean {\n return this.known === true;\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAdA,IA2BKA,kBAAk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