You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Element-R: implement {get,store}SessionBackupPrivateKey (#3622)
This commit is contained in:
committed by
GitHub
parent
29b815b678
commit
0e95df5dba
@@ -698,6 +698,33 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
||||
return new RustVerificationRequest(request, this.outgoingRequestProcessor, this._supportedVerificationMethods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the backup decryption key we have saved in our store.
|
||||
*
|
||||
* Implementation of {@link CryptoApi#getSessionBackupPrivateKey}.
|
||||
*
|
||||
* @returns the key, if any, or null
|
||||
*/
|
||||
public async getSessionBackupPrivateKey(): Promise<Uint8Array | null> {
|
||||
const backupKeys: RustSdkCryptoJs.BackupKeys = await this.olmMachine.getBackupKeys();
|
||||
if (!backupKeys.decryptionKeyBase64) return null;
|
||||
return Buffer.from(backupKeys.decryptionKeyBase64, "base64");
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the backup decryption key.
|
||||
*
|
||||
* Implementation of {@link CryptoApi#storeSessionBackupPrivateKey}.
|
||||
*
|
||||
* @param key - the backup decryption key
|
||||
*/
|
||||
public async storeSessionBackupPrivateKey(key: Uint8Array): Promise<void> {
|
||||
const base64Key = Buffer.from(key).toString("base64");
|
||||
|
||||
// TODO get version from backupManager
|
||||
await this.olmMachine.saveBackupDecryptionKey(RustSdkCryptoJs.BackupDecryptionKey.fromBase64(base64Key), "");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SyncCryptoCallbacks implementation
|
||||
|
||||
Reference in New Issue
Block a user