From d315f6c469e7125398f31c0ad98b0710f6082fdd Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Mon, 26 Oct 2026 02:59:18 +0000 Subject: [PATCH 1/2] fix(identity): one delegation-chain rule for demand-side grants Aligns authorizeDemandGrant with adcontextprotocol/adcp#8473 and runs its 48 cross-SDK vectors: implicit authority when account.operator and the signer's operator are each the brand or its house; at most two grants from the house to the signer's operator, with account.operator the brand, the house, or the first grantee; exclusive_grants makes the house's grants the complete list whatever the scope; a grant that does not cover the claim never narrows seller discretion. Co-Authored-By: Claude Opus 5.5 (1M context) --- .changeset/one-delegation-chain-rule.md | 11 + src/lib/identity-3.3/trust.ts | 81 +- test/fixtures/delegation-chains/PINNED.json | 5 + .../delegation-chains/delegation-chains.json | 2345 +++++++++++++++++ ...ntity-3.3-delegation-chain-vectors.test.js | 78 + ... => identity-3.3-exclusive-grants.test.js} | 47 +- test/lib/identity-3.3-implicit-house.test.js | 19 +- ...identity-3.3-trust-grant-followups.test.js | 27 +- test/lib/identity-3.3.test.js | 17 +- 9 files changed, 2536 insertions(+), 94 deletions(-) create mode 100644 .changeset/one-delegation-chain-rule.md create mode 100644 test/fixtures/delegation-chains/PINNED.json create mode 100644 test/fixtures/delegation-chains/delegation-chains.json create mode 100644 test/lib/identity-3.3-delegation-chain-vectors.test.js rename test/lib/{identity-3.3-exclusive-scope.test.js => identity-3.3-exclusive-grants.test.js} (63%) diff --git a/.changeset/one-delegation-chain-rule.md b/.changeset/one-delegation-chain-rule.md new file mode 100644 index 000000000..d5b12c14b --- /dev/null +++ b/.changeset/one-delegation-chain-rule.md @@ -0,0 +1,11 @@ +--- +'@adcp/sdk': minor +--- + +Align `authorizeDemandGrant` with the one delegation-chain rule (adcontextprotocol/adcp#8473, an erratum to ratified R6), and run its cross-SDK vectors. + +- **Implicit authority:** `account.operator` and the signer's operator only need to each be the brand or its house. A brand-operated account with the house's own agent signing (or the reverse) is implicit; before, both had to equal the same domain. +- **Chains:** at most two grants from the house's record to the signer's operator, every grant covering the claim, with `account.operator` the brand, the house, or the first grant's grantee. Brand- and house-operated accounts can now use a two-grant chain, and the brand's own record can supply the second grant. When several candidate chains exist, an unreadable intermediary record is an outage only if no other chain authorizes. +- **Exclusivity:** `exclusive_grants: true` on the house's record makes `grants[]` the complete list whatever the scope, so an uncovered claim is `grant_absent` and `sellerAuthorization` is never called. This reverses the per-scope reading shipped in 16.5.0. Without it, an uncovered claim is at the seller's discretion, and a grant that does not cover the claim no longer narrows that discretion. + +`test/lib/identity-3.3-delegation-chain-vectors.test.js` runs all 48 vectors from `static/test-vectors/delegation-chains.json` (vendored, pinned in `test/fixtures/delegation-chains/PINNED.json`). diff --git a/src/lib/identity-3.3/trust.ts b/src/lib/identity-3.3/trust.ts index f50d271cc..8a3768ca1 100644 --- a/src/lib/identity-3.3/trust.ts +++ b/src/lib/identity-3.3/trust.ts @@ -408,10 +408,7 @@ export interface DemandGrantAuthorization { export interface DemandGrantOptions { evaluator: TrustEvaluator; now?: () => number; - /** - * Only evaluated for uncovered claims, never fetch failures, and never for a scope an - * `exclusive_grants: true` record names in any grant. - */ + /** Only evaluated for uncovered claims against a record without `exclusive_grants: true`; never fetch failures. */ sellerAuthorization?: (claim: DemandGrantClaim) => Promise; /** Only for authoritative absence; never after a 200 or an exclusive record. */ legacyAuthorization?: (claim: DemandGrantClaim) => Promise; @@ -433,7 +430,10 @@ function grantsScope(grant: TrustGrant, scope: string): boolean { } function grantMatches(grant: TrustGrant, target: string, claim: DemandGrantClaim, now: number): boolean { // Exact match on a registrable grantee: never reduce a host grantee to its eTLD+1. - if (registrableGrantee(grant.grantee) !== target) return false; + return registrableGrantee(grant.grantee) === target && grantCovers(grant, claim, now); +} +/** Every covering condition but the grantee: scope, agents[] narrowing, brands, countries and window. */ +function grantCovers(grant: TrustGrant, claim: DemandGrantClaim, now: number): boolean { if (!grantsScope(grant, claim.scope)) return false; // An agents[] URL that does not parse lists no agent: the grant fails to // match on its own and never throws out of the evaluation of other grants. @@ -485,7 +485,6 @@ export async function authorizeDemandGrant( : {}), }); if (brand === operator && account === operator) return result('implicit', [brand]); - if (brand === operator && account !== operator) throw new IdentityAuthorizationError('grant_absent'); let house: { domain: string; brand_id: string } | undefined; try { house = await options.resolveBrandHouse?.(claim.brand); @@ -502,9 +501,10 @@ export async function authorizeDemandGrant( unavailable(cause); } const authoritativeBrand = house ? eTldPlusOne(house.domain) : brand; - // The house operating its own child brand: implicit. The signer's record, - // already matched above, is the house's record. - if (authoritativeBrand === operator && account === operator) return result('implicit', [brand, operator]); + // Implicit: account.operator and the signer's operator are each the brand or + // its house. The signer's record, already matched above, lists the agent. + const self = new Set([brand, authoritativeBrand]); + if (self.has(account) && self.has(operator)) return result('implicit', [...new Set([brand, account, operator])]); const grantClaim = house ? { ...claim, brand: { ...claim.brand, brand_id: house.brand_id } } : claim; // A grantor that once served a record and is now unreachable (404/410 // included) is an outage, never a grant removal or a legacy fallback. @@ -513,42 +513,39 @@ export async function authorizeDemandGrant( if (await options.legacyAuthorization?.(claim)) return result('legacy', [brand, account, operator]); throw new IdentityAuthorizationError('grant_absent'); } - const first = (record.record.grants ?? []).filter(g => grantMatches(g, account, grantClaim, now)); - if (account === operator && first.length) return result('trust', [brand, operator], [first[0]!]); - // A self-operated brand (brand is its own account.operator) may grant the - // signer's operator directly: account.operator is on the chain as the brand. - const selfOperated = account === brand || account === authoritativeBrand; - if (selfOperated && account !== operator) { - const direct = (record.record.grants ?? []).find(g => grantMatches(g, operator, grantClaim, now)); - if (direct) return result('trust', [brand, operator], [direct]); + // The one delegation-chain rule (L2 Grants in trust records): at most two + // grants from the house's record to the signer's operator, every grant + // covering the claim, with account.operator the brand, its house, or the + // first grant's grantee. + const firsts: { grant: TrustGrant; grantee: string }[] = []; + for (const grant of record.record.grants ?? []) { + const grantee = registrableGrantee(grant.grantee); + if (grantee === undefined || !grantCovers(grant, grantClaim, now)) continue; + if (!self.has(account) && account !== grantee) continue; + if (grantee === operator) return result('trust', [brand, operator], [grant]); + firsts.push({ grant, grantee }); } - if (account !== operator && account !== brand && first.length) { - const intermediary = await options.evaluator.get(account); - if (intermediary.status === 'present') { - const second = (intermediary.record.grants ?? []).find(g => grantMatches(g, operator, grantClaim, now)); - if (second) return result('trust', [brand, account, operator], [first[0]!, second]); + let outage: unknown; + for (const { grant: first, grantee } of firsts) { + let intermediary: Awaited>; + try { + intermediary = await options.evaluator.get(grantee); + } catch (cause) { + // Another chain may still authorize; an unreadable link is an outage + // only if none does. + outage ??= cause; + continue; } + if (intermediary.status !== 'present') continue; + const second = (intermediary.record.grants ?? []).find(g => grantMatches(g, operator, grantClaim, now)); + if (second) return result('trust', [brand, grantee, operator], [first, second]); } - // A grant to account.operator (or, self-operated, to the signer's operator) - // for this scope that did not match is published narrowing: it blocks the - // seller's discretion. A grant whose grantee is not a registrable domain - // covers no claim, so it does not count here; its scopes still count for - // exclusive_grants. - const covered = (record.record.grants ?? []).some(g => { - const grantee = registrableGrantee(g.grantee); - return ( - grantee !== undefined && - (grantee === account || (selfOperated && grantee === operator)) && - grantsScope(g, claim.scope) - ); - }); - // exclusive_grants makes grants[] exhaustive only for the scopes it names - // (any grant's scopes, registrable grantee or not). A scope no grant names, - // including every scope of a record with no grants, stays at the seller's - // discretion. - const exclusive = - record.record.exclusive_grants === true && (record.record.grants ?? []).some(g => grantsScope(g, claim.scope)); - if (!covered && !exclusive && (await options.sellerAuthorization?.(claim))) + if (outage !== undefined) throw outage; + // L2 Absence: exclusive_grants on the authorizing record makes grants[] the + // complete list, whatever the scope. Without it, an uncovered claim is at + // the seller's discretion, and a grant that does not cover the claim never + // narrows that discretion. Only this (the house's) record's flag counts. + if (record.record.exclusive_grants !== true && (await options.sellerAuthorization?.(claim))) return result('seller', [brand, account, operator]); throw new IdentityAuthorizationError('grant_absent'); } diff --git a/test/fixtures/delegation-chains/PINNED.json b/test/fixtures/delegation-chains/PINNED.json new file mode 100644 index 000000000..f6580dbbf --- /dev/null +++ b/test/fixtures/delegation-chains/PINNED.json @@ -0,0 +1,5 @@ +{ + "source": "adcontextprotocol/adcp#8473", + "sha": "3832036f8b2c153b7954992a2ffa06d1f5057898", + "path": "static/test-vectors/delegation-chains.json" +} diff --git a/test/fixtures/delegation-chains/delegation-chains.json b/test/fixtures/delegation-chains/delegation-chains.json new file mode 100644 index 000000000..ab65fa78b --- /dev/null +++ b/test/fixtures/delegation-chains/delegation-chains.json @@ -0,0 +1,2345 @@ +{ + "version": 1, + "name": "Delegation chains for demand-side grants", + "specification": "https://adcontextprotocol.org/docs/building/by-layer/L2/accounts-and-agents#grants-in-trust-records-experimental", + "description": "Cross-SDK vectors for the delegation-chain rule in L2 Grants in trust records, which is experimental in 3.3 (adcontextprotocol/adcp#8118, P7). Each vector gives an acts-for claim and the trust records that each registrable domain publishes, and the seller's expected outcome. `input.brand` is `account.brand`. `input.parent_organization` is the parent organization that brand.json resolves, or null for a standalone brand. `input.signer.operator` is the signer's operator, and `input.signer.origin` is the signer's canonical origin. `input.trust_records` maps each registrable domain to the `grants` and `exclusive_grants` of its trust.json; a domain that is absent publishes no grants. All domains are registrable domains already, so no Public Suffix List lookup is needed, and every record is fetched. `expected.outcome` is one of `implicit`, `authorized`, `grant_absent`, or `seller_discretion`. When no delegation chain covers the claim, the outcome is `grant_absent` if the parent organization's record sets `exclusive_grants: true`, and `seller_discretion` otherwise: the seller's own onboarding records decide. `expected` holds the outcome only. Each vector tests one premise: every other premise of the claim holds, so an implementation fails a vector only when it gets that premise wrong, whatever order it checks the premises in. Look up vectors by `id`; `description` prose may change.", + "vectors": [ + { + "id": "parent-grants-signer-operator", + "description": "The parent organization grants the agency, and the agency operates the account and signs with its own agent.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "brand-operates-account-through-hosted-agent", + "description": "The brand operates its account through an agent that a platform hosts. The parent organization grants the platform.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "agency-works-through-platform", + "description": "The parent organization grants the agency, and the agency grants the platform that hosts the signing agent. The narrowing is on the second grant.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "parent-record-later-grant-authorizes", + "description": "The parent organization grants the agency twice. The first grant covers governance only, and the second covers media buying, so the second grant authorizes. Every grant in grants[] is a candidate.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + }, + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "intermediary-record-later-grant-authorizes", + "description": "The agency grants the platform twice. The first grant covers governance only, and the second covers media buying, so the delegation chain runs through the second.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + }, + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "parent-operates-account-through-hosted-agent", + "description": "The parent organization operates the account through an agent that a platform hosts, and grants the platform directly. No grant to itself is needed.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-holdings.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "parent-operates-account-on-two-grant-chain", + "description": "The parent organization operates the account, grants the agency, and the agency grants the platform. The rule admits this combination.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-holdings.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "brand-operates-account-on-two-grant-chain", + "description": "The brand operates the account, the parent organization grants the agency, and the agency grants the platform. The rule admits this combination.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "implicit-authority-brand", + "description": "The brand operates the account and signs with its own agent. Authority is implicit, and the exclusive record without a grant to the brand does not matter.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "nova-motors.example", + "origin": "https://buyer.nova-motors.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "implicit" + } + }, + { + "id": "implicit-authority-parent", + "description": "The parent organization operates the account and signs with its own agent. Authority is implicit.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-holdings.example", + "signer": { + "operator": "nova-holdings.example", + "origin": "https://buyer.nova-holdings.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "implicit" + } + }, + { + "id": "implicit-authority-brand-account-parent-signer", + "description": "The brand operates the account, and the parent organization signs with its own agent. Each is the brand or its parent organization, so authority is implicit.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "nova-holdings.example", + "origin": "https://buyer.nova-holdings.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "implicit" + } + }, + { + "id": "implicit-authority-parent-account-brand-signer", + "description": "The parent organization operates the account, and the brand signs with its own agent. Each is the brand or its parent organization, so authority is implicit.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-holdings.example", + "signer": { + "operator": "nova-motors.example", + "origin": "https://buyer.nova-motors.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "implicit" + } + }, + { + "id": "agency-account-brand-signer-denied", + "description": "The brand signs with its own agent, but the account names the agency as its operator. Implicit authority needs the brand or the parent organization as both the account operator and the signer's operator.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "nova-motors.example", + "origin": "https://buyer.nova-motors.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "standalone-brand-record-authorizes", + "description": "A brand with no parent organization authorizes from its own record.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": null, + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-motors.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "standalone-brand-exclusive-record-denied", + "description": "A brand with no parent organization publishes an exclusive record that grants the agency governance only. The brand has no separate parent organization, so its own exclusive_grants counts and the media-buying claim is denied.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": null, + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-motors.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "three-grant-chain-denied", + "description": "The platform grants a relay a third time. A delegation chain has at most two grants, so the relay's agent is not covered.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "relay-exchange.example", + "origin": "https://buy.relay-exchange.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + }, + "orbit-platform.example": { + "grants": [ + { + "grantee": "relay-exchange.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "three-grant-chain-through-brand-denied", + "description": "The parent organization grants the brand, the brand grants the agency, and the agency grants the platform. The brand operates the account. A delegation chain has at most two grants, even when the brand is a middle grantee, so the platform's agent is not covered.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "nova-motors.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "nova-motors.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "account-operator-not-on-chain-denied", + "description": "The parent organization grants the platform, but the account names an agency that is neither the brand, the parent organization, nor the first grantee.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "account-operator-is-second-grantee-denied", + "description": "The account names the platform, which is the grantee of the second grant. account.operator must be the brand, the parent organization, or the grantee of the first grant.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "orbit-platform.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-scope-denied", + "description": "The first grant covers governance only, so it does not cover the media-buying claim. The second grant covers it.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-brands-denied", + "description": "The first grant covers a different brand the parent organization owns. The second grant covers the account's brand.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_trucks"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-countries-denied", + "description": "The first grant covers CA only, and the account's brand covers the US. The second grant is global.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "countries": ["CA"] + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-valid-from-denied", + "description": "The check time is before the first grant's valid_from. The second grant is already valid.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "valid_from": "2026-11-01T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-valid-until-denied", + "description": "The second grant is still valid, but the check time is at or after the first grant's valid_until.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-12-31T00:00:00Z" + } + ] + } + }, + "check_time": "2027-07-15T00:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "first-grant-agents-denied", + "description": "The first grant lists only the agency's own agents, so it never covers the platform's agent, even though the agency grants the platform.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://buyer.pinnacle-agency.example/mcp" + } + ] + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-scope-denied", + "description": "The second grant covers governance only, so it does not cover the media-buying claim. The first grant covers it.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-brands-denied", + "description": "The second grant covers a different brand. The first grant covers the account's brand.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_trucks"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-countries-denied", + "description": "The account's brand covers GB. The second grant covers CA and the US only, so it doesn't cover the brand's countries.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["GB", "US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "countries": ["CA", "US"] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-valid-from-denied", + "description": "The first grant is still valid, but the check time is before the second grant's valid_from.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-12-31T00:00:00Z", + "valid_from": "2026-11-01T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-valid-until-denied", + "description": "The check time is at or after the second grant's valid_until. The first grant is still valid.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2026-10-01T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "second-grant-agents-denied", + "description": "The second grant lists only another of the platform's agents, so the signer's canonical origin is not listed. The first grant is unnarrowed.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://reporting.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "agents-origin-port-mismatch-denied", + "description": "The parent organization grants the platform for an agent on port 8443. The signer's canonical origin has the default port, so it is a different origin and the grant does not cover it.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example:8443/mcp" + } + ] + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "valid-until-at-check-time-denied", + "description": "The check time equals the grant's valid_until. A grant is inactive at or after valid_until, so it doesn't cover the claim.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2026-10-24T12:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "valid-from-at-check-time-authorizes", + "description": "The check time equals the grant's valid_from. A grant is active from valid_from on, so it covers the claim.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "valid_from": "2026-10-24T12:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "brand-without-countries-needs-global-grant-denied", + "description": "The account's brand lists no countries, and the grant covers the US only. A brand reference with no countries is covered only by a global grant.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors" + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "countries": ["US"] + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "brand-without-brand-id-denied", + "description": "The account's brand reference has no brand_id, and the grant lists specific brands. A brand reference with no brand_id is covered only by [\"*\"] or an omitted list.", + "input": { + "brand": { + "domain": "nova-motors.example", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "brand-not-covered-denied", + "description": "The grant covers a different brand the parent organization owns.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_trucks"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "wildcard-brands-grant-authorizes", + "description": "The grant lists [\"*\"] as its brands, which covers every brand the parent organization owns.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["*"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "scope-mismatch-denied", + "description": "The parent organization's exclusive record grants the platform governance only. No grant covers media buying, and the record is the complete list for every scope, so the claim is denied.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "orbit-platform.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "wildcard-scope-grant-authorizes", + "description": "The grant lists [\"*\"] as its scopes. The bare token * covers every scope in every namespace, so it covers the media-buying claim.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["*"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "brand-record-ignored-when-parent-denies", + "description": "The brand's own record grants the platform, but only the parent organization's record authorizes, and it grants the agency only.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "orbit-platform.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "nova-motors.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "brand-record-ignored-when-parent-grants", + "description": "The brand's own record is exclusive and grants another domain, but the parent organization's record grants the platform.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "orbit-platform.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "nova-motors.example": { + "grants": [ + { + "grantee": "acme-media.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "brand-record-supplies-second-grant", + "description": "The parent organization grants the brand, and the brand operates the account. The brand's own record supplies the second grant, to the platform that hosts the signing agent.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "nova-motors.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "nova-motors.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ], + "exclusive_grants": true + }, + "nova-motors.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "authorized" + } + }, + { + "id": "exclusive-no-grants-denied", + "description": "The parent organization's exclusive record lists no grants, so no third party acts for it.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "grant_absent" + } + }, + { + "id": "nonexclusive-uncovered-seller-discretion", + "description": "The parent organization's record is not exclusive and grants the platform governance only. No delegation chain covers the platform's media-buying claim, so the seller's onboarding records decide.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "orbit-platform.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "seller_discretion" + } + }, + { + "id": "nonexclusive-nonmatching-grant-seller-discretion", + "description": "The parent organization's nonexclusive record grants the agency media buying for another brand it owns. The grant covers nothing for this brand and doesn't narrow the seller's discretion.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_trucks"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "seller_discretion" + } + }, + { + "id": "exclusive-brand-record-seller-discretion", + "description": "The brand's own record is exclusive and lists no grants, and the parent organization's record is not exclusive. Only the parent organization's exclusive_grants counts, so a claim that no delegation chain covers stays at the seller's discretion.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "pinnacle-agency.example", + "origin": "https://buyer.pinnacle-agency.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_trucks"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + }, + "nova-motors.example": { + "grants": [], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "seller_discretion" + } + }, + { + "id": "exclusive-intermediary-record-seller-discretion", + "description": "The agency's own record is exclusive, and the parent organization's record is not. The second grant covers governance only, so no delegation chain covers the media-buying claim. Only the parent organization's exclusive_grants counts, so the claim stays at the seller's discretion.", + "input": { + "brand": { + "domain": "nova-motors.example", + "brand_id": "nova_motors", + "countries": ["US"] + }, + "parent_organization": "nova-holdings.example", + "account_operator": "pinnacle-agency.example", + "signer": { + "operator": "orbit-platform.example", + "origin": "https://agents.orbit-platform.example" + }, + "trust_records": { + "nova-holdings.example": { + "grants": [ + { + "grantee": "pinnacle-agency.example", + "scopes": ["adcp:media_buying"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z" + } + ] + }, + "pinnacle-agency.example": { + "grants": [ + { + "grantee": "orbit-platform.example", + "scopes": ["adcp:governance"], + "profiles": { + "adcp": { + "brands": ["nova_motors"] + } + }, + "valid_until": "2027-06-30T00:00:00Z", + "agents": [ + { + "url": "https://agents.orbit-platform.example/mcp" + } + ] + } + ], + "exclusive_grants": true + } + }, + "check_time": "2026-10-24T12:00:00Z", + "scope": "adcp:media_buying" + }, + "expected": { + "outcome": "seller_discretion" + } + } + ] +} diff --git a/test/lib/identity-3.3-delegation-chain-vectors.test.js b/test/lib/identity-3.3-delegation-chain-vectors.test.js new file mode 100644 index 000000000..cdf96ef34 --- /dev/null +++ b/test/lib/identity-3.3-delegation-chain-vectors.test.js @@ -0,0 +1,78 @@ +// Cross-SDK delegation-chain vectors (adcontextprotocol/adcp L2 "Grants in +// trust records"), vendored from adcontextprotocol/adcp#8473. Each vector is +// an acts-for claim, the parent organization the brand resolves to, and the +// trust records each domain publishes; authorizeDemandGrant must reach the +// expected outcome. +process.env.NODE_ENV = 'test'; +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const identity = require('../../dist/lib/identity-3.3'); +const fixture = require('../fixtures/delegation-chains/delegation-chains.json'); + +// The vectors use `.example` names, which have no registrable domain under +// the PSL. Map each to a registrable placeholder; domains are opaque labels. +const registrable = value => value.replace(/\.example\b/g, '-dcv.com'); +const mapped = value => JSON.parse(registrable(JSON.stringify(value))); + +const OUTCOMES = { implicit: 'implicit', authorized: 'trust', seller_discretion: 'seller' }; + +function evaluator(records, now) { + return new identity.TrustEvaluator({ + now: () => now, + fetchOptions: { + trustedFetchFn: async url => { + const record = records[new URL(url).hostname]; + return new Response(record === undefined ? '' : JSON.stringify(record), { + status: record === undefined ? 404 : 200, + }); + }, + }, + }); +} + +test('the vendored vectors cover every outcome', () => { + const outcomes = new Set(fixture.vectors.map(v => v.expected.outcome)); + assert.deepEqual([...outcomes].sort(), ['authorized', 'grant_absent', 'implicit', 'seller_discretion']); +}); + +for (const vector of fixture.vectors) { + test(`delegation-chain vector ${vector.id}`, async () => { + const input = mapped(vector.input); + const now = Date.parse(input.check_time) / 1000; + const records = { ...input.trust_records }; + // Every operator a chain reaches lists the signer, so binding is never the reason a vector fails. + records[input.signer.operator] = { + ...records[input.signer.operator], + agents: [{ url: input.signer.origin, roles: ['adcp:buying'] }], + }; + let sellerCalls = 0; + const run = identity.authorizeDemandGrant( + { + signerOrigin: input.signer.origin, + brand: input.brand, + accountOperator: input.account_operator, + scope: input.scope, + }, + { + evaluator: evaluator(records, now), + now: () => now, + resolveBrandHouse: async () => + input.parent_organization ? { domain: input.parent_organization, brand_id: input.brand.brand_id } : undefined, + sellerAuthorization: async () => { + sellerCalls++; + return true; + }, + } + ); + if (vector.expected.outcome === 'grant_absent') { + await assert.rejects( + run, + e => e instanceof identity.IdentityAuthorizationError && e.details?.reason === 'grant_absent' + ); + assert.equal(sellerCalls, 0, 'an exclusive record never defers to the seller'); + } else { + const result = await run; + assert.equal(result.source, OUTCOMES[vector.expected.outcome], vector.description); + } + }); +} diff --git a/test/lib/identity-3.3-exclusive-scope.test.js b/test/lib/identity-3.3-exclusive-grants.test.js similarity index 63% rename from test/lib/identity-3.3-exclusive-scope.test.js rename to test/lib/identity-3.3-exclusive-grants.test.js index 601f0e059..dcb6d74e3 100644 --- a/test/lib/identity-3.3-exclusive-scope.test.js +++ b/test/lib/identity-3.3-exclusive-grants.test.js @@ -1,7 +1,7 @@ -// exclusive_grants makes grants[] exhaustive only for the scopes it names -// (adcontextprotocol/adcp L2 "Grants in trust records": Absence). A scope no -// grant names stays at the seller's discretion, as does every scope of an -// exclusive record that publishes no grants. +// exclusive_grants on the house's record makes grants[] the complete list, +// whatever the scope (adcontextprotocol/adcp L2 "Grants in trust records": +// Absence). Without it, an uncovered claim is at the seller's discretion, and +// a grant that does not cover the claim never narrows that discretion. process.env.NODE_ENV = 'test'; const { test } = require('node:test'); const assert = require('node:assert/strict'); @@ -47,48 +47,43 @@ function authorize(brandRecord) { return { run, sellerCalls: () => sellerCalls }; } -test('an exclusive record leaves a scope no grant names at the seller discretion', async () => { +test('an exclusive record refuses an uncovered claim in a scope no grant names', async () => { const { run, sellerCalls } = authorize({ grants: [grant('other-agency.com', ['adcp:governance'])], exclusive_grants: true, }); - assert.equal((await run).source, 'seller'); - assert.equal(sellerCalls(), 1); + await assert.rejects(run, isGrantAbsent); + assert.equal(sellerCalls(), 0); }); test('an exclusive record refuses an uncovered claim in a scope a grant names', async () => { const { run, sellerCalls } = authorize({ - grants: [grant('other-agency.com', ['adcp:governance', 'adcp:media_buying'])], + grants: [grant('other-agency.com', ['adcp:media_buying'])], exclusive_grants: true, }); await assert.rejects(run, isGrantAbsent); assert.equal(sellerCalls(), 0); }); -test('adcp:all and * name every scope they cover for exclusivity', async () => { - for (const scopes of [['adcp:all'], ['*']]) { - const { run, sellerCalls } = authorize({ grants: [grant('other-agency.com', scopes)], exclusive_grants: true }); - await assert.rejects(run, isGrantAbsent, `scopes ${scopes}`); - assert.equal(sellerCalls(), 0); - } -}); - -test('a non-registrable grantee still names its scopes for exclusivity', async () => { - const { run, sellerCalls } = authorize({ - grants: [grant('github.io', ['adcp:media_buying'])], - exclusive_grants: true, - }); +test('an exclusive record with no grants authorizes no one', async () => { + const { run, sellerCalls } = authorize({ grants: [], exclusive_grants: true }); await assert.rejects(run, isGrantAbsent); assert.equal(sellerCalls(), 0); }); -test('an exclusive record with no grants names no scope', async () => { - const { run, sellerCalls } = authorize({ grants: [], exclusive_grants: true }); - assert.equal((await run).source, 'seller'); - assert.equal(sellerCalls(), 1); +test('a nonexclusive record leaves an uncovered claim to the seller, even beside a near-miss grant', async () => { + for (const grants of [ + [], + [grant('other-agency.com', ['adcp:media_buying'])], + [grant('agency.com', ['adcp:governance'])], + ]) { + const { run, sellerCalls } = authorize({ grants }); + assert.equal((await run).source, 'seller'); + assert.equal(sellerCalls(), 1); + } }); -test('a matching grant in an exclusive scope still authorizes', async () => { +test('a matching grant authorizes under an exclusive record', async () => { const { run, sellerCalls } = authorize({ grants: [grant('agency.com', ['adcp:media_buying'])], exclusive_grants: true, diff --git a/test/lib/identity-3.3-implicit-house.test.js b/test/lib/identity-3.3-implicit-house.test.js index ede7af0e3..8997d81a3 100644 --- a/test/lib/identity-3.3-implicit-house.test.js +++ b/test/lib/identity-3.3-implicit-house.test.js @@ -112,16 +112,15 @@ test('an operator outside the brand and its house still needs a grant', async () assert.equal(result.source, 'trust'); }); -test('the house agent under a self-operated child brand account is not implicit', async () => { - // account.operator is the brand, not the signer's operator: a grant is needed. - await assert.rejects( - identity.authorizeDemandGrant(claim(HOUSE_AGENT, 'novamotors.com', 'novamotors.com'), { - evaluator: evaluator(records()).trust, - now: () => now, - resolveBrandHouse: mutualAssertionHouse, - }), - isGrantAbsent - ); +test('the house agent under a self-operated child brand account is implicit', async () => { + // account.operator and the signer's operator are each the brand or its house + // (L2 Implicit authority; vector implicit-authority-brand-account-parent-signer). + const result = await identity.authorizeDemandGrant(claim(HOUSE_AGENT, 'novamotors.com', 'novamotors.com'), { + evaluator: evaluator(records()).trust, + now: () => now, + resolveBrandHouse: mutualAssertionHouse, + }); + assert.equal(result.source, 'implicit'); }); test('a house resolution failure is an outage, never grant_absent', async () => { diff --git a/test/lib/identity-3.3-trust-grant-followups.test.js b/test/lib/identity-3.3-trust-grant-followups.test.js index b1d6a925b..b264f3604 100644 --- a/test/lib/identity-3.3-trust-grant-followups.test.js +++ b/test/lib/identity-3.3-trust-grant-followups.test.js @@ -510,21 +510,20 @@ test('S2: self-operated chains work through a verified house and respect nonexcl resolveBrandHouse, }); assert.deepEqual(result.chain, ['child.com', 'platform.com']); - // A covering grant that does not match (wrong brand) blocks nonexclusive seller fallback. + // A grant that does not cover the claim (wrong brand) never narrows a + // nonexclusive record: the claim stays at the seller's discretion (L2 Absence). let fallback = 0; - await assert.rejects( - identity.authorizeDemandGrant(claim, { - evaluator: evaluator(records).trust, - now: () => now, - resolveBrandHouse: async () => ({ domain: 'house.com', brand_id: 'other' }), - sellerAuthorization: async () => { - fallback++; - return true; - }, - }), - e => e.details?.reason === 'grant_absent' - ); - assert.equal(fallback, 0); + const discretion = await identity.authorizeDemandGrant(claim, { + evaluator: evaluator(records).trust, + now: () => now, + resolveBrandHouse: async () => ({ domain: 'house.com', brand_id: 'other' }), + sellerAuthorization: async () => { + fallback++; + return true; + }, + }); + assert.equal(discretion.source, 'seller'); + assert.equal(fallback, 1); // With no covering grant, nonexclusive records may fall back to the seller. records['house.com'] = { grants: [] }; const seller = await identity.authorizeDemandGrant(claim, { diff --git a/test/lib/identity-3.3.test.js b/test/lib/identity-3.3.test.js index 24221d3be..db08f89e5 100644 --- a/test/lib/identity-3.3.test.js +++ b/test/lib/identity-3.3.test.js @@ -575,11 +575,23 @@ test('sandbox open binding without access context and existing RFC principal bot await clean.syncOpen(claim.signerOrigin); await assert.rejects(clean.authorizeBound(claim.signerOrigin)); }); -test('published narrowing denies even nonexclusive seller fallback and house record authority stays on the verified brand path', async () => { +test('a grant that does not cover the claim never narrows nonexclusive seller discretion, and house record authority stays on the verified brand path', async () => { const records = baseRecords(); records['brand.com'].exclusive_grants = false; records['brand.com'].grants[0].countries = ['CA']; let fallback = 0; + const discretion = await identity.authorizeDemandGrant(claim, { + evaluator: evaluator(records).trust, + now: () => now, + sellerAuthorization: async () => { + fallback++; + return true; + }, + }); + assert.equal(discretion.source, 'seller'); + assert.equal(fallback, 1); + records['brand.com'].exclusive_grants = true; + fallback = 0; await assert.rejects( identity.authorizeDemandGrant(claim, { evaluator: evaluator(records).trust, @@ -588,7 +600,8 @@ test('published narrowing denies even nonexclusive seller fallback and house rec fallback++; return true; }, - }) + }), + e => e.details?.reason === 'grant_absent' ); assert.equal(fallback, 0); records['house.com'] = { grants: [grant('agency.com', { profiles: { adcp: { brands: ['child'] } } })] }; From 1a15502bb7ef7a0e2ac3d7c6640555d901c474e9 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Mon, 26 Oct 2026 13:20:50 +0000 Subject: [PATCH 2/2] perf(identity): fetch candidate intermediary records once each, in parallel Review: a brand- or house-operated account makes every covering grant a candidate first link, and each intermediary record was fetched sequentially. Distinct intermediaries are now fetched once, eight at a time, so N candidates cost about ceil(N/8) fetch timeouts. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/lib/identity-3.3/trust.ts | 22 ++++++++--- .../lib/identity-3.3-exclusive-grants.test.js | 39 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/lib/identity-3.3/trust.ts b/src/lib/identity-3.3/trust.ts index 8a3768ca1..a59a501df 100644 --- a/src/lib/identity-3.3/trust.ts +++ b/src/lib/identity-3.3/trust.ts @@ -423,6 +423,8 @@ export interface DemandGrantOptions { */ resolveBrandHouse?: (brand: DemandGrantClaim['brand']) => Promise<{ domain: string; brand_id: string } | undefined>; } +/** Candidate intermediary records fetched in parallel for one authorization. */ +const INTERMEDIARY_FETCH_CONCURRENCY = 8; function grantsScope(grant: TrustGrant, scope: string): boolean { return grant.scopes.some( granted => granted === '*' || granted === scope || (granted === 'adcp:all' && scope.startsWith('adcp:')) @@ -525,15 +527,25 @@ export async function authorizeDemandGrant( if (grantee === operator) return result('trust', [brand, operator], [grant]); firsts.push({ grant, grantee }); } + // Each distinct intermediary record is fetched once, at most + // INTERMEDIARY_FETCH_CONCURRENCY at a time, so N candidate chains cost about + // ceil(N / concurrency) fetch timeouts rather than N. + const grantees = [...new Set(firsts.map(f => f.grantee))]; + const records = new Map> | { failed: unknown }>(); + for (let i = 0; i < grantees.length; i += INTERMEDIARY_FETCH_CONCURRENCY) { + const batch = grantees.slice(i, i + INTERMEDIARY_FETCH_CONCURRENCY); + const settled = await Promise.allSettled(batch.map(grantee => options.evaluator.get(grantee))); + settled.forEach((outcome, j) => + records.set(batch[j]!, outcome.status === 'fulfilled' ? outcome.value : { failed: outcome.reason }) + ); + } let outage: unknown; for (const { grant: first, grantee } of firsts) { - let intermediary: Awaited>; - try { - intermediary = await options.evaluator.get(grantee); - } catch (cause) { + const intermediary = records.get(grantee)!; + if ('failed' in intermediary) { // Another chain may still authorize; an unreadable link is an outage // only if none does. - outage ??= cause; + outage ??= intermediary.failed; continue; } if (intermediary.status !== 'present') continue; diff --git a/test/lib/identity-3.3-exclusive-grants.test.js b/test/lib/identity-3.3-exclusive-grants.test.js index dcb6d74e3..1bf2a59cd 100644 --- a/test/lib/identity-3.3-exclusive-grants.test.js +++ b/test/lib/identity-3.3-exclusive-grants.test.js @@ -91,3 +91,42 @@ test('a matching grant authorizes under an exclusive record', async () => { assert.equal((await run).source, 'trust'); assert.equal(sellerCalls(), 0); }); + +test('candidate intermediaries are fetched once each and in parallel', async () => { + const houseGrants = Array.from({ length: 12 }, (_, i) => grant(`agency${i}.com`, ['adcp:media_buying'])); + houseGrants.push(grant('agency0.com', ['adcp:media_buying'])); + const fetches = new Map(); + let inFlight = 0, + maxInFlight = 0; + const trust = new identity.TrustEvaluator({ + now: () => now, + fetchOptions: { + trustedFetchFn: async url => { + const host = new URL(url).hostname; + fetches.set(host, (fetches.get(host) ?? 0) + 1); + inFlight++; + maxInFlight = Math.max(maxInFlight, inFlight); + await new Promise(resolve => setTimeout(resolve, 20)); + inFlight--; + const records = { 'house.com': { grants: houseGrants }, 'signer.com': agent('https://buyer.signer.com') }; + const record = records[host] ?? { grants: [] }; + return new Response(JSON.stringify(record), { status: 200 }); + }, + }, + }); + await assert.rejects( + identity.authorizeDemandGrant( + { + signerOrigin: 'https://buyer.signer.com', + brand: { domain: 'house.com', brand_id: 'brand', countries: ['US'] }, + accountOperator: 'house.com', + scope: 'adcp:media_buying', + }, + { evaluator: trust, now: () => now } + ), + isGrantAbsent + ); + for (let i = 0; i < 12; i++) assert.equal(fetches.get(`agency${i}.com`), 1, `agency${i}.com fetched once`); + assert.ok(maxInFlight > 1, 'intermediaries are fetched concurrently'); + assert.ok(maxInFlight <= 8 + 1, 'concurrency stays bounded'); +});