Implement a storage adapter
FederationStorage is the persistence boundary shared by Authorities, Leaf, OIDC, and Wallet. Pass one handle when you create a host. Pass storage directly to standalone operations through their options or service configuration. The specification assigns responsibilities such as issuing Subordinate Statements and verifying client assertions. The application chooses where to keep the data needed for those operations. Storage API
Declare the features you serve
| Feature | Storage required |
|---|---|
| Authority Fetch and List | Subordinate read |
| Managed registration, update, and revocation | Subordinate read and write plus a serializable transaction. Add event writes to the same boundary when capturing events. |
| Subordinate Events endpoint | Subordinate and event reads from a snapshot or transaction. |
| Trust Mark retrieval, listing, and status | Trust Mark read plus a consistent snapshot. |
| Managed Trust Mark issuance and revocation | Trust Mark read and write, a consistent snapshot, and serializable transactions. |
| Collection publication and pagination | Collection repository |
Federation private_key_jwt, automatic registration, hosted PAR, and JTI Client Attestation |
Replay repository |
| Discovery, Wallet trust operations, and Resolve | Optional cache |
A stateless Leaf or explicit-registration-only provider can run without storage. Attached roles and their calls use the host’s storage. Standalone PAR requires replay for Request Objects, client assertions, and JTI-based attestation.
Transactions and consistent reads
Bind subordinate, Trust Mark, and event data to the same transactional backend when a feature reads or writes them together. Return detached values and capture mutable input before waiting on a queue or database. Preserve finite host timestamps and event append order. Keep history after removing a subordinate registration.
Use serializable writes for the transaction capability. The callback can run again after a confirmed abort. Roll back all writes if it throws. Handle a lost commit acknowledgment according to the backend's commit protocol. Scoped read and write views close when the callback finishes. Collection publishes its anchor pointer and snapshot atomically through its own repository.
Managed Trust Mark issuance captures the complete candidate set and a revision in one snapshot. The service verifies candidate signatures and current eligibility after closing the snapshot. It then calls tx.trustMark.checkRevision(expected) before reuse or insertion. Every effective issuance or revocation must change the revision in the same write transaction. Compare full JWTs for exact identity even if an index uses a digest.
Subordinates
Order matching records lexicographically by exact Entity Identifier. Apply standard filters before paginating. With no page options, return all matches. The cursor points to the first unreturned position, and a request includes that position if it matches. An empty page may carry a continuation. When present, the continuation is strictly greater than the incoming cursor and every returned identifier.
Capture changes before queuing an update. Read the current registration, merge the changes, and validate the complete record in the same write transaction. Preserve the Entity Identifier and its creation time.
Keys
Keep private signing material in the host’s signer. Subordinate records and inline metadata JWKS hold public keys only. Apply the configured registry when validating deployment-specific public key types. Crypto context
Replay protection
Claim the tuple [issuer, audience, jti] atomically using the receiver's namespace. Use the absolute acceptance deadline supplied by the library, which can include clock skew. Check expiry in the atomic operation so an expired row can be replaced before cleanup. Keep live claims on capacity or timeout failures and fail closed. Include the same logical proof scope across replicas and routes where a proof can be replayed.
Cache
Cache entries may expire or be evicted. Store detached JSON and scope all operations, including clear, to the owning cache namespace. Protect cache writers because Resolve can sign responses based on stored assessment data. Resolve isolates its assessment keys per service instance, and a cached entry is still subject to evidence expiry.
Use composeFederationStorage when replay or cache lives on another backend. Supply the same logical namespace to each part. The host owns and closes its clients and pools. The host uses its own crypto context for signing.
Verify your adapter
The PostgreSQL example implements durable Collection storage. pnpm test:storage:memory runs the in-memory contract. pnpm test:storage:adapters compares independent clients and verifies that a Collection cursor resumes the same page after a database restart. PostgreSQL example · Migration guide
Cut over a durable deployment
- Inventory exact namespaces and clock policies, and back up subordinate records, Trust Mark JWTs and revocations, event history, Collection snapshots and cursors, and live replay claims. Record the current replay key encoding and the longest acceptance window including leeway.
- Prepare the new schema and validate persisted data. Preserve exact Entity Identifiers, timestamps including fractions, signed JWTs byte for byte, and event order including duplicates. Rebuild Trust Mark indexes using the production compact-token limits. Quarantine invalid rows and account for them before enabling readers.
- Keep all old and new writers coordinated during the cutover. Either make both versions enforce replay against the same live claim dataset using the original tuple and digest encoding, or pause acceptance of affected proofs, drain in-flight requests, and wait out the longest old acceptance window. Changing the endpoint URL alone leaves old proofs usable until expiry.
- Verify records and counts across namespaces, exact-token status, managed registration and event rollback, continuation cursors, and cross-instance replay. Preserve each cursor's original snapshot and expiry. If the new store cannot read old cursors, allow them to expire or document the required client restart before transfer.
- Switch the affected hosts together. Keep compatibility with the current replay dataset during rollback or repeat the pause-and-drain process. Reconcile writes since cutover before restoring an earlier schema. Cache entries may be discarded and rebuilt after the switch.
Run the adapter contract suite for any backend receiving live traffic. The PostgreSQL example illustrates transaction and replay behavior.
Provision a fresh schema or database for the payload layout. Validate each record on read and write, preserve permitted protocol extension fields, and put private JSON data in extensions.
Entity Identifiers containing raw whitespace, control characters, or backslashes now fail storage validation. Correct an invalid identifier through the normal enrollment process before importing the row. Preserve valid identifiers and their signed evidence exactly.
Import records into the PostgreSQL layout
For an installation that uses earlier PostgreSQL example tables, pause the hosts that write registrations, marks, events, Collection data, and replay claims. Stop accepting incoming replay-protected proofs during the transfer. Back up the original tables and identify their schema and exact namespaces.
- Provision the
oidfedschema in a fresh target database with the migration role. Keep the source tables available for transfer and rollback. - In an offline importer, read
namespace,kind,id, andpayloadfrom the original record table. In a temporary copy of the PostgreSQL example, reuse theoperationshelper with the migration connection and the host's validation settings. Call itssetmethod for each row inside a write transaction. It validates the payload and derives the namespace and record index keys, subordinate sort keys, and Trust Mark lookup rows. - Copy all kinds, including
markRevisionandcollectionSequence. Preserve the original replay digests and deadlines, event order, Collection pointers, and cursor IDs. The adapter initializes namespace guard rows on the first write. Treat any rejected payload as a migration failure to resolve before switching. - Verify counts per namespace and kind. Check exact Trust Mark status, a known Collection cursor, and rejection of a live replay claim against the target schema. Switch all replicas serving the same proof scope together. Use the replay cutover rules above if you need to switch back.
Repair a malformed subordinate registration
Pause managed writes for the affected namespace and take a backup. Identify the row by its exact Entity Identifier. Obtain the replacement public keys through your normal subordinate registration process and run the full replacement through parseStoragePayload("subordinate", id, replacement, "write", validationOptions) or your adapter's equivalent. Preserve the original Entity Identifier and creation time, and set the repair's update time.
Use a restricted administrative transaction to replace the row only if it still matches the row you inspected. Preserve its event history and record the repair in the operator audit log. Read the repaired record through the normal repository before resuming writes. If any step fails, leave the namespace paused until the record can be validated.
Rebuild Collection snapshots
If stored verifiedMarks items lack the exact JWT reference, pause Collection writes and back up the affected namespace. Remove the affected snapshots, their current pointers, and their cursors in one administrative transaction. In the PostgreSQL example these records use the collectionSnapshot, collectionCurrent, and collectionCursor kinds.
Refresh from verified evidence before serving Collection again. A client holding a removed cursor receives page_not_found and can start a new query.