// testing/cassette/signature.ts — Request signature computation (SPEC-743)
// Computes sha256 of normalised request payload for cassette matching.
import { createHash } from 'node:crypto';
/**
 * Normalise a request object for hashing.
 * Sorts keys alphabetically so { a:1, b:2 } and { b:2, a:1 } produce the same hash.
 */
function normalise(obj) {
    if (obj === null || typeof obj !== 'object') {
        return obj;
    }
    if (Array.isArray(obj)) {
        return obj.map(normalise);
    }
    const sorted = {};
    for (const key of Object.keys(obj).sort((a, b) => a.localeCompare(b))) {
        sorted[key] = normalise(obj[key]);
    }
    return sorted;
}
/**
 * Compute a stable sha256 hex digest of an Anthropic request.
 * The hash covers: model + messages + system (key-sorted JSON).
 */
export function computeRequestSha(request) {
    const payload = {
        model: request.model,
        messages: request.messages,
        system: request.system,
    };
    const normalised = normalise(payload);
    const json = JSON.stringify(normalised);
    return createHash('sha256').update(json).digest('hex');
}
//# sourceMappingURL=signature.js.map