mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
added types for crypto
This commit is contained in:
2
frontend/package-lock.json
generated
2
frontend/package-lock.json
generated
@@ -102,7 +102,7 @@
|
||||
"@storybook/testing-library": "^0.2.0",
|
||||
"@tailwindcss/typography": "^0.5.4",
|
||||
"@types/jsrp": "^0.2.4",
|
||||
"@types/node": "18.11.9",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/react": "^18.0.26",
|
||||
"@types/sanitize-html": "^2.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.48.1",
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
"@storybook/testing-library": "^0.2.0",
|
||||
"@tailwindcss/typography": "^0.5.4",
|
||||
"@types/jsrp": "^0.2.4",
|
||||
"@types/node": "18.11.9",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/react": "^18.0.26",
|
||||
"@types/sanitize-html": "^2.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.48.1",
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import axios from "axios";
|
||||
import crypto from "crypto";
|
||||
import crypto from "crypto"; // added types from @types/node
|
||||
|
||||
///// REMINDER: ensure all logs are deleted!!! /////
|
||||
|
||||
export const checkIsPasswordBreached = async (password: string) => {
|
||||
const dataBreachCheckAPIBaseURL = "https://api.pwnedpasswords.com/range/";
|
||||
try {
|
||||
|
||||
console.log("password:", password); // delete later!!!
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
@@ -14,7 +13,7 @@ export const checkIsPasswordBreached = async (password: string) => {
|
||||
const encodedPwd = textEncoder.encode(password);
|
||||
console.log("encodedPwd:", encodedPwd); // delete later!!!
|
||||
|
||||
const hashBuffer = crypto.subtle.digest("SHA-1", encodedPwd); // removed async
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-1", encodedPwd); // returns promise
|
||||
console.log("hashBuffer:", hashBuffer); // delete later!!!
|
||||
|
||||
const hashedPwd = Array.from(new Uint8Array(hashBuffer))
|
||||
@@ -24,9 +23,7 @@ export const checkIsPasswordBreached = async (password: string) => {
|
||||
|
||||
console.log("hashedPwd:", hashedPwd); // delete later!!!
|
||||
|
||||
const response = await axios.get(
|
||||
`${dataBreachCheckAPIBaseURL}${hashedPwd.slice(0, 5)}`
|
||||
);
|
||||
const response = await axios.get(`${dataBreachCheckAPIBaseURL}${hashedPwd.slice(0, 5)}`);
|
||||
console.log("response:", response); // delete later!!!
|
||||
|
||||
const responseData = response.data.toUpperCase();
|
||||
@@ -40,11 +37,7 @@ export const checkIsPasswordBreached = async (password: string) => {
|
||||
|
||||
return isBreachedPassword;
|
||||
} catch (err: any) {
|
||||
if (
|
||||
axios.isAxiosError(err) &&
|
||||
err.response &&
|
||||
err.response.status === 429
|
||||
) {
|
||||
if (axios.isAxiosError(err) && err.response && err.response.status === 429) {
|
||||
console.error("Received a 429 response from the Pwnd Passwords API");
|
||||
// Handle the 429 error here
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user