@blowfishxyz/blocklist

中文文档
0.0.11发布于 2026/02/02ISCTypeScriptESM + CJS近 30 天下载 9.6万

Fetch and execute lookups on Blowfish blocklists

原始使用文档
文档目录15 节
  1. Install
  2. Usage
  3. Basic usage
  4. Bloom filter
  5. Error handling
  6. Guides
  7. Browser extension
  8. React Native
  9. API Reference
  10. BlowfishLocalBlocklist
  11. Constructor arguments
  12. Methods
  13. fetchBlocklist(): Promise<LocalBlocklist | undefined>
  14. scanDomain(url: string): Promise<Action>
  15. allowDomainLocally(url: string): Promise<Action>

Blowfish Local Blocklists

This is a Javascript/Typescript library that makes it easy to access the Blowfish Local Blocklist API: for example, to fetch the blocklist object from API, scan a domain against the blocklist and saved bloom filter.

It's designed to support React Native, Chrome Extension and Node.js environments.

Install

npm install @blowfishxyz/blocklist

It's also recommended for React Native apps to install react-native-url-polyfill.

Usage

In order to execute lookups, you need to fetch a blocklist object and bloom filter. After the first fetch, you should keep these objects updated. You can save the objects in a local database (for example, using local storage in Chrome extension).

We recommend updating it every 5 minutes.

Basic usage

import {
  BlowfishLocalBlocklist,
  ApiConfig,
  BLOWFISH_API_BASE_URL,
} from "@blowfishxyz/blocklist";

const apiConfig: ApiConfig = {
  basePath: BLOWFISH_API_BASE_URL,
  // It's highly encouraged to use a proxy server to not expose your API key on the client (see: https://docs.blowfish.xyz/docs/wallet-integration-guide#optional-proxy-server).
  // When using a proxy server, replace basePath with your endpoint and set apiKey to `undefined`.
  apiKey: "you-api-key",
};
const blocklist = new BlowfishLocalBlocklist(apiConfig);

// 1. Fetch the blocklist and persist it in the storage
blocklist.fetchBlocklist();

// 2. Re-refetch the blocklist every 5 minutes
setInterval(() => blocklist.fetchBlocklist(), 1000 * 60 * 5);

// 3. Once you have a blocklist object and a bloom filter saved, you can execute lookups
const action = blocklist.scanDomain("https://scam-website.io");

if (action === Action.BLOCK) {
  // block the domain
}

You can skip apiKey and pass custom basePath to route the query to your backend app or a proxy.

Bloom filter

Blocklist object links to a bloom filter. However, bloom filter is a 700 KB file, so your app should only re-download it when nessesary.

To do that, we are tracking bloom filter's hash and re-fetching it if necessary.

Then, we save the bloom filter object itself and its hash to the storage.

We don't update blocklist hash more often than every 24 hours.

Error handling

Functions that depend on API an/or network can return null when I/O errors are encountered.

If you would like to track errors, you can pass optional reportError callback to BlowfishLocalBlocklist constructor.

It could be called with an Error or with a string.

Guides

Browser extension

  1. Install Necessary Dependencies:
npm install @blowfishxyz/blocklist webextension-polyfill
  1. Create Blocklist Module:
// src/blocklist.ts
import {
  BlowfishLocalBlocklist,
  BlowfishBlocklistStorageKey,
  BlowfishBlocklistStorage,
  BLOWFISH_API_BASE_URL,
} from "@blowfishxyz/blocklist";

const storage: BlowfishBlocklistStorage = {
  async getItem<T>(key: BlowfishBlocklistStorageKey) {
    const storage = chrome.storage.local.get([key]);
    return storage[key] as T | undefined;
  },
  async setItem(key: BlowfishBlocklistStorageKey, data: unknown) {
    return chrome.storage.local.set({
      [key]: data,
    });
  },
};

export const blocklist = new BlowfishLocalBlocklist(
  { basePath: BLOWFISH_API_BASE_URL, apiKey: undefined },
  undefined,
  storage
);
export { Action } from "@blowfishxyz/blocklist";
  1. Schedule Blocklist Updates:
