{"version":3,"sources":["../src/index.ts","../package.json","../src/commands/chain.ts","../src/util/entity-id.ts","../src/util/trust-anchors.ts","../src/commands/decode.ts","../src/commands/entity.ts","../src/commands/expiry.ts","../src/commands/fetch.ts","../src/util/discover-endpoint.ts","../src/commands/health.ts","../src/commands/keygen.ts","../src/commands/list.ts","../src/commands/list-extended.ts","../src/commands/resolve.ts","../src/commands/sign.ts","../src/commands/trust-mark-list.ts","../src/commands/trust-mark-status.ts","../src/commands/validate.ts","../src/commands/verify.ts","../src/config.ts","../src/output/colors.ts","../src/output/human.ts","../src/output/json.ts","../src/output/index.ts","../src/util/exit.ts","../src/util/http.ts","../src/util/logger.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport * as chainCmd from \"./commands/chain.js\";\nimport * as decodeCmd from \"./commands/decode.js\";\nimport * as entityCmd from \"./commands/entity.js\";\nimport * as expiryCmd from \"./commands/expiry.js\";\nimport * as fetchCmd from \"./commands/fetch.js\";\nimport * as healthCmd from \"./commands/health.js\";\nimport * as keygenCmd from \"./commands/keygen.js\";\nimport * as listCmd from \"./commands/list.js\";\nimport * as listExtendedCmd from \"./commands/list-extended.js\";\nimport * as resolveCmd from \"./commands/resolve.js\";\nimport * as signCmd from \"./commands/sign.js\";\nimport * as trustMarkListCmd from \"./commands/trust-mark-list.js\";\nimport * as trustMarkStatusCmd from \"./commands/trust-mark-status.js\";\nimport * as validateCmd from \"./commands/validate.js\";\nimport * as verifyCmd from \"./commands/verify.js\";\nimport { DEFAULT_CONFIG, loadConfig } from \"./config.js\";\nimport { createFormatter } from \"./output/index.js\";\nimport { ExitCode } from \"./util/exit.js\";\nimport { createHttpClient } from \"./util/http.js\";\nimport { createLogger } from \"./util/logger.js\";\n\nexport { type Config, DEFAULT_CONFIG, loadConfig } from \"./config.js\";\nexport { createFormatter, type OutputFormatter } from \"./output/index.js\";\nexport { ExitCode, resultToExitCode } from \"./util/exit.js\";\nexport { createHttpClient } from \"./util/http.js\";\nexport { createLogger, type Logger } from \"./util/logger.js\";\n\nexport interface ProgramOptions {\n\treadonly json?: boolean | undefined;\n\treadonly quiet?: boolean;\n\treadonly verbose?: boolean;\n\treadonly config?: string;\n}\n\nexport function createProgram(): Command {\n\tconst program = new Command();\n\n\tprogram\n\t\t.name(\"oidfed\")\n\t\t.description(\"OpenID Federation CLI — fetch, resolve, validate trust chains\")\n\t\t.version(pkg.version)\n\t\t.option(\"--json\", \"Output raw JSON (machine-readable, suitable for piping to jq)\")\n\t\t.option(\"-q, --quiet\", \"Suppress informational output\", false)\n\t\t.option(\"-v, --verbose\", \"Enable debug output\", false)\n\t\t.option(\"-c, --config <path>\", \"Path to config file\");\n\n\treturn program;\n}\n\nexport async function run(argv: string[]): Promise<number> {\n\tconst program = createProgram();\n\tprogram.parseOptions(argv);\n\n\tconst opts = program.opts<ProgramOptions>();\n\n\tconst formatter = createFormatter({ json: opts.json });\n\tconst logger = createLogger({\n\t\tquiet: opts.quiet ?? false,\n\t\tverbose: opts.verbose ?? false,\n\t});\n\n\tconst configResult = await loadConfig(opts.config);\n\tlet config = DEFAULT_CONFIG;\n\tif (configResult.ok) {\n\t\tconfig = configResult.value;\n\t} else {\n\t\tlogger.warn(`Config load failed (using defaults): ${configResult.error.description}`);\n\t}\n\tconst httpClient = createHttpClient(config.http_timeout_ms);\n\tconst fileReader = (path: string) => readFile(path, \"utf-8\");\n\n\tentityCmd.register(program, { httpClient, formatter, logger });\n\tdecodeCmd.register(program, { formatter, logger });\n\tkeygenCmd.register(program, { formatter, logger });\n\tsignCmd.register(program, { formatter, logger, readFile: fileReader });\n\tchainCmd.register(program, { httpClient, formatter, logger, config });\n\tresolveCmd.register(program, { httpClient, formatter, logger, config });\n\tvalidateCmd.register(program, { httpClient, formatter, logger, config });\n\texpiryCmd.register(program, { httpClient, formatter, logger, config });\n\tfetchCmd.register(program, { httpClient, formatter, logger });\n\tlistCmd.register(program, { httpClient, formatter, logger });\n\tlistExtendedCmd.register(program, { httpClient, formatter, logger });\n\ttrustMarkStatusCmd.register(program, { httpClient, formatter, logger });\n\ttrustMarkListCmd.register(program, { httpClient, formatter, logger });\n\thealthCmd.register(program, { httpClient, formatter, logger, readFile: fileReader });\n\tverifyCmd.register(program, { httpClient, formatter, logger, readFile: fileReader });\n\n\ttry {\n\t\tawait program.parseAsync(argv, { from: \"user\" });\n\t\treturn process.exitCode ? Number(process.exitCode) : ExitCode.OK;\n\t} catch {\n\t\treturn ExitCode.FEDERATION_ERROR;\n\t}\n}\n","{\n\t\"name\": \"@oidfed/cli\",\n\t\"version\": \"1.0.0\",\n\t\"description\": \"Command-line interface for inspecting, validating, and debugging OpenID Federation deployments — resolve trust chains, decode entity statements, verify signatures, and more.\",\n\t\"license\": \"Apache-2.0\",\n\t\"author\": \"Justin Dah-kenangnon <dah.kenangnon@gmail.com>\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/Dahkenangnon/oidfed.git\",\n\t\t\"directory\": \"tools/cli\"\n\t},\n\t\"homepage\": \"https://github.com/Dahkenangnon/oidfed/tree/main/tools/cli#readme\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/Dahkenangnon/oidfed/issues\"\n\t},\n\t\"keywords\": [\n\t\t\"openid-federation\",\n\t\t\"openid federation\",\n\t\t\"trust chain\",\n\t\t\"trust-chain\",\n\t\t\"entity-statement\",\n\t\t\"oauth2\",\n\t\t\"oidc\",\n\t\t\"federation\",\n\t\t\"eidas\",\n\t\t\"edugain\",\n\t\t\"federated-identity\",\n\t\t\"trust-mark\",\n\t\t\"subordinate-statement\",\n\t\t\"trust-anchor\",\n\t\t\"cli\"\n\t],\n\t\"type\": \"module\",\n\t\"main\": \"./dist/index.cjs\",\n\t\"module\": \"./dist/index.js\",\n\t\"types\": \"./dist/index.d.ts\",\n\t\"bin\": {\n\t\t\"oidfed\": \"./dist/bin.js\",\n\t\t\"openidfed\": \"./dist/bin.js\"\n\t},\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.ts\",\n\t\t\t\"import\": \"./dist/index.js\",\n\t\t\t\"require\": \"./dist/index.cjs\"\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"LICENSE\",\n\t\t\"NOTICE\"\n\t],\n\t\"sideEffects\": false,\n\t\"engines\": {\n\t\t\"node\": \">=22.12.0\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsup\",\n\t\t\"typecheck\": \"tsc --noEmit\",\n\t\t\"test\": \"vitest run\",\n\t\t\"clean\": \"rm -rf dist\"\n\t},\n\t\"dependencies\": {\n\t\t\"@oidfed/core\": \"workspace:^\",\n\t\t\"commander\": \"15.0.0\",\n\t\t\"yaml\": \"2.9.0\",\n\t\t\"chalk\": \"5.6.2\",\n\t\t\"zod\": \"4.4.3\"\n\t}\n}\n","import {\n\tchainRemainingTtl,\n\tcheckConstraints,\n\tdecodeEntityStatement,\n\tdescribeTrustChain,\n\ttype HttpClient,\n\tisChainExpired,\n\tlongestExpiry,\n\tok,\n\ttype ParsedEntityStatement,\n\ttype Result,\n\tresolveMetadataPolicy,\n\tshortestChain,\n\tvalidateTrustChain,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { Config } from \"../config.js\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\nimport { requireAnchorIds, resolveOrError } from \"../util/trust-anchors.js\";\n\nexport interface ChainDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly config: Config;\n}\n\nexport interface ChainArgs {\n\treadonly entityId: string;\n\treadonly trustAnchors: readonly string[];\n\treadonly maxDepth?: number | undefined;\n\treadonly strategy?: \"shortest\" | \"longest-expiry\" | undefined;\n}\n\nexport async function handler(args: ChainArgs, deps: ChainDeps): Promise<Result<string>> {\n\tconst anchorResult = requireAnchorIds(args.trustAnchors, deps.config);\n\tif (!anchorResult.ok) return anchorResult;\n\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tconst resolveResult = await resolveOrError(\n\t\teid,\n\t\tanchorResult.value,\n\t\tdeps.httpClient,\n\t\targs.maxDepth ?? deps.config.max_chain_depth,\n\t\tdeps.config,\n\t);\n\tif (!resolveResult.ok) return resolveResult;\n\tconst { anchors, result: resolved } = resolveResult.value;\n\n\tconst validatedChains = [];\n\tconst results = [];\n\tfor (const chain of resolved.chains) {\n\t\tconst validationResult = await validateTrustChain([...chain.statements], anchors);\n\t\tif (validationResult.valid) {\n\t\t\tvalidatedChains.push(validationResult.chain);\n\n\t\t\t// Decode statements for policy/constraints\n\t\t\tconst decoded = chain.statements.map((s) => decodeEntityStatement(s));\n\t\t\tconst parsedStatements: ParsedEntityStatement[] = [];\n\t\t\tfor (const d of decoded) {\n\t\t\t\tif (d.ok) parsedStatements.push(d.value);\n\t\t\t}\n\n\t\t\t// Resolve metadata policy\n\t\t\tlet policy: unknown;\n\t\t\tif (parsedStatements.length > 0) {\n\t\t\t\tconst policyResult = resolveMetadataPolicy(parsedStatements);\n\t\t\t\tif (policyResult.ok) {\n\t\t\t\t\tpolicy = policyResult.value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check constraints\n\t\t\tconst constraintResults: { position: number; status: string; error?: string | undefined }[] =\n\t\t\t\t[];\n\t\t\tfor (let i = 0; i < parsedStatements.length; i++) {\n\t\t\t\tconst stmt = parsedStatements[i];\n\t\t\t\tif (!stmt) continue;\n\t\t\t\tconst payload = stmt.payload as Record<string, unknown>;\n\t\t\t\tconst constraints = payload.constraints as\n\t\t\t\t\t| Parameters<typeof checkConstraints>[0]\n\t\t\t\t\t| undefined;\n\t\t\t\tif (constraints) {\n\t\t\t\t\tconst check = checkConstraints(constraints, i, parsedStatements);\n\t\t\t\t\tconstraintResults.push({\n\t\t\t\t\t\tposition: i,\n\t\t\t\t\t\tstatus: check.ok ? \"pass\" : \"fail\",\n\t\t\t\t\t\t...(check.ok ? {} : { error: check.error.description }),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresults.push({\n\t\t\t\tdescription: describeTrustChain(validationResult.chain),\n\t\t\t\texpired: isChainExpired(validationResult.chain),\n\t\t\t\tremaining_ttl_seconds: chainRemainingTtl(validationResult.chain),\n\t\t\t\tentity_id: validationResult.chain.entityId,\n\t\t\t\ttrust_anchor_id: validationResult.chain.trustAnchorId,\n\t\t\t\tstatements: validationResult.chain.statements.length,\n\t\t\t\twarnings: validationResult.errors.length,\n\t\t\t\ttrust_chain: [...chain.statements],\n\t\t\t\t...(policy ? { metadata_policy: policy } : {}),\n\t\t\t\t...(constraintResults.length > 0 ? { constraints: constraintResults } : {}),\n\t\t\t});\n\t\t} else {\n\t\t\tresults.push({\n\t\t\t\tdescription: \"invalid\",\n\t\t\t\terrors: validationResult.errors.map((e) => e.message),\n\t\t\t});\n\t\t}\n\t}\n\n\t// Apply selection strategy if specified and multiple valid chains\n\tif (args.strategy && validatedChains.length > 1) {\n\t\tconst selector = args.strategy === \"shortest\" ? shortestChain : longestExpiry;\n\t\tconst selected = selector(validatedChains);\n\t\tconst selectedIdx = validatedChains.indexOf(selected);\n\t\tif (selectedIdx >= 0) {\n\t\t\treturn ok(\n\t\t\t\tdeps.formatter.format({ selected: results[selectedIdx], all_chains: results.length }),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn ok(deps.formatter.format(results));\n}\n\nexport function register(program: Command, deps: ChainDeps): void {\n\tprogram\n\t\t.command(\"chain\")\n\t\t.description(\"Resolve and validate trust chains for an entity\")\n\t\t.argument(\"<entity-id>\", \"Entity identifier (URL)\")\n\t\t.option(\n\t\t\t\"-t, --trust-anchor <url>\",\n\t\t\t\"Trust anchor entity IDs (repeatable)\",\n\t\t\t(v: string, a: string[]) => [...a, v],\n\t\t\t[] as string[],\n\t\t)\n\t\t.option(\"--max-depth <n>\", \"Maximum chain depth\", Number.parseInt)\n\t\t.option(\"--strategy <type>\", \"Chain selection: shortest or longest-expiry\")\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tentityIdArg: string,\n\t\t\t\topts: { trustAnchor: string[]; maxDepth?: number; strategy?: string },\n\t\t\t) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: entityIdArg,\n\t\t\t\t\t\ttrustAnchors: opts.trustAnchor,\n\t\t\t\t\t\tmaxDepth: opts.maxDepth,\n\t\t\t\t\t\tstrategy: opts.strategy as \"shortest\" | \"longest-expiry\" | undefined,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import {\n\ttype EntityId,\n\tentityId,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\ttype JWKSet,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\n\nexport function parseEntityIdOrError(raw: string): Result<EntityId> {\n\ttry {\n\t\treturn ok(entityId(raw));\n\t} catch (e) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\te instanceof Error ? e.message : \"Invalid entity ID\",\n\t\t\t),\n\t\t);\n\t}\n}\n\n/**\n * Extract JWKS from an Entity Configuration payload.\n * Entity Configurations MUST contain `jwks`.\n */\nexport function extractJwks(payload: Record<string, unknown>): Result<JWKSet> {\n\tconst jwks = payload.jwks as JWKSet | undefined;\n\tif (!jwks?.keys) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\"Entity Configuration missing required jwks\",\n\t\t\t),\n\t\t);\n\t}\n\treturn ok(jwks);\n}\n","import {\n\tdecodeEntityStatement,\n\ttype EntityId,\n\tentityId,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchEntityConfiguration,\n\ttype HttpClient,\n\ttype JWKSet,\n\tJWKSetSchema,\n\tok,\n\ttype Result,\n\tresolveTrustChains,\n\ttype TrustAnchorSet,\n\ttype TrustChainResult,\n} from \"@oidfed/core\";\nimport type { Config } from \"../config.js\";\nimport { extractJwks } from \"./entity-id.js\";\n\n/**\n * Build a TrustAnchorSet from a list of anchor entity IDs.\n *\n * If the operator has supplied a JWKS for an anchor in the config (the\n * independent out-of-band retrieval mechanism), that JWKS is used directly\n * after schema validation. Otherwise the anchor's Entity Configuration is\n * fetched and its embedded `jwks` is extracted.\n */\nexport async function buildTrustAnchors(\n\tanchorIds: readonly string[],\n\thttpClient: HttpClient,\n\tconfig?: Config,\n): Promise<Result<TrustAnchorSet>> {\n\tconst configIndex = new Map<string, JWKSet | undefined>();\n\tif (config) {\n\t\tfor (const ta of config.trust_anchors) {\n\t\t\tif (ta.jwks) {\n\t\t\t\tconst parsed = JWKSetSchema.safeParse(ta.jwks);\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\treturn err(\n\t\t\t\t\t\tfederationError(\n\t\t\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t\t\t`Config-supplied JWKS for trust anchor ${ta.entity_id} is invalid: ${parsed.error.message}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconfigIndex.set(ta.entity_id, parsed.data);\n\t\t\t} else {\n\t\t\t\tconfigIndex.set(ta.entity_id, undefined);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst anchors = new Map<EntityId, Readonly<{ jwks: JWKSet }>>();\n\tfor (const anchor of anchorIds) {\n\t\tlet eid: EntityId;\n\t\ttry {\n\t\t\teid = entityId(anchor);\n\t\t} catch {\n\t\t\treturn err(\n\t\t\t\tfederationError(FederationErrorCode.InvalidRequest, `Invalid trust anchor ID: ${anchor}`),\n\t\t\t);\n\t\t}\n\n\t\tconst configuredJwks = configIndex.get(anchor);\n\t\tif (configuredJwks) {\n\t\t\tanchors.set(eid, { jwks: configuredJwks });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst ecResult = await fetchEntityConfiguration(eid, { httpClient });\n\t\tif (!ecResult.ok) {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Failed to fetch entity configuration for trust anchor ${anchor}: ${ecResult.error.description}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst decoded = decodeEntityStatement(ecResult.value);\n\t\tif (!decoded.ok) {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Failed to decode entity configuration for trust anchor ${anchor}: ${decoded.error.description}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst payload = decoded.value.payload as Record<string, unknown>;\n\t\tconst jwksResult = extractJwks(payload);\n\t\tif (!jwksResult.ok) {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Trust anchor ${anchor} missing required jwks: ${jwksResult.error.description}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tanchors.set(eid, { jwks: jwksResult.value });\n\t}\n\treturn ok(anchors as unknown as TrustAnchorSet);\n}\n\nexport function resolveAnchorIds(args: readonly string[], config: Config): readonly string[] {\n\treturn args.length > 0 ? args : config.trust_anchors.map((ta) => ta.entity_id);\n}\n\nexport function requireAnchorIds(\n\targs: readonly string[],\n\tconfig: Config,\n): Result<readonly string[]> {\n\tconst anchorIds = resolveAnchorIds(args, config);\n\tif (anchorIds.length === 0) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\"No trust anchors specified. Use --trust-anchor or configure trust_anchors in config.\",\n\t\t\t),\n\t\t);\n\t}\n\treturn ok(anchorIds);\n}\n\nexport interface ResolvedTrustData {\n\treadonly anchors: TrustAnchorSet;\n\treadonly result: TrustChainResult;\n}\n\n/**\n * Build trust anchors, resolve trust chains, and check that at least one chain exists.\n *\n * Shared by resolve, chain, validate, and expiry CLI commands.\n */\nexport async function resolveOrError(\n\teid: EntityId,\n\tanchorIds: readonly string[],\n\thttpClient: HttpClient,\n\tmaxChainDepth?: number,\n\tconfig?: Config,\n): Promise<Result<ResolvedTrustData>> {\n\tconst anchorsResult = await buildTrustAnchors(anchorIds, httpClient, config);\n\tif (!anchorsResult.ok) return anchorsResult;\n\n\tconst resolved = await resolveTrustChains(eid, anchorsResult.value, {\n\t\thttpClient,\n\t\t...(maxChainDepth !== undefined ? { maxChainDepth } : {}),\n\t});\n\n\tif (resolved.chains.length === 0) {\n\t\tconst errorMsg = resolved.errors.map((e) => e.description).join(\"; \");\n\t\treturn err(\n\t\t\tfederationError(FederationErrorCode.InvalidTrustChain, `No trust chains found: ${errorMsg}`),\n\t\t);\n\t}\n\n\treturn ok({ anchors: anchorsResult.value, result: resolved });\n}\n","import { decodeEntityStatement, ok, type Result } from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface DecodeDeps {\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface DecodeArgs {\n\treadonly jwt: string;\n\treadonly headerOnly: boolean;\n}\n\nexport function handler(args: DecodeArgs, deps: DecodeDeps): Result<string> {\n\tconst result = decodeEntityStatement(args.jwt);\n\tif (!result.ok) return result;\n\n\tconst data = args.headerOnly ? result.value.header : result.value.payload;\n\treturn ok(deps.formatter.format(data));\n}\n\nexport function register(program: Command, deps: DecodeDeps): void {\n\tprogram\n\t\t.command(\"decode\")\n\t\t.description(\"Decode a JWT entity statement without verification\")\n\t\t.argument(\"<jwt>\", \"JWT string to decode\")\n\t\t.option(\"--header\", \"Show only the JOSE header\", false)\n\t\t.action((jwt: string, opts: { header: boolean }) => {\n\t\t\tconst result = handler({ jwt, headerOnly: opts.header }, deps);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\tdecodeEntityStatement,\n\tfetchEntityConfiguration,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n\tverifyEntityStatement,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { extractJwks, parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface EntityDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface EntityArgs {\n\treadonly entityId: string;\n\treadonly decode: boolean;\n\treadonly verify: boolean;\n}\n\nexport async function handler(args: EntityArgs, deps: EntityDeps): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tconst result = await fetchEntityConfiguration(eid, {\n\t\thttpClient: deps.httpClient,\n\t});\n\n\tif (!result.ok) return result;\n\n\tif (args.verify) {\n\t\t// Self-verify: decode to get JWKS, then verify signature\n\t\tconst decoded = decodeEntityStatement(result.value);\n\t\tif (!decoded.ok) return decoded;\n\n\t\tconst payload = decoded.value.payload as Record<string, unknown>;\n\t\tconst jwksResult = extractJwks(payload);\n\t\tif (!jwksResult.ok) return jwksResult;\n\n\t\tconst verified = await verifyEntityStatement(result.value, jwksResult.value);\n\t\tif (!verified.ok) return verified;\n\n\t\treturn ok(deps.formatter.format(verified.value.payload));\n\t}\n\n\tif (!args.decode) {\n\t\treturn ok(deps.formatter.format(result.value));\n\t}\n\n\tconst decoded = decodeEntityStatement(result.value);\n\tif (!decoded.ok) return decoded;\n\n\treturn ok(deps.formatter.format(decoded.value.payload));\n}\n\nexport function register(program: Command, deps: EntityDeps): void {\n\tprogram\n\t\t.command(\"entity\")\n\t\t.description(\"Fetch and display an entity configuration\")\n\t\t.argument(\"<entity-id>\", \"Entity identifier (URL)\")\n\t\t.option(\"--decode\", \"Decode the JWT payload\", false)\n\t\t.option(\"--verify\", \"Verify the JWT signature (implies decode)\", false)\n\t\t.action(async (entityIdArg: string, opts: { decode: boolean; verify: boolean }) => {\n\t\t\tconst result = await handler(\n\t\t\t\t{ entityId: entityIdArg, decode: opts.decode, verify: opts.verify },\n\t\t\t\tdeps,\n\t\t\t);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\tcalculateChainExpiration,\n\tdecodeEntityStatement,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\ttype HttpClient,\n\tisValidEntityId,\n\tnowSeconds,\n\tok,\n\ttype ParsedEntityStatement,\n\ttype Result,\n\tvalidateTrustChain,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { Config } from \"../config.js\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\nimport { requireAnchorIds, resolveOrError } from \"../util/trust-anchors.js\";\n\nexport interface ExpiryDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly config: Config;\n}\n\nexport interface ExpiryArgs {\n\treadonly jwt: string;\n\treadonly trustAnchors?: readonly string[] | undefined;\n}\n\nasync function handleEntityIdMode(\n\tentityUrl: string,\n\ttrustAnchorArgs: readonly string[],\n\tdeps: ExpiryDeps,\n): Promise<Result<string>> {\n\tconst anchorResult = requireAnchorIds(trustAnchorArgs, deps.config);\n\tif (!anchorResult.ok) return anchorResult;\n\tconst anchorIds = anchorResult.value;\n\n\tconst eidResult = parseEntityIdOrError(entityUrl);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tdeps.logger.info(`Resolving trust chains for ${entityUrl}`);\n\tconst resolveResult = await resolveOrError(\n\t\teid,\n\t\tanchorIds,\n\t\tdeps.httpClient,\n\t\tdeps.config.max_chain_depth,\n\t\tdeps.config,\n\t);\n\tif (!resolveResult.ok) return resolveResult;\n\tconst { anchors, result: resolved } = resolveResult.value;\n\n\tconst chain = resolved.chains[0];\n\tif (!chain) {\n\t\treturn err(federationError(FederationErrorCode.InvalidTrustChain, \"No trust chains resolved\"));\n\t}\n\tconst validationResult = await validateTrustChain([...chain.statements], anchors);\n\n\tif (!validationResult.valid) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidTrustChain,\n\t\t\t\t`Chain validation failed: ${validationResult.errors.map((e) => e.message).join(\"; \")}`,\n\t\t\t),\n\t\t);\n\t}\n\n\t// Decode all statements to calculate chain expiration\n\tconst parsedStatements: ParsedEntityStatement[] = [];\n\tfor (const stmt of chain.statements) {\n\t\tconst decoded = decodeEntityStatement(stmt);\n\t\tif (decoded.ok) parsedStatements.push(decoded.value);\n\t}\n\n\tconst chainExp = calculateChainExpiration(parsedStatements);\n\tconst now = nowSeconds();\n\tconst remainingSeconds = chainExp - now;\n\tconst expired = remainingSeconds <= 0;\n\tconst warningThresholdHours = 24;\n\tconst warningThresholdSeconds = warningThresholdHours * 3600;\n\n\treturn ok(\n\t\tdeps.formatter.format({\n\t\t\tentity_id: entityUrl,\n\t\t\ttrust_anchor_id: validationResult.chain.trustAnchorId,\n\t\t\tchain_expires_at: new Date(chainExp * 1000).toISOString(),\n\t\t\texpired,\n\t\t\tremaining_seconds: Math.max(0, remainingSeconds),\n\t\t\twarning: !expired && remainingSeconds < warningThresholdSeconds,\n\t\t\tstatements: parsedStatements.length,\n\t\t}),\n\t);\n}\n\nexport function handleJwt(jwt: string, deps: ExpiryDeps): Result<string> {\n\tconst decoded = decodeEntityStatement(jwt);\n\tif (!decoded.ok) return decoded;\n\n\tconst payload = decoded.value.payload as Record<string, unknown>;\n\tconst iat = payload.iat as number | undefined;\n\tconst exp = payload.exp as number | undefined;\n\tconst iss = payload.iss as string | undefined;\n\tconst sub = payload.sub as string | undefined;\n\n\tif (!exp) {\n\t\treturn err(federationError(FederationErrorCode.InvalidRequest, \"JWT has no exp claim\"));\n\t}\n\n\tconst now = nowSeconds();\n\tconst remainingSeconds = exp - now;\n\tconst expired = remainingSeconds <= 0;\n\n\treturn ok(\n\t\tdeps.formatter.format({\n\t\t\tissuer: iss ?? \"unknown\",\n\t\t\tsubject: sub ?? \"unknown\",\n\t\t\tissued_at: iat ? new Date(iat * 1000).toISOString() : \"unknown\",\n\t\t\texpires_at: new Date(exp * 1000).toISOString(),\n\t\t\texpired,\n\t\t\tremaining_seconds: Math.max(0, remainingSeconds),\n\t\t}),\n\t);\n}\n\nexport async function handler(args: ExpiryArgs, deps: ExpiryDeps): Promise<Result<string>> {\n\tif (isValidEntityId(args.jwt)) {\n\t\treturn handleEntityIdMode(args.jwt, args.trustAnchors ?? [], deps);\n\t}\n\treturn handleJwt(args.jwt, deps);\n}\n\nexport function register(program: Command, deps: ExpiryDeps): void {\n\tprogram\n\t\t.command(\"expiry\")\n\t\t.description(\"Show expiration details for a JWT or entity trust chain\")\n\t\t.argument(\"<jwt-or-entity-id>\", \"JWT string or entity ID URL\")\n\t\t.option(\n\t\t\t\"-t, --trust-anchor <url>\",\n\t\t\t\"Trust anchor entity IDs (repeatable, for entity-id mode)\",\n\t\t\t(v: string, a: string[]) => [...a, v],\n\t\t\t[] as string[],\n\t\t)\n\t\t.action(async (jwt: string, opts: { trustAnchor: string[] }) => {\n\t\t\tconst result = await handler({ jwt, trustAnchors: opts.trustAnchor }, deps);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\tdecodeEntityStatement,\n\tfetchSubordinateStatement,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { discoverEndpoint } from \"../util/discover-endpoint.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface FetchDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface FetchArgs {\n\treadonly issuer: string;\n\treadonly subject: string;\n\treadonly decode: boolean;\n\treadonly fetchEndpoint?: string | undefined;\n}\n\nexport async function handler(args: FetchArgs, deps: FetchDeps): Promise<Result<string>> {\n\tconst issuerResult = parseEntityIdOrError(args.issuer);\n\tif (!issuerResult.ok) return issuerResult;\n\n\tconst subjectResult = parseEntityIdOrError(args.subject);\n\tif (!subjectResult.ok) return subjectResult;\n\n\tlet endpoint: string;\n\tif (args.fetchEndpoint) {\n\t\tendpoint = args.fetchEndpoint;\n\t} else {\n\t\tconst epResult = await discoverEndpoint(\n\t\t\tissuerResult.value,\n\t\t\t\"federation_fetch_endpoint\",\n\t\t\tdeps.httpClient,\n\t\t);\n\t\tif (!epResult.ok) return epResult;\n\t\tendpoint = epResult.value;\n\t}\n\n\tdeps.logger.info(`Fetching subordinate statement from ${endpoint}`);\n\tconst ssResult = await fetchSubordinateStatement(endpoint, subjectResult.value, {\n\t\thttpClient: deps.httpClient,\n\t});\n\tif (!ssResult.ok) return ssResult;\n\n\tif (!args.decode) {\n\t\treturn ok(deps.formatter.format(ssResult.value));\n\t}\n\n\tconst decoded = decodeEntityStatement(ssResult.value);\n\tif (!decoded.ok) return decoded;\n\n\treturn ok(deps.formatter.format(decoded.value.payload));\n}\n\nexport function register(program: Command, deps: FetchDeps): void {\n\tprogram\n\t\t.command(\"fetch\")\n\t\t.description(\"Fetch a subordinate statement from an authority\")\n\t\t.requiredOption(\"-i, --issuer <url>\", \"Issuer (authority) entity ID\")\n\t\t.requiredOption(\"-s, --subject <url>\", \"Subject entity ID\")\n\t\t.option(\"--fetch-endpoint <url>\", \"Override the federation_fetch_endpoint discovery (advanced)\")\n\t\t.option(\"--decode\", \"Decode the JWT payload\", false)\n\t\t.action(\n\t\t\tasync (opts: {\n\t\t\t\tissuer: string;\n\t\t\t\tsubject: string;\n\t\t\t\tdecode: boolean;\n\t\t\t\tfetchEndpoint?: string;\n\t\t\t}) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tissuer: opts.issuer,\n\t\t\t\t\t\tsubject: opts.subject,\n\t\t\t\t\t\tdecode: opts.decode,\n\t\t\t\t\t\tfetchEndpoint: opts.fetchEndpoint,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import {\n\tdecodeEntityStatement,\n\ttype EntityId,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchEntityConfiguration,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\n\n/**\n * Fetch an entity's configuration and extract a federation endpoint URL\n * advertised under `metadata.federation_entity[metadataKey]`.\n *\n * The federation endpoints (fetch, list, resolve, trust-mark, trust-mark-list,\n * trust-mark-status, historical-keys) are advertised by URL in the EC metadata\n * and may live at any path; consumers MUST use the published URL rather than\n * assuming a conventional location.\n */\nexport async function discoverEndpoint(\n\tentityId: EntityId,\n\tmetadataKey: string,\n\thttpClient: HttpClient,\n): Promise<Result<string>> {\n\tconst ecResult = await fetchEntityConfiguration(entityId, { httpClient });\n\tif (!ecResult.ok) return ecResult;\n\n\tconst decoded = decodeEntityStatement(ecResult.value);\n\tif (!decoded.ok) return decoded;\n\n\tconst payload = decoded.value.payload as Record<string, unknown>;\n\tconst metadata = payload.metadata as Record<string, Record<string, unknown>> | undefined;\n\tconst fedEntity = metadata?.federation_entity;\n\tconst endpoint = fedEntity?.[metadataKey] as string | undefined;\n\n\tif (!endpoint || typeof endpoint !== \"string\") {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.NotFound,\n\t\t\t\t`Entity ${entityId} does not advertise ${metadataKey} in federation_entity metadata`,\n\t\t\t),\n\t\t);\n\t}\n\n\treturn ok(endpoint);\n}\n","import {\n\tcompareTrustAnchorKeys,\n\tdecodeEntityStatement,\n\terr,\n\tFederationEndpoint,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchEntityConfiguration,\n\ttype HttpClient,\n\tJWKSetSchema,\n\tok,\n\ttype Result,\n\tWELL_KNOWN_OPENID_FEDERATION,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { extractJwks, parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface HealthDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly readFile: (path: string) => Promise<string>;\n}\n\nexport interface HealthArgs {\n\treadonly entityId: string;\n\treadonly taJwks?: string | undefined;\n}\n\nexport async function handler(args: HealthArgs, deps: HealthDeps): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tconst checks: { endpoint: string; status: string; time_ms: number }[] = [];\n\n\t// Check well-known endpoint\n\tconst ecStart = Date.now();\n\tconst ecResult = await fetchEntityConfiguration(eid, { httpClient: deps.httpClient });\n\tchecks.push({\n\t\tendpoint: WELL_KNOWN_OPENID_FEDERATION,\n\t\tstatus: ecResult.ok ? \"ok\" : \"error\",\n\t\ttime_ms: Date.now() - ecStart,\n\t});\n\n\t// Detect available endpoints from EC metadata\n\tif (ecResult.ok) {\n\t\tconst decoded = decodeEntityStatement(ecResult.value);\n\t\tif (decoded.ok) {\n\t\t\tconst payload = decoded.value.payload as Record<string, unknown>;\n\t\t\tconst metadata = payload.metadata as Record<string, Record<string, unknown>> | undefined;\n\t\t\tconst fedEntity = metadata?.federation_entity;\n\n\t\t\tconst endpointsToCheck: {\n\t\t\t\tname: string;\n\t\t\t\tkey: string;\n\t\t\t\tmethod?: string | undefined;\n\t\t\t\theaders?: Record<string, string> | undefined;\n\t\t\t\tbody?: string | undefined;\n\t\t\t}[] = [\n\t\t\t\t{ name: FederationEndpoint.List, key: \"federation_list_endpoint\" },\n\t\t\t\t{ name: FederationEndpoint.Fetch, key: \"federation_fetch_endpoint\" },\n\t\t\t\t{ name: FederationEndpoint.Resolve, key: \"federation_resolve_endpoint\" },\n\t\t\t\t{\n\t\t\t\t\tname: FederationEndpoint.TrustMarkStatus,\n\t\t\t\t\tkey: \"federation_trust_mark_status_endpoint\",\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\t\t\t\tbody: new URLSearchParams({ trust_mark: \"health-check\" }).toString(),\n\t\t\t\t},\n\t\t\t];\n\n\t\t\tfor (const ep of endpointsToCheck) {\n\t\t\t\tconst url = fedEntity?.[ep.key] as string | undefined;\n\t\t\t\tif (url) {\n\t\t\t\t\tconst start = Date.now();\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst init: RequestInit = {};\n\t\t\t\t\t\tif (ep.method) init.method = ep.method;\n\t\t\t\t\t\tif (ep.headers) init.headers = ep.headers;\n\t\t\t\t\t\tif (ep.body) init.body = ep.body;\n\t\t\t\t\t\tconst resp = await deps.httpClient(url, init);\n\t\t\t\t\t\tchecks.push({\n\t\t\t\t\t\t\tendpoint: ep.name,\n\t\t\t\t\t\t\tstatus: resp.ok || resp.status === 400 ? \"ok\" : `error (${resp.status})`,\n\t\t\t\t\t\t\ttime_ms: Date.now() - start,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tchecks.push({ endpoint: ep.name, status: \"unreachable\", time_ms: Date.now() - start });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TA key comparison if --ta-jwks provided\n\tlet keyComparison: unknown;\n\tif (args.taJwks && ecResult.ok) {\n\t\tlet taJwksRaw: string;\n\t\ttry {\n\t\t\ttaJwksRaw = await deps.readFile(args.taJwks);\n\t\t} catch {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Cannot read TA JWKS file: ${args.taJwks}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tlet fileJwksRaw: unknown;\n\t\ttry {\n\t\t\tfileJwksRaw = JSON.parse(taJwksRaw);\n\t\t} catch {\n\t\t\treturn err(\n\t\t\t\tfederationError(FederationErrorCode.InvalidRequest, \"TA JWKS file is not valid JSON\"),\n\t\t\t);\n\t\t}\n\t\tconst fileJwks = JWKSetSchema.safeParse(fileJwksRaw);\n\t\tif (!fileJwks.success) {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t\"TA JWKS file must be a public JWK Set with unique non-empty kids\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst decoded = decodeEntityStatement(ecResult.value);\n\t\tif (decoded.ok) {\n\t\t\tconst payload = decoded.value.payload as Record<string, unknown>;\n\t\t\tconst jwksResult = extractJwks(payload);\n\t\t\tif (!jwksResult.ok) return jwksResult;\n\t\t\tkeyComparison = await compareTrustAnchorKeys(jwksResult.value, fileJwks.data, eid);\n\t\t}\n\t}\n\n\tconst allOk = checks.every((c) => c.status === \"ok\");\n\treturn ok(\n\t\tdeps.formatter.format({\n\t\t\tentity_id: args.entityId,\n\t\t\thealthy: allOk,\n\t\t\tchecks,\n\t\t\t...(keyComparison ? { key_comparison: keyComparison } : {}),\n\t\t}),\n\t);\n}\n\nexport function register(program: Command, deps: HealthDeps): void {\n\tprogram\n\t\t.command(\"health\")\n\t\t.description(\"Check health of federation endpoints for an entity\")\n\t\t.argument(\"<entity-id>\", \"Entity ID to check\")\n\t\t.option(\"--ta-jwks <path>\", \"Path to out-of-band TA JWKS file for key comparison\")\n\t\t.action(async (entityIdArg: string, opts: { taJwks?: string }) => {\n\t\t\tconst result = await handler({ entityId: entityIdArg, taJwks: opts.taJwks }, deps);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\terr,\n\tfederationError,\n\tgenerateSigningKey,\n\tInternalErrorCode,\n\tok,\n\ttype Result,\n\tSUPPORTED_ALGORITHMS,\n\ttype SupportedAlgorithm,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface KeygenDeps {\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface KeygenArgs {\n\treadonly algorithm: string;\n\treadonly publicOnly: boolean;\n}\n\nexport async function handler(args: KeygenArgs, deps: KeygenDeps): Promise<Result<string>> {\n\tif (!(SUPPORTED_ALGORITHMS as readonly string[]).includes(args.algorithm)) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tInternalErrorCode.UnsupportedAlg,\n\t\t\t\t`Unsupported algorithm: ${args.algorithm}. Supported: ${SUPPORTED_ALGORITHMS.join(\", \")}`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst keyPair = await generateSigningKey(args.algorithm as SupportedAlgorithm);\n\n\tconst output = args.publicOnly\n\t\t? { keys: [keyPair.publicKey] }\n\t\t: { publicKey: keyPair.publicKey, privateKey: keyPair.privateKey };\n\n\treturn ok(deps.formatter.format(output));\n}\n\nexport function register(program: Command, deps: KeygenDeps): void {\n\tprogram\n\t\t.command(\"keygen\")\n\t\t.description(\"Generate a signing key pair\")\n\t\t.option(\"-a, --algorithm <alg>\", \"Signing algorithm\", \"ES256\")\n\t\t.option(\"--public-only\", \"Output only the public key as a JWKS\", false)\n\t\t.action(async (opts: { algorithm: string; publicOnly: boolean }) => {\n\t\t\tconst result = await handler(\n\t\t\t\t{ algorithm: opts.algorithm, publicOnly: opts.publicOnly },\n\t\t\t\tdeps,\n\t\t\t);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\ttype EntityType,\n\tfetchListSubordinates,\n\ttype HttpClient,\n\ttype ListSubordinatesFilter,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { discoverEndpoint } from \"../util/discover-endpoint.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface ListDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface ListArgs {\n\treadonly entityId: string;\n\treadonly entityType?: string | undefined;\n\treadonly trustMarked?: boolean | undefined;\n\treadonly trustMarkType?: string | undefined;\n\treadonly intermediate?: boolean | undefined;\n\treadonly listEndpoint?: string | undefined;\n}\n\nexport async function handler(args: ListArgs, deps: ListDeps): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\n\tlet endpoint: string;\n\tif (args.listEndpoint) {\n\t\tendpoint = args.listEndpoint;\n\t} else {\n\t\tconst epResult = await discoverEndpoint(\n\t\t\teidResult.value,\n\t\t\t\"federation_list_endpoint\",\n\t\t\tdeps.httpClient,\n\t\t);\n\t\tif (!epResult.ok) return epResult;\n\t\tendpoint = epResult.value;\n\t}\n\n\tconst filter: ListSubordinatesFilter = {};\n\tif (args.entityType) filter.entityType = args.entityType as EntityType;\n\tif (args.trustMarked !== undefined) filter.trustMarked = args.trustMarked;\n\tif (args.trustMarkType) filter.trustMarkType = args.trustMarkType;\n\tif (args.intermediate !== undefined) filter.intermediate = args.intermediate;\n\n\tdeps.logger.info(`Fetching subordinate list from ${endpoint}`);\n\tconst result = await fetchListSubordinates(endpoint, filter, { httpClient: deps.httpClient });\n\tif (!result.ok) return result;\n\n\treturn ok(deps.formatter.format(result.value));\n}\n\nexport function register(program: Command, deps: ListDeps): void {\n\tprogram\n\t\t.command(\"list\")\n\t\t.description(\"List subordinate entities of an authority\")\n\t\t.argument(\"<entity-id>\", \"Authority entity ID\")\n\t\t.option(\"--entity-type <type>\", \"Filter by entity type\")\n\t\t.option(\"--trust-marked\", \"Only list entities that have a recognised Trust Mark\")\n\t\t.option(\"--trust-mark-type <id>\", \"Filter by trust mark type identifier\")\n\t\t.option(\"--intermediate\", \"Only list intermediate authorities\")\n\t\t.option(\"--list-endpoint <url>\", \"Override the federation_list_endpoint discovery (advanced)\")\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tentityIdArg: string,\n\t\t\t\topts: {\n\t\t\t\t\tentityType?: string;\n\t\t\t\t\ttrustMarked?: boolean;\n\t\t\t\t\ttrustMarkType?: string;\n\t\t\t\t\tintermediate?: boolean;\n\t\t\t\t\tlistEndpoint?: string;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: entityIdArg,\n\t\t\t\t\t\tentityType: opts.entityType,\n\t\t\t\t\t\ttrustMarked: opts.trustMarked,\n\t\t\t\t\t\ttrustMarkType: opts.trustMarkType,\n\t\t\t\t\t\tintermediate: opts.intermediate,\n\t\t\t\t\t\tlistEndpoint: opts.listEndpoint,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import {\n\ttype EntityType,\n\ttype ExtendedListClaim,\n\ttype ExtendedListRequestParams,\n\ttype ExtendedListResponse,\n\tfetchExtendedSubordinatesList,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { discoverEndpoint } from \"../util/discover-endpoint.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface ListExtendedDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface ListExtendedArgs {\n\treadonly entityId: string;\n\treadonly from?: string | undefined;\n\treadonly limit?: number | undefined;\n\treadonly updatedAfter?: number | undefined;\n\treadonly updatedBefore?: number | undefined;\n\treadonly auditTimestamps?: boolean | undefined;\n\treadonly claims?: ReadonlyArray<string> | undefined;\n\treadonly entityType?: string | undefined;\n\treadonly trustMarked?: boolean | undefined;\n\treadonly trustMarkType?: string | undefined;\n\treadonly intermediate?: boolean | undefined;\n\treadonly extendedListEndpoint?: string | undefined;\n}\n\nexport async function handler(\n\targs: ListExtendedArgs,\n\tdeps: ListExtendedDeps,\n): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\n\tlet endpoint: string;\n\tif (args.extendedListEndpoint) {\n\t\tendpoint = args.extendedListEndpoint;\n\t} else {\n\t\tconst epResult = await discoverEndpoint(\n\t\t\teidResult.value,\n\t\t\t\"federation_extended_list_endpoint\",\n\t\t\tdeps.httpClient,\n\t\t);\n\t\tif (!epResult.ok) return epResult;\n\t\tendpoint = epResult.value;\n\t}\n\n\tconst params: ExtendedListRequestParams = {};\n\tif (args.from !== undefined) params.fromEntityId = args.from;\n\tif (args.limit !== undefined) params.limit = args.limit;\n\tif (args.updatedAfter !== undefined) params.updatedAfter = args.updatedAfter;\n\tif (args.updatedBefore !== undefined) params.updatedBefore = args.updatedBefore;\n\tif (args.auditTimestamps !== undefined) params.auditTimestamps = args.auditTimestamps;\n\tif (args.claims !== undefined) {\n\t\tparams.claims = args.claims as ReadonlyArray<ExtendedListClaim | string>;\n\t}\n\tif (args.entityType !== undefined) params.entityType = args.entityType as EntityType;\n\tif (args.trustMarked !== undefined) params.trustMarked = args.trustMarked;\n\tif (args.trustMarkType !== undefined) params.trustMarkType = args.trustMarkType;\n\tif (args.intermediate !== undefined) params.intermediate = args.intermediate;\n\n\tdeps.logger.info(`Fetching extended subordinate listing from ${endpoint}`);\n\tconst result = await fetchExtendedSubordinatesList(endpoint, params, {\n\t\thttpClient: deps.httpClient,\n\t});\n\tif (!result.ok) return result;\n\n\treturn ok(deps.formatter.format(result.value as ExtendedListResponse));\n}\n\nfunction parsePositiveIntOption(raw: string): number {\n\tif (!/^[1-9][0-9]*$/.test(raw)) {\n\t\tthrow new Error(`expected positive integer, got '${raw}'`);\n\t}\n\treturn Number.parseInt(raw, 10);\n}\n\nfunction parseNumericDateOption(raw: string): number {\n\tif (!/^[0-9]+$/.test(raw)) {\n\t\tthrow new Error(`expected NumericDate (non-negative integer), got '${raw}'`);\n\t}\n\treturn Number.parseInt(raw, 10);\n}\n\nexport function register(program: Command, deps: ListExtendedDeps): void {\n\tprogram\n\t\t.command(\"list-extended\")\n\t\t.description(\n\t\t\t\"List subordinate entities of an authority via the Extended Subordinate Listing endpoint (paginated, with bulk claim retrieval)\",\n\t\t)\n\t\t.argument(\"<entity-id>\", \"Authority entity ID\")\n\t\t.option(\"--from <entity-id>\", \"Resume cursor: from_entity_id (inclusive)\")\n\t\t.option(\"--limit <n>\", \"Maximum number of entities to return\", parsePositiveIntOption)\n\t\t.option(\n\t\t\t\"--updated-after <numericdate>\",\n\t\t\t\"Filter to entities updated at/after this NumericDate\",\n\t\t\tparseNumericDateOption,\n\t\t)\n\t\t.option(\n\t\t\t\"--updated-before <numericdate>\",\n\t\t\t\"Filter to entities updated at/before this NumericDate\",\n\t\t\tparseNumericDateOption,\n\t\t)\n\t\t.option(\"--audit-timestamps\", \"Include 'registered' and 'updated' fields per entity\")\n\t\t.option(\n\t\t\t\"--claims <name>\",\n\t\t\t\"Repeatable: request a top-level Entity Statement claim per entity (e.g. subordinate_statement, trust_marks, metadata)\",\n\t\t\t(value: string, previous: string[] | undefined) => [...(previous ?? []), value],\n\t\t)\n\t\t.option(\"--entity-type <type>\", \"Inherited base filter: only this entity type\")\n\t\t.option(\"--trust-marked\", \"Inherited base filter: only entities with a recognised Trust Mark\")\n\t\t.option(\"--trust-mark-type <id>\", \"Inherited base filter: trust mark type identifier\")\n\t\t.option(\"--intermediate\", \"Inherited base filter: only intermediate authorities\")\n\t\t.option(\n\t\t\t\"--extended-list-endpoint <url>\",\n\t\t\t\"Override federation_extended_list_endpoint discovery (advanced)\",\n\t\t)\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tentityIdArg: string,\n\t\t\t\topts: {\n\t\t\t\t\tfrom?: string;\n\t\t\t\t\tlimit?: number;\n\t\t\t\t\tupdatedAfter?: number;\n\t\t\t\t\tupdatedBefore?: number;\n\t\t\t\t\tauditTimestamps?: boolean;\n\t\t\t\t\tclaims?: string[];\n\t\t\t\t\tentityType?: string;\n\t\t\t\t\ttrustMarked?: boolean;\n\t\t\t\t\ttrustMarkType?: string;\n\t\t\t\t\tintermediate?: boolean;\n\t\t\t\t\textendedListEndpoint?: string;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: entityIdArg,\n\t\t\t\t\t\tfrom: opts.from,\n\t\t\t\t\t\tlimit: opts.limit,\n\t\t\t\t\t\tupdatedAfter: opts.updatedAfter,\n\t\t\t\t\t\tupdatedBefore: opts.updatedBefore,\n\t\t\t\t\t\tauditTimestamps: opts.auditTimestamps,\n\t\t\t\t\t\tclaims: opts.claims,\n\t\t\t\t\t\tentityType: opts.entityType,\n\t\t\t\t\t\ttrustMarked: opts.trustMarked,\n\t\t\t\t\t\ttrustMarkType: opts.trustMarkType,\n\t\t\t\t\t\tintermediate: opts.intermediate,\n\t\t\t\t\t\textendedListEndpoint: opts.extendedListEndpoint,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import { type HttpClient, ok, type Result } from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { Config } from \"../config.js\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\nimport { requireAnchorIds, resolveOrError } from \"../util/trust-anchors.js\";\n\nexport interface ResolveDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly config: Config;\n}\n\nexport interface ResolveArgs {\n\treadonly entityId: string;\n\treadonly trustAnchors: readonly string[];\n\treadonly maxDepth?: number | undefined;\n}\n\nexport async function handler(args: ResolveArgs, deps: ResolveDeps): Promise<Result<string>> {\n\tconst anchorResult = requireAnchorIds(args.trustAnchors, deps.config);\n\tif (!anchorResult.ok) return anchorResult;\n\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tconst resolveResult = await resolveOrError(\n\t\teid,\n\t\tanchorResult.value,\n\t\tdeps.httpClient,\n\t\targs.maxDepth ?? deps.config.max_chain_depth,\n\t\tdeps.config,\n\t);\n\tif (!resolveResult.ok) return resolveResult;\n\tconst result = resolveResult.value.result;\n\n\tconst summary = result.chains.map((chain) => ({\n\t\tentity_id: chain.entityId,\n\t\ttrust_anchor_id: chain.trustAnchorId,\n\t\tstatements: chain.statements.length,\n\t\texpires_at: new Date(chain.expiresAt * 1000).toISOString(),\n\t}));\n\n\treturn ok(\n\t\tdeps.formatter.format({\n\t\t\tchains_found: result.chains.length,\n\t\t\terrors: result.errors.length,\n\t\t\tchains: summary,\n\t\t}),\n\t);\n}\n\nexport function register(program: Command, deps: ResolveDeps): void {\n\tprogram\n\t\t.command(\"resolve\")\n\t\t.description(\"Resolve trust chains for an entity\")\n\t\t.argument(\"<entity-id>\", \"Entity identifier (URL)\")\n\t\t.option(\n\t\t\t\"-t, --trust-anchor <url>\",\n\t\t\t\"Trust anchor entity IDs (repeatable)\",\n\t\t\t(v: string, a: string[]) => [...a, v],\n\t\t\t[] as string[],\n\t\t)\n\t\t.option(\"--max-depth <n>\", \"Maximum chain depth\", Number.parseInt)\n\t\t.action(async (entityIdArg: string, opts: { trustAnchor: string[]; maxDepth?: number }) => {\n\t\t\tconst result = await handler(\n\t\t\t\t{ entityId: entityIdArg, trustAnchors: opts.trustAnchor, maxDepth: opts.maxDepth },\n\t\t\t\tdeps,\n\t\t\t);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tInternalErrorCode,\n\ttype JWK,\n\tJwkSigner,\n\tok,\n\ttype Result,\n\tSUPPORTED_ALGORITHMS,\n\ttype SupportedAlgorithm,\n\tsignEntityStatement,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface SignDeps {\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly readFile: (path: string) => Promise<string>;\n}\n\nexport interface SignArgs {\n\treadonly payloadPath: string;\n\treadonly keyPath: string;\n\treadonly algorithm?: string | undefined;\n}\n\nexport async function handler(args: SignArgs, deps: SignDeps): Promise<Result<string>> {\n\tlet payloadRaw: string;\n\ttry {\n\t\tpayloadRaw = await deps.readFile(args.payloadPath);\n\t} catch {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t`Cannot read payload file: ${args.payloadPath}`,\n\t\t\t),\n\t\t);\n\t}\n\n\tlet keyRaw: string;\n\ttry {\n\t\tkeyRaw = await deps.readFile(args.keyPath);\n\t} catch {\n\t\treturn err(\n\t\t\tfederationError(FederationErrorCode.InvalidRequest, `Cannot read key file: ${args.keyPath}`),\n\t\t);\n\t}\n\n\tlet payload: Record<string, unknown>;\n\ttry {\n\t\tpayload = JSON.parse(payloadRaw) as Record<string, unknown>;\n\t} catch {\n\t\treturn err(\n\t\t\tfederationError(FederationErrorCode.InvalidRequest, \"Payload file is not valid JSON\"),\n\t\t);\n\t}\n\n\tlet privateKey: Record<string, unknown>;\n\ttry {\n\t\tprivateKey = JSON.parse(keyRaw) as Record<string, unknown>;\n\t} catch {\n\t\treturn err(federationError(FederationErrorCode.InvalidRequest, \"Key file is not valid JSON\"));\n\t}\n\n\ttry {\n\t\tif (\n\t\t\targs.algorithm !== undefined &&\n\t\t\t!(SUPPORTED_ALGORITHMS as readonly string[]).includes(args.algorithm)\n\t\t) {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Unsupported algorithm: ${args.algorithm}. Supported: ${SUPPORTED_ALGORITHMS.join(\", \")}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tconst signer = new JwkSigner(\n\t\t\tprivateKey as JWK,\n\t\t\targs.algorithm ? { alg: args.algorithm as SupportedAlgorithm } : undefined,\n\t\t);\n\t\tconst jwt = await signEntityStatement(payload, signer);\n\t\treturn ok(jwt);\n\t} catch (e) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tInternalErrorCode.SignatureInvalid,\n\t\t\t\t`Signing failed: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\t),\n\t\t);\n\t}\n}\n\nexport function register(program: Command, deps: SignDeps): void {\n\tprogram\n\t\t.command(\"sign\")\n\t\t.description(\"Sign a JSON payload as a JWT entity statement\")\n\t\t.requiredOption(\"-p, --payload <path>\", \"Path to JSON payload file\")\n\t\t.requiredOption(\"-k, --key <path>\", \"Path to JWK private key file\")\n\t\t.option(\"-a, --algorithm <alg>\", \"Signing algorithm (default: from key)\")\n\t\t.action(async (opts: { payload: string; key: string; algorithm?: string | undefined }) => {\n\t\t\tconst result = await handler(\n\t\t\t\t{ payloadPath: opts.payload, keyPath: opts.key, algorithm: opts.algorithm },\n\t\t\t\tdeps,\n\t\t\t);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\ttype EntityId,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchTrustMarkList,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { discoverEndpoint } from \"../util/discover-endpoint.js\";\nimport { parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface TrustMarkListDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface TrustMarkListArgs {\n\treadonly entityId: string;\n\treadonly trustMarkType?: string | undefined;\n\treadonly sub?: string | undefined;\n\treadonly listEndpoint?: string | undefined;\n}\n\nexport async function handler(\n\targs: TrustMarkListArgs,\n\tdeps: TrustMarkListDeps,\n): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\n\tif (!args.trustMarkType) {\n\t\treturn err(\n\t\t\tfederationError(FederationErrorCode.InvalidRequest, \"--trust-mark-type is required\"),\n\t\t);\n\t}\n\n\tlet endpoint: string;\n\tif (args.listEndpoint) {\n\t\tendpoint = args.listEndpoint;\n\t} else {\n\t\tconst epResult = await discoverEndpoint(\n\t\t\teidResult.value,\n\t\t\t\"federation_trust_mark_list_endpoint\",\n\t\t\tdeps.httpClient,\n\t\t);\n\t\tif (!epResult.ok) return epResult;\n\t\tendpoint = epResult.value;\n\t}\n\n\tlet subEid: EntityId | undefined;\n\tif (args.sub) {\n\t\tconst subResult = parseEntityIdOrError(args.sub);\n\t\tif (!subResult.ok) return subResult;\n\t\tsubEid = subResult.value;\n\t}\n\n\tdeps.logger.info(`Fetching trust mark list from ${endpoint}`);\n\tconst params: { trustMarkType: string; sub?: EntityId } = {\n\t\ttrustMarkType: args.trustMarkType,\n\t};\n\tif (subEid) params.sub = subEid;\n\n\tconst result = await fetchTrustMarkList(endpoint, params, { httpClient: deps.httpClient });\n\tif (!result.ok) return result;\n\n\treturn ok(deps.formatter.format(result.value));\n}\n\nexport function register(program: Command, deps: TrustMarkListDeps): void {\n\tprogram\n\t\t.command(\"trust-mark-list\")\n\t\t.description(\"List entities holding an active Trust Mark of a given type\")\n\t\t.argument(\"<entity-id>\", \"Trust Mark Issuer entity ID\")\n\t\t.requiredOption(\"--trust-mark-type <id>\", \"Trust Mark type identifier\")\n\t\t.option(\"--sub <url>\", \"Filter to a specific subject Entity Identifier\")\n\t\t.option(\n\t\t\t\"--list-endpoint <url>\",\n\t\t\t\"Override federation_trust_mark_list_endpoint discovery (advanced)\",\n\t\t)\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tentityIdArg: string,\n\t\t\t\topts: { trustMarkType: string; sub?: string; listEndpoint?: string },\n\t\t\t) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: entityIdArg,\n\t\t\t\t\t\ttrustMarkType: opts.trustMarkType,\n\t\t\t\t\t\tsub: opts.sub,\n\t\t\t\t\t\tlistEndpoint: opts.listEndpoint,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import {\n\tdecodeEntityStatement,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchEntityConfiguration,\n\tfetchTrustMarkStatus,\n\ttype HttpClient,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { discoverEndpoint } from \"../util/discover-endpoint.js\";\nimport { extractJwks, parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface TrustMarkStatusDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n}\n\nexport interface TrustMarkStatusArgs {\n\treadonly entityId: string;\n\treadonly trustMark?: string | undefined;\n\treadonly subject?: string | undefined;\n\treadonly trustMarkType?: string | undefined;\n\treadonly verify: boolean;\n\treadonly statusEndpoint?: string | undefined;\n}\n\nexport async function handler(\n\targs: TrustMarkStatusArgs,\n\tdeps: TrustMarkStatusDeps,\n): Promise<Result<string>> {\n\tconst eidResult = parseEntityIdOrError(args.entityId);\n\tif (!eidResult.ok) return eidResult;\n\n\tconst hasTrustMark = !!args.trustMark;\n\tconst hasSubjectType = !!args.subject && !!args.trustMarkType;\n\n\tif (!hasTrustMark && !hasSubjectType) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\"Either --trust-mark or both --subject and --trust-mark-type are required\",\n\t\t\t),\n\t\t);\n\t}\n\tif (hasTrustMark && hasSubjectType) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\"Cannot use --trust-mark together with --subject/--trust-mark-type\",\n\t\t\t),\n\t\t);\n\t}\n\n\tlet endpoint: string;\n\tif (args.statusEndpoint) {\n\t\tendpoint = args.statusEndpoint;\n\t} else {\n\t\tconst epResult = await discoverEndpoint(\n\t\t\teidResult.value,\n\t\t\t\"federation_trust_mark_status_endpoint\",\n\t\t\tdeps.httpClient,\n\t\t);\n\t\tif (!epResult.ok) return epResult;\n\t\tendpoint = epResult.value;\n\t}\n\n\t// JWT mode: route through fetchTrustMarkStatus when --verify is set, since\n\t// the core helper enforces HTTPS, no-fragment, Content-Type, typ-header,\n\t// and signature verification against the issuer's JWKS.\n\tif (hasTrustMark && args.verify) {\n\t\tconst ecResult = await fetchEntityConfiguration(eidResult.value, {\n\t\t\thttpClient: deps.httpClient,\n\t\t});\n\t\tif (!ecResult.ok) return ecResult;\n\t\tconst ecDecoded = decodeEntityStatement(ecResult.value);\n\t\tif (!ecDecoded.ok) return ecDecoded;\n\t\tconst jwksResult = extractJwks(ecDecoded.value.payload as Record<string, unknown>);\n\t\tif (!jwksResult.ok) return jwksResult;\n\n\t\tdeps.logger.info(`POSTing trust mark to ${endpoint} (verifying response)`);\n\t\tconst statusResult = await fetchTrustMarkStatus(\n\t\t\tendpoint,\n\t\t\targs.trustMark as string,\n\t\t\tjwksResult.value,\n\t\t\t{\n\t\t\t\thttpClient: deps.httpClient,\n\t\t\t},\n\t\t);\n\t\tif (!statusResult.ok) return statusResult;\n\t\treturn ok(deps.formatter.format(statusResult.value));\n\t}\n\n\t// Non-verify or sub+type mode: raw POST routed through the shared httpClient\n\t// (preserves SSRF / timeout policy supplied by createHttpClient).\n\tdeps.logger.info(`POSTing to ${endpoint}`);\n\tconst formParams = hasTrustMark\n\t\t? { trust_mark: args.trustMark as string }\n\t\t: { sub: args.subject as string, trust_mark_type: args.trustMarkType as string };\n\tconst body = new URLSearchParams(formParams).toString();\n\n\tconst response = await deps.httpClient(endpoint, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\tbody,\n\t});\n\tif (!response.ok) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.NotFound,\n\t\t\t\t`Trust mark status check failed with status ${response.status}`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst responseBody = await response.text();\n\tconst decoded = decodeEntityStatement(responseBody);\n\tif (decoded.ok) {\n\t\treturn ok(deps.formatter.format(decoded.value.payload));\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(responseBody);\n\t} catch {\n\t\treturn ok(deps.formatter.format({ response: responseBody }));\n\t}\n\treturn ok(deps.formatter.format(parsed));\n}\n\nexport function register(program: Command, deps: TrustMarkStatusDeps): void {\n\tprogram\n\t\t.command(\"trust-mark-status\")\n\t\t.description(\"Check the status of a Trust Mark at its issuer\")\n\t\t.argument(\"<entity-id>\", \"Trust Mark Issuer entity ID\")\n\t\t.option(\"--trust-mark <jwt>\", \"Trust Mark JWT to check\")\n\t\t.option(\"--subject <url>\", \"Subject entity ID (use with --trust-mark-type)\")\n\t\t.option(\"--trust-mark-type <id>\", \"Trust Mark type identifier (use with --subject)\")\n\t\t.option(\"--verify\", \"Verify the response JWT signature against the issuer's JWKS\", false)\n\t\t.option(\n\t\t\t\"--status-endpoint <url>\",\n\t\t\t\"Override federation_trust_mark_status_endpoint discovery (advanced)\",\n\t\t)\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tentityIdArg: string,\n\t\t\t\topts: {\n\t\t\t\t\ttrustMark?: string;\n\t\t\t\t\tsubject?: string;\n\t\t\t\t\ttrustMarkType?: string;\n\t\t\t\t\tverify: boolean;\n\t\t\t\t\tstatusEndpoint?: string;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst result = await handler(\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: entityIdArg,\n\t\t\t\t\t\ttrustMark: opts.trustMark,\n\t\t\t\t\t\tsubject: opts.subject,\n\t\t\t\t\t\ttrustMarkType: opts.trustMarkType,\n\t\t\t\t\t\tverify: opts.verify,\n\t\t\t\t\t\tstatusEndpoint: opts.statusEndpoint,\n\t\t\t\t\t},\n\t\t\t\t\tdeps,\n\t\t\t\t);\n\t\t\t\tif (result.ok) {\n\t\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t\t} else {\n\t\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n}\n","import {\n\tchainRemainingTtl,\n\tdecodeEntityStatement,\n\tdescribeTrustChain,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\ttype HttpClient,\n\tisChainExpired,\n\tisValidEntityId,\n\ttype JWKSet,\n\tok,\n\ttype Result,\n\tvalidateTrustChain,\n\tvalidateTrustMark,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { Config } from \"../config.js\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { extractJwks, parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\nimport { buildTrustAnchors, requireAnchorIds, resolveOrError } from \"../util/trust-anchors.js\";\n\nexport interface ValidateDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly config: Config;\n}\n\nexport interface ValidateArgs {\n\treadonly jwts: readonly string[];\n\treadonly trustAnchors: readonly string[];\n}\n\nasync function handleEntityIdMode(\n\tentityUrl: string,\n\ttrustAnchorArgs: readonly string[],\n\tdeps: ValidateDeps,\n): Promise<Result<string>> {\n\tconst anchorResult = requireAnchorIds(trustAnchorArgs, deps.config);\n\tif (!anchorResult.ok) return anchorResult;\n\tconst anchorIds = anchorResult.value;\n\n\tconst eidResult = parseEntityIdOrError(entityUrl);\n\tif (!eidResult.ok) return eidResult;\n\tconst eid = eidResult.value;\n\n\tdeps.logger.info(`Resolving trust chains for ${entityUrl}`);\n\tconst resolveResult = await resolveOrError(\n\t\teid,\n\t\tanchorIds,\n\t\tdeps.httpClient,\n\t\tdeps.config.max_chain_depth,\n\t\tdeps.config,\n\t);\n\tif (!resolveResult.ok) return resolveResult;\n\tconst { anchors, result: resolved } = resolveResult.value;\n\n\t// Validate first resolvable chain\n\tconst chain = resolved.chains[0];\n\tif (!chain) {\n\t\treturn err(federationError(FederationErrorCode.InvalidTrustChain, \"No trust chains resolved\"));\n\t}\n\tconst validationResult = await validateTrustChain([...chain.statements], anchors);\n\n\t// Decode the leaf EC to extract trust_marks\n\tconst leafStatement = chain.statements[0];\n\tif (!leafStatement) {\n\t\treturn err(federationError(FederationErrorCode.InvalidTrustChain, \"Empty chain\"));\n\t}\n\tconst leafEc = decodeEntityStatement(leafStatement);\n\tconst trustMarkResults: { id: string; valid: boolean; error?: string | undefined }[] = [];\n\n\tif (leafEc.ok) {\n\t\tconst payload = leafEc.value.payload as Record<string, unknown>;\n\t\tconst trustMarks = payload.trust_marks as { id: string; trust_mark: string }[] | undefined;\n\n\t\tif (trustMarks && Array.isArray(trustMarks)) {\n\t\t\t// Extract trust_mark_issuers from TA EC for validation\n\t\t\tconst taStatement = chain.statements[chain.statements.length - 1];\n\t\t\tconst taEc = taStatement ? decodeEntityStatement(taStatement) : undefined;\n\t\t\tif (taEc?.ok) {\n\t\t\t\tconst taPayload = taEc.value.payload as Record<string, unknown>;\n\t\t\t\tconst taJwksResult = extractJwks(taPayload);\n\t\t\t\tconst taJwks: JWKSet = taJwksResult.ok ? taJwksResult.value : { keys: [] };\n\t\t\t\tconst trustMarkIssuers = ((taPayload.trust_mark_issuers as\n\t\t\t\t\t| Record<string, string[]>\n\t\t\t\t\t| undefined) ?? {}) as Record<string, string[]>;\n\n\t\t\t\tfor (const tm of trustMarks) {\n\t\t\t\t\tconst tmResult = await validateTrustMark(tm.trust_mark, trustMarkIssuers, taJwks);\n\t\t\t\t\ttrustMarkResults.push({\n\t\t\t\t\t\tid: tm.id,\n\t\t\t\t\t\tvalid: tmResult.ok,\n\t\t\t\t\t\t...(tmResult.ok ? {} : { error: tmResult.error.description }),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst chainValid = validationResult.valid;\n\tconst output: Record<string, unknown> = {\n\t\tvalid: chainValid,\n\t\tentity_id: entityUrl,\n\t};\n\n\tif (chainValid) {\n\t\toutput.description = describeTrustChain(validationResult.chain);\n\t\toutput.expired = isChainExpired(validationResult.chain);\n\t\toutput.remaining_ttl_seconds = chainRemainingTtl(validationResult.chain);\n\t\toutput.trust_anchor_id = validationResult.chain.trustAnchorId;\n\t\toutput.statements = validationResult.chain.statements.length;\n\t} else {\n\t\toutput.errors = validationResult.errors.map((e) => ({\n\t\t\tcode: e.code,\n\t\t\tmessage: e.message,\n\t\t}));\n\t}\n\n\tif (trustMarkResults.length > 0) {\n\t\toutput.trust_marks = trustMarkResults;\n\t}\n\n\toutput.pass = chainValid && trustMarkResults.every((tm) => tm.valid);\n\n\treturn ok(deps.formatter.format(output));\n}\n\nexport async function handler(args: ValidateArgs, deps: ValidateDeps): Promise<Result<string>> {\n\t// Auto-detect: if first arg starts with http, treat as entity-id mode\n\tconst firstArg = args.jwts[0];\n\tif (args.jwts.length === 1 && firstArg && isValidEntityId(firstArg)) {\n\t\treturn handleEntityIdMode(firstArg, args.trustAnchors, deps);\n\t}\n\n\tif (args.jwts.length === 0) {\n\t\treturn err(federationError(FederationErrorCode.InvalidRequest, \"At least one JWT is required\"));\n\t}\n\n\tconst anchorResult = requireAnchorIds(args.trustAnchors, deps.config);\n\tif (!anchorResult.ok) return anchorResult;\n\n\tconst anchorsResult = await buildTrustAnchors(anchorResult.value, deps.httpClient, deps.config);\n\tif (!anchorsResult.ok) return anchorsResult;\n\n\tconst validationResult = await validateTrustChain([...args.jwts], anchorsResult.value);\n\n\tif (validationResult.valid) {\n\t\treturn ok(\n\t\t\tdeps.formatter.format({\n\t\t\t\tvalid: true,\n\t\t\t\tdescription: describeTrustChain(validationResult.chain),\n\t\t\t\texpired: isChainExpired(validationResult.chain),\n\t\t\t\tremaining_ttl_seconds: chainRemainingTtl(validationResult.chain),\n\t\t\t\tentity_id: validationResult.chain.entityId,\n\t\t\t\ttrust_anchor_id: validationResult.chain.trustAnchorId,\n\t\t\t\tstatements: validationResult.chain.statements.length,\n\t\t\t\twarnings: validationResult.errors.map((e) => e.message),\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn ok(\n\t\tdeps.formatter.format({\n\t\t\tvalid: false,\n\t\t\terrors: validationResult.errors.map((e) => ({\n\t\t\t\tcode: e.code,\n\t\t\t\tmessage: e.message,\n\t\t\t\tstatement_index: e.statementIndex,\n\t\t\t\tfield: e.field,\n\t\t\t})),\n\t\t}),\n\t);\n}\n\nexport function register(program: Command, deps: ValidateDeps): void {\n\tprogram\n\t\t.command(\"validate\")\n\t\t.description(\"Validate a trust chain from JWTs or by resolving an entity ID\")\n\t\t.argument(\n\t\t\t\"<jwt-or-entity-id...>\",\n\t\t\t\"JWT entity statements (leaf → TA) or a single entity ID URL\",\n\t\t)\n\t\t.option(\n\t\t\t\"-t, --trust-anchor <url>\",\n\t\t\t\"Trust anchor entity IDs (repeatable)\",\n\t\t\t(v: string, a: string[]) => [...a, v],\n\t\t\t[] as string[],\n\t\t)\n\t\t.action(async (jwts: string[], opts: { trustAnchor: string[] }) => {\n\t\t\tconst result = await handler({ jwts, trustAnchors: opts.trustAnchor }, deps);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import {\n\tdecodeEntityStatement,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tfetchEntityConfiguration,\n\ttype HttpClient,\n\ttype JWKSet,\n\tok,\n\ttype Result,\n\tverifyEntityStatement,\n} from \"@oidfed/core\";\nimport type { Command } from \"commander\";\nimport type { OutputFormatter } from \"../output/index.js\";\nimport { extractJwks, parseEntityIdOrError } from \"../util/entity-id.js\";\nimport type { Logger } from \"../util/logger.js\";\n\nexport interface VerifyDeps {\n\treadonly httpClient: HttpClient;\n\treadonly formatter: OutputFormatter;\n\treadonly logger: Logger;\n\treadonly readFile: (path: string) => Promise<string>;\n}\n\nexport interface VerifyArgs {\n\treadonly jwt: string;\n\treadonly jwksFile?: string | undefined;\n\treadonly entityId?: string | undefined;\n}\n\nexport async function handler(args: VerifyArgs, deps: VerifyDeps): Promise<Result<string>> {\n\t// Resolve JWKS from one of three sources\n\tlet jwks: JWKSet;\n\n\tif (args.jwksFile) {\n\t\tlet raw: string;\n\t\ttry {\n\t\t\traw = await deps.readFile(args.jwksFile);\n\t\t} catch {\n\t\t\treturn err(\n\t\t\t\tfederationError(\n\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t`Cannot read JWKS file: ${args.jwksFile}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\ttry {\n\t\t\tjwks = JSON.parse(raw) as JWKSet;\n\t\t} catch {\n\t\t\treturn err(\n\t\t\t\tfederationError(FederationErrorCode.InvalidRequest, \"JWKS file is not valid JSON\"),\n\t\t\t);\n\t\t}\n\t} else {\n\t\t// Determine entity ID: from --entity-id or from JWT iss claim\n\t\tlet eid: string;\n\t\tif (args.entityId) {\n\t\t\teid = args.entityId;\n\t\t} else {\n\t\t\tconst decoded = decodeEntityStatement(args.jwt);\n\t\t\tif (!decoded.ok) return decoded;\n\t\t\teid = (decoded.value.payload as Record<string, unknown>).iss as string;\n\t\t\tif (!eid) {\n\t\t\t\treturn err(\n\t\t\t\t\tfederationError(\n\t\t\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t\t\t\"JWT has no iss claim; specify --jwks-file or --entity-id\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst validEidResult = parseEntityIdOrError(eid);\n\t\tif (!validEidResult.ok) return validEidResult;\n\t\tconst validEid = validEidResult.value;\n\n\t\tconst ecResult = await fetchEntityConfiguration(validEid, {\n\t\t\thttpClient: deps.httpClient,\n\t\t});\n\t\tif (!ecResult.ok) return ecResult;\n\n\t\tconst ecDecoded = decodeEntityStatement(ecResult.value);\n\t\tif (!ecDecoded.ok) return ecDecoded;\n\n\t\tconst payload = ecDecoded.value.payload as Record<string, unknown>;\n\t\tconst jwksResult = extractJwks(payload);\n\t\tif (!jwksResult.ok) return jwksResult;\n\t\tjwks = jwksResult.value;\n\t}\n\n\tconst verified = await verifyEntityStatement(args.jwt, jwks);\n\tif (!verified.ok) return verified;\n\n\treturn ok(\n\t\tdeps.formatter.format({ header: verified.value.header, payload: verified.value.payload }),\n\t);\n}\n\nexport function register(program: Command, deps: VerifyDeps): void {\n\tprogram\n\t\t.command(\"verify\")\n\t\t.description(\"Verify a JWT signature against a JWKS\")\n\t\t.argument(\"<jwt>\", \"JWT string to verify\")\n\t\t.option(\"--jwks-file <path>\", \"Path to JWKS JSON file\")\n\t\t.option(\"--entity-id <url>\", \"Fetch JWKS from this entity's configuration\")\n\t\t.action(async (jwt: string, opts: { jwksFile?: string; entityId?: string }) => {\n\t\t\tconst result = await handler({ jwt, jwksFile: opts.jwksFile, entityId: opts.entityId }, deps);\n\t\t\tif (result.ok) {\n\t\t\t\tprocess.stdout.write(`${result.value}\\n`);\n\t\t\t} else {\n\t\t\t\tdeps.logger.error(result.error.description);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n","import { readFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_CHAIN_DEPTH,\n\terr,\n\tFederationErrorCode,\n\tfederationError,\n\tJWKSetSchema,\n\tok,\n\ttype Result,\n} from \"@oidfed/core\";\nimport { parse as parseYaml } from \"yaml\";\nimport { z } from \"zod\";\n\nconst MAX_CHAIN_DEPTH_LIMIT = 100;\n\nexport const TrustAnchorConfigSchema = z\n\t.object({\n\t\tentity_id: z.string(),\n\t\tjwks: JWKSetSchema.optional(),\n\t})\n\t.strict();\n\nexport const ConfigSchema = z\n\t.object({\n\t\ttrust_anchors: z.array(TrustAnchorConfigSchema).default([]),\n\t\thttp_timeout_ms: z.number().int().positive().default(10_000),\n\t\tmax_chain_depth: z\n\t\t\t.number()\n\t\t\t.int()\n\t\t\t.positive()\n\t\t\t.max(MAX_CHAIN_DEPTH_LIMIT)\n\t\t\t.default(DEFAULT_MAX_CHAIN_DEPTH),\n\t})\n\t.strict();\n\nexport type Config = z.infer<typeof ConfigSchema>;\n\nexport const DEFAULT_CONFIG: Config = {\n\ttrust_anchors: [],\n\thttp_timeout_ms: 10_000,\n\tmax_chain_depth: DEFAULT_MAX_CHAIN_DEPTH,\n};\n\nexport function configDir(): string {\n\treturn join(homedir(), \".oidfed\");\n}\n\nexport function configPath(): string {\n\treturn join(configDir(), \"config.yaml\");\n}\n\n/**\n * Load the CLI configuration.\n *\n * Path resolution order:\n *   1. The `path` argument if supplied (typically from `--config`).\n *   2. `process.env.OIDFED_CONFIG_PATH` if set.\n *   3. The default `~/.oidfed/config.yaml`.\n *\n * Missing files (ENOENT) silently produce DEFAULT_CONFIG; YAML or schema\n * validation errors are returned as `Result.err`.\n */\nexport async function loadConfig(path?: string): Promise<Result<Config>> {\n\tconst filePath = path ?? process.env.OIDFED_CONFIG_PATH ?? configPath();\n\tlet raw: string;\n\ttry {\n\t\traw = await readFile(filePath, \"utf-8\");\n\t} catch (e: unknown) {\n\t\tif (e instanceof Error && \"code\" in e && e.code === \"ENOENT\") {\n\t\t\treturn ok(DEFAULT_CONFIG);\n\t\t}\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t`Failed to read config: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\t),\n\t\t);\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = parseYaml(raw);\n\t} catch (e: unknown) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t`Invalid YAML in config: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst result = ConfigSchema.safeParse(parsed);\n\tif (!result.success) {\n\t\treturn err(\n\t\t\tfederationError(\n\t\t\t\tFederationErrorCode.InvalidRequest,\n\t\t\t\t`Invalid config: ${result.error.message}`,\n\t\t\t),\n\t\t);\n\t}\n\n\treturn ok(result.data);\n}\n","import chalk from \"chalk\";\n\nexport const colors = {\n\t// JSON tokens\n\tkey: (s: string) => chalk.cyan(s),\n\tstring: (s: string) => chalk.green(s),\n\tnumber: (s: string) => chalk.yellow(s),\n\tboolean: (s: string) => chalk.magenta(s),\n\tnull: (s: string) => chalk.dim(s),\n\n\t// Table\n\theader: (s: string) => chalk.bold.white(s),\n\tseparator: (s: string) => chalk.dim(s),\n\tlabel: (s: string) => chalk.cyan(s),\n\n\t// Status\n\tok: (s: string) => chalk.green(s),\n\twarn: (s: string) => chalk.yellow(s),\n\terror: (s: string) => chalk.red(s),\n\n\t// JWT segments\n\tjwtHeader: (s: string) => chalk.cyan(s),\n\tjwtPayload: (s: string) => chalk.green(s),\n\tjwtSignature: (s: string) => chalk.dim(s),\n\n\t// Logger levels\n\tinfo: (s: string) => chalk.blue(s),\n\tdebug: (s: string) => chalk.dim(s),\n} as const;\n\nexport function isCompactJwt(data: unknown): data is string {\n\tif (typeof data !== \"string\") return false;\n\tconst parts = data.split(\".\");\n\treturn parts.length === 3 && parts.every((p) => p.length > 0);\n}\n","import { colors, isCompactJwt } from \"./colors.js\";\nimport type { OutputFormatter } from \"./index.js\";\n\nconst STATUS_OK = new Set([\"ok\", \"active\", \"true\"]);\nconst STATUS_ERR = new Set([\"error\", \"expired\", \"revoked\", \"unreachable\", \"false\"]);\n\nfunction colorizeCell(value: unknown): string {\n\tif (typeof value === \"boolean\") {\n\t\treturn value ? colors.ok(\"✓\") : colors.error(\"✗\");\n\t}\n\tconst s = String(value ?? \"\");\n\tif (isCompactJwt(value)) {\n\t\tconst [h = \"\", p = \"\", sig = \"\"] = s.split(\".\");\n\t\treturn `${colors.jwtHeader(h)}.${colors.jwtPayload(p)}.${colors.jwtSignature(sig)}`;\n\t}\n\tconst lower = s.toLowerCase();\n\tif (STATUS_OK.has(lower)) return colors.ok(s);\n\tif (STATUS_ERR.has(lower)) return colors.error(s);\n\tif (lower === \"expiring_soon\") return colors.warn(s);\n\tif (typeof value === \"number\") return colors.number(s);\n\treturn s;\n}\n\nfunction stripAnsi(s: string): number {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI strip\n\treturn s.replace(/\\x1b\\[[0-9;]*m/g, \"\").length;\n}\n\nfunction padCell(content: string, width: number): string {\n\tconst visible = stripAnsi(content);\n\treturn content + \" \".repeat(Math.max(0, width - visible));\n}\n\nfunction isDigit(c: string): boolean {\n\treturn c >= \"0\" && c <= \"9\";\n}\n\nfunction isWordChar(c: string | undefined): boolean {\n\tif (c === undefined) return false;\n\treturn (c >= \"a\" && c <= \"z\") || (c >= \"A\" && c <= \"Z\") || (c >= \"0\" && c <= \"9\") || c === \"_\";\n}\n\n/**\n * Colorize a JSON document for terminal output.\n *\n * Implemented as a single left-to-right pass over the input so that each\n * character is examined a constant number of times — no backtracking, no\n * regex on the raw input. The complexity is therefore linear in the input\n * length, which avoids the polynomial-time pitfalls of mixed-alternation\n * regular expressions on JSON-shaped strings.\n */\nfunction colorizeJson(json: string): string {\n\tlet out = \"\";\n\tlet i = 0;\n\tconst n = json.length;\n\twhile (i < n) {\n\t\tconst c = json[i] as string;\n\t\tif (c === '\"') {\n\t\t\tlet j = i + 1;\n\t\t\tlet terminated = false;\n\t\t\twhile (j < n) {\n\t\t\t\tconst cj = json[j];\n\t\t\t\tif (cj === \"\\\\\") {\n\t\t\t\t\tj += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (cj === '\"') {\n\t\t\t\t\tj++;\n\t\t\t\t\tterminated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tconst tokenEnd = terminated ? j : n;\n\t\t\tconst literal = json.slice(i, tokenEnd);\n\t\t\tlet k = tokenEnd;\n\t\t\twhile (k < n && (json[k] === \" \" || json[k] === \"\\t\")) k++;\n\t\t\tif (terminated && json[k] === \":\") {\n\t\t\t\tout += colors.key(literal);\n\t\t\t} else {\n\t\t\t\tout += colors.string(literal);\n\t\t\t}\n\t\t\ti = tokenEnd;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst startsKeyword = (c === \"t\" || c === \"f\" || c === \"n\") && !isWordChar(json[i - 1]);\n\t\tif (startsKeyword) {\n\t\t\tif (c === \"t\" && json.slice(i, i + 4) === \"true\" && !isWordChar(json[i + 4])) {\n\t\t\t\tout += colors.boolean(\"true\");\n\t\t\t\ti += 4;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (c === \"f\" && json.slice(i, i + 5) === \"false\" && !isWordChar(json[i + 5])) {\n\t\t\t\tout += colors.boolean(\"false\");\n\t\t\t\ti += 5;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (c === \"n\" && json.slice(i, i + 4) === \"null\" && !isWordChar(json[i + 4])) {\n\t\t\t\tout += colors.null(\"null\");\n\t\t\t\ti += 4;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tconst numberStart =\n\t\t\t(c === \"-\" && isDigit(json[i + 1] ?? \"\")) || (isDigit(c) && !isWordChar(json[i - 1]));\n\t\tif (numberStart) {\n\t\t\tlet j = i;\n\t\t\tif (json[j] === \"-\") j++;\n\t\t\twhile (j < n && isDigit(json[j] as string)) j++;\n\t\t\tif (json[j] === \".\") {\n\t\t\t\tj++;\n\t\t\t\twhile (j < n && isDigit(json[j] as string)) j++;\n\t\t\t}\n\t\t\tif (json[j] === \"e\" || json[j] === \"E\") {\n\t\t\t\tj++;\n\t\t\t\tif (json[j] === \"+\" || json[j] === \"-\") j++;\n\t\t\t\twhile (j < n && isDigit(json[j] as string)) j++;\n\t\t\t}\n\t\t\tout += colors.number(json.slice(i, j));\n\t\t\ti = j;\n\t\t\tcontinue;\n\t\t}\n\n\t\tout += c;\n\t\ti++;\n\t}\n\treturn out;\n}\n\nexport class HumanFormatter implements OutputFormatter {\n\tformat(data: unknown): string {\n\t\tif (isCompactJwt(data)) {\n\t\t\tconst [header = \"\", payload = \"\", signature = \"\"] = data.split(\".\");\n\t\t\treturn `${colors.jwtHeader(header)}.${colors.jwtPayload(payload)}.${colors.jwtSignature(signature)}`;\n\t\t}\n\n\t\tif (Array.isArray(data) && data.length > 0 && typeof data[0] === \"object\" && data[0] !== null) {\n\t\t\treturn formatTable(data as Record<string, unknown>[]);\n\t\t}\n\n\t\tif (typeof data === \"object\" && data !== null && !Array.isArray(data)) {\n\t\t\treturn formatKeyValue(data as Record<string, unknown>);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof data === \"string\" ||\n\t\t\ttypeof data === \"number\" ||\n\t\t\ttypeof data === \"boolean\" ||\n\t\t\tdata === null\n\t\t) {\n\t\t\treturn colorizeJson(JSON.stringify(data, null, 2));\n\t\t}\n\n\t\treturn String(data);\n\t}\n}\n\nfunction formatTable(rows: Record<string, unknown>[]): string {\n\tconst first = rows[0] as Record<string, unknown>;\n\tconst keys = Object.keys(first);\n\tconst cells = rows.map((r) => keys.map((k) => colorizeCell(r[k])));\n\tconst rawLens = rows.map((r) => keys.map((k) => String(r[k] ?? \"\").length));\n\tconst widths = keys.map((k, i) => Math.max(k.length, ...rawLens.map((r) => r[i] ?? 0)));\n\n\tconst header = keys.map((k, i) => colors.header(k.padEnd(widths[i] ?? 0))).join(\"  \");\n\tconst separator = colors.separator(widths.map((w) => \"─\".repeat(w)).join(\"──\"));\n\tconst body = cells\n\t\t.map((row) => row.map((c, i) => padCell(c, widths[i] ?? 0)).join(\"  \"))\n\t\t.join(\"\\n\");\n\n\treturn `${header}\\n${separator}\\n${body}`;\n}\n\nfunction formatSubTable(arr: Record<string, unknown>[], indent: string): string {\n\tconst first = arr[0] as Record<string, unknown>;\n\tconst keys = Object.keys(first);\n\tconst widths = keys.map((k) => Math.max(k.length, ...arr.map((r) => String(r[k] ?? \"\").length)));\n\n\tconst header = indent + keys.map((k, i) => colors.header(k.padEnd(widths[i] ?? 0))).join(\"  \");\n\tconst sep = indent + colors.separator(widths.map((w) => \"─\".repeat(w)).join(\"──\"));\n\tconst body = arr\n\t\t.map((r) => indent + keys.map((k, i) => padCell(colorizeCell(r[k]), widths[i] ?? 0)).join(\"  \"))\n\t\t.join(\"\\n\");\n\n\treturn `${header}\\n${sep}\\n${body}`;\n}\n\nfunction formatKeyValue(obj: Record<string, unknown>): string {\n\tconst entries = Object.entries(obj);\n\tif (entries.length === 0) return \"\";\n\tconst maxKey = Math.max(...entries.map(([k]) => k.length));\n\treturn entries\n\t\t.map(([k, v]) => {\n\t\t\tif (Array.isArray(v) && v.length > 0 && typeof v[0] === \"object\" && v[0] !== null) {\n\t\t\t\tconst label = colors.label(k.padEnd(maxKey));\n\t\t\t\treturn `${label}\\n${formatSubTable(v as Record<string, unknown>[], \"  \")}`;\n\t\t\t}\n\t\t\tconst val = typeof v === \"object\" && v !== null ? JSON.stringify(v) : colorizeCell(v);\n\t\t\treturn `${colors.label(k.padEnd(maxKey))}  ${val}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n","import type { OutputFormatter } from \"./index.js\";\n\nexport class JsonFormatter implements OutputFormatter {\n\tformat(data: unknown): string {\n\t\treturn JSON.stringify(data, null, 2);\n\t}\n}\n","export interface OutputFormatter {\n\tformat(data: unknown): string;\n}\n\nexport { HumanFormatter } from \"./human.js\";\nexport { JsonFormatter } from \"./json.js\";\n\nimport { HumanFormatter } from \"./human.js\";\nimport { JsonFormatter } from \"./json.js\";\n\nexport function createFormatter(options: { json?: boolean | undefined }): OutputFormatter {\n\treturn options.json ? new JsonFormatter() : new HumanFormatter();\n}\n","import type { Result } from \"@oidfed/core\";\n\n/** Exit codes: 0 = success, 1 = federation error, 2 = usage error */\nexport const ExitCode = {\n\tOK: 0,\n\tFEDERATION_ERROR: 1,\n\tUSAGE_ERROR: 2,\n} as const;\n\nexport type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];\n\nexport function resultToExitCode(result: Result<unknown>): ExitCode {\n\treturn result.ok ? ExitCode.OK : ExitCode.FEDERATION_ERROR;\n}\n","import type { HttpClient } from \"@oidfed/core\";\n\nexport function createHttpClient(timeoutMs?: number): HttpClient {\n\tif (!timeoutMs) return fetch;\n\treturn (input, init) => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), timeoutMs);\n\t\treturn fetch(input, { ...init, signal: controller.signal }).finally(() => clearTimeout(timer));\n\t};\n}\n","import { colors } from \"../output/colors.js\";\n\nexport interface LoggerOptions {\n\treadonly quiet: boolean;\n\treadonly verbose: boolean;\n\treadonly stderr?: Pick<NodeJS.WritableStream, \"write\">;\n}\n\nexport interface Logger {\n\tinfo(msg: string): void;\n\terror(msg: string): void;\n\tdebug(msg: string): void;\n\twarn(msg: string): void;\n}\n\nexport function createLogger(opts: LoggerOptions): Logger {\n\tconst stream = opts.stderr ?? process.stderr;\n\tconst write = (prefix: string, msg: string) => {\n\t\tstream.write(`${prefix} ${msg}\\n`);\n\t};\n\n\treturn {\n\t\tinfo(msg: string) {\n\t\t\tif (!opts.quiet) write(colors.info(\"[info]\"), msg);\n\t\t},\n\t\terror(msg: string) {\n\t\t\twrite(colors.error(\"[error]\"), msg);\n\t\t},\n\t\tdebug(msg: string) {\n\t\t\tif (opts.verbose) write(colors.debug(\"[debug]\"), msg);\n\t\t},\n\t\twarn(msg: string) {\n\t\t\tif (!opts.quiet) write(colors.warn(\"[warn]\"), msg);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAyB;AACzB,uBAAwB;;;ACDxB;AAAA,EACC,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,SAAW;AAAA,EACX,QAAU;AAAA,EACV,YAAc;AAAA,IACb,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACd;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,IACP,KAAO;AAAA,EACR;AAAA,EACA,UAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,KAAO;AAAA,IACN,QAAU;AAAA,IACV,WAAa;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACV,KAAK;AAAA,MACJ,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACZ;AAAA,EACD;AAAA,EACA,OAAS;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,EACD;A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AACtE,EAAiBA,WAAS,SAAS,EAAE,YAAY,WAAW,OAAO,CAAC;AACpE,EAAUA,UAAS,SAAS,EAAE,YAAY,WAAW,QAAQ,UAAU,WAAW,CAAC;AACnF,EAAUA,WAAS,SAAS,EAAE,YAAY,WAAW,QAAQ,UAAU,WAAW,CAAC;AAEnF,MAAI;AACH,UAAM,QAAQ,WAAW,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAO,QAAQ,WAAW,OAAO,QAAQ,QAAQ,IAAI,SAAS;AAAA,EAC/D,QAAQ;AACP,WAAO,SAAS;AAAA,EACjB;AACD;","names":["import_promises","import_core","import_core","import_core","handler","register","import_core","handler","decoded","register","import_core","handler","register","import_core","import_core","entityId","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handler","register","import_core","handleEntityIdMode","handler","register","import_core","handler","register","import_core","parseYaml","chalk","register"]}