"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CetAdaptorSignaturesV0 = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
/**
 * CetAdaptorSignatures V0 contains CET signatures and any necessary
 * information linking the signatures to their corresponding outcome
 */
class CetAdaptorSignaturesV0 {
    constructor() {
        /**
         * The type for cet_adaptor_signature message. cet_adaptor_signature = 42774
         */
        this.type = CetAdaptorSignaturesV0.type;
        this.sigs = [];
    }
    /**
     * Deserializes a cet_adaptor_signature_v0 message
     * @param buf
     */
    static deserialize(buf) {
        const instance = new CetAdaptorSignaturesV0();
        const reader = new bufio_1.BufferReader(buf);
        reader.readBigSize(); // read type
        instance.length = reader.readBigSize();
        reader.readBigSize(); // nb_signatures
        while (!reader.eof) {
            const encryptedSig = reader.readBytes(65);
            const dleqProof = reader.readBytes(97);
            instance.sigs.push({ encryptedSig, dleqProof });
        }
        return instance;
    }
    /**
     * Converts cet_adaptor_signature to JSON
     */
    toJSON() {
        return {
            type: this.type,
            sigs: this.sigs.map((sig) => {
                return {
                    encryptedSig: sig.encryptedSig.toString('hex'),
                    dleqProof: sig.dleqProof.toString('hex'),
                };
            }),
        };
    }
    /**
     * Serializes the cet_adaptor_signature message into a Buffer
     */
    serialize() {
        const writer = new bufio_1.BufferWriter();
        writer.writeBigSize(this.type);
        const dataWriter = new bufio_1.BufferWriter();
        dataWriter.writeBigSize(this.sigs.length);
        for (const sig of this.sigs) {
            dataWriter.writeBytes(sig.encryptedSig);
            dataWriter.writeBytes(sig.dleqProof);
        }
        writer.writeBigSize(dataWriter.size);
        writer.writeBytes(dataWriter.toBuffer());
        return writer.toBuffer();
    }
}
exports.CetAdaptorSignaturesV0 = CetAdaptorSignaturesV0;
CetAdaptorSignaturesV0.type = MessageType_1.MessageType.CetAdaptorSignaturesV0;
//# sourceMappingURL=CetAdaptorSignaturesV0.js.map