// src/background.ts
import Browser from "webextension-polyfill";
import { blocklist } from "./blocklist";

Browser.alarms.onAlarm.addListener((alarm) => {
  if (alarm.name === "refetch-blocklist") {
    blocklist.fetchBlocklist();
  }
});

Browser.alarms.create("refetch-blocklist", {
  periodInMinutes: 5,
  delayInMinutes: 0,
});
  1. Domain Scanning:
// src/content-script.ts
import Browser from "webextension-polyfill";
import { blocklist, Action } from "./blocklist";

blocklist.scanDomain(window.location.href).then((action) => {
  if (action === Action.BLOCK) {
    Browser.runtime.sendMessage({
      type: "block-domain",
      host: window.location.hostname,
      href: encodeURI(window.location.href),
    });
  }
});
  1. Blocked Domain Screen:
// src/block-screen.tsx
import { blocklist } from "./blocklist";

function proceedToBlockedDomainButtonClickHandler() {
  blocklist.allowDomainLocally(window.location.href);
}

React Native

  1. Install Necessary Dependencies:
npm install @blowfishxyz/blocklist react-native-async-storage react-native-background-timer react-native-url-polyfill
  1. Create Blocklist Module:
// src/blocklist.ts
import {
  BlowfishLocalBlocklist,
  BlowfishBlocklistStorageKey,
  BlowfishBlocklistStorage,
  BLOWFISH_API_BASE_URL,
} from "@blowfishxyz/blocklist";
import AsyncStorage from "@react-native-async-storage/async-storage";

const storage: BlowfishBlocklistStorage = {
  async getItem<T>(key: BlowfishBlocklistStorageKey): Promise<T | undefined> {
    const data = await AsyncStorage.getItem(key);
    return data ? (JSON.parse(data) as T) : undefined;
  },
  async setItem(
    key: BlowfishBlocklistStorageKey,
    data: unknown
  ): Promise<void> {
    await AsyncStorage.setItem(key, JSON.stringify(data));
  },
};

export const blocklist = new BlowfishLocalBlocklist(
  { basePath: BLOWFISH_API_BASE_URL, apiKey: undefined },
  undefined,
  storage
);
export { Action } from "@blowfishxyz/blocklist";
  1. Schedule Blocklist Updates:
// src/background.ts
import { blocklist } from "./blocklist";
import BackgroundTimer from "react-native-background-timer";

let intervalId;

const refetchBlocklist = () => {
  blocklist.fetchBlocklist();
};
export const startBlocklistRefetch = () => {
  intervalId = BackgroundTimer.setInterval(refetchBlocklist, 5 * 60 * 60);
};

export const stopBlocklistRefetch = () => {
  BackgroundTimer.clearInterval(intervalId);
};
  1. Domain Scanning:
// src/domainScanner.ts
import { blocklist, Action } from "./blocklist";

const scanCurrentDomain = async (url: string) => {
  const action = await blocklist.scanDomain(url);
  if (action === Action.BLOCK) {
    // Handle domain blocking logic
    console.warn("Blocked domain:", url);
  }
};

export default scanCurrentDomain;
  1. Blocked Domain Screen:
// src/BlockScreen.tsx
import React from "react";
import { TouchableOpacity, Text } from "react-native";
import { blocklist } from "./blocklist";

function proceedToBlockedDomainHandler(url: string) {
  blocklist.allowDomainLocally(url);
}

const BlockScreen: React.FC<{ url: string }> = ({ url }) => {
  return (
    <TouchableOpacity onPress={() => proceedToBlockedDomainHandler(url)}>
      <Text>Proceed to Blocked Domain</Text>
    </TouchableOpacity>
  );
};

export default BlockScreen;

API Reference

BlowfishLocalBlocklist

