import { convertToArrayBuffer } from "../../helpers/bytes"; import type { InputCheckPasswordSRP } from "../../layer"; import { aesEncryptSync, aesDecryptSync, sha256HashSync, sha1HashSync, bytesModPow } from "./crypto_utils"; export default abstract class CryptoWorkerMethods { abstract performTaskWorker(task: string, ...args: any[]): Promise; public sha1Hash(bytes: Parameters[0]): Promise { return this.performTaskWorker('sha1-hash', bytes); } public sha256Hash(bytes: Parameters[0]) { return this.performTaskWorker('sha256-hash', bytes); } public pbkdf2(buffer: Uint8Array, salt: Uint8Array, iterations: number) { return this.performTaskWorker('pbkdf2', buffer, salt, iterations); } public aesEncrypt(bytes: Parameters[0], keyBytes: Parameters[1], ivBytes: Parameters[2]) { return this.performTaskWorker>('aes-encrypt', convertToArrayBuffer(bytes), convertToArrayBuffer(keyBytes), convertToArrayBuffer(ivBytes)); } public aesDecrypt(encryptedBytes: Parameters[0], keyBytes: Parameters[1], ivBytes: Parameters[2]): 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: Uint8Array) { return this.performTaskWorker<[number[], number[], number]>('factorize', [...bytes]); } public modPow(x: Parameters[0], y: Parameters[1], m: Parameters[2]) { 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, isNew = false): Promise { return this.performTaskWorker('computeSRP', password, state, isNew); } }