@agentcontextdistributionprotocol/acdp

中文文档
0.21.4发布于 2026/11/07MIT OR Apache-2.0TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 2930

Agent Context Distribution Protocol — Node.js SDK

原始使用文档
文档目录9 节
  1. Install
  2. Install (development)
  3. Build a release binary
  4. Quickstart
  5. Verifying a retrieved body
  6. Verifying a registry receipt
  7. Verification surface
  8. Design rules
  9. Public surface

acdp — Node.js SDK

Thin NAPI-rs binding over the acdp Rust library. Implements the producer- and consumer-side crypto for the Agent Context Distribution Protocol — the 0.1.0–0.4.0 Final lines plus RFC-ACDP-0016 external anchors; see the spec's version matrix for exactly which protocol lines each release implements. HTTP is intentionally left to the caller — pair this with fetch / undici for transport.

The package is released at the same version as the acdp crate.

Install

npm install @agentcontextdistributionprotocol/acdp

Prebuilt native binaries are published for macOS (x64/arm64) and Linux (x64/arm64-gnu); the loader package selects the right one at install time.

Requires Node.js 22 or newer (engines.node: ">=22"; Node 20 is end-of-life and was dropped in 0.15.1). CI tests Node 22 and 24.

Install (development)

package-lock.json is committed; use npm ci (as CI does) to install exactly that pinned graph, including the exact @napi-rs/cli version — it fails instead of silently re-resolving if package.json and the lockfile disagree.

npm ci                       # installs @napi-rs/cli from the lockfile
npm run build:debug          # produces index.js + acdp.<platform>.node
node --test tests/*.mjs      # in-process unit tests, no HTTP

Build a release binary

npm run build                # release mode (LTO + strip)

Quickstart

import { AcdpProducer, AcdpVerifier } from '@agentcontextdistributionprotocol/acdp';

const producer = AcdpProducer.generate(
  'did:web:agents.example.com:my-agent',
  'did:web:agents.example.com:my-agent#key-1',
);

const raw = producer.buildPublishRequest({
  title: 'Q1 snapshot',
  contextType: 'data_snapshot',
  summary: 'Quarter-end inventory',
});

// POST `raw` (the JSON string) to your registry's /contexts endpoint.
// On retrieve:
const body = (await response.json()).body;
AcdpVerifier.verifyContentHash(JSON.stringify(body), body.content_hash);
AcdpVerifier.verifySignature(
  pubKeyB64,                  // resolved from the producer's did:web doc
  body.signature.value,
  body.content_hash,
);

Verifying a retrieved body

ctx_id is registry-assigned and sits in the RFC-ACDP-0001 §5.7 exclusion set, so it is stripped before content_hash is computed — neither the hash recompute above nor the producer's signature covers it. Without an explicit comparison, a registry could serve any other validly-signed body from the same producer under the ctx_id URL you asked for, and every check above would still pass. Call verifyCtxIdBinding to close that gap (RFC-ACDP-0006 §4.1 step 7, NORMATIVE):

// Argument order matters: `bodyJson` carries the *served* ctx_id,
// `expectedCtxId` is the one you requested.
AcdpVerifier.verifyCtxIdBinding(JSON.stringify(body), requestedCtxId);

Like the rest of the AcdpVerifier bool surface, this returns true on success and throws on failure — never false — so if (AcdpVerifier.verifyCtxIdBinding(...)) guards a branch that can't be reached.

Verifying a registry receipt

verifyReceipt (RFC-ACDP-0010 §8) takes the accompanying bodyJson as a required second argument — it binds the receipt's lineage_id, origin_registry, and created_at to the served body's own fields (§8 step 3):

AcdpVerifier.verifyReceipt(
  receiptJson,            // the `registry_receipt` object, as received
  bodyJson,                // the accompanying `body`, same retrieval
  registryPublicKeyB64,    // resolved via AcdpDid.webToUrl + fetch
  expectedCtxId,           // the ctx_id you actually requested
  recomputedBodyHash,      // YOUR OWN verifyContentHash result — never
                            // the body's echoed content_hash field
  producerKeyFingerprint,  // fingerprint of the resolved producer key
);

Throws on a malformed bodyJson (host input) or a body/receipt mismatch (verification failure) alike — never false. Two checks still stay the HOST's obligation, because neither needs the body: the serving-authority binding (receipt.registry_did must equal the authority you actually fetched from) and recomputing (never trusting) the body hash you pass in.

Verification surface

AcdpVerifier covers the full verification surface in addition to the basics above: identity binding (verifyCtxIdBinding, see Verifying a retrieved body above), offline did:key verification (verifyBodyOffline, verifyPublishRequestOffline), registry receipts (verifyReceipt(receiptJson, bodyJson, registryPublicKeyB64, expectedCtxId, recomputedBodyHash, producerKeyFingerprint), see Verifying a registry receipt above; verifyLineageHeadReceipt), the transparency log (verifyLogCheckpoint, verifyLogInclusion, verifyLogConsistency), lifecycle events (verifyLifecycleEvent), key revocation (parseKeyRevocation, classifyUnderRevocation), and witness cosigning (buildWitnessCosignature, verifyWitnessCosignature, evaluateWitnessQuorum). AcdpP256Producer, AcdpDid, AcdpDidDocument, AcdpCanonicalizer, AcdpMerkle, and AcdpSsrfPolicy are also exported.

Design rules

  • JSON across the FFI boundary. Every method accepts and returns JSON strings — never a Rust type, never a JS class instance you'd have to serialize before sending.
  • Crypto in Rust, HTTP in JS. Key generation, JCS + SHA-256 hashing, Ed25519 signing, and signature verification happen in the underlying acdp crate. Transport, retries, and observability are yours.
  • AcdpProducer stores a 32-byte seed. The Rust SigningKey is ZeroizeOnDrop and not Clone, so the binding rebuilds the signing key from the seed on each call.
  • Golden vector parity. golden content_hash + signature match sig-001 pins the JS-side content_hash and signature.value against the spec's sig-001 fixture — the same constants the Rust suite asserts. A drift on either side is a protocol break.

Public surface

The canonical list of exported classes and methods (and their arity) is bindings/interop/expected_surface.json, enforced against this package by the interop parity tests.

版本与发布记录

@agentcontextdistributionprotocol/acdp 共发布 35 个版本,首次发布于 2026/06/09;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.21.4latest2026/11/07今天
0.21.32026/11/07今天
0.21.22026/11/07今天
0.21.12026/11/071 天前
0.21.02026/11/016 天前
0.19.02026/10/317 天前

关于 @agentcontextdistributionprotocol/acdp 的常见问题

@agentcontextdistributionprotocol/acdp 是什么?

Agent Context Distribution Protocol — Node.js SDK

如何安装 @agentcontextdistributionprotocol/acdp?

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

@agentcontextdistributionprotocol/acdp 支持 TypeScript 吗?

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

@agentcontextdistributionprotocol/acdp 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@agentcontextdistributionprotocol/acdp 需要什么版本的 Node.js?

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

@agentcontextdistributionprotocol/acdp 可以商用吗?

@agentcontextdistributionprotocol/acdp 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agentcontextdistributionprotocol/acdp 的下载量有多少?

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

@agentcontextdistributionprotocol/acdp 还在维护吗?

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