diff --git a/lib/tdf3/src/crypto/decrypt-worker.ts b/lib/tdf3/src/crypto/decrypt-worker.ts index d33665ad..7f328c0c 100644 --- a/lib/tdf3/src/crypto/decrypt-worker.ts +++ b/lib/tdf3/src/crypto/decrypt-worker.ts @@ -29,7 +29,7 @@ interface WorkersQueue { freeWorkers: Worker[]; resolvers: ((worker: Worker) => void)[]; push: (worker: Worker) => void; - pop: () => Promise, + pop: () => Promise; } const workersQueue: WorkersQueue = { @@ -54,8 +54,8 @@ const workersQueue: WorkersQueue = { this.resolvers.push(resolve); } }); - } -} + }, +}; export async function decrypt(data: DecryptData): Promise { const worker: Worker = await workersQueue.pop(); @@ -64,7 +64,7 @@ export async function decrypt(data: DecryptData): Promise { const { success, data, error } = event.data; workersQueue.push(worker); if (success) { - resolve((data as ArrayBuffer)); + resolve(data as ArrayBuffer); } else { reject(new TdfDecryptError(error)); } @@ -72,4 +72,4 @@ export async function decrypt(data: DecryptData): Promise { worker.postMessage(data); }); -}; \ No newline at end of file +} diff --git a/lib/tdf3/src/crypto/index.ts b/lib/tdf3/src/crypto/index.ts index defa8c48..8f70df92 100644 --- a/lib/tdf3/src/crypto/index.ts +++ b/lib/tdf3/src/crypto/index.ts @@ -276,11 +276,13 @@ async function _doDecrypt( algoDomString.iv = iv.asArrayBuffer(); try { - const decrypted = ( - navigator?.hardwareConcurrency - ? await workerDecrypt({ key: importedKey, encryptedPayload: payloadBuffer, algo: algoDomString }) - : await crypto.subtle.decrypt(algoDomString, importedKey, payloadBuffer) - ) + const decrypted = navigator?.hardwareConcurrency + ? await workerDecrypt({ + key: importedKey, + encryptedPayload: payloadBuffer, + algo: algoDomString, + }) + : await crypto.subtle.decrypt(algoDomString, importedKey, payloadBuffer); return { payload: Binary.fromArrayBuffer(decrypted) }; } catch (err) { diff --git a/lib/tdf3/src/tdf.ts b/lib/tdf3/src/tdf.ts index 88029c2f..befe85d0 100644 --- a/lib/tdf3/src/tdf.ts +++ b/lib/tdf3/src/tdf.ts @@ -996,25 +996,23 @@ export async function sliceAndDecrypt({ ); promises.push( - limit( - () => ( - decryptChunk( - encryptedChunk, - reconstructedKeyBinary, - slice[index]['hash'], - cipher, - segmentIntegrityAlgorithm, - cryptoService - ).then((decryptedChunk) => { - if (!decryptedChunk) return; - slice[index].decryptedChunk = decryptedChunk; - if (slice[index]._resolve) { - (slice[index]._resolve as (value: unknown) => void)(null); - } - }) - ) + limit(() => + decryptChunk( + encryptedChunk, + reconstructedKeyBinary, + slice[index]['hash'], + cipher, + segmentIntegrityAlgorithm, + cryptoService + ).then((decryptedChunk) => { + if (!decryptedChunk) return; + slice[index].decryptedChunk = decryptedChunk; + if (slice[index]._resolve) { + (slice[index]._resolve as (value: unknown) => void)(null); + } + }) ) - ) + ); } await Promise.all(promises); }