import type { McpServerRef, PinStore, ToolDef, WardenGate, WardenGateInput, WardenGateResult } from "./types.js"; /** * Tool-definition pinning + drift detection ("rug-pull" defence). * * A server can advertise benign tools at approval time and silently swap in a * poisoned definition later. We hash the canonical tool-def set on approval and * compare on every subsequent connection: a changed hash means the contract the * user approved no longer holds, so (under policy.pinToolDefs) we block and force * re-approval. First-contact servers are flagged UNPINNED so the chain knows the * pin is established only when the user approves. */ export declare class PinningGate implements WardenGate { private readonly store; readonly name = "pinning"; constructor(store: PinStore); /** Identity-only check: safe before starting the untrusted process. */ evaluateLaunch(input: WardenGateInput): Promise; evaluate(input: WardenGateInput): Promise; /** * Has the program behind this server changed since approval? * * Silent when the pin predates {@link PinnedServer.identityHash}: an absent * value is "not recorded", never "changed". The next `approve()` records it. */ private identityDrift; /** * The tool-def set has no canonical form (see {@link canonicalToolsHash}), so no * hash can be produced for it. What that means depends on whether a pin exists: * * - **No pin yet** — nothing is being contradicted; the pin simply cannot be * established, which is a `medium` warning and not evidence of an attack. * - **Pin exists** — the snapshot the user approved can no longer be re-verified, * which is indistinguishable from drift and is treated as drift. Otherwise a * server could disarm the rug-pull defence at will by adding one fractional * number to a schema. */ private uncanonical; /** * Persist the current tool-def set as the trusted snapshot for this server. * Called by Warden.approve() once a user has accepted the connection. * * Throws {@link CanonicalizationError} only when the set has no RFC 8785 form at * all (a lone surrogate, nesting past the bound); fractional numbers are pinned * with {@link pinToolsHash}. The host must fail closed when pinning is required. */ pin(server: McpServerRef, tools: ToolDef[], approvalMode?: "operator" | "automatic"): Promise; } /** * Marker used where a tool-def hash is *recorded* rather than compared, and the set * turned out to have no canonical form. It can never collide with a sha256 hex * digest, so anything that later compares it simply reports a mismatch. */ export declare const UNCANONICAL_TOOLS_HASH = "uncanonical:non-canonical-tool-defs"; /** * sha256 over the canonical tool-def set: tools sorted by name, each reduced to * all advertised fields (including title, outputSchema, annotations and extensions), serialised with * {@link canonicalize} — RFC 8785 (JCS) as profiled in `awr/SPEC.md` §4. * * This digest is quoted in receipts and re-checked elsewhere (`argus verify`, the * sealed mandate), so it has to be reproducible by an implementation that is not * this one. Two consequences: * * - **Ordering is by UTF-16 code unit, never `localeCompare`.** `localeCompare` * depends on the host locale and ICU version — `["a", "B"]` sorts one way under * `en-US` and another under the C locale — so a digest built on it is not even * stable across two machines running this same code, let alone across languages. * JavaScript's `<`/`>` on strings compare UTF-16 code units, which is exactly * RFC 8785 §3.2.3's rule. * - **Non-integer numbers are refused** (`AWR-CANON-001`, SPEC §4.3) rather than * serialised. Whether `1` is an integer or a double is a language accident that * silently changes the bytes, so a schema carrying e.g. `"multipleOf": 0.01` has * no canonical form here and this function throws * {@link CanonicalizationError}. Callers must handle that — refusing to emit a * digest is honest; emitting one nobody else can reproduce is not. */ export declare function canonicalToolsHash(tools: ToolDef[]): string; /** Prefix of a {@link pinToolsHash} taken over plain RFC 8785 because the set has fractional numbers. */ export declare const RFC8785_PIN_PREFIX = "rfc8785:"; /** * The hash a host pins and re-checks ITSELF: {@link canonicalToolsHash} wherever * that exists, so every existing pin still matches; otherwise `rfc8785:` + sha256 * over plain RFC 8785, which serialises a fractional number (`"default": 0.7`) in * its ECMAScript form instead of refusing it. * * About one public server in fourteen has a fractional number somewhere in its * schemas. Refusing to pin those made them impossible to wrap at all. Drift is * still caught: adding or removing a fractional number moves the set between the * two forms, and the two never compare equal. The `rfc8785:` form is local * state, never a receipt digest — receipts keep {@link tryCanonicalToolsHash}. */ export declare function pinToolsHash(tools: ToolDef[]): string; /** * Like {@link canonicalToolsHash} but total: returns `undefined` instead of * throwing, for call sites that record a hash rather than enforce one. */ export declare function tryCanonicalToolsHash(tools: ToolDef[]): string | undefined; /** * sha256 over the server's launch identity: transport, command, args, url, name. * * Deliberately NOT the whole `McpServerRef`: `catalog` is provenance rather than * identity (the origin gate is what has an opinion about it), and `env` holds * secrets that must not be hashed into a value stored on disk next to the pin. * * Missing fields serialize as empty rather than being omitted, so a server that * gains a `url` reads as a change instead of hashing the same as before. */ export declare function serverIdentityHash(server: McpServerRef): string; //# sourceMappingURL=pinning.d.ts.map