/** * Soma Check — conditional payment protocol (soma-check/1.0) * * The first conditional payment protocol for APIs. Agents check a content * hash before paying — if data hasn't changed, they pay nothing. Built on * the existing birth-certificate `dataHash`, so the primitive that proves * provenance also drives change detection. * * Headers: * Request: `If-Soma-Hash: ` — agent's last-known hash for this resource * Response: `X-Soma-Hash: ` — current content hash * `X-Soma-Protocol: soma-check/1.0` * * Flow: * 1. Agent calls an endpoint normally → gets response with X-Soma-Hash * 2. Agent stores hash, keyed by URL/resource * 3. Next time, agent sends If-Soma-Hash with the stored hash * 4. If server's current hash matches → { unchanged: true }, 0 cost * 5. If different → normal paid response with new hash * * Backward compatible: clients that don't send If-Soma-Hash pay normally. */ export declare const SOMA_CHECK_PROTOCOL = "soma-check/1.0"; /** Minimum length (hex characters) for any hash used in the Soma Check protocol. */ export declare const SOMA_CHECK_MIN_HASH_LENGTH = 16; export declare const SOMA_CHECK_HEADERS: { /** Request header — agent's last-known hash. */ readonly IF_SOMA_HASH: "If-Soma-Hash"; /** Response header — current content hash. */ readonly X_SOMA_HASH: "X-Soma-Hash"; /** Response header — protocol version marker. */ readonly X_SOMA_PROTOCOL: "X-Soma-Protocol"; }; /** A Soma Check response body when data is unchanged (0-cost hit). */ export interface UnchangedResponse { unchanged: true; dataHash: string; /** ISO-8601 timestamp of when the hash was last computed. */ cachedAt?: string; /** Whether the cached entry is still fresh (vs. stale-but-matching). */ fresh?: boolean; /** Age of the cache entry in seconds. */ age?: number; /** Protocol marker. */ protocol: 'soma-check'; creditsUsed?: 0; } /** Metadata describing a cached resource for a check response. */ export interface CheckMetadata { cachedAt?: string | Date; freshUntil?: string | Date; fresh?: boolean; age?: number; } /** * Build the response headers a provider should emit on every call. * Agents use the `X-Soma-Hash` value in their next `If-Soma-Hash` request. */ export declare function buildSomaCheckResponseHeaders(dataHash: string): Record; /** * Build the request headers for a consumer sending `If-Soma-Hash`. */ export declare function buildSomaCheckRequestHeaders(lastKnownHash: string): Record; /** * Extract the `If-Soma-Hash` value from a request's headers. * Returns null if header is missing. Headers are read case-insensitively. * Throws if the header is present but the hash is shorter than * {@link SOMA_CHECK_MIN_HASH_LENGTH} hex characters. */ export declare function extractIfSomaHash(headers: Record | Headers | undefined | null): string | null; /** * Extract the current `X-Soma-Hash` from a response's headers. * Consumers store this to send back as `If-Soma-Hash` on next call. */ export declare function extractSomaHash(headers: Record | Headers | undefined | null): string | null; /** Check whether a response was served via Soma Check (carries protocol header). */ export declare function isSomaCheckResponse(headers: Record | Headers | undefined | null): boolean; /** * Given a cached data hash and an incoming request's `If-Soma-Hash` header, * decide whether the provider should respond with `unchanged: true` (0 cost) * instead of doing the full paid fetch. * * Returns null if there's no match (caller should proceed with normal flow). */ export declare function shouldRespondUnchanged(incomingHash: string | null, currentHash: string | null): boolean; /** * Build the response body for a cache hit where hash hasn't changed. * The caller is responsible for setting the response headers separately * via `buildSomaCheckResponseHeaders(dataHash)`. */ export declare function buildUnchangedResponse(dataHash: string, meta?: CheckMetadata): UnchangedResponse; /** * In-memory hash store keyed by URL/resource. * For production use, persist this to disk or a small KV store. */ export declare class SomaCheckHashStore { private readonly hashes; get(key: string): string | undefined; set(key: string, hash: string): void; has(key: string): boolean; delete(key: string): boolean; clear(): void; size(): number; entries(): IterableIterator<[string, string]>; } /** * Verify that a birth certificate's `dataHash` matches the `X-Soma-Hash` * header value. The spec requires these to be identical — call this after * extracting both values to confirm they are consistent. */ export declare function verifyDataHashConsistency(birthCertDataHash: string, xSomaHashHeader: string): boolean; //# sourceMappingURL=soma-check.d.ts.map