mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 23:03:32 +00:00
breach report audit api
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { AuditService as AuditServiceAbstraction } from '../abstractions/audit.service';
|
||||
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
|
||||
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
|
||||
|
||||
const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/';
|
||||
const HibpBreachApi = 'https://haveibeenpwned.com/api/v2/breachedaccount/';
|
||||
|
||||
export class AuditService implements AuditServiceAbstraction {
|
||||
constructor(private cryptoFunctionService: CryptoFunctionService) { }
|
||||
@@ -21,4 +25,15 @@ export class AuditService implements AuditServiceAbstraction {
|
||||
|
||||
return match != null ? parseInt(match.split(':')[1], 10) : 0;
|
||||
}
|
||||
|
||||
async breachedAccounts(email: string): Promise<BreachAccountResponse[]> {
|
||||
const response = await fetch(HibpBreachApi + email);
|
||||
if (response.status === 404) {
|
||||
return [];
|
||||
} else if (response.status !== 200) {
|
||||
throw new Error();
|
||||
}
|
||||
const responseJson = await response.json();
|
||||
return responseJson.map((a) => new BreachAccountResponse(a));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user