"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha256 = sha256;
exports.stableJson = stableJson;
const crypto_1 = require("crypto");
function sha256(data) {
    return (0, crypto_1.createHash)('sha256').update(data, 'utf8').digest('hex');
}
// Stable JSON stringify: sorts object keys recursively.
function stableJson(value) {
    return JSON.stringify(sortValue(value));
}
function sortValue(value) {
    if (Array.isArray(value)) {
        return value.map(sortValue);
    }
    if (value && typeof value === 'object') {
        const entries = Object.entries(value)
            .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
            .map(([k, v]) => [k, sortValue(v)]);
        return Object.fromEntries(entries);
    }
    return value;
}
