Skip to main content

self_agent_sdk/
lib.rs

1// SPDX-FileCopyrightText: 2025-2026 Social Connect Labs, Inc.
2// SPDX-License-Identifier: BUSL-1.1
3// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
4
5//! Rust SDK for Self Agent ID — on-chain AI agent identity with proof-of-human.
6//!
7//! # Quick Start
8//!
9//! ## Agent side (signing requests)
10//!
11//! ```no_run
12//! use self_agent_sdk::{SelfAgent, SelfAgentConfig, NetworkName};
13//!
14//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! # tokio::runtime::Runtime::new()?.block_on(async {
16//! let agent = SelfAgent::new(SelfAgentConfig {
17//!     private_key: "0x...".to_string(),
18//!     network: Some(NetworkName::Testnet),
19//!     registry_address: None,
20//!     rpc_url: None,
21//! })?;
22//!
23//! // Check on-chain status
24//! let registered = agent.is_registered().await?;
25//!
26//! // Auto-signed HTTP request
27//! let response = agent.fetch("https://api.example.com/data", None, None).await?;
28//! # let _ = (registered, response);
29//! # Ok::<(), Box<dyn std::error::Error>>(())
30//! # })?;
31//! # Ok(())
32//! # }
33//! ```
34//!
35//! ## Service side (verifying requests)
36//!
37//! ```no_run
38//! use self_agent_sdk::{SelfAgentVerifier, VerifierConfig};
39//!
40//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
41//! # tokio::runtime::Runtime::new()?.block_on(async {
42//! let mut verifier = SelfAgentVerifier::new(VerifierConfig::default());
43//! let signature = "0x...";
44//! let timestamp = "1700000000000";
45//! let body = r#"{"test":true}"#;
46//! let result = verifier.verify(signature, timestamp, "POST", "/api/data", Some(body)).await;
47//! if result.valid {
48//!     println!("Verified agent: {:?}", result.agent_address);
49//! }
50//! # Ok::<(), Box<dyn std::error::Error>>(())
51//! # })?;
52//! # Ok(())
53//! # }
54//! ```
55
56pub mod agent;
57pub mod agent_card;
58pub mod constants;
59pub mod ed25519_agent;
60pub mod registration;
61pub mod registration_flow;
62pub mod verifier;
63
64#[cfg(feature = "axum")]
65pub mod middleware;
66
67// Re-exports
68pub use agent::{AgentInfo, SelfAgent, SelfAgentConfig};
69pub use agent_card::{
70    AgentSkill, CardCredentials, SelfProtocolExtension, TrustModel,
71    AgentInterface, A2ACapabilities, A2AProvider,
72    SecurityScheme, JwsSignature, AgentExtension,
73    Erc8004Service, Erc8004Registration, Erc8004AgentDocument,
74    A2AOptions, GenerateRegistrationJsonOptions,
75    get_provider_label, get_strength_color, generate_registration_json,
76};
77
78pub use constants::{headers, NetworkName};
79pub use ed25519_agent::{Ed25519Agent, Ed25519AgentConfig};
80pub use registration::{
81    RegistrationDisclosures, SignatureParts, SignedRegistrationChallenge,
82    build_advanced_deregister_user_data_ascii, build_advanced_register_user_data_ascii,
83    build_simple_deregister_user_data_ascii, build_simple_register_user_data_ascii,
84    build_wallet_free_register_user_data_ascii, compute_registration_challenge_hash,
85    get_registration_config_index, sign_registration_challenge,
86};
87pub use registration_flow::{
88    DeregistrationRequest, DeregistrationSession, ProofRefreshRequest, ProofRefreshResult,
89    RefreshSession, RegistrationError, RegistrationRequest, RegistrationResult,
90    RegistrationSession, request_proof_refresh,
91};
92pub use verifier::{
93    AgentCredentials, RateLimitConfig, SelfAgentVerifier, VerificationResult, VerifierBuilder,
94    VerifierConfig, VerifierFromConfig,
95};
96
97#[cfg(feature = "axum")]
98pub use middleware::{self_agent_auth, VerifiedAgent};
99
100/// Errors that can occur in the SDK.
101#[derive(Debug, thiserror::Error)]
102pub enum Error {
103    #[error("invalid private key")]
104    InvalidPrivateKey,
105    #[error("invalid RPC URL")]
106    InvalidRpcUrl,
107    #[error("invalid signature")]
108    InvalidSignature,
109    #[error("signing error: {0}")]
110    SigningError(String),
111    #[error("RPC error: {0}")]
112    RpcError(String),
113    #[error("HTTP error: {0}")]
114    HttpError(String),
115}