"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScriptWitnessV0 = void 0;
const bufio_1 = require("@node-dlc/bufio");
/**
 * ScriptWitness is the data for a witness element in a witness stack.
 * An empty witness_stack is an error, as every input must be Segwit.
 * Witness elements should not include their length as part of the witness
 * data.
 */
class ScriptWitnessV0 {
    /**
     * Deserializes an script_witness_v0 message
     * @param buf
     */
    static deserialize(buf) {
        const instance = new ScriptWitnessV0();
        const reader = new bufio_1.BufferReader(buf);
        instance.length = Number(reader.readBigSize());
        instance.witness = reader.readBytes(instance.length);
        return instance;
    }
    static getWitness(reader) {
        const length = Number(reader.readBigSize());
        const body = reader.readBytes(Number(length));
        const writer = new bufio_1.BufferWriter();
        writer.writeBigSize(length);
        writer.writeBytes(body);
        return writer.toBuffer();
    }
    /**
     * Converts script_witness_v0 to JSON
     */
    toJSON() {
        return {
            witness: this.witness.toString('hex'),
        };
    }
    /**
     * Serializes the script_witness_v0 message into a Buffer
     */
    serialize() {
        const writer = new bufio_1.BufferWriter();
        writer.writeBigSize(this.witness.length);
        writer.writeBytes(this.witness);
        return writer.toBuffer();
    }
}
exports.ScriptWitnessV0 = ScriptWitnessV0;
//# sourceMappingURL=ScriptWitnessV0.js.map