import { p as Decision, s as BlockReason } from "./types-CsUMEPQx.mjs"; import { AssuranceTier } from "@kya-os/checkpoint-shared"; //#region src/policy-evaluator.d.ts /** * Owned, plain-data request the host hands to * {@link PolicyEvaluatorRuntime.authorize}. Mirrors the Rust * `AuthorizeInput` (`rust/crates/kya-os-engine/src/policy/authorize.rs`); * keys are camelCase across the wasm-bindgen boundary, matching every * other engine wire type. * * The evaluator is **synchronous over pre-resolved facts** (H-1 Kickoff * § 4.5): the host pre-fetches the agent's delegation chain, reputation, * etc. and ships the results here — no JS callbacks cross the boundary. * * `agentDid` and `reputation` are optional (omit or pass `undefined` for * an anonymous or reputation-less request); `grantedScopes` defaults to an * empty list when omitted. * * The attribute-based facts — `name`, `category`, `delegation`, `path` — * are optional too. They populate the principal / resource entity * attributes (`principal.name`, `principal.category`, * `principal.delegation`, `resource.path`) that attribute-based Cedar * policies reference. When omitted, the engine fills each with its default * (`""` for strings) so a policy comparing them evaluates to `false` * instead of erroring on an undefined attribute. */ export interface AuthorizeInput { /** Server-owned application permission for this authenticated user/operation. * Never accept from request JSON, headers, classification, or clearance. */ applicationAuthorized?: boolean; /** Agent DID if identity has been established, otherwise omitted. */ agentDid?: string; /** Exact user DID asserted by a verified delegation issuer; not merchant IAM. */ authorizingUserDid?: string; /** The action being requested (e.g., `"book_flight"`). */ action: string; /** The resource being acted on (e.g., `"travel_api"`). */ resource: string; /** Scopes granted by the agent's delegation chain. Defaults to `[]`. */ grantedScopes?: string[]; /** Agent's reputation score in `[0.0, 1.0]`, if computed. */ reputation?: number; /** Tenant identifier. */ tenantId: string; /** Known-agent label (e.g. `"ClaudeDesktop"`) → `principal.name`. */ name?: string; /** Agent category (e.g. `"scraper"`) → `principal.category`. */ category?: string; /** Delegation posture (e.g. `"verified"`) → `principal.delegation`. */ delegation?: string; /** Resource path (e.g. `"/checkout"`) → `resource.path`. */ path?: string; /** * draft-kya-http-02 §1 assurance tier the request reached * (`anonymous` | `attested-bearer` | `key-bound` | `registered` | * `delegated`) → `context.assurance`. Defaults to `"anonymous"` (the * monotone floor) when omitted, so a policy gating on * `context.assurance == "delegated"` evaluates rather than erroring. */ assurance?: AssuranceTier; /** * Locally verified browser risk, independent of credential assurance. * `'cleared'` is the human step-up outcome: a request carrying a valid * `__Host-kya_clearance` JWT (verified by the host, bound to the * session cookie, 10-minute lifetime) → `context.integrity = "cleared"`, * which the engine-default policy permits. */ integrity?: 'agent-driven' | 'human' | 'insufficient' | 'unknown' | 'cleared'; /** * Detection confidence on the shared 0-100 scale → `principal.confidence` * (a Cedar Long). Absent stays absent — no default — so a caller that * never supplies this leaves the Cedar entity byte-identical to before * this field existed. */ confidence?: number; /** * Coarse IP-routing classification from the host's network context → * `context.ip_routing_type`. Omit when the host has no network context. */ ipRoutingType?: 'residential' | 'mobile' | 'datacenter' | 'hosting' | 'unknown'; /** * Whether the request's `trueIp` was flagged as a proxy/anonymization * exit → `context.is_proxy`. Omit when the host has no network context. */ isProxy?: boolean; /** * Coarse category of a confirmed proxy/anonymization service → * `context.proxy_type`. Omit when the host has no proxy verdict (same * posture as `isProxy` — only present once a proxy verdict was computed). */ proxyType?: 'vpn' | 'tor' | 'datacenter' | 'residential_proxy' | 'unknown'; /** * The host's IP-intelligence provider's confidence in the proxy verdict, * `0..=100` → `context.network_confidence` (a Cedar Long). Omit when the * host has no proxy verdict. */ networkConfidence?: number; /** * Gateway-computed request count for this client (session-cookie or * JA4+IP keyed) in the trailing 300-second window → * `context.request_rate_300s` (a Cedar Long). Omit when the host has no * velocity tracker for this request. */ requestRate300s?: number; } /** * Structural type of the WASM `PolicyEvaluator` class the cedar glue * exports. Pinned here so this bridge type-checks against the artifact's * `.d.ts` (`constructor(policy_text: string)`, `authorize(input): any`, * `free()`). */ interface WasmPolicyEvaluator { authorize(input: AuthorizeInput): unknown; free(): void; } /** * Result of validating a tenant policy bundle against the canonical Cedar * schema. Mirrors the Rust `PolicyValidation` * (`rust/crates/kya-os-engine/src/policy/schema.rs`); a typo'd attribute, * wrong-type comparison, or unknown entity surfaces in `errors`. */ export interface PolicyValidation { /** True iff the bundle compiled AND type-checked with no errors (warnings OK). */ valid: boolean; /** Type/parse errors — author must fix (typo'd attribute, wrong type, …). */ errors: string[]; /** Non-fatal validation warnings (impossible/shadowed clause, …). */ warnings: string[]; } /** * Host-facing wrapper around one compiled Cedar policy bundle. * * Construction compiles the bundle once; every {@link authorize} call * evaluates a single owned request against it without re-parsing policy * text (the compile-once / evaluate-many contract the engine upholds, * carried across the boundary). */ export declare class PolicyEvaluatorRuntime { private readonly inner; /** * @param inner - The compiled WASM `PolicyEvaluator` handle. Built in * {@link createPolicyEvaluator}; reused by every {@link authorize} * call for the lifetime of this wrapper. */ constructor(inner: WasmPolicyEvaluator); /** * Authorize one owned request against the compiled policy bundle. * * The evaluator owns the fail-closed posture — a request it cannot * marshal into Cedar, or one matching no `permit`, comes back as a * {@link Decision} `Block` (not a thrown error). Authorization * *verdicts* never throw; they surface inside the returned value. * * @throws {Error} only for boundary faults the WASM glue rejects: a * malformed `input` that fails `AuthorizeInput` deserialisation, or a * failure serialising the resulting `Decision`. */ authorize(input: AuthorizeInput): Decision; /** * Release the compiled bundle's WASM memory. Call when the evaluator is * no longer needed; after this the wrapper must not be reused. */ free(): void; } /** * Compile a Cedar policy bundle into a reusable in-process evaluator. * * Loads like `engine/node.ts`: routes through the cedar * `--target nodejs` glue, which self-loads its `.wasm` sibling via CJS * `__dirname` + `require('fs')`. The returned {@link PolicyEvaluatorRuntime} * holds one compiled bundle and authorizes many requests against it. * * @param policyText - The tenant's Cedar policy bundle as source text. * @throws {Error} if `policyText` is not syntactically valid Cedar — a * malformed bundle is an infrastructure fault surfaced here at * construction, never as a per-request deny. * * @example * ```typescript * import { createPolicyEvaluator } from '@kya-os/checkpoint-wasm-runtime/policy'; * * const evaluator = createPolicyEvaluator('permit(principal, action, resource);'); * const decision = evaluator.authorize({ * action: 'book_flight', * resource: 'travel_api', * tenantId: 'tenant-a', * grantedScopes: ['book_flight'], * }); * if (decision.kind === 'Permit') { * // proceed * } * ``` */ export declare function createPolicyEvaluator(policyText: string): PolicyEvaluatorRuntime; /** * Validate a tenant Cedar bundle against the canonical schema WITHOUT compiling * an evaluator or throwing (E4.7 / #3076). Returns the type/parse errors + * warnings so an author-time surface (the dashboard's /policy-compose path) can * show a typo'd attribute / wrong type as a LOUD error before deploy — instead * of the runtime's silent fail-closed deny. A blank bundle is valid ("no * composed policy"). Pure: changes no authorization verdict. * * @example * ```typescript * import { validatePolicy } from '@kya-os/checkpoint-wasm-runtime/policy'; * const { valid, errors } = validatePolicy('permit(principal, action, resource) when { principal.catgory == "x" };'); * // valid === false; errors describes the unknown `catgory` attribute. * ``` */ export declare function validatePolicy(policyText: string): PolicyValidation; //#endregion export type { BlockReason, Decision }; //# sourceMappingURL=policy.d.mts.map