From b2efcb9515699a00ed36ef0f412421e38478daef Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 29 Nov 2021 17:05:15 +0530 Subject: [PATCH] Convert SecretStorage.js to ts --- src/matrix/Session.js | 2 +- .../ssss/{SecretStorage.js => SecretStorage.ts} | 12 +++++++++--- src/matrix/ssss/index.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) rename src/matrix/ssss/{SecretStorage.js => SecretStorage.ts} (83%) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index e3f3cda3..49151252 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -43,7 +43,7 @@ import { removeKey as ssssRemoveKey, keyFromDehydratedDeviceKey as createSSSSKeyFromDehydratedDeviceKey } from "./ssss/index"; -import {SecretStorage} from "./ssss/SecretStorage.js"; +import {SecretStorage} from "./ssss/SecretStorage"; import {ObservableValue, RetainedObservableValue} from "../observable/ObservableValue"; const PICKLE_KEY = "DEFAULT_KEY"; diff --git a/src/matrix/ssss/SecretStorage.js b/src/matrix/ssss/SecretStorage.ts similarity index 83% rename from src/matrix/ssss/SecretStorage.js rename to src/matrix/ssss/SecretStorage.ts index 04597084..3bbbc070 100644 --- a/src/matrix/ssss/SecretStorage.js +++ b/src/matrix/ssss/SecretStorage.ts @@ -13,14 +13,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +import type {Key} from "./common"; +import type {Platform} from "../../platform/web/Platform.js"; +import type {Transaction} from "../storage/idb/Transaction"; export class SecretStorage { - constructor({key, platform}) { + private readonly _key: Key; + private readonly _platform: Platform; + + constructor({key, platform}: {key: Key, platform: Platform}) { this._key = key; this._platform = platform; } - async readSecret(name, txn) { + async readSecret(name: string, txn: Transaction): Promise { const accountData = await txn.accountData.get(name); if (!accountData) { return; @@ -37,7 +43,7 @@ export class SecretStorage { } } - async _decryptAESSecret(type, encryptedData) { + async _decryptAESSecret(type: string, encryptedData: any): Promise { const {base64, utf8} = this._platform.encoding; // now derive the aes and mac key from the 4s key const hkdfKey = await this._platform.crypto.derive.hkdf( diff --git a/src/matrix/ssss/index.ts b/src/matrix/ssss/index.ts index fa09228d..c82729f2 100644 --- a/src/matrix/ssss/index.ts +++ b/src/matrix/ssss/index.ts @@ -22,7 +22,7 @@ import type {Storage} from "../storage/idb/Storage"; import type {Transaction} from "../storage/idb/Transaction"; import type {IKeyDescription} from "./common"; import type {Platform} from "../../platform/web/Platform.js"; -import type { Olm } from "./recoveryKey"; +import type {Olm} from "./recoveryKey"; const SSSS_KEY = `${SESSION_E2EE_KEY_PREFIX}ssssKey`;