import { BufferWriter , StreamReader } from "@node-lightning/bufio" ; import { ICloneable } from "./ICloneable" ; /**
 * Represents segregated witness data. This data is nothing more than a
 * buffer.
 */ export class Witness implements ICloneable < Witness > { param reader public static parse ( reader ) { const len = reader . readVarInt ( ) ; const data = reader . readBytes ( Number ( len ) ) ; return new Witness ( data ) ; } param hex public static fromHex ( hex ) { return Witness . parse ( StreamReader . fromHex ( hex ) ) ; } constructor ( readonly data ) { } /**
     * Serializes witness data into a buffer in the format:
     *
     * [varint] length
     * [length] data
     */ public serialize ( ) { const writer = new BufferWriter ( ) ; writer . writeVarInt ( this . data . length ) ; writer . writeBytes ( this . data ) ; return writer . toBuffer ( ) ; } /**
     * Returns the string of a piece of witness data
     */ public toString ( ) { return this . data . toString ( "hex" ) ; } /**
     * Returns the string of a piece of witness data
     */ public toJSON ( ) { return this . toString ( ) ; } /**
     * Clone via deep copy
     */ public clone ( ) { return new Witness ( Buffer . from ( this . data ) ) ; } }