import { convertToArrayBuffer, convertToByteArray } from "../bin_utils"; import type { InputCheckPasswordSRP } from "../../layer"; export default abstract class CryptoWorkerMethods { abstract performTaskWorker(task: string, ...args: any[]): Promise; public sha1Hash(bytes: number[] | ArrayBuffer | Uint8Array): Promise { return this.performTaskWorker('sha1-hash', bytes); } public sha256Hash(bytes: any) { return this.performTaskWorker('sha256-hash', bytes); } public pbkdf2(buffer: Uint8Array, salt: Uint8Array, iterations: number) { return this.performTaskWorker('pbkdf2', buffer, salt, iterations); } public aesEncrypt(bytes: any, keyBytes: any, ivBytes: any) { return this.performTaskWorker('aes-encrypt', convertToArrayBuffer(bytes), convertToArrayBuffer(keyBytes), convertToArrayBuffer(ivBytes)); } public aesDecrypt(encryptedBytes: any, keyBytes: any, ivBytes: any): Promise { return this.performTaskWorker('aes-decrypt', encryptedBytes, keyBytes, ivBytes) .then(bytes => convertToArrayBuffer(bytes)); } public rsaEncrypt(publicKey: {modulus: string, exponent: string}, bytes: any): Promise { return this.performTaskWorker('rsa-encrypt', publicKey, bytes); } public factorize(bytes: any) { bytes = convertToByteArray(bytes); return this.performTaskWorker<[number[], number[], number]>('factorize', bytes); } public modPow(x: any, y: any, m: any) { return this.performTaskWorker('mod-pow', x, y, m); } public gzipUncompress(bytes: ArrayBuffer, toString?: boolean) { return this.performTaskWorker('gzipUncompress', bytes, toString); } public computeSRP(password: string, state: any): Promise { return this.performTaskWorker('computeSRP', password, state); } }