11.1. Persist federation state with transaction guarantees
Feature guides / 11. Operating a federation application · Example context
An enrollment at eduGAIN can change a subordinate record and its event history together. A database failure must not leave the public event stream claiming an enrollment that never committed.
How to use it
Connect the application's FederationStorage when constructing its TrustAnchor or Intermediate, then use the host's enrollment and lifecycle methods. Those operations validate publication claims and coordinate transaction and event behavior. The bundled MemoryFederationStorage is for local examples; a deployment supplies a durable adapter implementing the same contracts. Federation relationships; Federation endpoints.
import { TrustAnchor } from "@oidfed/authority";
import { entityId, type CryptoContext, type FederationStorage, type JWKSet } from "@oidfed/core";
export async function eduGainWithStorage(crypto: CryptoContext, storage: FederationStorage) {
const eduGain = await TrustAnchor.create({
entityId: "https://edugain.example", crypto, storage,
metadata: { federation_entity: {
federation_fetch_endpoint: "https://edugain.example/fetch",
federation_list_endpoint: "https://edugain.example/list",
} },
});
return {
eduGain,
enrollSwamid: (jwks: JWKSet) => eduGain.registerSubordinate({
entityId: entityId("https://swamid.example"), jwks, entityTypes: ["federation_entity"], isIntermediate: true,
}),
};
}
What your application owns
Choose durable storage, namespace it by authority, return detached records, and provide atomic commit and rollback. Honor ordering and cursor contracts even for empty filtered pages. Use the Authority lifecycle methods for normal writes so publication validation and event handling run. Authority storage does not automatically persist OP registrations or wallet application state. The specifications leave database technology to the operator.
Separate durable state from acceleration
eduGAIN's subordinate and Trust Mark records are authoritative state. A discovery cache is replaceable acceleration. Losing the first can change what the federation publishes; losing the second should trigger bounded retrieval rather than inventing new trust.
Use the memory adapters for local examples, then implement the same contracts over deployment storage. Test transaction rollback, concurrent issuance, copied snapshots, and process restart. Queued writes must use captured inputs rather than objects the caller can mutate while waiting. See the durable-adapter guide for the individual stores and their transaction boundaries.
Trust Mark issuer storage
Leaf and Authority issuer hosting share TrustMarkStore. Durable adapters provide serializable transaction and consistent readSnapshot operations. candidates({ issuer, trustMarkType?, subject? }) returns all matching records, including revoked and superseded marks. The service verifies candidates before selecting an eligible JWT. Adapter guide