# @anon-rpc/browser-harness 中文文档

规范地址：https://npmcn.com/package/%40anon-rpc/browser-harness/

版本：0\.4\.0
npm 元数据更新时间：2026-10-28T03:03:22.127Z
中文译文更新时间：2026-11-06T12:13:04.792Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40anon-rpc/browser-harness
原文对照：https://npmcn.com/package/%40anon-rpc/browser-harness/?lang=original
项目主页：https://github.com/ethereum/anon-rpc
源码仓库：https://github.com/ethereum/anon-rpc

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：185 kB，40 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2026-07-06T05:33:17.766Z
- 最新版本发布：2026-10-28T03:03:21.782Z
- 近 30 天下载量：3254（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：6（近 12 个月 6 个）

## 中文简介

anon-rpc浏览器控制器:在无源iframe隔离下装入被散列的aon-client工人,并暴露出匿名取取(SPEC §3.1兼容目标).

## 安装

```sh
npm install @anon-rpc/browser-harness
```

也可以使用：`pnpm add @anon-rpc/browser-harness`、`yarn add @anon-rpc/browser-harness`、`bun add @anon-rpc/browser-harness`

## README

# @anon-rpc/浏览器harness

浏览器控制器 [动画](https://github.com/ethereum/anon-rpc) ——允许钱包或应用程序生成的标准 **匿名的RPC请求** 在沙箱工人体内运行被散装的肛门客户密码.

执行 [阳起角规格](https://ethereum.github.io/anon-rpc/spec/) 版本 **0.4.0 (中文(简体) )**. (软件包版本保留) `>=` 已执行的光谱 版本;没有光谱变化的软件包发布会撞过它. )

绳子:

-   解决来自链上指定合同的动因客户捆绑——结束 `https:` 科索沃警察部队本身通过 `kps:` 解析器条目(SPEC §4.1-4.2) - 并核实 `keccak256(bytes) == workerHash()` 执行单曲前 字节( 相信散列而不是 URL );
-   运行在一个 **无效沙盒内网络工人**,没有 环境访问您的 DOM、 存储、 饼干或密钥;
-   赋予它一个小型、明确的能力API——入境接听电话,a [科索沃警察部队](https://ethereum.github.io/kps/) 键控运输 (剪接后工人从不接触WebRTC),持续存储 (IndexedDB关于主机源头,每个指定点的名称空格),并记录;
-   将你带回一件事: 无名化 `fetch`。 。 。 .

## 安装

```sh
npm install @anon-rpc/browser-harness
```

## 使用

```ts
import { AnonRpcWorker } from "@anon-rpc/browser-harness";

const worker = new AnonRpcWorker({
  // The IWorkerSpecifier contract identifying the anon-client by hash.
  address: "0x…",
  // Optional: a plain value (JSON, plus undefined, Uint8Array, ArrayBuffer)
  // delivered to the worker exactly as `anonRpcWorker.config`. Opaque to the
  // harness; schema is the worker's. Anything else throws a TypeError here.
  config: { network: "mainnet" },
  // Bootstrap provider used only to read the specifier (breaks the circular
  // "need the chain to reach the chain" dependency).
  preExisting: { rpcProvider },
});

// Optional: Wait for the worker to report that it is ready. You can start
// making fetch calls before this - they'll just get buffered.
// await worker.ready;

// A standard fetch, routed through the sandboxed anon-client.
// It is this-bound, so passing it around as a free function is fine.
const res = await worker.fetch("https://rpc.example/", {
  method: "POST",
  body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_blockNumber" }),
});

worker.close(); // tears down the iframe and worker
```

### 按呼选项

`anonOptions` 在一个 `fetch` 它被传递给工人,而不是目的地 (SPEC 第9.3节):

```ts
await worker.fetch(url, { method: "POST", body, anonOptions: { isolationKey: "account-1" } });
```

`isolationKey` 要求不同密钥下的通话不能连接到一个 另一个 支持不尽相同——如果是的话,请检查您的网络对这个密钥做了什么 对你很重要.

### 收集工人的日志

工人第13节 `log` 呼叫控制台,除非你收到 拉他们 与 `acceptLog()` (SPEC §5, 第13.1段) 并且不再被重复:

```ts
for (;;) {
  // Resolves with the next entry; waits when there is none. Rejects once the
  // worker has failed or closed AND its retained entries are drained — so the
  // lines explaining a failure arrive before the rejection does.
  const { level, args } = await worker.acceptLog();
  render(level, args);
}
```

从工人开始就保留了条目,所以有一条线被记录 当你第一次问起的时候,靴子还在那里。 缓冲器是被绑定的(1 000) 条目),并放出最古老的; 第13.1节使这里成为一个 磁带可能会失去它已经接受的日志呼叫.

### 严格内容安全政策

默认情况下,这个带子用 `srcdoc` 和内线 脚本,不需要你帮忙 如果你的页面 CSP 省略 `'unsafe-inline'` 页:1 `script-src`这靴子不会跑.. `srcdoc` 文档继承嵌入者的政策,而政策只能收紧 从文件里面,永远不要放松。 症状是 `ready` 从来没有 和解,加CSP违反 控制台.

自己把绳子的靴子绑好,指点一下 `iframeUrl` (SPEC 第5条) 内容:

```ts
new AnonRpcWorker({ address, preExisting, iframeUrl: "/anon-rpc-iframe.html" });
```

这页只需要带子的脚本 里面有船 软件包为 `dist/iframe-boot.js`数字 :

```html
<!doctype html><meta charset="utf-8"><script src="/anon-rpc-iframe.js"></script>
```

绳子仍然适用 `sandbox="allow-scripts"` 因此文档是 放置在不透明来源, 无论来自哪条路由, 第6节要求 URL 与你的页面同源 跨出源的靴子会让 与第三方隔离,所以绳子拒绝一个.

在Firefox上,允许 `data:` 在靴子的页面 `script-src` 无论政策如何 在此应用: Firefox 拒绝 `importScripts(blob:)` 在不透明来源中 工人们,所以绳子上载了经证实的捆绑 `data:` URL 代替( 它 检测到这一点;其他浏览器继续使用 `blob:`) (中文(简体) ).

MV3 浏览器扩展名不是可选的, 页面必须附加 将在名单中宣布 `sandbox.pages`· ; [`@anon-rpc/browser-extension-harness`](https://npmcn.com/package/%40anon-rpc/browser-extension-harness) 软件包 这一切.

## 页:1

-   仅浏览器: 隔离模型是无效的 Iframe 和 KPS 运输通过WebRTC. 本地/节点的牵引装置是单独的 软件包.
-   提高工人的适应能力`anonRpcWorker`)和所有符合规定 所需经费的定义见 [规格](https://github.com/ethereum/anon-rpc/blob/main/SPEC.md)。 。 。 . 复制住址的 anon 客户端模板 [`impl/passthrough-worker`](https://github.com/ethereum/anon-rpc/tree/main/impl/passthrough-worker)。 。 。 .
-   现状:样板草稿的原型级参考执行;接口 跟踪谱并可能改变.

## 许可证

麻省理工学院埃特鲁姆基金会

## 常见问题

### @anon-rpc/browser-harness 是什么？

anon-rpc浏览器控制器:在无源iframe隔离下装入被散列的aon-client工人,并暴露出匿名取取\(SPEC §3\.1兼容目标\)\.

### 如何安装 @anon-rpc/browser-harness？

在项目目录运行 npm install @anon-rpc/browser-harness，或使用 pnpm add / yarn add / bun add。

### @anon-rpc/browser-harness 支持 TypeScript 吗？

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

### @anon-rpc/browser-harness 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @anon-rpc/browser-harness 可以商用吗？

@anon-rpc/browser-harness 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @anon-rpc/browser-harness 的下载量有多少？

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

### @anon-rpc/browser-harness 还在维护吗？

最新版本 0\.4\.0 发布于 2026/10/28（10 天前）；至今共发布 6 个版本，其中过去 12 个月发布了 6 个；首次发布于 2026/07/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

