Skip to content

Commit

Permalink
API Key format
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 committed Feb 26, 2024
1 parent 4662e78 commit 0e0072c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions admin_frontend/src/components/ApiKeys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/constants/ErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
2 changes: 2 additions & 0 deletions backend/src/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 0e0072c

Please sign in to comment.