import BN from 'bn.js' ; import crypto from 'crypto' ; export const safeRandomNumber = ( ) : number => { const randomUnboundBN = new BN ( crypto . randomBytes ( 8 ) ) ; const bnBound = new BN ( Number . MAX_SAFE_INTEGER ) ; const randomNumberBN = randomUnboundBN . mod ( bnBound ) ; const randomNumber = randomNumberBN . toNumber ( ) ; const randomBoolean = Math . random ( ) <= 0.5 ; const randomPosOrNegNum = randomNumber * ( randomBoolean ? 1 : - 1 ) ; const boundNum = Math . min ( Math . max ( Number . MIN_SAFE_INTEGER , randomPosOrNegNum ) , Number . MAX_SAFE_INTEGER ) ; return boundNum ; } ; export const createNonce = ( ) : number => { return safeRandomNumber ( ) ; } ;