@freedomofpress/tuf-browser

中文文档
0.3.0发布于 2026/10/31MITTypeScriptES Module构建来源已验证近 30 天下载 11.3万

A minimal TUF client for both node and the browser.

原始使用文档
文档目录11 节
  1. Features
  2. Limitations
  3. Usage
  4. Storage Backends
  5. Development
  6. Example: CLI Usage
  7. Running the TUF Conformance Test Suite
  8. Conformance
  9. Known Issues & TODOs
  10. License
  11. Acknowledgments

Minimal Browser-Compatible Implementation of TUF

Conformance

A minimal TypeScript implementation of The Update Framework (TUF) specification, optimized for browser compatibility.

This is a lightweight alternative to tuf-js that focuses on core TUF functionality needed for secure software updates in browser environments.

[!CAUTION]
This library has not received an independent security audit. Maintenance is performed by volunteers, and the project is not officially supported or endorsed by the Freedom of the Press Foundation.

Features

  • Core TUF Security: Implements essential TUF security guarantees including rollback protection, key rotation, and consistent snapshots
  • Browser-First: Designed for web browsers with support for LocalStorage, Chrome Extension Storage, and filesystem backends
  • Minimal Dependencies: Zero external dependencies for maximum compatibility
  • Spec Compliant: Passes TUF conformance tests for supported features
  • ECDSA & Ed25519 Support: Uses Web Crypto API for ECDSA-P256 and Ed25519 signatures Browsers without native Ed25519 need the application to call installEd25519Fallback() from @freedomofpress/crypto-browser/noble once at startup.

Limitations

This minimal implementation intentionally omits certain TUF features to optimize for size and browser compatibility:

  • No delegation support
  • No RSA key support (ECDSA and Ed25519 only)
  • No mirror lists
  • No custom download limits

Usage

import { TUFClient } from 'tuf-browser';

// Initialize client with repository URL and root metadata
const client = new TUFClient(
  'https://repository.example.com/metadata/',
  rootMetadata,
  'my-app'
);

// Fetch and verify a target file
const targetData = await client.getTarget('path/to/target.json');

Storage Backends

The library automatically selects the appropriate storage backend based on the runtime environment:

EnvironmentBackend usedNotes
Node.js (CLI / tests)FSBackendWrites metadata and targets to disk. Required for TUF conformance.
Browser ExtensionExtensionStorageBackendUses the browser.storage.local API (Firefox/Chrome extension storage).
Browser Web PageLocalStorageBackendUses localStorage, minimal persistent storage.

Development

# Install dependencies
npm install

# Build the project
npm run build

Example: CLI Usage

Download 1.root.json or a newer one and trigger a refresh.

$ node ./dist/cli.js \
    --metadata-dir /tmp/ \
    --metadata-url https://tuf-repo-cdn.sigstore.dev \
    refresh 1.root.json

Example output:

[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/2.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/3.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/4.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/5.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/6.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/7.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/8.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/9.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/10.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/11.root.json
KeyId 7247f0dbad85b147e1863bade761243cc785dcb7aa410e7105dd3d2b61a36d2c does not match the expected 0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5, importing anyway the provided one for proper referencing.
KeyId 7247f0dbad85b147e1863bade761243cc785dcb7aa410e7105dd3d2b61a36d2c does not match the expected 0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5, importing anyway the provided one for proper referencing.
KeyId 7247f0dbad85b147e1863bade761243cc785dcb7aa410e7105dd3d2b61a36d2c does not match the expected 0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5, importing anyway the provided one for proper referencing.
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/12.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/13.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/14.root.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/timestamp.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/162.snapshot.json
[TUF] Fetching https://tuf-repo-cdn.sigstore.dev/13.targets.json

The CLI behavior follows the TUF client specification required by the tuf-conformance suite.

Note: The CLI is a minimal reference implementation for conformance testing. It implements the core init, refresh, and download commands but lacks some commands (e.g., metadata) expected by certain conformance tests. For production use, import and use the TUFClient class directly rather than relying on the CLI.

Running the TUF Conformance Test Suite

Requires Python 3.11 and virtualenv.

git clone https://github.com/theupdateframework/tuf-conformance
cd tuf-conformance
make env/pyvenv.cfg
./env/bin/pytest -v tuf_conformance \
   --entrypoint "/usr/bin/node /tuf-browser/dist/cli.js" \
   --repository-dump-dir /tmp/

Conformance

This implementation passes 75 out of 108 TUF conformance tests. The remaining tests cover intentionally unsupported features (delegations, RSA keys).

Known Issues & TODOs

The core TUF functionality is implemented (metadata verification, signature checking, rollback protection, hash verification with SHA-256/SHA-512 support). Remaining conformance test failures:

  • Root metadata byte preservation (test_metadata_bytes_match)

    Root metadata is re-serialized on write (tuf.ts:236 uses setInCache → backend.write), while other roles correctly use writeRaw to preserve bytes.

  • Fast-forward recovery (3 tests in test_rollback.py)

    Partial implementation: cached metadata is cleared when keys rotate (tuf.ts:245-267). The code strictly rejects version downgrades rather than attempting recovery.

  • Additional test failures (~10 remaining tests)

    Various failures related to file downloads, static repositories, and edge cases.

License

MIT License - see LICENSE file for details. Portions of this package incorporate code from sigstore-js and are licensed under the Apache License 2.0. These sections are clearly indicated in the corresponding source file headers.

Acknowledgments

This project is based on the TUF specification and adapted from tuf-js and sigstore-js.

版本与发布记录

@freedomofpress/tuf-browser 共发布 13 个版本,首次发布于 2025/11/27;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/10/3115 天前
0.2.12026/10/3116 天前
0.2.02026/10/3016 天前
0.1.112026/02/149 个月前
0.1.102026/02/149 个月前
0.1.92026/02/139 个月前

关于 @freedomofpress/tuf-browser 的常见问题

@freedomofpress/tuf-browser 是什么?

A minimal TUF client for both node and the browser.

如何安装 @freedomofpress/tuf-browser?

在项目目录运行 npm install @freedomofpress/tuf-browser,或使用 pnpm add / yarn add / bun add。

@freedomofpress/tuf-browser 支持 TypeScript 吗?

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

@freedomofpress/tuf-browser 支持 ESM 还是 CommonJS?

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

@freedomofpress/tuf-browser 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@freedomofpress/tuf-browser 可以商用吗?

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

@freedomofpress/tuf-browser 的下载量有多少?

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

@freedomofpress/tuf-browser 还在维护吗?

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