Skip to content

Commit

Permalink
Review of device.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Apr 21, 2023
1 parent d8a78c7 commit 529b9d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
7 changes: 1 addition & 6 deletions src/crypto/deviceinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { ISignatures } from "../@types/signed";
import { DeviceVerification } from "../models/device";

export interface IDevice {
keys: Record<string, string>;
Expand All @@ -25,12 +26,6 @@ export interface IDevice {
signatures?: ISignatures;
}

export enum DeviceVerification {
Blocked = -1,
Unverified = 0,
Verified = 1,
}

/**
* Information about a user's device
*/
Expand Down
1 change: 1 addition & 0 deletions src/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from "./models/poll";
export * from "./models/room-member";
export * from "./models/room-state";
export * from "./models/user";
export * from "./models/device";
export * from "./scheduler";
export * from "./filter";
export * from "./timeline-window";
Expand Down
33 changes: 17 additions & 16 deletions src/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { DeviceVerification } from "../crypto/deviceinfo";
/** State of the verification of the device.
* Beware that the enum values are numbers instead of plain strings
*/
export enum DeviceVerification {
Blocked = -1,
Unverified = 0,
Verified = 1,
}

// user-Id → device-Id → IDevice
/** A map from user ID to device ID to Device */
export type DeviceMap = Map<string, Map<string, Device>>;

type DeviceParameters = Pick<Device, "deviceId" | "userId" | "algorithms" | "keys"> & Partial<Device>;

/**
* Information on a user's device, as returned by {@link CryptoApi.getUserDeviceInfo}.
*/
export class Device {
/** id of the device */
public readonly deviceId: string;

/** id of the device user */
/** id of the user that owns the device */
public readonly userId: string;

/** list of algorithms supported by this device */
Expand All @@ -37,20 +47,20 @@ export class Device {
/** whether the device has been verified/blocked by the user */
public readonly verified: DeviceVerification;

/** additional data from the homeserver */
public readonly unsigned: Map<string, string>;

/** a map `<userId, map<algorithm:device_id, signature>>` */
public readonly signatures: Map<string, Map<string, string>>;

/** display name of the device */
public readonly displayName?: string;

public constructor(opts: DeviceParameters) {
this.deviceId = opts.deviceId;
this.userId = opts.userId;
this.algorithms = opts.algorithms;
this.keys = opts.keys;
this.verified = opts.verified || DeviceVerification.Unverified;
this.unsigned = opts.unsigned || new Map();
this.signatures = opts.signatures || new Map();
this.displayName = opts.displayName;
}

/**
Expand All @@ -70,13 +80,4 @@ export class Device {
public getIdentityKey(): string | undefined {
return this.keys.get(`curve25519:${this.deviceId}`);
}

/**
* Get the configured display name for this device, if any
* In `unsigned.device_display_name`
* @returns the device display name
*/
public getDisplayName(): string | undefined {
return this.unsigned.get("device_display_name");
}
}

0 comments on commit 529b9d4

Please sign in to comment.