Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of legacy crypto in event.ts #4666

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
15 changes: 7 additions & 8 deletions spec/unit/models/event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { MockedObject } from "jest-mock";

import { MatrixEvent, MatrixEventEvent } from "../../../src/models/event";
import { emitPromise } from "../../test-utils/test-utils";
import { Crypto, IEventDecryptionResult } from "../../../src/crypto";
import {
IAnnotatedPushRule,
MatrixClient,
Expand All @@ -28,7 +27,7 @@ import {
TweakName,
} from "../../../src";
import { DecryptionFailureCode } from "../../../src/crypto-api";
import { DecryptionError } from "../../../src/common-crypto/CryptoBackend";
import { CryptoBackend, DecryptionError, EventDecryptionResult } from "../../../src/common-crypto/CryptoBackend";

describe("MatrixEvent", () => {
it("should create copies of itself", () => {
Expand Down Expand Up @@ -369,7 +368,7 @@ describe("MatrixEvent", () => {
const testError = new Error("test error");
const crypto = {
decryptEvent: jest.fn().mockRejectedValue(testError),
} as unknown as Crypto;
} as unknown as CryptoBackend;

await encryptedEvent.attemptDecryption(crypto);
expect(encryptedEvent.isEncrypted()).toBeTruthy();
Expand All @@ -391,7 +390,7 @@ describe("MatrixEvent", () => {
const testError = new DecryptionError(DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID, "uisi");
const crypto = {
decryptEvent: jest.fn().mockRejectedValue(testError),
} as unknown as Crypto;
} as unknown as CryptoBackend;

await encryptedEvent.attemptDecryption(crypto);
expect(encryptedEvent.isEncrypted()).toBeTruthy();
Expand All @@ -418,7 +417,7 @@ describe("MatrixEvent", () => {
"The sender has disabled encrypting to unverified devices.",
),
),
} as unknown as Crypto;
} as unknown as CryptoBackend;

await encryptedEvent.attemptDecryption(crypto);
expect(encryptedEvent.isEncrypted()).toBeTruthy();
Expand Down Expand Up @@ -453,7 +452,7 @@ describe("MatrixEvent", () => {
},
});
}),
} as unknown as Crypto;
} as unknown as CryptoBackend;

await encryptedEvent.attemptDecryption(crypto);

Expand All @@ -478,7 +477,7 @@ describe("MatrixEvent", () => {

const crypto = {
decryptEvent: jest.fn().mockImplementationOnce(() => {
return Promise.resolve<IEventDecryptionResult>({
return Promise.resolve<EventDecryptionResult>({
clearEvent: {
type: "m.room.message",
content: {
Expand All @@ -491,7 +490,7 @@ describe("MatrixEvent", () => {
},
});
}),
} as unknown as Crypto;
} as unknown as CryptoBackend;

await encryptedEvent.attemptDecryption(crypto);
expect(encryptedEvent.getType()).toEqual("m.room.message");
Expand Down
34 changes: 0 additions & 34 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { ExtensibleEvent, ExtensibleEvents, Optional } from "matrix-events-sdk";

import type { IEventDecryptionResult } from "../@types/crypto.ts";
import { logger } from "../logger.ts";
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest.ts";
import {
EVENT_VISIBILITY_CHANGE_TYPE,
EventType,
Expand All @@ -33,7 +32,6 @@ import {
UNSIGNED_THREAD_ID_FIELD,
UNSIGNED_MEMBERSHIP_FIELD,
} from "../@types/event.ts";
import { Crypto } from "../crypto/index.ts";
import { deepSortedObjectEntries, internaliseString } from "../utils.ts";
import { RoomMember } from "./room-member.ts";
import { Thread, THREAD_RELATION_TYPE, ThreadEvent, ThreadEventHandlerMap } from "./thread.ts";
Expand Down Expand Up @@ -406,12 +404,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
*/
public forwardLooking = true;

/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
* `Crypto` will set this the `VerificationRequest` for the event
* so it can be easily accessed from the timeline.
*/
public verificationRequest?: VerificationRequest;

private readonly reEmitter: TypedReEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap>;

/**
Expand Down Expand Up @@ -889,28 +881,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
return this.decryptionPromise;
}

/**
* Cancel any room key request for this event and resend another.
*
* @param crypto - crypto module
* @param userId - the user who received this event
*
* @returns a promise that resolves when the request is queued
*/
public cancelAndResendKeyRequest(crypto: Crypto, userId: string): Promise<void> {
const wireContent = this.getWireContent();
return crypto.requestRoomKey(
{
algorithm: wireContent.algorithm,
room_id: this.getRoomId()!,
session_id: wireContent.session_id,
sender_key: wireContent.sender_key,
},
this.getKeyRequestRecipients(userId),
true,
);
}

/**
* Calculate the recipients for keyshare requests.
*
Expand Down Expand Up @@ -1720,10 +1690,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
};
}

public setVerificationRequest(request: VerificationRequest): void {
this.verificationRequest = request;
}

public setTxnId(txnId: string): void {
this.txnId = txnId;
}
Expand Down
Loading