Improve typings for LibsignalProtocol

pull/1162/head
Mikunj 5 years ago
parent cbc32b9989
commit 41fa167e79

@ -1,7 +1,10 @@
import { CipherTextObject } from '../../../../window/types/libsignal-protocol'; import {
CipherTextObject,
SessionCipher,
} from '../../../../window/types/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"]

@ -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;
} }

Loading…
Cancel
Save