UNPKG

@node-dlc/bitcoin

Version:
63 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Witness = void 0; const bufio_1 = require("@node-dlc/bufio"); /** * Represents segregated witness data. This data is nothing more than a * buffer. */ class Witness { /** * Parses witness data * @param reader */ static parse(reader) { const len = reader.readVarInt(); const data = reader.readBytes(Number(len)); return new Witness(data); } /** * Hex-encoded Witness data. This method interally creates a * StreamReader and uses the parse function * @param hex encoded as a string */ static fromHex(hex) { return Witness.parse(bufio_1.StreamReader.fromHex(hex)); } constructor(data) { this.data = data; } /** * Serializes witness data into a buffer in the format: * * [varint] length * [length] data */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeVarInt(this.data.length); writer.writeBytes(this.data); return writer.toBuffer(); } /** * Returns the string of a piece of witness data */ toString() { return this.data.toString('hex'); } /** * Returns the string of a piece of witness data */ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types toJSON() { return this.toString(); } /** * Clone via deep copy */ clone() { return new Witness(Buffer.from(this.data)); } } exports.Witness = Witness; //# sourceMappingURL=Witness.js.map