import bcrypt from './bcrypt/bcrypt' ; import ISecurityOptions from '../ISecurityOptions' ; import IHashMethod from './IHashMethod' ; export interface IHashProviderMap { [ s ] : ( options ? : object ) => IHashMethod ; } const availableMethod = { bcrypt , } ; param { IHashMethod | string } hashMethod returns { boolean } function isHashMethod ( hashMethod ) { return ( ( hashMethod as IHashMethod ) . compare !== undefined && ( hashMethod as IHashMethod ) . hash !== undefined ) ; } param config param methods export default function hashMethodProvider ( config , methods ? ) { const allMethods = { ... availableMethod , ... methods } ; if ( config . hash ) { const { method , options } = config . hash ; if ( typeof method === 'string' && allMethods [ method ] ) { return allMethods [ method ] ( options ) ; } if ( isHashMethod ( method ) ) { return { hash : ( password , salt ? ) => method . hash ( password , salt , options ) , compare : ( userPassword , hashedPassword , salt ? ) => method . compare ( userPassword , hashedPassword , salt , options ) , } ; } } return allMethods . bcrypt ( ) ; }