You've already forked matrix-js-sdk
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:
committed by
GitHub
parent
1b91cd7037
commit
b2d83c1f80
@@ -147,12 +147,12 @@ export interface IPusher {
|
|||||||
app_display_name: string;
|
app_display_name: string;
|
||||||
app_id: string;
|
app_id: string;
|
||||||
data: {
|
data: {
|
||||||
format?: string; // TODO: Types
|
format?: string;
|
||||||
url?: string; // TODO: Required if kind==http
|
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;
|
device_display_name: string;
|
||||||
kind: string; // TODO: Types
|
kind: "http" | string;
|
||||||
lang: string;
|
lang: string;
|
||||||
profile_tag?: string;
|
profile_tag?: string;
|
||||||
pushkey: string;
|
pushkey: string;
|
||||||
|
|||||||
@@ -75,11 +75,13 @@ import {
|
|||||||
IKeyBackupPrepareOpts,
|
IKeyBackupPrepareOpts,
|
||||||
IKeyBackupRestoreOpts,
|
IKeyBackupRestoreOpts,
|
||||||
IKeyBackupRestoreResult,
|
IKeyBackupRestoreResult,
|
||||||
|
IKeyBackupRoomSessions,
|
||||||
|
IKeyBackupSession,
|
||||||
} from "./crypto/keybackup";
|
} from "./crypto/keybackup";
|
||||||
import { IIdentityServerProvider } from "./@types/IIdentityServerProvider";
|
import { IIdentityServerProvider } from "./@types/IIdentityServerProvider";
|
||||||
import type Request from "request";
|
import type Request from "request";
|
||||||
import { MatrixScheduler } from "./scheduler";
|
import { MatrixScheduler } from "./scheduler";
|
||||||
import { ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
|
import { IAuthData, ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
|
||||||
import {
|
import {
|
||||||
CrossSigningKey,
|
CrossSigningKey,
|
||||||
IAddSecretStorageKeyOpts,
|
IAddSecretStorageKeyOpts,
|
||||||
@@ -677,6 +679,14 @@ interface IRoomSummary extends Omit<IPublicRoomsChunkRoom, "canonical_alias" | "
|
|||||||
membership?: string;
|
membership?: string;
|
||||||
is_encrypted: boolean;
|
is_encrypted: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IRoomKeysResponse {
|
||||||
|
sessions: IKeyBackupRoomSessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IRoomsKeysResponse {
|
||||||
|
rooms: Record<string, IRoomKeysResponse>;
|
||||||
|
}
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -724,7 +734,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
protected fallbackICEServerAllowed = false;
|
protected fallbackICEServerAllowed = false;
|
||||||
protected roomList: RoomList;
|
protected roomList: RoomList;
|
||||||
protected syncApi: SyncApi;
|
protected syncApi: SyncApi;
|
||||||
public pushRules: any; // TODO: Types
|
public pushRules: IPushRules;
|
||||||
protected syncLeftRoomsPromise: Promise<Room[]>;
|
protected syncLeftRoomsPromise: Promise<Room[]>;
|
||||||
protected syncedLeftRooms = false;
|
protected syncedLeftRooms = false;
|
||||||
protected clientOpts: IStoredClientOpts;
|
protected clientOpts: IStoredClientOpts;
|
||||||
@@ -2719,7 +2729,6 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||||
* key counts.
|
* key counts.
|
||||||
*/
|
*/
|
||||||
// TODO: Types
|
|
||||||
public async restoreKeyBackupWithPassword(
|
public async restoreKeyBackupWithPassword(
|
||||||
password: string,
|
password: string,
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
@@ -2746,7 +2755,6 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||||
* key counts.
|
* key counts.
|
||||||
*/
|
*/
|
||||||
// TODO: Types
|
|
||||||
public async restoreKeyBackupWithSecretStorage(
|
public async restoreKeyBackupWithSecretStorage(
|
||||||
backupInfo: IKeyBackupInfo,
|
backupInfo: IKeyBackupInfo,
|
||||||
targetRoomId?: string,
|
targetRoomId?: string,
|
||||||
@@ -2783,7 +2791,6 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||||
* key counts.
|
* key counts.
|
||||||
*/
|
*/
|
||||||
// TODO: Types
|
|
||||||
public restoreKeyBackupWithRecoveryKey(
|
public restoreKeyBackupWithRecoveryKey(
|
||||||
recoveryKey: string,
|
recoveryKey: string,
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
@@ -2795,7 +2802,6 @@ export class MatrixClient extends EventEmitter {
|
|||||||
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
|
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Types
|
|
||||||
public async restoreKeyBackupWithCache(
|
public async restoreKeyBackupWithCache(
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
targetSessionId: string,
|
targetSessionId: string,
|
||||||
@@ -2856,11 +2862,11 @@ export class MatrixClient extends EventEmitter {
|
|||||||
const res = await this.http.authedRequest(
|
const res = await this.http.authedRequest(
|
||||||
undefined, "GET", path.path, path.queryData, undefined,
|
undefined, "GET", path.path, path.queryData, undefined,
|
||||||
{ prefix: PREFIX_UNSTABLE },
|
{ prefix: PREFIX_UNSTABLE },
|
||||||
);
|
) as IRoomsKeysResponse | IRoomKeysResponse | IKeyBackupSession;
|
||||||
|
|
||||||
if (res.rooms) {
|
if ((res as IRoomsKeysResponse).rooms) {
|
||||||
// TODO: Types
|
const rooms = (res as IRoomsKeysResponse).rooms;
|
||||||
for (const [roomId, roomData] of Object.entries<any>(res.rooms)) {
|
for (const [roomId, roomData] of Object.entries(rooms)) {
|
||||||
if (!roomData.sessions) continue;
|
if (!roomData.sessions) continue;
|
||||||
|
|
||||||
totalKeyCount += Object.keys(roomData.sessions).length;
|
totalKeyCount += Object.keys(roomData.sessions).length;
|
||||||
@@ -2870,9 +2876,10 @@ export class MatrixClient extends EventEmitter {
|
|||||||
keys.push(k);
|
keys.push(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (res.sessions) {
|
} else if ((res as IRoomKeysResponse).sessions) {
|
||||||
totalKeyCount = Object.keys(res.sessions).length;
|
const sessions = (res as IRoomKeysResponse).sessions;
|
||||||
keys = await algorithm.decryptSessions(res.sessions);
|
totalKeyCount = Object.keys(sessions).length;
|
||||||
|
keys = await algorithm.decryptSessions(sessions);
|
||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
k.room_id = targetRoomId;
|
k.room_id = targetRoomId;
|
||||||
}
|
}
|
||||||
@@ -2880,7 +2887,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
totalKeyCount = 1;
|
totalKeyCount = 1;
|
||||||
try {
|
try {
|
||||||
const [key] = await algorithm.decryptSessions({
|
const [key] = await algorithm.decryptSessions({
|
||||||
[targetSessionId]: res,
|
[targetSessionId]: res as IKeyBackupSession,
|
||||||
});
|
});
|
||||||
key.room_id = targetRoomId;
|
key.room_id = targetRoomId;
|
||||||
key.session_id = targetSessionId;
|
key.session_id = targetSessionId;
|
||||||
@@ -7510,7 +7517,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
return this.http.authedRequest(undefined, "GET", path, qps, undefined);
|
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);
|
const data = Object.assign({}, keys);
|
||||||
if (auth) Object.assign(data, { auth });
|
if (auth) Object.assign(data, { auth });
|
||||||
return this.http.authedRequest(
|
return this.http.authedRequest(
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const privateKeys: Record<string, Uint8Array> = {};
|
const privateKeys: Record<string, Uint8Array> = {};
|
||||||
const keys: Record<string, any> = {}; // TODO types
|
const keys: Record<string, ICrossSigningKey> = {};
|
||||||
let masterSigning;
|
let masterSigning;
|
||||||
let masterPub;
|
let masterPub;
|
||||||
|
|
||||||
|
|||||||
@@ -58,14 +58,7 @@ export interface IEncryptedEventInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IRecoveryKey {
|
export interface IRecoveryKey {
|
||||||
keyInfo?: {
|
keyInfo?: IAddSecretStorageKeyOpts;
|
||||||
pubkey: string;
|
|
||||||
passphrase?: {
|
|
||||||
algorithm: string;
|
|
||||||
iterations: number;
|
|
||||||
salt: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
privateKey: Uint8Array;
|
privateKey: Uint8Array;
|
||||||
encodedPrivateKey?: string;
|
encodedPrivateKey?: string;
|
||||||
}
|
}
|
||||||
@@ -125,12 +118,13 @@ export interface IPassphraseInfo {
|
|||||||
algorithm: "m.pbkdf2";
|
algorithm: "m.pbkdf2";
|
||||||
iterations: number;
|
iterations: number;
|
||||||
salt: string;
|
salt: string;
|
||||||
bits: number;
|
bits?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAddSecretStorageKeyOpts {
|
export interface IAddSecretStorageKeyOpts {
|
||||||
name: string;
|
pubkey: string;
|
||||||
passphrase: IPassphraseInfo;
|
passphrase?: IPassphraseInfo;
|
||||||
|
name?: string;
|
||||||
key: Uint8Array;
|
key: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import {
|
|||||||
ISecretRequest,
|
ISecretRequest,
|
||||||
SecretStorageKeyObject,
|
SecretStorageKeyObject,
|
||||||
} from './SecretStorage';
|
} from './SecretStorage';
|
||||||
import { IAddSecretStorageKeyOpts, IImportRoomKeysOpts, ISecretStorageKeyInfo } from "./api";
|
import { IAddSecretStorageKeyOpts, ICreateSecretStorageOpts, IImportRoomKeysOpts, ISecretStorageKeyInfo } from "./api";
|
||||||
import { OutgoingRoomKeyRequestManager } from './OutgoingRoomKeyRequestManager';
|
import { OutgoingRoomKeyRequestManager } from './OutgoingRoomKeyRequestManager';
|
||||||
import { IndexedDBCryptoStore } from './store/indexeddb-crypto-store';
|
import { IndexedDBCryptoStore } from './store/indexeddb-crypto-store';
|
||||||
import { ReciprocateQRCode, SCAN_QR_CODE_METHOD, SHOW_QR_CODE_METHOD } from './verification/QRCode';
|
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 { Room } from "../models/room";
|
||||||
import { RoomMember } from "../models/room-member";
|
import { RoomMember } from "../models/room-member";
|
||||||
import { MatrixEvent, EventStatus } from "../models/event";
|
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 { EncryptionAlgorithm, DecryptionAlgorithm } from "./algorithms/base";
|
||||||
import type { IRoomEncryption, RoomList } from "./RoomList";
|
import type { IRoomEncryption, RoomList } from "./RoomList";
|
||||||
import { IRecoveryKey, IEncryptedEventInfo } from "./api";
|
import { IRecoveryKey, IEncryptedEventInfo } from "./api";
|
||||||
@@ -108,17 +108,6 @@ export interface IBootstrapCrossSigningOpts {
|
|||||||
authUploadDeviceSigningKeys?(makeRequest: (authData: any) => {}): Promise<void>;
|
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 */
|
/* eslint-disable camelcase */
|
||||||
interface IRoomKey {
|
interface IRoomKey {
|
||||||
room_id: string;
|
room_id: string;
|
||||||
@@ -762,12 +751,12 @@ export class Crypto extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
// TODO this does not resolve with what it says it does
|
// TODO this does not resolve with what it says it does
|
||||||
public async bootstrapSecretStorage({
|
public async bootstrapSecretStorage({
|
||||||
createSecretStorageKey = async () => ({ }),
|
createSecretStorageKey = async () => ({} as IRecoveryKey),
|
||||||
keyBackupInfo,
|
keyBackupInfo,
|
||||||
setupNewKeyBackup,
|
setupNewKeyBackup,
|
||||||
setupNewSecretStorage,
|
setupNewSecretStorage,
|
||||||
getKeyBackupPassphrase,
|
getKeyBackupPassphrase,
|
||||||
}: IBootstrapSecretStorageOpts = {}) {
|
}: ICreateSecretStorageOpts = {}) {
|
||||||
logger.log("Bootstrapping Secure Secret Storage");
|
logger.log("Bootstrapping Secure Secret Storage");
|
||||||
const delegateCryptoCallbacks = this.baseApis.cryptoCallbacks;
|
const delegateCryptoCallbacks = this.baseApis.cryptoCallbacks;
|
||||||
const builder = new EncryptionSetupBuilder(
|
const builder = new EncryptionSetupBuilder(
|
||||||
@@ -783,8 +772,7 @@ export class Crypto extends EventEmitter {
|
|||||||
let newKeyId = null;
|
let newKeyId = null;
|
||||||
|
|
||||||
// create a new SSSS key and set it as default
|
// create a new SSSS key and set it as default
|
||||||
const createSSSS = async (opts, privateKey: Uint8Array) => {
|
const createSSSS = async (opts: IAddSecretStorageKeyOpts, privateKey: Uint8Array) => {
|
||||||
opts = opts || {};
|
|
||||||
if (privateKey) {
|
if (privateKey) {
|
||||||
opts.key = privateKey;
|
opts.key = privateKey;
|
||||||
}
|
}
|
||||||
@@ -800,7 +788,7 @@ export class Crypto extends EventEmitter {
|
|||||||
return keyId;
|
return keyId;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ensureCanCheckPassphrase = async (keyId, keyInfo) => {
|
const ensureCanCheckPassphrase = async (keyId: string, keyInfo: ISecretStorageKeyInfo) => {
|
||||||
if (!keyInfo.mac) {
|
if (!keyInfo.mac) {
|
||||||
const key = await this.baseApis.cryptoCallbacks.getSecretStorageKey(
|
const key = await this.baseApis.cryptoCallbacks.getSecretStorageKey(
|
||||||
{ keys: { [keyId]: keyInfo } }, "",
|
{ keys: { [keyId]: keyInfo } }, "",
|
||||||
@@ -880,7 +868,7 @@ export class Crypto extends EventEmitter {
|
|||||||
const backupKey = await this.getSessionBackupPrivateKey() || await getKeyBackupPassphrase();
|
const backupKey = await this.getSessionBackupPrivateKey() || await getKeyBackupPassphrase();
|
||||||
|
|
||||||
// create a new SSSS key and use the backup key as the new SSSS key
|
// 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 (
|
if (
|
||||||
keyBackupInfo.auth_data.private_key_salt &&
|
keyBackupInfo.auth_data.private_key_salt &&
|
||||||
@@ -898,9 +886,7 @@ export class Crypto extends EventEmitter {
|
|||||||
newKeyId = await createSSSS(opts, backupKey);
|
newKeyId = await createSSSS(opts, backupKey);
|
||||||
|
|
||||||
// store the backup key in secret storage
|
// store the backup key in secret storage
|
||||||
await secretStorage.store(
|
await secretStorage.store("m.megolm_backup.v1", olmlib.encodeBase64(backupKey), [newKeyId]);
|
||||||
"m.megolm_backup.v1", olmlib.encodeBase64(backupKey), [newKeyId],
|
|
||||||
);
|
|
||||||
|
|
||||||
// The backup is trusted because the user provided the private key.
|
// The backup is trusted because the user provided the private key.
|
||||||
// Sign the backup with the cross-signing key so the key backup can
|
// 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(
|
private async checkForValidDeviceSignature(
|
||||||
userId: string,
|
userId: string,
|
||||||
key: any, // TODO types
|
key: ICrossSigningKey,
|
||||||
devices: Record<string, IDevice>,
|
devices: Record<string, IDevice>,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const deviceIds: string[] = [];
|
const deviceIds: string[] = [];
|
||||||
@@ -1609,7 +1595,7 @@ export class Crypto extends EventEmitter {
|
|||||||
*
|
*
|
||||||
* @param {object} keys The new trusted set of keys
|
* @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) {
|
if (keys) {
|
||||||
this.crossSigningInfo.setKeys(keys);
|
this.crossSigningInfo.setKeys(keys);
|
||||||
} else {
|
} else {
|
||||||
@@ -2662,7 +2648,7 @@ export class Crypto extends EventEmitter {
|
|||||||
* @param {Function} opts.progressCallback called with an object which has a stage param
|
* @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
|
* @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 successes = 0;
|
||||||
let failures = 0;
|
let failures = 0;
|
||||||
const total = keys.length;
|
const total = keys.length;
|
||||||
@@ -2689,7 +2675,7 @@ export class Crypto extends EventEmitter {
|
|||||||
successes++;
|
successes++;
|
||||||
if (opts.progressCallback) { updateProgress(); }
|
if (opts.progressCallback) { updateProgress(); }
|
||||||
});
|
});
|
||||||
}));
|
})).then();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user