Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions src/crypto-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,41 @@ export interface CryptoApi {
}

export class DeviceVerificationStatus {
/**
* True if this device has been verified via cross signing.
*
* This does *not* take into account `trustCrossSignedDevices`.
*/
public readonly crossSigningVerified: boolean;

/**
* TODO: tofu magic wtf does this do?
*/
public readonly tofu: boolean;

/**
* True if the device has been marked as locally verified.
*/
public readonly localVerified: boolean;

/**
* True if the client has been configured to trust cross-signed devices via {@link CryptoApi#setTrustCrossSignedDevices}.
*/
private readonly trustCrossSignedDevices: boolean;

public constructor(
/**
* True if this device has been verified via cross signing.
*
* This does *not* take into account `trustCrossSignedDevices`.
*/
public readonly crossSigningVerified: boolean,

/**
* TODO: tofu magic wtf does this do?
*/
public readonly tofu: boolean,

/**
* True if the device has been marked as locally verified.
*/
public readonly localVerified: boolean,

/**
* True if the client has been configured to trust cross-signed devices via {@link CryptoApi#setTrustCrossSignedDevices}.
*/
private readonly trustCrossSignedDevices: boolean,
) {}
opts: Partial<DeviceVerificationStatus> & {
/**
* True if cross-signed devices should be considered verified for {@link DeviceVerificationStatus#isVerified}.
*/
trustCrossSignedDevices?: boolean;
},
) {
this.crossSigningVerified = opts.crossSigningVerified ?? false;
this.tofu = opts.tofu ?? false;
this.localVerified = opts.localVerified ?? false;
this.trustCrossSignedDevices = opts.trustCrossSignedDevices ?? false;
}

/**
* Check if we should consider this device "verified".
Expand Down
9 changes: 9 additions & 0 deletions src/crypto/CrossSigning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ export class UserTrustLevel {
* @deprecated Use {@link DeviceVerificationStatus}.
*/
export class DeviceTrustLevel extends DeviceVerificationStatus {
public constructor(
crossSigningVerified: boolean,
tofu: boolean,
localVerified: boolean,
trustCrossSignedDevices: boolean,
) {
super({ crossSigningVerified, tofu, localVerified, trustCrossSignedDevices });
}

public static fromUserTrustLevel(
userTrustLevel: UserTrustLevel,
localVerified: boolean,
Expand Down
11 changes: 5 additions & 6 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,11 @@ export class RustCrypto implements CryptoBackend {

if (!device) return null;

return new DeviceVerificationStatus(
device.isCrossSigningTrusted(),
false, // tofu
device.isLocallyTrusted(),
this._trustCrossSignedDevices,
);
return new DeviceVerificationStatus({
crossSigningVerified: device.isCrossSigningTrusted(),
localVerified: device.isLocallyTrusted(),
trustCrossSignedDevices: this._trustCrossSignedDevices,
});
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down