hibp 0.0.0-dev.8859c6fb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +508 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +22 -0
- package/MIGRATION.md +227 -0
- package/README.md +255 -0
- package/dist/browser/hibp.module.js +2 -0
- package/dist/browser/hibp.module.js.map +1 -0
- package/dist/browser/hibp.umd.js +2 -0
- package/dist/browser/hibp.umd.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/fetchFromApi.js +107 -0
- package/dist/cjs/api/haveibeenpwned/fetchFromApi.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/index.js +6 -0
- package/dist/cjs/api/haveibeenpwned/index.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/responses.js +79 -0
- package/dist/cjs/api/haveibeenpwned/responses.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/fetchFromApi.js +44 -0
- package/dist/cjs/api/pwnedpasswords/fetchFromApi.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/index.js +5 -0
- package/dist/cjs/api/pwnedpasswords/index.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/responses.js +20 -0
- package/dist/cjs/api/pwnedpasswords/responses.js.map +1 -0
- package/dist/cjs/breach.js +55 -0
- package/dist/cjs/breach.js.map +1 -0
- package/dist/cjs/breachedAccount.js +101 -0
- package/dist/cjs/breachedAccount.js.map +1 -0
- package/dist/cjs/breaches.js +55 -0
- package/dist/cjs/breaches.js.map +1 -0
- package/dist/cjs/dataClasses.js +34 -0
- package/dist/cjs/dataClasses.js.map +1 -0
- package/dist/cjs/hibp.js +21 -0
- package/dist/cjs/hibp.js.map +1 -0
- package/dist/cjs/maybe-fetch.js +12 -0
- package/dist/cjs/maybe-fetch.js.map +1 -0
- package/dist/cjs/package.json.js +7 -0
- package/dist/cjs/package.json.js.map +1 -0
- package/dist/cjs/pasteAccount.js +59 -0
- package/dist/cjs/pasteAccount.js.map +1 -0
- package/dist/cjs/pwnedPassword.js +45 -0
- package/dist/cjs/pwnedPassword.js.map +1 -0
- package/dist/cjs/pwnedPasswordRange.js +63 -0
- package/dist/cjs/pwnedPasswordRange.js.map +1 -0
- package/dist/cjs/search.js +97 -0
- package/dist/cjs/search.js.map +1 -0
- package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs +104 -0
- package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs.map +1 -0
- package/dist/esm/api/haveibeenpwned/index.mjs +2 -0
- package/dist/esm/api/haveibeenpwned/index.mjs.map +1 -0
- package/dist/esm/api/haveibeenpwned/responses.mjs +71 -0
- package/dist/esm/api/haveibeenpwned/responses.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs +42 -0
- package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/index.mjs +2 -0
- package/dist/esm/api/pwnedpasswords/index.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/responses.mjs +17 -0
- package/dist/esm/api/pwnedpasswords/responses.mjs.map +1 -0
- package/dist/esm/breach.mjs +53 -0
- package/dist/esm/breach.mjs.map +1 -0
- package/dist/esm/breachedAccount.mjs +99 -0
- package/dist/esm/breachedAccount.mjs.map +1 -0
- package/dist/esm/breaches.mjs +53 -0
- package/dist/esm/breaches.mjs.map +1 -0
- package/dist/esm/dataClasses.mjs +32 -0
- package/dist/esm/dataClasses.mjs.map +1 -0
- package/dist/esm/hibp.mjs +10 -0
- package/dist/esm/hibp.mjs.map +1 -0
- package/dist/esm/maybe-fetch.mjs +8 -0
- package/dist/esm/maybe-fetch.mjs.map +1 -0
- package/dist/esm/package.json.mjs +4 -0
- package/dist/esm/package.json.mjs.map +1 -0
- package/dist/esm/pasteAccount.mjs +57 -0
- package/dist/esm/pasteAccount.mjs.map +1 -0
- package/dist/esm/pwnedPassword.mjs +43 -0
- package/dist/esm/pwnedPassword.mjs.map +1 -0
- package/dist/esm/pwnedPasswordRange.mjs +61 -0
- package/dist/esm/pwnedPasswordRange.mjs.map +1 -0
- package/dist/esm/search.mjs +95 -0
- package/dist/esm/search.mjs.map +1 -0
- package/dist/hibp.d.ts +502 -0
- package/example/runkit.js +16 -0
- package/package.json +138 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Known potential responses from the remote API.
|
|
5
|
+
*
|
|
6
|
+
* https://haveibeenpwned.com/api/v3#PwnedPasswords
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
/** @internal */
|
|
10
|
+
const OK = {
|
|
11
|
+
status: 200
|
|
12
|
+
};
|
|
13
|
+
/** @internal */
|
|
14
|
+
const BAD_REQUEST = {
|
|
15
|
+
status: 400,
|
|
16
|
+
body: 'The hash prefix was not in a valid format'
|
|
17
|
+
};
|
|
18
|
+
exports.BAD_REQUEST = BAD_REQUEST;
|
|
19
|
+
exports.OK = OK;
|
|
20
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sources":["../../../../src/api/pwnedpasswords/responses.ts"],"sourcesContent":["/**\n * Known potential responses from the remote API.\n *\n * https://haveibeenpwned.com/api/v3#PwnedPasswords\n *\n */\n\n/** @internal */\nexport interface PwnedPasswordsApiResponse {\n status: number;\n body?: string;\n}\n\n/** @internal */\nexport const OK: PwnedPasswordsApiResponse = {\n status: 200,\n};\n\n/** @internal */\nexport const BAD_REQUEST: PwnedPasswordsApiResponse = {\n status: 400,\n body: 'The hash prefix was not in a valid format',\n};\n"],"names":["OK","status","BAD_REQUEST","body"],"mappings":";;AAAA;;;;;AAKG;AAQH;AACa,MAAAA,EAAE,GAA8B;EAC3CC,MAAM,EAAE;CACR;AAEF;AACa,MAAAC,WAAW,GAA8B;EACpDD,MAAM,EAAE,GAAG;EACXE,IAAI,EAAE;;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object representing a breach.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {object} Breach
|
|
9
|
+
* @property {string} Name
|
|
10
|
+
* @property {string} Title
|
|
11
|
+
* @property {string} Domain
|
|
12
|
+
* @property {string} BreachDate
|
|
13
|
+
* @property {string} AddedDate
|
|
14
|
+
* @property {string} ModifiedDate
|
|
15
|
+
* @property {number} PwnCount
|
|
16
|
+
* @property {string} Description
|
|
17
|
+
* @property {string} LogoPath
|
|
18
|
+
* @property {string[]} DataClasses
|
|
19
|
+
* @property {boolean} IsVerified
|
|
20
|
+
* @property {boolean} IsFabricated
|
|
21
|
+
* @property {boolean} IsSensitive
|
|
22
|
+
* @property {boolean} IsRetired
|
|
23
|
+
* @property {boolean} IsSpamList
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Fetches data for a specific breach event.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} breachName the name of a breach in the system
|
|
29
|
+
* @param {object} [options] a configuration object
|
|
30
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
31
|
+
* haveibeenpwned.com API endpoints (default:
|
|
32
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
33
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
34
|
+
* field in the request headers (default: `hibp <version>`)
|
|
35
|
+
* @returns {(Promise<Breach>|Promise<null>)} a Promise which resolves to an
|
|
36
|
+
* object representing a breach (or null if no breach was found), or rejects
|
|
37
|
+
* with an Error
|
|
38
|
+
* @example
|
|
39
|
+
* breach('Adobe')
|
|
40
|
+
* .then(data => {
|
|
41
|
+
* if (data) {
|
|
42
|
+
* // ...
|
|
43
|
+
* } else {
|
|
44
|
+
* // ...
|
|
45
|
+
* }
|
|
46
|
+
* })
|
|
47
|
+
* .catch(err => {
|
|
48
|
+
* // ...
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
function breach(breachName, options = {}) {
|
|
52
|
+
return fetchFromApi.fetchFromApi(`/breach/${encodeURIComponent(breachName)}`, options);
|
|
53
|
+
}
|
|
54
|
+
exports.breach = breach;
|
|
55
|
+
//# sourceMappingURL=breach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breach.js","sources":["../../src/breach.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * An object representing a breach.\n *\n * @typedef {object} Breach\n * @property {string} Name\n * @property {string} Title\n * @property {string} Domain\n * @property {string} BreachDate\n * @property {string} AddedDate\n * @property {string} ModifiedDate\n * @property {number} PwnCount\n * @property {string} Description\n * @property {string} LogoPath\n * @property {string[]} DataClasses\n * @property {boolean} IsVerified\n * @property {boolean} IsFabricated\n * @property {boolean} IsSensitive\n * @property {boolean} IsRetired\n * @property {boolean} IsSpamList\n */\n\n/**\n * Fetches data for a specific breach event.\n *\n * @param {string} breachName the name of a breach in the system\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<Breach>|Promise<null>)} a Promise which resolves to an\n * object representing a breach (or null if no breach was found), or rejects\n * with an Error\n * @example\n * breach('Adobe')\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breach(\n breachName: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<Breach | null> {\n return fetchFromApi(\n `/breach/${encodeURIComponent(breachName)}`,\n options,\n ) as Promise<Breach | null>;\n}\n"],"names":["breach","breachName","options","fetchFromApi","encodeURIComponent"],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;AAmBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;SACaA,MAAM,CACpBC,UAAkB,EAClBC,UAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAAA,CAAAA,YAAY,CACjB,WAAWC,kBAAkB,CAACH,UAAU,CAAG,EAAA,EAC3CC,OAAO,CACkB;AAC7B;"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches breach data for a specific account.
|
|
7
|
+
*
|
|
8
|
+
* ***Warning (July 18, 2019):***
|
|
9
|
+
*
|
|
10
|
+
* `haveibeenpwned.com` now requires an API key from
|
|
11
|
+
* https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
|
|
12
|
+
* `apiKey` option here is not explicitly required, but direct requests made
|
|
13
|
+
* without it (that is, without specifying a `baseUrl` to a proxy that inserts a
|
|
14
|
+
* valid API key on your behalf) will fail.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} account a username or email address
|
|
17
|
+
* @param {object} [options] a configuration object
|
|
18
|
+
* @param {string} [options.apiKey] an API key from
|
|
19
|
+
* https://haveibeenpwned.com/API/Key (default: undefined)
|
|
20
|
+
* @param {string} [options.domain] a domain by which to filter the results
|
|
21
|
+
* (default: all domains)
|
|
22
|
+
* @param {boolean} [options.includeUnverified] include "unverified" breaches in
|
|
23
|
+
* the results (default: true)
|
|
24
|
+
* @param {boolean} [options.truncate] truncate the results to only include
|
|
25
|
+
* the name of each breach (default: true)
|
|
26
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
27
|
+
* haveibeenpwned.com API endpoints (default:
|
|
28
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
29
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
30
|
+
* field in the request headers (default: `hibp <version>`)
|
|
31
|
+
* @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
|
|
32
|
+
* array of breach objects (or null if no breaches were found), or rejects with
|
|
33
|
+
* an Error
|
|
34
|
+
* @example
|
|
35
|
+
* breachedAccount('foo', { apiKey: 'my-api-key' })
|
|
36
|
+
* .then(data => {
|
|
37
|
+
* if (data) {
|
|
38
|
+
* // ...
|
|
39
|
+
* } else {
|
|
40
|
+
* // ...
|
|
41
|
+
* }
|
|
42
|
+
* })
|
|
43
|
+
* .catch(err => {
|
|
44
|
+
* // ...
|
|
45
|
+
* });
|
|
46
|
+
* @example
|
|
47
|
+
* breachedAccount('bar', {
|
|
48
|
+
* includeUnverified: false,
|
|
49
|
+
* baseUrl: 'https://my-hibp-proxy:8080',
|
|
50
|
+
* })
|
|
51
|
+
* .then(data => {
|
|
52
|
+
* if (data) {
|
|
53
|
+
* // ...
|
|
54
|
+
* } else {
|
|
55
|
+
* // ...
|
|
56
|
+
* }
|
|
57
|
+
* })
|
|
58
|
+
* .catch(err => {
|
|
59
|
+
* // ...
|
|
60
|
+
* });
|
|
61
|
+
* @example
|
|
62
|
+
* breachedAccount('baz', {
|
|
63
|
+
* apiKey: 'my-api-key',
|
|
64
|
+
* domain: 'adobe.com',
|
|
65
|
+
* truncate: false,
|
|
66
|
+
* userAgent: 'my-app 1.0'
|
|
67
|
+
* })
|
|
68
|
+
* .then(data => {
|
|
69
|
+
* if (data) {
|
|
70
|
+
* // ...
|
|
71
|
+
* } else {
|
|
72
|
+
* // ...
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* .catch(err => {
|
|
76
|
+
* // ...
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
79
|
+
function breachedAccount(account, options = {
|
|
80
|
+
includeUnverified: true,
|
|
81
|
+
truncate: true
|
|
82
|
+
}) {
|
|
83
|
+
const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;
|
|
84
|
+
const params = [];
|
|
85
|
+
if (options.domain) {
|
|
86
|
+
params.push(`domain=${encodeURIComponent(options.domain)}`);
|
|
87
|
+
}
|
|
88
|
+
if (options.includeUnverified === false) {
|
|
89
|
+
params.push('includeUnverified=false');
|
|
90
|
+
}
|
|
91
|
+
if (options.truncate === false) {
|
|
92
|
+
params.push('truncateResponse=false');
|
|
93
|
+
}
|
|
94
|
+
return fetchFromApi.fetchFromApi(`${endpoint}${params.join('&')}`, {
|
|
95
|
+
apiKey: options.apiKey,
|
|
96
|
+
baseUrl: options.baseUrl,
|
|
97
|
+
userAgent: options.userAgent
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.breachedAccount = breachedAccount;
|
|
101
|
+
//# sourceMappingURL=breachedAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breachedAccount.js","sources":["../../src/breachedAccount.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches breach data for a specific account.\n *\n * ***Warning (July 18, 2019):***\n *\n * `haveibeenpwned.com` now requires an API key from\n * https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The\n * `apiKey` option here is not explicitly required, but direct requests made\n * without it (that is, without specifying a `baseUrl` to a proxy that inserts a\n * valid API key on your behalf) will fail.\n *\n * @param {string} account a username or email address\n * @param {object} [options] a configuration object\n * @param {string} [options.apiKey] an API key from\n * https://haveibeenpwned.com/API/Key (default: undefined)\n * @param {string} [options.domain] a domain by which to filter the results\n * (default: all domains)\n * @param {boolean} [options.includeUnverified] include \"unverified\" breaches in\n * the results (default: true)\n * @param {boolean} [options.truncate] truncate the results to only include\n * the name of each breach (default: true)\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an\n * array of breach objects (or null if no breaches were found), or rejects with\n * an Error\n * @example\n * breachedAccount('foo', { apiKey: 'my-api-key' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breachedAccount('bar', {\n * includeUnverified: false,\n * baseUrl: 'https://my-hibp-proxy:8080',\n * })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breachedAccount('baz', {\n * apiKey: 'my-api-key',\n * domain: 'adobe.com',\n * truncate: false,\n * userAgent: 'my-app 1.0'\n * })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breachedAccount(\n account: string,\n options: {\n apiKey?: string;\n domain?: string;\n includeUnverified?: boolean;\n truncate?: boolean;\n baseUrl?: string;\n userAgent?: string;\n } = {\n includeUnverified: true,\n truncate: true,\n },\n): Promise<Breach[] | null> {\n const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;\n const params: Array<string> = [];\n if (options.domain) {\n params.push(`domain=${encodeURIComponent(options.domain)}`);\n }\n if (options.includeUnverified === false) {\n params.push('includeUnverified=false');\n }\n if (options.truncate === false) {\n params.push('truncateResponse=false');\n }\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Breach[] | null>;\n}\n"],"names":["breachedAccount","account","options","includeUnverified","truncate","endpoint","encodeURIComponent","params","domain","push","fetchFromApi","join","apiKey","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEG;AACa,SAAAA,eAAe,CAC7BC,OAAe,EACfC,OAOI,GAAA;EACFC,iBAAiB,EAAE,IAAI;EACvBC,QAAQ,EAAE;AACX,CAAA,EAAA;EAED,MAAMC,QAAQ,GAAuB,oBAAAC,kBAAkB,CAACL,OAAO,IAAI;EACnE,MAAMM,MAAM,GAAkB,EAAE;EAChC,IAAIL,OAAO,CAACM,MAAM,EAAE;IAClBD,MAAM,CAACE,IAAI,CAAC,UAAUH,kBAAkB,CAACJ,OAAO,CAACM,MAAM,CAAG,EAAA,CAAC;EAC5D;EACD,IAAIN,OAAO,CAACC,iBAAiB,KAAK,KAAK,EAAE;IACvCI,MAAM,CAACE,IAAI,CAAC,yBAAyB,CAAC;EACvC;EACD,IAAIP,OAAO,CAACE,QAAQ,KAAK,KAAK,EAAE;IAC9BG,MAAM,CAACE,IAAI,CAAC,wBAAwB,CAAC;EACtC;EACD,OAAOC,YAAY,CAAAA,YAAA,CAAI,GAAAL,QAAW,GAAAE,MAAM,CAACI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDC,MAAM,EAAEV,OAAO,CAACU,MAAM;IACtBC,OAAO,EAAEX,OAAO,CAACW,OAAO;IACxBC,SAAS,EAAEZ,OAAO,CAACY;EACpB,CAAA,CAA6B;AAChC;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches all breach events in the system.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} [options] a configuration object
|
|
9
|
+
* @param {string} [options.domain] a domain by which to filter the results
|
|
10
|
+
* (default: all domains)
|
|
11
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
12
|
+
* haveibeenpwned.com API endpoints (default:
|
|
13
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
14
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
15
|
+
* field in the request headers (default: `hibp <version>`)
|
|
16
|
+
* @returns {Promise<Breach[]>} a Promise which resolves to an array of breach
|
|
17
|
+
* objects (an empty array if no breaches were found), or rejects with an Error
|
|
18
|
+
* @example
|
|
19
|
+
* breaches()
|
|
20
|
+
* .then(data => {
|
|
21
|
+
* if (data) {
|
|
22
|
+
* // ...
|
|
23
|
+
* } else {
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* })
|
|
27
|
+
* .catch(err => {
|
|
28
|
+
* // ...
|
|
29
|
+
* });
|
|
30
|
+
* @example
|
|
31
|
+
* breaches({ domain: 'adobe.com' })
|
|
32
|
+
* .then(data => {
|
|
33
|
+
* if (data) {
|
|
34
|
+
* // ...
|
|
35
|
+
* } else {
|
|
36
|
+
* // ...
|
|
37
|
+
* }
|
|
38
|
+
* })
|
|
39
|
+
* .catch(err => {
|
|
40
|
+
* // ...
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
function breaches(options = {}) {
|
|
44
|
+
const endpoint = '/breaches?';
|
|
45
|
+
const params = [];
|
|
46
|
+
if (options.domain) {
|
|
47
|
+
params.push(`domain=${encodeURIComponent(options.domain)}`);
|
|
48
|
+
}
|
|
49
|
+
return fetchFromApi.fetchFromApi(`${endpoint}${params.join('&')}`, {
|
|
50
|
+
baseUrl: options.baseUrl,
|
|
51
|
+
userAgent: options.userAgent
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.breaches = breaches;
|
|
55
|
+
//# sourceMappingURL=breaches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breaches.js","sources":["../../src/breaches.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches all breach events in the system.\n *\n * @param {object} [options] a configuration object\n * @param {string} [options.domain] a domain by which to filter the results\n * (default: all domains)\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<Breach[]>} a Promise which resolves to an array of breach\n * objects (an empty array if no breaches were found), or rejects with an Error\n * @example\n * breaches()\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breaches({ domain: 'adobe.com' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breaches(\n options: {\n domain?: string;\n baseUrl?: string;\n userAgent?: string;\n } = {},\n): Promise<Breach[]> {\n const endpoint = '/breaches?';\n const params: Array<string> = [];\n if (options.domain) {\n params.push(`domain=${encodeURIComponent(options.domain)}`);\n }\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Breach[]>;\n}\n"],"names":["breaches","options","endpoint","params","domain","push","encodeURIComponent","fetchFromApi","join","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AACa,SAAAA,QAAQ,CACtBC,OAAA,GAII,EAAE,EAAA;EAEN,MAAMC,QAAQ,GAAG,YAAY;EAC7B,MAAMC,MAAM,GAAkB,EAAE;EAChC,IAAIF,OAAO,CAACG,MAAM,EAAE;IAClBD,MAAM,CAACE,IAAI,CAAC,UAAUC,kBAAkB,CAACL,OAAO,CAACG,MAAM,CAAG,EAAA,CAAC;EAC5D;EACD,OAAOG,YAAY,CAAAA,YAAA,CAAI,GAAAL,QAAW,GAAAC,MAAM,CAACK,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDC,OAAO,EAAER,OAAO,CAACQ,OAAO;IACxBC,SAAS,EAAET,OAAO,CAACS;EACpB,CAAA,CAAsB;AACzB;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches all data classes in the system.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} [options] a configuration object
|
|
9
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
10
|
+
* haveibeenpwned.com API endpoints (default:
|
|
11
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
12
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
13
|
+
* field in the request headers (default: `hibp <version>`)
|
|
14
|
+
* @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an
|
|
15
|
+
* array of strings (or null if no data classes were found), or rejects with an
|
|
16
|
+
* Error
|
|
17
|
+
* @example
|
|
18
|
+
* dataClasses()
|
|
19
|
+
* .then(data => {
|
|
20
|
+
* if (data) {
|
|
21
|
+
* // ...
|
|
22
|
+
* } else {
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
* .catch(err => {
|
|
27
|
+
* // ...
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
function dataClasses(options = {}) {
|
|
31
|
+
return fetchFromApi.fetchFromApi('/dataclasses', options);
|
|
32
|
+
}
|
|
33
|
+
exports.dataClasses = dataClasses;
|
|
34
|
+
//# sourceMappingURL=dataClasses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataClasses.js","sources":["../../src/dataClasses.ts"],"sourcesContent":["import { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches all data classes in the system.\n *\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an\n * array of strings (or null if no data classes were found), or rejects with an\n * Error\n * @example\n * dataClasses()\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function dataClasses(\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<string[] | null> {\n return fetchFromApi('/dataclasses', options) as Promise<string[] | null>;\n}\n"],"names":["dataClasses","options","fetchFromApi"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACa,SAAAA,WAAW,CACzBC,OAAA,GAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAY,CAAAA,YAAA,CAAC,cAAc,EAAED,OAAO,CAA6B;AAC1E;"}
|
package/dist/cjs/hibp.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var breach = /*#__PURE__*/require('./breach.js');
|
|
4
|
+
var breachedAccount = /*#__PURE__*/require('./breachedAccount.js');
|
|
5
|
+
var breaches = /*#__PURE__*/require('./breaches.js');
|
|
6
|
+
var dataClasses = /*#__PURE__*/require('./dataClasses.js');
|
|
7
|
+
var pasteAccount = /*#__PURE__*/require('./pasteAccount.js');
|
|
8
|
+
var pwnedPassword = /*#__PURE__*/require('./pwnedPassword.js');
|
|
9
|
+
var pwnedPasswordRange = /*#__PURE__*/require('./pwnedPasswordRange.js');
|
|
10
|
+
var search = /*#__PURE__*/require('./search.js');
|
|
11
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
12
|
+
exports.breach = breach.breach;
|
|
13
|
+
exports.breachedAccount = breachedAccount.breachedAccount;
|
|
14
|
+
exports.breaches = breaches.breaches;
|
|
15
|
+
exports.dataClasses = dataClasses.dataClasses;
|
|
16
|
+
exports.pasteAccount = pasteAccount.pasteAccount;
|
|
17
|
+
exports.pwnedPassword = pwnedPassword.pwnedPassword;
|
|
18
|
+
exports.pwnedPasswordRange = pwnedPasswordRange.pwnedPasswordRange;
|
|
19
|
+
exports.search = search.search;
|
|
20
|
+
exports.RateLimitError = fetchFromApi.RateLimitError;
|
|
21
|
+
//# sourceMappingURL=hibp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hibp.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
5
|
+
var fetch = typeof window !== 'undefined' ? window.fetch : webFetchWrapper;
|
|
6
|
+
function webFetchWrapper(input, init) {
|
|
7
|
+
return Promise.resolve().then(() => _interopRequireWildcard(require('@remix-run/web-fetch'))).then(({
|
|
8
|
+
default: webFetch
|
|
9
|
+
}) => webFetch(input, init));
|
|
10
|
+
}
|
|
11
|
+
module.exports = fetch;
|
|
12
|
+
//# sourceMappingURL=maybe-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maybe-fetch.js","sources":["../../src/maybe-fetch.ts"],"sourcesContent":["export default typeof window !== 'undefined' ? window.fetch : webFetchWrapper;\n\nfunction webFetchWrapper(\n input: string | URL,\n init?: RequestInit | undefined,\n): Promise<Response> {\n return import('@remix-run/web-fetch').then(({ default: webFetch }) =>\n webFetch(input, init),\n );\n}\n"],"names":["fetch","window","webFetchWrapper","input","init","then","default","webFetch"],"mappings":";;;;AAAA,IAAeA,KAAA,GAAA,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,CAACD,KAAK,GAAGE,eAAe;AAE7E,SAASA,eAAe,CACtBC,KAAmB,EACnBC,IAA8B,EAAA;EAE9B,OAAO,6DAAO,sBAAsB,IAAEC,IAAI,CAAC,CAAC;IAAEC,OAAO,EAAEC;EAAQ,CAAE,KAC/DA,QAAQ,CAACJ,KAAK,EAAEC,IAAI,CAAC,CACtB;AACH;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object representing a paste.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {object} Paste
|
|
9
|
+
* @property {string} Id
|
|
10
|
+
* @property {string} Source
|
|
11
|
+
* @property {string} Title
|
|
12
|
+
* @property {string} Date
|
|
13
|
+
* @property {number} EmailCount
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Fetches paste data for a specific account (email address).
|
|
17
|
+
*
|
|
18
|
+
* ***Warning (July 18, 2019):***
|
|
19
|
+
*
|
|
20
|
+
* `haveibeenpwned.com` now requires an API key from
|
|
21
|
+
* https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The
|
|
22
|
+
* `apiKey` option here is not explicitly required, but direct requests made
|
|
23
|
+
* without it (that is, without specifying a `baseUrl` to a proxy that inserts a
|
|
24
|
+
* valid API key on your behalf) will fail.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} email the email address to query
|
|
27
|
+
* @param {object} [options] a configuration object
|
|
28
|
+
* @param {string} [options.apiKey] an API key from
|
|
29
|
+
* https://haveibeenpwned.com/API/Key
|
|
30
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
31
|
+
* haveibeenpwned.com API endpoints (default:
|
|
32
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
33
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
34
|
+
* field in the request headers (default: `hibp <version>`)
|
|
35
|
+
* @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an
|
|
36
|
+
* array of paste objects (or null if no pastes were found), or rejects with an
|
|
37
|
+
* Error
|
|
38
|
+
* @example
|
|
39
|
+
* pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })
|
|
40
|
+
* .then(data => {
|
|
41
|
+
* if (data) {
|
|
42
|
+
* // ...
|
|
43
|
+
* } else {
|
|
44
|
+
* // ...
|
|
45
|
+
* }
|
|
46
|
+
* })
|
|
47
|
+
* .catch(err => {
|
|
48
|
+
* // ...
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
function pasteAccount(email, options = {}) {
|
|
52
|
+
return fetchFromApi.fetchFromApi(`/pasteaccount/${encodeURIComponent(email)}`, {
|
|
53
|
+
apiKey: options.apiKey,
|
|
54
|
+
baseUrl: options.baseUrl,
|
|
55
|
+
userAgent: options.userAgent
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.pasteAccount = pasteAccount;
|
|
59
|
+
//# sourceMappingURL=pasteAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pasteAccount.js","sources":["../../src/pasteAccount.ts"],"sourcesContent":["import type { Paste } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * An object representing a paste.\n *\n * @typedef {object} Paste\n * @property {string} Id\n * @property {string} Source\n * @property {string} Title\n * @property {string} Date\n * @property {number} EmailCount\n */\n\n/**\n * Fetches paste data for a specific account (email address).\n *\n * ***Warning (July 18, 2019):***\n *\n * `haveibeenpwned.com` now requires an API key from\n * https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The\n * `apiKey` option here is not explicitly required, but direct requests made\n * without it (that is, without specifying a `baseUrl` to a proxy that inserts a\n * valid API key on your behalf) will fail.\n *\n * @param {string} email the email address to query\n * @param {object} [options] a configuration object\n * @param {string} [options.apiKey] an API key from\n * https://haveibeenpwned.com/API/Key\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an\n * array of paste objects (or null if no pastes were found), or rejects with an\n * Error\n * @example\n * pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function pasteAccount(\n email: string,\n options: { apiKey?: string; baseUrl?: string; userAgent?: string } = {},\n): Promise<Paste[] | null> {\n return fetchFromApi(`/pasteaccount/${encodeURIComponent(email)}`, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Paste[] | null>;\n}\n"],"names":["pasteAccount","email","options","fetchFromApi","encodeURIComponent","apiKey","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;AASG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;SACaA,YAAY,CAC1BC,KAAa,EACbC,UAAqE,EAAE,EAAA;EAEvE,OAAOC,YAAAA,CAAAA,YAAY,CAAkB,iBAAAC,kBAAkB,CAACH,KAAK,GAAG,EAAE;IAChEI,MAAM,EAAEH,OAAO,CAACG,MAAM;IACtBC,OAAO,EAAEJ,OAAO,CAACI,OAAO;IACxBC,SAAS,EAAEL,OAAO,CAACK;EACpB,CAAA,CAA4B;AAC/B;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var JSSHA = /*#__PURE__*/require('jssha/dist/sha1');
|
|
4
|
+
var pwnedPasswordRange = /*#__PURE__*/require('./pwnedPasswordRange.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the number of times the the given password has been exposed in a
|
|
8
|
+
* breach (0 indicating no exposure). The password is given in plain text, but
|
|
9
|
+
* only the first 5 characters of its SHA-1 hash will be submitted to the API.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} password a password in plain text
|
|
12
|
+
* @param {object} [options] a configuration object
|
|
13
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
14
|
+
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
|
|
15
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
16
|
+
* field in the request headers (default: `hibp <version>`)
|
|
17
|
+
* @returns {Promise<number>} a Promise which resolves to the number of times
|
|
18
|
+
* the password has been exposed in a breach, or rejects with an Error
|
|
19
|
+
* @example
|
|
20
|
+
* pwnedPassword('f00b4r')
|
|
21
|
+
* .then(numPwns => {
|
|
22
|
+
* // truthy check or numeric condition
|
|
23
|
+
* if (numPwns) {
|
|
24
|
+
* // ...
|
|
25
|
+
* } else {
|
|
26
|
+
* // ...
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* .catch(err => {
|
|
30
|
+
* // ...
|
|
31
|
+
* });
|
|
32
|
+
* @see https://haveibeenpwned.com/api/v3#PwnedPasswords
|
|
33
|
+
*/
|
|
34
|
+
function pwnedPassword(password, options = {}) {
|
|
35
|
+
const sha1 = new JSSHA('SHA-1', 'TEXT');
|
|
36
|
+
sha1.update(password);
|
|
37
|
+
const hash = sha1.getHash('HEX', {
|
|
38
|
+
outputUpper: true
|
|
39
|
+
});
|
|
40
|
+
const prefix = hash.slice(0, 5);
|
|
41
|
+
const suffix = hash.slice(5);
|
|
42
|
+
return pwnedPasswordRange.pwnedPasswordRange(prefix, options).then(range => range[suffix] || 0);
|
|
43
|
+
}
|
|
44
|
+
exports.pwnedPassword = pwnedPassword;
|
|
45
|
+
//# sourceMappingURL=pwnedPassword.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pwnedPassword.js","sources":["../../src/pwnedPassword.ts"],"sourcesContent":["import JSSHA from 'jssha/dist/sha1';\nimport { pwnedPasswordRange } from './pwnedPasswordRange';\n\n/**\n * Fetches the number of times the the given password has been exposed in a\n * breach (0 indicating no exposure). The password is given in plain text, but\n * only the first 5 characters of its SHA-1 hash will be submitted to the API.\n *\n * @param {string} password a password in plain text\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<number>} a Promise which resolves to the number of times\n * the password has been exposed in a breach, or rejects with an Error\n * @example\n * pwnedPassword('f00b4r')\n * .then(numPwns => {\n * // truthy check or numeric condition\n * if (numPwns) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @see https://haveibeenpwned.com/api/v3#PwnedPasswords\n */\nexport function pwnedPassword(\n password: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<number> {\n const sha1 = new JSSHA('SHA-1', 'TEXT');\n sha1.update(password);\n const hash = sha1.getHash('HEX', { outputUpper: true });\n const prefix = hash.slice(0, 5);\n const suffix = hash.slice(5);\n\n return pwnedPasswordRange(prefix, options).then(\n (range) => range[suffix] || 0,\n );\n}\n"],"names":["pwnedPassword","password","options","sha1","JSSHA","update","hash","getHash","outputUpper","prefix","slice","suffix","pwnedPasswordRange","then","range"],"mappings":";;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;SACaA,aAAa,CAC3BC,QAAgB,EAChBC,UAAoD,EAAE,EAAA;EAEtD,MAAMC,IAAI,GAAG,IAAIC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;EACvCD,IAAI,CAACE,MAAM,CAACJ,QAAQ,CAAC;EACrB,MAAMK,IAAI,GAAGH,IAAI,CAACI,OAAO,CAAC,KAAK,EAAE;IAAEC,WAAW,EAAE;EAAI,CAAE,CAAC;EACvD,MAAMC,MAAM,GAAGH,IAAI,CAACI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;EAC/B,MAAMC,MAAM,GAAGL,IAAI,CAACI,KAAK,CAAC,CAAC,CAAC;EAE5B,OAAOE,qCAAkB,CAACH,MAAM,EAAEP,OAAO,CAAC,CAACW,IAAI,CAC5CC,KAAK,IAAKA,KAAK,CAACH,MAAM,CAAC,IAAI,CAAC,CAC9B;AACH;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/pwnedpasswords/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object mapping an exposed password hash suffix (corresponding to a given
|
|
7
|
+
* hash prefix) to how many times it occurred in the Pwned Passwords repository.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {Object.<string, number>} PwnedPasswordSuffixes
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.
|
|
13
|
+
*
|
|
14
|
+
* When a password hash with the same first 5 characters is found in the Pwned
|
|
15
|
+
* Passwords repository, the API will respond with an HTTP 200 and include the
|
|
16
|
+
* suffix of every hash beginning with the specified prefix, followed by a count
|
|
17
|
+
* of how many times it appears in the data set. This function parses the
|
|
18
|
+
* response and returns a more structured format.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} prefix the first 5 characters of a SHA-1 password hash (case
|
|
21
|
+
* insensitive)
|
|
22
|
+
* @param {object} [options] a configuration object
|
|
23
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
24
|
+
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
|
|
25
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
26
|
+
* field in the request headers (default: `hibp <version>`)
|
|
27
|
+
* @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an
|
|
28
|
+
* object mapping the `suffix` that when matched with the prefix composes the
|
|
29
|
+
* complete hash, to the `count` of how many times it appears in the breached
|
|
30
|
+
* password data set, or rejects with an Error
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* pwnedPasswordRange('5BAA6')
|
|
34
|
+
* .then(results => {
|
|
35
|
+
* // results will have the following shape:
|
|
36
|
+
* // {
|
|
37
|
+
* // "003D68EB55068C33ACE09247EE4C639306B": 3,
|
|
38
|
+
* // "012C192B2F16F82EA0EB9EF18D9D539B0DD": 1,
|
|
39
|
+
* // ...
|
|
40
|
+
* // }
|
|
41
|
+
* })
|
|
42
|
+
* @example
|
|
43
|
+
* const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';
|
|
44
|
+
* pwnedPasswordRange('5BAA6')
|
|
45
|
+
* .then(results => (results[suffix] || 0))
|
|
46
|
+
* .catch(err => {
|
|
47
|
+
* // ...
|
|
48
|
+
* });
|
|
49
|
+
* @see https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange
|
|
50
|
+
*/
|
|
51
|
+
function pwnedPasswordRange(prefix, options = {}) {
|
|
52
|
+
return fetchFromApi.fetchFromApi(`/range/${encodeURIComponent(prefix)}`, options)
|
|
53
|
+
// create array from lines of text in response body
|
|
54
|
+
.then(data => data.split('\n').filter(Boolean))
|
|
55
|
+
// convert into an object mapping suffix to count for each line
|
|
56
|
+
.then(results => results.reduce((acc, row) => {
|
|
57
|
+
const [suffix, countString] = row.split(':');
|
|
58
|
+
acc[suffix] = parseInt(countString, 10);
|
|
59
|
+
return acc;
|
|
60
|
+
}, {}));
|
|
61
|
+
}
|
|
62
|
+
exports.pwnedPasswordRange = pwnedPasswordRange;
|
|
63
|
+
//# sourceMappingURL=pwnedPasswordRange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pwnedPasswordRange.js","sources":["../../src/pwnedPasswordRange.ts"],"sourcesContent":["import { fetchFromApi } from './api/pwnedpasswords';\n\nexport interface PwnedPasswordSuffixes {\n [suffix: string]: number;\n}\n\n/**\n * An object mapping an exposed password hash suffix (corresponding to a given\n * hash prefix) to how many times it occurred in the Pwned Passwords repository.\n *\n * @typedef {Object.<string, number>} PwnedPasswordSuffixes\n */\n\n/**\n * Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.\n *\n * When a password hash with the same first 5 characters is found in the Pwned\n * Passwords repository, the API will respond with an HTTP 200 and include the\n * suffix of every hash beginning with the specified prefix, followed by a count\n * of how many times it appears in the data set. This function parses the\n * response and returns a more structured format.\n *\n * @param {string} prefix the first 5 characters of a SHA-1 password hash (case\n * insensitive)\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an\n * object mapping the `suffix` that when matched with the prefix composes the\n * complete hash, to the `count` of how many times it appears in the breached\n * password data set, or rejects with an Error\n *\n * @example\n * pwnedPasswordRange('5BAA6')\n * .then(results => {\n * // results will have the following shape:\n * // {\n * // \"003D68EB55068C33ACE09247EE4C639306B\": 3,\n * // \"012C192B2F16F82EA0EB9EF18D9D539B0DD\": 1,\n * // ...\n * // }\n * })\n * @example\n * const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';\n * pwnedPasswordRange('5BAA6')\n * .then(results => (results[suffix] || 0))\n * .catch(err => {\n * // ...\n * });\n * @see https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange\n */\nexport function pwnedPasswordRange(\n prefix: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<PwnedPasswordSuffixes> {\n return (\n fetchFromApi(`/range/${encodeURIComponent(prefix)}`, options)\n // create array from lines of text in response body\n .then((data) => data.split('\\n').filter(Boolean))\n // convert into an object mapping suffix to count for each line\n .then((results) =>\n results.reduce<PwnedPasswordSuffixes>((acc, row) => {\n const [suffix, countString] = row.split(':');\n acc[suffix] = parseInt(countString, 10);\n return acc;\n }, {}),\n )\n );\n}\n"],"names":["pwnedPasswordRange","prefix","options","fetchFromApi","encodeURIComponent","then","data","split","filter","Boolean","results","reduce","acc","row","suffix","countString","parseInt"],"mappings":";;;;AAMA;;;;;AAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;SACaA,kBAAkB,CAChCC,MAAc,EACdC,UAAoD,EAAE,EAAA;EAEtD,OACEC,YAAAA,CAAAA,YAAY,CAAW,UAAAC,kBAAkB,CAACH,MAAM,CAAC,EAAE,EAAEC,OAAO;;GAEzDG,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC;;GAE/CJ,IAAI,CAAEK,OAAO,IACZA,OAAO,CAACC,MAAM,CAAwB,CAACC,GAAG,EAAEC,GAAG,KAAI;IACjD,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GAAGF,GAAG,CAACN,KAAK,CAAC,GAAG,CAAC;IAC5CK,GAAG,CAACE,MAAM,CAAC,GAAGE,QAAQ,CAACD,WAAW,EAAE,EAAE,CAAC;IACvC,OAAOH,GAAG;EACZ,CAAC,EAAE,CAAA,CAAE,CAAC,CACP;AAEP;"}
|