Hi there,
I’m trying to test my code but the webhook returns as Invalid signature error.
I tried using another account and it’s working perfectly (Status:201) I don’t understand why my main account get’s Invalid signature error.
I’m using nestjs
@Post('/webhook')
async patreonWebhook(@Headers() headers: any, @Body() body: WebhookBodyDto) {
await this.setPatreonKeys();
const signature = headers['x-patreon-signature'];
const verified = computeHash(this.patreonWebhookSecret, body) === signature;
if (!verified) {
logger('error', {
message: 'Invalid signature',
signature,
secret: this.patreonWebhookSecret,
body,
});
throw new BadRequestException('Invalid signature');
}
}
import * as crypto from 'crypto';
export const computeHash = (secret, payload) => {
const str = JSON.stringify(payload);
const md5Hasher = crypto.createHmac('md5', secret);
return md5Hasher.update(str).digest('hex');
};