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