Merge pull request #1162 from Mikunj/type-fixes

Improve typings for window objects.
pull/1170/head
Mikunj Varsani 5 years ago committed by GitHub
commit 02e8391e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,42 @@
import { SignalService } from '../../protobuf';
import { CipherTextObject } from '../../../libtextsecure/libsignal-protocol';
export interface SecretSessionCipherConstructor {
new (storage: any): SecretSessionCipherInterface;
}
export interface SecretSessionCipherInterface {
encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}
export declare class SecretSessionCipher
implements SecretSessionCipherInterface {
constructor(storage: any);
public encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
public decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}

@ -0,0 +1,9 @@
import { SecretSessionCipherConstructor } from './metadata/SecretSessionCipher';
interface Metadata {
SecretSessionCipher: SecretSessionCipherConstructor;
}
export interface SignalInterface {
Metadata: Metadata;
}

@ -7,15 +7,16 @@ export type CipherTextObject = {
body: BinaryString; body: BinaryString;
registrationId?: number; registrationId?: number;
}; };
export interface SignalProtocolAddressConstructor {
new (hexEncodedPublicKey: string, deviceId: number): SignalProtocolAddress;
fromString(encodedAddress: string): SignalProtocolAddress;
}
export declare class SignalProtocolAddress { export interface SignalProtocolAddress {
constructor(hexEncodedPublicKey: string, deviceId: number); getName(): string;
// tslint:disable-next-line: function-name getDeviceId(): number;
public static fromString(encodedAddress: string): SignalProtocolAddress; toString(): string;
public getName(): string; equals(other: SignalProtocolAddress): boolean;
public getDeviceId(): number;
public toString(): string;
public equals(other: SignalProtocolAddress): boolean;
} }
export type KeyPair = { export type KeyPair = {
@ -99,29 +100,30 @@ export interface KeyHelperInterface {
}>; }>;
} }
export declare class SessionCipher { export type SessionCipherConstructor = new (
constructor(storage: any, remoteAddress: SignalProtocolAddress); storage: any,
remoteAddress: SignalProtocolAddress
) => SessionCipher;
export interface SessionCipher {
/** /**
* @returns The envelope type, registration id and binary encoded encrypted body. * @returns The envelope type, registration id and binary encoded encrypted body.
*/ */
public encrypt(buffer: ArrayBuffer | Uint8Array): Promise<CipherTextObject>; encrypt(buffer: ArrayBuffer | Uint8Array): Promise<CipherTextObject>;
public decryptPreKeyWhisperMessage( decryptPreKeyWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>;
public decryptWhisperMessage(
buffer: ArrayBuffer | Uint8Array buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>; ): Promise<ArrayBuffer>;
public getRecord(encodedNumber: string): Promise<any | undefined>; decryptWhisperMessage(buffer: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
public getRemoteRegistrationId(): Promise<number>; getRecord(encodedNumber: string): Promise<any | undefined>;
public hasOpenSession(): Promise<boolean>; getRemoteRegistrationId(): Promise<number>;
public closeOpenSessionForDevice(): Promise<void>; hasOpenSession(): Promise<boolean>;
public deleteAllSessionsForDevice(): Promise<void>; closeOpenSessionForDevice(): Promise<void>;
deleteAllSessionsForDevice(): Promise<void>;
} }
export interface LibsignalProtocol { export interface LibsignalProtocol {
SignalProtocolAddress: typeof SignalProtocolAddress; SignalProtocolAddress: SignalProtocolAddressConstructor;
Curve: CurveInterface; Curve: CurveInterface;
crypto: CryptoInterface; crypto: CryptoInterface;
KeyHelper: KeyHelperInterface; KeyHelper: KeyHelperInterface;
SessionCipher: typeof SessionCipher; SessionCipher: SessionCipherConstructor;
} }

@ -1,8 +1,8 @@
import { EncryptionType } from '../types/EncryptionType'; import { EncryptionType } from '../types/EncryptionType';
import { SignalService } from '../../protobuf'; import { SignalService } from '../../protobuf';
import { libloki, libsignal, Signal, textsecure } from '../../window'; import { libloki, libsignal, Signal, textsecure } from '../../window';
import { CipherTextObject } from '../../window/types/libsignal-protocol';
import { UserUtil } from '../../util'; import { UserUtil } from '../../util';
import { CipherTextObject } from '../../../libtextsecure/libsignal-protocol';
export function padPlainTextBuffer(messageBuffer: Uint8Array): Uint8Array { export function padPlainTextBuffer(messageBuffer: Uint8Array): Uint8Array {
const plaintext = new Uint8Array( const plaintext = new Uint8Array(

@ -1,4 +1,4 @@
import { CipherTextObject } from '../../../../window/types/libsignal-protocol'; import { CipherTextObject } from '../../../../../libtextsecure/libsignal-protocol';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
export class FallBackSessionCipherStub { export class FallBackSessionCipherStub {

@ -1,7 +1,8 @@
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
import { CipherTextObject } from '../../../../window/types/libsignal-protocol'; import { CipherTextObject } from '../../../../../libtextsecure/libsignal-protocol';
import { SecretSessionCipherInterface } from '../../../../../js/modules/metadata/SecretSessionCipher';
export class SecretSessionCipherStub { export class SecretSessionCipherStub implements SecretSessionCipherInterface {
public async encrypt( public async encrypt(
_destinationPubkey: string, _destinationPubkey: string,
_senderCertificate: SignalService.SenderCertificate, _senderCertificate: SignalService.SenderCertificate,

@ -1,7 +1,10 @@
import { CipherTextObject } from '../../../../window/types/libsignal-protocol'; import {
CipherTextObject,
SessionCipher,
} from '../../../../../libtextsecure/libsignal-protocol';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
export class SessionCipherStub { export class SessionCipherStub implements SessionCipher {
public storage: any; public storage: any;
public address: any; public address: any;
constructor(storage: any, address: any) { constructor(storage: any, address: any) {
@ -17,4 +20,36 @@ export class SessionCipherStub {
body: Buffer.from(buffer).toString('binary'), body: Buffer.from(buffer).toString('binary'),
}; };
} }
public async decryptPreKeyWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer> {
throw new Error('Method not implemented.');
}
public async decryptWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer> {
throw new Error('Method not implemented.');
}
public async getRecord(encodedNumber: string): Promise<any> {
throw new Error('Method not implemented.');
}
public async getRemoteRegistrationId(): Promise<number> {
throw new Error('Method not implemented.');
}
public async hasOpenSession(): Promise<boolean> {
throw new Error('Method not implemented.');
}
public async closeOpenSessionForDevice(): Promise<void> {
throw new Error('Method not implemented.');
}
public async deleteAllSessionsForDevice(): Promise<void> {
throw new Error('Method not implemented.');
}
} }

@ -9,6 +9,7 @@
"max-func-body-length": false, "max-func-body-length": false,
"no-unused-expression": false, "no-unused-expression": false,
"no-unused-variable": false,
"await-promise": [true, "PromiseLike"], "await-promise": [true, "PromiseLike"],
"no-floating-promises": [true, "PromiseLike"] "no-floating-promises": [true, "PromiseLike"]

@ -1,5 +1,5 @@
import { getItemById } from '../../js/modules/data'; import { getItemById } from '../../js/modules/data';
import { KeyPair } from '../window/types/libsignal-protocol'; import { KeyPair } from '../../libtextsecure/libsignal-protocol';
export async function getCurrentDevicePubKey(): Promise<string | undefined> { export async function getCurrentDevicePubKey(): Promise<string | undefined> {
const item = await getItemById('number_id'); const item = await getItemById('number_id');

@ -1,8 +1,8 @@
import { LibsignalProtocol } from './types/libsignal-protocol';
import { SignalInterface } from './types/signal';
import { LocalizerType } from '../types/Util'; import { LocalizerType } from '../types/Util';
import LokiMessageAPI from '../../js/modules/loki_message_api'; import LokiMessageAPI from '../../js/modules/loki_message_api';
import LokiPublicChatFactoryAPI from '../../js/modules/loki_public_chat_api'; import LokiPublicChatFactoryAPI from '../../js/modules/loki_public_chat_api';
import { LibsignalProtocol } from '../../libtextsecure/libsignal-protocol';
import { SignalInterface } from '../../js/modules/signal';
interface WindowInterface extends Window { interface WindowInterface extends Window {
seedNodeList: any; seedNodeList: any;

@ -1,20 +0,0 @@
import { SignalService } from '../../protobuf';
import { CipherTextObject } from './libsignal-protocol';
export declare class SecretSessionCipher {
constructor(storage: any);
public encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
public decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}

@ -1,9 +0,0 @@
import { SecretSessionCipher } from './SecretSessionCipher';
interface Metadata {
SecretSessionCipher: typeof SecretSessionCipher;
}
export interface SignalInterface {
Metadata: Metadata;
}
Loading…
Cancel
Save