Skip to content

Commit

Permalink
add validators
Browse files Browse the repository at this point in the history
  • Loading branch information
gianfra-t committed Nov 12, 2024
1 parent a6be1ed commit 9f671b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions signer-service/src/api/middlewares/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ const validateSep10Input = (req, res, next) => {
next();
};

const validateSiweCreate = (req, res, next) => {
const { walletAddress } = req.body;
if (!walletAddress) {
return res.status(400).json({ error: 'Missing address: walletAddress' });
}
next();
};

const validateSiweValidate = (req, res, next) => {
const { nonce, signature } = req.body;
if (!signature) {
return res.status(400).json({ error: 'Missing signature: signature' });
}

if (!nonce) {
return res.status(400).json({ error: 'Missing initial nonce: nonce' });
}

next();
};

module.exports = {
validateChangeOpInput,
validateQuoteInput,
Expand All @@ -166,4 +187,6 @@ module.exports = {
validateRatingInput,
validateExecuteXCM,
validateSep10Input,
validateSiweCreate,
validateSiweValidate,
};
5 changes: 3 additions & 2 deletions signer-service/src/api/routes/v1/siwe.route.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const express = require('express');
const controller = require('../../controllers/siwe.controller');
const { validateSiweCreate, validateSiweValidate } = require('../../middlewares/validators');

const router = express.Router({ mergeParams: true });

router.route('/create').post(controller.sendSiweMessage);
router.route('/create').post(validateSiweCreate, controller.sendSiweMessage);

router.route('/validate').post(controller.validateSiweSignature);
router.route('/validate').post(validateSiweValidate, controller.validateSiweSignature);

module.exports = router;

0 comments on commit 9f671b5

Please sign in to comment.