You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Fix types (#2056)
This commit is contained in:
committed by
GitHub
parent
f926a2f777
commit
4e9fe8f53f
@@ -3106,7 +3106,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* data event.
|
* data event.
|
||||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
*/
|
*/
|
||||||
public async getAccountDataFromServer<T>(eventType: string): Promise<T> {
|
public async getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
|
||||||
if (this.isInitialSyncComplete()) {
|
if (this.isInitialSyncComplete()) {
|
||||||
const event = this.store.getAccountData(eventType);
|
const event = this.store.getAccountData(eventType);
|
||||||
if (!event) {
|
if (!event) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export interface ISecretRequest {
|
|||||||
|
|
||||||
export interface IAccountDataClient extends EventEmitter {
|
export interface IAccountDataClient extends EventEmitter {
|
||||||
// Subset of MatrixClient (which also uses any for the event content)
|
// Subset of MatrixClient (which also uses any for the event content)
|
||||||
getAccountDataFromServer: <T>(eventType: string) => Promise<T>;
|
getAccountDataFromServer: <T extends {[k: string]: any}>(eventType: string) => Promise<T>;
|
||||||
getAccountData: (eventType: string) => MatrixEvent;
|
getAccountData: (eventType: string) => MatrixEvent;
|
||||||
setAccountData: (eventType: string, content: any) => Promise<{}>;
|
setAccountData: (eventType: string, content: any) => Promise<{}>;
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,13 @@ interface IDecryptors {
|
|||||||
decrypt: (ciphertext: IEncryptedPayload) => Promise<string>;
|
decrypt: (ciphertext: IEncryptedPayload) => Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ISecretInfo {
|
||||||
|
encrypted: {
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
key_id: IEncryptedPayload;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements Secure Secret Storage and Sharing (MSC1946)
|
* Implements Secure Secret Storage and Sharing (MSC1946)
|
||||||
* @module crypto/SecretStorage
|
* @module crypto/SecretStorage
|
||||||
@@ -149,7 +156,7 @@ export class SecretStorage {
|
|||||||
do {
|
do {
|
||||||
keyId = randomString(32);
|
keyId = randomString(32);
|
||||||
} while (
|
} while (
|
||||||
await this.accountDataAdapter.getAccountDataFromServer(
|
await this.accountDataAdapter.getAccountDataFromServer<ISecretStorageKeyInfo>(
|
||||||
`m.secret_storage.key.${keyId}`,
|
`m.secret_storage.key.${keyId}`,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -182,9 +189,9 @@ export class SecretStorage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyInfo = await this.accountDataAdapter.getAccountDataFromServer(
|
const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<ISecretStorageKeyInfo>(
|
||||||
"m.secret_storage.key." + keyId,
|
"m.secret_storage.key." + keyId,
|
||||||
) as ISecretStorageKeyInfo;
|
);
|
||||||
return keyInfo ? [keyId, keyInfo] : null;
|
return keyInfo ? [keyId, keyInfo] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +284,7 @@ export class SecretStorage {
|
|||||||
* @return {string} the contents of the secret
|
* @return {string} the contents of the secret
|
||||||
*/
|
*/
|
||||||
public async get(name: string): Promise<string> {
|
public async get(name: string): Promise<string> {
|
||||||
const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<any>(name); // TODO types
|
const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<ISecretInfo>(name);
|
||||||
if (!secretInfo) {
|
if (!secretInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -339,7 +346,7 @@ export class SecretStorage {
|
|||||||
*/
|
*/
|
||||||
public async isStored(name: string, checkKey: boolean): Promise<Record<string, ISecretStorageKeyInfo>> {
|
public async isStored(name: string, checkKey: boolean): Promise<Record<string, ISecretStorageKeyInfo>> {
|
||||||
// check if secret exists
|
// check if secret exists
|
||||||
const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<any>(name); // TODO types
|
const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<ISecretInfo>(name);
|
||||||
if (!secretInfo) return null;
|
if (!secretInfo) return null;
|
||||||
if (!secretInfo.encrypted) {
|
if (!secretInfo.encrypted) {
|
||||||
return null;
|
return null;
|
||||||
@@ -352,7 +359,7 @@ export class SecretStorage {
|
|||||||
// filter secret encryption keys with supported algorithm
|
// filter secret encryption keys with supported algorithm
|
||||||
for (const keyId of Object.keys(secretInfo.encrypted)) {
|
for (const keyId of Object.keys(secretInfo.encrypted)) {
|
||||||
// get key information from key storage
|
// get key information from key storage
|
||||||
const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<any>( // TODO types
|
const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<ISecretStorageKeyInfo>(
|
||||||
"m.secret_storage.key." + keyId,
|
"m.secret_storage.key." + keyId,
|
||||||
);
|
);
|
||||||
if (!keyInfo) continue;
|
if (!keyInfo) continue;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import { BackupManager } from "./backup";
|
|||||||
import { IStore } from "../store";
|
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, IClearEvent } from "../models/event";
|
import { MatrixEvent, EventStatus, IClearEvent, IEvent } from "../models/event";
|
||||||
import { MatrixClient, IKeysUploadResponse, SessionStore, ISignedKey, ICrossSigningKey } 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";
|
||||||
@@ -2791,7 +2791,7 @@ export class Crypto extends EventEmitter {
|
|||||||
type: "m.room.message",
|
type: "m.room.message",
|
||||||
content: {},
|
content: {},
|
||||||
unsigned: {
|
unsigned: {
|
||||||
redacted_because: decryptedEvent.clearEvent,
|
redacted_because: decryptedEvent.clearEvent as IEvent,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import { RoomMember } from "./room-member";
|
|||||||
import { Thread, ThreadEvent } from "./thread";
|
import { Thread, ThreadEvent } from "./thread";
|
||||||
import { IActionsObject } from '../pushprocessor';
|
import { IActionsObject } from '../pushprocessor';
|
||||||
import { ReEmitter } from '../ReEmitter';
|
import { ReEmitter } from '../ReEmitter';
|
||||||
|
import { MatrixError } from "../http-api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for event statuses.
|
* Enum for event statuses.
|
||||||
@@ -85,7 +86,7 @@ export interface IUnsigned {
|
|||||||
age?: number;
|
age?: number;
|
||||||
prev_sender?: string;
|
prev_sender?: string;
|
||||||
prev_content?: IContent;
|
prev_content?: IContent;
|
||||||
redacted_because?: IClearEvent;
|
redacted_because?: IEvent;
|
||||||
transaction_id?: string;
|
transaction_id?: string;
|
||||||
invite_room_state?: StrippedState[];
|
invite_room_state?: StrippedState[];
|
||||||
}
|
}
|
||||||
@@ -203,7 +204,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
public sender: RoomMember = null;
|
public sender: RoomMember = null;
|
||||||
public target: RoomMember = null;
|
public target: RoomMember = null;
|
||||||
public status: EventStatus = null;
|
public status: EventStatus = null;
|
||||||
public error: Error = null;
|
public error: MatrixError = null;
|
||||||
public forwardLooking = true;
|
public forwardLooking = true;
|
||||||
|
|
||||||
/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
|
/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
|
||||||
|
|||||||
Reference in New Issue
Block a user