import crypto from 'node:crypto';
import env from '#start/env';
import { SumsubService } from '#services/sumsub_service';
export default class SumsubWebhookController {
    async handleWebhook({ request, response }) {
        const secretKey = env.get('SUMSUB_SECRET_KEY');
        const signature = request.header('x-payload-digest');
        const algorithm = request.header('x-payload-digest-alg') || 'HMAC_SHA256';
        const rawBody = request.raw() || JSON.stringify(request.body());
        if (signature) {
            const computedSignature = crypto
                .createHmac(algorithm.toLowerCase().replace('-', ''), secretKey)
                .update(rawBody)
                .digest('hex');
            if (computedSignature !== signature) {
                return response.unauthorized({ error: 'Invalid webhook signature' });
            }
        }
        const payload = request.body();
        await SumsubService.handleWebhook(payload);
        return response.ok({ received: true });
    }
}
//# sourceMappingURL=sumsub_webhook_controller.js.map