Skip to content

Commit

Permalink
refactor: parse data immediately (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
csirianni authored Dec 2, 2023
1 parent 89055bd commit 4368acd
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions frontend/app/psi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4368acd

Please sign in to comment.