aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/activitypub/signature.ts
blob: 0ce15c1f6e735a88379eabb736b17037872bc0c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { body } from 'express-validator/check'
import * as express from 'express'

import {
  logger,
  isDateValid,
  isSignatureTypeValid,
  isSignatureCreatorValid,
  isSignatureValueValid
} from '../../../helpers'
import { checkErrors } 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 } })

    checkErrors(req, res, next)
  }
]

// ---------------------------------------------------------------------------

export {
  signatureValidator
}