import { BN } from 'bn.js' ; export const squareRootBN = ( n , closeness = new BN ( 1 ) ) => { let x = n ; let root ; let count = 0 ; const TWO = new BN ( 2 ) ; while ( count < Number . MAX_SAFE_INTEGER ) { count ++ ; root = x . add ( n . div ( x ) ) . div ( TWO ) ; if ( x . sub ( root ) . abs ( ) . lte ( closeness ) ) break ; x = root ; } return root ; } ;