mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-06-10 02:21:19 +03:00
feat(sliding sync): Use SyncCryptoCallback api instead of legacy crypto (#4624)
This commit is contained in:
parent
78e7e2af31
commit
a6fd28b03d
@ -44,6 +44,7 @@ import { logger } from "../../src/logger";
|
|||||||
import { emitPromise } from "../test-utils/test-utils";
|
import { emitPromise } from "../test-utils/test-utils";
|
||||||
import { defer } from "../../src/utils";
|
import { defer } from "../../src/utils";
|
||||||
import { KnownMembership } from "../../src/@types/membership";
|
import { KnownMembership } from "../../src/@types/membership";
|
||||||
|
import { SyncCryptoCallbacks } from "../../src/common-crypto/CryptoBackend";
|
||||||
|
|
||||||
declare module "../../src/@types/event" {
|
declare module "../../src/@types/event" {
|
||||||
interface AccountDataEvents {
|
interface AccountDataEvents {
|
||||||
@ -57,6 +58,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
let httpBackend: MockHttpBackend | undefined;
|
let httpBackend: MockHttpBackend | undefined;
|
||||||
let sdk: SlidingSyncSdk | undefined;
|
let sdk: SlidingSyncSdk | undefined;
|
||||||
let mockSlidingSync: SlidingSync | undefined;
|
let mockSlidingSync: SlidingSync | undefined;
|
||||||
|
let syncCryptoCallback: SyncCryptoCallbacks | undefined;
|
||||||
const selfUserId = "@alice:localhost";
|
const selfUserId = "@alice:localhost";
|
||||||
const selfAccessToken = "aseukfgwef";
|
const selfAccessToken = "aseukfgwef";
|
||||||
|
|
||||||
@ -126,8 +128,9 @@ describe("SlidingSyncSdk", () => {
|
|||||||
mockSlidingSync = mockifySlidingSync(new SlidingSync("", new Map(), {}, client, 0));
|
mockSlidingSync = mockifySlidingSync(new SlidingSync("", new Map(), {}, client, 0));
|
||||||
if (testOpts.withCrypto) {
|
if (testOpts.withCrypto) {
|
||||||
httpBackend!.when("GET", "/room_keys/version").respond(404, {});
|
httpBackend!.when("GET", "/room_keys/version").respond(404, {});
|
||||||
await client!.initLegacyCrypto();
|
await client!.initRustCrypto({ useIndexedDB: false });
|
||||||
syncOpts.cryptoCallbacks = syncOpts.crypto = client!.crypto;
|
syncCryptoCallback = client!.getCrypto() as unknown as SyncCryptoCallbacks;
|
||||||
|
syncOpts.cryptoCallbacks = syncCryptoCallback;
|
||||||
}
|
}
|
||||||
httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {});
|
httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {});
|
||||||
sdk = new SlidingSyncSdk(mockSlidingSync, client, testOpts, syncOpts);
|
sdk = new SlidingSyncSdk(mockSlidingSync, client, testOpts, syncOpts);
|
||||||
@ -640,13 +643,6 @@ describe("SlidingSyncSdk", () => {
|
|||||||
ext = findExtension("e2ee");
|
ext = findExtension("e2ee");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
// needed else we do some async operations in the background which can cause Jest to whine:
|
|
||||||
// "Cannot log after tests are done. Did you forget to wait for something async in your test?"
|
|
||||||
// Attempted to log "Saving device tracking data null"."
|
|
||||||
client!.crypto!.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("gets enabled on the initial request only", () => {
|
it("gets enabled on the initial request only", () => {
|
||||||
expect(ext.onRequest(true)).toEqual({
|
expect(ext.onRequest(true)).toEqual({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -655,28 +651,28 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can update device lists", () => {
|
it("can update device lists", () => {
|
||||||
client!.crypto!.processDeviceLists = jest.fn();
|
syncCryptoCallback!.processDeviceLists = jest.fn();
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
device_lists: {
|
device_lists: {
|
||||||
changed: ["@alice:localhost"],
|
changed: ["@alice:localhost"],
|
||||||
left: ["@bob:localhost"],
|
left: ["@bob:localhost"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(client!.crypto!.processDeviceLists).toHaveBeenCalledWith({
|
expect(syncCryptoCallback!.processDeviceLists).toHaveBeenCalledWith({
|
||||||
changed: ["@alice:localhost"],
|
changed: ["@alice:localhost"],
|
||||||
left: ["@bob:localhost"],
|
left: ["@bob:localhost"],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can update OTK counts and unused fallback keys", () => {
|
it("can update OTK counts and unused fallback keys", () => {
|
||||||
client!.crypto!.processKeyCounts = jest.fn();
|
syncCryptoCallback!.processKeyCounts = jest.fn();
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
device_one_time_keys_count: {
|
device_one_time_keys_count: {
|
||||||
signed_curve25519: 42,
|
signed_curve25519: 42,
|
||||||
},
|
},
|
||||||
device_unused_fallback_key_types: ["signed_curve25519"],
|
device_unused_fallback_key_types: ["signed_curve25519"],
|
||||||
});
|
});
|
||||||
expect(client!.crypto!.processKeyCounts).toHaveBeenCalledWith({ signed_curve25519: 42 }, [
|
expect(syncCryptoCallback!.processKeyCounts).toHaveBeenCalledWith({ signed_curve25519: 42 }, [
|
||||||
"signed_curve25519",
|
"signed_curve25519",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -30,7 +30,6 @@ import {
|
|||||||
SetPresence,
|
SetPresence,
|
||||||
} from "./sync.ts";
|
} from "./sync.ts";
|
||||||
import { MatrixEvent } from "./models/event.ts";
|
import { MatrixEvent } from "./models/event.ts";
|
||||||
import { Crypto } from "./crypto/index.ts";
|
|
||||||
import { IMinimalEvent, IRoomEvent, IStateEvent, IStrippedState, ISyncResponse } from "./sync-accumulator.ts";
|
import { IMinimalEvent, IRoomEvent, IStateEvent, IStrippedState, ISyncResponse } from "./sync-accumulator.ts";
|
||||||
import { MatrixError } from "./http-api/index.ts";
|
import { MatrixError } from "./http-api/index.ts";
|
||||||
import {
|
import {
|
||||||
@ -66,7 +65,7 @@ type ExtensionE2EEResponse = Pick<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
class ExtensionE2EE implements Extension<ExtensionE2EERequest, ExtensionE2EEResponse> {
|
class ExtensionE2EE implements Extension<ExtensionE2EERequest, ExtensionE2EEResponse> {
|
||||||
public constructor(private readonly crypto: Crypto) {}
|
public constructor(private readonly crypto: SyncCryptoCallbacks) {}
|
||||||
|
|
||||||
public name(): string {
|
public name(): string {
|
||||||
return "e2ee";
|
return "e2ee";
|
||||||
@ -373,8 +372,8 @@ export class SlidingSyncSdk {
|
|||||||
new ExtensionTyping(this.client),
|
new ExtensionTyping(this.client),
|
||||||
new ExtensionReceipts(this.client),
|
new ExtensionReceipts(this.client),
|
||||||
];
|
];
|
||||||
if (this.syncOpts.crypto) {
|
if (this.syncOpts.cryptoCallbacks) {
|
||||||
extensions.push(new ExtensionE2EE(this.syncOpts.crypto));
|
extensions.push(new ExtensionE2EE(this.syncOpts.cryptoCallbacks));
|
||||||
}
|
}
|
||||||
extensions.forEach((ext) => {
|
extensions.forEach((ext) => {
|
||||||
this.slidingSync.registerExtension(ext);
|
this.slidingSync.registerExtension(ext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user