Skip to content

Commit 59a4dbd

Browse files
committed
Remove MatrixClient.initLegacyCrypto
1 parent bdd4d82 commit 59a4dbd

File tree

1 file changed

+3
-86
lines changed

1 file changed

+3
-86
lines changed

src/client.ts

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export interface ICreateClientOpts {
296296
* specified, uses a default implementation (indexeddb in the browser,
297297
* in-memory otherwise).
298298
*
299-
* This is only used for the legacy crypto implementation (as used by {@link MatrixClient#initLegacyCrypto}),
299+
* This is only used for the legacy crypto implementation,
300300
* but if you use the rust crypto implementation ({@link MatrixClient#initRustCrypto}) and the device
301301
* previously used legacy crypto (so must be migrated), then this must still be provided, so that the
302302
* data can be migrated from the legacy store.
@@ -391,7 +391,7 @@ export interface ICreateClientOpts {
391391
*
392392
* This must be set to the same value every time the client is initialised for the same device.
393393
*
394-
* This is only used for the legacy crypto implementation (as used by {@link MatrixClient#initLegacyCrypto}),
394+
* This is only used for the legacy crypto implementation,
395395
* but if you use the rust crypto implementation ({@link MatrixClient#initRustCrypto}) and the device
396396
* previously used legacy crypto (so must be migrated), then this must still be provided, so that the
397397
* data can be migrated from the legacy store.
@@ -2138,92 +2138,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
21382138
return this.serverCapabilitiesService.fetchCapabilities();
21392139
}
21402140

2141-
/**
2142-
* Initialise support for end-to-end encryption in this client, using libolm.
2143-
*
2144-
* You should call this method after creating the matrixclient, but *before*
2145-
* calling `startClient`, if you want to support end-to-end encryption.
2146-
*
2147-
* It will return a Promise which will resolve when the crypto layer has been
2148-
* successfully initialised.
2149-
*
2150-
* @deprecated libolm is deprecated. Prefer {@link initRustCrypto}.
2151-
*/
2152-
public async initLegacyCrypto(): Promise<void> {
2153-
if (!isCryptoAvailable()) {
2154-
throw new Error(
2155-
`End-to-end encryption not supported in this js-sdk build: did ` +
2156-
`you remember to load the olm library?`,
2157-
);
2158-
}
2159-
2160-
if (this.cryptoBackend) {
2161-
this.logger.warn("Attempt to re-initialise e2e encryption on MatrixClient");
2162-
return;
2163-
}
2164-
2165-
if (!this.cryptoStore) {
2166-
// the cryptostore is provided by sdk.createClient, so this shouldn't happen
2167-
throw new Error(`Cannot enable encryption: no cryptoStore provided`);
2168-
}
2169-
2170-
this.logger.debug("Crypto: Starting up crypto store...");
2171-
await this.cryptoStore.startup();
2172-
2173-
const userId = this.getUserId();
2174-
if (userId === null) {
2175-
throw new Error(
2176-
`Cannot enable encryption on MatrixClient with unknown userId: ` +
2177-
`ensure userId is passed in createClient().`,
2178-
);
2179-
}
2180-
if (this.deviceId === null) {
2181-
throw new Error(
2182-
`Cannot enable encryption on MatrixClient with unknown deviceId: ` +
2183-
`ensure deviceId is passed in createClient().`,
2184-
);
2185-
}
2186-
2187-
const crypto = new Crypto(this, userId, this.deviceId, this.store, this.cryptoStore, this.verificationMethods!);
2188-
2189-
this.reEmitter.reEmit(crypto, [
2190-
LegacyCryptoEvent.KeyBackupFailed,
2191-
LegacyCryptoEvent.KeyBackupSessionsRemaining,
2192-
LegacyCryptoEvent.RoomKeyRequest,
2193-
LegacyCryptoEvent.RoomKeyRequestCancellation,
2194-
LegacyCryptoEvent.Warning,
2195-
LegacyCryptoEvent.DevicesUpdated,
2196-
LegacyCryptoEvent.WillUpdateDevices,
2197-
LegacyCryptoEvent.DeviceVerificationChanged,
2198-
LegacyCryptoEvent.UserTrustStatusChanged,
2199-
LegacyCryptoEvent.KeysChanged,
2200-
]);
2201-
2202-
this.logger.debug("Crypto: initialising crypto object...");
2203-
await crypto.init({
2204-
exportedOlmDevice: this.exportedOlmDeviceToImport,
2205-
pickleKey: this.pickleKey,
2206-
});
2207-
delete this.exportedOlmDeviceToImport;
2208-
2209-
this.olmVersion = Crypto.getOlmVersion();
2210-
2211-
// if crypto initialisation was successful, tell it to attach its event handlers.
2212-
crypto.registerEventHandlers(this as Parameters<Crypto["registerEventHandlers"]>[0]);
2213-
this.cryptoBackend = this.crypto = crypto;
2214-
2215-
// upload our keys in the background
2216-
this.crypto.uploadDeviceKeys().catch((e) => {
2217-
// TODO: throwing away this error is a really bad idea.
2218-
this.logger.error("Error uploading device keys", e);
2219-
});
2220-
}
2221-
22222141
/**
22232142
* Initialise support for end-to-end encryption in this client, using the rust matrix-sdk-crypto.
22242143
*
2225-
* An alternative to {@link initLegacyCrypto}.
2226-
*
22272144
* **WARNING**: the cryptography stack is not thread-safe. Having multiple `MatrixClient` instances connected to
22282145
* the same Indexed DB will cause data corruption and decryption failures. The application layer is responsible for
22292146
* ensuring that only one `MatrixClient` issue is instantiated at a time.
@@ -2323,7 +2240,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
23232240
/**
23242241
* Access the crypto API for this client.
23252242
*
2326-
* If end-to-end encryption has been enabled for this client (via {@link initLegacyCrypto} or {@link initRustCrypto}),
2243+
* If end-to-end encryption has been enabled for this client (via {@link initRustCrypto}),
23272244
* returns an object giving access to the crypto API. Otherwise, returns `undefined`.
23282245
*/
23292246
public getCrypto(): CryptoApi | undefined {

0 commit comments

Comments
 (0)