Skip to content

Commit b156707

Browse files
authored
Remove usage of legacy crypto in event.ts (#4666)
* feat(legacy crypto!): remove legacy crypto usage in `event.ts` * test(legacy crypto): update event.spec.ts to not use legacy crypto types
1 parent 89cec0a commit b156707

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

spec/unit/models/event.spec.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { MockedObject } from "jest-mock";
1818

1919
import { MatrixEvent, MatrixEventEvent } from "../../../src/models/event";
2020
import { emitPromise } from "../../test-utils/test-utils";
21-
import { Crypto, IEventDecryptionResult } from "../../../src/crypto";
2221
import {
2322
IAnnotatedPushRule,
2423
MatrixClient,
@@ -28,7 +27,7 @@ import {
2827
TweakName,
2928
} from "../../../src";
3029
import { DecryptionFailureCode } from "../../../src/crypto-api";
31-
import { DecryptionError } from "../../../src/common-crypto/CryptoBackend";
30+
import { CryptoBackend, DecryptionError, EventDecryptionResult } from "../../../src/common-crypto/CryptoBackend";
3231

3332
describe("MatrixEvent", () => {
3433
it("should create copies of itself", () => {
@@ -369,7 +368,7 @@ describe("MatrixEvent", () => {
369368
const testError = new Error("test error");
370369
const crypto = {
371370
decryptEvent: jest.fn().mockRejectedValue(testError),
372-
} as unknown as Crypto;
371+
} as unknown as CryptoBackend;
373372

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

396395
await encryptedEvent.attemptDecryption(crypto);
397396
expect(encryptedEvent.isEncrypted()).toBeTruthy();
@@ -418,7 +417,7 @@ describe("MatrixEvent", () => {
418417
"The sender has disabled encrypting to unverified devices.",
419418
),
420419
),
421-
} as unknown as Crypto;
420+
} as unknown as CryptoBackend;
422421

423422
await encryptedEvent.attemptDecryption(crypto);
424423
expect(encryptedEvent.isEncrypted()).toBeTruthy();
@@ -453,7 +452,7 @@ describe("MatrixEvent", () => {
453452
},
454453
});
455454
}),
456-
} as unknown as Crypto;
455+
} as unknown as CryptoBackend;
457456

458457
await encryptedEvent.attemptDecryption(crypto);
459458

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

479478
const crypto = {
480479
decryptEvent: jest.fn().mockImplementationOnce(() => {
481-
return Promise.resolve<IEventDecryptionResult>({
480+
return Promise.resolve<EventDecryptionResult>({
482481
clearEvent: {
483482
type: "m.room.message",
484483
content: {
@@ -491,7 +490,7 @@ describe("MatrixEvent", () => {
491490
},
492491
});
493492
}),
494-
} as unknown as Crypto;
493+
} as unknown as CryptoBackend;
495494

496495
await encryptedEvent.attemptDecryption(crypto);
497496
expect(encryptedEvent.getType()).toEqual("m.room.message");

src/models/event.ts

-34
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { ExtensibleEvent, ExtensibleEvents, Optional } from "matrix-events-sdk";
2323

2424
import type { IEventDecryptionResult } from "../@types/crypto.ts";
2525
import { logger } from "../logger.ts";
26-
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest.ts";
2726
import {
2827
EVENT_VISIBILITY_CHANGE_TYPE,
2928
EventType,
@@ -33,7 +32,6 @@ import {
3332
UNSIGNED_THREAD_ID_FIELD,
3433
UNSIGNED_MEMBERSHIP_FIELD,
3534
} from "../@types/event.ts";
36-
import { Crypto } from "../crypto/index.ts";
3735
import { deepSortedObjectEntries, internaliseString } from "../utils.ts";
3836
import { RoomMember } from "./room-member.ts";
3937
import { Thread, THREAD_RELATION_TYPE, ThreadEvent, ThreadEventHandlerMap } from "./thread.ts";
@@ -406,12 +404,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
406404
*/
407405
public forwardLooking = true;
408406

409-
/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
410-
* `Crypto` will set this the `VerificationRequest` for the event
411-
* so it can be easily accessed from the timeline.
412-
*/
413-
public verificationRequest?: VerificationRequest;
414-
415407
private readonly reEmitter: TypedReEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap>;
416408

417409
/**
@@ -889,28 +881,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
889881
return this.decryptionPromise;
890882
}
891883

892-
/**
893-
* Cancel any room key request for this event and resend another.
894-
*
895-
* @param crypto - crypto module
896-
* @param userId - the user who received this event
897-
*
898-
* @returns a promise that resolves when the request is queued
899-
*/
900-
public cancelAndResendKeyRequest(crypto: Crypto, userId: string): Promise<void> {
901-
const wireContent = this.getWireContent();
902-
return crypto.requestRoomKey(
903-
{
904-
algorithm: wireContent.algorithm,
905-
room_id: this.getRoomId()!,
906-
session_id: wireContent.session_id,
907-
sender_key: wireContent.sender_key,
908-
},
909-
this.getKeyRequestRecipients(userId),
910-
true,
911-
);
912-
}
913-
914884
/**
915885
* Calculate the recipients for keyshare requests.
916886
*
@@ -1720,10 +1690,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
17201690
};
17211691
}
17221692

1723-
public setVerificationRequest(request: VerificationRequest): void {
1724-
this.verificationRequest = request;
1725-
}
1726-
17271693
public setTxnId(txnId: string): void {
17281694
this.txnId = txnId;
17291695
}

0 commit comments

Comments
 (0)