Constructor arguments

  • apiConfig: ApiConfig
    • basePath: string: the URL for the domain blocklist. You can use it to pass API requests to a proxy that sits between your users and Blowfish API.
    • apiKey: string | undefined: the API key for the Blowfish API. Can be undefined when using a proxy.
  • blocklistConfig: BlocklistConfig
    • priorityBlockLists: PriorityBlockListsEnum[] | undefined: Always block domain if it present on one of these lists, even if it's allow-listed on one of regular allow lists (ex: PHANTOM, BLOWFISH, BLOWFISH_AUTOMATED, SOLFARE, PHISHFORT, SCAMSNIFFER, METAMASK)
    • priorityAllowLists: PriorityAllowListsEnum[] | undefined: Override domain blocking if domain is present on one of these lists, even if it's block-listed on of regular block lists (ex: BLOWFISH, METAMASK, DEFILLAMA)
    • blockLists: BlockListsEnum[] | undefined: Override domain blocking if domain is present on one of these lists, even if it's block-listed on of regular block lists (ex: PHANTOM, BLOWFISH, BLOWFISH_AUTOMATED, SOLFARE, PHISHFORT, SCAMSNIFFER, METAMASK)
    • allowLists: AllowListsEnum[] | undefined: Override domain blocking if domain is present on one of these lists, even if it's block-listed on of regular block lists (ex: BLOWFISH, METAMASK, DEFILLAMA)
    • bloomFilterTtl?: number: How long a bloom filter and corresponding hash should remain static. By default, 24 hours. Minimum 24 hours, maximum 14 days. During this time, new domains will be added to recentlyAdded and removed from recentlyRemoved fields.
  • storage: BlowfishBlocklistStorage If storage is not specified we use in-memory storage. It is highly encouraged to provide the proper storage for your environemnt (see guides).
    • getItem<T>(key: BlowfishBlocklistStorageKey): Promise<T | undefined>: get item by key from the environment storage.
    • setItem(key: BlowfishBlocklistStorageKey, data: unknown): set item by key to the environment storage.
  • reportError: (error: unknown) => void: A callback function that library uses to track errors when result is null. (optional)

Methods

fetchBlocklist(): Promise<LocalBlocklist | undefined>

Fetches the blocklist metadata and saves it to the storage. If the fetched blocklist hash is different from one in the storage, it re-fetches the bloom filter and saves it to the storage.

If the blocklist fetch fails, the method returns undefined and reports the error to reportError.

scanDomain(url: string): Promise<Action>

Scans a domain against the stored domain blocklist and returns the action to be taken (either BLOCK or NONE).

If there is no stored blocklist it fetches the blocklist using fetchBlocklist method and returns the resulting action.

If the fetch fails, the method returns the action NONE and reports the error to reportError.

allowDomainLocally(url: string): Promise<Action>

If the user wants to proceed to the blocked domain with an explicit action, the domain is added in the user allow list (locally in the storage).

The scanDomain method will return NONE action for this domain even if it's in the blocklist.

版本与发布记录

@blowfishxyz/blocklist 共发布 11 个版本,首次发布于 2023/02/09;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.0.11latest2026/02/029 个月前
0.0.102025/07/011.4 年前
0.0.92025/06/301.4 年前
0.0.82024/04/232 年前
0.0.72023/10/183 年前
0.0.62023/05/153 年前

关于 @blowfishxyz/blocklist 的常见问题

@blowfishxyz/blocklist 是什么?

Fetch and execute lookups on Blowfish blocklists

如何安装 @blowfishxyz/blocklist?

在项目目录运行 npm install @blowfishxyz/blocklist,或使用 pnpm add / yarn add / bun add。

@blowfishxyz/blocklist 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@blowfishxyz/blocklist 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@blowfishxyz/blocklist 可以商用吗?

@blowfishxyz/blocklist 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@blowfishxyz/blocklist 的下载量有多少?

根据 npm 官方下载统计,@blowfishxyz/blocklist 在 2026/10/09 – 2026/11/07 这 30 天内被下载 96,196 次,日均约 3,207 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@blowfishxyz/blocklist 还在维护吗?

最新版本 0.0.11 发布于 2026/02/02(9 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。