From c301208241eb152c8396020c7921441cda9cf536 Mon Sep 17 00:00:00 2001 From: chou-godaddy Date: Thu, 1 Oct 2026 14:28:06 -0700 Subject: [PATCH 1/4] feat(hcs-25): add ans-trust-discovery adapter Implements the ans-trust-discovery adapter and signal family documented in the HCS-25 specification (adapters/ans-trust-discovery.md and signals/ans-trust-discovery.md). - Passes through the eight ANS Trust Index signals stored under metadata.ansTrustDiscovery (certtype, dnssecurity, agentage, versionstability, dnsconsistency, httpsrecord, agentcard, certificatehygiene) as one component each. Null or absent signals are excluded from the adapter mean. - Scoped to registry=ans with weight 1 and default component key ans-trust-discovery.certtype, per the specification. - A stored ansTrustDiscoveryStatus of stale applies the stale multiplier. - Adds the stored-field schema and HCS25_SIGNAL_CATALOG entry, registers the adapter in createHcs25AdapterCatalog, and adds tests. Refs: hiero-ledger/hiero-consensus-specifications#38 Signed-off-by: chou-godaddy --- .../hcs-25/hcs-25-adapter-catalog.test.ts | 2 + ...cs-25-adapters-ans-trust-discovery.test.ts | 290 ++++++++++++++++++ .../hcs-25/hcs-25-signal-schemas.test.ts | 29 ++ src/hcs-25/adapters/ans-trust-discovery.ts | 86 ++++++ src/hcs-25/adapters/index.ts | 3 + src/hcs-25/signals/ans-trust-discovery.ts | 46 +++ src/hcs-25/signals/index.ts | 16 + 7 files changed, 472 insertions(+) create mode 100644 __tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts create mode 100644 src/hcs-25/adapters/ans-trust-discovery.ts create mode 100644 src/hcs-25/signals/ans-trust-discovery.ts diff --git a/__tests__/hcs-25/hcs-25-adapter-catalog.test.ts b/__tests__/hcs-25/hcs-25-adapter-catalog.test.ts index db7d927..fd49326 100644 --- a/__tests__/hcs-25/hcs-25-adapter-catalog.test.ts +++ b/__tests__/hcs-25/hcs-25-adapter-catalog.test.ts @@ -30,6 +30,7 @@ describe('HCS-25 adapter catalog', () => { 'model-tier', 'output-verification', 'connectivity', + 'ans-trust-discovery', ].sort(), ); }); @@ -55,6 +56,7 @@ describe('HCS-25 adapter catalog', () => { 'model-tier': ['conditional', 2], 'output-verification': ['scoped', 1], connectivity: ['conditional', 1], + 'ans-trust-discovery': ['scoped', 1], }; for (const adapter of catalog) { diff --git a/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts b/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts new file mode 100644 index 0000000..b6e2c2d --- /dev/null +++ b/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts @@ -0,0 +1,290 @@ +import { describe, expect, test } from '@jest/globals'; + +import type { Hcs25JsonValue, Hcs25Subject } from '../../src/hcs-25/types'; +import { + compileScoringConfig, + computeTrustScore, +} from '../../src/hcs-25/scoring'; +import { + createAnsTrustDiscoveryAdapter, + createAvailabilityAdapter, +} from '../../src/hcs-25/adapters'; + +type AdapterDefinition = Parameters< + typeof computeTrustScore +>[0]['config']['adapters'][number]; + +function scoreOne( + adapter: AdapterDefinition, + subject: Hcs25Subject, +): ReturnType { + return computeTrustScore({ + subject, + snapshot: {}, + config: { version: 1, adapters: [adapter] }, + }); +} + +const UAID = + 'uaid:aid:7bU8xK;uid=b8d9425f-fd9f-47a5-ae5d-8ab51bda04c9;registry=ans;proto=a2a;nativeId=support-agent.example.com;version=v1.0.0'; + +const FULL_SIGNALS: Record = { + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.dnssecurity': 80, + 'ans-trust-discovery.agentage': 60, + 'ans-trust-discovery.versionstability': 100, + 'ans-trust-discovery.dnsconsistency': 70, + 'ans-trust-discovery.httpsrecord': 100, + 'ans-trust-discovery.agentcard': 100, + 'ans-trust-discovery.certificatehygiene': 95, +}; + +function ansSubject( + ansTrustDiscovery?: Record, + registry = 'ans', +): Hcs25Subject { + return { + id: UAID, + registry, + metadata: ansTrustDiscovery ? { ansTrustDiscovery } : {}, + }; +} + +describe('HCS-25 ANS trust discovery adapter', () => { + test('declares the specified id, mode, weight, and default component key', () => { + const adapter = createAnsTrustDiscoveryAdapter(); + + expect(adapter.id).toBe('ans-trust-discovery'); + expect(adapter.contributionMode).toBe('scoped'); + expect(adapter.weight).toBe(1); + expect(adapter.includeRegistries).toEqual(['ans']); + expect(adapter.defaultComponentKey).toBe('ans-trust-discovery.certtype'); + expect(adapter.components.map(component => component.name)).toEqual([ + 'certtype', + 'dnssecurity', + 'agentage', + 'versionstability', + 'dnsconsistency', + 'httpsrecord', + 'agentcard', + 'certificatehygiene', + ]); + expect(() => + compileScoringConfig({ version: 1, adapters: [adapter] }), + ).not.toThrow(); + }); + + test('passes each provider score through as one component', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ ...FULL_SIGNALS, ansTrustDiscoveryStatus: 'ok' }), + ); + + for (const [key, value] of Object.entries(FULL_SIGNALS)) { + expect(result.trustScores[key]).toBe(value); + } + const adapterScore = result.breakdown.adapters[0]; + expect(adapterScore?.applicable).toBe(true); + expect(adapterScore?.inDenominator).toBe(true); + expect(adapterScore?.unavailable).toEqual([]); + expect(adapterScore?.total).toBe(88.13); + expect(result.trustScores.total).toBe(88.13); + }); + + test('clamps out-of-range scores to [0,100]', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': 140, + 'ans-trust-discovery.dnssecurity': -5, + }), + ); + + expect(result.trustScores['ans-trust-discovery.certtype']).toBe(100); + expect(result.trustScores['ans-trust-discovery.dnssecurity']).toBe(0); + }); + + test('excludes missing signals from the adapter total', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.dnssecurity': 50, + 'ans-trust-discovery.agentcard': null, + }), + ); + + const adapterScore = result.breakdown.adapters[0]; + expect(adapterScore?.components.map(component => component.key)).toEqual([ + 'ans-trust-discovery.certtype', + 'ans-trust-discovery.dnssecurity', + ]); + expect(adapterScore?.unavailable).toEqual([ + 'ans-trust-discovery.agentage', + 'ans-trust-discovery.versionstability', + 'ans-trust-discovery.dnsconsistency', + 'ans-trust-discovery.httpsrecord', + 'ans-trust-discovery.agentcard', + 'ans-trust-discovery.certificatehygiene', + ]); + expect(adapterScore?.total).toBe(75); + expect(result.trustScores['ans-trust-discovery.agentcard']).toBeUndefined(); + }); + + test('keeps a measured zero distinct from a missing signal', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.httpsrecord': 0, + }), + ); + + expect(result.trustScores['ans-trust-discovery.httpsrecord']).toBe(0); + expect(result.breakdown.adapters[0]?.total).toBe(50); + }); + + test('treats non-numeric values as missing', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': '90', + 'ans-trust-discovery.dnssecurity': true, + 'ans-trust-discovery.agentage': 40, + }), + ); + + const adapterScore = result.breakdown.adapters[0]; + expect(adapterScore?.unavailable).toContain('ans-trust-discovery.certtype'); + expect(adapterScore?.unavailable).toContain( + 'ans-trust-discovery.dnssecurity', + ); + expect(adapterScore?.total).toBe(40); + }); + + test('ignores signals outside the specified set', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.unlisted': 0, + }), + ); + + expect(result.trustScores['ans-trust-discovery.unlisted']).toBeUndefined(); + expect(result.breakdown.adapters[0]?.total).toBe(100); + }); + + test('stays in the denominator at zero when no signals are available', () => { + for (const subject of [ansSubject(), ansSubject({})]) { + const result = scoreOne(createAnsTrustDiscoveryAdapter(), subject); + const adapterScore = result.breakdown.adapters[0]; + + expect(adapterScore?.inDenominator).toBe(true); + expect(adapterScore?.total).toBe(0); + expect(adapterScore?.components).toEqual([ + { + key: 'ans-trust-discovery.certtype', + value: 0, + status: 'missing', + weight: 1, + }, + ]); + expect(adapterScore?.unavailable).toHaveLength(8); + } + }); + + test('applies only to subjects in the ans registry', () => { + const other = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject(FULL_SIGNALS, 'agentverse'), + ); + expect(other.breakdown.adapters[0]?.applicable).toBe(false); + expect(other.breakdown.adapters[0]?.inDenominator).toBe(false); + expect(other.trustScores['ans-trust-discovery.certtype']).toBeUndefined(); + + const unregistered = scoreOne(createAnsTrustDiscoveryAdapter(), { + id: 'agent:a', + metadata: { ansTrustDiscovery: FULL_SIGNALS }, + }); + expect(unregistered.breakdown.adapters[0]?.applicable).toBe(false); + }); + + test('supports custom registries', () => { + const result = scoreOne( + createAnsTrustDiscoveryAdapter({ + includeRegistries: ['example-registry'], + }), + ansSubject(FULL_SIGNALS, 'example-registry'), + ); + + expect(result.breakdown.adapters[0]?.applicable).toBe(true); + expect(result.trustScores['ans-trust-discovery.certtype']).toBe(100); + }); + + test('applies the staleness multiplier to stale signals', () => { + const result = computeTrustScore({ + subject: ansSubject({ + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.agentage': 60, + ansTrustDiscoveryStatus: 'stale', + }), + snapshot: {}, + config: { + version: 1, + staleMultiplier: 0.5, + adapters: [createAnsTrustDiscoveryAdapter()], + }, + }); + + expect(result.trustScores['ans-trust-discovery.certtype']).toBe(50); + expect(result.trustScores['ans-trust-discovery.agentage']).toBe(30); + expect(result.breakdown.adapters[0]?.components[0]?.status).toBe('stale'); + }); + + test('keeps present scores when the collection status is error or timeout', () => { + for (const status of ['error', 'timeout']) { + const result = scoreOne( + createAnsTrustDiscoveryAdapter(), + ansSubject({ + 'ans-trust-discovery.certtype': 100, + ansTrustDiscoveryStatus: status, + }), + ); + const adapterScore = result.breakdown.adapters[0]; + + expect(adapterScore?.components).toEqual([ + { + key: 'ans-trust-discovery.certtype', + value: 100, + status: 'ok', + weight: 1, + }, + ]); + expect(adapterScore?.unavailable).toHaveLength(7); + } + }); + + test('contributes to the composite alongside other adapters', () => { + const result = computeTrustScore({ + subject: { + ...ansSubject(FULL_SIGNALS), + metadata: { + availabilityScore: 0.5, + ansTrustDiscovery: FULL_SIGNALS, + }, + }, + snapshot: {}, + config: { + version: 1, + adapters: [ + createAvailabilityAdapter(), + createAnsTrustDiscoveryAdapter(), + ], + }, + }); + + expect(result.trustScores['availability.uptime']).toBe(50); + expect(result.trustScores.total).toBe(69.07); + }); +}); diff --git a/__tests__/hcs-25/hcs-25-signal-schemas.test.ts b/__tests__/hcs-25/hcs-25-signal-schemas.test.ts index b451605..3b79dce 100644 --- a/__tests__/hcs-25/hcs-25-signal-schemas.test.ts +++ b/__tests__/hcs-25/hcs-25-signal-schemas.test.ts @@ -3,6 +3,7 @@ import { describe, expect, test } from '@jest/globals'; import { HCS25_SIGNAL_CATALOG, hcs25AcpMetricsSchema, + hcs25AnsTrustDiscoveryFieldsSchema, hcs25AgentverseInsightsSchema, hcs25AvailabilityFieldsSchema, hcs25ChatbotArenaFieldsSchema, @@ -36,6 +37,7 @@ describe('HCS-25 signal catalog coverage', () => { 'huggingface-model-index', 'openllm-leaderboard', 'output-verification', + 'ans-trust-discovery', ]; expect(Object.keys(HCS25_SIGNAL_CATALOG).sort()).toEqual( @@ -249,4 +251,31 @@ describe('HCS-25 signal schemas', () => { }); expect(invalid.success).toBe(false); }); + + test('validates ANS trust discovery signals with missing values', () => { + const parsed = hcs25AnsTrustDiscoveryFieldsSchema.safeParse({ + 'ans-trust-discovery.certtype': 100, + 'ans-trust-discovery.dnssecurity': 80, + 'ans-trust-discovery.agentage': 60, + 'ans-trust-discovery.versionstability': 100, + 'ans-trust-discovery.dnsconsistency': 70, + 'ans-trust-discovery.httpsrecord': 0, + 'ans-trust-discovery.agentcard': null, + 'ans-trust-discovery.certificatehygiene': 95, + ansTrustDiscoveryStatus: 'ok', + ansTrustDiscoveryUpdatedAt: '2026-08-18T01:58:17.623Z', + }); + expect(parsed.success).toBe(true); + + expect( + hcs25AnsTrustDiscoveryFieldsSchema.safeParse({ + 'ans-trust-discovery.certtype': 140, + }).success, + ).toBe(false); + expect( + hcs25AnsTrustDiscoveryFieldsSchema.safeParse({ + ansTrustDiscoveryStatus: 'unknown', + }).success, + ).toBe(false); + }); }); diff --git a/src/hcs-25/adapters/ans-trust-discovery.ts b/src/hcs-25/adapters/ans-trust-discovery.ts new file mode 100644 index 0000000..8cd884b --- /dev/null +++ b/src/hcs-25/adapters/ans-trust-discovery.ts @@ -0,0 +1,86 @@ +import { clampScore } from '../scoring'; +import type { + Hcs25AdapterDefinition, + Hcs25ComponentDefinition, + Hcs25NormalizedValue, + Hcs25Subject, +} from '../types'; +import { + HCS25_ANS_TRUST_DISCOVERY_SIGNALS, + readMetadataRecord, + readNumber, + readString, + type Hcs25AnsTrustDiscoverySignal, +} from '../signals'; + +/** + * Options for the ANS Trust Discovery adapter. + */ +export interface Hcs25AnsTrustDiscoveryAdapterOptions { + /** Registries whose subjects carry ANS Trust Index signals. */ + includeRegistries?: readonly string[]; +} + +const ADAPTER_ID = 'ans-trust-discovery'; + +const DEFAULT_INCLUDED_REGISTRIES: readonly string[] = ['ans']; + +const MISSING: Hcs25NormalizedValue = { value: 0, status: 'missing' }; + +/** + * Reads one stored signal score. A null or absent score is missing; a present + * score keeps the record-level `ansTrustDiscoveryStatus` of `stale` so the + * scoring layer applies the stale multiplier. + */ +function normalizeAnsTrustSignal( + subject: Hcs25Subject, + signal: Hcs25AnsTrustDiscoverySignal, +): Hcs25NormalizedValue { + const record = readMetadataRecord(subject, 'ansTrustDiscovery'); + if (!record) { + return MISSING; + } + + const score = readNumber(record, `${ADAPTER_ID}.${signal}`); + if (score === null) { + return MISSING; + } + + const status = readString(record, 'ansTrustDiscoveryStatus'); + return { + value: clampScore(score), + status: status === 'stale' ? 'stale' : 'ok', + }; +} + +/** + * Creates the `ans-trust-discovery` adapter: passes through the + * infrastructure trust signals published by an ANS Trust Index provider + * (certificate type, DNS security, agent age, version stability, DNS + * consistency, HTTPS record, agent card, certificate hygiene) as one + * component each. Scores are pre-normalized to `[0,100]` by the provider; + * signals the provider could not compute are excluded from the adapter + * total, which is the mean of the remaining components. + * + * Applies to subjects whose `registry` is `ans` (the UAID `registry` + * parameter); callers set `subject.registry` when building the subject. + */ +export function createAnsTrustDiscoveryAdapter( + options: Hcs25AnsTrustDiscoveryAdapterOptions = {}, +): Hcs25AdapterDefinition { + return { + id: ADAPTER_ID, + weight: 1, + contributionMode: 'scoped', + includeRegistries: options.includeRegistries ?? DEFAULT_INCLUDED_REGISTRIES, + defaultComponentKey: `${ADAPTER_ID}.certtype`, + components: HCS25_ANS_TRUST_DISCOVERY_SIGNALS.map( + (signal): Hcs25ComponentDefinition => ({ + name: signal, + nonScorableWhenUnavailable: true, + normalize: ({ subject }): Hcs25NormalizedValue => + normalizeAnsTrustSignal(subject, signal), + }), + ), + }; +} diff --git a/src/hcs-25/adapters/index.ts b/src/hcs-25/adapters/index.ts index 54e427f..96dadda 100644 --- a/src/hcs-25/adapters/index.ts +++ b/src/hcs-25/adapters/index.ts @@ -4,6 +4,7 @@ import { createAgentverseInsightsAdapter, createAgentverseVerifierAdapter, } from './agentverse'; +import { createAnsTrustDiscoveryAdapter } from './ans-trust-discovery'; import { createAvailabilityAdapter } from './availability'; import { createConnectivityAdapter } from './connectivity'; import { createErc8004FeedbackAdapter } from './erc8004-feedback'; @@ -35,6 +36,7 @@ export * from './agentverse'; export * from './model-evals'; export * from './output-verification'; export * from './connectivity'; +export * from './ans-trust-discovery'; /** * Creates the full HCS-25 adapter catalog documented in the specification, @@ -61,5 +63,6 @@ export function createHcs25AdapterCatalog(): Hcs25AdapterDefinition[] { createModelTierAdapter(), createOutputVerificationAdapter(), createConnectivityAdapter(), + createAnsTrustDiscoveryAdapter(), ]; } diff --git a/src/hcs-25/signals/ans-trust-discovery.ts b/src/hcs-25/signals/ans-trust-discovery.ts new file mode 100644 index 0000000..2c8f449 --- /dev/null +++ b/src/hcs-25/signals/ans-trust-discovery.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +import { hcs25SignalStatusSchema } from '../types'; + +/** + * Signals published by an ANS Trust Index provider and consumed by the + * `ans-trust-discovery` adapter, in specification order. + */ +export const HCS25_ANS_TRUST_DISCOVERY_SIGNALS = [ + 'certtype', + 'dnssecurity', + 'agentage', + 'versionstability', + 'dnsconsistency', + 'httpsrecord', + 'agentcard', + 'certificatehygiene', +] as const; + +/** + * One signal name from {@link HCS25_ANS_TRUST_DISCOVERY_SIGNALS}. + */ +export type Hcs25AnsTrustDiscoverySignal = + (typeof HCS25_ANS_TRUST_DISCOVERY_SIGNALS)[number]; + +const ansTrustDiscoveryScoreSchema = z.number().min(0).max(100).nullish(); + +/** + * Stored-field schema for ANS Trust Index signals stored under + * `metadata.ansTrustDiscovery`. Each signal is a provider-normalized score + * in `[0,100]`, or null when the provider could not compute it. + */ +export const hcs25AnsTrustDiscoveryFieldsSchema = z + .object({ + 'ans-trust-discovery.certtype': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.dnssecurity': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.agentage': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.versionstability': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.dnsconsistency': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.httpsrecord': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.agentcard': ansTrustDiscoveryScoreSchema, + 'ans-trust-discovery.certificatehygiene': ansTrustDiscoveryScoreSchema, + ansTrustDiscoveryStatus: hcs25SignalStatusSchema.nullish(), + ansTrustDiscoveryUpdatedAt: z.string().nullish(), + }) + .passthrough(); diff --git a/src/hcs-25/signals/index.ts b/src/hcs-25/signals/index.ts index 651b0fe..eeaa2b4 100644 --- a/src/hcs-25/signals/index.ts +++ b/src/hcs-25/signals/index.ts @@ -3,6 +3,7 @@ export * from './simple-evals'; export * from './marketplace'; export * from './operational'; export * from './model-evals'; +export * from './ans-trust-discovery'; /** * Documentation for one published signal family: where it is stored on the @@ -220,4 +221,19 @@ export const HCS25_SIGNAL_CATALOG: Readonly< 'updatedAt', ], }, + 'ans-trust-discovery': { + storage: 'metadata.ansTrustDiscovery', + fields: [ + 'ans-trust-discovery.certtype', + 'ans-trust-discovery.dnssecurity', + 'ans-trust-discovery.agentage', + 'ans-trust-discovery.versionstability', + 'ans-trust-discovery.dnsconsistency', + 'ans-trust-discovery.httpsrecord', + 'ans-trust-discovery.agentcard', + 'ans-trust-discovery.certificatehygiene', + 'ansTrustDiscoveryStatus', + 'ansTrustDiscoveryUpdatedAt', + ], + }, }; From bce193cdf398ffa99ecad2e333312204f265cabd Mon Sep 17 00:00:00 2001 From: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> Date: Thu, 8 Oct 2026 10:51:37 -0400 Subject: [PATCH 2/4] fix(hcs-25): propagate ans trust discovery collection failures A stored ansTrustDiscoveryStatus of timeout or error with no score now surfaces that status, matching the other HCS-25 adapters. Present scores still pass through, and stale still keeps the score for the multiplier. Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> --- ...cs-25-adapters-ans-trust-discovery.test.ts | 33 +++++++++++++++ src/hcs-25/adapters/ans-trust-discovery.ts | 40 +++++++++++++------ 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts b/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts index b6e2c2d..c8aacdc 100644 --- a/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts +++ b/__tests__/hcs-25/hcs-25-adapters-ans-trust-discovery.test.ts @@ -242,6 +242,39 @@ describe('HCS-25 ANS trust discovery adapter', () => { expect(result.breakdown.adapters[0]?.components[0]?.status).toBe('stale'); }); + test('surfaces error and timeout when no score was stored', () => { + const adapter = createAnsTrustDiscoveryAdapter(); + const config = compileScoringConfig({ version: 1, adapters: [adapter] }); + + for (const status of ['error', 'timeout'] as const) { + for (const component of adapter.components) { + expect( + component.normalize({ + subject: ansSubject({ ansTrustDiscoveryStatus: status }), + snapshot: {}, + config, + }), + ).toEqual({ value: 0, status }); + } + } + }); + + test('treats a stale record with no score as missing', () => { + const adapter = createAnsTrustDiscoveryAdapter(); + const config = compileScoringConfig({ version: 1, adapters: [adapter] }); + const certtype = adapter.components.find( + component => component.name === 'certtype', + ); + + expect( + certtype?.normalize({ + subject: ansSubject({ ansTrustDiscoveryStatus: 'stale' }), + snapshot: {}, + config, + }), + ).toEqual({ value: 0, status: 'missing' }); + }); + test('keeps present scores when the collection status is error or timeout', () => { for (const status of ['error', 'timeout']) { const result = scoreOne( diff --git a/src/hcs-25/adapters/ans-trust-discovery.ts b/src/hcs-25/adapters/ans-trust-discovery.ts index 8cd884b..2d93067 100644 --- a/src/hcs-25/adapters/ans-trust-discovery.ts +++ b/src/hcs-25/adapters/ans-trust-discovery.ts @@ -28,9 +28,29 @@ const DEFAULT_INCLUDED_REGISTRIES: readonly string[] = ['ans']; const MISSING: Hcs25NormalizedValue = { value: 0, status: 'missing' }; /** - * Reads one stored signal score. A null or absent score is missing; a present - * score keeps the record-level `ansTrustDiscoveryStatus` of `stale` so the - * scoring layer applies the stale multiplier. + * Maps a stored `ansTrustDiscoveryStatus` onto one signal. A present score + * keeps `stale` so the scoring layer applies the stale multiplier, and + * otherwise passes through as ok. `timeout` or `error` with no score surfaces + * as that status. Anything else without a score is missing. + */ +function ansTrustStatus( + status: string | null, + score: number | null, +): Hcs25NormalizedValue { + if (score !== null) { + return { + value: clampScore(score), + status: status === 'stale' ? 'stale' : 'ok', + }; + } + if (status === 'timeout' || status === 'error') { + return { value: 0, status }; + } + return MISSING; +} + +/** + * Reads one stored signal score from `metadata.ansTrustDiscovery`. */ function normalizeAnsTrustSignal( subject: Hcs25Subject, @@ -41,16 +61,10 @@ function normalizeAnsTrustSignal( return MISSING; } - const score = readNumber(record, `${ADAPTER_ID}.${signal}`); - if (score === null) { - return MISSING; - } - - const status = readString(record, 'ansTrustDiscoveryStatus'); - return { - value: clampScore(score), - status: status === 'stale' ? 'stale' : 'ok', - }; + return ansTrustStatus( + readString(record, 'ansTrustDiscoveryStatus'), + readNumber(record, `${ADAPTER_ID}.${signal}`), + ); } /** From 70b9dede9e7d3d072a6ec8cd1d5c9cce38bf1d48 Mon Sep 17 00:00:00 2001 From: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> Date: Thu, 8 Oct 2026 10:59:57 -0400 Subject: [PATCH 3/4] feat(hcs-25): collect ans trust discovery signals Adds the ans-trust-discovery signal collector next to the other HCS-25 collectors. It reads the provider registered-agent response, stores the eight scores under metadata.ansTrustDiscovery, and records timeout or error when the request fails. Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> --- __tests__/hcs-25/hcs-25-collectors.test.ts | 136 ++++++++++++ src/hcs-25/collectors/ans-trust-discovery.ts | 216 +++++++++++++++++++ src/hcs-25/collectors/catalog.ts | 18 +- src/hcs-25/collectors/index.ts | 1 + 4 files changed, 369 insertions(+), 2 deletions(-) create mode 100644 src/hcs-25/collectors/ans-trust-discovery.ts diff --git a/__tests__/hcs-25/hcs-25-collectors.test.ts b/__tests__/hcs-25/hcs-25-collectors.test.ts index 429c75c..2a3c5dc 100644 --- a/__tests__/hcs-25/hcs-25-collectors.test.ts +++ b/__tests__/hcs-25/hcs-25-collectors.test.ts @@ -2,6 +2,7 @@ import { describe, expect, test } from '@jest/globals'; import { computeTrustScore } from '../../src/hcs-25/scoring'; import { + createAnsTrustDiscoveryAdapter, createAvailabilityAdapter, createConnectivityAdapter, createEthosAdapter, @@ -19,6 +20,7 @@ import { collectAndScoreTrustScore, collectHcs25Signals, createAgentverseInsightsSignalAdapter, + createAnsTrustDiscoverySignalAdapter, createAvailabilitySignalAdapter, createErc8004SignalAdapter, createEthosSignalAdapter, @@ -1011,6 +1013,138 @@ describe('isTimeoutError', () => { }); }); +describe('ans trust discovery signal adapter', () => { + const UAID = + 'uaid:aid:7bU8xK;uid=b8d9425f-fd9f-47a5-ae5d-8ab51bda04c9;registry=ans;proto=a2a;nativeId=support-agent.example.com;version=v1.0.0'; + + const providerResponse = { + signals: { + certtype: { score: 100, missing: false }, + dnssecurity: { score: 80, missing: false }, + agentage: { score: 60, missing: false }, + versionstability: { score: 100, missing: false }, + dnsconsistency: { score: 70, missing: false }, + httpsrecord: { score: 140, missing: false }, + agentcard: { score: 100, missing: true }, + certificatehygiene: { score: 95, missing: false }, + }, + }; + + test('stores provider scores and the scoring adapter consumes them', async () => { + let requested = ''; + const fetchImpl: Hcs25Fetch = async url => { + requested = url; + return okResponse(providerResponse); + }; + const collection = await collectHcs25Signals( + { id: UAID, registry: 'ans' }, + { + adapters: [ + createAnsTrustDiscoverySignalAdapter({ + baseUrl: 'https://ans.example.com/', + }), + ], + fetch: fetchImpl, + now: new Date('2026-08-18T01:58:17.623Z'), + }, + ); + + expect(requested).toBe( + 'https://ans.example.com/v1/ans/registered-agents/support-agent.example.com', + ); + const stored = collection.subject.metadata?.ansTrustDiscovery as Record< + string, + unknown + >; + expect(stored['ans-trust-discovery.certtype']).toBe(100); + expect(stored['ans-trust-discovery.httpsrecord']).toBe(100); + expect(stored['ans-trust-discovery.agentcard']).toBeNull(); + expect(stored.ansTrustDiscoveryStatus).toBe('ok'); + expect(stored.ansTrustDiscoveryUpdatedAt).toBe('2026-08-18T01:58:17.623Z'); + expect(collection.snapshot['ans-trust-discovery.agentcard'].status).toBe( + 'missing', + ); + + const record = computeTrustScore({ + subject: collection.subject, + snapshot: collection.snapshot, + config: { version: 1, adapters: [createAnsTrustDiscoveryAdapter()] }, + }); + expect(record.trustScores['ans-trust-discovery.certtype']).toBe(100); + expect(record.trustScores['ans-trust-discovery.httpsrecord']).toBe(100); + expect(record.trustScores['ans-trust-discovery.agentcard']).toBeUndefined(); + expect(record.trustScores.total).toBe(86.43); + }); + + test('is missing when the subject has no ANS agent id', async () => { + const collection = await collectHcs25Signals( + { id: 'agent:plain', registry: 'ans' }, + { + adapters: [createAnsTrustDiscoverySignalAdapter()], + fetch: fetchReturning({}), + }, + ); + expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( + 'missing', + ); + expect(collection.subject.metadata?.ansTrustDiscovery).toBeUndefined(); + }); + + test('treats HTTP 404 as missing', async () => { + const collection = await collectHcs25Signals( + { id: UAID, registry: 'ans' }, + { + adapters: [createAnsTrustDiscoverySignalAdapter()], + fetch: fetchWithStatus(404), + }, + ); + expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( + 'missing', + ); + expect(collection.results[0]?.status).toBe('missing'); + }); + + test('stores timeout and error without a score', async () => { + for (const [name, status] of [ + ['TimeoutError', 'timeout'], + ['Error', 'error'], + ] as const) { + const fetchImpl: Hcs25Fetch = async () => { + const error = new Error('upstream failed'); + error.name = name; + throw error; + }; + const collection = await collectHcs25Signals( + { id: UAID, registry: 'ans' }, + { + adapters: [createAnsTrustDiscoverySignalAdapter()], + fetch: fetchImpl, + }, + ); + const stored = collection.subject.metadata?.ansTrustDiscovery as Record< + string, + unknown + >; + expect(stored.ansTrustDiscoveryStatus).toBe(status); + expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( + status, + ); + } + }); + + test('does not apply outside the ans registry', async () => { + const collection = await collectHcs25Signals( + { id: UAID, registry: 'agentverse' }, + { + adapters: [createAnsTrustDiscoverySignalAdapter()], + fetch: fetchReturning(providerResponse), + }, + ); + expect(collection.results[0]?.applicable).toBe(false); + expect(collection.snapshot['ans-trust-discovery.certtype']).toBeUndefined(); + }); +}); + describe('adapter coverage mapping', () => { test('every scoring adapter has at least one signal collector', () => { const transport = { @@ -1034,6 +1168,7 @@ describe('adapter coverage mapping', () => { outputVerification: { providers: [{ id: 'test', baseUrl: 'https://verify.example.com' }], }, + ansTrustDiscovery: true, simpleEvals: { a2a: { transport }, agentverse: { transport }, @@ -1074,6 +1209,7 @@ describe('adapter coverage mapping', () => { ], 'output-verification': ['output-verification'], connectivity: ['connectivity'], + 'ans-trust-discovery': ['ans-trust-discovery'], }; const scoringAdapters = createHcs25AdapterCatalog(); diff --git a/src/hcs-25/collectors/ans-trust-discovery.ts b/src/hcs-25/collectors/ans-trust-discovery.ts new file mode 100644 index 0000000..80f9ee4 --- /dev/null +++ b/src/hcs-25/collectors/ans-trust-discovery.ts @@ -0,0 +1,216 @@ +import type { Hcs25JsonValue, Hcs25Subject } from '../types'; +import { readString } from '../signals'; +import { HCS25_ANS_TRUST_DISCOVERY_SIGNALS } from '../signals/ans-trust-discovery'; +import { + Hcs25CollectorHttpError, + isTimeoutError, + requestJson, + stripTrailingSlashes, +} from './http'; +import type { + Hcs25CollectContext, + Hcs25SignalAdapter, + Hcs25SignalAdapterResult, +} from './types'; + +/** + * Provider listed in the ANS Trust Discovery signal specification. + * Callers can point {@link Hcs25AnsTrustDiscoverySignalAdapterOptions.baseUrl} + * at another provider that serves the same response shape. + */ +const DEFAULT_ANS_BASE_URL = 'https://api.godaddy.com'; + +const SIGNAL_IDS = HCS25_ANS_TRUST_DISCOVERY_SIGNALS.map( + signal => `ans-trust-discovery.${signal}`, +); + +/** + * Options for the ANS Trust Discovery signal adapter. + */ +export interface Hcs25AnsTrustDiscoverySignalAdapterOptions { + /** + * ANS Trust Index origin. Requests + * `GET {baseUrl}/v1/ans/registered-agents/{agentId}`. + * Default `https://api.godaddy.com`. + */ + baseUrl?: string; + /** Extra request headers, such as a provider credential. */ + headers?: Record; + /** + * Resolves the provider agent id. Default reads `metadata.nativeId`, + * then the `nativeId` parameter of a UAID in `subject.id` or + * `metadata.uaidFull`. + */ + resolveAgentId?: (subject: Hcs25Subject) => string | null; + timeoutMs?: number; + includeRegistries?: readonly string[]; + excludeRegistries?: readonly string[]; + appliesTo?: (subject: Hcs25Subject) => boolean; +} + +const DEFAULT_INCLUDED_REGISTRIES: readonly string[] = ['ans']; + +interface AnsSignalPayload { + score?: unknown; + missing?: unknown; +} + +interface AnsTrustResponse { + signals?: Record; +} + +function nativeIdFromUaid(value: string | null): string | null { + if (!value) { + return null; + } + const nativeId = value.match(/(?:^|;)nativeId=([^;]+)(?:;|$)/i)?.[1]?.trim(); + if (!nativeId) { + return null; + } + try { + return decodeURIComponent(nativeId); + } catch { + return nativeId; + } +} + +function defaultResolveAgentId(subject: Hcs25Subject): string | null { + const metadata = subject.metadata ?? {}; + return ( + readString(metadata, 'nativeId') ?? + nativeIdFromUaid(subject.id) ?? + nativeIdFromUaid(readString(metadata, 'uaidFull')) + ); +} + +function readSignalScore(payload: AnsSignalPayload | undefined): number | null { + if (!payload || payload.missing === true) { + return null; + } + const score = payload.score; + if (typeof score !== 'number' || !Number.isFinite(score)) { + return null; + } + return Math.min(100, Math.max(0, score)); +} + +function statusResult( + status: 'missing' | 'timeout' | 'error', + now: string, + url: string | undefined, + agentId: string | undefined, +): Hcs25SignalAdapterResult[] { + return [ + { + signalId: SIGNAL_IDS[0], + status, + fields: + status === 'missing' + ? undefined + : [ + { + scope: 'ansTrustDiscovery', + values: { + ansTrustDiscoveryStatus: status, + ansTrustDiscoveryUpdatedAt: now, + }, + }, + ], + provenance: { + source: 'ans-trust-discovery', + sourceUrl: url, + subjectId: agentId, + fetchedAt: now, + }, + }, + ]; +} + +/** + * Creates the `ans-trust-discovery` signal adapter: reads the eight ANS + * Trust Index signals from a provider's registered-agent endpoint and + * stores them under `metadata.ansTrustDiscovery`. + */ +export function createAnsTrustDiscoverySignalAdapter( + options: Hcs25AnsTrustDiscoverySignalAdapterOptions = {}, +): Hcs25SignalAdapter { + const resolveAgentId = options.resolveAgentId ?? defaultResolveAgentId; + const baseUrl = stripTrailingSlashes(options.baseUrl ?? DEFAULT_ANS_BASE_URL); + + const collect = async ( + subject: Hcs25Subject, + context: Hcs25CollectContext, + ): Promise => { + const now = context.now.toISOString(); + const agentId = resolveAgentId(subject); + if (!agentId) { + return statusResult('missing', now, undefined, undefined); + } + + const url = `${baseUrl}/v1/ans/registered-agents/${encodeURIComponent(agentId)}`; + let data: AnsTrustResponse; + try { + data = await requestJson(url, { + fetch: context.fetch, + headers: options.headers, + timeoutMs: context.timeoutMs, + signal: context.signal, + }); + } catch (error) { + if (error instanceof Hcs25CollectorHttpError && error.status === 404) { + return statusResult('missing', now, url, agentId); + } + return statusResult( + isTimeoutError(error) ? 'timeout' : 'error', + now, + url, + agentId, + ); + } + + const signals = data.signals; + const values: Record = { + ansTrustDiscoveryUpdatedAt: now, + }; + let present = 0; + const results: Hcs25SignalAdapterResult[] = []; + + for (const signal of HCS25_ANS_TRUST_DISCOVERY_SIGNALS) { + const payload = + signals && typeof signals === 'object' ? signals[signal] : undefined; + const score = readSignalScore(payload); + const signalId = `ans-trust-discovery.${signal}`; + values[signalId] = score; + if (score !== null) { + present += 1; + } + results.push({ + signalId, + status: score === null ? 'missing' : 'ok', + value: score ?? undefined, + provenance: { + source: 'ans-trust-discovery', + sourceUrl: url, + subjectId: agentId, + fetchedAt: now, + }, + }); + } + + values.ansTrustDiscoveryStatus = present > 0 ? 'ok' : 'missing'; + const carrier = + results.find(result => result.status === 'ok') ?? results[0]; + carrier.fields = [{ scope: 'ansTrustDiscovery', values }]; + return results; + }; + + return { + id: 'ans-trust-discovery', + produces: SIGNAL_IDS, + timeoutMs: options.timeoutMs, + includeRegistries: options.includeRegistries ?? DEFAULT_INCLUDED_REGISTRIES, + excludeRegistries: options.excludeRegistries, + appliesTo: options.appliesTo, + collect, + }; +} diff --git a/src/hcs-25/collectors/catalog.ts b/src/hcs-25/collectors/catalog.ts index 9a4c3f9..4405105 100644 --- a/src/hcs-25/collectors/catalog.ts +++ b/src/hcs-25/collectors/catalog.ts @@ -7,6 +7,10 @@ import { createAgentverseInsightsSignalAdapter, type Hcs25AgentverseSignalAdapterOptions, } from './agentverse'; +import { + createAnsTrustDiscoverySignalAdapter, + type Hcs25AnsTrustDiscoverySignalAdapterOptions, +} from './ans-trust-discovery'; import { createAvailabilitySignalAdapter, type Hcs25AvailabilitySignalAdapterOptions, @@ -60,8 +64,9 @@ type OmitRequired = Enable< * Per-family configuration for {@link createHcs25SignalAdapters}. Each key * accepts `true` (enable with defaults) or an options object; keys omitted * entirely are disabled. `x402` scans on-chain usage by default (viem); - * `openrouterEvals`, `chatbotArena`, and `openLlm` ship with the - * production-shaped sources. Families still requiring configuration: + * `openrouterEvals`, `chatbotArena`, `openLlm`, and `ansTrustDiscovery` + * ship with the production-shaped sources. Families still requiring + * configuration: * `acp`, `erc8004`, `outputVerification`, `simpleEvals` — pass the options * object. */ @@ -79,6 +84,11 @@ export interface Hcs25SignalAdaptersOptions { chatbotArena?: Enable; openLlm?: Enable; outputVerification?: Hcs25OutputVerificationSignalAdapterOptions; + /** + * ANS Trust Index collector. `true` uses `https://api.godaddy.com`; + * pass `baseUrl` for another provider. + */ + ansTrustDiscovery?: Enable; /** * Simple-evals adapters per subject family. `a2a` covers A2A/HTTP * subjects, `agentverse` is the same schema scoped to AgentVerse/uAgent @@ -163,6 +173,10 @@ export function createHcs25SignalAdapters( createOutputVerificationSignalAdapter(options.outputVerification), ); } + const ansTrustDiscovery = optionsOf(options.ansTrustDiscovery); + if (ansTrustDiscovery) { + adapters.push(createAnsTrustDiscoverySignalAdapter(ansTrustDiscovery)); + } if (options.simpleEvals) { const a2a = optionsOf(options.simpleEvals.a2a); diff --git a/src/hcs-25/collectors/index.ts b/src/hcs-25/collectors/index.ts index e6d91ae..b9bb7bf 100644 --- a/src/hcs-25/collectors/index.ts +++ b/src/hcs-25/collectors/index.ts @@ -5,6 +5,7 @@ export * from './merge'; export * from './runner'; export * from './pipeline'; export * from './endpoints'; +export * from './ans-trust-discovery'; export * from './availability'; export * from './connectivity'; export * from './ethos'; From 45ec45309d3d1b61af31df2bdeeae37046fad464 Mon Sep 17 00:00:00 2001 From: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:11:41 -0400 Subject: [PATCH 4/4] fix(hcs-25): record every ans trust signal on collection failure A missing, timeout, or error response now writes the same status for all eight ans-trust-discovery signals. The stored status field still rides on the first signal. Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com> --- __tests__/hcs-25/hcs-25-collectors.test.ts | 29 ++++++++---- src/hcs-25/collectors/ans-trust-discovery.ts | 48 ++++++++++---------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/__tests__/hcs-25/hcs-25-collectors.test.ts b/__tests__/hcs-25/hcs-25-collectors.test.ts index 2a3c5dc..8d5ed28 100644 --- a/__tests__/hcs-25/hcs-25-collectors.test.ts +++ b/__tests__/hcs-25/hcs-25-collectors.test.ts @@ -1084,9 +1084,12 @@ describe('ans trust discovery signal adapter', () => { fetch: fetchReturning({}), }, ); - expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( - 'missing', - ); + for (const signalId of [ + 'ans-trust-discovery.certtype', + 'ans-trust-discovery.certificatehygiene', + ]) { + expect(collection.snapshot[signalId].status).toBe('missing'); + } expect(collection.subject.metadata?.ansTrustDiscovery).toBeUndefined(); }); @@ -1098,9 +1101,13 @@ describe('ans trust discovery signal adapter', () => { fetch: fetchWithStatus(404), }, ); - expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( - 'missing', - ); + for (const signalId of [ + 'ans-trust-discovery.certtype', + 'ans-trust-discovery.dnssecurity', + 'ans-trust-discovery.certificatehygiene', + ]) { + expect(collection.snapshot[signalId].status).toBe('missing'); + } expect(collection.results[0]?.status).toBe('missing'); }); @@ -1126,9 +1133,13 @@ describe('ans trust discovery signal adapter', () => { unknown >; expect(stored.ansTrustDiscoveryStatus).toBe(status); - expect(collection.snapshot['ans-trust-discovery.certtype'].status).toBe( - status, - ); + for (const signalId of [ + 'ans-trust-discovery.certtype', + 'ans-trust-discovery.dnssecurity', + 'ans-trust-discovery.certificatehygiene', + ]) { + expect(collection.snapshot[signalId].status).toBe(status); + } } }); diff --git a/src/hcs-25/collectors/ans-trust-discovery.ts b/src/hcs-25/collectors/ans-trust-discovery.ts index 80f9ee4..ea5fe10 100644 --- a/src/hcs-25/collectors/ans-trust-discovery.ts +++ b/src/hcs-25/collectors/ans-trust-discovery.ts @@ -100,30 +100,30 @@ function statusResult( url: string | undefined, agentId: string | undefined, ): Hcs25SignalAdapterResult[] { - return [ - { - signalId: SIGNAL_IDS[0], - status, - fields: - status === 'missing' - ? undefined - : [ - { - scope: 'ansTrustDiscovery', - values: { - ansTrustDiscoveryStatus: status, - ansTrustDiscoveryUpdatedAt: now, - }, - }, - ], - provenance: { - source: 'ans-trust-discovery', - sourceUrl: url, - subjectId: agentId, - fetchedAt: now, - }, - }, - ]; + const provenance = { + source: 'ans-trust-discovery', + sourceUrl: url, + subjectId: agentId, + fetchedAt: now, + }; + const fields = + status === 'missing' + ? undefined + : [ + { + scope: 'ansTrustDiscovery', + values: { + ansTrustDiscoveryStatus: status, + ansTrustDiscoveryUpdatedAt: now, + }, + }, + ]; + return SIGNAL_IDS.map((signalId, index) => ({ + signalId, + status, + fields: index === 0 ? fields : undefined, + provenance, + })); } /**