Skip to content

Commit

Permalink
Merge branch 'develop' into crypto-wasm-11
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg authored Dec 3, 2024
2 parents 6cf645f + c4ea57d commit cb6b623
Show file tree
Hide file tree
Showing 30 changed files with 185 additions and 344 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ module.exports = {
tryExtensions: [".ts"],
},
],
"no-extra-boolean-cast": "error",
},
},
{
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/release-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release Sanity checks
on:
workflow_call:
secrets:
ELEMENT_BOT_TOKEN:
required: false
inputs:
repository:
type: string
required: false
default: ${{ github.repository }}
description: "The repository (in form owner/repo) to check for release blockers"

permissions: {}
jobs:
checks:
name: Sanity checks
runs-on: ubuntu-24.04
steps:
- name: Check for X-Release-Blocker label on any open issues or PRs
uses: actions/github-script@v7
env:
REPO: ${{ inputs.repository }}
with:
github-token: ${{ secrets.ELEMENT_BOT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const { REPO } = process.env;
const { data } = await github.rest.search.issuesAndPullRequests({
q: `repo:${REPO} label:X-Release-Blocker is:open`,
per_page: 50,
});
if (data.total_count) {
data.items.forEach(item => {
core.error(`Release blocker: ${item.html_url}`);
});
core.setFailed(`Found release blockers!`);
}
18 changes: 1 addition & 17 deletions .github/workflows/release-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,10 @@ permissions: {}
jobs:
checks:
name: Sanity checks
runs-on: ubuntu-24.04
permissions:
issues: read
pull-requests: read
steps:
- name: Check for X-Release-Blocker label on any open issues or PRs
uses: actions/github-script@v7
with:
script: |
const { data } = await github.rest.search.issuesAndPullRequests({
q: `repo:${context.repo.owner}/${context.repo.repo} label:X-Release-Blocker is:open`,
per_page: 50,
});
if (data.total_count) {
data.items.forEach(item => {
core.error(`Release blocker: ${item.html_url}`);
});
core.setFailed(`Found release blockers!`);
}
uses: matrix-org/matrix-js-sdk/.github/workflows/release-checks.yml@develop

release:
name: Release
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
Changes in [34.13.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v34.13.0) (2024-12-03)
====================================================================================================
## 🦖 Deprecations

* Deprecate `MatrixClient.isEventSenderVerified` ([#4527](https://github.com/matrix-org/matrix-js-sdk/pull/4527)). Contributed by @florianduros.
* Add `restoreKeybackup` to `CryptoApi`. ([#4476](https://github.com/matrix-org/matrix-js-sdk/pull/4476)). Contributed by @florianduros.

## ✨ Features

* Ensure we disambiguate display names which look like MXIDs ([#4540](https://github.com/matrix-org/matrix-js-sdk/pull/4540)). Contributed by @t3chguy.
* Add `CryptoApi.getBackupInfo` ([#4512](https://github.com/matrix-org/matrix-js-sdk/pull/4512)). Contributed by @florianduros.
* Fix local echo in embedded mode ([#4498](https://github.com/matrix-org/matrix-js-sdk/pull/4498)). Contributed by @toger5.
* Add `restoreKeybackup` to `CryptoApi`. ([#4476](https://github.com/matrix-org/matrix-js-sdk/pull/4476)). Contributed by @florianduros.

## 🐛 Bug Fixes

* Fix `RustBackupManager` remaining values after current backup removal ([#4537](https://github.com/matrix-org/matrix-js-sdk/pull/4537)). Contributed by @florianduros.


Changes in [34.12.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v34.12.0) (2024-11-19)
====================================================================================================
## 🦖 Deprecations
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matrix-js-sdk",
"version": "34.12.0",
"version": "34.13.0",
"description": "Matrix Client-Server SDK for Javascript",
"engines": {
"node": ">=20.0.0"
Expand Down Expand Up @@ -120,7 +120,7 @@
"prettier": "3.4.1",
"rimraf": "^6.0.0",
"ts-node": "^10.9.2",
"typedoc": "^0.26.0",
"typedoc": "^0.27.0",
"typedoc-plugin-coverage": "^3.0.0",
"typedoc-plugin-mdn-links": "^4.0.0",
"typedoc-plugin-missing-exports": "^3.0.0",
Expand Down
22 changes: 22 additions & 0 deletions spec/integ/matrix-client-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,28 @@ describe("MatrixClient", function () {
return prom;
});
});

describe("getDomain", () => {
it("should return null if no userId is set", () => {
const client = new MatrixClient({ baseUrl: "http://localhost" });
expect(client.getDomain()).toBeNull();
});

it("should return the domain of the userId", () => {
expect(client.getDomain()).toBe("localhost");
});
});

describe("getUserIdLocalpart", () => {
it("should return null if no userId is set", () => {
const client = new MatrixClient({ baseUrl: "http://localhost" });
expect(client.getUserIdLocalpart()).toBeNull();
});

it("should return the localpart of the userId", () => {
expect(client.getUserIdLocalpart()).toBe("alice");
});
});
});

function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent {
Expand Down
3 changes: 3 additions & 0 deletions spec/test-utils/webrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ export class MockCallMatrixClient extends TypedEventEmitter<EmittedEvents, Emitt
public getUserId(): string {
return this.userId;
}
public getSafeUserId(): string {
return this.userId;
}

public getDeviceId(): string {
return this.deviceId;
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/webrtc/groupCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ describe("Group Call", function () {
let client: MatrixClient;

beforeEach(() => {
client = new MatrixClient({ baseUrl: "base_url" });
client = new MatrixClient({ baseUrl: "base_url", userId: "my_user_id" });

jest.spyOn(client, "sendStateEvent").mockResolvedValue({} as any);
});
Expand Down
2 changes: 1 addition & 1 deletion src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ declare global {
interface Navigator {
// We check for the webkit-prefixed getUserMedia to detect if we're
// on webkit: we should check if we still need to do this
webkitGetUserMedia: DummyInterfaceWeShouldntBeUsingThis;
webkitGetUserMedia?: DummyInterfaceWeShouldntBeUsingThis;
}
}
2 changes: 1 addition & 1 deletion src/autodiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class AutoDiscovery {
* configuration, which may include error states. Rejects on unexpected
* failure, not when verification fails.
*/
public static async fromDiscoveryConfig(wellknown: IClientWellKnown): Promise<ClientConfig> {
public static async fromDiscoveryConfig(wellknown?: IClientWellKnown): Promise<ClientConfig> {
// Step 1 is to get the config, which is provided to us here.

// We default to an error state to make the first few checks easier to
Expand Down
22 changes: 10 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { noUnsafeEventProps, QueryDict, replaceParam, safeSet, sleep } from "./u
import { Direction, EventTimeline } from "./models/event-timeline.ts";
import { IActionsObject, PushProcessor } from "./pushprocessor.ts";
import { AutoDiscovery, AutoDiscoveryAction } from "./autodiscovery.ts";
import * as olmlib from "./crypto/olmlib.ts";
import { decodeBase64, encodeBase64, encodeUnpaddedBase64Url } from "./base64.ts";
import { IExportedDevice as IExportedOlmDevice } from "./crypto/OlmDevice.ts";
import { IOlmDevice } from "./crypto/algorithms/megolm.ts";
Expand Down Expand Up @@ -252,6 +251,9 @@ export type Store = IStore;
export type ResetTimelineCallback = (roomId: string) => boolean;

const SCROLLBACK_DELAY_MS = 3000;
/**
* @deprecated Not supported for Rust Cryptography.
*/
export const CRYPTO_ENABLED: boolean = isCryptoAvailable();
const TURN_CHECK_INTERVAL = 10 * 60 * 1000; // poll for turn credentials every 10 minutes

Expand Down Expand Up @@ -1830,10 +1832,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns MXID for the logged-in user, or null if not logged in
*/
public getUserId(): string | null {
if (this.credentials && this.credentials.userId) {
return this.credentials.userId;
}
return null;
return this.credentials?.userId ?? null;
}

/**
Expand All @@ -1855,7 +1854,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Domain of this MXID
*/
public getDomain(): string | null {
if (this.credentials && this.credentials.userId) {
if (this.credentials?.userId) {
return this.credentials.userId.replace(/^.*?:/, "");
}
return null;
Expand All @@ -1866,10 +1865,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns The user ID localpart or null.
*/
public getUserIdLocalpart(): string | null {
if (this.credentials && this.credentials.userId) {
return this.credentials.userId.split(":")[0].substring(1);
}
return null;
return this.credentials?.userId?.split(":")[0].substring(1) ?? null;
}

/**
Expand Down Expand Up @@ -2430,6 +2426,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*
* @remarks
* Fires {@link CryptoEvent#DeviceVerificationChanged}
*
* @deprecated Not supported for Rust Cryptography.
*/
public setDeviceVerified(userId: string, deviceId: string, verified = true): Promise<void> {
const prom = this.setDeviceVerification(userId, deviceId, verified, null, null);
Expand Down Expand Up @@ -4309,7 +4307,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*/
public getIgnoredUsers(): string[] {
const event = this.getAccountData("m.ignored_user_list");
if (!event || !event.getContent() || !event.getContent()["ignored_users"]) return [];
if (!event?.getContent()["ignored_users"]) return [];
return Object.keys(event.getContent()["ignored_users"]);
}

Expand Down Expand Up @@ -10115,7 +10113,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
type: EventType.RoomEncryption,
state_key: "",
content: {
algorithm: olmlib.MEGOLM_ALGORITHM,
algorithm: "m.megolm.v1.aes-sha2",
},
},
],
Expand Down
1 change: 1 addition & 0 deletions src/common-crypto/CryptoBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface CryptoBackend extends SyncCryptoCallbacks, CryptoApi {
* Get information about the encryption of an event
*
* @param event - event to be checked
* @deprecated Use {@link CryptoApi#getEncryptionInfoForEvent} instead
*/
getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo;

Expand Down
1 change: 1 addition & 0 deletions src/crypto-api/CryptoEventHandlerMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export type CryptoEventHandlerMap = {
[CryptoEvent.KeysChanged]: (data: {}) => void;
[CryptoEvent.WillUpdateDevices]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.DevicesUpdated]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.LegacyCryptoStoreMigrationProgress]: (progress: number, total: number) => void;
} & RustBackupCryptoEventMap;
2 changes: 1 addition & 1 deletion src/crypto/EncryptionSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class EncryptionSetupBuilder {
if (!this.keySignatures) {
this.keySignatures = {};
}
const userSignatures = this.keySignatures[userId] || {};
const userSignatures = this.keySignatures[userId] ?? {};
this.keySignatures[userId] = userSignatures;
userSignatures[deviceId] = signature;
}
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/dehydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import decryptAESSecretStorageItem from "../utils/decryptAESSecretStorageItem.ts
import encryptAESSecretStorageItem from "../utils/encryptAESSecretStorageItem.ts";

export interface IDehydratedDevice {
device_id: string; // eslint-disable-line camelcase
device_data: SecretStorageKeyDescription & {
device_id?: string; // eslint-disable-line camelcase
device_data?: SecretStorageKeyDescription & {
// eslint-disable-line camelcase
algorithm: string;
account: string; // pickle
Expand Down Expand Up @@ -90,7 +90,7 @@ export class DehydrationManager {
}

public async setKey(
key: Uint8Array,
key?: Uint8Array,
keyInfo: { [props: string]: any } = {},
deviceDisplayName?: string,
): Promise<boolean | undefined> {
Expand Down
2 changes: 0 additions & 2 deletions src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ export type CryptoEventHandlerMap = CryptoApiCryptoEventHandlerMap & {
*/
[CryptoEvent.Warning]: (type: string) => void;
[CryptoEvent.UserCrossSigningUpdated]: (userId: string) => void;

[CryptoEvent.LegacyCryptoStoreMigrationProgress]: (progress: number, total: number) => void;
};

export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap> implements CryptoBackend {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/store/localStorage-crypto-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore implements Crypto
func: (session: ISessionInfo) => void,
): void {
const sessions = this._getEndToEndSessions(deviceKey);
func(sessions[sessionId] || {});
func(sessions[sessionId] ?? {});
}

public getEndToEndSessions(
deviceKey: string,
txn: unknown,
func: (sessions: { [sessionId: string]: ISessionInfo }) => void,
): void {
func(this._getEndToEndSessions(deviceKey) || {});
func(this._getEndToEndSessions(deviceKey) ?? {});
}

public getAllEndToEndSessions(txn: unknown, func: (session: ISessionInfo) => void): void {
Expand Down
8 changes: 4 additions & 4 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
return {} as T;
}
if (this.clearEvent) {
return (this.clearEvent.content || {}) as T;
return (this.clearEvent.content ?? {}) as T;
}
return (this.event.content || {}) as T;
return (this.event.content ?? {}) as T;
}

/**
Expand All @@ -575,7 +575,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
if (this._localRedactionEvent) {
return {} as T;
} else if (this._replacingEvent) {
return this._replacingEvent.getContent()["m.new_content"] || {};
return this._replacingEvent.getContent()["m.new_content"] ?? {};
} else {
return this.getOriginalContent();
}
Expand Down Expand Up @@ -1633,7 +1633,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
* @param otherEvent - The other event to check against.
* @returns True if the events are the same, false otherwise.
*/
public isEquivalentTo(otherEvent: MatrixEvent): boolean {
public isEquivalentTo(otherEvent?: MatrixEvent): boolean {
if (!otherEvent) return false;
if (otherEvent === this) return true;
const myProps = deepSortedObjectEntries(this.event);
Expand Down
6 changes: 4 additions & 2 deletions src/models/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RelationType } from "../@types/event.ts";
import { TypedEventEmitter } from "./typed-event-emitter.ts";
import { MatrixClient } from "../client.ts";
import { Room } from "./room.ts";
import { CryptoBackend } from "../common-crypto/CryptoBackend.ts";

export enum RelationsEvent {
Add = "Relations.add",
Expand Down Expand Up @@ -323,8 +324,9 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
return event;
}, null);

if (lastReplacement?.shouldAttemptDecryption() && this.client.isCryptoEnabled()) {
await lastReplacement.attemptDecryption(this.client.crypto!);
if (lastReplacement?.shouldAttemptDecryption() && this.client.getCrypto()) {
// Dirty but we are expecting to pass the cryptoBackend which is not accessible here
await lastReplacement.attemptDecryption(this.client.getCrypto() as CryptoBackend);
} else if (lastReplacement?.isBeingDecrypted()) {
await lastReplacement.getDecryptionPromise();
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
* @returns Signals when all events have been decrypted
*/
public async decryptCriticalEvents(): Promise<void> {
if (!this.client.isCryptoEnabled()) return;
if (!this.client.getCrypto()) return;

const readReceiptEventId = this.getEventReadUpTo(this.client.getUserId()!, true);
const events = this.getLiveTimeline().getEvents();
Expand All @@ -567,7 +567,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
* @returns Signals when all events have been decrypted
*/
public async decryptAllEvents(): Promise<void> {
if (!this.client.isCryptoEnabled()) return;
if (!this.client.getCrypto()) return;

const decryptionPromises = this.getUnfilteredTimelineSet()
.getLiveTimeline()
Expand Down
Loading

0 comments on commit cb6b623

Please sign in to comment.