<?php

namespace App\Services\Events;

/**
 * HMAC-SHA256 signing for platform service-event webhooks.
 */
class ServiceEventSignature
{
    public static function sign(string $body, string $secret): string
    {
        return 'sha256='.hash_hmac('sha256', $body, $secret);
    }

    public static function verify(string $body, string $signature, string $secret): bool
    {
        if ($secret === '' || $signature === '') {
            return false;
        }

        return hash_equals(self::sign($body, $secret), $signature);
    }
}
