pub struct Gateway { /* private fields */ }Expand description
A2A Gateway with reputation-based access control
Implementations§
Source§impl Gateway
impl Gateway
Sourcepub fn with_rate_limit(max_requests_per_minute: u32) -> Self
pub fn with_rate_limit(max_requests_per_minute: u32) -> Self
Create gateway with custom rate limit
Sourcepub fn check_permission(
&self,
user_pubkey: &str,
action: &SwarmAction,
) -> Result<PermissionCheck, GatewayError>
pub fn check_permission( &self, user_pubkey: &str, action: &SwarmAction, ) -> Result<PermissionCheck, GatewayError>
Check if an agent has permission to execute an action
This is the critical security function that enforces reputation-based access control for the 22-Layer Stack.
§Security Model
┌─────────────────────────────────────────────────────────────────┐
│ PERMISSION CHECK FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Request → Rate Limit Check → Session Verify → Reputation Check │
│ │
│ Layer 1-16: score >= 0 → ALLOW │
│ Layer 17-21: score >= 300 → ALLOW (Collateral Threshold) │
│ Layer 22: score >= 500 → ALLOW (Swarm Coordinator) │
│ │
│ Below threshold → 403 FORBIDDEN │
│ │
└─────────────────────────────────────────────────────────────────┘Sourcepub fn enforce_permission(
&self,
user_pubkey: &str,
action: &SwarmAction,
) -> Result<(), GatewayError>
pub fn enforce_permission( &self, user_pubkey: &str, action: &SwarmAction, ) -> Result<(), GatewayError>
Enforce permission check - returns Ok(()) if allowed, Err(Forbidden) if not
USE THIS for actual enforcement in request handlers.
Sourcepub fn enforce_swarm_permission(
&self,
user_pubkey: &str,
) -> Result<(), GatewayError>
pub fn enforce_swarm_permission( &self, user_pubkey: &str, ) -> Result<(), GatewayError>
Specific check for Layer 22 Swarm Coordination
Returns 403 Forbidden if threshold_proofs[“swarm_coordinator”] is false.
Sourcepub fn check_rate_limit(&self, agent_pubkey: &str) -> Result<(), GatewayError>
pub fn check_rate_limit(&self, agent_pubkey: &str) -> Result<(), GatewayError>
Check rate limit for an agent
Sourcepub fn process_request(
&self,
request: &A2ARequest,
) -> Result<PermissionCheck, GatewayError>
pub fn process_request( &self, request: &A2ARequest, ) -> Result<PermissionCheck, GatewayError>
Process a full A2A request with all security checks
Sourcepub fn get_reputation(
&self,
user_pubkey: &str,
) -> Result<TrustScore, GatewayError>
pub fn get_reputation( &self, user_pubkey: &str, ) -> Result<TrustScore, GatewayError>
Get reputation engine for a user (creates if not exists)
Sourcepub fn record_attestation(
&self,
user_pubkey: &str,
attestation: &AttestationRecord,
) -> Result<TrustScore, GatewayError>
pub fn record_attestation( &self, user_pubkey: &str, attestation: &AttestationRecord, ) -> Result<TrustScore, GatewayError>
Update reputation with attestation (used after successful actions)
Sourcepub fn hire_sub_agent(
&self,
user_pubkey: &str,
sub_agent_pubkey: &str,
task_id: &str,
budget: u64,
) -> Result<HireResult, GatewayError>
pub fn hire_sub_agent( &self, user_pubkey: &str, sub_agent_pubkey: &str, task_id: &str, budget: u64, ) -> Result<HireResult, GatewayError>
Hire a sub-agent for a specific task
§Security Rules:
- User must have sufficient reputation (Layer 20 for hire, Layer 22 for swarm)
- User cannot exceed their tier’s max_sub_agents limit
- A 1% management fee is captured and deposited to user’s vault
§Fee Capture Flow:
User Budget: 1000 CRED
Fee (1%): 10 CRED → User's Vault
Net to Agent: 990 CRED → Sub-AgentSourcepub fn coordinate_swarm(
&self,
user_pubkey: &str,
task_id: &str,
sub_agents: &[String],
budget_per_agent: u64,
) -> Result<SwarmCoordinationResult, GatewayError>
pub fn coordinate_swarm( &self, user_pubkey: &str, task_id: &str, sub_agents: &[String], budget_per_agent: u64, ) -> Result<SwarmCoordinationResult, GatewayError>
Coordinate multiple sub-agents for a complex task (Layer 22)
This is the highest-tier operation requiring Elite-level reputation. Orchestrates multiple sub-agents for parallel task execution.
Sourcepub fn release_sub_agent(
&self,
user_pubkey: &str,
sub_agent_pubkey: &str,
) -> Result<bool, GatewayError>
pub fn release_sub_agent( &self, user_pubkey: &str, sub_agent_pubkey: &str, ) -> Result<bool, GatewayError>
Release a sub-agent (end contract)
Sourcepub fn get_sub_agent_status(
&self,
user_pubkey: &str,
) -> Result<(Vec<String>, u64, u8), GatewayError>
pub fn get_sub_agent_status( &self, user_pubkey: &str, ) -> Result<(Vec<String>, u64, u8), GatewayError>
Get sub-agent status for a user
Sourcepub fn register_referral(
&self,
referrer_agent: &str,
referred_user: &str,
) -> Result<(), GatewayError>
pub fn register_referral( &self, referrer_agent: &str, referred_user: &str, ) -> Result<(), GatewayError>
Register a new referral when a user joins via agent invite code
Called when: User redeems an invite code issued by an agent
Sourcepub fn process_referral_bounty(
&self,
referred_user: &str,
verified_credential_tier: u8,
) -> Result<ReferralBountyResult, GatewayError>
pub fn process_referral_bounty( &self, referred_user: &str, verified_credential_tier: u8, ) -> Result<ReferralBountyResult, GatewayError>
Process a referral bounty when a referred user verifies a Tier 1+ credential
§Bounty Rules:
- The referred user must have been invited by an agent (registered referral)
- The referred user must verify a Tier 1 or higher credential
- The bounty is 10% of the referrer agent’s current base reputation score
- Each referral can only be paid once
§Returns:
ReferralBountyResult with the boost amount and new score
Sourcepub fn get_agent_referral_stats(
&self,
agent_pubkey: &str,
) -> Result<(Vec<ReferralRecord>, u32), GatewayError>
pub fn get_agent_referral_stats( &self, agent_pubkey: &str, ) -> Result<(Vec<ReferralRecord>, u32), GatewayError>
Get referral statistics for an agent
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Gateway
impl RefUnwindSafe for Gateway
impl Send for Gateway
impl Sync for Gateway
impl Unpin for Gateway
impl UnsafeUnpin for Gateway
impl UnwindSafe for Gateway
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more