@aamp/protocol 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Layer 2: Agent SDK
3
+ */
4
+ import { AccessPurpose, SignedAccessRequest, FeedbackSignal, QualityFlag } from './types';
5
+ export interface AccessOptions {
6
+ adsDisplayed?: boolean;
7
+ }
8
+ export declare class AAMPAgent {
9
+ private keyPair;
10
+ agentId: string;
11
+ /**
12
+ * Initialize the Agent Identity (Ephemeral or Persisted)
13
+ * @param customAgentId Optional persistent ID for this agent. If omitted, generates a session ID.
14
+ */
15
+ initialize(customAgentId?: string): Promise<void>;
16
+ createAccessRequest(resource: string, purpose: AccessPurpose, options?: AccessOptions): Promise<SignedAccessRequest>;
17
+ /**
18
+ * NEW IN V1.1: Quality Feedback Loop
19
+ * Allows the Agent to report spam or verify quality of a resource.
20
+ */
21
+ generateFeedback(resource: string, score: number, flags: QualityFlag[]): Promise<{
22
+ signal: FeedbackSignal;
23
+ signature: string;
24
+ }>;
25
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AAMPAgent = void 0;
4
+ const crypto_1 = require("./crypto");
5
+ const constants_1 = require("./constants");
6
+ class AAMPAgent {
7
+ constructor() {
8
+ this.keyPair = null;
9
+ this.agentId = "pending";
10
+ }
11
+ /**
12
+ * Initialize the Agent Identity (Ephemeral or Persisted)
13
+ * @param customAgentId Optional persistent ID for this agent. If omitted, generates a session ID.
14
+ */
15
+ async initialize(customAgentId) {
16
+ this.keyPair = await (0, crypto_1.generateKeyPair)();
17
+ // Use the provided ID (authentic) or generate a session ID (ephemeral)
18
+ this.agentId = customAgentId || "agent_" + Math.random().toString(36).substring(7);
19
+ }
20
+ async createAccessRequest(resource, purpose, options = {}) {
21
+ if (!this.keyPair)
22
+ throw new Error("Agent not initialized. Call initialize() first.");
23
+ const header = {
24
+ v: constants_1.AAMP_VERSION,
25
+ ts: new Date().toISOString(),
26
+ agent_id: this.agentId,
27
+ resource,
28
+ purpose,
29
+ context: {
30
+ ads_displayed: options.adsDisplayed || false
31
+ }
32
+ };
33
+ const signature = await (0, crypto_1.signData)(this.keyPair.privateKey, JSON.stringify(header));
34
+ const publicKeyExport = await (0, crypto_1.exportPublicKey)(this.keyPair.publicKey);
35
+ return { header, signature, publicKey: publicKeyExport };
36
+ }
37
+ /**
38
+ * NEW IN V1.1: Quality Feedback Loop
39
+ * Allows the Agent to report spam or verify quality of a resource.
40
+ */
41
+ async generateFeedback(resource, score, flags) {
42
+ if (!this.keyPair)
43
+ throw new Error("Agent not initialized.");
44
+ const signal = {
45
+ target_resource: resource,
46
+ agent_id: this.agentId,
47
+ quality_score: Math.max(0, Math.min(1, score)),
48
+ flags,
49
+ timestamp: new Date().toISOString()
50
+ };
51
+ const signature = await (0, crypto_1.signData)(this.keyPair.privateKey, JSON.stringify(signal));
52
+ return { signal, signature };
53
+ }
54
+ }
55
+ exports.AAMPAgent = AAMPAgent;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Layer 1: Protocol Constants
3
+ * These values are immutable and defined by the AAMP Specification.
4
+ */
5
+ export declare const AAMP_VERSION = "1.1";
6
+ export declare const HEADERS: {
7
+ readonly PAYLOAD: "x-aamp-payload";
8
+ readonly SIGNATURE: "x-aamp-signature";
9
+ readonly PUBLIC_KEY: "x-aamp-public-key";
10
+ readonly AGENT_ID: "x-aamp-agent-id";
11
+ readonly TIMESTAMP: "x-aamp-timestamp";
12
+ readonly ALGORITHM: "x-aamp-alg";
13
+ readonly CONTENT_ORIGIN: "x-aamp-content-origin";
14
+ readonly PROVENANCE_SIG: "x-aamp-provenance-sig";
15
+ };
16
+ export declare const CRYPTO_CONFIG: {
17
+ readonly ALGORITHM_NAME: "ECDSA";
18
+ readonly CURVE: "P-256";
19
+ readonly HASH: "SHA-256";
20
+ };
21
+ export declare const MAX_CLOCK_SKEW_MS: number;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Layer 1: Protocol Constants
4
+ * These values are immutable and defined by the AAMP Specification.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MAX_CLOCK_SKEW_MS = exports.CRYPTO_CONFIG = exports.HEADERS = exports.AAMP_VERSION = void 0;
8
+ exports.AAMP_VERSION = '1.1';
9
+ // HTTP Headers used for the handshake
10
+ exports.HEADERS = {
11
+ // Transport: The signed payload (Base64 encoded JSON of ProtocolHeader)
12
+ PAYLOAD: 'x-aamp-payload',
13
+ // Transport: The cryptographic signature (Hex)
14
+ SIGNATURE: 'x-aamp-signature',
15
+ // Transport: The Agent's Public Key (Base64 SPKI)
16
+ PUBLIC_KEY: 'x-aamp-public-key',
17
+ // Informational / Legacy (Optional if Payload is present)
18
+ AGENT_ID: 'x-aamp-agent-id',
19
+ TIMESTAMP: 'x-aamp-timestamp',
20
+ ALGORITHM: 'x-aamp-alg',
21
+ // v1.1 Addition: Provenance (Server to Agent)
22
+ CONTENT_ORIGIN: 'x-aamp-content-origin',
23
+ PROVENANCE_SIG: 'x-aamp-provenance-sig'
24
+ };
25
+ // Cryptographic Settings
26
+ exports.CRYPTO_CONFIG = {
27
+ ALGORITHM_NAME: 'ECDSA',
28
+ CURVE: 'P-256',
29
+ HASH: 'SHA-256',
30
+ };
31
+ // Tolerance
32
+ exports.MAX_CLOCK_SKEW_MS = 5 * 60 * 1000; // 5 minutes
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Layer 1: Cryptographic Primitives
3
+ * Implementation of ECDSA P-256 signing/verification.
4
+ */
5
+ export declare function generateKeyPair(): Promise<CryptoKeyPair>;
6
+ export declare function signData(privateKey: CryptoKey, data: string): Promise<string>;
7
+ export declare function verifySignature(publicKey: CryptoKey, data: string, signatureHex: string): Promise<boolean>;
8
+ export declare function exportPublicKey(key: CryptoKey): Promise<string>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Layer 1: Cryptographic Primitives
4
+ * Implementation of ECDSA P-256 signing/verification.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.generateKeyPair = generateKeyPair;
8
+ exports.signData = signData;
9
+ exports.verifySignature = verifySignature;
10
+ exports.exportPublicKey = exportPublicKey;
11
+ async function generateKeyPair() {
12
+ // Uses standard Web Crypto API (Node 19+ compatible)
13
+ return await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
14
+ }
15
+ async function signData(privateKey, data) {
16
+ const encoder = new TextEncoder();
17
+ const encoded = encoder.encode(data);
18
+ const signature = await crypto.subtle.sign({ name: "ECDSA", hash: { name: "SHA-256" } }, privateKey, encoded);
19
+ return bufToHex(signature);
20
+ }
21
+ async function verifySignature(publicKey, data, signatureHex) {
22
+ const encoder = new TextEncoder();
23
+ const encodedData = encoder.encode(data);
24
+ const signatureBytes = hexToBuf(signatureHex);
25
+ return await crypto.subtle.verify({ name: "ECDSA", hash: { name: "SHA-256" } }, publicKey, signatureBytes, encodedData);
26
+ }
27
+ async function exportPublicKey(key) {
28
+ const exported = await crypto.subtle.exportKey("spki", key);
29
+ return btoa(String.fromCharCode(...new Uint8Array(exported)));
30
+ }
31
+ // Helpers
32
+ function bufToHex(buffer) {
33
+ return Array.from(new Uint8Array(buffer))
34
+ .map(b => b.toString(16).padStart(2, '0'))
35
+ .join('');
36
+ }
37
+ function hexToBuf(hex) {
38
+ return new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
39
+ }
@@ -0,0 +1,20 @@
1
+ import { AccessPolicy, ContentOrigin } from './types';
2
+ export interface AAMPConfig {
3
+ policy: Omit<AccessPolicy, 'version'>;
4
+ meta: {
5
+ origin: keyof typeof ContentOrigin;
6
+ paymentPointer?: string;
7
+ };
8
+ }
9
+ export declare class AAMP {
10
+ private publisher;
11
+ private origin;
12
+ private ready;
13
+ private constructor();
14
+ static init(config: AAMPConfig): AAMP;
15
+ /**
16
+ * Express Middleware
17
+ */
18
+ middleware(): (req: any, res: any, next: any) => Promise<void>;
19
+ discoveryHandler(): (req: any, res: any) => void;
20
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AAMP = void 0;
4
+ /**
5
+ * Layer 3: Framework Adapters
6
+ * Zero-friction integration for Express/Node.js.
7
+ */
8
+ const publisher_1 = require("./publisher");
9
+ const types_1 = require("./types");
10
+ const crypto_1 = require("./crypto");
11
+ const constants_1 = require("./constants");
12
+ class AAMP {
13
+ constructor(config) {
14
+ this.publisher = new publisher_1.AAMPPublisher({
15
+ version: '1.1',
16
+ ...config.policy
17
+ });
18
+ this.origin = types_1.ContentOrigin[config.meta.origin];
19
+ this.ready = (0, crypto_1.generateKeyPair)().then(keys => {
20
+ return this.publisher.initialize(keys);
21
+ });
22
+ }
23
+ static init(config) {
24
+ return new AAMP(config);
25
+ }
26
+ /**
27
+ * Express Middleware
28
+ */
29
+ middleware() {
30
+ return async (req, res, next) => {
31
+ await this.ready;
32
+ // 1. Inject Provenance Headers (Passive Protection)
33
+ const headers = await this.publisher.generateResponseHeaders(this.origin);
34
+ Object.entries(headers).forEach(([k, v]) => {
35
+ res.setHeader(k, v);
36
+ });
37
+ // 2. Active Verification (If Agent sends signed headers)
38
+ const payloadHeader = req.headers[constants_1.HEADERS.PAYLOAD];
39
+ const sigHeader = req.headers[constants_1.HEADERS.SIGNATURE];
40
+ const keyHeader = req.headers[constants_1.HEADERS.PUBLIC_KEY];
41
+ if (payloadHeader && sigHeader && keyHeader) {
42
+ try {
43
+ const headerJson = atob(payloadHeader); // RAW STRING
44
+ const requestHeader = JSON.parse(headerJson);
45
+ const signedRequest = {
46
+ header: requestHeader,
47
+ signature: sigHeader,
48
+ publicKey: keyHeader
49
+ };
50
+ const agentKey = await crypto.subtle.importKey("spki", new Uint8Array(atob(keyHeader).split('').map(c => c.charCodeAt(0))), { name: "ECDSA", namedCurve: "P-256" }, true, ["verify"]);
51
+ // Pass raw headerJson to ensure signature matches exactly what was signed
52
+ const result = await this.publisher.verifyRequest(signedRequest, agentKey, headerJson);
53
+ if (!result.allowed) {
54
+ res.status(403).json({ error: result.reason });
55
+ return;
56
+ }
57
+ // Verified!
58
+ req.aamp = { verified: true, ...requestHeader };
59
+ }
60
+ catch (e) {
61
+ res.status(400).json({ error: "Invalid AAMP Signature" });
62
+ return;
63
+ }
64
+ }
65
+ next();
66
+ };
67
+ }
68
+ discoveryHandler() {
69
+ return (req, res) => {
70
+ res.setHeader('Content-Type', 'application/json');
71
+ res.send(JSON.stringify(this.publisher.getPolicy(), null, 2));
72
+ };
73
+ }
74
+ }
75
+ exports.AAMP = AAMP;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * AAMP SDK Public API
3
+ *
4
+ * This is the main entry point for the library.
5
+ */
6
+ export * from './types';
7
+ export * from './constants';
8
+ export * from './agent';
9
+ export * from './publisher';
10
+ export * from './crypto';
11
+ export * from './express';
12
+ export { AAMPNext } from './nextjs';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /**
3
+ * AAMP SDK Public API
4
+ *
5
+ * This is the main entry point for the library.
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.AAMPNext = void 0;
23
+ __exportStar(require("./types"), exports);
24
+ __exportStar(require("./constants"), exports);
25
+ __exportStar(require("./agent"), exports);
26
+ __exportStar(require("./publisher"), exports);
27
+ __exportStar(require("./crypto"), exports);
28
+ __exportStar(require("./express"), exports); // Node.js / Express Adapter
29
+ var nextjs_1 = require("./nextjs"); // Serverless / Next.js Adapter
30
+ Object.defineProperty(exports, "AAMPNext", { enumerable: true, get: function () { return nextjs_1.AAMPNext; } });
@@ -0,0 +1,23 @@
1
+ import { AccessPolicy, ContentOrigin } from './types';
2
+ type NextRequest = any;
3
+ type NextResponse = any;
4
+ export interface AAMPConfig {
5
+ policy: Omit<AccessPolicy, 'version'>;
6
+ meta: {
7
+ origin: keyof typeof ContentOrigin;
8
+ paymentPointer?: string;
9
+ };
10
+ }
11
+ export declare class AAMPNext {
12
+ private publisher;
13
+ private origin;
14
+ private ready;
15
+ private constructor();
16
+ static init(config: AAMPConfig): AAMPNext;
17
+ /**
18
+ * Serverless Route Wrapper
19
+ */
20
+ withProtection(handler: (req: NextRequest) => Promise<NextResponse>): (req: NextRequest) => Promise<any>;
21
+ discoveryHandler(): () => Promise<Response>;
22
+ }
23
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AAMPNext = void 0;
4
+ /**
5
+ * Layer 3: Framework Adapters
6
+ * Serverless integration for Next.js (App Router & API Routes).
7
+ */
8
+ const publisher_1 = require("./publisher");
9
+ const types_1 = require("./types");
10
+ const crypto_1 = require("./crypto");
11
+ const constants_1 = require("./constants");
12
+ const createJsonResponse = (body, status = 200) => {
13
+ return new Response(JSON.stringify(body), {
14
+ status,
15
+ headers: { 'Content-Type': 'application/json' }
16
+ });
17
+ };
18
+ class AAMPNext {
19
+ constructor(config) {
20
+ this.publisher = new publisher_1.AAMPPublisher({
21
+ version: '1.1',
22
+ ...config.policy
23
+ });
24
+ this.origin = types_1.ContentOrigin[config.meta.origin];
25
+ this.ready = (0, crypto_1.generateKeyPair)().then(keys => this.publisher.initialize(keys));
26
+ }
27
+ static init(config) {
28
+ return new AAMPNext(config);
29
+ }
30
+ /**
31
+ * Serverless Route Wrapper
32
+ */
33
+ withProtection(handler) {
34
+ return async (req) => {
35
+ await this.ready;
36
+ // 1. Active Verification
37
+ const payloadHeader = req.headers.get(constants_1.HEADERS.PAYLOAD);
38
+ const sigHeader = req.headers.get(constants_1.HEADERS.SIGNATURE);
39
+ const keyHeader = req.headers.get(constants_1.HEADERS.PUBLIC_KEY);
40
+ if (payloadHeader && sigHeader && keyHeader) {
41
+ try {
42
+ const headerJson = atob(payloadHeader); // RAW STRING
43
+ const requestHeader = JSON.parse(headerJson);
44
+ const signedRequest = {
45
+ header: requestHeader,
46
+ signature: sigHeader,
47
+ publicKey: keyHeader
48
+ };
49
+ const agentKey = await crypto.subtle.importKey("spki", new Uint8Array(atob(keyHeader).split('').map(c => c.charCodeAt(0))), { name: "ECDSA", namedCurve: "P-256" }, true, ["verify"]);
50
+ // Pass raw headerJson to ensure signature matches exactly what was signed
51
+ const result = await this.publisher.verifyRequest(signedRequest, agentKey, headerJson);
52
+ if (!result.allowed) {
53
+ return createJsonResponse({ error: result.reason }, 403);
54
+ }
55
+ }
56
+ catch (e) {
57
+ return createJsonResponse({ error: "Invalid AAMP Signature" }, 400);
58
+ }
59
+ }
60
+ // 2. Execute Handler
61
+ const response = await handler(req);
62
+ // 3. Inject Provenance Headers (Passive)
63
+ const aampHeaders = await this.publisher.generateResponseHeaders(this.origin);
64
+ if (response && response.headers) {
65
+ Object.entries(aampHeaders).forEach(([k, v]) => {
66
+ response.headers.set(k, v);
67
+ });
68
+ }
69
+ return response;
70
+ };
71
+ }
72
+ discoveryHandler() {
73
+ return async () => {
74
+ return createJsonResponse(this.publisher.getPolicy());
75
+ };
76
+ }
77
+ }
78
+ exports.AAMPNext = AAMPNext;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Layer 2: Publisher Middleware
3
+ * Used by content owners to enforce policy and log access.
4
+ */
5
+ import { AccessPolicy, SignedAccessRequest, ContentOrigin, FeedbackSignal } from './types';
6
+ export interface VerificationResult {
7
+ allowed: boolean;
8
+ reason: string;
9
+ responseHeaders?: Record<string, string>;
10
+ }
11
+ export declare class AAMPPublisher {
12
+ private policy;
13
+ private keyPair;
14
+ constructor(policy: AccessPolicy);
15
+ initialize(keyPair: CryptoKeyPair): Promise<void>;
16
+ getPolicy(): AccessPolicy;
17
+ /**
18
+ * Verifies an incoming AI access request.
19
+ *
20
+ * @param request The parsed request object
21
+ * @param requestPublicKey The agent's public key
22
+ * @param rawPayload (Optional) The raw string received over the wire. REQUIRED for robust verification.
23
+ */
24
+ verifyRequest(request: SignedAccessRequest, requestPublicKey: CryptoKey, rawPayload?: string): Promise<VerificationResult>;
25
+ /**
26
+ * Verifies a Feedback Signal (Spam Report) from an Agent.
27
+ * Part of the AAMP Immune System.
28
+ */
29
+ verifyFeedback(signal: FeedbackSignal, signature: string, agentPublicKey: CryptoKey): Promise<boolean>;
30
+ generateResponseHeaders(origin: ContentOrigin): Promise<Record<string, string>>;
31
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AAMPPublisher = void 0;
4
+ /**
5
+ * Layer 2: Publisher Middleware
6
+ * Used by content owners to enforce policy and log access.
7
+ */
8
+ const types_1 = require("./types");
9
+ const crypto_1 = require("./crypto");
10
+ const constants_1 = require("./constants");
11
+ class AAMPPublisher {
12
+ constructor(policy) {
13
+ this.keyPair = null;
14
+ this.policy = policy;
15
+ }
16
+ // Publishers now need keys too, to sign their Content Origin declarations
17
+ async initialize(keyPair) {
18
+ this.keyPair = keyPair;
19
+ }
20
+ getPolicy() {
21
+ return this.policy;
22
+ }
23
+ /**
24
+ * Verifies an incoming AI access request.
25
+ *
26
+ * @param request The parsed request object
27
+ * @param requestPublicKey The agent's public key
28
+ * @param rawPayload (Optional) The raw string received over the wire. REQUIRED for robust verification.
29
+ */
30
+ async verifyRequest(request, requestPublicKey, rawPayload) {
31
+ // 1. Replay Attack Prevention (Timestamp Check)
32
+ const requestTime = new Date(request.header.ts).getTime();
33
+ const now = Date.now();
34
+ if (Math.abs(now - requestTime) > constants_1.MAX_CLOCK_SKEW_MS) {
35
+ return { allowed: false, reason: 'TIMESTAMP_INVALID: Clock skew exceeded.' };
36
+ }
37
+ // 2. Policy Enforcement (Usage Type)
38
+ // STRICT CHECK: Training
39
+ if (request.header.purpose === types_1.AccessPurpose.CRAWL_TRAINING && !this.policy.allowTraining) {
40
+ return { allowed: false, reason: 'POLICY_DENIED: Training not allowed by site owner.' };
41
+ }
42
+ // STRICT CHECK: RAG / Retrieval
43
+ if (request.header.purpose === types_1.AccessPurpose.RAG_RETRIEVAL && !this.policy.allowRAG) {
44
+ return { allowed: false, reason: 'POLICY_DENIED: RAG Retrieval not allowed.' };
45
+ }
46
+ // 3. Economic Policy Enforcement
47
+ if (this.policy.requiresPayment) {
48
+ const isExemptViaAds = this.policy.allowAdSupportedAccess && request.header.context.ads_displayed;
49
+ if (!isExemptViaAds) {
50
+ return {
51
+ allowed: false,
52
+ reason: 'PAYMENT_REQUIRED: Site requires payment or ad-supported access.'
53
+ };
54
+ }
55
+ }
56
+ // 4. Cryptographic Verification (The "Proof")
57
+ // CRITICAL: We prefer the rawPayload if available to avoid JSON parsing/stringify mismatches.
58
+ const signableString = rawPayload || JSON.stringify(request.header);
59
+ const isValid = await (0, crypto_1.verifySignature)(requestPublicKey, signableString, request.signature);
60
+ if (!isValid) {
61
+ return { allowed: false, reason: 'CRYPTO_FAIL: Signature verification failed.' };
62
+ }
63
+ return { allowed: true, reason: 'OK' };
64
+ }
65
+ /**
66
+ * Verifies a Feedback Signal (Spam Report) from an Agent.
67
+ * Part of the AAMP Immune System.
68
+ */
69
+ async verifyFeedback(signal, signature, agentPublicKey) {
70
+ const signableString = JSON.stringify(signal);
71
+ return await (0, crypto_1.verifySignature)(agentPublicKey, signableString, signature);
72
+ }
73
+ async generateResponseHeaders(origin) {
74
+ if (!this.keyPair)
75
+ throw new Error("Publisher keys not initialized");
76
+ const payload = JSON.stringify({ origin, ts: Date.now() });
77
+ const signature = await (0, crypto_1.signData)(this.keyPair.privateKey, payload);
78
+ return {
79
+ [constants_1.HEADERS.CONTENT_ORIGIN]: origin,
80
+ [constants_1.HEADERS.PROVENANCE_SIG]: signature
81
+ };
82
+ }
83
+ }
84
+ exports.AAMPPublisher = AAMPPublisher;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Layer 1: Protocol Definitions
3
+ * Shared types used by both Agent and Publisher.
4
+ */
5
+ export declare enum AccessPurpose {
6
+ CRAWL_TRAINING = "CRAWL_TRAINING",
7
+ RAG_RETRIEVAL = "RAG_RETRIEVAL",
8
+ SUMMARY = "SUMMARY",
9
+ QUOTATION = "QUOTATION",
10
+ EMBEDDING = "EMBEDDING"
11
+ }
12
+ export declare enum ContentOrigin {
13
+ HUMAN = "HUMAN",// Created by humans. High training value.
14
+ SYNTHETIC = "SYNTHETIC",// Created by AI. Risk of model collapse.
15
+ HYBRID = "HYBRID"
16
+ }
17
+ export declare enum QualityFlag {
18
+ SEO_SPAM = "SEO_SPAM",
19
+ INACCURATE = "INACCURATE",
20
+ HATE_SPEECH = "HATE_SPEECH",
21
+ HIGH_QUALITY = "HIGH_QUALITY"
22
+ }
23
+ /**
24
+ * Optional Rate Limiting (The Speed Limit)
25
+ * Defines technical boundaries for the handshake.
26
+ */
27
+ export interface RateLimitConfig {
28
+ requestsPerMinute: number;
29
+ tokensPerMinute?: number;
30
+ }
31
+ /**
32
+ * Optional Monetization (The Settlement Layer)
33
+ *
34
+ * AAMP is neutral. Settlement can happen via:
35
+ * 1. BROKER: A 3rd party clearing house (e.g., "AI-AdSense").
36
+ * 2. CRYPTO: Direct on-chain settlement.
37
+ * 3. TREATY: A private legal contract signed offline (Enterprise).
38
+ */
39
+ export interface MonetizationConfig {
40
+ method: 'BROKER' | 'CRYPTO' | 'PRIVATE_TREATY';
41
+ /**
42
+ * The destination for settlement.
43
+ * - If BROKER: The API URL of the clearing house.
44
+ * - If CRYPTO: The wallet address.
45
+ * - If TREATY: The Contract ID or "Contact Sales".
46
+ */
47
+ location: string;
48
+ }
49
+ export interface AccessPolicy {
50
+ version: '1.1';
51
+ allowTraining: boolean;
52
+ allowRAG: boolean;
53
+ attributionRequired: boolean;
54
+ allowAdSupportedAccess: boolean;
55
+ requiresPayment: boolean;
56
+ paymentPointer?: string;
57
+ rateLimit?: RateLimitConfig;
58
+ monetization?: MonetizationConfig;
59
+ }
60
+ export interface ProtocolHeader {
61
+ v: '1.1';
62
+ ts: string;
63
+ agent_id: string;
64
+ resource: string;
65
+ purpose: AccessPurpose;
66
+ context: {
67
+ ads_displayed: boolean;
68
+ };
69
+ }
70
+ export interface SignedAccessRequest {
71
+ header: ProtocolHeader;
72
+ signature: string;
73
+ publicKey?: string;
74
+ }
75
+ export interface FeedbackSignal {
76
+ target_resource: string;
77
+ agent_id: string;
78
+ quality_score: number;
79
+ flags: QualityFlag[];
80
+ timestamp: string;
81
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * Layer 1: Protocol Definitions
4
+ * Shared types used by both Agent and Publisher.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.QualityFlag = exports.ContentOrigin = exports.AccessPurpose = void 0;
8
+ var AccessPurpose;
9
+ (function (AccessPurpose) {
10
+ AccessPurpose["CRAWL_TRAINING"] = "CRAWL_TRAINING";
11
+ AccessPurpose["RAG_RETRIEVAL"] = "RAG_RETRIEVAL";
12
+ AccessPurpose["SUMMARY"] = "SUMMARY";
13
+ AccessPurpose["QUOTATION"] = "QUOTATION";
14
+ AccessPurpose["EMBEDDING"] = "EMBEDDING";
15
+ })(AccessPurpose || (exports.AccessPurpose = AccessPurpose = {}));
16
+ var ContentOrigin;
17
+ (function (ContentOrigin) {
18
+ ContentOrigin["HUMAN"] = "HUMAN";
19
+ ContentOrigin["SYNTHETIC"] = "SYNTHETIC";
20
+ ContentOrigin["HYBRID"] = "HYBRID"; // Edited by humans, drafted by AI.
21
+ })(ContentOrigin || (exports.ContentOrigin = ContentOrigin = {}));
22
+ var QualityFlag;
23
+ (function (QualityFlag) {
24
+ QualityFlag["SEO_SPAM"] = "SEO_SPAM";
25
+ QualityFlag["INACCURATE"] = "INACCURATE";
26
+ QualityFlag["HATE_SPEECH"] = "HATE_SPEECH";
27
+ QualityFlag["HIGH_QUALITY"] = "HIGH_QUALITY";
28
+ })(QualityFlag || (exports.QualityFlag = QualityFlag = {}));
@@ -0,0 +1 @@
1
+ export {};