From 0e0072cfdd0b39acd6c68056605bfe15efb10cc2 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Mon, 26 Feb 2024 14:14:58 +0530 Subject: [PATCH] API Key format --- README.md | 8 ++++++++ admin_frontend/src/components/ApiKeys.jsx | 4 ++++ backend/src/constants/ErrorMessage.ts | 3 ++- backend/src/routes/admin.ts | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45714e6..181d15b 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,14 @@ There is an option to run the code locally without using AWS and only using loca } } which also needs to be converted into `base64` value +## API KEY VALIDATION +- In ARKA Admin Frontend, create an API_KEY with the following format - +* Min length - 8 Max length - 20 +* contains atleast one Special characters out of these - `@$!%*-_&` +* contains atleast one lowercase alphabet +* contains atleast one uppercase alphabet +* contains atleast one digit 0-9 + ## 🔙 Arka Backend diff --git a/admin_frontend/src/components/ApiKeys.jsx b/admin_frontend/src/components/ApiKeys.jsx index e68bf33..6dcb179 100644 --- a/admin_frontend/src/components/ApiKeys.jsx +++ b/admin_frontend/src/components/ApiKeys.jsx @@ -68,6 +68,10 @@ const ApiKeysPage = () => { toast.error("Please input both API_KEY & PRIVATE_KEY field"); return; } + if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(apiKey)) { + toast.error("Invalid Validation: API_KEY format. Please see the docs for more info"); + return; + } try { setLoading(true); const requestData = { diff --git a/backend/src/constants/ErrorMessage.ts b/backend/src/constants/ErrorMessage.ts index 03e9d9e..6c981be 100644 --- a/backend/src/constants/ErrorMessage.ts +++ b/backend/src/constants/ErrorMessage.ts @@ -8,5 +8,6 @@ export default { INVALID_MODE: 'Invalid mode selected', DUPLICATE_RECORD: 'Duplicate record found', QUOTA_EXCEEDED: 'Quota exceeded for this month', - RECORD_NOT_FOUND: 'Api Key provided not found' + RECORD_NOT_FOUND: 'Api Key provided not found', + API_KEY_VALIDATION_FAILED: 'Api Key is not in the right format as described', } \ No newline at end of file diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index bc3900e..2406814 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -62,6 +62,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => { if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY }); if (!body.API_KEY || !body.PRIVATE_KEY) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA }); + if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(body.API_KEY)) + return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_VALIDATION_FAILED }) const wallet = new ethers.Wallet(body.PRIVATE_KEY); const publicAddress = await wallet.getAddress(); const result: any[] = await new Promise((resolve, reject) => {