1 import * as express from 'express'
2 import { body } from 'express-validator'
4 isSignatureCreatorValid, isSignatureTypeValid,
6 } from '../../../helpers/custom-validators/activitypub/signature'
7 import { isDateValid } from '../../../helpers/custom-validators/misc'
8 import { logger } from '../../../helpers/logger'
9 import { areValidationErrors } from '../utils'
11 const signatureValidator = [
12 body('signature.type')
14 .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
15 body('signature.created')
17 .custom(isDateValid).withMessage('Should have a valid signature created date'),
18 body('signature.creator')
20 .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
21 body('signature.signatureValue')
23 .custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
25 (req: express.Request, res: express.Response, next: express.NextFunction) => {
26 logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
28 if (areValidationErrors(req, res)) return
34 // ---------------------------------------------------------------------------