import bcrypt from 'bcryptjs' ; export interface AccessTokenManager { createToken ( ) : Promise < { plainTextToken : string ; hashedToken : string ; } > ; validateToken ( params ) : Promise < boolean > ; } export class DevelopmentAccessTokenManager implements AccessTokenManager { constructor ( private options ) { } async createToken ( ) { const token = this . options . tokenGenerator ( ) ; return { plainTextToken : token , hashedToken : token } ; } async validateToken ( params ) { return params . providedToken === params . actualHash ; } } export class BcryptAccessTokenManager { constructor ( private options ) { } async createToken ( ) { const token = await this . options . tokenGenerator ( ) ; const hashedToken = await bcrypt . hash ( token , 10 ) ; return { plainTextToken : token , hashedToken } ; } async validateToken ( params ) { return bcrypt . compare ( params . providedToken , params . actualHash ) ; } }