Skip to content

Commit c54ca29

Browse files
authored
Rename initCrypto into initLegacyCrypto (#4567)
1 parent beb3721 commit c54ca29

16 files changed

+61
-57
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ Then visit `http://localhost:8005` to see the API docs.
307307

308308
## Initialization
309309

310-
**Do not use `matrixClient.initCrypto()`. This method is deprecated and no longer maintained.**
310+
**Do not use `matrixClient.initLegacyCrypto()`. This method is deprecated and no longer maintained.**
311311

312312
To initialize the end-to-end encryption support in the matrix client:
313313

@@ -398,10 +398,10 @@ Once the cross-signing is set up on one of your devices, you can verify another
398398

399399
## Migrating from the legacy crypto stack to Rust crypto
400400

401-
If your application previously used the legacy crypto stack, (i.e, it called `MatrixClient.initCrypto()`), you will
401+
If your application previously used the legacy crypto stack, (i.e, it called `MatrixClient.initLegacyCrypto()`), you will
402402
need to migrate existing devices to the Rust crypto stack.
403403

404-
This migration happens automatically when you call `initRustCrypto()` instead of `initCrypto()`,
404+
This migration happens automatically when you call `initRustCrypto()` instead of `initLegacyCrypto()`,
405405
but you need to provide the legacy [`cryptoStore`](https://matrix-org.github.io/matrix-js-sdk/interfaces/matrix.ICreateClientOpts.html#cryptoStore) and [`pickleKey`](https://matrix-org.github.io/matrix-js-sdk/interfaces/matrix.ICreateClientOpts.html#pickleKey) to [`createClient`](https://matrix-org.github.io/matrix-js-sdk/functions/matrix.createClient.html):
406406

407407
```javascript

spec/integ/crypto/crypto.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
17411741
groupSession: groupSession,
17421742
room_id: ROOM_ID,
17431743
});
1744-
await testClient.client.initCrypto();
1744+
await testClient.client.initLegacyCrypto();
17451745
const keys = [
17461746
{
17471747
room_id: ROOM_ID,
@@ -1853,7 +1853,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
18531853

18541854
oldBackendOnly("Alice receives shared history before being invited to a room by the sharer", async () => {
18551855
const beccaTestClient = new TestClient("@becca:localhost", "foobar", "bazquux");
1856-
await beccaTestClient.client.initCrypto();
1856+
await beccaTestClient.client.initLegacyCrypto();
18571857

18581858
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
18591859
await startClientAndAwaitFirstSync();
@@ -2007,7 +2007,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
20072007

20082008
oldBackendOnly("Alice receives shared history before being invited to a room by someone else", async () => {
20092009
const beccaTestClient = new TestClient("@becca:localhost", "foobar", "bazquux");
2010-
await beccaTestClient.client.initCrypto();
2010+
await beccaTestClient.client.initLegacyCrypto();
20112011

20122012
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
20132013
await startClientAndAwaitFirstSync();

spec/integ/crypto/olm-encryption-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ describe("MatrixClient crypto", () => {
345345

346346
beforeEach(async () => {
347347
aliTestClient = new TestClient(aliUserId, aliDeviceId, aliAccessToken);
348-
await aliTestClient.client.initCrypto();
348+
await aliTestClient.client.initLegacyCrypto();
349349

350350
bobTestClient = new TestClient(bobUserId, bobDeviceId, bobAccessToken);
351-
await bobTestClient.client.initCrypto();
351+
await bobTestClient.client.initLegacyCrypto();
352352

353353
aliMessages = [];
354354
bobMessages = [];

spec/integ/devicelist-integ.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("DeviceList management:", function () {
7777

7878
async function createTestClient() {
7979
const testClient = new TestClient("@alice:localhost", "xzcvb", "akjgkrgjs", sessionStoreBackend);
80-
await testClient.client.initCrypto();
80+
await testClient.client.initLegacyCrypto();
8181
return testClient;
8282
}
8383

spec/integ/matrix-client-methods.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ describe("MatrixClient", function () {
650650
}
651651

652652
beforeEach(function () {
653-
// running initCrypto should trigger a key upload
653+
// running initLegacyCrypto should trigger a key upload
654654
httpBackend.when("POST", "/keys/upload").respond(200, {});
655-
return Promise.all([client.initCrypto(), httpBackend.flush("/keys/upload", 1)]);
655+
return Promise.all([client.initLegacyCrypto(), httpBackend.flush("/keys/upload", 1)]);
656656
});
657657

658658
afterEach(() => {

spec/integ/matrix-client-syncing.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("MatrixClient syncing", () => {
112112
});
113113

114114
it("should emit RoomEvent.MyMembership for invite->leave->invite cycles", async () => {
115-
await client!.initCrypto();
115+
await client!.initLegacyCrypto();
116116

117117
const roomId = "!cycles:example.org";
118118

@@ -227,7 +227,7 @@ describe("MatrixClient syncing", () => {
227227
});
228228

229229
it("should emit RoomEvent.MyMembership for knock->leave->knock cycles", async () => {
230-
await client!.initCrypto();
230+
await client!.initLegacyCrypto();
231231

232232
const roomId = "!cycles:example.org";
233233

@@ -2573,7 +2573,7 @@ describe("MatrixClient syncing (IndexedDB version)", () => {
25732573
idbHttpBackend.when("GET", "/pushrules/").respond(200, {});
25742574
idbHttpBackend.when("POST", "/filter").respond(200, { filter_id: "a filter id" });
25752575

2576-
await idbClient.initCrypto();
2576+
await idbClient.initLegacyCrypto();
25772577

25782578
const roomId = "!invite:example.org";
25792579

spec/integ/sliding-sync-sdk.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("SlidingSyncSdk", () => {
119119
mockSlidingSync = mockifySlidingSync(new SlidingSync("", new Map(), {}, client, 0));
120120
if (testOpts.withCrypto) {
121121
httpBackend!.when("GET", "/room_keys/version").respond(404, {});
122-
await client!.initCrypto();
122+
await client!.initLegacyCrypto();
123123
syncOpts.cryptoCallbacks = syncOpts.crypto = client!.crypto;
124124
}
125125
httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {});

spec/test-utils/test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export type InitCrypto = (_: MatrixClient) => Promise<void>;
561561

562562
CRYPTO_BACKENDS["rust-sdk"] = (client: MatrixClient) => client.initRustCrypto();
563563
if (globalThis.Olm) {
564-
CRYPTO_BACKENDS["libolm"] = (client: MatrixClient) => client.initCrypto();
564+
CRYPTO_BACKENDS["libolm"] = (client: MatrixClient) => client.initLegacyCrypto();
565565
}
566566

567567
export const emitPromise = (e: EventEmitter, k: string): Promise<any> => new Promise((r) => e.once(k, r));

spec/unit/crypto.spec.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("Crypto", function () {
119119

120120
it("getVersion() should return the current version of the olm library", async () => {
121121
const client = new TestClient("@alice:example.com", "deviceid").client;
122-
await client.initCrypto();
122+
await client.initLegacyCrypto();
123123

124124
const olmVersionTuple = Crypto.getOlmVersion();
125125
expect(client.getCrypto()?.getVersion()).toBe(
@@ -130,7 +130,7 @@ describe("Crypto", function () {
130130
describe("encrypted events", function () {
131131
it("provides encryption information for events from unverified senders", async function () {
132132
const client = new TestClient("@alice:example.com", "deviceid").client;
133-
await client.initCrypto();
133+
await client.initLegacyCrypto();
134134

135135
// unencrypted event
136136
const event = {
@@ -210,7 +210,7 @@ describe("Crypto", function () {
210210
let client: MatrixClient;
211211
beforeEach(async () => {
212212
client = new TestClient("@alice:example.com", "deviceid").client;
213-
await client.initCrypto();
213+
await client.initLegacyCrypto();
214214

215215
// mock out the verification check
216216
client.crypto!.checkUserTrust = (userId) => new UserTrustLevel(true, false, false);
@@ -306,7 +306,7 @@ describe("Crypto", function () {
306306

307307
it("doesn't throw an error when attempting to decrypt a redacted event", async () => {
308308
const client = new TestClient("@alice:example.com", "deviceid").client;
309-
await client.initCrypto();
309+
await client.initLegacyCrypto();
310310

311311
const event = new MatrixEvent({
312312
content: {},
@@ -439,10 +439,10 @@ describe("Crypto", function () {
439439
secondAliceClient = new TestClient("@alice:example.com", "secondAliceDevice").client;
440440
bobClient = new TestClient("@bob:example.com", "bobdevice").client;
441441
claraClient = new TestClient("@clara:example.com", "claradevice").client;
442-
await aliceClient.initCrypto();
443-
await secondAliceClient.initCrypto();
444-
await bobClient.initCrypto();
445-
await claraClient.initCrypto();
442+
await aliceClient.initLegacyCrypto();
443+
await secondAliceClient.initLegacyCrypto();
444+
await bobClient.initLegacyCrypto();
445+
await claraClient.initLegacyCrypto();
446446
});
447447

448448
afterEach(async function () {
@@ -1111,7 +1111,7 @@ describe("Crypto", function () {
11111111
jest.spyOn(logger, "debug").mockImplementation(() => {});
11121112
jest.setTimeout(10000);
11131113
const client = new TestClient("@a:example.com", "dev").client;
1114-
await client.initCrypto();
1114+
await client.initLegacyCrypto();
11151115
client.crypto!.isCrossSigningReady = async () => false;
11161116
client.crypto!.baseApis.uploadDeviceSigningKeys = jest.fn().mockResolvedValue(null);
11171117
client.crypto!.baseApis.setAccountData = jest.fn().mockResolvedValue(null);
@@ -1147,9 +1147,9 @@ describe("Crypto", function () {
11471147

11481148
client = new TestClient("@alice:example.org", "aliceweb");
11491149

1150-
// running initCrypto should trigger a key upload
1150+
// running initLegacyCrypto should trigger a key upload
11511151
client.httpBackend.when("POST", "/keys/upload").respond(200, {});
1152-
await Promise.all([client.client.initCrypto(), client.httpBackend.flush("/keys/upload", 1)]);
1152+
await Promise.all([client.client.initLegacyCrypto(), client.httpBackend.flush("/keys/upload", 1)]);
11531153

11541154
encryptedPayload = {
11551155
algorithm: "m.olm.v1.curve25519-aes-sha2",
@@ -1264,9 +1264,9 @@ describe("Crypto", function () {
12641264

12651265
client = new TestClient("@alice:example.org", "aliceweb");
12661266

1267-
// running initCrypto should trigger a key upload
1267+
// running initLegacyCrypto should trigger a key upload
12681268
client.httpBackend.when("POST", "/keys/upload").respond(200, {});
1269-
await Promise.all([client.client.initCrypto(), client.httpBackend.flush("/keys/upload", 1)]);
1269+
await Promise.all([client.client.initLegacyCrypto(), client.httpBackend.flush("/keys/upload", 1)]);
12701270

12711271
encryptedPayload = {
12721272
algorithm: "m.olm.v1.curve25519-aes-sha2",
@@ -1362,7 +1362,7 @@ describe("Crypto", function () {
13621362

13631363
beforeEach(async () => {
13641364
client = new TestClient("@alice:example.org", "aliceweb");
1365-
await client.client.initCrypto();
1365+
await client.client.initLegacyCrypto();
13661366
});
13671367

13681368
afterEach(async () => {
@@ -1388,7 +1388,7 @@ describe("Crypto", function () {
13881388

13891389
beforeEach(async () => {
13901390
client = new TestClient("@alice:example.org", "aliceweb");
1391-
await client.client.initCrypto();
1391+
await client.client.initLegacyCrypto();
13921392
});
13931393

13941394
afterEach(async () => {
@@ -1414,7 +1414,7 @@ describe("Crypto", function () {
14141414

14151415
beforeEach(async () => {
14161416
client = new TestClient("@alice:example.org", "aliceweb");
1417-
await client.client.initCrypto();
1417+
await client.client.initLegacyCrypto();
14181418
});
14191419

14201420
afterEach(async function () {

spec/unit/crypto/algorithms/megolm.spec.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,11 @@ describe("MegolmDecryption", function () {
610610
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
611611
const bobClient1 = new TestClient("@bob:example.com", "bobdevice1").client;
612612
const bobClient2 = new TestClient("@bob:example.com", "bobdevice2").client;
613-
await Promise.all([aliceClient.initCrypto(), bobClient1.initCrypto(), bobClient2.initCrypto()]);
613+
await Promise.all([
614+
aliceClient.initLegacyCrypto(),
615+
bobClient1.initLegacyCrypto(),
616+
bobClient2.initLegacyCrypto(),
617+
]);
614618
const aliceDevice = aliceClient.crypto!.olmDevice;
615619
const bobDevice1 = bobClient1.crypto!.olmDevice;
616620
const bobDevice2 = bobClient2.crypto!.olmDevice;
@@ -704,7 +708,7 @@ describe("MegolmDecryption", function () {
704708
it("does not block unverified devices when sending verification events", async function () {
705709
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
706710
const bobClient = new TestClient("@bob:example.com", "bobdevice").client;
707-
await Promise.all([aliceClient.initCrypto(), bobClient.initCrypto()]);
711+
await Promise.all([aliceClient.initLegacyCrypto(), bobClient.initLegacyCrypto()]);
708712
const bobDevice = bobClient.crypto!.olmDevice;
709713

710714
const encryptionCfg = {
@@ -789,7 +793,7 @@ describe("MegolmDecryption", function () {
789793
it("notifies devices when unable to create olm session", async function () {
790794
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
791795
const bobClient = new TestClient("@bob:example.com", "bobdevice").client;
792-
await Promise.all([aliceClient.initCrypto(), bobClient.initCrypto()]);
796+
await Promise.all([aliceClient.initLegacyCrypto(), bobClient.initLegacyCrypto()]);
793797
const aliceDevice = aliceClient.crypto!.olmDevice;
794798
const bobDevice = bobClient.crypto!.olmDevice;
795799

@@ -873,7 +877,7 @@ describe("MegolmDecryption", function () {
873877
it("throws an error describing why it doesn't have a key", async function () {
874878
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
875879
const bobClient = new TestClient("@bob:example.com", "bobdevice").client;
876-
await Promise.all([aliceClient.initCrypto(), bobClient.initCrypto()]);
880+
await Promise.all([aliceClient.initLegacyCrypto(), bobClient.initLegacyCrypto()]);
877881
const bobDevice = bobClient.crypto!.olmDevice;
878882

879883
const aliceEventEmitter = new TypedEventEmitter<ClientEvent.ToDeviceEvent, any>();
@@ -955,7 +959,7 @@ describe("MegolmDecryption", function () {
955959
it("throws an error describing the lack of an olm session", async function () {
956960
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
957961
const bobClient = new TestClient("@bob:example.com", "bobdevice").client;
958-
await Promise.all([aliceClient.initCrypto(), bobClient.initCrypto()]);
962+
await Promise.all([aliceClient.initLegacyCrypto(), bobClient.initLegacyCrypto()]);
959963

960964
const aliceEventEmitter = new TypedEventEmitter<ClientEvent.ToDeviceEvent, any>();
961965
aliceClient.crypto!.registerEventHandlers(aliceEventEmitter);
@@ -1051,7 +1055,7 @@ describe("MegolmDecryption", function () {
10511055
it("throws an error to indicate a wedged olm session", async function () {
10521056
const aliceClient = new TestClient("@alice:example.com", "alicedevice").client;
10531057
const bobClient = new TestClient("@bob:example.com", "bobdevice").client;
1054-
await Promise.all([aliceClient.initCrypto(), bobClient.initCrypto()]);
1058+
await Promise.all([aliceClient.initLegacyCrypto(), bobClient.initLegacyCrypto()]);
10551059
const aliceEventEmitter = new TypedEventEmitter<ClientEvent.ToDeviceEvent, any>();
10561060
aliceClient.crypto!.registerEventHandlers(aliceEventEmitter);
10571061

spec/unit/crypto/backup.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe("MegolmBackup", function () {
231231

232232
test("fail if given backup has no version", async () => {
233233
const client = makeTestClient(cryptoStore);
234-
await client.initCrypto();
234+
await client.initLegacyCrypto();
235235
const data = {
236236
algorithm: olmlib.MEGOLM_BACKUP_ALGORITHM,
237237
auth_data: {
@@ -314,7 +314,7 @@ describe("MegolmBackup", function () {
314314
megolmDecryption.olmlib = mockOlmLib;
315315

316316
return client
317-
.initCrypto()
317+
.initLegacyCrypto()
318318
.then(() => {
319319
return cryptoStore.doTxn("readwrite", [IndexedDBCryptoStore.STORE_SESSIONS], (txn) => {
320320
cryptoStore.addEndToEndInboundGroupSession(
@@ -391,7 +391,7 @@ describe("MegolmBackup", function () {
391391
megolmDecryption.olmlib = mockOlmLib;
392392

393393
return client
394-
.initCrypto()
394+
.initLegacyCrypto()
395395
.then(() => {
396396
return client.crypto!.storeSessionBackupPrivateKey(new Uint8Array(32));
397397
})
@@ -471,7 +471,7 @@ describe("MegolmBackup", function () {
471471
// @ts-ignore private field access
472472
megolmDecryption.olmlib = mockOlmLib;
473473

474-
await client.initCrypto();
474+
await client.initLegacyCrypto();
475475
client.uploadDeviceSigningKeys = async function (e) {
476476
return {};
477477
};
@@ -560,7 +560,7 @@ describe("MegolmBackup", function () {
560560
// @ts-ignore private field access
561561
megolmDecryption.olmlib = mockOlmLib;
562562

563-
await client.initCrypto();
563+
await client.initLegacyCrypto();
564564
await cryptoStore.doTxn("readwrite", [IndexedDBCryptoStore.STORE_SESSIONS], (txn) => {
565565
cryptoStore.addEndToEndInboundGroupSession(
566566
"F0Q2NmyJNgUVj9DGsb4ZQt3aVxhVcUQhg7+gvW0oyKI",
@@ -636,7 +636,7 @@ describe("MegolmBackup", function () {
636636
// @ts-ignore private field access
637637
megolmDecryption.olmlib = mockOlmLib;
638638

639-
return client.initCrypto();
639+
return client.initLegacyCrypto();
640640
});
641641

642642
afterEach(function () {
@@ -773,7 +773,7 @@ describe("MegolmBackup", function () {
773773
// initialising the crypto library will trigger a key upload request, which we can stub out
774774
client.uploadKeysRequest = jest.fn();
775775

776-
await client.initCrypto();
776+
await client.initLegacyCrypto();
777777

778778
cryptoStore.countSessionsNeedingBackup = jest.fn().mockReturnValue(6);
779779
await expect(client.flagAllGroupSessionsForBackup()).resolves.toBe(6);
@@ -784,7 +784,7 @@ describe("MegolmBackup", function () {
784784
describe("getKeyBackupInfo", () => {
785785
it("should return throw an `Not implemented`", async () => {
786786
const client = makeTestClient(cryptoStore);
787-
await client.initCrypto();
787+
await client.initLegacyCrypto();
788788
await expect(client.getCrypto()?.getKeyBackupInfo()).rejects.toThrow("Not implemented");
789789
});
790790
});

spec/unit/crypto/cross-signing.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function makeTestClient(
7878
const testClient = new TestClient(userInfo.userId, userInfo.deviceId, undefined, undefined, options);
7979
const client = testClient.client;
8080

81-
await client.initCrypto();
81+
await client.initLegacyCrypto();
8282

8383
return { client, httpBackend: testClient.httpBackend };
8484
}

spec/unit/crypto/dehydration.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe("Dehydration", () => {
6868
},
6969
});
7070

71-
await alice.client.initCrypto();
71+
await alice.client.initLegacyCrypto();
7272

7373
alice.httpBackend.when("GET", "/room_keys/version").respond(404, {
7474
errcode: "M_NOT_FOUND",

spec/unit/crypto/secrets.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function makeTestClient(
4343
return true;
4444
};
4545

46-
await client.initCrypto();
46+
await client.initLegacyCrypto();
4747

4848
// No need to download keys for these tests
4949
jest.spyOn(client.crypto!, "downloadKeys").mockResolvedValue(new Map());

0 commit comments

Comments
 (0)