Implementing a Registry
This page is for people building an ACDP registry — a service that accepts
publishes, stores contexts, and serves retrieval/search. It covers the server
feature's building blocks. The normative registry behavior is specified in
RFC-ACDP-0003 (Publish),
RFC-ACDP-0004 (Retrieval),
RFC-ACDP-0005 (Discovery),
and RFC-ACDP-0007 (Capabilities & Errors).
cargo add acdp --features serverThis crate does not host a real server. It ships the validation and storage building blocks that separate
acdp-registry-*crates compose into a production service (with their own HTTP framework, database, auth, and rate limiting).InMemoryStoreis for tests and reference, not production.
The publish pipeline — the one rule
The single most important invariant: never persist a context before its
signature is verified (RFC-ACDP-0003 §2.1).
RegistryServer::publish_verified encodes the full, ordered pipeline (the
"§2.1 step" numbers are the spec's):
publish_verified(req, idempotency_key, resolver):
1. rate-limit gate ← before any expensive work (RFC-ACDP-0008 §4.3)
2. validate_post_schema ← §2.1 steps 1–5 + the key_id binding of step 6:
schema, size, embedded, content_hash recompute,
algorithm check
3. verify_publish_request_signature
← §2.1 steps 6–7: did:web key resolution
(assertionMethod) + signature verification
4. self-revocation check ← RFC-ACDP-0014 §5 step 2: a key-revocation body
must not be signed by the key it revokes
(acdp_version >= 0.3.0)
5. atomic commit via store ← §2.1 steps 8–12: identifiers, lineage,
idempotency lookup, predecessor check
(incl. the RFC-0014 §4 admission hook),
insert, supersession marking — one critical sectionThe §2.1 pre-step (request Content-Type, unsupported_media_type, fixture
err-002) happens before the body is parsed, so it is the HTTP host's job,
not this crate's.
# #[cfg(feature = "server")]
# async fn run(
# server: &acdp::registry::RegistryServer<acdp::registry::InMemoryStore>,
# resolver: &acdp::did::WebResolver,
# req: &acdp::PublishRequest,
# ) -> Result<(), acdp::AcdpError> {
let resp = server.publish_verified(req, None, resolver).await?;
println!("assigned {} v{}", resp.ctx_id, resp.version);
# Ok(()) }
RegistryServer::publish_unverified_for_testsexists for integration tests that can't run a live DID resolver. It is#[doc(hidden)], skips §2.1 steps 6–7, and is a protocol violation in production. Never call it from a real service.publish_unverified_in_tenant_for_testsis the same test-only bypass with an added idempotency key and tenant argument, for tests that need to exercise idempotent replay or tenant stamping without a live resolver.
RegistryServer
# #[cfg(feature = "server")]
# fn build(caps: acdp::CapabilitiesDocument) {
use acdp::registry::{RegistryServer, InMemoryStore};
let server = RegistryServer::new(
InMemoryStore::default(), // your RegistryStore impl
caps, // this registry's CapabilitiesDocument
"registry.example.com", // this registry's authority (host)
);
# }| Method | Role |
|---|---|
new(store, caps, authority) | Construct. Also try_new (validates caps) and try_new_for_test_authority. |
with_rate_limiter(limiter) | Swap in a RateLimiter (default NoopRateLimiter). |
with_receipt_signer(signer) | Mint an RFC-ACDP-0010 registry receipt atomically with each commit (acdp-registry-receipts). The signer's registry_did must match the capabilities. |
with_lineage_head_receipts() | Enable RFC-ACDP-0011 lineage-head receipts. Requires with_receipt_signer first. |
with_lifecycle() | Enable RFC-ACDP-0013 lifecycle events (acdp-registry-lifecycle, acdp_version ≥ 0.3.0). Needs a store that implements commit_lifecycle_event. A server without it never records lifecycle events, but its read paths do not filter them: do not run a lifecycle-disabled server over a store that already contains them. |
publish_verified(req, idem, resolver) | The conformant publish path (above). |
publish_verified_in_tenant(req, idem, resolver, tenant) | Same, binding the row to a tenant id for multi-tenant stores. |
publish_verified_did_key(req, idem) / publish_verified_did_key_in_tenant(...) | The same pipeline for did:key producers. Synchronous: key resolution is offline. Refused with KeyResolution unless the capabilities list did:key in supported_did_methods (fixture dk-003). |
publish_pinned_verified_in_tenant(...) | The same pipeline against a caller-supplied, already-verified public key and algorithm. |
publish_verified_in_tenant_with_outcome(...) / publish_verified_did_key_in_tenant_with_outcome(...) / publish_pinned_verified_in_tenant_with_outcome(...) | The three tenant publish forms, returning PublishCommitOutcome instead of a bare PublishResponse (see below). Use these when answering POST /contexts. |
prove_publish_identity(req, resolver) / _did_key(req) / _pinned(req, key, alg) | Split half of the publish pipeline — §2.1 steps 1–7 (identity; diagram steps 1–4) without persisting. Pairs with commit_proven. |
commit_proven(proven, idem, tenant) | The other half — the atomic store commit, given a Proven. |
retract_verified(event, requester, resolver) / republish_verified(...) (and _did_key twins) | RFC-ACDP-0013 lifecycle transitions on a signed LifecycleEvent. Require with_lifecycle(). |
prove_lifecycle_identity(event, endpoint, requester, resolver) / _did_key(event, endpoint, requester) | Split half of the lifecycle pipeline — §6 steps 1–3 plus the §5 signature check, without persisting. Pairs with commit_lifecycle_proven. |
commit_lifecycle_proven(proven) | The other half — the atomic transition + append, returning LifecycleCommitOutcome. |
retrieve / retrieve_body / lineage / current | Read paths (RFC-ACDP-0004). Each takes requester: Option<&AgentDid> for visibility filtering. |
search | Discovery (RFC-ACDP-0005). Same requester argument. |
store() / capabilities() | Accessors. |
Read authentication is the host's job. requester is the DID the host
has already authenticated, or None for an anonymous read; the server only
applies visibility rules to it. This crate does not verify any read
authentication method — including the registered bearer_jwt
(RFC-ACDP-0008 §6.2,
registries/auth-methods.md).
The client only presents tokens, through an AuthProvider. acdp-registry-rs
implements the server side; see its
bearer_jwt conformance notes.
The client side is covered in Security.
The did:web publish pipeline is async (it resolves DIDs over the network,
requiring the client feature transitively); the did:key and pinned forms
and the read paths are synchronous.
Insert vs. idempotent replay
PublishCommitOutcome tells a front-end which HTTP status to send:
| Variant | Meaning | Respond with |
|---|---|---|
Inserted(PublishResponse) | a fresh publish was persisted | 201 Created + Location |
IdempotentReplay(PublishResponse) | the same (agent_id, Idempotency-Key) and content_hash was already committed; this is the original response | 200 OK — never 201 (RFC-ACDP-0003 idem-002) |
is_replay(), response(), and into_response() read it. The publish entry
points without _with_outcome return into_response(), so they cannot make
this distinction.
Splitting prove from commit
publish_verified_in_tenant_with_outcome (and its _did_key/_pinned
siblings) are each a one-line composition of a prove_publish_identity* call
followed by commit_proven — the split is published, not just an internal
implementation detail, for callers that need to know identity was
cryptographically established before doing something else that shouldn't
happen for an unverified request (e.g. arming a rate-limit charge that's only
correct to apply once the producer is known to control the signing key) but
that also shouldn't happen twice if persistence is later skipped:
# #[cfg(all(feature = "server", feature = "client"))]
# async fn run(
# server: &acdp::registry::RegistryServer<acdp::registry::InMemoryStore>,
# resolver: &acdp::did::WebResolver,
# req: &acdp::PublishRequest,
# ) -> Result<(), acdp::AcdpError> {
let proven = server.prove_publish_identity(req, resolver).await?;
// ... identity is now established; safe to arm a side effect here ...
let outcome = server.commit_proven(proven, None, None)?;
# let _ = outcome; Ok(()) }Proven has no public constructor and is not Clone — the only way to get
one is a successful prove_publish_identity* call, and it's a move-only
value consumed by commit_proven: one proof commits once, by construction,
not by a runtime check rejecting a second attempt (the type system makes
a second attempt inexpressible — there's no second Proven to move).
commit_proven also rejects a Proven established against a
differently-configured RegistryServer, even one sharing the same
authority string — e.g. proving against an instance with no receipt
signer configured and committing on one that requires receipts — so a
"prove against server A, commit on server B" mixup fails loudly instead
of silently persisting under the wrong configuration.
Splitting prove from commit for lifecycle events
The lifecycle endpoints have the same split. retract_verified /
republish_verified (and their _did_key twins) are each a
prove_lifecycle_identity* call followed by commit_lifecycle_proven, so a
registry that charges a per-producer rate limit can charge after the event's
signature verifies and before anything is written, without verifying twice:
# #[cfg(all(feature = "server", feature = "client"))]
# async fn run(
# server: &acdp::registry::RegistryServer<acdp::registry::InMemoryStore>,
# resolver: &acdp::did::WebResolver,
# event: &acdp::types::lifecycle::LifecycleEvent,
# ) -> Result<(), acdp::AcdpError> {
use acdp::registry::{LifecycleCommitOutcome, LifecycleEndpoint};
let proven = server
.prove_lifecycle_identity(event, LifecycleEndpoint::Retract, None, resolver)
.await?;
// ... the producer is authenticated (proven.actor()); charge here ...
let replay = matches!(
server.commit_lifecycle_proven(proven)?,
LifecycleCommitOutcome::IdempotentReplay(_), // byte-identical event_id retry
);
# let _ = replay; Ok(()) }ProvenLifecycle follows the same rules as Proven: no public constructor,
not Clone, consumed by the commit. commit_lifecycle_proven re-checks that
lifecycle is enabled on the committing instance (NotImplemented otherwise)
and rejects a token proved against a different authority (RegistryInternal).
Proving checks visibility, event shape and endpoint binding, the actor rule,
and the signature. It does not check the retracted/republished
alternation, or whether the event_id was already appended: the store's
locked check at commit time is the only authoritative one. So a double
retract still fails at commit (InvalidLifecycleTransition), and a
byte-identical retry proves successfully and commits as IdempotentReplay.
A registry that charges between prove and commit therefore charges retries
and transitions that turn out to be illegal. That matches the publish split,
where an idempotent replay is also charged.
PublishValidator — validation without a server
If you have your own storage/transaction layer and only want the validation
half, use PublishValidator directly:
# #[cfg(feature = "server")]
# fn run(caps: &acdp::CapabilitiesDocument, req: &acdp::PublishRequest, raw_len: usize) -> Result<(), acdp::AcdpError> {
use acdp::registry::PublishValidator;
let validator = PublishValidator::for_authority(caps, "registry.example.com");
let validated = validator.validate_post_schema(req, raw_len)?; // schema + size + structure
// ... then you run signature verification and persist atomically yourself.
# let _ = validated; Ok(()) }validate_post_schema(req, raw_bytes)— schema, payload size, embedded size, and structural checks; returns aValidatedPublish.validate_structural(...)— the structural subset.assign_identifiers(...)— derivectx_id,lineage_id,created_at(RFC-ACDP-0003 §3.1).
PublishValidator does not verify the signature — call
acdp::verify::verify_publish_request_signature(req, resolver) for
that. RegistryServer wires the two together in the correct order; if you
compose them yourself, keep that order.
RegistryStore — pluggable persistence
RegistryStore is the trait you implement to back the server with a real
database. The critical method is commit_publish, which the server calls to
perform the entire post-verification commit as one atomic critical section:
| Method | Purpose |
|---|---|
put / get | basic context storage |
lineage / current / first_version_ctx_id | lineage navigation |
mark_superseded | flip a predecessor's status |
search | discovery query |
idempotency_lookup / idempotency_record / idempotency_evict_expired | Idempotency-Key handling (RFC-ACDP-0003 §6) |
commit_publish | idempotency lookup + predecessor verification + insert + supersession marking, atomically |
commit_lifecycle_event | persist an RFC-ACDP-0013 lifecycle event. The default returns NotImplemented; a store backing a with_lifecycle() server must implement it. |
PublishCommit::predecessor_admission. When the RFC-ACDP-0014 version gate applies and the publish setssupersedes, the server passes a hook inPublishCommit::predecessor_admission.commit_publishmust call it with the predecessor's storedBody, inside the same critical section, and only after its producer-continuity and tenant checks (calling it earlier leaks the predecessor's existence and type across tenants). AnErrmust abort the commit. A store that ignores the hook fails an RFC-ACDP-0014 §4 MUST.
Why
commit_publishis atomic. Two concurrent publishes against the samesupersedestarget (or the sameIdempotency-Key) must not both succeed.InMemoryStoredoes this under a single mutex; a SQL-backed store should do it in one transaction with the right isolation level. Splitting the steps (insert, then a separate "mark superseded" UPDATE) reopens the supersession race in RFC-ACDP-0008's threat model.
InMemoryStore is a complete reference implementation — read
crates/acdp-server/src/registry/store.rs to see exactly what commit_publish must guarantee.
Key-revocation publish gates (RFC-ACDP-0014)
PublishValidator and RegistryServer gate key-revocation publishes on the
acdp_version the registry advertises in its capabilities:
Advertised acdp_version | Behavior |
|---|---|
| < 0.3.0 | No RFC-ACDP-0014 checks. |
| [0.3.0, 0.5.0) | Full §4 validation of standard key-revocation bodies, plus the §4 rule that a revocation is superseded only by a revocation (rejected as SchemaViolation). The interim acdp:key-revocation form is not §4-validated, but it still gets the §5 not-self-signed and controller checks. |
| ≥ 0.5.0 (Draft) | As above, except a non-revocation superseding a revocation is rejected as SupersededTarget with reason RevocationTypeMismatch (details.reason: revocation_type_mismatch; see the spec's reason table), and a new publish of the interim acdp:key-revocation form is rejected as SchemaViolation. Already-stored interim bodies are still served. |
A malformed advertised version turns the gates on, not off.
acdp::registry::validator::key_revocation_gate_applies and
check_revocation_supersession are public for registries that compose the
pipeline themselves. The normative text is RFC-ACDP-0014
§4
and
§10,
with the 0.5.0 amendments summarized in the spec's
VERSIONING.md.
For a production registry built on these pieces, including adoption of the
prove_publish_identity* / commit_proven split, see acdp-registry-rs's
docs/ENGINEERING-LOG.md
and
docs/ARCHITECTURE.md.
Transparency log
acdp::registry::MerkleLog is an in-memory RFC 6962-style Merkle tree for
the RFC-ACDP-0012 transparency log: append, signed checkpoints,
inclusion_proof, and consistency_proof. It is a building block only — it
is not wired into RegistryServer or RegistryStore, so a registry
claiming acdp-registry-transparency-log owns committing the leaf atomically
with the body and receipt, and serving the log endpoints.
Rate limiting
Rate limiting is a registry responsibility (RFC-ACDP-0008 §4.3). The server
gates before any expensive work via the RateLimiter trait:
# #[cfg(feature = "server")]
# fn run() {
use acdp::registry::{RegistryServer, InMemoryStore, NoopRateLimiter};
# let caps = unimplemented!();
let server = RegistryServer::new(InMemoryStore::default(), caps, "registry.example.com")
.with_rate_limiter(NoopRateLimiter); // replace with a real per-agent limiter
# let _: RegistryServer<_, NoopRateLimiter> = server;
# }The default is NoopRateLimiter. A production registry MUST enforce a
per-producing-agent limit (RFC-ACDP-0008 §4.3), either by supplying a real
RateLimiter via with_rate_limiter or by enforcing its own limiter in the
host (for example at the HTTP layer, charging once identity is proven). The
RateLimiter trait is the building block this crate offers, not the only
conforming way to meet the requirement.
Capabilities & profiles
Your registry advertises what it supports via a CapabilitiesDocument served at
GET /.well-known/acdp.json (RFC-ACDP-0007). It MUST include ed25519 in
supported_signature_algorithms (identifiers per the spec's
signature-algorithms registry) and
did:web in supported_did_methods.
did:key is optional: add it to supported_did_methods to accept did:key
producers; without it, did:key publishes are refused (fixture dk-003).
The conformance profile(s) your registry claims determine which fixture set you
must pass. The registered profiles and their required endpoints and fixtures
are owned by the spec — see
registries/profiles.md
(machine-readable: registries/profiles.json) rather than a list here, which
would drift. acdp::profile::Profile is the typed vocabulary for the profiles
this crate models; it can lag the spec registry, so treat the spec as
authoritative. Conformance & testing covers running the
fixtures.