From e82b5fe1dbf5302ad70c02f3d648f20778e12119 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 12 Jul 2023 15:38:14 +0100 Subject: [PATCH] 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 --- src/@types/requests.ts | 6 ++++++ src/client.ts | 3 ++- src/crypto/index.ts | 12 +++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/@types/requests.ts b/src/@types/requests.ts index 0c79534e875..eca0132fb31 100644 --- a/src/@types/requests.ts +++ b/src/@types/requests.ts @@ -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; diff --git a/src/client.ts b/src/client.ts index 16da1791701..b8568a0a3c6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -133,6 +133,7 @@ import { IFilterResponse, ITagsResponse, IStatusResponse, + IAddThreePidBody, } from "./@types/requests"; import { EventType, @@ -8519,7 +8520,7 @@ export class MatrixClient extends TypedEventEmitter { + public addThreePid(creds: IAddThreePidBody, bind: boolean): Promise<{ submit_url?: string }> { const path = "/account/3pid"; const data = { threePidCreds: creds, diff --git a/src/crypto/index.ts b/src/crypto/index.ts index beeefa54645..ab588afce9f 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -1242,20 +1242,22 @@ export class Crypto extends TypedEventEmitter { - let key = await new Promise((resolve) => { + const encodedKey = await new Promise((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;