import { Md5 } from 'ts-md5' ; import { ethers } from 'ethers' ; import { HashAlgorithm , HashFunction } from '../types' ; import { add0x , remove0x } from './misc' ; param preimage returns export const Md5Hash = ( preimage ) : string => { return Md5 . hashStr ( preimage ) . toString ( ) ; } ; param value returns export const keccak256 = ( value ) : string => { const preimage = add0x ( value ) ; return remove0x ( ethers . utils . keccak256 ( preimage ) ) ; } ; param algo returns export const hashFunctionFor = ( algo ) : HashFunction => { switch ( algo ) { case HashAlgorithm . MD5 : return Md5Hash ; case HashAlgorithm . KECCAK256 : return keccak256 ; default : throw Error ( `HashAlgorithm ${ algo } not supported.` ) ; } } ;