1
0
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:
Kyle Spearrin
2018-06-28 11:57:29 -04:00
parent 569ad25208
commit a097ef9bea
3 changed files with 47 additions and 0 deletions

View File

@@ -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));
}
}