@@ -215,6 +215,7 @@ import { UIARequest, UIAResponse } from "./@types/uia";
215
215
import { LocalNotificationSettings } from "./@types/local_notifications" ;
216
216
import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync" ;
217
217
import { buildFeatureSupportMap , Feature , ServerSupport } from "./feature" ;
218
+ import { CryptoBackend } from "./common-crypto/CryptoBackend" ;
218
219
219
220
export type Store = IStore ;
220
221
@@ -1142,7 +1143,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
1142
1143
public urlPreviewCache : { [ key : string ] : Promise < IPreviewUrlResponse > } = { } ;
1143
1144
public identityServer ?: IIdentityServerProvider ;
1144
1145
public http : MatrixHttpApi < IHttpOpts & { onlyData : true } > ; // XXX: Intended private, used in code.
1145
- public crypto ?: Crypto ; // XXX: Intended private, used in code.
1146
+ public crypto ?: Crypto ; // libolm crypto implementation. XXX: Intended private, used in code. Being replaced by cryptoBackend
1147
+ private cryptoBackend ?: CryptoBackend ; // one of crypto or rustCrypto
1146
1148
public cryptoCallbacks : ICryptoCallbacks ; // XXX: Intended private, used in code.
1147
1149
public callEventHandler ?: CallEventHandler ; // XXX: Intended private, used in code.
1148
1150
public groupCallEventHandler ?: GroupCallEventHandler ;
@@ -1449,7 +1451,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
1449
1451
* clean shutdown.
1450
1452
*/
1451
1453
public stopClient ( ) : void {
1452
- this . crypto ?. stop ( ) ; // crypto might have been initialised even if the client wasn't fully started
1454
+ this . cryptoBackend ?. stop ( ) ; // crypto might have been initialised even if the client wasn't fully started
1453
1455
1454
1456
if ( ! this . clientRunning ) return ; // already stopped
1455
1457
@@ -1954,7 +1956,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
1954
1956
}
1955
1957
1956
1958
/**
1957
- * Initialise support for end-to-end encryption in this client
1959
+ * Initialise support for end-to-end encryption in this client, using libolm.
1958
1960
*
1959
1961
* You should call this method after creating the matrixclient, but *before*
1960
1962
* calling `startClient`, if you want to support end-to-end encryption.
@@ -1970,7 +1972,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
1970
1972
) ;
1971
1973
}
1972
1974
1973
- if ( this . crypto ) {
1975
+ if ( this . cryptoBackend ) {
1974
1976
logger . warn ( "Attempt to re-initialise e2e encryption on MatrixClient" ) ;
1975
1977
return ;
1976
1978
}
@@ -2035,7 +2037,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2035
2037
2036
2038
// if crypto initialisation was successful, tell it to attach its event handlers.
2037
2039
crypto . registerEventHandlers ( this as Parameters < Crypto [ "registerEventHandlers" ] > [ 0 ] ) ;
2038
- this . crypto = crypto ;
2040
+ this . cryptoBackend = this . crypto = crypto ;
2039
2041
2040
2042
// upload our keys in the background
2041
2043
this . crypto . uploadDeviceKeys ( ) . catch ( ( e ) => {
@@ -2049,7 +2051,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2049
2051
* @returns True if end-to-end is enabled.
2050
2052
*/
2051
2053
public isCryptoEnabled ( ) : boolean {
2052
- return ! ! this . crypto ;
2054
+ return ! ! this . cryptoBackend ;
2053
2055
}
2054
2056
2055
2057
/**
@@ -2297,21 +2299,21 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2297
2299
* @param value - whether to blacklist all unverified devices by default
2298
2300
*/
2299
2301
public setGlobalBlacklistUnverifiedDevices ( value : boolean ) : boolean {
2300
- if ( ! this . crypto ) {
2302
+ if ( ! this . cryptoBackend ) {
2301
2303
throw new Error ( "End-to-end encryption disabled" ) ;
2302
2304
}
2303
- this . crypto . globalBlacklistUnverifiedDevices = value ;
2305
+ this . cryptoBackend . globalBlacklistUnverifiedDevices = value ;
2304
2306
return value ;
2305
2307
}
2306
2308
2307
2309
/**
2308
2310
* @returns whether to blacklist all unverified devices by default
2309
2311
*/
2310
2312
public getGlobalBlacklistUnverifiedDevices ( ) : boolean {
2311
- if ( ! this . crypto ) {
2313
+ if ( ! this . cryptoBackend ) {
2312
2314
throw new Error ( "End-to-end encryption disabled" ) ;
2313
2315
}
2314
- return this . crypto . globalBlacklistUnverifiedDevices ;
2316
+ return this . cryptoBackend . globalBlacklistUnverifiedDevices ;
2315
2317
}
2316
2318
2317
2319
/**
@@ -2325,10 +2327,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2325
2327
* @param value - whether error on unknown devices
2326
2328
*/
2327
2329
public setGlobalErrorOnUnknownDevices ( value : boolean ) : void {
2328
- if ( ! this . crypto ) {
2330
+ if ( ! this . cryptoBackend ) {
2329
2331
throw new Error ( "End-to-end encryption disabled" ) ;
2330
2332
}
2331
- this . crypto . globalErrorOnUnknownDevices = value ;
2333
+ this . cryptoBackend . globalErrorOnUnknownDevices = value ;
2332
2334
}
2333
2335
2334
2336
/**
@@ -2337,10 +2339,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2337
2339
* This API is currently UNSTABLE and may change or be removed without notice.
2338
2340
*/
2339
2341
public getGlobalErrorOnUnknownDevices ( ) : boolean {
2340
- if ( ! this . crypto ) {
2342
+ if ( ! this . cryptoBackend ) {
2341
2343
throw new Error ( "End-to-end encryption disabled" ) ;
2342
2344
}
2343
- return this . crypto . globalErrorOnUnknownDevices ;
2345
+ return this . cryptoBackend . globalErrorOnUnknownDevices ;
2344
2346
}
2345
2347
2346
2348
/**
@@ -2480,10 +2482,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
2480
2482
* the cross-signing pseudo-device.
2481
2483
*/
2482
2484
public userHasCrossSigningKeys ( ) : Promise < boolean > {
2483
- if ( ! this . crypto ) {
2485
+ if ( ! this . cryptoBackend ) {
2484
2486
throw new Error ( "End-to-end encryption disabled" ) ;
2485
2487
}
2486
- return this . crypto . userHasCrossSigningKeys ( ) ;
2488
+ return this . cryptoBackend . userHasCrossSigningKeys ( ) ;
2487
2489
}
2488
2490
2489
2491
/**
@@ -7216,7 +7218,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7216
7218
*/
7217
7219
public decryptEventIfNeeded ( event : MatrixEvent , options ?: IDecryptOptions ) : Promise < void > {
7218
7220
if ( event . shouldAttemptDecryption ( ) && this . isCryptoEnabled ( ) ) {
7219
- event . attemptDecryption ( this . crypto ! , options ) ;
7221
+ event . attemptDecryption ( this . cryptoBackend ! , options ) ;
7220
7222
}
7221
7223
7222
7224
if ( event . isBeingDecrypted ( ) ) {
0 commit comments