8.3. Choose a validated path for a partner
Feature guides / 8. Discovery and caching · Example context
LIGO Wiki can reach Umeå University OP through more than one anchor. The shortest path may be convenient, while a registration exchange or an offline recipient may need a particular shared anchor.
How to use it
The host's discoverEntity() returns the shortest valid chain by default. Set chainSelection to shortestChain, longestExpiry, preferTrustAnchor(...), or your own synchronous callback to choose among eligible chains. Leaf, Intermediate, and TrustAnchor carry this setting in their options; protocol roles can override it, and a call can override the role. Core exports the reusable selectors; supplying one does not require manually orchestrating candidate validation. resolveTrustChainForAnchor() performs resolution and validation for a selected pre-trusted anchor. Shared recipient anchor.
import { Leaf } from "@oidfed/leaf";
import { entityId, preferTrustAnchor, type CryptoContext, type TrustAnchorSet } from "@oidfed/core";
export async function ligoWikiWithPreferredPath(keys: CryptoContext, trustAnchors: TrustAnchorSet) {
const ligoWiki = await Leaf.create({
entityId: "https://wiki.ligo.example", authorityHints: ["https://incommon.example"],
crypto: keys, trustAnchors, metadata: { federation_entity: {} },
options: { chainSelection: preferTrustAnchor("https://edugain.example") },
});
return {
ligoWiki,
discoverUmeaOp: () => ligoWiki.discoverEntity(entityId("https://op.umu.example")),
};
}
The factory above sets a campus preference for the host. Override it for one operation when a different ranking is appropriate:
import type { Leaf } from "@oidfed/leaf";
import { entityId, longestExpiry } from "@oidfed/core";
export function chooseLongerLivedPath(ligoWiki: Leaf) {
return ligoWiki.discoverEntity(entityId("https://op.umu.example"), {
chainSelection: longestExpiry,
});
}
Driving Licence Federation can use the same option in its Wallet roles. When a customer presents a signed request, the library validates the request and applies contextual policy before offering eligible paths to the selector. A preferred path cannot override the recipient's required anchor or allow an unregistered response endpoint.
A Trust Mark issuer may belong to a different accreditation framework and need not offer Umeå University OP's OP service or a Driving Licence Federation wallet service. Protocol filters apply to the entity being assessed. Your selector may also be called for an accreditation issuer's eligible paths; use the candidate's entityId when the choice depends on who is being evaluated.
Discovery and candidate validation share the HTTP allowance, which defaults to 50 calls. A custom selection fails if resource limits prevent discovery from completing. You can increase the limit for a larger topology. Core helpers also accept a zero-fetch allowance when all evidence is supplied or cached.
What your application owns
Decide which anchors your application accepts before selecting a path. A ranking helper does not turn an unvalidated candidate into trusted evidence. Keep the selected anchor and expiry with the decision, and handle the absence of a valid path explicitly. A longer expiry does not imply stronger accreditation or a more appropriate recipient.
Select only from eligible candidates
LIGO Wiki might prefer eduGAIN's regional path for a particular operation. Apply that preference to candidates that already satisfy the operation's chain and protocol checks. Shared-anchor registration must first find compatible RP and OP paths; a preference cannot make incompatible anchors compatible.
Keep selectors synchronous and choose a candidate provided by the library. Returning a copied or fabricated chain does not preserve authenticated evidence. If discovery is incomplete, a custom selection may fail rather than claim to have evaluated the full choice. Make that distinction visible in operational diagnostics.
Configure selection across federation operations
A federation can offer several paths to the same entity. Those paths may produce different metadata. chainSelection lets the application choose among chains that passed the operation's validation:
Use the per-call override above to change selection for one operation. Attached OIDC and Wallet roles accept the same chainSelection option in their own trust options.
You can also supply shortestChain, longestExpiry, or a synchronous callback. Return one of the candidates received by that callback. Candidate contents are detached and frozen; sorting the callback's array is allowed. Throws, asynchronous returns, and foreign results produce errors. preferTrustAnchor is a preference with a fallback, not an anchor allowlist: restrict anchors when an anchor is mandatory.
The option reaches discovery, refresh, peer-chain selection, issuer discovery, Resolve hosting, and protocol operations. Protocol consumers first apply their metadata, shared-anchor, and request requirements. Wallet request selection waits for contextual policy completion. Fresh cached chains keep their existing assessment until refresh is requested or required. Discovery and candidate validation share one HTTP allowance. The default maxTotalFetches: 50 covers the combined work; it is not renewed for each phase or candidate. If a deployment previously relied on separate allowances, it may need a larger configured limit. Cached and supplied evidence consume no allowance. Core discovery, supplied-chain discovery, refresh, and peer-chain helpers accept maxTotalFetches: 0: they can use available evidence, but a missing document fails before transport is called.
A custom selector only runs after discovery completes within the configured limits. If a limit truncates discovery, the operation returns an error rather than asking the callback to rank a partial candidate set. Resolve hosting returns HTTP 503 with temporarily_unavailable and does not cache a successful assessment. This is oidfed's selection contract; Federation §10.3 permits local selection policy without requiring exhaustive discovery.