import * as crypto from 'node:crypto';
import { schema } from '../db/database.js';
class HmacService {
    algorithm = 'sha256';
    async isEnabled(id) {
        const result = await schema().select('hmac_enabled').from('_nango_environments').where({ id });
        const enabled = result[0]?.hmac_enabled ?? false;
        return enabled;
    }
    async getKey(id) {
        const result = await schema().select('hmac_key').from('_nango_environments').where({ id });
        const key = result[0]?.hmac_key ?? '';
        return key;
    }
    async verify(expectedDigest, id, ...values) {
        const actualDigest = await this.digest(id, ...values);
        return expectedDigest === actualDigest;
    }
    async digest(id, ...values) {
        const key = await this.getKey(id);
        const hmac = crypto.createHmac(this.algorithm, key);
        const data = values.join(':');
        hmac.update(data);
        return hmac.digest('hex');
    }
}
export default new HmacService();
//# sourceMappingURL=hmac.service.js.map