Skip to main content

wasm_capability_contract/component/traits/
component_validator.rs

1//! [`ComponentValidator`] — checks a component before its route is ever registered.
2
3use crate::{CapabilityError, ValidateComponentRequest};
4
5/// Checks a Wasm component's manifest and real bytes before its route is
6/// registered. A real implementor enforces two gates, per ADR-001:
7///
8/// 1. **Manifest-level grant check** — every capability
9///    `req.manifest.capabilities` declares must appear in
10///    `req.granted_capabilities` (deny-by-default), and each grant's
11///    `CapabilityScope` must be non-trivially empty for its kind.
12/// 2. **Structural import check** — `req.component_bytes`' actual
13///    component-level imports must each be backed by either a granted
14///    capability with a real host implementation, or an unconditional
15///    base-ABI runtime-support import.
16///
17/// Zero implementation here — this port only declares the contract.
18pub trait ComponentValidator: Send + Sync {
19    /// Validate `req`, per the two-gate contract above.
20    ///
21    /// # Errors
22    ///
23    /// Returns [`CapabilityError`] naming which gate failed and why.
24    fn validate(&self, req: ValidateComponentRequest) -> Result<(), CapabilityError>;
25}