import { StreamReader } from "@node-lightning/bufio" ; import { HashByteOrder } from "./HashByteOrder" ; import { ICloneable } from "./ICloneable" ; export class HashValue implements ICloneable < HashValue > { param stream public static parse ( reader ) { return new HashValue ( reader . readBytes ( 32 ) ) ; } param stream public static fromRpcStream ( reader ) { const value = reader . readBytes ( 32 ) . reverse ( ) ; return new HashValue ( value ) ; } param value public static fromRpc ( value ) { const reader = StreamReader . fromHex ( value ) ; return this . fromRpcStream ( reader ) ; } /**
     * Internal-byte-order version of the hash value
     */ private _value : Buffer ; param value constructor ( value ) { this . _value = value ; } /**
     * Returns the hash value as a hex string. Defaults to using RPC
     * (reversed/big-endian) byte order.
     */ public toString ( byteOrder = HashByteOrder . RPC ) { if ( byteOrder === HashByteOrder . RPC ) { return Buffer . from ( this . _value ) . reverse ( ) . toString ( "hex" ) ; } else { return Buffer . from ( this . _value ) . toString ( "hex" ) ; } } /**
     * Serializes to JSON returning a hex string. Defaults to using
     * RPC (reversed/big endian) byte order.
     */ public toJSON ( byteOrder ? ) { return this . toString ( byteOrder ) ; } /**
     * Serializes the hash value into an internal-byte order Buffer
     */ public serialize ( byteOrder = HashByteOrder . Internal ) { if ( byteOrder === HashByteOrder . Internal ) { return Buffer . from ( this . _value ) ; } else { return Buffer . from ( this . _value ) . reverse ( ) ; } } /**
     * Deep copy clone
     */ public clone ( ) { return new HashValue ( Buffer . from ( this . _value ) ) ; } }