interface ConverterInterface { toBigInt ( buf , bigEndian ? ) : bigint ; fromBigInt ( num , buf , bigEndian ? ) : Buffer ; } declare var process ; let converter ; if ( ! process . browser ) { try { converter = require ( 'bindings' ) ( 'bigint_buffer' ) ; } catch ( e ) { console . warn ( 'bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)' ) ; } } param buf returns export function toBigIntLE ( buf ) { if ( process . browser || converter === undefined ) { const reversed = Buffer . from ( buf ) ; reversed . reverse ( ) ; const hex = reversed . toString ( 'hex' ) ; if ( hex . length === 0 ) { return BigInt ( 0 ) ; } return BigInt ( `0x${ hex }` ) ; } return converter . toBigInt ( buf , false ) ; } param buf returns export function toBigIntBE ( buf ) { if ( process . browser || converter === undefined ) { const hex = buf . toString ( 'hex' ) ; if ( hex . length === 0 ) { return BigInt ( 0 ) ; } return BigInt ( `0x${ hex }` ) ; } return converter . toBigInt ( buf , true ) ; } param num param width returns export function toBufferLE ( num , width ) { if ( process . browser || converter === undefined ) { const hex = num . toString ( 16 ) ; const buffer = Buffer . from ( hex . padStart ( width * 2 , '0' ) . slice ( 0 , width * 2 ) , 'hex' ) ; buffer . reverse ( ) ; return buffer ; } return converter . fromBigInt ( num , Buffer . allocUnsafe ( width ) , false ) ; } param num param width returns export function toBufferBE ( num , width ) { if ( process . browser || converter === undefined ) { const hex = num . toString ( 16 ) ; return Buffer . from ( hex . padStart ( width * 2 , '0' ) . slice ( 0 , width * 2 ) , 'hex' ) ; } return converter . fromBigInt ( num , Buffer . allocUnsafe ( width ) , true ) ; }