import * as bcryptjs from 'bcryptjs' ; import { randomBytes } from 'crypto' ; export const SecurityUtils = { hashWithBcrypt : async ( str , saltRounds ) => { const salt = await bcryptjs . genSalt ( saltRounds ) ; return bcryptjs . hash ( str , salt ) ; } , bcryptHashIsValid : async ( value , hash ) => bcryptjs . compare ( value , hash ) , generateRandomString : ( chars ) : string => { const buffer = randomBytes ( ( chars + 1 ) / 2 ) ; return buffer . toString ( 'hex' ) . substr ( 0 , chars ) ; } , } ;