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

Use SyncCryptoCallback api instead of legacy crypto in sliding sync #4624

Merged

Conversation

florianduros
Copy link
Contributor

@florianduros florianduros commented Jan 16, 2025

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

Replace the usage of deprecated MatrixClient.crypto by the SyncCryptoCallback api.

Hopefully, they can be swapped without any difficulty because ExtensionE2EE is using shared methods between legacy crypto and SyncCryptoCallback:

class ExtensionE2EE implements Extension<ExtensionE2EERequest, ExtensionE2EEResponse> {
public constructor(private readonly crypto: SyncCryptoCallbacks) {}
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({});
}
}

The syncCryptoCallback parameter is already provided in the matrixClient:

matrix-js-sdk/src/client.ts

Lines 1552 to 1566 in 1dfeaac

/**
* Construct a SyncApiOptions for this client, suitable for passing into the SyncApi constructor
*/
protected buildSyncApiOptions(): SyncApiOptions {
return {
crypto: this.crypto,
cryptoCallbacks: this.cryptoBackend,
canResetEntireTimeline: (roomId: string): boolean => {
if (!this.canResetTimelineCallback) {
return false;
}
return this.canResetTimelineCallback(roomId);
},
};
}

@florianduros florianduros force-pushed the florianduros/rip-out-legacy-crypto/sliding-sync branch from 1dfeaac to 493ca94 Compare January 17, 2025 08:47
@florianduros florianduros changed the title Use SyncCryptoCallback api instead of legacy crypto in sliding sync Use SyncCryptoCallback api instead of legacy crypto in sliding sync Jan 17, 2025
Comment on lines -643 to -648
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();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work without it and doesn't add more error message.

@florianduros florianduros marked this pull request as ready for review January 17, 2025 09:01
@florianduros florianduros requested a review from a team as a code owner January 17, 2025 09:01
@florianduros florianduros requested review from dbkr and t3chguy January 17, 2025 09:01
Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks plausible!

@florianduros florianduros added this pull request to the merge queue Jan 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 17, 2025
@florianduros florianduros added this pull request to the merge queue Jan 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 17, 2025
@florianduros florianduros added this pull request to the merge queue Jan 17, 2025
Merged via the queue into develop with commit a6fd28b Jan 17, 2025
38 checks passed
@florianduros florianduros deleted the florianduros/rip-out-legacy-crypto/sliding-sync branch January 17, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants