@@ -309,6 +309,40 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
309
309
return ;
310
310
}
311
311
312
+ /**
313
+ * Implementation of {@link CryptoBackend#getBackupDecryptor}.
314
+ */
315
+ public async getBackupDecryptor ( backupInfo : KeyBackupInfo , privKey : ArrayLike < number > ) : Promise < BackupDecryptor > {
316
+ if ( backupInfo . algorithm != "m.megolm_backup.v1.curve25519-aes-sha2" ) {
317
+ throw new Error ( `getBackupDecryptor Unsupported algorithm ${ backupInfo . algorithm } ` ) ;
318
+ }
319
+
320
+ const authData = < Curve25519AuthData > backupInfo . auth_data ;
321
+
322
+ if ( ! ( privKey instanceof Uint8Array ) ) {
323
+ throw new Error ( `getBackupDecryptor expects Uint8Array` ) ;
324
+ }
325
+
326
+ const backupDecryptionKey = RustSdkCryptoJs . BackupDecryptionKey . fromBase64 ( encodeBase64 ( privKey ) ) ;
327
+
328
+ if ( authData . public_key != backupDecryptionKey . megolmV1PublicKey . publicKeyBase64 ) {
329
+ throw new Error ( `getBackupDecryptor key mismatch error` ) ;
330
+ }
331
+
332
+ return this . backupManager . createBackupDecryptor ( backupDecryptionKey ) ;
333
+ }
334
+
335
+ /**
336
+ * Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
337
+ */
338
+ public async importBackedUpRoomKeys (
339
+ keys : IMegolmSessionData [ ] ,
340
+ backupVersion : string ,
341
+ opts ?: ImportRoomKeysOpts ,
342
+ ) : Promise < void > {
343
+ return await this . backupManager . importBackedUpRoomKeys ( keys , backupVersion , opts ) ;
344
+ }
345
+
312
346
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
313
347
//
314
348
// CryptoApi implementation
@@ -1166,30 +1200,12 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
1166
1200
this . checkKeyBackupAndEnable ( ) ;
1167
1201
}
1168
1202
1169
- /**
1170
- * Implementation of {@link CryptoApi#importSecretsBundle}.
1171
- */
1172
- public async importSecretsBundle (
1173
- secrets : Parameters < NonNullable < CryptoApi [ "importSecretsBundle" ] > > [ 0 ] ,
1174
- ) : Promise < void > {
1175
- const secretsBundle = RustSdkCryptoJs . SecretsBundle . from_json ( secrets ) ;
1176
- await this . getOlmMachineOrThrow ( ) . importSecretsBundle ( secretsBundle ) ; // this method frees the SecretsBundle
1177
- }
1178
-
1179
- /**
1180
- * Implementation of {@link CryptoApi#exportSecretsBundle}.
1181
- */
1182
- public async exportsSecretsBundle ( ) : ReturnType < NonNullable < CryptoApi [ "exportSecretsBundle" ] > > {
1183
- const secretsBundle = await this . getOlmMachineOrThrow ( ) . exportSecretsBundle ( ) ;
1184
- const secrets = secretsBundle . to_json ( ) ;
1185
- secretsBundle . free ( ) ;
1186
- return secrets ;
1187
- }
1188
-
1189
1203
/**
1190
1204
* Signs the given object with the current device and current identity (if available).
1191
1205
* As defined in {@link https://spec.matrix.org/v1.8/appendices/#signing-json | Signing JSON}.
1192
1206
*
1207
+ * Helper for {@link RustCrypto#resetKeyBackup}.
1208
+ *
1193
1209
* @param obj - The object to sign
1194
1210
*/
1195
1211
private async signObject < T extends ISignableObject & object > ( obj : T ) : Promise < void > {
@@ -1213,54 +1229,40 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
1213
1229
}
1214
1230
1215
1231
/**
1216
- * Implementation of {@link CryptoBackend#getBackupDecryptor }.
1232
+ * Implementation of {@link CryptoApi#isDehydrationSupported }.
1217
1233
*/
1218
- public async getBackupDecryptor ( backupInfo : KeyBackupInfo , privKey : ArrayLike < number > ) : Promise < BackupDecryptor > {
1219
- if ( backupInfo . algorithm != "m.megolm_backup.v1.curve25519-aes-sha2" ) {
1220
- throw new Error ( `getBackupDecryptor Unsupported algorithm ${ backupInfo . algorithm } ` ) ;
1221
- }
1222
-
1223
- const authData = < Curve25519AuthData > backupInfo . auth_data ;
1224
-
1225
- if ( ! ( privKey instanceof Uint8Array ) ) {
1226
- throw new Error ( `getBackupDecryptor expects Uint8Array` ) ;
1227
- }
1228
-
1229
- const backupDecryptionKey = RustSdkCryptoJs . BackupDecryptionKey . fromBase64 ( encodeBase64 ( privKey ) ) ;
1230
-
1231
- if ( authData . public_key != backupDecryptionKey . megolmV1PublicKey . publicKeyBase64 ) {
1232
- throw new Error ( `getBackupDecryptor key mismatch error` ) ;
1233
- }
1234
-
1235
- return this . backupManager . createBackupDecryptor ( backupDecryptionKey ) ;
1234
+ public async isDehydrationSupported ( ) : Promise < boolean > {
1235
+ return await this . dehydratedDeviceManager . isSupported ( ) ;
1236
1236
}
1237
1237
1238
1238
/**
1239
- * Implementation of {@link CryptoBackend#importBackedUpRoomKeys }.
1239
+ * Implementation of {@link CryptoApi#startDehydration }.
1240
1240
*/
1241
- public async importBackedUpRoomKeys (
1242
- keys : IMegolmSessionData [ ] ,
1243
- backupVersion : string ,
1244
- opts ?: ImportRoomKeysOpts ,
1245
- ) : Promise < void > {
1246
- return await this . backupManager . importBackedUpRoomKeys ( keys , backupVersion , opts ) ;
1241
+ public async startDehydration ( createNewKey ?: boolean ) : Promise < void > {
1242
+ if ( ! ( await this . isCrossSigningReady ( ) ) || ! ( await this . isSecretStorageReady ( ) ) ) {
1243
+ throw new Error ( "Device dehydration requires cross-signing and secret storage to be set up" ) ;
1244
+ }
1245
+ return await this . dehydratedDeviceManager . start ( createNewKey ) ;
1247
1246
}
1248
1247
1249
1248
/**
1250
- * Implementation of {@link CryptoBackend#isDehydrationSupported }.
1249
+ * Implementation of {@link CryptoApi#importSecretsBundle }.
1251
1250
*/
1252
- public async isDehydrationSupported ( ) : Promise < boolean > {
1253
- return await this . dehydratedDeviceManager . isSupported ( ) ;
1251
+ public async importSecretsBundle (
1252
+ secrets : Parameters < NonNullable < CryptoApi [ "importSecretsBundle" ] > > [ 0 ] ,
1253
+ ) : Promise < void > {
1254
+ const secretsBundle = RustSdkCryptoJs . SecretsBundle . from_json ( secrets ) ;
1255
+ await this . getOlmMachineOrThrow ( ) . importSecretsBundle ( secretsBundle ) ; // this method frees the SecretsBundle
1254
1256
}
1255
1257
1256
1258
/**
1257
- * Implementation of {@link CryptoBackend#startDehydration }.
1259
+ * Implementation of {@link CryptoApi#exportSecretsBundle }.
1258
1260
*/
1259
- public async startDehydration ( createNewKey ?: boolean ) : Promise < void > {
1260
- if ( ! ( await this . isCrossSigningReady ( ) ) || ! ( await this . isSecretStorageReady ( ) ) ) {
1261
- throw new Error ( "Device dehydration requires cross-signing and secret storage to be set up" ) ;
1262
- }
1263
- return await this . dehydratedDeviceManager . start ( createNewKey ) ;
1261
+ public async exportsSecretsBundle ( ) : ReturnType < NonNullable < CryptoApi [ "exportSecretsBundle" ] > > {
1262
+ const secretsBundle = await this . getOlmMachineOrThrow ( ) . exportSecretsBundle ( ) ;
1263
+ const secrets = secretsBundle . to_json ( ) ;
1264
+ secretsBundle . free ( ) ;
1265
+ return secrets ;
1264
1266
}
1265
1267
1266
1268
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments