From 4368acdc07d4a1b4b0de1a662a4d338c9ca5ac20 Mon Sep 17 00:00:00 2001 From: Cedric Sirianni Date: Sat, 2 Dec 2023 15:00:45 -0500 Subject: [PATCH] refactor: parse data immediately (#32) --- frontend/app/psi.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/frontend/app/psi.ts b/frontend/app/psi.ts index bb0182b..d1267c1 100644 --- a/frontend/app/psi.ts +++ b/frontend/app/psi.ts @@ -39,29 +39,18 @@ function computeIntersection( data: ServerResponse, aInverse: Uint8Array ): boolean { - const password = data.userPassword; - const serverSet = data.breachedPasswords; - - const options = new Set( - serverSet.map(function (element) { - return base64.parse(element).join(""); - }) - ); + const userPassword = base64.parse(data.userPassword); + const breachedPasswords = new Set((data.breachedPasswords).map(function (element) { return base64.parse(element).join(""); })); // Client phase 2 - applies inverse seed A to (user password)^ab // so now ((user password)^ab)^-a = (user password)^b const clientPasswordB = sodium.crypto_scalarmult_ristretto255( aInverse, - base64.parse(password) + userPassword ); // End of Client phase 2. - if (options.has(clientPasswordB.join(""))) { - console.log(clientPasswordB.join("")); - return true; - } - - return false; + return breachedPasswords.has(clientPasswordB.join("")); } // Make API call to server to check if password was found in breached dataset