import { BigNumber } from 'bignumber.js' ; import { ERROR_CODE } from './../error' ; import { bigIntFromBytes , bigIntToBytes } from './../utils' ; const SIZE = 8 ; /**
 * Big positive integer base on BigNumber
 */ export default class BigInt { param hex static fromHexstr ( hex ) { return new BigInt ( bigIntFromBytes ( hex ) ) ; } value : string | number ; ledgerCompatible : boolean ; constructor ( value , ledgerCompatible = true ) { const bi = new BigNumber ( value ) ; if ( ! bi . isInteger ( ) ) { throw new Error ( String ( ERROR_CODE . INVALID_PARAMS ) ) ; } this . value = value ; this . ledgerCompatible = ledgerCompatible ; } /**
     * Create hex string from BigInt
     */ toHexstr ( ) { let hex = bigIntToBytes ( this . value ) ; if ( this . ledgerCompatible && ( hex . length % 2 !== 0 || hex . length < 16 ) ) { hex = hex + '0' . repeat ( SIZE * 2 - hex . length ) ; } return hex ; } }