blob: d41bb6a8d6e387062ef21c0a30607fde98e4577c (
plain) (
tree)
|
|
import * as express from 'express'
import { body } from 'express-validator/check'
import { logger } from '../../../helpers'
import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub'
import { isDateValid } from '../../../helpers/custom-validators/misc'
import { areValidationErrors } from '../utils'
const signatureValidator = [
body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
if (areValidationErrors(req, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
signatureValidator
}
|