Skip to content

Fairfetch-co/fairad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

FairAd

The open-source protocol for the agentic ad economy.

CI Python 3.10+ License: Apache 2.0 Code style: Ruff MCP Security Policy


Merchants pay AI agents to prioritize and display their products during user conversationsβ€”with zero-config discovery, signed bidding, Proof of Human, and mandatory transparency. E-commerce transacts on the last mile of the conversation with proof, not promises.

Quick Start Β· Merchant onboarding Β· Concepts Β· Development


The Idea

Two parties, one protocol: merchants bid for placement; agents show sponsored recommendations only when a real human is in the loop. Every impression is attested, disclosed, and settled via a Proof of Impression receipt.

πŸ›’ Merchant πŸ€– AI Agent
Goal Get products in front of humans in conversation Monetize the last mile with paid, verifiable ads
Deploys .well-known/fairad.json + Merchant MCP Discovery crawler + MCP client
Gets Qualified impressions, settlement on proof Payment commitment + rich product metadata
Guide Merchant onboarding β†’ Concepts & protocol β†’

Features

  • Zero-config discovery β€” fairad.json at domain.com/.well-known/fairad.json; crawler builds a local merchant directory for agents.
  • Signed bidding β€” Merchant MCP returns product metadata (Markdown/JSON) and a Payment Commitment: a cryptographic promise to pay $X upon proof of human-verified impression.
  • Proof of Human (PoH) β€” X-FairAd-Human-Token in the handshake; attestations from Worldcoin, Privy, or OIDC. Payment commitments are binding only when PoH is valid.
  • Mandatory transparency β€” Sponsored replies must include "Sponsored Recommendation from [Merchant]"; the Proof of Impression hash includes this disclosure.
  • Proof of Impression (PoI) β€” Ad-receipt combining bid signature + human token + disclosure hash; the invoice for settlement.

πŸš€ Quick Start

git clone https://github.com/Fairfetch-co/fairad.git
cd fairad
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
make setup-dev
For merchants β€” serve a manifest and run the Ad-Server

Host fairad.json at https://yourdomain.com/.well-known/fairad.json:

{
  "mcp_endpoint": "https://yourdomain.com/mcp",
  "public_key": "<base64 Ed25519 public key>",
  "bidding_categories": ["electronics", "apparel"],
  "currency": "USD",
  "min_bid": "100"
}
export FAIRAD_MERCHANT_DOMAIN=yourdomain.com
export FAIRAD_MERCHANT_NAME="Your Store"
python -m mcp_server.server
For AI agents β€” discover and query
# Discover merchants (crawls .well-known/fairad.json)
python examples/run_discovery.py example.com

# MCP Inspector: connect and call get_sponsored_context
npx @modelcontextprotocol/inspector python -m mcp_server.server

HTTP API (same semantics as MCP):

make dev-api
# API runs on http://localhost:8403
curl -X POST http://localhost:8403/sponsored-context -H "Content-Type: application/json" -d '{"category":"electronics"}'

HTTP API

Endpoint Method Description
/health GET Health check
/manifest GET FairAd manifest (same as .well-known/fairad.json)
/well-known/fairad.json GET Manifest at well-known path
/sponsored-context POST Body: { "category": "electronics", "amount": "100" }. Header: X-FairAd-Human-Token for binding commitment
/settlement/submit POST Submit Proof of Impression JSON; returns settlement_id
/settlement/status/{id} GET Status of a settlement
# Get sponsored context (no PoH)
curl -X POST http://localhost:8403/sponsored-context -H "Content-Type: application/json" -d '{"category":"electronics"}'

# Submit PoI for settlement
curl -X POST http://localhost:8403/settlement/submit -H "Content-Type: application/json" -d @receipt.json

Stricter Proof of Human (PoH)

Set FAIRAD_POH_STRICT=true to enforce:

  • OIDC β€” When you have the raw token, use verify_poh_with_token(raw_token) to verify JWT signature against the issuer’s JWKS (.well-known/jwks.json).
  • Worldcoin / Privy β€” Non-empty subject and (in strict mode) signature required.

Settlement ledger

The settlement ledger accepts PoI receipts at POST /settlement/submit. It validates:

  • Payment Commitment signature (Ed25519)
  • Disclosure hash format (sha256: + 64 hex chars)
  • Unique poi_id (no duplicate submissions)

