Moves libtextsecure to Typescript

* Starting to work through lint errors

* libsignal-protocol: Update changes for primary repo compatibility

* Step 1: task_with_timeout rename

* Step 2: Apply the changes to TaskWithTimeout.ts

* Step 1: All to-be-converted libtextsecure/*.js files moved

* Step 2: No Typescript errors!

* Get libtextsecure tests passing again

* TSLint errors down to 1

* Compilation succeeds, no lint errors or test failures

* WebSocketResources - update import for case-sensitive filesystems

* Fixes for lint-deps

* Remove unnecessary @ts-ignore

* Fix inability to message your own contact after link

* Add log message for the end of migration 20

* lint fix
This commit is contained in:
Scott Nonnenberg 2020-04-13 10:37:29 -07:00
parent 2f2d027161
commit b7d56def82
45 changed files with 5983 additions and 4042 deletions

135
ts/window.d.ts vendored
View file

@ -1,17 +1,32 @@
// Captures the globals put in place by preload.js, background.js and others
import {
LibSignalType,
SignalProtocolAddressClass,
StorageType,
} from './libsignal.d';
import { TextSecureType } from './textsecure.d';
import { WebAPIConnectType } from './textsecure/WebAPI';
import * as Crypto from './Crypto';
declare global {
interface Window {
dcodeIO: DCodeIOType;
getExpiration: () => string;
getEnvironment: () => string;
getSocketStatus: () => number;
libphonenumber: {
util: {
getRegionCodeForNumber: (number: string) => string;
};
};
libsignal: LibSignalType;
log: {
info: LoggerType;
warn: LoggerType;
error: LoggerType;
};
normalizeUuids: (obj: any, paths: Array<string>, context: string) => any;
restart: () => void;
storage: {
put: (key: string, value: any) => void;
@ -20,12 +35,32 @@ declare global {
};
textsecure: TextSecureType;
Signal: {
Crypto: typeof Crypto;
Metadata: {
SecretSessionCipher: typeof SecretSessionCipherClass;
createCertificateValidator: (
trustRoot: ArrayBuffer
) => CertificateValidatorType;
};
};
ConversationController: ConversationControllerType;
WebAPI: WebAPIConnectType;
Whisper: WhisperType;
}
}
export type ConversationType = {
updateE164: (e164?: string) => void;
updateUuid: (uuid?: string) => void;
id: string;
};
export type ConversationControllerType = {
getOrCreateAndWait: (
identifier: string,
type: 'private' | 'group'
) => Promise<ConversationType>;
getConversationId: (identifier: string) => string | null;
prepareForSend: (
id: string,
@ -34,65 +69,65 @@ export type ConversationControllerType = {
wrap: (promise: Promise<any>) => Promise<void>;
sendOptions: Object;
};
get: (
identifier: string
) => null | {
get: (key: string) => any;
};
};
export type DCodeIOType = {
ByteBuffer: {
wrap: (
value: any,
type?: string
) => {
toString: (type: string) => string;
toArrayBuffer: () => ArrayBuffer;
};
ByteBuffer: typeof ByteBufferClass;
Long: {
fromBits: (low: number, high: number, unsigned: boolean) => number;
};
};
export type LibSignalType = {
KeyHelper: {
generateIdentityKeyPair: () => Promise<{
privKey: ArrayBuffer;
pubKey: ArrayBuffer;
}>;
};
Curve: {
async: {
calculateAgreement: (
publicKey: ArrayBuffer,
privateKey: ArrayBuffer
) => Promise<ArrayBuffer>;
};
};
HKDF: {
deriveSecrets: (
packKey: ArrayBuffer,
salt: ArrayBuffer,
info: ArrayBuffer
) => Promise<Array<ArrayBuffer>>;
};
};
export class CertificateValidatorType {
validate: (cerficate: any, certificateTime: number) => Promise<void>;
}
export class SecretSessionCipherClass {
constructor(storage: StorageType);
decrypt: (
validator: CertificateValidatorType,
ciphertext: ArrayBuffer,
serverTimestamp: number,
me: any
) => Promise<{
isMe: boolean;
sender: SignalProtocolAddressClass;
senderUuid: SignalProtocolAddressClass;
content: ArrayBuffer;
}>;
getRemoteRegistrationId: (
address: SignalProtocolAddressClass
) => Promise<number>;
closeOpenSessionForDevice: (
address: SignalProtocolAddressClass
) => Promise<void>;
encrypt: (
address: SignalProtocolAddressClass,
senderCertificate: any,
plaintext: ArrayBuffer | Uint8Array
) => Promise<ArrayBuffer>;
}
export class ByteBufferClass {
constructor(value?: any, encoding?: string);
static wrap: (value: any, type?: string) => ByteBufferClass;
toString: (type: string) => string;
toArrayBuffer: () => ArrayBuffer;
slice: (start: number, end?: number) => ByteBufferClass;
append: (data: ArrayBuffer) => void;
limit: number;
offset: 0;
readVarint32: () => number;
skip: (length: number) => void;
}
export type LoggerType = (...args: Array<any>) => void;
export type TextSecureType = {
storage: {
user: {
getNumber: () => string;
};
get: (key: string) => any;
};
messaging: {
sendStickerPackSync: (
operations: Array<{
packId: string;
packKey: string;
installed: boolean;
}>,
options: Object
) => Promise<void>;
};
};
export type WhisperType = {
events: {
trigger: (name: string, param1: any, param2: any) => void;