"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bytes32FromUtf8 = bytes32FromUtf8;
exports.instructionIdFromTxHash = instructionIdFromTxHash;
exports.uetrFromTxHash = uetrFromTxHash;
exports.uetrBytes32FromTxHash = uetrBytes32FromTxHash;
exports.hashShortUtf8 = hashShortUtf8;
exports.authAttestationHashFromProof = authAttestationHashFromProof;
const ethers_1 = require("ethers");
function bytes32FromUtf8(label, value) {
    return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`${label}:${value}`));
}
function instructionIdFromTxHash(txHash) {
    return bytes32FromUtf8('INSTR', txHash);
}
function uetrFromTxHash(txHash) {
    const h = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`UETR:${txHash}`));
    const hex = h.slice(2);
    return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
}
function uetrBytes32FromTxHash(txHash) {
    return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(uetrFromTxHash(txHash)));
}
function hashShortUtf8(value) {
    if (!value)
        return ethers_1.ethers.ZeroHash;
    return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(value));
}
/** KTT off-chain test-key attestation per SMART_CONTRACTS_ISO20022_FIN_METHODOLOGY §5.3 */
function authAttestationHashFromProof(testKeyProof, normalizedBody) {
    const proof = testKeyProof.trim();
    const body = normalizedBody.trim();
    if (!proof && !body)
        return ethers_1.ethers.ZeroHash;
    return ethers_1.ethers.keccak256(ethers_1.ethers.concat([ethers_1.ethers.toUtf8Bytes(proof), ethers_1.ethers.toUtf8Bytes(body)]));
}