Optional: set FAIRAD_LEDGER_PATH=/path/to/ledger.json to persist settlements to disk. By default the ledger is in-memory.


Generate a Proof of Impression (Ad-Receipt)

python scripts/poi_generator.py \
  --commitment commitment.json \
  --human-token poh_token.json \
  --merchant-name "Example Merchant" \
  --snippet "Sponsored Recommendation from [Example Merchant]\nProduct snippet..." \
  -o receipt.json

Protocol at a glance

  1. Discovery β€” Agent crawls /.well-known/fairad.json, gets mcp_endpoint, public_key, bidding_categories, min_bid.
  2. Signed bidding β€” Agent calls Merchant MCP get_sponsored_context(category, amount?, human_token?). Receives product metadata + Payment Commitment (signed). Commitment is binding only if human_token is valid PoH.
  3. Transparency β€” Agent must append "Sponsored Recommendation from [Merchant]" to the UI. Disclosure is hashed into the Proof of Impression.
  4. Proof of Impression β€” On human-verified impression, agent builds PoI: commitment + PoH token id + disclosure hash. This is the settlement invoice.

πŸ“ Project structure

fairad/
β”œβ”€β”€ api/                      # HTTP API (REST wrapper)
β”‚   β”œβ”€β”€ main.py               # FastAPI app, CORS
β”‚   └── routes.py             # /manifest, /sponsored-context, /settlement
β”œβ”€β”€ settlement/               # Ledger stub
β”‚   └── ledger.py            # Accepts PoI, validates, persists (optional)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ CONCEPTS.md           # Protocol concepts and headers
β”‚   β”œβ”€β”€ MERCHANT_ONBOARDING.md
β”‚   β”œβ”€β”€ PROTOCOL_STANDARDS.md # RFCs and world standards
β”‚   └── WELL_KNOWN_SPEC.md
β”œβ”€β”€ interfaces/               # Open standard types
β”‚   β”œβ”€β”€ manifest.py           # fairad.json schema
β”‚   β”œβ”€β”€ payment.py            # Payment Commitment
β”‚   └── poh.py                # Proof of Human attestation
β”œβ”€β”€ core/                     # Signing, PoH, transparency, PoI
β”‚   β”œβ”€β”€ signatures.py
β”‚   β”œβ”€β”€ poh_verifier.py
β”‚   β”œβ”€β”€ transparency.py
β”‚   β”œβ”€β”€ transparency_middleware.py
β”‚   β”œβ”€β”€ poi.py
β”‚   └── url_validation.py     # SSRF protection
β”œβ”€β”€ discovery/                # Zero-config discovery
β”‚   └── crawler.py
β”œβ”€β”€ mcp_server/               # Merchant MCP (Ad-Server)
β”‚   β”œβ”€β”€ logic.py
β”‚   └── server.py
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ poi_generator.py
β”‚   └── run_api.py
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ well-known/fairad.json
β”‚   └── run_discovery.py
β”œβ”€β”€ tests/
β”œβ”€β”€ .github/workflows/
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ Makefile
└── LICENSE                   # Apache 2.0

Standards & security

FairAd follows world-standard protocols:

  • Well-known URI β€” RFC 8615 for /.well-known/fairad.json.
  • HTTPS β€” TLS in production; discovery blocks private IPs and SSRF targets.
  • Ed25519 β€” RFC 8032 for Payment Commitments and PoI.
  • JSON β€” RFC 8259; OIDC/JWT for Proof of Human.

See docs/PROTOCOL_STANDARDS.md for the full list. SECURITY.md for reporting and best practices.


πŸ“– Detailed guides

Guide What's inside
Merchant onboarding Publish your manifest and run the Ad-Server
Concepts Terms, headers, and flows in plain language
Protocol standards RFCs and world standards (well-known, HTTPS, Ed25519)
Development Local setup, running services, testing
Contributing How to contribute, CLA, code standards
Security Reporting vulnerabilities and security measures
Code of Conduct Community standards

πŸ“„ License

Apache 2.0 β€” use it freely, commercially or otherwise.



Docs Β· Issues Β· Contributing

Built so merchants and AI agents can transact on the last mile of the conversationβ€”with proof, not promises.

About

The Ad-Exchange for Agents

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published