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 Crypto module #4564

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
52 changes: 0 additions & 52 deletions src/sliding-sync-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
SetPresence,
} from "./sync.ts";
import { MatrixEvent } from "./models/event.ts";
import { Crypto } from "./crypto/index.ts";
import { IMinimalEvent, IRoomEvent, IStateEvent, IStrippedState, ISyncResponse } from "./sync-accumulator.ts";
import { MatrixError } from "./http-api/index.ts";
import {
Expand All @@ -53,54 +52,6 @@ import { KnownMembership } from "./@types/membership.ts";
// keepAlive is successful but the server /sync fails.
const FAILED_SYNC_ERROR_THRESHOLD = 3;

type ExtensionE2EERequest = {
enabled: boolean;
};

type ExtensionE2EEResponse = Pick<
ISyncResponse,
| "device_lists"
| "device_one_time_keys_count"
| "device_unused_fallback_key_types"
| "org.matrix.msc2732.device_unused_fallback_key_types"
>;

class ExtensionE2EE implements Extension<ExtensionE2EERequest, ExtensionE2EEResponse> {
public constructor(private readonly crypto: Crypto) {}

public name(): string {
return "e2ee";
}

public when(): ExtensionState {
return ExtensionState.PreProcess;
}

public onRequest(isInitial: boolean): ExtensionE2EERequest | undefined {
if (!isInitial) {
return undefined;
}
return {
enabled: true, // this is sticky so only send it on the initial request
};
}

public async onResponse(data: ExtensionE2EEResponse): Promise<void> {
// Handle device list updates
if (data.device_lists) {
await this.crypto.processDeviceLists(data.device_lists);
}

// Handle one_time_keys_count and unused_fallback_key_types
await this.crypto.processKeyCounts(
data.device_one_time_keys_count,
data["device_unused_fallback_key_types"] || data["org.matrix.msc2732.device_unused_fallback_key_types"],
);

this.crypto.onSyncCompleted({});
}
}

type ExtensionToDeviceRequest = {
since?: string;
limit?: number;
Expand Down Expand Up @@ -373,9 +324,6 @@ export class SlidingSyncSdk {
new ExtensionTyping(this.client),
new ExtensionReceipts(this.client),
];
if (this.syncOpts.crypto) {
extensions.push(new ExtensionE2EE(this.syncOpts.crypto));
}
extensions.forEach((ext) => {
this.slidingSync.registerExtension(ext);
});
Expand Down
26 changes: 0 additions & 26 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { BeaconEvent } from "./models/beacon.ts";
import { IEventsResponse } from "./@types/requests.ts";
import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync.ts";
import { Feature, ServerSupport } from "./feature.ts";
import { Crypto } from "./crypto/index.ts";
import { KnownMembership } from "./@types/membership.ts";

const DEBUG = true;
Expand Down Expand Up @@ -116,13 +115,6 @@ function debuglog(...params: any[]): void {
* Options passed into the constructor of SyncApi by MatrixClient
*/
export interface SyncApiOptions {
/**
* Crypto manager
*
* @deprecated in favour of cryptoCallbacks
*/
crypto?: Crypto;

/**
* If crypto is enabled on our client, callbacks into the crypto module
*/
Expand Down Expand Up @@ -642,9 +634,6 @@ export class SyncApi {
}
this.opts.filter.setLazyLoadMembers(true);
}
if (this.opts.lazyLoadMembers) {
this.syncOpts.crypto?.enableLazyLoading();
}
};

private storeClientOptions = async (): Promise<void> => {
Expand Down Expand Up @@ -880,12 +869,6 @@ export class SyncApi {
catchingUp: this.catchingUp,
};

if (this.syncOpts.crypto) {
// tell the crypto module we're about to process a sync
// response
await this.syncOpts.crypto.onSyncWillProcess(syncEventData);
}

try {
await this.processSyncResponse(syncEventData, data);
} catch (e) {
Expand Down Expand Up @@ -920,15 +903,6 @@ export class SyncApi {
this.updateSyncState(SyncState.Syncing, syncEventData);

if (this.client.store.wantsSave()) {
// We always save the device list (if it's dirty) before saving the sync data:
// this means we know the saved device list data is at least as fresh as the
// stored sync data which means we don't have to worry that we may have missed
// device changes. We can also skip the delay since we're not calling this very
// frequently (and we don't really want to delay the sync for it).
if (this.syncOpts.crypto) {
await this.syncOpts.crypto.saveDeviceList(0);
}

// tell databases that everything is now in a consistent state and can be saved.
await this.client.store.save();
}
Expand Down
Loading