proofgate 0.1.1

Official ProofGate SDK — blockchain transaction validation and guardrails for AI agents
Documentation
# proofgate

> Blockchain guardrails for AI agents. Validate transactions before execution.

[![Crates.io](https://img.shields.io/crates/v/proofgate.svg)](https://crates.io/crates/proofgate)
[![Documentation](https://docs.rs/proofgate/badge.svg)](https://docs.rs/proofgate)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## What is ProofGate?

ProofGate validates blockchain transactions before your AI agent executes them. It prevents:

- 🚫 **Wallet drains** from prompt injection attacks
- 🚫 **Infinite approvals** to malicious contracts  
- 🚫 **Excessive spending** beyond daily limits
- 🚫 **High slippage** swaps that lose money

## Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
proofgate = "0.1"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
```

## Quick Start

```rust
use proofgate::{ProofGate, ValidateRequest};

#[tokio::main]
async fn main() -> Result<(), proofgate::Error> {
    // Initialize client
    let pg = ProofGate::new("pg_your_api_key")?; // Get from proofgate.xyz/dashboard

    // Validate before sending
    let result = pg.validate(ValidateRequest {
        from: "0xYourAgentWallet".to_string(),
        to: "0xContractAddress".to_string(),
        data: "0xa9059cbb...".to_string(), // Transaction calldata
        value: Some("0".to_string()),
        guardrail_id: None,
        chain_id: None,
    }).await?;

    if result.safe {
        // ✅ Execute the transaction
        println!("Transaction approved!");
    } else {
        // 🚫 Transaction blocked
        println!("Blocked: {}", result.reason);
    }

    Ok(())
}
```

## API Reference

### `ProofGate::new(api_key)`

Create a new ProofGate client.

```rust
let pg = ProofGate::new("pg_xxx")?;
```

### `ProofGate::with_config(config)`

Create with custom configuration:

```rust
use proofgate::{ProofGate, ProofGateConfig};
use std::time::Duration;

let pg = ProofGate::with_config(ProofGateConfig {
    api_key: "pg_xxx".to_string(),
    chain_id: 56,                    // BSC Mainnet
    guardrail_id: Some("xxx".to_string()),
    base_url: "https://...".to_string(),
    timeout: Duration::from_secs(30),
})?;
```

### `pg.validate(request)`

Validate a transaction:

```rust
let result = pg.validate(ValidateRequest {
    from: "0xAgent...".to_string(),
    to: "0xContract...".to_string(),
    data: "0x...".to_string(),
    value: Some("0".to_string()),
    guardrail_id: None,
    chain_id: None,
}).await?;

// ValidateResponse has:
// - validation_id: String
// - result: ValidationResult (Pass, Fail, Pending)
// - reason: String
// - safe: bool
// - checks: Vec<ValidationCheck>
// - authenticated: bool
// - evidence_uri: String
```

### `pg.validate_or_throw(request)`

Validate and return error if unsafe:

```rust
use proofgate::Error;

match pg.validate_or_throw(request).await {
    Ok(result) => {
        // Safe to execute
    }
    Err(Error::ValidationFailed { reason, result }) => {
        println!("Blocked: {}", reason);
    }
    Err(e) => return Err(e),
}
```

### `pg.check_agent(wallet)`

Check an agent's trust score:

```rust
let agent = pg.check_agent("0x123...").await?;

println!("{} {}/100", agent.tier_emoji, agent.trust_score);
// Output: 🥇 85/100
```

### `pg.get_evidence(validation_id)`

Get evidence for a past validation:

```rust
let evidence = pg.get_evidence("val_abc123").await?;
println!("{:?}", evidence.transaction);
```

## Guardrails

Guardrails define what your agent can do. Create them at [proofgate.xyz/guardrails](https://www.proofgate.xyz/guardrails).

Example guardrail rules:
- **Whitelist contracts**: Only Uniswap, Aave, Compound
- **Max approval**: 1,000 USDC per approval
- **Max slippage**: 1% on swaps
- **Daily limit**: $10,000 total spending

## Error Handling

```rust
use proofgate::Error;

match pg.validate(request).await {
    Ok(result) => { /* success */ }
    Err(Error::MissingApiKey) => { /* No API key */ }
    Err(Error::InvalidApiKey) => { /* Key doesn't start with pg_ */ }
    Err(Error::ValidationFailed { reason, .. }) => { /* Tx blocked */ }
    Err(Error::ApiError { status, message }) => { /* API error */ }
    Err(Error::NetworkError(e)) => { /* Network failed */ }
    Err(Error::Timeout) => { /* Request timeout */ }
    Err(Error::ParseError(e)) => { /* JSON parse failed */ }
}
```

## Feature Flags

- `native-tls` (default) - Use native TLS
- `rustls` - Use rustls for TLS

```toml
[dependencies]
proofgate = { version = "0.1", default-features = false, features = ["rustls"] }
```

## Get Your API Key

1. Go to [proofgate.xyz]https://www.proofgate.xyz
2. Connect your wallet
3. Register your AI agent
4. Copy your API key (starts with `pg_`)

**Free tier:** 100 validations/month

## Links

- **Website:** [proofgate.xyz]https://www.proofgate.xyz
- **Documentation:** [docs.rs/proofgate]https://docs.rs/proofgate
- **Dashboard:** [proofgate.xyz/dashboard]https://www.proofgate.xyz/dashboard
- **GitHub:** [github.com/ProofGate/proofgate-rs]https://github.com/ProofGate/proofgate-rs

## License

MIT © [0xCR6](https://twitter.com/0xCR6)