1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Fix types in getSessionBackupPrivateKey (#3595)

* Fix type issue around `getSessionBackupPrivateKey`

* Fix sending auth: null due to broken types around UIA

* Discard changes to src/crypto/index.ts

* Add comment

* Fix types

* Fix types for MatrixClient::addThreePid

* Iterate
This commit is contained in:
Michael Telatynski
2023-07-12 15:38:14 +01:00
committed by GitHub
parent 9602aa88ea
commit e82b5fe1db
3 changed files with 15 additions and 6 deletions

View File

@@ -181,6 +181,12 @@ export interface IBindThreePidBody {
sid: string;
}
export interface IAddThreePidBody {
client_secret: string;
id_server: string;
sid: string;
}
export interface IRelationsRequestOpts {
from?: string;
to?: string;

View File

@@ -133,6 +133,7 @@ import {
IFilterResponse,
ITagsResponse,
IStatusResponse,
IAddThreePidBody,
} from "./@types/requests";
import {
EventType,
@@ -8519,7 +8520,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: on success
* @returns Rejects: with an error response.
*/
public addThreePid(creds: IBindThreePidBody, bind: boolean): Promise<{ submit_url?: string }> {
public addThreePid(creds: IAddThreePidBody, bind: boolean): Promise<{ submit_url?: string }> {
const path = "/account/3pid";
const data = {
threePidCreds: creds,

View File

@@ -1242,20 +1242,22 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
* @returns the key, if any, or null
*/
public async getSessionBackupPrivateKey(): Promise<Uint8Array | null> {
let key = await new Promise<Uint8Array | IEncryptedPayload | null>((resolve) => {
const encodedKey = await new Promise<Uint8Array | IEncryptedPayload | string | null>((resolve) => {
this.cryptoStore.doTxn("readonly", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
this.cryptoStore.getSecretStorePrivateKey(txn, resolve, "m.megolm_backup.v1");
});
});
let key: Uint8Array | null = null;
// make sure we have a Uint8Array, rather than a string
if (key && typeof key === "string") {
key = new Uint8Array(olmlib.decodeBase64(fixBackupKey(key) || key));
if (typeof encodedKey === "string") {
key = new Uint8Array(olmlib.decodeBase64(fixBackupKey(encodedKey) || encodedKey));
await this.storeSessionBackupPrivateKey(key);
}
if (key && typeof key === "object" && "ciphertext" in key) {
if (encodedKey && typeof encodedKey === "object" && "ciphertext" in encodedKey) {
const pickleKey = Buffer.from(this.olmDevice.pickleKey);
const decrypted = await decryptAES(key, pickleKey, "m.megolm_backup.v1");
const decrypted = await decryptAES(encodedKey, pickleKey, "m.megolm_backup.v1");
key = olmlib.decodeBase64(decrypted);
}
return key;