wKovacs64/hibp

GitHub: wKovacs64/hibp

一个非官方的TypeScript SDK,用于查询「Have I been pwned?」服务,帮助检测账户、密码或邮箱是否在数据泄露事件中暴露。

Stars: 117 | Forks: 8

logo # HIBP 查询 _一个非官方的 TypeScript SDK,用于 [Troy Hunt][troy] 的 [Have I been pwned?][haveibeenpwned] 服务。_ [![npm 版本](https://img.shields.io/npm/v/hibp.svg?style=flat-square)][npm-url] [![构建状态](https://img.shields.io/github/actions/workflow/status/wKovacs64/hibp/ci.yml?logo=github&style=flat-square)][ci-url] [![代码覆盖率](https://img.shields.io/codecov/c/github/wKovacs64/hibp/main.svg?style=flat-square)][coverage-url] [![所有贡献者](https://img.shields.io/github/all-contributors/wKovacs64/hibp?style=flat-square)](#contributors-) ## 安装 在 Node.js 中: ``` npm install hibp ``` 在 [Deno][deno] 中: ``` // Replace x.y.z with the desired hibp version import * as hibp from "npm:hibp@x.y.z"; ``` 有关如何在浏览器中使用它的信息,请参阅下面的 [浏览器](#using-in-the-browser) 部分。 ## 功能 (🔑 = [需要][api-key-blog-post] [API 密钥][get-api-key]) - 获取最近新增的漏洞事件 - 获取单个漏洞事件 - 获取某个账户的所有漏洞事件 🔑 - 获取某个域名的所有已泄露邮箱地址 🔑 - 获取系统中的所有漏洞事件 - 获取所有数据类别 - 获取某个账户的所有粘贴信息 🔑 - [安全地][search-by-range]检查密码是否在数据泄露事件中暴露 - 检查 SHA-1 或 NTLM 前缀是否在数据泄露事件中暴露 - 同时搜索某个账户的漏洞和粘贴信息 🔑 - 获取某个邮箱地址的所有窃取日志域名 🔑 - 获取某个邮箱域的所有窃取日志邮箱别名 🔑 - 获取某个网站域名的所有窃取日志邮箱地址 🔑 - 获取所有已订阅的域名 🔑 - 获取您的订阅状态 🔑 - 所有查询都返回一个 Promise - 提供自定义的 `AbortSignal` 以取消进行中的请求 - 支持服务端(例如 Node.js)和客户端(浏览器)使用 - 使用 TypeScript 编写,因此所有模块都带有完整的类型定义 ## 使用 ``` // import individual modules as needed import { dataClasses, search } from "hibp"; // or, import all modules into a local namespace import * as hibp from "hibp"; ``` 可用的模块包括: - [breach](API.md#breach) - [breachedAccount](API.md#breachedaccount) - [breachedDomain](API.md#breacheddomain) - [breaches](API.md#breaches) - [dataClasses](API.md#dataclasses) - [latestBreach](API.md#latestbreach) - [pasteAccount](API.md#pasteaccount) - [pwnedPassword](API.md#pwnedpassword) - [pwnedPasswordRange](API.md#pwnedpasswordrange) - [search](API.md#search) - [stealerLogsByEmail](API.md#stealerlogsbyemail) - [stealerLogsByEmailDomain](API.md#stealerlogsbyemaildomain) - [stealerLogsByWebsiteDomain](API.md#stealerlogsbywebsitedomain) - [subscribedDomains](API.md#subscribeddomains) - [subscriptionStatus](API.md#subscriptionstatus) 更详细的用法信息和示例请参阅 [API 参考文档](API.md)。 #### 快速入门示例 ``` import { search } from "hibp"; async function main() { try { const data = await search("someAccountOrEmail", { apiKey: "my-api-key" }); if (data.breaches || data.pastes) { // Bummer... console.log(data); } else { // Phew! We're clear. console.log("Good news — no pwnage found!"); } } catch (err) { // Something went wrong. console.log(err.message); } } void main(); ``` #### 速率限制 haveibeenpwned.com API 会对请求进行[速率限制][haveibeenpwned-rate-limiting]以防止滥用。如果您的请求受到速率限制,此模块将抛出一个自定义的 `RateLimitError`,其中包含一个 `retryAfterSeconds` 属性,让您知道何时可以重试调用(该属性为 `number` 类型,除非远程 API 未提供此信息,此时其值将为 `undefined` — 但这种情况理论上不应发生)。 #### 在浏览器中使用 您有几种方式可以在浏览器环境中使用此库: 1. 打包使用 最有效且推荐的方法是使用模块打包工具(具体选择通常由您使用的 Web 应用框架决定)将其与客户端代码打包在一起。 2. 浏览器 ESM 模式 或者,您也可以在 [现代浏览器][caniuse-esm] 中通过 ` 有关在浏览器中使用 ESM 的更多信息,请查阅 [在浏览器中使用 JS 模块][js-modules]。 ## 试用 [使用 StackBlitz 在您的浏览器中测试 hibp。][stackblitz] ## 使用 hibp 的项目 - [pwned][pwned] - 一个用于查询 '[Have I been pwned?][haveibeenpwned]' 服务的命令行工具 - [Password Lense][pwl] - 一个用于揭示密码中字符类型的静态 Web 应用 - [Plasmic](https://www.plasmic.app/) - 适用于您技术栈的开源可视化构建器 - [Medplum](https://www.medplum.com/) - 快速简便的医疗健康开发 - [Hasura Backend Plus](https://nhost.github.io/hasura-backend-plus/) - 面向 Hasura 的认证与存储 - [Staart API](https://staart.js.org/api/) - 面向 SaaS 初创公司的 Node.js 后端启动模板 - [BanManager-WebUI](https://github.com/BanManagement/BanManager-WebUI) - BanManager 的 Web 界面 欢迎向我提交 [PR][pulls] 或发送邮件,我会将您的项目添加到列表中! ## 许可证 本模块根据 [MIT 许可证][license] 分发。
标签:AbortSignal, API客户端, Atomic Red Team, Deno, GNU通用公共许可证, HIBP服务, MITM代理, Node.js, npm包, NTLM哈希, Promise异步, SHA-1哈希, TypeScript, 二进制发布, 信息检索, 后端开发, 安全API, 安全插件, 密码安全, 开源工具, 数据泄露检测, 数据泄露警报, 数据类, 泄露查询, 浏览器兼容, 窃取日志, 类型安全, 粘贴查询, 网络安全, 网络安全, 范围查询, 订阅管理, 请求取消, 账户安全, 隐私保护, 隐私保护