export default class Webhooks { publicKey: string; secretKey?: string; constructor({ publicKey, secretKey, }: { publicKey: string; secretKey?: string; }); /** * Injects the webhook public key for authentication * @param header X-FormSG-Signature header * @param uri The endpoint that FormSG is POSTing to * @returns true if the header is verified * @throws {WebhookAuthenticateError} If the signature or uri cannot be verified */ authenticate: (header: string, uri: string) => boolean; /** * Generates a signature based on the URI, submission ID and epoch timestamp. * @param params The parameters needed to generate the signature * @param params.uri Full URL of the request * @param params.submissionId Submission Mongo ObjectId saved to the database * @param params.epoch Number of milliseconds since Jan 1, 1970 * @returns the generated signature * @throws {MissingSecretKeyError} if a secret key is not provided when instantiating this class * @throws {TypeError} if any parameters are undefined */ generateSignature: ({ uri, submissionId, formId, epoch, }: { uri: string; submissionId: string; formId: string; epoch: number; }) => string; /** * Constructs the `X-FormSG-Signature` header * @param params The parameters needed to construct the header * @param params.epoch Epoch timestamp * @param params.submissionId Mongo ObjectId * @param params.formId Mongo ObjectId * @param params.signature A signature generated by the generateSignature() function * @returns The `X-FormSG-Signature` header * @throws {Error} if a secret key is not provided when instantiating this class */ constructHeader: ({ epoch, submissionId, formId, signature, }: { epoch: number; submissionId: string; formId: string; signature: string; }) => string; }