]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { body } from 'express-validator' |
da854ddd | 3 | import { |
10363c74 C |
4 | isSignatureCreatorValid, |
5 | isSignatureTypeValid, | |
da854ddd C |
6 | isSignatureValueValid |
7 | } from '../../../helpers/custom-validators/activitypub/signature' | |
3fd3ab2d | 8 | import { isDateValid } from '../../../helpers/custom-validators/misc' |
da854ddd | 9 | import { logger } from '../../../helpers/logger' |
10363c74 | 10 | import { areValidationErrors } from '../shared' |
e4f97bab C |
11 | |
12 | const signatureValidator = [ | |
41f2ebae C |
13 | body('signature.type') |
14 | .optional() | |
15 | .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), | |
16 | body('signature.created') | |
17 | .optional() | |
70330f63 | 18 | .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'), |
41f2ebae C |
19 | body('signature.creator') |
20 | .optional() | |
21 | .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), | |
22 | body('signature.signatureValue') | |
23 | .optional() | |
24 | .custom(isSignatureValueValid).withMessage('Should have a valid signature value'), | |
e4f97bab C |
25 | |
26 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
e7053b1d | 27 | logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } }) |
e4f97bab | 28 | |
a2431b7d C |
29 | if (areValidationErrors(req, res)) return |
30 | ||
31 | return next() | |
e4f97bab C |
32 | } |
33 | ] | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | export { | |
38 | signatureValidator | |
39 | } |