diff --git a/src/matrix/e2ee/Dehydration.js b/src/matrix/e2ee/Dehydration.js index 461e6c42..1f51c054 100644 --- a/src/matrix/e2ee/Dehydration.js +++ b/src/matrix/e2ee/Dehydration.js @@ -15,7 +15,7 @@ limitations under the License. */ const DEHYDRATION_LIBOLM_PICKLE_ALGORITHM = "org.matrix.msc2697.v1.olm.libolm_pickle"; -import {KeyDescription} from "../ssss/common.js"; +import {KeyDescription} from "../ssss/common"; import {keyFromCredentialAndDescription} from "../ssss/index.js"; export async function getDehydratedDevice(hsApi, olm, platform, log) { diff --git a/src/matrix/ssss/common.js b/src/matrix/ssss/common.ts similarity index 71% rename from src/matrix/ssss/common.js rename to src/matrix/ssss/common.ts index 406e8558..97653673 100644 --- a/src/matrix/ssss/common.js +++ b/src/matrix/ssss/common.ts @@ -14,25 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. */ +import type {Platform} from "../../platform/web/Platform.js"; + +interface IKeyDescription { + algorithm: string; + passphrase: { + algorithm: string; + iterations: number; + salt: string; + }; + mac: string; + iv: string; +} + export class KeyDescription { - constructor(id, keyDescription) { + private readonly _id: string; + private readonly _keyDescription: IKeyDescription; + + constructor(id: string, keyDescription: IKeyDescription) { this._id = id; this._keyDescription = keyDescription; } - get id() { + get id(): string { return this._id; } - get passphraseParams() { + get passphraseParams(): IKeyDescription["passphrase"] { return this._keyDescription?.passphrase; } - get algorithm() { + get algorithm(): string { return this._keyDescription?.algorithm; } - async isCompatible(key, platform) { + async isCompatible(key: Key, platform: Platform): Promise { if (this.algorithm === "m.secret_storage.v1.aes-hmac-sha2") { const kd = this._keyDescription; if (kd.mac) { @@ -53,33 +69,36 @@ export class KeyDescription { } export class Key { - constructor(keyDescription, binaryKey) { + private readonly _keyDescription: KeyDescription; + private readonly _binaryKey: Uint8Array; + + constructor(keyDescription: KeyDescription, binaryKey: Uint8Array) { this._keyDescription = keyDescription; this._binaryKey = binaryKey; } - withDescription(description) { + withDescription(description: KeyDescription): Key { return new Key(description, this._binaryKey); } - get description() { + get description(): KeyDescription { return this._keyDescription; } - get id() { + get id(): string { return this._keyDescription.id; } - get binaryKey() { + get binaryKey(): Uint8Array { return this._binaryKey; } - get algorithm() { + get algorithm(): string { return this._keyDescription.algorithm; } } -async function calculateKeyMac(key, ivStr, platform) { +async function calculateKeyMac(key: BufferSource, ivStr: string, platform: Platform): Promise { const {crypto, encoding} = platform; const {utf8, base64} = encoding; const {derive, aes, hmac} = crypto; diff --git a/src/matrix/ssss/index.js b/src/matrix/ssss/index.js index b063ab0b..0a4783b1 100644 --- a/src/matrix/ssss/index.js +++ b/src/matrix/ssss/index.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {KeyDescription, Key} from "./common.js"; +import {KeyDescription, Key} from "./common"; import {keyFromPassphrase} from "./passphrase.js"; import {keyFromRecoveryKey} from "./recoveryKey.js"; import {SESSION_E2EE_KEY_PREFIX} from "../e2ee/common.js"; diff --git a/src/matrix/ssss/passphrase.js b/src/matrix/ssss/passphrase.js index 681e4548..9460e4db 100644 --- a/src/matrix/ssss/passphrase.js +++ b/src/matrix/ssss/passphrase.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {Key} from "./common.js"; +import {Key} from "./common"; const DEFAULT_ITERATIONS = 500000; const DEFAULT_BITSIZE = 256; diff --git a/src/matrix/ssss/recoveryKey.js b/src/matrix/ssss/recoveryKey.js index bfe132a4..b1a746bc 100644 --- a/src/matrix/ssss/recoveryKey.js +++ b/src/matrix/ssss/recoveryKey.js @@ -13,7 +13,7 @@ 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 {Key} from "./common.js"; +import {Key} from "./common"; const OLM_RECOVERY_KEY_PREFIX = [0x8B, 0x01];