Producing Contexts

This page covers building and signing a PublishRequest with Producer and RequestBuilder. For what the fields mean and the publish wire contract, see RFC-ACDP-0002 (Context Body) and RFC-ACDP-0003 (Publish & Supersession). The language-neutral walkthrough is the spec's integration guide.

Available in the default (core) build — no feature flags, no HTTP. The producer only builds and signs; transport is your responsibility (use the client feature, the CLI, or your own HTTP).

The producer

A Producer binds a signing key to a producer identity and a key id. For a did:web producer the key id is the verification-method id in the producer's did:web document. For a did:key producer (ACDP 0.2) both the identity and the key id are derived from the public key itself.

use acdp::{crypto::SigningKey, producer::Producer, types::AgentDid};

# let seed = [7u8; 32];
let key = SigningKey::from_bytes(&seed);          // or SigningKey::generate()
let producer = Producer::new(
    key,
    AgentDid::new("did:web:agents.example.com:my-agent"),
    "did:web:agents.example.com:my-agent#key-1",
);
ConstructorAlgorithmNotes
Producer::new(key, agent_id, key_id)Ed25519The common case.
Producer::new_ed25519(...)Ed25519Explicit alias of new.
Producer::new_p256(key, ...)ECDSA-P256Interop only. Ed25519 is mandatory (RFC-ACDP-0001 §5.10); P256 is optional and some registries may not accept it. Signatures are emitted low-S and deterministic (see Security and the spec's non-uniqueness rules).
Producer::new_did_key(key)Ed25519did:key identity derived from the key: no domain or DID-document hosting, and consumers verify offline. A did:key cannot rotate, so a new key is a new identity and ends the lineage.
Producer::new_did_key_p256(p256_key)ECDSA-P256As above, for P-256. Returns Result (fails only on a malformed SEC1 point).

SigningKey is ZeroizeOnDrop and not Clone — it erases its seed on drop. Load the 32-byte seed from secure storage in production rather than calling generate() (which uses OS entropy and gives you a fresh, unrecoverable key).

Building a first version

use acdp::types::{ContextType, Visibility};

# use acdp::{crypto::SigningKey, producer::Producer, types::AgentDid};
# let producer = Producer::new(
#     SigningKey::from_bytes(&[7u8; 32]),
#     AgentDid::new("did:web:agents.example.com:my-agent"),
#     "did:web:agents.example.com:my-agent#key-1",
# );
let req = producer
    .publish_request()
    .title("Q1 2026 revenue snapshot")          // required, 1..=500 chars
    .context_type(ContextType::DataSnapshot)     // required
    .visibility(Visibility::Public)              // defaults to Public
    .description("Quarterly revenue figures aggregated by region.")
    .tags(vec!["finance", "revenue"])
    .domain("finance")
    .summary("Q1 2026 revenue snapshot.")
    .metadata(serde_json::json!({ "currency": "USD" }))
    .build()?;
# Ok::<(), acdp::AcdpError>(())

.build() performs four steps in order (crates/acdp-producer/src/builder.rs):

  1. Assemble ProducerContent (producer-controlled fields only).
  2. Compute content_hash = sha256(JCS(ProducerContent)).
  3. Sign the content_hash string with the producer's key.
  4. Return a wire-ready PublishRequest (with content_hash + signature attached).

Before step 2 it runs validation::validate_publish_request, so a bad request fails locally with a typed AcdpError rather than at the registry. Timestamps you pass (expires_at, data_period) are truncated to milliseconds (RFC-ACDP-0001 §5.3) so the canonical form is stable.

Builder methods

MethodFieldRequired?
.title(s)titleyes (1..=500 chars)
.context_type(t)typeyes
.visibility(v)visibilitydefaults to Public
.description(s) / .summary(s)description / summaryoptional
.tags(vec) / .domain(s)tags / domainoptional
.data_refs(vec)data_refsoptional — see below
.contributors(vec) / .audience(vec)contributors / audienceoptional
.derived_from(vec)derived_from (lineage)optional
.metadata(json)metadataoptional (depth/size capped)
.schema_uri(s)schema_urioptional
.expires_at(dt) / .data_period(dp)expiry / periodoptional
.version(n) / .expected_lineage_id(l)version / lineage checkv2+ only (see Supersession)
.anchors(vec) / .clear_anchors()anchors (RFC-ACDP-0016 typed external anchors; schemes in registries/anchor-schemes.md)optional — an empty Vec fails build() with SchemaViolation, so call .anchors only with at least one AnchorEntry
.acdp_version(v) / .omit_acdp_version()acdp_versionemitted as ACDP_VERSION by default (see below)

Data references

DataRef describes where a context's underlying data lives — by URI, by embedded blob, or by structured locator. Use the constructors rather than building the struct by hand; they set the encoding and shape correctly.

use acdp::types::{DataRef, DataRefType};
# let content_hash = acdp::types::ContentHash::parse(
#     "sha256:0000000000000000000000000000000000000000000000000000000000000000",
# )?;

// By URI (most common)
DataRef::uri(DataRefType::PrimaryResult, "https://data.example.com/q1.parquet");

// By URI with a pre-known content hash (verified on fetch)
DataRef::uri_verified(DataRefType::PrimaryResult, "https://…", content_hash);

// Embedded inline — pick the encoding that matches your payload
DataRef::embedded_json(DataRefType::PrimaryResult, serde_json::json!({ "rows": 42 }));
DataRef::embedded_utf8(DataRefType::SupportingInfo, "free-form text");
DataRef::embedded_base64(DataRefType::RawData, "SGVsbG8=");
# Ok::<(), acdp::AcdpError>(())

Convenience shorthands exist too: DataRef::primary_result_uri(uri), raw_data_uri, supporting_info_uri, derived_data_uri, primary_result_json, derived_data_json.

Embedded size cap. Embedded content is bounded (64 KB — RFC-ACDP-0007 limits.max_embedded_bytes). Oversize embeds fail build() with AcdpError::EmbeddedTooLarge. For large data, reference by URI and set the DataRef's content_hash (as uri_verified does) so a consumer can verify the fetched bytes.

Data-reference hashes

A DataRef can carry two hashes, checked in different places:

FieldApplies toChecked
DataRef.content_hash (root, RFC-ACDP-0002 §6.1)location (URI) refsby the consumer after fetching, in fetch_and_verify_data_ref
EmbeddedContent.content_hash (embedded.content_hash, RFC-ACDP-0002 §6.3/§6.6)embedded refs: SHA-256 of the decoded embedded.content bytesat validation and publish time by validation::verify_embedded_hash, which build(), PublishValidator, and VerifiedContext all run

A mismatch on either is AcdpError::DataRefHashMismatch (wire data_ref_hash_mismatch), not the body-level HashMismatch. For an embedded ref, a root content_hash carries no verification obligation and is not checked; the embedded integrity check is embedded.content_hash only.

Supersession

A new version of an existing context supersedes the previous one. The preferred entry point is supersede_body, which propagates the version number and lineage id from the retrieved previous Body (RFC-ACDP-0003 §3.1):

# fn supersede(
#     producer: &acdp::producer::Producer,
#     previous: &acdp::types::Body,
# ) -> Result<(), acdp::AcdpError> {
// `previous` is the Body you retrieved for the current version.
let v2 = producer
    .supersede_body(&previous)        // sets supersedes, version+1, expected_lineage_id
    .title(previous.title.clone())
    .context_type(previous.context_type.clone())
    .summary("Updated with corrected April figures.")
    .build()?;
# Ok(()) }
MethodUse when
supersede_body(&prev)You have the full previous Body. Recommended — auto-sets version, supersedes, and expected_lineage_id.
new_version_from(&prev)Most fields stay the same; you only change data/summary/metadata. Carries every producer field over from prev, then you override what changed.
supersede(prev_ctx_id)You only have the previous ctx_id. You must also call .version(n) yourself.

v1 vs v2+ rule. expected_lineage_id MUST NOT appear on a v1 publish; on v2+ it is optional and lets the registry check the lineage you expect. The builder enforces the v1 rule — calling .expected_lineage_id(...) on a v1 request (or omitting .version() on a manual supersede) fails build(). Use supersede_body and you won't hit this.

Lineage vs. derived-from

Two different relationships, easy to confuse:

  • Lineage (supersedes / lineage_id) — successive versions of the same work. A lineage_id is derived from the v1 ctx_id and is stable across versions.
  • Derived-from (.derived_from(vec)) — this context was built using those other contexts as inputs. A provenance edge, not a version bump. The CrossRegistryResolver walks these.

The acdp_version field

Since 0.2.0 the builder emits acdp_version explicitly by default, set to acdp::ACDP_VERSION (the newest Final wire line; see the spec's VERSIONING.md). Use .acdp_version(v) to pin a different line. Conformant consumers treat an absent field as "0.1.0" (RFC-ACDP-0001 §6). To reproduce the 0.1.x omitted form, which is what the sig-001 golden vector was signed with, opt out:

# fn opt_out(builder: acdp::producer::RequestBuilder<'_>) -> acdp::producer::RequestBuilder<'_> {
builder.omit_acdp_version()   // drops the field, matching the 0.1.x wire form
# }

⚠️ The absent and explicit forms produce different content_hash values — the JCS byte sequences differ. Pick one convention and keep it consistent within a lineage, or supersession self-verification and round-trip tests will surprise you. New lineages should keep the explicit default.

Keyless signing (RFC-ACDP-0021)

The key id and key_attestation field (§6.1–§6.2) are Final at 0.5.0. The attestation request, POST /key-attestations (§5.1), is on the registry side and remains Draft.

With the keyless feature, a workload with no long-lived key can sign under its OIDC or SPIFFE identity:

use acdp::producer::keyless::EphemeralKey;
use acdp::types::keyless::IdentityDescriptor;

let key = EphemeralKey::generate();
// The token's `aud` must be the registry DID; it SHOULD carry
// cnf.jkt = key.jwk()?.thumbprint()?.
let req = key.attestation_request(
    "did:web:agents.example.com:ci",          // controller
    "did:web:registry.example.com",           // registry
    IdentityDescriptor::oidc(issuer, subject, token),
    None,                                     // default TTL (600 s)
)?;
let attestation = client.request_key_attestation(&req).await?;
let producer = key.into_producer(&attestation.body)?;
let publish = producer.publish_request().title("…").build()?;
client.publish(&publish).await?;               // same registry, inside the window

The controller's DID document must list the identity in an AcdpKeylessSigning service. The registry must advertise acdp-registry-keyless and acdp_version 0.5.0 or later. The key never leaves the process. build() adds key_attestation to the request, and the field is covered by content_hash.

What you get back

build() returns a PublishRequest with content_hash and signature populated. Serialize it and POST it:

# use acdp::{crypto::SigningKey, producer::Producer, types::AgentDid};
# let producer = Producer::new(
#     SigningKey::from_bytes(&[7u8; 32]),
#     AgentDid::new("did:web:agents.example.com:my-agent"),
#     "did:web:agents.example.com:my-agent#key-1",
# );
# let req = producer
#     .publish_request()
#     .title("Q1 2026 revenue snapshot")
#     .context_type(acdp::types::ContextType::DataSnapshot)
#     .build()?;
let json = serde_json::to_string_pretty(&req)?;   // the publish body
println!("{}", req.content_hash);                 // sha256:<hex>
println!("{} / {}", req.signature.algorithm, req.signature.key_id);
# Ok::<(), Box<dyn std::error::Error>>(())

To actually publish over HTTP, see Consuming & verifying → publishing or the acdp publish CLI command.