2023-01-18 09:40:15 -05:00
|
|
|
import { ICryptoRepository } from '@app/domain';
|
2023-01-23 23:13:42 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { JwtService, JwtVerifyOptions } from '@nestjs/jwt';
|
2023-01-18 09:40:15 -05:00
|
|
|
import { compareSync, hash } from 'bcrypt';
|
|
|
|
import { randomBytes } from 'crypto';
|
|
|
|
|
2023-01-23 23:13:42 -05:00
|
|
|
@Injectable()
|
|
|
|
export class CryptoRepository implements ICryptoRepository {
|
|
|
|
constructor(private jwtService: JwtService) {}
|
|
|
|
|
|
|
|
randomBytes = randomBytes;
|
|
|
|
hash = hash;
|
|
|
|
compareSync = compareSync;
|
|
|
|
|
|
|
|
signJwt(payload: string | Buffer | object) {
|
|
|
|
return this.jwtService.sign(payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyJwtAsync<T extends object = any>(token: string, options?: JwtVerifyOptions): Promise<T> {
|
|
|
|
return this.jwtService.verifyAsync(token, options);
|
|
|
|
}
|
|
|
|
}
|