import { binToNumberUint32LE , numberToBinUint32LE } from './numbers' ; const msPerLocktimeSecond = 1000 ; /**
 * The minimum Unix timestamp (inclusive) which can be encoded by a
 * transaction's `locktime`.
 */ export const minimumLocktimeTimestamp = 500000000 ; /**
 * The maximum Unix timestamp (inclusive) which can be encoded by a
 * transaction's `locktime`.
 */ export const maximumLocktimeTimestamp = 0xffffffff ; /**
 * The minimum Date (inclusive) which can be encoded by a transaction's
 * `locktime`.
 */ export const minimumLocktimeDate = new Date ( minimumLocktimeTimestamp * msPerLocktimeSecond ) ; /**
 * The maximum Date (inclusive) which can be encoded by a transaction's
 * `locktime`.
 */ export const maximumLocktimeDate = new Date ( maximumLocktimeTimestamp * msPerLocktimeSecond ) ; export enum LocktimeError { dateOutOfRange = 'The provided Date is outside of the range which can be encoded in locktime.' , locktimeOutOfRange = 'The provided locktime is outside of the range which can be encoded as a Date (greater than or equal to 500000000 and less than or equal to 4294967295).' , incorrectLength = 'The provided locktime is not the correct length (4 bytes).' } param date export const dateToLocktime = ( date ) => date < minimumLocktimeDate || date > maximumLocktimeDate ? LocktimeError . dateOutOfRange : Math . round ( date . getTime ( ) / msPerLocktimeSecond ) ; param locktime export const locktimeToDate = ( locktime ) => locktime < minimumLocktimeTimestamp || locktime > maximumLocktimeTimestamp ? LocktimeError . locktimeOutOfRange : new Date ( locktime * msPerLocktimeSecond ) ; param date export const dateToLocktimeBin = ( date ) => { const result = dateToLocktime ( date ) ; return typeof result === 'string' ? result : numberToBinUint32LE ( result ) ; } ; const locktimeByteLength = 4 ; param bin export const parseLocktimeBin = ( bin ) => { if ( bin . length !== locktimeByteLength ) return LocktimeError . incorrectLength ; const parsed = binToNumberUint32LE ( bin ) ; return parsed >= minimumLocktimeTimestamp ? new Date ( parsed * msPerLocktimeSecond ) : parsed ; } ;