Skip to content
Wallet and Entity Collection draft updates
Documentation menu

14.1. Build and query an Entity Collection

Feature guides / 14. Entity Collection · Example context

Maya's wallet needs a directory of membership issuers in Driving Licence Federation. It should not have to walk every branch before showing candidates, but a directory result must not become a trust decision.

How to use it

Configure collection on a Leaf, TrustAnchor, or Intermediate and advertise its endpoint. The host exposes its configured collection service for scheduled refreshes and in-process queries; handleRequest() routes its HTTP requests. The example also serves Resolve, following the Collection publisher recommendation. Directory results remain informational; a Wallet role must still discover and validate the chosen participant. Entity Collection Draft 01; Collection security.

import { Leaf } from "@oidfed/leaf";
import { entityId, type CryptoContext, type TrustAnchorSet } from "@oidfed/core";

export async function createLicenceDirectory(crypto: CryptoContext, anchors: TrustAnchorSet) {
  const publisher = await Leaf.create({
    entityId: "https://directory.licence-federation.example", authorityHints: ["https://licence-federation.example"],
    crypto, trustAnchors: anchors, resolver: {},
    metadata: { federation_entity: {
      federation_collection_endpoint: "https://directory.licence-federation.example/collection",
      federation_resolve_endpoint: "https://directory.licence-federation.example/resolve",
    } },
    collection: { trustAnchors: anchors },
  });
  const directory = publisher.collection;
  if (!directory) throw new Error("Collection was not configured");
  return {
    publisher,
    refresh: () => directory.refresh(entityId("https://licence-federation.example")),
    query: () => directory.query({
      trustAnchor: entityId("https://licence-federation.example"),
      entityType: ["openid_credential_issuer"], infoClaims: ["display_name"], limit: 25,
    }),
    handleRequest: (request: Request) => publisher.handleRequest(request),
  };
}

Search another provider

A remote directory consumer needs core's HTTP client; the Wallet role starts once the user selects a candidate. Here the client returns informational JSON and does not establish trust:

import type { CryptoEngine } from "@oidfed/crypto";
import { entityId, fetchEntityCollection } from "@oidfed/core";

export function findDrivingLicenceIssuers(engine: CryptoEngine, endpoint: string, from?: string) {
  return fetchEntityCollection(endpoint, {
    trustAnchor: entityId("https://licence-federation.example"),
    entityType: ["openid_credential_issuer"], infoClaims: ["display_name"], locale: ["en"], limit: 25,
    ...(from ? { from } : {}),
  }, { engine });
}

What your application owns

Provide durable snapshot/cursor storage, a refresh schedule, scope policy, and multi-process coordination when needed. Requests query snapshots rather than triggering traversal. Pass a response's opaque next cursor as the next request's from value while preserving its filters. entityType, trustMarkType, query, entityClaims, infoClaims, and locale offer distinct selection controls. Custom collectors and filters may narrow eligibility; extra informational claims must be declared consistently at production and consumption. The default collector verifies eligible chains; custom collectors own their input and eligibility rules. Trust Mark type filtering requires every requested type (AND). Returned marks remain unverified from the reader's perspective. Preserve the previous snapshot when refresh cannot complete, and monitor its age.

For LIGO Wiki, a Collection URL with a fixed entity_type filter returns the same subset over GET and POST. Configure that URL as the service’s endpoint; conflicting caller filters are rejected. Reordering a repeatable filter or repeating an identical value does not change its meaning, so those requests are accepted. Anonymous requests may use either method, while authenticated requests use POST. Both shared authentication and the existing prebuilt clientAssertion are supported, but cannot be combined.

Adapting the directory

A custom inventory can provide entity_infos without repeating every type in entity_types. The service combines both sources before storing the snapshot, so Maya can still find an issuer through the type filter. Requested claims continue to control what the response exposes.

Driving Licence Federation can also choose how a query matches an issuer name:

import type { LeafConfig } from "@oidfed/leaf";

export const directoryPolicy: NonNullable<LeafConfig["collection"]>["queryMatcher"] = (query, entity) => {
  const name = entity.entity_infos?.openid_credential_issuer?.display_name;
  return typeof name === "string" && name.toLowerCase().startsWith(query.toLowerCase());
};
// Add queryMatcher: directoryPolicy to the publisher's collection configuration above.

The callback receives frozen snapshot data and returns a boolean synchronously. Keep matching deterministic across pages. Collect external search data during refresh instead of fetching it from the matcher. Without this option, the service retains its case-insensitive substring search.

Suppose the alliance accepts a membership accreditation from a separate federation. Set options.trustMarkVerification to { mode: "resolve", trustAnchors: accreditationAnchors }, or use mode: "provided" with previously verified issuer evidence or an explicitly trusted out-of-band issuer. The default remains verification under the collection anchor. The exact mark must still be published by its holder and pass signature, delegation, and validity checks. See accreditation settings.

An aborted refresh returns promptly even when waiting behind another refresh. Later refreshes stay in order, and incomplete work does not replace the last snapshot. Put custom authentication parameters in the POST body (or use the registered method’s credential headers): the service rejects registered credential names in the URL even if anonymous access is also enabled.

Refresh a snapshot before serving searches

eduGAIN's collection service gathers participant information under its configured policy and stores a snapshot for requests. Keep collection refresh scheduling separate from individual user searches so an anonymous search does not trigger an uncontrolled federation crawl.

Treat custom collector output as input to the same ingestion rules as ordinary discovery. Verify that exposed entity types and information remain consistent after claim selection. Consumers must still establish their own trust in an entry before registration or another sensitive action; a collection response is useful discovery information, not pre-authorized access.

Collection entries and refresh evidence

Use EntityCollectionService to refresh Draft 01 collections, query them in process, and handle Web-standard HTTP requests. Supply a handle with storage.entityCollection for snapshots and cursors. Enable entityCollection on MemoryFederationStorage to develop locally. The fetchEntityCollection client retrieves unsigned informational JSON from collection providers, including independent applications. See the Entity Collection guide for the APIs, filters, authentication, storage, and defaults.

When cancellation or a work limit stops resolution, resolveTrustChains reports incomplete: true alongside its chains and errors. Collection refresh rejects these incomplete results. Pass a signal to createConcurrencyLimiter(maxConcurrent, signal?) to cancel queued work. When caching calls to fetchSubordinateStatement, supply the actual Entity Identifier as issuer in the options to distinguish authorities hosted on the same origin.

Collection configuration accepts an optional collector for application inventories and a filter for additional restrictions. queryMatcher lets hosts define synchronous search over frozen snapshot data; the default remains case-insensitive substring matching. Custom inventories have their known entity types reconciled before storage. Collection honors explicit options.trustMarkVerification accreditation settings while retaining same-anchor verification by default. Queued refresh cancellation settles the caller promptly without allowing later refreshes to overtake active work. Core validates collector output and verifies the marks used for filtering. EntityCollectionCandidate contains informational entity data and an eligibility deadline; CollectionEntry adds optional chain evidence and core-verified mark evidence. The collection policy examples cover independent sources and snapshot-time filters. Chain validation and Trust Mark evaluation have separate results, as described above.

For operations that contact several entities, supply options.getEndpointAuthentication({ endpoint, responder, signal }). Choose credentials from your application's approved endpoint/entity configuration, or return undefined for anonymous access. A callback error stops that request. Use this callback instead of static authentication; Entity Configuration discovery remains anonymous GET. The Collection guide shows how LIGO Wiki can choose credentials for each authority.

Next: 14.2. Operate an Entity Collection

View source on GitHub