1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Iterate type definitions (#2029)

This commit is contained in:
Michael Telatynski
2021-11-19 17:35:09 +00:00
committed by GitHub
parent 1b91cd7037
commit b2d83c1f80
5 changed files with 43 additions and 56 deletions

View File

@@ -147,12 +147,12 @@ export interface IPusher {
app_display_name: string;
app_id: string;
data: {
format?: string; // TODO: Types
format?: string;
url?: string; // TODO: Required if kind==http
brand?: string; // TODO: For email notifications only?
brand?: string; // TODO: For email notifications only? Unspecced field
};
device_display_name: string;
kind: string; // TODO: Types
kind: "http" | string;
lang: string;
profile_tag?: string;
pushkey: string;

View File

@@ -75,11 +75,13 @@ import {
IKeyBackupPrepareOpts,
IKeyBackupRestoreOpts,
IKeyBackupRestoreResult,
IKeyBackupRoomSessions,
IKeyBackupSession,
} from "./crypto/keybackup";
import { IIdentityServerProvider } from "./@types/IIdentityServerProvider";
import type Request from "request";
import { MatrixScheduler } from "./scheduler";
import { ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
import { IAuthData, ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
import {
CrossSigningKey,
IAddSecretStorageKeyOpts,
@@ -677,6 +679,14 @@ interface IRoomSummary extends Omit<IPublicRoomsChunkRoom, "canonical_alias" | "
membership?: string;
is_encrypted: boolean;
}
interface IRoomKeysResponse {
sessions: IKeyBackupRoomSessions;
}
interface IRoomsKeysResponse {
rooms: Record<string, IRoomKeysResponse>;
}
/* eslint-enable camelcase */
/**
@@ -724,7 +734,7 @@ export class MatrixClient extends EventEmitter {
protected fallbackICEServerAllowed = false;
protected roomList: RoomList;
protected syncApi: SyncApi;
public pushRules: any; // TODO: Types
public pushRules: IPushRules;
protected syncLeftRoomsPromise: Promise<Room[]>;
protected syncedLeftRooms = false;
protected clientOpts: IStoredClientOpts;
@@ -2719,7 +2729,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: string,
@@ -2746,7 +2755,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public async restoreKeyBackupWithSecretStorage(
backupInfo: IKeyBackupInfo,
targetRoomId?: string,
@@ -2783,7 +2791,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: string,
@@ -2795,7 +2802,6 @@ export class MatrixClient extends EventEmitter {
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
}
// TODO: Types
public async restoreKeyBackupWithCache(
targetRoomId: string,
targetSessionId: string,
@@ -2856,11 +2862,11 @@ export class MatrixClient extends EventEmitter {
const res = await this.http.authedRequest(
undefined, "GET", path.path, path.queryData, undefined,
{ prefix: PREFIX_UNSTABLE },
);
) as IRoomsKeysResponse | IRoomKeysResponse | IKeyBackupSession;
if (res.rooms) {
// TODO: Types
for (const [roomId, roomData] of Object.entries<any>(res.rooms)) {
if ((res as IRoomsKeysResponse).rooms) {
const rooms = (res as IRoomsKeysResponse).rooms;
for (const [roomId, roomData] of Object.entries(rooms)) {
if (!roomData.sessions) continue;
totalKeyCount += Object.keys(roomData.sessions).length;
@@ -2870,9 +2876,10 @@ export class MatrixClient extends EventEmitter {
keys.push(k);
}
}
} else if (res.sessions) {
totalKeyCount = Object.keys(res.sessions).length;
keys = await algorithm.decryptSessions(res.sessions);
} else if ((res as IRoomKeysResponse).sessions) {
const sessions = (res as IRoomKeysResponse).sessions;
totalKeyCount = Object.keys(sessions).length;
keys = await algorithm.decryptSessions(sessions);
for (const k of keys) {
k.room_id = targetRoomId;
}
@@ -2880,7 +2887,7 @@ export class MatrixClient extends EventEmitter {
totalKeyCount = 1;
try {
const [key] = await algorithm.decryptSessions({
[targetSessionId]: res,
[targetSessionId]: res as IKeyBackupSession,
});
key.room_id = targetRoomId;
key.session_id = targetSessionId;
@@ -7510,7 +7517,7 @@ export class MatrixClient extends EventEmitter {
return this.http.authedRequest(undefined, "GET", path, qps, undefined);
}
public uploadDeviceSigningKeys(auth: any, keys?: CrossSigningKeys): Promise<{}> { // TODO: types
public uploadDeviceSigningKeys(auth?: IAuthData, keys?: CrossSigningKeys): Promise<{}> {
const data = Object.assign({}, keys);
if (auth) Object.assign(data, { auth });
return this.http.authedRequest(

View File

@@ -304,7 +304,7 @@ export class CrossSigningInfo extends EventEmitter {
}
const privateKeys: Record<string, Uint8Array> = {};
const keys: Record<string, any> = {}; // TODO types
const keys: Record<string, ICrossSigningKey> = {};
let masterSigning;
let masterPub;

View File

@@ -58,14 +58,7 @@ export interface IEncryptedEventInfo {
}
export interface IRecoveryKey {
keyInfo?: {
pubkey: string;
passphrase?: {
algorithm: string;
iterations: number;
salt: string;
};
};
keyInfo?: IAddSecretStorageKeyOpts;
privateKey: Uint8Array;
encodedPrivateKey?: string;
}
@@ -125,12 +118,13 @@ export interface IPassphraseInfo {
algorithm: "m.pbkdf2";
iterations: number;
salt: string;
bits: number;
bits?: number;
}
export interface IAddSecretStorageKeyOpts {
name: string;
passphrase: IPassphraseInfo;
pubkey: string;
passphrase?: IPassphraseInfo;
name?: string;
key: Uint8Array;
}

View File

@@ -40,7 +40,7 @@ import {
ISecretRequest,
SecretStorageKeyObject,
} from './SecretStorage';
import { IAddSecretStorageKeyOpts, IImportRoomKeysOpts, ISecretStorageKeyInfo } from "./api";
import { IAddSecretStorageKeyOpts, ICreateSecretStorageOpts, IImportRoomKeysOpts, ISecretStorageKeyInfo } from "./api";
import { OutgoingRoomKeyRequestManager } from './OutgoingRoomKeyRequestManager';
import { IndexedDBCryptoStore } from './store/indexeddb-crypto-store';
import { ReciprocateQRCode, SCAN_QR_CODE_METHOD, SHOW_QR_CODE_METHOD } from './verification/QRCode';
@@ -59,7 +59,7 @@ import { IStore } from "../store";
import { Room } from "../models/room";
import { RoomMember } from "../models/room-member";
import { MatrixEvent, EventStatus } from "../models/event";
import { MatrixClient, IKeysUploadResponse, SessionStore, ISignedKey } from "../client";
import { MatrixClient, IKeysUploadResponse, SessionStore, ISignedKey, ICrossSigningKey } from "../client";
import type { EncryptionAlgorithm, DecryptionAlgorithm } from "./algorithms/base";
import type { IRoomEncryption, RoomList } from "./RoomList";
import { IRecoveryKey, IEncryptedEventInfo } from "./api";
@@ -108,17 +108,6 @@ export interface IBootstrapCrossSigningOpts {
authUploadDeviceSigningKeys?(makeRequest: (authData: any) => {}): Promise<void>;
}
interface IBootstrapSecretStorageOpts {
keyBackupInfo?: any; // TODO types
setupNewKeyBackup?: boolean;
setupNewSecretStorage?: boolean;
createSecretStorageKey?(): Promise<{
keyInfo?: any; // TODO types
privateKey?: Uint8Array;
}>;
getKeyBackupPassphrase?(): Promise<Uint8Array | null>;
}
/* eslint-disable camelcase */
interface IRoomKey {
room_id: string;
@@ -762,12 +751,12 @@ export class Crypto extends EventEmitter {
*/
// TODO this does not resolve with what it says it does
public async bootstrapSecretStorage({
createSecretStorageKey = async () => ({ }),
createSecretStorageKey = async () => ({} as IRecoveryKey),
keyBackupInfo,
setupNewKeyBackup,
setupNewSecretStorage,
getKeyBackupPassphrase,
}: IBootstrapSecretStorageOpts = {}) {
}: ICreateSecretStorageOpts = {}) {
logger.log("Bootstrapping Secure Secret Storage");
const delegateCryptoCallbacks = this.baseApis.cryptoCallbacks;
const builder = new EncryptionSetupBuilder(
@@ -783,8 +772,7 @@ export class Crypto extends EventEmitter {
let newKeyId = null;
// create a new SSSS key and set it as default
const createSSSS = async (opts, privateKey: Uint8Array) => {
opts = opts || {};
const createSSSS = async (opts: IAddSecretStorageKeyOpts, privateKey: Uint8Array) => {
if (privateKey) {
opts.key = privateKey;
}
@@ -800,7 +788,7 @@ export class Crypto extends EventEmitter {
return keyId;
};
const ensureCanCheckPassphrase = async (keyId, keyInfo) => {
const ensureCanCheckPassphrase = async (keyId: string, keyInfo: ISecretStorageKeyInfo) => {
if (!keyInfo.mac) {
const key = await this.baseApis.cryptoCallbacks.getSecretStorageKey(
{ keys: { [keyId]: keyInfo } }, "",
@@ -880,7 +868,7 @@ export class Crypto extends EventEmitter {
const backupKey = await this.getSessionBackupPrivateKey() || await getKeyBackupPassphrase();
// create a new SSSS key and use the backup key as the new SSSS key
const opts: any = {}; // TODO types
const opts = {} as IAddSecretStorageKeyOpts;
if (
keyBackupInfo.auth_data.private_key_salt &&
@@ -898,9 +886,7 @@ export class Crypto extends EventEmitter {
newKeyId = await createSSSS(opts, backupKey);
// store the backup key in secret storage
await secretStorage.store(
"m.megolm_backup.v1", olmlib.encodeBase64(backupKey), [newKeyId],
);
await secretStorage.store("m.megolm_backup.v1", olmlib.encodeBase64(backupKey), [newKeyId]);
// The backup is trusted because the user provided the private key.
// Sign the backup with the cross-signing key so the key backup can
@@ -1274,7 +1260,7 @@ export class Crypto extends EventEmitter {
*/
private async checkForValidDeviceSignature(
userId: string,
key: any, // TODO types
key: ICrossSigningKey,
devices: Record<string, IDevice>,
): Promise<string[]> {
const deviceIds: string[] = [];
@@ -1609,7 +1595,7 @@ export class Crypto extends EventEmitter {
*
* @param {object} keys The new trusted set of keys
*/
private async storeTrustedSelfKeys(keys: any): Promise<void> { // TODO types
private async storeTrustedSelfKeys(keys: Record<string, ICrossSigningKey>): Promise<void> {
if (keys) {
this.crossSigningInfo.setKeys(keys);
} else {
@@ -2662,7 +2648,7 @@ export class Crypto extends EventEmitter {
* @param {Function} opts.progressCallback called with an object which has a stage param
* @return {Promise} a promise which resolves once the keys have been imported
*/
public importRoomKeys(keys: IMegolmSessionData[], opts: IImportRoomKeysOpts = {}): Promise<any> { // TODO types
public importRoomKeys(keys: IMegolmSessionData[], opts: IImportRoomKeysOpts = {}): Promise<void> {
let successes = 0;
let failures = 0;
const total = keys.length;
@@ -2689,7 +2675,7 @@ export class Crypto extends EventEmitter {
successes++;
if (opts.progressCallback) { updateProgress(); }
});
}));
})).then();
}
/**