signature.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as express from 'express'
  2. import { body } from 'express-validator/check'
  3. import {
  4. isSignatureCreatorValid, isSignatureTypeValid,
  5. isSignatureValueValid
  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'
  10. const signatureValidator = [
  11. body('signature.type')
  12. .optional()
  13. .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
  14. body('signature.created')
  15. .optional()
  16. .custom(isDateValid).withMessage('Should have a valid signature created date'),
  17. body('signature.creator')
  18. .optional()
  19. .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
  20. body('signature.signatureValue')
  21. .optional()
  22. .custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
  23. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  24. logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
  25. if (areValidationErrors(req, res)) return
  26. return next()
  27. }
  28. ]
  29. // ---------------------------------------------------------------------------
  30. export {
  31. signatureValidator
  32. }